hono-takibi 0.33.1 → 0.33.4
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/cli.js +5 -5
- package/dist/core/docs/index.js +1 -1
- package/dist/core/hooks/index.js +1 -1
- package/dist/core/rpc/index.js +2 -2
- package/dist/core/type/index.js +76 -9
- package/dist/{core-CajXzO16.js → core--c3Vfca8.js} +24 -14
- package/dist/{docs-hKJj12Gm.js → docs-Md7vHZib.js} +1 -1
- package/dist/generate/index.js +1 -1
- package/dist/generator/mock/index.js +1 -1
- package/dist/generator/zod-openapi-hono/openapi/index.js +1 -1
- package/dist/{hooks-CSMf3pkH.js → hooks-BYOaM0T6.js} +29 -7
- package/dist/{mock-CvrfyklR.js → mock-EWnJ65d3.js} +2 -2
- package/dist/{openapi-BMJPrf4w.js → openapi-DAYtJjPV.js} +2 -2
- package/dist/{routes-Cg-imktp.js → routes-65ua_FNx.js} +86 -30
- package/dist/{rpc-DALShbf3.js → rpc-Qup_vU4w.js} +3 -3
- package/dist/{shared-BrQVwt_b.js → shared-CDr0M6z-.js} +4 -4
- package/dist/{utils-BeXPKXuG.js → utils-DuQdDbou.js} +11 -1
- package/dist/vite-plugin/index.js +2 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -5,7 +5,7 @@ import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
|
5
5
|
import { Console, Effect, FileSystem, Option, Path, Ref, Schema, Stream } from "effect";
|
|
6
6
|
import { Argument, CliError, Command, Flag } from "effect/cli";
|
|
7
7
|
// package.json
|
|
8
|
-
var version = "0.33.
|
|
8
|
+
var version = "0.33.4";
|
|
9
9
|
var description = "Hono Takibi is a code generator from OpenAPI to @hono/zod-openapi";
|
|
10
10
|
// src/cli/index.ts
|
|
11
11
|
const COMMAND_NAME = "hono-takibi";
|
|
@@ -41,7 +41,7 @@ function runJobs(config) {
|
|
|
41
41
|
const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob, openAPI3, packageRoots }] = yield* Effect.promise(() => Promise.all([
|
|
42
42
|
import("./openapi-BxSVfs_l.js").then((n) => n.t),
|
|
43
43
|
import("./format-BF7SbaMP.js").then((n) => n.r),
|
|
44
|
-
import("./shared-
|
|
44
|
+
import("./shared-CDr0M6z-.js").then((n) => n.o)
|
|
45
45
|
]));
|
|
46
46
|
const openAPI = yield* openAPI3(yield* parseOpenAPI(config.input), config.input);
|
|
47
47
|
const jobs = makeJob(openAPI, config, yield* packageRoots(openAPI, config));
|
|
@@ -79,7 +79,7 @@ function reportJobs(config, previous) {
|
|
|
79
79
|
onFailure: (error) => Console.error(`❌ ${error.message}`),
|
|
80
80
|
onSuccess: (report) => Console.log(report)
|
|
81
81
|
}));
|
|
82
|
-
const { outsideSources } = yield* Effect.promise(() => import("./shared-
|
|
82
|
+
const { outsideSources } = yield* Effect.promise(() => import("./shared-CDr0M6z-.js").then((n) => n.o));
|
|
83
83
|
const inputDirectory = path.dirname(path.resolve(config.input));
|
|
84
84
|
return {
|
|
85
85
|
inputDirectory,
|
|
@@ -208,8 +208,8 @@ function generate(args) {
|
|
|
208
208
|
if (input !== void 0 && output !== void 0) {
|
|
209
209
|
const [{ parseOpenAPI }, { takibi }, { openAPI3 }] = yield* Effect.promise(() => Promise.all([
|
|
210
210
|
import("./openapi-BxSVfs_l.js").then((n) => n.t),
|
|
211
|
-
import("./core
|
|
212
|
-
import("./shared-
|
|
211
|
+
import("./core--c3Vfca8.js").then((n) => n.t),
|
|
212
|
+
import("./shared-CDr0M6z-.js").then((n) => n.o)
|
|
213
213
|
]));
|
|
214
214
|
const document = yield* openAPI3(yield* parseOpenAPI(input), input);
|
|
215
215
|
return yield* Console.log(yield* takibi(document, output));
|
package/dist/core/docs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as docs } from "../../docs-
|
|
1
|
+
export { t as docs } from "../../docs-Md7vHZib.js";
|
package/dist/core/hooks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as hooks } from "../../hooks-
|
|
1
|
+
export { t as hooks } from "../../hooks-BYOaM0T6.js";
|
package/dist/core/rpc/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { N as isRecord, S as isOpenAPIPaths, et as HTTP_METHODS, w as isOperationLike } from "../../guard-ngBos42D.js";
|
|
2
2
|
import { t as emit } from "../../emit-8SmO5pHF.js";
|
|
3
3
|
import { i as GenerateError } from "../../format-BF7SbaMP.js";
|
|
4
|
-
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "../../rpc-
|
|
5
|
-
import { _ as routeName, u as makeInferRequestType } from "../../utils-
|
|
4
|
+
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "../../rpc-Qup_vU4w.js";
|
|
5
|
+
import { _ as routeName, u as makeInferRequestType } from "../../utils-DuQdDbou.js";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
import { dirname } from "node:path";
|
|
8
8
|
// src/core/rpc/index.ts
|
package/dist/core/type/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { C as isOperation, E as isParameterArray, I as isRequestBody, M as isPresent, R as isSchemaArray, S as isOpenAPIPaths, T as isParameter, W as isStringRef, b as isMediaWithSchema, h as isHttpMethod, u as isBinaryFile } from "../../guard-ngBos42D.js";
|
|
2
2
|
import { t as emit } from "../../emit-8SmO5pHF.js";
|
|
3
|
-
import { d as makeSafeKey, v as statusCodeToNumber, y as
|
|
3
|
+
import { b as toIdentifierPascalCase, d as makeSafeKey, f as makeStringLiteral, v as statusCodeToNumber, y as toHonoPath } from "../../utils-DuQdDbou.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
// src/core/type/index.ts
|
|
@@ -14,6 +14,74 @@ const DEEP_READONLY_TYPE = "type DeepReadonly<T>=T extends(infer R)[]?readonly D
|
|
|
14
14
|
*/
|
|
15
15
|
const RESERVED_TYPE_NAMES = /* @__PURE__ */ new Set(["DeepReadonly", "File"]);
|
|
16
16
|
/**
|
|
17
|
+
* The status codes of Hono's `StatusCode` (`hono/utils/http-status`).
|
|
18
|
+
*/
|
|
19
|
+
const HONO_STATUS_CODES = /* @__PURE__ */ new Set([
|
|
20
|
+
100,
|
|
21
|
+
101,
|
|
22
|
+
102,
|
|
23
|
+
103,
|
|
24
|
+
200,
|
|
25
|
+
201,
|
|
26
|
+
202,
|
|
27
|
+
203,
|
|
28
|
+
204,
|
|
29
|
+
205,
|
|
30
|
+
206,
|
|
31
|
+
207,
|
|
32
|
+
208,
|
|
33
|
+
226,
|
|
34
|
+
300,
|
|
35
|
+
301,
|
|
36
|
+
302,
|
|
37
|
+
303,
|
|
38
|
+
304,
|
|
39
|
+
305,
|
|
40
|
+
306,
|
|
41
|
+
307,
|
|
42
|
+
308,
|
|
43
|
+
400,
|
|
44
|
+
401,
|
|
45
|
+
402,
|
|
46
|
+
403,
|
|
47
|
+
404,
|
|
48
|
+
405,
|
|
49
|
+
406,
|
|
50
|
+
407,
|
|
51
|
+
408,
|
|
52
|
+
409,
|
|
53
|
+
410,
|
|
54
|
+
411,
|
|
55
|
+
412,
|
|
56
|
+
413,
|
|
57
|
+
414,
|
|
58
|
+
415,
|
|
59
|
+
416,
|
|
60
|
+
417,
|
|
61
|
+
418,
|
|
62
|
+
421,
|
|
63
|
+
422,
|
|
64
|
+
423,
|
|
65
|
+
424,
|
|
66
|
+
425,
|
|
67
|
+
426,
|
|
68
|
+
428,
|
|
69
|
+
429,
|
|
70
|
+
431,
|
|
71
|
+
451,
|
|
72
|
+
500,
|
|
73
|
+
501,
|
|
74
|
+
502,
|
|
75
|
+
503,
|
|
76
|
+
504,
|
|
77
|
+
505,
|
|
78
|
+
506,
|
|
79
|
+
507,
|
|
80
|
+
508,
|
|
81
|
+
510,
|
|
82
|
+
511
|
|
83
|
+
]);
|
|
84
|
+
/**
|
|
17
85
|
* Generates TypeScript type declarations from OpenAPI specification.
|
|
18
86
|
*/
|
|
19
87
|
function type(openAPI, output, readonly) {
|
|
@@ -54,7 +122,7 @@ function aliasOf(schemaName, schema, aliases) {
|
|
|
54
122
|
function makeHonoSchemaType(openAPI, aliases) {
|
|
55
123
|
const paths = isOpenAPIPaths(openAPI.paths) ? openAPI.paths : {};
|
|
56
124
|
const pathEntries = Object.entries(paths).flatMap(([openApiPath, pathItem]) => {
|
|
57
|
-
const honoPath =
|
|
125
|
+
const honoPath = toHonoPath(openApiPath);
|
|
58
126
|
const pathLevelParams = isParameterArray(pathItem.parameters) ? pathItem.parameters : [];
|
|
59
127
|
const methods = Object.entries(pathItem).filter((entry) => {
|
|
60
128
|
const [method, op] = entry;
|
|
@@ -68,10 +136,7 @@ function makeHonoSchemaType(openAPI, aliases) {
|
|
|
68
136
|
methods: methods.map((m) => `${m.method}:${m.type}`).join(";")
|
|
69
137
|
}] : [];
|
|
70
138
|
});
|
|
71
|
-
return pathEntries.length === 0 ? "{}" : pathEntries.map(({ path: p, methods }) => `{
|
|
72
|
-
}
|
|
73
|
-
function makeHonoPath(openApiPath) {
|
|
74
|
-
return openApiPath.replaceAll(/\{([^}]+)\}/gu, ":$1");
|
|
139
|
+
return pathEntries.length === 0 ? "{}" : pathEntries.map(({ path: p, methods }) => `{${makeStringLiteral(p)}:{${methods}}}`).join("&");
|
|
75
140
|
}
|
|
76
141
|
function makeMethodType(operation, openApiPath, aliases, pathLevelParams) {
|
|
77
142
|
const inputType = makeInputType(operation, openApiPath, aliases, pathLevelParams);
|
|
@@ -140,8 +205,10 @@ function makeOutputTypes(responses, aliases, inputType) {
|
|
|
140
205
|
return Object.entries(responses ?? {}).flatMap(([statusCode, response]) => {
|
|
141
206
|
const resolvedResponse = makeResolvedResponse(response, aliases.components);
|
|
142
207
|
const status = statusCodeToNumber(statusCode);
|
|
143
|
-
if (!
|
|
144
|
-
|
|
208
|
+
if (!HONO_STATUS_CODES.has(status)) return [];
|
|
209
|
+
const mediaEntries = Object.entries(resolvedResponse.content ?? {}).filter((entry) => isMediaWithSchema(entry[1]));
|
|
210
|
+
if (mediaEntries.length === 0) return [`{input:${inputType};output:{};outputFormat:string;status:${status}}`];
|
|
211
|
+
return mediaEntries.map(([mediaType, media]) => {
|
|
145
212
|
return `{input:${inputType};output:${makeSchemaTypeString(media.schema, aliases, /* @__PURE__ */ new Set())};outputFormat:${isJsonMediaType(mediaType) ? "'json'" : "'text'"};status:${status}}`;
|
|
146
213
|
});
|
|
147
214
|
});
|
|
@@ -194,7 +261,7 @@ function makeSchemaTypeString(schema, aliases, visited) {
|
|
|
194
261
|
if (schema.anyOf && schema.anyOf.length > 0) return schema.anyOf.map((s) => makeSchemaTypeString(s, aliases, visited)).join("|");
|
|
195
262
|
if (schema.allOf && schema.allOf.length > 0) return makeAllOfTypeString(schema.allOf, aliases, visited);
|
|
196
263
|
const isBigintLiteral = (value) => typeof value === "number" && Number.isInteger(value) && (Array.isArray(schema.type) ? schema.type.includes("integer") : schema.type === "integer") && (schema.format === "int64" || schema.format === "uint64" || schema.format === "bigint");
|
|
197
|
-
if (schema.enum && schema.enum.length > 0) return schema.enum.map((v) => typeof v === "string" ? `'${v.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'` : isBigintLiteral(v) ? `${v}n` : String(v)).join("|");
|
|
264
|
+
if (schema.enum && schema.enum.length > 0) return schema.enum.map((v) => typeof v === "string" ? `'${v.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'` : isBigintLiteral(v) ? `${v}n` : typeof v === "object" && v !== null ? JSON.stringify(v) : String(v)).join("|");
|
|
198
265
|
if (schema.const !== void 0) {
|
|
199
266
|
if (typeof schema.const === "string") return `'${schema.const.replaceAll("\\", "\\\\").replaceAll("'", "\\'")}'`;
|
|
200
267
|
if (isBigintLiteral(schema.const)) return `${schema.const}n`;
|
|
@@ -1,15 +1,15 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
2
2
|
import { A as isPathItemEntry, C as isOperation, J as COMPONENT_NAMES, K as isValidIdent, N as isRecord, S as isOpenAPIPaths, d as isCallbacks, et as HTTP_METHODS, h as isHttpMethod, k as isPathItem } from "./guard-ngBos42D.js";
|
|
3
3
|
import { i as GenerateError, n as fmt } from "./format-BF7SbaMP.js";
|
|
4
|
-
import { _ as routeName, a as ensureSuffix, b as
|
|
5
|
-
import { C as makePathItem, D as makeWebhookEntries, E as makeRouteProperties, O as resolveParameter, S as makeCallback, T as makeRouteEntries, _ as identifierNames, a as requestBodiesCode, b as textOf, c as makeSplitSchemaFile, d as makeImports, f as makeModuleSpec, g as descendantsWhere, h as declarationOf, i as responsesCode, k as resolvePathItem, l as makeConst, m as ast, n as componentsCode, o as parametersCode, p as analyzeCircularSchemas, r as schemasCode, s as headersCode, u as makeExportConst, v as parseModule, w as makeRef, x as zodToOpenAPI, y as parseSource } from "./routes-
|
|
6
|
-
import { t as zodOpenAPIHono } from "./openapi-
|
|
7
|
-
import { t as makeMock } from "./mock-
|
|
8
|
-
import { a as entryNames, c as makeGroupClientName, l as operationTags, o as freeName, s as groupNameOf } from "./rpc-
|
|
4
|
+
import { S as zodToOpenAPISchema, _ as routeName, a as ensureSuffix, b as toIdentifierPascalCase, c as escapeRegexLiteral, h as renderNamedImport, l as makeBarrel, x as uncapitalize } from "./utils-DuQdDbou.js";
|
|
5
|
+
import { C as makePathItem, D as makeWebhookEntries, E as makeRouteProperties, O as resolveParameter, S as makeCallback, T as makeRouteEntries, _ as identifierNames, a as requestBodiesCode, b as textOf, c as makeSplitSchemaFile, d as makeImports, f as makeModuleSpec, g as descendantsWhere, h as declarationOf, i as responsesCode, k as resolvePathItem, l as makeConst, m as ast, n as componentsCode, o as parametersCode, p as analyzeCircularSchemas, r as schemasCode, s as headersCode, u as makeExportConst, v as parseModule, w as makeRef, x as zodToOpenAPI, y as parseSource } from "./routes-65ua_FNx.js";
|
|
6
|
+
import { t as zodOpenAPIHono } from "./openapi-DAYtJjPV.js";
|
|
7
|
+
import { t as makeMock } from "./mock-EWnJ65d3.js";
|
|
8
|
+
import { a as entryNames, c as makeGroupClientName, l as operationTags, o as freeName, s as groupNameOf } from "./rpc-Qup_vU4w.js";
|
|
9
9
|
import { i as readdir, n as mkdir, o as writeFile, r as readFile } from "./file-hO_bjDys.js";
|
|
10
10
|
import { t as emit } from "./emit-8SmO5pHF.js";
|
|
11
|
-
import { t as hooks } from "./hooks-
|
|
12
|
-
import { t as docs } from "./docs-
|
|
11
|
+
import { t as hooks } from "./hooks-BYOaM0T6.js";
|
|
12
|
+
import { t as docs } from "./docs-Md7vHZib.js";
|
|
13
13
|
import { rpc } from "./core/rpc/index.js";
|
|
14
14
|
import { type } from "./core/type/index.js";
|
|
15
15
|
import { Effect } from "effect";
|
|
@@ -736,6 +736,16 @@ function handlerNameOf(fileName) {
|
|
|
736
736
|
return basename(fileName, ".ts").replaceAll(/-+([0-9A-Za-z_]?)/gu, (_, char) => char.toUpperCase());
|
|
737
737
|
}
|
|
738
738
|
/**
|
|
739
|
+
* The export of an inline handler file: the name the file goes by in code, followed by
|
|
740
|
+
* `Handler`, `real-time-events.ts` as `realTimeEventsHandler`. A name that starts with a
|
|
741
|
+
* digit is no identifier, so it is prefixed the way its group is: `2020-05-31.ts` as
|
|
742
|
+
* `__20200531Handler` (#506).
|
|
743
|
+
*/
|
|
744
|
+
function handlerExportOf(fileName) {
|
|
745
|
+
const name = handlerNameOf(fileName);
|
|
746
|
+
return /^[0-9]/u.test(name) ? `__${name}Handler` : `${name}Handler`;
|
|
747
|
+
}
|
|
748
|
+
/**
|
|
739
749
|
* Derives the handler file name for an operation, in kebab case: the first segment of its
|
|
740
750
|
* path (`/` → `__root`), `/real-time-events/{id}` as `real-time-events.ts`. The tags of the
|
|
741
751
|
* operation say nothing of the file.
|
|
@@ -837,7 +847,7 @@ function makeInlineStubHandlerInfo(paths, path, method, existing) {
|
|
|
837
847
|
return makeHandlerInfo(paths, path, method, existing, "Route", (routeId) => `.openapi(${routeId}Route,(c)=>{})`);
|
|
838
848
|
}
|
|
839
849
|
function makeInlineStubFileContent(handler, importFrom) {
|
|
840
|
-
const exportName =
|
|
850
|
+
const exportName = handlerExportOf(handler.fileName);
|
|
841
851
|
const routeImports = [...new Set(handler.routeNames)].join(", ");
|
|
842
852
|
return `${`import { OpenAPIHono } from '@hono/zod-openapi'\n${routeImports ? `import { ${routeImports} } from '${importFrom}';` : ""}`}\n\nconst app = new OpenAPIHono()\n\nexport const ${exportName} = app\n${handler.contents.join("\n")}`;
|
|
843
853
|
}
|
|
@@ -1478,28 +1488,28 @@ function app(openapi, output, basePath, pathAlias, routeImport, routeHandler = f
|
|
|
1478
1488
|
return [
|
|
1479
1489
|
importSection,
|
|
1480
1490
|
appInit,
|
|
1481
|
-
routeNames.length > 0 ? `export const api=${appVar}.openapiRoutes([${routeNames.join(",")}] as const)` :
|
|
1491
|
+
routeNames.length > 0 ? `export const api=${appVar}.openapiRoutes([${routeNames.join(",")}] as const)` : `export const api=${appVar}`,
|
|
1482
1492
|
appExport
|
|
1483
|
-
].
|
|
1493
|
+
].join("\n\n");
|
|
1484
1494
|
}
|
|
1485
1495
|
if (!routeHandler) {
|
|
1486
1496
|
const handlerFileNames = inlineHandlerFileNames ?? handlerFilesOf(openapi);
|
|
1487
1497
|
const files = [...new Set(handlerFileNames.map(handlerNameOf))];
|
|
1488
|
-
const handlerExportNames = files.map(
|
|
1498
|
+
const handlerExportNames = files.map(handlerExportOf);
|
|
1489
1499
|
const handlerModule = handlerModuleOverride ?? (aliasPrefix ? `${aliasPrefix}/handlers` : "./handlers");
|
|
1490
1500
|
const importSection = [honoImport, handlerExportNames.length > 0 ? `import{${handlerExportNames.join(",")}}from'${handlerModule}'` : ""].filter(Boolean).join("\n");
|
|
1491
1501
|
if (split) return [
|
|
1492
1502
|
importSection,
|
|
1493
1503
|
appInit,
|
|
1494
|
-
...groups.map((name) => `export const ${name}=${appVar}${files.filter((file) => groupNameOf(file) === name).map((file) => `.route('/',${file}
|
|
1504
|
+
...groups.map((name) => `export const ${name}=${appVar}${files.filter((file) => groupNameOf(file) === name).map((file) => `.route('/',${handlerExportOf(file)})`).join("")}`),
|
|
1495
1505
|
appExport
|
|
1496
1506
|
].join("\n\n");
|
|
1497
1507
|
return [
|
|
1498
1508
|
importSection,
|
|
1499
1509
|
appInit,
|
|
1500
|
-
handlerExportNames.length > 0 ? `export const api=${appVar}${handlerExportNames.map((name) => `.route('/',${name})`).join("")}` :
|
|
1510
|
+
handlerExportNames.length > 0 ? `export const api=${appVar}${handlerExportNames.map((name) => `.route('/',${name})`).join("")}` : `export const api=${appVar}`,
|
|
1501
1511
|
appExport
|
|
1502
|
-
].
|
|
1512
|
+
].join("\n\n");
|
|
1503
1513
|
}
|
|
1504
1514
|
const routeNames = [...new Set(routeMappings.map((m) => m.routeName))];
|
|
1505
1515
|
const routeModule = routeImport ?? (aliasPrefix ? `${aliasPrefix}/${routeBasename}` : `./${routeBasename}`);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { n as mkdir, o as writeFile } from "./file-hO_bjDys.js";
|
|
2
2
|
import { N as isRecord, P as isRefObject, R as isSchemaArray, et as HTTP_METHODS, it as MULTIPART_MEDIA_TYPE } from "./guard-ngBos42D.js";
|
|
3
|
-
import { i as decodePercent, s as escapeHtml } from "./utils-
|
|
3
|
+
import { i as decodePercent, s as escapeHtml } from "./utils-DuQdDbou.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import { STATUS_CODES } from "node:http";
|
package/dist/generate/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseConfig } from "../index.js";
|
|
2
2
|
import { t as FormatOptions } from "../format-BF7SbaMP.js";
|
|
3
3
|
import { n as parseOpenAPI } from "../openapi-BxSVfs_l.js";
|
|
4
|
-
import { a as packageRoots, n as makeJob, r as openAPI3, t as cleanSplitOutputs } from "../shared-
|
|
4
|
+
import { a as packageRoots, n as makeJob, r as openAPI3, t as cleanSplitOutputs } from "../shared-CDr0M6z-.js";
|
|
5
5
|
import * as NodeServices from "@effect/platform-node/NodeServices";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
// src/generate/index.ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as makeMock } from "../../mock-
|
|
1
|
+
export { t as makeMock } from "../../mock-EWnJ65d3.js";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as zodOpenAPIHono } from "../../../openapi-
|
|
1
|
+
export { t as zodOpenAPIHono } from "../../../openapi-DAYtJjPV.js";
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { N as isRecord, S as isOpenAPIPaths, et as HTTP_METHODS, i as hasNoContentResponse, w as isOperationLike } from "./guard-ngBos42D.js";
|
|
2
2
|
import { t as emit } from "./emit-8SmO5pHF.js";
|
|
3
3
|
import { i as GenerateError } from "./format-BF7SbaMP.js";
|
|
4
|
-
import { _ as routeName, n as capitalize, y as
|
|
5
|
-
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "./rpc-
|
|
4
|
+
import { _ as routeName, b as toIdentifierPascalCase, n as capitalize, y as toHonoPath } from "./utils-DuQdDbou.js";
|
|
5
|
+
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "./rpc-Qup_vU4w.js";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
import path from "node:path";
|
|
8
8
|
// src/helper/query.ts
|
|
@@ -46,6 +46,27 @@ function makeArgsType(clientName, method, pathStr, hasBasePath = false) {
|
|
|
46
46
|
function queryNameMethod(method) {
|
|
47
47
|
return method === "get" ? "" : method;
|
|
48
48
|
}
|
|
49
|
+
function libraryValueImports(config) {
|
|
50
|
+
return new Set([
|
|
51
|
+
config.queryFn,
|
|
52
|
+
config.mutationFn,
|
|
53
|
+
config.suspenseQueryFn,
|
|
54
|
+
config.infiniteQueryFn,
|
|
55
|
+
config.suspenseInfiniteQueryFn,
|
|
56
|
+
config.immutableQueryFn
|
|
57
|
+
].filter((name) => name !== void 0));
|
|
58
|
+
}
|
|
59
|
+
function queryHookStem(method, pathFuncName, config) {
|
|
60
|
+
const stem = capitalize(pathFuncName);
|
|
61
|
+
if (method !== "get") return stem;
|
|
62
|
+
const reserved = libraryValueImports(config);
|
|
63
|
+
return [
|
|
64
|
+
"",
|
|
65
|
+
"Suspense",
|
|
66
|
+
"Infinite",
|
|
67
|
+
"SuspenseInfinite"
|
|
68
|
+
].some((variant) => reserved.has(`${config.hookPrefix}${variant}${stem}`)) ? `Get${stem}` : stem;
|
|
69
|
+
}
|
|
49
70
|
function makeQueryKeyGetterName(method, pathStr, paths, isSWR) {
|
|
50
71
|
if (isSWR) return `get${capitalize(routeName(method, pathStr, paths))}Key`;
|
|
51
72
|
return `get${capitalize(routeName(queryNameMethod(method), pathStr, paths))}QueryKey`;
|
|
@@ -397,7 +418,7 @@ function makeHookCode(paths, pathStr, method, item, deps, config, clientName, ha
|
|
|
397
418
|
const runtimeAccess = makeRuntimeAccess(clientName, method, pathStr, hasBasePath);
|
|
398
419
|
const responseType = makeResponseTypeFromClient(clientName, method, pathStr, hasBasePath);
|
|
399
420
|
const hasNoContent = hasNoContentResponse(op);
|
|
400
|
-
const honoPath = pathStr
|
|
421
|
+
const honoPath = toHonoPath(pathStr);
|
|
401
422
|
if (config.isSWR) {
|
|
402
423
|
if (isQuery) {
|
|
403
424
|
const keyGetterName = makeQueryKeyGetterName(method, pathStr, paths, true);
|
|
@@ -432,8 +453,9 @@ function makeHookCode(paths, pathStr, method, item, deps, config, clientName, ha
|
|
|
432
453
|
};
|
|
433
454
|
}
|
|
434
455
|
if (isQuery) {
|
|
435
|
-
const queryHookName = makeHookName(queryNameMethod(method), pathStr, config.hookPrefix, paths);
|
|
436
456
|
const pathFuncName = routeName(queryNameMethod(method), pathStr, paths);
|
|
457
|
+
const hookStem = queryHookStem(method, pathFuncName, config);
|
|
458
|
+
const queryHookName = `${config.hookPrefix}${hookStem}`;
|
|
437
459
|
const keyGetterName = makeQueryKeyGetterName(method, pathStr, paths);
|
|
438
460
|
const optionsGetterName = `get${capitalize(pathFuncName)}QueryOptions`;
|
|
439
461
|
const keyGetterCode = makeQueryKeyGetterCode(keyGetterName, hasArgs, argsType, honoPath, config, excludedArgs, method);
|
|
@@ -449,7 +471,7 @@ function makeHookCode(paths, pathStr, method, item, deps, config, clientName, ha
|
|
|
449
471
|
...config.hasInfiniteQueryOptionsHelper ? { hasInfiniteQueryOptionsHelper: true } : {},
|
|
450
472
|
...config.errorType ? { errorType: config.errorType } : {}
|
|
451
473
|
}) : null;
|
|
452
|
-
const suspenseHookName = `${config.hookPrefix}Suspense${
|
|
474
|
+
const suspenseHookName = `${config.hookPrefix}Suspense${hookStem}`;
|
|
453
475
|
const suspenseHookCode = config.suspenseQueryFn && config.useSuspenseQueryOptionsType ? makeQueryHookCode(suspenseHookName, keyGetterName, optionsGetterName, runtimeAccess, hasArgs, argsType, responseType, {
|
|
454
476
|
queryFn: config.suspenseQueryFn,
|
|
455
477
|
useQueryOptionsType: config.useSuspenseQueryOptionsType,
|
|
@@ -460,7 +482,7 @@ function makeHookCode(paths, pathStr, method, item, deps, config, clientName, ha
|
|
|
460
482
|
...config.hookTail ? { hookTail: config.hookTail } : {},
|
|
461
483
|
...config.unwrapOptionsAccessor ? { unwrapOptionsAccessor: true } : {}
|
|
462
484
|
}) : null;
|
|
463
|
-
const infiniteHookName = `${config.hookPrefix}Infinite${
|
|
485
|
+
const infiniteHookName = `${config.hookPrefix}Infinite${hookStem}`;
|
|
464
486
|
const infiniteHookCode = hasInfinite ? makeInfiniteQueryHookCode(infiniteHookName, runtimeAccess, infiniteKeyGetterName, infiniteOptionsGetterName, hasArgs, argsType, responseType, {
|
|
465
487
|
infiniteQueryFn,
|
|
466
488
|
useInfiniteQueryOptionsType,
|
|
@@ -471,7 +493,7 @@ function makeHookCode(paths, pathStr, method, item, deps, config, clientName, ha
|
|
|
471
493
|
...config.hookTail ? { hookTail: config.hookTail } : {},
|
|
472
494
|
...config.unwrapOptionsAccessor ? { unwrapOptionsAccessor: true } : {}
|
|
473
495
|
}) : null;
|
|
474
|
-
const suspenseInfiniteHookName = `${config.hookPrefix}SuspenseInfinite${
|
|
496
|
+
const suspenseInfiniteHookName = `${config.hookPrefix}SuspenseInfinite${hookStem}`;
|
|
475
497
|
return {
|
|
476
498
|
code: [
|
|
477
499
|
keyGetterCode,
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { A as isPathItemEntry, C as isOperation, H as isSecurityScheme, M as isPresent, P as isRefObject, R as isSchemaArray, T as isParameter, V as isSecurityArray, Y as COMPONENT_REF_PREFIX, _ as isInlineMedia, b as isMediaWithSchema, et as HTTP_METHODS, h as isHttpMethod, j as isPathItemRef, o as hasNumericConstraint, ot as TEXT_MEDIA_TYPE, rt as JSON_MEDIA_TYPE, s as hasRequestBodyContent, z as isSchemaObject } from "./guard-ngBos42D.js";
|
|
2
|
-
import { _ as routeName, a as ensureSuffix, d as makeSafeKey, f as makeStringLiteral, p as normalizeTypes, r as cyclicNodes, v as statusCodeToNumber
|
|
3
|
-
import { n as componentsCode, t as routeCode } from "./routes-
|
|
2
|
+
import { _ as routeName, a as ensureSuffix, b as toIdentifierPascalCase, d as makeSafeKey, f as makeStringLiteral, p as normalizeTypes, r as cyclicNodes, v as statusCodeToNumber } from "./utils-DuQdDbou.js";
|
|
3
|
+
import { n as componentsCode, t as routeCode } from "./routes-65ua_FNx.js";
|
|
4
4
|
// src/helper/faker.ts
|
|
5
5
|
const FORMAT_TO_FAKER = {
|
|
6
6
|
date: "faker.date.past().toISOString().slice(0, 10)",
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { J as COMPONENT_NAMES, N as isRecord, X as COMPONENT_SUFFIXES, Y as COMPONENT_REF_PREFIX, et as HTTP_METHODS } from "./guard-ngBos42D.js";
|
|
2
|
-
import { a as ensureSuffix,
|
|
3
|
-
import { D as makeWebhookEntries, n as componentsCode, t as routeCode } from "./routes-
|
|
2
|
+
import { a as ensureSuffix, b as toIdentifierPascalCase, i as decodePercent } from "./utils-DuQdDbou.js";
|
|
3
|
+
import { D as makeWebhookEntries, n as componentsCode, t as routeCode } from "./routes-65ua_FNx.js";
|
|
4
4
|
// src/helper/names.ts
|
|
5
5
|
/**
|
|
6
6
|
* Renames the components whose identifiers would collide, and every `$ref` to them.
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { A as isPathItemEntry, C as isOperation, F as isRefOnly, G as isUntypedObject, J as COMPONENT_NAMES, K as isValidIdent, L as isResponses, M as isPresent, N as isRecord, O as isParameterRef, P as isRefObject, R as isSchemaArray, T as isParameter, U as isSingleSchema, X as COMPONENT_SUFFIXES$1, Y as COMPONENT_REF_PREFIX, Z as FORM_MEDIA_TYPES, a as hasNoUserChain, c as hasTypelessConstraint, d as isCallbacks, et as HTTP_METHODS, f as isDiscriminableBranch, g as isInheritedName, j as isPathItemRef, k as isPathItem, l as isAnnotationOnly, m as isHeader, n as fileMimeTypes, p as isExamplesInput, q as ARROW_FUNCTION_PATTERN, r as hasMimeAlternatives, t as ANNOTATION_KEYWORDS, u as isBinaryFile, x as isOffsetTime, y as isMedia, z as isSchemaObject } from "./guard-ngBos42D.js";
|
|
2
|
-
import { _ as routeName, a as ensureSuffix, b as
|
|
2
|
+
import { S as zodToOpenAPISchema, _ as routeName, a as ensureSuffix, b as toIdentifierPascalCase, c as escapeRegexLiteral, d as makeSafeKey, f as makeStringLiteral, g as requestParamsArray, h as renderNamedImport, i as decodePercent, m as regexLiteral, o as error, p as normalizeTypes, r as cyclicNodes, t as baseError, x as uncapitalize } from "./utils-DuQdDbou.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { parseSync, rawTransferSupported, visitorKeys } from "oxc-parser";
|
|
5
5
|
// src/helper/wire.ts
|
|
@@ -614,10 +614,11 @@ function makeHeaderSchema(header, readonly) {
|
|
|
614
614
|
*/
|
|
615
615
|
function makeResponses(responses, readonly, schemas) {
|
|
616
616
|
if (responses.$ref) return makeRef(responses.$ref);
|
|
617
|
+
const content = responses.content ? makeContent(responses.content, readonly, void 0, schemas) : [];
|
|
617
618
|
return `{${[
|
|
618
619
|
responses.summary ? `summary:${JSON.stringify(responses.summary)}` : void 0,
|
|
619
620
|
`description:${JSON.stringify(responses.description ?? "")}`,
|
|
620
|
-
|
|
621
|
+
content.length > 0 ? `content:{${content.join(",")}}` : void 0,
|
|
621
622
|
responses.headers ? `headers:${makeHeaderResponses(responses.headers, readonly)}` : void 0,
|
|
622
623
|
responses.links ? `links:{${Object.entries(responses.links).map(([key, link]) => "$ref" in link && link.$ref ? `${JSON.stringify(key)}:${makeRef(link.$ref)}` : `${JSON.stringify(key)}:${makeLinkOrReference(link)}`).join(",")}}` : void 0
|
|
623
624
|
].filter((v) => v !== void 0).join(",")}}`;
|
|
@@ -2835,21 +2836,29 @@ function string(schema, options) {
|
|
|
2835
2836
|
const enc = schema.contentEncoding;
|
|
2836
2837
|
const mediaType = schema.contentMediaType;
|
|
2837
2838
|
const contentSchema = schema.contentSchema;
|
|
2838
|
-
if ((enc !== void 0 || mediaType !== void 0 || contentSchema !== void 0) && !hashBase && !isBinaryFile(schema))
|
|
2839
|
-
|
|
2840
|
-
|
|
2841
|
-
|
|
2842
|
-
|
|
2843
|
-
|
|
2839
|
+
if ((enc !== void 0 || mediaType !== void 0 || contentSchema !== void 0) && !hashBase && !isBinaryFile(schema)) {
|
|
2840
|
+
const baseStr = (() => {
|
|
2841
|
+
if (enc === "base64") return "z.base64()";
|
|
2842
|
+
if (enc === "base64url") return "z.base64url()";
|
|
2843
|
+
return "z.string()";
|
|
2844
|
+
})();
|
|
2844
2845
|
const mt = mediaType ? mediaType.toLowerCase() : "";
|
|
2845
2846
|
const isBinary = /^(image|audio|video)\//u.test(mt) || mt === "application/octet-stream";
|
|
2846
2847
|
const isJson = mt.length > 0 && mt.includes("json");
|
|
2847
|
-
const
|
|
2848
|
-
const
|
|
2849
|
-
|
|
2850
|
-
|
|
2851
|
-
|
|
2852
|
-
|
|
2848
|
+
const isEncoded = enc === "base64" || enc === "base64url";
|
|
2849
|
+
const validates = contentSchema !== void 0 && mt.length > 0 && !isBinary;
|
|
2850
|
+
const jsonParseStep = (textExpr) => {
|
|
2851
|
+
return `.transform((val,ctx)=>{try{return JSON.parse(${textExpr})}catch(err){ctx.addIssue(${errorMessage ? `{code:"custom",message:${JSON.stringify(errorMessage)},params:{cause:err instanceof Error?err.message:String(err)}}` : "{code:\"custom\",params:{cause:err instanceof Error?err.message:String(err)}}"});return z.NEVER}})`;
|
|
2852
|
+
};
|
|
2853
|
+
return `${baseStr}${(() => {
|
|
2854
|
+
if (!isEncoded) return isJson && validates ? jsonParseStep("val") : "";
|
|
2855
|
+
const bytesExpr = `Uint8Array.from(atob(${enc === "base64url" ? "val.replace(/-/g,\"+\").replace(/_/g,\"/\")" : "val"}),(char)=>char.charCodeAt(0))`;
|
|
2856
|
+
const textExpr = `new TextDecoder().decode(${bytesExpr})`;
|
|
2857
|
+
if (isBinary) return `.transform((val)=>${bytesExpr})`;
|
|
2858
|
+
if (isJson) return jsonParseStep(textExpr);
|
|
2859
|
+
return `.transform((val)=>${textExpr})`;
|
|
2860
|
+
})()}${validates ? `.pipe(${zodToOpenAPI(contentSchema, void 0, options)})` : ""}`;
|
|
2861
|
+
}
|
|
2853
2862
|
const format = schema.format && Object.hasOwn(FORMAT_STRING, schema.format) ? FORMAT_STRING[schema.format] : void 0;
|
|
2854
2863
|
const isTransformFormat = !!(schema.format && TRANSFORM_FORMATS.has(schema.format));
|
|
2855
2864
|
const isValidationFormat = !!(format && !isTransformFormat);
|
|
@@ -2932,6 +2941,13 @@ function withRawStatements(zod, statements, declarations = []) {
|
|
|
2932
2941
|
function hasOwnWrapping(branch) {
|
|
2933
2942
|
return branch.nullable === true || normalizeTypes(branch.type).includes("null") || branch.default !== void 0 || branch["x-prefault"] !== void 0 || branch["x-catch"] !== void 0;
|
|
2934
2943
|
}
|
|
2944
|
+
/**
|
|
2945
|
+
* Whether a schema is a reference with nothing beside it that constrains a value: the
|
|
2946
|
+
* `$ref` alone, or with the annotations `title` and `description`.
|
|
2947
|
+
*/
|
|
2948
|
+
function isAnnotatedRef(schema) {
|
|
2949
|
+
return typeof schema.$ref === "string" && Object.keys(schema).every((key) => key === "$ref" || key === "title" || key === "description");
|
|
2950
|
+
}
|
|
2935
2951
|
function zodToOpenAPI(schema, meta, options) {
|
|
2936
2952
|
if (schema === true) return wrap("z.any()", {}, meta, options);
|
|
2937
2953
|
if (schema === false) return wrap("z.never()", {}, meta, options);
|
|
@@ -2971,9 +2987,11 @@ function zodToOpenAPI(schema, meta, options) {
|
|
|
2971
2987
|
const withSiblings = (zod) => {
|
|
2972
2988
|
if (!isWrapped) return zod;
|
|
2973
2989
|
const checked = withRawCheck(withRawCheck(zod, makeSiblingCombinatorCheck(schema, siblings, (s) => zodToOpenAPI(s, void 0, childOptions))), parentStrict);
|
|
2990
|
+
const emittedRefs = new Set((emittedCombinator === void 0 ? [] : schema[emittedCombinator] ?? []).flatMap((sub) => isAnnotatedRef(sub) ? [sub.$ref] : []));
|
|
2991
|
+
const repeatsEmitted = (key, list) => emittedCombinator === "allOf" && (key === "oneOf" ? list.length === 1 : true) && list.some((sub) => isAnnotatedRef(sub) && emittedRefs.has(sub.$ref));
|
|
2974
2992
|
const stated = [...siblings.flatMap((key) => {
|
|
2975
2993
|
const list = key === "not" ? void 0 : schema[key];
|
|
2976
|
-
return list === void 0 ? [] : [`${key}:${schemaList(list, childOptions?.schemas)}`];
|
|
2994
|
+
return list === void 0 || repeatsEmitted(key, list) ? [] : [`${key}:${schemaList(list, childOptions?.schemas)}`];
|
|
2977
2995
|
}), ...parentStrict === void 0 ? [] : ["additionalProperties:false"]];
|
|
2978
2996
|
return stated.length === 0 ? checked : `${checked}.openapi({${stated.join(",")}})`;
|
|
2979
2997
|
};
|
|
@@ -3474,12 +3492,29 @@ function zodToOpenAPI(schema, meta, options) {
|
|
|
3474
3492
|
return done("z.any()", schema);
|
|
3475
3493
|
}
|
|
3476
3494
|
// src/helper/syntax.ts
|
|
3477
|
-
const
|
|
3495
|
+
const BASE_PARSER_OPTIONS = {
|
|
3478
3496
|
lang: "ts",
|
|
3479
|
-
sourceType: "module"
|
|
3497
|
+
sourceType: "module"
|
|
3498
|
+
};
|
|
3499
|
+
const PARSER_OPTIONS = {
|
|
3500
|
+
...BASE_PARSER_OPTIONS,
|
|
3480
3501
|
...rawTransferSupported() ? { experimentalRawTransfer: true } : {}
|
|
3481
3502
|
};
|
|
3482
3503
|
/**
|
|
3504
|
+
* The buffer is read into objects by functions that call one another once per level of the
|
|
3505
|
+
* tree, and a handler file is one chain of `.openapi()` calls, a level deeper with each
|
|
3506
|
+
* operation: at about 1,500 of them the stack overflows (#521). The tree written out as
|
|
3507
|
+
* JSON is read back without that depth, so such a module is parsed again that way.
|
|
3508
|
+
*/
|
|
3509
|
+
function parse(code) {
|
|
3510
|
+
try {
|
|
3511
|
+
return parseSync("module.ts", code, PARSER_OPTIONS);
|
|
3512
|
+
} catch (error) {
|
|
3513
|
+
if (!(error instanceof RangeError)) throw error;
|
|
3514
|
+
return parseSync("module.ts", code, BASE_PARSER_OPTIONS);
|
|
3515
|
+
}
|
|
3516
|
+
}
|
|
3517
|
+
/**
|
|
3483
3518
|
* Parses a TypeScript module for reading. What a caller takes from the tree is a position,
|
|
3484
3519
|
* a name or a kind; the text of a node is sliced from `code` by its position, so that what
|
|
3485
3520
|
* is written back is the source as it was, comments included.
|
|
@@ -3489,7 +3524,7 @@ const PARSER_OPTIONS = {
|
|
|
3489
3524
|
* edit may have broken asks for the errors, and leaves such a file alone.
|
|
3490
3525
|
*/
|
|
3491
3526
|
function parseSource(code) {
|
|
3492
|
-
const { program, errors } =
|
|
3527
|
+
const { program, errors } = parse(code);
|
|
3493
3528
|
return {
|
|
3494
3529
|
program,
|
|
3495
3530
|
errors: errors.map((error) => error.message)
|
|
@@ -3506,17 +3541,28 @@ function isNode(value) {
|
|
|
3506
3541
|
return typeof value === "object" && value !== null && "type" in value && typeof value.type === "string" && "start" in value;
|
|
3507
3542
|
}
|
|
3508
3543
|
/**
|
|
3509
|
-
*
|
|
3510
|
-
*
|
|
3544
|
+
* The children of a node, in the order the grammar lists them. A node whose children the
|
|
3545
|
+
* parser does not list is read over its fields.
|
|
3511
3546
|
*/
|
|
3512
|
-
function
|
|
3513
|
-
|
|
3514
|
-
const keys = visitorKeys[node.type] ?? Object.keys(node).filter((key) => key !== "type" && key !== "parent");
|
|
3515
|
-
for (const key of keys) {
|
|
3547
|
+
function childrenOf(node) {
|
|
3548
|
+
return (visitorKeys[node.type] ?? Object.keys(node).filter((key) => key !== "type" && key !== "parent")).flatMap((key) => {
|
|
3516
3549
|
const child = Reflect.get(node, key);
|
|
3517
|
-
if (Array.isArray(child))
|
|
3518
|
-
|
|
3519
|
-
|
|
3550
|
+
if (Array.isArray(child)) return child.filter(isNode);
|
|
3551
|
+
return isNode(child) ? [child] : [];
|
|
3552
|
+
});
|
|
3553
|
+
}
|
|
3554
|
+
/**
|
|
3555
|
+
* Calls `visit` on `node` and on every node under it, each child in the order the grammar
|
|
3556
|
+
* lists them.
|
|
3557
|
+
*
|
|
3558
|
+
* The nodes still to visit are kept in a list rather than on the call stack: a handler
|
|
3559
|
+
* file is one chain of `.openapi()` calls, as deep as the file has operations (#521).
|
|
3560
|
+
*/
|
|
3561
|
+
function walk(root, visit) {
|
|
3562
|
+
const pending = [root];
|
|
3563
|
+
for (let node = pending.pop(); node !== void 0; node = pending.pop()) {
|
|
3564
|
+
visit(node);
|
|
3565
|
+
pending.push(...childrenOf(node).toReversed());
|
|
3520
3566
|
}
|
|
3521
3567
|
}
|
|
3522
3568
|
/** The nodes under `node` that `is` picks out, in tree order, the node itself included. */
|
|
@@ -3837,7 +3883,7 @@ function makeTypeString(schema, selfTypeName, cyclicGroup, readonly) {
|
|
|
3837
3883
|
if (!isPresent(schema)) return "unknown";
|
|
3838
3884
|
if (Object.keys(schema).length === 0) return "unknown";
|
|
3839
3885
|
const types = normalizeType(schema);
|
|
3840
|
-
const isNullable = schema.nullable === true || types.includes("null") || schema.default === null || (schema.enum?.includes(null) ?? false);
|
|
3886
|
+
const isNullable = schema.nullable === true || types.includes("null") || schema.default === null || (schema.enum?.includes(null) ?? false) || (intersectedMembers(schema)?.some(isNullMember) ?? false);
|
|
3841
3887
|
const baseType = makeNonNullTypeString(schema, types.filter((typeName) => typeName !== "null"), selfTypeName, cyclicGroup, readonly);
|
|
3842
3888
|
if (!isNullable || baseType === "null") return baseType;
|
|
3843
3889
|
return `(${baseType}|null)`;
|
|
@@ -3846,11 +3892,12 @@ function makeNonNullTypeString(schema, types, selfTypeName, cyclicGroup, readonl
|
|
|
3846
3892
|
if (schema.$ref) return makeRefTypeString(schema.$ref, selfTypeName);
|
|
3847
3893
|
if (schema.oneOf && schema.oneOf.length > 0) return makeUnionTypeString(schema.oneOf, selfTypeName, cyclicGroup, "|", readonly);
|
|
3848
3894
|
if (schema.anyOf && schema.anyOf.length > 0) return makeUnionTypeString(schema.anyOf, selfTypeName, cyclicGroup, "|", readonly);
|
|
3849
|
-
|
|
3895
|
+
const members = intersectedMembers(schema);
|
|
3896
|
+
if (members !== void 0) return makeUnionTypeString(members.filter((member) => !(isNullMember(member) || isAnnotationOnly(member))), selfTypeName, cyclicGroup, "&", readonly);
|
|
3850
3897
|
if (schema.enum && schema.enum.length > 0) {
|
|
3851
3898
|
const values = schema.enum.filter((v) => v !== null);
|
|
3852
3899
|
if (values.length === 0) return "null";
|
|
3853
|
-
return values.map((v) => typeof v === "string" ? makeStringLiteral(v) : String(v)).join("|");
|
|
3900
|
+
return values.map((v) => typeof v === "string" ? makeStringLiteral(v) : typeof v === "object" ? JSON.stringify(v) : String(v)).join("|");
|
|
3854
3901
|
}
|
|
3855
3902
|
if (schema.const !== void 0) {
|
|
3856
3903
|
if (typeof schema.const === "string") return makeStringLiteral(schema.const);
|
|
@@ -3859,6 +3906,15 @@ function makeNonNullTypeString(schema, types, selfTypeName, cyclicGroup, readonl
|
|
|
3859
3906
|
}
|
|
3860
3907
|
return makeBaseTypeString(schema, types, selfTypeName, cyclicGroup, readonly);
|
|
3861
3908
|
}
|
|
3909
|
+
function intersectedMembers(schema) {
|
|
3910
|
+
if (schema.$ref) return void 0;
|
|
3911
|
+
if (schema.oneOf && schema.oneOf.length > 0) return void 0;
|
|
3912
|
+
if (schema.anyOf && schema.anyOf.length > 0) return void 0;
|
|
3913
|
+
return schema.allOf && schema.allOf.length > 0 ? schema.allOf.filter(Boolean) : void 0;
|
|
3914
|
+
}
|
|
3915
|
+
function isNullMember(member) {
|
|
3916
|
+
return member.type === "null" || member.nullable === true && isAnnotationOnly(member);
|
|
3917
|
+
}
|
|
3862
3918
|
function makeRefTypeString(ref, selfTypeName) {
|
|
3863
3919
|
const propertiesMatch = /^#\/components\/schemas\/([^/]+)\/properties\//u.exec(ref);
|
|
3864
3920
|
if (propertiesMatch) {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { B as isSchemaProperty, D as isParameterObject, K as isValidIdent, N as isRecord, P as isRefObject, Z as FORM_MEDIA_TYPES, rt as JSON_MEDIA_TYPE, w as isOperationLike } from "./guard-ngBos42D.js";
|
|
2
|
+
import { y as toHonoPath } from "./utils-DuQdDbou.js";
|
|
2
3
|
// src/helper/group.ts
|
|
3
4
|
const RESERVED = /* @__PURE__ */ new Set([
|
|
4
5
|
"arguments",
|
|
@@ -141,9 +142,8 @@ function formatPath(p, hasBasePath) {
|
|
|
141
142
|
hasBracket: false
|
|
142
143
|
};
|
|
143
144
|
}
|
|
144
|
-
const
|
|
145
|
-
if (p !== "/" && p.endsWith("/"))
|
|
146
|
-
const honoSegs = segs.map((seg) => seg.replaceAll(/\{([^}]+)\}/gu, ":$1"));
|
|
145
|
+
const honoSegs = toHonoPath(p).replace(/^\/+/u, "").split("/").filter(Boolean);
|
|
146
|
+
if (p !== "/" && p.endsWith("/")) honoSegs.push("index");
|
|
147
147
|
const firstBracketIdx = honoSegs.findIndex((seg) => !isValidIdent(seg));
|
|
148
148
|
const hasBracket = firstBracketIdx !== -1;
|
|
149
149
|
const runtimePath = honoSegs.map((seg) => isValidIdent(seg) ? `.${seg}` : `['${makeEscaped(seg)}']`).join("");
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D8jQpDG7.js";
|
|
2
2
|
import { $ as HOOK_LIBRARIES, J as COMPONENT_NAMES } from "./guard-ngBos42D.js";
|
|
3
|
-
import { C as appEntryOutput, D as makeGeneratedImport, E as makeAppEntryImport, S as pathGroupOf, T as makeAppEntryFile, _ as headers, a as takibi, b as client, c as securitySchemes, d as requestBodies, f as pathItems, g as links, h as mediaTypes, i as defineTemplate, l as schemas, m as components, n as webhooks, o as route, p as parameters, r as template, s as mock, u as responses, v as examples, w as isInsideDirectory, x as handlerGroupOf, y as callbacks } from "./core
|
|
4
|
-
import { t as docs } from "./docs-
|
|
5
|
-
import { t as hooks } from "./hooks-
|
|
3
|
+
import { C as appEntryOutput, D as makeGeneratedImport, E as makeAppEntryImport, S as pathGroupOf, T as makeAppEntryFile, _ as headers, a as takibi, b as client, c as securitySchemes, d as requestBodies, f as pathItems, g as links, h as mediaTypes, i as defineTemplate, l as schemas, m as components, n as webhooks, o as route, p as parameters, r as template, s as mock, u as responses, v as examples, w as isInsideDirectory, x as handlerGroupOf, y as callbacks } from "./core--c3Vfca8.js";
|
|
4
|
+
import { t as docs } from "./docs-Md7vHZib.js";
|
|
5
|
+
import { t as hooks } from "./hooks-BYOaM0T6.js";
|
|
6
6
|
import { rpc } from "./core/rpc/index.js";
|
|
7
7
|
import { type } from "./core/type/index.js";
|
|
8
8
|
import { i as GenerateError } from "./format-BF7SbaMP.js";
|
|
9
9
|
import { a as unlink, i as readdir, t as exists } from "./file-hO_bjDys.js";
|
|
10
|
-
import { n as normalizeOpenAPI } from "./openapi-
|
|
10
|
+
import { n as normalizeOpenAPI } from "./openapi-DAYtJjPV.js";
|
|
11
11
|
import { Effect, FileSystem, Schema } from "effect";
|
|
12
12
|
import path from "node:path";
|
|
13
13
|
import SwaggerParser from "@apidevtools/swagger-parser";
|
|
@@ -7,6 +7,16 @@ function normalizeTypes(type) {
|
|
|
7
7
|
return type === void 0 ? [] : Array.isArray(type) ? type : [type];
|
|
8
8
|
}
|
|
9
9
|
/**
|
|
10
|
+
* The Hono path @hono/zod-openapi registers for an OpenAPI path, and the key its client type
|
|
11
|
+
* is built from. It converts only a `{name}` that opens a segment (`ConvertPathType` at the
|
|
12
|
+
* type level, `replaceAll(/\/{(.+?)}/g, '/:$1')` at runtime), so a parameter inside a segment
|
|
13
|
+
* stays as written: `/api/v{version}/{id}` → `/api/v{version}/:id`, `/{section}.{format}` →
|
|
14
|
+
* `/:section.{format}`.
|
|
15
|
+
*/
|
|
16
|
+
function toHonoPath(openApiPath) {
|
|
17
|
+
return openApiPath.replaceAll(/\/\{([^}]+)\}/gu, "/:$1");
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
10
20
|
* Generates a PascalCase route name from HTTP method and path.
|
|
11
21
|
*
|
|
12
22
|
*
|
|
@@ -511,4 +521,4 @@ function cyclicNodes(deps) {
|
|
|
511
521
|
for (const node of deps.keys()) if (!indices.has(node)) connect(node);
|
|
512
522
|
return result;
|
|
513
523
|
}
|
|
514
|
-
export { routeName as _, ensureSuffix as a,
|
|
524
|
+
export { zodToOpenAPISchema as S, routeName as _, ensureSuffix as a, toIdentifierPascalCase as b, escapeRegexLiteral as c, makeSafeKey as d, makeStringLiteral as f, requestParamsArray as g, renderNamedImport as h, decodePercent as i, makeBarrel as l, regexLiteral as m, capitalize as n, error as o, normalizeTypes as p, cyclicNodes as r, escapeHtml as s, baseError as t, makeInferRequestType as u, statusCodeToNumber as v, uncapitalize as x, toHonoPath as y };
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { parseConfig } from "../index.js";
|
|
2
2
|
import { N as isRecord, nt as INPUT_EXTENSIONS } from "../guard-ngBos42D.js";
|
|
3
3
|
import { t as FormatOptions } from "../format-BF7SbaMP.js";
|
|
4
|
-
import { C as appEntryOutput, w as isInsideDirectory } from "../core
|
|
4
|
+
import { C as appEntryOutput, w as isInsideDirectory } from "../core--c3Vfca8.js";
|
|
5
5
|
import { n as parseOpenAPI } from "../openapi-BxSVfs_l.js";
|
|
6
|
-
import { a as packageRoots, i as outsideSources, n as makeJob, r as openAPI3, t as cleanSplitOutputs } from "../shared-
|
|
6
|
+
import { a as packageRoots, i as outsideSources, n as makeJob, r as openAPI3, t as cleanSplitOutputs } from "../shared-CDr0M6z-.js";
|
|
7
7
|
import { Effect, FileSystem, Option, Result } from "effect";
|
|
8
8
|
import path from "node:path";
|
|
9
9
|
import crypto from "node:crypto";
|