Function
validate
({
schema,
input,
code = `BAD_REQUEST`,
message,
}: {
schema: any;
input: any;
code?: ErrorCodesType;
message?: string;
})
Source from the content-addressed store, hash-verified
| 1 | import {ApiErrorZod, ErrorCodesType} from './errors'; |
| 2 | |
| 3 | async 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 | |
| 23 | export default validate; |
Callers
nothing calls this directly
Tested by
no test coverage detected