/** * `createLocalStorageTrackerStore` — first-party `TxTrackerStore` * implementation backed by `localStorage` (or any `Storage`-shaped * object). Targeted at browser dApps that need durable per-hash * subscriptions surviving page reloads but don't want to maintain * their own custom store. * * Key layout (under the consumer-supplied `keyPrefix`): * * {keyPrefix}:{chainId}:{hash} → the TrackedTxRecord JSON * {keyPrefix}:eventlog:{chainId}:{hash} → the per-hash event log JSON * * The eventlog is a separate key from the record so put/get can avoid * paying read-and-rewrite for the (potentially-large) log on every * status update. * * **`delete()` clears BOTH keys.** This is the contract the * `TxTrackerStore.delete` docstring requires; we lock it in here so * consumers don't accumulate orphan eventlogs when records expire * (the canonical bug that motivated this first-party store — * consumer-implemented localStorage stores routinely forgot to clear * the eventlog key). * * Browser-safety: `localStorage` is browser-only. The factory accepts * a `storage` override (defaults to `globalThis.localStorage`) so * (a) tests can inject a fake and (b) consumers running in * server-rendered contexts can supply a no-op implementation rather * than throwing at construction. */ import type { PersistedSubscription, TxTrackerStore } from './store.js'; /** * Storage-shaped interface — the subset of the DOM `Storage` API the * store needs. `localStorage` and `sessionStorage` both satisfy this; * consumers can supply any object with the same shape (in-memory fake, * server-rendered no-op, IndexedDB-backed polyfill, etc.). */ export interface LocalStorageLike { getItem(key: string): string | null; setItem(key: string, value: string): void; removeItem(key: string): void; readonly length: number; key(index: number): string | null; } export interface LocalStorageTrackerStoreOptions { /** * Namespace prefix for all keys this store writes. Required. Use * a versioned prefix (e.g. `'myapp.tx-tracker.v1'`) and bump the * version suffix when the persisted shape changes — the prior- * prefix keys can then be cleaned up via `cleanupLegacyPrefixes`. */ keyPrefix: string; /** * Storage backend. Defaults to `globalThis.localStorage` when * available; throws at construction otherwise (server-rendered or * Node contexts must supply an explicit `storage` parameter, even * if it's a no-op). */ storage?: LocalStorageLike; /** * Cap on the per-hash event log. When `appendEvent` would push the * log past this length, the oldest entries are dropped. Default 256 * (matches `InMemoryStoreOptions.eventLogCapacity`). */ eventLogCapacity?: number; /** * On construction, delete every key in `storage` that starts with * any of these prefixes followed by `:`. Use to clean up records * orphaned by a prior `keyPrefix` bump. Pass the OLD prefix (or * prefixes), not the current one — passing the current one would * wipe live state. */ cleanupLegacyPrefixes?: string[]; } /** * Build a localStorage-backed `TxTrackerStore`. See module docstring * for the key layout and serialization details. * * @example * import { * createTxTracker, * createLocalStorageTrackerStore, * } from '@valve-tech/tx-tracker' * * const store = createLocalStorageTrackerStore({ * keyPrefix: 'myapp.tx-tracker.v1', * cleanupLegacyPrefixes: ['myapp.tx-tracker.v0'], * }) * const tracker = createTxTracker({ source, chainId: 1, store }) */ export declare const createLocalStorageTrackerStore: (options: LocalStorageTrackerStoreOptions) => TxTrackerStore; /** * Delete every key in `storage` whose name starts with `prefix`. * Exported so consumers can run prefix cleanup without instantiating * the full store — e.g., on app boot before constructing the tracker. */ export declare const deleteKeysStartingWith: (storage: LocalStorageLike, prefix: string) => void; export type { PersistedSubscription }; //# sourceMappingURL=local-storage-store.d.ts.map