|
1 | | -import { Buffer } from 'node:buffer' |
| 1 | +import type { Buffer } from 'node:buffer' |
2 | 2 | import { mkdir, readdir, readFile, rm, unlink, writeFile } from 'node:fs/promises' |
3 | 3 | import { basename, dirname, join, normalize, resolve } from 'node:path' |
4 | 4 | import { checkKey } from 'npm:@chelonia/lib/db' |
| 5 | +import * as z from 'npm:zod' |
5 | 6 | import DatabaseBackend from './DatabaseBackend.ts' |
6 | 7 |
|
| 8 | +const ConfigSchema = z.strictObject({ |
| 9 | + dirname: z.optional(z.string()), |
| 10 | + depth: z.optional(z.number()), |
| 11 | + keyChunkLength: z.optional(z.number()), |
| 12 | + skipFsCaseSensitivityCheck: z.optional(z.boolean()), |
| 13 | +}) |
| 14 | + |
7 | 15 | // Some operating systems (such as macOS and Windows) use case-insensitive |
8 | 16 | // filesystems by default. This can be problematic for Chelonia / Group Income, |
9 | 17 | // as we rely on keys being case-sensitive. This is especially relevant for CIDs, |
@@ -48,6 +56,7 @@ export default class FsBackend extends DatabaseBackend { |
48 | 56 |
|
49 | 57 | constructor (options: { dirname?: string; depth?: number; keyChunkLength?: number, skipFsCaseSensitivityCheck?: boolean } = {}) { |
50 | 58 | super() |
| 59 | + ConfigSchema.parse(options) |
51 | 60 | if (options.dirname) this.dataFolder = resolve(options.dirname) |
52 | 61 | if (options.depth) this.depth = options.depth |
53 | 62 | if (options.keyChunkLength) this.keyChunkLength = options.keyChunkLength |
|
0 commit comments