@jderstd/hono-standard-validator 0.1.0 → 0.2.0-dev.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 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
- __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);
3
+ let __jderstd_hono_response_error_http = require("@jderstd/hono/response/error/http");
8
4
 
9
5
  const sValidatorHook = (result, c) => {
10
6
  if (result.success) return void 0;
@@ -23,7 +19,7 @@ const sValidatorHook = (result, c) => {
23
19
  message: err.message
24
20
  });
25
21
  }
26
- throw new hono_http_exception.HTTPException(400, { res: (0, __jderstd_hono_response.createJsonResponse)(c, { errors }) });
22
+ throw new __jderstd_hono_response_error_http.JderHttpException(400, { res: (0, __jderstd_hono_response.createJsonResponse)(c, { errors }) });
27
23
  };
28
24
 
29
25
  exports.sValidatorHook = sValidatorHook;
package/dist/hook.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hook.js","names":["errors: JsonResponseError[]","errs: readonly StandardSchemaV1.Issue[]","i: number","err: StandardSchemaV1.Issue | undefined","path: string[]","ResponseErrorCode","HTTPException"],"sources":["../src/hook.ts"],"sourcesContent":["import type { JsonResponseError } from \"@jderstd/hono/response\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { Context } from \"hono\";\nimport type { Env, TypedResponse, ValidationTargets } from \"hono/types\";\n\nimport { createJsonResponse } from \"@jderstd/hono/response\";\nimport { ResponseErrorCode } from \"@jderstd/hono/response/error\";\nimport { HTTPException } from \"hono/http-exception\";\n\nconst sValidatorHook = <\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>(\n result: (\n | {\n success: true;\n data: T;\n }\n | {\n success: false;\n error: readonly StandardSchemaV1.Issue[];\n data: T;\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: readonly StandardSchemaV1.Issue[] = result.error;\n\n for (let i: number = 0; i < errs.length; i++) {\n const err: StandardSchemaV1.Issue | undefined = errs[i];\n\n if (!err) continue;\n\n const path: string[] =\n err.path?.map((p) => {\n if (typeof p === \"object\") return p.key.toString();\n return p.toString();\n }) ?? [];\n\n errors.push({\n code: ResponseErrorCode.Parse,\n path,\n message: err.message,\n });\n }\n\n throw new HTTPException(400, {\n res: createJsonResponse(c, {\n errors,\n }),\n });\n};\n\nexport { sValidatorHook };\n"],"mappings":";;;;;;;;AASA,MAAM,kBAQF,QAaA,MAMiD;AACjD,KAAI,OAAO,QAAS,QAAO,KAAK;CAEhC,MAAMA,SAA8B,EAAE;CAEtC,MAAMC,OAA0C,OAAO;AAEvD,MAAK,IAAIC,IAAY,GAAG,IAAI,KAAK,QAAQ,KAAK;EAC1C,MAAMC,MAA0C,KAAK;AAErD,MAAI,CAAC,IAAK;EAEV,MAAMC,OACF,IAAI,MAAM,KAAK,MAAM;AACjB,OAAI,OAAO,MAAM,SAAU,QAAO,EAAE,IAAI,UAAU;AAClD,UAAO,EAAE,UAAU;IACrB,IAAI,EAAE;AAEZ,SAAO,KAAK;GACR,MAAMC,gDAAkB;GACxB;GACA,SAAS,IAAI;GAChB,CAAC;;AAGN,OAAM,IAAIC,kCAAc,KAAK,EACzB,qDAAwB,GAAG,EACvB,QACH,CAAC,EACL,CAAC"}
1
+ {"version":3,"file":"hook.js","names":["errors: JsonResponseError[]","errs: readonly StandardSchemaV1.Issue[]","i: number","err: StandardSchemaV1.Issue | undefined","path: string[]","ResponseErrorCode","JderHttpException"],"sources":["../src/hook.ts"],"sourcesContent":["import type { JsonResponseError } from \"@jderstd/hono/response\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { Context } from \"hono\";\nimport type { Env, TypedResponse, ValidationTargets } from \"hono/types\";\n\nimport { createJsonResponse } from \"@jderstd/hono/response\";\nimport { ResponseErrorCode } from \"@jderstd/hono/response/error\";\nimport { JderHttpException } from \"@jderstd/hono/response/error/http\";\n\nconst sValidatorHook = <\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>(\n result: (\n | {\n success: true;\n data: T;\n }\n | {\n success: false;\n error: readonly StandardSchemaV1.Issue[];\n data: T;\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: readonly StandardSchemaV1.Issue[] = result.error;\n\n for (let i: number = 0; i < errs.length; i++) {\n const err: StandardSchemaV1.Issue | undefined = errs[i];\n\n if (!err) continue;\n\n const path: string[] =\n err.path?.map((p) => {\n if (typeof p === \"object\") return p.key.toString();\n return p.toString();\n }) ?? [];\n\n errors.push({\n code: ResponseErrorCode.Parse,\n path,\n message: err.message,\n });\n }\n\n throw new JderHttpException(400, {\n res: createJsonResponse(c, {\n errors,\n }),\n });\n};\n\nexport { sValidatorHook };\n"],"mappings":";;;;AASA,MAAM,kBAQF,QAaA,MAMiD;AACjD,KAAI,OAAO,QAAS,QAAO,KAAK;CAEhC,MAAMA,SAA8B,EAAE;CAEtC,MAAMC,OAA0C,OAAO;AAEvD,MAAK,IAAIC,IAAY,GAAG,IAAI,KAAK,QAAQ,KAAK;EAC1C,MAAMC,MAA0C,KAAK;AAErD,MAAI,CAAC,IAAK;EAEV,MAAMC,OACF,IAAI,MAAM,KAAK,MAAM;AACjB,OAAI,OAAO,MAAM,SAAU,QAAO,EAAE,IAAI,UAAU;AAClD,UAAO,EAAE,UAAU;IACrB,IAAI,EAAE;AAEZ,SAAO,KAAK;GACR,MAAMC,gDAAkB;GACxB;GACA,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 { HTTPException } from "hono/http-exception";
3
+ import { JderHttpException } from "@jderstd/hono/response/error/http";
4
4
 
5
5
  const sValidatorHook = (result, c) => {
6
6
  if (result.success) return void 0;
@@ -19,7 +19,7 @@ const sValidatorHook = (result, c) => {
19
19
  message: err.message
20
20
  });
21
21
  }
22
- throw new HTTPException(400, { res: createJsonResponse(c, { errors }) });
22
+ throw new JderHttpException(400, { res: createJsonResponse(c, { errors }) });
23
23
  };
24
24
 
25
25
  export { sValidatorHook };
package/dist/hook.mjs.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"hook.mjs","names":["errors: JsonResponseError[]","errs: readonly StandardSchemaV1.Issue[]","i: number","err: StandardSchemaV1.Issue | undefined","path: string[]"],"sources":["../src/hook.ts"],"sourcesContent":["import type { JsonResponseError } from \"@jderstd/hono/response\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { Context } from \"hono\";\nimport type { Env, TypedResponse, ValidationTargets } from \"hono/types\";\n\nimport { createJsonResponse } from \"@jderstd/hono/response\";\nimport { ResponseErrorCode } from \"@jderstd/hono/response/error\";\nimport { HTTPException } from \"hono/http-exception\";\n\nconst sValidatorHook = <\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>(\n result: (\n | {\n success: true;\n data: T;\n }\n | {\n success: false;\n error: readonly StandardSchemaV1.Issue[];\n data: T;\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: readonly StandardSchemaV1.Issue[] = result.error;\n\n for (let i: number = 0; i < errs.length; i++) {\n const err: StandardSchemaV1.Issue | undefined = errs[i];\n\n if (!err) continue;\n\n const path: string[] =\n err.path?.map((p) => {\n if (typeof p === \"object\") return p.key.toString();\n return p.toString();\n }) ?? [];\n\n errors.push({\n code: ResponseErrorCode.Parse,\n path,\n message: err.message,\n });\n }\n\n throw new HTTPException(400, {\n res: createJsonResponse(c, {\n errors,\n }),\n });\n};\n\nexport { sValidatorHook };\n"],"mappings":";;;;AASA,MAAM,kBAQF,QAaA,MAMiD;AACjD,KAAI,OAAO,QAAS,QAAO,KAAK;CAEhC,MAAMA,SAA8B,EAAE;CAEtC,MAAMC,OAA0C,OAAO;AAEvD,MAAK,IAAIC,IAAY,GAAG,IAAI,KAAK,QAAQ,KAAK;EAC1C,MAAMC,MAA0C,KAAK;AAErD,MAAI,CAAC,IAAK;EAEV,MAAMC,OACF,IAAI,MAAM,KAAK,MAAM;AACjB,OAAI,OAAO,MAAM,SAAU,QAAO,EAAE,IAAI,UAAU;AAClD,UAAO,EAAE,UAAU;IACrB,IAAI,EAAE;AAEZ,SAAO,KAAK;GACR,MAAM,kBAAkB;GACxB;GACA,SAAS,IAAI;GAChB,CAAC;;AAGN,OAAM,IAAI,cAAc,KAAK,EACzB,KAAK,mBAAmB,GAAG,EACvB,QACH,CAAC,EACL,CAAC"}
1
+ {"version":3,"file":"hook.mjs","names":["errors: JsonResponseError[]","errs: readonly StandardSchemaV1.Issue[]","i: number","err: StandardSchemaV1.Issue | undefined","path: string[]"],"sources":["../src/hook.ts"],"sourcesContent":["import type { JsonResponseError } from \"@jderstd/hono/response\";\nimport type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { Context } from \"hono\";\nimport type { Env, TypedResponse, ValidationTargets } from \"hono/types\";\n\nimport { createJsonResponse } from \"@jderstd/hono/response\";\nimport { ResponseErrorCode } from \"@jderstd/hono/response/error\";\nimport { JderHttpException } from \"@jderstd/hono/response/error/http\";\n\nconst sValidatorHook = <\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>(\n result: (\n | {\n success: true;\n data: T;\n }\n | {\n success: false;\n error: readonly StandardSchemaV1.Issue[];\n data: T;\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: readonly StandardSchemaV1.Issue[] = result.error;\n\n for (let i: number = 0; i < errs.length; i++) {\n const err: StandardSchemaV1.Issue | undefined = errs[i];\n\n if (!err) continue;\n\n const path: string[] =\n err.path?.map((p) => {\n if (typeof p === \"object\") return p.key.toString();\n return p.toString();\n }) ?? [];\n\n errors.push({\n code: ResponseErrorCode.Parse,\n path,\n message: err.message,\n });\n }\n\n throw new JderHttpException(400, {\n res: createJsonResponse(c, {\n errors,\n }),\n });\n};\n\nexport { sValidatorHook };\n"],"mappings":";;;;AASA,MAAM,kBAQF,QAaA,MAMiD;AACjD,KAAI,OAAO,QAAS,QAAO,KAAK;CAEhC,MAAMA,SAA8B,EAAE;CAEtC,MAAMC,OAA0C,OAAO;AAEvD,MAAK,IAAIC,IAAY,GAAG,IAAI,KAAK,QAAQ,KAAK;EAC1C,MAAMC,MAA0C,KAAK;AAErD,MAAI,CAAC,IAAK;EAEV,MAAMC,OACF,IAAI,MAAM,KAAK,MAAM;AACjB,OAAI,OAAO,MAAM,SAAU,QAAO,EAAE,IAAI,UAAU;AAClD,UAAO,EAAE,UAAU;IACrB,IAAI,EAAE;AAEZ,SAAO,KAAK;GACR,MAAM,kBAAkB;GACxB;GACA,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_standard_validator = require("@hono/standard-validator");
4
- __hono_standard_validator = require_rolldown_runtime.__toESM(__hono_standard_validator);
5
3
 
6
4
  /**
7
5
  * Validate the request with validator based on Standard Schema.
package/dist/index.js.map CHANGED
@@ -1 +1 @@
1
- {"version":3,"file":"index.js","names":["sValidatorHook"],"sources":["../src/index.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { ValidationTargets } from \"hono\";\n\nimport { sValidator as sv } from \"@hono/standard-validator\";\n\nimport { sValidatorHook } from \"#/hook\";\n\n/**\n * Validate the request with validator based on Standard Schema.\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 { sValidator } from \"@jderstd/hono-standard-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 * sValidator(\"json\", json),\n * (c: RouteContext): Response => {\n * const data: Json = c.req.valid(\"json\");\n * return c.json(data);\n * }\n * );\n * ```\n */\nconst sValidator = <\n Target extends keyof ValidationTargets,\n Schema extends StandardSchemaV1,\n>(\n target: Target,\n schema: Schema,\n) => {\n return sv(target, schema, sValidatorHook);\n};\n\nexport { sValidator };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAM,cAIF,QACA,WACC;AACD,kDAAU,QAAQ,QAAQA,4BAAe"}
1
+ {"version":3,"file":"index.js","names":["sValidatorHook"],"sources":["../src/index.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { ValidationTargets } from \"hono\";\n\nimport { sValidator as sv } from \"@hono/standard-validator\";\n\nimport { sValidatorHook } from \"#/hook\";\n\n/**\n * Validate the request with validator based on Standard Schema.\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 { sValidator } from \"@jderstd/hono-standard-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 * sValidator(\"json\", json),\n * (c: RouteContext): Response => {\n * const data: Json = c.req.valid(\"json\");\n * return c.json(data);\n * }\n * );\n * ```\n */\nconst sValidator = <\n Target extends keyof ValidationTargets,\n Schema extends StandardSchemaV1,\n>(\n target: Target,\n schema: Schema,\n) => {\n return sv(target, schema, sValidatorHook);\n};\n\nexport { sValidator };\n"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAmEA,MAAM,cAIF,QACA,WACC;AACD,kDAAU,QAAQ,QAAQA,4BAAe"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@jderstd/hono-standard-validator",
3
- "version": "0.1.0",
3
+ "version": "0.2.0-dev.0",
4
4
  "description": "A standard validator for Hono",
5
5
  "keywords": [
6
6
  "jder",
@@ -48,7 +48,7 @@
48
48
  },
49
49
  "devDependencies": {
50
50
  "hono": "4.5.0",
51
- "@jderstd/hono": "0.6.0"
51
+ "@jderstd/hono": "0.7.0-dev.0"
52
52
  },
53
53
  "peerDependencies": {
54
54
  "@jderstd/hono": "~0.6.0",
@@ -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;