/** * QueryCacheManager — In-memory cache with IndexedDB persistence for freeschema query results. * * Architecture: * - **Reads** (`get`) are synchronous from an in-memory Map — no async overhead. * - **Writes** (`set`) update the Map immediately, then persist to IndexedDB * in the background (fire-and-forget). Also dispatches a CustomEvent so * active subscribers (SchemaQueryObservable) can re-render with fresh data. * - **On startup**, `init()` loads all persisted query results from IndexedDB * into the Map so cached data is available from the very first read. * * This gives us the speed of in-memory access with the durability of IndexedDB * (no 5 MB localStorage limit, survives page reloads). * * The stale-while-revalidate flow in FreeschemaQueryApi: * 1. `get(hash)` returns cached data synchronously from memory * 2. Caller returns cached data to UI immediately * 3. Background fetch gets fresh data from API * 4. `set(hash, fresh)` updates memory + IndexedDB + fires CustomEvent * 5. Subscribers pick up the event and re-render with fresh data */ export declare class QueryCacheManager { /** Prefix for CustomEvent names — ensures no collision with other window events */ private static prefix; /** In-memory cache: hash → query result data */ private static cacheMap; /** * Loads all persisted query cache data from IndexedDB into memory. * Call this once during app initialization (handled automatically by `init()`). * Safe to call multiple times — just overwrites the Map. * * Skips entirely when `Environments.getValue('enableCache', true)` is `false`, * which is set by the `enableCache` parameter passed to `init()`. */ static init(): Promise; /** * Computes a SHA-256 hash of a query object for use as a cache key. * * The query is canonicalized by recursively sorting all object keys before * hashing, so that `{a:1, b:2}` and `{b:2, a:1}` produce the same hash. * * @param query - The freeschema query object to hash * @returns Hex-encoded SHA-256 hash string */ static getHash(query: any): Promise; /** * Retrieves cached query results by hash key (synchronous, from memory). * * Returns `null` immediately when `Environments.getValue('enableCache', true)` is `false`, * causing `FreeschemaQueryApi` to fall through to a live backend fetch. * * @param hash - The SHA-256 hash of the query (from getHash) * @returns The cached result data, or null if not found or cache is disabled */ static get(hash: string): any | null; /** * Stores query results in memory, persists to IndexedDB, and notifies subscribers. * * Includes a deduplication guard: if the new data serializes identically to * what's already in memory, the write and event dispatch are both skipped. * This prevents infinite revalidation loops (set → event → fetch → set → ...). * * No-ops entirely when `Environments.getValue('enableCache', true)` is `false` * so neither memory nor IndexedDB is written to. * * @param hash - The SHA-256 hash key for this query * @param data - The query result data to cache */ static set(hash: string, data: any): void; /** * Subscribes to cache updates for a specific query hash. * * Uses window CustomEvents (synchronous, in-memory) so subscribers are * notified immediately when `set()` is called — no IndexedDB polling needed. * * @param hash - The query hash to listen for updates on * @param callback - Function called with the fresh data when cache is updated * @returns An unsubscribe function — call it to stop listening */ static subscribe(hash: string, callback: (data: any) => void): () => void; /** * Removes a single cached query result from memory and IndexedDB. * @param hash - The query hash key to remove */ static remove(hash: string): void; /** * Clears all cached query results from memory and IndexedDB. * Useful for cache invalidation on logout or environment switch. */ static clearAll(): void; } /** * Computes a deterministic SHA-256 hash of any JSON-serializable object. * * To ensure that semantically identical objects always produce the same hash * regardless of property insertion order, all object keys are recursively sorted * before serialization. Arrays maintain their order (only object keys are sorted). * * @param obj - Any JSON-serializable value (object, array, string, number, etc.) * @returns Hex-encoded SHA-256 hash string (64 characters) * * @example * // These produce the same hash: * await hashJsonObject({ a: 1, b: 2 }); * await hashJsonObject({ b: 2, a: 1 }); */ export declare function hashJsonObject(obj: any): Promise;