(key: string[], fn: (draft: T) => void)
| 179 | } |
| 180 | |
| 181 | export async function update<T>(key: string[], fn: (draft: T) => void) { |
| 182 | const dir = await state().then((x) => x.dir) |
| 183 | const target = path.join(dir, ...key) + ".json" |
| 184 | return withErrorHandling(async () => { |
| 185 | using _ = await Lock.write(target) |
| 186 | const content = await Bun.file(target).json() |
| 187 | fn(content) |
| 188 | await Bun.write(target, JSON.stringify(content, null, 2)) |
| 189 | return content as T |
| 190 | }) |
| 191 | } |
| 192 | |
| 193 | export async function write<T>(key: string[], content: T) { |
| 194 | const dir = await state().then((x) => x.dir) |
nothing calls this directly
no test coverage detected