MCPcopy Create free account
hub / github.com/MoonshotAI/kimi-code / readJsonFile

Function readJsonFile

apps/kimi-code/src/utils/persistence.ts:35–49  ·  view source on GitHub ↗
(
  filePath: string,
  schema: z.ZodType<T>,
  fallback: T,
)

Source from the content-addressed store, hash-verified

33}
34
35export 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
51export async function writeJsonFile<T>(
52 filePath: string,

Callers 4

readBannerDisplayStateFunction · 0.90
readUpdateCacheFunction · 0.90
readUpdateInstallStateFunction · 0.90

Calls 2

isNotFoundFunction · 0.70
readFileFunction · 0.50

Tested by

no test coverage detected