@jderstd/hono-zod-validator 0.6.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025-present, Alpheus
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,9 @@
1
+ # JDER Hono Zod Validator
2
+
3
+ A Zod validator for Hono.
4
+
5
+ This package includes a Zod validator based on the JSON response structure specified in [JSON Data Errors Response (JDER)](https://github.com/jderstd/spec). With the validator, various kinds of requests can be validated easily and send JSON responses instead of plain text responses.
6
+
7
+ ## License
8
+
9
+ This project is licensed under the terms of the MIT license.
@@ -0,0 +1,23 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
4
+ var __getOwnPropNames = Object.getOwnPropertyNames;
5
+ var __getProtoOf = Object.getPrototypeOf;
6
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
7
+ var __copyProps = (to, from, except, desc) => {
8
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
9
+ key = keys[i];
10
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
11
+ get: ((k) => from[k]).bind(null, key),
12
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
13
+ });
14
+ }
15
+ return to;
16
+ };
17
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
18
+ value: mod,
19
+ enumerable: true
20
+ }) : target, mod));
21
+
22
+
23
+ exports.__toESM = __toESM;
package/dist/hook.d.ts ADDED
@@ -0,0 +1,21 @@
1
+ import { Context, Env, TypedResponse, ValidationTargets } from "hono";
2
+ import * as v3 from "zod/v3";
3
+ import * as v4 from "zod/v4/core";
4
+ /** Zod schema for both v3 and v4. */
5
+ type ZodSchema = v3.ZodType | v4.$ZodType;
6
+ /** Zod error for both v3 and v4. */
7
+ type ZodError<T extends ZodSchema> = T extends v4.$ZodType ? v4.$ZodError : v3.ZodError;
8
+ /**
9
+ * Zod validator hook.
10
+ */
11
+ declare const zValidatorHook: <T, E extends Env, P extends string, Target extends keyof ValidationTargets = keyof ValidationTargets, O = {}, Schema extends ZodSchema = any>(result: ({
12
+ success: true;
13
+ data: T;
14
+ } | {
15
+ success: false;
16
+ error: ZodError<Schema>;
17
+ }) & {
18
+ target: Target;
19
+ }, c: Context<E, P>) => Response | void | TypedResponse<O> | Promise<Response | void | TypedResponse<O>>;
20
+ export { type ZodError, type ZodSchema, zValidatorHook };
21
+ //# sourceMappingURL=hook.d.ts.map
package/dist/hook.js ADDED
@@ -0,0 +1,29 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.js');
2
+ let __jderstd_hono_response = require("@jderstd/hono/response");
3
+ __jderstd_hono_response = require_rolldown_runtime.__toESM(__jderstd_hono_response);
4
+ let __jderstd_hono_response_error = require("@jderstd/hono/response/error");
5
+ __jderstd_hono_response_error = require_rolldown_runtime.__toESM(__jderstd_hono_response_error);
6
+ let hono_http_exception = require("hono/http-exception");
7
+ hono_http_exception = require_rolldown_runtime.__toESM(hono_http_exception);
8
+
9
+ /**
10
+ * Zod validator hook.
11
+ */
12
+ const zValidatorHook = (result, c) => {
13
+ if (result.success) return void 0;
14
+ const errors = [];
15
+ const errs = result.error.issues;
16
+ for (let i = 0; i < errs.length; i++) {
17
+ const err = errs[i];
18
+ if (!err) continue;
19
+ errors.push({
20
+ code: __jderstd_hono_response_error.ResponseErrorCode.Parse,
21
+ path: err.path.map((p) => String(p)),
22
+ message: err.message
23
+ });
24
+ }
25
+ throw new hono_http_exception.HTTPException(400, { res: (0, __jderstd_hono_response.createJsonResponse)(c, { errors }) });
26
+ };
27
+
28
+ exports.zValidatorHook = zValidatorHook;
29
+ //# sourceMappingURL=hook.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.js","names":["errors: JsonResponseError[]","errs: v4.$ZodIssue[] | v3.ZodIssue[]","i: number","err: v4.$ZodIssue | v3.ZodIssue | undefined","ResponseErrorCode","HTTPException"],"sources":["../src/hook.ts"],"sourcesContent":["import type { JsonResponseError } from \"@jderstd/hono/response\";\nimport type { Context, Env, TypedResponse, ValidationTargets } from \"hono\";\nimport type * as v3 from \"zod/v3\";\nimport type * as v4 from \"zod/v4/core\";\n\nimport { createJsonResponse } from \"@jderstd/hono/response\";\nimport { ResponseErrorCode } from \"@jderstd/hono/response/error\";\nimport { HTTPException } from \"hono/http-exception\";\n\n/** Zod schema for both v3 and v4. */\ntype ZodSchema = v3.ZodType | v4.$ZodType;\n\n/** Zod error for both v3 and v4. */\ntype ZodError<T extends ZodSchema> = T extends v4.$ZodType\n ? v4.$ZodError\n : v3.ZodError;\n\n/**\n * Zod validator hook.\n */\nconst zValidatorHook = <\n T,\n E extends Env,\n P extends string,\n Target extends keyof ValidationTargets = keyof ValidationTargets,\n // biome-ignore lint/complexity/noBannedTypes: any non-nullable value\n O = {},\n Schema extends ZodSchema = any,\n>(\n result: (\n | {\n success: true;\n data: T;\n }\n | {\n success: false;\n error: ZodError<Schema>;\n }\n ) & {\n target: Target;\n },\n c: Context<E, P>,\n):\n | Response\n | void\n | TypedResponse<O>\n // biome-ignore lint/suspicious/noConfusingVoidType: return type\n | Promise<Response | void | TypedResponse<O>> => {\n if (result.success) return void 0;\n\n const errors: JsonResponseError[] = [];\n\n const errs: v4.$ZodIssue[] | v3.ZodIssue[] = result.error.issues;\n\n for (let i: number = 0; i < errs.length; i++) {\n const err: v4.$ZodIssue | v3.ZodIssue | undefined = errs[i];\n\n if (!err) continue;\n\n errors.push({\n code: ResponseErrorCode.Parse,\n path: err.path.map((p): string => String(p)),\n message: err.message,\n });\n }\n\n throw new HTTPException(400, {\n res: createJsonResponse(c, {\n errors,\n }),\n });\n};\n\nexport type { ZodSchema, ZodError };\nexport { zValidatorHook };\n"],"mappings":";;;;;;;;;;;AAoBA,MAAM,kBASF,QAYA,MAMiD;AACjD,KAAI,OAAO,QAAS,QAAO,KAAK;CAEhC,MAAMA,SAA8B,EAAE;CAEtC,MAAMC,OAAuC,OAAO,MAAM;AAE1D,MAAK,IAAIC,IAAY,GAAG,IAAI,KAAK,QAAQ,KAAK;EAC1C,MAAMC,MAA8C,KAAK;AAEzD,MAAI,CAAC,IAAK;AAEV,SAAO,KAAK;GACR,MAAMC,gDAAkB;GACxB,MAAM,IAAI,KAAK,KAAK,MAAc,OAAO,EAAE,CAAC;GAC5C,SAAS,IAAI;GAChB,CAAC;;AAGN,OAAM,IAAIC,kCAAc,KAAK,EACzB,qDAAwB,GAAG,EACvB,QACH,CAAC,EACL,CAAC"}
package/dist/hook.mjs ADDED
@@ -0,0 +1,25 @@
1
+ import { createJsonResponse } from "@jderstd/hono/response";
2
+ import { ResponseErrorCode } from "@jderstd/hono/response/error";
3
+ import { HTTPException } from "hono/http-exception";
4
+
5
+ /**
6
+ * Zod validator hook.
7
+ */
8
+ const zValidatorHook = (result, c) => {
9
+ if (result.success) return void 0;
10
+ const errors = [];
11
+ const errs = result.error.issues;
12
+ for (let i = 0; i < errs.length; i++) {
13
+ const err = errs[i];
14
+ if (!err) continue;
15
+ errors.push({
16
+ code: ResponseErrorCode.Parse,
17
+ path: err.path.map((p) => String(p)),
18
+ message: err.message
19
+ });
20
+ }
21
+ throw new HTTPException(400, { res: createJsonResponse(c, { errors }) });
22
+ };
23
+
24
+ export { zValidatorHook };
25
+ //# sourceMappingURL=hook.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"hook.mjs","names":["errors: JsonResponseError[]","errs: v4.$ZodIssue[] | v3.ZodIssue[]","i: number","err: v4.$ZodIssue | v3.ZodIssue | undefined"],"sources":["../src/hook.ts"],"sourcesContent":["import type { JsonResponseError } from \"@jderstd/hono/response\";\nimport type { Context, Env, TypedResponse, ValidationTargets } from \"hono\";\nimport type * as v3 from \"zod/v3\";\nimport type * as v4 from \"zod/v4/core\";\n\nimport { createJsonResponse } from \"@jderstd/hono/response\";\nimport { ResponseErrorCode } from \"@jderstd/hono/response/error\";\nimport { HTTPException } from \"hono/http-exception\";\n\n/** Zod schema for both v3 and v4. */\ntype ZodSchema = v3.ZodType | v4.$ZodType;\n\n/** Zod error for both v3 and v4. */\ntype ZodError<T extends ZodSchema> = T extends v4.$ZodType\n ? v4.$ZodError\n : v3.ZodError;\n\n/**\n * Zod validator hook.\n */\nconst zValidatorHook = <\n T,\n E extends Env,\n P extends string,\n Target extends keyof ValidationTargets = keyof ValidationTargets,\n // biome-ignore lint/complexity/noBannedTypes: any non-nullable value\n O = {},\n Schema extends ZodSchema = any,\n>(\n result: (\n | {\n success: true;\n data: T;\n }\n | {\n success: false;\n error: ZodError<Schema>;\n }\n ) & {\n target: Target;\n },\n c: Context<E, P>,\n):\n | Response\n | void\n | TypedResponse<O>\n // biome-ignore lint/suspicious/noConfusingVoidType: return type\n | Promise<Response | void | TypedResponse<O>> => {\n if (result.success) return void 0;\n\n const errors: JsonResponseError[] = [];\n\n const errs: v4.$ZodIssue[] | v3.ZodIssue[] = result.error.issues;\n\n for (let i: number = 0; i < errs.length; i++) {\n const err: v4.$ZodIssue | v3.ZodIssue | undefined = errs[i];\n\n if (!err) continue;\n\n errors.push({\n code: ResponseErrorCode.Parse,\n path: err.path.map((p): string => String(p)),\n message: err.message,\n });\n }\n\n throw new HTTPException(400, {\n res: createJsonResponse(c, {\n errors,\n }),\n });\n};\n\nexport type { ZodSchema, ZodError };\nexport { zValidatorHook };\n"],"mappings":";;;;;;;AAoBA,MAAM,kBASF,QAYA,MAMiD;AACjD,KAAI,OAAO,QAAS,QAAO,KAAK;CAEhC,MAAMA,SAA8B,EAAE;CAEtC,MAAMC,OAAuC,OAAO,MAAM;AAE1D,MAAK,IAAIC,IAAY,GAAG,IAAI,KAAK,QAAQ,KAAK;EAC1C,MAAMC,MAA8C,KAAK;AAEzD,MAAI,CAAC,IAAK;AAEV,SAAO,KAAK;GACR,MAAM,kBAAkB;GACxB,MAAM,IAAI,KAAK,KAAK,MAAc,OAAO,EAAE,CAAC;GAC5C,SAAS,IAAI;GAChB,CAAC;;AAGN,OAAM,IAAI,cAAc,KAAK,EACzB,KAAK,mBAAmB,GAAG,EACvB,QACH,CAAC,EACL,CAAC"}
@@ -0,0 +1,72 @@
1
+ import { ZodSchema } from "./hook.js";
2
+ import * as hono0 from "hono";
3
+ import { ValidationTargets } from "hono";
4
+ import * as zod_v4_core0 from "zod/v4/core";
5
+ import * as zod0 from "zod";
6
+ import * as zod_v40 from "zod/v4";
7
+ /**
8
+ * Validate the request with Zod.
9
+ *
10
+ * Following error may returned if the request is invalid:
11
+ *
12
+ * ```jsonc
13
+ * // Status: 400
14
+ * {
15
+ * "success": false,
16
+ * "errors": [
17
+ * {
18
+ * "code": "parse",
19
+ * "path": ["xxx"],
20
+ * "message": "xxx"
21
+ * }
22
+ * ]
23
+ * }
24
+ * ```
25
+ *
26
+ * ### Example
27
+ *
28
+ * ```ts
29
+ * import type { Context, Env } from "hono";
30
+ *
31
+ * import { Hono } from "hono";
32
+ * import { z } from "zod";
33
+ * import { zValidator } from "@jderstd/hono-zod-validator";
34
+ *
35
+ * const app: Hono = new Hono();
36
+ *
37
+ * const json = z.object({
38
+ * name: z.string(),
39
+ * age: z.number()
40
+ * });
41
+ *
42
+ * type Json = z.infer<typeof json>;
43
+ *
44
+ * type RouteContext = Context<
45
+ * Env,
46
+ * "/",
47
+ * {
48
+ * in: {
49
+ * json: Json;
50
+ * },
51
+ * out: {
52
+ * json: Json;
53
+ * },
54
+ * },
55
+ * >;
56
+ *
57
+ * app.post(
58
+ * "/",
59
+ * zValidator("json", json),
60
+ * (c: RouteContext): Response => {
61
+ * const data: Json = c.req.valid("json");
62
+ * return c.json(data);
63
+ * }
64
+ * );
65
+ * ```
66
+ */
67
+ declare const zValidator: <T extends ZodSchema, Target extends keyof ValidationTargets>(target: Target, schema: T) => hono0.MiddlewareHandler<hono0.Env, string, {
68
+ in: (undefined extends (T extends zod0.ZodType<any, zod0.ZodTypeDef, any> ? zod0.input<T> : T extends zod_v4_core0.$ZodType<unknown, unknown> ? zod_v40.input<T> : never) ? true : false) extends true ? { [K in Target]?: ((T extends zod0.ZodType<any, zod0.ZodTypeDef, any> ? zod0.input<T> : T extends zod_v4_core0.$ZodType<unknown, unknown> ? zod_v40.input<T> : never) extends infer T_1 ? T_1 extends (T extends zod0.ZodType<any, zod0.ZodTypeDef, any> ? zod0.input<T> : T extends zod_v4_core0.$ZodType<unknown, unknown> ? zod_v40.input<T> : never) ? T_1 extends ValidationTargets[K] ? T_1 : { [K2 in keyof T_1]?: ValidationTargets[K][K2] | undefined } : never : never) | undefined } : { [K_1 in Target]: (T extends zod0.ZodType<any, zod0.ZodTypeDef, any> ? zod0.input<T> : T extends zod_v4_core0.$ZodType<unknown, unknown> ? zod_v40.input<T> : never) extends infer T_1 ? T_1 extends (T extends zod0.ZodType<any, zod0.ZodTypeDef, any> ? zod0.input<T> : T extends zod_v4_core0.$ZodType<unknown, unknown> ? zod_v40.input<T> : never) ? T_1 extends ValidationTargets[K_1] ? T_1 : { [K2 in keyof T_1]: ValidationTargets[K_1][K2] } : never : never };
69
+ out: { [K_2 in Target]: T extends zod0.ZodType<any, zod0.ZodTypeDef, any> ? zod0.output<T> : T extends zod_v4_core0.$ZodType<unknown, unknown> ? zod_v40.infer<T> : never };
70
+ }>;
71
+ export { zValidator };
72
+ //# sourceMappingURL=index.d.ts.map
package/dist/index.js ADDED
@@ -0,0 +1,71 @@
1
+ const require_rolldown_runtime = require('./_virtual/rolldown_runtime.js');
2
+ const require_hook = require('./hook.js');
3
+ let __hono_zod_validator = require("@hono/zod-validator");
4
+ __hono_zod_validator = require_rolldown_runtime.__toESM(__hono_zod_validator);
5
+
6
+ /**
7
+ * Validate the request with Zod.
8
+ *
9
+ * Following error may returned if the request is invalid:
10
+ *
11
+ * ```jsonc
12
+ * // Status: 400
13
+ * {
14
+ * "success": false,
15
+ * "errors": [
16
+ * {
17
+ * "code": "parse",
18
+ * "path": ["xxx"],
19
+ * "message": "xxx"
20
+ * }
21
+ * ]
22
+ * }
23
+ * ```
24
+ *
25
+ * ### Example
26
+ *
27
+ * ```ts
28
+ * import type { Context, Env } from "hono";
29
+ *
30
+ * import { Hono } from "hono";
31
+ * import { z } from "zod";
32
+ * import { zValidator } from "@jderstd/hono-zod-validator";
33
+ *
34
+ * const app: Hono = new Hono();
35
+ *
36
+ * const json = z.object({
37
+ * name: z.string(),
38
+ * age: z.number()
39
+ * });
40
+ *
41
+ * type Json = z.infer<typeof json>;
42
+ *
43
+ * type RouteContext = Context<
44
+ * Env,
45
+ * "/",
46
+ * {
47
+ * in: {
48
+ * json: Json;
49
+ * },
50
+ * out: {
51
+ * json: Json;
52
+ * },
53
+ * },
54
+ * >;
55
+ *
56
+ * app.post(
57
+ * "/",
58
+ * zValidator("json", json),
59
+ * (c: RouteContext): Response => {
60
+ * const data: Json = c.req.valid("json");
61
+ * return c.json(data);
62
+ * }
63
+ * );
64
+ * ```
65
+ */
66
+ const zValidator = (target, schema) => {
67
+ return (0, __hono_zod_validator.zValidator)(target, schema, require_hook.zValidatorHook);
68
+ };
69
+
70
+ exports.zValidator = zValidator;
71
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","names":["zValidatorHook"],"sources":["../src/index.ts"],"sourcesContent":["import type { ValidationTargets } from \"hono\";\n\nimport type { ZodSchema } from \"#/hook\";\n\nimport { zValidator as zv } from \"@hono/zod-validator\";\n\nimport { zValidatorHook } from \"#/hook\";\n\n/**\n * Validate the request with Zod.\n *\n * Following error may returned if the request is invalid:\n *\n * ```jsonc\n * // Status: 400\n * {\n * \"success\": false,\n * \"errors\": [\n * {\n * \"code\": \"parse\",\n * \"path\": [\"xxx\"],\n * \"message\": \"xxx\"\n * }\n * ]\n * }\n * ```\n *\n * ### Example\n *\n * ```ts\n * import type { Context, Env } from \"hono\";\n *\n * import { Hono } from \"hono\";\n * import { z } from \"zod\";\n * import { zValidator } from \"@jderstd/hono-zod-validator\";\n *\n * const app: Hono = new Hono();\n *\n * const json = z.object({\n * name: z.string(),\n * age: z.number()\n * });\n *\n * type Json = z.infer<typeof json>;\n *\n * type RouteContext = Context<\n * Env,\n * \"/\",\n * {\n * in: {\n * json: Json;\n * },\n * out: {\n * json: Json;\n * },\n * },\n * >;\n *\n * app.post(\n * \"/\",\n * zValidator(\"json\", json),\n * (c: RouteContext): Response => {\n * const data: Json = c.req.valid(\"json\");\n * return c.json(data);\n * }\n * );\n * ```\n */\nconst zValidator = <\n T extends ZodSchema,\n Target extends keyof ValidationTargets,\n>(\n target: Target,\n schema: T,\n) => {\n return zv(target, schema, zValidatorHook);\n};\n\nexport { zValidator };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAM,cAIF,QACA,WACC;AACD,6CAAU,QAAQ,QAAQA,4BAAe"}
package/dist/index.mjs ADDED
@@ -0,0 +1,69 @@
1
+ import { zValidatorHook } from "./hook.mjs";
2
+ import { zValidator as zValidator$1 } from "@hono/zod-validator";
3
+
4
+ /**
5
+ * Validate the request with Zod.
6
+ *
7
+ * Following error may returned if the request is invalid:
8
+ *
9
+ * ```jsonc
10
+ * // Status: 400
11
+ * {
12
+ * "success": false,
13
+ * "errors": [
14
+ * {
15
+ * "code": "parse",
16
+ * "path": ["xxx"],
17
+ * "message": "xxx"
18
+ * }
19
+ * ]
20
+ * }
21
+ * ```
22
+ *
23
+ * ### Example
24
+ *
25
+ * ```ts
26
+ * import type { Context, Env } from "hono";
27
+ *
28
+ * import { Hono } from "hono";
29
+ * import { z } from "zod";
30
+ * import { zValidator } from "@jderstd/hono-zod-validator";
31
+ *
32
+ * const app: Hono = new Hono();
33
+ *
34
+ * const json = z.object({
35
+ * name: z.string(),
36
+ * age: z.number()
37
+ * });
38
+ *
39
+ * type Json = z.infer<typeof json>;
40
+ *
41
+ * type RouteContext = Context<
42
+ * Env,
43
+ * "/",
44
+ * {
45
+ * in: {
46
+ * json: Json;
47
+ * },
48
+ * out: {
49
+ * json: Json;
50
+ * },
51
+ * },
52
+ * >;
53
+ *
54
+ * app.post(
55
+ * "/",
56
+ * zValidator("json", json),
57
+ * (c: RouteContext): Response => {
58
+ * const data: Json = c.req.valid("json");
59
+ * return c.json(data);
60
+ * }
61
+ * );
62
+ * ```
63
+ */
64
+ const zValidator = (target, schema) => {
65
+ return zValidator$1(target, schema, zValidatorHook);
66
+ };
67
+
68
+ export { zValidator };
69
+ //# sourceMappingURL=index.mjs.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.mjs","names":["zv"],"sources":["../src/index.ts"],"sourcesContent":["import type { ValidationTargets } from \"hono\";\n\nimport type { ZodSchema } from \"#/hook\";\n\nimport { zValidator as zv } from \"@hono/zod-validator\";\n\nimport { zValidatorHook } from \"#/hook\";\n\n/**\n * Validate the request with Zod.\n *\n * Following error may returned if the request is invalid:\n *\n * ```jsonc\n * // Status: 400\n * {\n * \"success\": false,\n * \"errors\": [\n * {\n * \"code\": \"parse\",\n * \"path\": [\"xxx\"],\n * \"message\": \"xxx\"\n * }\n * ]\n * }\n * ```\n *\n * ### Example\n *\n * ```ts\n * import type { Context, Env } from \"hono\";\n *\n * import { Hono } from \"hono\";\n * import { z } from \"zod\";\n * import { zValidator } from \"@jderstd/hono-zod-validator\";\n *\n * const app: Hono = new Hono();\n *\n * const json = z.object({\n * name: z.string(),\n * age: z.number()\n * });\n *\n * type Json = z.infer<typeof json>;\n *\n * type RouteContext = Context<\n * Env,\n * \"/\",\n * {\n * in: {\n * json: Json;\n * },\n * out: {\n * json: Json;\n * },\n * },\n * >;\n *\n * app.post(\n * \"/\",\n * zValidator(\"json\", json),\n * (c: RouteContext): Response => {\n * const data: Json = c.req.valid(\"json\");\n * return c.json(data);\n * }\n * );\n * ```\n */\nconst zValidator = <\n T extends ZodSchema,\n Target extends keyof ValidationTargets,\n>(\n target: Target,\n schema: T,\n) => {\n return zv(target, schema, zValidatorHook);\n};\n\nexport { zValidator };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAoEA,MAAM,cAIF,QACA,WACC;AACD,QAAOA,aAAG,QAAQ,QAAQ,eAAe"}
package/package.json ADDED
@@ -0,0 +1,59 @@
1
+ {
2
+ "name": "@jderstd/hono-zod-validator",
3
+ "version": "0.6.0",
4
+ "description": "A Zod validator for Hono",
5
+ "keywords": [
6
+ "jder",
7
+ "hono",
8
+ "zod",
9
+ "validator",
10
+ "ts",
11
+ "typescript",
12
+ "js",
13
+ "javascript"
14
+ ],
15
+ "homepage": "https://github.com/jderstd/hono",
16
+ "bugs": "https://github.com/jderstd/hono/issues",
17
+ "repository": {
18
+ "type": "git",
19
+ "url": "https://github.com/jderstd/hono.git",
20
+ "directory": "packages/hono-zod-validator"
21
+ },
22
+ "license": "MIT",
23
+ "author": {
24
+ "name": "Alpheus",
25
+ "email": "contact@alphe.us"
26
+ },
27
+ "exports": {
28
+ ".": {
29
+ "types": "./dist/index.d.ts",
30
+ "import": "./dist/index.mjs",
31
+ "require": "./dist/index.js"
32
+ },
33
+ "./hook": {
34
+ "types": "./dist/hook.d.ts",
35
+ "import": "./dist/hook.mjs",
36
+ "require": "./dist/hook.js"
37
+ },
38
+ "./package.json": "./package.json"
39
+ },
40
+ "main": "./dist/index.js",
41
+ "module": "./dist/index.mjs",
42
+ "types": "./dist/index.d.ts",
43
+ "files": [
44
+ "dist"
45
+ ],
46
+ "dependencies": {
47
+ "@hono/zod-validator": "~0.7.0"
48
+ },
49
+ "devDependencies": {
50
+ "hono": "4.5.0",
51
+ "zod": "3.25.6",
52
+ "@jderstd/hono": "0.6.0"
53
+ },
54
+ "peerDependencies": {
55
+ "@jderstd/hono": "~0.6.0",
56
+ "hono": "^4.5.0",
57
+ "zod": "^3.25.6 || ^4.0.0"
58
+ }
59
+ }