MCPcopy Create free account
hub / github.com/CommandCodeAI/BaseAI / validate

Function validate

packages/baseai/src/dev/hono/validate.ts:3–21  ·  view source on GitHub ↗
({
	schema,
	input,
	code = `BAD_REQUEST`,
	message,
}: {
	schema: any;
	input: any;
	code?: ErrorCodesType;
	message?: string;
})

Source from the content-addressed store, hash-verified

1import {ApiErrorZod, ErrorCodesType} from './errors';
2
3async function validate({
4 schema,
5 input,
6 code = `BAD_REQUEST`,
7 message,
8}: {
9 schema: any;
10 input: any;
11 code?: ErrorCodesType;
12 message?: string;
13}) {
14 const result = await schema.safeParseAsync(input);
15 ApiErrorZod.handle({code, result, message});
16
17 // Since ApiError.handle throws, TypeScript may not infer that execution ends above
18 // and result.data is now avaiable.
19 // @ts-ignore - TS doesn't know that the function ends above.
20 return result.data; // Return the validated data
21}
22
23export default validate;

Callers

nothing calls this directly

Calls 1

handleMethod · 0.80

Tested by

no test coverage detected