import { CacheDriverInterface, IndexedDBCacheRecord, IndexedDBDriverOptions } from "../types.mjs"; //#region ../cache/src/drivers/IndexedDBDriver.d.ts /** * Defaults for the IndexedDB driver. * * Exported so a consumer can reuse the same database from their own * tooling (a "clear all caches" button, a devtools panel) without * hard-coding the strings. */ declare const DEFAULT_INDEXED_DB_NAME = "mongez-cache"; declare const DEFAULT_INDEXED_DB_STORE = "cache"; declare const DEFAULT_INDEXED_DB_VERSION = 1; /** * IndexedDB cache driver — opt-in. * * Unlike the Web Storage drivers this one is never wired up for you: * opening a database is a side effect, and a package import should not * create one. Pass an instance explicitly: * * ```ts * setCacheConfigurations({ driver: new IndexedDBDriver() }); * ``` * * Storage layout: a single object store with out-of-line keys, where the * key is the (prefixed) cache key and the record is * `{ value, expiresAt }`. Values go through the structured clone * algorithm, so `Date`, `Map`, `Set`, `ArrayBuffer` and friends survive * a round-trip untouched — no JSON pass by default. Values that are not * cloneable (functions, class instances with methods, DOM nodes) are * rejected by the browser; give the driver a `setValueConverter` / * `setValueParser` pair if you need to serialize those yourself. * * Why IndexedDB is not the default: it is asynchronous, per-origin * quota'd, and unavailable during server-side rendering, while * localStorage is present in every browser context the other drivers * already support. Consumers who need more than the ~5MB Web Storage * budget, or structured values, opt in. */ declare class IndexedDBDriver implements CacheDriverInterface { /** * Prefix key */ prefixKey: string; /** * Database name */ readonly databaseName: string; /** * Object store name */ readonly storeName: string; /** * Database version */ readonly version: number; /** * Migration hook */ protected readonly onUpgrade?: IndexedDBDriverOptions["onUpgrade"]; /** * The memoized open-database promise * * Every operation awaits this one promise, so N concurrent calls made * before the database is open share a single `open()` request instead * of racing each other into N connections. */ protected connection?: Promise; /** * Value parser */ protected _valueParser: (value: any) => any; /** * Value converter */ protected _valueConverter: (value: any) => any; constructor(options?: IndexedDBDriverOptions); /** * Determine whether the current runtime can use this driver * * Use it to pick a driver at bootstrap instead of catching the * `IndexedDBUnavailableError` thrown by the first read. */ static isSupported(): boolean; /** * Resolve the `indexedDB` factory or fail loudly * * Looked up lazily — at call time, never at import or construction * time — so that a module that merely *mentions* this driver can be * bundled into a server-rendered app without exploding on import. */ protected factory(): IDBFactory; /** * Open (once) and return the database connection */ protected database(): Promise; /** * Close the database connection * * The next operation reopens it. Mostly useful in tests and in code * that deletes the database. */ close(): Promise; /** * Run a single request against the object store */ protected request(mode: IDBTransactionMode, run: (store: IDBObjectStore) => IDBRequest): Promise; /** * Determine whether an error is the browser's out-of-quota signal */ protected isQuotaError(error: any): boolean; /** * Parse a stored value * * Identity by default: IndexedDB stores structured clones, so there * is nothing to decode. */ protected parseValue(value: any): any; /** * Convert a value before storing it */ protected convertValue(value: any): any; /** * Set value parser */ setValueParser(parser: any): this; /** * Set value converter */ setValueConverter(converter: any): this; /** * Get a proper key */ getKey(key: string): string; /** * Get prefix key */ getPrefixKey(): string; /** * Set prefix key */ setPrefixKey(key: string): this; /** * Compute the absolute expiry timestamp for a write */ protected expiryOf(expiresAfter?: number): number | undefined; /** * Read the raw record stored under a cache key */ protected record(key: string): Promise; /** * Determine whether a record is past its expiry */ protected isExpired(record: IndexedDBCacheRecord): boolean; /** * Get value from cache engine, if key does not exist return default value */ get(key: string, defaultValue?: any): Promise; /** * Set cache into storage */ set(key: string, value: any, expiresAfter?: number): Promise; /** * Determine whether the cache engine has a live entry for the key */ has(key: string): Promise; /** * Remove the given key from the cache storage */ remove(key: string): Promise; /** * List every key held in the object store */ protected storageKeys(): Promise; /** * List the caller-facing keys owned by this engine */ keys(): Promise; /** * Read every live entry owned by this engine in one transaction * * The returned object has a null prototype and every key is defined * as an own property, so a cache key of `__proto__`, `constructor` or * `prototype` — which any script sharing the origin can write into * the database — lands as plain data instead of reaching a prototype * setter and polluting every object in the runtime. */ getAll(): Promise>; /** * Walk every record in the store inside a single transaction */ protected eachRecord(handle: (key: string, record: IndexedDBCacheRecord) => void): Promise; /** * Clear the cache storage * * Prefix-scoped exactly like the Web Storage engines: the cache * database is shared by every driver instance pointed at it, so an * app that namespaced its keys must not wipe its neighbour's. With no * prefix the engine owns the whole store and clears it. */ clear(): Promise; } //#endregion export { DEFAULT_INDEXED_DB_NAME, DEFAULT_INDEXED_DB_STORE, DEFAULT_INDEXED_DB_VERSION, IndexedDBDriver }; //# sourceMappingURL=IndexedDBDriver.d.mts.map