/** * Mock KV Namespace for testing Cloudflare Workers * * Provides a Map-backed implementation of KVNamespace for testing * rate limiting, caching, and other KV-dependent functionality. * * @example * ```typescript * const kv = createMockKV(); * * // Use in tests * const env = { RATE_LIMITS: kv as unknown as KVNamespace }; * * // Pre-populate data * await kv.put('user:123:count', '5'); * * // Check stored values * expect(kv._store.get('user:123:count')).toBe('5'); * * // Check TTL tracking (if needed) * expect(kv._ttls.get('user:123:count')).toBeGreaterThan(Date.now()); * * // Reset between tests * kv._reset(); * ``` */ /** * KV list result item */ interface KVListKey { name: string; expiration?: number; metadata?: unknown; } /** * KV list result */ interface KVListResult { keys: KVListKey[]; list_complete: boolean; cursor?: string; } /** * Extended mock KV namespace with test helpers */ export interface MockKVNamespace { get: (key: string, options?: { type?: 'text' | 'json' | 'arrayBuffer' | 'stream'; }) => Promise; put: (key: string, value: string, options?: { expirationTtl?: number; expiration?: number; metadata?: unknown; }) => Promise; delete: (key: string) => Promise; list: (options?: { prefix?: string; limit?: number; cursor?: string; }) => Promise; getWithMetadata: (key: string) => Promise<{ value: string | null; metadata: T | null; cacheStatus: null; }>; /** Internal storage map (for assertions) */ _store: Map; /** TTL tracking map - stores expiration timestamps */ _ttls: Map; /** Metadata tracking map */ _metadata: Map; /** Reset all storage */ _reset: () => void; } /** * Creates a mock KV namespace for testing * * The mock uses an in-memory Map for storage and tracks TTLs * for expiration testing. * * @returns A mock KV namespace that can be cast to KVNamespace */ export declare function createMockKV(): MockKVNamespace; export {}; //# sourceMappingURL=kv.d.ts.map