hono-problem-details 0.1.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 +21 -0
- package/README.md +287 -0
- package/dist/chunk-ANLH2WEX.js +37 -0
- package/dist/chunk-ANLH2WEX.js.map +1 -0
- package/dist/index.cjs +191 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +84 -0
- package/dist/index.d.ts +84 -0
- package/dist/index.js +132 -0
- package/dist/index.js.map +1 -0
- package/dist/integrations/openapi.cjs +82 -0
- package/dist/integrations/openapi.cjs.map +1 -0
- package/dist/integrations/openapi.d.cts +62 -0
- package/dist/integrations/openapi.d.ts +62 -0
- package/dist/integrations/openapi.js +30 -0
- package/dist/integrations/openapi.js.map +1 -0
- package/dist/integrations/standard-schema.cjs +55 -0
- package/dist/integrations/standard-schema.cjs.map +1 -0
- package/dist/integrations/standard-schema.d.cts +16 -0
- package/dist/integrations/standard-schema.d.ts +16 -0
- package/dist/integrations/standard-schema.js +30 -0
- package/dist/integrations/standard-schema.js.map +1 -0
- package/dist/integrations/valibot.cjs +53 -0
- package/dist/integrations/valibot.cjs.map +1 -0
- package/dist/integrations/valibot.d.cts +12 -0
- package/dist/integrations/valibot.d.ts +12 -0
- package/dist/integrations/valibot.js +28 -0
- package/dist/integrations/valibot.js.map +1 -0
- package/dist/integrations/zod.cjs +53 -0
- package/dist/integrations/zod.cjs.map +1 -0
- package/dist/integrations/zod.d.cts +16 -0
- package/dist/integrations/zod.d.ts +16 -0
- package/dist/integrations/zod.js +28 -0
- package/dist/integrations/zod.js.map +1 -0
- package/package.json +145 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,84 @@
|
|
|
1
|
+
import * as hono from 'hono';
|
|
2
|
+
import { ErrorHandler } from 'hono';
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* RFC 9457 Problem Details object.
|
|
6
|
+
* Supports 5 standard fields + extension members.
|
|
7
|
+
*/
|
|
8
|
+
interface ProblemDetails<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
9
|
+
/** Problem type URI. Default: "about:blank" */
|
|
10
|
+
type: string;
|
|
11
|
+
/** HTTP status code */
|
|
12
|
+
status: number;
|
|
13
|
+
/** Short summary of the problem type */
|
|
14
|
+
title: string;
|
|
15
|
+
/** Human-readable explanation specific to this occurrence */
|
|
16
|
+
detail?: string;
|
|
17
|
+
/** URI that identifies the specific occurrence */
|
|
18
|
+
instance?: string;
|
|
19
|
+
/** RFC 9457 extension members (flattened to top level on serialization) */
|
|
20
|
+
extensions?: T;
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* Input for problemDetails() factory.
|
|
24
|
+
* type and title are optional (auto-derived from status).
|
|
25
|
+
*/
|
|
26
|
+
interface ProblemDetailsInput<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
27
|
+
status: number;
|
|
28
|
+
type?: string;
|
|
29
|
+
title?: string;
|
|
30
|
+
detail?: string;
|
|
31
|
+
instance?: string;
|
|
32
|
+
extensions?: T;
|
|
33
|
+
}
|
|
34
|
+
/**
|
|
35
|
+
* Options for problemDetailsHandler().
|
|
36
|
+
*/
|
|
37
|
+
interface ProblemDetailsHandlerOptions {
|
|
38
|
+
/** Prefix for type URI. When set, status-based suffix is appended */
|
|
39
|
+
typePrefix?: string;
|
|
40
|
+
/** Default type URI. Defaults to "about:blank" */
|
|
41
|
+
defaultType?: string;
|
|
42
|
+
/** Include stack trace in detail (for development) */
|
|
43
|
+
includeStack?: boolean;
|
|
44
|
+
/** Custom error to ProblemDetails mapping */
|
|
45
|
+
mapError?: (error: Error) => ProblemDetailsInput | undefined;
|
|
46
|
+
/** Localize title/detail before sending the response */
|
|
47
|
+
localize?: (pd: ProblemDetails, c: hono.Context) => ProblemDetails;
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
declare function statusToPhrase(status: number): string | undefined;
|
|
51
|
+
declare function statusToSlug(status: number): string | undefined;
|
|
52
|
+
|
|
53
|
+
declare class ProblemDetailsError extends Error {
|
|
54
|
+
readonly problemDetails: ProblemDetails;
|
|
55
|
+
constructor(input: ProblemDetailsInput);
|
|
56
|
+
getResponse(): Response;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
declare function problemDetails<T extends Record<string, unknown>>(input: ProblemDetailsInput<T>): ProblemDetailsError;
|
|
60
|
+
|
|
61
|
+
declare function problemDetailsHandler(options?: ProblemDetailsHandlerOptions): ErrorHandler;
|
|
62
|
+
|
|
63
|
+
interface ProblemTypeDefinition {
|
|
64
|
+
type: string;
|
|
65
|
+
status: number;
|
|
66
|
+
title: string;
|
|
67
|
+
}
|
|
68
|
+
interface CreateOptions<T extends Record<string, unknown> = Record<string, unknown>> {
|
|
69
|
+
detail?: string;
|
|
70
|
+
instance?: string;
|
|
71
|
+
extensions?: T;
|
|
72
|
+
}
|
|
73
|
+
interface ProblemTypeRegistry<K extends string> {
|
|
74
|
+
create: <T extends Record<string, unknown>>(key: K, options?: CreateOptions<T>) => ProblemDetailsError;
|
|
75
|
+
get: (key: K) => ProblemTypeDefinition;
|
|
76
|
+
types: () => K[];
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Create a registry of pre-defined problem types.
|
|
80
|
+
* Provides type-safe error creation from registered definitions.
|
|
81
|
+
*/
|
|
82
|
+
declare function createProblemTypeRegistry<K extends string>(definitions: Record<K, ProblemTypeDefinition>): ProblemTypeRegistry<K>;
|
|
83
|
+
|
|
84
|
+
export { type ProblemDetails, ProblemDetailsError, type ProblemDetailsHandlerOptions, type ProblemDetailsInput, createProblemTypeRegistry, problemDetails, problemDetailsHandler, statusToPhrase, statusToSlug };
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
import {
|
|
2
|
+
statusToPhrase,
|
|
3
|
+
statusToSlug
|
|
4
|
+
} from "./chunk-ANLH2WEX.js";
|
|
5
|
+
|
|
6
|
+
// src/error.ts
|
|
7
|
+
function normalizeProblemDetails(input) {
|
|
8
|
+
return {
|
|
9
|
+
type: input.type ?? "about:blank",
|
|
10
|
+
status: input.status,
|
|
11
|
+
title: input.title ?? statusToPhrase(input.status) ?? "Unknown Error",
|
|
12
|
+
detail: input.detail,
|
|
13
|
+
instance: input.instance,
|
|
14
|
+
extensions: input.extensions
|
|
15
|
+
};
|
|
16
|
+
}
|
|
17
|
+
var ProblemDetailsError = class extends Error {
|
|
18
|
+
problemDetails;
|
|
19
|
+
constructor(input) {
|
|
20
|
+
const pd = normalizeProblemDetails(input);
|
|
21
|
+
super(pd.detail ?? pd.title);
|
|
22
|
+
this.name = "ProblemDetailsError";
|
|
23
|
+
this.problemDetails = pd;
|
|
24
|
+
}
|
|
25
|
+
getResponse() {
|
|
26
|
+
const { extensions, ...standard } = this.problemDetails;
|
|
27
|
+
const body = { ...standard, ...extensions };
|
|
28
|
+
return new Response(JSON.stringify(body), {
|
|
29
|
+
status: this.problemDetails.status,
|
|
30
|
+
headers: { "Content-Type": "application/problem+json" }
|
|
31
|
+
});
|
|
32
|
+
}
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// src/factory.ts
|
|
36
|
+
function problemDetails(input) {
|
|
37
|
+
return new ProblemDetailsError(input);
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// src/handler.ts
|
|
41
|
+
import { HTTPException } from "hono/http-exception";
|
|
42
|
+
function buildType(status, options) {
|
|
43
|
+
if (options.typePrefix) {
|
|
44
|
+
const slug = statusToSlug(status);
|
|
45
|
+
if (slug) return `${options.typePrefix}/${slug}`;
|
|
46
|
+
}
|
|
47
|
+
return options.defaultType ?? "about:blank";
|
|
48
|
+
}
|
|
49
|
+
function toResponse(input, c, options) {
|
|
50
|
+
let pd = {
|
|
51
|
+
type: input.type ?? "about:blank",
|
|
52
|
+
status: input.status,
|
|
53
|
+
title: input.title ?? statusToPhrase(input.status) ?? "Unknown Error",
|
|
54
|
+
detail: input.detail,
|
|
55
|
+
instance: input.instance,
|
|
56
|
+
extensions: input.extensions
|
|
57
|
+
};
|
|
58
|
+
if (options.localize) {
|
|
59
|
+
pd = { ...pd, ...options.localize(pd, c) };
|
|
60
|
+
}
|
|
61
|
+
const { extensions, ...rest } = pd;
|
|
62
|
+
const body = { ...rest, ...extensions };
|
|
63
|
+
c.set("problemDetails", pd);
|
|
64
|
+
return new Response(JSON.stringify(body), {
|
|
65
|
+
status: pd.status,
|
|
66
|
+
headers: { "Content-Type": "application/problem+json" }
|
|
67
|
+
});
|
|
68
|
+
}
|
|
69
|
+
function problemDetailsHandler(options = {}) {
|
|
70
|
+
return (error, c) => {
|
|
71
|
+
if (error instanceof ProblemDetailsError) {
|
|
72
|
+
c.set("problemDetails", error.problemDetails);
|
|
73
|
+
return error.getResponse();
|
|
74
|
+
}
|
|
75
|
+
if (options.mapError) {
|
|
76
|
+
const mapped = options.mapError(error);
|
|
77
|
+
if (mapped) {
|
|
78
|
+
return toResponse(mapped, c, options);
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
if (error instanceof HTTPException) {
|
|
82
|
+
return toResponse(
|
|
83
|
+
{
|
|
84
|
+
status: error.status,
|
|
85
|
+
type: buildType(error.status, options),
|
|
86
|
+
title: statusToPhrase(error.status),
|
|
87
|
+
detail: error.message
|
|
88
|
+
},
|
|
89
|
+
c,
|
|
90
|
+
options
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
return toResponse(
|
|
94
|
+
{
|
|
95
|
+
status: 500,
|
|
96
|
+
type: buildType(500, options),
|
|
97
|
+
title: "Internal Server Error",
|
|
98
|
+
detail: options.includeStack ? error.stack : void 0
|
|
99
|
+
},
|
|
100
|
+
c,
|
|
101
|
+
options
|
|
102
|
+
);
|
|
103
|
+
};
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
// src/registry.ts
|
|
107
|
+
function createProblemTypeRegistry(definitions) {
|
|
108
|
+
return {
|
|
109
|
+
create: (key, options) => {
|
|
110
|
+
const def = definitions[key];
|
|
111
|
+
return new ProblemDetailsError({
|
|
112
|
+
type: def.type,
|
|
113
|
+
status: def.status,
|
|
114
|
+
title: def.title,
|
|
115
|
+
detail: options?.detail,
|
|
116
|
+
instance: options?.instance,
|
|
117
|
+
extensions: options?.extensions
|
|
118
|
+
});
|
|
119
|
+
},
|
|
120
|
+
get: (key) => definitions[key],
|
|
121
|
+
types: () => Object.keys(definitions)
|
|
122
|
+
};
|
|
123
|
+
}
|
|
124
|
+
export {
|
|
125
|
+
ProblemDetailsError,
|
|
126
|
+
createProblemTypeRegistry,
|
|
127
|
+
problemDetails,
|
|
128
|
+
problemDetailsHandler,
|
|
129
|
+
statusToPhrase,
|
|
130
|
+
statusToSlug
|
|
131
|
+
};
|
|
132
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../src/error.ts","../src/factory.ts","../src/handler.ts","../src/registry.ts"],"sourcesContent":["import { statusToPhrase } from \"./status.js\";\nimport type { ProblemDetails, ProblemDetailsInput } from \"./types.js\";\n\nfunction normalizeProblemDetails<T extends Record<string, unknown>>(\n\tinput: ProblemDetailsInput<T>,\n): ProblemDetails<T> {\n\treturn {\n\t\ttype: input.type ?? \"about:blank\",\n\t\tstatus: input.status,\n\t\ttitle: input.title ?? statusToPhrase(input.status) ?? \"Unknown Error\",\n\t\tdetail: input.detail,\n\t\tinstance: input.instance,\n\t\textensions: input.extensions,\n\t};\n}\n\nexport class ProblemDetailsError extends Error {\n\treadonly problemDetails: ProblemDetails;\n\n\tconstructor(input: ProblemDetailsInput) {\n\t\tconst pd = normalizeProblemDetails(input);\n\t\tsuper(pd.detail ?? pd.title);\n\t\tthis.name = \"ProblemDetailsError\";\n\t\tthis.problemDetails = pd;\n\t}\n\n\tgetResponse(): Response {\n\t\tconst { extensions, ...standard } = this.problemDetails;\n\t\tconst body = { ...standard, ...extensions };\n\t\treturn new Response(JSON.stringify(body), {\n\t\t\tstatus: this.problemDetails.status,\n\t\t\theaders: { \"Content-Type\": \"application/problem+json\" },\n\t\t});\n\t}\n}\n","import { ProblemDetailsError } from \"./error.js\";\nimport type { ProblemDetailsInput } from \"./types.js\";\n\nexport function problemDetails<T extends Record<string, unknown>>(\n\tinput: ProblemDetailsInput<T>,\n): ProblemDetailsError {\n\treturn new ProblemDetailsError(input);\n}\n","import type { Context, ErrorHandler } from \"hono\";\nimport { HTTPException } from \"hono/http-exception\";\nimport { ProblemDetailsError } from \"./error.js\";\nimport { statusToPhrase, statusToSlug } from \"./status.js\";\nimport type { ProblemDetailsHandlerOptions, ProblemDetailsInput } from \"./types.js\";\n\nfunction buildType(status: number, options: ProblemDetailsHandlerOptions): string {\n\tif (options.typePrefix) {\n\t\tconst slug = statusToSlug(status);\n\t\tif (slug) return `${options.typePrefix}/${slug}`;\n\t}\n\treturn options.defaultType ?? \"about:blank\";\n}\n\nfunction toResponse(\n\tinput: ProblemDetailsInput,\n\tc: Context,\n\toptions: ProblemDetailsHandlerOptions,\n): Response {\n\tlet pd = {\n\t\ttype: input.type ?? \"about:blank\",\n\t\tstatus: input.status,\n\t\ttitle: input.title ?? statusToPhrase(input.status) ?? \"Unknown Error\",\n\t\tdetail: input.detail,\n\t\tinstance: input.instance,\n\t\textensions: input.extensions,\n\t};\n\n\tif (options.localize) {\n\t\tpd = { ...pd, ...options.localize(pd, c) };\n\t}\n\n\tconst { extensions, ...rest } = pd;\n\tconst body = { ...rest, ...extensions };\n\n\tc.set(\"problemDetails\", pd);\n\n\treturn new Response(JSON.stringify(body), {\n\t\tstatus: pd.status,\n\t\theaders: { \"Content-Type\": \"application/problem+json\" },\n\t});\n}\n\nexport function problemDetailsHandler(options: ProblemDetailsHandlerOptions = {}): ErrorHandler {\n\treturn (error, c) => {\n\t\tif (error instanceof ProblemDetailsError) {\n\t\t\tc.set(\"problemDetails\", error.problemDetails);\n\t\t\treturn error.getResponse();\n\t\t}\n\n\t\tif (options.mapError) {\n\t\t\tconst mapped = options.mapError(error);\n\t\t\tif (mapped) {\n\t\t\t\treturn toResponse(mapped, c, options);\n\t\t\t}\n\t\t}\n\n\t\tif (error instanceof HTTPException) {\n\t\t\treturn toResponse(\n\t\t\t\t{\n\t\t\t\t\tstatus: error.status,\n\t\t\t\t\ttype: buildType(error.status, options),\n\t\t\t\t\ttitle: statusToPhrase(error.status),\n\t\t\t\t\tdetail: error.message,\n\t\t\t\t},\n\t\t\t\tc,\n\t\t\t\toptions,\n\t\t\t);\n\t\t}\n\n\t\treturn toResponse(\n\t\t\t{\n\t\t\t\tstatus: 500,\n\t\t\t\ttype: buildType(500, options),\n\t\t\t\ttitle: \"Internal Server Error\",\n\t\t\t\tdetail: options.includeStack ? error.stack : undefined,\n\t\t\t},\n\t\t\tc,\n\t\t\toptions,\n\t\t);\n\t};\n}\n","import { ProblemDetailsError } from \"./error.js\";\n\ninterface ProblemTypeDefinition {\n\ttype: string;\n\tstatus: number;\n\ttitle: string;\n}\n\ninterface CreateOptions<T extends Record<string, unknown> = Record<string, unknown>> {\n\tdetail?: string;\n\tinstance?: string;\n\textensions?: T;\n}\n\ninterface ProblemTypeRegistry<K extends string> {\n\tcreate: <T extends Record<string, unknown>>(\n\t\tkey: K,\n\t\toptions?: CreateOptions<T>,\n\t) => ProblemDetailsError;\n\tget: (key: K) => ProblemTypeDefinition;\n\ttypes: () => K[];\n}\n\n/**\n * Create a registry of pre-defined problem types.\n * Provides type-safe error creation from registered definitions.\n */\nexport function createProblemTypeRegistry<K extends string>(\n\tdefinitions: Record<K, ProblemTypeDefinition>,\n): ProblemTypeRegistry<K> {\n\treturn {\n\t\tcreate: (key, options) => {\n\t\t\tconst def = definitions[key];\n\t\t\treturn new ProblemDetailsError({\n\t\t\t\ttype: def.type,\n\t\t\t\tstatus: def.status,\n\t\t\t\ttitle: def.title,\n\t\t\t\tdetail: options?.detail,\n\t\t\t\tinstance: options?.instance,\n\t\t\t\textensions: options?.extensions,\n\t\t\t});\n\t\t},\n\t\tget: (key) => definitions[key],\n\t\ttypes: () => Object.keys(definitions) as K[],\n\t};\n}\n"],"mappings":"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","names":[]}
|
|
@@ -0,0 +1,82 @@
|
|
|
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/integrations/openapi.ts
|
|
21
|
+
var openapi_exports = {};
|
|
22
|
+
__export(openapi_exports, {
|
|
23
|
+
ProblemDetailsSchema: () => ProblemDetailsSchema,
|
|
24
|
+
createProblemDetailsSchema: () => createProblemDetailsSchema,
|
|
25
|
+
problemDetailsResponse: () => problemDetailsResponse
|
|
26
|
+
});
|
|
27
|
+
module.exports = __toCommonJS(openapi_exports);
|
|
28
|
+
var import_zod_openapi = require("@hono/zod-openapi");
|
|
29
|
+
|
|
30
|
+
// src/status.ts
|
|
31
|
+
var STATUS_PHRASES = {
|
|
32
|
+
400: "Bad Request",
|
|
33
|
+
401: "Unauthorized",
|
|
34
|
+
403: "Forbidden",
|
|
35
|
+
404: "Not Found",
|
|
36
|
+
405: "Method Not Allowed",
|
|
37
|
+
406: "Not Acceptable",
|
|
38
|
+
408: "Request Timeout",
|
|
39
|
+
409: "Conflict",
|
|
40
|
+
410: "Gone",
|
|
41
|
+
411: "Length Required",
|
|
42
|
+
412: "Precondition Failed",
|
|
43
|
+
413: "Content Too Large",
|
|
44
|
+
415: "Unsupported Media Type",
|
|
45
|
+
422: "Unprocessable Content",
|
|
46
|
+
429: "Too Many Requests",
|
|
47
|
+
500: "Internal Server Error",
|
|
48
|
+
501: "Not Implemented",
|
|
49
|
+
502: "Bad Gateway",
|
|
50
|
+
503: "Service Unavailable",
|
|
51
|
+
504: "Gateway Timeout"
|
|
52
|
+
};
|
|
53
|
+
function statusToPhrase(status) {
|
|
54
|
+
return STATUS_PHRASES[status];
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
// src/integrations/openapi.ts
|
|
58
|
+
var ProblemDetailsSchema = import_zod_openapi.z.object({
|
|
59
|
+
type: import_zod_openapi.z.string().openapi({ description: "Problem type URI", example: "about:blank" }),
|
|
60
|
+
status: import_zod_openapi.z.number().int().openapi({ description: "HTTP status code", example: 400 }),
|
|
61
|
+
title: import_zod_openapi.z.string().openapi({ description: "Short summary of the problem type", example: "Bad Request" }),
|
|
62
|
+
detail: import_zod_openapi.z.string().optional().openapi({ description: "Human-readable explanation" }),
|
|
63
|
+
instance: import_zod_openapi.z.string().optional().openapi({ description: "URI identifying the occurrence" })
|
|
64
|
+
}).openapi({ title: "ProblemDetails" });
|
|
65
|
+
function createProblemDetailsSchema(extensions) {
|
|
66
|
+
return ProblemDetailsSchema.merge(extensions).openapi({ title: "ProblemDetails" });
|
|
67
|
+
}
|
|
68
|
+
function problemDetailsResponse(status, description, schema = ProblemDetailsSchema) {
|
|
69
|
+
return {
|
|
70
|
+
content: {
|
|
71
|
+
"application/problem+json": { schema }
|
|
72
|
+
},
|
|
73
|
+
description: description ?? statusToPhrase(status) ?? "Error"
|
|
74
|
+
};
|
|
75
|
+
}
|
|
76
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
77
|
+
0 && (module.exports = {
|
|
78
|
+
ProblemDetailsSchema,
|
|
79
|
+
createProblemDetailsSchema,
|
|
80
|
+
problemDetailsResponse
|
|
81
|
+
});
|
|
82
|
+
//# sourceMappingURL=openapi.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/openapi.ts","../../src/status.ts"],"sourcesContent":["import { z } from \"@hono/zod-openapi\";\nimport { statusToPhrase } from \"../status.js\";\n\n/**\n * Base RFC 9457 Problem Details Zod schema for OpenAPI documentation.\n * Use in createRoute() response definitions with @hono/zod-openapi.\n */\nexport const ProblemDetailsSchema = z\n\t.object({\n\t\ttype: z.string().openapi({ description: \"Problem type URI\", example: \"about:blank\" }),\n\t\tstatus: z.number().int().openapi({ description: \"HTTP status code\", example: 400 }),\n\t\ttitle: z\n\t\t\t.string()\n\t\t\t.openapi({ description: \"Short summary of the problem type\", example: \"Bad Request\" }),\n\t\tdetail: z.string().optional().openapi({ description: \"Human-readable explanation\" }),\n\t\tinstance: z.string().optional().openapi({ description: \"URI identifying the occurrence\" }),\n\t})\n\t.openapi({ title: \"ProblemDetails\" });\n\n/**\n * Create a Problem Details schema with typed extension members.\n * Extensions are merged at top level per RFC 9457.\n */\nexport function createProblemDetailsSchema<T extends z.ZodRawShape>(extensions: z.ZodObject<T>) {\n\treturn ProblemDetailsSchema.merge(extensions).openapi({ title: \"ProblemDetails\" });\n}\n\n/**\n * Create an OpenAPI response object for Problem Details.\n * Use in createRoute() responses: { 422: problemDetailsResponse(422) }\n */\nexport function problemDetailsResponse(\n\tstatus: number,\n\tdescription?: string,\n\tschema: z.ZodTypeAny = ProblemDetailsSchema,\n) {\n\treturn {\n\t\tcontent: {\n\t\t\t\"application/problem+json\": { schema },\n\t\t},\n\t\tdescription: description ?? statusToPhrase(status) ?? \"Error\",\n\t};\n}\n","const STATUS_PHRASES: Record<number, string> = {\n\t400: \"Bad Request\",\n\t401: \"Unauthorized\",\n\t403: \"Forbidden\",\n\t404: \"Not Found\",\n\t405: \"Method Not Allowed\",\n\t406: \"Not Acceptable\",\n\t408: \"Request Timeout\",\n\t409: \"Conflict\",\n\t410: \"Gone\",\n\t411: \"Length Required\",\n\t412: \"Precondition Failed\",\n\t413: \"Content Too Large\",\n\t415: \"Unsupported Media Type\",\n\t422: \"Unprocessable Content\",\n\t429: \"Too Many Requests\",\n\t500: \"Internal Server Error\",\n\t501: \"Not Implemented\",\n\t502: \"Bad Gateway\",\n\t503: \"Service Unavailable\",\n\t504: \"Gateway Timeout\",\n};\n\nexport function statusToPhrase(status: number): string | undefined {\n\treturn STATUS_PHRASES[status];\n}\n\nexport function statusToSlug(status: number): string | undefined {\n\tconst phrase = STATUS_PHRASES[status];\n\tif (!phrase) return undefined;\n\treturn phrase.toLowerCase().replace(/ /g, \"-\");\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAAkB;;;ACAlB,IAAM,iBAAyC;AAAA,EAC9C,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AAAA,EACL,KAAK;AACN;AAEO,SAAS,eAAe,QAAoC;AAClE,SAAO,eAAe,MAAM;AAC7B;;;ADlBO,IAAM,uBAAuB,qBAClC,OAAO;AAAA,EACP,MAAM,qBAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,oBAAoB,SAAS,cAAc,CAAC;AAAA,EACpF,QAAQ,qBAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,oBAAoB,SAAS,IAAI,CAAC;AAAA,EAClF,OAAO,qBACL,OAAO,EACP,QAAQ,EAAE,aAAa,qCAAqC,SAAS,cAAc,CAAC;AAAA,EACtF,QAAQ,qBAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,6BAA6B,CAAC;AAAA,EACnF,UAAU,qBAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,iCAAiC,CAAC;AAC1F,CAAC,EACA,QAAQ,EAAE,OAAO,iBAAiB,CAAC;AAM9B,SAAS,2BAAoD,YAA4B;AAC/F,SAAO,qBAAqB,MAAM,UAAU,EAAE,QAAQ,EAAE,OAAO,iBAAiB,CAAC;AAClF;AAMO,SAAS,uBACf,QACA,aACA,SAAuB,sBACtB;AACD,SAAO;AAAA,IACN,SAAS;AAAA,MACR,4BAA4B,EAAE,OAAO;AAAA,IACtC;AAAA,IACA,aAAa,eAAe,eAAe,MAAM,KAAK;AAAA,EACvD;AACD;","names":[]}
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { z } from '@hono/zod-openapi';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base RFC 9457 Problem Details Zod schema for OpenAPI documentation.
|
|
5
|
+
* Use in createRoute() response definitions with @hono/zod-openapi.
|
|
6
|
+
*/
|
|
7
|
+
declare const ProblemDetailsSchema: z.ZodObject<{
|
|
8
|
+
type: z.ZodString;
|
|
9
|
+
status: z.ZodNumber;
|
|
10
|
+
title: z.ZodString;
|
|
11
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
12
|
+
instance: z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
status: number;
|
|
15
|
+
type: string;
|
|
16
|
+
title: string;
|
|
17
|
+
detail?: string | undefined;
|
|
18
|
+
instance?: string | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
status: number;
|
|
21
|
+
type: string;
|
|
22
|
+
title: string;
|
|
23
|
+
detail?: string | undefined;
|
|
24
|
+
instance?: string | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Create a Problem Details schema with typed extension members.
|
|
28
|
+
* Extensions are merged at top level per RFC 9457.
|
|
29
|
+
*/
|
|
30
|
+
declare function createProblemDetailsSchema<T extends z.ZodRawShape>(extensions: z.ZodObject<T>): z.ZodObject<z.objectUtil.extendShape<{
|
|
31
|
+
type: z.ZodString;
|
|
32
|
+
status: z.ZodNumber;
|
|
33
|
+
title: z.ZodString;
|
|
34
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
35
|
+
instance: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, T>, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<z.objectUtil.extendShape<{
|
|
37
|
+
type: z.ZodString;
|
|
38
|
+
status: z.ZodNumber;
|
|
39
|
+
title: z.ZodString;
|
|
40
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
41
|
+
instance: z.ZodOptional<z.ZodString>;
|
|
42
|
+
}, T>>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<z.objectUtil.extendShape<{
|
|
43
|
+
type: z.ZodString;
|
|
44
|
+
status: z.ZodNumber;
|
|
45
|
+
title: z.ZodString;
|
|
46
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
47
|
+
instance: z.ZodOptional<z.ZodString>;
|
|
48
|
+
}, T>> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>;
|
|
49
|
+
/**
|
|
50
|
+
* Create an OpenAPI response object for Problem Details.
|
|
51
|
+
* Use in createRoute() responses: { 422: problemDetailsResponse(422) }
|
|
52
|
+
*/
|
|
53
|
+
declare function problemDetailsResponse(status: number, description?: string, schema?: z.ZodTypeAny): {
|
|
54
|
+
content: {
|
|
55
|
+
"application/problem+json": {
|
|
56
|
+
schema: z.ZodTypeAny;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
description: string;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { ProblemDetailsSchema, createProblemDetailsSchema, problemDetailsResponse };
|
|
@@ -0,0 +1,62 @@
|
|
|
1
|
+
import { z } from '@hono/zod-openapi';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Base RFC 9457 Problem Details Zod schema for OpenAPI documentation.
|
|
5
|
+
* Use in createRoute() response definitions with @hono/zod-openapi.
|
|
6
|
+
*/
|
|
7
|
+
declare const ProblemDetailsSchema: z.ZodObject<{
|
|
8
|
+
type: z.ZodString;
|
|
9
|
+
status: z.ZodNumber;
|
|
10
|
+
title: z.ZodString;
|
|
11
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
12
|
+
instance: z.ZodOptional<z.ZodString>;
|
|
13
|
+
}, "strip", z.ZodTypeAny, {
|
|
14
|
+
status: number;
|
|
15
|
+
type: string;
|
|
16
|
+
title: string;
|
|
17
|
+
detail?: string | undefined;
|
|
18
|
+
instance?: string | undefined;
|
|
19
|
+
}, {
|
|
20
|
+
status: number;
|
|
21
|
+
type: string;
|
|
22
|
+
title: string;
|
|
23
|
+
detail?: string | undefined;
|
|
24
|
+
instance?: string | undefined;
|
|
25
|
+
}>;
|
|
26
|
+
/**
|
|
27
|
+
* Create a Problem Details schema with typed extension members.
|
|
28
|
+
* Extensions are merged at top level per RFC 9457.
|
|
29
|
+
*/
|
|
30
|
+
declare function createProblemDetailsSchema<T extends z.ZodRawShape>(extensions: z.ZodObject<T>): z.ZodObject<z.objectUtil.extendShape<{
|
|
31
|
+
type: z.ZodString;
|
|
32
|
+
status: z.ZodNumber;
|
|
33
|
+
title: z.ZodString;
|
|
34
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
35
|
+
instance: z.ZodOptional<z.ZodString>;
|
|
36
|
+
}, T>, z.UnknownKeysParam, z.ZodTypeAny, z.objectUtil.addQuestionMarks<z.baseObjectOutputType<z.objectUtil.extendShape<{
|
|
37
|
+
type: z.ZodString;
|
|
38
|
+
status: z.ZodNumber;
|
|
39
|
+
title: z.ZodString;
|
|
40
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
41
|
+
instance: z.ZodOptional<z.ZodString>;
|
|
42
|
+
}, T>>, any> extends infer T_1 ? { [k in keyof T_1]: T_1[k]; } : never, z.baseObjectInputType<z.objectUtil.extendShape<{
|
|
43
|
+
type: z.ZodString;
|
|
44
|
+
status: z.ZodNumber;
|
|
45
|
+
title: z.ZodString;
|
|
46
|
+
detail: z.ZodOptional<z.ZodString>;
|
|
47
|
+
instance: z.ZodOptional<z.ZodString>;
|
|
48
|
+
}, T>> extends infer T_2 ? { [k_1 in keyof T_2]: T_2[k_1]; } : never>;
|
|
49
|
+
/**
|
|
50
|
+
* Create an OpenAPI response object for Problem Details.
|
|
51
|
+
* Use in createRoute() responses: { 422: problemDetailsResponse(422) }
|
|
52
|
+
*/
|
|
53
|
+
declare function problemDetailsResponse(status: number, description?: string, schema?: z.ZodTypeAny): {
|
|
54
|
+
content: {
|
|
55
|
+
"application/problem+json": {
|
|
56
|
+
schema: z.ZodTypeAny;
|
|
57
|
+
};
|
|
58
|
+
};
|
|
59
|
+
description: string;
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export { ProblemDetailsSchema, createProblemDetailsSchema, problemDetailsResponse };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import {
|
|
2
|
+
statusToPhrase
|
|
3
|
+
} from "../chunk-ANLH2WEX.js";
|
|
4
|
+
|
|
5
|
+
// src/integrations/openapi.ts
|
|
6
|
+
import { z } from "@hono/zod-openapi";
|
|
7
|
+
var ProblemDetailsSchema = z.object({
|
|
8
|
+
type: z.string().openapi({ description: "Problem type URI", example: "about:blank" }),
|
|
9
|
+
status: z.number().int().openapi({ description: "HTTP status code", example: 400 }),
|
|
10
|
+
title: z.string().openapi({ description: "Short summary of the problem type", example: "Bad Request" }),
|
|
11
|
+
detail: z.string().optional().openapi({ description: "Human-readable explanation" }),
|
|
12
|
+
instance: z.string().optional().openapi({ description: "URI identifying the occurrence" })
|
|
13
|
+
}).openapi({ title: "ProblemDetails" });
|
|
14
|
+
function createProblemDetailsSchema(extensions) {
|
|
15
|
+
return ProblemDetailsSchema.merge(extensions).openapi({ title: "ProblemDetails" });
|
|
16
|
+
}
|
|
17
|
+
function problemDetailsResponse(status, description, schema = ProblemDetailsSchema) {
|
|
18
|
+
return {
|
|
19
|
+
content: {
|
|
20
|
+
"application/problem+json": { schema }
|
|
21
|
+
},
|
|
22
|
+
description: description ?? statusToPhrase(status) ?? "Error"
|
|
23
|
+
};
|
|
24
|
+
}
|
|
25
|
+
export {
|
|
26
|
+
ProblemDetailsSchema,
|
|
27
|
+
createProblemDetailsSchema,
|
|
28
|
+
problemDetailsResponse
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=openapi.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/openapi.ts"],"sourcesContent":["import { z } from \"@hono/zod-openapi\";\nimport { statusToPhrase } from \"../status.js\";\n\n/**\n * Base RFC 9457 Problem Details Zod schema for OpenAPI documentation.\n * Use in createRoute() response definitions with @hono/zod-openapi.\n */\nexport const ProblemDetailsSchema = z\n\t.object({\n\t\ttype: z.string().openapi({ description: \"Problem type URI\", example: \"about:blank\" }),\n\t\tstatus: z.number().int().openapi({ description: \"HTTP status code\", example: 400 }),\n\t\ttitle: z\n\t\t\t.string()\n\t\t\t.openapi({ description: \"Short summary of the problem type\", example: \"Bad Request\" }),\n\t\tdetail: z.string().optional().openapi({ description: \"Human-readable explanation\" }),\n\t\tinstance: z.string().optional().openapi({ description: \"URI identifying the occurrence\" }),\n\t})\n\t.openapi({ title: \"ProblemDetails\" });\n\n/**\n * Create a Problem Details schema with typed extension members.\n * Extensions are merged at top level per RFC 9457.\n */\nexport function createProblemDetailsSchema<T extends z.ZodRawShape>(extensions: z.ZodObject<T>) {\n\treturn ProblemDetailsSchema.merge(extensions).openapi({ title: \"ProblemDetails\" });\n}\n\n/**\n * Create an OpenAPI response object for Problem Details.\n * Use in createRoute() responses: { 422: problemDetailsResponse(422) }\n */\nexport function problemDetailsResponse(\n\tstatus: number,\n\tdescription?: string,\n\tschema: z.ZodTypeAny = ProblemDetailsSchema,\n) {\n\treturn {\n\t\tcontent: {\n\t\t\t\"application/problem+json\": { schema },\n\t\t},\n\t\tdescription: description ?? statusToPhrase(status) ?? \"Error\",\n\t};\n}\n"],"mappings":";;;;;AAAA,SAAS,SAAS;AAOX,IAAM,uBAAuB,EAClC,OAAO;AAAA,EACP,MAAM,EAAE,OAAO,EAAE,QAAQ,EAAE,aAAa,oBAAoB,SAAS,cAAc,CAAC;AAAA,EACpF,QAAQ,EAAE,OAAO,EAAE,IAAI,EAAE,QAAQ,EAAE,aAAa,oBAAoB,SAAS,IAAI,CAAC;AAAA,EAClF,OAAO,EACL,OAAO,EACP,QAAQ,EAAE,aAAa,qCAAqC,SAAS,cAAc,CAAC;AAAA,EACtF,QAAQ,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,6BAA6B,CAAC;AAAA,EACnF,UAAU,EAAE,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,aAAa,iCAAiC,CAAC;AAC1F,CAAC,EACA,QAAQ,EAAE,OAAO,iBAAiB,CAAC;AAM9B,SAAS,2BAAoD,YAA4B;AAC/F,SAAO,qBAAqB,MAAM,UAAU,EAAE,QAAQ,EAAE,OAAO,iBAAiB,CAAC;AAClF;AAMO,SAAS,uBACf,QACA,aACA,SAAuB,sBACtB;AACD,SAAO;AAAA,IACN,SAAS;AAAA,MACR,4BAA4B,EAAE,OAAO;AAAA,IACtC;AAAA,IACA,aAAa,eAAe,eAAe,MAAM,KAAK;AAAA,EACvD;AACD;","names":[]}
|
|
@@ -0,0 +1,55 @@
|
|
|
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/integrations/standard-schema.ts
|
|
21
|
+
var standard_schema_exports = {};
|
|
22
|
+
__export(standard_schema_exports, {
|
|
23
|
+
standardSchemaProblemHook: () => standardSchemaProblemHook
|
|
24
|
+
});
|
|
25
|
+
module.exports = __toCommonJS(standard_schema_exports);
|
|
26
|
+
function formatPath(path) {
|
|
27
|
+
return path.map((segment) => typeof segment === "object" ? String(segment.key) : String(segment)).join(".");
|
|
28
|
+
}
|
|
29
|
+
function formatIssues(issues) {
|
|
30
|
+
return issues.map((issue) => ({
|
|
31
|
+
field: issue.path ? formatPath(issue.path) : "",
|
|
32
|
+
message: issue.message
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
function standardSchemaProblemHook(options) {
|
|
36
|
+
return (result, c) => {
|
|
37
|
+
if (result.success) return;
|
|
38
|
+
const body = {
|
|
39
|
+
type: "about:blank",
|
|
40
|
+
status: 422,
|
|
41
|
+
title: options?.title ?? "Validation Error",
|
|
42
|
+
detail: options?.detail ?? "Request validation failed",
|
|
43
|
+
errors: formatIssues(result.error)
|
|
44
|
+
};
|
|
45
|
+
return new Response(JSON.stringify(body), {
|
|
46
|
+
status: 422,
|
|
47
|
+
headers: { "Content-Type": "application/problem+json" }
|
|
48
|
+
});
|
|
49
|
+
};
|
|
50
|
+
}
|
|
51
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
52
|
+
0 && (module.exports = {
|
|
53
|
+
standardSchemaProblemHook
|
|
54
|
+
});
|
|
55
|
+
//# sourceMappingURL=standard-schema.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/standard-schema.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { Context } from \"hono\";\n\nexport interface StandardSchemaProblemHookOptions {\n\ttitle?: string;\n\tdetail?: string;\n}\n\ninterface ValidationError {\n\tfield: string;\n\tmessage: string;\n}\n\nfunction formatPath(path: ReadonlyArray<PropertyKey | StandardSchemaV1.PathSegment>): string {\n\treturn path\n\t\t.map((segment) => (typeof segment === \"object\" ? String(segment.key) : String(segment)))\n\t\t.join(\".\");\n}\n\nfunction formatIssues(issues: readonly StandardSchemaV1.Issue[]): ValidationError[] {\n\treturn issues.map((issue) => ({\n\t\tfield: issue.path ? formatPath(issue.path) : \"\",\n\t\tmessage: issue.message,\n\t}));\n}\n\nexport function standardSchemaProblemHook(options?: StandardSchemaProblemHookOptions) {\n\treturn (\n\t\tresult:\n\t\t\t| { success: true; data: unknown }\n\t\t\t| { success: false; error: readonly StandardSchemaV1.Issue[] },\n\t\tc: Context,\n\t) => {\n\t\tif (result.success) return;\n\n\t\tconst body = {\n\t\t\ttype: \"about:blank\",\n\t\t\tstatus: 422,\n\t\t\ttitle: options?.title ?? \"Validation Error\",\n\t\t\tdetail: options?.detail ?? \"Request validation failed\",\n\t\t\terrors: formatIssues(result.error),\n\t\t};\n\n\t\treturn new Response(JSON.stringify(body), {\n\t\t\tstatus: 422,\n\t\t\theaders: { \"Content-Type\": \"application/problem+json\" },\n\t\t});\n\t};\n}\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAaA,SAAS,WAAW,MAAyE;AAC5F,SAAO,KACL,IAAI,CAAC,YAAa,OAAO,YAAY,WAAW,OAAO,QAAQ,GAAG,IAAI,OAAO,OAAO,CAAE,EACtF,KAAK,GAAG;AACX;AAEA,SAAS,aAAa,QAA8D;AACnF,SAAO,OAAO,IAAI,CAAC,WAAW;AAAA,IAC7B,OAAO,MAAM,OAAO,WAAW,MAAM,IAAI,IAAI;AAAA,IAC7C,SAAS,MAAM;AAAA,EAChB,EAAE;AACH;AAEO,SAAS,0BAA0B,SAA4C;AACrF,SAAO,CACN,QAGA,MACI;AACJ,QAAI,OAAO,QAAS;AAEpB,UAAM,OAAO;AAAA,MACZ,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,OAAO,SAAS,SAAS;AAAA,MACzB,QAAQ,SAAS,UAAU;AAAA,MAC3B,QAAQ,aAAa,OAAO,KAAK;AAAA,IAClC;AAEA,WAAO,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;AAAA,MACzC,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,2BAA2B;AAAA,IACvD,CAAC;AAAA,EACF;AACD;","names":[]}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import { Context } from 'hono';
|
|
3
|
+
|
|
4
|
+
interface StandardSchemaProblemHookOptions {
|
|
5
|
+
title?: string;
|
|
6
|
+
detail?: string;
|
|
7
|
+
}
|
|
8
|
+
declare function standardSchemaProblemHook(options?: StandardSchemaProblemHookOptions): (result: {
|
|
9
|
+
success: true;
|
|
10
|
+
data: unknown;
|
|
11
|
+
} | {
|
|
12
|
+
success: false;
|
|
13
|
+
error: readonly StandardSchemaV1.Issue[];
|
|
14
|
+
}, c: Context) => Response | undefined;
|
|
15
|
+
|
|
16
|
+
export { type StandardSchemaProblemHookOptions, standardSchemaProblemHook };
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { StandardSchemaV1 } from '@standard-schema/spec';
|
|
2
|
+
import { Context } from 'hono';
|
|
3
|
+
|
|
4
|
+
interface StandardSchemaProblemHookOptions {
|
|
5
|
+
title?: string;
|
|
6
|
+
detail?: string;
|
|
7
|
+
}
|
|
8
|
+
declare function standardSchemaProblemHook(options?: StandardSchemaProblemHookOptions): (result: {
|
|
9
|
+
success: true;
|
|
10
|
+
data: unknown;
|
|
11
|
+
} | {
|
|
12
|
+
success: false;
|
|
13
|
+
error: readonly StandardSchemaV1.Issue[];
|
|
14
|
+
}, c: Context) => Response | undefined;
|
|
15
|
+
|
|
16
|
+
export { type StandardSchemaProblemHookOptions, standardSchemaProblemHook };
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// src/integrations/standard-schema.ts
|
|
2
|
+
function formatPath(path) {
|
|
3
|
+
return path.map((segment) => typeof segment === "object" ? String(segment.key) : String(segment)).join(".");
|
|
4
|
+
}
|
|
5
|
+
function formatIssues(issues) {
|
|
6
|
+
return issues.map((issue) => ({
|
|
7
|
+
field: issue.path ? formatPath(issue.path) : "",
|
|
8
|
+
message: issue.message
|
|
9
|
+
}));
|
|
10
|
+
}
|
|
11
|
+
function standardSchemaProblemHook(options) {
|
|
12
|
+
return (result, c) => {
|
|
13
|
+
if (result.success) return;
|
|
14
|
+
const body = {
|
|
15
|
+
type: "about:blank",
|
|
16
|
+
status: 422,
|
|
17
|
+
title: options?.title ?? "Validation Error",
|
|
18
|
+
detail: options?.detail ?? "Request validation failed",
|
|
19
|
+
errors: formatIssues(result.error)
|
|
20
|
+
};
|
|
21
|
+
return new Response(JSON.stringify(body), {
|
|
22
|
+
status: 422,
|
|
23
|
+
headers: { "Content-Type": "application/problem+json" }
|
|
24
|
+
});
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
export {
|
|
28
|
+
standardSchemaProblemHook
|
|
29
|
+
};
|
|
30
|
+
//# sourceMappingURL=standard-schema.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"sources":["../../src/integrations/standard-schema.ts"],"sourcesContent":["import type { StandardSchemaV1 } from \"@standard-schema/spec\";\nimport type { Context } from \"hono\";\n\nexport interface StandardSchemaProblemHookOptions {\n\ttitle?: string;\n\tdetail?: string;\n}\n\ninterface ValidationError {\n\tfield: string;\n\tmessage: string;\n}\n\nfunction formatPath(path: ReadonlyArray<PropertyKey | StandardSchemaV1.PathSegment>): string {\n\treturn path\n\t\t.map((segment) => (typeof segment === \"object\" ? String(segment.key) : String(segment)))\n\t\t.join(\".\");\n}\n\nfunction formatIssues(issues: readonly StandardSchemaV1.Issue[]): ValidationError[] {\n\treturn issues.map((issue) => ({\n\t\tfield: issue.path ? formatPath(issue.path) : \"\",\n\t\tmessage: issue.message,\n\t}));\n}\n\nexport function standardSchemaProblemHook(options?: StandardSchemaProblemHookOptions) {\n\treturn (\n\t\tresult:\n\t\t\t| { success: true; data: unknown }\n\t\t\t| { success: false; error: readonly StandardSchemaV1.Issue[] },\n\t\tc: Context,\n\t) => {\n\t\tif (result.success) return;\n\n\t\tconst body = {\n\t\t\ttype: \"about:blank\",\n\t\t\tstatus: 422,\n\t\t\ttitle: options?.title ?? \"Validation Error\",\n\t\t\tdetail: options?.detail ?? \"Request validation failed\",\n\t\t\terrors: formatIssues(result.error),\n\t\t};\n\n\t\treturn new Response(JSON.stringify(body), {\n\t\t\tstatus: 422,\n\t\t\theaders: { \"Content-Type\": \"application/problem+json\" },\n\t\t});\n\t};\n}\n"],"mappings":";AAaA,SAAS,WAAW,MAAyE;AAC5F,SAAO,KACL,IAAI,CAAC,YAAa,OAAO,YAAY,WAAW,OAAO,QAAQ,GAAG,IAAI,OAAO,OAAO,CAAE,EACtF,KAAK,GAAG;AACX;AAEA,SAAS,aAAa,QAA8D;AACnF,SAAO,OAAO,IAAI,CAAC,WAAW;AAAA,IAC7B,OAAO,MAAM,OAAO,WAAW,MAAM,IAAI,IAAI;AAAA,IAC7C,SAAS,MAAM;AAAA,EAChB,EAAE;AACH;AAEO,SAAS,0BAA0B,SAA4C;AACrF,SAAO,CACN,QAGA,MACI;AACJ,QAAI,OAAO,QAAS;AAEpB,UAAM,OAAO;AAAA,MACZ,MAAM;AAAA,MACN,QAAQ;AAAA,MACR,OAAO,SAAS,SAAS;AAAA,MACzB,QAAQ,SAAS,UAAU;AAAA,MAC3B,QAAQ,aAAa,OAAO,KAAK;AAAA,IAClC;AAEA,WAAO,IAAI,SAAS,KAAK,UAAU,IAAI,GAAG;AAAA,MACzC,QAAQ;AAAA,MACR,SAAS,EAAE,gBAAgB,2BAA2B;AAAA,IACvD,CAAC;AAAA,EACF;AACD;","names":[]}
|