refactor(zod-validator): pass the path to `Context` for the hook (#74)

* refactor(zod-validator): pass the path to `Context` for the hook

* add changeset
pull/73/head
Yusuke Wada 2023-03-21 18:24:29 +09:00 committed by GitHub
parent 9ce42c23dd
commit 7d84e06943
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 3 deletions

View File

@ -0,0 +1,5 @@
---
'@hono/zod-validator': patch
---
refactor: pass the path to Context for the hook

View File

@ -3,9 +3,9 @@ import { validator } from 'hono/validator'
import type { z } from 'zod'
import type { ZodSchema, ZodError } from 'zod'
type Hook<T, E extends Env> = (
type Hook<T, E extends Env, P extends string> = (
result: { success: true; data: T } | { success: false; error: ZodError },
c: Context<E>
c: Context<E, P>
) => Response | Promise<Response> | void
export const zValidator = <
@ -23,7 +23,7 @@ export const zValidator = <
>(
target: Target,
schema: T,
hook?: Hook<z.infer<T>, E>
hook?: Hook<z.infer<T>, E, P>
): MiddlewareHandler<E, P, V> =>
validator(target, (value, c) => {
const result = schema.safeParse(value)