fix(zod-validator): fix and refactor types (#24)
* fix(zod-validator): fix and refactor types * add changesetpull/25/head
parent
f181cf59bf
commit
a831696e1f
|
@ -0,0 +1,5 @@
|
|||
---
|
||||
'@hono/zod-validator': patch
|
||||
---
|
||||
|
||||
fix and refactor types
|
|
@ -34,5 +34,8 @@
|
|||
"devDependencies": {
|
||||
"hono": "3.0.0-rc.3",
|
||||
"zod": "3.19.1"
|
||||
},
|
||||
"dependencies": {
|
||||
"hono": "3.0.0-rc.7"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
import type { Context } from 'hono'
|
||||
import type { Context, MiddlewareHandler, Env } from 'hono'
|
||||
import { validator } from 'hono/validator'
|
||||
import type { z } from 'zod'
|
||||
import type { ZodSchema, ZodError } from 'zod'
|
||||
|
@ -9,11 +9,16 @@ type Hook<T> = (
|
|||
c: Context
|
||||
) => Response | Promise<Response> | void
|
||||
|
||||
export const zValidator = <T extends ZodSchema, Type extends ValidationTypes>(
|
||||
export const zValidator = <
|
||||
T extends ZodSchema,
|
||||
Type extends ValidationTypes,
|
||||
E extends Env,
|
||||
P extends string
|
||||
>(
|
||||
type: Type,
|
||||
schema: T,
|
||||
hook?: Hook<z.infer<T>>
|
||||
) =>
|
||||
): MiddlewareHandler<E, P, { type: Type; data: z.infer<T> }> =>
|
||||
validator(type, (value, c) => {
|
||||
const result = schema.safeParse(value)
|
||||
|
||||
|
|
10
yarn.lock
10
yarn.lock
|
@ -2780,16 +2780,16 @@ hast-util-whitespace@^2.0.0:
|
|||
resolved "https://registry.yarnpkg.com/hast-util-whitespace/-/hast-util-whitespace-2.0.1.tgz#0ec64e257e6fc216c7d14c8a1b74d27d650b4557"
|
||||
integrity sha512-nAxA0v8+vXSBDt3AnRUNjyRIQ0rD+ntpbAp4LnPkumc5M9yUbSMa4XDU9Q6etY4f1Wp4bNgvc1yjiZtsTTrSng==
|
||||
|
||||
hono@3.0.0-rc.3:
|
||||
version "3.0.0-rc.3"
|
||||
resolved "https://registry.yarnpkg.com/hono/-/hono-3.0.0-rc.3.tgz#8f4cfc03816114bc3541c1802f0c65e0730327e8"
|
||||
integrity sha512-j5GLwfTb9smHcneQ8hm1I7bwnLGxKHAZYuCOZuq+CGpEg/SrWW0niIiuhLE4FIIFAfeL3vUsjy0BzOWS6Hur0w==
|
||||
|
||||
hono@3.0.0-rc.4:
|
||||
version "3.0.0-rc.4"
|
||||
resolved "https://registry.yarnpkg.com/hono/-/hono-3.0.0-rc.4.tgz#7bfe8c89d4b004ff90d587c8ba45279a175fbce7"
|
||||
integrity sha512-76R3mb8kPeuD9TOmQ1WZi59w4QbpaUOlyX3wC7zQpt7IM7iFVBTxj2fpv++6ROPtd5iUBMCrmH/65ZrNXYYgmg==
|
||||
|
||||
hono@3.0.0-rc.7:
|
||||
version "3.0.0-rc.7"
|
||||
resolved "https://registry.yarnpkg.com/hono/-/hono-3.0.0-rc.7.tgz#c6a5c44ce7fad1e187f47e1d7828a20fad2b20b2"
|
||||
integrity sha512-ZiAz4XnIDgRFw8ZRwvxv8EfArEoCOdxkz1rDE2N6TOrYi7mf7DGIbIjgj/T1CwXlbV9VulKU17IqEZg0asqkTQ==
|
||||
|
||||
hono@^2.3.0:
|
||||
version "2.6.2"
|
||||
resolved "https://registry.yarnpkg.com/hono/-/hono-2.6.2.tgz#1e32a4b4b3bf557a8aa87e392b00b505a1ec1fdd"
|
||||
|
|
Loading…
Reference in New Issue