UNPKG

@casual-simulation/aux-common

Version:
81 lines 3.07 kB
import type { Doc } from 'yjs'; import type { Observable } from 'rxjs'; export declare const PREFERRED_TRIM_SIZE = 500; export type ApplyUpdatesCallback = (updatesStore: IDBObjectStore) => void; export declare const fetchUpdates: (idbPersistence: YjsIndexedDBPersistence, beforeApplyUpdatesCallback?: ApplyUpdatesCallback, afterApplyUpdatesCallback?: ApplyUpdatesCallback) => Promise<IDBObjectStore>; export declare const storeState: (idbPersistence: YjsIndexedDBPersistence, forceStore?: boolean) => Promise<void>; export declare const clearDocument: (name: string) => Promise<any>; export interface YjsIndexedDBPersistenceOptions { /** * The ID of the persistence instance. */ id?: string; /** * Whether to broadcast the changes using a broadcast channel. * The channel name is always formatted as `yjs/${name}`. * * Defaults to false. */ broadcastChanges?: boolean; } /** * Defines a class that is able to persist a Yjs document to IndexedDB. */ export declare class YjsIndexedDBPersistence { private _doc; private _name; private _dbref; private _dbsize; private _destroyed; private _db; private _storeTimeout; private _storeTimeoutId; private _onSyncChanged; private _channel; private _whenSynced; private _encryptionKey; private _id; private _initPromise; db: IDBDatabase; get whenSynced(): Promise<void>; get storeTimeout(): number; set storeTimeout(val: number); get onSyncChanged(): Observable<boolean>; get synced(): boolean; get destroyed(): boolean; get doc(): Doc; get dbref(): number; set dbref(val: number); get dbsize(): number; set dbsize(val: number); constructor(name: string, doc: Doc, options?: YjsIndexedDBPersistenceOptions); waitForInit(): Promise<void>; private _initDb; private _fetchUpdates; private _storeUpdate; destroy(): Promise<void>; /** * Destroys this instance and removes all data from indexeddb. */ clearData(): Promise<void>; /** * Retrieves a value from the IndexedDB database. * @param key - The key of the value to retrieve. * @returns A promise that resolves with the retrieved value. */ get(key: string | number | ArrayBuffer | Date): Promise<string | number | ArrayBuffer | Date | any>; /** * Sets a value in the IndexedDB database. * @param key The key to use for the value. Can be a string, number, ArrayBuffer, or Date. * @param value The value to store in the database. * @returns A Promise that resolves when the value has been successfully stored. */ set(key: string | number | ArrayBuffer | Date, value: any): Promise<any>; /** * Deletes the value associated with the given key from the custom store. * @param key The key of the value to delete. * @returns A promise that resolves when the value has been deleted. */ del(key: string | number | ArrayBuffer | Date): Promise<void>; } //# sourceMappingURL=YjsIndexedDBPersistence.d.ts.map