feat: add models package

This commit is contained in:
Karol Sójko
2022-07-05 20:47:11 +02:00
parent 60d1554ff7
commit b614c71e79
199 changed files with 8772 additions and 22 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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