@hono/zod-validator
Advanced tools
Comparing version 0.2.2 to 0.3.0
@@ -10,3 +10,3 @@ "use strict"; | ||
if (hook) { | ||
const hookResult = await hook({ data: value, ...result }, c); | ||
const hookResult = await hook({ data: value, ...result, target }, c); | ||
if (hookResult) { | ||
@@ -13,0 +13,0 @@ if (hookResult instanceof Response) { |
import type { Context, MiddlewareHandler, Env, ValidationTargets, TypedResponse, Input } from 'hono'; | ||
import type { z, ZodError } from 'zod'; | ||
export type Hook<T, E extends Env, P extends string, O = {}> = (result: { | ||
export type Hook<T, E extends Env, P extends string, Target extends keyof ValidationTargets = keyof ValidationTargets, O = {}> = (result: ({ | ||
success: true; | ||
@@ -10,2 +10,4 @@ data: T; | ||
data: T; | ||
}) & { | ||
target: Target; | ||
}, c: Context<E, P>) => Response | void | TypedResponse<O> | Promise<Response | void | TypedResponse<O>>; | ||
@@ -16,3 +18,3 @@ type HasUndefined<T> = undefined extends T ? true : false; | ||
out: { [K_2 in Target]: Out; }; | ||
}, V extends I = I>(target: Target, schema: T, hook?: Hook<z.TypeOf<T>, E, P, {}> | undefined) => MiddlewareHandler<E, P, V>; | ||
}, V extends I = I>(target: Target, schema: T, hook?: Hook<z.TypeOf<T>, E, P, Target, {}> | undefined) => MiddlewareHandler<E, P, V>; | ||
export {}; |
@@ -7,3 +7,3 @@ import { validator } from 'hono/validator'; | ||
if (hook) { | ||
const hookResult = await hook({ data: value, ...result }, c); | ||
const hookResult = await hook({ data: value, ...result, target }, c); | ||
if (hookResult) { | ||
@@ -10,0 +10,0 @@ if (hookResult instanceof Response) { |
{ | ||
"name": "@hono/zod-validator", | ||
"version": "0.2.2", | ||
"version": "0.3.0", | ||
"description": "Validator middleware using Zod", | ||
@@ -5,0 +5,0 @@ "type": "module", |
5049
65