hono-takibi 0.25.0 → 0.26.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/README.md +3 -1
- package/dist/cli.js +14 -9
- package/dist/{constants-CxrXPVxh.js → constants-hwmOoQfI.js} +22 -1
- package/dist/core/docs/index.js +1 -1
- package/dist/core/hooks/index.d.ts +1 -1
- package/dist/core/hooks/index.js +1 -1
- package/dist/core/rpc/index.d.ts +1 -1
- package/dist/core/rpc/index.js +6 -6
- package/dist/core/type/index.js +2 -2
- package/dist/{core-rnNgBu4D.js → core-FnayWJZV.js} +18 -18
- package/dist/{docs-BApYjFQG.js → docs-D8ivFJrR.js} +2 -2
- package/dist/generator/zod-openapi-hono/openapi/index.js +1 -1
- package/dist/{hooks-RrTkHWCS.js → hooks-DJHtFXnM.js} +28 -28
- package/dist/{index-CtUxilW-.d.ts → index-BNrSddFB.d.ts} +11 -4
- package/dist/{index-j7o04Qt1.d.ts → index-D3apEdjU.d.ts} +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +5 -4
- package/dist/{openapi-CuyeukCF.js → openapi-CU23GKuM.js} +231 -70
- package/dist/{rpc-BOAnGH-n.js → rpc-CSZ3hBkn.js} +2 -2
- package/dist/{shared-Tq3KgO4s.js → shared-BvbKZMJK.js} +18 -5
- package/dist/{utils-v71BPo5C.js → utils-Bw0Q2Ozg.js} +60 -2
- package/dist/vite-plugin/index.js +10 -5
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -21,7 +21,7 @@ From one document it can generate:
|
|
|
21
21
|
npm install -D hono-takibi
|
|
22
22
|
```
|
|
23
23
|
|
|
24
|
-
Pass an OpenAPI (`.yaml`, `.json`) or TypeSpec (`.tsp`) document and an output file:
|
|
24
|
+
Pass an OpenAPI (`.yaml`, `.yml`, `.json`) or TypeSpec (`.tsp`) document and an output file:
|
|
25
25
|
|
|
26
26
|
```bash
|
|
27
27
|
npx hono-takibi openapi.yaml -o src/routes.ts
|
|
@@ -38,6 +38,8 @@ export default defineConfig({
|
|
|
38
38
|
})
|
|
39
39
|
```
|
|
40
40
|
|
|
41
|
+
`input` also takes an `http(s)` URL, with or without a file extension: a remote document is read by its content.
|
|
42
|
+
|
|
41
43
|
```bash
|
|
42
44
|
npx hono-takibi
|
|
43
45
|
```
|
package/dist/cli.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
|
-
import {
|
|
2
|
+
import { h as isInputPath, u as INPUT_EXTENSIONS } from "./constants-hwmOoQfI.js";
|
|
3
3
|
import * as NodeRuntime from "@effect/platform-node/NodeRuntime";
|
|
4
4
|
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
|
//#region package.json
|
|
8
|
-
var version = "0.
|
|
8
|
+
var version = "0.26.0";
|
|
9
9
|
var description = "Hono Takibi is a code generator from OpenAPI to @hono/zod-openapi";
|
|
10
10
|
//#endregion
|
|
11
11
|
//#region src/cli/index.ts
|
|
12
12
|
const COMMAND_NAME = "hono-takibi";
|
|
13
13
|
const DEFAULT_CONFIG_FILE = "hono-takibi.config.ts";
|
|
14
|
-
const DocumentPathSchema = Schema.String.pipe(Schema.refine(
|
|
14
|
+
const DocumentPathSchema = Schema.String.pipe(Schema.refine(isInputPath, { message: "an OpenAPI (.yaml, .yml, .json) or TypeSpec (.tsp) document" })).annotate({
|
|
15
15
|
title: "Input document",
|
|
16
16
|
description: "OpenAPI or TypeSpec document the one-shot mode generates from.",
|
|
17
17
|
examples: [
|
|
@@ -39,12 +39,12 @@ function loadConfig(configPath, reload) {
|
|
|
39
39
|
}
|
|
40
40
|
function runJobs(config) {
|
|
41
41
|
return Effect.gen(function* () {
|
|
42
|
-
const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob, packageRoots }] = yield* Effect.promise(() => Promise.all([
|
|
42
|
+
const [{ parseOpenAPI }, { FormatOptions }, { cleanSplitOutputs, makeJob, openAPI3, packageRoots }] = yield* Effect.promise(() => Promise.all([
|
|
43
43
|
import("./openapi-t_u-tF52.js").then((n) => n.t),
|
|
44
44
|
import("./format-CuHABcKC.js").then((n) => n.r),
|
|
45
|
-
import("./shared-
|
|
45
|
+
import("./shared-BvbKZMJK.js").then((n) => n.o)
|
|
46
46
|
]));
|
|
47
|
-
const openAPI = yield* parseOpenAPI(config.input);
|
|
47
|
+
const openAPI = yield* openAPI3(yield* parseOpenAPI(config.input), config.input);
|
|
48
48
|
const jobs = makeJob(openAPI, config, yield* packageRoots(openAPI, config));
|
|
49
49
|
yield* cleanSplitOutputs(jobs.filter((job) => job.split).map((job) => job.output));
|
|
50
50
|
return (yield* Effect.forEach(jobs, (job) => job.run(job.output), { concurrency: "unbounded" }).pipe(Effect.provideService(FormatOptions, config.format ?? {}))).filter((message) => message !== "").join("\n");
|
|
@@ -80,7 +80,7 @@ function reportJobs(config, previous) {
|
|
|
80
80
|
onFailure: (error) => Console.error(`❌ ${error.message}`),
|
|
81
81
|
onSuccess: (report) => Console.log(report)
|
|
82
82
|
}));
|
|
83
|
-
const { outsideSources } = yield* Effect.promise(() => import("./shared-
|
|
83
|
+
const { outsideSources } = yield* Effect.promise(() => import("./shared-BvbKZMJK.js").then((n) => n.o));
|
|
84
84
|
const inputDirectory = path.dirname(path.resolve(config.input));
|
|
85
85
|
return {
|
|
86
86
|
inputDirectory,
|
|
@@ -207,8 +207,13 @@ function generate(args) {
|
|
|
207
207
|
})]
|
|
208
208
|
});
|
|
209
209
|
if (input !== void 0 && output !== void 0) {
|
|
210
|
-
const [{ parseOpenAPI }, { takibi }] = yield* Effect.promise(() => Promise.all([
|
|
211
|
-
|
|
210
|
+
const [{ parseOpenAPI }, { takibi }, { openAPI3 }] = yield* Effect.promise(() => Promise.all([
|
|
211
|
+
import("./openapi-t_u-tF52.js").then((n) => n.t),
|
|
212
|
+
import("./core-FnayWJZV.js").then((n) => n.t),
|
|
213
|
+
import("./shared-BvbKZMJK.js").then((n) => n.o)
|
|
214
|
+
]));
|
|
215
|
+
const document = yield* openAPI3(yield* parseOpenAPI(input), input);
|
|
216
|
+
return yield* Console.log(yield* takibi(document, output));
|
|
212
217
|
}
|
|
213
218
|
const resolvedConfig = configPath ?? DEFAULT_CONFIG_FILE;
|
|
214
219
|
if (args.watch) return yield* watchConfig(resolvedConfig, yield* reportConfigPass(resolvedConfig, false, void 0));
|
|
@@ -13,6 +13,23 @@ const COMPONENT_NAMES = [
|
|
|
13
13
|
"pathItems",
|
|
14
14
|
"mediaTypes"
|
|
15
15
|
];
|
|
16
|
+
/**
|
|
17
|
+
* What the identifier of a component is suffixed with, by section: `#/components/schemas/User`
|
|
18
|
+
* is `UserSchema`. A security scheme is named by `security` requirements, not by `$ref`.
|
|
19
|
+
*/
|
|
20
|
+
const COMPONENT_SUFFIXES = {
|
|
21
|
+
schemas: "Schema",
|
|
22
|
+
parameters: "ParamsSchema",
|
|
23
|
+
headers: "HeaderSchema",
|
|
24
|
+
securitySchemes: "SecurityScheme",
|
|
25
|
+
requestBodies: "RequestBody",
|
|
26
|
+
responses: "Response",
|
|
27
|
+
examples: "Example",
|
|
28
|
+
links: "Link",
|
|
29
|
+
callbacks: "Callback",
|
|
30
|
+
pathItems: "PathItem",
|
|
31
|
+
mediaTypes: "MediaTypeSchema"
|
|
32
|
+
};
|
|
16
33
|
/** The extensions of an input document: OpenAPI as YAML (`.yaml` or `.yml`) or JSON, or a TypeSpec entry. */
|
|
17
34
|
const INPUT_EXTENSIONS = [
|
|
18
35
|
".yaml",
|
|
@@ -20,6 +37,10 @@ const INPUT_EXTENSIONS = [
|
|
|
20
37
|
".json",
|
|
21
38
|
".tsp"
|
|
22
39
|
];
|
|
40
|
+
/** An input document by its extension, or an `http(s)` URL to one (see `InputPath`). */
|
|
41
|
+
function isInputPath(v) {
|
|
42
|
+
return typeof v === "string" && (INPUT_EXTENSIONS.some((extension) => v.endsWith(extension)) || /^https?:\/\//u.test(v));
|
|
43
|
+
}
|
|
23
44
|
/** A JavaScript identifier that can be written bare: as a binding, or a key or member access. */
|
|
24
45
|
const IDENTIFIER_PATTERN = /^[A-Za-z_$][A-Za-z0-9_$]*$/u;
|
|
25
46
|
/**
|
|
@@ -79,4 +100,4 @@ const HTTP_METHODS = [
|
|
|
79
100
|
"query"
|
|
80
101
|
];
|
|
81
102
|
//#endregion
|
|
82
|
-
export {
|
|
103
|
+
export { FORM_MEDIA_TYPES as a, HTTP_METHODS as c, JSON_MEDIA_TYPE as d, MULTIPART_MEDIA_TYPE as f, isInputPath as h, COMPONENT_SUFFIXES as i, IDENTIFIER_PATTERN as l, TEXT_MEDIA_TYPE as m, COMPONENT_NAMES as n, FORM_URLENCODED_MEDIA_TYPE as o, OCTET_STREAM_MEDIA_TYPE as p, COMPONENT_REF_PREFIX as r, HOOK_LIBRARIES as s, ARROW_FUNCTION_PATTERN as t, INPUT_EXTENSIONS as u };
|
package/dist/core/docs/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as docs } from "../../docs-
|
|
1
|
+
export { t as docs } from "../../docs-D8ivFJrR.js";
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as OpenAPI } from "../../index-B3ze4n_I.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-D3apEdjU.js";
|
|
4
4
|
//#region src/core/hooks/index.d.ts
|
|
5
5
|
declare const HOOK_CONFIGS: {
|
|
6
6
|
readonly swr: {
|
package/dist/core/hooks/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as hooks } from "../../hooks-
|
|
1
|
+
export { t as hooks } from "../../hooks-DJHtFXnM.js";
|
package/dist/core/rpc/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { t as OpenAPI } from "../../index-B3ze4n_I.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-D3apEdjU.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,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as HTTP_METHODS } from "../../constants-hwmOoQfI.js";
|
|
2
2
|
import { i as GenerateError } from "../../format-CuHABcKC.js";
|
|
3
|
-
import {
|
|
4
|
-
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "../../rpc-
|
|
3
|
+
import { V as isOperationLike, Y as isRecord, _ as routeName, u as makeInferRequestType, z as isOpenAPIPaths } from "../../utils-Bw0Q2Ozg.js";
|
|
4
|
+
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "../../rpc-CSZ3hBkn.js";
|
|
5
5
|
import { t as emit } from "../../emit-uwlZZeRM.js";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
import { dirname } from "node:path";
|
|
@@ -21,7 +21,7 @@ function makeJsDoc(operation, method, path) {
|
|
|
21
21
|
sections.push([`${method.toUpperCase()} ${path}`]);
|
|
22
22
|
return `/**\n${sections.map((lines) => lines.join("\n")).join("\n\n").split("\n").map((line) => line ? ` * ${line}` : " *").join("\n")}\n */\n`;
|
|
23
23
|
}
|
|
24
|
-
function makeOperationCode(path, method, item, base, useParseResponse, hasBasePath, docs, grouping) {
|
|
24
|
+
function makeOperationCode(paths, path, method, item, base, useParseResponse, hasBasePath, docs, grouping) {
|
|
25
25
|
const operation = item[method];
|
|
26
26
|
if (!isOperationLike(operation)) return null;
|
|
27
27
|
const group = grouping?.(path, operationTags(operation));
|
|
@@ -29,7 +29,7 @@ function makeOperationCode(path, method, item, base, useParseResponse, hasBasePa
|
|
|
29
29
|
...base,
|
|
30
30
|
client: makeGroupClientName(group)
|
|
31
31
|
};
|
|
32
|
-
const funcName =
|
|
32
|
+
const funcName = routeName(method, path, paths);
|
|
33
33
|
const pathResult = formatPath(path, hasBasePath);
|
|
34
34
|
const hasArgs = operationHasArgs(item, operation, deps);
|
|
35
35
|
const inferType = makeInferRequestType(deps.client, pathResult, method);
|
|
@@ -45,7 +45,7 @@ function makeOperationCode(path, method, item, base, useParseResponse, hasBasePa
|
|
|
45
45
|
function makeOperationCodes(paths, deps, useParseResponse, hasBasePath, docs, grouping) {
|
|
46
46
|
return Object.entries(paths).filter((entry) => isRecord(entry[1])).flatMap(([p, rawItem]) => {
|
|
47
47
|
const pathItem = parsePathItem(rawItem);
|
|
48
|
-
return HTTP_METHODS.map((method) => makeOperationCode(p, method, pathItem, deps, useParseResponse, hasBasePath, docs, grouping)).filter((item) => item !== null);
|
|
48
|
+
return HTTP_METHODS.map((method) => makeOperationCode(paths, p, method, pathItem, deps, useParseResponse, hasBasePath, docs, grouping)).filter((item) => item !== null);
|
|
49
49
|
});
|
|
50
50
|
}
|
|
51
51
|
function makeHeader(importPath, needsInferRequestType, clientNames, useParseResponse) {
|
package/dist/core/type/index.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import "../../constants-
|
|
2
|
-
import {
|
|
1
|
+
import "../../constants-hwmOoQfI.js";
|
|
2
|
+
import { B as isOperation, H as isParameter, L as isMediaWithSchema, N as isHttpMethod, Q as isRequestBody, U as isParameterArray, d as makeSafeKey, et as isSchemaArray, ot as isStringRef, v as statusCodeToNumber, y as toIdentifierPascalCase, z as isOpenAPIPaths } from "../../utils-Bw0Q2Ozg.js";
|
|
3
3
|
import { t as emit } from "../../emit-uwlZZeRM.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import path from "node:path";
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
-
import {
|
|
2
|
+
import { c as HTTP_METHODS, d as JSON_MEDIA_TYPE, m as TEXT_MEDIA_TYPE, n as COMPONENT_NAMES, r as COMPONENT_REF_PREFIX } from "./constants-hwmOoQfI.js";
|
|
3
3
|
import { i as GenerateError, n as fmt } from "./format-CuHABcKC.js";
|
|
4
|
-
import {
|
|
5
|
-
import { A as resolvePathItem, C as makeCallback, D as makeRouteProperties, E as makeRouteEntries, O as makeWebhookEntries, S as zodToOpenAPI, T as makeRef, _ as descendantsWhere, a as responsesCode, b as parseSource, c as headersCode, d as makeExportConst, f as makeImports, g as declarationOf, h as ast, i as schemasCode, k as resolveParameter, 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 identifierNames, w as makePathItem, x as textOf, y as parseModule } from "./openapi-
|
|
6
|
-
import { a as entryNames, c as makeGroupClientName, l as operationTags, o as freeName, s as groupNameOf } from "./rpc-
|
|
4
|
+
import { A as isCallbacks, B as isOperation, D as hasNumericConstraint, F as isInlineMedia, H as isParameter, J as isPathItemRef, K as isPathItem, L as isMediaWithSchema, N as isHttpMethod, O as hasRequestBodyContent, S as zodToOpenAPISchema, X as isRefObject, _ as routeName, a as ensureSuffix, b as uncapitalize, c as escapeRegexLiteral, d as makeSafeKey, et as isSchemaArray, f as makeStringLiteral, h as renderNamedImport, it as isSecurityScheme, l as makeBarrel, p as normalizeTypes, q as isPathItemEntry, r as cyclicNodes, rt as isSecurityArray, st as isValidIdent, tt as isSchemaObject, v as statusCodeToNumber, x as uncapitalizeWord, y as toIdentifierPascalCase, z as isOpenAPIPaths } from "./utils-Bw0Q2Ozg.js";
|
|
5
|
+
import { A as resolvePathItem, C as makeCallback, D as makeRouteProperties, E as makeRouteEntries, O as makeWebhookEntries, S as zodToOpenAPI, T as makeRef, _ as descendantsWhere, a as responsesCode, b as parseSource, c as headersCode, d as makeExportConst, f as makeImports, g as declarationOf, h as ast, i as schemasCode, k as resolveParameter, 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 identifierNames, w as makePathItem, x as textOf, y as parseModule } from "./openapi-CU23GKuM.js";
|
|
6
|
+
import { a as entryNames, c as makeGroupClientName, l as operationTags, o as freeName, s as groupNameOf } from "./rpc-CSZ3hBkn.js";
|
|
7
7
|
import { i as readdir, n as mkdir, o as writeFile, r as readFile } from "./file-K6j5IJXi.js";
|
|
8
8
|
import { t as emit } from "./emit-uwlZZeRM.js";
|
|
9
|
-
import { t as hooks } from "./hooks-
|
|
10
|
-
import { t as docs } from "./docs-
|
|
9
|
+
import { t as hooks } from "./hooks-DJHtFXnM.js";
|
|
10
|
+
import { t as docs } from "./docs-D8ivFJrR.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";
|
|
@@ -629,7 +629,7 @@ function defineEntries(openapi, readonly) {
|
|
|
629
629
|
} : operation;
|
|
630
630
|
const properties = makeRouteProperties(path, method, effective, readonly, openapi.components?.schemas);
|
|
631
631
|
const asConst = readonly ? " as const" : "";
|
|
632
|
-
const entryName =
|
|
632
|
+
const entryName = routeName(method, path, openapi.paths);
|
|
633
633
|
return [{
|
|
634
634
|
name: entryName,
|
|
635
635
|
path,
|
|
@@ -1386,24 +1386,24 @@ function makePaths(output, pathAlias, routeImport) {
|
|
|
1386
1386
|
importFrom: routeImport ?? (aliasPrefix ? `${aliasPrefix}/${routeModuleName}` : `../${routeModuleName}`)
|
|
1387
1387
|
};
|
|
1388
1388
|
}
|
|
1389
|
-
function makeHandlerInfo(path, method, operation, existing, member, body) {
|
|
1390
|
-
const routeId =
|
|
1389
|
+
function makeHandlerInfo(paths, path, method, operation, existing, member, body) {
|
|
1390
|
+
const routeId = routeName(method, path, paths);
|
|
1391
1391
|
return {
|
|
1392
1392
|
fileName: resolveHandlerFileName(makeHandlerFileName(path, operation.tags), `${routeId}${member}`, existing),
|
|
1393
1393
|
contents: [body(routeId)],
|
|
1394
1394
|
routeNames: [`${routeId}Route`]
|
|
1395
1395
|
};
|
|
1396
1396
|
}
|
|
1397
|
-
function makeInlineStubHandlerInfo(path, method, operation, existing) {
|
|
1398
|
-
return makeHandlerInfo(path, method, operation, existing, "Route", (routeId) => `.openapi(${routeId}Route,(c)=>{})`);
|
|
1397
|
+
function makeInlineStubHandlerInfo(paths, path, method, operation, existing) {
|
|
1398
|
+
return makeHandlerInfo(paths, path, method, operation, existing, "Route", (routeId) => `.openapi(${routeId}Route,(c)=>{})`);
|
|
1399
1399
|
}
|
|
1400
1400
|
function makeInlineStubFileContent(handler, importFrom) {
|
|
1401
1401
|
const exportName = `${basename(handler.fileName, ".ts")}Handler`;
|
|
1402
1402
|
const routeImports = [...new Set(handler.routeNames)].join(", ");
|
|
1403
1403
|
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")}`;
|
|
1404
1404
|
}
|
|
1405
|
-
function makeStubHandlerInfo(path, method, operation, existing) {
|
|
1406
|
-
return makeHandlerInfo(path, method, operation, existing, "RouteHandler", (routeId) => `export const ${routeId}RouteHandler:RouteHandler<typeof ${routeId}Route>=async(c)=>{}`);
|
|
1405
|
+
function makeStubHandlerInfo(paths, path, method, operation, existing) {
|
|
1406
|
+
return makeHandlerInfo(paths, path, method, operation, existing, "RouteHandler", (routeId) => `export const ${routeId}RouteHandler:RouteHandler<typeof ${routeId}Route>=async(c)=>{}`);
|
|
1407
1407
|
}
|
|
1408
1408
|
function makeMergedHandlers(handlers) {
|
|
1409
1409
|
const handlerMap = /* @__PURE__ */ new Map();
|
|
@@ -1467,7 +1467,7 @@ function zodOpenAPIHonoHandler(openapi, output, pathAlias, routeImport, routeHan
|
|
|
1467
1467
|
const paths = openapi.paths;
|
|
1468
1468
|
const { handlerPath, importFrom } = makePaths(output, pathAlias, routeImport);
|
|
1469
1469
|
const existing = yield* scanExistingHandlerFiles(handlerPath, routeHandler ? (code) => collectExportedNames(code, "RouteHandler") : collectInlineRouteNames);
|
|
1470
|
-
const specHandlers = makeMergedHandlers(Object.entries(paths).flatMap(([path, pathItem]) => Object.entries(pathItem).filter((entry) => isHttpMethod(entry[0]) && isOperation(entry[1])).map(([method, operation]) => routeHandler ? makeStubHandlerInfo(path, method, operation, existing) : makeInlineStubHandlerInfo(path, method, operation, existing))));
|
|
1470
|
+
const specHandlers = makeMergedHandlers(Object.entries(paths).flatMap(([path, pathItem]) => Object.entries(pathItem).filter((entry) => isHttpMethod(entry[0]) && isOperation(entry[1])).map(([method, operation]) => routeHandler ? makeStubHandlerInfo(paths, path, method, operation, existing) : makeInlineStubHandlerInfo(paths, path, method, operation, existing))));
|
|
1471
1471
|
const handlers = [...specHandlers, ...makeOrphanHandlers(existing, specHandlers.map((h) => h.fileName))];
|
|
1472
1472
|
yield* mkdir(handlerPath);
|
|
1473
1473
|
yield* Effect.all([...handlers.map((handler) => writeHandler({
|
|
@@ -1487,7 +1487,7 @@ function resolveInlineHandlerFileNames(openapi, output, pathAlias, routeImport)
|
|
|
1487
1487
|
return Effect.gen(function* () {
|
|
1488
1488
|
const { handlerPath } = makePaths(output, pathAlias, routeImport);
|
|
1489
1489
|
const existing = yield* scanExistingHandlerFiles(handlerPath, collectInlineRouteNames);
|
|
1490
|
-
const fileNames = Object.entries(openapi.paths).flatMap(([path, pathItem]) => Object.entries(pathItem).filter((entry) => isHttpMethod(entry[0]) && isOperation(entry[1])).map(([method, operation]) => resolveHandlerFileName(makeHandlerFileName(path, operation.tags), `${
|
|
1490
|
+
const fileNames = Object.entries(openapi.paths).flatMap(([path, pathItem]) => Object.entries(pathItem).filter((entry) => isHttpMethod(entry[0]) && isOperation(entry[1])).map(([method, operation]) => resolveHandlerFileName(makeHandlerFileName(path, operation.tags), `${routeName(method, path, openapi.paths)}Route`, existing)));
|
|
1491
1491
|
return [...new Set(fileNames)];
|
|
1492
1492
|
});
|
|
1493
1493
|
}
|
|
@@ -2356,7 +2356,7 @@ function makeMock(openapi, basePath, options = {}) {
|
|
|
2356
2356
|
const allRefs = /* @__PURE__ */ new Set();
|
|
2357
2357
|
const processed = Object.entries(paths).flatMap(([p, pathItem]) => Object.entries(pathItem).flatMap(([method, operation]) => {
|
|
2358
2358
|
if (!(isHttpMethod(method) && isOperation(operation))) return [];
|
|
2359
|
-
const routeId =
|
|
2359
|
+
const routeId = routeName(method, p, paths);
|
|
2360
2360
|
const security = extractSecurityInfo(isSecurityArray(operation.security) ? operation.security : void 0, isSecurityArray(openapi.security) ? openapi.security : void 0, securitySchemes);
|
|
2361
2361
|
const requiresAuth = security.length > 0;
|
|
2362
2362
|
const success = resolveSuccessResponse(operation.responses, componentResponses);
|
|
@@ -2547,8 +2547,8 @@ function app(openapi, output, basePath, pathAlias, routeImport, routeHandler = f
|
|
|
2547
2547
|
return Object.entries(paths).flatMap(([path, pathItem]) => Object.entries(pathItem).flatMap(([method]) => {
|
|
2548
2548
|
if (!isHttpMethod(method)) return [];
|
|
2549
2549
|
return {
|
|
2550
|
-
routeName: `${
|
|
2551
|
-
handlerName: `${
|
|
2550
|
+
routeName: `${routeName(method, path, paths)}Route`,
|
|
2551
|
+
handlerName: `${routeName(method, path, paths)}RouteHandler`,
|
|
2552
2552
|
path
|
|
2553
2553
|
};
|
|
2554
2554
|
}));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { c as HTTP_METHODS, f as MULTIPART_MEDIA_TYPE } from "./constants-hwmOoQfI.js";
|
|
2
|
+
import { X as isRefObject, Y as isRecord, et as isSchemaArray, i as decodePercent, s as escapeHtml } from "./utils-Bw0Q2Ozg.js";
|
|
3
3
|
import { n as mkdir, o as writeFile } from "./file-K6j5IJXi.js";
|
|
4
4
|
import { Effect } from "effect";
|
|
5
5
|
import path from "node:path";
|
|
@@ -1 +1 @@
|
|
|
1
|
-
export { t as zodOpenAPIHono } from "../../../openapi-
|
|
1
|
+
export { t as zodOpenAPIHono } from "../../../openapi-CU23GKuM.js";
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as HTTP_METHODS } from "./constants-hwmOoQfI.js";
|
|
2
2
|
import { i as GenerateError } from "./format-CuHABcKC.js";
|
|
3
|
-
import {
|
|
4
|
-
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "./rpc-
|
|
3
|
+
import { V as isOperationLike, Y as isRecord, _ as routeName, n as capitalize, w as hasNoContentResponse, y as toIdentifierPascalCase, z as isOpenAPIPaths } from "./utils-Bw0Q2Ozg.js";
|
|
4
|
+
import { c as makeGroupClientName, i as parsePathItem, l as operationTags, n as makeOperationDeps, r as operationHasArgs, t as formatPath } from "./rpc-CSZ3hBkn.js";
|
|
5
5
|
import { t as emit } from "./emit-uwlZZeRM.js";
|
|
6
6
|
import { Effect } from "effect";
|
|
7
7
|
import path from "node:path";
|
|
@@ -26,8 +26,8 @@ const VUE_MUTATION_MEMBER = `{mutationFn?:unknown}`;
|
|
|
26
26
|
function makeOmitInjectedKeys(optionsType, keys, vueMember) {
|
|
27
27
|
return `Omit<${vueMember ? `Extract<${optionsType},${vueMember}>` : optionsType},${keys}>`;
|
|
28
28
|
}
|
|
29
|
-
function makeHookName(method, pathStr, prefix) {
|
|
30
|
-
const funcName =
|
|
29
|
+
function makeHookName(method, pathStr, prefix, paths) {
|
|
30
|
+
const funcName = routeName(method, pathStr, paths);
|
|
31
31
|
return `${prefix}${capitalize(funcName)}`;
|
|
32
32
|
}
|
|
33
33
|
function makeRuntimeAccess(clientName, method, pathStr, hasBasePath = false) {
|
|
@@ -46,20 +46,20 @@ function makeArgsType(clientName, method, pathStr, hasBasePath = false) {
|
|
|
46
46
|
function queryNameMethod(method) {
|
|
47
47
|
return method === "get" ? "" : method;
|
|
48
48
|
}
|
|
49
|
-
function makeQueryKeyGetterName(method, pathStr, isSWR) {
|
|
50
|
-
if (isSWR) return `get${capitalize(
|
|
51
|
-
return `get${capitalize(
|
|
49
|
+
function makeQueryKeyGetterName(method, pathStr, paths, isSWR) {
|
|
50
|
+
if (isSWR) return `get${capitalize(routeName(method, pathStr, paths))}Key`;
|
|
51
|
+
return `get${capitalize(routeName(queryNameMethod(method), pathStr, paths))}QueryKey`;
|
|
52
52
|
}
|
|
53
|
-
function makeMutationKeyGetterName(method, pathStr, isSWR) {
|
|
54
|
-
if (isSWR) return `get${capitalize(
|
|
55
|
-
return `get${capitalize(
|
|
53
|
+
function makeMutationKeyGetterName(method, pathStr, paths, isSWR) {
|
|
54
|
+
if (isSWR) return `get${capitalize(routeName(method, pathStr, paths))}Key`;
|
|
55
|
+
return `get${capitalize(routeName(method, pathStr, paths))}MutationKey`;
|
|
56
56
|
}
|
|
57
57
|
function makeMutationKeyGetterCode(keyGetterName, method, honoPath) {
|
|
58
58
|
return `export function ${keyGetterName}(){return['${honoPath.replace(/^\//u, "").split("/")[0]}','${honoPath}','${method.toUpperCase()}']as const}`;
|
|
59
59
|
}
|
|
60
|
-
function makeInfiniteQueryKeyGetterName(method, pathStr, isSWR) {
|
|
61
|
-
if (isSWR) return `get${capitalize(
|
|
62
|
-
return `get${capitalize(
|
|
60
|
+
function makeInfiniteQueryKeyGetterName(method, pathStr, paths, isSWR) {
|
|
61
|
+
if (isSWR) return `get${capitalize(routeName(method, pathStr, paths))}InfiniteKey`;
|
|
62
|
+
return `get${capitalize(routeName(queryNameMethod(method), pathStr, paths))}InfiniteQueryKey`;
|
|
63
63
|
}
|
|
64
64
|
function makeVueReactiveKey(keyCall) {
|
|
65
65
|
return `computed(()=>${keyCall})`;
|
|
@@ -382,16 +382,16 @@ function makeMutationHookCode(hookName, optionsGetterName, hasArgs, argsType, re
|
|
|
382
382
|
if (config.useThunk) return `export function ${hookName}${tErrorGeneric}(options?:()=>${optionsType}${tail.sig}){return ${config.mutationFn}(()=>{const{mutation,options:clientOptions}=options?.()??{};const mutationDefaults=${factoryCall};return{...mutation,...mutationDefaults,mutationKey:mutation?.mutationKey??mutationDefaults.mutationKey}}${tail.arg})}`;
|
|
383
383
|
return `export function ${hookName}${tErrorGeneric}(options?:${optionsType}${tail.sig}){const{mutation:mutationOptions,options:clientOptions}=options??{};const mutationDefaults=${factoryCall};return ${config.mutationFn}({...mutationOptions,...mutationDefaults,mutationKey:mutationOptions?.mutationKey??mutationDefaults.mutationKey}${tail.arg})}`;
|
|
384
384
|
}
|
|
385
|
-
function makeHookCode(pathStr, method, item, deps, config, clientName, hasBasePath = false) {
|
|
385
|
+
function makeHookCode(paths, pathStr, method, item, deps, config, clientName, hasBasePath = false) {
|
|
386
386
|
const op = item[method];
|
|
387
387
|
if (!isOperationLike(op)) return null;
|
|
388
|
-
const hookName = makeHookName(method, pathStr, config.hookPrefix);
|
|
388
|
+
const hookName = makeHookName(method, pathStr, config.hookPrefix, paths);
|
|
389
389
|
const hasArgs = operationHasArgs(item, op, deps);
|
|
390
390
|
const isQuery = method === "get" || method === "query";
|
|
391
391
|
const hasPagination = op["x-pagination"] === true;
|
|
392
392
|
const params = [...deps.toParameterLikes(item.parameters), ...deps.toParameterLikes(op.parameters)];
|
|
393
393
|
const excludedArgs = KEY_EXCLUDED_ARGS.filter((kind) => params.some((p) => p.in === kind));
|
|
394
|
-
const operationFileName =
|
|
394
|
+
const operationFileName = routeName(method, pathStr, paths);
|
|
395
395
|
const argsType = makeArgsType(clientName, method, pathStr, hasBasePath);
|
|
396
396
|
const runtimeAccess = makeRuntimeAccess(clientName, method, pathStr, hasBasePath);
|
|
397
397
|
const responseType = makeResponseTypeFromClient(clientName, method, pathStr, hasBasePath);
|
|
@@ -399,12 +399,12 @@ function makeHookCode(pathStr, method, item, deps, config, clientName, hasBasePa
|
|
|
399
399
|
const honoPath = pathStr.replaceAll(/\{([^}]+)\}/gu, ":$1");
|
|
400
400
|
if (config.isSWR) {
|
|
401
401
|
if (isQuery) {
|
|
402
|
-
const keyGetterName = makeQueryKeyGetterName(method, pathStr, true);
|
|
402
|
+
const keyGetterName = makeQueryKeyGetterName(method, pathStr, paths, true);
|
|
403
403
|
const keyGetterCode = makeQueryKeyGetterCode(keyGetterName, hasArgs, argsType, honoPath, config, excludedArgs, method);
|
|
404
404
|
const hookCode = makeSWRQueryHookCode(hookName, keyGetterName, hasArgs, argsType, runtimeAccess, responseType, config.queryFn, config.errorType);
|
|
405
405
|
const immutableHookName = `${config.hookPrefix}Immutable${capitalize(operationFileName)}`;
|
|
406
406
|
const immutableHookCode = config.immutableQueryFn ? makeSWRQueryHookCode(immutableHookName, keyGetterName, hasArgs, argsType, runtimeAccess, responseType, config.immutableQueryFn, config.errorType) : null;
|
|
407
|
-
const infiniteKeyGetterName = makeInfiniteQueryKeyGetterName(method, pathStr, true);
|
|
407
|
+
const infiniteKeyGetterName = makeInfiniteQueryKeyGetterName(method, pathStr, paths, true);
|
|
408
408
|
const infiniteKeyGetterCode = hasPagination ? makeInfiniteQueryKeyGetterCode(infiniteKeyGetterName, hasArgs, argsType, honoPath, config, excludedArgs, method) : null;
|
|
409
409
|
const infiniteHookName = `${config.hookPrefix}Infinite${capitalize(operationFileName)}`;
|
|
410
410
|
return {
|
|
@@ -421,7 +421,7 @@ function makeHookCode(pathStr, method, item, deps, config, clientName, hasBasePa
|
|
|
421
421
|
operationFileName
|
|
422
422
|
};
|
|
423
423
|
}
|
|
424
|
-
const mutationKeyGetterName = makeMutationKeyGetterName(method, pathStr, true);
|
|
424
|
+
const mutationKeyGetterName = makeMutationKeyGetterName(method, pathStr, paths, true);
|
|
425
425
|
return {
|
|
426
426
|
code: `${makeMutationKeyGetterCode(mutationKeyGetterName, method, honoPath)}\n\n${makeSWRMutationHookCode(hookName, `${mutationKeyGetterName}()`, hasArgs, argsType, responseType, runtimeAccess, hasNoContent, config.errorType)}`,
|
|
427
427
|
isQuery: false,
|
|
@@ -431,14 +431,14 @@ function makeHookCode(pathStr, method, item, deps, config, clientName, hasBasePa
|
|
|
431
431
|
};
|
|
432
432
|
}
|
|
433
433
|
if (isQuery) {
|
|
434
|
-
const queryHookName = makeHookName(queryNameMethod(method), pathStr, config.hookPrefix);
|
|
435
|
-
const pathFuncName =
|
|
436
|
-
const keyGetterName = makeQueryKeyGetterName(method, pathStr);
|
|
434
|
+
const queryHookName = makeHookName(queryNameMethod(method), pathStr, config.hookPrefix, paths);
|
|
435
|
+
const pathFuncName = routeName(queryNameMethod(method), pathStr, paths);
|
|
436
|
+
const keyGetterName = makeQueryKeyGetterName(method, pathStr, paths);
|
|
437
437
|
const optionsGetterName = `get${capitalize(pathFuncName)}QueryOptions`;
|
|
438
438
|
const keyGetterCode = makeQueryKeyGetterCode(keyGetterName, hasArgs, argsType, honoPath, config, excludedArgs, method);
|
|
439
439
|
const optionsGetterCode = makeQueryOptionsGetterCode(optionsGetterName, keyGetterName, hasArgs, argsType, runtimeAccess, responseType, config);
|
|
440
440
|
const hookCode = makeQueryHookCode(queryHookName, keyGetterName, optionsGetterName, runtimeAccess, hasArgs, argsType, responseType, config);
|
|
441
|
-
const infiniteKeyGetterName = makeInfiniteQueryKeyGetterName(method, pathStr);
|
|
441
|
+
const infiniteKeyGetterName = makeInfiniteQueryKeyGetterName(method, pathStr, paths);
|
|
442
442
|
const infiniteOptionsGetterName = `get${capitalize(pathFuncName)}InfiniteQueryOptions`;
|
|
443
443
|
const { infiniteQueryFn, useInfiniteQueryOptionsType } = config;
|
|
444
444
|
const hasInfinite = !!(infiniteQueryFn && useInfiniteQueryOptionsType) && hasPagination;
|
|
@@ -497,8 +497,8 @@ function makeHookCode(pathStr, method, item, deps, config, clientName, hasBasePa
|
|
|
497
497
|
operationFileName
|
|
498
498
|
};
|
|
499
499
|
}
|
|
500
|
-
const optionsGetterName = `get${capitalize(
|
|
501
|
-
const mutationKeyGetterName = makeMutationKeyGetterName(method, pathStr);
|
|
500
|
+
const optionsGetterName = `get${capitalize(routeName(method, pathStr, paths))}MutationOptions`;
|
|
501
|
+
const mutationKeyGetterName = makeMutationKeyGetterName(method, pathStr, paths);
|
|
502
502
|
return {
|
|
503
503
|
code: `${makeMutationKeyGetterCode(mutationKeyGetterName, method, honoPath)}\n\n${makeMutationOptionsGetterCode(optionsGetterName, mutationKeyGetterName, hasArgs, argsType, runtimeAccess, responseType, hasNoContent, config)}\n\n${makeMutationHookCode(hookName, optionsGetterName, hasArgs, argsType, responseType, config, hasNoContent)}`,
|
|
504
504
|
isQuery: false,
|
|
@@ -513,9 +513,9 @@ function makeHookCodes(paths, deps, config, clientOf, hasBasePath = false) {
|
|
|
513
513
|
return HTTP_METHODS.map((method) => {
|
|
514
514
|
const operation = pathItem[method];
|
|
515
515
|
const client = clientOf(p, isOperationLike(operation) ? operationTags(operation) : void 0);
|
|
516
|
-
const result = makeHookCode(p, method, pathItem, deps, config, client, hasBasePath);
|
|
516
|
+
const result = makeHookCode(paths, p, method, pathItem, deps, config, client, hasBasePath);
|
|
517
517
|
return result ? {
|
|
518
|
-
hookName: makeHookName(method, p, config.hookPrefix),
|
|
518
|
+
hookName: makeHookName(method, p, config.hookPrefix, paths),
|
|
519
519
|
client,
|
|
520
520
|
code: result.code,
|
|
521
521
|
isQuery: result.isQuery,
|
|
@@ -1,12 +1,19 @@
|
|
|
1
1
|
import { Effect, FileSystem, Schema } from "effect";
|
|
2
2
|
import { FormatConfig } from "oxfmt";
|
|
3
3
|
//#region src/constants/index.d.ts
|
|
4
|
+
/** The extensions of an input document: OpenAPI as YAML (`.yaml` or `.yml`) or JSON, or a TypeSpec entry. */
|
|
5
|
+
declare const INPUT_EXTENSIONS: readonly ['.yaml', '.yml', '.json', '.tsp'];
|
|
6
|
+
/**
|
|
7
|
+
* An input document: a path by its extension, or an `http(s)` URL whatever its path (a
|
|
8
|
+
* document served without an extension is OpenAPI by content).
|
|
9
|
+
*/
|
|
10
|
+
type InputPath = `${string}${(typeof INPUT_EXTENSIONS)[number]}` | `http://${string}` | `https://${string}`;
|
|
4
11
|
/** The query libraries the hooks are generated for, each a config key of its own. */
|
|
5
12
|
declare const HOOK_LIBRARIES: readonly ['swr', 'tanstack-query', 'preact-query', 'solid-query', 'vue-query', 'svelte-query', 'angular-query'];
|
|
6
13
|
//#endregion
|
|
7
14
|
//#region src/config/index.d.ts
|
|
8
15
|
declare const ConfigSchema: Schema.decodeTo<Schema.toType<Schema.Struct<{
|
|
9
|
-
readonly input: Schema.declare
|
|
16
|
+
readonly input: Schema.declare<InputPath, InputPath>;
|
|
10
17
|
readonly output: Schema.optionalKey<Schema.declare<`${string}.ts`, `${string}.ts`>>;
|
|
11
18
|
readonly basePath: Schema.withDecodingDefault<Schema.String, never>;
|
|
12
19
|
readonly readonly: Schema.optionalKey<Schema.Boolean>;
|
|
@@ -220,7 +227,7 @@ declare const ConfigSchema: Schema.decodeTo<Schema.toType<Schema.Struct<{
|
|
|
220
227
|
readonly baseUrl: Schema.optionalKey<Schema.String>;
|
|
221
228
|
}>]>>;
|
|
222
229
|
}>>, Schema.Struct<{
|
|
223
|
-
readonly input: Schema.declare
|
|
230
|
+
readonly input: Schema.declare<InputPath, InputPath>;
|
|
224
231
|
readonly output: Schema.optionalKey<Schema.declare<`${string}.ts`, `${string}.ts`>>;
|
|
225
232
|
readonly basePath: Schema.withDecodingDefault<Schema.String, never>;
|
|
226
233
|
readonly readonly: Schema.optionalKey<Schema.Boolean>;
|
|
@@ -441,7 +448,7 @@ declare const ConfigError_base: Schema.Class<ConfigError, Schema.TaggedStruct<"C
|
|
|
441
448
|
}>, import("effect/Cause").YieldableError>;
|
|
442
449
|
declare class ConfigError extends ConfigError_base {}
|
|
443
450
|
declare function parseConfig(config: unknown): Effect.Effect<{
|
|
444
|
-
readonly input:
|
|
451
|
+
readonly input: InputPath;
|
|
445
452
|
readonly output?: `${string}.ts`;
|
|
446
453
|
readonly basePath: string;
|
|
447
454
|
readonly readonly?: boolean;
|
|
@@ -656,7 +663,7 @@ declare function parseConfig(config: unknown): Effect.Effect<{
|
|
|
656
663
|
};
|
|
657
664
|
}, ConfigError, never>;
|
|
658
665
|
declare function readConfig(configPath?: string, reload?: boolean): Effect.Effect<{
|
|
659
|
-
readonly input:
|
|
666
|
+
readonly input: InputPath;
|
|
660
667
|
readonly output?: `${string}.ts`;
|
|
661
668
|
readonly basePath: string;
|
|
662
669
|
readonly readonly?: boolean;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import { a as parseConfig, i as defineConfig, n as ConfigError, o as readConfig, r as ConfigInput, t as Config } from "./index-
|
|
1
|
+
import { a as parseConfig, i as defineConfig, n as ConfigError, o as readConfig, r as ConfigInput, t as Config } from "./index-BNrSddFB.js";
|
|
2
2
|
export { Config, ConfigError, ConfigInput, defineConfig, parseConfig, readConfig };
|
package/dist/index.js
CHANGED
|
@@ -1,16 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { h as isInputPath, l as IDENTIFIER_PATTERN, n as COMPONENT_NAMES, s as HOOK_LIBRARIES } from "./constants-hwmOoQfI.js";
|
|
2
2
|
import { Effect, FileSystem, Schema, SchemaIssue, SchemaTransformation } from "effect";
|
|
3
3
|
import { posix, resolve } from "node:path";
|
|
4
4
|
import { pathToFileURL } from "node:url";
|
|
5
5
|
//#region src/config/index.ts
|
|
6
6
|
const ConfigSchema = Schema.Struct({
|
|
7
|
-
input: Schema.declare(
|
|
7
|
+
input: Schema.declare(isInputPath, { message: "must be .yaml | .yml | .json | .tsp, or an http(s) URL" }).annotate({
|
|
8
8
|
title: "Input document",
|
|
9
|
-
description: "OpenAPI or TypeSpec entry document that every generator reads.",
|
|
9
|
+
description: "OpenAPI or TypeSpec entry document that every generator reads: a file by its extension, or an http(s) URL.",
|
|
10
10
|
examples: [
|
|
11
11
|
"openapi.yaml",
|
|
12
12
|
"./spec/openapi.json",
|
|
13
|
-
"./spec/main.tsp"
|
|
13
|
+
"./spec/main.tsp",
|
|
14
|
+
"https://example.com/openapi"
|
|
14
15
|
]
|
|
15
16
|
}),
|
|
16
17
|
output: Schema.optionalKey(Schema.declare(Schema.is(Schema.TemplateLiteral([Schema.String, ".ts"])), { message: "must be .ts file" }).annotate({
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { $ as
|
|
1
|
+
import { a as FORM_MEDIA_TYPES, c as HTTP_METHODS, i as COMPONENT_SUFFIXES$1, n as COMPONENT_NAMES, r as COMPONENT_REF_PREFIX, t as ARROW_FUNCTION_PATTERN } from "./constants-hwmOoQfI.js";
|
|
2
|
+
import { $ as isResponses, A as isCallbacks, B as isOperation, C as discriminatedBranches, E as hasNotProperty, G as isParameterRef, H as isParameter, I as isMedia, J as isPathItemRef, K as isPathItem, M as isHeader, P as isInheritedName, R as isOffsetTime, S as zodToOpenAPISchema, T as hasNoUserChain, X as isRefObject, Y as isRecord, Z as isRefOnly, _ as routeName, a as ensureSuffix, at as isSingleSchema, b as uncapitalize, c as escapeRegexLiteral, d as makeSafeKey, et as isSchemaArray, f as makeStringLiteral, g as requestParamsArray, h as renderNamedImport, i as decodePercent, j as isExamplesInput, k as hasTypelessConstraint, m as regexLiteral, o as error, p as normalizeTypes, q as isPathItemEntry, r as cyclicNodes, st as isValidIdent, t as baseError, tt as isSchemaObject, y as toIdentifierPascalCase } from "./utils-Bw0Q2Ozg.js";
|
|
3
3
|
import path from "node:path";
|
|
4
4
|
import { parseSync, visitorKeys } from "oxc-parser";
|
|
5
5
|
//#region src/helper/wire.ts
|
|
@@ -498,59 +498,14 @@ function isEmptyAbsent(parameter, schemas) {
|
|
|
498
498
|
//#endregion
|
|
499
499
|
//#region src/helper/openapi.ts
|
|
500
500
|
function makeRef($ref) {
|
|
501
|
-
const COMPONENT_SUFFIX_MAP = [
|
|
502
|
-
{
|
|
503
|
-
prefix: COMPONENT_REF_PREFIX.schemas,
|
|
504
|
-
suffix: "Schema"
|
|
505
|
-
},
|
|
506
|
-
{
|
|
507
|
-
prefix: COMPONENT_REF_PREFIX.parameters,
|
|
508
|
-
suffix: "ParamsSchema"
|
|
509
|
-
},
|
|
510
|
-
{
|
|
511
|
-
prefix: COMPONENT_REF_PREFIX.headers,
|
|
512
|
-
suffix: "HeaderSchema"
|
|
513
|
-
},
|
|
514
|
-
{
|
|
515
|
-
prefix: COMPONENT_REF_PREFIX.securitySchemes,
|
|
516
|
-
suffix: "SecurityScheme"
|
|
517
|
-
},
|
|
518
|
-
{
|
|
519
|
-
prefix: COMPONENT_REF_PREFIX.requestBodies,
|
|
520
|
-
suffix: "RequestBody"
|
|
521
|
-
},
|
|
522
|
-
{
|
|
523
|
-
prefix: COMPONENT_REF_PREFIX.responses,
|
|
524
|
-
suffix: "Response"
|
|
525
|
-
},
|
|
526
|
-
{
|
|
527
|
-
prefix: COMPONENT_REF_PREFIX.examples,
|
|
528
|
-
suffix: "Example"
|
|
529
|
-
},
|
|
530
|
-
{
|
|
531
|
-
prefix: COMPONENT_REF_PREFIX.links,
|
|
532
|
-
suffix: "Link"
|
|
533
|
-
},
|
|
534
|
-
{
|
|
535
|
-
prefix: COMPONENT_REF_PREFIX.callbacks,
|
|
536
|
-
suffix: "Callback"
|
|
537
|
-
},
|
|
538
|
-
{
|
|
539
|
-
prefix: COMPONENT_REF_PREFIX.pathItems,
|
|
540
|
-
suffix: "PathItem"
|
|
541
|
-
},
|
|
542
|
-
{
|
|
543
|
-
prefix: COMPONENT_REF_PREFIX.mediaTypes,
|
|
544
|
-
suffix: "MediaTypeSchema"
|
|
545
|
-
}
|
|
546
|
-
];
|
|
547
501
|
const propertiesMatch = $ref.match(/^#\/components\/schemas\/([^/]+)\/properties\/(.+)$/u);
|
|
548
502
|
if (propertiesMatch) return `z.lazy(()=>${toIdentifierPascalCase(ensureSuffix(decodePercent(propertiesMatch[1]), "Schema"))})`;
|
|
549
503
|
const rawRef = $ref.split("/").at(-1);
|
|
550
504
|
if (!rawRef) return "Schema";
|
|
551
505
|
const decodedRef = decodePercent(rawRef);
|
|
552
|
-
const
|
|
553
|
-
|
|
506
|
+
const section = COMPONENT_NAMES.find((name) => $ref.startsWith(COMPONENT_REF_PREFIX[name]));
|
|
507
|
+
const suffix = section === void 0 ? "Schema" : COMPONENT_SUFFIXES$1[section];
|
|
508
|
+
return toIdentifierPascalCase(ensureSuffix(decodedRef, suffix));
|
|
554
509
|
}
|
|
555
510
|
function makeExamples(examples) {
|
|
556
511
|
return `{${Object.entries(examples).map(([k, example]) => {
|
|
@@ -900,7 +855,7 @@ function makeRouteEntries(openapi, readonly) {
|
|
|
900
855
|
parameters
|
|
901
856
|
} : operation, readonly, openapi.components?.schemas);
|
|
902
857
|
const asConst = readonly ? " as const" : "";
|
|
903
|
-
const entryName =
|
|
858
|
+
const entryName = routeName(method, path, openapi.paths);
|
|
904
859
|
return [{
|
|
905
860
|
name: entryName,
|
|
906
861
|
code: `export const ${entryName}Route=createRoute({${properties}}${asConst})`
|
|
@@ -937,6 +892,7 @@ function makeWebhookEntries(openapi, readonly) {
|
|
|
937
892
|
}
|
|
938
893
|
//#endregion
|
|
939
894
|
//#region src/helper/wrap.ts
|
|
895
|
+
const structuralProps = /* @__PURE__ */ new Set(["$defs", "definitions"]);
|
|
940
896
|
const zodExpressedProps = /* @__PURE__ */ new Set([
|
|
941
897
|
"type",
|
|
942
898
|
"format",
|
|
@@ -1078,8 +1034,24 @@ const decorationProps = /* @__PURE__ */ new Set([
|
|
|
1078
1034
|
function undecorated(schema) {
|
|
1079
1035
|
return Object.entries(schema).reduce((kept, [key, value]) => zodExpressedProps.has(key) && !decorationProps.has(key) ? Object.assign(kept, { [key]: value }) : kept, {});
|
|
1080
1036
|
}
|
|
1037
|
+
/** The keys of a Parameter Object (OpenAPI 3.1 §4.8.12); a document may carry others. */
|
|
1038
|
+
const PARAMETER_KEYS = /* @__PURE__ */ new Set([
|
|
1039
|
+
"name",
|
|
1040
|
+
"in",
|
|
1041
|
+
"description",
|
|
1042
|
+
"required",
|
|
1043
|
+
"deprecated",
|
|
1044
|
+
"allowEmptyValue",
|
|
1045
|
+
"style",
|
|
1046
|
+
"explode",
|
|
1047
|
+
"allowReserved",
|
|
1048
|
+
"schema",
|
|
1049
|
+
"content",
|
|
1050
|
+
"example",
|
|
1051
|
+
"examples"
|
|
1052
|
+
]);
|
|
1081
1053
|
function makeSerializedParam(param) {
|
|
1082
|
-
return `{${Object.entries(param).filter(([, value]) => value !== void 0).map(([key, value]) => {
|
|
1054
|
+
return `{${Object.entries(param).filter(([key, value]) => value !== void 0 && (PARAMETER_KEYS.has(key) || key.startsWith("x-"))).map(([key, value]) => {
|
|
1083
1055
|
if (key === "examples" && isExamplesInput(value)) return `"examples":${makeExamples(value)}`;
|
|
1084
1056
|
if (key === "content" && isRecord(value)) return `"content":{${Object.entries(value).map(([mediaType, mediaObj]) => {
|
|
1085
1057
|
if (!isRecord(mediaObj)) return `${JSON.stringify(mediaType)}:${JSON.stringify(mediaObj)}`;
|
|
@@ -1092,6 +1064,96 @@ function makeSerializedParam(param) {
|
|
|
1092
1064
|
return `${JSON.stringify(key)}:${JSON.stringify(value)}`;
|
|
1093
1065
|
}).join(",")}}`;
|
|
1094
1066
|
}
|
|
1067
|
+
/**
|
|
1068
|
+
* The default as a value of its schema, or that it is not one. A string that spells a
|
|
1069
|
+
* boolean (`'true'`) or a number (`'10'`) for a schema of that type is read as the value
|
|
1070
|
+
* (YAML and query strings arrive as text); a number for a string is written as text. An
|
|
1071
|
+
* enum or const takes only what it lists; an array takes an array whose every item
|
|
1072
|
+
* conforms. A schema with no type of its own (a reference, a `oneOf`) is not checked.
|
|
1073
|
+
*/
|
|
1074
|
+
function conformDefault(schema, value) {
|
|
1075
|
+
if (value === void 0) return { ok: false };
|
|
1076
|
+
if (value === null) return {
|
|
1077
|
+
ok: true,
|
|
1078
|
+
value
|
|
1079
|
+
};
|
|
1080
|
+
if (schema.enum !== void 0) return schema.enum.some((member) => member === value) ? {
|
|
1081
|
+
ok: true,
|
|
1082
|
+
value
|
|
1083
|
+
} : { ok: false };
|
|
1084
|
+
if (schema.const !== void 0) return JSON.stringify(schema.const) === JSON.stringify(value) ? {
|
|
1085
|
+
ok: true,
|
|
1086
|
+
value
|
|
1087
|
+
} : { ok: false };
|
|
1088
|
+
const types = (Array.isArray(schema.type) ? schema.type : [schema.type]).filter((t) => t !== void 0 && t !== "null");
|
|
1089
|
+
if (types.length === 0) return {
|
|
1090
|
+
ok: true,
|
|
1091
|
+
value
|
|
1092
|
+
};
|
|
1093
|
+
const read = (type) => {
|
|
1094
|
+
if (type === "boolean") {
|
|
1095
|
+
if (typeof value === "boolean") return {
|
|
1096
|
+
ok: true,
|
|
1097
|
+
value
|
|
1098
|
+
};
|
|
1099
|
+
if (value === "true" || value === "false") return {
|
|
1100
|
+
ok: true,
|
|
1101
|
+
value: value === "true"
|
|
1102
|
+
};
|
|
1103
|
+
return;
|
|
1104
|
+
}
|
|
1105
|
+
if (type === "number" || type === "integer") {
|
|
1106
|
+
const number = typeof value === "number" ? value : typeof value === "string" && value.trim() !== "" && Number.isFinite(Number(value)) ? Number(value) : void 0;
|
|
1107
|
+
if (number === void 0) return void 0;
|
|
1108
|
+
if (type === "integer" && !Number.isInteger(number)) return void 0;
|
|
1109
|
+
return {
|
|
1110
|
+
ok: true,
|
|
1111
|
+
value: number
|
|
1112
|
+
};
|
|
1113
|
+
}
|
|
1114
|
+
if (type === "string") {
|
|
1115
|
+
if (typeof value === "string") return {
|
|
1116
|
+
ok: true,
|
|
1117
|
+
value
|
|
1118
|
+
};
|
|
1119
|
+
if (typeof value === "number" || typeof value === "boolean") return {
|
|
1120
|
+
ok: true,
|
|
1121
|
+
value: String(value)
|
|
1122
|
+
};
|
|
1123
|
+
return;
|
|
1124
|
+
}
|
|
1125
|
+
if (type === "array") {
|
|
1126
|
+
if (!Array.isArray(value)) return void 0;
|
|
1127
|
+
const items = schema.items;
|
|
1128
|
+
if (items === void 0 || typeof items === "boolean" || isSchemaArray(items)) return {
|
|
1129
|
+
ok: true,
|
|
1130
|
+
value
|
|
1131
|
+
};
|
|
1132
|
+
const readItems = value.map((item) => conformDefault(items, item));
|
|
1133
|
+
return readItems.every((item) => item.ok) ? {
|
|
1134
|
+
ok: true,
|
|
1135
|
+
value: readItems.map((item) => item.ok ? item.value : void 0)
|
|
1136
|
+
} : void 0;
|
|
1137
|
+
}
|
|
1138
|
+
if (type === "object") return isRecord(value) ? {
|
|
1139
|
+
ok: true,
|
|
1140
|
+
value
|
|
1141
|
+
} : void 0;
|
|
1142
|
+
return {
|
|
1143
|
+
ok: true,
|
|
1144
|
+
value
|
|
1145
|
+
};
|
|
1146
|
+
};
|
|
1147
|
+
const asIs = types.find((type) => typeOf(value) === type);
|
|
1148
|
+
return (asIs === void 0 ? void 0 : read(asIs)) ?? types.map(read).find((result) => result !== void 0) ?? { ok: false };
|
|
1149
|
+
}
|
|
1150
|
+
function typeOf(value) {
|
|
1151
|
+
if (typeof value === "boolean") return "boolean";
|
|
1152
|
+
if (typeof value === "number") return Number.isInteger(value) ? "integer" : "number";
|
|
1153
|
+
if (typeof value === "string") return "string";
|
|
1154
|
+
if (Array.isArray(value)) return "array";
|
|
1155
|
+
if (isRecord(value)) return "object";
|
|
1156
|
+
}
|
|
1095
1157
|
function wrap(zod, schema, meta, options) {
|
|
1096
1158
|
const unsupportedProps = /* @__PURE__ */ new Set([
|
|
1097
1159
|
"$recursiveRef",
|
|
@@ -1136,11 +1198,14 @@ function wrap(zod, schema, meta, options) {
|
|
|
1136
1198
|
const style = parameter === void 0 ? void 0 : wireStyle(parameter, typeList.includes("array"));
|
|
1137
1199
|
const readers = [...options?.readers ?? [], ...style === void 0 ? [] : [style]];
|
|
1138
1200
|
const acceptBothArities = (inner) => readers.reduceRight((read, reader) => `z.preprocess(${reader},${read})`, inner);
|
|
1139
|
-
const
|
|
1201
|
+
const conformed = conformDefault(schema, schema.default);
|
|
1202
|
+
const defaultValue = conformed.ok ? conformed.value : void 0;
|
|
1203
|
+
const droppedDefault = schema.default !== void 0 && !conformed.ok;
|
|
1204
|
+
const isNullable = schema.nullable === true || typeList.includes("null") || defaultValue === null;
|
|
1140
1205
|
const build = (core) => {
|
|
1141
1206
|
const typed = isNullable ? `${acceptBothArities(core)}.nullable()` : acceptBothArities(core);
|
|
1142
1207
|
const n = options?.nullRead === "first" ? `z.preprocess(${WIRE_NULL},${typed})` : options?.nullRead === "last" ? `((schema)=>z.union([schema,z.preprocess(${WIRE_NULL},schema)]))(${typed})` : typed;
|
|
1143
|
-
const d =
|
|
1208
|
+
const d = defaultValue !== void 0 ? `${n}.default(${formatLiteral(defaultValue)})` : n;
|
|
1144
1209
|
const pf = schema["x-prefault"] !== void 0 ? `${d}.prefault(${formatLiteral(schema["x-prefault"])})` : d;
|
|
1145
1210
|
const c = schema["x-catch"] !== void 0 ? `${pf}.catch(${formatLiteral(schema["x-catch"])})` : pf;
|
|
1146
1211
|
const superRefineChain = `${`${schema["x-readonly"] === true ? `${c}.readonly()` : c}${schema["x-refine"] ?? ""}`}${schema["x-superRefine"] ?? ""}`;
|
|
@@ -1157,21 +1222,21 @@ function wrap(zod, schema, meta, options) {
|
|
|
1157
1222
|
const absentReaders = [...options?.inheritedAbsent === true ? [WIRE_INHERITED] : [], ...options?.emptyAbsent === true ? [WIRE_EMPTY] : []];
|
|
1158
1223
|
if (absentReaders.length === 0) return chain;
|
|
1159
1224
|
const read = (inner) => absentReaders.reduceRight((inside, reader) => `z.preprocess(${reader},${inside})`, inner);
|
|
1160
|
-
if (
|
|
1225
|
+
if (defaultValue !== void 0) return `${read(chain)}.default(${formatLiteral(defaultValue)})`;
|
|
1161
1226
|
return read(`${chain}${(parameter === void 0 ? options?.isOptional !== true : parameter.required === true) ? "" : ".optional()"}`);
|
|
1162
1227
|
};
|
|
1163
1228
|
const z = absent(build(around(zod)));
|
|
1164
1229
|
const headerDupKeys = new Set(meta?.headers ? Object.entries(meta.headers).filter(([, v]) => v !== void 0).map(([k]) => k) : []);
|
|
1165
|
-
const args = filterUnsupportedProps(Object.fromEntries(
|
|
1230
|
+
const args = filterUnsupportedProps(Object.fromEntries([
|
|
1231
|
+
...Object.entries(schema).filter(([k, v]) => !(zodExpressedProps.has(k) || structuralProps.has(k) || k === "required" && typeof v === "boolean" || headerDupKeys.has(k))),
|
|
1232
|
+
...droppedDefault ? [["default", schema.default]] : [],
|
|
1233
|
+
...typeof schema.pattern === "string" && regexLiteral(schema.pattern) === void 0 ? [["pattern", schema.pattern]] : []
|
|
1234
|
+
]));
|
|
1166
1235
|
const headerMetaProps = meta?.headers ? [
|
|
1167
1236
|
meta.headers.description ? `description:${JSON.stringify(meta.headers.description)}` : void 0,
|
|
1168
1237
|
meta.headers.deprecated ? `deprecated:${JSON.stringify(meta.headers.deprecated)}` : void 0,
|
|
1169
1238
|
meta.headers.example ? `example:${JSON.stringify(meta.headers.example)}` : void 0,
|
|
1170
|
-
meta.headers.examples ? `examples:${makeExamples(meta.headers.examples)}` : void 0
|
|
1171
|
-
meta.headers.style ? `style:${JSON.stringify(meta.headers.style)}` : void 0,
|
|
1172
|
-
meta.headers.explode ? `explode:${JSON.stringify(meta.headers.explode)}` : void 0,
|
|
1173
|
-
meta.headers.allowReserved ? `allowReserved:${JSON.stringify(meta.headers.allowReserved)}` : void 0,
|
|
1174
|
-
meta.headers.content ? `content:${JSON.stringify(meta.headers.content)}` : void 0
|
|
1239
|
+
meta.headers.examples ? `examples:${makeExamples(meta.headers.examples)}` : void 0
|
|
1175
1240
|
].filter((v) => v !== void 0) : [];
|
|
1176
1241
|
const openapiSchema = args ? JSON.stringify(args) : void 0;
|
|
1177
1242
|
const openapiSchemaBody = openapiSchema?.startsWith("{") && openapiSchema?.endsWith("}") ? openapiSchema.slice(1, -1) : openapiSchema;
|
|
@@ -1271,8 +1336,10 @@ function issueObj(messageExpr, pathExpr) {
|
|
|
1271
1336
|
return `{${parts.join(",")}}`;
|
|
1272
1337
|
}
|
|
1273
1338
|
function makeObjectChecks(schema, recurse) {
|
|
1274
|
-
const
|
|
1275
|
-
const
|
|
1339
|
+
const ownKeys = Object.keys(schema.properties ?? {});
|
|
1340
|
+
const patterns = Object.keys(schema.patternProperties ?? {});
|
|
1341
|
+
const declared = [...ownKeys.length > 0 ? [`!${JSON.stringify(ownKeys)}.includes(k)`] : [], ...patterns.length > 0 ? [`!${JSON.stringify(patterns)}.some((p)=>new RegExp(p).test(k))`] : []];
|
|
1342
|
+
const forUndeclaredKeys = (body) => `for(const k of Object.keys(val)){${declared.length === 0 ? body : `if(${declared.join("&&")}){${body}}`}}`;
|
|
1276
1343
|
const requiredMessage = messageFor(schema, "required");
|
|
1277
1344
|
const requiredChecks = Array.isArray(schema.required) ? schema.required.map((key) => `if(!Object.hasOwn(val,${JSON.stringify(key)})){ctx.addIssue(${issueObj(requiredMessage)})}`) : [];
|
|
1278
1345
|
const minPropertiesCheck = typeof schema.minProperties === "number" ? `if(Object.keys(val).length<${schema.minProperties}){ctx.addIssue(${issueObj(messageFor(schema, "minProperties"))})}` : void 0;
|
|
@@ -1281,8 +1348,8 @@ function makeObjectChecks(schema, recurse) {
|
|
|
1281
1348
|
const propertyChecks = schema.properties ? Object.entries(schema.properties).map(([key, sub]) => `if(Object.hasOwn(val,${JSON.stringify(key)})){const Schema=${recurse(sub)};if(!Schema.safeParse(Reflect.get(val,${JSON.stringify(key)})).success){ctx.addIssue(${issueObj(propertiesMessage)})}}`) : [];
|
|
1282
1349
|
const additionalPropertiesMessage = messageFor(schema, "additionalProperties");
|
|
1283
1350
|
const additionalPropertiesCheck = (() => {
|
|
1284
|
-
if (schema.additionalProperties === false) return `
|
|
1285
|
-
if (isSchemaObject(schema.additionalProperties)) return `{const Schema=${recurse(schema.additionalProperties)}
|
|
1351
|
+
if (schema.additionalProperties === false) return forUndeclaredKeys(`ctx.addIssue(${issueObj(additionalPropertiesMessage)})`);
|
|
1352
|
+
if (isSchemaObject(schema.additionalProperties)) return `{const Schema=${recurse(schema.additionalProperties)};${forUndeclaredKeys(`if(!Schema.safeParse(Reflect.get(val,k)).success){ctx.addIssue(${issueObj(additionalPropertiesMessage)})}`)}}`;
|
|
1286
1353
|
})();
|
|
1287
1354
|
const patternPropertiesMessage = messageFor(schema, "patternProperties");
|
|
1288
1355
|
const patternPropertiesChecks = schema.patternProperties ? Object.entries(schema.patternProperties).map(([pattern, sub]) => `{const Schema=${recurse(sub)};for(const k of Object.keys(val)){if(new RegExp(${JSON.stringify(pattern)}).test(k)){if(!Schema.safeParse(Reflect.get(val,k)).success){ctx.addIssue(${issueObj(patternPropertiesMessage)})}}}}`) : [];
|
|
@@ -1295,7 +1362,7 @@ function makeObjectChecks(schema, recurse) {
|
|
|
1295
1362
|
const dependentSchemasMessage = messageFor(schema, "dependentSchemas");
|
|
1296
1363
|
const dependentSchemasMessageField = dependentSchemasMessage !== void 0 ? `,message:${JSON.stringify(dependentSchemasMessage)}` : "";
|
|
1297
1364
|
const dependentSchemasChecks = schema.dependentSchemas ? Object.entries(schema.dependentSchemas).map(([key, sub]) => `if(Object.hasOwn(val,${JSON.stringify(key)})){const Schema=${recurse(sub)};const result=Schema.safeParse(val);if(!result.success){for(const issue of result.error.issues){ctx.addIssue({...issue,path:issue.path${dependentSchemasMessageField}})}}}`) : [];
|
|
1298
|
-
const unevaluatedPropertiesCheck = schema.unevaluatedProperties === false ? `
|
|
1365
|
+
const unevaluatedPropertiesCheck = schema.unevaluatedProperties === false ? forUndeclaredKeys(`ctx.addIssue(${issueObj(messageFor(schema, "unevaluatedProperties"))})`) : void 0;
|
|
1299
1366
|
return [
|
|
1300
1367
|
...requiredChecks,
|
|
1301
1368
|
minPropertiesCheck,
|
|
@@ -1903,9 +1970,9 @@ function string(schema, options) {
|
|
|
1903
1970
|
const endUpper = usePipe ? "" : postUpper;
|
|
1904
1971
|
const endNormalize = usePipe ? "" : postNormalize;
|
|
1905
1972
|
const patternMessage = schema["x-pattern-message"] ?? errorMessage;
|
|
1906
|
-
const hasUnicodeProperty = schema.pattern && /\\[pP]\{/u.test(schema.pattern);
|
|
1907
1973
|
const patternMessagePart = patternMessage ? `,${error(patternMessage)}` : "";
|
|
1908
|
-
const
|
|
1974
|
+
const literal = schema.pattern === void 0 ? void 0 : regexLiteral(schema.pattern);
|
|
1975
|
+
const pattern = literal ? `.regex(/${escapeRegexLiteral(literal.source)}/${literal.flags}${patternMessagePart})` : void 0;
|
|
1909
1976
|
const lengthMessage = schema["x-length-message"] ?? errorMessage;
|
|
1910
1977
|
const lengthMessagePart = lengthMessage ? `,${error(lengthMessage)}` : "";
|
|
1911
1978
|
const minLengthMessage = schema["x-minLength-message"] ?? errorMessage;
|
|
@@ -2587,6 +2654,7 @@ function makeImports(code, fromFile, components, split = false, honoExtras = [])
|
|
|
2587
2654
|
//#region src/helper/type.ts
|
|
2588
2655
|
function makeTypeString(schema, selfTypeName, cyclicGroup, readonly) {
|
|
2589
2656
|
if (!schema) return "unknown";
|
|
2657
|
+
if (Object.keys(schema).length === 0) return "unknown";
|
|
2590
2658
|
const types = normalizeType(schema);
|
|
2591
2659
|
const isNullable = schema.nullable === true || types.includes("null") || schema.default === null || (schema.enum?.includes(null) ?? false);
|
|
2592
2660
|
const baseType = makeNonNullTypeString(schema, types.filter((t) => t !== "null"), selfTypeName, cyclicGroup, readonly);
|
|
@@ -2699,7 +2767,10 @@ function makeObjectTypeString(schema, selfTypeName, cyclicGroup, readonly) {
|
|
|
2699
2767
|
*/
|
|
2700
2768
|
function zodType(schema, typeName, cyclicGroup, readonly) {
|
|
2701
2769
|
const isRecordLike = (Array.isArray(schema.type) ? schema.type.includes("object") : schema.type === "object") && schema.additionalProperties && (!schema.properties || Object.keys(schema.properties).length === 0);
|
|
2702
|
-
if (cyclicGroup && cyclicGroup.size > 0 && isRecordLike)
|
|
2770
|
+
if (cyclicGroup && cyclicGroup.size > 0 && isRecordLike) {
|
|
2771
|
+
const record = `{[key:string]:${makeTypeString(typeof schema.additionalProperties === "object" ? schema.additionalProperties : {}, typeName, cyclicGroup, readonly)}}`;
|
|
2772
|
+
return `type ${typeName}Type = ${schema.nullable === true || Array.isArray(schema.type) && schema.type.includes("null") ? `${record}|null` : record}`;
|
|
2773
|
+
}
|
|
2703
2774
|
return `type ${typeName}Type=${makeTypeString(schema, typeName, cyclicGroup, readonly)}`;
|
|
2704
2775
|
}
|
|
2705
2776
|
//#endregion
|
|
@@ -3069,6 +3140,96 @@ function routeCode(openapi, readonly) {
|
|
|
3069
3140
|
return makeRouteEntries(openapi, readonly).map((entry) => entry.code).join("\n\n");
|
|
3070
3141
|
}
|
|
3071
3142
|
//#endregion
|
|
3143
|
+
//#region src/helper/names.ts
|
|
3144
|
+
/**
|
|
3145
|
+
* Renames the components whose identifiers would collide, and every `$ref` to them.
|
|
3146
|
+
*
|
|
3147
|
+
* An identifier is made of the letters and digits of a component name, so
|
|
3148
|
+
* `api-response-common-failure` and `api_response_common_failure` (Cloudflare) are both
|
|
3149
|
+
* `ApiResponseCommonFailureSchema`: one declaration was silently lost, and a type alias
|
|
3150
|
+
* came to name itself (`type X = X`). The first component in document order keeps its
|
|
3151
|
+
* name; every later one that would share an identifier is numbered
|
|
3152
|
+
* (`api_response_common_failure2`, so `ApiResponseCommonFailure2Schema`), and the
|
|
3153
|
+
* references to it follow. The document that is emitted names the schema the new way too.
|
|
3154
|
+
*
|
|
3155
|
+
* Security schemes are left alone: `security` requirements name them, and a `$ref` does not.
|
|
3156
|
+
*/
|
|
3157
|
+
function uniqueComponentNames(document) {
|
|
3158
|
+
const components = document.components;
|
|
3159
|
+
if (!isRecord(components)) return document;
|
|
3160
|
+
const renames = COMPONENT_NAMES.flatMap((section) => {
|
|
3161
|
+
if (section === "securitySchemes") return [];
|
|
3162
|
+
const entries = components[section];
|
|
3163
|
+
if (!isRecord(entries)) return [];
|
|
3164
|
+
const identifier = (name) => toIdentifierPascalCase(ensureSuffix(name, COMPONENT_SUFFIXES$1[section]));
|
|
3165
|
+
const taken = /* @__PURE__ */ new Set();
|
|
3166
|
+
return Object.keys(entries).flatMap((name) => {
|
|
3167
|
+
const own = identifier(name);
|
|
3168
|
+
if (!taken.has(own)) {
|
|
3169
|
+
taken.add(own);
|
|
3170
|
+
return [];
|
|
3171
|
+
}
|
|
3172
|
+
const renamed = numbered(name, (candidate) => !taken.has(identifier(candidate)));
|
|
3173
|
+
taken.add(identifier(renamed));
|
|
3174
|
+
return [{
|
|
3175
|
+
section,
|
|
3176
|
+
name,
|
|
3177
|
+
renamed
|
|
3178
|
+
}];
|
|
3179
|
+
});
|
|
3180
|
+
});
|
|
3181
|
+
if (renames.length === 0) return document;
|
|
3182
|
+
const renamedSections = Object.fromEntries(COMPONENT_NAMES.flatMap((section) => {
|
|
3183
|
+
const entries = components[section];
|
|
3184
|
+
const own = renames.filter((rename) => rename.section === section);
|
|
3185
|
+
if (!isRecord(entries) || own.length === 0) return [];
|
|
3186
|
+
return [[section, Object.fromEntries(Object.entries(entries).map(([name, value]) => [own.find((rename) => rename.name === name)?.renamed ?? name, value]))]];
|
|
3187
|
+
}));
|
|
3188
|
+
const refs = new Map(renames.map((rename) => [`#/components/${rename.section}/${rename.name}`, rename]));
|
|
3189
|
+
const rewriteRef = (ref) => {
|
|
3190
|
+
if (!ref.startsWith("#/components/")) return ref;
|
|
3191
|
+
const segments = ref.split("/");
|
|
3192
|
+
const section = segments[2];
|
|
3193
|
+
const encoded = segments[3];
|
|
3194
|
+
const rest = segments.slice(4);
|
|
3195
|
+
if (section === void 0 || encoded === void 0) return ref;
|
|
3196
|
+
const rename = refs.get(`#/components/${section}/${decodePercent(encoded)}`);
|
|
3197
|
+
if (rename === void 0) return ref;
|
|
3198
|
+
return [
|
|
3199
|
+
"#",
|
|
3200
|
+
"components",
|
|
3201
|
+
section,
|
|
3202
|
+
encoded.includes("%") ? encodeURIComponent(rename.renamed) : rename.renamed,
|
|
3203
|
+
...rest
|
|
3204
|
+
].join("/");
|
|
3205
|
+
};
|
|
3206
|
+
const rewrite = (node) => {
|
|
3207
|
+
if (Array.isArray(node)) return node.map(rewrite);
|
|
3208
|
+
if (!isRecord(node)) return node;
|
|
3209
|
+
return Object.fromEntries(Object.entries(node).map(([key, value]) => {
|
|
3210
|
+
if (key === "$ref" && typeof value === "string") return [key, rewriteRef(value)];
|
|
3211
|
+
if (key === "mapping" && isRecord(value)) return [key, Object.fromEntries(Object.entries(value).map(([k, v]) => [k, typeof v === "string" ? rewriteRef(v) : v]))];
|
|
3212
|
+
return [key, rewrite(value)];
|
|
3213
|
+
}));
|
|
3214
|
+
};
|
|
3215
|
+
const rewritten = rewrite({
|
|
3216
|
+
...document,
|
|
3217
|
+
components: {
|
|
3218
|
+
...components,
|
|
3219
|
+
...renamedSections
|
|
3220
|
+
}
|
|
3221
|
+
});
|
|
3222
|
+
return isRecord(rewritten) ? {
|
|
3223
|
+
...document,
|
|
3224
|
+
...rewritten
|
|
3225
|
+
} : document;
|
|
3226
|
+
}
|
|
3227
|
+
/** `name2`, `name3`, ...: the first that `isFree`. */
|
|
3228
|
+
function numbered(name, isFree) {
|
|
3229
|
+
const candidates = (n) => isFree(`${name}${n}`) ? `${name}${n}` : candidates(n + 1);
|
|
3230
|
+
return candidates(2);
|
|
3231
|
+
}
|
|
3232
|
+
//#endregion
|
|
3072
3233
|
//#region src/helper/pointer.ts
|
|
3073
3234
|
/**
|
|
3074
3235
|
* Inlines every `$ref` whose pointer names no component, so that what reaches the
|
|
@@ -3132,7 +3293,7 @@ function webhookCode(openapi, readonly) {
|
|
|
3132
3293
|
//#endregion
|
|
3133
3294
|
//#region src/generator/zod-openapi-hono/openapi/index.ts
|
|
3134
3295
|
function zodOpenAPIHono(document, options = {}) {
|
|
3135
|
-
const openapi = inlinePointerRefs(document);
|
|
3296
|
+
const openapi = uniqueComponentNames(inlinePointerRefs(document));
|
|
3136
3297
|
const components = openapi.components ? componentsCode(openapi.components, options) : "";
|
|
3137
3298
|
const routes = routeCode(openapi, options.readonly);
|
|
3138
3299
|
const webhooks = webhookCode(openapi, options.readonly);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { a as FORM_MEDIA_TYPES, d as JSON_MEDIA_TYPE } from "./constants-hwmOoQfI.js";
|
|
2
|
+
import { V as isOperationLike, W as isParameterObject, X as isRefObject, Y as isRecord, nt as isSchemaProperty, st as isValidIdent } from "./utils-Bw0Q2Ozg.js";
|
|
3
3
|
//#region src/helper/group.ts
|
|
4
4
|
const RESERVED = /* @__PURE__ */ new Set([
|
|
5
5
|
"arguments",
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { t as __exportAll } from "./rolldown-runtime-D7D4PA-g.js";
|
|
2
|
-
import { n as COMPONENT_NAMES,
|
|
2
|
+
import { n as COMPONENT_NAMES, s as HOOK_LIBRARIES } from "./constants-hwmOoQfI.js";
|
|
3
3
|
import { i as GenerateError } from "./format-CuHABcKC.js";
|
|
4
|
-
import { C as isInsideDirectory, E as makeGeneratedImport, S as appEntryOutput, T as makeAppEntryImport, _ 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 makeAppEntryFile, x as handlerGroupOf, y as callbacks } from "./core-
|
|
4
|
+
import { C as isInsideDirectory, E as makeGeneratedImport, S as appEntryOutput, T as makeAppEntryImport, _ 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 makeAppEntryFile, x as handlerGroupOf, y as callbacks } from "./core-FnayWJZV.js";
|
|
5
5
|
import { a as unlink, i as readdir, t as exists } from "./file-K6j5IJXi.js";
|
|
6
|
-
import { t as hooks } from "./hooks-
|
|
7
|
-
import { t as docs } from "./docs-
|
|
6
|
+
import { t as hooks } from "./hooks-DJHtFXnM.js";
|
|
7
|
+
import { t as docs } from "./docs-D8ivFJrR.js";
|
|
8
8
|
import { rpc } from "./core/rpc/index.js";
|
|
9
9
|
import { type } from "./core/type/index.js";
|
|
10
10
|
import { Effect, FileSystem, Schema } from "effect";
|
|
@@ -14,6 +14,7 @@ import SwaggerParser from "@apidevtools/swagger-parser";
|
|
|
14
14
|
var shared_exports = /* @__PURE__ */ __exportAll({
|
|
15
15
|
cleanSplitOutputs: () => cleanSplitOutputs,
|
|
16
16
|
makeJob: () => makeJob,
|
|
17
|
+
openAPI3: () => openAPI3,
|
|
17
18
|
outsideSources: () => outsideSources,
|
|
18
19
|
packageRoots: () => packageRoots,
|
|
19
20
|
referencedKinds: () => referencedKinds
|
|
@@ -167,6 +168,18 @@ function importTargets(config) {
|
|
|
167
168
|
* Fails when a file would import another package that names no `package`: the import
|
|
168
169
|
* could not be written.
|
|
169
170
|
*/
|
|
171
|
+
/**
|
|
172
|
+
* The document, when it is OpenAPI 3; a Swagger 2.0 document fails instead. 2.0 keeps a
|
|
173
|
+
* parameter's type on the parameter, a body in `in: formData` / `in: body` parameters and a
|
|
174
|
+
* response schema in `responses.<code>.schema`, none of which the reader of OpenAPI 3 looks
|
|
175
|
+
* at: it would generate `z.any()` for every parameter and no response schema, and look
|
|
176
|
+
* complete (#374).
|
|
177
|
+
*/
|
|
178
|
+
function openAPI3(document, input) {
|
|
179
|
+
const swagger = Reflect.get(document, "swagger");
|
|
180
|
+
if (document.openapi === void 0 && typeof swagger === "string") return Effect.fail(new GenerateError({ message: `${input} is a Swagger ${swagger} document; hono-takibi reads OpenAPI 3.x. Convert it first (npx swagger2openapi ${input} -o openapi3.json).` }));
|
|
181
|
+
return Effect.succeed(document);
|
|
182
|
+
}
|
|
170
183
|
function packageRoots(openAPI, config) {
|
|
171
184
|
return Effect.gen(function* () {
|
|
172
185
|
const referenced = referencedKinds(openAPI);
|
|
@@ -485,4 +498,4 @@ function makeJob(openAPI, config, packageRoot = () => void 0) {
|
|
|
485
498
|
].filter((job) => job !== void 0);
|
|
486
499
|
}
|
|
487
500
|
//#endregion
|
|
488
|
-
export {
|
|
501
|
+
export { packageRoots as a, outsideSources as i, makeJob as n, shared_exports as o, openAPI3 as r, cleanSplitOutputs as t };
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { c as
|
|
1
|
+
import { c as HTTP_METHODS, l as IDENTIFIER_PATTERN, r as COMPONENT_REF_PREFIX, t as ARROW_FUNCTION_PATTERN } from "./constants-hwmOoQfI.js";
|
|
2
2
|
//#region src/guard/index.ts
|
|
3
3
|
function isRecord(v) {
|
|
4
4
|
return typeof v === "object" && v !== null && !Array.isArray(v);
|
|
@@ -263,6 +263,38 @@ function methodPath(method, path) {
|
|
|
263
263
|
const apiPath = path.split("/").filter((segment) => segment !== "").map((segment) => /[A-Za-z0-9]/u.test(segment) ? segment.replaceAll(/[^A-Za-z0-9]/gu, " ") : Array.from(segment, symbolWord).join(" ")).join(" ").trim().split(/\s+/u).map((str) => `${str.charAt(0).toUpperCase()}${str.slice(1)}`).join("");
|
|
264
264
|
return apiPath ? `${method}${apiPath}${hasTrailingSlash ? "Index" : ""}` : method;
|
|
265
265
|
}
|
|
266
|
+
/**
|
|
267
|
+
* `methodPath`, made unique within a document. Two paths that differ only in separators
|
|
268
|
+
* or case (`/billable-usage` and `/billable/usage`, `/indicator-types` and
|
|
269
|
+
* `/indicatorTypes`) share a name; the first in document order keeps it, and every later
|
|
270
|
+
* one is numbered (`getEventsIndicatorTypes2`). The number comes from the path alone, so
|
|
271
|
+
* every method of the same path, and every generator that names a route, a handler, a
|
|
272
|
+
* client function or a hook after it, agrees.
|
|
273
|
+
*
|
|
274
|
+
* @example
|
|
275
|
+
* routeName('get', '/events/indicatorTypes', { '/events/indicator-types': {}, '/events/indicatorTypes': {} })
|
|
276
|
+
* // 'getEventsIndicatorTypes2'
|
|
277
|
+
*/
|
|
278
|
+
function routeName(method, path, paths) {
|
|
279
|
+
const ordinal = pathOrdinals(paths).get(path) ?? 0;
|
|
280
|
+
const name = methodPath(method, path);
|
|
281
|
+
return ordinal === 0 ? name : `${name}${ordinal + 1}`;
|
|
282
|
+
}
|
|
283
|
+
const PATH_ORDINALS = /* @__PURE__ */ new WeakMap();
|
|
284
|
+
function pathOrdinals(paths) {
|
|
285
|
+
const known = PATH_ORDINALS.get(paths);
|
|
286
|
+
if (known !== void 0) return known;
|
|
287
|
+
const seen = /* @__PURE__ */ new Map();
|
|
288
|
+
const ordinals = /* @__PURE__ */ new Map();
|
|
289
|
+
for (const path of Object.keys(paths)) {
|
|
290
|
+
const name = methodPath("", path);
|
|
291
|
+
const count = seen.get(name) ?? 0;
|
|
292
|
+
seen.set(name, count + 1);
|
|
293
|
+
ordinals.set(path, count);
|
|
294
|
+
}
|
|
295
|
+
PATH_ORDINALS.set(paths, ordinals);
|
|
296
|
+
return ordinals;
|
|
297
|
+
}
|
|
266
298
|
const SYMBOL_WORDS = {
|
|
267
299
|
"-": "Dash",
|
|
268
300
|
_: "Underscore",
|
|
@@ -365,6 +397,32 @@ const REGEX_LINE_TERMINATOR_ESCAPES = {
|
|
|
365
397
|
* escapeRegexLiteral('a\nb') // → 'a\\nb'
|
|
366
398
|
* ```
|
|
367
399
|
*/
|
|
400
|
+
/**
|
|
401
|
+
* A `pattern` as a JavaScript regex literal: its source and flags, or `undefined` when no
|
|
402
|
+
* literal can stand for it. A leading inline flag group, `(?i)` / `(?s)` / `(?m)` (PCRE,
|
|
403
|
+
* which JavaScript has not), becomes the flag; `\p{..}` asks for `u`. What is left is
|
|
404
|
+
* compiled once here: a pattern JavaScript rejects (`(?x)`, a possessive quantifier) would
|
|
405
|
+
* otherwise be written into a literal that keeps the whole file from parsing (#370).
|
|
406
|
+
*
|
|
407
|
+
* @example
|
|
408
|
+
* regexLiteral('(?i)^(pay|details)$') // { source: '^(pay|details)$', flags: 'i' }
|
|
409
|
+
* regexLiteral('a++') // undefined
|
|
410
|
+
*/
|
|
411
|
+
function regexLiteral(pattern) {
|
|
412
|
+
const inline = pattern.match(/^\(\?([a-z]+)\)/u);
|
|
413
|
+
const letters = inline?.[1] ?? "";
|
|
414
|
+
if (letters.split("").some((letter) => !"ims".includes(letter))) return void 0;
|
|
415
|
+
const source = inline === null ? pattern : pattern.slice(inline[0].length);
|
|
416
|
+
const flags = [.../* @__PURE__ */ new Set([...letters.split(""), .../\\[pP]\{/u.test(source) ? ["u"] : []])].join("");
|
|
417
|
+
try {
|
|
418
|
+
return {
|
|
419
|
+
source,
|
|
420
|
+
flags: new RegExp(source, flags).flags
|
|
421
|
+
};
|
|
422
|
+
} catch {
|
|
423
|
+
return;
|
|
424
|
+
}
|
|
425
|
+
}
|
|
368
426
|
function escapeRegexLiteral(source) {
|
|
369
427
|
return source.replaceAll(/\\([\s\S]?)|[/\n\r\u2028\u2029]/gu, (match, escaped) => {
|
|
370
428
|
if (escaped === void 0) return match === "/" ? "\\/" : REGEX_LINE_TERMINATOR_ESCAPES[match] ?? match;
|
|
@@ -616,4 +674,4 @@ function cyclicNodes(deps) {
|
|
|
616
674
|
return result;
|
|
617
675
|
}
|
|
618
676
|
//#endregion
|
|
619
|
-
export {
|
|
677
|
+
export { isResponses as $, isCallbacks as A, isOperation as B, discriminatedBranches as C, hasNumericConstraint as D, hasNotProperty as E, isInlineMedia as F, isParameterRef as G, isParameter as H, isMedia as I, isPathItemRef as J, isPathItem as K, isMediaWithSchema as L, isHeader as M, isHttpMethod as N, hasRequestBodyContent as O, isInheritedName as P, isRequestBody as Q, isOffsetTime as R, zodToOpenAPISchema as S, hasNoUserChain as T, isParameterArray as U, isOperationLike as V, isParameterObject as W, isRefObject as X, isRecord as Y, isRefOnly as Z, routeName as _, ensureSuffix as a, isSingleSchema as at, uncapitalize as b, escapeRegexLiteral as c, makeSafeKey as d, isSchemaArray as et, makeStringLiteral as f, requestParamsArray as g, renderNamedImport as h, decodePercent as i, isSecurityScheme as it, isExamplesInput as j, hasTypelessConstraint as k, makeBarrel as l, regexLiteral as m, capitalize as n, isSchemaProperty as nt, error as o, isStringRef as ot, normalizeTypes as p, isPathItemEntry as q, cyclicNodes as r, isSecurityArray as rt, escapeHtml as s, isValidIdent as st, baseError as t, isSchemaObject as tt, makeInferRequestType as u, statusCodeToNumber as v, hasNoContentResponse as w, uncapitalizeWord as x, toIdentifierPascalCase as y, isOpenAPIPaths as z };
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { u as INPUT_EXTENSIONS } from "../constants-hwmOoQfI.js";
|
|
2
2
|
import { parseConfig } from "../index.js";
|
|
3
3
|
import { t as FormatOptions } from "../format-CuHABcKC.js";
|
|
4
|
-
import {
|
|
5
|
-
import { C as isInsideDirectory, S as appEntryOutput } from "../core-
|
|
4
|
+
import { Y as isRecord } from "../utils-Bw0Q2Ozg.js";
|
|
5
|
+
import { C as isInsideDirectory, S as appEntryOutput } from "../core-FnayWJZV.js";
|
|
6
6
|
import { n as parseOpenAPI } from "../openapi-t_u-tF52.js";
|
|
7
|
-
import {
|
|
7
|
+
import { a as packageRoots, i as outsideSources, n as makeJob, r as openAPI3, t as cleanSplitOutputs } from "../shared-BvbKZMJK.js";
|
|
8
8
|
import { Effect, FileSystem, Option, Result } from "effect";
|
|
9
9
|
import path from "node:path";
|
|
10
10
|
import crypto from "node:crypto";
|
|
@@ -147,7 +147,12 @@ function sameOutputSnapshot(before, after) {
|
|
|
147
147
|
*/
|
|
148
148
|
function runAllGenerationTasks(config) {
|
|
149
149
|
return Effect.gen(function* () {
|
|
150
|
-
const
|
|
150
|
+
const parsed = yield* Effect.result(parseOpenAPI(config.input));
|
|
151
|
+
if (Result.isFailure(parsed)) return {
|
|
152
|
+
logs: [`❌ parseOpenAPI: ${parsed.failure.message}`],
|
|
153
|
+
changed: false
|
|
154
|
+
};
|
|
155
|
+
const openAPIResult = yield* Effect.result(openAPI3(parsed.success, config.input));
|
|
151
156
|
if (Result.isFailure(openAPIResult)) return {
|
|
152
157
|
logs: [`❌ parseOpenAPI: ${openAPIResult.failure.message}`],
|
|
153
158
|
changed: false
|