hono-takibi 0.20.0 → 0.21.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cli.js +4 -4
- package/dist/core/docs/index.js +1 -1
- package/dist/core/hooks/index.d.ts +2 -2
- package/dist/core/hooks/index.js +1 -1
- package/dist/core/rpc/index.d.ts +1 -1
- package/dist/core/rpc/index.js +2 -2
- package/dist/{core-D-vKEwJs.js → core-BDhKAR3A.js} +58 -213
- package/dist/{docs-NIDBdFyt.js → docs-Im22cNpx.js} +28 -28
- package/dist/generator/zod-openapi-hono/openapi/index.js +1 -1
- package/dist/{hooks-GhEZu5l6.js → hooks-CR7angVC.js} +43 -31
- package/dist/{index-CMoB1dLg.d.ts → index-3BQ2KpP9.d.ts} +1 -1
- package/dist/{index-B7AwLlPY.d.ts → index-DhipYt_q.d.ts} +4 -0
- package/dist/index.d.ts +1 -1
- package/dist/index.js +26 -9
- package/dist/{openapi-C2BSoZRM.js → openapi-BRK0691x.js} +186 -250
- package/dist/{rpc-D_ka_cCX.js → rpc-Bgtv3nGI.js} +2 -2
- package/dist/{shared-_h_FDhSi.js → shared-COpMVRhG.js} +21 -10
- package/dist/vite-plugin/index.js +2 -2
- package/package.json +1 -1
package/dist/cli.js
CHANGED
|
@@ -4,7 +4,7 @@ import { NodeRuntime, NodeServices } from "@effect/platform-node";
|
|
|
4
4
|
import { Console, Effect, FileSystem, Option, Path, Ref, Schema, Stream } from "effect";
|
|
5
5
|
import { Argument, CliError, Command, Flag } from "effect/cli";
|
|
6
6
|
//#region package.json
|
|
7
|
-
var version = "0.
|
|
7
|
+
var version = "0.21.0";
|
|
8
8
|
var description = "Hono Takibi is a code generator from OpenAPI to @hono/zod-openapi";
|
|
9
9
|
//#endregion
|
|
10
10
|
//#region src/cli/index.ts
|
|
@@ -41,7 +41,7 @@ function runJobs(config) {
|
|
|
41
41
|
const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob, packageRoots }] = yield* Effect.promise(() => Promise.all([
|
|
42
42
|
import("./openapi-DQRxq2_O.js").then((n) => n.t),
|
|
43
43
|
import("./format-CuHABcKC.js").then((n) => n.r),
|
|
44
|
-
import("./shared-
|
|
44
|
+
import("./shared-COpMVRhG.js").then((n) => n.a)
|
|
45
45
|
]));
|
|
46
46
|
const openAPI = yield* parseOpenAPI(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-COpMVRhG.js").then((n) => n.a));
|
|
83
83
|
const inputDirectory = path.dirname(path.resolve(config.input));
|
|
84
84
|
return {
|
|
85
85
|
inputDirectory,
|
|
@@ -206,7 +206,7 @@ function generate(args) {
|
|
|
206
206
|
})]
|
|
207
207
|
});
|
|
208
208
|
if (input !== void 0 && output !== void 0) {
|
|
209
|
-
const [{ parseOpenAPI }, { takibi }] = yield* Effect.promise(() => Promise.all([import("./openapi-DQRxq2_O.js").then((n) => n.t), import("./core-
|
|
209
|
+
const [{ parseOpenAPI }, { takibi }] = yield* Effect.promise(() => Promise.all([import("./openapi-DQRxq2_O.js").then((n) => n.t), import("./core-BDhKAR3A.js").then((n) => n.t)]));
|
|
210
210
|
return yield* Console.log(yield* takibi(yield* parseOpenAPI(input), output));
|
|
211
211
|
}
|
|
212
212
|
const resolvedConfig = configPath ?? DEFAULT_CONFIG_FILE;
|
package/dist/core/docs/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as docs } from "../../docs-
|
|
1
|
+
import { t as docs } from "../../docs-Im22cNpx.js";
|
|
2
2
|
export { docs };
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as OpenAPI } from "../../index-tsPqeV6H.js";
|
|
2
2
|
import { n as GenerateError, t as FormatError } from "../../index-D_gf3Xzx.js";
|
|
3
|
-
import { t as Grouping } from "../../index-
|
|
3
|
+
import { t as Grouping } from "../../index-3BQ2KpP9.js";
|
|
4
4
|
//#region src/core/hooks/index.d.ts
|
|
5
5
|
declare const HOOK_CONFIGS: {
|
|
6
6
|
readonly swr: {
|
|
@@ -166,5 +166,5 @@ export declare function hooks(openAPI: OpenAPI, output: string, importPath: stri
|
|
|
166
166
|
readonly clientName?: string;
|
|
167
167
|
readonly grouping?: Grouping;
|
|
168
168
|
readonly basePath?: string;
|
|
169
|
-
}): import("effect/Effect").Effect
|
|
169
|
+
}): import("effect/Effect").Effect<`Generated ${string} hooks written to ${string}`, FormatError | GenerateError | import("effect/PlatformError").PlatformError, import("effect/FileSystem").FileSystem>;
|
|
170
170
|
//#endregion
|
package/dist/core/hooks/index.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as hooks } from "../../hooks-
|
|
1
|
+
import { t as hooks } from "../../hooks-CR7angVC.js";
|
|
2
2
|
export { hooks };
|
package/dist/core/rpc/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as OpenAPI } from "../../index-tsPqeV6H.js";
|
|
2
2
|
import { n as GenerateError, t as FormatError } from "../../index-D_gf3Xzx.js";
|
|
3
|
-
import { t as Grouping } from "../../index-
|
|
3
|
+
import { t as Grouping } from "../../index-3BQ2KpP9.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
//#region src/core/rpc/index.d.ts
|
|
6
6
|
/**
|
package/dist/core/rpc/index.js
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import { s as HTTP_METHODS } from "../../constants-Bz8YiPum.js";
|
|
2
2
|
import { i as GenerateError } from "../../format-CuHABcKC.js";
|
|
3
3
|
import { L as isOpenAPIPaths, f as methodPath, l as makeInferRequestType, q as isRecord, z as isOperationLike } from "../../utils-vw99OasL.js";
|
|
4
|
+
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "../../rpc-Bgtv3nGI.js";
|
|
4
5
|
import { t as emit } from "../../emit-uwlZZeRM.js";
|
|
5
|
-
import { i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, s as groupClientName, t as formatPath } from "../../rpc-D_ka_cCX.js";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
import { dirname } from "node:path";
|
|
8
8
|
//#region src/core/rpc/index.ts
|
|
@@ -27,7 +27,7 @@ function makeOperationCode(path, method, item, base, useParseResponse, hasBasePa
|
|
|
27
27
|
const group = grouping?.(path, operationTags(operation));
|
|
28
28
|
const deps = group === void 0 ? base : {
|
|
29
29
|
...base,
|
|
30
|
-
client:
|
|
30
|
+
client: makeGroupClientName(group)
|
|
31
31
|
};
|
|
32
32
|
const funcName = methodPath(method, path);
|
|
33
33
|
const pathResult = formatPath(path, hasBasePath);
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
2
|
import { n as COMPONENT_NAMES, p as TEXT_MEDIA_TYPE, r as COMPONENT_REF_PREFIX, s as HTTP_METHODS, u as JSON_MEDIA_TYPE } from "./constants-Bz8YiPum.js";
|
|
3
3
|
import { i as GenerateError, n as fmt } from "./format-CuHABcKC.js";
|
|
4
|
-
import { $ as isSchemaObject, B as isParameter, D as isCallbacks, F as isMediaWithSchema, G as isPathItemEntry, J as isRefObject, K as isPathItemRef, L as isOpenAPIPaths, N as isInlineMedia, Q as isSchemaArray, R as isOperation, T as hasRequestBodyContent,
|
|
5
|
-
import { C as
|
|
4
|
+
import { $ as isSchemaObject, B as isParameter, D as isCallbacks, F as isMediaWithSchema, G as isPathItemEntry, J as isRefObject, K as isPathItemRef, L as isOpenAPIPaths, N as isInlineMedia, Q as isSchemaArray, R as isOperation, T as hasRequestBodyContent, W as isPathItem, _ as toIdentifierPascalCase, at as isValidIdent, b as zodToOpenAPISchema, c as makeBarrel, d as makeStringLiteral, f as methodPath, g as statusCodeToNumber, i as ensureSuffix, j as isHttpMethod, m as renderNamedImport, nt as isSecurityScheme, p as normalizeTypes, r as cyclicNodes, s as escapeRegexLiteral, tt as isSecurityArray, u as makeSafeKey, v as uncapitalize, w as hasNumericConstraint, y as uncapitalizeWord } from "./utils-vw99OasL.js";
|
|
5
|
+
import { C as resolveParameter, S as makeWebhookEntries, _ as makeCallback, a as responsesCode, b as makeRouteEntries, c as headersCode, d as makeExportConst, f as makeImports, g as zodToOpenAPI, h as ast, i as schemasCode, l as makeSplitSchemaFile, m as analyzeCircularSchemas, n as routeCode, o as requestBodiesCode, p as makeModuleSpec, r as componentsCode, s as parametersCode, t as zodOpenAPIHono, u as makeConst, v as makePathItem, w as resolvePathItem, x as makeRouteProperties, y as makeRef } from "./openapi-BRK0691x.js";
|
|
6
|
+
import { a as entryNames, c as makeGroupClientName, l as operationTags, o as freeName, s as groupNameOf } from "./rpc-Bgtv3nGI.js";
|
|
6
7
|
import { i as readdir, n as mkdir, o as writeFile, r as readFile } from "./file-K6j5IJXi.js";
|
|
7
8
|
import { t as emit } from "./emit-uwlZZeRM.js";
|
|
8
|
-
import {
|
|
9
|
-
import { t as
|
|
10
|
-
import { t as docs } from "./docs-NIDBdFyt.js";
|
|
9
|
+
import { t as hooks } from "./hooks-CR7angVC.js";
|
|
10
|
+
import { t as docs } from "./docs-Im22cNpx.js";
|
|
11
11
|
import { rpc } from "./core/rpc/index.js";
|
|
12
12
|
import { type } from "./core/type/index.js";
|
|
13
13
|
import { Effect } from "effect";
|
|
@@ -202,7 +202,7 @@ function fakerPattern(pattern) {
|
|
|
202
202
|
return ".+*?()$|{}".includes(escaped) ? `[${escaped}]` : match;
|
|
203
203
|
});
|
|
204
204
|
}
|
|
205
|
-
function
|
|
205
|
+
function makeBoundedPattern(pattern, minLength, maxLength) {
|
|
206
206
|
if (minLength === void 0 && maxLength === void 0) return pattern;
|
|
207
207
|
const repeated = /^((?:\[(?:\\.|[^\]\\])+\]|\\[dws]|\.))([+*])$/u.exec(pattern);
|
|
208
208
|
if (!repeated) return pattern;
|
|
@@ -261,7 +261,7 @@ const BOUNDED_FORMATS = {
|
|
|
261
261
|
tail: ".io"
|
|
262
262
|
}]
|
|
263
263
|
};
|
|
264
|
-
function
|
|
264
|
+
function makeBoundedFormat(schema) {
|
|
265
265
|
const { format, minLength, maxLength } = schema;
|
|
266
266
|
if (format === void 0 || minLength === void 0 && maxLength === void 0) return;
|
|
267
267
|
if (format === "password") {
|
|
@@ -282,7 +282,7 @@ function schemaExample(schema) {
|
|
|
282
282
|
if (schema.example !== void 0) return schema.example;
|
|
283
283
|
return Array.isArray(schema.examples) ? schema.examples[0] : void 0;
|
|
284
284
|
}
|
|
285
|
-
function
|
|
285
|
+
function makeExampleLiteral(schema) {
|
|
286
286
|
const example = schemaExample(schema);
|
|
287
287
|
if (example === void 0) return void 0;
|
|
288
288
|
const types = normalizeTypes(schema.type);
|
|
@@ -402,7 +402,7 @@ function hashFaker(schema) {
|
|
|
402
402
|
function lookupBytes(alg) {
|
|
403
403
|
return alg !== void 0 && Object.hasOwn(HASH_BYTES, alg) ? HASH_BYTES[alg] : void 0;
|
|
404
404
|
}
|
|
405
|
-
function
|
|
405
|
+
function makeVendorFormat(schema) {
|
|
406
406
|
const hash = hashFaker(schema);
|
|
407
407
|
if (hash !== void 0) return hash;
|
|
408
408
|
const { format } = schema;
|
|
@@ -415,7 +415,7 @@ function vendorFormat(schema) {
|
|
|
415
415
|
if (protocol !== void 0 && (format === "uri" || format === "url")) return `faker.internet.url({ protocol: '${protocol}' })`;
|
|
416
416
|
if (format === "date-time" && schema["x-isoLocal"] === true) return "faker.date.past().toISOString().slice(0, 19)";
|
|
417
417
|
}
|
|
418
|
-
function
|
|
418
|
+
function makeAffixedValue(schema, value) {
|
|
419
419
|
const parts = [
|
|
420
420
|
...schema["x-startsWith"] === void 0 ? [] : [makeStringLiteral(schema["x-startsWith"])],
|
|
421
421
|
value,
|
|
@@ -465,12 +465,12 @@ function conditionalRequired(schema) {
|
|
|
465
465
|
}
|
|
466
466
|
function schemaToFaker(schema, propertyName, options = {}) {
|
|
467
467
|
const value = schemaValue(schema, propertyName, options);
|
|
468
|
-
return schema.type === "string" && schema.const === void 0 && schema.enum === void 0 && !value.startsWith("\"") ?
|
|
468
|
+
return schema.type === "string" && schema.const === void 0 && schema.enum === void 0 && !value.startsWith("\"") ? makeAffixedValue(schema, value) : value;
|
|
469
469
|
}
|
|
470
470
|
function schemaValue(schema, propertyName, options = {}) {
|
|
471
471
|
if (schema.const !== void 0) return `${JSON.stringify(schema.const)} as const`;
|
|
472
472
|
if (options.useExamples) {
|
|
473
|
-
const example =
|
|
473
|
+
const example = makeExampleLiteral(schema);
|
|
474
474
|
if (example !== void 0) return example;
|
|
475
475
|
}
|
|
476
476
|
if (schema.enum && schema.enum.length > 0) return `faker.helpers.arrayElement([${schema.enum.map((v) => JSON.stringify(v)).join(", ")}] as const)`;
|
|
@@ -566,7 +566,7 @@ function schemaValue(schema, propertyName, options = {}) {
|
|
|
566
566
|
const type = typeof schema.type === "string" ? schema.type : void 0;
|
|
567
567
|
if ((type === "integer" || type === "number") && hasNumericConstraint(schema)) return numericFaker(schema, numericRange(schema, type === "integer"));
|
|
568
568
|
if (type === "string" && schema.contentEncoding === "base64") return schema.contentSchema ? `(btoa(JSON.stringify(${schemaToFaker(schema.contentSchema, void 0, options)})) as any)` : "btoa(faker.string.alphanumeric(12))";
|
|
569
|
-
const formatHint = (type === "string" || type === void 0 ?
|
|
569
|
+
const formatHint = (type === "string" || type === void 0 ? makeVendorFormat(schema) ?? makeBoundedFormat(schema) : void 0) ?? (schema.format ? lookup(FORMAT_TO_FAKER, schema.format) : void 0);
|
|
570
570
|
if (formatHint && isHintCompatible(type, formatHint)) return formatHint;
|
|
571
571
|
const nameHint = propertyName ? propertyNameHint(propertyName) : void 0;
|
|
572
572
|
if (nameHint && isHintCompatible(type, nameHint)) {
|
|
@@ -575,7 +575,7 @@ function schemaValue(schema, propertyName, options = {}) {
|
|
|
575
575
|
}
|
|
576
576
|
if (type === "string") {
|
|
577
577
|
if (schema.pattern) {
|
|
578
|
-
const pattern =
|
|
578
|
+
const pattern = makeBoundedPattern(fakerPattern(schema.pattern), schema.minLength, schema.maxLength);
|
|
579
579
|
return `faker.helpers.fromRegExp(${makeStringLiteral(pattern)})`;
|
|
580
580
|
}
|
|
581
581
|
const min = schema.minLength ?? Math.min(5, schema.maxLength ?? 5);
|
|
@@ -616,67 +616,28 @@ function getNonExistentValue(schema, schemas) {
|
|
|
616
616
|
* "register in the OpenAPI document" behavior made explicit.
|
|
617
617
|
*/
|
|
618
618
|
function defineEntries(openapi, readonly) {
|
|
619
|
-
const
|
|
620
|
-
|
|
621
|
-
`method:${JSON.stringify(method)}`,
|
|
622
|
-
`path:${JSON.stringify(path)}`,
|
|
623
|
-
operation.tags ? `tags:${JSON.stringify(operation.tags)}` : void 0,
|
|
624
|
-
operation.summary ? `summary:${JSON.stringify(operation.summary)}` : void 0,
|
|
625
|
-
operation.description ? `description:${JSON.stringify(operation.description)}` : void 0,
|
|
626
|
-
operation.externalDocs ? `externalDocs:${JSON.stringify(operation.externalDocs)}` : void 0,
|
|
627
|
-
operation.operationId ? `operationId:${JSON.stringify(operation.operationId)}` : void 0,
|
|
628
|
-
makeRequest(operation.parameters, operation.requestBody, readonly, openapi.components?.schemas) ? `request:${makeRequest(operation.parameters, operation.requestBody, readonly, openapi.components?.schemas)}` : void 0,
|
|
629
|
-
operation.responses ? `responses:${makeOperationResponses(operation.responses, readonly)}` : void 0,
|
|
630
|
-
operation.callbacks ? `callbacks:{${makeCallbacks(operation.callbacks, readonly)}}` : void 0,
|
|
631
|
-
operation.deprecated ? `deprecated:${JSON.stringify(operation.deprecated)}` : void 0,
|
|
632
|
-
operation.security ? `security:${JSON.stringify(operation.security)}` : void 0,
|
|
633
|
-
operation.servers ? `servers:${JSON.stringify(operation.servers)}` : void 0
|
|
634
|
-
].filter((v) => v !== void 0).join(",");
|
|
635
|
-
const asConst = readonly ? " as const" : "";
|
|
636
|
-
const entryName = methodPath(method, path);
|
|
637
|
-
return {
|
|
638
|
-
name: entryName,
|
|
639
|
-
path,
|
|
640
|
-
...operation.tags ? { tags: operation.tags } : {},
|
|
641
|
-
code: `export const ${entryName}Route=defineOpenAPIRoute({route:createRoute({${properties}}${asConst}),handler:async(c)=>{},addRoute:true})`
|
|
642
|
-
};
|
|
643
|
-
};
|
|
644
|
-
const resolveParameter = (parameter) => {
|
|
645
|
-
if ("name" in parameter && "in" in parameter) return parameter;
|
|
646
|
-
const ref = "$ref" in parameter ? parameter.$ref : void 0;
|
|
647
|
-
if (!ref || !isParameterRef(ref)) return void 0;
|
|
648
|
-
const resolved = openapi.components?.parameters?.[ref.slice(ref.lastIndexOf("/") + 1)];
|
|
649
|
-
if (!resolved) return void 0;
|
|
650
|
-
return {
|
|
651
|
-
...resolved,
|
|
652
|
-
$ref: ref
|
|
653
|
-
};
|
|
654
|
-
};
|
|
655
|
-
const resolvePathItem = (pathItem) => {
|
|
656
|
-
if (pathItem.$ref && isPathItemRef(pathItem.$ref)) {
|
|
657
|
-
const name = pathItem.$ref.slice(pathItem.$ref.lastIndexOf("/") + 1);
|
|
658
|
-
const resolved = openapi.components?.pathItems?.[name];
|
|
659
|
-
if (resolved) {
|
|
660
|
-
const { $ref: _, ...siblings } = pathItem;
|
|
661
|
-
return {
|
|
662
|
-
...resolved,
|
|
663
|
-
...siblings
|
|
664
|
-
};
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
return pathItem;
|
|
668
|
-
};
|
|
619
|
+
const resolve = resolveParameter(openapi);
|
|
620
|
+
const resolveItem = resolvePathItem(openapi);
|
|
669
621
|
return Object.entries(openapi.paths).flatMap(([path, pathItem]) => {
|
|
670
622
|
if (!isPathItemEntry(pathItem)) return [];
|
|
671
|
-
const resolved =
|
|
623
|
+
const resolved = resolveItem(pathItem);
|
|
672
624
|
return HTTP_METHODS.flatMap((method) => {
|
|
673
625
|
const operation = resolved[method];
|
|
674
626
|
if (!operation?.responses) return [];
|
|
675
|
-
const parameters = [...resolved.parameters ?? [], ...operation.parameters ?? []].map(
|
|
676
|
-
|
|
627
|
+
const parameters = [...resolved.parameters ?? [], ...operation.parameters ?? []].map(resolve).filter((p) => p !== void 0);
|
|
628
|
+
const effective = parameters.length > 0 ? {
|
|
677
629
|
...operation,
|
|
678
630
|
parameters
|
|
679
|
-
} : operation
|
|
631
|
+
} : operation;
|
|
632
|
+
const properties = makeRouteProperties(path, method, effective, readonly, openapi.components?.schemas);
|
|
633
|
+
const asConst = readonly ? " as const" : "";
|
|
634
|
+
const entryName = methodPath(method, path);
|
|
635
|
+
return [{
|
|
636
|
+
name: entryName,
|
|
637
|
+
path,
|
|
638
|
+
...effective.tags ? { tags: effective.tags } : {},
|
|
639
|
+
code: `export const ${entryName}Route=defineOpenAPIRoute({route:createRoute({${properties}}${asConst}),handler:async(c)=>{},addRoute:true})`
|
|
640
|
+
}];
|
|
680
641
|
});
|
|
681
642
|
});
|
|
682
643
|
}
|
|
@@ -1254,7 +1215,7 @@ function appEntryDirectory(appOutput, define) {
|
|
|
1254
1215
|
return define || !appOutput.endsWith("/index.ts") ? path.dirname(appOutput) : path.dirname(path.dirname(appOutput));
|
|
1255
1216
|
}
|
|
1256
1217
|
/** The file the app entry is, whichever output the config names. */
|
|
1257
|
-
function
|
|
1218
|
+
function makeAppEntryFile(appOutput, define) {
|
|
1258
1219
|
return path.join(appEntryDirectory(appOutput, define), "index.ts");
|
|
1259
1220
|
}
|
|
1260
1221
|
function relativeSpecifier(from, to) {
|
|
@@ -1266,7 +1227,7 @@ function relativeSpecifier(from, to) {
|
|
|
1266
1227
|
* the path alias, which stands for the directory the app entry is in. An alias that names a
|
|
1267
1228
|
* directory, `@/api`, is the entry as it stands; one that names a root, `@/`, takes `index`.
|
|
1268
1229
|
*/
|
|
1269
|
-
function
|
|
1230
|
+
function makeAppEntryImport(from, appOutput, pathAlias, define) {
|
|
1270
1231
|
if (pathAlias !== void 0) {
|
|
1271
1232
|
const prefix = pathAlias.endsWith("/") ? pathAlias.slice(0, -1) : pathAlias;
|
|
1272
1233
|
return prefix.includes("/") ? prefix : `${prefix}/index`;
|
|
@@ -1277,7 +1238,7 @@ function appEntryImport(from, appOutput, pathAlias, define) {
|
|
|
1277
1238
|
* The module specifier a generated file is imported by from `from`: under the path alias
|
|
1278
1239
|
* when the file is in the directory the alias stands for, and relative to `from` otherwise.
|
|
1279
1240
|
*/
|
|
1280
|
-
function
|
|
1241
|
+
function makeGeneratedImport(from, file, appOutput, pathAlias, define) {
|
|
1281
1242
|
const target = file.replace(/(?:\/index)?\.ts$/u, "");
|
|
1282
1243
|
if (pathAlias !== void 0 && appOutput !== void 0) {
|
|
1283
1244
|
const inside = path.relative(appEntryDirectory(appOutput, define), target).split(path.sep).join("/");
|
|
@@ -1370,9 +1331,7 @@ function makeOrphanHandlers(existing, assignedFileNames) {
|
|
|
1370
1331
|
return [...new Set(existing.locations.values())].filter((fileName) => !assignedFileNames.includes(fileName)).map((fileName) => ({
|
|
1371
1332
|
fileName,
|
|
1372
1333
|
contents: [],
|
|
1373
|
-
routeNames: []
|
|
1374
|
-
needsFaker: false,
|
|
1375
|
-
usedRefs: /* @__PURE__ */ new Set()
|
|
1334
|
+
routeNames: []
|
|
1376
1335
|
}));
|
|
1377
1336
|
}
|
|
1378
1337
|
function makePaths(output, pathAlias, routeImport) {
|
|
@@ -1386,30 +1345,24 @@ function makePaths(output, pathAlias, routeImport) {
|
|
|
1386
1345
|
importFrom: routeImport ?? (aliasPrefix ? `${aliasPrefix}/${routeModuleName}` : `../${routeModuleName}`)
|
|
1387
1346
|
};
|
|
1388
1347
|
}
|
|
1389
|
-
function
|
|
1348
|
+
function makeHandlerInfo(path, method, operation, existing, member, body) {
|
|
1390
1349
|
const routeId = methodPath(method, path);
|
|
1391
1350
|
return {
|
|
1392
|
-
fileName: resolveHandlerFileName(makeHandlerFileName(path, operation.tags), `${routeId}
|
|
1393
|
-
contents: [
|
|
1394
|
-
routeNames: [`${routeId}Route`]
|
|
1395
|
-
needsFaker: false,
|
|
1396
|
-
usedRefs: /* @__PURE__ */ new Set()
|
|
1351
|
+
fileName: resolveHandlerFileName(makeHandlerFileName(path, operation.tags), `${routeId}${member}`, existing),
|
|
1352
|
+
contents: [body(routeId)],
|
|
1353
|
+
routeNames: [`${routeId}Route`]
|
|
1397
1354
|
};
|
|
1398
1355
|
}
|
|
1356
|
+
function makeInlineStubHandlerInfo(path, method, operation, existing) {
|
|
1357
|
+
return makeHandlerInfo(path, method, operation, existing, "Route", (routeId) => `.openapi(${routeId}Route,(c)=>{})`);
|
|
1358
|
+
}
|
|
1399
1359
|
function makeInlineStubFileContent(handler, importFrom) {
|
|
1400
1360
|
const exportName = `${basename(handler.fileName, ".ts")}Handler`;
|
|
1401
1361
|
const routeImports = [...new Set(handler.routeNames)].join(", ");
|
|
1402
1362
|
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")}`;
|
|
1403
1363
|
}
|
|
1404
1364
|
function makeStubHandlerInfo(path, method, operation, existing) {
|
|
1405
|
-
|
|
1406
|
-
return {
|
|
1407
|
-
fileName: resolveHandlerFileName(makeHandlerFileName(path, operation.tags), `${routeId}RouteHandler`, existing),
|
|
1408
|
-
contents: [`export const ${routeId}RouteHandler:RouteHandler<typeof ${routeId}Route>=async(c)=>{}`],
|
|
1409
|
-
routeNames: [`${routeId}Route`],
|
|
1410
|
-
needsFaker: false,
|
|
1411
|
-
usedRefs: /* @__PURE__ */ new Set()
|
|
1412
|
-
};
|
|
1365
|
+
return makeHandlerInfo(path, method, operation, existing, "RouteHandler", (routeId) => `export const ${routeId}RouteHandler:RouteHandler<typeof ${routeId}Route>=async(c)=>{}`);
|
|
1413
1366
|
}
|
|
1414
1367
|
function makeMergedHandlers(handlers) {
|
|
1415
1368
|
const handlerMap = /* @__PURE__ */ new Map();
|
|
@@ -1418,9 +1371,7 @@ function makeMergedHandlers(handlers) {
|
|
|
1418
1371
|
if (existing) handlerMap.set(handler.fileName, {
|
|
1419
1372
|
...handler,
|
|
1420
1373
|
contents: [...existing.contents, ...handler.contents],
|
|
1421
|
-
routeNames: [.../* @__PURE__ */ new Set([...existing.routeNames, ...handler.routeNames])]
|
|
1422
|
-
needsFaker: existing.needsFaker || handler.needsFaker,
|
|
1423
|
-
usedRefs: /* @__PURE__ */ new Set([...existing.usedRefs, ...handler.usedRefs])
|
|
1374
|
+
routeNames: [.../* @__PURE__ */ new Set([...existing.routeNames, ...handler.routeNames])]
|
|
1424
1375
|
});
|
|
1425
1376
|
else handlerMap.set(handler.fileName, handler);
|
|
1426
1377
|
}
|
|
@@ -1562,18 +1513,21 @@ function makeBaseUrl(baseUrl) {
|
|
|
1562
1513
|
url: "baseUrl"
|
|
1563
1514
|
};
|
|
1564
1515
|
}
|
|
1516
|
+
function makeOptions(credentials) {
|
|
1517
|
+
return credentials === void 0 ? "" : `,{init:{credentials:${JSON.stringify(credentials)}}}`;
|
|
1518
|
+
}
|
|
1565
1519
|
/**
|
|
1566
1520
|
* The typed client, as the `hcWithType` of the Hono guide: the type of the client is
|
|
1567
1521
|
* declared once, so that it is worked out when this file is compiled and not again by every
|
|
1568
1522
|
* file that calls `hc`.
|
|
1569
1523
|
*/
|
|
1570
|
-
function makeClient(name, app, url, access = "", imported = app, whole = false) {
|
|
1524
|
+
function makeClient(name, app, url, access = "", imported = app, whole = false, options = "") {
|
|
1571
1525
|
const typeName = capitalizeFirst(name);
|
|
1572
1526
|
const factory = whole ? "hcWithType" : `hc${capitalizeFirst(app)}WithType`;
|
|
1573
1527
|
return [
|
|
1574
1528
|
`type ${typeName}=ReturnType<typeof hc<typeof ${imported}>>`,
|
|
1575
1529
|
`const ${factory}=(...args:Parameters<typeof hc>):${typeName}=>hc<typeof ${imported}>(...args)`,
|
|
1576
|
-
`export const ${name}=${factory}(${url})${access}`
|
|
1530
|
+
`export const ${name}=${factory}(${url}${options})${access}`
|
|
1577
1531
|
].join("\n\n");
|
|
1578
1532
|
}
|
|
1579
1533
|
function ownNames(apps, environment, whole) {
|
|
@@ -1585,8 +1539,8 @@ function ownNames(apps, environment, whole) {
|
|
|
1585
1539
|
"Client",
|
|
1586
1540
|
"hcWithType"
|
|
1587
1541
|
] : [
|
|
1588
|
-
|
|
1589
|
-
capitalizeFirst(
|
|
1542
|
+
makeGroupClientName(app),
|
|
1543
|
+
capitalizeFirst(makeGroupClientName(app)),
|
|
1590
1544
|
`hc${capitalizeFirst(app)}WithType`
|
|
1591
1545
|
])
|
|
1592
1546
|
];
|
|
@@ -1598,13 +1552,14 @@ function importedName(app, apps, own) {
|
|
|
1598
1552
|
* Generates the file of typed clients: `client` for the application, or one client for
|
|
1599
1553
|
* each group of a split application, `booksClient` for `books` and `__rootClient` for `__root`.
|
|
1600
1554
|
*/
|
|
1601
|
-
function client(openAPI, output, importPath, baseUrl, basePath, grouping, barrel) {
|
|
1555
|
+
function client(openAPI, output, importPath, baseUrl, basePath, grouping, barrel, credentials) {
|
|
1602
1556
|
return Effect.gen(function* () {
|
|
1603
1557
|
const paths = openAPI.paths;
|
|
1604
1558
|
if (!isOpenAPIPaths(paths)) return yield* new GenerateError({ message: "Invalid OpenAPI paths" });
|
|
1605
1559
|
const whole = grouping === void 0;
|
|
1606
1560
|
const apps = whole ? ["api"] : [...new Set(Object.entries(paths).flatMap(([route, pathItem]) => Object.entries(pathItem).flatMap(([method, operation]) => isHttpMethod(method) && isOperation(operation) ? [grouping(route, operationTags(operation))] : [])))];
|
|
1607
1561
|
const { imports: environment, declaration, url } = makeBaseUrl(baseUrl);
|
|
1562
|
+
const options = makeOptions(credentials);
|
|
1608
1563
|
const own = ownNames(apps, typeof baseUrl === "string" ? [] : "import" in baseUrl ? [baseUrl.name] : ["baseUrl"], whole);
|
|
1609
1564
|
const imports = [
|
|
1610
1565
|
"import{hc}from'hono/client'",
|
|
@@ -1615,7 +1570,7 @@ function client(openAPI, output, importPath, baseUrl, basePath, grouping, barrel
|
|
|
1615
1570
|
...environment
|
|
1616
1571
|
].join("\n");
|
|
1617
1572
|
const access = makeBasePathAccess(basePath);
|
|
1618
|
-
const code = `${imports}\n\n${[...declaration, ...apps.map((name) => makeClient(whole ? "client" :
|
|
1573
|
+
const code = `${imports}\n\n${[...declaration, ...apps.map((name) => makeClient(whole ? "client" : makeGroupClientName(name), name, url, access, importedName(name, apps, own), whole, options))].join("\n\n")}\n`;
|
|
1619
1574
|
yield* emit(code, path.dirname(output), output);
|
|
1620
1575
|
if (barrel !== void 0) {
|
|
1621
1576
|
const line = `export * from './${path.basename(output, ".ts")}'`;
|
|
@@ -2324,7 +2279,7 @@ function preferProblem(detail: string): never {
|
|
|
2324
2279
|
)
|
|
2325
2280
|
}`;
|
|
2326
2281
|
const SEED_REF_DATE = "2025-01-01T00:00:00.000Z";
|
|
2327
|
-
function
|
|
2282
|
+
function makeDelayMiddlewareCode(delay) {
|
|
2328
2283
|
const ms = typeof delay === "number" ? `${delay}` : typeof delay === "object" && delay !== null ? `faker.number.int({ min: ${delay.min}, max: ${delay.max} })` : void 0;
|
|
2329
2284
|
if (ms === void 0) return "";
|
|
2330
2285
|
return `\n\napp.use(async (_c, next) => {\n await new Promise((resolve) => setTimeout(resolve, ${ms}))\n await next()\n})`;
|
|
@@ -2461,7 +2416,7 @@ function makeMock(openapi, basePath, options = {}) {
|
|
|
2461
2416
|
const usesPrefer = handlers.length > 0;
|
|
2462
2417
|
const imports = `import { OpenAPIHono, createRoute, z, type RouteHandler } from '@hono/zod-openapi'
|
|
2463
2418
|
${fakerImport}${needsCookieImport ? `\nimport { getCookie } from 'hono/cookie'` : ""}${usesPrefer ? `\nimport { HTTPException } from 'hono/http-exception'\nimport type { ContentfulStatusCode } from 'hono/utils/http-status'` : ""}`;
|
|
2464
|
-
const delayMiddleware =
|
|
2419
|
+
const delayMiddleware = makeDelayMiddlewareCode(delay);
|
|
2465
2420
|
const appCode = `const app = new OpenAPIHono()${basePath !== "/" ? `.basePath('${basePath}')` : ""}${delayMiddleware}
|
|
2466
2421
|
|
|
2467
2422
|
export const api = app${appSetup}
|
|
@@ -2493,68 +2448,7 @@ function route(openAPI, routes, components, readonly) {
|
|
|
2493
2448
|
return Effect.gen(function* () {
|
|
2494
2449
|
if (!routes?.output) return yield* new GenerateError({ message: "routes.output is required" });
|
|
2495
2450
|
const { output, split = false } = routes;
|
|
2496
|
-
const
|
|
2497
|
-
warnUnroutablePath(path);
|
|
2498
|
-
const properties = [
|
|
2499
|
-
`method:${JSON.stringify(method)}`,
|
|
2500
|
-
`path:${JSON.stringify(path)}`,
|
|
2501
|
-
operation.tags ? `tags:${JSON.stringify(operation.tags)}` : void 0,
|
|
2502
|
-
operation.summary ? `summary:${JSON.stringify(operation.summary)}` : void 0,
|
|
2503
|
-
operation.description ? `description:${JSON.stringify(operation.description)}` : void 0,
|
|
2504
|
-
operation.externalDocs ? `externalDocs:${JSON.stringify(operation.externalDocs)}` : void 0,
|
|
2505
|
-
operation.operationId ? `operationId:${JSON.stringify(operation.operationId)}` : void 0,
|
|
2506
|
-
makeRequest(operation.parameters, operation.requestBody, readonly, openAPI.components?.schemas) ? `request:${makeRequest(operation.parameters, operation.requestBody, readonly, openAPI.components?.schemas)}` : void 0,
|
|
2507
|
-
operation.responses ? `responses:${makeOperationResponses(operation.responses, readonly)}` : void 0,
|
|
2508
|
-
operation.callbacks ? `callbacks:{${makeCallbacks(operation.callbacks, readonly)}}` : void 0,
|
|
2509
|
-
operation.deprecated ? `deprecated:${JSON.stringify(operation.deprecated)}` : void 0,
|
|
2510
|
-
operation.security ? `security:${JSON.stringify(operation.security)}` : void 0,
|
|
2511
|
-
operation.servers ? `servers:${JSON.stringify(operation.servers)}` : void 0
|
|
2512
|
-
].filter((v) => v !== void 0).join(",");
|
|
2513
|
-
const asConst = readonly ? " as const" : "";
|
|
2514
|
-
const entryName = methodPath(method, path);
|
|
2515
|
-
return {
|
|
2516
|
-
name: entryName,
|
|
2517
|
-
code: `export const ${entryName}Route=createRoute({${properties}}${asConst})`
|
|
2518
|
-
};
|
|
2519
|
-
};
|
|
2520
|
-
const resolveParameter = (parameter) => {
|
|
2521
|
-
if ("name" in parameter && "in" in parameter) return parameter;
|
|
2522
|
-
const ref = "$ref" in parameter ? parameter.$ref : void 0;
|
|
2523
|
-
if (!ref || !isParameterRef(ref)) return void 0;
|
|
2524
|
-
const resolved = openAPI.components?.parameters?.[ref.slice(ref.lastIndexOf("/") + 1)];
|
|
2525
|
-
if (!resolved) return void 0;
|
|
2526
|
-
return {
|
|
2527
|
-
...resolved,
|
|
2528
|
-
$ref: ref
|
|
2529
|
-
};
|
|
2530
|
-
};
|
|
2531
|
-
const resolvePathItem = (pathItem) => {
|
|
2532
|
-
if (pathItem.$ref && isPathItemRef(pathItem.$ref)) {
|
|
2533
|
-
const name = pathItem.$ref.slice(pathItem.$ref.lastIndexOf("/") + 1);
|
|
2534
|
-
const resolved = openAPI.components?.pathItems?.[name];
|
|
2535
|
-
if (resolved) {
|
|
2536
|
-
const { $ref: _, ...siblings } = pathItem;
|
|
2537
|
-
return {
|
|
2538
|
-
...resolved,
|
|
2539
|
-
...siblings
|
|
2540
|
-
};
|
|
2541
|
-
}
|
|
2542
|
-
}
|
|
2543
|
-
return pathItem;
|
|
2544
|
-
};
|
|
2545
|
-
const entries = Object.entries(openAPI.paths).flatMap(([path, pathItem]) => {
|
|
2546
|
-
if (!isPathItemEntry(pathItem)) return [];
|
|
2547
|
-
const resolved = resolvePathItem(pathItem);
|
|
2548
|
-
return HTTP_METHODS.flatMap((method) => {
|
|
2549
|
-
const operation = resolved[method];
|
|
2550
|
-
if (!operation?.responses) return [];
|
|
2551
|
-
const parameters = [...resolved.parameters ?? [], ...operation.parameters ?? []].map(resolveParameter).filter((p) => p !== void 0);
|
|
2552
|
-
return [makeEntry(path, method, parameters.length > 0 ? {
|
|
2553
|
-
...operation,
|
|
2554
|
-
parameters
|
|
2555
|
-
} : operation)];
|
|
2556
|
-
});
|
|
2557
|
-
});
|
|
2451
|
+
const entries = makeRouteEntries(openAPI, readonly);
|
|
2558
2452
|
if (!split || entries.length === 0) {
|
|
2559
2453
|
const code = makeImports(entries.map((entry) => entry.code).join("\n\n"), output, components);
|
|
2560
2454
|
yield* emit(code, dirname(output), output);
|
|
@@ -2711,7 +2605,7 @@ function defineTemplate(openAPI, output, componentsOutput, basePath, pathAlias,
|
|
|
2711
2605
|
//#region src/core/template/index.ts
|
|
2712
2606
|
function template(openAPI, output, basePath, pathAlias, routeImport, routeHandler, split = false) {
|
|
2713
2607
|
return Effect.gen(function* () {
|
|
2714
|
-
const target =
|
|
2608
|
+
const target = makeAppEntryFile(output, false);
|
|
2715
2609
|
yield* zodOpenAPIHonoHandler(openAPI, output, pathAlias, routeImport, routeHandler);
|
|
2716
2610
|
const inlineFiles = routeHandler ? void 0 : yield* resolveInlineHandlerFileNames(openAPI, output, pathAlias, routeImport);
|
|
2717
2611
|
const appCode = yield* fmt(app(openAPI, output, basePath, pathAlias, routeImport, routeHandler, false, void 0, inlineFiles, split));
|
|
@@ -2729,56 +2623,7 @@ function webhooks(openAPI, webhooks, components, readonly) {
|
|
|
2729
2623
|
if (!webhooks?.output) return yield* new GenerateError({ message: "webhooks.output is required" });
|
|
2730
2624
|
if (!openAPI.webhooks) return yield* new GenerateError({ message: "No webhooks found" });
|
|
2731
2625
|
const { output, split = false } = webhooks;
|
|
2732
|
-
const
|
|
2733
|
-
const makeEntry = (name, method, operation) => {
|
|
2734
|
-
const properties = [
|
|
2735
|
-
`method:${JSON.stringify(method)}`,
|
|
2736
|
-
`path:${JSON.stringify(`/${name}`)}`,
|
|
2737
|
-
operation.tags ? `tags:${JSON.stringify(operation.tags)}` : void 0,
|
|
2738
|
-
operation.summary ? `summary:${JSON.stringify(operation.summary)}` : void 0,
|
|
2739
|
-
operation.description ? `description:${JSON.stringify(operation.description)}` : void 0,
|
|
2740
|
-
operation.externalDocs ? `externalDocs:${JSON.stringify(operation.externalDocs)}` : void 0,
|
|
2741
|
-
operation.operationId ? `operationId:${JSON.stringify(operation.operationId)}` : void 0,
|
|
2742
|
-
makeRequest(operation.parameters, operation.requestBody, readonly, openAPI.components?.schemas) ? `request:${makeRequest(operation.parameters, operation.requestBody, readonly, openAPI.components?.schemas)}` : void 0,
|
|
2743
|
-
operation.responses ? `responses:${makeOperationResponses(operation.responses, readonly)}` : void 0,
|
|
2744
|
-
operation.callbacks ? `callbacks:{${makeCallbacks(operation.callbacks, readonly)}}` : void 0,
|
|
2745
|
-
operation.deprecated ? `deprecated:${JSON.stringify(operation.deprecated)}` : void 0,
|
|
2746
|
-
operation.security ? `security:${JSON.stringify(operation.security)}` : void 0,
|
|
2747
|
-
operation.servers ? `servers:${JSON.stringify(operation.servers)}` : void 0
|
|
2748
|
-
].filter((v) => v !== void 0).join(",");
|
|
2749
|
-
const asConst = readonly ? " as const" : "";
|
|
2750
|
-
const pascalName = toIdentifierPascalCase(name);
|
|
2751
|
-
const entryName = `${pascalName.charAt(0).toLowerCase() + pascalName.slice(1)}${method.charAt(0).toUpperCase()}${method.slice(1)}`;
|
|
2752
|
-
return {
|
|
2753
|
-
name: entryName,
|
|
2754
|
-
code: `export const ${entryName}Webhook={${properties}}${asConst}`
|
|
2755
|
-
};
|
|
2756
|
-
};
|
|
2757
|
-
if (!openAPI.webhooks) return [];
|
|
2758
|
-
const resolve = (parameter) => {
|
|
2759
|
-
if ("name" in parameter && "in" in parameter) return parameter;
|
|
2760
|
-
const ref = "$ref" in parameter ? parameter.$ref : void 0;
|
|
2761
|
-
if (!(ref && isParameterRef(ref))) return void 0;
|
|
2762
|
-
const resolved = openAPI.components?.parameters?.[ref.slice(ref.lastIndexOf("/") + 1)];
|
|
2763
|
-
if (!resolved) return void 0;
|
|
2764
|
-
return {
|
|
2765
|
-
...resolved,
|
|
2766
|
-
$ref: ref
|
|
2767
|
-
};
|
|
2768
|
-
};
|
|
2769
|
-
return Object.entries(openAPI.webhooks).flatMap(([name, pathItem]) => pathItem ? HTTP_METHODS.filter((m) => pathItem[m]?.responses).flatMap((method) => {
|
|
2770
|
-
const operation = pathItem[method];
|
|
2771
|
-
if (!operation) return [];
|
|
2772
|
-
const sourceParams = [...pathItem.parameters ?? [], ...operation.parameters ?? []];
|
|
2773
|
-
const params = sourceParams.map(resolve).filter((p) => p !== void 0);
|
|
2774
|
-
const effectiveOperation = sourceParams.length > 0 ? {
|
|
2775
|
-
...operation,
|
|
2776
|
-
parameters: params
|
|
2777
|
-
} : operation;
|
|
2778
|
-
return [makeEntry(name, method, effectiveOperation)];
|
|
2779
|
-
}) : []);
|
|
2780
|
-
};
|
|
2781
|
-
const entries = webhookEntries();
|
|
2626
|
+
const entries = makeWebhookEntries(openAPI, readonly);
|
|
2782
2627
|
if (entries.length === 0) return "No webhooks found";
|
|
2783
2628
|
if (!split) {
|
|
2784
2629
|
const code = makeImports(entries.map((entry) => entry.code).join("\n\n"), output, components);
|
|
@@ -2821,4 +2666,4 @@ var core_exports = /* @__PURE__ */ __exportAll({
|
|
|
2821
2666
|
webhooks: () => webhooks
|
|
2822
2667
|
});
|
|
2823
2668
|
//#endregion
|
|
2824
|
-
export {
|
|
2669
|
+
export { isInsideDirectory as C, makeGeneratedImport as E, appEntryOutput as S, makeAppEntryImport as T, headers as _, takibi as a, client as b, securitySchemes as c, requestBodies as d, pathItems as f, links as g, mediaTypes as h, defineTemplate as i, schemas as l, components as m, webhooks as n, route as o, parameters as p, template as r, mock as s, core_exports as t, responses as u, examples as v, makeAppEntryFile as w, handlerGroupOf as x, callbacks as y };
|