diff --git a/.yarn/cache/@standardnotes-common-npm-1.48.3-83aea658e0-191d97879d.zip b/.yarn/cache/@standardnotes-common-npm-1.50.0-071931e90e-5388811ee5.zip similarity index 74% rename from .yarn/cache/@standardnotes-common-npm-1.48.3-83aea658e0-191d97879d.zip rename to .yarn/cache/@standardnotes-common-npm-1.50.0-071931e90e-5388811ee5.zip index 0be3e2087..8f7fe3ec9 100644 Binary files a/.yarn/cache/@standardnotes-common-npm-1.48.3-83aea658e0-191d97879d.zip and b/.yarn/cache/@standardnotes-common-npm-1.50.0-071931e90e-5388811ee5.zip differ diff --git a/.yarn/cache/@standardnotes-domain-core-npm-1.19.0-47cf4e4bba-40d3cad6d6.zip b/.yarn/cache/@standardnotes-domain-core-npm-1.22.0-066d18eb9d-aaa4812146.zip similarity index 75% rename from .yarn/cache/@standardnotes-domain-core-npm-1.19.0-47cf4e4bba-40d3cad6d6.zip rename to .yarn/cache/@standardnotes-domain-core-npm-1.22.0-066d18eb9d-aaa4812146.zip index 6ad7fc569..d78691796 100644 Binary files a/.yarn/cache/@standardnotes-domain-core-npm-1.19.0-47cf4e4bba-40d3cad6d6.zip and b/.yarn/cache/@standardnotes-domain-core-npm-1.22.0-066d18eb9d-aaa4812146.zip differ diff --git a/packages/api/package.json b/packages/api/package.json index 8a6ee79e5..dc643158e 100644 --- a/packages/api/package.json +++ b/packages/api/package.json @@ -36,8 +36,8 @@ "typescript": "*" }, "dependencies": { - "@standardnotes/common": "^1.48.3", - "@standardnotes/domain-core": "^1.12.0", + "@standardnotes/common": "^1.50.0", + "@standardnotes/domain-core": "^1.22.0", "@standardnotes/models": "workspace:*", "@standardnotes/responses": "workspace:*", "@standardnotes/security": "^1.7.6", diff --git a/packages/desktop/package.json b/packages/desktop/package.json index 27e1cd6c2..471781ba3 100644 --- a/packages/desktop/package.json +++ b/packages/desktop/package.json @@ -35,7 +35,7 @@ }, "dependencies": { "@electron/remote": "^2.0.9", - "@standardnotes/domain-core": "^1.18.0", + "@standardnotes/domain-core": "^1.22.0", "@standardnotes/electron-clear-data": "1.1.1", "@standardnotes/web": "workspace:*", "axios": "^1.1.3", diff --git a/packages/encryption/package.json b/packages/encryption/package.json index ff424d3b0..503eb326b 100644 --- a/packages/encryption/package.json +++ b/packages/encryption/package.json @@ -28,7 +28,8 @@ "typescript": "*" }, "dependencies": { - "@standardnotes/common": "^1.48.3", + "@standardnotes/common": "^1.50.0", + "@standardnotes/domain-core": "^1.22.0", "@standardnotes/models": "workspace:*", "@standardnotes/responses": "workspace:*", "@standardnotes/sncrypto-common": "workspace:*", diff --git a/packages/encryption/src/Domain/Keys/ItemsKey/ItemsKey.ts b/packages/encryption/src/Domain/Keys/ItemsKey/ItemsKey.ts index 383b76eb6..73b0b9e78 100644 --- a/packages/encryption/src/Domain/Keys/ItemsKey/ItemsKey.ts +++ b/packages/encryption/src/Domain/Keys/ItemsKey/ItemsKey.ts @@ -1,4 +1,5 @@ -import { ContentType, ProtocolVersion } from '@standardnotes/common' +import { ProtocolVersion } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { ConflictStrategy, DecryptedItem, @@ -10,7 +11,7 @@ import { } from '@standardnotes/models' export function isItemsKey(x: unknown): x is ItemsKeyInterface { - return (x as ItemsKeyInterface).content_type === ContentType.ItemsKey + return (x as ItemsKeyInterface).content_type === ContentType.TYPES.ItemsKey } /** diff --git a/packages/encryption/src/Domain/Keys/ItemsKey/Registration.ts b/packages/encryption/src/Domain/Keys/ItemsKey/Registration.ts index 74e904d82..7410cafdd 100644 --- a/packages/encryption/src/Domain/Keys/ItemsKey/Registration.ts +++ b/packages/encryption/src/Domain/Keys/ItemsKey/Registration.ts @@ -1,6 +1,10 @@ -import { ContentType } from '@standardnotes/common' import { DecryptedItemMutator, ItemsKeyContent, RegisterItemClass } from '@standardnotes/models' +import { ContentType } from '@standardnotes/domain-core' import { SNItemsKey } from './ItemsKey' import { ItemsKeyMutator } from './ItemsKeyMutator' -RegisterItemClass(ContentType.ItemsKey, SNItemsKey, ItemsKeyMutator as unknown as DecryptedItemMutator) +RegisterItemClass( + ContentType.TYPES.ItemsKey, + SNItemsKey, + ItemsKeyMutator as unknown as DecryptedItemMutator, +) diff --git a/packages/encryption/src/Domain/Keys/KeySystemItemsKey/KeySystemItemsKey.ts b/packages/encryption/src/Domain/Keys/KeySystemItemsKey/KeySystemItemsKey.ts index 9b52d4794..691218c96 100644 --- a/packages/encryption/src/Domain/Keys/KeySystemItemsKey/KeySystemItemsKey.ts +++ b/packages/encryption/src/Domain/Keys/KeySystemItemsKey/KeySystemItemsKey.ts @@ -1,4 +1,5 @@ -import { ContentType, ProtocolVersion } from '@standardnotes/common' +import { ProtocolVersion } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { ConflictStrategy, DecryptedItem, @@ -10,7 +11,7 @@ import { } from '@standardnotes/models' export function isKeySystemItemsKey(x: unknown): x is KeySystemItemsKeyInterface { - return (x as KeySystemItemsKeyInterface).content_type === ContentType.KeySystemItemsKey + return (x as KeySystemItemsKeyInterface).content_type === ContentType.TYPES.KeySystemItemsKey } /** diff --git a/packages/encryption/src/Domain/Keys/KeySystemItemsKey/Registration.ts b/packages/encryption/src/Domain/Keys/KeySystemItemsKey/Registration.ts index 721cecb64..0ef85f114 100644 --- a/packages/encryption/src/Domain/Keys/KeySystemItemsKey/Registration.ts +++ b/packages/encryption/src/Domain/Keys/KeySystemItemsKey/Registration.ts @@ -1,10 +1,11 @@ -import { ContentType } from '@standardnotes/common' import { DecryptedItemMutator, KeySystemItemsKeyContent, RegisterItemClass } from '@standardnotes/models' +import { ContentType } from '@standardnotes/domain-core' + import { KeySystemItemsKey } from './KeySystemItemsKey' import { KeySystemItemsKeyMutator } from './KeySystemItemsKeyMutator' RegisterItemClass( - ContentType.KeySystemItemsKey, + ContentType.TYPES.KeySystemItemsKey, KeySystemItemsKey, KeySystemItemsKeyMutator as unknown as DecryptedItemMutator, ) diff --git a/packages/encryption/src/Domain/Keys/RootKey/Functions.ts b/packages/encryption/src/Domain/Keys/RootKey/Functions.ts index 2cc0d30d5..c29ec1b40 100644 --- a/packages/encryption/src/Domain/Keys/RootKey/Functions.ts +++ b/packages/encryption/src/Domain/Keys/RootKey/Functions.ts @@ -1,4 +1,4 @@ -import { ContentType, ProtocolVersion } from '@standardnotes/common' +import { ProtocolVersion } from '@standardnotes/common' import { DecryptedPayload, FillItemContentSpecialized, @@ -9,13 +9,14 @@ import { } from '@standardnotes/models' import { UuidGenerator } from '@standardnotes/utils' import { SNRootKey } from './RootKey' +import { ContentType } from '@standardnotes/domain-core' export function CreateNewRootKey(content: RootKeyContentSpecialized): K { const uuid = UuidGenerator.GenerateUuid() const payload = new DecryptedPayload({ uuid: uuid, - content_type: ContentType.RootKey, + content_type: ContentType.TYPES.RootKey, content: FillRootKeyContent(content), ...PayloadTimestampDefaults(), }) diff --git a/packages/encryption/src/Domain/Operator/001/Operator001.ts b/packages/encryption/src/Domain/Operator/001/Operator001.ts index 93fe76c8d..fd67dcbd7 100644 --- a/packages/encryption/src/Domain/Operator/001/Operator001.ts +++ b/packages/encryption/src/Domain/Operator/001/Operator001.ts @@ -1,4 +1,4 @@ -import { ContentType, KeyParamsOrigination, ProtocolVersion, ProtocolVersionLength } from '@standardnotes/common' +import { KeyParamsOrigination, ProtocolVersion, ProtocolVersionLength } from '@standardnotes/common' import { CreateDecryptedItemFromPayload, DecryptedPayload, @@ -32,6 +32,7 @@ import { PublicKeySet } from '../Types/PublicKeySet' import { AsymmetricDecryptResult } from '../Types/AsymmetricDecryptResult' import { AsymmetricSignatureVerificationDetachedResult } from '../Types/AsymmetricSignatureVerificationDetachedResult' import { AsyncOperatorInterface } from '../OperatorInterface/AsyncOperatorInterface' +import { ContentType } from '@standardnotes/domain-core' const NO_IV = '00000000000000000000000000000000' @@ -71,7 +72,7 @@ export class SNProtocolOperator001 implements OperatorInterface, AsyncOperatorIn public createItemsKey(): ItemsKeyInterface { const payload = new DecryptedPayload({ uuid: UuidGenerator.GenerateUuid(), - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, content: this.generateNewItemsKeyContent(), ...PayloadTimestampDefaults(), }) diff --git a/packages/encryption/src/Domain/Operator/002/Operator002.ts b/packages/encryption/src/Domain/Operator/002/Operator002.ts index 5e7822f53..fef97d2c6 100644 --- a/packages/encryption/src/Domain/Operator/002/Operator002.ts +++ b/packages/encryption/src/Domain/Operator/002/Operator002.ts @@ -1,5 +1,6 @@ import * as Common from '@standardnotes/common' import * as Models from '@standardnotes/models' +import { ContentType } from '@standardnotes/domain-core' import { ItemContent, PayloadTimestampDefaults } from '@standardnotes/models' import * as Utils from '@standardnotes/utils' import { UuidGenerator } from '@standardnotes/utils' @@ -44,7 +45,7 @@ export class SNProtocolOperator002 extends SNProtocolOperator001 { public override createItemsKey(): Models.ItemsKeyInterface { const payload = new Models.DecryptedPayload({ uuid: UuidGenerator.GenerateUuid(), - content_type: Common.ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, content: this.generateNewItemsKeyContent(), ...PayloadTimestampDefaults(), }) diff --git a/packages/encryption/src/Domain/Operator/003/Operator003.ts b/packages/encryption/src/Domain/Operator/003/Operator003.ts index 9273844fe..f80edc6c1 100644 --- a/packages/encryption/src/Domain/Operator/003/Operator003.ts +++ b/packages/encryption/src/Domain/Operator/003/Operator003.ts @@ -1,4 +1,4 @@ -import { ContentType, KeyParamsOrigination, ProtocolVersion } from '@standardnotes/common' +import { KeyParamsOrigination, ProtocolVersion } from '@standardnotes/common' import { CreateDecryptedItemFromPayload, DecryptedPayload, @@ -14,6 +14,7 @@ import { CreateNewRootKey } from '../../Keys/RootKey/Functions' import { Create003KeyParams } from '../../Keys/RootKey/KeyParamsFunctions' import { SNRootKeyParams } from '../../Keys/RootKey/RootKeyParams' import { SNProtocolOperator002 } from '../002/Operator002' +import { ContentType } from '@standardnotes/domain-core' /** * @legacy @@ -46,7 +47,7 @@ export class SNProtocolOperator003 extends SNProtocolOperator002 { const content = this.generateNewItemsKeyContent() const payload = new DecryptedPayload({ uuid: UuidGenerator.GenerateUuid(), - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, content: FillItemContent(content), ...PayloadTimestampDefaults(), }) diff --git a/packages/encryption/src/Domain/Operator/004/Operator004.spec.ts b/packages/encryption/src/Domain/Operator/004/Operator004.spec.ts index 1118292bf..083764c4b 100644 --- a/packages/encryption/src/Domain/Operator/004/Operator004.spec.ts +++ b/packages/encryption/src/Domain/Operator/004/Operator004.spec.ts @@ -1,9 +1,10 @@ -import { ContentType, ProtocolVersion } from '@standardnotes/common' +import { ProtocolVersion } from '@standardnotes/common' import { DecryptedPayload, ItemContent, ItemsKeyContent, PayloadTimestampDefaults } from '@standardnotes/models' import { SNItemsKey } from '../../Keys/ItemsKey/ItemsKey' import { SNProtocolOperator004 } from './Operator004' import { getMockedCrypto } from './MockedCrypto' import { deconstructEncryptedPayloadString } from './V004AlgorithmHelpers' +import { ContentType } from '@standardnotes/domain-core' describe('operator 004', () => { const crypto = getMockedCrypto() @@ -31,7 +32,7 @@ describe('operator 004', () => { it('should generateEncryptedParameters', () => { const payload = { uuid: '123', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: { foo: 'bar' } as unknown as jest.Mocked, ...PayloadTimestampDefaults(), } as jest.Mocked @@ -39,7 +40,7 @@ describe('operator 004', () => { const key = new SNItemsKey( new DecryptedPayload({ uuid: 'key-456', - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, content: { itemsKey: 'secret', version: ProtocolVersion.V004, @@ -56,7 +57,7 @@ describe('operator 004', () => { key_system_identifier: undefined, shared_vault_uuid: undefined, content: '004:random-string:{"foo"|"bar"}:base64-{"u"|"123","v"|"004"}:base64-{}', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, enc_item_key: '004:random-string:random-string:base64-{"u"|"123","v"|"004"}:base64-{}', version: '004', }) diff --git a/packages/encryption/src/Domain/Operator/004/Operator004.ts b/packages/encryption/src/Domain/Operator/004/Operator004.ts index 5fceb1121..bbfa98a6b 100644 --- a/packages/encryption/src/Domain/Operator/004/Operator004.ts +++ b/packages/encryption/src/Domain/Operator/004/Operator004.ts @@ -13,7 +13,7 @@ import { RootKeyInterface, KeySystemRootKeyParamsInterface, } from '@standardnotes/models' -import { ContentType, KeyParamsOrigination, ProtocolVersion } from '@standardnotes/common' +import { KeyParamsOrigination, ProtocolVersion } from '@standardnotes/common' import { HexString, PkcKeyPair, PureCryptoInterface, Utf8String } from '@standardnotes/sncrypto-common' import { V004Algorithm } from '../../Algorithm' import { SNRootKeyParams } from '../../Keys/RootKey/RootKeyParams' @@ -48,6 +48,7 @@ import { AsymmetricSignatureVerificationDetachedResult } from '../Types/Asymmetr import { AsymmetricSignatureVerificationDetachedUseCase } from './UseCase/Asymmetric/AsymmetricSignatureVerificationDetached' import { DeriveKeySystemRootKeyUseCase } from './UseCase/KeySystem/DeriveKeySystemRootKey' import { SyncOperatorInterface } from '../OperatorInterface/SyncOperatorInterface' +import { ContentType } from '@standardnotes/domain-core' export class SNProtocolOperator004 implements OperatorInterface, SyncOperatorInterface { constructor(protected readonly crypto: PureCryptoInterface) {} @@ -76,7 +77,7 @@ export class SNProtocolOperator004 implements OperatorInterface, SyncOperatorInt public createItemsKey(): ItemsKeyInterface { const payload = new DecryptedPayload({ uuid: UuidGenerator.GenerateUuid(), - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, content: this.generateNewItemsKeyContent(), key_system_identifier: undefined, shared_vault_uuid: undefined, diff --git a/packages/encryption/src/Domain/Operator/004/UseCase/KeySystem/CreateKeySystemItemsKey.ts b/packages/encryption/src/Domain/Operator/004/UseCase/KeySystem/CreateKeySystemItemsKey.ts index 3671e4203..594652e5e 100644 --- a/packages/encryption/src/Domain/Operator/004/UseCase/KeySystem/CreateKeySystemItemsKey.ts +++ b/packages/encryption/src/Domain/Operator/004/UseCase/KeySystem/CreateKeySystemItemsKey.ts @@ -10,7 +10,8 @@ import { } from '@standardnotes/models' import { PureCryptoInterface } from '@standardnotes/sncrypto-common' import { V004Algorithm } from '../../../../Algorithm' -import { ContentType, ProtocolVersion } from '@standardnotes/common' +import { ProtocolVersion } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' export class CreateKeySystemItemsKeyUseCase { constructor(private readonly crypto: PureCryptoInterface) {} @@ -31,7 +32,7 @@ export class CreateKeySystemItemsKeyUseCase { const transferPayload: DecryptedTransferPayload = { uuid: dto.uuid, - content_type: ContentType.KeySystemItemsKey, + content_type: ContentType.TYPES.KeySystemItemsKey, key_system_identifier: dto.keySystemIdentifier, shared_vault_uuid: dto.sharedVaultUuid, content: content, diff --git a/packages/encryption/src/Domain/Operator/004/UseCase/KeySystem/DeriveKeySystemRootKey.ts b/packages/encryption/src/Domain/Operator/004/UseCase/KeySystem/DeriveKeySystemRootKey.ts index db6790320..d0aed46cb 100644 --- a/packages/encryption/src/Domain/Operator/004/UseCase/KeySystem/DeriveKeySystemRootKey.ts +++ b/packages/encryption/src/Domain/Operator/004/UseCase/KeySystem/DeriveKeySystemRootKey.ts @@ -12,7 +12,8 @@ import { PayloadTimestampDefaults, KeySystemRootKeyParamsInterface, } from '@standardnotes/models' -import { ContentType, ProtocolVersion } from '@standardnotes/common' +import { ProtocolVersion } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' export class DeriveKeySystemRootKeyUseCase { constructor(private readonly crypto: PureCryptoInterface) {} @@ -44,7 +45,7 @@ export class DeriveKeySystemRootKeyUseCase { const payload = new DecryptedPayload({ uuid: uuid, - content_type: ContentType.KeySystemRootKey, + content_type: ContentType.TYPES.KeySystemRootKey, content: FillItemContentSpecialized(content), ...PayloadTimestampDefaults(), }) diff --git a/packages/encryption/src/Domain/Operator/004/UseCase/Symmetric/GenerateAuthenticatedData.spec.ts b/packages/encryption/src/Domain/Operator/004/UseCase/Symmetric/GenerateAuthenticatedData.spec.ts index 0b409b4cb..87aa310b9 100644 --- a/packages/encryption/src/Domain/Operator/004/UseCase/Symmetric/GenerateAuthenticatedData.spec.ts +++ b/packages/encryption/src/Domain/Operator/004/UseCase/Symmetric/GenerateAuthenticatedData.spec.ts @@ -1,5 +1,5 @@ import { CreateAnyKeyParams } from '../../../../Keys/RootKey/KeyParamsFunctions' -import { AnyKeyParamsContent, ContentType, ProtocolVersion } from '@standardnotes/common' +import { AnyKeyParamsContent, ProtocolVersion } from '@standardnotes/common' import { GenerateAuthenticatedDataUseCase } from './GenerateAuthenticatedData' import { DecryptedPayloadInterface, @@ -8,6 +8,7 @@ import { RootKeyInterface, } from '@standardnotes/models' import { KeySystemItemsKey } from '../../../../Keys/KeySystemItemsKey/KeySystemItemsKey' +import { ContentType } from '@standardnotes/domain-core' describe('generate authenticated data use case', () => { let usecase: GenerateAuthenticatedDataUseCase @@ -19,7 +20,7 @@ describe('generate authenticated data use case', () => { it('should include key params if payload being encrypted is an items key', () => { const payload = { uuid: '123', - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, } as jest.Mocked const keyParams = CreateAnyKeyParams({ @@ -42,7 +43,7 @@ describe('generate authenticated data use case', () => { it('should include root key params if payload is a key system items key', () => { const payload = { uuid: '123', - content_type: ContentType.KeySystemItemsKey, + content_type: ContentType.TYPES.KeySystemItemsKey, shared_vault_uuid: 'shared-vault-uuid-123', key_system_identifier: 'key-system-identifier-123', } as jest.Mocked @@ -52,7 +53,7 @@ describe('generate authenticated data use case', () => { keyParams: { seed: 'seed-123', }, - content_type: ContentType.KeySystemRootKey, + content_type: ContentType.TYPES.KeySystemRootKey, token: '123', } as jest.Mocked @@ -70,7 +71,7 @@ describe('generate authenticated data use case', () => { it('should include key system identifier and shared vault uuid', () => { const payload = { uuid: '123', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, shared_vault_uuid: 'shared-vault-uuid-123', key_system_identifier: 'key-system-identifier-123', } as jest.Mocked @@ -78,7 +79,7 @@ describe('generate authenticated data use case', () => { const itemsKey = { creationTimestamp: 123, keyVersion: ProtocolVersion.V004, - content_type: ContentType.KeySystemItemsKey, + content_type: ContentType.TYPES.KeySystemItemsKey, } as jest.Mocked const authenticatedData = usecase.execute(payload, itemsKey) @@ -94,11 +95,11 @@ describe('generate authenticated data use case', () => { it('should include only uuid and version if non-keysystem item with items key', () => { const payload = { uuid: '123', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, } as jest.Mocked const itemsKey = { - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, } as jest.Mocked const authenticatedData = usecase.execute(payload, itemsKey) diff --git a/packages/encryption/src/Domain/Operator/004/UseCase/Symmetric/GenerateDecryptedParameters.spec.ts b/packages/encryption/src/Domain/Operator/004/UseCase/Symmetric/GenerateDecryptedParameters.spec.ts index db5583165..b0b74cb35 100644 --- a/packages/encryption/src/Domain/Operator/004/UseCase/Symmetric/GenerateDecryptedParameters.spec.ts +++ b/packages/encryption/src/Domain/Operator/004/UseCase/Symmetric/GenerateDecryptedParameters.spec.ts @@ -1,10 +1,10 @@ import { PkcKeyPair, PureCryptoInterface } from '@standardnotes/sncrypto-common' import { getMockedCrypto } from '../../MockedCrypto' import { GenerateDecryptedParametersUseCase } from './GenerateDecryptedParameters' -import { ContentType } from '@standardnotes/common' import { DecryptedPayloadInterface, ItemsKeyInterface } from '@standardnotes/models' import { GenerateEncryptedParametersUseCase } from './GenerateEncryptedParameters' import { EncryptedInputParameters, EncryptedOutputParameters } from '../../../../Types/EncryptedParameters' +import { ContentType } from '@standardnotes/domain-core' describe('generate decrypted parameters usecase', () => { let crypto: PureCryptoInterface @@ -18,7 +18,7 @@ describe('generate decrypted parameters usecase', () => { itemsKey = { uuid: 'items-key-id', itemsKey: 'items-key', - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, } as jest.Mocked }) @@ -28,7 +28,7 @@ describe('generate decrypted parameters usecase', () => { content: { text: plaintext, }, - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, } as unknown as jest.Mocked const encryptedParametersUsecase = new GenerateEncryptedParametersUseCase(crypto) diff --git a/packages/encryption/src/Domain/Operator/004/UseCase/Symmetric/GenerateEncryptedParameters.spec.ts b/packages/encryption/src/Domain/Operator/004/UseCase/Symmetric/GenerateEncryptedParameters.spec.ts index ed80094b8..750302ba4 100644 --- a/packages/encryption/src/Domain/Operator/004/UseCase/Symmetric/GenerateEncryptedParameters.spec.ts +++ b/packages/encryption/src/Domain/Operator/004/UseCase/Symmetric/GenerateEncryptedParameters.spec.ts @@ -1,6 +1,6 @@ import { PkcKeyPair, PureCryptoInterface } from '@standardnotes/sncrypto-common' import { getMockedCrypto } from '../../MockedCrypto' -import { AnyKeyParamsContent, ContentType, ProtocolVersion } from '@standardnotes/common' +import { AnyKeyParamsContent, ProtocolVersion } from '@standardnotes/common' import { GenerateEncryptedParametersUseCase } from './GenerateEncryptedParameters' import { DecryptedPayloadInterface, @@ -11,6 +11,7 @@ import { import { deconstructEncryptedPayloadString } from '../../V004AlgorithmHelpers' import { ParseConsistentBase64JsonPayloadUseCase } from '../Utils/ParseConsistentBase64JsonPayload' import { SymmetricItemAdditionalData } from '../../../../Types/EncryptionAdditionalData' +import { ContentType } from '@standardnotes/domain-core' describe('generate encrypted parameters usecase', () => { let crypto: PureCryptoInterface @@ -29,20 +30,20 @@ describe('generate encrypted parameters usecase', () => { title: 'title', text: 'text', }, - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, } as unknown as jest.Mocked const itemsKey = { uuid: 'items-key-id', itemsKey: 'items-key', - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, } as jest.Mocked const result = usecase.execute(decrypted, itemsKey) expect(result).toEqual({ uuid: '123', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, items_key_id: 'items-key-id', content: expect.any(String), enc_item_key: expect.any(String), @@ -57,7 +58,7 @@ describe('generate encrypted parameters usecase', () => { content: { foo: 'bar', }, - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, } as unknown as jest.Mocked const rootKey = { @@ -66,7 +67,7 @@ describe('generate encrypted parameters usecase', () => { keyParams: { content: {} as jest.Mocked, }, - content_type: ContentType.RootKey, + content_type: ContentType.TYPES.RootKey, } as jest.Mocked const result = usecase.execute(decrypted, rootKey) @@ -80,13 +81,13 @@ describe('generate encrypted parameters usecase', () => { content: { foo: 'bar', }, - content_type: ContentType.KeySystemItemsKey, + content_type: ContentType.TYPES.KeySystemItemsKey, } as unknown as jest.Mocked const rootKey = { uuid: 'items-key-id', itemsKey: 'items-key', - content_type: ContentType.KeySystemRootKey, + content_type: ContentType.TYPES.KeySystemRootKey, } as jest.Mocked const result = usecase.execute(decrypted, rootKey) @@ -111,13 +112,13 @@ describe('generate encrypted parameters usecase', () => { title: 'title', text: 'text', }, - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, } as unknown as jest.Mocked const itemsKey = { uuid: 'items-key-id', itemsKey: 'items-key', - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, } as jest.Mocked const result = usecase.execute(decrypted, itemsKey, signingKeyPair) diff --git a/packages/encryption/src/Domain/Types/EncryptedParameters.ts b/packages/encryption/src/Domain/Types/EncryptedParameters.ts index 1640f0fc2..3a3ec53ed 100644 --- a/packages/encryption/src/Domain/Types/EncryptedParameters.ts +++ b/packages/encryption/src/Domain/Types/EncryptedParameters.ts @@ -1,11 +1,11 @@ -import { ContentType, ProtocolVersion } from '@standardnotes/common' +import { ProtocolVersion } from '@standardnotes/common' import { EncryptedPayloadInterface, DecryptedPayloadInterface, PersistentSignatureData } from '@standardnotes/models' import { DecryptedParameters } from './DecryptedParameters' export type EncryptedOutputParameters = { uuid: string content: string - content_type: ContentType + content_type: string items_key_id: string | undefined enc_item_key: string version: ProtocolVersion diff --git a/packages/features/package.json b/packages/features/package.json index 1f0783cfc..a4a0676be 100644 --- a/packages/features/package.json +++ b/packages/features/package.json @@ -25,8 +25,8 @@ "test": "jest" }, "dependencies": { - "@standardnotes/common": "^1.48.3", - "@standardnotes/domain-core": "^1.12.0", + "@standardnotes/common": "^1.50.0", + "@standardnotes/domain-core": "^1.22.0", "@standardnotes/security": "^1.7.6", "reflect-metadata": "^0.1.13" }, diff --git a/packages/features/src/Domain/Component/ComponentPermission.ts b/packages/features/src/Domain/Component/ComponentPermission.ts index 41ca8d7b9..e782037a1 100644 --- a/packages/features/src/Domain/Component/ComponentPermission.ts +++ b/packages/features/src/Domain/Component/ComponentPermission.ts @@ -1,7 +1,6 @@ -import { ContentType } from '@standardnotes/common' import { ComponentAction } from './ComponentAction' export type ComponentPermission = { name: ComponentAction - content_types?: ContentType[] + content_types?: string[] } diff --git a/packages/features/src/Domain/Feature/FeatureDescription.ts b/packages/features/src/Domain/Feature/FeatureDescription.ts index 24b445913..7b87eafc1 100644 --- a/packages/features/src/Domain/Feature/FeatureDescription.ts +++ b/packages/features/src/Domain/Feature/FeatureDescription.ts @@ -1,5 +1,4 @@ import { ComponentPermission } from '../Component/ComponentPermission' -import { ContentType } from '@standardnotes/common' import { ComponentArea } from '../Component/ComponentArea' import { PermissionName } from '../Permission/PermissionName' import { FeatureIdentifier } from './FeatureIdentifier' @@ -51,7 +50,7 @@ export type ClientFeatureDescription = RoleFields & { export type ComponentFeatureDescription = BaseFeatureDescription & { /** The relative path of the index.html file or the main css file if theme, within the component folder itself */ index_path: string - content_type: ContentType + content_type: string area: ComponentArea } diff --git a/packages/features/src/Domain/Lists/DeprecatedFeatures.ts b/packages/features/src/Domain/Lists/DeprecatedFeatures.ts index f974d11bd..8af3498f3 100644 --- a/packages/features/src/Domain/Lists/DeprecatedFeatures.ts +++ b/packages/features/src/Domain/Lists/DeprecatedFeatures.ts @@ -1,4 +1,4 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType, RoleName } from '@standardnotes/domain-core' import { EditorFeatureDescription, IframeComponentFeatureDescription, @@ -10,7 +10,6 @@ import { NoteType } from '../Component/NoteType' import { FillEditorComponentDefaults } from './Utilities/FillEditorComponentDefaults' import { ComponentAction } from '../Component/ComponentAction' import { ComponentArea } from '../Component/ComponentArea' -import { RoleName } from '@standardnotes/domain-core' export function GetDeprecatedFeatures(): FeatureDescription[] { const bold: EditorFeatureDescription = FillEditorComponentDefaults({ @@ -21,14 +20,14 @@ export function GetDeprecatedFeatures(): FeatureDescription[] { component_permissions: [ { name: ComponentAction.StreamContextItem, - content_types: [ContentType.Note], + content_types: [ContentType.TYPES.Note], }, { name: ComponentAction.StreamItems, content_types: [ - ContentType.FilesafeCredentials, - ContentType.FilesafeFileMetadata, - ContentType.FilesafeIntegration, + ContentType.TYPES.FilesafeCredentials, + ContentType.TYPES.FilesafeFileMetadata, + ContentType.TYPES.FilesafeIntegration, ], }, ], @@ -101,14 +100,14 @@ export function GetDeprecatedFeatures(): FeatureDescription[] { component_permissions: [ { name: ComponentAction.StreamContextItem, - content_types: [ContentType.Note], + content_types: [ContentType.TYPES.Note], }, { name: ComponentAction.StreamItems, content_types: [ - ContentType.FilesafeCredentials, - ContentType.FilesafeFileMetadata, - ContentType.FilesafeIntegration, + ContentType.TYPES.FilesafeCredentials, + ContentType.TYPES.FilesafeFileMetadata, + ContentType.TYPES.FilesafeIntegration, ], }, ], diff --git a/packages/features/src/Domain/Lists/Utilities/FillEditorComponentDefaults.ts b/packages/features/src/Domain/Lists/Utilities/FillEditorComponentDefaults.ts index 5f5c0a8e8..7dd7d9a8b 100644 --- a/packages/features/src/Domain/Lists/Utilities/FillEditorComponentDefaults.ts +++ b/packages/features/src/Domain/Lists/Utilities/FillEditorComponentDefaults.ts @@ -1,5 +1,6 @@ +import { ContentType } from '@standardnotes/domain-core' + import { ComponentAction } from '../../Component/ComponentAction' -import { ContentType } from '@standardnotes/common' import { EditorFeatureDescription } from '../../Feature/FeatureDescription' import { ComponentArea } from '../../Component/ComponentArea' @@ -16,12 +17,12 @@ export function FillEditorComponentDefaults( component.component_permissions = [ { name: ComponentAction.StreamContextItem, - content_types: [ContentType.Note], + content_types: [ContentType.TYPES.Note], }, ] } - component.content_type = ContentType.Component + component.content_type = ContentType.TYPES.Component if (!component.area) { component.area = ComponentArea.Editor } diff --git a/packages/features/src/Domain/Lists/Utilities/FillThemeComponentDefaults.ts b/packages/features/src/Domain/Lists/Utilities/FillThemeComponentDefaults.ts index ebff21976..d9ee9e82e 100644 --- a/packages/features/src/Domain/Lists/Utilities/FillThemeComponentDefaults.ts +++ b/packages/features/src/Domain/Lists/Utilities/FillThemeComponentDefaults.ts @@ -1,4 +1,5 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' + import { ThemeFeatureDescription } from '../../Feature/FeatureDescription' import { ComponentArea } from '../../Component/ComponentArea' @@ -11,7 +12,7 @@ export function FillThemeComponentDefaults( theme.index_path = 'index.css' } - theme.content_type = ContentType.Theme + theme.content_type = ContentType.TYPES.Theme if (!theme.area) { theme.area = ComponentArea.Themes diff --git a/packages/filepicker/example/src/classic_file_api.ts b/packages/filepicker/example/src/classic_file_api.ts index 5be2f1b36..5c18804af 100644 --- a/packages/filepicker/example/src/classic_file_api.ts +++ b/packages/filepicker/example/src/classic_file_api.ts @@ -39,7 +39,7 @@ export class ClassicFileApi { downloadFileBytes = async (remoteIdentifier: string): Promise => { console.log('Downloading file', remoteIdentifier) const file = this.application['itemManager'] - .getItems(ContentType.File) + .getItems(ContentType.TYPES.File) .find((file: FileItem) => file.remoteIdentifier === remoteIdentifier) let receivedBytes = new Uint8Array() diff --git a/packages/filepicker/package.json b/packages/filepicker/package.json index ade9b2a05..d9104f162 100644 --- a/packages/filepicker/package.json +++ b/packages/filepicker/package.json @@ -26,7 +26,7 @@ "typescript": "*" }, "dependencies": { - "@standardnotes/common": "^1.48.3", + "@standardnotes/common": "^1.50.0", "@standardnotes/files": "workspace:*", "@standardnotes/utils": "workspace:*", "@types/wicg-file-system-access": "^2020.9.5", diff --git a/packages/files/package.json b/packages/files/package.json index 267642706..8bea5c8af 100644 --- a/packages/files/package.json +++ b/packages/files/package.json @@ -28,7 +28,7 @@ "typescript": "*" }, "dependencies": { - "@standardnotes/common": "^1.48.3", + "@standardnotes/common": "^1.50.0", "@standardnotes/encryption": "workspace:*", "@standardnotes/models": "workspace:*", "@standardnotes/responses": "workspace:*", diff --git a/packages/models/package.json b/packages/models/package.json index a4bbd36dd..8144ce710 100644 --- a/packages/models/package.json +++ b/packages/models/package.json @@ -22,7 +22,8 @@ "test": "jest" }, "dependencies": { - "@standardnotes/common": "^1.48.3", + "@standardnotes/common": "^1.50.0", + "@standardnotes/domain-core": "^1.22.0", "@standardnotes/features": "workspace:*", "@standardnotes/responses": "workspace:*", "@standardnotes/sncrypto-common": "workspace:^", diff --git a/packages/models/src/Domain/Abstract/Component/MessageData.ts b/packages/models/src/Domain/Abstract/Component/MessageData.ts index 02a970c51..72b1f1c8f 100644 --- a/packages/models/src/Domain/Abstract/Component/MessageData.ts +++ b/packages/models/src/Domain/Abstract/Component/MessageData.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { ComponentPermission } from '@standardnotes/features' import { IncomingComponentItemPayload } from './IncomingComponentItemPayload' @@ -8,7 +7,7 @@ export type MessageData = Partial<{ /** Related to the stream-item-context action */ item?: IncomingComponentItemPayload /** Related to the stream-items action */ - content_types?: ContentType[] + content_types?: string[] items?: IncomingComponentItemPayload[] /** Related to the request-permission action */ permissions?: ComponentPermission[] @@ -25,7 +24,7 @@ export type MessageData = Partial<{ /** Related to themes action */ themes?: string[] /** Related to clear-selection action */ - content_type?: ContentType + content_type?: string /** Related to key-pressed action */ keyboardModifier?: KeyboardModifier }> diff --git a/packages/models/src/Domain/Abstract/Component/OutgoingItemMessagePayload.ts b/packages/models/src/Domain/Abstract/Component/OutgoingItemMessagePayload.ts index a5bc7d723..446ab23aa 100644 --- a/packages/models/src/Domain/Abstract/Component/OutgoingItemMessagePayload.ts +++ b/packages/models/src/Domain/Abstract/Component/OutgoingItemMessagePayload.ts @@ -1,9 +1,8 @@ import { ItemContent } from './../Content/ItemContent' -import { ContentType } from '@standardnotes/common' export type OutgoingItemMessagePayload = { uuid: string - content_type: ContentType + content_type: string created_at: Date updated_at: Date deleted?: boolean diff --git a/packages/models/src/Domain/Abstract/Contextual/ContextPayload.ts b/packages/models/src/Domain/Abstract/Contextual/ContextPayload.ts index 256706a19..ef4ea9fe3 100644 --- a/packages/models/src/Domain/Abstract/Contextual/ContextPayload.ts +++ b/packages/models/src/Domain/Abstract/Contextual/ContextPayload.ts @@ -1,9 +1,8 @@ -import { ContentType } from '@standardnotes/common' import { ItemContent } from '../Content/ItemContent' export interface ContextPayload { uuid: string - content_type: ContentType + content_type: string content: C | string | undefined deleted: boolean diff --git a/packages/models/src/Domain/Abstract/Contextual/OfflineSyncSaved.ts b/packages/models/src/Domain/Abstract/Contextual/OfflineSyncSaved.ts index e6d9b64aa..2d4e22b26 100644 --- a/packages/models/src/Domain/Abstract/Contextual/OfflineSyncSaved.ts +++ b/packages/models/src/Domain/Abstract/Contextual/OfflineSyncSaved.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { DecryptedPayloadInterface, DeletedPayloadInterface, isDeletedPayload } from '../Payload' /** @@ -8,7 +7,7 @@ import { DecryptedPayloadInterface, DeletedPayloadInterface, isDeletedPayload } * nothing else. */ export interface OfflineSyncSavedContextualPayload { - content_type: ContentType + content_type: string created_at_timestamp: number deleted: boolean updated_at_timestamp?: number diff --git a/packages/models/src/Domain/Abstract/Contextual/ServerSyncSaved.ts b/packages/models/src/Domain/Abstract/Contextual/ServerSyncSaved.ts index 8ec169fe0..cac3636e6 100644 --- a/packages/models/src/Domain/Abstract/Contextual/ServerSyncSaved.ts +++ b/packages/models/src/Domain/Abstract/Contextual/ServerSyncSaved.ts @@ -1,6 +1,5 @@ import { useBoolean } from '@standardnotes/utils' import { FilteredServerItem } from './FilteredServerItem' -import { ContentType } from '@standardnotes/common' /** * The saved sync item payload represents the payload we want to map @@ -9,7 +8,7 @@ import { ContentType } from '@standardnotes/common' * nothing else. */ export interface ServerSyncSavedContextualPayload { - content_type: ContentType + content_type: string created_at_timestamp: number created_at: Date deleted: boolean diff --git a/packages/models/src/Domain/Abstract/Item/Implementations/GenericItem.ts b/packages/models/src/Domain/Abstract/Item/Implementations/GenericItem.ts index ba974a484..5869e7eda 100644 --- a/packages/models/src/Domain/Abstract/Item/Implementations/GenericItem.ts +++ b/packages/models/src/Domain/Abstract/Item/Implementations/GenericItem.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { dateToLocalizedString, deepFreeze } from '@standardnotes/utils' import { TransferPayload } from './../../TransferPayload/Interfaces/TransferPayload' import { ItemContentsDiffer } from '../../../Utilities/Item/ItemContentsDiffer' @@ -36,7 +35,7 @@ export abstract class GenericItem

return this.payload.uuid } - get content_type(): ContentType { + get content_type(): string { return this.payload.content_type } diff --git a/packages/models/src/Domain/Abstract/Item/Interfaces/ItemInterface.ts b/packages/models/src/Domain/Abstract/Item/Interfaces/ItemInterface.ts index 3e399aecf..ad074e753 100644 --- a/packages/models/src/Domain/Abstract/Item/Interfaces/ItemInterface.ts +++ b/packages/models/src/Domain/Abstract/Item/Interfaces/ItemInterface.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { TransferPayload } from './../../TransferPayload/Interfaces/TransferPayload' import { PayloadInterface } from '../../Payload/Interfaces/PayloadInterface' import { PredicateInterface } from '../../../Runtime/Predicate/Interface' @@ -21,7 +20,7 @@ export interface ItemInterface

{ get last_edited_by_uuid(): string | undefined get signatureData(): PersistentSignatureData | undefined - content_type: ContentType + content_type: string created_at: Date serverUpdatedAt: Date serverUpdatedAtTimestamp: number | undefined diff --git a/packages/models/src/Domain/Abstract/Payload/Implementations/PurePayload.ts b/packages/models/src/Domain/Abstract/Payload/Implementations/PurePayload.ts index d30c87e32..373f07ef3 100644 --- a/packages/models/src/Domain/Abstract/Payload/Implementations/PurePayload.ts +++ b/packages/models/src/Domain/Abstract/Payload/Implementations/PurePayload.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { deepFreeze, useBoolean } from '@standardnotes/utils' import { PayloadInterface } from '../Interfaces/PayloadInterface' import { PayloadSource } from '../Types/PayloadSource' @@ -19,7 +18,7 @@ export abstract class PurePayload, C extends ItemCo { readonly source: PayloadSource readonly uuid: string - readonly content_type: ContentType + readonly content_type: string readonly deleted: boolean readonly content: C | string | undefined diff --git a/packages/models/src/Domain/Abstract/Payload/Interfaces/PayloadInterface.ts b/packages/models/src/Domain/Abstract/Payload/Interfaces/PayloadInterface.ts index 1819b11e6..503f7a66f 100644 --- a/packages/models/src/Domain/Abstract/Payload/Interfaces/PayloadInterface.ts +++ b/packages/models/src/Domain/Abstract/Payload/Interfaces/PayloadInterface.ts @@ -1,5 +1,4 @@ import { SyncResolvedParams, SyncResolvedPayload } from './../../../Runtime/Deltas/Utilities/SyncResolvedPayload' -import { ContentType } from '@standardnotes/common' import { ItemContent } from '../../Content/ItemContent' import { TransferPayload } from '../../TransferPayload/Interfaces/TransferPayload' import { PayloadSource } from '../Types/PayloadSource' @@ -8,7 +7,7 @@ import { PersistentSignatureData } from '../../../Runtime/Encryption/PersistentS export interface PayloadInterface { readonly source: PayloadSource readonly uuid: string - readonly content_type: ContentType + readonly content_type: string content: C | string | undefined deleted: boolean diff --git a/packages/models/src/Domain/Abstract/Reference/AnonymousReference.ts b/packages/models/src/Domain/Abstract/Reference/AnonymousReference.ts index 253929d40..e9fbdd56e 100644 --- a/packages/models/src/Domain/Abstract/Reference/AnonymousReference.ts +++ b/packages/models/src/Domain/Abstract/Reference/AnonymousReference.ts @@ -1,8 +1,7 @@ -import { ContentType } from '@standardnotes/common' import { ContentReferenceType } from './ContenteReferenceType' export interface AnonymousReference { uuid: string - content_type: ContentType + content_type: string reference_type: ContentReferenceType } diff --git a/packages/models/src/Domain/Abstract/Reference/FileToFileReference.ts b/packages/models/src/Domain/Abstract/Reference/FileToFileReference.ts index f6f7daf12..deb2c804e 100644 --- a/packages/models/src/Domain/Abstract/Reference/FileToFileReference.ts +++ b/packages/models/src/Domain/Abstract/Reference/FileToFileReference.ts @@ -1,8 +1,7 @@ -import { ContentType } from '@standardnotes/common' import { AnonymousReference } from './AnonymousReference' import { ContentReferenceType } from './ContenteReferenceType' export interface FileToFileReference extends AnonymousReference { - content_type: ContentType.File + content_type: string reference_type: ContentReferenceType.FileToFile } diff --git a/packages/models/src/Domain/Abstract/Reference/FileToNoteReference.ts b/packages/models/src/Domain/Abstract/Reference/FileToNoteReference.ts index 5ae3e2ec1..da68675a3 100644 --- a/packages/models/src/Domain/Abstract/Reference/FileToNoteReference.ts +++ b/packages/models/src/Domain/Abstract/Reference/FileToNoteReference.ts @@ -1,8 +1,7 @@ -import { ContentType } from '@standardnotes/common' import { AnonymousReference } from './AnonymousReference' import { ContentReferenceType } from './ContenteReferenceType' export interface FileToNoteReference extends AnonymousReference { - content_type: ContentType.Note + content_type: string reference_type: ContentReferenceType.FileToNote } diff --git a/packages/models/src/Domain/Abstract/Reference/Functions.ts b/packages/models/src/Domain/Abstract/Reference/Functions.ts index 18c0a5434..1cfdde476 100644 --- a/packages/models/src/Domain/Abstract/Reference/Functions.ts +++ b/packages/models/src/Domain/Abstract/Reference/Functions.ts @@ -1,5 +1,5 @@ -/* eslint-disable @typescript-eslint/no-explicit-any */ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' + import { ItemInterface } from '../Item/Interfaces/ItemInterface' import { ContentReferenceType } from './ContenteReferenceType' import { ContentReference } from './ContentReference' @@ -20,8 +20,8 @@ export const isLegacyTagToNoteReference = ( x: LegacyAnonymousReference, currentItem: ItemInterface, ): x is LegacyTagToNoteReference => { - const isReferenceToANote = x.content_type === ContentType.Note - const isReferenceFromATag = currentItem.content_type === ContentType.Tag + const isReferenceToANote = x.content_type === ContentType.TYPES.Note + const isReferenceFromATag = currentItem.content_type === ContentType.TYPES.Tag return isReferenceToANote && isReferenceFromATag } diff --git a/packages/models/src/Domain/Abstract/Reference/LegacyTagToNoteReference.ts b/packages/models/src/Domain/Abstract/Reference/LegacyTagToNoteReference.ts index 61a47284c..9deb5e55b 100644 --- a/packages/models/src/Domain/Abstract/Reference/LegacyTagToNoteReference.ts +++ b/packages/models/src/Domain/Abstract/Reference/LegacyTagToNoteReference.ts @@ -1,6 +1,5 @@ -import { ContentType } from '@standardnotes/common' import { LegacyAnonymousReference } from './LegacyAnonymousReference' export interface LegacyTagToNoteReference extends LegacyAnonymousReference { - content_type: ContentType.Note + content_type: string } diff --git a/packages/models/src/Domain/Abstract/Reference/NoteToNoteReference.ts b/packages/models/src/Domain/Abstract/Reference/NoteToNoteReference.ts index 5370304d9..43c209083 100644 --- a/packages/models/src/Domain/Abstract/Reference/NoteToNoteReference.ts +++ b/packages/models/src/Domain/Abstract/Reference/NoteToNoteReference.ts @@ -1,8 +1,7 @@ -import { ContentType } from '@standardnotes/common' import { AnonymousReference } from './AnonymousReference' import { ContentReferenceType } from './ContenteReferenceType' export interface NoteToNoteReference extends AnonymousReference { - content_type: ContentType.Note + content_type: string reference_type: ContentReferenceType.NoteToNote } diff --git a/packages/models/src/Domain/Abstract/Reference/TagToFileReference.ts b/packages/models/src/Domain/Abstract/Reference/TagToFileReference.ts index b9b34e073..dfe6b2d6c 100644 --- a/packages/models/src/Domain/Abstract/Reference/TagToFileReference.ts +++ b/packages/models/src/Domain/Abstract/Reference/TagToFileReference.ts @@ -1,8 +1,7 @@ -import { ContentType } from '@standardnotes/common' import { AnonymousReference } from './AnonymousReference' import { ContentReferenceType } from './ContenteReferenceType' export interface TagToFileReference extends AnonymousReference { - content_type: ContentType.File + content_type: string reference_type: ContentReferenceType.TagToFile } diff --git a/packages/models/src/Domain/Abstract/Reference/TagToParentTagReference.ts b/packages/models/src/Domain/Abstract/Reference/TagToParentTagReference.ts index cdf74ec2c..3cf9b36fd 100644 --- a/packages/models/src/Domain/Abstract/Reference/TagToParentTagReference.ts +++ b/packages/models/src/Domain/Abstract/Reference/TagToParentTagReference.ts @@ -1,8 +1,7 @@ -import { ContentType } from '@standardnotes/common' import { AnonymousReference } from './AnonymousReference' import { ContentReferenceType } from './ContenteReferenceType' export interface TagToParentTagReference extends AnonymousReference { - content_type: ContentType.Tag + content_type: string reference_type: ContentReferenceType.TagToParentTag } diff --git a/packages/models/src/Domain/Abstract/TransferPayload/Interfaces/TransferPayload.ts b/packages/models/src/Domain/Abstract/TransferPayload/Interfaces/TransferPayload.ts index 91ec7be33..fca3c9c30 100644 --- a/packages/models/src/Domain/Abstract/TransferPayload/Interfaces/TransferPayload.ts +++ b/packages/models/src/Domain/Abstract/TransferPayload/Interfaces/TransferPayload.ts @@ -1,10 +1,9 @@ -import { ContentType } from '@standardnotes/common' import { ItemContent } from '../../Content/ItemContent' import { PersistentSignatureData } from '../../../Runtime/Encryption/PersistentSignatureData' export interface TransferPayload { uuid: string - content_type: ContentType + content_type: string content: C | string | undefined deleted?: boolean diff --git a/packages/models/src/Domain/Abstract/TransferPayload/Interfaces/TypeCheck.spec.ts b/packages/models/src/Domain/Abstract/TransferPayload/Interfaces/TypeCheck.spec.ts index 5299bf1c4..9234b150a 100644 --- a/packages/models/src/Domain/Abstract/TransferPayload/Interfaces/TypeCheck.spec.ts +++ b/packages/models/src/Domain/Abstract/TransferPayload/Interfaces/TypeCheck.spec.ts @@ -1,4 +1,4 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { PayloadTimestampDefaults } from '../../Payload' import { isCorruptTransferPayload } from './TypeCheck' @@ -8,7 +8,7 @@ describe('type check', () => { expect( isCorruptTransferPayload({ uuid: '123', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: '123', ...PayloadTimestampDefaults(), }), @@ -19,7 +19,7 @@ describe('type check', () => { expect( isCorruptTransferPayload({ uuid: undefined as never, - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: '123', ...PayloadTimestampDefaults(), }), @@ -30,7 +30,7 @@ describe('type check', () => { expect( isCorruptTransferPayload({ uuid: '123', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: '123', deleted: true, ...PayloadTimestampDefaults(), @@ -42,7 +42,7 @@ describe('type check', () => { expect( isCorruptTransferPayload({ uuid: '123', - content_type: ContentType.Unknown, + content_type: ContentType.TYPES.Unknown, content: '123', ...PayloadTimestampDefaults(), }), diff --git a/packages/models/src/Domain/Abstract/TransferPayload/Interfaces/TypeCheck.ts b/packages/models/src/Domain/Abstract/TransferPayload/Interfaces/TypeCheck.ts index 17f8c4485..9466a6d96 100644 --- a/packages/models/src/Domain/Abstract/TransferPayload/Interfaces/TypeCheck.ts +++ b/packages/models/src/Domain/Abstract/TransferPayload/Interfaces/TypeCheck.ts @@ -1,4 +1,4 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { isObject, isString } from '@standardnotes/utils' import { DecryptedTransferPayload } from './DecryptedTransferPayload' import { DeletedTransferPayload } from './DeletedTransferPayload' @@ -26,5 +26,5 @@ export function isDeletedTransferPayload(payload: TransferPayload): payload is D export function isCorruptTransferPayload(payload: TransferPayload): boolean { const invalidDeletedState = payload.deleted === true && payload.content != undefined - return payload.uuid == undefined || invalidDeletedState || payload.content_type === ContentType.Unknown + return payload.uuid == undefined || invalidDeletedState || payload.content_type === ContentType.TYPES.Unknown } diff --git a/packages/models/src/Domain/Runtime/Collection/Collection.ts b/packages/models/src/Domain/Runtime/Collection/Collection.ts index 31320f9dd..f16317c1d 100644 --- a/packages/models/src/Domain/Runtime/Collection/Collection.ts +++ b/packages/models/src/Domain/Runtime/Collection/Collection.ts @@ -1,12 +1,11 @@ import { extendArray, isObject, isString, UuidMap } from '@standardnotes/utils' -import { ContentType } from '@standardnotes/common' import { remove } from 'lodash' import { ItemContent } from '../../Abstract/Content/ItemContent' import { ContentReference } from '../../Abstract/Item' export interface CollectionElement { uuid: string - content_type: ContentType + content_type: string dirty?: boolean deleted?: boolean } @@ -33,7 +32,7 @@ export abstract class Collection< Deleted extends DeletedCollectionElement, > { readonly map: Partial> = {} - readonly typedMap: Partial> = {} + readonly typedMap: Partial> = {} /** An array of uuids of items that are dirty */ dirtyIndex: Set = new Set() @@ -74,7 +73,7 @@ export abstract class Collection< constructor( copy = false, mapCopy?: Partial>, - typedMapCopy?: Partial>, + typedMapCopy?: Partial>, referenceMapCopy?: UuidMap, conflictMapCopy?: UuidMap, ) { @@ -93,7 +92,7 @@ export abstract class Collection< return Object.keys(this.map) } - public all(contentType?: ContentType | ContentType[]): Element[] { + public all(contentType?: string | string[]): Element[] { if (contentType) { if (Array.isArray(contentType)) { const elements: Element[] = [] @@ -254,7 +253,7 @@ export abstract class Collection< return this.findAll(uuids) } - public elementsReferencingElement(element: Decrypted, contentType?: ContentType): Element[] { + public elementsReferencingElement(element: Decrypted, contentType?: string): Element[] { const uuids = this.uuidsThatReferenceUuid(element.uuid) const items = this.findAll(uuids) diff --git a/packages/models/src/Domain/Runtime/Collection/CollectionSort.ts b/packages/models/src/Domain/Runtime/Collection/CollectionSort.ts index d409f40b6..f117a542e 100644 --- a/packages/models/src/Domain/Runtime/Collection/CollectionSort.ts +++ b/packages/models/src/Domain/Runtime/Collection/CollectionSort.ts @@ -1,8 +1,6 @@ -import { ContentType } from '@standardnotes/common' - export interface SortableItem { uuid: string - content_type: ContentType + content_type: string created_at: Date userModifiedDate: Date title?: string diff --git a/packages/models/src/Domain/Runtime/Collection/Item/ItemCollection.spec.ts b/packages/models/src/Domain/Runtime/Collection/Item/ItemCollection.spec.ts index 2dbb1d391..bb775af03 100644 --- a/packages/models/src/Domain/Runtime/Collection/Item/ItemCollection.spec.ts +++ b/packages/models/src/Domain/Runtime/Collection/Item/ItemCollection.spec.ts @@ -1,5 +1,5 @@ import { NoteContent } from './../../../Syncable/Note/NoteContent' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { DecryptedItem } from '../../../Abstract/Item' import { DecryptedPayload, PayloadTimestampDefaults } from '../../../Abstract/Payload' import { ItemCollection } from './ItemCollection' @@ -9,7 +9,7 @@ describe('item collection', () => { const createDecryptedPayload = (uuid?: string, content?: Partial): DecryptedPayload => { return new DecryptedPayload({ uuid: uuid || String(Math.random()), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: FillItemContent({ title: 'foo', ...content, diff --git a/packages/models/src/Domain/Runtime/Collection/Item/ItemCollection.ts b/packages/models/src/Domain/Runtime/Collection/Item/ItemCollection.ts index ee5868afc..9b04fc70a 100644 --- a/packages/models/src/Domain/Runtime/Collection/Item/ItemCollection.ts +++ b/packages/models/src/Domain/Runtime/Collection/Item/ItemCollection.ts @@ -1,6 +1,5 @@ import { ItemContent } from './../../../Abstract/Content/ItemContent' import { EncryptedItemInterface } from './../../../Abstract/Item/Interfaces/EncryptedItem' -import { ContentType } from '@standardnotes/common' import { SNIndex } from '../../Index/SNIndex' import { isDecryptedItem } from '../../../Abstract/Item/Interfaces/TypeCheck' import { DecryptedItemInterface } from '../../../Abstract/Item/Interfaces/DecryptedItem' @@ -53,7 +52,7 @@ export class ItemCollection return mapped as (DecryptedItemInterface | undefined)[] } - public allDecrypted(contentType: ContentType | ContentType[]): T[] { + public allDecrypted(contentType: string | string[]): T[] { return this.all(contentType).filter(isDecryptedItem) as T[] } } diff --git a/packages/models/src/Domain/Runtime/Collection/Item/ItemCounter.spec.ts b/packages/models/src/Domain/Runtime/Collection/Item/ItemCounter.spec.ts index ba9dd2ec4..b355954d7 100644 --- a/packages/models/src/Domain/Runtime/Collection/Item/ItemCounter.spec.ts +++ b/packages/models/src/Domain/Runtime/Collection/Item/ItemCounter.spec.ts @@ -1,6 +1,6 @@ import { ItemCounter } from './ItemCounter' import { NoteContent } from '../../../Syncable/Note/NoteContent' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { DecryptedItem, EncryptedItem } from '../../../Abstract/Item' import { DecryptedPayload, EncryptedPayload, PayloadTimestampDefaults } from '../../../Abstract/Payload' import { ItemCollection } from './ItemCollection' @@ -12,7 +12,7 @@ describe('tag notes index', () => { const createEncryptedItem = (uuid?: string) => { const payload = new EncryptedPayload({ uuid: uuid || String(Math.random()), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: '004:...', enc_item_key: '004:...', items_key_id: '123', @@ -24,7 +24,7 @@ describe('tag notes index', () => { return new EncryptedItem(payload) } - const createDecryptedItem = (uuid?: string, content_type = ContentType.Note) => { + const createDecryptedItem = (uuid?: string, content_type = ContentType.TYPES.Note) => { const payload = new DecryptedPayload({ uuid: uuid || String(Math.random()), content_type, diff --git a/packages/models/src/Domain/Runtime/Collection/Item/ItemCounter.ts b/packages/models/src/Domain/Runtime/Collection/Item/ItemCounter.ts index 869d05e45..05a42b1c4 100644 --- a/packages/models/src/Domain/Runtime/Collection/Item/ItemCounter.ts +++ b/packages/models/src/Domain/Runtime/Collection/Item/ItemCounter.ts @@ -1,5 +1,4 @@ import { removeFromArray } from '@standardnotes/utils' -import { ContentType } from '@standardnotes/common' import { isTag, SNTag } from '../../../Syncable/Tag/Tag' import { SNIndex } from '../../Index/SNIndex' import { ItemCollection } from './ItemCollection' @@ -13,6 +12,7 @@ import { HiddenContentCriteriaValidator } from '../../Display/Validator/HiddenCo import { CustomFilterCriteriaValidator } from '../../Display/Validator/CustomFilterCriteriaValidator' import { AnyDisplayOptions, VaultDisplayOptions } from '../../Display' import { isExclusioanaryOptionsValue } from '../../Display/VaultDisplayOptionsTypes' +import { ContentType } from '@standardnotes/domain-core' type AllNotesUuidSignifier = undefined export type TagItemCountChangeObserver = (tagUuid: string | AllNotesUuidSignifier) => void @@ -20,7 +20,7 @@ export type TagItemCountChangeObserver = (tagUuid: string | AllNotesUuidSignifie export class ItemCounter implements SNIndex { private tagToItemsMap: Partial>> = {} private allCountableItems = new Set() - private countableItemsByType = new Map>() + private countableItemsByType = new Map>() private displayOptions?: AnyDisplayOptions private vaultDisplayOptions?: VaultDisplayOptions @@ -50,11 +50,11 @@ export class ItemCounter implements SNIndex { } public allCountableNotesCount(): number { - return this.countableItemsByType.get(ContentType.Note)?.size || 0 + return this.countableItemsByType.get(ContentType.TYPES.Note)?.size || 0 } public allCountableFilesCount(): number { - return this.countableItemsByType.get(ContentType.File)?.size || 0 + return this.countableItemsByType.get(ContentType.TYPES.File)?.size || 0 } public countableItemsForTag(tag: SNTag): number { @@ -63,7 +63,7 @@ export class ItemCounter implements SNIndex { public onChange(delta: ItemDelta): void { const items = [...delta.changed, ...delta.inserted, ...delta.discarded].filter( - (i) => i.content_type === ContentType.Note || i.content_type === ContentType.File, + (i) => i.content_type === ContentType.TYPES.Note || i.content_type === ContentType.TYPES.File, ) const tags = [...delta.changed, ...delta.inserted].filter(isDecryptedItem).filter(isTag) @@ -115,7 +115,7 @@ export class ItemCounter implements SNIndex { private receiveTagChanges(tags: SNTag[]): void { for (const tag of tags) { const uuids = tag.references - .filter((ref) => ref.content_type === ContentType.Note || ref.content_type === ContentType.File) + .filter((ref) => ref.content_type === ContentType.TYPES.Note || ref.content_type === ContentType.TYPES.File) .map((ref) => ref.uuid) const countableUuids = uuids.filter((uuid) => this.allCountableItems.has(uuid)) const previousSet = this.tagToItemsMap[tag.uuid] diff --git a/packages/models/src/Domain/Runtime/Collection/Payload/ImmutablePayloadCollection.ts b/packages/models/src/Domain/Runtime/Collection/Payload/ImmutablePayloadCollection.ts index 3d52bfe8d..e85d460db 100644 --- a/packages/models/src/Domain/Runtime/Collection/Payload/ImmutablePayloadCollection.ts +++ b/packages/models/src/Domain/Runtime/Collection/Payload/ImmutablePayloadCollection.ts @@ -1,5 +1,4 @@ import { FullyFormedPayloadInterface } from './../../../Abstract/Payload/Interfaces/UnionTypes' -import { ContentType } from '@standardnotes/common' import { UuidMap } from '@standardnotes/utils' import { PayloadCollection } from './PayloadCollection' @@ -33,7 +32,7 @@ export class ImmutablePayloadCollection< const result = new ImmutablePayloadCollection( true, mapCopy, - typedMapCopy as Partial>, + typedMapCopy as Partial>, referenceMapCopy, conflictMapCopy, ) diff --git a/packages/models/src/Domain/Runtime/Deltas/Conflict.spec.ts b/packages/models/src/Domain/Runtime/Deltas/Conflict.spec.ts index edd117ac5..dce3b5a1e 100644 --- a/packages/models/src/Domain/Runtime/Deltas/Conflict.spec.ts +++ b/packages/models/src/Domain/Runtime/Deltas/Conflict.spec.ts @@ -1,4 +1,4 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { FillItemContent } from '../../Abstract/Content/ItemContent' import { ConflictStrategy } from '../../Abstract/Item' import { @@ -25,7 +25,7 @@ describe('conflict delta', () => { const createDecryptedItemsKey = (uuid: string, key: string, timestamp = 0) => { return new DecryptedPayload({ uuid: uuid, - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, content: FillItemContent({ itemsKey: key, }), @@ -37,7 +37,7 @@ describe('conflict delta', () => { const createErroredItemsKey = (uuid: string, timestamp = 0) => { return new EncryptedPayload({ uuid: uuid, - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, content: '004:...', enc_item_key: '004:...', items_key_id: undefined, diff --git a/packages/models/src/Domain/Runtime/Deltas/Conflict.ts b/packages/models/src/Domain/Runtime/Deltas/Conflict.ts index 843fafe3f..a4c81fa4b 100644 --- a/packages/models/src/Domain/Runtime/Deltas/Conflict.ts +++ b/packages/models/src/Domain/Runtime/Deltas/Conflict.ts @@ -1,4 +1,5 @@ import { uniqCombineObjArrays } from '@standardnotes/utils' +import { ContentType } from '@standardnotes/domain-core' import { ImmutablePayloadCollection } from '../Collection/Payload/ImmutablePayloadCollection' import { CreateDecryptedItemFromPayload, CreateItemFromPayload } from '../../Utilities/Item/ItemGenerator' import { HistoryMap, historyMapFunctions } from '../History/HistoryMap' @@ -11,7 +12,6 @@ import { isErrorDecryptingPayload, isDeletedPayload, } from '../../Abstract/Payload/Interfaces/TypeCheck' -import { ContentType } from '@standardnotes/common' import { SyncResolvedPayload } from './Utilities/SyncResolvedPayload' import { ItemsKeyDelta } from './ItemsKeyDelta' import { SourcelessSyncDeltaEmit } from './Abstract/DeltaEmit' @@ -26,7 +26,7 @@ export class ConflictDelta { ) {} public result(): SourcelessSyncDeltaEmit { - if (this.applyPayload.content_type === ContentType.ItemsKey) { + if (this.applyPayload.content_type === ContentType.TYPES.ItemsKey) { const keyDelta = new ItemsKeyDelta(this.baseCollection, [this.applyPayload]) return keyDelta.result() diff --git a/packages/models/src/Domain/Runtime/Deltas/ItemsKeyDelta.spec.ts b/packages/models/src/Domain/Runtime/Deltas/ItemsKeyDelta.spec.ts index 3ec99b697..8b69db5de 100644 --- a/packages/models/src/Domain/Runtime/Deltas/ItemsKeyDelta.spec.ts +++ b/packages/models/src/Domain/Runtime/Deltas/ItemsKeyDelta.spec.ts @@ -1,4 +1,4 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { FillItemContent } from '../../Abstract/Content/ItemContent' import { DecryptedPayload, @@ -16,7 +16,7 @@ describe('items key delta', () => { const baseCollection = new PayloadCollection() const basePayload = new DecryptedPayload({ uuid: '123', - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, content: FillItemContent({ itemsKey: 'secret', }), @@ -28,7 +28,7 @@ describe('items key delta', () => { const payloadToIgnore = new EncryptedPayload({ uuid: '123', - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, content: '004:...', enc_item_key: '004:...', items_key_id: undefined, diff --git a/packages/models/src/Domain/Runtime/Deltas/OutOfSync.ts b/packages/models/src/Domain/Runtime/Deltas/OutOfSync.ts index 91540a549..bbdc3e683 100644 --- a/packages/models/src/Domain/Runtime/Deltas/OutOfSync.ts +++ b/packages/models/src/Domain/Runtime/Deltas/OutOfSync.ts @@ -2,7 +2,7 @@ import { PayloadEmitSource } from '../../Abstract/Payload' import { isDecryptedPayload } from '../../Abstract/Payload/Interfaces/TypeCheck' import { PayloadContentsEqual } from '../../Utilities/Payload/PayloadContentsEqual' import { ConflictDelta } from './Conflict' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { ItemsKeyDelta } from './ItemsKeyDelta' import { payloadByFinalizingSyncState } from './Utilities/ApplyDirtyState' import { ImmutablePayloadCollection } from '../Collection/Payload/ImmutablePayloadCollection' @@ -25,7 +25,7 @@ export class DeltaOutOfSync implements SyncDeltaInterface { } for (const apply of this.applyCollection.all()) { - if (apply.content_type === ContentType.ItemsKey) { + if (apply.content_type === ContentType.TYPES.ItemsKey) { const itemsKeyDeltaEmit = new ItemsKeyDelta(this.baseCollection, [apply]).result() extendSyncDelta(result, itemsKeyDeltaEmit) diff --git a/packages/models/src/Domain/Runtime/Deltas/RemoteRejected.spec.ts b/packages/models/src/Domain/Runtime/Deltas/RemoteRejected.spec.ts index 17304f5d9..963879a82 100644 --- a/packages/models/src/Domain/Runtime/Deltas/RemoteRejected.spec.ts +++ b/packages/models/src/Domain/Runtime/Deltas/RemoteRejected.spec.ts @@ -1,4 +1,4 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { FillItemContent } from '../../Abstract/Content/ItemContent' import { DecryptedPayload, FullyFormedPayloadInterface, PayloadTimestampDefaults } from '../../Abstract/Payload' import { NoteContent } from '../../Syncable/Note' @@ -15,7 +15,7 @@ describe('remote rejected delta', () => { const baseCollection = new PayloadCollection() const basePayload = new DecryptedPayload({ uuid: '123', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, dirty: true, content: FillItemContent({ title: 'foo', diff --git a/packages/models/src/Domain/Runtime/Deltas/RemoteRejected.ts b/packages/models/src/Domain/Runtime/Deltas/RemoteRejected.ts index aac65c260..60ba0a5aa 100644 --- a/packages/models/src/Domain/Runtime/Deltas/RemoteRejected.ts +++ b/packages/models/src/Domain/Runtime/Deltas/RemoteRejected.ts @@ -15,7 +15,7 @@ import { ConflictType, } from '@standardnotes/responses' import { PayloadsByDuplicating } from '../../Utilities/Payload/PayloadsByDuplicating' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' export class DeltaRemoteRejected implements SyncDeltaInterface { constructor( @@ -61,7 +61,7 @@ export class DeltaRemoteRejected implements SyncDeltaInterface { return this.resultByDuplicatingBasePayloadAsNonVaultedAndRemovingBaseItemLocally(base) } - if (base.content_type === ContentType.KeySystemItemsKey) { + if (base.content_type === ContentType.TYPES.KeySystemItemsKey) { return this.discardChangesOfBasePayload(base) } diff --git a/packages/models/src/Domain/Runtime/Deltas/RemoteRetrieved.spec.ts b/packages/models/src/Domain/Runtime/Deltas/RemoteRetrieved.spec.ts index 991fc2610..664f29fbd 100644 --- a/packages/models/src/Domain/Runtime/Deltas/RemoteRetrieved.spec.ts +++ b/packages/models/src/Domain/Runtime/Deltas/RemoteRetrieved.spec.ts @@ -1,4 +1,4 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { FillItemContent } from '../../Abstract/Content/ItemContent' import { DecryptedPayload, @@ -16,7 +16,7 @@ describe('remote retrieved delta', () => { const baseCollection = new PayloadCollection() const basePayload = new DecryptedPayload({ uuid: '123', - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, content: FillItemContent({ itemsKey: 'secret', }), @@ -28,7 +28,7 @@ describe('remote retrieved delta', () => { const payloadToIgnore = new EncryptedPayload({ uuid: '123', - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, content: '004:...', enc_item_key: '004:...', items_key_id: undefined, diff --git a/packages/models/src/Domain/Runtime/Deltas/RemoteRetrieved.ts b/packages/models/src/Domain/Runtime/Deltas/RemoteRetrieved.ts index d441cba8b..21a2e2025 100644 --- a/packages/models/src/Domain/Runtime/Deltas/RemoteRetrieved.ts +++ b/packages/models/src/Domain/Runtime/Deltas/RemoteRetrieved.ts @@ -2,7 +2,7 @@ import { ImmutablePayloadCollection } from './../Collection/Payload/ImmutablePay import { ConflictDelta } from './Conflict' import { isErrorDecryptingPayload, isDecryptedPayload } from '../../Abstract/Payload/Interfaces/TypeCheck' import { FullyFormedPayloadInterface, PayloadEmitSource } from '../../Abstract/Payload' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { HistoryMap } from '../History' import { ServerSyncPushContextualPayload } from '../../Abstract/Contextual/ServerSyncPush' import { payloadByFinalizingSyncState } from './Utilities/ApplyDirtyState' @@ -36,7 +36,10 @@ export class DeltaRemoteRetrieved implements SyncDeltaInterface { * or if the item is locally dirty, filter it out of retrieved_items, and add to potential conflicts. */ for (const apply of this.applyCollection.all()) { - if (apply.content_type === ContentType.ItemsKey || apply.content_type === ContentType.KeySystemItemsKey) { + if ( + apply.content_type === ContentType.TYPES.ItemsKey || + apply.content_type === ContentType.TYPES.KeySystemItemsKey + ) { const itemsKeyDeltaEmit = new ItemsKeyDelta(this.baseCollection, [apply]).result() extendSyncDelta(result, itemsKeyDeltaEmit) diff --git a/packages/models/src/Domain/Runtime/Display/DisplayOptions.ts b/packages/models/src/Domain/Runtime/Display/DisplayOptions.ts index 25a215398..a6fbec02e 100644 --- a/packages/models/src/Domain/Runtime/Display/DisplayOptions.ts +++ b/packages/models/src/Domain/Runtime/Display/DisplayOptions.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { SmartView } from '../../Syncable/SmartView' import { SNTag } from '../../Syncable/Tag' import { CollectionSortDirection, CollectionSortProperty } from '../Collection/CollectionSort' @@ -16,7 +15,7 @@ export interface NotesAndFilesDisplayOptions extends GenericDisplayOptions { tags?: SNTag[] views?: SmartView[] searchQuery?: SearchQuery - hiddenContentTypes?: ContentType[] + hiddenContentTypes?: string[] customFilter?: DisplayControllerCustomFilter } diff --git a/packages/models/src/Domain/Runtime/Display/DisplayOptionsToFilters.ts b/packages/models/src/Domain/Runtime/Display/DisplayOptionsToFilters.ts index 4c51e32dc..e8c3da9f0 100644 --- a/packages/models/src/Domain/Runtime/Display/DisplayOptionsToFilters.ts +++ b/packages/models/src/Domain/Runtime/Display/DisplayOptionsToFilters.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { DecryptedItem } from '../../Abstract/Item' import { SNTag } from '../../Syncable/Tag' import { CompoundPredicate } from '../Predicate/CompoundPredicate' @@ -7,6 +6,7 @@ import { itemMatchesQuery, itemPassesFilters } from './Search/SearchUtilities' import { ItemFilter, ReferenceLookupCollection, SearchableDecryptedItem } from './Search/Types' import { NotesAndFilesDisplayOptions } from './DisplayOptions' import { SystemViewId } from '../../Syncable/SmartView' +import { ContentType } from '@standardnotes/domain-core' export function computeUnifiedFilterForDisplayOptions( options: NotesAndFilesDisplayOptions, @@ -40,7 +40,7 @@ export function computeFiltersForDisplayOptions( const noteWithTags = ItemWithTags.Create( item.payload, item, - collection.elementsReferencingElement(item, ContentType.Tag) as SNTag[], + collection.elementsReferencingElement(item, ContentType.TYPES.Tag) as SNTag[], ) return compoundPredicate.matchesItem(noteWithTags) } else { diff --git a/packages/models/src/Domain/Runtime/Display/ItemDisplayController.spec.ts b/packages/models/src/Domain/Runtime/Display/ItemDisplayController.spec.ts index 9c386883e..bbd02e8d1 100644 --- a/packages/models/src/Domain/Runtime/Display/ItemDisplayController.spec.ts +++ b/packages/models/src/Domain/Runtime/Display/ItemDisplayController.spec.ts @@ -1,7 +1,7 @@ import { CreateItemDelta } from './../Index/ItemDelta' import { DeletedPayload } from './../../Abstract/Payload/Implementations/DeletedPayload' import { createFile, createNote, createTagWithTitle, mockUuid, pinnedContent } from './../../Utilities/Test/SpecUtils' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { DeletedItem, EncryptedItem } from '../../Abstract/Item' import { EncryptedPayload, PayloadTimestampDefaults } from '../../Abstract/Payload' import { createNoteWithContent } from '../../Utilities/Test/SpecUtils' @@ -16,7 +16,7 @@ describe('item display controller', () => { const noteB = createNoteWithContent({ title: 'b' }) collection.set([noteA, noteB]) - const controller = new ItemDisplayController(collection, [ContentType.Note], { + const controller = new ItemDisplayController(collection, [ContentType.TYPES.Note], { sortBy: 'title', sortDirection: 'asc', }) @@ -36,7 +36,7 @@ describe('item display controller', () => { const noteB = createNoteWithContent({ title: 'b' }) collection.set([noteA, noteB]) - const controller = new ItemDisplayController(collection, [ContentType.Note], { + const controller = new ItemDisplayController(collection, [ContentType.TYPES.Note], { sortBy: 'title', sortDirection: 'asc', }) @@ -56,7 +56,7 @@ describe('item display controller', () => { const noteA = createNoteWithContent({ title: 'a' }) collection.set([noteA]) - const controller = new ItemDisplayController(collection, [ContentType.Note], { + const controller = new ItemDisplayController(collection, [ContentType.TYPES.Note], { sortBy: 'title', sortDirection: 'asc', }) @@ -76,7 +76,7 @@ describe('item display controller', () => { const noteA = new EncryptedItem( new EncryptedPayload({ uuid: mockUuid(), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: '004:...', enc_item_key: '004:...', items_key_id: mockUuid(), @@ -87,7 +87,7 @@ describe('item display controller', () => { ) collection.set([noteA]) - const controller = new ItemDisplayController(collection, [ContentType.Note], { + const controller = new ItemDisplayController(collection, [ContentType.TYPES.Note], { sortBy: 'title', sortDirection: 'asc', }) @@ -101,7 +101,7 @@ describe('item display controller', () => { const noteB = createNoteWithContent({ title: 'b' }) collection.set([noteA, noteB]) - const controller = new ItemDisplayController(collection, [ContentType.Note], { + const controller = new ItemDisplayController(collection, [ContentType.TYPES.Note], { sortBy: 'title', sortDirection: 'asc', }) @@ -134,7 +134,7 @@ describe('item display controller', () => { const noteA = createNoteWithContent({ title: 'a' }) collection.set([noteA]) - const controller = new ItemDisplayController(collection, [ContentType.Note], { + const controller = new ItemDisplayController(collection, [ContentType.TYPES.Note], { sortBy: 'title', sortDirection: 'asc', }) @@ -159,7 +159,7 @@ describe('item display controller', () => { const noteA = createNoteWithContent({ title: 'a' }) collection.set([noteA]) - const controller = new ItemDisplayController(collection, [ContentType.Note], { + const controller = new ItemDisplayController(collection, [ContentType.TYPES.Note], { sortBy: 'title', sortDirection: 'asc', }) @@ -177,7 +177,7 @@ describe('item display controller', () => { const tag = createTagWithTitle() collection.set([note, tag]) - const controller = new ItemDisplayController(collection, [ContentType.Note], { + const controller = new ItemDisplayController(collection, [ContentType.TYPES.Note], { sortBy: 'title', sortDirection: 'asc', }) @@ -190,7 +190,7 @@ describe('item display controller', () => { const tag = createTagWithTitle() collection.set([note, tag]) - const controller = new ItemDisplayController(collection, [ContentType.Note], { + const controller = new ItemDisplayController(collection, [ContentType.TYPES.Note], { sortBy: 'title', sortDirection: 'asc', }) @@ -203,7 +203,7 @@ describe('item display controller', () => { const note = createNoteWithContent({ title: 'a' }) collection.set([note]) - const controller = new ItemDisplayController(collection, [ContentType.Note], { + const controller = new ItemDisplayController(collection, [ContentType.TYPES.Note], { sortBy: 'title', sortDirection: 'asc', }) @@ -222,7 +222,7 @@ describe('item display controller', () => { const file = createFile('A') collection.set([note, file]) - const controller = new ItemDisplayController(collection, [ContentType.Note, ContentType.File], { + const controller = new ItemDisplayController(collection, [ContentType.TYPES.Note, ContentType.TYPES.File], { sortBy: 'title', sortDirection: 'asc', }) @@ -242,14 +242,14 @@ describe('item display controller', () => { const file = createFile() collection.set([note, file]) - const controller = new ItemDisplayController(collection, [ContentType.Note, ContentType.File], { + const controller = new ItemDisplayController(collection, [ContentType.TYPES.Note, ContentType.TYPES.File], { sortBy: 'title', sortDirection: 'asc', }) expect(controller.items()).toHaveLength(2) - controller.setDisplayOptions({ hiddenContentTypes: [ContentType.File] }) + controller.setDisplayOptions({ hiddenContentTypes: [ContentType.TYPES.File] }) expect(controller.items()).toHaveLength(1) }) diff --git a/packages/models/src/Domain/Runtime/Display/ItemDisplayController.ts b/packages/models/src/Domain/Runtime/Display/ItemDisplayController.ts index f438860e4..68b0b2d22 100644 --- a/packages/models/src/Domain/Runtime/Display/ItemDisplayController.ts +++ b/packages/models/src/Domain/Runtime/Display/ItemDisplayController.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { compareValues } from '@standardnotes/utils' import { isDeletedItem, isEncryptedItem } from '../../Abstract/Item' import { ItemDelta } from '../Index/ItemDelta' @@ -21,7 +20,7 @@ export class ItemDisplayController matchResultForStringQuery(tag, searchQuery.query) !== MatchResult.None) if (itemToMatch.protected && !searchQuery.includeProtectedNoteText) { diff --git a/packages/models/src/Domain/Runtime/Display/Validator/HiddenContentCriteriaValidator.ts b/packages/models/src/Domain/Runtime/Display/Validator/HiddenContentCriteriaValidator.ts index 8ed5b8a2c..e47cbf24d 100644 --- a/packages/models/src/Domain/Runtime/Display/Validator/HiddenContentCriteriaValidator.ts +++ b/packages/models/src/Domain/Runtime/Display/Validator/HiddenContentCriteriaValidator.ts @@ -1,9 +1,8 @@ import { DecryptedItemInterface } from './../../../Abstract/Item/Interfaces/DecryptedItem' -import { ContentType } from '@standardnotes/common' import { CriteriaValidatorInterface } from './CriteriaValidatorInterface' export class HiddenContentCriteriaValidator implements CriteriaValidatorInterface { - constructor(private hiddenContentTypes: ContentType[], private element: DecryptedItemInterface) {} + constructor(private hiddenContentTypes: string[], private element: DecryptedItemInterface) {} public passes(): boolean { return !this.hiddenContentTypes.includes(this.element.content_type) diff --git a/packages/models/src/Domain/Runtime/Encryption/ContentTypeUsesKeySystemRootKeyEncryption.ts b/packages/models/src/Domain/Runtime/Encryption/ContentTypeUsesKeySystemRootKeyEncryption.ts index a2471569d..a41efe0ca 100644 --- a/packages/models/src/Domain/Runtime/Encryption/ContentTypeUsesKeySystemRootKeyEncryption.ts +++ b/packages/models/src/Domain/Runtime/Encryption/ContentTypeUsesKeySystemRootKeyEncryption.ts @@ -1,5 +1,5 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' -export function ContentTypeUsesKeySystemRootKeyEncryption(contentType: ContentType): boolean { - return contentType === ContentType.KeySystemItemsKey +export function ContentTypeUsesKeySystemRootKeyEncryption(contentType: string): boolean { + return contentType === ContentType.TYPES.KeySystemItemsKey } diff --git a/packages/models/src/Domain/Runtime/Encryption/ContentTypeUsesRootKeyEncryption.ts b/packages/models/src/Domain/Runtime/Encryption/ContentTypeUsesRootKeyEncryption.ts index 727036543..f2ef6e2ba 100644 --- a/packages/models/src/Domain/Runtime/Encryption/ContentTypeUsesRootKeyEncryption.ts +++ b/packages/models/src/Domain/Runtime/Encryption/ContentTypeUsesRootKeyEncryption.ts @@ -1,6 +1,5 @@ -import { ContentType } from '@standardnotes/common' import { ContentTypesUsingRootKeyEncryption } from './ContentTypesUsingRootKeyEncryption' -export function ContentTypeUsesRootKeyEncryption(contentType: ContentType): boolean { +export function ContentTypeUsesRootKeyEncryption(contentType: string): boolean { return ContentTypesUsingRootKeyEncryption().includes(contentType) } diff --git a/packages/models/src/Domain/Runtime/Encryption/ContentTypesUsingRootKeyEncryption.ts b/packages/models/src/Domain/Runtime/Encryption/ContentTypesUsingRootKeyEncryption.ts index 46c2b82cb..78ac3a046 100644 --- a/packages/models/src/Domain/Runtime/Encryption/ContentTypesUsingRootKeyEncryption.ts +++ b/packages/models/src/Domain/Runtime/Encryption/ContentTypesUsingRootKeyEncryption.ts @@ -1,11 +1,11 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' -export function ContentTypesUsingRootKeyEncryption(): ContentType[] { +export function ContentTypesUsingRootKeyEncryption(): string[] { return [ - ContentType.RootKey, - ContentType.ItemsKey, - ContentType.EncryptedStorage, - ContentType.TrustedContact, - ContentType.KeySystemRootKey, + ContentType.TYPES.RootKey, + ContentType.TYPES.ItemsKey, + ContentType.TYPES.EncryptedStorage, + ContentType.TYPES.TrustedContact, + ContentType.TYPES.KeySystemRootKey, ] } diff --git a/packages/models/src/Domain/Runtime/History/Generator.ts b/packages/models/src/Domain/Runtime/History/Generator.ts index 9f14ea3ee..d27938d91 100644 --- a/packages/models/src/Domain/Runtime/History/Generator.ts +++ b/packages/models/src/Domain/Runtime/History/Generator.ts @@ -1,5 +1,6 @@ +import { ContentType } from '@standardnotes/domain-core' + import { DecryptedPayloadInterface } from './../../Abstract/Payload/Interfaces/DecryptedPayload' -import { ContentType } from '@standardnotes/common' import { NoteContent } from '../../Syncable/Note' import { HistoryEntry } from './HistoryEntry' import { NoteHistoryEntry } from './NoteHistoryEntry' @@ -14,9 +15,9 @@ export function CreateHistoryEntryForPayload( return entry } -function historyClassForContentType(contentType: ContentType) { +function historyClassForContentType(contentType: string) { switch (contentType) { - case ContentType.Note: + case ContentType.TYPES.Note: return NoteHistoryEntry default: return HistoryEntry diff --git a/packages/models/src/Domain/Runtime/Predicate/Predicate.spec.ts b/packages/models/src/Domain/Runtime/Predicate/Predicate.spec.ts index 201c3484c..dfc5f85b2 100644 --- a/packages/models/src/Domain/Runtime/Predicate/Predicate.spec.ts +++ b/packages/models/src/Domain/Runtime/Predicate/Predicate.spec.ts @@ -1,7 +1,6 @@ /* eslint-disable @typescript-eslint/no-explicit-any */ import { ItemInterface } from '../../Abstract/Item/Interfaces/ItemInterface' -import { ContentType } from '@standardnotes/common' import { compoundPredicateFromArguments, includesPredicateFromArguments, @@ -13,9 +12,10 @@ import { IncludesPredicate } from './IncludesPredicate' import { Predicate } from './Predicate' import { CompoundPredicate } from './CompoundPredicate' import { NotPredicate } from './NotPredicate' +import { ContentType } from '@standardnotes/domain-core' interface Item extends ItemInterface { - content_type: ContentType + content_type: string updated_at: Date } @@ -32,7 +32,7 @@ interface Tag extends Item { function createNote(content: Record, tags?: Tag[]): Note { return { ...content, - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, tags, } as jest.Mocked } @@ -40,7 +40,7 @@ function createNote(content: Record, tags?: Tag[]): Note { function createTag(title: string): Tag { return { title, - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, } as jest.Mocked } @@ -48,7 +48,7 @@ function createItem(content: Record, updatedAt?: Date): Item { return { ...content, updated_at: updatedAt, - content_type: ContentType.Any, + content_type: ContentType.TYPES.Any, } as jest.Mocked } @@ -100,7 +100,7 @@ describe('predicates', () => { expect( compoundPredicateFromArguments('or', [ { keypath: 'title', operator: '=', value: 'Hello' }, - { keypath: 'content_type', operator: '=', value: ContentType.Note }, + { keypath: 'content_type', operator: '=', value: ContentType.TYPES.Note }, ]).matchesItem(item), ).toEqual(true) }) @@ -118,7 +118,7 @@ describe('predicates', () => { expect( compoundPredicateFromArguments('or', [ { keypath: 'title', operator: '=', value: 'Wrong' }, - { keypath: 'content_type', operator: '=', value: ContentType.Note }, + { keypath: 'content_type', operator: '=', value: ContentType.TYPES.Note }, ]).matchesItem(item), ).toEqual(true) }) @@ -158,7 +158,7 @@ describe('predicates', () => { expect( compoundPredicateFromArguments('and', [ { keypath: 'title', operator: '=', value: title }, - { keypath: 'content_type', operator: '=', value: ContentType.Note }, + { keypath: 'content_type', operator: '=', value: ContentType.TYPES.Note }, ]).matchesItem(item), ).toEqual(true) }) @@ -167,7 +167,7 @@ describe('predicates', () => { expect( compoundPredicateFromArguments('and', [ { keypath: 'title', operator: '=', value: 'Wrong' }, - { keypath: 'content_type', operator: '=', value: ContentType.Note }, + { keypath: 'content_type', operator: '=', value: ContentType.TYPES.Note }, ]).matchesItem(item), ).toEqual(false) }) @@ -184,7 +184,7 @@ describe('predicates', () => { it('explicit compound syntax', () => { const compoundProd = new CompoundPredicate('and', [ new Predicate('title', '=', title), - new Predicate('content_type', '=', ContentType.Note), + new Predicate('content_type', '=', ContentType.TYPES.Note), ]) expect(compoundProd.matchesItem(item)).toEqual(true) }) diff --git a/packages/models/src/Domain/Syncable/Component/Component.spec.ts b/packages/models/src/Domain/Syncable/Component/Component.spec.ts index a91d47d40..aff8997fd 100644 --- a/packages/models/src/Domain/Syncable/Component/Component.spec.ts +++ b/packages/models/src/Domain/Syncable/Component/Component.spec.ts @@ -1,6 +1,6 @@ import { PayloadSource } from './../../Abstract/Payload/Types/PayloadSource' import { DecryptedPayload } from './../../Abstract/Payload/Implementations/DecryptedPayload' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { FillItemContent } from '../../Abstract/Content/ItemContent' import { SNComponent } from './Component' import { ComponentContent } from './ComponentContent' @@ -13,7 +13,7 @@ describe('component model', () => { new DecryptedPayload( { uuid: String(Math.random()), - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, content: FillItemContent({ url: 'http://foo.com', hosted_url: 'http://bar.com', @@ -33,7 +33,7 @@ describe('component model', () => { new DecryptedPayload( { uuid: String(Math.random()), - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, content: FillItemContent({ url: 'http://foo.com', hosted_url: '#{foo.zoo}', @@ -53,7 +53,7 @@ describe('component model', () => { new DecryptedPayload( { uuid: String(Math.random()), - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, content: FillItemContent({ package_info: { note_type: NoteType.Authentication, @@ -73,7 +73,7 @@ describe('component model', () => { new DecryptedPayload( { uuid: String(Math.random()), - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, content: FillItemContent({ package_info: {}, } as ComponentContent), diff --git a/packages/models/src/Domain/Syncable/Component/Component.ts b/packages/models/src/Domain/Syncable/Component/Component.ts index 1b13d37dc..cf2dcc4b1 100644 --- a/packages/models/src/Domain/Syncable/Component/Component.ts +++ b/packages/models/src/Domain/Syncable/Component/Component.ts @@ -1,5 +1,4 @@ import { isValidUrl } from '@standardnotes/utils' -import { ContentType } from '@standardnotes/common' import { FeatureIdentifier, ThirdPartyFeatureDescription, @@ -20,11 +19,12 @@ import { Predicate } from '../../Runtime/Predicate/Predicate' import { ItemInterface } from '../../Abstract/Item/Interfaces/ItemInterface' import { DecryptedItemInterface } from './../../Abstract/Item/Interfaces/DecryptedItem' import { ComponentPackageInfo } from './PackageInfo' +import { ContentType } from '@standardnotes/domain-core' -export const isComponent = (x: ItemInterface): x is SNComponent => x.content_type === ContentType.Component +export const isComponent = (x: ItemInterface): x is SNComponent => x.content_type === ContentType.TYPES.Component export const isComponentOrTheme = (x: ItemInterface): x is SNComponent => - x.content_type === ContentType.Component || x.content_type === ContentType.Theme + x.content_type === ContentType.TYPES.Component || x.content_type === ContentType.TYPES.Theme /** * Components are mostly iframe based extensions that communicate with the SN parent @@ -111,7 +111,7 @@ export class SNComponent extends DecryptedItem implements Comp } public isTheme(): boolean { - return this.content_type === ContentType.Theme || this.area === ComponentArea.Themes + return this.content_type === ContentType.TYPES.Theme || this.area === ComponentArea.Themes } /** @deprecated Use global application PrefKey.DefaultEditorIdentifier */ diff --git a/packages/models/src/Domain/Syncable/File/File.spec.ts b/packages/models/src/Domain/Syncable/File/File.spec.ts index 466f6b019..46d9a3177 100644 --- a/packages/models/src/Domain/Syncable/File/File.spec.ts +++ b/packages/models/src/Domain/Syncable/File/File.spec.ts @@ -1,5 +1,5 @@ import { ConflictStrategy } from './../../Abstract/Item/Types/ConflictStrategy' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { FillItemContent } from '../../Abstract/Content/ItemContent' import { DecryptedPayload, PayloadTimestampDefaults } from '../../Abstract/Payload' import { FileContent, FileItem } from './File' @@ -12,7 +12,7 @@ describe('file', () => { return new FileItem( new DecryptedPayload({ uuid: '123', - content_type: ContentType.File, + content_type: ContentType.TYPES.File, content: FillItemContent({ name: 'name.png', key: 'secret', diff --git a/packages/models/src/Domain/Syncable/File/File.ts b/packages/models/src/Domain/Syncable/File/File.ts index b89cf9e94..e5d957e04 100644 --- a/packages/models/src/Domain/Syncable/File/File.ts +++ b/packages/models/src/Domain/Syncable/File/File.ts @@ -1,3 +1,4 @@ +import { ContentType } from '@standardnotes/domain-core' import { DecryptedItem } from '../../Abstract/Item/Implementations/DecryptedItem' import { ItemContent } from '../../Abstract/Content/ItemContent' import { DecryptedPayloadInterface } from '../../Abstract/Payload/Interfaces/DecryptedPayload' @@ -5,7 +6,6 @@ import { FileMetadata } from './FileMetadata' import { FileProtocolV1 } from './FileProtocolV1' import { SortableItem } from '../../Runtime/Collection/CollectionSort' import { ConflictStrategy, ItemInterface } from '../../Abstract/Item' -import { ContentType } from '@standardnotes/common' type EncryptedBytesLength = number type DecryptedBytesLength = number @@ -32,7 +32,7 @@ export type FileContentSpecialized = FileContentWithoutSize & FileMetadata & Siz export type FileContent = FileContentSpecialized & ItemContent -export const isFile = (x: ItemInterface): x is FileItem => x.content_type === ContentType.File +export const isFile = (x: ItemInterface): x is FileItem => x.content_type === ContentType.TYPES.File export class FileItem extends DecryptedItem diff --git a/packages/models/src/Domain/Syncable/File/FileMutator.ts b/packages/models/src/Domain/Syncable/File/FileMutator.ts index ecf540916..a4509bbf0 100644 --- a/packages/models/src/Domain/Syncable/File/FileMutator.ts +++ b/packages/models/src/Domain/Syncable/File/FileMutator.ts @@ -1,4 +1,4 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { SNNote } from '../Note/Note' import { FileContent, FileItem } from './File' import { FileToNoteReference } from '../../Abstract/Reference/FileToNoteReference' @@ -18,7 +18,7 @@ export class FileMutator extends DecryptedItemMutator { public addNote(note: SNNote): void { const reference: FileToNoteReference = { reference_type: ContentReferenceType.FileToNote, - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, uuid: note.uuid, } @@ -39,7 +39,7 @@ export class FileMutator extends DecryptedItemMutator { const reference: FileToFileReference = { uuid: file.uuid, - content_type: ContentType.File, + content_type: ContentType.TYPES.File, reference_type: ContentReferenceType.FileToFile, } diff --git a/packages/models/src/Domain/Syncable/KeySystemRootKey/KeySystemRootKey.ts b/packages/models/src/Domain/Syncable/KeySystemRootKey/KeySystemRootKey.ts index d7207efe2..cf81e6baf 100644 --- a/packages/models/src/Domain/Syncable/KeySystemRootKey/KeySystemRootKey.ts +++ b/packages/models/src/Domain/Syncable/KeySystemRootKey/KeySystemRootKey.ts @@ -1,4 +1,4 @@ -import { ContentType, ProtocolVersion } from '@standardnotes/common' +import { ProtocolVersion } from '@standardnotes/common' import { ConflictStrategy, DecryptedItem } from '../../Abstract/Item' import { DecryptedPayloadInterface } from '../../Abstract/Payload' import { HistoryEntryInterface } from '../../Runtime/History' @@ -6,9 +6,10 @@ import { KeySystemRootKeyContent } from './KeySystemRootKeyContent' import { KeySystemRootKeyInterface } from './KeySystemRootKeyInterface' import { KeySystemIdentifier } from './KeySystemIdentifier' import { KeySystemRootKeyParamsInterface } from '../../Local/KeyParams/KeySystemRootKeyParamsInterface' +import { ContentType } from '@standardnotes/domain-core' -export function isKeySystemRootKey(x: { content_type: ContentType }): x is KeySystemRootKey { - return x.content_type === ContentType.KeySystemRootKey +export function isKeySystemRootKey(x: { content_type: string }): x is KeySystemRootKey { + return x.content_type === ContentType.TYPES.KeySystemRootKey } export class KeySystemRootKey extends DecryptedItem implements KeySystemRootKeyInterface { diff --git a/packages/models/src/Domain/Syncable/Note/Note.ts b/packages/models/src/Domain/Syncable/Note/Note.ts index 122aefdf9..a7e9b2775 100644 --- a/packages/models/src/Domain/Syncable/Note/Note.ts +++ b/packages/models/src/Domain/Syncable/Note/Note.ts @@ -1,13 +1,13 @@ import { AppDataField } from './../../Abstract/Item/Types/AppDataField' -import { ContentType } from '@standardnotes/common' import { FeatureIdentifier, NoteType } from '@standardnotes/features' import { DecryptedItem } from '../../Abstract/Item/Implementations/DecryptedItem' import { ItemInterface } from '../../Abstract/Item/Interfaces/ItemInterface' import { DecryptedPayloadInterface } from '../../Abstract/Payload/Interfaces/DecryptedPayload' import { NoteContent, NoteContentSpecialized } from './NoteContent' import { EditorLineWidth } from '../UserPrefs' +import { ContentType } from '@standardnotes/domain-core' -export const isNote = (x: ItemInterface): x is SNNote => x.content_type === ContentType.Note +export const isNote = (x: ItemInterface): x is SNNote => x.content_type === ContentType.TYPES.Note export class SNNote extends DecryptedItem implements NoteContentSpecialized { public readonly title: string diff --git a/packages/models/src/Domain/Syncable/Note/NoteMutator.ts b/packages/models/src/Domain/Syncable/Note/NoteMutator.ts index 453d848aa..3f08cd392 100644 --- a/packages/models/src/Domain/Syncable/Note/NoteMutator.ts +++ b/packages/models/src/Domain/Syncable/Note/NoteMutator.ts @@ -2,10 +2,10 @@ import { NoteContent } from './NoteContent' import { DecryptedItemMutator } from '../../Abstract/Item/Mutator/DecryptedItemMutator' import { SNNote } from './Note' import { NoteToNoteReference } from '../../Abstract/Reference/NoteToNoteReference' -import { ContentType } from '@standardnotes/common' import { ContentReferenceType } from '../../Abstract/Item' import { FeatureIdentifier, NoteType } from '@standardnotes/features' import { EditorLineWidth } from '../UserPrefs' +import { ContentType } from '@standardnotes/domain-core' export class NoteMutator extends DecryptedItemMutator { set title(title: string) { @@ -63,7 +63,7 @@ export class NoteMutator extends DecryptedItemMutator { const reference: NoteToNoteReference = { uuid: note.uuid, - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, reference_type: ContentReferenceType.NoteToNote, } diff --git a/packages/models/src/Domain/Syncable/SmartView/SmartView.ts b/packages/models/src/Domain/Syncable/SmartView/SmartView.ts index 10e092d6f..dbe1be07c 100644 --- a/packages/models/src/Domain/Syncable/SmartView/SmartView.ts +++ b/packages/models/src/Domain/Syncable/SmartView/SmartView.ts @@ -1,3 +1,5 @@ +import { ContentType } from '@standardnotes/domain-core' + import { DecryptedItem } from '../../Abstract/Item/Implementations/DecryptedItem' import { PredicateInterface } from '../../Runtime/Predicate/Interface' import { predicateFromJson } from '../../Runtime/Predicate/Generators' @@ -8,7 +10,6 @@ import { SmartViewDefaultIconName, systemViewIcon } from './SmartViewIcons' import { SmartViewContent } from './SmartViewContent' import { TagPreferences } from '../Tag/TagPreferences' import { ItemInterface } from '../../Abstract/Item' -import { ContentType } from '@standardnotes/common' export const SMART_TAG_DSL_PREFIX = '![' @@ -16,7 +17,7 @@ export function isSystemView(view: SmartView): boolean { return Object.values(SystemViewId).includes(view.uuid as SystemViewId) } -export const isSmartView = (x: ItemInterface): x is SmartView => x.content_type === ContentType.SmartView +export const isSmartView = (x: ItemInterface): x is SmartView => x.content_type === ContentType.TYPES.SmartView export class SmartView extends DecryptedItem { public readonly predicate!: PredicateInterface diff --git a/packages/models/src/Domain/Syncable/SmartView/SmartViewBuilder.ts b/packages/models/src/Domain/Syncable/SmartView/SmartViewBuilder.ts index 5e492685e..f43602837 100644 --- a/packages/models/src/Domain/Syncable/SmartView/SmartViewBuilder.ts +++ b/packages/models/src/Domain/Syncable/SmartView/SmartViewBuilder.ts @@ -4,19 +4,19 @@ import { SmartView } from './SmartView' import { SmartViewContent } from './SmartViewContent' import { SystemViewId } from './SystemViewId' import { ItemWithTags } from '../../Runtime/Display/Search/ItemWithTags' -import { ContentType } from '@standardnotes/common' import { FillItemContent } from '../../Abstract/Content/ItemContent' import { Predicate } from '../../Runtime/Predicate/Predicate' import { CompoundPredicate } from '../../Runtime/Predicate/CompoundPredicate' import { PayloadTimestampDefaults } from '../../Abstract/Payload' import { NotesAndFilesDisplayOptions } from '../../Runtime/Display' import { FileItem } from '../File' +import { ContentType } from '@standardnotes/domain-core' export function BuildSmartViews(options: NotesAndFilesDisplayOptions): SmartView[] { const notes = new SmartView( new DecryptedPayload({ uuid: SystemViewId.AllNotes, - content_type: ContentType.SmartView, + content_type: ContentType.TYPES.SmartView, ...PayloadTimestampDefaults(), content: FillItemContent({ title: 'Notes', @@ -28,7 +28,7 @@ export function BuildSmartViews(options: NotesAndFilesDisplayOptions): SmartView const files = new SmartView( new DecryptedPayload({ uuid: SystemViewId.Files, - content_type: ContentType.SmartView, + content_type: ContentType.TYPES.SmartView, ...PayloadTimestampDefaults(), content: FillItemContent({ title: 'Files', @@ -40,7 +40,7 @@ export function BuildSmartViews(options: NotesAndFilesDisplayOptions): SmartView const archived = new SmartView( new DecryptedPayload({ uuid: SystemViewId.ArchivedNotes, - content_type: ContentType.SmartView, + content_type: ContentType.TYPES.SmartView, ...PayloadTimestampDefaults(), content: FillItemContent({ title: 'Archived', @@ -52,7 +52,7 @@ export function BuildSmartViews(options: NotesAndFilesDisplayOptions): SmartView const trash = new SmartView( new DecryptedPayload({ uuid: SystemViewId.TrashedNotes, - content_type: ContentType.SmartView, + content_type: ContentType.TYPES.SmartView, ...PayloadTimestampDefaults(), content: FillItemContent({ title: 'Trash', @@ -64,7 +64,7 @@ export function BuildSmartViews(options: NotesAndFilesDisplayOptions): SmartView const untagged = new SmartView( new DecryptedPayload({ uuid: SystemViewId.UntaggedNotes, - content_type: ContentType.SmartView, + content_type: ContentType.TYPES.SmartView, ...PayloadTimestampDefaults(), content: FillItemContent({ title: 'Untagged', @@ -76,7 +76,7 @@ export function BuildSmartViews(options: NotesAndFilesDisplayOptions): SmartView const starred = new SmartView( new DecryptedPayload({ uuid: SystemViewId.StarredNotes, - content_type: ContentType.SmartView, + content_type: ContentType.TYPES.SmartView, ...PayloadTimestampDefaults(), content: FillItemContent({ title: 'Starred', @@ -88,7 +88,7 @@ export function BuildSmartViews(options: NotesAndFilesDisplayOptions): SmartView const conflicts = new SmartView( new DecryptedPayload({ uuid: SystemViewId.Conflicts, - content_type: ContentType.SmartView, + content_type: ContentType.TYPES.SmartView, ...PayloadTimestampDefaults(), content: FillItemContent({ title: 'Conflicts', @@ -101,7 +101,7 @@ export function BuildSmartViews(options: NotesAndFilesDisplayOptions): SmartView } function allNotesPredicate(options: NotesAndFilesDisplayOptions) { - const subPredicates: Predicate[] = [new Predicate('content_type', '=', ContentType.Note)] + const subPredicates: Predicate[] = [new Predicate('content_type', '=', ContentType.TYPES.Note)] if (options.includeTrashed === false) { subPredicates.push(new Predicate('trashed', '=', false)) @@ -121,7 +121,7 @@ function allNotesPredicate(options: NotesAndFilesDisplayOptions) { } function filesPredicate(options: NotesAndFilesDisplayOptions) { - const subPredicates: Predicate[] = [new Predicate('content_type', '=', ContentType.File)] + const subPredicates: Predicate[] = [new Predicate('content_type', '=', ContentType.TYPES.File)] if (options.includeTrashed === false) { subPredicates.push(new Predicate('trashed', '=', false)) @@ -143,7 +143,7 @@ function filesPredicate(options: NotesAndFilesDisplayOptions) { function archivedNotesPredicate(options: NotesAndFilesDisplayOptions) { const subPredicates: Predicate[] = [ new Predicate('archived', '=', true), - new Predicate('content_type', '=', ContentType.Note), + new Predicate('content_type', '=', ContentType.TYPES.Note), ] if (options.includeTrashed === false) { subPredicates.push(new Predicate('trashed', '=', false)) @@ -162,7 +162,7 @@ function archivedNotesPredicate(options: NotesAndFilesDisplayOptions) { function trashedNotesPredicate(options: NotesAndFilesDisplayOptions) { const subPredicates: Predicate[] = [ new Predicate('trashed', '=', true), - new Predicate('content_type', '=', ContentType.Note), + new Predicate('content_type', '=', ContentType.TYPES.Note), ] if (options.includeArchived === false) { subPredicates.push(new Predicate('archived', '=', false)) @@ -180,7 +180,7 @@ function trashedNotesPredicate(options: NotesAndFilesDisplayOptions) { function untaggedNotesPredicate(options: NotesAndFilesDisplayOptions) { const subPredicates = [ - new Predicate('content_type', '=', ContentType.Note), + new Predicate('content_type', '=', ContentType.TYPES.Note), new Predicate('tagsCount', '=', 0), ] if (options.includeArchived === false) { @@ -200,7 +200,7 @@ function untaggedNotesPredicate(options: NotesAndFilesDisplayOptions) { function starredNotesPredicate(options: NotesAndFilesDisplayOptions) { const subPredicates: Predicate[] = [ new Predicate('starred', '=', true), - new Predicate('content_type', '=', ContentType.Note), + new Predicate('content_type', '=', ContentType.TYPES.Note), ] if (options.includeTrashed === false) { subPredicates.push(new Predicate('trashed', '=', false)) @@ -217,7 +217,7 @@ function starredNotesPredicate(options: NotesAndFilesDisplayOptions) { } function conflictsPredicate(options: NotesAndFilesDisplayOptions) { - const subPredicates: Predicate[] = [new Predicate('content_type', '=', ContentType.Note)] + const subPredicates: Predicate[] = [new Predicate('content_type', '=', ContentType.TYPES.Note)] if (options.includeTrashed === false) { subPredicates.push(new Predicate('trashed', '=', false)) diff --git a/packages/models/src/Domain/Syncable/Tag/Tag.spec.ts b/packages/models/src/Domain/Syncable/Tag/Tag.spec.ts index 90074601c..29ce581fc 100644 --- a/packages/models/src/Domain/Syncable/Tag/Tag.spec.ts +++ b/packages/models/src/Domain/Syncable/Tag/Tag.spec.ts @@ -1,7 +1,7 @@ import { PayloadSource } from './../../Abstract/Payload/Types/PayloadSource' import { DecryptedPayload } from './../../Abstract/Payload/Implementations/DecryptedPayload' import { SNTag } from './Tag' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { FillItemContent } from '../../Abstract/Content/ItemContent' import { ContentReference } from '../../Abstract/Reference/ContentReference' import { PayloadTimestampDefaults } from '../../Abstract/Payload' @@ -14,7 +14,7 @@ const create = (title: string, references: ContentReference[] = []): SNTag => { new DecryptedPayload( { uuid: randUuid(), - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, content: FillItemContent({ title, references, @@ -31,9 +31,9 @@ const create = (title: string, references: ContentReference[] = []): SNTag => { describe('SNTag Tests', () => { it('should count notes in the basic case', () => { const tag = create('helloworld', [ - { uuid: randUuid(), content_type: ContentType.Note }, - { uuid: randUuid(), content_type: ContentType.Note }, - { uuid: randUuid(), content_type: ContentType.Tag }, + { uuid: randUuid(), content_type: ContentType.TYPES.Note }, + { uuid: randUuid(), content_type: ContentType.TYPES.Note }, + { uuid: randUuid(), content_type: ContentType.TYPES.Tag }, ]) expect(tag.noteCount).toEqual(2) diff --git a/packages/models/src/Domain/Syncable/Tag/Tag.ts b/packages/models/src/Domain/Syncable/Tag/Tag.ts index 380280cbc..d7cd2b408 100644 --- a/packages/models/src/Domain/Syncable/Tag/Tag.ts +++ b/packages/models/src/Domain/Syncable/Tag/Tag.ts @@ -1,5 +1,4 @@ import { VectorIconNameOrEmoji, IconType } from './../../Utilities/Icon/IconType' -import { ContentType } from '@standardnotes/common' import { DecryptedItem } from '../../Abstract/Item/Implementations/DecryptedItem' import { ItemInterface } from '../../Abstract/Item/Interfaces/ItemInterface' import { ContentReference } from '../../Abstract/Reference/ContentReference' @@ -7,12 +6,13 @@ import { isTagToParentTagReference } from '../../Abstract/Reference/Functions' import { DecryptedPayloadInterface } from '../../Abstract/Payload/Interfaces/DecryptedPayload' import { TagContent, TagContentSpecialized } from './TagContent' import { TagPreferences } from './TagPreferences' +import { ContentType } from '@standardnotes/domain-core' export const TagFolderDelimitter = '.' export const DefaultTagIconName: IconType = 'hashtag' -export const isTag = (x: ItemInterface): x is SNTag => x.content_type === ContentType.Tag +export const isTag = (x: ItemInterface): x is SNTag => x.content_type === ContentType.TYPES.Tag export class SNTag extends DecryptedItem implements TagContentSpecialized { public readonly title: string @@ -34,7 +34,7 @@ export class SNTag extends DecryptedItem implements TagContentSpecia get noteReferences(): ContentReference[] { const references = this.payload.references - return references.filter((ref) => ref.content_type === ContentType.Note) + return references.filter((ref) => ref.content_type === ContentType.TYPES.Note) } get noteCount(): number { diff --git a/packages/models/src/Domain/Syncable/Tag/TagMutator.spec.ts b/packages/models/src/Domain/Syncable/Tag/TagMutator.spec.ts index adefc13a0..28859e5fc 100644 --- a/packages/models/src/Domain/Syncable/Tag/TagMutator.spec.ts +++ b/packages/models/src/Domain/Syncable/Tag/TagMutator.spec.ts @@ -1,4 +1,4 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { ContentReferenceType, MutationType } from '../../Abstract/Item' import { createFile, createTagWithContent, createTagWithTitle } from '../../Utilities/Test/SpecUtils' import { SNTag } from './Tag' @@ -15,7 +15,7 @@ describe('tag mutator', () => { expect(result.content.references[0]).toEqual({ uuid: file.uuid, - content_type: ContentType.File, + content_type: ContentType.TYPES.File, reference_type: ContentReferenceType.TagToFile, }) }) diff --git a/packages/models/src/Domain/Syncable/Tag/TagMutator.ts b/packages/models/src/Domain/Syncable/Tag/TagMutator.ts index 0f3854d7f..f1b955db4 100644 --- a/packages/models/src/Domain/Syncable/Tag/TagMutator.ts +++ b/packages/models/src/Domain/Syncable/Tag/TagMutator.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { SNTag } from './Tag' import { TagContent } from './TagContent' import { FileItem } from '../File' @@ -10,6 +9,7 @@ import { DecryptedItemMutator } from '../../Abstract/Item/Mutator/DecryptedItemM import { TagToFileReference } from '../../Abstract/Reference/TagToFileReference' import { TagPreferences } from './TagPreferences' import { DecryptedItemInterface, MutationType } from '../../Abstract/Item' +import { ContentType } from '@standardnotes/domain-core' export class TagMutator extends DecryptedItemMutator { private mutablePreferences?: TagPreferences @@ -51,7 +51,7 @@ export class TagMutator extends Decrypt const reference: TagToParentTagReference = { reference_type: ContentReferenceType.TagToParentTag, - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, uuid: tag.uuid, } @@ -71,7 +71,7 @@ export class TagMutator extends Decrypt const reference: TagToFileReference = { reference_type: ContentReferenceType.TagToFile, - content_type: ContentType.File, + content_type: ContentType.TYPES.File, uuid: file.uuid, } diff --git a/packages/models/src/Domain/Syncable/Theme/Theme.ts b/packages/models/src/Domain/Syncable/Theme/Theme.ts index ece75dc9c..80a3cc12d 100644 --- a/packages/models/src/Domain/Syncable/Theme/Theme.ts +++ b/packages/models/src/Domain/Syncable/Theme/Theme.ts @@ -4,11 +4,11 @@ import { ConflictStrategy } from '../../Abstract/Item/Types/ConflictStrategy' import { AppDataField } from '../../Abstract/Item/Types/AppDataField' import { HistoryEntryInterface } from '../../Runtime/History' import { DecryptedItemInterface, ItemInterface } from '../../Abstract/Item' -import { ContentType } from '@standardnotes/common' import { useBoolean } from '@standardnotes/utils' import { ThemePackageInfo } from '../Component/PackageInfo' +import { ContentType } from '@standardnotes/domain-core' -export const isTheme = (x: ItemInterface): x is SNTheme => x.content_type === ContentType.Theme +export const isTheme = (x: ItemInterface): x is SNTheme => x.content_type === ContentType.TYPES.Theme export class SNTheme extends SNComponent { public override area: ComponentArea = ComponentArea.Themes diff --git a/packages/models/src/Domain/Syncable/UserPrefs/UserPrefs.ts b/packages/models/src/Domain/Syncable/UserPrefs/UserPrefs.ts index 75aeceff2..fe02f3c39 100644 --- a/packages/models/src/Domain/Syncable/UserPrefs/UserPrefs.ts +++ b/packages/models/src/Domain/Syncable/UserPrefs/UserPrefs.ts @@ -1,10 +1,10 @@ +import { ContentType } from '@standardnotes/domain-core' import { DecryptedItem } from '../../Abstract/Item/Implementations/DecryptedItem' -import { ContentType } from '@standardnotes/common' import { Predicate } from '../../Runtime/Predicate/Predicate' import { PrefKey, PrefValue } from './PrefKey' export class SNUserPrefs extends DecryptedItem { - static singletonPredicate = new Predicate('content_type', '=', ContentType.UserPrefs) + static singletonPredicate = new Predicate('content_type', '=', ContentType.TYPES.UserPrefs) override get isSingleton(): true { return true diff --git a/packages/models/src/Domain/Utilities/Item/ItemGenerator.ts b/packages/models/src/Domain/Utilities/Item/ItemGenerator.ts index 92d87ae46..5d42898ac 100644 --- a/packages/models/src/Domain/Utilities/Item/ItemGenerator.ts +++ b/packages/models/src/Domain/Utilities/Item/ItemGenerator.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { EncryptedItem } from '../../Abstract/Item/Implementations/EncryptedItem' import { DecryptedPayloadInterface } from '../../Abstract/Payload/Interfaces/DecryptedPayload' import { FileItem } from '../../Syncable/File/File' @@ -40,6 +39,7 @@ import { isDeletedPayload, isEncryptedPayload, } from '../../Abstract/Payload' +import { ContentType } from '@standardnotes/domain-core' type ItemClass = new (payload: DecryptedPayloadInterface) => DecryptedItem @@ -53,24 +53,24 @@ type MappingEntry = { mutatorClass?: MutatorClass } -const ContentTypeClassMapping: Partial> = { - [ContentType.ActionsExtension]: { +const ContentTypeClassMapping: Partial> = { + [ContentType.TYPES.ActionsExtension]: { itemClass: SNActionsExtension, mutatorClass: ActionsExtensionMutator, }, - [ContentType.Component]: { itemClass: SNComponent, mutatorClass: ComponentMutator }, - [ContentType.KeySystemRootKey]: { itemClass: KeySystemRootKey, mutatorClass: KeySystemRootKeyMutator }, - [ContentType.TrustedContact]: { itemClass: TrustedContact, mutatorClass: TrustedContactMutator }, - [ContentType.VaultListing]: { itemClass: VaultListing, mutatorClass: VaultListingMutator }, - [ContentType.Editor]: { itemClass: SNEditor }, - [ContentType.ExtensionRepo]: { itemClass: SNFeatureRepo }, - [ContentType.File]: { itemClass: FileItem, mutatorClass: FileMutator }, - [ContentType.Note]: { itemClass: SNNote, mutatorClass: NoteMutator }, - [ContentType.SmartView]: { itemClass: SmartView, mutatorClass: SmartViewMutator }, - [ContentType.Tag]: { itemClass: SNTag, mutatorClass: TagMutator }, - [ContentType.Theme]: { itemClass: SNTheme, mutatorClass: ThemeMutator }, - [ContentType.UserPrefs]: { itemClass: SNUserPrefs, mutatorClass: UserPrefsMutator }, -} as unknown as Partial> + [ContentType.TYPES.Component]: { itemClass: SNComponent, mutatorClass: ComponentMutator }, + [ContentType.TYPES.KeySystemRootKey]: { itemClass: KeySystemRootKey, mutatorClass: KeySystemRootKeyMutator }, + [ContentType.TYPES.TrustedContact]: { itemClass: TrustedContact, mutatorClass: TrustedContactMutator }, + [ContentType.TYPES.VaultListing]: { itemClass: VaultListing, mutatorClass: VaultListingMutator }, + [ContentType.TYPES.Editor]: { itemClass: SNEditor }, + [ContentType.TYPES.ExtensionRepo]: { itemClass: SNFeatureRepo }, + [ContentType.TYPES.File]: { itemClass: FileItem, mutatorClass: FileMutator }, + [ContentType.TYPES.Note]: { itemClass: SNNote, mutatorClass: NoteMutator }, + [ContentType.TYPES.SmartView]: { itemClass: SmartView, mutatorClass: SmartViewMutator }, + [ContentType.TYPES.Tag]: { itemClass: SNTag, mutatorClass: TagMutator }, + [ContentType.TYPES.Theme]: { itemClass: SNTheme, mutatorClass: ThemeMutator }, + [ContentType.TYPES.UserPrefs]: { itemClass: SNUserPrefs, mutatorClass: UserPrefsMutator }, +} as unknown as Partial> export function CreateDecryptedMutatorForItem< I extends DecryptedItemInterface, @@ -87,7 +87,7 @@ export function CreateDecryptedMutatorForItem< export function RegisterItemClass< C extends ItemContent = ItemContent, M extends DecryptedItemMutator = DecryptedItemMutator, ->(contentType: ContentType, itemClass: ItemClass, mutatorClass: M) { +>(contentType: string, itemClass: ItemClass, mutatorClass: M) { const entry: MappingEntry = { itemClass: itemClass, mutatorClass: mutatorClass as unknown as MutatorClass, diff --git a/packages/models/src/Domain/Utilities/Payload/PayloadsByAlternatingUuid.ts b/packages/models/src/Domain/Utilities/Payload/PayloadsByAlternatingUuid.ts index 01442ad37..cd8af1037 100644 --- a/packages/models/src/Domain/Utilities/Payload/PayloadsByAlternatingUuid.ts +++ b/packages/models/src/Domain/Utilities/Payload/PayloadsByAlternatingUuid.ts @@ -1,5 +1,4 @@ import { DeletedPayload } from '../../Abstract/Payload/Implementations/DeletedPayload' -import { ContentType } from '@standardnotes/common' import { extendArray, UuidGenerator } from '@standardnotes/utils' import { ImmutablePayloadCollection } from '../../Runtime/Collection/Payload/ImmutablePayloadCollection' import { DecryptedPayloadInterface } from '../../Abstract/Payload/Interfaces/DecryptedPayload' @@ -9,6 +8,7 @@ import { EncryptedPayloadInterface } from '../../Abstract/Payload/Interfaces/Enc import { PayloadsByUpdatingReferencingPayloadReferences } from './PayloadsByUpdatingReferencingPayloadReferences' import { SyncResolvedPayload } from '../../Runtime/Deltas/Utilities/SyncResolvedPayload' import { getIncrementedDirtyIndex } from '../../Runtime/DirtyCounter/DirtyCounter' +import { ContentType } from '@standardnotes/domain-core' /** * Return the payloads that result if you alternated the uuid for the payload. @@ -50,7 +50,7 @@ export function PayloadsByAlternatingUuid

): SNNote => { new DecryptedPayload( { uuid: mockUuid(), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: FillItemContent({ ...content }), ...PayloadTimestampDefaults(), }, @@ -32,7 +32,7 @@ export const createNoteWithContent = (content: Partial, createdAt?: new DecryptedPayload( { uuid: mockUuid(), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: FillItemContent(content), ...PayloadTimestampDefaults(), created_at: createdAt || new Date(), @@ -47,7 +47,7 @@ export const createTagWithContent = (content: Partial): SNTag => { new DecryptedPayload( { uuid: mockUuid(), - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, content: FillItemContent(content), ...PayloadTimestampDefaults(), }, @@ -61,7 +61,7 @@ export const createSmartViewWithContent = (content: Partial): new DecryptedPayload( { uuid: mockUuid(), - content_type: ContentType.SmartView, + content_type: ContentType.TYPES.SmartView, content: FillItemContent(content), ...PayloadTimestampDefaults(), }, @@ -75,7 +75,7 @@ export const createTagWithTitle = (title = 'photos') => { new DecryptedPayload( { uuid: mockUuid(), - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, content: FillItemContent({ title }), ...PayloadTimestampDefaults(), }, @@ -89,7 +89,7 @@ export const createSmartViewWithTitle = (title = 'photos') => { new DecryptedPayload( { uuid: mockUuid(), - content_type: ContentType.SmartView, + content_type: ContentType.TYPES.SmartView, content: FillItemContent({ title }), ...PayloadTimestampDefaults(), }, @@ -103,7 +103,7 @@ export const createFile = (name = 'screenshot.png') => { new DecryptedPayload( { uuid: mockUuid(), - content_type: ContentType.File, + content_type: ContentType.TYPES.File, content: FillItemContent({ name }), ...PayloadTimestampDefaults(), }, diff --git a/packages/responses/package.json b/packages/responses/package.json index ffed8a8fc..59e403c53 100644 --- a/packages/responses/package.json +++ b/packages/responses/package.json @@ -33,7 +33,7 @@ "typescript": "*" }, "dependencies": { - "@standardnotes/common": "^1.48.3", + "@standardnotes/common": "^1.50.0", "@standardnotes/features": "workspace:*", "@standardnotes/security": "^1.7.6", "reflect-metadata": "^0.1.13" diff --git a/packages/responses/src/Domain/Item/ServerItemResponse.ts b/packages/responses/src/Domain/Item/ServerItemResponse.ts index 4221e2858..62e4e6dd3 100644 --- a/packages/responses/src/Domain/Item/ServerItemResponse.ts +++ b/packages/responses/src/Domain/Item/ServerItemResponse.ts @@ -1,7 +1,5 @@ -import { ContentType } from '@standardnotes/common' - export interface ServerItemResponse { - content_type: ContentType + content_type: string content: string | undefined created_at_timestamp: number created_at: Date diff --git a/packages/responses/src/Domain/Listed/ActionResponse.ts b/packages/responses/src/Domain/Listed/ActionResponse.ts index 0b61db50b..b0b0f290b 100644 --- a/packages/responses/src/Domain/Listed/ActionResponse.ts +++ b/packages/responses/src/Domain/Listed/ActionResponse.ts @@ -1,10 +1,10 @@ -import { AnyKeyParamsContent, ContentType } from '@standardnotes/common' +import { AnyKeyParamsContent } from '@standardnotes/common' import { DeprecatedHttpResponse } from '../Http/DeprecatedHttpResponse' import { ServerItemResponse } from '../Item/ServerItemResponse' export type ActionResponse = DeprecatedHttpResponse & { description: string - supported_types: ContentType[] + supported_types: string[] deprecation?: string actions: unknown[] item?: ServerItemResponse diff --git a/packages/services/package.json b/packages/services/package.json index 60395e826..51c5c94fd 100644 --- a/packages/services/package.json +++ b/packages/services/package.json @@ -17,8 +17,8 @@ }, "dependencies": { "@standardnotes/api": "workspace:^", - "@standardnotes/common": "^1.48.3", - "@standardnotes/domain-core": "^1.12.0", + "@standardnotes/common": "^1.50.0", + "@standardnotes/domain-core": "^1.22.0", "@standardnotes/encryption": "workspace:^", "@standardnotes/features": "workspace:^", "@standardnotes/files": "workspace:^", diff --git a/packages/services/src/Domain/Application/ApplicationInterface.ts b/packages/services/src/Domain/Application/ApplicationInterface.ts index 35cad8ce1..ae114a45a 100644 --- a/packages/services/src/Domain/Application/ApplicationInterface.ts +++ b/packages/services/src/Domain/Application/ApplicationInterface.ts @@ -3,7 +3,7 @@ import { SyncOptions } from './../Sync/SyncOptions' import { ImportDataReturnType } from './../Mutator/ImportDataUseCase' import { ChallengeServiceInterface } from './../Challenge/ChallengeServiceInterface' import { VaultServiceInterface } from './../Vaults/VaultServiceInterface' -import { ApplicationIdentifier, ContentType } from '@standardnotes/common' +import { ApplicationIdentifier } from '@standardnotes/common' import { BackupFile, DecryptedItemInterface, @@ -57,7 +57,7 @@ export interface ApplicationInterface { getPreference(key: K, defaultValue?: PrefValue[K]): PrefValue[K] | undefined setPreference(key: K, value: PrefValue[K]): Promise streamItems( - contentType: ContentType | ContentType[], + contentType: string | string[], stream: ItemStream, ): () => void diff --git a/packages/services/src/Domain/AsymmetricMessage/UseCase/HandleTrustedSharedVaultInviteMessage.spec.ts b/packages/services/src/Domain/AsymmetricMessage/UseCase/HandleTrustedSharedVaultInviteMessage.spec.ts index c789c835f..1b1375bec 100644 --- a/packages/services/src/Domain/AsymmetricMessage/UseCase/HandleTrustedSharedVaultInviteMessage.spec.ts +++ b/packages/services/src/Domain/AsymmetricMessage/UseCase/HandleTrustedSharedVaultInviteMessage.spec.ts @@ -2,7 +2,7 @@ import { MutatorClientInterface } from './../../Mutator/MutatorClientInterface' import { HandleTrustedSharedVaultInviteMessage } from './HandleTrustedSharedVaultInviteMessage' import { SyncServiceInterface } from '../../Sync/SyncServiceInterface' import { ContactServiceInterface } from '../../Contacts/ContactServiceInterface' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { AsymmetricMessagePayloadType, AsymmetricMessageSharedVaultInvite, @@ -55,11 +55,11 @@ describe('HandleTrustedSharedVaultInviteMessage', () => { await handleTrustedSharedVaultInviteMessage.execute(testMessage, sharedVaultUuid, senderUuid) const keySystemRootKeyCallIndex = mutatorMock.createItem.mock.calls.findIndex( - ([contentType]) => contentType === ContentType.KeySystemRootKey, + ([contentType]) => contentType === ContentType.TYPES.KeySystemRootKey, ) const vaultListingCallIndex = mutatorMock.createItem.mock.calls.findIndex( - ([contentType]) => contentType === ContentType.VaultListing, + ([contentType]) => contentType === ContentType.TYPES.VaultListing, ) expect(keySystemRootKeyCallIndex).toBeLessThan(vaultListingCallIndex) diff --git a/packages/services/src/Domain/AsymmetricMessage/UseCase/HandleTrustedSharedVaultInviteMessage.ts b/packages/services/src/Domain/AsymmetricMessage/UseCase/HandleTrustedSharedVaultInviteMessage.ts index 1a3cebdfb..da8b491b3 100644 --- a/packages/services/src/Domain/AsymmetricMessage/UseCase/HandleTrustedSharedVaultInviteMessage.ts +++ b/packages/services/src/Domain/AsymmetricMessage/UseCase/HandleTrustedSharedVaultInviteMessage.ts @@ -9,8 +9,8 @@ import { VaultListingContentSpecialized, KeySystemRootKeyStorageMode, } from '@standardnotes/models' -import { ContentType } from '@standardnotes/common' import { MutatorClientInterface } from '../../Mutator/MutatorClientInterface' +import { ContentType } from '@standardnotes/domain-core' export class HandleTrustedSharedVaultInviteMessage { constructor( @@ -39,12 +39,12 @@ export class HandleTrustedSharedVaultInviteMessage { } await this.mutator.createItem( - ContentType.KeySystemRootKey, + ContentType.TYPES.KeySystemRootKey, FillItemContent(rootKeyContent), true, ) - await this.mutator.createItem(ContentType.VaultListing, FillItemContentSpecialized(content), true) + await this.mutator.createItem(ContentType.TYPES.VaultListing, FillItemContentSpecialized(content), true) for (const contact of trustedContacts) { if (contact.isMe) { diff --git a/packages/services/src/Domain/AsymmetricMessage/UseCase/HandleTrustedSharedVaultRootKeyChangedMessage.ts b/packages/services/src/Domain/AsymmetricMessage/UseCase/HandleTrustedSharedVaultRootKeyChangedMessage.ts index 1bc493b84..b2cc1ed22 100644 --- a/packages/services/src/Domain/AsymmetricMessage/UseCase/HandleTrustedSharedVaultRootKeyChangedMessage.ts +++ b/packages/services/src/Domain/AsymmetricMessage/UseCase/HandleTrustedSharedVaultRootKeyChangedMessage.ts @@ -9,7 +9,7 @@ import { VaultListingMutator, } from '@standardnotes/models' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { GetVaultUseCase } from '../../Vaults/UseCase/GetVault' import { EncryptionProviderInterface } from '@standardnotes/encryption' @@ -25,7 +25,7 @@ export class HandleTrustedSharedVaultRootKeyChangedMessage { const rootKeyContent = message.data.rootKey await this.mutator.createItem( - ContentType.KeySystemRootKey, + ContentType.TYPES.KeySystemRootKey, FillItemContent(rootKeyContent), true, ) diff --git a/packages/services/src/Domain/Backups/BackupService.ts b/packages/services/src/Domain/Backups/BackupService.ts index 80ae57da9..676d053b5 100644 --- a/packages/services/src/Domain/Backups/BackupService.ts +++ b/packages/services/src/Domain/Backups/BackupService.ts @@ -1,6 +1,5 @@ import { NoteType } from '@standardnotes/features' import { ApplicationStage } from './../Application/ApplicationStage' -import { ContentType } from '@standardnotes/common' import { EncryptionProviderInterface } from '@standardnotes/encryption' import { PayloadEmitSource, @@ -34,6 +33,7 @@ import { StorageKey } from '../Storage/StorageKeys' import { SessionsClientInterface } from '../Session/SessionsClientInterface' import { PayloadManagerInterface } from '../Payloads/PayloadManagerInterface' import { HistoryServiceInterface } from '../History/HistoryServiceInterface' +import { ContentType } from '@standardnotes/domain-core' const PlaintextBackupsDirectoryName = 'Plaintext Backups' export const TextBackupsDirectoryName = 'Text Backups' @@ -65,16 +65,19 @@ export class FilesBackupService extends AbstractService implements BackupService ) { super(internalEventBus) - this.filesObserverDisposer = items.addObserver(ContentType.File, ({ changed, inserted, source }) => { - const applicableSources = [ - PayloadEmitSource.LocalDatabaseLoaded, - PayloadEmitSource.RemoteSaved, - PayloadEmitSource.RemoteRetrieved, - ] - if (applicableSources.includes(source)) { - void this.handleChangedFiles([...changed, ...inserted]) - } - }) + this.filesObserverDisposer = items.addObserver( + ContentType.TYPES.File, + ({ changed, inserted, source }) => { + const applicableSources = [ + PayloadEmitSource.LocalDatabaseLoaded, + PayloadEmitSource.RemoteSaved, + PayloadEmitSource.RemoteRetrieved, + ] + if (applicableSources.includes(source)) { + void this.handleChangedFiles([...changed, ...inserted]) + } + }, + ) const noteAndTagSources = [ PayloadEmitSource.RemoteSaved, @@ -82,13 +85,13 @@ export class FilesBackupService extends AbstractService implements BackupService PayloadEmitSource.OfflineSyncSaved, ] - this.notesObserverDisposer = items.addObserver(ContentType.Note, ({ changed, inserted, source }) => { + this.notesObserverDisposer = items.addObserver(ContentType.TYPES.Note, ({ changed, inserted, source }) => { if (noteAndTagSources.includes(source)) { void this.handleChangedNotes([...changed, ...inserted]) } }) - this.tagsObserverDisposer = items.addObserver(ContentType.Tag, ({ changed, inserted, source }) => { + this.tagsObserverDisposer = items.addObserver(ContentType.TYPES.Tag, ({ changed, inserted, source }) => { if (noteAndTagSources.includes(source)) { void this.handleChangedTags([...changed, ...inserted]) } @@ -266,7 +269,7 @@ export class FilesBackupService extends AbstractService implements BackupService this.storage.setValue(StorageKey.PlaintextBackupsEnabled, true) this.storage.setValue(StorageKey.PlaintextBackupsLocation, location) - void this.handleChangedNotes(this.items.getItems(ContentType.Note)) + void this.handleChangedNotes(this.items.getItems(ContentType.TYPES.Note)) } disablePlaintextBackups(): void { @@ -319,7 +322,7 @@ export class FilesBackupService extends AbstractService implements BackupService } private backupAllFiles(): void { - const files = this.items.getItems(ContentType.File) + const files = this.items.getItems(ContentType.TYPES.File) void this.handleChangedFiles(files) } @@ -453,7 +456,7 @@ export class FilesBackupService extends AbstractService implements BackupService } for (const tag of tags) { - const notes = this.items.referencesForItem(tag, ContentType.Note) + const notes = this.items.referencesForItem(tag, ContentType.TYPES.Note) await this.handleChangedNotes(notes) } } diff --git a/packages/services/src/Domain/Contacts/ContactService.ts b/packages/services/src/Domain/Contacts/ContactService.ts index 2a0aea17d..0f20fbd62 100644 --- a/packages/services/src/Domain/Contacts/ContactService.ts +++ b/packages/services/src/Domain/Contacts/ContactService.ts @@ -15,7 +15,6 @@ import { TrustedContactMutator, DecryptedItemInterface, } from '@standardnotes/models' -import { ContentType } from '@standardnotes/common' import { AbstractService } from '../Service/AbstractService' import { SyncServiceInterface } from '../Sync/SyncServiceInterface' import { ItemManagerInterface } from '../Item/ItemManagerInterface' @@ -31,6 +30,7 @@ import { FindTrustedContactUseCase } from './UseCase/FindTrustedContact' import { SelfContactManager } from './Managers/SelfContactManager' import { CreateOrEditTrustedContactUseCase } from './UseCase/CreateOrEditTrustedContact' import { UpdateTrustedContactUseCase } from './UseCase/UpdateTrustedContact' +import { ContentType } from '@standardnotes/domain-core' export class ContactService extends AbstractService @@ -191,7 +191,7 @@ export class ContactService }) } else { contact = await this.mutator.createItem( - ContentType.TrustedContact, + ContentType.TYPES.TrustedContact, FillItemContent(data), true, ) @@ -224,7 +224,7 @@ export class ContactService } getAllContacts(): TrustedContactInterface[] { - return this.items.getItems(ContentType.TrustedContact) + return this.items.getItems(ContentType.TYPES.TrustedContact) } findTrustedContact(userUuid: string): TrustedContactInterface | undefined { diff --git a/packages/services/src/Domain/Contacts/Managers/SelfContactManager.ts b/packages/services/src/Domain/Contacts/Managers/SelfContactManager.ts index 4b3dfa0e2..61c0a5244 100644 --- a/packages/services/src/Domain/Contacts/Managers/SelfContactManager.ts +++ b/packages/services/src/Domain/Contacts/Managers/SelfContactManager.ts @@ -15,9 +15,9 @@ import { TrustedContactContentSpecialized, TrustedContactInterface, } from '@standardnotes/models' -import { ContentType } from '@standardnotes/common' import { CreateOrEditTrustedContactUseCase } from '../UseCase/CreateOrEditTrustedContact' import { PublicKeySet } from '@standardnotes/encryption' +import { ContentType } from '@standardnotes/domain-core' export class SelfContactManager { public selfContact?: TrustedContactInterface @@ -57,7 +57,7 @@ export class SelfContactManager { } this.selfContact = this.singletons.findSingleton( - ContentType.TrustedContact, + ContentType.TYPES.TrustedContact, TrustedContact.singletonPredicate, ) } @@ -117,7 +117,7 @@ export class SelfContactManager { this.selfContact = await this.singletons.findOrCreateSingleton( TrustedContact.singletonPredicate, - ContentType.TrustedContact, + ContentType.TYPES.TrustedContact, FillItemContent(content), ) diff --git a/packages/services/src/Domain/Contacts/UseCase/CreateOrEditTrustedContact.ts b/packages/services/src/Domain/Contacts/UseCase/CreateOrEditTrustedContact.ts index 27940adba..efd571a6f 100644 --- a/packages/services/src/Domain/Contacts/UseCase/CreateOrEditTrustedContact.ts +++ b/packages/services/src/Domain/Contacts/UseCase/CreateOrEditTrustedContact.ts @@ -10,8 +10,8 @@ import { } from '@standardnotes/models' import { FindTrustedContactUseCase } from './FindTrustedContact' import { UnknownContactName } from '../UnknownContactName' -import { ContentType } from '@standardnotes/common' import { UpdateTrustedContactUseCase } from './UpdateTrustedContact' +import { ContentType } from '@standardnotes/domain-core' export class CreateOrEditTrustedContactUseCase { constructor( @@ -49,7 +49,7 @@ export class CreateOrEditTrustedContactUseCase { } const contact = await this.mutator.createItem( - ContentType.TrustedContact, + ContentType.TYPES.TrustedContact, FillItemContent(content), true, ) diff --git a/packages/services/src/Domain/Contacts/UseCase/FindTrustedContact.ts b/packages/services/src/Domain/Contacts/UseCase/FindTrustedContact.ts index 4240fd852..703d44ec4 100644 --- a/packages/services/src/Domain/Contacts/UseCase/FindTrustedContact.ts +++ b/packages/services/src/Domain/Contacts/UseCase/FindTrustedContact.ts @@ -1,7 +1,7 @@ import { Predicate, TrustedContactInterface } from '@standardnotes/models' import { ItemManagerInterface } from './../../Item/ItemManagerInterface' -import { ContentType } from '@standardnotes/common' import { FindContactQuery } from './FindContactQuery' +import { ContentType } from '@standardnotes/domain-core' export class FindTrustedContactUseCase { constructor(private items: ItemManagerInterface) {} @@ -9,18 +9,18 @@ export class FindTrustedContactUseCase { execute(query: FindContactQuery): TrustedContactInterface | undefined { if ('userUuid' in query && query.userUuid) { return this.items.itemsMatchingPredicate( - ContentType.TrustedContact, + ContentType.TYPES.TrustedContact, new Predicate('contactUuid', '=', query.userUuid), )[0] } if ('signingPublicKey' in query && query.signingPublicKey) { - const allContacts = this.items.getItems(ContentType.TrustedContact) + const allContacts = this.items.getItems(ContentType.TYPES.TrustedContact) return allContacts.find((contact) => contact.isSigningKeyTrusted(query.signingPublicKey)) } if ('publicKey' in query && query.publicKey) { - const allContacts = this.items.getItems(ContentType.TrustedContact) + const allContacts = this.items.getItems(ContentType.TYPES.TrustedContact) return allContacts.find((contact) => contact.isPublicKeyTrusted(query.publicKey)) } diff --git a/packages/services/src/Domain/Device/DatabaseLoadOptions.ts b/packages/services/src/Domain/Device/DatabaseLoadOptions.ts index cebd73e11..a4ffbb2be 100644 --- a/packages/services/src/Domain/Device/DatabaseLoadOptions.ts +++ b/packages/services/src/Domain/Device/DatabaseLoadOptions.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { FullyFormedTransferPayload } from '@standardnotes/models' export type DatabaseKeysLoadChunk = { @@ -42,7 +41,7 @@ export function isFullEntryLoadChunkResponse( } export type DatabaseLoadOptions = { - contentTypePriority: ContentType[] + contentTypePriority: string[] uuidPriority: string[] batchSize: number } diff --git a/packages/services/src/Domain/Device/DatabaseLoadSorter.spec.ts b/packages/services/src/Domain/Device/DatabaseLoadSorter.spec.ts index d52f4167c..dd815463c 100644 --- a/packages/services/src/Domain/Device/DatabaseLoadSorter.spec.ts +++ b/packages/services/src/Domain/Device/DatabaseLoadSorter.spec.ts @@ -1,28 +1,28 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { FullyFormedPayloadInterface } from '@standardnotes/models' import { GetSortedPayloadsByPriority } from './DatabaseLoadSorter' describe('GetSortedPayloadsByPriority', () => { let payloads: FullyFormedPayloadInterface[] = [] - const contentTypePriority = [ContentType.ItemsKey, ContentType.UserPrefs, ContentType.Component, ContentType.Theme] + const contentTypePriority = [ContentType.TYPES.ItemsKey, ContentType.TYPES.UserPrefs, ContentType.TYPES.Component, ContentType.TYPES.Theme] let launchPriorityUuids: string[] = [] it('should sort payloads based on content type priority', () => { payloads = [ { - content_type: ContentType.Theme, + content_type: ContentType.TYPES.Theme, } as FullyFormedPayloadInterface, { - content_type: ContentType.UserPrefs, + content_type: ContentType.TYPES.UserPrefs, } as FullyFormedPayloadInterface, { - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, } as FullyFormedPayloadInterface, { - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, } as FullyFormedPayloadInterface, { - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, } as FullyFormedPayloadInterface, ] @@ -33,15 +33,15 @@ describe('GetSortedPayloadsByPriority', () => { }) expect(itemsKeyPayloads.length).toBe(1) - expect(itemsKeyPayloads[0].content_type).toBe(ContentType.ItemsKey) + expect(itemsKeyPayloads[0].content_type).toBe(ContentType.TYPES.ItemsKey) expect(contentTypePriorityPayloads.length).toBe(3) - expect(contentTypePriorityPayloads[0].content_type).toBe(ContentType.UserPrefs) - expect(contentTypePriorityPayloads[1].content_type).toBe(ContentType.Component) - expect(contentTypePriorityPayloads[2].content_type).toBe(ContentType.Theme) + expect(contentTypePriorityPayloads[0].content_type).toBe(ContentType.TYPES.UserPrefs) + expect(contentTypePriorityPayloads[1].content_type).toBe(ContentType.TYPES.Component) + expect(contentTypePriorityPayloads[2].content_type).toBe(ContentType.TYPES.Theme) expect(remainingPayloads.length).toBe(1) - expect(remainingPayloads[0].content_type).toBe(ContentType.Note) + expect(remainingPayloads[0].content_type).toBe(ContentType.TYPES.Note) }) it('should sort payloads based on launch priority uuids', () => { @@ -53,31 +53,31 @@ describe('GetSortedPayloadsByPriority', () => { payloads = [ { - content_type: ContentType.Theme, + content_type: ContentType.TYPES.Theme, } as FullyFormedPayloadInterface, { - content_type: ContentType.UserPrefs, + content_type: ContentType.TYPES.UserPrefs, } as FullyFormedPayloadInterface, { - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, } as FullyFormedPayloadInterface, { - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, } as FullyFormedPayloadInterface, { - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, uuid: unprioritizedNoteUuid, } as FullyFormedPayloadInterface, { - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, uuid: unprioritizedTagUuid, } as FullyFormedPayloadInterface, { - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, uuid: prioritizedNoteUuid, } as FullyFormedPayloadInterface, { - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, uuid: prioritizedTagUuid, } as FullyFormedPayloadInterface, ] @@ -91,12 +91,12 @@ describe('GetSortedPayloadsByPriority', () => { }) expect(itemsKeyPayloads.length).toBe(1) - expect(itemsKeyPayloads[0].content_type).toBe(ContentType.ItemsKey) + expect(itemsKeyPayloads[0].content_type).toBe(ContentType.TYPES.ItemsKey) expect(contentTypePriorityPayloads.length).toBe(3) - expect(contentTypePriorityPayloads[0].content_type).toBe(ContentType.UserPrefs) - expect(contentTypePriorityPayloads[1].content_type).toBe(ContentType.Component) - expect(contentTypePriorityPayloads[2].content_type).toBe(ContentType.Theme) + expect(contentTypePriorityPayloads[0].content_type).toBe(ContentType.TYPES.UserPrefs) + expect(contentTypePriorityPayloads[1].content_type).toBe(ContentType.TYPES.Component) + expect(contentTypePriorityPayloads[2].content_type).toBe(ContentType.TYPES.Theme) expect(remainingPayloads.length).toBe(4) expect(remainingPayloads[0].uuid).toBe(prioritizedNoteUuid) @@ -114,21 +114,21 @@ describe('GetSortedPayloadsByPriority', () => { payloads = [ { - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, uuid: unprioritizedNoteUuid, updated_at: new Date(1), } as FullyFormedPayloadInterface, { - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, uuid: unprioritizedTagUuid, updated_at: new Date(2), } as FullyFormedPayloadInterface, { - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, uuid: prioritizedNoteUuid, } as FullyFormedPayloadInterface, { - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, uuid: prioritizedTagUuid, } as FullyFormedPayloadInterface, ] diff --git a/packages/services/src/Domain/Device/DatabaseLoadSorter.ts b/packages/services/src/Domain/Device/DatabaseLoadSorter.ts index dfdede807..9820691eb 100644 --- a/packages/services/src/Domain/Device/DatabaseLoadSorter.ts +++ b/packages/services/src/Domain/Device/DatabaseLoadSorter.ts @@ -1,6 +1,7 @@ +import { ContentType } from '@standardnotes/domain-core' + import { DatabaseItemMetadata } from './DatabaseItemMetadata' import { DatabaseLoadOptions } from './DatabaseLoadOptions' -import { ContentType } from '@standardnotes/common' /** * Sorts payloads according by most recently modified first, according to the priority, @@ -9,7 +10,7 @@ import { ContentType } from '@standardnotes/common' */ function SortPayloadsByRecentAndContentPriority( payloads: T[], - contentTypePriorityList: ContentType[], + contentTypePriorityList: string[], ): T[] { return payloads.sort((a, b) => { const dateResult = new Date(b.updated_at).getTime() - new Date(a.updated_at).getTime() @@ -97,11 +98,11 @@ export function GetSortedPayloadsByPriority payload.content_type === ContentType.ItemsKey && isDecryptedPayload(payload), + (payload) => payload.content_type === ContentType.TYPES.ItemsKey && isDecryptedPayload(payload), ) if (hasEncryptedItem && hasDecryptedItemsKey) { @@ -149,7 +149,7 @@ export class DecryptBackupFileUseCase { const encryptedPayloads: EncryptedPayloadInterface[] = [] payloads.forEach((payload) => { - if (payload.content_type === ContentType.ItemsKey && isDecryptedPayload(payload)) { + if (payload.content_type === ContentType.TYPES.ItemsKey && isDecryptedPayload(payload)) { decryptedItemsKeys.push(payload as DecryptedPayloadInterface) } else if (isEncryptedPayload(payload)) { encryptedPayloads.push(payload) diff --git a/packages/services/src/Domain/Encryption/EncryptionService.ts b/packages/services/src/Domain/Encryption/EncryptionService.ts index c91c248da..db0a4d905 100644 --- a/packages/services/src/Domain/Encryption/EncryptionService.ts +++ b/packages/services/src/Domain/Encryption/EncryptionService.ts @@ -62,7 +62,6 @@ import { AnyKeyParamsContent, ApplicationIdentifier, compareVersions, - ContentType, isVersionLessThanOrEqualTo, KeyParamsOrigination, ProtocolVersion, @@ -92,6 +91,7 @@ import { RootKeyEncryptPayloadWithKeyLookupUseCase } from './UseCase/RootEncrypt import { RootKeyEncryptPayloadUseCase } from './UseCase/RootEncryption/EncryptPayload' import { ValidateAccountPasswordResult } from './RootKey/ValidateAccountPasswordResult' import { ValidatePasscodeResult } from './RootKey/ValidatePasscodeResult' +import { ContentType } from '@standardnotes/domain-core' /** * The encryption service is responsible for the encryption and decryption of payloads, and @@ -746,7 +746,7 @@ export class EncryptionService } public createDecryptedBackupFile(): BackupFile { - const payloads = this.payloads.nonDeletedItems.filter((item) => item.content_type !== ContentType.ItemsKey) + const payloads = this.payloads.nonDeletedItems.filter((item) => item.content_type !== ContentType.TYPES.ItemsKey) const data: BackupFile = { version: ProtocolVersionLatest, diff --git a/packages/services/src/Domain/Encryption/ItemsEncryption.ts b/packages/services/src/Domain/Encryption/ItemsEncryption.ts index d7475446f..00a62b8bb 100644 --- a/packages/services/src/Domain/Encryption/ItemsEncryption.ts +++ b/packages/services/src/Domain/Encryption/ItemsEncryption.ts @@ -1,4 +1,4 @@ -import { ContentType, ProtocolVersion } from '@standardnotes/common' +import { ProtocolVersion } from '@standardnotes/common' import { DecryptedParameters, ErrorDecryptingParameters, @@ -32,6 +32,7 @@ import { PayloadManagerInterface } from '../Payloads/PayloadManagerInterface' import { AbstractService } from '../Service/AbstractService' import { StorageServiceInterface } from '../Storage/StorageServiceInterface' import { PkcKeyPair } from '@standardnotes/sncrypto-common' +import { ContentType } from '@standardnotes/domain-core' export class ItemsEncryptionService extends AbstractService { private removeItemsObserver!: () => void @@ -47,7 +48,7 @@ export class ItemsEncryptionService extends AbstractService { ) { super(internalEventBus) - this.removeItemsObserver = this.itemManager.addObserver([ContentType.ItemsKey], ({ changed, inserted }) => { + this.removeItemsObserver = this.itemManager.addObserver([ContentType.TYPES.ItemsKey], ({ changed, inserted }) => { if (changed.concat(inserted).length > 0) { void this.decryptErroredItemPayloads() } @@ -84,7 +85,9 @@ export class ItemsEncryptionService extends AbstractService { payload: EncryptedPayloadInterface, ): ItemsKeyInterface | KeySystemItemsKeyInterface | undefined { const itemsKeys = this.getItemsKeys() - const keySystemItemsKeys = this.itemManager.getItems(ContentType.KeySystemItemsKey) + const keySystemItemsKeys = this.itemManager.getItems( + ContentType.TYPES.KeySystemItemsKey, + ) return [...itemsKeys, ...keySystemItemsKeys].find( (key) => key.uuid === payload.items_key_id || key.duplicateOf === payload.items_key_id, diff --git a/packages/services/src/Domain/Encryption/UseCase/ItemsKey/CreateNewDefaultItemsKey.ts b/packages/services/src/Domain/Encryption/UseCase/ItemsKey/CreateNewDefaultItemsKey.ts index ba7361ae0..63c437fc0 100644 --- a/packages/services/src/Domain/Encryption/UseCase/ItemsKey/CreateNewDefaultItemsKey.ts +++ b/packages/services/src/Domain/Encryption/UseCase/ItemsKey/CreateNewDefaultItemsKey.ts @@ -1,10 +1,5 @@ import { OperatorManager } from '@standardnotes/encryption' -import { - ContentType, - ProtocolVersionLastNonrootItemsKey, - ProtocolVersionLatest, - compareVersions, -} from '@standardnotes/common' +import { ProtocolVersionLastNonrootItemsKey, ProtocolVersionLatest, compareVersions } from '@standardnotes/common' import { CreateDecryptedItemFromPayload, DecryptedPayload, @@ -18,6 +13,7 @@ import { UuidGenerator } from '@standardnotes/utils' import { MutatorClientInterface } from '../../../Mutator/MutatorClientInterface' import { ItemManagerInterface } from '../../../Item/ItemManagerInterface' import { RootKeyManager } from '../../RootKey/RootKeyManager' +import { ContentType } from '@standardnotes/domain-core' /** * Creates a new random items key to use for item encryption, and adds it to model management. @@ -41,7 +37,7 @@ export class CreateNewDefaultItemsKeyUseCase { /** Create root key based items key */ const payload = new DecryptedPayload({ uuid: UuidGenerator.GenerateUuid(), - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, content: FillItemContentSpecialized({ itemsKey: rootKey.masterKey, dataAuthenticationKey: rootKey.dataAuthenticationKey, diff --git a/packages/services/src/Domain/Files/FileService.ts b/packages/services/src/Domain/Files/FileService.ts index dee2614e1..99fb48126 100644 --- a/packages/services/src/Domain/Files/FileService.ts +++ b/packages/services/src/Domain/Files/FileService.ts @@ -5,7 +5,6 @@ import { isClientDisplayableError, isErrorResponse, } from '@standardnotes/responses' -import { ContentType } from '@standardnotes/common' import { FileItem, FileProtocolV1Constants, @@ -54,6 +53,7 @@ import { SharedVaultServerInterface, HttpServiceInterface, } from '@standardnotes/api' +import { ContentType } from '@standardnotes/domain-core' const OneHundredMb = 100 * 1_000_000 @@ -268,7 +268,7 @@ export class FileService extends AbstractService implements FilesClientInterface } const file = await this.mutator.createItem( - ContentType.File, + ContentType.TYPES.File, FillItemContentSpecialized(fileContent), true, operation.vault, diff --git a/packages/services/src/Domain/Item/ItemManagerInterface.ts b/packages/services/src/Domain/Item/ItemManagerInterface.ts index 45d271151..2d490cfbe 100644 --- a/packages/services/src/Domain/Item/ItemManagerInterface.ts +++ b/packages/services/src/Domain/Item/ItemManagerInterface.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { ItemsKeyInterface, DecryptedItemInterface, @@ -54,13 +53,13 @@ export interface ItemManagerInterface extends AbstractService { getCollection(): ItemCollection addObserver( - contentType: ContentType | ContentType[], + contentType: string | string[], callback: ItemManagerChangeObserverCallback, ): () => void get items(): DecryptedItemInterface[] - getItems(contentType: ContentType | ContentType[]): T[] + getItems(contentType: string | string[]): T[] get invalidItems(): EncryptedItemInterface[] allTrackedItems(): ItemInterface[] getDisplayableItemsKeys(): ItemsKeyInterface[] @@ -69,17 +68,14 @@ export interface ItemManagerInterface extends AbstractService { C extends ItemContent = ItemContent, I extends DecryptedItemInterface = DecryptedItemInterface, >( - contentType: ContentType, + contentType: string, content?: C, override?: Partial>, ): I - itemsMatchingPredicate( - contentType: ContentType, - predicate: PredicateInterface, - ): T[] + itemsMatchingPredicate(contentType: string, predicate: PredicateInterface): T[] itemsMatchingPredicates( - contentType: ContentType, + contentType: string, predicates: PredicateInterface[], ): T[] subItemsMatchingPredicates(items: T[], predicates: PredicateInterface[]): T[] @@ -90,11 +86,11 @@ export interface ItemManagerInterface extends AbstractService { getSortedTagsForItem(item: DecryptedItemInterface): SNTag[] itemsReferencingItem( itemToLookupUuidFor: { uuid: string }, - contentType?: ContentType, + contentType?: string, ): I[] referencesForItem( itemToLookupUuidFor: DecryptedItemInterface, - contentType?: ContentType, + contentType?: string, ): I[] findItem(uuid: string): T | undefined findItems(uuids: string[]): T[] diff --git a/packages/services/src/Domain/Item/StaticItemCounter.spec.ts b/packages/services/src/Domain/Item/StaticItemCounter.spec.ts index f64536991..9b3214740 100644 --- a/packages/services/src/Domain/Item/StaticItemCounter.spec.ts +++ b/packages/services/src/Domain/Item/StaticItemCounter.spec.ts @@ -1,4 +1,4 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { SNNote, SNTag } from '@standardnotes/models' import { StaticItemCounter } from './StaticItemCounter' @@ -18,10 +18,10 @@ describe('ItemCounter', () => { trashed: true, } as jest.Mocked, { - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, } as jest.Mocked, { - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, } as jest.Mocked, ] diff --git a/packages/services/src/Domain/Item/StaticItemCounter.ts b/packages/services/src/Domain/Item/StaticItemCounter.ts index d8721d12d..47921934f 100644 --- a/packages/services/src/Domain/Item/StaticItemCounter.ts +++ b/packages/services/src/Domain/Item/StaticItemCounter.ts @@ -1,4 +1,4 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { SNNote, SNTag, ItemCounts } from '@standardnotes/models' export class StaticItemCounter { @@ -21,12 +21,12 @@ export class StaticItemCounter { continue } - if (item.content_type === ContentType.Note && !item.conflictOf) { + if (item.content_type === ContentType.TYPES.Note && !item.conflictOf) { counts.notes++ continue } - if (item.content_type === ContentType.Tag) { + if (item.content_type === ContentType.TYPES.Tag) { counts.tags++ continue diff --git a/packages/services/src/Domain/KeySystem/KeySystemKeyManager.ts b/packages/services/src/Domain/KeySystem/KeySystemKeyManager.ts index e6b737c43..dd2d9b4cd 100644 --- a/packages/services/src/Domain/KeySystem/KeySystemKeyManager.ts +++ b/packages/services/src/Domain/KeySystem/KeySystemKeyManager.ts @@ -16,9 +16,9 @@ import { VaultListingInterface, } from '@standardnotes/models' import { ItemManagerInterface } from './../Item/ItemManagerInterface' -import { ContentType } from '@standardnotes/common' import { KeySystemKeyManagerInterface } from '@standardnotes/encryption' import { AbstractService } from '../Service/AbstractService' +import { ContentType } from '@standardnotes/domain-core' const RootKeyStorageKeyPrefix = 'key-system-root-key-' @@ -76,7 +76,7 @@ export class KeySystemKeyManager extends AbstractService implements KeySystemKey } public getAllSyncedKeySystemRootKeys(): KeySystemRootKeyInterface[] { - return this.items.getItems(ContentType.KeySystemRootKey) + return this.items.getItems(ContentType.TYPES.KeySystemRootKey) } public clearMemoryOfKeysRelatedToVault(vault: VaultListingInterface): void { @@ -88,7 +88,7 @@ export class KeySystemKeyManager extends AbstractService implements KeySystemKey public getSyncedKeySystemRootKeysForVault(systemIdentifier: KeySystemIdentifier): KeySystemRootKeyInterface[] { return this.items.itemsMatchingPredicate( - ContentType.KeySystemRootKey, + ContentType.TYPES.KeySystemRootKey, new Predicate('systemIdentifier', '=', systemIdentifier), ) } @@ -131,14 +131,16 @@ export class KeySystemKeyManager extends AbstractService implements KeySystemKey } public getAllKeySystemItemsKeys(): (KeySystemItemsKeyInterface | EncryptedItemInterface)[] { - const decryptedItems = this.items.getItems(ContentType.KeySystemItemsKey) - const encryptedItems = this.items.invalidItems.filter((item) => item.content_type === ContentType.KeySystemItemsKey) + const decryptedItems = this.items.getItems(ContentType.TYPES.KeySystemItemsKey) + const encryptedItems = this.items.invalidItems.filter( + (item) => item.content_type === ContentType.TYPES.KeySystemItemsKey, + ) return [...decryptedItems, ...encryptedItems] } public getKeySystemItemsKeys(systemIdentifier: KeySystemIdentifier): KeySystemItemsKeyInterface[] { return this.items - .getItems(ContentType.KeySystemItemsKey) + .getItems(ContentType.TYPES.KeySystemItemsKey) .filter((key) => key.key_system_identifier === systemIdentifier) } diff --git a/packages/services/src/Domain/Mutator/ImportDataUseCase.ts b/packages/services/src/Domain/Mutator/ImportDataUseCase.ts index 6812c71bb..2852401de 100644 --- a/packages/services/src/Domain/Mutator/ImportDataUseCase.ts +++ b/packages/services/src/Domain/Mutator/ImportDataUseCase.ts @@ -4,7 +4,7 @@ import { PayloadManagerInterface } from '../Payloads/PayloadManagerInterface' import { ProtectionsClientInterface } from '../Protection/ProtectionClientInterface' import { SyncServiceInterface } from '../Sync/SyncServiceInterface' import { ItemManagerInterface } from '../Item/ItemManagerInterface' -import { ContentType, ProtocolVersion, compareVersions } from '@standardnotes/common' +import { ProtocolVersion, compareVersions } from '@standardnotes/common' import { BackupFile, BackupFileDecryptedContextualPayload, @@ -20,6 +20,7 @@ import { import { ClientDisplayableError } from '@standardnotes/responses' import { EncryptionProviderInterface } from '@standardnotes/encryption' import { Challenge, ChallengePrompt, ChallengeReason, ChallengeValidation } from '../Challenge' +import { ContentType } from '@standardnotes/domain-core' const Strings = { UnsupportedBackupFileVersion: @@ -115,7 +116,7 @@ export class ImportDataUseCase { const validPayloads = decryptedPayloadsOrError.filter(isDecryptedPayload).map((payload) => { /* Don't want to activate any components during import process in * case of exceptions breaking up the import proccess */ - if (payload.content_type === ContentType.Component && (payload.content as ComponentContent).active) { + if (payload.content_type === ContentType.TYPES.Component && (payload.content as ComponentContent).active) { const typedContent = payload as DecryptedPayloadInterface return CopyPayloadWithContentOverride(typedContent, { active: false, diff --git a/packages/services/src/Domain/Mutator/MutatorClientInterface.ts b/packages/services/src/Domain/Mutator/MutatorClientInterface.ts index 131081277..14f6002ce 100644 --- a/packages/services/src/Domain/Mutator/MutatorClientInterface.ts +++ b/packages/services/src/Domain/Mutator/MutatorClientInterface.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { ComponentMutator, DecryptedItemInterface, @@ -37,7 +36,7 @@ export interface MutatorClientInterface { isUserModified?: boolean, ): Promise createItem( - contentType: ContentType, + contentType: string, content: C, needsSync?: boolean, vault?: VaultListingInterface, diff --git a/packages/services/src/Domain/SharedVaults/SharedVaultService.ts b/packages/services/src/Domain/SharedVaults/SharedVaultService.ts index da2000731..7bca6bfb0 100644 --- a/packages/services/src/Domain/SharedVaults/SharedVaultService.ts +++ b/packages/services/src/Domain/SharedVaults/SharedVaultService.ts @@ -33,7 +33,6 @@ import { import { SharedVaultServiceInterface } from './SharedVaultServiceInterface' import { SharedVaultServiceEvent, SharedVaultServiceEventPayload } from './SharedVaultServiceEvent' import { EncryptionProviderInterface } from '@standardnotes/encryption' -import { ContentType } from '@standardnotes/common' import { GetSharedVaultUsersUseCase } from './UseCase/GetSharedVaultUsers' import { RemoveVaultMemberUseCase } from './UseCase/RemoveSharedVaultMember' import { AbstractService } from '../Service/AbstractService' @@ -64,6 +63,7 @@ import { CreateSharedVaultUseCase } from './UseCase/CreateSharedVault' import { SendSharedVaultMetadataChangedMessageToAll } from './UseCase/SendSharedVaultMetadataChangedMessageToAll' import { ConvertToSharedVaultUseCase } from './UseCase/ConvertToSharedVault' import { GetVaultUseCase } from '../Vaults/UseCase/GetVault' +import { ContentType } from '@standardnotes/domain-core' export class SharedVaultService extends AbstractService @@ -111,20 +111,23 @@ export class SharedVaultService ) this.eventDisposers.push( - items.addObserver(ContentType.TrustedContact, async ({ changed, inserted, source }) => { - await this.reprocessCachedInvitesTrustStatusAfterTrustedContactsChange() + items.addObserver( + ContentType.TYPES.TrustedContact, + async ({ changed, inserted, source }) => { + await this.reprocessCachedInvitesTrustStatusAfterTrustedContactsChange() - if (source === PayloadEmitSource.LocalChanged && inserted.length > 0) { - void this.handleCreationOfNewTrustedContacts(inserted) - } - if (source === PayloadEmitSource.LocalChanged && changed.length > 0) { - void this.handleTrustedContactsChange(changed) - } - }), + if (source === PayloadEmitSource.LocalChanged && inserted.length > 0) { + void this.handleCreationOfNewTrustedContacts(inserted) + } + if (source === PayloadEmitSource.LocalChanged && changed.length > 0) { + void this.handleTrustedContactsChange(changed) + } + }, + ), ) this.eventDisposers.push( - items.addObserver(ContentType.VaultListing, ({ changed, source }) => { + items.addObserver(ContentType.TYPES.VaultListing, ({ changed, source }) => { if (source === PayloadEmitSource.LocalChanged && changed.length > 0) { void this.handleVaultListingsChange(changed) } diff --git a/packages/services/src/Domain/Singleton/SingletonManagerInterface.ts b/packages/services/src/Domain/Singleton/SingletonManagerInterface.ts index c3dafd0be..8bc1c069d 100644 --- a/packages/services/src/Domain/Singleton/SingletonManagerInterface.ts +++ b/packages/services/src/Domain/Singleton/SingletonManagerInterface.ts @@ -1,17 +1,13 @@ import { DecryptedItemInterface, ItemContent, Predicate, PredicateInterface } from '@standardnotes/models' -import { ContentType } from '@standardnotes/common' export interface SingletonManagerInterface { - findSingleton( - contentType: ContentType, - predicate: PredicateInterface, - ): T | undefined + findSingleton(contentType: string, predicate: PredicateInterface): T | undefined findOrCreateContentTypeSingleton< C extends ItemContent = ItemContent, T extends DecryptedItemInterface = DecryptedItemInterface, >( - contentType: ContentType, + contentType: string, createContent: ItemContent, ): Promise @@ -20,7 +16,7 @@ export interface SingletonManagerInterface { T extends DecryptedItemInterface = DecryptedItemInterface, >( predicate: Predicate, - contentType: ContentType, + contentType: string, createContent: ItemContent, ): Promise } diff --git a/packages/services/src/Domain/Vaults/UseCase/CreateVault.ts b/packages/services/src/Domain/Vaults/UseCase/CreateVault.ts index e51cc3625..33dae625c 100644 --- a/packages/services/src/Domain/Vaults/UseCase/CreateVault.ts +++ b/packages/services/src/Domain/Vaults/UseCase/CreateVault.ts @@ -10,8 +10,8 @@ import { FillItemContentSpecialized, KeySystemRootKeyInterface, } from '@standardnotes/models' -import { ContentType } from '@standardnotes/common' import { MutatorClientInterface } from '../../Mutator/MutatorClientInterface' +import { ContentType } from '@standardnotes/domain-core' export class CreateVaultUseCase { constructor( @@ -70,7 +70,7 @@ export class CreateVaultUseCase { description: dto.vaultDescription, } - return this.mutator.createItem(ContentType.VaultListing, FillItemContentSpecialized(content), true) + return this.mutator.createItem(ContentType.TYPES.VaultListing, FillItemContentSpecialized(content), true) } private async createKeySystemItemsKey(keySystemIdentifier: string, rootKeyToken: string): Promise { diff --git a/packages/services/src/Domain/Vaults/UseCase/GetVault.ts b/packages/services/src/Domain/Vaults/UseCase/GetVault.ts index de8298b0d..3ca8ced16 100644 --- a/packages/services/src/Domain/Vaults/UseCase/GetVault.ts +++ b/packages/services/src/Domain/Vaults/UseCase/GetVault.ts @@ -1,12 +1,12 @@ import { VaultListingInterface } from '@standardnotes/models' import { ItemManagerInterface } from './../../Item/ItemManagerInterface' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' export class GetVaultUseCase { constructor(private items: ItemManagerInterface) {} execute(query: { keySystemIdentifier: string } | { sharedVaultUuid: string }): T | undefined { - const vaults = this.items.getItems(ContentType.VaultListing) + const vaults = this.items.getItems(ContentType.TYPES.VaultListing) if ('keySystemIdentifier' in query) { return vaults.find((listing) => listing.systemIdentifier === query.keySystemIdentifier) as T diff --git a/packages/services/src/Domain/Vaults/UseCase/MoveItemsToVault.ts b/packages/services/src/Domain/Vaults/UseCase/MoveItemsToVault.ts index 433a14105..7181df7c3 100644 --- a/packages/services/src/Domain/Vaults/UseCase/MoveItemsToVault.ts +++ b/packages/services/src/Domain/Vaults/UseCase/MoveItemsToVault.ts @@ -2,7 +2,7 @@ import { MutatorClientInterface, SyncServiceInterface } from '@standardnotes/ser import { ClientDisplayableError } from '@standardnotes/responses' import { DecryptedItemInterface, FileItem, VaultListingInterface } from '@standardnotes/models' import { FilesClientInterface } from '@standardnotes/files' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' export class MoveItemsToVaultUseCase { constructor( @@ -25,7 +25,7 @@ export class MoveItemsToVaultUseCase { await this.sync.sync() for (const item of dto.items) { - if (item.content_type !== ContentType.File) { + if (item.content_type !== ContentType.TYPES.File) { continue } diff --git a/packages/services/src/Domain/Vaults/UseCase/RemoveItemFromVault.ts b/packages/services/src/Domain/Vaults/UseCase/RemoveItemFromVault.ts index 44ca73529..5ad721126 100644 --- a/packages/services/src/Domain/Vaults/UseCase/RemoveItemFromVault.ts +++ b/packages/services/src/Domain/Vaults/UseCase/RemoveItemFromVault.ts @@ -1,7 +1,7 @@ import { MutatorClientInterface, SyncServiceInterface } from '@standardnotes/services' import { ClientDisplayableError } from '@standardnotes/responses' import { DecryptedItemInterface, FileItem } from '@standardnotes/models' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { FilesClientInterface } from '@standardnotes/files' export class RemoveItemFromVault { @@ -19,7 +19,7 @@ export class RemoveItemFromVault { await this.sync.sync() - if (dto.item.content_type === ContentType.File) { + if (dto.item.content_type === ContentType.TYPES.File) { await this.files.moveFileOutOfSharedVault(dto.item as FileItem) } } diff --git a/packages/services/src/Domain/Vaults/VaultService.ts b/packages/services/src/Domain/Vaults/VaultService.ts index b12e1c8d5..b20dedf76 100644 --- a/packages/services/src/Domain/Vaults/VaultService.ts +++ b/packages/services/src/Domain/Vaults/VaultService.ts @@ -24,11 +24,11 @@ import { MoveItemsToVaultUseCase } from './UseCase/MoveItemsToVault' import { RotateVaultRootKeyUseCase } from './UseCase/RotateVaultRootKey' import { FilesClientInterface } from '@standardnotes/files' -import { ContentType } from '@standardnotes/common' import { GetVaultUseCase } from './UseCase/GetVault' import { ChangeVaultKeyOptionsUseCase } from './UseCase/ChangeVaultKeyOptions' import { MutatorClientInterface } from '../Mutator/MutatorClientInterface' import { AlertService } from '../Alert/AlertService' +import { ContentType } from '@standardnotes/domain-core' export class VaultService extends AbstractService @@ -47,13 +47,16 @@ export class VaultService ) { super(eventBus) - items.addObserver([ContentType.KeySystemItemsKey, ContentType.KeySystemRootKey, ContentType.VaultListing], () => { - void this.recomputeAllVaultsLockingState() - }) + items.addObserver( + [ContentType.TYPES.KeySystemItemsKey, ContentType.TYPES.KeySystemRootKey, ContentType.TYPES.VaultListing], + () => { + void this.recomputeAllVaultsLockingState() + }, + ) } getVaults(): VaultListingInterface[] { - return this.items.getItems(ContentType.VaultListing).sort((a, b) => { + return this.items.getItems(ContentType.TYPES.VaultListing).sort((a, b) => { return a.name.localeCompare(b.name) }) } diff --git a/packages/snjs/lib/Application/Application.ts b/packages/snjs/lib/Application/Application.ts index b5bbf5924..91ad40ad0 100644 --- a/packages/snjs/lib/Application/Application.ts +++ b/packages/snjs/lib/Application/Application.ts @@ -690,7 +690,7 @@ export class SNApplication implements ApplicationInterface, AppGroupManagedAppli * items matching the constraint are added, changed, or deleted. */ public streamItems( - contentType: Common.ContentType | Common.ContentType[], + contentType: string | string[], stream: ItemStream, ): () => void { const removeItemManagerObserver = this.itemManager.addObserver( diff --git a/packages/snjs/lib/Domain/UseCase/GetRevision/GetRevision.ts b/packages/snjs/lib/Domain/UseCase/GetRevision/GetRevision.ts index dcfe9985f..c076be65f 100644 --- a/packages/snjs/lib/Domain/UseCase/GetRevision/GetRevision.ts +++ b/packages/snjs/lib/Domain/UseCase/GetRevision/GetRevision.ts @@ -9,7 +9,6 @@ import { NoteContent, PayloadTimestampDefaults, } from '@standardnotes/models' -import { ContentType } from '@standardnotes/common' import { EncryptionProviderInterface } from '@standardnotes/encryption' import { GetRevisionDTO } from './GetRevisionDTO' @@ -51,7 +50,7 @@ export class GetRevision implements UseCaseInterface { enc_item_key: revision.enc_item_key as string, items_key_id: revision.items_key_id as string, auth_hash: revision.auth_hash as string, - content_type: revision.content_type as ContentType, + content_type: revision.content_type, updated_at: new Date(revision.updated_at), created_at: new Date(revision.created_at), key_system_identifier: revision.key_system_identifier ?? undefined, diff --git a/packages/snjs/lib/Migrations/Applicators/TagsToFolders.ts b/packages/snjs/lib/Migrations/Applicators/TagsToFolders.ts index 690d9b15b..b57d385e7 100644 --- a/packages/snjs/lib/Migrations/Applicators/TagsToFolders.ts +++ b/packages/snjs/lib/Migrations/Applicators/TagsToFolders.ts @@ -2,11 +2,11 @@ import { MutatorClientInterface } from '@standardnotes/services' import { SNTag, TagMutator, TagFolderDelimitter } from '@standardnotes/models' import { ItemManager } from '@Lib/Services' import { lastElement, sortByKey, withoutLastElement } from '@standardnotes/utils' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' export class TagsToFoldersMigrationApplicator { public static isApplicableToCurrentData(itemManager: ItemManager): boolean { - const tags = itemManager.getItems(ContentType.Tag) + const tags = itemManager.getItems(ContentType.TYPES.Tag) for (const tag of tags) { if (tag.title.includes(TagFolderDelimitter) && !tag.parentId) { return true @@ -17,7 +17,7 @@ export class TagsToFoldersMigrationApplicator { } public static async run(itemManager: ItemManager, mutator: MutatorClientInterface): Promise { - const tags = itemManager.getItems(ContentType.Tag) as SNTag[] + const tags = itemManager.getItems(ContentType.TYPES.Tag) as SNTag[] const sortedTags = sortByKey(tags, 'title') for (const tag of sortedTags) { diff --git a/packages/snjs/lib/Migrations/Versions/2_20_0.ts b/packages/snjs/lib/Migrations/Versions/2_20_0.ts index 020cb5516..b00ab3c36 100644 --- a/packages/snjs/lib/Migrations/Versions/2_20_0.ts +++ b/packages/snjs/lib/Migrations/Versions/2_20_0.ts @@ -1,5 +1,4 @@ import { Migration } from '@Lib/Migrations/Migration' -import { ContentType } from '@standardnotes/common' import { ApplicationStage } from '@standardnotes/services' export class Migration2_20_0 extends Migration { @@ -15,7 +14,7 @@ export class Migration2_20_0 extends Migration { } private async deleteMfaItems(): Promise { - const contentType = 'SF|MFA' as ContentType + const contentType = 'SF|MFA' const items = this.services.itemManager.getItems(contentType) for (const item of items) { diff --git a/packages/snjs/lib/Migrations/Versions/2_36_0.ts b/packages/snjs/lib/Migrations/Versions/2_36_0.ts index 70efaff09..dbeb3e521 100644 --- a/packages/snjs/lib/Migrations/Versions/2_36_0.ts +++ b/packages/snjs/lib/Migrations/Versions/2_36_0.ts @@ -1,5 +1,4 @@ import { Migration } from '@Lib/Migrations/Migration' -import { ContentType } from '@standardnotes/common' import { ApplicationStage } from '@standardnotes/services' export class Migration2_36_0 extends Migration { @@ -15,7 +14,7 @@ export class Migration2_36_0 extends Migration { } private async removeServerExtensionsLocally(): Promise { - const contentType = 'SF|Extension' as ContentType + const contentType = 'SF|Extension' const items = this.services.itemManager.getItems(contentType) for (const item of items) { diff --git a/packages/snjs/lib/Migrations/Versions/2_42_0.ts b/packages/snjs/lib/Migrations/Versions/2_42_0.ts index d69bc084f..48b706280 100644 --- a/packages/snjs/lib/Migrations/Versions/2_42_0.ts +++ b/packages/snjs/lib/Migrations/Versions/2_42_0.ts @@ -1,8 +1,8 @@ -import { ContentType } from '@standardnotes/common' import { ApplicationStage } from '@standardnotes/services' import { FeatureIdentifier } from '@standardnotes/features' import { Migration } from '@Lib/Migrations/Migration' import { SNTheme } from '@standardnotes/models' +import { ContentType } from '@standardnotes/domain-core' const NoDistractionIdentifier = 'org.standardnotes.theme-no-distraction' as FeatureIdentifier @@ -19,7 +19,7 @@ export class Migration2_42_0 extends Migration { } private async deleteNoDistraction(): Promise { - const themes = (this.services.itemManager.getItems(ContentType.Theme) as SNTheme[]).filter((theme) => { + const themes = (this.services.itemManager.getItems(ContentType.TYPES.Theme) as SNTheme[]).filter((theme) => { return theme.identifier === NoDistractionIdentifier }) diff --git a/packages/snjs/lib/Migrations/Versions/2_7_0.ts b/packages/snjs/lib/Migrations/Versions/2_7_0.ts index 8d20f8dba..ec3a9fdfd 100644 --- a/packages/snjs/lib/Migrations/Versions/2_7_0.ts +++ b/packages/snjs/lib/Migrations/Versions/2_7_0.ts @@ -1,7 +1,7 @@ import { CompoundPredicate, Predicate, SNComponent } from '@standardnotes/models' import { Migration } from '@Lib/Migrations/Migration' -import { ContentType } from '@standardnotes/common' import { ApplicationStage } from '@standardnotes/services' +import { ContentType } from '@standardnotes/domain-core' export class Migration2_7_0 extends Migration { static override version(): string { @@ -19,11 +19,11 @@ export class Migration2_7_0 extends Migration { const batchMgrId = 'org.standardnotes.batch-manager' const batchMgrPred = new CompoundPredicate('and', [ - new Predicate('content_type', '=', ContentType.Component), + new Predicate('content_type', '=', ContentType.TYPES.Component), new Predicate('identifier', '=', batchMgrId), ]) - const batchMgrSingleton = this.services.singletonManager.findSingleton(ContentType.Component, batchMgrPred) + const batchMgrSingleton = this.services.singletonManager.findSingleton(ContentType.TYPES.Component, batchMgrPred) if (batchMgrSingleton) { await this.services.mutator.setItemToBeDeleted(batchMgrSingleton) diff --git a/packages/snjs/lib/Services/Actions/ActionsService.ts b/packages/snjs/lib/Services/Actions/ActionsService.ts index badf32fa4..22d26d684 100644 --- a/packages/snjs/lib/Services/Actions/ActionsService.ts +++ b/packages/snjs/lib/Services/Actions/ActionsService.ts @@ -3,7 +3,6 @@ import { SNRootKey } from '@standardnotes/encryption' import { ChallengeService } from '../Challenge' import { ListedService } from '../Listed/ListedService' import { ActionResponse, DeprecatedHttpResponse } from '@standardnotes/responses' -import { ContentType } from '@standardnotes/common' import { ItemManager } from '@Lib/Services/Items/ItemManager' import { SNActionsExtension, @@ -36,6 +35,7 @@ import { EncryptionService, Challenge, } from '@standardnotes/services' +import { ContentType } from '@standardnotes/domain-core' type PayloadRequestHandler = (uuid: string) => TransferPayload | undefined @@ -97,7 +97,7 @@ export class SNActionsService extends AbstractService { } public getExtensions(): SNActionsExtension[] { - const extensionItems = this.itemManager.getItems(ContentType.ActionsExtension) + const extensionItems = this.itemManager.getItems(ContentType.TYPES.ActionsExtension) const excludingListed = extensionItems.filter((extension) => !extension.isListedExtension) return excludingListed } diff --git a/packages/snjs/lib/Services/ComponentManager/ComponentManager.spec.ts b/packages/snjs/lib/Services/ComponentManager/ComponentManager.spec.ts index 5fa9a6096..671f00c3b 100644 --- a/packages/snjs/lib/Services/ComponentManager/ComponentManager.spec.ts +++ b/packages/snjs/lib/Services/ComponentManager/ComponentManager.spec.ts @@ -12,7 +12,6 @@ import { FeatureIdentifier, NoteType, } from '@standardnotes/features' -import { ContentType } from '@standardnotes/common' import { GenericItem, SNComponent, Environment, Platform } from '@standardnotes/models' import { DesktopManagerInterface, @@ -25,6 +24,7 @@ import { ItemManager } from '@Lib/Services/Items/ItemManager' import { SNFeaturesService } from '@Lib/Services/Features/FeaturesService' import { SNComponentManager } from './ComponentManager' import { SNSyncService } from '../Sync/SyncService' +import { ContentType } from '@standardnotes/domain-core' describe('featuresService', () => { let itemManager: ItemManager @@ -100,7 +100,7 @@ describe('featuresService', () => { const nativeComponent = (identifier?: FeatureIdentifier, file_type?: FeatureDescription['file_type']) => { return new SNComponent({ uuid: '789', - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, content: { package_info: { hosted_url: 'https://example.com/component', @@ -115,7 +115,7 @@ describe('featuresService', () => { const deprecatedComponent = () => { return new SNComponent({ uuid: '789', - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, content: { package_info: { hosted_url: 'https://example.com/component', @@ -129,7 +129,7 @@ describe('featuresService', () => { const thirdPartyComponent = () => { return new SNComponent({ uuid: '789', - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, content: { local_url: 'sn://Extensions/non-native-identifier/dist/index.html', hosted_url: 'https://example.com/component', @@ -146,7 +146,7 @@ describe('featuresService', () => { const permissions: ComponentPermission[] = [ { name: ComponentAction.StreamContextItem, - content_types: [ContentType.Note], + content_types: [ContentType.TYPES.Note], }, ] @@ -160,7 +160,7 @@ describe('featuresService', () => { const permissions: ComponentPermission[] = [ { name: ComponentAction.StreamItems, - content_types: [ContentType.Note], + content_types: [ContentType.TYPES.Note], }, ] @@ -172,7 +172,7 @@ describe('featuresService', () => { const permissions: ComponentPermission[] = [ { name: ComponentAction.StreamItems, - content_types: [ContentType.Tag], + content_types: [ContentType.TYPES.Tag], }, ] @@ -184,7 +184,7 @@ describe('featuresService', () => { const permissions: ComponentPermission[] = [ { name: ComponentAction.StreamItems, - content_types: [ContentType.Tag, ContentType.Note], + content_types: [ContentType.TYPES.Tag, ContentType.TYPES.Note], }, ] @@ -196,7 +196,7 @@ describe('featuresService', () => { const permissions: ComponentPermission[] = [ { name: ComponentAction.StreamItems, - content_types: [ContentType.Tag, ContentType.FilesafeFileMetadata], + content_types: [ContentType.TYPES.Tag, ContentType.TYPES.FilesafeFileMetadata], }, ] @@ -211,9 +211,9 @@ describe('featuresService', () => { { name: ComponentAction.StreamItems, content_types: [ - ContentType.FilesafeFileMetadata, - ContentType.FilesafeCredentials, - ContentType.FilesafeIntegration, + ContentType.TYPES.FilesafeFileMetadata, + ContentType.TYPES.FilesafeCredentials, + ContentType.TYPES.FilesafeIntegration, ], }, ] @@ -229,9 +229,9 @@ describe('featuresService', () => { { name: ComponentAction.StreamItems, content_types: [ - ContentType.FilesafeFileMetadata, - ContentType.FilesafeCredentials, - ContentType.FilesafeIntegration, + ContentType.TYPES.FilesafeFileMetadata, + ContentType.TYPES.FilesafeCredentials, + ContentType.TYPES.FilesafeIntegration, ], }, ] @@ -247,9 +247,9 @@ describe('featuresService', () => { { name: ComponentAction.StreamItems, content_types: [ - ContentType.FilesafeFileMetadata, - ContentType.FilesafeCredentials, - ContentType.FilesafeIntegration, + ContentType.TYPES.FilesafeFileMetadata, + ContentType.TYPES.FilesafeCredentials, + ContentType.TYPES.FilesafeIntegration, ], }, ] @@ -290,7 +290,7 @@ describe('featuresService', () => { const manager = createManager(Environment.Desktop, Platform.MacDesktop) const component = new SNComponent({ uuid: '789', - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, content: { hosted_url: 'https://example.com/component', package_info: { diff --git a/packages/snjs/lib/Services/ComponentManager/ComponentManager.ts b/packages/snjs/lib/Services/ComponentManager/ComponentManager.ts index 57fb5ea76..eaab74abf 100644 --- a/packages/snjs/lib/Services/ComponentManager/ComponentManager.ts +++ b/packages/snjs/lib/Services/ComponentManager/ComponentManager.ts @@ -1,7 +1,6 @@ import { AllowedBatchStreaming } from './Types' import { SNPreferencesService } from '../Preferences/PreferencesService' import { SNFeaturesService } from '@Lib/Services/Features/FeaturesService' -import { ContentType, DisplayStringForContentType } from '@standardnotes/common' import { ItemManager } from '@Lib/Services/Items/ItemManager' import { ActionObserver, @@ -41,6 +40,7 @@ import { isMobileDevice, MutatorClientInterface, } from '@standardnotes/services' +import { ContentType } from '@standardnotes/domain-core' const DESKTOP_URL_PREFIX = 'sn://' const LOCAL_HOST = 'localhost' @@ -223,7 +223,7 @@ export class SNComponentManager addItemObserver(): void { this.removeItemObserver = this.itemManager.addObserver( - [ContentType.Component, ContentType.Theme], + [ContentType.TYPES.Component, ContentType.TYPES.Theme], ({ changed, inserted, removed, source }) => { const items = [...changed, ...inserted] this.handleChangedComponents(items, source) @@ -654,12 +654,17 @@ export class SNComponentManager if (!permission.content_types) { return } - permission.content_types.forEach((contentType) => { - const desc = DisplayStringForContentType(contentType) + permission.content_types.forEach((contentTypeString: string) => { + const contentTypeOrError = ContentType.create(contentTypeString) + if (contentTypeOrError.isFailed()) { + return + } + const contentType = contentTypeOrError.getValue() + const desc = contentType.getDisplayName() if (desc) { contentTypeStrings.push(`${desc}s`) } else { - contentTypeStrings.push(`items of type ${contentType}`) + contentTypeStrings.push(`items of type ${contentType.value}`) } }) break diff --git a/packages/snjs/lib/Services/ComponentManager/ComponentViewer.ts b/packages/snjs/lib/Services/ComponentManager/ComponentViewer.ts index e3182f1f7..6b4c4d57d 100644 --- a/packages/snjs/lib/Services/ComponentManager/ComponentViewer.ts +++ b/packages/snjs/lib/Services/ComponentManager/ComponentViewer.ts @@ -52,7 +52,6 @@ import { import { ComponentAction, ComponentPermission, ComponentArea, FindNativeFeature } from '@standardnotes/features' import { ItemManager } from '@Lib/Services/Items/ItemManager' import { UuidString } from '@Lib/Types/UuidString' -import { ContentType } from '@standardnotes/common' import { isString, extendArray, @@ -65,6 +64,7 @@ import { sureSearchArray, isNotUndefined, } from '@standardnotes/utils' +import { ContentType } from '@standardnotes/domain-core' type RunWithPermissionsCallback = ( componentUuid: UuidString, @@ -88,7 +88,7 @@ const ReadwriteActions = [ type Writeable = { -readonly [P in keyof T]: T[P] } export class ComponentViewer implements ComponentViewerInterface { - private streamItems?: ContentType[] + private streamItems?: string[] private streamContextItemOriginalMessage?: ComponentMessage private streamItemsOriginalMessage?: ComponentMessage private removeItemObserver: () => void @@ -123,7 +123,7 @@ export class ComponentViewer implements ComponentViewerInterface { actionObserver?: ActionObserver, ) { this.removeItemObserver = this.itemManager.addObserver( - ContentType.Any, + ContentType.TYPES.Any, ({ changed, inserted, removed, source, sourceKey }) => { if (this.dealloced) { return @@ -686,7 +686,7 @@ export class ComponentViewer implements ComponentViewerInterface { if (item.locked) { remove(responsePayloads, { uuid: item.uuid }) lockedCount++ - if (item.content_type === ContentType.Note) { + if (item.content_type === ContentType.TYPES.Note) { lockedNoteCount++ } } @@ -836,7 +836,7 @@ export class ComponentViewer implements ComponentViewerInterface { const data = message.data as DeleteItemsMessageData const items = data.items.filter((item) => AllowedBatchContentTypes.includes(item.content_type)) - const requiredContentTypes = uniq(items.map((item) => item.content_type)).sort() as ContentType[] + const requiredContentTypes = uniq(items.map((item) => item.content_type)).sort() const requiredPermissions: ComponentPermission[] = [ { diff --git a/packages/snjs/lib/Services/ComponentManager/Types.ts b/packages/snjs/lib/Services/ComponentManager/Types.ts index 1a7484add..e2f23cd60 100644 --- a/packages/snjs/lib/Services/ComponentManager/Types.ts +++ b/packages/snjs/lib/Services/ComponentManager/Types.ts @@ -1,7 +1,7 @@ import { ComponentArea, ComponentAction, FeatureIdentifier, LegacyFileSafeIdentifier } from '@standardnotes/features' import { ComponentMessage, MessageData, OutgoingItemMessagePayload } from '@standardnotes/models' import { UuidString } from '@Lib/Types/UuidString' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' /** * Extensions allowed to batch stream AllowedBatchContentTypes @@ -16,9 +16,9 @@ export const AllowedBatchStreaming = Object.freeze([ * Content types which are allowed to be managed/streamed in bulk by a component. */ export const AllowedBatchContentTypes = Object.freeze([ - ContentType.FilesafeCredentials, - ContentType.FilesafeFileMetadata, - ContentType.FilesafeIntegration, + ContentType.TYPES.FilesafeCredentials, + ContentType.TYPES.FilesafeFileMetadata, + ContentType.TYPES.FilesafeIntegration, ]) export type StreamObserver = { diff --git a/packages/snjs/lib/Services/Features/FeaturesService.spec.ts b/packages/snjs/lib/Services/Features/FeaturesService.spec.ts index 7074f89f8..7e644f54b 100644 --- a/packages/snjs/lib/Services/Features/FeaturesService.spec.ts +++ b/packages/snjs/lib/Services/Features/FeaturesService.spec.ts @@ -2,8 +2,7 @@ import { ItemInterface, SNComponent, SNFeatureRepo } from '@standardnotes/models import { SNSyncService } from '../Sync/SyncService' import { SettingName } from '@standardnotes/settings' import { SNFeaturesService } from '@Lib/Services/Features' -import { ContentType } from '@standardnotes/common' -import { RoleName } from '@standardnotes/domain-core' +import { ContentType, RoleName } from '@standardnotes/domain-core' import { FeatureDescription, FeatureIdentifier, GetFeatures } from '@standardnotes/features' import { SNWebSocketsService } from '../Api/WebsocketsService' import { SNSettingsService } from '../Settings' @@ -157,7 +156,7 @@ describe('featuresService', () => { { identifier: FeatureIdentifier.PlusEditor, expires_at: tomorrow_server, - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, }, ] @@ -307,10 +306,10 @@ describe('featuresService', () => { expect(mutator.createItem).toHaveBeenCalledTimes(2) expect(mutator.createItem).toHaveBeenCalledWith( - ContentType.Theme, + ContentType.TYPES.Theme, expect.objectContaining({ package_info: expect.objectContaining({ - content_type: ContentType.Theme, + content_type: ContentType.TYPES.Theme, expires_at: tomorrow_client, identifier: FeatureIdentifier.MidnightTheme, }), @@ -318,10 +317,10 @@ describe('featuresService', () => { true, ) expect(mutator.createItem).toHaveBeenCalledWith( - ContentType.Component, + ContentType.TYPES.Component, expect.objectContaining({ package_info: expect.objectContaining({ - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, expires_at: tomorrow_client, identifier: FeatureIdentifier.PlusEditor, }), @@ -333,7 +332,7 @@ describe('featuresService', () => { it('if item for a feature exists updates its content', async () => { const existingItem = new SNComponent({ uuid: '789', - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, content: { package_info: { identifier: FeatureIdentifier.PlusEditor, @@ -379,10 +378,10 @@ describe('featuresService', () => { await featuresService.fetchFeatures('123', didChangeRoles) expect(mutator.createItem).toHaveBeenCalledWith( - ContentType.Component, + ContentType.TYPES.Component, expect.objectContaining({ package_info: expect.objectContaining({ - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, expires_at: yesterday_client, identifier: FeatureIdentifier.PlusEditor, }), @@ -394,7 +393,7 @@ describe('featuresService', () => { it('deletes items for expired themes', async () => { const existingItem = new SNComponent({ uuid: '456', - content_type: ContentType.Theme, + content_type: ContentType.TYPES.Theme, content: { package_info: { identifier: FeatureIdentifier.MidnightTheme, @@ -498,7 +497,7 @@ describe('featuresService', () => { it('remote native features should be swapped with compiled version', async () => { const remoteFeature = { identifier: FeatureIdentifier.PlusEditor, - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, expires_at: tomorrow_server, } as FeatureDescription @@ -528,7 +527,7 @@ describe('featuresService', () => { it('mapRemoteNativeFeatureToItem should throw if called with client controlled feature', async () => { const clientFeature = { identifier: FeatureIdentifier.DarkTheme, - content_type: ContentType.Theme, + content_type: ContentType.TYPES.Theme, clientControlled: true, } as FeatureDescription @@ -573,13 +572,13 @@ describe('featuresService', () => { features = [ { identifier: FeatureIdentifier.MidnightTheme, - content_type: ContentType.Theme, + content_type: ContentType.TYPES.Theme, expires_at: tomorrow_server, role_name: RoleName.NAMES.PlusUser, }, { identifier: FeatureIdentifier.PlusEditor, - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, expires_at: expiredDate, role_name: RoleName.NAMES.ProUser, }, @@ -617,14 +616,14 @@ describe('featuresService', () => { const themeFeature = { identifier: 'third-party-theme' as FeatureIdentifier, - content_type: ContentType.Theme, + content_type: ContentType.TYPES.Theme, expires_at: tomorrow_server, role_name: RoleName.NAMES.CoreUser, } const editorFeature = { identifier: 'third-party-editor' as FeatureIdentifier, - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, expires_at: expiredDate, role_name: RoleName.NAMES.PlusUser, } @@ -636,7 +635,7 @@ describe('featuresService', () => { itemManager.getDisplayableComponents = jest.fn().mockReturnValue([ new SNComponent({ uuid: '123', - content_type: ContentType.Theme, + content_type: ContentType.TYPES.Theme, content: { valid_until: themeFeature.expires_at, package_info: { @@ -646,7 +645,7 @@ describe('featuresService', () => { } as never), new SNComponent({ uuid: '456', - content_type: ContentType.Component, + content_type: ContentType.TYPES.Component, content: { valid_until: new Date(editorFeature.expires_at), package_info: { @@ -774,7 +773,7 @@ describe('featuresService', () => { const extensionKey = '129b029707e3470c94a8477a437f9394' const extensionRepoItem = new SNFeatureRepo({ uuid: '456', - content_type: ContentType.ExtensionRepo, + content_type: ContentType.TYPES.ExtensionRepo, content: { url: `https://extensions.standardnotes.org/${extensionKey}`, }, diff --git a/packages/snjs/lib/Services/Features/FeaturesService.ts b/packages/snjs/lib/Services/Features/FeaturesService.ts index aee6833bd..c5ee89de3 100644 --- a/packages/snjs/lib/Services/Features/FeaturesService.ts +++ b/packages/snjs/lib/Services/Features/FeaturesService.ts @@ -8,8 +8,7 @@ import { isString, } from '@standardnotes/utils' import { ClientDisplayableError, isErrorResponse } from '@standardnotes/responses' -import { ContentType } from '@standardnotes/common' -import { RoleName } from '@standardnotes/domain-core' +import { ContentType, RoleName } from '@standardnotes/domain-core' import { FillItemContent, PayloadEmitSource } from '@standardnotes/models' import { ItemManager } from '../Items/ItemManager' import { LEGACY_PROD_EXT_ORIGIN, PROD_OFFLINE_FEATURES_URL } from '../../Hosts' @@ -96,7 +95,7 @@ export class SNFeaturesService }) this.removefeatureReposObserver = this.itemManager.addObserver( - ContentType.ExtensionRepo, + ContentType.TYPES.ExtensionRepo, async ({ changed, inserted, source }) => { const sources = [ PayloadEmitSource.InitialObserverRegistrationPush, @@ -119,7 +118,7 @@ export class SNFeaturesService this.removeSignInObserver = this.userService.addEventObserver((eventName: AccountEvent) => { if (eventName === AccountEvent.SignedInOrRegistered) { - const featureRepos = this.itemManager.getItems(ContentType.ExtensionRepo) as Models.SNFeatureRepo[] + const featureRepos = this.itemManager.getItems(ContentType.TYPES.ExtensionRepo) as Models.SNFeatureRepo[] if (!this.apiService.isThirdPartyHostUsed()) { void this.migrateFeatureRepoToUserSetting(featureRepos) @@ -179,7 +178,10 @@ export class SNFeaturesService private async mapClientControlledFeaturesToItems() { const clientFeatures = FeaturesImports.GetFeatures().filter((feature) => feature.clientControlled) - const currentItems = this.itemManager.getItems([ContentType.Component, ContentType.Theme]) + const currentItems = this.itemManager.getItems([ + ContentType.TYPES.Component, + ContentType.TYPES.Theme, + ]) for (const feature of clientFeatures) { if (!feature.content_type) { @@ -226,7 +228,7 @@ export class SNFeaturesService void this.storageService.setValue(StorageKey.ExperimentalFeatures, this.enabledExperimentalFeatures) const component = this.itemManager - .getItems([ContentType.Component, ContentType.Theme]) + .getItems([ContentType.TYPES.Component, ContentType.TYPES.Theme]) .find((component) => component.identifier === identifier) if (!component) { return @@ -273,7 +275,7 @@ export class SNFeaturesService } const offlineRepo = (await this.mutator.createItem( - ContentType.ExtensionRepo, + ContentType.TYPES.ExtensionRepo, FillItemContent({ offlineFeaturesUrl: result.featuresUrl, offlineKey: result.extensionKey, @@ -289,7 +291,7 @@ export class SNFeaturesService } private getOfflineRepo(): Models.SNFeatureRepo | undefined { - const repos = this.itemManager.getItems(ContentType.ExtensionRepo) as Models.SNFeatureRepo[] + const repos = this.itemManager.getItems(ContentType.TYPES.ExtensionRepo) as Models.SNFeatureRepo[] return repos.filter((repo) => repo.migratedToOfflineEntitlements)[0] } @@ -638,7 +640,10 @@ export class SNFeaturesService } private async mapRemoteNativeFeaturesToItems(features: FeaturesImports.FeatureDescription[]): Promise { - const currentItems = this.itemManager.getItems([ContentType.Component, ContentType.Theme]) + const currentItems = this.itemManager.getItems([ + ContentType.TYPES.Component, + ContentType.TYPES.Theme, + ]) const itemsToDelete: Models.SNComponent[] = [] let hasChanges = false @@ -715,7 +720,7 @@ export class SNFeaturesService } else { resultingItem = existingItem } - } else if (!expired || feature.content_type === ContentType.Component) { + } else if (!expired || feature.content_type === ContentType.TYPES.Component) { resultingItem = (await this.mutator.createItem( feature.content_type, this.componentContentForNativeFeatureDescription(feature), @@ -725,7 +730,7 @@ export class SNFeaturesService } if (expired && resultingItem) { - if (feature.content_type !== ContentType.Component) { + if (feature.content_type !== ContentType.TYPES.Component) { itemsToDelete.push(resultingItem) hasChanges = true } @@ -786,10 +791,10 @@ export class SNFeaturesService } const isValidContentType = [ - ContentType.Component, - ContentType.Theme, - ContentType.ActionsExtension, - ContentType.ExtensionRepo, + ContentType.TYPES.Component, + ContentType.TYPES.Theme, + ContentType.TYPES.ActionsExtension, + ContentType.TYPES.ExtensionRepo, ].includes(rawFeature.content_type) if (!isValidContentType) { diff --git a/packages/snjs/lib/Services/History/HistoryManager.ts b/packages/snjs/lib/Services/History/HistoryManager.ts index 0ef205282..f46356665 100644 --- a/packages/snjs/lib/Services/History/HistoryManager.ts +++ b/packages/snjs/lib/Services/History/HistoryManager.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { removeFromArray } from '@standardnotes/utils' import { ItemManager } from '@Lib/Services/Items/ItemManager' import { DiskStorageService } from '@Lib/Services/Storage/DiskStorageService' @@ -11,6 +10,7 @@ import { HistoryServiceInterface, InternalEventBusInterface, } from '@standardnotes/services' +import { ContentType } from '@standardnotes/domain-core' /** The amount of revisions per item above which should call for an optimization. */ const DefaultItemRevisionsThreshold = 20 @@ -53,7 +53,7 @@ export class SNHistoryManager extends AbstractService implements HistoryServiceI protected override internalEventBus: InternalEventBusInterface, ) { super(internalEventBus) - this.removeChangeObserver = this.itemManager.addObserver(ContentType.Note, ({ changed, inserted }) => { + this.removeChangeObserver = this.itemManager.addObserver(ContentType.TYPES.Note, ({ changed, inserted }) => { this.recordNewHistoryForItems(changed.concat(inserted) as SNNote[]) }) } diff --git a/packages/snjs/lib/Services/Items/ItemManager.spec.ts b/packages/snjs/lib/Services/Items/ItemManager.spec.ts index bdc07e3ed..4d15943a5 100644 --- a/packages/snjs/lib/Services/Items/ItemManager.spec.ts +++ b/packages/snjs/lib/Services/Items/ItemManager.spec.ts @@ -1,4 +1,4 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { AlertService, InternalEventBusInterface, ItemRelationshipDirection } from '@standardnotes/services' import { ItemManager } from './ItemManager' import { PayloadManager } from '../Payloads/PayloadManager' @@ -65,7 +65,7 @@ describe('itemManager', () => { return new Models.SNTag( new Models.DecryptedPayload({ uuid: String(Math.random()), - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, content: Models.FillItemContent({ title: title, }), @@ -78,7 +78,7 @@ describe('itemManager', () => { return new Models.FileItem( new Models.DecryptedPayload({ uuid: String(Math.random()), - content_type: ContentType.File, + content_type: ContentType.TYPES.File, content: Models.FillItemContent({ name: name, }), @@ -91,7 +91,7 @@ describe('itemManager', () => { it('deleted payloads should map to removed items', async () => { const payload = new DeletedPayload({ uuid: String(Math.random()), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: undefined, deleted: true, dirty: true, @@ -110,7 +110,7 @@ describe('itemManager', () => { it('decrypted items who become encrypted should be removed from ui', async () => { const decrypted = new DecryptedPayload({ uuid: String(Math.random()), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: FillItemContent({ title: 'foo', }), @@ -372,7 +372,7 @@ describe('itemManager', () => { it('create template item', async () => { setupRandomUuid() - const item = await itemManager.createTemplateItem(ContentType.Note, { + const item = await itemManager.createTemplateItem(ContentType.TYPES.Note, { title: 'hello', references: [], }) @@ -386,7 +386,7 @@ describe('itemManager', () => { it('isTemplateItem return the correct value', async () => { setupRandomUuid() - const item = await itemManager.createTemplateItem(ContentType.Note, { + const item = await itemManager.createTemplateItem(ContentType.TYPES.Note, { title: 'hello', references: [], }) @@ -511,9 +511,9 @@ describe('itemManager', () => { expect(view2).toBeTruthy() expect(view3).toBeTruthy() - expect(view1.content_type).toEqual(ContentType.SmartView) - expect(view2.content_type).toEqual(ContentType.SmartView) - expect(view3.content_type).toEqual(ContentType.SmartView) + expect(view1.content_type).toEqual(ContentType.TYPES.SmartView) + expect(view2.content_type).toEqual(ContentType.TYPES.SmartView) + expect(view3.content_type).toEqual(ContentType.TYPES.SmartView) }) it('lets me use a smart view', async () => { @@ -550,9 +550,9 @@ describe('itemManager', () => { expect(tag2).toBeTruthy() expect(tag3).toBeTruthy() - expect(tag1.content_type).toEqual(ContentType.SmartView) - expect(tag2.content_type).toEqual(ContentType.SmartView) - expect(tag3.content_type).toEqual(ContentType.SmartView) + expect(tag1.content_type).toEqual(ContentType.TYPES.SmartView) + expect(tag2.content_type).toEqual(ContentType.TYPES.SmartView) + expect(tag3.content_type).toEqual(ContentType.TYPES.SmartView) }) it('will create smart view or tags from the generic method', async () => { @@ -561,8 +561,8 @@ describe('itemManager', () => { const someTag = await mutator.createTagOrSmartView('some-tag') const someView = await mutator.createTagOrSmartView(VIEW_LONG) - expect(someTag.content_type).toEqual(ContentType.Tag) - expect(someView.content_type).toEqual(ContentType.SmartView) + expect(someTag.content_type).toEqual(ContentType.TYPES.Tag) + expect(someView.content_type).toEqual(ContentType.TYPES.SmartView) }) }) diff --git a/packages/snjs/lib/Services/Items/ItemManager.ts b/packages/snjs/lib/Services/Items/ItemManager.ts index f7b36109d..3eb238cd7 100644 --- a/packages/snjs/lib/Services/Items/ItemManager.ts +++ b/packages/snjs/lib/Services/Items/ItemManager.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { assert, naturalSort, removeFromArray, UuidGenerator, Uuids } from '@standardnotes/utils' import { SNItemsKey } from '@standardnotes/encryption' import { PayloadManager } from '../Payloads/PayloadManager' @@ -8,9 +7,10 @@ import * as Models from '@standardnotes/models' import * as Services from '@standardnotes/services' import { PayloadManagerChangeData } from '../Payloads' import { ItemRelationshipDirection } from '@standardnotes/services' +import { ContentType } from '@standardnotes/domain-core' type ItemsChangeObserver = { - contentType: ContentType[] + contentType: string[] callback: Services.ItemManagerChangeObserverCallback } @@ -48,7 +48,7 @@ export class ItemManager extends Services.AbstractService implements Services.It this.payloadManager = payloadManager this.systemSmartViews = this.rebuildSystemSmartViews({}) this.createCollection() - this.unsubChangeObserver = this.payloadManager.addObserver(ContentType.Any, this.setPayloads.bind(this)) + this.unsubChangeObserver = this.payloadManager.addObserver(ContentType.TYPES.Any, this.setPayloads.bind(this)) } private rebuildSystemSmartViews(criteria: Models.NotesAndFilesDisplayOptions): Models.SmartView[] { @@ -65,34 +65,34 @@ export class ItemManager extends Services.AbstractService implements Services.It this.navigationDisplayController = new Models.ItemDisplayController( this.collection, - [ContentType.Note, ContentType.File], + [ContentType.TYPES.Note, ContentType.TYPES.File], { sortBy: 'created_at', sortDirection: 'dsc', hiddenContentTypes: [], }, ) - this.tagDisplayController = new Models.ItemDisplayController(this.collection, [ContentType.Tag], { + this.tagDisplayController = new Models.ItemDisplayController(this.collection, [ContentType.TYPES.Tag], { sortBy: 'title', sortDirection: 'asc', }) - this.itemsKeyDisplayController = new Models.ItemDisplayController(this.collection, [ContentType.ItemsKey], { + this.itemsKeyDisplayController = new Models.ItemDisplayController(this.collection, [ContentType.TYPES.ItemsKey], { sortBy: 'created_at', sortDirection: 'asc', }) - this.componentDisplayController = new Models.ItemDisplayController(this.collection, [ContentType.Component], { + this.componentDisplayController = new Models.ItemDisplayController(this.collection, [ContentType.TYPES.Component], { sortBy: 'created_at', sortDirection: 'asc', }) - this.themeDisplayController = new Models.ItemDisplayController(this.collection, [ContentType.Theme], { + this.themeDisplayController = new Models.ItemDisplayController(this.collection, [ContentType.TYPES.Theme], { sortBy: 'title', sortDirection: 'asc', }) - this.smartViewDisplayController = new Models.ItemDisplayController(this.collection, [ContentType.SmartView], { + this.smartViewDisplayController = new Models.ItemDisplayController(this.collection, [ContentType.TYPES.SmartView], { sortBy: 'title', sortDirection: 'asc', }) - this.fileDisplayController = new Models.ItemDisplayController(this.collection, [ContentType.File], { + this.fileDisplayController = new Models.ItemDisplayController(this.collection, [ContentType.TYPES.File], { sortBy: 'title', sortDirection: 'asc', }) @@ -177,7 +177,7 @@ export class ItemManager extends Services.AbstractService implements Services.It ...{ tags: mostRecentVersionOfTags, views: mostRecentVersionOfViews, - hiddenContentTypes: [ContentType.Tag], + hiddenContentTypes: [ContentType.TYPES.Tag], }, } @@ -324,7 +324,7 @@ export class ItemManager extends Services.AbstractService implements Services.It } public addObserver( - contentType: ContentType | ContentType[], + contentType: string | string[], callback: Services.ItemManagerChangeObserverCallback, ): () => void { if (!Array.isArray(contentType)) { @@ -349,7 +349,7 @@ export class ItemManager extends Services.AbstractService implements Services.It */ public itemsReferencingItem( itemToLookupUuidFor: { uuid: UuidString }, - contentType?: ContentType, + contentType?: string, ): I[] { const uuids = this.collection.uuidsThatReferenceUuid(itemToLookupUuidFor.uuid) let referencing = this.findItems(uuids) @@ -366,7 +366,7 @@ export class ItemManager extends Services.AbstractService implements Services.It */ public referencesForItem( itemToLookupUuidFor: Models.DecryptedItemInterface, - contentType?: ContentType, + contentType?: string, ): I[] { const item = this.findSureItem(itemToLookupUuidFor.uuid) const uuids = item.references.map((ref) => ref.uuid) @@ -386,7 +386,7 @@ export class ItemManager extends Services.AbstractService implements Services.It return Models.CreateItemFromPayload(payload) } - const affectedContentTypes = new Set() + const affectedContentTypes = new Set() const changedItems = changed.map((p) => { affectedContentTypes.add(p.content_type) @@ -490,9 +490,9 @@ export class ItemManager extends Services.AbstractService implements Services.It source: Models.PayloadEmitSource, sourceKey?: string, ) { - const filter = (items: I[], types: ContentType[]) => { + const filter = (items: I[], types: string[]) => { return items.filter((item) => { - return types.includes(ContentType.Any) || types.includes(item.content_type) + return types.includes(ContentType.TYPES.Any) || types.includes(item.content_type) }) } @@ -536,7 +536,7 @@ export class ItemManager extends Services.AbstractService implements Services.It public createTemplateItem< C extends Models.ItemContent = Models.ItemContent, I extends Models.DecryptedItemInterface = Models.DecryptedItemInterface, - >(contentType: ContentType, content?: C, override?: Partial>): I { + >(contentType: string, content?: C, override?: Partial>): I { const payload = new Models.DecryptedPayload({ uuid: UuidGenerator.GenerateUuid(), content_type: contentType, @@ -556,23 +556,23 @@ export class ItemManager extends Services.AbstractService implements Services.It return !this.findItem(item.uuid) } - public getItems(contentType: ContentType | ContentType[]): T[] { + public getItems(contentType: string | string[]): T[] { return this.collection.allDecrypted(contentType) } - getAnyItems(contentType: ContentType | ContentType[]): Models.ItemInterface[] { + getAnyItems(contentType: string | string[]): Models.ItemInterface[] { return this.collection.all(contentType) } public itemsMatchingPredicate( - contentType: ContentType, + contentType: string, predicate: Models.PredicateInterface, ): T[] { return this.itemsMatchingPredicates(contentType, [predicate]) } public itemsMatchingPredicates( - contentType: ContentType, + contentType: string, predicates: Models.PredicateInterface[], ): T[] { const subItems = this.getItems(contentType) @@ -687,7 +687,7 @@ export class ItemManager extends Services.AbstractService implements Services.It return [] } - const tags = this.collection.elementsReferencingElement(tag, ContentType.Tag) as Models.SNTag[] + const tags = this.collection.elementsReferencingElement(tag, ContentType.TYPES.Tag) as Models.SNTag[] return tags.filter((tag) => tag.parentId === itemToLookupUuidFor.uuid) } @@ -736,7 +736,7 @@ export class ItemManager extends Services.AbstractService implements Services.It public getSortedTagsForItem(item: Models.DecryptedItemInterface): Models.SNTag[] { return naturalSort( this.itemsReferencingItem(item).filter((ref) => { - return ref?.content_type === ContentType.Tag + return ref?.content_type === ContentType.TYPES.Tag }) as Models.SNTag[], 'title', ) @@ -753,7 +753,7 @@ export class ItemManager extends Services.AbstractService implements Services.It return Models.notesAndFilesMatchingOptions( criteria, - this.collection.allDecrypted(ContentType.Note), + this.collection.allDecrypted(ContentType.TYPES.Note), this.collection, ) as Models.SNNote[] } @@ -790,7 +790,7 @@ export class ItemManager extends Services.AbstractService implements Services.It * The number of notes currently managed */ public get noteCount(): number { - return this.collection.all(ContentType.Note).length + return this.collection.all(ContentType.TYPES.Note).length } /** diff --git a/packages/snjs/lib/Services/KeyRecovery/KeyRecoveryOperation.ts b/packages/snjs/lib/Services/KeyRecovery/KeyRecoveryOperation.ts index d1da868fa..f3f2874f4 100644 --- a/packages/snjs/lib/Services/KeyRecovery/KeyRecoveryOperation.ts +++ b/packages/snjs/lib/Services/KeyRecovery/KeyRecoveryOperation.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { ItemsKeyInterface } from '@standardnotes/models' import { dateSorted } from '@standardnotes/utils' import { SNRootKeyParams, EncryptionProviderInterface } from '@standardnotes/encryption' @@ -6,6 +5,7 @@ import { DecryptionQueueItem, KeyRecoveryOperationResult } from './Types' import { serverKeyParamsAreSafe } from './Utils' import { ChallengeServiceInterface, DecryptItemsKeyByPromptingUser } from '@standardnotes/services' import { ItemManager } from '../Items' +import { ContentType } from '@standardnotes/domain-core' export class KeyRecoveryOperation { constructor( @@ -29,7 +29,7 @@ export class KeyRecoveryOperation { if (queueItemKeyParamsAreBetterOrEqualToClients) { const latestDecryptedItemsKey = dateSorted( - this.itemManager.getItems(ContentType.ItemsKey), + this.itemManager.getItems(ContentType.TYPES.ItemsKey), 'created_at', false, )[0] diff --git a/packages/snjs/lib/Services/KeyRecovery/KeyRecoveryService.ts b/packages/snjs/lib/Services/KeyRecovery/KeyRecoveryService.ts index 8b44a4886..3e3a979eb 100644 --- a/packages/snjs/lib/Services/KeyRecovery/KeyRecoveryService.ts +++ b/packages/snjs/lib/Services/KeyRecovery/KeyRecoveryService.ts @@ -16,7 +16,6 @@ import { DiskStorageService } from '../Storage/DiskStorageService' import { PayloadManager } from '../Payloads/PayloadManager' import { ChallengeService } from '../Challenge' import { SNApiService } from '@Lib/Services/Api/ApiService' -import { ContentType } from '@standardnotes/common' import { ItemManager } from '../Items/ItemManager' import { removeFromArray, Uuids } from '@standardnotes/utils' import { ClientDisplayableError, isErrorResponse } from '@standardnotes/responses' @@ -43,6 +42,7 @@ import { KeyRecoveryOperationResult, } from './Types' import { serverKeyParamsAreSafe } from './Utils' +import { ContentType } from '@standardnotes/domain-core' /** * The key recovery service listens to items key changes to detect any that cannot be decrypted. @@ -99,7 +99,7 @@ export class SNKeyRecoveryService extends AbstractService { if (source === PayloadEmitSource.LocalChanged) { return @@ -181,7 +181,7 @@ export class SNKeyRecoveryService extends AbstractService i.content_type === ContentType.ItemsKey) + .filter((i) => i.content_type === ContentType.TYPES.ItemsKey) .map((i) => i.payload) void this.handleIgnoredItemsKeys(invalidKeys, false) diff --git a/packages/snjs/lib/Services/Listed/ListedService.ts b/packages/snjs/lib/Services/Listed/ListedService.ts index a7988a2ed..7f7a1391a 100644 --- a/packages/snjs/lib/Services/Listed/ListedService.ts +++ b/packages/snjs/lib/Services/Listed/ListedService.ts @@ -1,7 +1,6 @@ import { SyncClientInterface } from './../Sync/SyncClientInterface' import { isString, lastElement, sleep } from '@standardnotes/utils' import { UuidString } from '@Lib/Types/UuidString' -import { ContentType } from '@standardnotes/common' import { ItemManager } from '@Lib/Services/Items/ItemManager' import { DeprecatedHttpService } from '../Api/DeprecatedHttpService' import { SettingName } from '@standardnotes/settings' @@ -12,6 +11,7 @@ import { isErrorResponse, ListedAccount, ListedAccountInfo, ListedAccountInfoRes import { NoteMutator, SNActionsExtension, SNNote } from '@standardnotes/models' import { AbstractService, InternalEventBusInterface, MutatorClientInterface } from '@standardnotes/services' import { SNProtectionService } from '../Protection' +import { ContentType } from '@standardnotes/domain-core' export class ListedService extends AbstractService implements ListedClientInterface { constructor( @@ -124,7 +124,7 @@ export class ListedService extends AbstractService implements ListedClientInterf private getLegacyListedAccounts(): ListedAccount[] { const extensions = this.itemManager - .getItems(ContentType.ActionsExtension) + .getItems(ContentType.TYPES.ActionsExtension) .filter((extension) => extension.isListedExtension) const accounts: ListedAccount[] = [] diff --git a/packages/snjs/lib/Services/Mutator/MutatorService.spec.ts b/packages/snjs/lib/Services/Mutator/MutatorService.spec.ts index f0804c8da..5304922c9 100644 --- a/packages/snjs/lib/Services/Mutator/MutatorService.spec.ts +++ b/packages/snjs/lib/Services/Mutator/MutatorService.spec.ts @@ -8,7 +8,7 @@ import { FileItem, SNTag, } from '@standardnotes/models' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { AlertService, InternalEventBusInterface } from '@standardnotes/services' import { MutatorService, PayloadManager, ItemManager } from '../' import { UuidGenerator } from '@standardnotes/utils' @@ -42,7 +42,7 @@ describe('mutator service', () => { const note = new SNNote( new DecryptedPayload({ uuid: String(Math.random()), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: FillItemContent({ title: title, }), diff --git a/packages/snjs/lib/Services/Mutator/MutatorService.ts b/packages/snjs/lib/Services/Mutator/MutatorService.ts index 1a74f1530..1652f682e 100644 --- a/packages/snjs/lib/Services/Mutator/MutatorService.ts +++ b/packages/snjs/lib/Services/Mutator/MutatorService.ts @@ -6,7 +6,7 @@ import { AlertService, } from '@standardnotes/services' import { ItemsKeyMutator, SNItemsKey } from '@standardnotes/encryption' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { ItemManager } from '../Items' import { PayloadManager } from '../Payloads/PayloadManager' import { TagsToFoldersMigrationApplicator } from '@Lib/Migrations/Applicators/TagsToFolders' @@ -329,7 +329,7 @@ export class MutatorService extends AbstractService implements MutatorClientInte } public async createItem( - contentType: ContentType, + contentType: string, content: C, needsSync = false, vault?: VaultListingInterface, @@ -451,7 +451,7 @@ export class MutatorService extends AbstractService implements MutatorClientInte createInVault?: VaultListingInterface }): Promise { const newTag = await this.createItem( - ContentType.Tag, + ContentType.TYPES.Tag, FillItemContent({ title: dto.title }), true, dto.createInVault, @@ -477,7 +477,7 @@ export class MutatorService extends AbstractService implements MutatorClientInte vault?: VaultListingInterface }): Promise { return this.createItem( - ContentType.SmartView, + ContentType.TYPES.SmartView, FillItemContent({ title: dto.title, predicate: dto.predicate.toJson(), diff --git a/packages/snjs/lib/Services/Payloads/PayloadManager.spec.ts b/packages/snjs/lib/Services/Payloads/PayloadManager.spec.ts index 1da81e662..f425c8436 100644 --- a/packages/snjs/lib/Services/Payloads/PayloadManager.spec.ts +++ b/packages/snjs/lib/Services/Payloads/PayloadManager.spec.ts @@ -7,7 +7,7 @@ import { } from '@standardnotes/models' import { PayloadManager } from './PayloadManager' import { InternalEventBusInterface } from '@standardnotes/services' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' describe('payload manager', () => { let payloadManager: PayloadManager @@ -23,7 +23,7 @@ describe('payload manager', () => { it('emitting a payload should emit as-is and not merge on top of existing payload', async () => { const decrypted = new DecryptedPayload({ uuid: '123', - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, content: FillItemContent({ itemsKey: 'secret', }), @@ -36,7 +36,7 @@ describe('payload manager', () => { const nondirty = new DecryptedPayload({ uuid: '123', - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, ...PayloadTimestampDefaults(), updated_at_timestamp: 2, content: FillItemContent({ diff --git a/packages/snjs/lib/Services/Payloads/PayloadManager.ts b/packages/snjs/lib/Services/Payloads/PayloadManager.ts index bc83ebf1f..1f3b6e082 100644 --- a/packages/snjs/lib/Services/Payloads/PayloadManager.ts +++ b/packages/snjs/lib/Services/Payloads/PayloadManager.ts @@ -1,4 +1,4 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { PayloadsChangeObserver, QueueElement, PayloadsChangeObserverCallback, EmitQueue } from './Types' import { removeFromArray, Uuids } from '@standardnotes/utils' import { @@ -74,7 +74,7 @@ export class PayloadManager extends AbstractService implements PayloadManagerInt return this.collection.findAll([uuid])[0] } - public all(contentType: ContentType): FullyFormedPayloadInterface[] { + public all(contentType: string): FullyFormedPayloadInterface[] { return this.collection.all(contentType) } @@ -224,7 +224,7 @@ export class PayloadManager extends AbstractService implements PayloadManagerInt * @param priority - The lower the priority, the earlier the function is called * wrt to other observers */ - public addObserver(types: ContentType | ContentType[], callback: PayloadsChangeObserverCallback, priority = 1) { + public addObserver(types: string | string[], callback: PayloadsChangeObserverCallback, priority = 1) { if (!Array.isArray(types)) { types = [types] } @@ -261,9 +261,9 @@ export class PayloadManager extends AbstractService implements PayloadManagerInt const filter =

( payloads: P[], - types: ContentType[], + types: string[], ) => { - return types.includes(ContentType.Any) + return types.includes(ContentType.TYPES.Any) ? payloads.slice() : payloads.slice().filter((payload) => { return types.includes(payload.content_type) @@ -304,7 +304,7 @@ export class PayloadManager extends AbstractService implements PayloadManagerInt this.collection.discard(payload) } - public erroredPayloadsForContentType(contentType: ContentType): EncryptedPayloadInterface[] { + public erroredPayloadsForContentType(contentType: string): EncryptedPayloadInterface[] { return this.collection.invalidElements().filter((p) => p.content_type === contentType) } diff --git a/packages/snjs/lib/Services/Payloads/Types.ts b/packages/snjs/lib/Services/Payloads/Types.ts index 27903e138..0162970a2 100644 --- a/packages/snjs/lib/Services/Payloads/Types.ts +++ b/packages/snjs/lib/Services/Payloads/Types.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { DecryptedPayloadInterface, DeletedPayloadInterface, @@ -34,7 +33,7 @@ export type PayloadManagerChangeData = { export type PayloadsChangeObserverCallback = (data: PayloadManagerChangeData) => void export type PayloadsChangeObserver = { - types: ContentType[] + types: string[] callback: PayloadsChangeObserverCallback priority: number } diff --git a/packages/snjs/lib/Services/Preferences/PreferencesService.ts b/packages/snjs/lib/Services/Preferences/PreferencesService.ts index 5ec0a3c4a..cac7e01fc 100644 --- a/packages/snjs/lib/Services/Preferences/PreferencesService.ts +++ b/packages/snjs/lib/Services/Preferences/PreferencesService.ts @@ -1,5 +1,4 @@ import { SNUserPrefs, PrefKey, PrefValue, UserPrefsMutator, ItemContent, FillItemContent } from '@standardnotes/models' -import { ContentType } from '@standardnotes/common' import { ItemManager } from '../Items/ItemManager' import { SNSingletonManager } from '../Singleton/SingletonManager' import { SNSyncService } from '../Sync/SyncService' @@ -12,6 +11,7 @@ import { PreferencesServiceEvent, MutatorClientInterface, } from '@standardnotes/services' +import { ContentType } from '@standardnotes/domain-core' export class SNPreferencesService extends AbstractService @@ -32,7 +32,7 @@ export class SNPreferencesService ) { super(internalEventBus) - this.removeItemObserver = itemManager.addObserver(ContentType.UserPrefs, () => { + this.removeItemObserver = itemManager.addObserver(ContentType.TYPES.UserPrefs, () => { this.shouldReload = true }) @@ -58,7 +58,7 @@ export class SNPreferencesService if (stage === ApplicationStage.LoadedDatabase_12) { /** Try to read preferences singleton from storage */ this.preferences = this.singletonManager.findSingleton( - ContentType.UserPrefs, + ContentType.TYPES.UserPrefs, SNUserPrefs.singletonPredicate, ) @@ -99,7 +99,7 @@ export class SNPreferencesService const previousRef = this.preferences this.preferences = await this.singletonManager.findOrCreateContentTypeSingleton( - ContentType.UserPrefs, + ContentType.TYPES.UserPrefs, FillItemContent({}), ) diff --git a/packages/snjs/lib/Services/Protection/ProtectionService.spec.ts b/packages/snjs/lib/Services/Protection/ProtectionService.spec.ts index ed99a272e..5f9357672 100644 --- a/packages/snjs/lib/Services/Protection/ProtectionService.spec.ts +++ b/packages/snjs/lib/Services/Protection/ProtectionService.spec.ts @@ -16,7 +16,7 @@ import { FillItemContent, PayloadTimestampDefaults, } from '@standardnotes/models' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' const setupRandomUuid = () => { UuidGenerator.SetGenerator(() => String(Math.random())) @@ -38,7 +38,7 @@ describe('protectionService', () => { return new FileItem( new DecryptedPayload({ uuid: String(Math.random()), - content_type: ContentType.File, + content_type: ContentType.TYPES.File, content: FillItemContent({ name: name, protected: isProtected, diff --git a/packages/snjs/lib/Services/Protection/ProtectionService.ts b/packages/snjs/lib/Services/Protection/ProtectionService.ts index f2c29f4cc..d2e863ea3 100644 --- a/packages/snjs/lib/Services/Protection/ProtectionService.ts +++ b/packages/snjs/lib/Services/Protection/ProtectionService.ts @@ -26,7 +26,7 @@ import { ProtectionsClientInterface, MutatorClientInterface, } from '@standardnotes/services' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' export enum ProtectionEvent { UnprotectedSessionBegan = 'UnprotectedSessionBegan', @@ -182,7 +182,7 @@ export class SNProtectionService extends AbstractService implem } return this.authorizeAction( - item.content_type === ContentType.Note + item.content_type === ContentType.TYPES.Note ? ChallengeReason.AccessProtectedNote : ChallengeReason.AccessProtectedFile, { fallBackToAccountPassword: true, requireAccountPassword: false, forcePrompt: false }, diff --git a/packages/snjs/lib/Services/Singleton/SingletonManager.ts b/packages/snjs/lib/Services/Singleton/SingletonManager.ts index ff26b1c57..b4fac7ca3 100644 --- a/packages/snjs/lib/Services/Singleton/SingletonManager.ts +++ b/packages/snjs/lib/Services/Singleton/SingletonManager.ts @@ -1,5 +1,4 @@ import { PayloadManager } from './../Payloads/PayloadManager' -import { ContentType } from '@standardnotes/common' import { ItemManager } from '@Lib/Services/Items/ItemManager' import { DecryptedItemInterface, @@ -21,6 +20,7 @@ import { SingletonManagerInterface, SyncEvent, } from '@standardnotes/services' +import { ContentType } from '@standardnotes/domain-core' /** * The singleton manager allow consumers to ensure that only 1 item exists of a certain @@ -83,7 +83,7 @@ export class SNSingletonManager extends AbstractService implements SingletonMana * all items keys have been downloaded. */ private addObservers() { - this.removeItemObserver = this.itemManager.addObserver(ContentType.Any, ({ inserted, unerrored }) => { + this.removeItemObserver = this.itemManager.addObserver(ContentType.TYPES.Any, ({ inserted, unerrored }) => { if (unerrored.length > 0) { this.resolveQueue = this.resolveQueue.concat(unerrored) } @@ -104,7 +104,7 @@ export class SNSingletonManager extends AbstractService implements SingletonMana } private validItemsMatchingPredicate( - contentType: ContentType, + contentType: string, predicate: PredicateInterface, ) { return this.itemManager.itemsMatchingPredicate(contentType, predicate) @@ -161,7 +161,7 @@ export class SNSingletonManager extends AbstractService implements SingletonMana } public findSingleton( - contentType: ContentType, + contentType: string, predicate: PredicateInterface, ): T | undefined { const matchingItems = this.validItemsMatchingPredicate(contentType, predicate) @@ -174,7 +174,7 @@ export class SNSingletonManager extends AbstractService implements SingletonMana public async findOrCreateContentTypeSingleton< C extends ItemContent = ItemContent, T extends DecryptedItemInterface = DecryptedItemInterface, - >(contentType: ContentType, createContent: ItemContent): Promise { + >(contentType: string, createContent: ItemContent): Promise { const existingItems = this.itemManager.getItems(contentType) if (existingItems.length > 0) { @@ -241,7 +241,7 @@ export class SNSingletonManager extends AbstractService implements SingletonMana public async findOrCreateSingleton< C extends ItemContent = ItemContent, T extends DecryptedItemInterface = DecryptedItemInterface, - >(predicate: Predicate, contentType: ContentType, createContent: ItemContent): Promise { + >(predicate: Predicate, contentType: string, createContent: ItemContent): Promise { const existingItems = this.itemManager.itemsMatchingPredicate(contentType, predicate) if (existingItems.length > 0) { return existingItems[0] diff --git a/packages/snjs/lib/Services/Storage/DiskStorageService.ts b/packages/snjs/lib/Services/Storage/DiskStorageService.ts index 02e413dd3..bd0c53ef7 100644 --- a/packages/snjs/lib/Services/Storage/DiskStorageService.ts +++ b/packages/snjs/lib/Services/Storage/DiskStorageService.ts @@ -1,4 +1,3 @@ -import { ContentType } from '@standardnotes/common' import { Copy, extendArray, UuidGenerator, Uuids } from '@standardnotes/utils' import { SNLog } from '../../Log' import { isErrorDecryptingParameters, SNRootKey } from '@standardnotes/encryption' @@ -20,6 +19,7 @@ import { LocalStorageEncryptedContextualPayload, FullyFormedTransferPayload, } from '@standardnotes/models' +import { ContentType } from '@standardnotes/domain-core' /** * The storage service is responsible for persistence of both simple key-values, and payload @@ -140,7 +140,7 @@ export class DiskStorageService extends Services.AbstractService implements Serv const payload = new EncryptedPayload({ ...wrappedValue, ...PayloadTimestampDefaults(), - content_type: ContentType.EncryptedStorage, + content_type: ContentType.TYPES.EncryptedStorage, }) const split: Encryption.KeyedDecryptionSplit = key @@ -232,7 +232,7 @@ export class DiskStorageService extends Services.AbstractService implements Serv const payload = new DecryptedPayload({ uuid: UuidGenerator.GenerateUuid(), content: valuesToWrap as unknown as ItemContent, - content_type: ContentType.EncryptedStorage, + content_type: ContentType.TYPES.EncryptedStorage, ...PayloadTimestampDefaults(), }) diff --git a/packages/snjs/lib/Services/Sync/SyncService.ts b/packages/snjs/lib/Services/Sync/SyncService.ts index f2360175a..2381fd2ac 100644 --- a/packages/snjs/lib/Services/Sync/SyncService.ts +++ b/packages/snjs/lib/Services/Sync/SyncService.ts @@ -1,7 +1,6 @@ import { ConflictParams, ConflictType } from '@standardnotes/responses' import { log, LoggingDomain } from './../../Logging' import { AccountSyncOperation } from '@Lib/Services/Sync/Account/Operation' -import { ContentType } from '@standardnotes/common' import { Uuids, extendArray, @@ -96,20 +95,21 @@ import { import { CreatePayloadFromRawServerItem } from './Account/Utilities' import { ApplicationSyncOptions } from '@Lib/Application/Options/OptionalOptions' import { DecryptedServerConflictMap, TrustedServerConflictMap } from './Account/ServerConflictMap' +import { ContentType } from '@standardnotes/domain-core' const DEFAULT_MAJOR_CHANGE_THRESHOLD = 15 const INVALID_SESSION_RESPONSE_STATUS = 401 /** Content types appearing first are always mapped first */ const ContentTypeLocalLoadPriorty = [ - ContentType.ItemsKey, - ContentType.KeySystemRootKey, - ContentType.KeySystemItemsKey, - ContentType.VaultListing, - ContentType.TrustedContact, - ContentType.UserPrefs, - ContentType.Component, - ContentType.Theme, + ContentType.TYPES.ItemsKey, + ContentType.TYPES.KeySystemRootKey, + ContentType.TYPES.KeySystemItemsKey, + ContentType.TYPES.VaultListing, + ContentType.TYPES.TrustedContact, + ContentType.TYPES.UserPrefs, + ContentType.TYPES.Component, + ContentType.TYPES.Theme, ] /** @@ -1141,7 +1141,7 @@ export class SNSyncService const results = await this.encryptionService.decryptSplit(rootKeySplit) results.forEach((result) => { - if (isDecryptedPayload(result) && result.content_type === ContentType.ItemsKey) { + if (isDecryptedPayload(result) && result.content_type === ContentType.TYPES.ItemsKey) { map[result.uuid] = result } }) @@ -1173,7 +1173,7 @@ export class SNSyncService results.forEach((result) => { if ( isDecryptedPayload(result) && - result.content_type === ContentType.KeySystemItemsKey + result.content_type === ContentType.TYPES.KeySystemItemsKey ) { map[result.uuid] = result } diff --git a/packages/snjs/lib/Spec/SpecUtils.ts b/packages/snjs/lib/Spec/SpecUtils.ts index cdb5083a1..8e7bd6d24 100644 --- a/packages/snjs/lib/Spec/SpecUtils.ts +++ b/packages/snjs/lib/Spec/SpecUtils.ts @@ -1,4 +1,4 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import * as Models from '@standardnotes/models' export const createNote = (payload?: Partial): Models.SNNote => { @@ -6,7 +6,7 @@ export const createNote = (payload?: Partial): Models.SNNote new Models.DecryptedPayload( { uuid: String(Math.random()), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: Models.FillItemContent({ ...payload }), ...Models.PayloadTimestampDefaults(), }, @@ -19,7 +19,7 @@ export const createNoteWithTitle = (title: string) => { return new Models.SNNote( new Models.DecryptedPayload({ uuid: String(Math.random()), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: Models.FillItemContent({ title: title, }), diff --git a/packages/snjs/mocha/004.test.js b/packages/snjs/mocha/004.test.js index 453dc836e..390a5fc81 100644 --- a/packages/snjs/mocha/004.test.js +++ b/packages/snjs/mocha/004.test.js @@ -71,7 +71,7 @@ describe('004 protocol operations', function () { it('properly encrypts and decrypts', async function () { const payload = new DecryptedPayload({ uuid: '123', - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, content: FillItemContent({ title: 'foo', text: 'bar', @@ -90,7 +90,7 @@ describe('004 protocol operations', function () { it('fails to decrypt non-matching aad', async function () { const payload = new DecryptedPayload({ uuid: '123', - content_type: ContentType.ItemsKey, + content_type: ContentType.TYPES.ItemsKey, content: FillItemContent({ title: 'foo', text: 'bar', diff --git a/packages/snjs/mocha/actions.test.js b/packages/snjs/mocha/actions.test.js index e8c7487a1..11d8348ec 100644 --- a/packages/snjs/mocha/actions.test.js +++ b/packages/snjs/mocha/actions.test.js @@ -110,7 +110,7 @@ describe('actions service', () => { const payload = new DecryptedPayload({ uuid: Utils.generateUuid(), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: { title: 'Testing', }, @@ -170,7 +170,7 @@ describe('actions service', () => { }) // Extension item - const extensionItem = await this.application.mutator.createItem(ContentType.ActionsExtension, this.actionsExtension) + const extensionItem = await this.application.mutator.createItem(ContentType.TYPES.ActionsExtension, this.actionsExtension) this.extensionItemUuid = extensionItem.uuid }) @@ -182,7 +182,7 @@ describe('actions service', () => { }) it('should get extension items', async function () { - await this.application.mutator.createItem(ContentType.Note, { + await this.application.mutator.createItem(ContentType.TYPES.Note, { title: 'A simple note', text: 'Standard Notes rocks! lml.', }) @@ -191,7 +191,7 @@ describe('actions service', () => { }) it('should get extensions in context of item', async function () { - const noteItem = await this.application.mutator.createItem(ContentType.Note, { + const noteItem = await this.application.mutator.createItem(ContentType.TYPES.Note, { title: 'Another note', text: 'Whiskey In The Jar', }) @@ -202,7 +202,7 @@ describe('actions service', () => { }) it('should get actions based on item context', async function () { - const tagItem = await this.application.mutator.createItem(ContentType.Tag, { + const tagItem = await this.application.mutator.createItem(ContentType.TYPES.Tag, { title: 'Music', }) @@ -214,7 +214,7 @@ describe('actions service', () => { }) it('should load extension in context of item', async function () { - const noteItem = await this.application.mutator.createItem(ContentType.Note, { + const noteItem = await this.application.mutator.createItem(ContentType.TYPES.Note, { title: 'Yet another note', text: 'And all things will end ♫', }) @@ -246,7 +246,7 @@ describe('actions service', () => { const sandbox = sinon.createSandbox() before(async function () { - this.noteItem = await this.application.mutator.createItem(ContentType.Note, { + this.noteItem = await this.application.mutator.createItem(ContentType.TYPES.Note, { title: 'Hey', text: 'Welcome To Paradise', }) @@ -328,7 +328,7 @@ describe('actions service', () => { const sandbox = sinon.createSandbox() before(async function () { - this.noteItem = await this.application.mutator.createItem(ContentType.Note, { + this.noteItem = await this.application.mutator.createItem(ContentType.TYPES.Note, { title: 'Excuse Me', text: 'Time To Be King 8)', }) diff --git a/packages/snjs/mocha/backups.test.js b/packages/snjs/mocha/backups.test.js index e63531da6..45e804bb1 100644 --- a/packages/snjs/mocha/backups.test.js +++ b/packages/snjs/mocha/backups.test.js @@ -106,7 +106,7 @@ describe('backups', function () { it('backup file item should have correct fields', async function () { await Factory.createSyncedNote(this.application) let backupData = await this.application.createDecryptedBackupFile() - let rawItem = backupData.items.find((i) => i.content_type === ContentType.Note) + let rawItem = backupData.items.find((i) => i.content_type === ContentType.TYPES.Note) expect(rawItem.fields).to.not.be.ok expect(rawItem.source).to.not.be.ok @@ -125,7 +125,7 @@ describe('backups', function () { }) backupData = await this.application.createEncryptedBackupFileForAutomatedDesktopBackups() - rawItem = backupData.items.find((i) => i.content_type === ContentType.Note) + rawItem = backupData.items.find((i) => i.content_type === ContentType.TYPES.Note) expect(rawItem.fields).to.not.be.ok expect(rawItem.source).to.not.be.ok @@ -195,21 +195,21 @@ describe('backups', function () { it('decrypted backup file should not have itemsKeys', async function () { const backup = await this.application.createDecryptedBackupFile() - expect(backup.items.some((item) => item.content_type === ContentType.ItemsKey)).to.be.false + expect(backup.items.some((item) => item.content_type === ContentType.TYPES.ItemsKey)).to.be.false }) it('encrypted backup file should have itemsKeys', async function () { await this.application.addPasscode('passcode') const backup = await this.application.createEncryptedBackupFileForAutomatedDesktopBackups() - expect(backup.items.some((item) => item.content_type === ContentType.ItemsKey)).to.be.true + expect(backup.items.some((item) => item.content_type === ContentType.TYPES.ItemsKey)).to.be.true }) it('backup file with no account and no passcode should be decrypted', async function () { const note = await Factory.createSyncedNote(this.application) const backup = await this.application.createDecryptedBackupFile() expect(backup).to.not.haveOwnProperty('keyParams') - expect(backup.items.some((item) => item.content_type === ContentType.ItemsKey)).to.be.false - expect(backup.items.find((item) => item.content_type === ContentType.Note).uuid).to.equal(note.uuid) + expect(backup.items.some((item) => item.content_type === ContentType.TYPES.ItemsKey)).to.be.false + expect(backup.items.find((item) => item.content_type === ContentType.TYPES.Note).uuid).to.equal(note.uuid) let error try { await this.application.createEncryptedBackupFileForAutomatedDesktopBackups() diff --git a/packages/snjs/mocha/collections.test.js b/packages/snjs/mocha/collections.test.js index 01eb229cd..72f057cdb 100644 --- a/packages/snjs/mocha/collections.test.js +++ b/packages/snjs/mocha/collections.test.js @@ -41,11 +41,11 @@ describe('payload collections', () => { it('references by content type', async () => { const [notePayload1, tagPayload1] = createRelatedNoteTagPairPayload() const collection = ImmutablePayloadCollection.WithPayloads([notePayload1, tagPayload1]) - const referencingTags = collection.elementsReferencingElement(notePayload1, ContentType.Tag) + const referencingTags = collection.elementsReferencingElement(notePayload1, ContentType.TYPES.Tag) expect(referencingTags.length).to.equal(1) expect(referencingTags[0].uuid).to.equal(tagPayload1.uuid) - const referencingNotes = collection.elementsReferencingElement(notePayload1, ContentType.Note) + const referencingNotes = collection.elementsReferencingElement(notePayload1, ContentType.TYPES.Note) expect(referencingNotes.length).to.equal(0) }) @@ -78,7 +78,7 @@ describe('payload collections', () => { collection.set([payload]) collection.set([payload, copy]) - const sorted = collection.all(ContentType.Note) + const sorted = collection.all(ContentType.TYPES.Note) expect(sorted.length).to.equal(1) }) }) diff --git a/packages/snjs/mocha/features.test.js b/packages/snjs/mocha/features.test.js index 5442950a1..4b242eba5 100644 --- a/packages/snjs/mocha/features.test.js +++ b/packages/snjs/mocha/features.test.js @@ -84,7 +84,7 @@ describe('features', () => { expect(application.apiService.getUserFeatures.callCount).to.equal(1) expect(application.mutator.createItem.callCount).to.equal(2) - const themeItems = application.items.getItems(ContentType.Theme) + const themeItems = application.items.getItems(ContentType.TYPES.Theme) const systemThemeCount = 1 expect(themeItems).to.have.lengthOf(1 + systemThemeCount) expect(themeItems[1].content).to.containSubset( @@ -97,7 +97,7 @@ describe('features', () => { ), ) - const editorItems = application.items.getItems(ContentType.Component) + const editorItems = application.items.getItems(ContentType.TYPES.Component) expect(editorItems).to.have.lengthOf(1) expect(editorItems[0].content).to.containSubset( JSON.parse( @@ -118,7 +118,7 @@ describe('features', () => { await application.featuresService.setOnlineRoles([]) // Create pre-existing item for theme without all the info await application.mutator.createItem( - ContentType.Theme, + ContentType.TYPES.Theme, FillItemContent({ package_info: { identifier: FeatureIdentifier.MidnightTheme, @@ -130,7 +130,7 @@ describe('features', () => { // Timeout since we don't await for features update await new Promise((resolve) => setTimeout(resolve, 1000)) expect(application.mutator.changeComponent.callCount).to.equal(1) - const themeItems = application.items.getItems(ContentType.Theme) + const themeItems = application.items.getItems(ContentType.TYPES.Theme) expect(themeItems).to.have.lengthOf(1) expect(themeItems[0].content).to.containSubset( JSON.parse( @@ -161,7 +161,7 @@ describe('features', () => { }) const themeItem = application.items - .getItems(ContentType.Theme) + .getItems(ContentType.TYPES.Theme) .find((theme) => theme.identifier === midnightThemeFeature.identifier) // Wipe roles from initial sync @@ -177,7 +177,7 @@ describe('features', () => { ) const noTheme = application.items - .getItems(ContentType.Theme) + .getItems(ContentType.TYPES.Theme) .find((theme) => theme.identifier === midnightThemeFeature.identifier) expect(noTheme).to.not.be.ok }) @@ -203,7 +203,7 @@ describe('features', () => { }) await application.mutator.createItem( - ContentType.ExtensionRepo, + ContentType.TYPES.ExtensionRepo, FillItemContent({ url: `https://extensions.standardnotes.org/${extensionKey}`, }), @@ -225,7 +225,7 @@ describe('features', () => { .callsFake(() => {}) const extensionKey = UuidGenerator.GenerateUuid().split('-').join('') await application.mutator.createItem( - ContentType.ExtensionRepo, + ContentType.TYPES.ExtensionRepo, FillItemContent({ url: `https://extensions.standardnotes.org/${extensionKey}`, }), @@ -256,7 +256,7 @@ describe('features', () => { }) const extensionKey = UuidGenerator.GenerateUuid().split('-').join('') await application.mutator.createItem( - ContentType.ExtensionRepo, + ContentType.TYPES.ExtensionRepo, FillItemContent({ url: `https://extensions.standardnotes.org/${extensionKey}`, }), @@ -282,7 +282,7 @@ describe('features', () => { expect(await application.settings.getDoesSensitiveSettingExist(SettingName.ExtensionKey)).to.equal(false) const extensionKey = UuidGenerator.GenerateUuid().split('-').join('') const promise = new Promise((resolve) => { - application.streamItems(ContentType.ExtensionRepo, ({ changed }) => { + application.streamItems(ContentType.TYPES.ExtensionRepo, ({ changed }) => { for (const item of changed) { if (item.content.migratedToUserSetting) { resolve() @@ -291,7 +291,7 @@ describe('features', () => { }) }) await application.mutator.createItem( - ContentType.ExtensionRepo, + ContentType.TYPES.ExtensionRepo, FillItemContent({ url: `https://extensions.standardnotes.org/${extensionKey}`, }), @@ -305,7 +305,7 @@ describe('features', () => { application = await Factory.signOutApplicationAndReturnNew(application) const extensionKey = UuidGenerator.GenerateUuid().split('-').join('') await application.mutator.createItem( - ContentType.ExtensionRepo, + ContentType.TYPES.ExtensionRepo, FillItemContent({ url: `https://extensions.standardnotes.org/${extensionKey}`, }), diff --git a/packages/snjs/mocha/history.test.js b/packages/snjs/mocha/history.test.js index 8d189de2c..99767d61e 100644 --- a/packages/snjs/mocha/history.test.js +++ b/packages/snjs/mocha/history.test.js @@ -97,7 +97,7 @@ describe('history manager', () => { it('creating new item and making 1 change should create 0 revisions', async function () { const context = await Factory.createAppContext() await context.launch() - const item = await context.application.items.createTemplateItem(ContentType.Note, { + const item = await context.application.items.createTemplateItem(ContentType.TYPES.Note, { references: [], }) await context.application.mutator.insertItem(item) diff --git a/packages/snjs/mocha/item.test.js b/packages/snjs/mocha/item.test.js index 9d7c4882d..bbbd58640 100644 --- a/packages/snjs/mocha/item.test.js +++ b/packages/snjs/mocha/item.test.js @@ -9,7 +9,7 @@ describe('item', () => { this.createBarePayload = () => { return new DecryptedPayload({ uuid: '123', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: { title: 'hello', }, @@ -30,7 +30,7 @@ describe('item', () => { return new SNTag( new DecryptedPayload({ uuid: Factory.generateUuidish(), - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, content: { title: 'thoughts', references: references, diff --git a/packages/snjs/mocha/item_manager.test.js b/packages/snjs/mocha/item_manager.test.js index c4c6ed8dd..20660a54a 100644 --- a/packages/snjs/mocha/item_manager.test.js +++ b/packages/snjs/mocha/item_manager.test.js @@ -25,7 +25,7 @@ describe('item manager', function () { }) const createNote = async () => { - return application.mutator.createItem(ContentType.Note, { + return application.mutator.createItem(ContentType.TYPES.Note, { title: 'hello', text: 'world', }) @@ -38,7 +38,7 @@ describe('item manager', function () { content_type: note.content_type, } }) - return application.mutator.createItem(ContentType.Tag, { + return application.mutator.createItem(ContentType.TYPES.Tag, { title: 'thoughts', references: references, }) @@ -110,7 +110,7 @@ describe('item manager', function () { it('observer', async function () { const observed = [] - application.items.addObserver(ContentType.Any, ({ changed, inserted, removed, source, sourceKey }) => { + application.items.addObserver(ContentType.TYPES.Any, ({ changed, inserted, removed, source, sourceKey }) => { observed.push({ changed, inserted, removed, source, sourceKey }) }) const note = await createNote() @@ -184,7 +184,7 @@ describe('item manager', function () { it('remove all items from memory', async function () { const observed = [] - application.items.addObserver(ContentType.Any, ({ changed, inserted, removed, ignored }) => { + application.items.addObserver(ContentType.TYPES.Any, ({ changed, inserted, removed, ignored }) => { observed.push({ changed, inserted, removed, ignored }) }) await createNote() @@ -197,7 +197,7 @@ describe('item manager', function () { it('remove item locally', async function () { const observed = [] - application.items.addObserver(ContentType.Any, ({ changed, inserted, removed, ignored }) => { + application.items.addObserver(ContentType.TYPES.Any, ({ changed, inserted, removed, ignored }) => { observed.push({ changed, inserted, removed, ignored }) }) const note = await createNote() @@ -220,7 +220,7 @@ describe('item manager', function () { const changedTitle = 'changed title' let didEmit = false let latestVersion - application.items.addObserver(ContentType.Note, ({ changed, inserted }) => { + application.items.addObserver(ContentType.TYPES.Note, ({ changed, inserted }) => { const all = changed.concat(inserted) if (!didEmit) { didEmit = true diff --git a/packages/snjs/mocha/key_recovery_service.test.js b/packages/snjs/mocha/key_recovery_service.test.js index 2d11ff77a..1694af8c2 100644 --- a/packages/snjs/mocha/key_recovery_service.test.js +++ b/packages/snjs/mocha/key_recovery_service.test.js @@ -272,7 +272,7 @@ describe('key recovery service', function () { const result = await contextB.application.changePassword(contextA.password, newPassword) expect(result.error).to.not.be.ok - expect(contextB.application.items.getAnyItems(ContentType.ItemsKey).length).to.equal(2) + expect(contextB.application.items.getAnyItems(ContentType.TYPES.ItemsKey).length).to.equal(2) const newItemsKey = contextB.application.items .getDisplayableItemsKeys() @@ -288,7 +288,7 @@ describe('key recovery service', function () { await recoveryPromise /** Same previously errored key should now no longer be errored, */ - expect(contextA.application.items.getAnyItems(ContentType.ItemsKey).length).to.equal(2) + expect(contextA.application.items.getAnyItems(ContentType.TYPES.ItemsKey).length).to.equal(2) for (const key of contextA.application.itemManager.getDisplayableItemsKeys()) { expect(key.errorDecrypting).to.not.be.ok } @@ -321,7 +321,7 @@ describe('key recovery service', function () { password: contextA.password, }) - expect(appA.items.getItems(ContentType.ItemsKey).length).to.equal(1) + expect(appA.items.getItems(ContentType.TYPES.ItemsKey).length).to.equal(1) /** Create simultaneous appB signed into same account */ const appB = await Factory.createApplicationWithFakeCrypto('another-namespace') diff --git a/packages/snjs/mocha/keys.test.js b/packages/snjs/mocha/keys.test.js index 510756c1d..add04b2e5 100644 --- a/packages/snjs/mocha/keys.test.js +++ b/packages/snjs/mocha/keys.test.js @@ -33,10 +33,10 @@ describe('keys', function () { }) it('validates content types requiring root encryption', function () { - expect(ContentTypeUsesRootKeyEncryption(ContentType.ItemsKey)).to.equal(true) - expect(ContentTypeUsesRootKeyEncryption(ContentType.EncryptedStorage)).to.equal(true) - expect(ContentTypeUsesRootKeyEncryption(ContentType.Item)).to.equal(false) - expect(ContentTypeUsesRootKeyEncryption(ContentType.Note)).to.equal(false) + expect(ContentTypeUsesRootKeyEncryption(ContentType.TYPES.ItemsKey)).to.equal(true) + expect(ContentTypeUsesRootKeyEncryption(ContentType.TYPES.EncryptedStorage)).to.equal(true) + expect(ContentTypeUsesRootKeyEncryption(ContentType.TYPES.Item)).to.equal(false) + expect(ContentTypeUsesRootKeyEncryption(ContentType.TYPES.Note)).to.equal(false) }) it('generating export params with no account or passcode should produce encrypted payload', async function () { @@ -126,7 +126,7 @@ describe('keys', function () { await this.application.sync.sync() const rawPayloads = await this.application.diskStorageService.getAllRawPayloads() - const rawNotePayload = rawPayloads.find((r) => r.content_type === ContentType.Note) + const rawNotePayload = rawPayloads.find((r) => r.content_type === ContentType.TYPES.Note) expect(typeof rawNotePayload.content).to.equal('string') }) @@ -143,7 +143,7 @@ describe('keys', function () { it('should use items key for encryption of note', async function () { const notePayload = Factory.createNotePayload() const keyToUse = await this.application.encryptionService.itemsEncryption.keyToUseForItemEncryption(notePayload) - expect(keyToUse.content_type).to.equal(ContentType.ItemsKey) + expect(keyToUse.content_type).to.equal(ContentType.TYPES.ItemsKey) }) it('encrypting an item should associate an items key to it', async function () { @@ -848,7 +848,7 @@ describe('keys', function () { password: this.password, }) await Factory.createSyncedNote(this.application) - const itemsKey = this.application.items.getItems(ContentType.ItemsKey)[0] + const itemsKey = this.application.items.getItems(ContentType.TYPES.ItemsKey)[0] /** Create another client and sign into account */ await Factory.loginToApplication({ @@ -862,7 +862,7 @@ describe('keys', function () { expect(defaultKeys.length).to.equal(1) const rawPayloads = await otherClient.diskStorageService.getAllRawPayloads() - const notePayload = rawPayloads.find((p) => p.content_type === ContentType.Note) + const notePayload = rawPayloads.find((p) => p.content_type === ContentType.TYPES.Note) expect(notePayload.items_key_id).to.equal(itemsKey.uuid) }) diff --git a/packages/snjs/mocha/lib/AppContext.js b/packages/snjs/mocha/lib/AppContext.js index 0b9573022..4d19d3f64 100644 --- a/packages/snjs/mocha/lib/AppContext.js +++ b/packages/snjs/mocha/lib/AppContext.js @@ -415,7 +415,7 @@ export class AppContext { if (!didCompleteRelevantSync) { if (data?.savedPayloads) { const matching = data.savedPayloads.find((p) => { - return p.content_type === ContentType.UserPrefs + return p.content_type === ContentType.TYPES.UserPrefs }) if (matching) { didCompleteRelevantSync = true @@ -510,7 +510,7 @@ export class AppContext { } spyOnChangedItems(callback) { - this.application.items.addObserver(ContentType.Any, ({ changed, unerrored }) => { + this.application.items.addObserver(ContentType.TYPES.Any, ({ changed, unerrored }) => { callback([...changed, ...unerrored]) }) } diff --git a/packages/snjs/mocha/lib/Items.js b/packages/snjs/mocha/lib/Items.js index d10a693bc..03cfebe95 100644 --- a/packages/snjs/mocha/lib/Items.js +++ b/packages/snjs/mocha/lib/Items.js @@ -20,7 +20,7 @@ export function createItemParams(contentType) { export function createNoteParams({ title, text, dirty = true } = {}) { const params = { uuid: Utils.generateUuid(), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, dirty: dirty, dirtyIndex: dirty ? getIncrementedDirtyIndex() : undefined, content: FillItemContent({ @@ -34,7 +34,7 @@ export function createNoteParams({ title, text, dirty = true } = {}) { export function createTagParams({ title, dirty = true, uuid = undefined } = {}) { const params = { uuid: uuid || Utils.generateUuid(), - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, dirty: dirty, dirtyIndex: dirty ? getIncrementedDirtyIndex() : undefined, content: FillItemContent({ diff --git a/packages/snjs/mocha/migrations/migration.test.js b/packages/snjs/mocha/migrations/migration.test.js index 6c4fcdb5d..70ab122ec 100644 --- a/packages/snjs/mocha/migrations/migration.test.js +++ b/packages/snjs/mocha/migrations/migration.test.js @@ -99,7 +99,7 @@ describe('migrations', () => { const noDistractionItem = CreateDecryptedItemFromPayload( new DecryptedPayload({ uuid: '123', - content_type: ContentType.Theme, + content_type: ContentType.TYPES.Theme, content: FillItemContent({ package_info: { identifier: 'org.standardnotes.theme-no-distraction', @@ -111,14 +111,14 @@ describe('migrations', () => { await application.sync.sync() const systemThemeCount = 1 - expect(application.items.getItems(ContentType.Theme).length).to.equal(1 + systemThemeCount) + expect(application.items.getItems(ContentType.TYPES.Theme).length).to.equal(1 + systemThemeCount) /** Run migration */ const migration = new Migration2_42_0(application.migrationService.services) await migration.handleStage(ApplicationStage.FullSyncCompleted_13) await application.sync.sync() - expect(application.items.getItems(ContentType.Theme).length).to.equal(systemThemeCount) + expect(application.items.getItems(ContentType.TYPES.Theme).length).to.equal(systemThemeCount) await Factory.safeDeinit(application) }) diff --git a/packages/snjs/mocha/model_tests/appmodels.test.js b/packages/snjs/mocha/model_tests/appmodels.test.js index a5da2e936..014cd2bc1 100644 --- a/packages/snjs/mocha/model_tests/appmodels.test.js +++ b/packages/snjs/mocha/model_tests/appmodels.test.js @@ -361,11 +361,11 @@ describe('app models', () => { it('maintains editor reference when duplicating note', async function () { const editor = await this.application.mutator.createItem( - ContentType.Component, + ContentType.TYPES.Component, { area: ComponentArea.Editor, package_info: { identifier: 'foo-editor' } }, true, ) - const note = await Factory.insertItemWithOverride(this.application, ContentType.Note, { + const note = await Factory.insertItemWithOverride(this.application, ContentType.TYPES.Note, { editorIdentifier: 'foo-editor', }) diff --git a/packages/snjs/mocha/model_tests/importing.test.js b/packages/snjs/mocha/model_tests/importing.test.js index 6d374e50f..08ca86cfb 100644 --- a/packages/snjs/mocha/model_tests/importing.test.js +++ b/packages/snjs/mocha/model_tests/importing.test.js @@ -73,8 +73,8 @@ describe('importing', function () { await application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged) expectedItemCount += 2 - const note = application.itemManager.getItems([ContentType.Note])[0] - const tag = application.itemManager.getItems([ContentType.Tag])[0] + const note = application.itemManager.getItems([ContentType.TYPES.Note])[0] + const tag = application.itemManager.getItems([ContentType.TYPES.Tag])[0] expect(tag.content.references.length).to.equal(1) expect(tag.noteCount).to.equal(1) @@ -352,8 +352,8 @@ describe('importing', function () { const storedPayloads = await application.diskStorageService.getAllRawPayloads() expect(application.itemManager.items.length).to.equal(storedPayloads.length) - const notes = storedPayloads.filter((p) => p.content_type === ContentType.Note) - const itemsKeys = storedPayloads.filter((p) => p.content_type === ContentType.ItemsKey) + const notes = storedPayloads.filter((p) => p.content_type === ContentType.TYPES.Note) + const itemsKeys = storedPayloads.filter((p) => p.content_type === ContentType.TYPES.ItemsKey) expect(notes.length).to.equal(1) expect(itemsKeys.length).to.equal(1) }) @@ -449,7 +449,7 @@ describe('importing', function () { version: oldVersion, }) - const noteItem = await application.mutator.createItem(ContentType.Note, { + const noteItem = await application.mutator.createItem(ContentType.TYPES.Note, { title: 'Encrypted note', text: 'On protocol version 003.', }) @@ -530,7 +530,7 @@ describe('importing', function () { password: password, }) - const noteItem = await application.mutator.createItem(ContentType.Note, { + const noteItem = await application.mutator.createItem(ContentType.TYPES.Note, { title: 'Encrypted note', text: 'On protocol version 004.', }) @@ -560,7 +560,7 @@ describe('importing', function () { password: password, }) - const noteItem = await application.mutator.createItem(ContentType.Note, { + const noteItem = await application.mutator.createItem(ContentType.TYPES.Note, { title: 'This is a valid, encrypted note', text: 'On protocol version 004.', }) @@ -598,7 +598,7 @@ describe('importing', function () { version: oldVersion, }) - await application.mutator.createItem(ContentType.Note, { + await application.mutator.createItem(ContentType.TYPES.Note, { title: 'Encrypted note', text: 'On protocol version 003.', }) @@ -635,7 +635,7 @@ describe('importing', function () { password: password, }) - await application.mutator.createItem(ContentType.Note, { + await application.mutator.createItem(ContentType.TYPES.Note, { title: 'This is a valid, encrypted note', text: 'On protocol version 004.', }) @@ -666,7 +666,7 @@ describe('importing', function () { password: password, }) - await application.mutator.createItem(ContentType.Note, { + await application.mutator.createItem(ContentType.TYPES.Note, { title: 'Encrypted note', text: 'On protocol version 004.', }) @@ -691,13 +691,13 @@ describe('importing', function () { }) Factory.handlePasswordChallenges(application, password) - await application.mutator.createItem(ContentType.Note, { + await application.mutator.createItem(ContentType.TYPES.Note, { title: 'Encrypted note', text: 'On protocol version 004.', }) const backupData = await application.createEncryptedBackupFileForAutomatedDesktopBackups() - backupData.items = backupData.items.filter((payload) => payload.content_type !== ContentType.ItemsKey) + backupData.items = backupData.items.filter((payload) => payload.content_type !== ContentType.TYPES.ItemsKey) await Factory.safeDeinit(application) application = await Factory.createInitAppWithFakeCrypto() diff --git a/packages/snjs/mocha/model_tests/mapping.test.js b/packages/snjs/mocha/model_tests/mapping.test.js index 06ede1a7a..f42ad5f65 100644 --- a/packages/snjs/mocha/model_tests/mapping.test.js +++ b/packages/snjs/mocha/model_tests/mapping.test.js @@ -118,7 +118,7 @@ describe('model manager mapping', () => { await this.application.mutator.emitItemsFromPayloads([payload], PayloadEmitSource.LocalChanged) const item = this.application.itemManager.items[0] return new Promise((resolve) => { - this.application.itemManager.addObserver(ContentType.Any, ({ changed }) => { + this.application.itemManager.addObserver(ContentType.TYPES.Any, ({ changed }) => { expect(changed[0].uuid === item.uuid) resolve() }) diff --git a/packages/snjs/mocha/model_tests/notes_tags.test.js b/packages/snjs/mocha/model_tests/notes_tags.test.js index 5936e8992..eb06acd84 100644 --- a/packages/snjs/mocha/model_tests/notes_tags.test.js +++ b/packages/snjs/mocha/model_tests/notes_tags.test.js @@ -26,14 +26,14 @@ describe('notes and tags', () => { it('uses proper class for note', async function () { const payload = Factory.createNotePayload() await this.application.mutator.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged) - const note = this.application.itemManager.getItems([ContentType.Note])[0] + const note = this.application.itemManager.getItems([ContentType.TYPES.Note])[0] expect(note.constructor === SNNote).to.equal(true) }) it('properly constructs syncing params', async function () { const title = 'Foo' const text = 'Bar' - const note = await this.application.items.createTemplateItem(ContentType.Note, { + const note = await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title, text, }) @@ -41,7 +41,7 @@ describe('notes and tags', () => { expect(note.content.title).to.equal(title) expect(note.content.text).to.equal(text) - const tag = await this.application.items.createTemplateItem(ContentType.Tag, { + const tag = await this.application.items.createTemplateItem(ContentType.TYPES.Tag, { title, }) @@ -74,8 +74,8 @@ describe('notes and tags', () => { }) await this.application.mutator.emitItemsFromPayloads([mutatedNote, mutatedTag], PayloadEmitSource.LocalChanged) - const note = this.application.itemManager.getItems([ContentType.Note])[0] - const tag = this.application.itemManager.getItems([ContentType.Tag])[0] + const note = this.application.itemManager.getItems([ContentType.TYPES.Note])[0] + const tag = this.application.itemManager.getItems([ContentType.TYPES.Tag])[0] expect(note.content.references.length).to.equal(1) expect(this.application.itemManager.itemsReferencingItem(tag).length).to.equal(1) @@ -131,8 +131,8 @@ describe('notes and tags', () => { const tagPayload = pair[1] await this.application.mutator.emitItemsFromPayloads(pair, PayloadEmitSource.LocalChanged) - let note = this.application.itemManager.getItems([ContentType.Note])[0] - let tag = this.application.itemManager.getItems([ContentType.Tag])[0] + let note = this.application.itemManager.getItems([ContentType.TYPES.Note])[0] + let tag = this.application.itemManager.getItems([ContentType.TYPES.Tag])[0] expect(note.content.references.length).to.equal(0) expect(tag.content.references.length).to.equal(1) @@ -178,8 +178,8 @@ describe('notes and tags', () => { const tagPayload = pair[1] await this.application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged) - const note = this.application.itemManager.getItems([ContentType.Note])[0] - let tag = this.application.itemManager.getItems([ContentType.Tag])[0] + const note = this.application.itemManager.getItems([ContentType.TYPES.Note])[0] + let tag = this.application.itemManager.getItems([ContentType.TYPES.Tag])[0] expect(note.content.references.length).to.equal(0) expect(tag.content.references.length).to.equal(1) @@ -233,7 +233,7 @@ describe('notes and tags', () => { const notePayload = pair[0] const tagPayload = pair[1] await this.application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged) - const note = this.application.itemManager.getItems([ContentType.Note])[0] + const note = this.application.itemManager.getItems([ContentType.TYPES.Note])[0] const duplicateNote = await this.application.mutator.duplicateItem(note, true) expect(note.uuid).to.not.equal(duplicateNote.uuid) @@ -247,8 +247,8 @@ describe('notes and tags', () => { const notePayload = pair[0] const tagPayload = pair[1] await this.application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged) - const note = this.application.itemManager.getItems([ContentType.Note])[0] - let tag = this.application.itemManager.getItems([ContentType.Tag])[0] + const note = this.application.itemManager.getItems([ContentType.TYPES.Note])[0] + let tag = this.application.itemManager.getItems([ContentType.TYPES.Tag])[0] expect(tag.content.references.length).to.equal(1) expect(tag.noteCount).to.equal(1) @@ -264,7 +264,7 @@ describe('notes and tags', () => { it('modifying item content should not modify payload content', async function () { const notePayload = Factory.createNotePayload() await this.application.mutator.emitItemsFromPayloads([notePayload], PayloadEmitSource.LocalChanged) - let note = this.application.itemManager.getItems([ContentType.Note])[0] + let note = this.application.itemManager.getItems([ContentType.TYPES.Note])[0] note = await this.application.changeAndSaveItem( note, (mutator) => { @@ -286,8 +286,8 @@ describe('notes and tags', () => { const tagPayload = pair[1] await this.application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged) - let note = this.application.itemManager.getItems([ContentType.Note])[0] - let tag = this.application.itemManager.getItems([ContentType.Tag])[0] + let note = this.application.itemManager.getItems([ContentType.TYPES.Note])[0] + let tag = this.application.itemManager.getItems([ContentType.TYPES.Tag])[0] await this.application.syncService.sync(syncOptions) await this.application.mutator.setItemToBeDeleted(tag) @@ -302,7 +302,7 @@ describe('notes and tags', () => { await Promise.all( ['Y', 'Z', 'A', 'B'].map(async (title) => { return this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { title }), + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title }), ) }), ) @@ -316,7 +316,7 @@ describe('notes and tags', () => { }) it('setting a note dirty should collapse its properties into content', async function () { - let note = await this.application.items.createTemplateItem(ContentType.Note, { + let note = await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'Foo', }) await this.application.mutator.insertItem(note) @@ -339,7 +339,7 @@ describe('notes and tags', () => { mutator.e2ePendingRefactor_addItemAsRelationship(taggedNote) }) await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'A', }), ) @@ -379,7 +379,7 @@ describe('notes and tags', () => { await Promise.all( ['Y', 'Z', 'A', 'B'].map(async (title) => { return this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title, }), ) @@ -413,17 +413,17 @@ describe('notes and tags', () => { describe('Smart views', function () { it('"title", "startsWith", "Foo"', async function () { const note = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'Foo 🎲', }), ) await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'Not Foo 🎲', }), ) const view = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.SmartView, { + await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, { title: 'Foo Notes', predicate: { keypath: 'title', @@ -447,7 +447,7 @@ describe('notes and tags', () => { it('"pinned", "=", true', async function () { const note = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'A', }), ) @@ -455,13 +455,13 @@ describe('notes and tags', () => { mutator.pinned = true }) await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'B', pinned: false, }), ) const view = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.SmartView, { + await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, { title: 'Pinned', predicate: { keypath: 'pinned', @@ -485,7 +485,7 @@ describe('notes and tags', () => { it('"pinned", "=", false', async function () { const pinnedNote = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'A', }), ) @@ -493,12 +493,12 @@ describe('notes and tags', () => { mutator.pinned = true }) const unpinnedNote = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'B', }), ) const view = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.SmartView, { + await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, { title: 'Not pinned', predicate: { keypath: 'pinned', @@ -522,19 +522,19 @@ describe('notes and tags', () => { it('"text.length", ">", 500', async function () { const longNote = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'A', text: Array(501).fill(0).join(''), }), ) await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'B', text: 'b', }), ) const view = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.SmartView, { + await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, { title: 'Long', predicate: { keypath: 'text.length', @@ -563,7 +563,7 @@ describe('notes and tags', () => { }) const recentNote = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'A', }), true, @@ -572,7 +572,7 @@ describe('notes and tags', () => { await this.application.sync.sync() const olderNote = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'B', text: 'b', }), @@ -584,13 +584,13 @@ describe('notes and tags', () => { /** Create an unsynced note which shouldn't get an updated_at */ await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'B', text: 'b', }), ) const view = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.SmartView, { + await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, { title: 'One day ago', predicate: { keypath: 'serverUpdatedAt', @@ -614,7 +614,7 @@ describe('notes and tags', () => { it('"tags.length", "=", 0', async function () { const untaggedNote = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'A', }), ) @@ -625,7 +625,7 @@ describe('notes and tags', () => { }) const view = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.SmartView, { + await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, { title: 'Untagged', predicate: { keypath: 'tags.length', @@ -653,13 +653,13 @@ describe('notes and tags', () => { mutator.e2ePendingRefactor_addItemAsRelationship(taggedNote) }) await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'A', }), ) const view = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.SmartView, { + await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, { title: 'B-tags', predicate: { keypath: 'tags', @@ -688,7 +688,7 @@ describe('notes and tags', () => { }) const pinnedNote = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'A', }), ) @@ -697,7 +697,7 @@ describe('notes and tags', () => { }) const lockedNote = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'A', }), ) @@ -706,7 +706,7 @@ describe('notes and tags', () => { }) const view = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.SmartView, { + await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, { title: 'Pinned & Locked', predicate: { operator: 'and', @@ -736,7 +736,7 @@ describe('notes and tags', () => { }) const pinnedNote = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'A', }), ) @@ -745,7 +745,7 @@ describe('notes and tags', () => { }) const pinnedAndProtectedNote = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'A', }), ) @@ -755,13 +755,13 @@ describe('notes and tags', () => { }) await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.Note, { + await this.application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'A', }), ) const view = await this.application.mutator.insertItem( - await this.application.items.createTemplateItem(ContentType.SmartView, { + await this.application.items.createTemplateItem(ContentType.TYPES.SmartView, { title: 'Protected or Pinned', predicate: { operator: 'or', diff --git a/packages/snjs/mocha/model_tests/performance.test.js b/packages/snjs/mocha/model_tests/performance.test.js index 8552eb346..8493aeee5 100644 --- a/packages/snjs/mocha/model_tests/performance.test.js +++ b/packages/snjs/mocha/model_tests/performance.test.js @@ -20,7 +20,7 @@ describe('mapping performance', () => { for (let i = 0; i < tagCount; i++) { var tag = { uuid: UuidGenerator.GenerateUuid(), - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, content: { title: `${Math.random()}`, references: [], @@ -31,7 +31,7 @@ describe('mapping performance', () => { for (let i = 0; i < noteCount; i++) { const note = { uuid: UuidGenerator.GenerateUuid(), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: { title: `${Math.random()}`, text: `${Math.random()}`, @@ -40,7 +40,7 @@ describe('mapping performance', () => { } const randomTag = Factory.randomArrayValue(tags) randomTag.content.references.push({ - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, uuid: note.uuid, }) notes.push(note) @@ -65,7 +65,7 @@ describe('mapping performance', () => { const expectedRunTime = 3 // seconds expect(seconds).to.be.at.most(expectedRunTime) - for (const note of application.itemManager.getItems(ContentType.Note)) { + for (const note of application.itemManager.getItems(ContentType.TYPES.Note)) { expect(application.itemManager.itemsReferencingItem(note).length).to.be.above(0) } await Factory.safeDeinit(application) @@ -84,7 +84,7 @@ describe('mapping performance', () => { const tag = { uuid: UuidGenerator.GenerateUuid(), - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, content: { title: `${Math.random()}`, references: [], @@ -94,7 +94,7 @@ describe('mapping performance', () => { for (let i = 0; i < noteCount; i++) { const note = { uuid: UuidGenerator.GenerateUuid(), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: { title: `${Math.random()}`, text: `${Math.random()}`, @@ -103,7 +103,7 @@ describe('mapping performance', () => { } tag.content.references.push({ - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, uuid: note.uuid, }) notes.push(note) @@ -131,8 +131,8 @@ describe('mapping performance', () => { const MAX_RUN_TIME = 15.0 // seconds expect(seconds).to.be.at.most(MAX_RUN_TIME) - application.itemManager.getItems(ContentType.Tag)[0] - for (const note of application.itemManager.getItems(ContentType.Note)) { + application.itemManager.getItems(ContentType.TYPES.Tag)[0] + for (const note of application.itemManager.getItems(ContentType.TYPES.Note)) { expect(application.itemManager.itemsReferencingItem(note).length).to.equal(1) } await Factory.safeDeinit(application) diff --git a/packages/snjs/mocha/mutator.test.js b/packages/snjs/mocha/mutator.test.js index 898283127..59bae15c4 100644 --- a/packages/snjs/mocha/mutator.test.js +++ b/packages/snjs/mocha/mutator.test.js @@ -9,7 +9,7 @@ describe('item mutator', () => { this.createBarePayload = () => { return new DecryptedPayload({ uuid: '123', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: { title: 'hello', }, @@ -30,7 +30,7 @@ describe('item mutator', () => { return new SNTag( new DecryptedPayload({ uuid: Factory.generateUuidish(), - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, content: { title: 'thoughts', references: references, diff --git a/packages/snjs/mocha/mutator_service.test.js b/packages/snjs/mocha/mutator_service.test.js index de993fd0e..be87f0bb5 100644 --- a/packages/snjs/mocha/mutator_service.test.js +++ b/packages/snjs/mocha/mutator_service.test.js @@ -28,7 +28,7 @@ describe('mutator service', function () { }) const createNote = async () => { - return mutator.createItem(ContentType.Note, { + return mutator.createItem(ContentType.TYPES.Note, { title: 'hello', text: 'world', }) @@ -41,7 +41,7 @@ describe('mutator service', function () { content_type: note.content_type, } }) - return mutator.createItem(ContentType.Tag, { + return mutator.createItem(ContentType.TYPES.Tag, { title: 'thoughts', references: references, }) @@ -127,7 +127,7 @@ describe('mutator service', function () { }) it('change non-existant item through uuid should fail', async function () { - const note = await application.items.createTemplateItem(ContentType.Note, { + const note = await application.items.createTemplateItem(ContentType.TYPES.Note, { title: 'hello', text: 'world', }) @@ -219,7 +219,7 @@ describe('mutator service', function () { }) it('duplicates item with additional content', async function () { - const note = await mutator.createItem(ContentType.Note, { + const note = await mutator.createItem(ContentType.TYPES.Note, { title: 'hello', text: 'world', }) diff --git a/packages/snjs/mocha/note_display_criteria.test.js b/packages/snjs/mocha/note_display_criteria.test.js index dfb384605..6b79f9489 100644 --- a/packages/snjs/mocha/note_display_criteria.test.js +++ b/packages/snjs/mocha/note_display_criteria.test.js @@ -9,7 +9,7 @@ describe('note display criteria', function () { this.mutator = new MutatorService(this.itemManager, this.payloadManager) this.createNote = async (title = 'hello', text = 'world') => { - return this.mutator.createItem(ContentType.Note, { + return this.mutator.createItem(ContentType.TYPES.Note, { title: title, text: text, }) @@ -22,7 +22,7 @@ describe('note display criteria', function () { content_type: note.content_type, } }) - return this.mutator.createItem(ContentType.Tag, { + return this.mutator.createItem(ContentType.TYPES.Tag, { title: title, references: references, }) @@ -41,7 +41,7 @@ describe('note display criteria', function () { expect( notesAndFilesMatchingOptions( criteria, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -57,7 +57,7 @@ describe('note display criteria', function () { expect( notesAndFilesMatchingOptions( criteria, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(2) @@ -73,7 +73,7 @@ describe('note display criteria', function () { expect( notesAndFilesMatchingOptions( criteria, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -89,7 +89,7 @@ describe('note display criteria', function () { expect( notesAndFilesMatchingOptions( criteria, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(2) @@ -105,7 +105,7 @@ describe('note display criteria', function () { expect( notesAndFilesMatchingOptions( criteria, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -123,7 +123,7 @@ describe('note display criteria', function () { expect( notesAndFilesMatchingOptions( criteria, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(2) @@ -139,7 +139,7 @@ describe('note display criteria', function () { expect( notesAndFilesMatchingOptions( criteria, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -157,7 +157,7 @@ describe('note display criteria', function () { expect( notesAndFilesMatchingOptions( criteria, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(2) @@ -174,7 +174,7 @@ describe('note display criteria', function () { expect( notesAndFilesMatchingOptions( criteria, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -191,7 +191,7 @@ describe('note display criteria', function () { expect( notesAndFilesMatchingOptions( criteria, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -208,7 +208,7 @@ describe('note display criteria', function () { expect( notesAndFilesMatchingOptions( matchingCriteria, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -219,7 +219,7 @@ describe('note display criteria', function () { expect( notesAndFilesMatchingOptions( nonmatchingCriteria, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -233,7 +233,7 @@ describe('note display criteria', function () { { views: [this.itemManager.allNotesSmartView], }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -243,7 +243,7 @@ describe('note display criteria', function () { { views: [this.itemManager.trashSmartView], }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -253,7 +253,7 @@ describe('note display criteria', function () { { views: [this.itemManager.archivedSmartView], }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -271,7 +271,7 @@ describe('note display criteria', function () { views: [this.itemManager.allNotesSmartView], includeTrashed: false, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -281,7 +281,7 @@ describe('note display criteria', function () { { views: [this.itemManager.trashSmartView], }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -291,7 +291,7 @@ describe('note display criteria', function () { { views: [this.itemManager.archivedSmartView], }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -309,7 +309,7 @@ describe('note display criteria', function () { views: [this.itemManager.allNotesSmartView], includeArchived: false, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -319,7 +319,7 @@ describe('note display criteria', function () { { views: [this.itemManager.trashSmartView], }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -329,7 +329,7 @@ describe('note display criteria', function () { { views: [this.itemManager.archivedSmartView], }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -347,7 +347,7 @@ describe('note display criteria', function () { { views: [this.itemManager.allNotesSmartView], }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -357,7 +357,7 @@ describe('note display criteria', function () { { views: [this.itemManager.trashSmartView], }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -367,7 +367,7 @@ describe('note display criteria', function () { { views: [this.itemManager.archivedSmartView], }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -384,7 +384,7 @@ describe('note display criteria', function () { views: [this.itemManager.allNotesSmartView], includeTrashed: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -395,7 +395,7 @@ describe('note display criteria', function () { views: [this.itemManager.trashSmartView], includeTrashed: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -414,7 +414,7 @@ describe('note display criteria', function () { views: [this.itemManager.allNotesSmartView], includeTrashed: false, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -425,7 +425,7 @@ describe('note display criteria', function () { views: [this.itemManager.allNotesSmartView], includeTrashed: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -436,7 +436,7 @@ describe('note display criteria', function () { views: [this.itemManager.trashSmartView], includeTrashed: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -447,7 +447,7 @@ describe('note display criteria', function () { views: [this.itemManager.archivedSmartView], includeTrashed: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -466,7 +466,7 @@ describe('note display criteria', function () { { views: [this.itemManager.allNotesSmartView], }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -476,7 +476,7 @@ describe('note display criteria', function () { { views: [this.itemManager.trashSmartView], }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -486,7 +486,7 @@ describe('note display criteria', function () { { views: [this.itemManager.archivedSmartView], }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -503,7 +503,7 @@ describe('note display criteria', function () { views: [this.itemManager.allNotesSmartView], includeArchived: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -514,7 +514,7 @@ describe('note display criteria', function () { views: [this.itemManager.trashSmartView], includeArchived: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -532,7 +532,7 @@ describe('note display criteria', function () { views: [this.itemManager.allNotesSmartView], includeArchived: false, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -543,7 +543,7 @@ describe('note display criteria', function () { views: [this.itemManager.allNotesSmartView], includeArchived: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -554,7 +554,7 @@ describe('note display criteria', function () { views: [this.itemManager.trashSmartView], includeArchived: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -565,7 +565,7 @@ describe('note display criteria', function () { views: [this.itemManager.archivedSmartView], includeArchived: false, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -584,7 +584,7 @@ describe('note display criteria', function () { views: [this.itemManager.allNotesSmartView], includeArchived: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -595,7 +595,7 @@ describe('note display criteria', function () { views: [this.itemManager.trashSmartView], includeArchived: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -606,7 +606,7 @@ describe('note display criteria', function () { views: [this.itemManager.archivedSmartView], includeArchived: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -626,7 +626,7 @@ describe('note display criteria', function () { this.itemManager.trashSmartView, ], }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -636,7 +636,7 @@ describe('note display criteria', function () { { views: [this.itemManager.trashSmartView], }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -654,7 +654,7 @@ describe('note display criteria', function () { views: [this.itemManager.allNotesSmartView], includeArchived: false, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -665,7 +665,7 @@ describe('note display criteria', function () { views: [this.itemManager.allNotesSmartView], includeArchived: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -676,7 +676,7 @@ describe('note display criteria', function () { views: [this.itemManager.trashSmartView], includeArchived: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -687,7 +687,7 @@ describe('note display criteria', function () { views: [this.itemManager.archivedSmartView], includeArchived: false, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -706,7 +706,7 @@ describe('note display criteria', function () { views: [this.itemManager.allNotesSmartView], includeArchived: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) @@ -717,7 +717,7 @@ describe('note display criteria', function () { views: [this.itemManager.trashSmartView], includeArchived: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(1) @@ -728,7 +728,7 @@ describe('note display criteria', function () { views: [this.itemManager.archivedSmartView], includeArchived: true, }, - this.itemManager.collection.all(ContentType.Note), + this.itemManager.collection.all(ContentType.TYPES.Note), this.itemManager.collection, ).length, ).to.equal(0) diff --git a/packages/snjs/mocha/payload.test.js b/packages/snjs/mocha/payload.test.js index ec03b2d71..4773e311b 100644 --- a/packages/snjs/mocha/payload.test.js +++ b/packages/snjs/mocha/payload.test.js @@ -9,7 +9,7 @@ describe('payload', () => { this.createBarePayload = () => { return new DecryptedPayload({ uuid: '123', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: { title: 'hello', }, @@ -19,7 +19,7 @@ describe('payload', () => { this.createEncryptedPayload = () => { return new EncryptedPayload({ uuid: '123', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: '004:foo:bar', }) } @@ -36,7 +36,7 @@ describe('payload', () => { it('not supplying source should default to constructor source', function () { const payload = new DecryptedPayload({ uuid: '123', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: { title: 'hello', }, @@ -74,7 +74,7 @@ describe('payload', () => { () => new EncryptedPayload({ uuid: '123', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: '000:somebase64string', }), 'Unrecognized protocol version 000', @@ -84,7 +84,7 @@ describe('payload', () => { it('payload format deleted', function () { const payload = new DeletedPayload({ uuid: '123', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, deleted: true, }) @@ -101,7 +101,7 @@ describe('payload', () => { const payload = this.createBarePayload() const merged = payload.copy({ uuid: '123', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, updated_at: new Date(), dirty: true, dirtyIndex: getIncrementedDirtyIndex(), @@ -116,7 +116,7 @@ describe('payload', () => { it('deleted and not dirty should be discardable', function () { const payload = new DeletedPayload({ uuid: '123', - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, deleted: true, dirty: false, }) diff --git a/packages/snjs/mocha/payload_manager.test.js b/packages/snjs/mocha/payload_manager.test.js index 5ce0e7573..f1943c8ce 100644 --- a/packages/snjs/mocha/payload_manager.test.js +++ b/packages/snjs/mocha/payload_manager.test.js @@ -10,7 +10,7 @@ describe('payload manager', () => { this.createNotePayload = async () => { return new DecryptedPayload({ uuid: Factory.generateUuidish(), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: { title: 'hello', text: 'world', @@ -45,7 +45,7 @@ describe('payload manager', () => { it('insertion observer', async function () { const observations = [] - this.payloadManager.addObserver(ContentType.Any, ({ inserted }) => { + this.payloadManager.addObserver(ContentType.TYPES.Any, ({ inserted }) => { observations.push({ inserted }) }) const payload = await this.createNotePayload() @@ -57,7 +57,7 @@ describe('payload manager', () => { it('change observer', async function () { const observations = [] - this.payloadManager.addObserver(ContentType.Any, ({ changed }) => { + this.payloadManager.addObserver(ContentType.TYPES.Any, ({ changed }) => { if (changed.length > 0) { observations.push({ changed }) } @@ -78,7 +78,7 @@ describe('payload manager', () => { }) it('reset state', async function () { - this.payloadManager.addObserver(ContentType.Any, ({}) => {}) + this.payloadManager.addObserver(ContentType.TYPES.Any, ({}) => {}) const payload = await this.createNotePayload() await this.payloadManager.emitPayload(payload) await this.payloadManager.resetState() diff --git a/packages/snjs/mocha/singletons.test.js b/packages/snjs/mocha/singletons.test.js index 3bd340ceb..c0f028da6 100644 --- a/packages/snjs/mocha/singletons.test.js +++ b/packages/snjs/mocha/singletons.test.js @@ -16,7 +16,7 @@ describe('singletons', function () { function createPrefsPayload() { const params = { uuid: UuidGenerator.GenerateUuid(), - content_type: ContentType.UserPrefs, + content_type: ContentType.TYPES.UserPrefs, content: { foo: 'bar', }, @@ -25,7 +25,7 @@ describe('singletons', function () { } function findOrCreatePrefsSingleton(application) { - return application.singletonManager.findOrCreateContentTypeSingleton(ContentType.UserPrefs, FillItemContent({})) + return application.singletonManager.findOrCreateContentTypeSingleton(ContentType.TYPES.UserPrefs, FillItemContent({})) } beforeEach(async function () { @@ -59,13 +59,13 @@ describe('singletons', function () { this.extManagerId = 'org.standardnotes.extensions-manager' this.extPred = new CompoundPredicate('and', [ - new Predicate('content_type', '=', ContentType.Component), + new Predicate('content_type', '=', ContentType.TYPES.Component), new Predicate('package_info.identifier', '=', this.extManagerId), ]) this.createExtMgr = () => { return this.application.mutator.createItem( - ContentType.Component, + ContentType.TYPES.Component, { package_info: { name: 'Extensions', @@ -121,14 +121,14 @@ describe('singletons', function () { await this.application.sync.sync(syncOptions) - expect(this.application.itemManager.itemsMatchingPredicate(ContentType.Component, this.extPred).length).to.equal(1) + expect(this.application.itemManager.itemsMatchingPredicate(ContentType.TYPES.Component, this.extPred).length).to.equal(1) }) it('resolves via find or create', async function () { /* Set to never synced as singleton manager will attempt to sync before resolving */ this.application.syncService.ut_clearLastSyncDate() this.application.syncService.ut_setDatabaseLoaded(false) - const contentType = ContentType.UserPrefs + const contentType = ContentType.TYPES.UserPrefs const predicate = new Predicate('content_type', '=', contentType) /* Start a sync right after we await singleton resolve below */ setTimeout(() => { @@ -198,7 +198,7 @@ describe('singletons', function () { didCompleteRelevantSync = true const saved = data.savedPayloads expect(saved.length).to.equal(1) - const matching = saved.find((p) => p.content_type === ContentType.Component && p.deleted) + const matching = saved.find((p) => p.content_type === ContentType.TYPES.Component && p.deleted) expect(matching).to.not.be.ok } }) @@ -252,7 +252,7 @@ describe('singletons', function () { }) it('if only result is errorDecrypting, create new item', async function () { - const item = this.application.itemManager.items.find((item) => item.content_type === ContentType.UserPrefs) + const item = this.application.itemManager.items.find((item) => item.content_type === ContentType.TYPES.UserPrefs) const erroredPayload = new EncryptedPayload({ ...item.payload.ejected(), @@ -292,7 +292,7 @@ describe('singletons', function () { const errorDecryptingFalse = false await Factory.insertItemWithOverride( this.application, - ContentType.Component, + ContentType.TYPES.Component, sharedContent, true, errorDecryptingFalse, @@ -301,7 +301,7 @@ describe('singletons', function () { const errorDecryptingTrue = true const errored = await Factory.insertItemWithOverride( this.application, - ContentType.Component, + ContentType.TYPES.Component, sharedContent, true, errorDecryptingTrue, @@ -324,7 +324,7 @@ describe('singletons', function () { await Factory.sleep(0) await this.application.syncService.sync(syncOptions) - expect(this.application.itemManager.itemsMatchingPredicate(ContentType.Component, this.extPred).length).to.equal(1) + expect(this.application.itemManager.itemsMatchingPredicate(ContentType.TYPES.Component, this.extPred).length).to.equal(1) }) it('alternating the uuid of a singleton should return correct result', async function () { diff --git a/packages/snjs/mocha/sync_tests/conflicting.test.js b/packages/snjs/mocha/sync_tests/conflicting.test.js index 202894423..60e659c9f 100644 --- a/packages/snjs/mocha/sync_tests/conflicting.test.js +++ b/packages/snjs/mocha/sync_tests/conflicting.test.js @@ -62,7 +62,7 @@ describe('online conflict handling', function () { } it('components should not be duplicated under any circumstances', async function () { - const payload = createDirtyPayload(ContentType.Component) + const payload = createDirtyPayload(ContentType.TYPES.Component) const item = await this.application.mutator.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged) @@ -90,7 +90,7 @@ describe('online conflict handling', function () { }) it('items keys should not be duplicated under any circumstances', async function () { - const payload = createDirtyPayload(ContentType.ItemsKey) + const payload = createDirtyPayload(ContentType.TYPES.ItemsKey) const item = await this.application.mutator.emitItemFromPayload(payload, PayloadEmitSource.LocalChanged) this.expectedItemCount++ await this.application.syncService.sync(syncOptions) @@ -527,13 +527,13 @@ describe('online conflict handling', function () { }).timeout(60000) it('duplicating an item should maintian its relationships', async function () { - const payload1 = Factory.createStorageItemPayload(ContentType.Tag) - const payload2 = Factory.createStorageItemPayload(ContentType.UserPrefs) + const payload1 = Factory.createStorageItemPayload(ContentType.TYPES.Tag) + const payload2 = Factory.createStorageItemPayload(ContentType.TYPES.UserPrefs) this.expectedItemCount -= 1 /** auto-created user preferences */ await this.application.mutator.emitItemsFromPayloads([payload1, payload2], PayloadEmitSource.LocalChanged) this.expectedItemCount += 2 - let tag = this.application.itemManager.getItems(ContentType.Tag)[0] - let userPrefs = this.application.itemManager.getItems(ContentType.UserPrefs)[0] + let tag = this.application.itemManager.getItems(ContentType.TYPES.Tag)[0] + let userPrefs = this.application.itemManager.getItems(ContentType.TYPES.UserPrefs)[0] expect(tag).to.be.ok expect(userPrefs).to.be.ok @@ -567,7 +567,7 @@ describe('online conflict handling', function () { const rawPayloads = await this.application.diskStorageService.getAllRawPayloads() expect(rawPayloads.length).to.equal(this.expectedItemCount) - const fooItems = this.application.itemManager.getItems(ContentType.Tag) + const fooItems = this.application.itemManager.getItems(ContentType.TYPES.Tag) const fooItem2 = fooItems[1] expect(fooItem2.content.conflict_of).to.equal(tag.uuid) @@ -772,9 +772,9 @@ describe('online conflict handling', function () { let backupFile = await this.application.createEncryptedBackupFileForAutomatedDesktopBackups() /** Sort matters, and is the cause of the original issue, where tag comes before the note */ backupFile.items = [ - backupFile.items.find((i) => i.content_type === ContentType.ItemsKey), - backupFile.items.find((i) => i.content_type === ContentType.Tag), - backupFile.items.find((i) => i.content_type === ContentType.Note), + backupFile.items.find((i) => i.content_type === ContentType.TYPES.ItemsKey), + backupFile.items.find((i) => i.content_type === ContentType.TYPES.Tag), + backupFile.items.find((i) => i.content_type === ContentType.TYPES.Note), ] backupFile = JSON.parse(JSON.stringify(backupFile)) /** Register new account and import this same data */ @@ -806,10 +806,10 @@ describe('online conflict handling', function () { }) let backupFile = await this.application.createEncryptedBackupFileForAutomatedDesktopBackups() backupFile.items = [ - backupFile.items.find((i) => i.content_type === ContentType.ItemsKey), - backupFile.items.filter((i) => i.content_type === ContentType.Note)[0], - backupFile.items.filter((i) => i.content_type === ContentType.Note)[1], - backupFile.items.find((i) => i.content_type === ContentType.Tag), + backupFile.items.find((i) => i.content_type === ContentType.TYPES.ItemsKey), + backupFile.items.filter((i) => i.content_type === ContentType.TYPES.Note)[0], + backupFile.items.filter((i) => i.content_type === ContentType.TYPES.Note)[1], + backupFile.items.find((i) => i.content_type === ContentType.TYPES.Tag), ] backupFile = JSON.parse(JSON.stringify(backupFile)) /** Register new account and import this same data */ diff --git a/packages/snjs/mocha/sync_tests/notes_tags.test.js b/packages/snjs/mocha/sync_tests/notes_tags.test.js index 0dd7d584a..b33bcba9c 100644 --- a/packages/snjs/mocha/sync_tests/notes_tags.test.js +++ b/packages/snjs/mocha/sync_tests/notes_tags.test.js @@ -53,8 +53,8 @@ describe('notes + tags syncing', function () { const tagPayload = pair[1] await this.application.mutator.emitItemsFromPayloads([notePayload, tagPayload], PayloadEmitSource.LocalChanged) - const note = this.application.itemManager.getItems([ContentType.Note])[0] - const tag = this.application.itemManager.getItems([ContentType.Tag])[0] + const note = this.application.itemManager.getItems([ContentType.TYPES.Note])[0] + const tag = this.application.itemManager.getItems([ContentType.TYPES.Tag])[0] expect(this.application.itemManager.getDisplayableNotes().length).to.equal(1) expect(this.application.itemManager.getDisplayableTags().length).to.equal(1) diff --git a/packages/snjs/mocha/sync_tests/offline.test.js b/packages/snjs/mocha/sync_tests/offline.test.js index 778886cfb..5cf4231d3 100644 --- a/packages/snjs/mocha/sync_tests/offline.test.js +++ b/packages/snjs/mocha/sync_tests/offline.test.js @@ -64,8 +64,8 @@ describe('offline syncing', () => { const rawPayloads2 = await this.application.diskStorageService.getAllRawPayloads() expect(rawPayloads2.length).to.equal(this.expectedItemCount) - const itemsKeyRaw = (await Factory.getStoragePayloadsOfType(this.application, ContentType.ItemsKey))[0] - const noteRaw = (await Factory.getStoragePayloadsOfType(this.application, ContentType.Note))[0] + const itemsKeyRaw = (await Factory.getStoragePayloadsOfType(this.application, ContentType.TYPES.ItemsKey))[0] + const noteRaw = (await Factory.getStoragePayloadsOfType(this.application, ContentType.TYPES.Note))[0] /** Encrypts with default items key */ expect(typeof noteRaw.content).to.equal('string') diff --git a/packages/snjs/mocha/sync_tests/online.test.js b/packages/snjs/mocha/sync_tests/online.test.js index 39699132f..f315a276a 100644 --- a/packages/snjs/mocha/sync_tests/online.test.js +++ b/packages/snjs/mocha/sync_tests/online.test.js @@ -54,7 +54,7 @@ describe('online syncing', function () { }) function noteObjectsFromObjects(items) { - return items.filter((item) => item.content_type === ContentType.Note) + return items.filter((item) => item.content_type === ContentType.TYPES.Note) } it('should register and sync basic model online', async function () { @@ -577,7 +577,7 @@ describe('online syncing', function () { await this.application.syncService.sync(syncOptions) this.expectedItemCount++ const rawPayloads = await this.application.diskStorageService.getAllRawPayloads() - const notePayload = rawPayloads.find((p) => p.content_type === ContentType.Note) + const notePayload = rawPayloads.find((p) => p.content_type === ContentType.TYPES.Note) expect(typeof notePayload.content).to.equal('string') }) @@ -593,7 +593,7 @@ describe('online syncing', function () { await Factory.sleep(0.3) const rawPayloads = await this.application.diskStorageService.getAllRawPayloads() - const notePayload = rawPayloads.find((p) => p.content_type === ContentType.Note) + const notePayload = rawPayloads.find((p) => p.content_type === ContentType.TYPES.Note) expect(typeof notePayload.content).to.equal('string') }) @@ -611,7 +611,7 @@ describe('online syncing', function () { ) this.expectedItemCount++ const rawPayloads = await this.application.diskStorageService.getAllRawPayloads() - const notePayload = rawPayloads.find((p) => p.content_type === ContentType.Note) + const notePayload = rawPayloads.find((p) => p.content_type === ContentType.TYPES.Note) expect(typeof notePayload.content).to.equal('string') expect(notePayload.content.length).to.be.above(text.length) }) @@ -790,7 +790,7 @@ describe('online syncing', function () { /** Create an item and sync it */ let note = await Factory.createMappedNote(this.application) - this.application.itemManager.addObserver(ContentType.Note, ({ source }) => { + this.application.itemManager.addObserver(ContentType.TYPES.Note, ({ source }) => { if (source === PayloadEmitSource.RemoteSaved) { actualSaveCount++ } @@ -837,7 +837,7 @@ describe('online syncing', function () { /** Create an item and sync it */ let note = await Factory.createMappedNote(this.application) - this.application.itemManager.addObserver(ContentType.Note, ({ source }) => { + this.application.itemManager.addObserver(ContentType.TYPES.Note, ({ source }) => { if (source === PayloadEmitSource.RemoteSaved) { actualSaveCount++ } @@ -876,7 +876,7 @@ describe('online syncing', function () { let didPerformMutatation = false const newText = `${Math.random()}` - this.application.itemManager.addObserver(ContentType.Note, async ({ changed, source }) => { + this.application.itemManager.addObserver(ContentType.TYPES.Note, async ({ changed, source }) => { if (source === PayloadEmitSource.RemoteSaved) { actualSaveCount++ } else if (source === PayloadEmitSource.PreSyncSave && !didPerformMutatation) { @@ -1015,7 +1015,7 @@ describe('online syncing', function () { it('deleting an item permanently should include it in PayloadEmitSource.PreSyncSave item change observer', async function () { let conditionMet = false - this.application.streamItems([ContentType.Note], async ({ removed, source }) => { + this.application.streamItems([ContentType.TYPES.Note], async ({ removed, source }) => { if (source === PayloadEmitSource.PreSyncSave && removed.length === 1) { conditionMet = true } diff --git a/packages/snjs/mocha/upgrading.test.js b/packages/snjs/mocha/upgrading.test.js index 9b31f8fce..9198efae6 100644 --- a/packages/snjs/mocha/upgrading.test.js +++ b/packages/snjs/mocha/upgrading.test.js @@ -192,7 +192,7 @@ describe('upgrading', () => { expect((await this.application.encryptionService.getRootKey()).keyVersion).to.equal(ProtocolVersion.V003) /** Ensure note is encrypted with 003 */ - const notePayloads = await Factory.getStoragePayloadsOfType(this.application, ContentType.Note) + const notePayloads = await Factory.getStoragePayloadsOfType(this.application, ContentType.TYPES.Note) expect(notePayloads.length).to.equal(1) expect(notePayloads[0].version).to.equal(ProtocolVersion.V003) @@ -211,7 +211,7 @@ describe('upgrading', () => { const note = this.application.itemManager.getDisplayableNotes()[0] await Factory.markDirtyAndSyncItem(this.application, note) - const refreshedNotePayloads = await Factory.getStoragePayloadsOfType(this.application, ContentType.Note) + const refreshedNotePayloads = await Factory.getStoragePayloadsOfType(this.application, ContentType.TYPES.Note) const refreshedNotePayload = refreshedNotePayloads[0] expect(refreshedNotePayload.version).to.equal(latestVersion) }).timeout(5000) diff --git a/packages/snjs/mocha/vaults/conflicts.test.js b/packages/snjs/mocha/vaults/conflicts.test.js index 5d52d3ca7..9c0bb0ff6 100644 --- a/packages/snjs/mocha/vaults/conflicts.test.js +++ b/packages/snjs/mocha/vaults/conflicts.test.js @@ -37,7 +37,7 @@ describe('shared vault conflicts', function () { expect(conflicts.length).to.equal(1) expect(conflicts[0].type).to.equal(ConflictType.SharedVaultNotMemberError) - expect(conflicts[0].unsaved_item.content_type).to.equal(ContentType.Note) + expect(conflicts[0].unsaved_item.content_type).to.equal(ContentType.TYPES.Note) const collaboratorNotes = contactContext.items.getDisplayableNotes() expect(collaboratorNotes.length).to.equal(1) @@ -89,7 +89,7 @@ describe('shared vault conflicts', function () { expect(conflicts.length).to.equal(1) expect(conflicts[0].type).to.equal(ConflictType.SharedVaultInsufficientPermissionsError) - expect(conflicts[0].unsaved_item.content_type).to.equal(ContentType.Note) + expect(conflicts[0].unsaved_item.content_type).to.equal(ContentType.TYPES.Note) await deinitContactContext() }) @@ -135,7 +135,7 @@ describe('shared vault conflicts', function () { expect(conflicts.length).to.equal(1) expect(conflicts[0].type).to.equal(ConflictType.SharedVaultNotMemberError) - expect(conflicts[0].unsaved_item.content_type).to.equal(ContentType.Note) + expect(conflicts[0].unsaved_item.content_type).to.equal(ContentType.TYPES.Note) }) it('should create a non-vaulted copy if attempting to move item from vault to user and item belongs to someone else', async () => { @@ -147,7 +147,7 @@ describe('shared vault conflicts', function () { const conflicts = await promise expect(conflicts.length).to.equal(1) - expect(conflicts[0].unsaved_item.content_type).to.equal(ContentType.Note) + expect(conflicts[0].unsaved_item.content_type).to.equal(ContentType.TYPES.Note) const duplicateNote = contactContext.findDuplicateNote(note.uuid) expect(duplicateNote).to.not.be.undefined @@ -172,7 +172,7 @@ describe('shared vault conflicts', function () { const conflicts = await promise expect(conflicts.length).to.equal(1) - expect(conflicts[0].unsaved_item.content_type).to.equal(ContentType.Note) + expect(conflicts[0].unsaved_item.content_type).to.equal(ContentType.TYPES.Note) const duplicateNote = context.findDuplicateNote(note.uuid) expect(duplicateNote).to.not.be.undefined diff --git a/packages/snjs/mocha/vaults/permissions.test.js b/packages/snjs/mocha/vaults/permissions.test.js index 81d475449..ba4924cce 100644 --- a/packages/snjs/mocha/vaults/permissions.test.js +++ b/packages/snjs/mocha/vaults/permissions.test.js @@ -82,7 +82,7 @@ describe('shared vault permissions', function () { const conflicts = await promise expect(conflicts.length).to.equal(1) - expect(conflicts[0].unsaved_item.content_type).to.equal(ContentType.KeySystemItemsKey) + expect(conflicts[0].unsaved_item.content_type).to.equal(ContentType.TYPES.KeySystemItemsKey) await deinitContactContext() }) @@ -103,7 +103,7 @@ describe('shared vault permissions', function () { const conflicts = await promise expect(conflicts.length).to.equal(1) - expect(conflicts[0].unsaved_item.content_type).to.equal(ContentType.Note) + expect(conflicts[0].unsaved_item.content_type).to.equal(ContentType.TYPES.Note) await deinitContactContext() }) diff --git a/packages/snjs/package.json b/packages/snjs/package.json index 7c59b5f9b..9f86ee150 100644 --- a/packages/snjs/package.json +++ b/packages/snjs/package.json @@ -36,8 +36,8 @@ "@babel/core": "*", "@babel/preset-env": "*", "@standardnotes/api": "workspace:*", - "@standardnotes/common": "^1.48.3", - "@standardnotes/domain-core": "^1.12.0", + "@standardnotes/common": "^1.50.0", + "@standardnotes/domain-core": "^1.22.0", "@standardnotes/domain-events": "^2.108.1", "@standardnotes/encryption": "workspace:*", "@standardnotes/features": "workspace:*", diff --git a/packages/ui-services/package.json b/packages/ui-services/package.json index a5abc5553..74a5aa9e0 100644 --- a/packages/ui-services/package.json +++ b/packages/ui-services/package.json @@ -15,7 +15,8 @@ "test": "jest spec" }, "dependencies": { - "@standardnotes/common": "^1.48.3", + "@standardnotes/common": "^1.50.0", + "@standardnotes/domain-core": "^1.22.0", "@standardnotes/features": "workspace:^", "@standardnotes/filepicker": "workspace:^", "@standardnotes/models": "workspace:^", diff --git a/packages/ui-services/src/Archive/ArchiveManager.ts b/packages/ui-services/src/Archive/ArchiveManager.ts index 8af9b9e32..b5ee72229 100644 --- a/packages/ui-services/src/Archive/ArchiveManager.ts +++ b/packages/ui-services/src/Archive/ArchiveManager.ts @@ -5,7 +5,7 @@ import { EncryptedItemInterface, NoteContent, } from '@standardnotes/models' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { ApplicationInterface } from '@standardnotes/services' export function sanitizeFileName(name: string): string { @@ -87,7 +87,7 @@ export class ArchiveManager { const item = items[index] let name, contents - if (item.content_type === ContentType.Note) { + if (item.content_type === ContentType.TYPES.Note) { const note = item as BackupFileDecryptedContextualPayload name = note.content.title contents = note.content.text diff --git a/packages/ui-services/src/Import/AegisConverter/AegisToAuthenticatorConverter.ts b/packages/ui-services/src/Import/AegisConverter/AegisToAuthenticatorConverter.ts index 1c062621a..0c3058259 100644 --- a/packages/ui-services/src/Import/AegisConverter/AegisToAuthenticatorConverter.ts +++ b/packages/ui-services/src/Import/AegisConverter/AegisToAuthenticatorConverter.ts @@ -1,8 +1,8 @@ import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models' -import { ContentType } from '@standardnotes/common' import { readFileAsText } from '../Utils' import { FeatureIdentifier, NoteType } from '@standardnotes/features' import { WebApplicationInterface } from '../../WebApplication/WebApplicationInterface' +import { ContentType } from '@standardnotes/domain-core' type AegisData = { db: { @@ -62,7 +62,7 @@ export class AegisToAuthenticatorConverter { updated_at: new Date(file.lastModified), updated_at_timestamp: file.lastModified, uuid: this.application.generateUUID(), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: { title: file.name.split('.')[0], text: JSON.stringify(entries), diff --git a/packages/ui-services/src/Import/EvernoteConverter/EvernoteConverter.spec.ts b/packages/ui-services/src/Import/EvernoteConverter/EvernoteConverter.spec.ts index 4a6626c3a..6ab411f88 100644 --- a/packages/ui-services/src/Import/EvernoteConverter/EvernoteConverter.spec.ts +++ b/packages/ui-services/src/Import/EvernoteConverter/EvernoteConverter.spec.ts @@ -2,7 +2,7 @@ * @jest-environment jsdom */ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { DecryptedTransferPayload, NoteContent, TagContent } from '@standardnotes/models' import { EvernoteConverter } from './EvernoteConverter' import data from './testData' @@ -37,13 +37,13 @@ describe('EvernoteConverter', () => { expect(result).not.toBeNull() expect(result?.length).toBe(3) - expect(result?.[0].content_type).toBe(ContentType.Note) + expect(result?.[0].content_type).toBe(ContentType.TYPES.Note) expect((result?.[0] as DecryptedTransferPayload).content.text).toBe('This is a test.') - expect(result?.[1].content_type).toBe(ContentType.Note) + expect(result?.[1].content_type).toBe(ContentType.TYPES.Note) expect((result?.[1] as DecryptedTransferPayload).content.text).toBe( 'Lorem ipsum dolor sit amet, consectetur adipiscing elit.', ) - expect(result?.[2].content_type).toBe(ContentType.Tag) + expect(result?.[2].content_type).toBe(ContentType.TYPES.Tag) expect((result?.[2] as DecryptedTransferPayload).content.title).toBe('evernote') expect((result?.[2] as DecryptedTransferPayload).content.references.length).toBe(2) expect((result?.[2] as DecryptedTransferPayload).content.references[0].uuid).toBe(result?.[0].uuid) @@ -57,13 +57,13 @@ describe('EvernoteConverter', () => { expect(result).not.toBeNull() expect(result?.length).toBe(3) - expect(result?.[0].content_type).toBe(ContentType.Note) + expect(result?.[0].content_type).toBe(ContentType.TYPES.Note) expect((result?.[0] as DecryptedTransferPayload).content.text).toBe('

This is a test.
') - expect(result?.[1].content_type).toBe(ContentType.Note) + expect(result?.[1].content_type).toBe(ContentType.TYPES.Note) expect((result?.[1] as DecryptedTransferPayload).content.text).toBe( '
Lorem ipsum dolor sit amet, consectetur adipiscing elit.
', ) - expect(result?.[2].content_type).toBe(ContentType.Tag) + expect(result?.[2].content_type).toBe(ContentType.TYPES.Tag) expect((result?.[2] as DecryptedTransferPayload).content.title).toBe('evernote') expect((result?.[2] as DecryptedTransferPayload).content.references.length).toBe(2) expect((result?.[2] as DecryptedTransferPayload).content.references[0].uuid).toBe(result?.[0].uuid) diff --git a/packages/ui-services/src/Import/EvernoteConverter/EvernoteConverter.ts b/packages/ui-services/src/Import/EvernoteConverter/EvernoteConverter.ts index da9a136cd..d9f092da1 100644 --- a/packages/ui-services/src/Import/EvernoteConverter/EvernoteConverter.ts +++ b/packages/ui-services/src/Import/EvernoteConverter/EvernoteConverter.ts @@ -1,10 +1,10 @@ -import { ContentType } from '@standardnotes/common' import { DecryptedTransferPayload, NoteContent, TagContent } from '@standardnotes/models' import { readFileAsText } from '../Utils' import dayjs from 'dayjs' import customParseFormat from 'dayjs/plugin/customParseFormat' import utc from 'dayjs/plugin/utc' import { WebApplicationInterface } from '../../WebApplication/WebApplicationInterface' +import { ContentType } from '@standardnotes/domain-core' dayjs.extend(customParseFormat) dayjs.extend(utc) @@ -36,7 +36,7 @@ export class EvernoteConverter { updated_at: now, updated_at_timestamp: now.getTime(), uuid: this.application.generateUUID(), - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, content: { title: defaultTagName, expanded: false, @@ -89,7 +89,7 @@ export class EvernoteConverter { updated_at: updatedAtDate, updated_at_timestamp: updatedAtDate.getTime(), uuid: this.application.generateUUID(), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: { title: !title ? `Imported note ${index + 1} from Evernote` : title, text, @@ -99,7 +99,7 @@ export class EvernoteConverter { if (defaultTag) { defaultTag.content.references.push({ - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, uuid: note.uuid, }) } @@ -112,7 +112,7 @@ export class EvernoteConverter { const now = new Date() tag = { uuid: this.application.generateUUID(), - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, created_at: now, created_at_timestamp: now.getTime(), updated_at: now, diff --git a/packages/ui-services/src/Import/GoogleKeepConverter/GoogleKeepConverter.ts b/packages/ui-services/src/Import/GoogleKeepConverter/GoogleKeepConverter.ts index fae0963f3..b5608d327 100644 --- a/packages/ui-services/src/Import/GoogleKeepConverter/GoogleKeepConverter.ts +++ b/packages/ui-services/src/Import/GoogleKeepConverter/GoogleKeepConverter.ts @@ -1,4 +1,4 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models' import { readFileAsText } from '../Utils' import { WebApplicationInterface } from '../../WebApplication/WebApplicationInterface' @@ -67,7 +67,7 @@ export class GoogleKeepConverter { updated_at: date, updated_at_timestamp: date.getTime(), uuid: this.application.generateUUID(), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: { title: title, text: content, @@ -121,7 +121,7 @@ export class GoogleKeepConverter { updated_at: date, updated_at_timestamp: date.getTime(), uuid: this.application.generateUUID(), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: { title: parsed.title, text: parsed.textContent, diff --git a/packages/ui-services/src/Import/PlaintextConverter/PlaintextConverter.ts b/packages/ui-services/src/Import/PlaintextConverter/PlaintextConverter.ts index 76220f3e4..7d100d949 100644 --- a/packages/ui-services/src/Import/PlaintextConverter/PlaintextConverter.ts +++ b/packages/ui-services/src/Import/PlaintextConverter/PlaintextConverter.ts @@ -1,4 +1,4 @@ -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { parseFileName } from '@standardnotes/filepicker' import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models' import { readFileAsText } from '../Utils' @@ -25,7 +25,7 @@ export class PlaintextConverter { updated_at: updatedAtDate, updated_at_timestamp: updatedAtDate.getTime(), uuid: this.application.generateUUID(), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: { title: name, text: content, diff --git a/packages/ui-services/src/Import/SimplenoteConverter/SimplenoteConverter.ts b/packages/ui-services/src/Import/SimplenoteConverter/SimplenoteConverter.ts index 6ce4076bc..0ee392d3e 100644 --- a/packages/ui-services/src/Import/SimplenoteConverter/SimplenoteConverter.ts +++ b/packages/ui-services/src/Import/SimplenoteConverter/SimplenoteConverter.ts @@ -1,5 +1,5 @@ import { DecryptedTransferPayload, NoteContent } from '@standardnotes/models' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { readFileAsText } from '../Utils' import { WebApplicationInterface } from '../../WebApplication/WebApplicationInterface' @@ -54,7 +54,7 @@ export class SimplenoteConverter { updated_at: updatedAtDate, updated_at_timestamp: updatedAtDate.getTime(), uuid: this.application.generateUUID(), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, content: { title, text: content, diff --git a/packages/ui-services/src/Theme/ThemeManager.ts b/packages/ui-services/src/Theme/ThemeManager.ts index 389f7d46c..5bc10ebea 100644 --- a/packages/ui-services/src/Theme/ThemeManager.ts +++ b/packages/ui-services/src/Theme/ThemeManager.ts @@ -1,5 +1,5 @@ import { dismissToast, ToastType, addTimedToast } from '@standardnotes/toast' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { CreateDecryptedLocalStorageContextPayload, LocalStorageDecryptedContextualPayload, @@ -136,7 +136,7 @@ export class ThemeManager extends AbstractUIServicee { } } - const activeThemes = (this.application.items.getItems(ContentType.Theme) as SNTheme[]).filter( + const activeThemes = (this.application.items.getItems(ContentType.TYPES.Theme) as SNTheme[]).filter( (theme) => theme.active, ) @@ -244,7 +244,7 @@ export class ThemeManager extends AbstractUIServicee { } }) - this.unregisterStream = this.application.streamItems(ContentType.Theme, ({ changed, inserted, source }) => { + this.unregisterStream = this.application.streamItems(ContentType.TYPES.Theme, ({ changed, inserted, source }) => { const items = changed.concat(inserted) const themes = items as SNTheme[] for (const theme of themes) { diff --git a/packages/utils/package.json b/packages/utils/package.json index 9af7ad3ad..fafb35cb1 100644 --- a/packages/utils/package.json +++ b/packages/utils/package.json @@ -25,7 +25,7 @@ "test": "jest spec" }, "dependencies": { - "@standardnotes/common": "^1.48.3", + "@standardnotes/common": "^1.50.0", "dompurify": "^2.4.1", "lodash": "^4.17.21", "reflect-metadata": "^0.1.13" diff --git a/packages/web/src/javascripts/Application/WebApplication.ts b/packages/web/src/javascripts/Application/WebApplication.ts index 479a9a939..fce0ae26d 100644 --- a/packages/web/src/javascripts/Application/WebApplication.ts +++ b/packages/web/src/javascripts/Application/WebApplication.ts @@ -325,7 +325,7 @@ export class WebApplication extends SNApplication implements WebApplicationInter public getItemTags(item: DecryptedItemInterface) { return this.items.itemsReferencingItem(item).filter((ref) => { - return ref.content_type === ContentType.Tag + return ref.content_type === ContentType.TYPES.Tag }) as SNTag[] } @@ -397,7 +397,7 @@ export class WebApplication extends SNApplication implements WebApplicationInter async handleReceivedTextEvent({ text, title }: { text: string; title?: string | undefined }) { const titleForNote = title || this.getViewControllerManager().itemListController.titleForNewNote() - const note = this.items.createTemplateItem(ContentType.Note, { + const note = this.items.createTemplateItem(ContentType.TYPES.Note, { title: titleForNote, text: text, references: [], diff --git a/packages/web/src/javascripts/Components/ClipperView/ClipperView.tsx b/packages/web/src/javascripts/Components/ClipperView/ClipperView.tsx index 6eac72f01..222a0bf61 100644 --- a/packages/web/src/javascripts/Components/ClipperView/ClipperView.tsx +++ b/packages/web/src/javascripts/Components/ClipperView/ClipperView.tsx @@ -209,7 +209,7 @@ const ClipperView = ({ const editorStateJSON = await getSuperJSONFromClipPayload(clipPayload) - const note = application.items.createTemplateItem(ContentType.Note, { + const note = application.items.createTemplateItem(ContentType.TYPES.Note, { title: clipPayload.title, text: editorStateJSON, editorIdentifier: FeatureIdentifier.SuperEditor, @@ -401,7 +401,7 @@ const ClipperView = ({ = ({ [hideTags, selectedTag, application], ) - const hasNotes = items.some((item) => item.content_type === ContentType.Note) + const hasNotes = items.some((item) => item.content_type === ContentType.TYPES.Note) return (
> = (props) => { switch (props.item.content_type) { - case ContentType.Note: + case ContentType.TYPES.Note: return - case ContentType.File: { + case ContentType.TYPES.File: { return } default: diff --git a/packages/web/src/javascripts/Components/ImportModal/ImportModalFileItem.tsx b/packages/web/src/javascripts/Components/ImportModal/ImportModalFileItem.tsx index df6147051..b52ccf7da 100644 --- a/packages/web/src/javascripts/Components/ImportModal/ImportModalFileItem.tsx +++ b/packages/web/src/javascripts/Components/ImportModal/ImportModalFileItem.tsx @@ -63,11 +63,11 @@ const ImportModalFileItem = ({ const notePayloads = file.status === 'ready' && file.payloads - ? file.payloads.filter((payload) => payload.content_type === ContentType.Note) + ? file.payloads.filter((payload) => payload.content_type === ContentType.TYPES.Note) : [] const tagPayloads = file.status === 'ready' && file.payloads - ? file.payloads.filter((payload) => payload.content_type === ContentType.Tag) + ? file.payloads.filter((payload) => payload.content_type === ContentType.TYPES.Tag) : [] const payloadsImportMessage = diff --git a/packages/web/src/javascripts/Components/ItemSelectionDropdown/ItemSelectionDropdown.tsx b/packages/web/src/javascripts/Components/ItemSelectionDropdown/ItemSelectionDropdown.tsx index 8d1f8557e..6170ff40a 100644 --- a/packages/web/src/javascripts/Components/ItemSelectionDropdown/ItemSelectionDropdown.tsx +++ b/packages/web/src/javascripts/Components/ItemSelectionDropdown/ItemSelectionDropdown.tsx @@ -7,14 +7,14 @@ import { useComboboxStore, VisuallyHidden, } from '@ariakit/react' -import { classNames, ContentType, DecryptedItem, naturalSort } from '@standardnotes/snjs' +import { classNames, DecryptedItem, naturalSort } from '@standardnotes/snjs' import { observer } from 'mobx-react-lite' import { useDeferredValue, useEffect, useState } from 'react' import { useApplication } from '../ApplicationProvider' import LinkedItemMeta from '../LinkedItems/LinkedItemMeta' type Props = { - contentTypes: ContentType[] + contentTypes: string[] placeholder: string onSelection: (item: DecryptedItem) => void className?: { diff --git a/packages/web/src/javascripts/Components/LinkedItems/LinkedItemBubble.tsx b/packages/web/src/javascripts/Components/LinkedItems/LinkedItemBubble.tsx index dc8e3aafb..27c70b8f4 100644 --- a/packages/web/src/javascripts/Components/LinkedItems/LinkedItemBubble.tsx +++ b/packages/web/src/javascripts/Components/LinkedItems/LinkedItemBubble.tsx @@ -120,7 +120,7 @@ const LinkedItemBubble = ({ {tagTitle && {tagTitle.titlePrefix}} - {link.type === 'linked-by' && link.item.content_type !== ContentType.Tag && ( + {link.type === 'linked-by' && link.item.content_type !== ContentType.TYPES.Tag && ( Linked By: )} {getItemTitleInContextOfLinkBubble(link.item)} diff --git a/packages/web/src/javascripts/Components/LinkedItems/LinkedItemBubblesContainer.tsx b/packages/web/src/javascripts/Components/LinkedItems/LinkedItemBubblesContainer.tsx index e48d74d42..496d574fe 100644 --- a/packages/web/src/javascripts/Components/LinkedItems/LinkedItemBubblesContainer.tsx +++ b/packages/web/src/javascripts/Components/LinkedItems/LinkedItemBubblesContainer.tsx @@ -115,7 +115,7 @@ const LinkedItemBubblesContainer = ({ return ( existsInAllItemLinks && - (link.item.content_type === ContentType.Note ? existsInNotesLinkingToItem : existsInFilesLinkingToItem) + (link.item.content_type === ContentType.TYPES.Note ? existsInNotesLinkingToItem : existsInFilesLinkingToItem) ) } diff --git a/packages/web/src/javascripts/Components/NoteView/Controller/FileViewController.ts b/packages/web/src/javascripts/Components/NoteView/Controller/FileViewController.ts index 85415f7b3..c326520b9 100644 --- a/packages/web/src/javascripts/Components/NoteView/Controller/FileViewController.ts +++ b/packages/web/src/javascripts/Components/NoteView/Controller/FileViewController.ts @@ -1,5 +1,5 @@ import { FileItem } from '@standardnotes/models' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { SNApplication } from '@standardnotes/snjs' import { ItemViewControllerInterface } from './ItemViewControllerInterface' @@ -23,20 +23,23 @@ export class FileViewController implements ItemViewControllerInterface { } private streamItems() { - this.removeStreamObserver = this.application.streamItems(ContentType.File, ({ changed, inserted }) => { - if (this.dealloced) { - return - } + this.removeStreamObserver = this.application.streamItems( + ContentType.TYPES.File, + ({ changed, inserted }) => { + if (this.dealloced) { + return + } - const files = changed.concat(inserted) + const files = changed.concat(inserted) - const matchingFile = files.find((item) => { - return item.uuid === this.item.uuid - }) + const matchingFile = files.find((item) => { + return item.uuid === this.item.uuid + }) - if (matchingFile) { - this.item = matchingFile - } - }) + if (matchingFile) { + this.item = matchingFile + } + }, + ) } } diff --git a/packages/web/src/javascripts/Components/NoteView/Controller/NoteViewController.spec.ts b/packages/web/src/javascripts/Components/NoteView/Controller/NoteViewController.spec.ts index 64cefb691..1ea495e92 100644 --- a/packages/web/src/javascripts/Components/NoteView/Controller/NoteViewController.spec.ts +++ b/packages/web/src/javascripts/Components/NoteView/Controller/NoteViewController.spec.ts @@ -1,5 +1,5 @@ import { WebApplication } from '@/Application/WebApplication' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { MutatorService, SNComponentManager, @@ -47,7 +47,7 @@ describe('note view controller', () => { await controller.initialize() expect(application.items.createTemplateItem).toHaveBeenCalledWith( - ContentType.Note, + ContentType.TYPES.Note, expect.objectContaining({ noteType: NoteType.Plain }), expect.anything(), ) @@ -68,7 +68,7 @@ describe('note view controller', () => { await controller.initialize() expect(application.items.createTemplateItem).toHaveBeenCalledWith( - ContentType.Note, + ContentType.TYPES.Note, expect.objectContaining({ noteType: NoteType.Markdown }), expect.anything(), ) diff --git a/packages/web/src/javascripts/Components/NoteView/Controller/NoteViewController.ts b/packages/web/src/javascripts/Components/NoteView/Controller/NoteViewController.ts index 1438ea313..8aea65bb1 100644 --- a/packages/web/src/javascripts/Components/NoteView/Controller/NoteViewController.ts +++ b/packages/web/src/javascripts/Components/NoteView/Controller/NoteViewController.ts @@ -11,7 +11,7 @@ import { } from '@standardnotes/models' import { UuidString } from '@standardnotes/snjs' import { removeFromArray } from '@standardnotes/utils' -import { ContentType } from '@standardnotes/common' +import { ContentType } from '@standardnotes/domain-core' import { ItemViewControllerInterface } from './ItemViewControllerInterface' import { TemplateNoteViewControllerOptions } from './TemplateNoteViewControllerOptions' import { log, LoggingDomain } from '@/Logging' @@ -99,7 +99,7 @@ export class NoteViewController implements ItemViewControllerInterface { const noteType = noteTypeForEditorIdentifier(editorIdentifier) const note = this.application.items.createTemplateItem( - ContentType.Note, + ContentType.TYPES.Note, { text: '', title: this.templateNoteOptions?.title || '', @@ -140,7 +140,7 @@ export class NoteViewController implements ItemViewControllerInterface { } this.disposers.push( - this.application.streamItems(ContentType.Note, ({ changed, inserted, source }) => { + this.application.streamItems(ContentType.TYPES.Note, ({ changed, inserted, source }) => { if (this.dealloced) { return } diff --git a/packages/web/src/javascripts/Components/NoteView/NoteView.tsx b/packages/web/src/javascripts/Components/NoteView/NoteView.tsx index dc3da5647..b70821679 100644 --- a/packages/web/src/javascripts/Components/NoteView/NoteView.tsx +++ b/packages/web/src/javascripts/Components/NoteView/NoteView.tsx @@ -425,21 +425,24 @@ class NoteView extends AbstractComponent { } streamItems() { - this.removeComponentStreamObserver = this.application.streamItems(ContentType.Component, async ({ source }) => { - log(LoggingDomain.NoteView, 'On component stream observer', PayloadEmitSource[source]) - if (isPayloadSourceInternalChange(source) || source === PayloadEmitSource.InitialObserverRegistrationPush) { - return - } + this.removeComponentStreamObserver = this.application.streamItems( + ContentType.TYPES.Component, + async ({ source }) => { + log(LoggingDomain.NoteView, 'On component stream observer', PayloadEmitSource[source]) + if (isPayloadSourceInternalChange(source) || source === PayloadEmitSource.InitialObserverRegistrationPush) { + return + } - if (!this.note) { - return - } + if (!this.note) { + return + } - await this.reloadStackComponents() - this.debounceReloadEditorComponent() - }) + await this.reloadStackComponents() + this.debounceReloadEditorComponent() + }, + ) - this.removeNoteStreamObserver = this.application.streamItems(ContentType.Note, async () => { + this.removeNoteStreamObserver = this.application.streamItems(ContentType.TYPES.Note, async () => { this.setState({ conflictedNotes: this.application.items.conflictsOf(this.note.uuid) as SNNote[], }) diff --git a/packages/web/src/javascripts/Components/NoteView/ReadonlyNoteContent.tsx b/packages/web/src/javascripts/Components/NoteView/ReadonlyNoteContent.tsx index b4e1d1261..e8cd9d906 100644 --- a/packages/web/src/javascripts/Components/NoteView/ReadonlyNoteContent.tsx +++ b/packages/web/src/javascripts/Components/NoteView/ReadonlyNoteContent.tsx @@ -36,7 +36,7 @@ export const ReadonlyNoteContent = ({ return undefined } - const templateNoteForRevision = application.items.createTemplateItem(ContentType.Note, note.content) as SNNote + const templateNoteForRevision = application.items.createTemplateItem(ContentType.TYPES.Note, note.content) as SNNote const componentViewer = application.componentManager.createComponentViewer(editorForCurrentNote) componentViewer.setReadonly(true) diff --git a/packages/web/src/javascripts/Components/Preferences/Panes/Appearance.tsx b/packages/web/src/javascripts/Components/Preferences/Panes/Appearance.tsx index 962cc2624..67b25d158 100644 --- a/packages/web/src/javascripts/Components/Preferences/Panes/Appearance.tsx +++ b/packages/web/src/javascripts/Components/Preferences/Panes/Appearance.tsx @@ -55,7 +55,7 @@ const Appearance: FunctionComponent = ({ application }) => { }) GetFeatures() - .filter((feature) => feature.content_type === ContentType.Theme && !feature.layerable) + .filter((feature) => feature.content_type === ContentType.TYPES.Theme && !feature.layerable) .forEach((theme) => { themesAsItems.push({ label: theme.name as string, diff --git a/packages/web/src/javascripts/Components/Preferences/Panes/General/Advanced/Packages/ConfirmCustomPackage.tsx b/packages/web/src/javascripts/Components/Preferences/Panes/General/Advanced/Packages/ConfirmCustomPackage.tsx index 51fa3788c..0c02e361b 100644 --- a/packages/web/src/javascripts/Components/Preferences/Panes/General/Advanced/Packages/ConfirmCustomPackage.tsx +++ b/packages/web/src/javascripts/Components/Preferences/Panes/General/Advanced/Packages/ConfirmCustomPackage.tsx @@ -1,4 +1,5 @@ -import { DisplayStringForContentType } from '@standardnotes/snjs' +import { ContentType } from '@standardnotes/snjs' + import Button from '@/Components/Button/Button' import { Fragment, FunctionComponent } from 'react' import { Title, Text, Subtitle } from '@/Components/Preferences/PreferencesComponents/Content' @@ -9,6 +10,12 @@ const ConfirmCustomPackage: FunctionComponent<{ component: AnyPackageType callback: (confirmed: boolean) => void }> = ({ component, callback }) => { + let contentTypeDisplayName = null + const contentTypeOrError = ContentType.create(component.content_type) + if (!contentTypeOrError.isFailed()) { + contentTypeDisplayName = contentTypeOrError.getValue().getDisplayName() + } + const fields = [ { label: 'Name', @@ -32,7 +39,7 @@ const ConfirmCustomPackage: FunctionComponent<{ }, { label: 'Extension Type', - value: DisplayStringForContentType(component.content_type), + value: contentTypeDisplayName, }, ] diff --git a/packages/web/src/javascripts/Components/Preferences/Panes/General/Advanced/Packages/Section.tsx b/packages/web/src/javascripts/Components/Preferences/Panes/General/Advanced/Packages/Section.tsx index 939543682..9e5dadd89 100644 --- a/packages/web/src/javascripts/Components/Preferences/Panes/General/Advanced/Packages/Section.tsx +++ b/packages/web/src/javascripts/Components/Preferences/Panes/General/Advanced/Packages/Section.tsx @@ -13,9 +13,9 @@ import PreferencesSegment from '../../../../PreferencesComponents/PreferencesSeg const loadExtensions = (application: WebApplication) => application.items.getItems([ - ContentType.ActionsExtension, - ContentType.Component, - ContentType.Theme, + ContentType.TYPES.ActionsExtension, + ContentType.TYPES.Component, + ContentType.TYPES.Theme, ]) as AnyPackageType[] type Props = { diff --git a/packages/web/src/javascripts/Components/Preferences/Panes/General/Moments.tsx b/packages/web/src/javascripts/Components/Preferences/Panes/General/Moments.tsx index db348d006..42f0b69e6 100644 --- a/packages/web/src/javascripts/Components/Preferences/Panes/General/Moments.tsx +++ b/packages/web/src/javascripts/Components/Preferences/Panes/General/Moments.tsx @@ -104,7 +104,7 @@ const Moments: FunctionComponent = ({ application }: Props) => {
)} diff --git a/packages/web/src/javascripts/Components/Preferences/Panes/General/SmartViews/SmartViews.tsx b/packages/web/src/javascripts/Components/Preferences/Panes/General/SmartViews/SmartViews.tsx index 47dd3859f..a3588f271 100644 --- a/packages/web/src/javascripts/Components/Preferences/Panes/General/SmartViews/SmartViews.tsx +++ b/packages/web/src/javascripts/Components/Preferences/Panes/General/SmartViews/SmartViews.tsx @@ -33,7 +33,7 @@ const SmartViews = ({ application, featuresController }: Props) => { ) useEffect(() => { - const disposeItemStream = application.streamItems([ContentType.SmartView], () => { + const disposeItemStream = application.streamItems([ContentType.TYPES.SmartView], () => { setSmartViews(application.items.getSmartViews().filter((view) => !isSystemView(view))) }) diff --git a/packages/web/src/javascripts/Components/Preferences/Panes/Security/EncryptionEnabled.tsx b/packages/web/src/javascripts/Components/Preferences/Panes/Security/EncryptionEnabled.tsx index 35ae3d433..570787b80 100644 --- a/packages/web/src/javascripts/Components/Preferences/Panes/Security/EncryptionEnabled.tsx +++ b/packages/web/src/javascripts/Components/Preferences/Panes/Security/EncryptionEnabled.tsx @@ -9,8 +9,10 @@ import { formatCount } from './formatCount' const EncryptionEnabled: FunctionComponent = () => { const application = useApplication() const itemCounter = new StaticItemCounter() - const count = itemCounter.countNotesAndTags(application.items.getItems([ContentType.Note, ContentType.Tag])) - const files = application.items.getItems([ContentType.File]) + const count = itemCounter.countNotesAndTags( + application.items.getItems([ContentType.TYPES.Note, ContentType.TYPES.Tag]), + ) + const files = application.items.getItems([ContentType.TYPES.File]) const notes = formatCount(count.notes, 'notes') const tags = formatCount(count.tags, 'tags') const archived = formatCount(count.archived, 'archived notes') diff --git a/packages/web/src/javascripts/Components/Preferences/Panes/Security/ErroredItems.tsx b/packages/web/src/javascripts/Components/Preferences/Panes/Security/ErroredItems.tsx index f18b9e4d3..ba2145f4f 100644 --- a/packages/web/src/javascripts/Components/Preferences/Panes/Security/ErroredItems.tsx +++ b/packages/web/src/javascripts/Components/Preferences/Panes/Security/ErroredItems.tsx @@ -1,13 +1,7 @@ import { observer } from 'mobx-react-lite' import { Fragment, FunctionComponent, useEffect, useState } from 'react' import { Text, Title, Subtitle } from '@/Components/Preferences/PreferencesComponents/Content' -import { - ButtonType, - ClientDisplayableError, - ContentType, - DisplayStringForContentType, - EncryptedItemInterface, -} from '@standardnotes/snjs' +import { ButtonType, ClientDisplayableError, ContentType, EncryptedItemInterface } from '@standardnotes/snjs' import Button from '@/Components/Button/Button' import HorizontalSeparator from '@/Components/Shared/HorizontalSeparator' import PreferencesSegment from '../../PreferencesComponents/PreferencesSegment' @@ -20,13 +14,17 @@ const ErroredItems: FunctionComponent = () => { const [erroredItems, setErroredItems] = useState(application.items.invalidNonVaultedItems) useEffect(() => { - return application.streamItems(ContentType.Any, () => { + return application.streamItems(ContentType.TYPES.Any, () => { setErroredItems(application.items.invalidNonVaultedItems) }) }, [application]) const getContentTypeDisplay = (item: EncryptedItemInterface): string => { - const display = DisplayStringForContentType(item.content_type) + const contentTypeOrError = ContentType.create(item.content_type) + let display = null + if (!contentTypeOrError.isFailed()) { + display = contentTypeOrError.getValue().getDisplayName() + } if (display) { return `${display[0].toUpperCase()}${display.slice(1)}` } else { diff --git a/packages/web/src/javascripts/Components/Preferences/Panes/Vaults/Vaults.tsx b/packages/web/src/javascripts/Components/Preferences/Panes/Vaults/Vaults.tsx index 17b8d629f..0aac0610f 100644 --- a/packages/web/src/javascripts/Components/Preferences/Panes/Vaults/Vaults.tsx +++ b/packages/web/src/javascripts/Components/Preferences/Panes/Vaults/Vaults.tsx @@ -61,7 +61,7 @@ const Vaults = () => { }, [application.sharedVaults, updateAllData]) useEffect(() => { - return application.streamItems([ContentType.VaultListing, ContentType.TrustedContact], () => { + return application.streamItems([ContentType.TYPES.VaultListing, ContentType.TYPES.TrustedContact], () => { void updateAllData() }) }, [application, updateAllData]) diff --git a/packages/web/src/javascripts/Components/QuickSettingsMenu/QuickSettingsMenu.tsx b/packages/web/src/javascripts/Components/QuickSettingsMenu/QuickSettingsMenu.tsx index f561d2858..f4cf070f7 100644 --- a/packages/web/src/javascripts/Components/QuickSettingsMenu/QuickSettingsMenu.tsx +++ b/packages/web/src/javascripts/Components/QuickSettingsMenu/QuickSettingsMenu.tsx @@ -43,7 +43,7 @@ const QuickSettingsMenu: FunctionComponent = ({ application, quickSet }) as ThemeItem[] GetFeatures() - .filter((feature) => feature.content_type === ContentType.Theme && !feature.layerable) + .filter((feature) => feature.content_type === ContentType.TYPES.Theme && !feature.layerable) .forEach((theme) => { if (themes.findIndex((item) => item.identifier === theme.identifier) === -1) { themes.push({ @@ -76,7 +76,7 @@ const QuickSettingsMenu: FunctionComponent = ({ application, quickSet }, [reloadThemes, themes.length]) useEffect(() => { - const cleanupItemStream = application.streamItems(ContentType.Theme, () => { + const cleanupItemStream = application.streamItems(ContentType.TYPES.Theme, () => { reloadThemes() }) @@ -86,7 +86,7 @@ const QuickSettingsMenu: FunctionComponent = ({ application, quickSet }, [application, reloadThemes]) useEffect(() => { - const cleanupItemStream = application.streamItems(ContentType.Component, () => { + const cleanupItemStream = application.streamItems(ContentType.TYPES.Component, () => { reloadToggleableComponents() }) diff --git a/packages/web/src/javascripts/Components/SuperEditor/Plugins/ItemSelectionPlugin/ItemSelectionPlugin.tsx b/packages/web/src/javascripts/Components/SuperEditor/Plugins/ItemSelectionPlugin/ItemSelectionPlugin.tsx index 32501dc09..2d1340b42 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/Plugins/ItemSelectionPlugin/ItemSelectionPlugin.tsx +++ b/packages/web/src/javascripts/Components/SuperEditor/Plugins/ItemSelectionPlugin/ItemSelectionPlugin.tsx @@ -60,7 +60,7 @@ export const ItemSelectionPlugin: FunctionComponent = ({ currentNote }) = return new ItemOption(item, item.title || '', { onSelect: (_queryString: string) => { void linkingController.linkItems(currentNote, item) - if (item.content_type === ContentType.File) { + if (item.content_type === ContentType.TYPES.File) { editor.dispatchCommand(INSERT_FILE_COMMAND, item.uuid) } else { editor.dispatchCommand(INSERT_BUBBLE_COMMAND, item.uuid) diff --git a/packages/web/src/javascripts/Components/SuperEditor/Plugins/ReadonlyPlugin/ReadonlyPlugin.tsx b/packages/web/src/javascripts/Components/SuperEditor/Plugins/ReadonlyPlugin/ReadonlyPlugin.tsx index c9224e356..9f5f35443 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/Plugins/ReadonlyPlugin/ReadonlyPlugin.tsx +++ b/packages/web/src/javascripts/Components/SuperEditor/Plugins/ReadonlyPlugin/ReadonlyPlugin.tsx @@ -9,7 +9,7 @@ const ReadonlyPlugin = ({ note }: { note: SNNote }) => { const [readOnly, setReadOnly] = useState(note.locked) useEffect(() => { - return application.streamItems(ContentType.Note, ({ changed }) => { + return application.streamItems(ContentType.TYPES.Note, ({ changed }) => { const changedNoteItem = changed.find((changedItem) => changedItem.uuid === note.uuid) if (changedNoteItem) { diff --git a/packages/web/src/javascripts/Components/SuperEditor/SuperNoteConverter.tsx b/packages/web/src/javascripts/Components/SuperEditor/SuperNoteConverter.tsx index dbb24f63f..a83388e09 100644 --- a/packages/web/src/javascripts/Components/SuperEditor/SuperNoteConverter.tsx +++ b/packages/web/src/javascripts/Components/SuperEditor/SuperNoteConverter.tsx @@ -55,7 +55,7 @@ const SuperNoteConverter = ({ return undefined } - const templateNoteForRevision = application.items.createTemplateItem(ContentType.Note, { + const templateNoteForRevision = application.items.createTemplateItem(ContentType.TYPES.Note, { title: note.title, text: convertedContent, references: note.references, diff --git a/packages/web/src/javascripts/Components/Tags/SmartViewsListItem.tsx b/packages/web/src/javascripts/Components/Tags/SmartViewsListItem.tsx index e3c10d6c3..c00590ad9 100644 --- a/packages/web/src/javascripts/Components/Tags/SmartViewsListItem.tsx +++ b/packages/web/src/javascripts/Components/Tags/SmartViewsListItem.tsx @@ -101,7 +101,7 @@ const SmartViewsListItem: FunctionComponent = ({ view, tagsState, setEdit return } - return application.streamItems(ContentType.Note, () => { + return application.streamItems(ContentType.TYPES.Note, () => { setConflictsCount(application.items.numberOfNotesWithConflicts()) }) }, [application, view]) diff --git a/packages/web/src/javascripts/Controllers/Abstract/PersistenceService.ts b/packages/web/src/javascripts/Controllers/Abstract/PersistenceService.ts index fb55f4ffc..05c64aa7b 100644 --- a/packages/web/src/javascripts/Controllers/Abstract/PersistenceService.ts +++ b/packages/web/src/javascripts/Controllers/Abstract/PersistenceService.ts @@ -23,7 +23,7 @@ export class PersistenceService { this.hydratePersistedValues() this.didHydrateOnce = true } else if (eventName === ApplicationEvent.LocalDataIncrementalLoad) { - const canHydrate = this.application.items.getItems([ContentType.Note, ContentType.Tag]).length > 0 + const canHydrate = this.application.items.getItems([ContentType.TYPES.Note, ContentType.TYPES.Tag]).length > 0 if (!canHydrate) { return diff --git a/packages/web/src/javascripts/Controllers/AccountMenu/AccountMenuController.ts b/packages/web/src/javascripts/Controllers/AccountMenu/AccountMenuController.ts index 2d5aa288b..23a7f45c9 100644 --- a/packages/web/src/javascripts/Controllers/AccountMenu/AccountMenuController.ts +++ b/packages/web/src/javascripts/Controllers/AccountMenu/AccountMenuController.ts @@ -77,9 +77,9 @@ export class AccountMenuController extends AbstractViewController { ) this.disposers.push( - this.application.streamItems([ContentType.Note, ContentType.Tag], () => { + this.application.streamItems([ContentType.TYPES.Note, ContentType.TYPES.Tag], () => { runInAction(() => { - this.notesAndTags = this.application.items.getItems([ContentType.Note, ContentType.Tag]) + this.notesAndTags = this.application.items.getItems([ContentType.TYPES.Note, ContentType.TYPES.Tag]) }) }), ) diff --git a/packages/web/src/javascripts/Controllers/FilePreviewModalController.ts b/packages/web/src/javascripts/Controllers/FilePreviewModalController.ts index 2b8d7907b..e81d3354b 100644 --- a/packages/web/src/javascripts/Controllers/FilePreviewModalController.ts +++ b/packages/web/src/javascripts/Controllers/FilePreviewModalController.ts @@ -21,7 +21,7 @@ export class FilePreviewModalController { }) this.eventObservers.push( - application.streamItems(ContentType.File, ({ changed, removed }) => { + application.streamItems(ContentType.TYPES.File, ({ changed, removed }) => { if (!this.currentFile) { return } diff --git a/packages/web/src/javascripts/Controllers/FilesController.ts b/packages/web/src/javascripts/Controllers/FilesController.ts index 46ff0925d..8918adb46 100644 --- a/packages/web/src/javascripts/Controllers/FilesController.ts +++ b/packages/web/src/javascripts/Controllers/FilesController.ts @@ -88,7 +88,7 @@ export class FilesController extends AbstractViewController { + application.streamItems(ContentType.TYPES.File, () => { this.reloadAllFiles() this.reloadAttachedFiles() }), diff --git a/packages/web/src/javascripts/Controllers/ImportModalController.ts b/packages/web/src/javascripts/Controllers/ImportModalController.ts index e4c270f55..855b0e528 100644 --- a/packages/web/src/javascripts/Controllers/ImportModalController.ts +++ b/packages/web/src/javascripts/Controllers/ImportModalController.ts @@ -91,8 +91,8 @@ export class ImportModalController { try { await this.importer.importFromTransferPayloads(payloads) - const notesImported = payloads.filter((payload) => payload.content_type === ContentType.Note) - const tagsImported = payloads.filter((payload) => payload.content_type === ContentType.Tag) + const notesImported = payloads.filter((payload) => payload.content_type === ContentType.TYPES.Note) + const tagsImported = payloads.filter((payload) => payload.content_type === ContentType.TYPES.Tag) const successMessage = `Successfully imported ${notesImported.length} ` + @@ -149,14 +149,14 @@ export class ImportModalController { } } const currentDate = new Date() - const importTagItem = this.application.items.createTemplateItem(ContentType.Tag, { + const importTagItem = this.application.items.createTemplateItem(ContentType.TYPES.Tag, { title: `Imported on ${currentDate.toLocaleString()}`, expanded: false, iconString: '', references: importedPayloads - .filter((payload) => payload.content_type === ContentType.Note) + .filter((payload) => payload.content_type === ContentType.TYPES.Note) .map((payload) => ({ - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, uuid: payload.uuid, })), }) diff --git a/packages/web/src/javascripts/Controllers/ItemList/ItemListController.spec.ts b/packages/web/src/javascripts/Controllers/ItemList/ItemListController.spec.ts index 93248cc3b..c72fe391b 100644 --- a/packages/web/src/javascripts/Controllers/ItemList/ItemListController.spec.ts +++ b/packages/web/src/javascripts/Controllers/ItemList/ItemListController.spec.ts @@ -1,5 +1,4 @@ -import { SNTag } from '@standardnotes/snjs' -import { ContentType } from '@standardnotes/common' +import { ContentType, SNTag } from '@standardnotes/snjs' import { InternalEventBus } from '@standardnotes/services' import { WebApplication } from '@/Application/WebApplication' import { NavigationController } from '../Navigation/NavigationController' @@ -57,7 +56,7 @@ describe('item list controller', () => { it('should return false first item is file', () => { controller.getFirstNonProtectedItem = jest.fn().mockReturnValue({ - content_type: ContentType.File, + content_type: ContentType.TYPES.File, }) expect(controller.shouldSelectFirstItem(ItemsReloadSource.UserTriggeredTagChange)).toBe(false) @@ -66,7 +65,7 @@ describe('item list controller', () => { it('should return false if selected tag is daily entry', () => { const tag = { isDailyEntry: true, - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, } as jest.Mocked Object.defineProperty(navigationController, 'selected', { @@ -78,7 +77,7 @@ describe('item list controller', () => { it('should return true if user triggered tag change', () => { const tag = { - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, } as jest.Mocked Object.defineProperty(navigationController, 'selected', { @@ -90,7 +89,7 @@ describe('item list controller', () => { it('should return false if not user triggered tag change and there is an existing selected item', () => { const tag = { - content_type: ContentType.Tag, + content_type: ContentType.TYPES.Tag, } as jest.Mocked Object.defineProperty(selectionController, 'selectedUuids', { diff --git a/packages/web/src/javascripts/Controllers/ItemList/ItemListController.ts b/packages/web/src/javascripts/Controllers/ItemList/ItemListController.ts index 43c62c90f..e66b01025 100644 --- a/packages/web/src/javascripts/Controllers/ItemList/ItemListController.ts +++ b/packages/web/src/javascripts/Controllers/ItemList/ItemListController.ts @@ -109,27 +109,33 @@ export class ItemListController extends AbstractViewController implements Intern this.resetPagination() this.disposers.push( - application.streamItems([ContentType.Note, ContentType.File], () => { + application.streamItems([ContentType.TYPES.Note, ContentType.TYPES.File], () => { void this.reloadItems(ItemsReloadSource.ItemStream) }), ) this.disposers.push( - application.streamItems([ContentType.Tag, ContentType.SmartView], async ({ changed, inserted }) => { - const tags = [...changed, ...inserted] + application.streamItems( + [ContentType.TYPES.Tag, ContentType.TYPES.SmartView], + async ({ changed, inserted }) => { + const tags = [...changed, ...inserted] - const { didReloadItems } = await this.reloadDisplayPreferences({ userTriggered: false }) - if (!didReloadItems) { - /** A tag could have changed its relationships, so we need to reload the filter */ - this.reloadNotesDisplayOptions() - void this.reloadItems(ItemsReloadSource.ItemStream) - } + const { didReloadItems } = await this.reloadDisplayPreferences({ userTriggered: false }) + if (!didReloadItems) { + /** A tag could have changed its relationships, so we need to reload the filter */ + this.reloadNotesDisplayOptions() + void this.reloadItems(ItemsReloadSource.ItemStream) + } - if (this.navigationController.selected && findInArray(tags, 'uuid', this.navigationController.selected.uuid)) { - /** Tag title could have changed */ - this.reloadPanelTitle() - } - }), + if ( + this.navigationController.selected && + findInArray(tags, 'uuid', this.navigationController.selected.uuid) + ) { + /** Tag title could have changed */ + this.reloadPanelTitle() + } + }, + ), ) this.disposers.push( diff --git a/packages/web/src/javascripts/Controllers/LinkingController.spec.ts b/packages/web/src/javascripts/Controllers/LinkingController.spec.ts index f8c5fbb2e..8ce8e6ff3 100644 --- a/packages/web/src/javascripts/Controllers/LinkingController.spec.ts +++ b/packages/web/src/javascripts/Controllers/LinkingController.spec.ts @@ -29,7 +29,7 @@ const createNote = (name: string, options?: Partial) => { archived: false, trashed: false, uuid: String(Math.random()), - content_type: ContentType.Note, + content_type: ContentType.TYPES.Note, ...options, } as jest.Mocked } @@ -40,7 +40,7 @@ const createFile = (name: string, options?: Partial) => { archived: false, trashed: false, uuid: String(Math.random()), - content_type: ContentType.File, + content_type: ContentType.TYPES.File, ...options, } as jest.Mocked } diff --git a/packages/web/src/javascripts/Controllers/LinkingController.tsx b/packages/web/src/javascripts/Controllers/LinkingController.tsx index 4fabe89b0..aaabde80a 100644 --- a/packages/web/src/javascripts/Controllers/LinkingController.tsx +++ b/packages/web/src/javascripts/Controllers/LinkingController.tsx @@ -100,7 +100,7 @@ export class LinkingController extends AbstractViewController { const referencingItem = naturalSort(this.application.items.itemsReferencingItem(item).filter(isFile), 'title') - if (item.content_type === ContentType.File) { + if (item.content_type === ContentType.TYPES.File) { return { filesLinkedToItem: referencesOfItem.map((item) => createLinkFromItem(item, 'linked')), filesLinkingToItem: referencingItem.map((item) => createLinkFromItem(item, 'linked-by')), diff --git a/packages/web/src/javascripts/Controllers/Navigation/NavigationController.ts b/packages/web/src/javascripts/Controllers/Navigation/NavigationController.ts index 91902b762..aa05afe4d 100644 --- a/packages/web/src/javascripts/Controllers/Navigation/NavigationController.ts +++ b/packages/web/src/javascripts/Controllers/Navigation/NavigationController.ts @@ -122,7 +122,7 @@ export class NavigationController }) this.disposers.push( - this.application.streamItems([ContentType.Tag, ContentType.SmartView], ({ changed, removed }) => { + this.application.streamItems([ContentType.TYPES.Tag, ContentType.TYPES.SmartView], ({ changed, removed }) => { this.reloadTags() runInAction(() => { @@ -599,7 +599,7 @@ export class NavigationController return } - const newTag = this.application.items.createTemplateItem(ContentType.Tag) as SNTag + const newTag = this.application.items.createTemplateItem(ContentType.TYPES.Tag) as SNTag runInAction(() => { this.selectedLocation = 'all' diff --git a/packages/web/src/javascripts/Controllers/NotesController/NotesController.ts b/packages/web/src/javascripts/Controllers/NotesController/NotesController.ts index 61546410f..cb6783d76 100644 --- a/packages/web/src/javascripts/Controllers/NotesController/NotesController.ts +++ b/packages/web/src/javascripts/Controllers/NotesController/NotesController.ts @@ -119,7 +119,7 @@ export class NotesController extends AbstractViewController implements NotesCont } public get selectedNotes(): SNNote[] { - return this.selectionController.getFilteredSelectedItems(ContentType.Note) + return this.selectionController.getFilteredSelectedItems(ContentType.TYPES.Note) } get firstSelectedNote(): SNNote | undefined { diff --git a/packages/web/src/javascripts/Controllers/SelectedItemsController.ts b/packages/web/src/javascripts/Controllers/SelectedItemsController.ts index c8392940e..f3f3b20f5 100644 --- a/packages/web/src/javascripts/Controllers/SelectedItemsController.ts +++ b/packages/web/src/javascripts/Controllers/SelectedItemsController.ts @@ -94,7 +94,7 @@ export class SelectedItemsController this.disposers.push( this.application.streamItems( - [ContentType.Note, ContentType.File], + [ContentType.TYPES.Note, ContentType.TYPES.File], ({ changed, inserted, removed }) => { runInAction(() => { for (const removedItem of removed) { @@ -121,7 +121,7 @@ export class SelectedItemsController } get selectedFiles(): FileItem[] { - return this.getFilteredSelectedItems(ContentType.File) + return this.getFilteredSelectedItems(ContentType.TYPES.File) } get selectedFilesCount(): number { @@ -137,7 +137,7 @@ export class SelectedItemsController return uuids.map((uuid) => this.application.items.findSureItem(uuid)).filter((item) => !!item) } - getFilteredSelectedItems = (contentType?: ContentType): T[] => { + getFilteredSelectedItems = (contentType?: string): T[] => { return Object.values(this.selectedItems).filter((item) => { return !contentType ? true : item.content_type === contentType }) as T[] @@ -243,9 +243,9 @@ export class SelectedItemsController if (this.selectedItemsCount === 1) { const item = this.firstSelectedItem - if (item.content_type === ContentType.Note) { + if (item.content_type === ContentType.TYPES.Note) { await this.itemListController.openNote(item.uuid) - } else if (item.content_type === ContentType.File) { + } else if (item.content_type === ContentType.TYPES.File) { await this.itemListController.openFile(item.uuid) } diff --git a/packages/web/src/javascripts/Hooks/useItemLinks.ts b/packages/web/src/javascripts/Hooks/useItemLinks.ts index b4c9a4498..8a53cd225 100644 --- a/packages/web/src/javascripts/Hooks/useItemLinks.ts +++ b/packages/web/src/javascripts/Hooks/useItemLinks.ts @@ -17,7 +17,7 @@ export const useItemLinks = (item: DecryptedItem | undefined) => { useEffect( () => - application.streamItems([ContentType.Note, ContentType.File, ContentType.Tag], () => { + application.streamItems([ContentType.TYPES.Note, ContentType.TYPES.File, ContentType.TYPES.Tag], () => { refresh(Date.now()) }), [application], diff --git a/packages/web/src/javascripts/Utils/Items/Search/getSearchResults.ts b/packages/web/src/javascripts/Utils/Items/Search/getSearchResults.ts index 65e9bc91b..c847fd5f1 100644 --- a/packages/web/src/javascripts/Utils/Items/Search/getSearchResults.ts +++ b/packages/web/src/javascripts/Utils/Items/Search/getSearchResults.ts @@ -19,7 +19,7 @@ export function getLinkingSearchResults( application: WebApplicationInterface, activeItem?: LinkableItem, options: { - contentType?: ContentType + contentType?: string returnEmptyIfQueryEmpty?: boolean } = { returnEmptyIfQueryEmpty: true }, ): { @@ -49,7 +49,7 @@ export function getLinkingSearchResults( } const searchableItems = naturalSort( - application.items.getItems([ContentType.Note, ContentType.File, ContentType.Tag]), + application.items.getItems([ContentType.TYPES.Note, ContentType.TYPES.File, ContentType.TYPES.Tag]), 'title', ) @@ -85,19 +85,26 @@ export function getLinkingSearchResults( const limitPerContentType = resultLimitForSearchQuery(searchQuery) if ( - item.content_type === ContentType.Tag && - (!enforceResultLimit || (unlinkedTags.length < limitPerContentType && item.content_type === ContentType.Tag)) + item.content_type === ContentType.TYPES.Tag && + (!enforceResultLimit || + (unlinkedTags.length < limitPerContentType && item.content_type === ContentType.TYPES.Tag)) ) { unlinkedTags.push(item) continue } - if (item.content_type === ContentType.Note && (!enforceResultLimit || unlinkedNotes.length < limitPerContentType)) { + if ( + item.content_type === ContentType.TYPES.Note && + (!enforceResultLimit || unlinkedNotes.length < limitPerContentType) + ) { unlinkedNotes.push(item) continue } - if (item.content_type === ContentType.File && (!enforceResultLimit || unlinkedFiles.length < limitPerContentType)) { + if ( + item.content_type === ContentType.TYPES.File && + (!enforceResultLimit || unlinkedFiles.length < limitPerContentType) + ) { unlinkedFiles.push(item) continue } diff --git a/packages/web/src/javascripts/Utils/Items/Search/isSearchResultExistingTag.ts b/packages/web/src/javascripts/Utils/Items/Search/isSearchResultExistingTag.ts index 375701244..7f4be5d9a 100644 --- a/packages/web/src/javascripts/Utils/Items/Search/isSearchResultExistingTag.ts +++ b/packages/web/src/javascripts/Utils/Items/Search/isSearchResultExistingTag.ts @@ -1,5 +1,5 @@ import { DecryptedItemInterface, ItemContent, ContentType } from '@standardnotes/snjs' export function isSearchResultExistingTag(result: DecryptedItemInterface, searchQuery: string) { - return result.content_type === ContentType.Tag && result.title === searchQuery + return result.content_type === ContentType.TYPES.Tag && result.title === searchQuery } diff --git a/packages/web/src/javascripts/Utils/createEditorMenuGroups.ts b/packages/web/src/javascripts/Utils/createEditorMenuGroups.ts index 6dd5b0c78..b5127714a 100644 --- a/packages/web/src/javascripts/Utils/createEditorMenuGroups.ts +++ b/packages/web/src/javascripts/Utils/createEditorMenuGroups.ts @@ -36,7 +36,7 @@ const insertNonInstalledNativeComponentsInMap = ( application: WebApplication, ): void => { GetFeatures() - .filter((feature) => feature.content_type === ContentType.Component && feature.area === ComponentArea.Editor) + .filter((feature) => feature.content_type === ContentType.TYPES.Component && feature.area === ComponentArea.Editor) .forEach((editorFeature) => { const notInstalled = !components.find((editor) => editor.identifier === editorFeature.identifier) const isExperimental = application.features.isExperimentalFeature(editorFeature.identifier) diff --git a/yarn.lock b/yarn.lock index 554a60aab..f0f69f9ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -3918,8 +3918,8 @@ __metadata: version: 0.0.0-use.local resolution: "@standardnotes/api@workspace:packages/api" dependencies: - "@standardnotes/common": ^1.48.3 - "@standardnotes/domain-core": ^1.12.0 + "@standardnotes/common": ^1.50.0 + "@standardnotes/domain-core": ^1.22.0 "@standardnotes/models": "workspace:*" "@standardnotes/responses": "workspace:*" "@standardnotes/security": ^1.7.6 @@ -4038,12 +4038,12 @@ __metadata: languageName: node linkType: hard -"@standardnotes/common@npm:^1.48.3": - version: 1.48.3 - resolution: "@standardnotes/common@npm:1.48.3" +"@standardnotes/common@npm:^1.50.0": + version: 1.50.0 + resolution: "@standardnotes/common@npm:1.50.0" dependencies: reflect-metadata: ^0.1.13 - checksum: 191d97879d3476af51490f21f23e58daad7a2c7bc3e7a69a78e7ba978b5e17bed86c1f7c3b681d62c1e1665eb1b16c2495f51a2a053ee9fa245a36cdf9092425 + checksum: 5388811ee595732d346fc5333d65aed9270dc406f9a3d4d36a3a9778f075e2f917c356b68d224c6e3e1e3737b1245d888f656405eabb9c647d2d57c3217f90e0 languageName: node linkType: hard @@ -4080,7 +4080,7 @@ __metadata: "@babel/core": "*" "@babel/preset-env": "*" "@electron/remote": ^2.0.9 - "@standardnotes/domain-core": ^1.18.0 + "@standardnotes/domain-core": ^1.22.0 "@standardnotes/electron-clear-data": 1.1.1 "@standardnotes/web": "workspace:*" "@types/fs-extra": ^11.0.1 @@ -4123,7 +4123,7 @@ __metadata: languageName: unknown linkType: soft -"@standardnotes/domain-core@npm:^1.11.3, @standardnotes/domain-core@npm:^1.12.0": +"@standardnotes/domain-core@npm:^1.11.3": version: 1.12.0 resolution: "@standardnotes/domain-core@npm:1.12.0" dependencies: @@ -4132,12 +4132,12 @@ __metadata: languageName: node linkType: hard -"@standardnotes/domain-core@npm:^1.18.0": - version: 1.19.0 - resolution: "@standardnotes/domain-core@npm:1.19.0" +"@standardnotes/domain-core@npm:^1.22.0": + version: 1.22.0 + resolution: "@standardnotes/domain-core@npm:1.22.0" dependencies: uuid: ^9.0.0 - checksum: 40d3cad6d6acc0794249fa24faebc086903bfa3337a60c0dda67ab891a23ab94ab0e69b56bbaae5b7847b0e08283c45bb3c2cec9066ff186843d850dcb4b8b4e + checksum: aaa4812146f7ffcac8ed83bfd370d9dfb58055dea768dd4332a44756cccbb3d1a667da4d6da804fa26d5be594b85c60f3aa9b4c3eebb89805ffdbbfd7444946e languageName: node linkType: hard @@ -4182,8 +4182,9 @@ __metadata: version: 0.0.0-use.local resolution: "@standardnotes/encryption@workspace:packages/encryption" dependencies: - "@standardnotes/common": ^1.48.3 + "@standardnotes/common": ^1.50.0 "@standardnotes/config": 2.4.3 + "@standardnotes/domain-core": ^1.22.0 "@standardnotes/models": "workspace:*" "@standardnotes/responses": "workspace:*" "@standardnotes/sncrypto-common": "workspace:*" @@ -4217,8 +4218,8 @@ __metadata: version: 0.0.0-use.local resolution: "@standardnotes/features@workspace:packages/features" dependencies: - "@standardnotes/common": ^1.48.3 - "@standardnotes/domain-core": ^1.12.0 + "@standardnotes/common": ^1.50.0 + "@standardnotes/domain-core": ^1.22.0 "@standardnotes/security": ^1.7.6 "@types/jest": ^29.2.3 "@typescript-eslint/eslint-plugin": "*" @@ -4235,7 +4236,7 @@ __metadata: version: 0.0.0-use.local resolution: "@standardnotes/filepicker@workspace:packages/filepicker" dependencies: - "@standardnotes/common": ^1.48.3 + "@standardnotes/common": ^1.50.0 "@standardnotes/files": "workspace:*" "@standardnotes/utils": "workspace:*" "@types/jest": ^29.2.3 @@ -4255,7 +4256,7 @@ __metadata: version: 0.0.0-use.local resolution: "@standardnotes/files@workspace:packages/files" dependencies: - "@standardnotes/common": ^1.48.3 + "@standardnotes/common": ^1.50.0 "@standardnotes/encryption": "workspace:*" "@standardnotes/models": "workspace:*" "@standardnotes/responses": "workspace:*" @@ -4422,7 +4423,8 @@ __metadata: version: 0.0.0-use.local resolution: "@standardnotes/models@workspace:packages/models" dependencies: - "@standardnotes/common": ^1.48.3 + "@standardnotes/common": ^1.50.0 + "@standardnotes/domain-core": ^1.22.0 "@standardnotes/features": "workspace:*" "@standardnotes/responses": "workspace:*" "@standardnotes/sncrypto-common": "workspace:^" @@ -4470,7 +4472,7 @@ __metadata: version: 0.0.0-use.local resolution: "@standardnotes/responses@workspace:packages/responses" dependencies: - "@standardnotes/common": ^1.48.3 + "@standardnotes/common": ^1.50.0 "@standardnotes/features": "workspace:*" "@standardnotes/security": ^1.7.6 "@types/jest": ^29.2.3 @@ -4508,8 +4510,8 @@ __metadata: resolution: "@standardnotes/services@workspace:packages/services" dependencies: "@standardnotes/api": "workspace:^" - "@standardnotes/common": ^1.48.3 - "@standardnotes/domain-core": ^1.12.0 + "@standardnotes/common": ^1.50.0 + "@standardnotes/domain-core": ^1.22.0 "@standardnotes/encryption": "workspace:^" "@standardnotes/features": "workspace:^" "@standardnotes/files": "workspace:^" @@ -4608,8 +4610,8 @@ __metadata: "@babel/core": "*" "@babel/preset-env": "*" "@standardnotes/api": "workspace:*" - "@standardnotes/common": ^1.48.3 - "@standardnotes/domain-core": ^1.12.0 + "@standardnotes/common": ^1.50.0 + "@standardnotes/domain-core": ^1.22.0 "@standardnotes/domain-events": ^2.108.1 "@standardnotes/encryption": "workspace:*" "@standardnotes/features": "workspace:*" @@ -4736,7 +4738,8 @@ __metadata: version: 0.0.0-use.local resolution: "@standardnotes/ui-services@workspace:packages/ui-services" dependencies: - "@standardnotes/common": ^1.48.3 + "@standardnotes/common": ^1.50.0 + "@standardnotes/domain-core": ^1.22.0 "@standardnotes/features": "workspace:^" "@standardnotes/filepicker": "workspace:^" "@standardnotes/models": "workspace:^" @@ -4761,7 +4764,7 @@ __metadata: version: 0.0.0-use.local resolution: "@standardnotes/utils@workspace:packages/utils" dependencies: - "@standardnotes/common": ^1.48.3 + "@standardnotes/common": ^1.50.0 "@types/dompurify": ^2.4.0 "@types/jest": ^29.2.3 "@types/jsdom": ^20.0.1