hono-takibi 0.9.99996 → 0.9.99997
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 +3 -2
- package/dist/core/docs/index.js +1 -1
- package/dist/core/hooks/index.js +1 -1
- package/dist/core/rpc/index.js +7 -4
- package/dist/core/type/index.js +3 -2
- package/dist/{docs-DJEuJ8Cn.js → docs-D6-_1ql4.js} +4 -4
- package/dist/generator/zod-openapi-hono/openapi/index.js +1 -1
- package/dist/{guard-B2ZfZYyO.js → guard-C_eRJ0au.js} +2 -2
- package/dist/{hooks-BfmklyQ_.js → hooks-qJjGH61L.js} +9 -5
- package/dist/{openapi-CmhbPLWG.js → openapi-QvfGV6Gp.js} +20 -7
- package/dist/{rpc-vbCXB2S_.js → rpc-BDZmSva1.js} +1 -1
- package/dist/{shared-DnibnCI5.js → shared-66qmwvRi.js} +117 -63
- package/dist/vite-plugin/index.js +5 -5
- package/package.json +2 -7
- package/dist/config/index.js +0 -2
package/dist/cli.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
import { readConfig } from "./index.js";
|
|
3
3
|
import { r as setFormatOptions } from "./emit-CFR63U4L.js";
|
|
4
|
-
import { n as parseOpenAPI, r as takibi, t as makeJob } from "./shared-
|
|
4
|
+
import { n as parseOpenAPI, r as takibi, t as makeJob } from "./shared-66qmwvRi.js";
|
|
5
5
|
import { existsSync } from "node:fs";
|
|
6
6
|
import { resolve } from "node:path";
|
|
7
7
|
//#region src/cli/index.ts
|
|
@@ -33,7 +33,8 @@ async function honoTakibi() {
|
|
|
33
33
|
ok: true,
|
|
34
34
|
value: HELP_TEXT
|
|
35
35
|
};
|
|
36
|
-
|
|
36
|
+
const abs = resolve(process.cwd(), "hono-takibi.config.ts");
|
|
37
|
+
if (!existsSync(abs)) {
|
|
37
38
|
const cliResult = parseCli(args);
|
|
38
39
|
if (!cliResult.ok) return {
|
|
39
40
|
ok: false,
|
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-D6-_1ql4.js";
|
|
2
2
|
export { docs };
|
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-qJjGH61L.js";
|
|
2
2
|
export { hooks };
|
package/dist/core/rpc/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as emit } from "../../emit-CFR63U4L.js";
|
|
2
|
-
import { N as methodPath, c as isOperationLike, f as isRecord, j as makeInferRequestType, o as isOpenAPIPaths } from "../../guard-
|
|
3
|
-
import { a as parsePathItem, i as operationHasArgs, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "../../rpc-
|
|
2
|
+
import { N as methodPath, c as isOperationLike, f as isRecord, j as makeInferRequestType, o as isOpenAPIPaths } from "../../guard-C_eRJ0au.js";
|
|
3
|
+
import { a as parsePathItem, i as operationHasArgs, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "../../rpc-BDZmSva1.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
//#region src/core/rpc/index.ts
|
|
6
6
|
/**
|
|
@@ -78,10 +78,13 @@ async function rpc(openAPI, output, importPath, split, clientName = "client", us
|
|
|
78
78
|
error: "Invalid OpenAPI paths"
|
|
79
79
|
};
|
|
80
80
|
const hasBasePath = basePath !== void 0 && basePath !== "/";
|
|
81
|
-
const
|
|
81
|
+
const componentsParameters = openAPI.components?.parameters ?? {};
|
|
82
|
+
const componentsRequestBodies = openAPI.components?.requestBodies ?? {};
|
|
83
|
+
const operationCodes = makeOperationCodes(paths, makeOperationDeps(clientName, componentsParameters, componentsRequestBodies), useParseResponse, hasBasePath, docs);
|
|
82
84
|
if (!split) {
|
|
83
85
|
const body = operationCodes.map(({ code }) => code).join("\n\n");
|
|
84
|
-
const
|
|
86
|
+
const code = `${makeHeader(importPath, operationCodes.some(({ hasArgs }) => hasArgs), clientName, useParseResponse)}${body}${operationCodes.length ? "\n" : ""}`;
|
|
87
|
+
const emitResult = await emit(code, path.dirname(output), output);
|
|
85
88
|
if (!emitResult.ok) return {
|
|
86
89
|
ok: false,
|
|
87
90
|
error: emitResult.error
|
package/dist/core/type/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as emit } from "../../emit-CFR63U4L.js";
|
|
2
|
-
import { L as statusCodeToNumber, M as makeSafeKey, g as isSchemaArray, i as isMediaWithSchema, l as isParameter, m as isRequestBody, n as isHttpMethod, s as isOperation, u as isParameterArray, x as isStringRef } from "../../guard-
|
|
2
|
+
import { L as statusCodeToNumber, M as makeSafeKey, g as isSchemaArray, i as isMediaWithSchema, l as isParameter, m as isRequestBody, n as isHttpMethod, s as isOperation, u as isParameterArray, x as isStringRef } from "../../guard-C_eRJ0au.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
//#region src/core/type/index.ts
|
|
5
5
|
/**
|
|
@@ -17,7 +17,8 @@ const DEEP_READONLY_TYPE = "type DeepReadonly<T>=T extends(infer R)[]?readonly D
|
|
|
17
17
|
async function type(openAPI, output, readonly) {
|
|
18
18
|
const schemaType = makeHonoSchemaType(openAPI);
|
|
19
19
|
const wrappedType = readonly ? `DeepReadonly<${schemaType}>` : schemaType;
|
|
20
|
-
const
|
|
20
|
+
const dts = `${readonly ? DEEP_READONLY_TYPE : ""}declare const routes:import('@hono/zod-openapi').OpenAPIHono<import('hono/types').Env,${wrappedType},'/'>\nexport default routes\n`;
|
|
21
|
+
const emitResult = await emit(dts, path.dirname(output), output);
|
|
21
22
|
return emitResult.ok ? {
|
|
22
23
|
ok: true,
|
|
23
24
|
value: `Generated type code written to ${output}`
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { a as writeFile, t as mkdir } from "./fsp-BXry-Hx5.js";
|
|
2
|
-
import { O as escapeHtml, a as isOAuthFlowValue, b as isSecurityScheme, f as isRecord, h as isResponses, m as isRequestBody, p as isRefObject, r as isMedia, y as isSecurityArray } from "./guard-
|
|
2
|
+
import { O as escapeHtml, a as isOAuthFlowValue, b as isSecurityScheme, f as isRecord, h as isResponses, m as isRequestBody, p as isRefObject, r as isMedia, y as isSecurityArray } from "./guard-C_eRJ0au.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { STATUS_CODES } from "node:http";
|
|
5
5
|
//#region src/generator/docs/index.ts
|
|
@@ -496,18 +496,18 @@ function flattenResponseSchemaFields(schema, components, prefix, visited = /* @_
|
|
|
496
496
|
description: propSchema.description ?? "none"
|
|
497
497
|
};
|
|
498
498
|
const nestedPrefix = (prefix ? `${prefix}»` : "»").replace(/»/g, "» ").trimEnd();
|
|
499
|
-
if (propSchema.type === "object" && propSchema.properties) return [row, ...flattenResponseSchemaFields(propSchema, components,
|
|
499
|
+
if (propSchema.type === "object" && propSchema.properties) return [row, ...flattenResponseSchemaFields(propSchema, components, nestedPrefix, visited, depth + 1)];
|
|
500
500
|
if (propSchema.$ref) {
|
|
501
501
|
if (visited.has(propSchema.$ref)) return [row];
|
|
502
502
|
visited.add(propSchema.$ref);
|
|
503
503
|
const innerResolved = resolveRef(propSchema.$ref, components);
|
|
504
|
-
if (isSchemaLike(innerResolved) && innerResolved.type === "object") return [row, ...flattenResponseSchemaFields(innerResolved, components,
|
|
504
|
+
if (isSchemaLike(innerResolved) && innerResolved.type === "object") return [row, ...flattenResponseSchemaFields(innerResolved, components, nestedPrefix, visited, depth + 1)];
|
|
505
505
|
}
|
|
506
506
|
if (propSchema.type === "array" && propSchema.items) {
|
|
507
507
|
const itemSchema = Array.isArray(propSchema.items) ? propSchema.items[0] : propSchema.items;
|
|
508
508
|
if (itemSchema) {
|
|
509
509
|
const resolvedItem = resolveArrayItem(itemSchema, components, visited);
|
|
510
|
-
if (resolvedItem.type === "object" && resolvedItem.properties) return [row, ...flattenResponseSchemaFields(resolvedItem, components,
|
|
510
|
+
if (resolvedItem.type === "object" && resolvedItem.properties) return [row, ...flattenResponseSchemaFields(resolvedItem, components, nestedPrefix, visited, depth + 1)];
|
|
511
511
|
}
|
|
512
512
|
}
|
|
513
513
|
return [row];
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { t as zodOpenAPIHono } from "../../../openapi-
|
|
1
|
+
import { t as zodOpenAPIHono } from "../../../openapi-QvfGV6Gp.js";
|
|
2
2
|
export { zodOpenAPIHono };
|
|
@@ -21,7 +21,7 @@ function normalizeTypes(t) {
|
|
|
21
21
|
function methodPath(method, path) {
|
|
22
22
|
const hasTrailingSlash = path !== "/" && path.endsWith("/");
|
|
23
23
|
const apiPath = path.replace(/[^A-Za-z0-9]/g, " ").trim().split(/\s+/).map((str) => `${str.charAt(0).toUpperCase()}${str.slice(1)}`).join("");
|
|
24
|
-
return apiPath ? `${method}${apiPath}${hasTrailingSlash ? "Index" : ""}` :
|
|
24
|
+
return apiPath ? `${method}${apiPath}${hasTrailingSlash ? "Index" : ""}` : method;
|
|
25
25
|
}
|
|
26
26
|
/**
|
|
27
27
|
* Generates an array of Zod validator strings from OpenAPI parameter objects.
|
|
@@ -231,7 +231,7 @@ function zodToOpenAPISchema(schemaName, zodSchema, exportSchema, exportType, not
|
|
|
231
231
|
* ```
|
|
232
232
|
*/
|
|
233
233
|
function makeBarrel(value) {
|
|
234
|
-
return `${Object.keys(value).
|
|
234
|
+
return `${Object.keys(value).toSorted().map((k) => `export * from './${k.charAt(0).toLowerCase() + k.slice(1)}'`).join("\n")}\n`;
|
|
235
235
|
}
|
|
236
236
|
/**
|
|
237
237
|
* Formats an error message argument using the Zod v4 unified `error` parameter.
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { t as emit } from "./emit-CFR63U4L.js";
|
|
2
|
-
import { N as methodPath, R as toIdentifierPascalCase, c as isOperationLike, f as isRecord, o as isOpenAPIPaths, w as capitalize } from "./guard-
|
|
3
|
-
import { a as parsePathItem, i as operationHasArgs, n as hasNoContentResponse, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "./rpc-
|
|
2
|
+
import { N as methodPath, R as toIdentifierPascalCase, c as isOperationLike, f as isRecord, o as isOpenAPIPaths, w as capitalize } from "./guard-C_eRJ0au.js";
|
|
3
|
+
import { a as parsePathItem, i as operationHasArgs, n as hasNoContentResponse, o as resolveSplitOutDir, r as makeOperationDeps, t as formatPath } from "./rpc-BDZmSva1.js";
|
|
4
4
|
import path from "node:path";
|
|
5
5
|
//#region src/helper/query.ts
|
|
6
6
|
function makeHookName(method, pathStr, prefix) {
|
|
7
|
-
|
|
7
|
+
const funcName = methodPath(method, pathStr);
|
|
8
|
+
return `${prefix}${capitalize(funcName)}`;
|
|
8
9
|
}
|
|
9
10
|
function makeRuntimeAccess(clientName, method, pathStr) {
|
|
10
11
|
return `${clientName}${formatPath(pathStr).runtimePath}.$${method}`;
|
|
@@ -545,14 +546,17 @@ async function makeQueryHooks(openAPI, output, importPath, config, split, client
|
|
|
545
546
|
ok: false,
|
|
546
547
|
error: "Invalid OpenAPI paths"
|
|
547
548
|
};
|
|
548
|
-
const
|
|
549
|
+
const componentsParameters = openAPI.components?.parameters ?? {};
|
|
550
|
+
const componentsRequestBodies = openAPI.components?.requestBodies ?? {};
|
|
551
|
+
const hookCodes = makeHookCodes(pathsMaybe, makeOperationDeps(clientName, componentsParameters, componentsRequestBodies), config, clientName);
|
|
549
552
|
const prefixKeyCodes = makePrefixKeyCodes(pathsMaybe);
|
|
550
553
|
const hasAnyArgs = hookCodes.some(({ hasArgs }) => hasArgs);
|
|
551
554
|
if (!split) {
|
|
552
555
|
const prefixBody = prefixKeyCodes.join("\n\n");
|
|
553
556
|
const hookBody = hookCodes.map(({ code }) => code).join("\n\n");
|
|
554
557
|
const body = prefixBody + (prefixBody && hookBody ? "\n\n" : "") + hookBody;
|
|
555
|
-
const
|
|
558
|
+
const code = `${makeHeader(importPath, clientName, hookCodes.some(({ isQuery }) => isQuery), hookCodes.some(({ isQuery }) => !isQuery), hasAnyArgs, config, hookCodes.some(({ isQuery, hasArgs }) => isQuery && hasArgs), hookCodes.some(({ hasInfinite }) => hasInfinite))}${body}${hookCodes.length ? "\n" : ""}`;
|
|
559
|
+
const emitResult = await emit(code, path.dirname(output), output);
|
|
556
560
|
if (!emitResult.ok) return {
|
|
557
561
|
ok: false,
|
|
558
562
|
error: emitResult.error
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { B as zodToOpenAPISchema, C as baseError, D as error, E as ensureSuffix, F as renderNamedImport, I as requestParamsArray, M as makeSafeKey, N as methodPath, P as normalizeTypes, R as toIdentifierPascalCase, T as cyclicNodes, _ as isSchemaObject, f as isRecord, g as isSchemaArray, k as escapeRegexLiteral, l as isParameter, p as isRefObject, r as isMedia, s as isOperation, z as uncapitalize } from "./guard-
|
|
1
|
+
import { B as zodToOpenAPISchema, C as baseError, D as error, E as ensureSuffix, F as renderNamedImport, I as requestParamsArray, M as makeSafeKey, N as methodPath, P as normalizeTypes, R as toIdentifierPascalCase, T as cyclicNodes, _ as isSchemaObject, f as isRecord, g as isSchemaArray, k as escapeRegexLiteral, l as isParameter, p as isRefObject, r as isMedia, s as isOperation, z as uncapitalize } from "./guard-C_eRJ0au.js";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
import { ts } from "ts-morph";
|
|
4
4
|
//#region src/helper/code.ts
|
|
@@ -293,7 +293,8 @@ function makeParameters(parameters, readonly) {
|
|
|
293
293
|
}, {});
|
|
294
294
|
}
|
|
295
295
|
function makeRequestParams(parameters, readonly) {
|
|
296
|
-
const
|
|
296
|
+
const paramsObject = makeParameters(parameters, readonly);
|
|
297
|
+
const paramsArray = requestParamsArray(paramsObject);
|
|
297
298
|
return paramsArray.length > 0 ? paramsArray.join(",") : void 0;
|
|
298
299
|
}
|
|
299
300
|
function makePathParameters(parameters) {
|
|
@@ -1646,7 +1647,8 @@ function collectIdentifiers(node) {
|
|
|
1646
1647
|
}
|
|
1647
1648
|
function findCyclicSchemas(names, deps) {
|
|
1648
1649
|
const var2name = new Map(names.map((n) => [toIdentifierPascalCase(ensureSuffix(n, "Schema")), n]));
|
|
1649
|
-
|
|
1650
|
+
const nameDeps = new Map(names.map((n) => [n, (deps.get(n) ?? []).map((v) => var2name.get(v)).filter((x) => x !== void 0)]));
|
|
1651
|
+
return cyclicNodes(nameDeps);
|
|
1650
1652
|
}
|
|
1651
1653
|
function analyzeCircularSchemas(schemas, schemaNames, readonly) {
|
|
1652
1654
|
const varNameSet = new Set(schemaNames.map((n) => toIdentifierPascalCase(ensureSuffix(n, "Schema"))));
|
|
@@ -1965,10 +1967,19 @@ function headersCode(components, exportHeaders, exportHeadersTypes, readonly) {
|
|
|
1965
1967
|
const isHeader = (v) => typeof v === "object" && v !== null && !("$ref" in v);
|
|
1966
1968
|
return Object.entries(headers).map(([k, header]) => {
|
|
1967
1969
|
const schemaName = toIdentifierPascalCase(ensureSuffix(k, "HeaderSchema"));
|
|
1968
|
-
if ("$ref" in header)
|
|
1970
|
+
if ("$ref" in header) {
|
|
1971
|
+
const refName = makeRef(header.$ref);
|
|
1972
|
+
return zodToOpenAPISchema(schemaName, refName, exportHeaders, exportHeadersTypes, true, readonly);
|
|
1973
|
+
}
|
|
1969
1974
|
if (isHeader(header)) {
|
|
1970
|
-
if (header.schema)
|
|
1971
|
-
|
|
1975
|
+
if (header.schema) {
|
|
1976
|
+
const schema = zodToOpenAPI(header.schema, { headers: header });
|
|
1977
|
+
return zodToOpenAPISchema(schemaName, schema, exportHeaders, exportHeadersTypes, true, readonly);
|
|
1978
|
+
}
|
|
1979
|
+
if (header.content) {
|
|
1980
|
+
const content = makeContent(header.content);
|
|
1981
|
+
return zodToOpenAPISchema(schemaName, `{${content.join(",")}}`, exportHeaders, exportHeadersTypes, true, readonly);
|
|
1982
|
+
}
|
|
1972
1983
|
}
|
|
1973
1984
|
return "";
|
|
1974
1985
|
}).filter(Boolean).join("\n\n");
|
|
@@ -2088,7 +2099,9 @@ function mediaTypesCode(components, exportMediaTypes, exportMediaTypesTypes, rea
|
|
|
2088
2099
|
if (entries.length === 0) return "";
|
|
2089
2100
|
return entries.map(([k, v]) => {
|
|
2090
2101
|
if (!isMedia(v)) return void 0;
|
|
2091
|
-
|
|
2102
|
+
const name = toIdentifierPascalCase(ensureSuffix(k, "MediaTypeSchema"));
|
|
2103
|
+
const zodCode = zodToOpenAPI(v.schema);
|
|
2104
|
+
return zodToOpenAPISchema(name, zodCode, exportMediaTypes, exportMediaTypesTypes, true, readonly);
|
|
2092
2105
|
}).filter((v) => v !== void 0).join("\n\n");
|
|
2093
2106
|
}
|
|
2094
2107
|
//#endregion
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { S as isValidIdent, c as isOperationLike, d as isParameterObject, f as isRecord, p as isRefObject, v as isSchemaProperty } from "./guard-
|
|
1
|
+
import { S as isValidIdent, c as isOperationLike, d as isParameterObject, f as isRecord, p as isRefObject, v as isSchemaProperty } from "./guard-C_eRJ0au.js";
|
|
2
2
|
import path from "node:path";
|
|
3
3
|
//#region src/helper/rpc.ts
|
|
4
4
|
function makeEscaped(s) {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { n as fmt, t as emit } from "./emit-CFR63U4L.js";
|
|
2
2
|
import { a as writeFile, i as unlink, n as readFile, r as readdir, t as mkdir } from "./fsp-BXry-Hx5.js";
|
|
3
|
-
import { A as makeBarrel, B as zodToOpenAPISchema, E as ensureSuffix, F as renderNamedImport, L as statusCodeToNumber, N as methodPath, R as toIdentifierPascalCase, T as cyclicNodes, b as isSecurityScheme, i as isMediaWithSchema, k as escapeRegexLiteral, l as isParameter, n as isHttpMethod, p as isRefObject, s as isOperation, t as isContentBody, y as isSecurityArray, z as uncapitalize } from "./guard-
|
|
4
|
-
import { S as makeModuleSpec, _ as makeRef, a as responsesCode, b as makeExportConst, c as headersCode, d as ast, f as zodToOpenAPI, g as makePathItem, h as makeOperationResponses, i as schemasCode, l as makeSplitSchemaFile, m as makeCallbacks, n as routeCode, o as requestBodiesCode, p as makeCallback, r as componentsCode, s as parametersCode, t as zodOpenAPIHono, u as analyzeCircularSchemas, v as makeRequest, x as makeImports, y as makeConst } from "./openapi-
|
|
5
|
-
import { t as hooks } from "./hooks-
|
|
6
|
-
import { t as docs } from "./docs-
|
|
3
|
+
import { A as makeBarrel, B as zodToOpenAPISchema, E as ensureSuffix, F as renderNamedImport, L as statusCodeToNumber, N as methodPath, R as toIdentifierPascalCase, T as cyclicNodes, b as isSecurityScheme, i as isMediaWithSchema, k as escapeRegexLiteral, l as isParameter, n as isHttpMethod, p as isRefObject, s as isOperation, t as isContentBody, y as isSecurityArray, z as uncapitalize } from "./guard-C_eRJ0au.js";
|
|
4
|
+
import { S as makeModuleSpec, _ as makeRef, a as responsesCode, b as makeExportConst, c as headersCode, d as ast, f as zodToOpenAPI, g as makePathItem, h as makeOperationResponses, i as schemasCode, l as makeSplitSchemaFile, m as makeCallbacks, n as routeCode, o as requestBodiesCode, p as makeCallback, r as componentsCode, s as parametersCode, t as zodOpenAPIHono, u as analyzeCircularSchemas, v as makeRequest, x as makeImports, y as makeConst } from "./openapi-QvfGV6Gp.js";
|
|
5
|
+
import { t as hooks } from "./hooks-qJjGH61L.js";
|
|
6
|
+
import { t as docs } from "./docs-D6-_1ql4.js";
|
|
7
7
|
import { rpc } from "./core/rpc/index.js";
|
|
8
8
|
import { type } from "./core/type/index.js";
|
|
9
9
|
import path from "node:path";
|
|
@@ -235,11 +235,12 @@ async function callbacks(callbacks, output, split, components, readonly) {
|
|
|
235
235
|
value: `Generated Callback code written to ${outDir}/*.ts (index.ts included)`
|
|
236
236
|
};
|
|
237
237
|
}
|
|
238
|
-
const
|
|
238
|
+
const code = Object.entries(callbacks).map(([k, callbackOrRef]) => {
|
|
239
239
|
if (!isCallbacks(callbackOrRef)) return void 0;
|
|
240
240
|
const callbackCode = makeCallback(callbackOrRef);
|
|
241
241
|
return callbackCode ? `${makeConst(true, k, "Callback")}{${callbackCode}}${asConst}` : void 0;
|
|
242
|
-
}).filter((v) => v !== void 0).join("\n\n")
|
|
242
|
+
}).filter((v) => v !== void 0).join("\n\n");
|
|
243
|
+
const emitResult = await emit(makeImports(code, output, components, split), path.dirname(output), output);
|
|
243
244
|
if (!emitResult.ok) return {
|
|
244
245
|
ok: false,
|
|
245
246
|
error: emitResult.error
|
|
@@ -270,9 +271,12 @@ async function examples(examples, output, split, readonly) {
|
|
|
270
271
|
const filePath = path.join(outDir, `${uncapitalize(k)}.ts`);
|
|
271
272
|
if (typeof v === "object" && v !== null && "$ref" in v && typeof v.$ref === "string") {
|
|
272
273
|
const refName = makeRef(v.$ref);
|
|
273
|
-
|
|
274
|
+
const refKey = v.$ref.split("/").at(-1) ?? "";
|
|
275
|
+
const body = `import { ${refName} } from '${`./${uncapitalize(refKey)}`}'\n\nexport const ${name} = ${refName}\n`;
|
|
276
|
+
return emit(body, path.dirname(filePath), filePath);
|
|
274
277
|
}
|
|
275
|
-
|
|
278
|
+
const body = `export const ${name} = ${JSON.stringify(v)}${asConst}\n`;
|
|
279
|
+
return emit(body, path.dirname(filePath), filePath);
|
|
276
280
|
}), emit(makeBarrel(examples), path.dirname(path.join(outDir, "index.ts")), path.join(outDir, "index.ts"))])).find((result) => !result.ok);
|
|
277
281
|
if (e) return e;
|
|
278
282
|
return {
|
|
@@ -280,7 +284,8 @@ async function examples(examples, output, split, readonly) {
|
|
|
280
284
|
value: `Generated Example code written to ${outDir}/*.ts (index.ts included)`
|
|
281
285
|
};
|
|
282
286
|
}
|
|
283
|
-
const
|
|
287
|
+
const code = makeExportConst(examples, "Example", readonly);
|
|
288
|
+
const emitResult = await emit(code, path.dirname(output), output);
|
|
284
289
|
if (!emitResult.ok) return {
|
|
285
290
|
ok: false,
|
|
286
291
|
error: emitResult.error
|
|
@@ -305,7 +310,8 @@ async function headers(headers, output, split, exportType, components, readonly)
|
|
|
305
310
|
if (split) {
|
|
306
311
|
const outDir = path.join(path.dirname(output), path.basename(output, ".ts"));
|
|
307
312
|
const e = (await Promise.all([...headerNames.map((headerName) => {
|
|
308
|
-
const
|
|
313
|
+
const singleComponent = { headers: { [headerName]: headers[headerName] } };
|
|
314
|
+
const code = headersCode(singleComponent, true, exportType, readonly);
|
|
309
315
|
const filePath = path.join(outDir, `${uncapitalize(headerName)}.ts`);
|
|
310
316
|
return emit(makeImports(code, filePath, components, split), path.dirname(filePath), filePath);
|
|
311
317
|
}), emit(makeBarrel(headers), outDir, path.join(outDir, "index.ts"))])).find((result) => !result.ok);
|
|
@@ -315,7 +321,8 @@ async function headers(headers, output, split, exportType, components, readonly)
|
|
|
315
321
|
value: `Generated headers code written to ${outDir}/*.ts (index.ts included)`
|
|
316
322
|
};
|
|
317
323
|
}
|
|
318
|
-
const
|
|
324
|
+
const headerDefinitions = headersCode({ headers }, true, exportType, readonly);
|
|
325
|
+
const emitResult = await emit(makeImports(headerDefinitions, output, components, split), path.dirname(output), output);
|
|
319
326
|
if (!emitResult.ok) return {
|
|
320
327
|
ok: false,
|
|
321
328
|
error: emitResult.error
|
|
@@ -352,7 +359,8 @@ async function links(links, output, split, readonly) {
|
|
|
352
359
|
value: `Generated Link code written to ${outDir}/*.ts (index.ts included)`
|
|
353
360
|
};
|
|
354
361
|
}
|
|
355
|
-
const
|
|
362
|
+
const code = makeExportConst(links, "Link", readonly);
|
|
363
|
+
const emitResult = await emit(code, path.dirname(output), output);
|
|
356
364
|
if (!emitResult.ok) return {
|
|
357
365
|
ok: false,
|
|
358
366
|
error: emitResult.error
|
|
@@ -381,9 +389,18 @@ async function mediaTypes(mediaTypes, output, split, readonly, components) {
|
|
|
381
389
|
const v = mediaTypes[k];
|
|
382
390
|
const name = toIdentifierPascalCase(ensureSuffix(k, "MediaTypeSchema"));
|
|
383
391
|
const filePath = path.join(outDir, `${uncapitalize(k)}.ts`);
|
|
384
|
-
if (typeof v === "object" && v !== null && "$ref" in v && v.$ref)
|
|
385
|
-
|
|
386
|
-
|
|
392
|
+
if (typeof v === "object" && v !== null && "$ref" in v && v.$ref) {
|
|
393
|
+
const refKey = v.$ref.split("/").at(-1) ?? "";
|
|
394
|
+
const body = `export const ${name} = ${toIdentifierPascalCase(ensureSuffix(refKey, "MediaTypeSchema"))}\n`;
|
|
395
|
+
return emit(makeImports(body, filePath, components, split), path.dirname(filePath), filePath);
|
|
396
|
+
}
|
|
397
|
+
if (typeof v === "object" && v !== null && "schema" in v) {
|
|
398
|
+
const zodCode = zodToOpenAPI(v.schema);
|
|
399
|
+
const schemaCode = zodToOpenAPISchema(name, zodCode, true, false, true, readonly);
|
|
400
|
+
return emit(makeImports(schemaCode, filePath, components, split), path.dirname(filePath), filePath);
|
|
401
|
+
}
|
|
402
|
+
const body = `export const ${name} = z.unknown()\n`;
|
|
403
|
+
return emit(makeImports(body, filePath, components, split), path.dirname(filePath), filePath);
|
|
387
404
|
}), emit(makeBarrel(mediaTypes), path.dirname(path.join(outDir, "index.ts")), path.join(outDir, "index.ts"))])).find((result) => !result.ok);
|
|
388
405
|
if (e) return e;
|
|
389
406
|
return {
|
|
@@ -391,13 +408,20 @@ async function mediaTypes(mediaTypes, output, split, readonly, components) {
|
|
|
391
408
|
value: `Generated MediaType code written to ${outDir}/*.ts (index.ts included)`
|
|
392
409
|
};
|
|
393
410
|
}
|
|
394
|
-
const
|
|
411
|
+
const code = `${importCode}\n\n${keys.map((k) => {
|
|
395
412
|
const v = mediaTypes[k];
|
|
396
413
|
const name = toIdentifierPascalCase(ensureSuffix(k, "MediaTypeSchema"));
|
|
397
|
-
if (typeof v === "object" && v !== null && "$ref" in v && v.$ref)
|
|
398
|
-
|
|
414
|
+
if (typeof v === "object" && v !== null && "$ref" in v && v.$ref) {
|
|
415
|
+
const refKey = v.$ref.split("/").at(-1) ?? "";
|
|
416
|
+
return `export const ${name} = ${toIdentifierPascalCase(ensureSuffix(refKey, "MediaTypeSchema"))}`;
|
|
417
|
+
}
|
|
418
|
+
if (typeof v === "object" && v !== null && "schema" in v) {
|
|
419
|
+
const zodCode = zodToOpenAPI(v.schema);
|
|
420
|
+
return zodToOpenAPISchema(name, zodCode, true, false, true, readonly);
|
|
421
|
+
}
|
|
399
422
|
return `export const ${name} = z.unknown()`;
|
|
400
|
-
}).join("\n\n")}\n
|
|
423
|
+
}).join("\n\n")}\n`;
|
|
424
|
+
const emitResult = await emit(code, path.dirname(output), output);
|
|
401
425
|
if (!emitResult.ok) return {
|
|
402
426
|
ok: false,
|
|
403
427
|
error: emitResult.error
|
|
@@ -436,7 +460,8 @@ async function components(openAPI, output, readonly) {
|
|
|
436
460
|
ok: true,
|
|
437
461
|
value: "No components found"
|
|
438
462
|
};
|
|
439
|
-
const
|
|
463
|
+
const withImports = `import{${code.includes("createRoute(") ? "createRoute,z" : "z"}}from'@hono/zod-openapi'\n\n${code}`;
|
|
464
|
+
const emitResult = await emit(withImports, path.dirname(output), output);
|
|
440
465
|
if (!emitResult.ok) return {
|
|
441
466
|
ok: false,
|
|
442
467
|
error: emitResult.error
|
|
@@ -461,7 +486,8 @@ async function parameters(parameters, output, split, exportType, components, rea
|
|
|
461
486
|
if (split) {
|
|
462
487
|
const outDir = path.join(path.dirname(output), path.basename(output, ".ts"));
|
|
463
488
|
const e = (await Promise.all([...parameterNames.map((parameterName) => {
|
|
464
|
-
const
|
|
489
|
+
const singleComponent = { parameters: { [parameterName]: parameters[parameterName] } };
|
|
490
|
+
const code = parametersCode(singleComponent, true, exportType, readonly);
|
|
465
491
|
const filePath = path.join(outDir, `${uncapitalize(parameterName)}.ts`);
|
|
466
492
|
return emit(makeImports(code, filePath, components, split), path.dirname(filePath), filePath);
|
|
467
493
|
}), emit(makeBarrel(parameters), outDir, path.join(outDir, "index.ts"))])).find((result) => !result.ok);
|
|
@@ -471,7 +497,8 @@ async function parameters(parameters, output, split, exportType, components, rea
|
|
|
471
497
|
value: `Generated parameters code written to ${outDir}/*.ts (index.ts included)`
|
|
472
498
|
};
|
|
473
499
|
}
|
|
474
|
-
const
|
|
500
|
+
const parameterDefinitions = parametersCode({ parameters }, true, exportType, readonly);
|
|
501
|
+
const emitResult = await emit(makeImports(parameterDefinitions, output, components, split), path.dirname(output), output);
|
|
475
502
|
if (!emitResult.ok) return {
|
|
476
503
|
ok: false,
|
|
477
504
|
error: emitResult.error
|
|
@@ -514,7 +541,8 @@ async function pathItems(components, pathItemsConfig, componentsConfig, readonly
|
|
|
514
541
|
value: "No pathItems found"
|
|
515
542
|
};
|
|
516
543
|
if (!split) {
|
|
517
|
-
const
|
|
544
|
+
const code = makeImports(entries.map((e) => e.code).join("\n\n"), output, componentsConfig);
|
|
545
|
+
const result = await emit(code, path.dirname(output), output);
|
|
518
546
|
if (!result.ok) return result;
|
|
519
547
|
return {
|
|
520
548
|
ok: true,
|
|
@@ -524,7 +552,8 @@ async function pathItems(components, pathItemsConfig, componentsConfig, readonly
|
|
|
524
552
|
const outDir = path.join(path.dirname(output), path.basename(output, ".ts"));
|
|
525
553
|
const e = (await Promise.all([...entries.map(async ({ key, code }) => {
|
|
526
554
|
const filePath = `${outDir}/${uncapitalize(key)}.ts`;
|
|
527
|
-
const
|
|
555
|
+
const withImports = makeImports(code, filePath, componentsConfig);
|
|
556
|
+
const result = await emit(withImports, path.dirname(filePath), filePath);
|
|
528
557
|
return result.ok ? {
|
|
529
558
|
ok: true,
|
|
530
559
|
value: filePath
|
|
@@ -551,7 +580,8 @@ async function requestBodies(requestBodies, output, split, components, readonly)
|
|
|
551
580
|
if (split) {
|
|
552
581
|
const outDir = path.join(path.dirname(output), path.basename(output, ".ts"));
|
|
553
582
|
const e = (await Promise.all([...bodyNames.map((bodyName) => {
|
|
554
|
-
const
|
|
583
|
+
const singleComponent = { requestBodies: { [bodyName]: requestBodies[bodyName] } };
|
|
584
|
+
const code = requestBodiesCode(singleComponent, true, readonly);
|
|
555
585
|
const filePath = path.join(outDir, `${uncapitalize(bodyName)}.ts`);
|
|
556
586
|
return emit(makeImports(code, filePath, components, split), path.dirname(filePath), filePath);
|
|
557
587
|
}), emit(makeBarrel(requestBodies), outDir, path.join(outDir, "index.ts"))])).find((result) => !result.ok);
|
|
@@ -561,7 +591,8 @@ async function requestBodies(requestBodies, output, split, components, readonly)
|
|
|
561
591
|
value: `Generated requestBodies code written to ${outDir}/*.ts (index.ts included)`
|
|
562
592
|
};
|
|
563
593
|
}
|
|
564
|
-
const
|
|
594
|
+
const bodyDefinitions = requestBodiesCode({ requestBodies }, true, readonly);
|
|
595
|
+
const emitResult = await emit(makeImports(bodyDefinitions, output, components, split), path.dirname(output), output);
|
|
565
596
|
if (!emitResult.ok) return {
|
|
566
597
|
ok: false,
|
|
567
598
|
error: emitResult.error
|
|
@@ -586,7 +617,8 @@ async function responses(responses, output, split, components, readonly) {
|
|
|
586
617
|
if (split) {
|
|
587
618
|
const outDir = path.join(path.dirname(output), path.basename(output, ".ts"));
|
|
588
619
|
const e = (await Promise.all([...responseNames.map((responseName) => {
|
|
589
|
-
const
|
|
620
|
+
const singleComponent = { responses: { [responseName]: responses[responseName] } };
|
|
621
|
+
const code = responsesCode(singleComponent, true, readonly);
|
|
590
622
|
const filePath = path.join(outDir, `${uncapitalize(responseName)}.ts`);
|
|
591
623
|
return emit(makeImports(code, filePath, components, split), path.dirname(filePath), filePath);
|
|
592
624
|
}), emit(makeBarrel(responses), outDir, path.join(outDir, "index.ts"))])).find((result) => !result.ok);
|
|
@@ -596,7 +628,8 @@ async function responses(responses, output, split, components, readonly) {
|
|
|
596
628
|
value: `Generated responses code written to ${outDir}/*.ts (index.ts included)`
|
|
597
629
|
};
|
|
598
630
|
}
|
|
599
|
-
const
|
|
631
|
+
const responseDefinitions = responsesCode({ responses }, true, readonly);
|
|
632
|
+
const emitResult = await emit(makeImports(responseDefinitions, output, components, split), path.dirname(output), output);
|
|
600
633
|
if (!emitResult.ok) return {
|
|
601
634
|
ok: false,
|
|
602
635
|
error: emitResult.error
|
|
@@ -632,7 +665,10 @@ async function schemas(schemas, output, split, exportType, readonly) {
|
|
|
632
665
|
value: `Generated schema code written to ${outDir}/*.ts (index.ts included)`
|
|
633
666
|
};
|
|
634
667
|
}
|
|
635
|
-
const
|
|
668
|
+
const importCode = renderNamedImport(["z"], "@hono/zod-openapi");
|
|
669
|
+
const schemaDefinitions = schemasCode({ schemas }, true, exportType, readonly);
|
|
670
|
+
const schemaDefinitionsCode = `${importCode}\n\n${ast(schemaDefinitions)}`;
|
|
671
|
+
const emitResult = await emit(schemaDefinitionsCode, path.dirname(output), output);
|
|
636
672
|
if (!emitResult.ok) return {
|
|
637
673
|
ok: false,
|
|
638
674
|
error: emitResult.error
|
|
@@ -669,7 +705,8 @@ async function securitySchemes(securitySchemes, output, split, readonly) {
|
|
|
669
705
|
value: `Generated SecurityScheme code written to ${outDir}/*.ts (index.ts included)`
|
|
670
706
|
};
|
|
671
707
|
}
|
|
672
|
-
const
|
|
708
|
+
const code = makeExportConst(securitySchemes, "SecurityScheme", readonly);
|
|
709
|
+
const emitResult = await emit(code, path.dirname(output), output);
|
|
673
710
|
if (!emitResult.ok) return {
|
|
674
711
|
ok: false,
|
|
675
712
|
error: emitResult.error
|
|
@@ -851,7 +888,7 @@ function resolveSuccessResponse(responses, componentResponses) {
|
|
|
851
888
|
"204",
|
|
852
889
|
"default"
|
|
853
890
|
].filter((key) => keys.includes(key));
|
|
854
|
-
const others = keys.filter((key) => !priority.includes(key) && statusCodeToNumber(key) >= 200 && statusCodeToNumber(key) < 300).
|
|
891
|
+
const others = keys.filter((key) => !priority.includes(key) && statusCodeToNumber(key) >= 200 && statusCodeToNumber(key) < 300).toSorted((a, b) => statusCodeToNumber(a) - statusCodeToNumber(b));
|
|
855
892
|
const key = [...priority, ...others][0];
|
|
856
893
|
if (!key) return void 0;
|
|
857
894
|
return {
|
|
@@ -1048,7 +1085,8 @@ export default app`
|
|
|
1048
1085
|
//#endregion
|
|
1049
1086
|
//#region src/core/mock/index.ts
|
|
1050
1087
|
async function mock(openAPI, output, basePath, options = {}) {
|
|
1051
|
-
const
|
|
1088
|
+
const mockCode = makeMock(openAPI, basePath, options);
|
|
1089
|
+
const emitResult = await emit(mockCode, path.dirname(output), output);
|
|
1052
1090
|
if (!emitResult.ok) return {
|
|
1053
1091
|
ok: false,
|
|
1054
1092
|
error: emitResult.error
|
|
@@ -1142,7 +1180,8 @@ async function route(openAPI, routes, components, readonly) {
|
|
|
1142
1180
|
};
|
|
1143
1181
|
const entries = routeEntries(openAPI, readonly);
|
|
1144
1182
|
if (!split || entries.length === 0) {
|
|
1145
|
-
const
|
|
1183
|
+
const code = makeImports(entries.map((e) => e.code).join("\n\n"), output, components);
|
|
1184
|
+
const result = await emit(code, path.dirname(output), output);
|
|
1146
1185
|
if (!result.ok) return result;
|
|
1147
1186
|
return {
|
|
1148
1187
|
ok: true,
|
|
@@ -1152,7 +1191,8 @@ async function route(openAPI, routes, components, readonly) {
|
|
|
1152
1191
|
const outDir = path.join(path.dirname(output), path.basename(output, ".ts"));
|
|
1153
1192
|
const e = (await Promise.all([...entries.map(async ({ name, code }) => {
|
|
1154
1193
|
const filePath = `${outDir}/${name}.ts`;
|
|
1155
|
-
const
|
|
1194
|
+
const withImports = makeImports(code, filePath, components);
|
|
1195
|
+
const result = await emit(withImports, path.dirname(filePath), filePath);
|
|
1156
1196
|
return result.ok ? {
|
|
1157
1197
|
ok: true,
|
|
1158
1198
|
value: filePath
|
|
@@ -2172,7 +2212,8 @@ async function zodOpenAPIHonoHandler(openapi, output, test = false, pathAlias, r
|
|
|
2172
2212
|
error: mkdirResult.error
|
|
2173
2213
|
};
|
|
2174
2214
|
const e = (await Promise.all([...handlers.map(async (handler) => {
|
|
2175
|
-
const
|
|
2215
|
+
const fileContent = routeHandler ? makeStubFileContent(handler, importFrom) : makeInlineStubFileContent(handler, importFrom);
|
|
2216
|
+
const fmtResult = await fmt(fileContent);
|
|
2176
2217
|
if (!fmtResult.ok) return {
|
|
2177
2218
|
ok: false,
|
|
2178
2219
|
error: fmtResult.error
|
|
@@ -2185,7 +2226,8 @@ async function zodOpenAPIHonoHandler(openapi, output, test = false, pathAlias, r
|
|
|
2185
2226
|
};
|
|
2186
2227
|
const merged = existingResult.value !== null ? mergeHandlerFile(existingResult.value, fmtResult.value) : fmtResult.value;
|
|
2187
2228
|
const finalFmtResult = await fmt(merged);
|
|
2188
|
-
const
|
|
2229
|
+
const content = finalFmtResult.ok ? finalFmtResult.value : merged;
|
|
2230
|
+
const writeResult = await writeFile(filePath, content);
|
|
2189
2231
|
if (!writeResult.ok) return {
|
|
2190
2232
|
ok: false,
|
|
2191
2233
|
error: writeResult.error
|
|
@@ -2203,7 +2245,8 @@ async function zodOpenAPIHonoHandler(openapi, output, test = false, pathAlias, r
|
|
|
2203
2245
|
};
|
|
2204
2246
|
const mergedTestCode = existingTestResult.value !== null ? mergeTestFile(existingTestResult.value, testCode) : testCode;
|
|
2205
2247
|
const finalFmtResult = await fmt(mergedTestCode);
|
|
2206
|
-
const
|
|
2248
|
+
const finalTestCode = finalFmtResult.ok ? finalFmtResult.value : mergedTestCode;
|
|
2249
|
+
const testWriteResult = await writeFile(testFilePath, finalTestCode);
|
|
2207
2250
|
if (!testWriteResult.ok) return {
|
|
2208
2251
|
ok: false,
|
|
2209
2252
|
error: testWriteResult.error
|
|
@@ -2226,7 +2269,8 @@ async function zodOpenAPIHonoHandler(openapi, output, test = false, pathAlias, r
|
|
|
2226
2269
|
ok: false,
|
|
2227
2270
|
error: existingResult.error
|
|
2228
2271
|
};
|
|
2229
|
-
const
|
|
2272
|
+
const content = existingResult.value !== null ? mergeBarrelFile(existingResult.value, fmtResult.value) : fmtResult.value;
|
|
2273
|
+
const writeResult = await writeFile(barrelPath, content);
|
|
2230
2274
|
if (!writeResult.ok) return {
|
|
2231
2275
|
ok: false,
|
|
2232
2276
|
error: writeResult.error
|
|
@@ -2301,7 +2345,9 @@ async function defineOpenAPIRouteHandler(openapi, output, componentsOutput, test
|
|
|
2301
2345
|
const handlerList = [...handlers.values()];
|
|
2302
2346
|
const e = (await Promise.all([...handlerList.map(async (handler) => {
|
|
2303
2347
|
const filePath = `${handlerPath}/${handler.fileName}`;
|
|
2304
|
-
const
|
|
2348
|
+
const chain = handler.contents.join("\n\n");
|
|
2349
|
+
const fileContent = makeImports(chain, filePath, componentsMap, false, ["defineOpenAPIRoute"]);
|
|
2350
|
+
const fmtResult = await fmt(fileContent);
|
|
2305
2351
|
if (!fmtResult.ok) return {
|
|
2306
2352
|
ok: false,
|
|
2307
2353
|
error: fmtResult.error
|
|
@@ -2313,7 +2359,8 @@ async function defineOpenAPIRouteHandler(openapi, output, componentsOutput, test
|
|
|
2313
2359
|
};
|
|
2314
2360
|
const merged = existingResult.value !== null ? mergeDefineFile(existingResult.value, fmtResult.value) : fmtResult.value;
|
|
2315
2361
|
const finalFmtResult = await fmt(merged);
|
|
2316
|
-
const
|
|
2362
|
+
const content = finalFmtResult.ok ? finalFmtResult.value : merged;
|
|
2363
|
+
const writeResult = await writeFile(filePath, content);
|
|
2317
2364
|
if (!writeResult.ok) return {
|
|
2318
2365
|
ok: false,
|
|
2319
2366
|
error: writeResult.error
|
|
@@ -2331,7 +2378,8 @@ async function defineOpenAPIRouteHandler(openapi, output, componentsOutput, test
|
|
|
2331
2378
|
};
|
|
2332
2379
|
const mergedTestCode = existingTestResult.value !== null ? mergeTestFile(existingTestResult.value, testCode) : testCode;
|
|
2333
2380
|
const finalTestFmt = await fmt(mergedTestCode);
|
|
2334
|
-
const
|
|
2381
|
+
const finalTestCode = finalTestFmt.ok ? finalTestFmt.value : mergedTestCode;
|
|
2382
|
+
const testWriteResult = await writeFile(testFilePath, finalTestCode);
|
|
2335
2383
|
if (!testWriteResult.ok) return {
|
|
2336
2384
|
ok: false,
|
|
2337
2385
|
error: testWriteResult.error
|
|
@@ -2354,7 +2402,8 @@ async function defineOpenAPIRouteHandler(openapi, output, componentsOutput, test
|
|
|
2354
2402
|
ok: false,
|
|
2355
2403
|
error: existingResult.error
|
|
2356
2404
|
};
|
|
2357
|
-
const
|
|
2405
|
+
const content = existingResult.value !== null ? mergeBarrelFile(existingResult.value, fmtResult.value) : fmtResult.value;
|
|
2406
|
+
const writeResult = await writeFile(barrelPath, content);
|
|
2358
2407
|
if (!writeResult.ok) return {
|
|
2359
2408
|
ok: false,
|
|
2360
2409
|
error: writeResult.error
|
|
@@ -2473,7 +2522,8 @@ async function defineTemplate(openAPI, output, componentsOutput, test, basePath,
|
|
|
2473
2522
|
};
|
|
2474
2523
|
const merged = existingResult.value !== null ? mergeAppFile(existingResult.value, appFmtResult.value) : appFmtResult.value;
|
|
2475
2524
|
const finalFmtResult = await fmt(merged);
|
|
2476
|
-
const
|
|
2525
|
+
const appContent = finalFmtResult.ok ? finalFmtResult.value : merged;
|
|
2526
|
+
const writeResult = await writeFile(target, appContent);
|
|
2477
2527
|
if (!writeResult.ok) return {
|
|
2478
2528
|
ok: false,
|
|
2479
2529
|
error: writeResult.error
|
|
@@ -2504,7 +2554,8 @@ async function template(openAPI, output, test, basePath, pathAlias, routeImport,
|
|
|
2504
2554
|
};
|
|
2505
2555
|
const merged = existingResult.value !== null ? mergeAppFile(existingResult.value, appFmtResult.value) : appFmtResult.value;
|
|
2506
2556
|
const finalFmtResult = await fmt(merged);
|
|
2507
|
-
const
|
|
2557
|
+
const appContent = finalFmtResult.ok ? finalFmtResult.value : merged;
|
|
2558
|
+
const writeResult = await writeFile(target, appContent);
|
|
2508
2559
|
if (!writeResult.ok) return {
|
|
2509
2560
|
ok: false,
|
|
2510
2561
|
error: writeResult.error
|
|
@@ -2537,7 +2588,8 @@ async function test(openAPI, output, importPath, basePath = "/", testFramework =
|
|
|
2537
2588
|
};
|
|
2538
2589
|
const merged = existingResult.value !== null ? mergeTestFile(existingResult.value, fmtResult.value) : fmtResult.value;
|
|
2539
2590
|
const finalFmtResult = await fmt(merged);
|
|
2540
|
-
const
|
|
2591
|
+
const content = finalFmtResult.ok ? finalFmtResult.value : merged;
|
|
2592
|
+
const writeResult = await writeFile(output, content);
|
|
2541
2593
|
if (!writeResult.ok) return {
|
|
2542
2594
|
ok: false,
|
|
2543
2595
|
error: writeResult.error
|
|
@@ -2627,7 +2679,8 @@ async function webhooks(openAPI, webhooks, components, readonly) {
|
|
|
2627
2679
|
value: "No webhooks found"
|
|
2628
2680
|
};
|
|
2629
2681
|
if (!split) {
|
|
2630
|
-
const
|
|
2682
|
+
const code = makeImports(entries.map((e) => e.code).join("\n\n"), output, components);
|
|
2683
|
+
const result = await emit(code, path.dirname(output), output);
|
|
2631
2684
|
if (!result.ok) return result;
|
|
2632
2685
|
return {
|
|
2633
2686
|
ok: true,
|
|
@@ -2637,7 +2690,8 @@ async function webhooks(openAPI, webhooks, components, readonly) {
|
|
|
2637
2690
|
const outDir = path.join(path.dirname(output), path.basename(output, ".ts"));
|
|
2638
2691
|
const e = (await Promise.all([...entries.map(async ({ name, code }) => {
|
|
2639
2692
|
const filePath = `${outDir}/${name}.ts`;
|
|
2640
|
-
const
|
|
2693
|
+
const withImports = makeImports(code, filePath, components);
|
|
2694
|
+
const result = await emit(withImports, path.dirname(filePath), filePath);
|
|
2641
2695
|
return result.ok ? {
|
|
2642
2696
|
ok: true,
|
|
2643
2697
|
value: filePath
|
|
@@ -2748,7 +2802,7 @@ function makeJob(openAPI, config) {
|
|
|
2748
2802
|
config.webhooks ? {
|
|
2749
2803
|
name: "webhooks",
|
|
2750
2804
|
output: config.webhooks.output,
|
|
2751
|
-
split: config.webhooks.split
|
|
2805
|
+
split: config.webhooks.split,
|
|
2752
2806
|
run: (output) => webhooks(openAPI, {
|
|
2753
2807
|
output,
|
|
2754
2808
|
split: config.webhooks?.split === true
|
|
@@ -2763,43 +2817,43 @@ function makeJob(openAPI, config) {
|
|
|
2763
2817
|
config.components?.schemas ? {
|
|
2764
2818
|
name: "schemas",
|
|
2765
2819
|
output: config.components.schemas.output,
|
|
2766
|
-
split: config.components.schemas.split
|
|
2820
|
+
split: config.components.schemas.split,
|
|
2767
2821
|
run: (output) => schemas(openAPI.components?.schemas, output, config.components?.schemas?.split === true, config.components?.schemas?.exportTypes === true, config.readonly)
|
|
2768
2822
|
} : void 0,
|
|
2769
2823
|
config.components?.parameters ? {
|
|
2770
2824
|
name: "parameters",
|
|
2771
2825
|
output: config.components.parameters.output,
|
|
2772
|
-
split: config.components.parameters.split
|
|
2826
|
+
split: config.components.parameters.split,
|
|
2773
2827
|
run: (output) => parameters(openAPI.components?.parameters, output, config.components?.parameters?.split === true, config.components?.parameters?.exportTypes === true, componentsResolve, config.readonly)
|
|
2774
2828
|
} : void 0,
|
|
2775
2829
|
config.components?.headers ? {
|
|
2776
2830
|
name: "headers",
|
|
2777
2831
|
output: config.components.headers.output,
|
|
2778
|
-
split: config.components.headers.split
|
|
2832
|
+
split: config.components.headers.split,
|
|
2779
2833
|
run: (output) => headers(openAPI.components?.headers, output, config.components?.headers?.split === true, config.components?.headers?.exportTypes === true, componentsResolve, config.readonly)
|
|
2780
2834
|
} : void 0,
|
|
2781
2835
|
config.components?.examples ? {
|
|
2782
2836
|
name: "examples",
|
|
2783
2837
|
output: config.components.examples.output,
|
|
2784
|
-
split: config.components.examples.split
|
|
2838
|
+
split: config.components.examples.split,
|
|
2785
2839
|
run: (output) => examples(openAPI.components?.examples, output, config.components?.examples?.split === true, config.readonly)
|
|
2786
2840
|
} : void 0,
|
|
2787
2841
|
config.components?.links ? {
|
|
2788
2842
|
name: "links",
|
|
2789
2843
|
output: config.components.links.output,
|
|
2790
|
-
split: config.components.links.split
|
|
2844
|
+
split: config.components.links.split,
|
|
2791
2845
|
run: (output) => links(openAPI.components?.links, output, config.components?.links?.split === true, config.readonly)
|
|
2792
2846
|
} : void 0,
|
|
2793
2847
|
config.components?.callbacks ? {
|
|
2794
2848
|
name: "callbacks",
|
|
2795
2849
|
output: config.components.callbacks.output,
|
|
2796
|
-
split: config.components.callbacks.split
|
|
2850
|
+
split: config.components.callbacks.split,
|
|
2797
2851
|
run: (output) => callbacks(openAPI.components?.callbacks, output, config.components?.callbacks?.split === true, componentsResolve, config.readonly)
|
|
2798
2852
|
} : void 0,
|
|
2799
2853
|
config.components?.pathItems ? {
|
|
2800
2854
|
name: "pathItems",
|
|
2801
2855
|
output: config.components.pathItems.output,
|
|
2802
|
-
split: config.components.pathItems.split
|
|
2856
|
+
split: config.components.pathItems.split,
|
|
2803
2857
|
run: (output) => pathItems(openAPI.components ?? {}, {
|
|
2804
2858
|
output,
|
|
2805
2859
|
split: config.components?.pathItems?.split === true
|
|
@@ -2808,31 +2862,31 @@ function makeJob(openAPI, config) {
|
|
|
2808
2862
|
config.components?.mediaTypes ? {
|
|
2809
2863
|
name: "mediaTypes",
|
|
2810
2864
|
output: config.components.mediaTypes.output,
|
|
2811
|
-
split: config.components.mediaTypes.split
|
|
2865
|
+
split: config.components.mediaTypes.split,
|
|
2812
2866
|
run: (output) => mediaTypes(openAPI.components?.mediaTypes, output, config.components?.mediaTypes?.split === true, config.readonly, componentsResolve)
|
|
2813
2867
|
} : void 0,
|
|
2814
2868
|
config.components?.securitySchemes ? {
|
|
2815
2869
|
name: "securitySchemes",
|
|
2816
2870
|
output: config.components.securitySchemes.output,
|
|
2817
|
-
split: config.components.securitySchemes.split
|
|
2871
|
+
split: config.components.securitySchemes.split,
|
|
2818
2872
|
run: (output) => securitySchemes(openAPI.components?.securitySchemes, output, config.components?.securitySchemes?.split === true, config.readonly)
|
|
2819
2873
|
} : void 0,
|
|
2820
2874
|
config.components?.requestBodies ? {
|
|
2821
2875
|
name: "requestBodies",
|
|
2822
2876
|
output: config.components.requestBodies.output,
|
|
2823
|
-
split: config.components.requestBodies.split
|
|
2877
|
+
split: config.components.requestBodies.split,
|
|
2824
2878
|
run: (output) => requestBodies(openAPI.components?.requestBodies, output, config.components?.requestBodies?.split === true, componentsResolve, config.readonly)
|
|
2825
2879
|
} : void 0,
|
|
2826
2880
|
config.components?.responses ? {
|
|
2827
2881
|
name: "responses",
|
|
2828
2882
|
output: config.components.responses.output,
|
|
2829
|
-
split: config.components.responses.split
|
|
2883
|
+
split: config.components.responses.split,
|
|
2830
2884
|
run: (output) => responses(openAPI.components?.responses, output, config.components?.responses?.split === true, componentsResolve, config.readonly)
|
|
2831
2885
|
} : void 0,
|
|
2832
2886
|
config.routes ? {
|
|
2833
2887
|
name: "routes",
|
|
2834
2888
|
output: config.routes.output,
|
|
2835
|
-
split: config.routes.split
|
|
2889
|
+
split: config.routes.split,
|
|
2836
2890
|
run: (output) => route(openAPI, {
|
|
2837
2891
|
output,
|
|
2838
2892
|
split: config.routes?.split === true
|
|
@@ -2850,7 +2904,7 @@ function makeJob(openAPI, config) {
|
|
|
2850
2904
|
config.rpc ? {
|
|
2851
2905
|
name: "rpc",
|
|
2852
2906
|
output: config.rpc.output,
|
|
2853
|
-
split: config.rpc.split
|
|
2907
|
+
split: config.rpc.split,
|
|
2854
2908
|
run: (output) => rpc(openAPI, output, config.rpc?.import ?? "", config.rpc?.split === true, config.rpc?.client ?? "client", config.rpc?.parseResponse ?? false, config.basePath, config.rpc?.docs ?? false)
|
|
2855
2909
|
} : void 0,
|
|
2856
2910
|
...[
|
|
@@ -2866,9 +2920,9 @@ function makeJob(openAPI, config) {
|
|
|
2866
2920
|
return cfg ? {
|
|
2867
2921
|
name: library,
|
|
2868
2922
|
output: cfg.output,
|
|
2869
|
-
split: cfg.split
|
|
2923
|
+
split: cfg.split,
|
|
2870
2924
|
run: (output) => hooks(openAPI, output, cfg.import, library, {
|
|
2871
|
-
split: cfg.split
|
|
2925
|
+
split: cfg.split,
|
|
2872
2926
|
clientName: cfg.client ?? "client"
|
|
2873
2927
|
})
|
|
2874
2928
|
} : void 0;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { parseConfig } from "../index.js";
|
|
2
2
|
import { r as setFormatOptions } from "../emit-CFR63U4L.js";
|
|
3
|
-
import { f as isRecord } from "../guard-
|
|
4
|
-
import { n as parseOpenAPI, t as makeJob } from "../shared-
|
|
3
|
+
import { f as isRecord } from "../guard-C_eRJ0au.js";
|
|
4
|
+
import { n as parseOpenAPI, t as makeJob } from "../shared-66qmwvRi.js";
|
|
5
5
|
import path from "node:path";
|
|
6
6
|
import fsp from "node:fs/promises";
|
|
7
7
|
import crypto from "node:crypto";
|
|
@@ -72,7 +72,7 @@ async function listWatchedInputFiles(directory) {
|
|
|
72
72
|
* "unknown" as "changed" and regenerate.
|
|
73
73
|
*/
|
|
74
74
|
async function hashWatchedInputs(directory) {
|
|
75
|
-
const files = [...await listWatchedInputFiles(directory)].
|
|
75
|
+
const files = [...await listWatchedInputFiles(directory)].toSorted();
|
|
76
76
|
if (files.length === 0) return null;
|
|
77
77
|
const contents = await Promise.all(files.map(async (file) => ({
|
|
78
78
|
file,
|
|
@@ -296,11 +296,11 @@ function honoTakibiVite() {
|
|
|
296
296
|
pluginState.lastInputHash = await hashWatchedInputs(inputDirectory);
|
|
297
297
|
server.watcher.add(absoluteConfigFilePath);
|
|
298
298
|
const debouncedRunGeneration = debounce(200, () => void enqueueRun(() => runIfInputsChanged(server)));
|
|
299
|
-
server.watcher.on("all",
|
|
299
|
+
server.watcher.on("all", (_eventType, filePath) => {
|
|
300
300
|
const absoluteChangedPath = path.resolve(filePath);
|
|
301
301
|
if (absoluteChangedPath === absoluteConfigFilePath) {
|
|
302
302
|
console.log("config changed (watch)");
|
|
303
|
-
|
|
303
|
+
enqueueRun(() => handleConfigurationChange(server));
|
|
304
304
|
return;
|
|
305
305
|
}
|
|
306
306
|
if (pluginState.inputDirectory && absoluteChangedPath.startsWith(pluginState.inputDirectory) && isWatchedInputFile(absoluteChangedPath)) debouncedRunGeneration();
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "hono-takibi",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.99997",
|
|
4
4
|
"description": "Hono Takibi is a code generator from OpenAPI to @hono/zod-openapi",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"hono",
|
|
@@ -32,10 +32,6 @@
|
|
|
32
32
|
"types": "./dist/vite-plugin/index.d.ts",
|
|
33
33
|
"import": "./dist/vite-plugin/index.js"
|
|
34
34
|
},
|
|
35
|
-
"./config": {
|
|
36
|
-
"types": "./dist/config/index.d.ts",
|
|
37
|
-
"import": "./dist/config/index.js"
|
|
38
|
-
},
|
|
39
35
|
"./zod-openapi-hono": {
|
|
40
36
|
"types": "./dist/generator/zod-openapi-hono/openapi/index.d.ts",
|
|
41
37
|
"import": "./dist/generator/zod-openapi-hono/openapi/index.js"
|
|
@@ -79,8 +75,7 @@
|
|
|
79
75
|
"@typespec/versioning": "^0.84.0",
|
|
80
76
|
"@typespec/xml": "^0.84.0",
|
|
81
77
|
"hono": "^4.12.32",
|
|
82
|
-
"tsdown": "0.22.14"
|
|
83
|
-
"zod": "^4.0.0"
|
|
78
|
+
"tsdown": "0.22.14"
|
|
84
79
|
},
|
|
85
80
|
"scripts": {
|
|
86
81
|
"build": "tsdown"
|
package/dist/config/index.js
DELETED