/** * Storage Utility — type-safe wrapper for localStorage and sessionStorage * with JSON serialisation, TTL (expiry), versioning, and event emission. * * @example * const storage = createStorage('my-app'); * storage.set('user', { name: 'Alice' }, { ttl: 60 * 60 * 1000 }); // 1 hour * const user = storage.get('user'); * storage.remove('user'); */ export interface StorageOptions { /** Time-to-live in milliseconds. If set, item expires after this duration. */ ttl?: number; /** Schema version. If stored version differs, item is removed and null returned. */ version?: number | string; } export type StorageType = 'local' | 'session'; declare class TypedStorage { private _ns; private _store; constructor(namespace: string, type?: StorageType); private _key; /** Set a value with optional TTL and version. */ set(key: string, value: T, options?: StorageOptions): void; /** Get a value. Returns null if missing, expired, or version mismatch. */ get(key: string, expectedVersion?: number | string): T | null; /** Get a value or return the fallback if missing. */ getOr(key: string, fallback: T, expectedVersion?: number | string): T; /** Check if a key exists and is valid (not expired). */ has(key: string): boolean; /** Remove a key. */ remove(key: string): void; /** Remove all keys in this namespace. */ clear(): void; /** Get all keys in this namespace (namespaced prefix stripped). */ keys(): string[]; /** Get all valid values in this namespace as a keyed record. */ getAll(): Record; /** Update a value by merging with existing object. */ merge(key: string, partial: Partial, options?: StorageOptions): void; /** Purge all expired entries in this namespace. */ pruneExpired(): number; /** Watch a key for changes from other tabs/windows (localStorage only). */ watch(key: string, callback: (newValue: T | null, oldValue: T | null) => void): () => void; /** Total number of valid (non-expired) items in this namespace. */ get size(): number; } /** * Create a namespaced localStorage store. * @example * const store = createStorage('myapp'); * store.set('settings', { theme: 'dark' }); */ export declare function createStorage(namespace?: string, type?: StorageType): TypedStorage; /** Convenience pre-built stores */ export declare const localStorage: TypedStorage; export declare const sessionStorage: TypedStorage; export { TypedStorage }; //# sourceMappingURL=storage.d.ts.map