diff options
| author | Dax Raad <[email protected]> | 2025-05-30 20:47:56 -0400 |
|---|---|---|
| committer | Dax Raad <[email protected]> | 2025-05-30 20:48:36 -0400 |
| commit | f3da73553c45f17e04b1e77cb13eb0fca714d1bd (patch) | |
| tree | a24317a19e1ab2a89da50db669dc6894f15d00d1 /js/src/storage | |
| parent | 9a26b3058ffc1023e5c7e54b6d571c903d15888e (diff) | |
| download | opencode-f3da73553c45f17e04b1e77cb13eb0fca714d1bd.tar.gz opencode-f3da73553c45f17e04b1e77cb13eb0fca714d1bd.zip | |
sync
Diffstat (limited to 'js/src/storage')
| -rw-r--r-- | js/src/storage/storage.ts | 55 |
1 files changed, 0 insertions, 55 deletions
diff --git a/js/src/storage/storage.ts b/js/src/storage/storage.ts deleted file mode 100644 index 983b7e0f9..000000000 --- a/js/src/storage/storage.ts +++ /dev/null @@ -1,55 +0,0 @@ -import { FileStorage } from "@flystorage/file-storage"; -import { LocalStorageAdapter } from "@flystorage/local-fs"; -import fs from "fs/promises"; -import { Log } from "../util/log"; -import { App } from "../app/app"; -import { AppPath } from "../app/path"; -import { Bus } from "../bus"; -import z from "zod"; - -export namespace Storage { - const log = Log.create({ service: "storage" }); - - export const Event = { - Write: Bus.event( - "storage.write", - z.object({ key: z.string(), content: z.any() }), - ), - }; - - const state = App.state("storage", async () => { - const app = await App.use(); - const storageDir = AppPath.storage(app.root); - await fs.mkdir(storageDir, { recursive: true }); - const storage = new FileStorage(new LocalStorageAdapter(storageDir)); - log.info("created", { path: storageDir }); - return { - storage, - }; - }); - - export async function readJSON<T>(key: string) { - 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 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; - } - } -} |
