| 3 | import { KV } from "../src/state/schema.js"; |
| 4 | |
| 5 | function mockKV() { |
| 6 | const store = new Map<string, Map<string, unknown>>(); |
| 7 | return { |
| 8 | get: async <T>(scope: string, key: string): Promise<T | null> => { |
| 9 | return (store.get(scope)?.get(key) as T) ?? null; |
| 10 | }, |
| 11 | set: async <T>(scope: string, key: string, data: T): Promise<T> => { |
| 12 | if (!store.has(scope)) store.set(scope, new Map()); |
| 13 | store.get(scope)!.set(key, data); |
| 14 | return data; |
| 15 | }, |
| 16 | delete: async (scope: string, key: string): Promise<void> => { |
| 17 | store.get(scope)?.delete(key); |
| 18 | }, |
| 19 | list: async <T>(scope: string): Promise<T[]> => { |
| 20 | if (!store.has(scope)) return []; |
| 21 | return Array.from(store.get(scope)!.values()) as T[]; |
| 22 | }, |
| 23 | }; |
| 24 | } |
| 25 | |
| 26 | function wire() { |
| 27 | const kv = mockKV(); |