/** * Helper functions for accessing the RxStorage instances. */ import type { BulkWriteRow, BulkWriteRowProcessed, CategorizeBulkWriteRowsOutput, RxAttachmentData, RxAttachmentWriteData, RxCollection, RxDatabase, RxDocumentData, RxDocumentWriteData, RxJsonSchema, RxStorageWriteError, RxStorageInstance, RxStorageInstanceCreationParams, StringKeys, RxStorage, FilledMangoQuery, RxStorageBulkWriteResponse } from './types/index.d.ts'; import { Observable } from 'rxjs'; export declare const INTERNAL_STORAGE_NAME = "_rxdb_internal"; export declare const RX_DATABASE_LOCAL_DOCS_STORAGE_NAME = "rxdatabase_storage_local"; /** * Context string used by RxCollection.bulkInsert(). * Documents written with this context are already cloned * by fillObjectDataBeforeInsert(), so the wrapped storage * can safely mutate them in place instead of cloning again. */ export declare const RX_COLLECTION_BULK_INSERT_CONTEXT = "rx-collection-bulk-insert"; /** * Register a bulkWrite context string as "mutable", * meaning the caller guarantees that insert documents * are already cloned and safe to mutate in place. * This allows the wrapped storage to skip a redundant * flatClone() call on the insert hot path. */ export declare function registerMutableWriteContext(context: string): void; export declare function getSingleDocument(storageInstance: RxStorageInstance, documentId: string): Promise | undefined>; /** * Writes a single document, * throws RxStorageBulkWriteError on failure */ export declare function writeSingle(instance: RxStorageInstance, writeRow: BulkWriteRow, context: string): Promise>; /** * Observe the plain document data of a single document. * Do not forget to unsubscribe. */ export declare function observeSingle(storageInstance: RxStorageInstance, documentId: string): Observable>; /** * Checkpoints must be stackable over another. * This is required form some RxStorage implementations * like the sharding plugin, where a checkpoint only represents * the document state from some, but not all shards. */ export declare function stackCheckpoints(checkpoints: (CheckpointType | undefined)[]): CheckpointType; export declare function throwIfIsStorageWriteError(collection: RxCollection, documentId: string, writeData: RxDocumentWriteData | RxDocType, error: RxStorageWriteError | undefined): void; /** * Analyzes a list of BulkWriteRows and determines * which documents must be inserted, updated or deleted * and which events must be emitted and which documents cause a conflict * and must not be written. * Used as helper inside of some RxStorage implementations. * @hotPath The performance of this function is critical */ export declare function categorizeBulkWriteRows(storageInstance: RxStorageInstance, primaryPath: StringKeys, /** * Current state of the documents * inside of the storage. Used to determine * which writes cause conflicts. * This must be a Map for better performance. */ docsInDb: Map[StringKeys] | string, RxDocumentData>, /** * The write rows that are passed to * RxStorageInstance().bulkWrite(). */ bulkWriteRows: BulkWriteRow[], context: string, /** * Used by some storages for better performance. * For example when get-by-id and insert/update can run in parallel. */ onInsert?: (docData: RxDocumentData) => void, onUpdate?: (docData: RxDocumentData) => void): CategorizeBulkWriteRowsOutput; export declare function stripAttachmentsDataFromRow(writeRow: BulkWriteRow): BulkWriteRowProcessed; /** * Used in custom RxStorage implementations. */ export declare function attachmentWriteDataToNormalData(writeData: RxAttachmentData | RxAttachmentWriteData): RxAttachmentData; export declare function stripAttachmentsDataFromDocument(doc: RxDocumentWriteData): RxDocumentData; /** * Flat clone the document data * and also the _meta field. * Used many times when we want to change the meta * during replication etc. */ export declare function flatCloneDocWithMeta(doc: RxDocumentData): RxDocumentData; export type WrappedRxStorageInstance = RxStorageInstance & { originalStorageInstance: RxStorageInstance; }; /** * Wraps the normal storageInstance of a RxCollection * to ensure that all access is properly using the hooks * and other data transformations and also ensure that database.lockedRun() * is used properly. */ export declare function getWrappedStorageInstance(database: RxDatabase<{}, Internals, InstanceCreationOptions, any>, storageInstance: RxStorageInstance, /** * The original RxJsonSchema * before it was mutated by hooks. */ rxJsonSchema: RxJsonSchema>): WrappedRxStorageInstance; /** * Each RxStorage implementation should * run this method at the first step of createStorageInstance() * to ensure that the configuration is correct. */ export declare function ensureRxStorageInstanceParamsAreCorrect(params: RxStorageInstanceCreationParams): void; export declare function hasEncryption(jsonSchema: RxJsonSchema): boolean; export declare function getChangedDocumentsSinceQuery(storageInstance: RxStorageInstance, limit: number, checkpoint?: CheckpointType): FilledMangoQuery; export declare function getChangedDocumentsSince(storageInstance: RxStorageInstance, limit: number, checkpoint?: CheckpointType): Promise<{ documents: RxDocumentData[]; /** * The checkpoint contains data so that another * call to getChangedDocumentsSince() will continue * from exactly the last document that was returned before. */ checkpoint: CheckpointType; }>; /** * For better performance, this is done only when accessed * because most of the time we do not need the results, only the errors. */ export declare function getWrittenDocumentsFromBulkWriteResponse(primaryPath: string, writeRows: BulkWriteRow[], response: RxStorageBulkWriteResponse, reInsertIds?: Set): RxDocumentData[]; /** * Wraps the storage and simluates * delays. Mostly used in tests. */ export declare function randomDelayStorage(input: { storage: RxStorage; delayTimeBefore: () => number; delayTimeAfter: () => number; }): RxStorage;