MCPcopy Create free account
hub / github.com/Kilo-Org/cloud / zodJsonValidator

Function zodJsonValidator

packages/worker-utils/src/zod-json-validator.ts:11–33  ·  view source on GitHub ↗
(
  schema: T,
  opts?: { errorMessage?: string }
)

Source from the content-addressed store, hash-verified

9};
10
11export function zodJsonValidator<T extends ZodTypeAny>(
12 schema: T,
13 opts?: { errorMessage?: string }
14) {
15 const errorMessage = opts?.errorMessage ?? 'Invalid request body';
16
17 return validator('json', (value, c: Context<Env>) => {
18 const parsed = schema.safeParse(value);
19
20 if (!parsed.success) {
21 return c.json(
22 {
23 success: false,
24 error: errorMessage,
25 issues: parsed.error.issues,
26 } satisfies ValidationErrorResponse,
27 400
28 );
29 }
30
31 return parsed.data;
32 });
33}

Callers 4

api.tsFile · 0.90
registerAdminRoutesFunction · 0.90
registerApiMetricsRoutesFunction · 0.90

Calls 1

jsonMethod · 0.65

Tested by

no test coverage detected