import { Observable } from 'rxjs'; import type { RxCollection, } from './rx-collection.d.ts'; import type { RxAttachment, RxAttachmentCreator, RxAttachmentCreatorBase64 } from './rx-attachment.d.ts'; import type { RxDocumentData, WithDeleted } from './rx-storage.d.ts'; import type { RxChangeEvent } from './rx-change-event.d.ts'; import type { DeepReadonly, MaybePromise, PlainJsonValue } from './util.d.ts'; import type { UpdateQuery } from './plugins/update.d.ts'; import type { CRDTEntry } from './plugins/crdt.d.ts'; import type { Reactified } from './plugins/reactivity.d.ts'; export type RxDocument = RxDocumentBase< RxDocumentType, OrmMethods, Reactivity > & RxDocumentType & OrmMethods & ExtendObservables & ExtendReactivity; /** * Extend the base properties by the property$ fields * so it knows that RxDocument.age also has RxDocument.age$ which is * an observable. * TODO how to do this for the nested fields? */ type ExtendObservables = { [P in keyof RxDocumentType as `${string & P}$`]: Observable; }; type ExtendReactivity = { [P in keyof RxDocumentType as `${string & P}$$`]: Reactified; }; /** * 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 RxDB. */ export type RxDocumentMeta = { /** * Last write time. * Unix epoch in milliseconds. */ lwt: number; /** * The replication plugins "tags" the origin * of writes to later know if a write came from * the replication or was done locally. */ o?: { hash: string; _rev: number; }; /** * Any other value can be attached to the _meta data. * Mostly done by plugins to mark documents. */ [k: string]: PlainJsonValue | undefined; }; export declare interface RxDocumentBase { isInstanceOfRxDocument: true; collection: RxCollection; readonly deleted: boolean; readonly $: Observable>; readonly $$: Reactified>; readonly deleted$: Observable; readonly deleted$$: Reactified; 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. Lazily initialized on first property access. */ _propertyCache: Map | undefined; $emit(cE: RxChangeEvent): void; _saveData(newData: any, oldData: RxDocumentData): Promise>; // /internal things // Returns the latest state of the document getLatest(): RxDocument; get$(path: string): Observable; get$$(path: string): Reactified; 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>; putAttachmentBase64( creator: RxAttachmentCreatorBase64 ): Promise>; putAttachments( creators: 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; close(): void; }