( filePath: string, schema: z.ZodType<T>, fallback: T, )
| 33 | } |
| 34 | |
| 35 | export async function readJsonFile<T>( |
| 36 | filePath: string, |
| 37 | schema: z.ZodType<T>, |
| 38 | fallback: T, |
| 39 | ): Promise<T> { |
| 40 | let raw: string; |
| 41 | try { |
| 42 | raw = await readFile(filePath, 'utf-8'); |
| 43 | } catch (error) { |
| 44 | if (isNotFound(error)) return fallback; |
| 45 | throw error; |
| 46 | } |
| 47 | const parsed = JSON.parse(raw) as unknown; |
| 48 | return schema.parse(parsed); |
| 49 | } |
| 50 | |
| 51 | export async function writeJsonFile<T>( |
| 52 | filePath: string, |
no test coverage detected