import type { RxChangeEvent, RxDocument, RxDocumentData } from './types'; import { Observable } from 'rxjs'; declare type CacheItem = { /** * Store the different document states of time * based on their revision height. * We store WeakRefs so that we can later clean up * document states that are no longer needed. */ documentByRevisionHeight: Map>>; /** * Store the latest known document state. * As long as any state of the document is in the cache, * we observe the changestream and update the latestDoc accordingly. * This makes it easier to optimize performance on other parts * because for each known document we can always get the current state * in the storage. * Also it makes it possible to call RxDocument.latest() in a non-async way * to retrieve the latest document state or to observe$ some property. * * To not prevent the whole cacheItem from being garbage collected, * we store only the document data here, but not the RxDocument. */ latestDoc: RxDocumentData; }; /** * The DocumentCache stores RxDocument objects * by their primary key and revision. * This is useful on client side applications where * it is not known how much memory can be used, so * we de-duplicate RxDocument states to save memory. * To not fill up the memory with old document states, the DocumentCache * only contains weak references to the RxDocuments themself. * @link https://caniuse.com/?search=weakref */ export declare class DocumentCache { readonly primaryPath: string; readonly changes$: Observable>; /** * A method that can create a RxDocument by the given document data. */ documentCreator: (docData: RxDocumentData) => RxDocument; cacheItemByDocId: Map>; /** * Some JavaScript runtimes like QuickJS, * so not have a FinalizationRegistry or WeakRef. * Therefore we need a workaround which might waste a lot of memory, * but at least works. */ private registry?; constructor(primaryPath: string, changes$: Observable>, /** * A method that can create a RxDocument by the given document data. */ documentCreator: (docData: RxDocumentData) => RxDocument); /** * Get the RxDocument from the cache * and create a new one if not exits before. */ getCachedRxDocument(docData: RxDocumentData): RxDocument; /** * Throws if not exists */ getLatestDocumentData(docId: string): RxDocumentData; getLatestDocumentDataIfExists(docId: string): RxDocumentData | undefined; } export {};