feat: add models package
This commit is contained in:
@@ -0,0 +1,15 @@
|
||||
import { Uuid } from '@standardnotes/common'
|
||||
import { DecryptedTransferPayload } from './../../TransferPayload/Interfaces/DecryptedTransferPayload'
|
||||
import { ItemContent } from '../../Content/ItemContent'
|
||||
import { ContentReference } from '../../Reference/ContentReference'
|
||||
import { PayloadInterface } from './PayloadInterface'
|
||||
|
||||
export interface DecryptedPayloadInterface<C extends ItemContent = ItemContent>
|
||||
extends PayloadInterface<DecryptedTransferPayload> {
|
||||
readonly content: C
|
||||
deleted: false
|
||||
|
||||
ejected(): DecryptedTransferPayload<C>
|
||||
get references(): ContentReference[]
|
||||
getReference(uuid: Uuid): ContentReference
|
||||
}
|
||||
@@ -0,0 +1,15 @@
|
||||
import { DeletedTransferPayload } from '../../TransferPayload'
|
||||
import { PayloadInterface } from './PayloadInterface'
|
||||
|
||||
export interface DeletedPayloadInterface extends PayloadInterface<DeletedTransferPayload> {
|
||||
readonly deleted: true
|
||||
readonly content: undefined
|
||||
|
||||
/**
|
||||
* Whether a payload can be discarded and removed from storage.
|
||||
* This value is true if a payload is marked as deleted and not dirty.
|
||||
*/
|
||||
discardable: boolean | undefined
|
||||
|
||||
ejected(): DeletedTransferPayload
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
import { ProtocolVersion } from '@standardnotes/common'
|
||||
import { EncryptedTransferPayload } from '../../TransferPayload/Interfaces/EncryptedTransferPayload'
|
||||
import { PayloadInterface } from './PayloadInterface'
|
||||
|
||||
export interface EncryptedPayloadInterface extends PayloadInterface<EncryptedTransferPayload> {
|
||||
readonly content: string
|
||||
readonly deleted: false
|
||||
readonly enc_item_key: string
|
||||
readonly items_key_id: string | undefined
|
||||
readonly errorDecrypting: boolean
|
||||
readonly waitingForKey: boolean
|
||||
readonly version: ProtocolVersion
|
||||
|
||||
/** @deprecated */
|
||||
readonly auth_hash?: string
|
||||
|
||||
ejected(): EncryptedTransferPayload
|
||||
}
|
||||
@@ -0,0 +1,41 @@
|
||||
import { SyncResolvedParams, SyncResolvedPayload } from './../../../Runtime/Deltas/Utilities/SyncResolvedPayload'
|
||||
import { ContentType, Uuid } from '@standardnotes/common'
|
||||
import { ItemContent } from '../../Content/ItemContent'
|
||||
import { TransferPayload } from '../../TransferPayload/Interfaces/TransferPayload'
|
||||
import { PayloadSource } from '../Types/PayloadSource'
|
||||
|
||||
export interface PayloadInterface<T extends TransferPayload = TransferPayload, C extends ItemContent = ItemContent> {
|
||||
readonly source: PayloadSource
|
||||
readonly uuid: Uuid
|
||||
readonly content_type: ContentType
|
||||
content: C | string | undefined
|
||||
deleted: boolean
|
||||
|
||||
/** updated_at is set by the server only, and not the client.*/
|
||||
readonly updated_at: Date
|
||||
readonly created_at: Date
|
||||
readonly created_at_timestamp: number
|
||||
readonly updated_at_timestamp: number
|
||||
get serverUpdatedAt(): Date
|
||||
get serverUpdatedAtTimestamp(): number
|
||||
|
||||
readonly dirtyIndex?: number
|
||||
readonly globalDirtyIndexAtLastSync?: number
|
||||
readonly dirty?: boolean
|
||||
|
||||
readonly lastSyncBegan?: Date
|
||||
readonly lastSyncEnd?: Date
|
||||
|
||||
readonly duplicate_of?: Uuid
|
||||
|
||||
/**
|
||||
* "Ejected" means a payload for
|
||||
* generic, non-contextual consumption, such as saving to a backup file or syncing
|
||||
* with a server.
|
||||
*/
|
||||
ejected(): TransferPayload
|
||||
|
||||
copy(override?: Partial<T>, source?: PayloadSource): this
|
||||
|
||||
copyAsSyncResolved(override?: Partial<T> & SyncResolvedParams, source?: PayloadSource): SyncResolvedPayload
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
import { ItemContent } from '../../Content/ItemContent'
|
||||
import {
|
||||
isDecryptedTransferPayload,
|
||||
isDeletedTransferPayload,
|
||||
isEncryptedTransferPayload,
|
||||
isErrorDecryptingTransferPayload,
|
||||
} from '../../TransferPayload'
|
||||
import { DecryptedPayloadInterface } from './DecryptedPayload'
|
||||
import { DeletedPayloadInterface } from './DeletedPayload'
|
||||
import { EncryptedPayloadInterface } from './EncryptedPayload'
|
||||
import { PayloadInterface } from './PayloadInterface'
|
||||
|
||||
export function isDecryptedPayload<C extends ItemContent = ItemContent>(
|
||||
payload: PayloadInterface,
|
||||
): payload is DecryptedPayloadInterface<C> {
|
||||
return isDecryptedTransferPayload(payload)
|
||||
}
|
||||
|
||||
export function isEncryptedPayload(payload: PayloadInterface): payload is EncryptedPayloadInterface {
|
||||
return isEncryptedTransferPayload(payload)
|
||||
}
|
||||
|
||||
export function isDeletedPayload(payload: PayloadInterface): payload is DeletedPayloadInterface {
|
||||
return isDeletedTransferPayload(payload)
|
||||
}
|
||||
|
||||
export function isErrorDecryptingPayload(payload: PayloadInterface): payload is EncryptedPayloadInterface {
|
||||
return isErrorDecryptingTransferPayload(payload)
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
import { ItemContent } from '../../Content/ItemContent'
|
||||
import { DecryptedPayloadInterface } from './DecryptedPayload'
|
||||
import { DeletedPayloadInterface } from './DeletedPayload'
|
||||
import { EncryptedPayloadInterface } from './EncryptedPayload'
|
||||
|
||||
export type FullyFormedPayloadInterface<C extends ItemContent = ItemContent> =
|
||||
| DecryptedPayloadInterface<C>
|
||||
| EncryptedPayloadInterface
|
||||
| DeletedPayloadInterface
|
||||
|
||||
export type AnyNonDecryptedPayloadInterface = EncryptedPayloadInterface | DeletedPayloadInterface
|
||||
Reference in New Issue
Block a user