mirror of
https://github.com/shishantbiswas/bknd.git
synced 2026-03-17 04:46:05 +00:00
repo chores: fixed root dir, removed unused class, added .env.example
This commit is contained in:
@@ -1,29 +0,0 @@
|
||||
import type { Env, Input, MiddlewareHandler, ValidationTargets } from "hono";
|
||||
import { validator } from "hono/validator";
|
||||
import type { Static, TSchema } from "simple-jsonschema-ts";
|
||||
|
||||
export const honoValidator = <
|
||||
Target extends keyof ValidationTargets,
|
||||
E extends Env,
|
||||
P extends string,
|
||||
const Schema extends TSchema = TSchema,
|
||||
Out = Static<Schema>,
|
||||
I extends Input = {
|
||||
in: { [K in Target]: Static<Schema> };
|
||||
out: { [K in Target]: Static<Schema> };
|
||||
},
|
||||
>(
|
||||
target: Target,
|
||||
schema: Schema,
|
||||
): MiddlewareHandler<E, P, I> => {
|
||||
// @ts-expect-error not typed well
|
||||
return validator(target, async (value, c) => {
|
||||
const coersed = schema.coerce(value);
|
||||
const result = schema.validate(coersed);
|
||||
if (!result.valid) {
|
||||
return c.json({ ...result, schema }, 400);
|
||||
}
|
||||
|
||||
return coersed as Out;
|
||||
});
|
||||
};
|
||||
Reference in New Issue
Block a user