feat: add models package
This commit is contained in:
@@ -0,0 +1,6 @@
|
||||
import { ItemContent } from '../../Content/ItemContent'
|
||||
import { TransferPayload } from './TransferPayload'
|
||||
|
||||
export interface DecryptedTransferPayload<C extends ItemContent = ItemContent> extends TransferPayload {
|
||||
content: C
|
||||
}
|
||||
@@ -0,0 +1,6 @@
|
||||
import { TransferPayload } from './TransferPayload'
|
||||
|
||||
export interface DeletedTransferPayload extends TransferPayload {
|
||||
content: undefined
|
||||
deleted: true
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { TransferPayload } from './TransferPayload'
|
||||
|
||||
export interface EncryptedTransferPayload extends TransferPayload {
|
||||
content: string
|
||||
enc_item_key: string
|
||||
items_key_id: string | undefined
|
||||
errorDecrypting: boolean
|
||||
waitingForKey: boolean
|
||||
/** @deprecated */
|
||||
auth_hash?: string
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
import { ContentType, Uuid } from '@standardnotes/common'
|
||||
import { ItemContent } from '../../Content/ItemContent'
|
||||
|
||||
export interface TransferPayload<C extends ItemContent = ItemContent> {
|
||||
uuid: Uuid
|
||||
content_type: ContentType
|
||||
content: C | string | undefined
|
||||
deleted?: boolean
|
||||
|
||||
updated_at: Date
|
||||
created_at: Date
|
||||
created_at_timestamp: number
|
||||
updated_at_timestamp: number
|
||||
|
||||
dirtyIndex?: number
|
||||
globalDirtyIndexAtLastSync?: number
|
||||
dirty?: boolean
|
||||
|
||||
lastSyncBegan?: Date
|
||||
lastSyncEnd?: Date
|
||||
|
||||
duplicate_of?: Uuid
|
||||
}
|
||||
@@ -0,0 +1,28 @@
|
||||
import { isObject, isString } from '@standardnotes/utils'
|
||||
import { DecryptedTransferPayload } from './DecryptedTransferPayload'
|
||||
import { DeletedTransferPayload } from './DeletedTransferPayload'
|
||||
import { EncryptedTransferPayload } from './EncryptedTransferPayload'
|
||||
import { TransferPayload } from './TransferPayload'
|
||||
|
||||
export type FullyFormedTransferPayload = DecryptedTransferPayload | EncryptedTransferPayload | DeletedTransferPayload
|
||||
|
||||
export function isDecryptedTransferPayload(payload: TransferPayload): payload is DecryptedTransferPayload {
|
||||
return isObject(payload.content)
|
||||
}
|
||||
|
||||
export function isEncryptedTransferPayload(payload: TransferPayload): payload is EncryptedTransferPayload {
|
||||
return 'content' in payload && isString(payload.content)
|
||||
}
|
||||
|
||||
export function isErrorDecryptingTransferPayload(payload: TransferPayload): payload is EncryptedTransferPayload {
|
||||
return isEncryptedTransferPayload(payload) && payload.errorDecrypting === true
|
||||
}
|
||||
|
||||
export function isDeletedTransferPayload(payload: TransferPayload): payload is DeletedTransferPayload {
|
||||
return 'deleted' in payload && payload.deleted === true
|
||||
}
|
||||
|
||||
export function isCorruptTransferPayload(payload: TransferPayload): boolean {
|
||||
const invalidDeletedState = payload.deleted === true && payload.content != undefined
|
||||
return payload.uuid == undefined || invalidDeletedState
|
||||
}
|
||||
@@ -0,0 +1,5 @@
|
||||
export * from './Interfaces/DecryptedTransferPayload'
|
||||
export * from './Interfaces/DeletedTransferPayload'
|
||||
export * from './Interfaces/EncryptedTransferPayload'
|
||||
export * from './Interfaces/TransferPayload'
|
||||
export * from './Interfaces/TypeCheck'
|
||||
Reference in New Issue
Block a user