(key: string[])
| 166 | } |
| 167 | |
| 168 | export async function read<T>(key: string[]) { |
| 169 | const dir = await state().then((x) => x.dir) |
| 170 | const target = path.join(dir, ...key) + ".json" |
| 171 | return withErrorHandling(async () => { |
| 172 | using _ = await Lock.read(target) |
| 173 | const result = await Bun.file(target).json().catch((e) => { |
| 174 | log.error("failed to parse JSON", { target, error: e.message }) |
| 175 | throw e |
| 176 | }) |
| 177 | return result as T |
| 178 | }) |
| 179 | } |
| 180 | |
| 181 | export async function update<T>(key: string[], fn: (draft: T) => void) { |
| 182 | const dir = await state().then((x) => x.dir) |
nothing calls this directly
no test coverage detected