@shware/http 0.2.7 → 0.2.9
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/__tests__/index.test.cjs +27 -0
- package/dist/__tests__/index.test.cjs.map +1 -0
- package/dist/__tests__/index.test.d.cts +2 -0
- package/dist/__tests__/index.test.d.ts +2 -0
- package/dist/__tests__/index.test.mjs +25 -0
- package/dist/__tests__/index.test.mjs.map +1 -0
- package/dist/detail.cjs +93 -0
- package/dist/detail.cjs.map +1 -0
- package/dist/detail.d.cts +101 -0
- package/dist/detail.d.ts +101 -0
- package/dist/detail.mjs +67 -0
- package/dist/detail.mjs.map +1 -0
- package/dist/hono/geolocation.cjs +59 -0
- package/dist/hono/geolocation.cjs.map +1 -0
- package/dist/hono/geolocation.d.cts +21 -0
- package/dist/hono/geolocation.d.ts +21 -0
- package/dist/hono/geolocation.mjs +33 -0
- package/dist/hono/geolocation.mjs.map +1 -0
- package/dist/hono/handler.cjs +42 -0
- package/dist/hono/handler.cjs.map +1 -0
- package/dist/hono/handler.d.cts +11 -0
- package/dist/hono/handler.d.ts +11 -0
- package/dist/hono/handler.mjs +17 -0
- package/dist/hono/handler.mjs.map +1 -0
- package/dist/hono/index.cjs +39 -0
- package/dist/hono/index.cjs.map +1 -0
- package/dist/hono/index.d.cts +8 -0
- package/dist/hono/index.d.ts +8 -0
- package/dist/hono/index.mjs +11 -0
- package/dist/hono/index.mjs.map +1 -0
- package/dist/hono/validator.cjs +44 -0
- package/dist/hono/validator.cjs.map +1 -0
- package/dist/hono/validator.d.cts +26 -0
- package/dist/hono/validator.d.ts +26 -0
- package/dist/hono/validator.mjs +19 -0
- package/dist/hono/validator.mjs.map +1 -0
- package/dist/index.cjs +13 -387
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -269
- package/dist/index.d.ts +6 -269
- package/dist/index.mjs +6 -370
- package/dist/index.mjs.map +1 -1
- package/dist/message.cjs +32 -0
- package/dist/message.cjs.map +1 -0
- package/dist/message.d.cts +3 -0
- package/dist/message.d.ts +3 -0
- package/dist/message.mjs +7 -0
- package/dist/message.mjs.map +1 -0
- package/dist/reason.cjs +19 -0
- package/dist/reason.cjs.map +1 -0
- package/dist/reason.d.cts +66 -0
- package/dist/reason.d.ts +66 -0
- package/dist/reason.mjs +1 -0
- package/dist/reason.mjs.map +1 -0
- package/dist/snowflake.cjs +75 -0
- package/dist/snowflake.cjs.map +1 -0
- package/dist/snowflake.d.cts +29 -0
- package/dist/snowflake.d.ts +29 -0
- package/dist/snowflake.mjs +49 -0
- package/dist/snowflake.mjs.map +1 -0
- package/dist/status.cjs +266 -0
- package/dist/status.cjs.map +1 -0
- package/dist/status.d.cts +69 -0
- package/dist/status.d.ts +69 -0
- package/dist/status.mjs +237 -0
- package/dist/status.mjs.map +1 -0
- package/dist/vaild.cjs +51 -0
- package/dist/vaild.cjs.map +1 -0
- package/dist/vaild.d.cts +13 -0
- package/dist/vaild.d.ts +13 -0
- package/dist/vaild.mjs +26 -0
- package/dist/vaild.mjs.map +1 -0
- package/package.json +14 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { HTTPResponseError, Bindings } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport { Status, StatusError } from '../status';\nimport { Details } from '../detail';\n\ntype Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\nexport function errorHandler<E extends Env = any>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n if (error instanceof StatusError) {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.url}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n error.body?.error?.details?.push(...details.list);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n return c.json(Status.internal(error.message).response(), 500);\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAIA,oBAAoC;AACpC,oBAAwB;AAOjB,SAAS,aACd,OACA,GAC8B;AAC9B,MAAI,iBAAiB,2BAAa;AAChC,UAAM,YAAY,EAAE,IAAI,WAAW;AACnC,UAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,GAAG;AACjD,UAAM,UAAU,sBAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AACpE,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,SAAO,EAAE,KAAK,qBAAO,SAAS,MAAM,OAAO,EAAE,SAAS,GAAG,GAAG;AAC9D;","names":[]}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Context } from 'hono';
|
|
2
|
+
import { Bindings, HTTPResponseError } from 'hono/types';
|
|
3
|
+
import { RequestIdVariables } from 'hono/request-id';
|
|
4
|
+
|
|
5
|
+
type Env = {
|
|
6
|
+
Variables: RequestIdVariables;
|
|
7
|
+
Bindings?: Bindings;
|
|
8
|
+
};
|
|
9
|
+
declare function errorHandler<E extends Env = any>(error: Error | HTTPResponseError, c: Context<E>): Response | Promise<Response>;
|
|
10
|
+
|
|
11
|
+
export { errorHandler };
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import { Context } from 'hono';
|
|
2
|
+
import { Bindings, HTTPResponseError } from 'hono/types';
|
|
3
|
+
import { RequestIdVariables } from 'hono/request-id';
|
|
4
|
+
|
|
5
|
+
type Env = {
|
|
6
|
+
Variables: RequestIdVariables;
|
|
7
|
+
Bindings?: Bindings;
|
|
8
|
+
};
|
|
9
|
+
declare function errorHandler<E extends Env = any>(error: Error | HTTPResponseError, c: Context<E>): Response | Promise<Response>;
|
|
10
|
+
|
|
11
|
+
export { errorHandler };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// src/hono/handler.ts
|
|
2
|
+
import { Status, StatusError } from "../status.mjs";
|
|
3
|
+
import { Details } from "../detail.mjs";
|
|
4
|
+
function errorHandler(error, c) {
|
|
5
|
+
if (error instanceof StatusError) {
|
|
6
|
+
const requestId = c.get("requestId");
|
|
7
|
+
const servingData = `${c.req.method}: ${c.req.url}`;
|
|
8
|
+
const details = Details.new().requestInfo({ requestId, servingData });
|
|
9
|
+
error.body?.error?.details?.push(...details.list);
|
|
10
|
+
return c.json(error.body, error.status);
|
|
11
|
+
}
|
|
12
|
+
return c.json(Status.internal(error.message).response(), 500);
|
|
13
|
+
}
|
|
14
|
+
export {
|
|
15
|
+
errorHandler
|
|
16
|
+
};
|
|
17
|
+
//# sourceMappingURL=handler.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hono/handler.ts"],"sourcesContent":["import type { Context } from 'hono';\nimport type { HTTPResponseError, Bindings } from 'hono/types';\nimport type { ContentfulStatusCode } from 'hono/utils/http-status';\nimport type { RequestIdVariables } from 'hono/request-id';\nimport { Status, StatusError } from '../status';\nimport { Details } from '../detail';\n\ntype Env = {\n Variables: RequestIdVariables;\n Bindings?: Bindings;\n};\n\nexport function errorHandler<E extends Env = any>(\n error: Error | HTTPResponseError,\n c: Context<E>\n): Response | Promise<Response> {\n if (error instanceof StatusError) {\n const requestId = c.get('requestId');\n const servingData = `${c.req.method}: ${c.req.url}`;\n const details = Details.new().requestInfo({ requestId, servingData });\n error.body?.error?.details?.push(...details.list);\n return c.json(error.body, error.status as ContentfulStatusCode);\n }\n\n return c.json(Status.internal(error.message).response(), 500);\n}\n"],"mappings":";AAIA,SAAS,QAAQ,mBAAmB;AACpC,SAAS,eAAe;AAOjB,SAAS,aACd,OACA,GAC8B;AAC9B,MAAI,iBAAiB,aAAa;AAChC,UAAM,YAAY,EAAE,IAAI,WAAW;AACnC,UAAM,cAAc,GAAG,EAAE,IAAI,MAAM,KAAK,EAAE,IAAI,GAAG;AACjD,UAAM,UAAU,QAAQ,IAAI,EAAE,YAAY,EAAE,WAAW,YAAY,CAAC;AACpE,UAAM,MAAM,OAAO,SAAS,KAAK,GAAG,QAAQ,IAAI;AAChD,WAAO,EAAE,KAAK,MAAM,MAAM,MAAM,MAA8B;AAAA,EAChE;AAEA,SAAO,EAAE,KAAK,OAAO,SAAS,MAAM,OAAO,EAAE,SAAS,GAAG,GAAG;AAC9D;","names":[]}
|
|
@@ -0,0 +1,39 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/hono/index.ts
|
|
21
|
+
var hono_exports = {};
|
|
22
|
+
__export(hono_exports, {
|
|
23
|
+
errorHandler: () => import_handler.errorHandler,
|
|
24
|
+
geolocation: () => import_geolocation.geolocation,
|
|
25
|
+
geolocationVercel: () => import_geolocation.geolocationVercel,
|
|
26
|
+
zValidator: () => import_validator.zValidator
|
|
27
|
+
});
|
|
28
|
+
module.exports = __toCommonJS(hono_exports);
|
|
29
|
+
var import_validator = require("./validator.cjs");
|
|
30
|
+
var import_handler = require("./handler.cjs");
|
|
31
|
+
var import_geolocation = require("./geolocation.cjs");
|
|
32
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
33
|
+
0 && (module.exports = {
|
|
34
|
+
errorHandler,
|
|
35
|
+
geolocation,
|
|
36
|
+
geolocationVercel,
|
|
37
|
+
zValidator
|
|
38
|
+
});
|
|
39
|
+
//# sourceMappingURL=index.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hono/index.ts"],"sourcesContent":["export { zValidator } from './validator';\nexport { errorHandler } from './handler';\nexport { geolocation, geolocationVercel } from './geolocation';\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,uBAA2B;AAC3B,qBAA6B;AAC7B,yBAA+C;","names":[]}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { zValidator } from './validator.cjs';
|
|
2
|
+
export { errorHandler } from './handler.cjs';
|
|
3
|
+
export { geolocation, geolocationVercel } from './geolocation.cjs';
|
|
4
|
+
import 'hono/utils/headers';
|
|
5
|
+
import 'hono/types';
|
|
6
|
+
import 'hono';
|
|
7
|
+
import 'zod';
|
|
8
|
+
import 'hono/request-id';
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
export { zValidator } from './validator.js';
|
|
2
|
+
export { errorHandler } from './handler.js';
|
|
3
|
+
export { geolocation, geolocationVercel } from './geolocation.js';
|
|
4
|
+
import 'hono/utils/headers';
|
|
5
|
+
import 'hono/types';
|
|
6
|
+
import 'hono';
|
|
7
|
+
import 'zod';
|
|
8
|
+
import 'hono/request-id';
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
// src/hono/index.ts
|
|
2
|
+
import { zValidator } from "./validator.mjs";
|
|
3
|
+
import { errorHandler } from "./handler.mjs";
|
|
4
|
+
import { geolocation, geolocationVercel } from "./geolocation.mjs";
|
|
5
|
+
export {
|
|
6
|
+
errorHandler,
|
|
7
|
+
geolocation,
|
|
8
|
+
geolocationVercel,
|
|
9
|
+
zValidator
|
|
10
|
+
};
|
|
11
|
+
//# sourceMappingURL=index.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hono/index.ts"],"sourcesContent":["export { zValidator } from './validator';\nexport { errorHandler } from './handler';\nexport { geolocation, geolocationVercel } from './geolocation';\n"],"mappings":";AAAA,SAAS,kBAAkB;AAC3B,SAAS,oBAAoB;AAC7B,SAAS,aAAa,yBAAyB;","names":[]}
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
+
var __export = (target, all) => {
|
|
7
|
+
for (var name in all)
|
|
8
|
+
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
+
};
|
|
10
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/hono/validator.ts
|
|
21
|
+
var validator_exports = {};
|
|
22
|
+
__export(validator_exports, {
|
|
23
|
+
zValidator: () => zValidator
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(validator_exports);
|
|
26
|
+
var import_validator = require("hono/validator");
|
|
27
|
+
var import_status = require("../status.cjs");
|
|
28
|
+
var import_detail = require("../detail.cjs");
|
|
29
|
+
function zValidator(target, schema) {
|
|
30
|
+
return (0, import_validator.validator)(target, async (value) => {
|
|
31
|
+
const result = await schema.safeParseAsync(value);
|
|
32
|
+
if (result.success) return result.data;
|
|
33
|
+
const fieldViolations = result.error.issues.map(
|
|
34
|
+
({ path, message }) => ({ field: path.join("."), description: message })
|
|
35
|
+
);
|
|
36
|
+
const details = import_detail.Details.new().badRequest({ fieldViolations });
|
|
37
|
+
throw import_status.Status.invalidArgument().error(details);
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
41
|
+
0 && (module.exports = {
|
|
42
|
+
zValidator
|
|
43
|
+
});
|
|
44
|
+
//# sourceMappingURL=validator.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hono/validator.ts"],"sourcesContent":["import type { z, ZodSchema } from 'zod';\nimport type { ValidationTargets } from 'hono';\nimport { validator } from 'hono/validator';\nimport { Status } from '../status';\nimport { Details } from '../detail';\nimport type { BadRequest } from '../detail';\n\nexport function zValidator<S extends ZodSchema>(target: keyof ValidationTargets, schema: S) {\n return validator(target, async (value) => {\n const result = await schema.safeParseAsync(value);\n if (result.success) return result.data as z.infer<S>;\n\n const fieldViolations: BadRequest['fieldViolations'] = result.error.issues.map(\n ({ path, message }) => ({ field: path.join('.'), description: message })\n );\n const details = Details.new().badRequest({ fieldViolations });\n throw Status.invalidArgument().error(details);\n });\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAEA,uBAA0B;AAC1B,oBAAuB;AACvB,oBAAwB;AAGjB,SAAS,WAAgC,QAAiC,QAAW;AAC1F,aAAO,4BAAU,QAAQ,OAAO,UAAU;AACxC,UAAM,SAAS,MAAM,OAAO,eAAe,KAAK;AAChD,QAAI,OAAO,QAAS,QAAO,OAAO;AAElC,UAAM,kBAAiD,OAAO,MAAM,OAAO;AAAA,MACzE,CAAC,EAAE,MAAM,QAAQ,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,GAAG,aAAa,QAAQ;AAAA,IACxE;AACA,UAAM,UAAU,sBAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,UAAM,qBAAO,gBAAgB,EAAE,MAAM,OAAO;AAAA,EAC9C,CAAC;AACH;","names":[]}
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as hono_utils_headers from 'hono/utils/headers';
|
|
2
|
+
import * as hono_types from 'hono/types';
|
|
3
|
+
import * as hono from 'hono';
|
|
4
|
+
import { ValidationTargets } from 'hono';
|
|
5
|
+
import { ZodSchema, z } from 'zod';
|
|
6
|
+
|
|
7
|
+
declare function zValidator<S extends ZodSchema>(target: keyof ValidationTargets, schema: S): hono.MiddlewareHandler<any, string, {
|
|
8
|
+
in: {
|
|
9
|
+
json: z.TypeOf<S> extends infer T ? T extends z.TypeOf<S> ? T extends Response & hono.TypedResponse<any> ? never : T : never : never;
|
|
10
|
+
form: (z.TypeOf<S> extends infer T_2 ? T_2 extends z.TypeOf<S> ? T_2 extends Response & hono.TypedResponse<any> ? never : T_2 : never : never) extends infer T_1 ? { [K2 in keyof T_1]: Record<string, hono_types.ParsedFormValue | hono_types.ParsedFormValue[]>[K2]; } : never;
|
|
11
|
+
query: (z.TypeOf<S> extends infer T_4 ? T_4 extends z.TypeOf<S> ? T_4 extends Response & hono.TypedResponse<any> ? never : T_4 : never : never) extends infer T_3 ? { [K2_1 in keyof T_3]: Record<string, string | string[]>[K2_1]; } : never;
|
|
12
|
+
param: (z.TypeOf<S> extends infer T_6 ? T_6 extends z.TypeOf<S> ? T_6 extends Response & hono.TypedResponse<any> ? never : T_6 : never : never) extends infer T_5 ? { [K2_2 in keyof T_5]: Record<string, string>[K2_2]; } : never;
|
|
13
|
+
header: (z.TypeOf<S> extends infer T_8 ? T_8 extends z.TypeOf<S> ? T_8 extends Response & hono.TypedResponse<any> ? never : T_8 : never : never) extends infer T_7 ? { [K2_3 in keyof T_7]: Record<hono_utils_headers.RequestHeader | hono_utils_headers.CustomHeader, string>[K2_3]; } : never;
|
|
14
|
+
cookie: (z.TypeOf<S> extends infer T_10 ? T_10 extends z.TypeOf<S> ? T_10 extends Response & hono.TypedResponse<any> ? never : T_10 : never : never) extends infer T_9 ? { [K2_4 in keyof T_9]: Record<string, string>[K2_4]; } : never;
|
|
15
|
+
};
|
|
16
|
+
out: {
|
|
17
|
+
json: z.TypeOf<S> extends infer T_11 ? T_11 extends z.TypeOf<S> ? T_11 extends Response & hono.TypedResponse<any> ? never : T_11 : never : never;
|
|
18
|
+
form: z.TypeOf<S> extends infer T_12 ? T_12 extends z.TypeOf<S> ? T_12 extends Response & hono.TypedResponse<any> ? never : T_12 : never : never;
|
|
19
|
+
query: z.TypeOf<S> extends infer T_13 ? T_13 extends z.TypeOf<S> ? T_13 extends Response & hono.TypedResponse<any> ? never : T_13 : never : never;
|
|
20
|
+
param: z.TypeOf<S> extends infer T_14 ? T_14 extends z.TypeOf<S> ? T_14 extends Response & hono.TypedResponse<any> ? never : T_14 : never : never;
|
|
21
|
+
header: z.TypeOf<S> extends infer T_15 ? T_15 extends z.TypeOf<S> ? T_15 extends Response & hono.TypedResponse<any> ? never : T_15 : never : never;
|
|
22
|
+
cookie: z.TypeOf<S> extends infer T_16 ? T_16 extends z.TypeOf<S> ? T_16 extends Response & hono.TypedResponse<any> ? never : T_16 : never : never;
|
|
23
|
+
};
|
|
24
|
+
}>;
|
|
25
|
+
|
|
26
|
+
export { zValidator };
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import * as hono_utils_headers from 'hono/utils/headers';
|
|
2
|
+
import * as hono_types from 'hono/types';
|
|
3
|
+
import * as hono from 'hono';
|
|
4
|
+
import { ValidationTargets } from 'hono';
|
|
5
|
+
import { ZodSchema, z } from 'zod';
|
|
6
|
+
|
|
7
|
+
declare function zValidator<S extends ZodSchema>(target: keyof ValidationTargets, schema: S): hono.MiddlewareHandler<any, string, {
|
|
8
|
+
in: {
|
|
9
|
+
json: z.TypeOf<S> extends infer T ? T extends z.TypeOf<S> ? T extends Response & hono.TypedResponse<any> ? never : T : never : never;
|
|
10
|
+
form: (z.TypeOf<S> extends infer T_2 ? T_2 extends z.TypeOf<S> ? T_2 extends Response & hono.TypedResponse<any> ? never : T_2 : never : never) extends infer T_1 ? { [K2 in keyof T_1]: Record<string, hono_types.ParsedFormValue | hono_types.ParsedFormValue[]>[K2]; } : never;
|
|
11
|
+
query: (z.TypeOf<S> extends infer T_4 ? T_4 extends z.TypeOf<S> ? T_4 extends Response & hono.TypedResponse<any> ? never : T_4 : never : never) extends infer T_3 ? { [K2_1 in keyof T_3]: Record<string, string | string[]>[K2_1]; } : never;
|
|
12
|
+
param: (z.TypeOf<S> extends infer T_6 ? T_6 extends z.TypeOf<S> ? T_6 extends Response & hono.TypedResponse<any> ? never : T_6 : never : never) extends infer T_5 ? { [K2_2 in keyof T_5]: Record<string, string>[K2_2]; } : never;
|
|
13
|
+
header: (z.TypeOf<S> extends infer T_8 ? T_8 extends z.TypeOf<S> ? T_8 extends Response & hono.TypedResponse<any> ? never : T_8 : never : never) extends infer T_7 ? { [K2_3 in keyof T_7]: Record<hono_utils_headers.RequestHeader | hono_utils_headers.CustomHeader, string>[K2_3]; } : never;
|
|
14
|
+
cookie: (z.TypeOf<S> extends infer T_10 ? T_10 extends z.TypeOf<S> ? T_10 extends Response & hono.TypedResponse<any> ? never : T_10 : never : never) extends infer T_9 ? { [K2_4 in keyof T_9]: Record<string, string>[K2_4]; } : never;
|
|
15
|
+
};
|
|
16
|
+
out: {
|
|
17
|
+
json: z.TypeOf<S> extends infer T_11 ? T_11 extends z.TypeOf<S> ? T_11 extends Response & hono.TypedResponse<any> ? never : T_11 : never : never;
|
|
18
|
+
form: z.TypeOf<S> extends infer T_12 ? T_12 extends z.TypeOf<S> ? T_12 extends Response & hono.TypedResponse<any> ? never : T_12 : never : never;
|
|
19
|
+
query: z.TypeOf<S> extends infer T_13 ? T_13 extends z.TypeOf<S> ? T_13 extends Response & hono.TypedResponse<any> ? never : T_13 : never : never;
|
|
20
|
+
param: z.TypeOf<S> extends infer T_14 ? T_14 extends z.TypeOf<S> ? T_14 extends Response & hono.TypedResponse<any> ? never : T_14 : never : never;
|
|
21
|
+
header: z.TypeOf<S> extends infer T_15 ? T_15 extends z.TypeOf<S> ? T_15 extends Response & hono.TypedResponse<any> ? never : T_15 : never : never;
|
|
22
|
+
cookie: z.TypeOf<S> extends infer T_16 ? T_16 extends z.TypeOf<S> ? T_16 extends Response & hono.TypedResponse<any> ? never : T_16 : never : never;
|
|
23
|
+
};
|
|
24
|
+
}>;
|
|
25
|
+
|
|
26
|
+
export { zValidator };
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
// src/hono/validator.ts
|
|
2
|
+
import { validator } from "hono/validator";
|
|
3
|
+
import { Status } from "../status.mjs";
|
|
4
|
+
import { Details } from "../detail.mjs";
|
|
5
|
+
function zValidator(target, schema) {
|
|
6
|
+
return validator(target, async (value) => {
|
|
7
|
+
const result = await schema.safeParseAsync(value);
|
|
8
|
+
if (result.success) return result.data;
|
|
9
|
+
const fieldViolations = result.error.issues.map(
|
|
10
|
+
({ path, message }) => ({ field: path.join("."), description: message })
|
|
11
|
+
);
|
|
12
|
+
const details = Details.new().badRequest({ fieldViolations });
|
|
13
|
+
throw Status.invalidArgument().error(details);
|
|
14
|
+
});
|
|
15
|
+
}
|
|
16
|
+
export {
|
|
17
|
+
zValidator
|
|
18
|
+
};
|
|
19
|
+
//# sourceMappingURL=validator.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/hono/validator.ts"],"sourcesContent":["import type { z, ZodSchema } from 'zod';\nimport type { ValidationTargets } from 'hono';\nimport { validator } from 'hono/validator';\nimport { Status } from '../status';\nimport { Details } from '../detail';\nimport type { BadRequest } from '../detail';\n\nexport function zValidator<S extends ZodSchema>(target: keyof ValidationTargets, schema: S) {\n return validator(target, async (value) => {\n const result = await schema.safeParseAsync(value);\n if (result.success) return result.data as z.infer<S>;\n\n const fieldViolations: BadRequest['fieldViolations'] = result.error.issues.map(\n ({ path, message }) => ({ field: path.join('.'), description: message })\n );\n const details = Details.new().badRequest({ fieldViolations });\n throw Status.invalidArgument().error(details);\n });\n}\n"],"mappings":";AAEA,SAAS,iBAAiB;AAC1B,SAAS,cAAc;AACvB,SAAS,eAAe;AAGjB,SAAS,WAAgC,QAAiC,QAAW;AAC1F,SAAO,UAAU,QAAQ,OAAO,UAAU;AACxC,UAAM,SAAS,MAAM,OAAO,eAAe,KAAK;AAChD,QAAI,OAAO,QAAS,QAAO,OAAO;AAElC,UAAM,kBAAiD,OAAO,MAAM,OAAO;AAAA,MACzE,CAAC,EAAE,MAAM,QAAQ,OAAO,EAAE,OAAO,KAAK,KAAK,GAAG,GAAG,aAAa,QAAQ;AAAA,IACxE;AACA,UAAM,UAAU,QAAQ,IAAI,EAAE,WAAW,EAAE,gBAAgB,CAAC;AAC5D,UAAM,OAAO,gBAAgB,EAAE,MAAM,OAAO;AAAA,EAC9C,CAAC;AACH;","names":[]}
|