MCPcopy Index your code
hub / github.com/nukeop/nuclear / loadValidated

Function loadValidated

packages/player/src/services/validatedStore.ts:7–26  ·  view source on GitHub ↗
(
  store: LazyStore,
  key: string,
  schema: S,
  domain: LogScope,
)

Source from the content-addressed store, hash-verified

5import type { LogScope } from './logger';
6
7export const loadValidated = async <S extends z.ZodType>(
8 store: LazyStore,
9 key: string,
10 schema: S,
11 domain: LogScope,
12): Promise<z.output<S> | null> => {
13 const raw = await store.get<unknown>(key);
14 if (raw == null) {
15 return null;
16 }
17 const result = schema.safeParse(raw);
18 if (!result.success) {
19 await reportError(domain, {
20 userMessage: `${domain} data is corrupted`,
21 error: result.error,
22 });
23 return null;
24 }
25 return result.data;
26};

Callers 2

loadMethod · 0.90
loadMethod · 0.90

Calls 1

reportErrorFunction · 0.90

Tested by

no test coverage detected