chore: fix ContentType usage (#2353)

* chore: fix ContentType usage

* chore: fix specs
This commit is contained in:
Karol Sójko
2023-07-12 13:53:29 +02:00
committed by GitHub
parent d057cdff84
commit 325737bfbd
247 changed files with 1092 additions and 1060 deletions

View File

@@ -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<Record<string, Element>> = {}
readonly typedMap: Partial<Record<ContentType, Element[]>> = {}
readonly typedMap: Partial<Record<string, Element[]>> = {}
/** An array of uuids of items that are dirty */
dirtyIndex: Set<string> = new Set()
@@ -74,7 +73,7 @@ export abstract class Collection<
constructor(
copy = false,
mapCopy?: Partial<Record<string, Element>>,
typedMapCopy?: Partial<Record<ContentType, Element[]>>,
typedMapCopy?: Partial<Record<string, Element[]>>,
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)

View File

@@ -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

View File

@@ -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<NoteContent>): DecryptedPayload => {
return new DecryptedPayload({
uuid: uuid || String(Math.random()),
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
content: FillItemContent<NoteContent>({
title: 'foo',
...content,

View File

@@ -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<C> | undefined)[]
}
public allDecrypted<T extends DecryptedItemInterface>(contentType: ContentType | ContentType[]): T[] {
public allDecrypted<T extends DecryptedItemInterface>(contentType: string | string[]): T[] {
return this.all(contentType).filter(isDecryptedItem) as T[]
}
}

View File

@@ -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,

View File

@@ -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<Record<string, Set<string>>> = {}
private allCountableItems = new Set<string>()
private countableItemsByType = new Map<ContentType, Set<string>>()
private countableItemsByType = new Map<string, Set<string>>()
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]

View File

@@ -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<T>(
true,
mapCopy,
typedMapCopy as Partial<Record<ContentType, T[]>>,
typedMapCopy as Partial<Record<string, T[]>>,
referenceMapCopy,
conflictMapCopy,
)

View File

@@ -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<ItemsKeyContent>({
uuid: uuid,
content_type: ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
content: FillItemContent<ItemsKeyContent>({
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,

View File

@@ -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()

View File

@@ -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<ItemsKeyContent>({
uuid: '123',
content_type: ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
content: FillItemContent<ItemsKeyContent>({
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,

View File

@@ -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)

View File

@@ -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<NoteContent>({
uuid: '123',
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
dirty: true,
content: FillItemContent<NoteContent>({
title: 'foo',

View File

@@ -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)
}

View File

@@ -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<ItemsKeyContent>({
uuid: '123',
content_type: ContentType.ItemsKey,
content_type: ContentType.TYPES.ItemsKey,
content: FillItemContent<ItemsKeyContent>({
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,

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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 {

View File

@@ -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)
})

View File

@@ -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<I extends DisplayItem, O extends AnyDisplayOp
constructor(
private readonly collection: ReadonlyItemCollection,
public readonly contentTypes: ContentType[],
public readonly contentTypes: string[],
private options: DisplayControllerDisplayOptions & O,
private vaultOptions?: VaultDisplayOptions,
) {

View File

@@ -1,4 +1,4 @@
import { ContentType } from '@standardnotes/common'
import { ContentType } from '@standardnotes/domain-core'
import { SNTag } from '../../../Syncable/Tag'
import { NotesAndFilesDisplayOptions } from '../DisplayOptions'
import { computeFiltersForDisplayOptions } from '../DisplayOptionsToFilters'
@@ -38,7 +38,7 @@ export function itemMatchesQuery(
searchQuery: SearchQuery,
collection: ReferenceLookupCollection,
): boolean {
const itemTags = collection.elementsReferencingElement(itemToMatch, ContentType.Tag) as SNTag[]
const itemTags = collection.elementsReferencingElement(itemToMatch, ContentType.TYPES.Tag) as SNTag[]
const someTagsMatches = itemTags.some((tag) => matchResultForStringQuery(tag, searchQuery.query) !== MatchResult.None)
if (itemToMatch.protected && !searchQuery.includeProtectedNoteText) {

View File

@@ -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)

View File

@@ -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
}

View File

@@ -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)
}

View File

@@ -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,
]
}

View File

@@ -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

View File

@@ -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<string, unknown>, tags?: Tag[]): Note {
return {
...content,
content_type: ContentType.Note,
content_type: ContentType.TYPES.Note,
tags,
} as jest.Mocked<Note>
}
@@ -40,7 +40,7 @@ function createNote(content: Record<string, unknown>, tags?: Tag[]): Note {
function createTag(title: string): Tag {
return {
title,
content_type: ContentType.Tag,
content_type: ContentType.TYPES.Tag,
} as jest.Mocked<Tag>
}
@@ -48,7 +48,7 @@ function createItem(content: Record<string, unknown>, updatedAt?: Date): Item {
return {
...content,
updated_at: updatedAt,
content_type: ContentType.Any,
content_type: ContentType.TYPES.Any,
} as jest.Mocked<Note>
}
@@ -100,7 +100,7 @@ describe('predicates', () => {
expect(
compoundPredicateFromArguments<Note>('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<Note>('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<Note>('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<Note>('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<Note>('title', '=', title),
new Predicate('content_type', '=', ContentType.Note),
new Predicate('content_type', '=', ContentType.TYPES.Note),
])
expect(compoundProd.matchesItem(item)).toEqual(true)
})