19 lines
448 B
TypeScript
19 lines
448 B
TypeScript
import type { ZodType } from 'zod';
|
|||
|
|
import { zValidator } from '@hono/zod-validator';
|
||
|
|
|
||
|
|
export function jsonValidator<T extends ZodType>(schema: T) {
|
||
|
|
return zValidator('json', schema, (result) => {
|
||
|
|
if (!result.success) {
|
||
|
|
throw result.error;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|
||
|
|
|
||
|
|
export function queryValidator<T extends ZodType>(schema: T) {
|
||
|
|
return zValidator('query', schema, (result) => {
|
||
|
|
if (!result.success) {
|
||
|
|
throw result.error;
|
||
|
|
}
|
||
|
|
});
|
||
|
|
}
|