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

Function writeJsonFile

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

Source from the content-addressed store, hash-verified

49}
50
51export async function writeJsonFile<T>(
52 filePath: string,
53 schema: z.ZodType<T>,
54 value: T,
55): Promise<void> {
56 assertNonConfigWrite(filePath);
57 const parsed = schema.parse(value);
58 await mkdir(dirname(filePath), { recursive: true });
59 const tmpPath = tempPathFor(filePath);
60 try {
61 await writeFile(tmpPath, `${JSON.stringify(parsed, null, 2)}\n`, 'utf-8');
62 await rename(tmpPath, filePath);
63 } catch (error) {
64 await unlink(tmpPath).catch(() => {});
65 throw error;
66 }
67}
68
69export async function readJsonlFile<T>(
70 filePath: string,

Callers 4

writeBannerDisplayStateFunction · 0.90
writeUpdateCacheFunction · 0.90
writeUpdateInstallStateFunction · 0.90

Calls 4

assertNonConfigWriteFunction · 0.85
tempPathForFunction · 0.85
mkdirFunction · 0.50
writeFileFunction · 0.50

Tested by

no test coverage detected