(key: string[], content: T)
| 191 | } |
| 192 | |
| 193 | export async function write<T>(key: string[], content: T) { |
| 194 | const dir = await state().then((x) => x.dir) |
| 195 | const target = path.join(dir, ...key) + ".json" |
| 196 | return withErrorHandling(async () => { |
| 197 | using _ = await Lock.write(target) |
| 198 | await Bun.write(target, JSON.stringify(content, null, 2)) |
| 199 | }) |
| 200 | } |
| 201 | |
| 202 | async function withErrorHandling<T>(body: () => Promise<T>) { |
| 203 | return body().catch((e) => { |
nothing calls this directly
no test coverage detected