import { Observable } from 'rxjs'; import { RxCollection, } from 'nxdb-old/src/types/rx-collection'; import { RxAttachment, RxAttachmentCreator } from 'nxdb-old/src/types/rx-attachment'; import { RxDocumentData, WithDeleted } from 'nxdb-old/src/types/rx-storage'; import { RxChangeEvent } from 'nxdb-old/src/types/rx-change-event'; import { DeepReadonly, MaybePromise, PlainJsonValue } from 'nxdb-old/src/types/util'; import { UpdateQuery } from 'nxdb-old/src/types/plugins/update'; import { CRDTEntry } from 'nxdb-old/src/types/plugins/crdt'; export type RxDocument = RxDocumentBase & RxDocumentType & OrmMethods; /** * The public facing modify update function. * It only gets the document parts as input, that * are mutateable by the user. */ export type ModifyFunction = ( doc: WithDeleted ) => MaybePromise> | MaybePromise; /** * Meta data that is attached to each document by NxDB. */ export type RxDocumentMeta = { /** * Last write time. * Unix epoch in milliseconds. */ lwt: number; /** * Any other value can be attached to the _meta data. * Mostly done by plugins to mark documents. */ [k: string]: PlainJsonValue; }; export declare interface RxDocumentBase { isInstanceOfRxDocument: true; collection: RxCollection; readonly deleted: boolean; readonly $: Observable>; readonly deleted$: Observable; readonly primary: string; readonly allAttachments$: Observable[]>; // internal things _data: RxDocumentData; primaryPath: string; revision: string; /** * Used to de-duplicate the enriched property objects * of the document. */ _propertyCache: Map; $emit(cE: RxChangeEvent): void; _saveData(newData: any, oldData: any): Promise>; // /internal things // Returns the latest state of the document getLatest(): RxDocument; get$(path: string): Observable; get(objPath: string): DeepReadonly; populate(objPath: string): Promise | any | null>; /** * mutate the document with a function */ modify(mutationFunction: ModifyFunction, context?: string): Promise>; incrementalModify(mutationFunction: ModifyFunction, context?: string): Promise>; /** * patches the given properties */ patch(patch: Partial): Promise>; incrementalPatch(patch: Partial): Promise>; update(updateObj: UpdateQuery): Promise>; incrementalUpdate(updateObj: UpdateQuery): Promise>; updateCRDT(updateObj: CRDTEntry | CRDTEntry[]): Promise>; remove(): Promise>; incrementalRemove(): Promise>; // only for temporary documents set(objPath: string, value: any): RxDocument; save(): Promise; // attachments putAttachment( creator: RxAttachmentCreator ): Promise>; getAttachment(id: string): RxAttachment | null; allAttachments(): RxAttachment[]; toJSON(withRevAndAttachments: true): DeepReadonly>; toJSON(withRevAndAttachments?: false): DeepReadonly; toMutableJSON(withRevAndAttachments: true): RxDocumentData; toMutableJSON(withRevAndAttachments?: false): RxDocType; destroy(): void; }