import { EventSubscriber, FileData, Operation } from '@verdant-web/common'; import { ContextInit } from '../context/context.js'; import { DocumentManager } from '../entities/DocumentManager.js'; import { EntityStore } from '../entities/EntityStore.js'; import { ExportedData } from '../persistence/interfaces.js'; import { CollectionQueries } from '../queries/CollectionQueries.js'; import { PublicQueryCacheAPI } from '../queries/QueryCache.js'; import { Sync } from '../sync/Sync.js'; export type ClientWithCollections = Client & { [key: string]: CollectionQueries; }; export declare class Client extends EventSubscriber<{ /** * Called when a change from a future version of the application has * been witnessed. These changes are not applied but it indicates * the app has been updated and a peer is using a newer version. * You should listen to this event and prompt the user to reload * their client, or reload it for them. * * This event may be called multiple times. */ futureSeen: () => void; /** * The server requested this replica reset its state * completely. This can happen when the replica has * been offline for too long and reconnects. */ resetToServer: () => void; /** * These are errors that, as a developer, you should subscribe to * and prompt users to contact you for resolution. Usually these errors * indicate the client is in an unrecoverable state. */ developerError: (err: Error) => void; /** * Listen for operations as they are applied to the database. * Wouldn't recommend using this unless you know what you're doing. * It's a very hot code path... */ operation: (operation: Operation) => void; /** * Emitted when storage rebases history. This should never actually affect application behavior * or stored data, but is useful for debugging and testing. */ rebase: () => void; /** * Emitted when a file is stored locally. Used for test coordination right now. */ fileSaved: (fileData: FileData) => void; }> { private contextInit; private _entities; private _queryCache; private _documentManager; private _fileManager; private context; readonly collectionNames: string[]; private _sync; constructor(contextInit: ContextInit); private importingPromise; private addData; get schema(): import("@verdant-web/common").StorageSchema; get namespace(): string; get undoHistory(): import("../UndoHistory.js").UndoHistory; get queries(): PublicQueryCacheAPI; get sync(): Sync; get entities(): EntityStore; get documentManager(): DocumentManager; getReplicaId(): Promise; /** * Batch multiple operations together to be executed in a single transaction. * The changes made will not be included in the same undo history step as * any other changes made outside of the batch. You can also disable undo * for your batch to omit changes from undo history. * * Provide a batch name to apply multiple changes to the same batch * across different invocations. Batches will automatically flush after * a short delay or if they reach a maximum size. */ get batch(): ({ undoable, batchName, max, timeout, }?: { undoable?: boolean; batchName?: string; max?: number | null; timeout?: number | null; }) => import("../entities/OperationBatcher.js").OperationBatch; stats: () => Promise; close: () => Promise; __dangerous__resetLocal: () => Promise; export: ({ downloadRemoteFiles }?: { downloadRemoteFiles?: boolean; }) => Promise; import: ({ data, fileData, files }: ExportedData) => Promise; /** * Export all data, then re-import it. This might resolve * some issues with the local database, but it should * only be done as a second-to-last resort. The last resort * would be __dangerous__resetLocal, which * clears all local data. * * Unlike __dangerous__resetLocal, this method allows local-only * clients to recover data, whereas __dangerous__resetLocal only * lets networked clients recover from the server. */ __dangerous__hardReset: () => Promise; /** * Immediately runs the file deletion process. This is useful * for testing, mostly. Or if your client is long-lived, since * normally this cleanup only runs on startup. * * Note this still follows the file deletion heuristic configured * on the client. So if you clean up files 3 days after delete, * invoking this manually will not skip that 3 day waiting period. */ __cleanupFilesImmediately: () => Promise; /** * Manually triggers storage rebasing. Follows normal * rebasing rules. Rebases already happen automatically * during normal operation, so you probably don't need this. */ __manualRebase: () => Promise; /** * WARNING: the internal functions of the persistence layer * are not guaranteed and cannot be relied upon for application * behavior. They are subject to change without notice. */ get __persistence(): { meta: Promise; queries: Promise; files: Promise; }; get __persistenceReady(): Promise; } export interface ClientStats { collections: Record; meta: { baselinesSize: { count: number; size: number; }; operationsSize: { count: number; size: number; }; }; files: { size: { count: number; size: number; }; }; storage: StorageEstimate | undefined; totalMetaSize: number; totalCollectionsSize: number; metaToDataRatio: number; quotaUsage: number | undefined; }