diff options
| author | Dax Raad <[email protected]> | 2025-05-26 13:21:15 -0400 |
|---|---|---|
| committer | Dax Raad <[email protected]> | 2025-05-26 13:21:15 -0400 |
| commit | 2ed17f4877478e20022a0d68bb9f6e3b4f726bb1 (patch) | |
| tree | e6cd5777a13edf3f655960e5820699fce1d86dee /js/src/storage | |
| parent | 80118212da3ce16babdee035974a67fa2f2b8ed9 (diff) | |
| download | opencode-2ed17f4877478e20022a0d68bb9f6e3b4f726bb1.tar.gz opencode-2ed17f4877478e20022a0d68bb9f6e3b4f726bb1.zip | |
exit properly
Diffstat (limited to 'js/src/storage')
| -rw-r--r-- | js/src/storage/storage.ts | 35 |
1 files changed, 16 insertions, 19 deletions
diff --git a/js/src/storage/storage.ts b/js/src/storage/storage.ts index 5572c3017..3b4c63cb8 100644 --- a/js/src/storage/storage.ts +++ b/js/src/storage/storage.ts @@ -28,31 +28,28 @@ export namespace Storage { }; }); - function expose<T extends keyof FileStorage>(key: T) { - const fn = FileStorage.prototype[key]; - return async ( - ...args: Parameters<typeof fn> - ): Promise<ReturnType<typeof fn>> => { - const { storage } = await state(); - const match = storage[key]; - // @ts-ignore - return match.call(storage, ...args); - }; - } - - export const write = expose("write"); - export const read = expose("read"); - export const list = expose("list"); - export const readToString = expose("readToString"); - export async function readJSON<T>(key: string) { - const data = await readToString(key + ".json"); + const storage = await state().then((x) => x.storage); + const data = await storage.readToString(key + ".json"); return JSON.parse(data) as T; } export async function writeJSON<T>(key: string, content: T) { + const storage = await state().then((x) => x.storage); const json = JSON.stringify(content); - await write(key + ".json", json); + await storage.write(key + ".json", json); Bus.publish(Event.Write, { key, content }); } + + export async function* list(prefix: string) { + try { + const storage = await state().then((x) => x.storage); + const list = storage.list(prefix); + for await (const item of list) { + yield item.path.slice(0, -5); + } + } catch { + return; + } + } } |
