chore: fix ContentType usage (#2353)
* chore: fix ContentType usage * chore: fix specs
This commit is contained in:
@@ -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
|
||||
}>
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { ItemContent } from './../Content/ItemContent'
|
||||
import { ContentType } from '@standardnotes/common'
|
||||
|
||||
export type OutgoingItemMessagePayload<C extends ItemContent = ItemContent> = {
|
||||
uuid: string
|
||||
content_type: ContentType
|
||||
content_type: string
|
||||
created_at: Date
|
||||
updated_at: Date
|
||||
deleted?: boolean
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { ContentType } from '@standardnotes/common'
|
||||
import { ItemContent } from '../Content/ItemContent'
|
||||
|
||||
export interface ContextPayload<C extends ItemContent = ItemContent> {
|
||||
uuid: string
|
||||
content_type: ContentType
|
||||
content_type: string
|
||||
content: C | string | undefined
|
||||
deleted: boolean
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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<P extends PayloadInterface = PayloadInterface>
|
||||
return this.payload.uuid
|
||||
}
|
||||
|
||||
get content_type(): ContentType {
|
||||
get content_type(): string {
|
||||
return this.payload.content_type
|
||||
}
|
||||
|
||||
|
||||
@@ -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<P extends PayloadInterface = PayloadInterface> {
|
||||
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
|
||||
|
||||
@@ -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<T extends TransferPayload<C>, 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
|
||||
|
||||
|
||||
@@ -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<T extends TransferPayload = TransferPayload, C extends ItemContent = ItemContent> {
|
||||
readonly source: PayloadSource
|
||||
readonly uuid: string
|
||||
readonly content_type: ContentType
|
||||
readonly content_type: string
|
||||
content: C | string | undefined
|
||||
deleted: boolean
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -1,10 +1,9 @@
|
||||
import { ContentType } from '@standardnotes/common'
|
||||
import { ItemContent } from '../../Content/ItemContent'
|
||||
import { PersistentSignatureData } from '../../../Runtime/Encryption/PersistentSignatureData'
|
||||
|
||||
export interface TransferPayload<C extends ItemContent = ItemContent> {
|
||||
uuid: string
|
||||
content_type: ContentType
|
||||
content_type: string
|
||||
content: C | string | undefined
|
||||
deleted?: boolean
|
||||
|
||||
|
||||
@@ -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(),
|
||||
}),
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user