diff --git a/.changeset/famous-parrots-shave.md b/.changeset/famous-parrots-shave.md new file mode 100644 index 00000000..de109bb8 --- /dev/null +++ b/.changeset/famous-parrots-shave.md @@ -0,0 +1,5 @@ +--- +'@hono/zod-validator': patch +--- + +refactor: pass the path to Context for the hook diff --git a/packages/zod-validator/src/index.ts b/packages/zod-validator/src/index.ts index 220a367e..75878ea4 100644 --- a/packages/zod-validator/src/index.ts +++ b/packages/zod-validator/src/index.ts @@ -3,9 +3,9 @@ import { validator } from 'hono/validator' import type { z } from 'zod' import type { ZodSchema, ZodError } from 'zod' -type Hook = ( +type Hook = ( result: { success: true; data: T } | { success: false; error: ZodError }, - c: Context + c: Context ) => Response | Promise | void export const zValidator = < @@ -23,7 +23,7 @@ export const zValidator = < >( target: Target, schema: T, - hook?: Hook, E> + hook?: Hook, E, P> ): MiddlewareHandler => validator(target, (value, c) => { const result = schema.safeParse(value)