@jderstd/hono-zod-validator 0.6.0 → 0.7.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/dist/hook.js +3 -7
- package/dist/hook.js.map +1 -1
- package/dist/hook.mjs +3 -3
- package/dist/hook.mjs.map +1 -1
- package/dist/index.js +0 -2
- package/dist/index.js.map +1 -1
- package/package.json +3 -3
- package/dist/_virtual/rolldown_runtime.js +0 -23
package/dist/hook.js
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.js');
|
|
2
1
|
let __jderstd_hono_response = require("@jderstd/hono/response");
|
|
3
|
-
__jderstd_hono_response = require_rolldown_runtime.__toESM(__jderstd_hono_response);
|
|
4
2
|
let __jderstd_hono_response_error = require("@jderstd/hono/response/error");
|
|
5
|
-
|
|
6
|
-
let hono_http_exception = require("hono/http-exception");
|
|
7
|
-
hono_http_exception = require_rolldown_runtime.__toESM(hono_http_exception);
|
|
3
|
+
let __jderstd_hono_response_error_http = require("@jderstd/hono/response/error/http");
|
|
8
4
|
|
|
9
5
|
/**
|
|
10
6
|
* Zod validator hook.
|
|
@@ -18,11 +14,11 @@ const zValidatorHook = (result, c) => {
|
|
|
18
14
|
if (!err) continue;
|
|
19
15
|
errors.push({
|
|
20
16
|
code: __jderstd_hono_response_error.ResponseErrorCode.Parse,
|
|
21
|
-
path: err.path.map((p) =>
|
|
17
|
+
path: err.path.map((p) => p.toString()),
|
|
22
18
|
message: err.message
|
|
23
19
|
});
|
|
24
20
|
}
|
|
25
|
-
throw new
|
|
21
|
+
throw new __jderstd_hono_response_error_http.JderHttpException(400, { res: (0, __jderstd_hono_response.createJsonResponse)(c, { errors }) });
|
|
26
22
|
};
|
|
27
23
|
|
|
28
24
|
exports.zValidatorHook = zValidatorHook;
|
package/dist/hook.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"hook.js","names":["errors: JsonResponseError[]","errs: v4.$ZodIssue[] | v3.ZodIssue[]","i: number","err: v4.$ZodIssue | v3.ZodIssue | undefined","ResponseErrorCode","
|
|
1
|
+
{"version":3,"file":"hook.js","names":["errors: JsonResponseError[]","errs: v4.$ZodIssue[] | v3.ZodIssue[]","i: number","err: v4.$ZodIssue | v3.ZodIssue | undefined","ResponseErrorCode","JderHttpException"],"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 { JderHttpException } from \"@jderstd/hono/response/error/http\";\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 => p.toString()),\n message: err.message,\n });\n }\n\n throw new JderHttpException(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,EAAE,UAAU,CAAC;GAC/C,SAAS,IAAI;GAChB,CAAC;;AAGN,OAAM,IAAIC,qDAAkB,KAAK,EAC7B,qDAAwB,GAAG,EACvB,QACH,CAAC,EACL,CAAC"}
|
package/dist/hook.mjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { createJsonResponse } from "@jderstd/hono/response";
|
|
2
2
|
import { ResponseErrorCode } from "@jderstd/hono/response/error";
|
|
3
|
-
import {
|
|
3
|
+
import { JderHttpException } from "@jderstd/hono/response/error/http";
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Zod validator hook.
|
|
@@ -14,11 +14,11 @@ const zValidatorHook = (result, c) => {
|
|
|
14
14
|
if (!err) continue;
|
|
15
15
|
errors.push({
|
|
16
16
|
code: ResponseErrorCode.Parse,
|
|
17
|
-
path: err.path.map((p) =>
|
|
17
|
+
path: err.path.map((p) => p.toString()),
|
|
18
18
|
message: err.message
|
|
19
19
|
});
|
|
20
20
|
}
|
|
21
|
-
throw new
|
|
21
|
+
throw new JderHttpException(400, { res: createJsonResponse(c, { errors }) });
|
|
22
22
|
};
|
|
23
23
|
|
|
24
24
|
export { zValidatorHook };
|
package/dist/hook.mjs.map
CHANGED
|
@@ -1 +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 {
|
|
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 { JderHttpException } from \"@jderstd/hono/response/error/http\";\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 => p.toString()),\n message: err.message,\n });\n }\n\n throw new JderHttpException(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,EAAE,UAAU,CAAC;GAC/C,SAAS,IAAI;GAChB,CAAC;;AAGN,OAAM,IAAI,kBAAkB,KAAK,EAC7B,KAAK,mBAAmB,GAAG,EACvB,QACH,CAAC,EACL,CAAC"}
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
const require_rolldown_runtime = require('./_virtual/rolldown_runtime.js');
|
|
2
1
|
const require_hook = require('./hook.js');
|
|
3
2
|
let __hono_zod_validator = require("@hono/zod-validator");
|
|
4
|
-
__hono_zod_validator = require_rolldown_runtime.__toESM(__hono_zod_validator);
|
|
5
3
|
|
|
6
4
|
/**
|
|
7
5
|
* Validate the request with Zod.
|
package/dist/index.js.map
CHANGED
|
@@ -1 +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":"
|
|
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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jderstd/hono-zod-validator",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.7.0",
|
|
4
4
|
"description": "A Zod validator for Hono",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"jder",
|
|
@@ -49,10 +49,10 @@
|
|
|
49
49
|
"devDependencies": {
|
|
50
50
|
"hono": "4.5.0",
|
|
51
51
|
"zod": "3.25.6",
|
|
52
|
-
"@jderstd/hono": "0.
|
|
52
|
+
"@jderstd/hono": "0.7.0"
|
|
53
53
|
},
|
|
54
54
|
"peerDependencies": {
|
|
55
|
-
"@jderstd/hono": "~0.
|
|
55
|
+
"@jderstd/hono": "~0.7.0",
|
|
56
56
|
"hono": "^4.5.0",
|
|
57
57
|
"zod": "^3.25.6 || ^4.0.0"
|
|
58
58
|
}
|
|
@@ -1,23 +0,0 @@
|
|
|
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;
|