/** * TypedStorage * * A generic wrapper that provides type-safe JSON serialization * on top of StorageAdapter or NamespacedStorage. * * @example * ```typescript * import { createStorage, TypedStorage } from '@frontmcp/utils'; * * interface User { * id: string; * name: string; * } * * const storage = await createStorage({ type: 'memory' }); * const users = new TypedStorage(storage); * * await users.set('user:1', { id: '1', name: 'Alice' }); * const user = await users.get('user:1'); * ``` */ import type { StorageAdapter, NamespacedStorage, SetOptions } from './types'; import type { TypedStorageOptions, TypedSetEntry } from './typed-storage.types'; /** * TypedStorage provides type-safe JSON serialization on top of StorageAdapter. * * Features: * - Automatic JSON serialization/deserialization * - Optional Zod schema validation on read * - Custom serializer support * - Batch operations (mget/mset) * - Full StorageAdapter method access */ export declare class TypedStorage { private readonly storage; private readonly serialize; private readonly deserialize; private readonly schema?; private readonly throwOnInvalid; constructor(storage: StorageAdapter | NamespacedStorage, options?: TypedStorageOptions); /** * Get a typed value by key. * * @param key - Storage key * @returns The typed value, or null if not found or invalid */ get(key: string): Promise; /** * Set a typed value with optional TTL. * * @param key - Storage key * @param value - Typed value to store * @param options - Optional TTL and conditional flags */ set(key: string, value: T, options?: SetOptions): Promise; /** * Delete a key. * * @param key - Storage key * @returns true if key existed and was deleted */ delete(key: string): Promise; /** * Check if a key exists. * * @param key - Storage key * @returns true if key exists */ exists(key: string): Promise; /** * Get multiple typed values. * * @param keys - Array of storage keys * @returns Array of typed values (null for missing/invalid keys) */ mget(keys: string[]): Promise<(T | null)[]>; /** * Set multiple typed values. * * @param entries - Array of key-value-options entries */ mset(entries: TypedSetEntry[]): Promise; /** * Delete multiple keys. * * @param keys - Array of storage keys * @returns Number of keys actually deleted */ mdelete(keys: string[]): Promise; /** * Update TTL on an existing key. * * @param key - Storage key * @param ttlSeconds - New TTL in seconds * @returns true if key exists and TTL was set */ expire(key: string, ttlSeconds: number): Promise; /** * Get remaining TTL for a key. * * @param key - Storage key * @returns TTL in seconds, -1 if no TTL, or null if key doesn't exist */ ttl(key: string): Promise; /** * List keys matching a pattern. * * @param pattern - Glob pattern (default: '*' for all keys) * @returns Array of matching keys */ keys(pattern?: string): Promise; /** * Count keys matching a pattern. * * @param pattern - Glob pattern (default: '*' for all keys) * @returns Number of matching keys */ count(pattern?: string): Promise; /** * Get the underlying storage adapter. * Use with caution - operations bypass type safety. */ get raw(): StorageAdapter | NamespacedStorage; /** * Parse and validate a raw value. */ private parseValue; }