@kubb/agent 5.0.0-alpha.34 → 5.0.0-alpha.36
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/.output/nitro.json +1 -1
- package/.output/server/chunks/nitro/nitro.mjs +1790 -20812
- package/.output/server/chunks/nitro/nitro.mjs.map +1 -1
- package/.output/server/chunks/routes/api/health.get.mjs +16 -14
- package/.output/server/chunks/routes/api/health.get.mjs.map +1 -1
- package/.output/server/index.mjs +16 -14
- package/.output/server/index.mjs.map +1 -1
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/constants.js +18 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/permessage-deflate.js +514 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/sender.js +602 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/stream.js +159 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/websocket-server.js +540 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/lib/websocket.js +1388 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/package.json +69 -0
- package/.output/server/node_modules/.nitro/ws@8.18.0/wrapper.mjs +8 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/buffer-util.js +131 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/event-target.js +292 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/extension.js +203 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/limiter.js +55 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/receiver.js +706 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/subprotocol.js +62 -0
- package/.output/server/node_modules/.nitro/ws@8.20.0/lib/validation.js +152 -0
- package/.output/server/node_modules/@clack/core/dist/index.mjs +11 -0
- package/.output/server/node_modules/@clack/core/package.json +60 -0
- package/.output/server/node_modules/@clack/prompts/dist/index.mjs +137 -0
- package/.output/server/node_modules/@clack/prompts/package.json +65 -0
- package/.output/server/node_modules/@kubb/ast/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/ast/dist/index.js +423 -0
- package/.output/server/node_modules/@kubb/ast/package.json +70 -0
- package/.output/server/node_modules/@kubb/core/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/core/dist/hooks.js +23 -0
- package/.output/server/node_modules/@kubb/core/dist/index.js +2311 -0
- package/.output/server/node_modules/@kubb/core/package.json +109 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/chunk-O_arW02_.js +17 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/defaultParser-iCpMSYCp.js +15 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/getRelativePath-NAm_Y-vp.js +55 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/index.js +653 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/onProcessExit-Cput7j2c.js +742 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/parsers/typescript.js +101 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/parsers.js +17 -0
- package/.output/server/node_modules/@kubb/fabric-core/dist/plugins.js +375 -0
- package/.output/server/node_modules/@kubb/fabric-core/package.json +111 -0
- package/.output/server/node_modules/@kubb/oas/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/oas/dist/index.js +918 -0
- package/.output/server/node_modules/@kubb/oas/package.json +94 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/StaticClassClient-bCe7RG_w.js +636 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/components.js +2 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/generators-BffddRNu.js +723 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/index.js +124 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/templates/clients/axios.source.js +6 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/templates/clients/fetch.source.js +6 -0
- package/.output/server/node_modules/@kubb/plugin-client/dist/templates/config.source.js +6 -0
- package/.output/server/node_modules/@kubb/plugin-client/package.json +153 -0
- package/.output/server/node_modules/@kubb/plugin-cypress/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-cypress/dist/components-BK_6GU4v.js +257 -0
- package/.output/server/node_modules/@kubb/plugin-cypress/dist/generators-D5YFtyyC.js +71 -0
- package/.output/server/node_modules/@kubb/plugin-cypress/dist/index.js +79 -0
- package/.output/server/node_modules/@kubb/plugin-cypress/package.json +108 -0
- package/.output/server/node_modules/@kubb/plugin-faker/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-faker/dist/components-BkBIov4R.js +419 -0
- package/.output/server/node_modules/@kubb/plugin-faker/dist/fakerGenerator-BztogaeO.js +200 -0
- package/.output/server/node_modules/@kubb/plugin-faker/dist/index.js +141 -0
- package/.output/server/node_modules/@kubb/plugin-faker/package.json +103 -0
- package/.output/server/node_modules/@kubb/plugin-mcp/dist/Server-H3SwqhwF.js +178 -0
- package/.output/server/node_modules/@kubb/plugin-mcp/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-mcp/dist/generators-BqkMrcs9.js +274 -0
- package/.output/server/node_modules/@kubb/plugin-mcp/dist/index.js +122 -0
- package/.output/server/node_modules/@kubb/plugin-mcp/package.json +107 -0
- package/.output/server/node_modules/@kubb/plugin-msw/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-msw/dist/components-DgtTZkWX.js +277 -0
- package/.output/server/node_modules/@kubb/plugin-msw/dist/generators-C34kqa1L.js +161 -0
- package/.output/server/node_modules/@kubb/plugin-msw/dist/index.js +84 -0
- package/.output/server/node_modules/@kubb/plugin-msw/package.json +109 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/SchemaMapper-CqMkO2T1.js +58 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/generators-D7C3CXsN.js +79 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/generators.js +2 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/getFooter-Pw3tLCiV.js +112 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/hooks.js +200 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/index.js +408 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/requestBody-pRavthCw.js +1336 -0
- package/.output/server/node_modules/@kubb/plugin-oas/dist/utils.js +268 -0
- package/.output/server/node_modules/@kubb/plugin-oas/package.json +122 -0
- package/.output/server/node_modules/@kubb/plugin-react-query/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-react-query/dist/components-CpyHYGOw.js +1520 -0
- package/.output/server/node_modules/@kubb/plugin-react-query/dist/generators-CpiBv5eE.js +1427 -0
- package/.output/server/node_modules/@kubb/plugin-react-query/dist/index.js +166 -0
- package/.output/server/node_modules/@kubb/plugin-react-query/package.json +112 -0
- package/.output/server/node_modules/@kubb/plugin-redoc/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-redoc/dist/index.js +65 -0
- package/.output/server/node_modules/@kubb/plugin-redoc/package.json +85 -0
- package/.output/server/node_modules/@kubb/plugin-redoc/static/redoc.hbs +22 -0
- package/.output/server/node_modules/@kubb/plugin-solid-query/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-solid-query/dist/components-BhStIi1M.js +665 -0
- package/.output/server/node_modules/@kubb/plugin-solid-query/dist/generators-CQClzsST.js +415 -0
- package/.output/server/node_modules/@kubb/plugin-solid-query/dist/index.js +145 -0
- package/.output/server/node_modules/@kubb/plugin-solid-query/package.json +113 -0
- package/.output/server/node_modules/@kubb/plugin-svelte-query/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-svelte-query/dist/components-DntKBsnB.js +666 -0
- package/.output/server/node_modules/@kubb/plugin-svelte-query/dist/generators-BtTsGGrM.js +414 -0
- package/.output/server/node_modules/@kubb/plugin-svelte-query/dist/index.js +145 -0
- package/.output/server/node_modules/@kubb/plugin-svelte-query/package.json +113 -0
- package/.output/server/node_modules/@kubb/plugin-swr/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-swr/dist/components-DRDGvgXG.js +702 -0
- package/.output/server/node_modules/@kubb/plugin-swr/dist/generators-ClWZJ-YG.js +399 -0
- package/.output/server/node_modules/@kubb/plugin-swr/dist/index.js +144 -0
- package/.output/server/node_modules/@kubb/plugin-swr/package.json +115 -0
- package/.output/server/node_modules/@kubb/plugin-ts/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-ts/dist/components-C7fu-sK1.js +723 -0
- package/.output/server/node_modules/@kubb/plugin-ts/dist/index.js +2 -0
- package/.output/server/node_modules/@kubb/plugin-ts/dist/plugin-CYC-FGXe.js +479 -0
- package/.output/server/node_modules/@kubb/plugin-ts/package.json +105 -0
- package/.output/server/node_modules/@kubb/plugin-vue-query/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-vue-query/dist/components-_AMBl0g-.js +1029 -0
- package/.output/server/node_modules/@kubb/plugin-vue-query/dist/generators-Zb1s5Wmb.js +661 -0
- package/.output/server/node_modules/@kubb/plugin-vue-query/dist/index.js +157 -0
- package/.output/server/node_modules/@kubb/plugin-vue-query/package.json +114 -0
- package/.output/server/node_modules/@kubb/plugin-zod/dist/chunk--u3MIqq1.js +8 -0
- package/.output/server/node_modules/@kubb/plugin-zod/dist/components-eECfXVou.js +842 -0
- package/.output/server/node_modules/@kubb/plugin-zod/dist/generators-D1R6NNf2.js +290 -0
- package/.output/server/node_modules/@kubb/plugin-zod/dist/index.js +175 -0
- package/.output/server/node_modules/@kubb/plugin-zod/dist/templates/ToZod.source.js +6 -0
- package/.output/server/node_modules/@kubb/plugin-zod/package.json +112 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/chunk-BGCRLu6H.js +38 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/index.js +525 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/jsx-runtime-Bl0DfUmV.js +1448 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/jsx-runtime.js +12 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/parsers.js +2 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/plugins.js +4 -0
- package/.output/server/node_modules/@kubb/react-fabric/dist/reactPlugin-QQPrjNuQ.js +17813 -0
- package/.output/server/node_modules/@kubb/react-fabric/package.json +143 -0
- package/.output/server/node_modules/@redocly/config/lib/root-config-schema.js +11 -1
- package/.output/server/node_modules/@redocly/config/package.json +1 -1
- package/.output/server/node_modules/@redocly/openapi-core/lib/bundle/bundle-document.js +25 -10
- package/.output/server/node_modules/@redocly/openapi-core/lib/bundle/bundle-visitor.js +32 -29
- package/.output/server/node_modules/@redocly/openapi-core/lib/config/config.js +5 -0
- package/.output/server/node_modules/@redocly/openapi-core/lib/decorators/oas2/index.js +1 -1
- package/.output/server/node_modules/@redocly/openapi-core/lib/decorators/oas2/remove-unused-components.js +47 -38
- package/.output/server/node_modules/@redocly/openapi-core/lib/decorators/oas3/index.js +1 -1
- package/.output/server/node_modules/@redocly/openapi-core/lib/decorators/oas3/remove-unused-components.js +45 -41
- package/.output/server/node_modules/@redocly/openapi-core/lib/rules/common/no-http-verbs-in-paths.js +3 -1
- package/.output/server/node_modules/@redocly/openapi-core/lib/rules/common/no-required-schema-properties-undefined.js +41 -55
- package/.output/server/node_modules/@redocly/openapi-core/lib/walk.js +28 -16
- package/.output/server/node_modules/@redocly/openapi-core/package.json +2 -2
- package/.output/server/node_modules/buffer-from/index.js +72 -0
- package/.output/server/node_modules/buffer-from/package.json +19 -0
- package/.output/server/node_modules/fast-string-truncated-width/dist/index.js +171 -0
- package/.output/server/node_modules/fast-string-truncated-width/dist/utils.js +15 -0
- package/.output/server/node_modules/fast-string-truncated-width/package.json +35 -0
- package/.output/server/node_modules/fast-string-width/dist/index.js +14 -0
- package/.output/server/node_modules/fast-string-width/package.json +34 -0
- package/.output/server/node_modules/fast-wrap-ansi/lib/main.js +216 -0
- package/.output/server/node_modules/fast-wrap-ansi/package.json +51 -0
- package/.output/server/node_modules/p-limit/index.js +127 -0
- package/.output/server/node_modules/p-limit/package.json +58 -0
- package/.output/server/node_modules/react-devtools-core/dist/backend.js +18302 -0
- package/.output/server/node_modules/react-devtools-core/package.json +38 -0
- package/.output/server/node_modules/sisteransi/package.json +34 -0
- package/.output/server/node_modules/sisteransi/src/index.js +58 -0
- package/.output/server/node_modules/source-map-support/package.json +31 -0
- package/.output/server/node_modules/source-map-support/source-map-support.js +625 -0
- package/.output/server/node_modules/typescript/lib/typescript.js +200276 -0
- package/.output/server/node_modules/typescript/package.json +120 -0
- package/.output/server/node_modules/yocto-queue/index.js +90 -0
- package/.output/server/node_modules/yocto-queue/package.json +48 -0
- package/.output/server/package.json +35 -4
- package/package.json +20 -20
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/buffer-util.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/event-target.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/extension.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/limiter.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/receiver.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/subprotocol.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.18.0}/lib/validation.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/constants.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/permessage-deflate.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/sender.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/stream.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/websocket-server.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/lib/websocket.js +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/package.json +0 -0
- /package/.output/server/node_modules/{ws → .nitro/ws@8.20.0}/wrapper.mjs +0 -0
|
@@ -0,0 +1,636 @@
|
|
|
1
|
+
import { t as __name } from "./chunk--u3MIqq1.js";
|
|
2
|
+
import { getComments, getParamsMapping, getPathParams } from "@kubb/plugin-oas/utils";
|
|
3
|
+
import { Const, File, Function as Function$1, FunctionParams } from "@kubb/react-fabric";
|
|
4
|
+
import { getDefaultValue, isOptional } from "@kubb/oas";
|
|
5
|
+
import { Fragment, jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
|
|
6
|
+
//#region ../../internals/utils/src/casing.ts
|
|
7
|
+
/**
|
|
8
|
+
* Shared implementation for camelCase and PascalCase conversion.
|
|
9
|
+
* Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
|
|
10
|
+
* and capitalizes each word according to `pascal`.
|
|
11
|
+
*
|
|
12
|
+
* When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
|
|
13
|
+
*/
|
|
14
|
+
function toCamelOrPascal(text, pascal) {
|
|
15
|
+
return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
|
|
16
|
+
if (word.length > 1 && word === word.toUpperCase()) return word;
|
|
17
|
+
if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
|
|
18
|
+
return word.charAt(0).toUpperCase() + word.slice(1);
|
|
19
|
+
}).join("").replace(/[^a-zA-Z0-9]/g, "");
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* Splits `text` on `.` and applies `transformPart` to each segment.
|
|
23
|
+
* The last segment receives `isLast = true`, all earlier segments receive `false`.
|
|
24
|
+
* Segments are joined with `/` to form a file path.
|
|
25
|
+
*/
|
|
26
|
+
function applyToFileParts(text, transformPart) {
|
|
27
|
+
const parts = text.split(".");
|
|
28
|
+
return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
|
|
29
|
+
}
|
|
30
|
+
/**
|
|
31
|
+
* Converts `text` to camelCase.
|
|
32
|
+
* When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
|
|
33
|
+
*
|
|
34
|
+
* @example
|
|
35
|
+
* camelCase('hello-world') // 'helloWorld'
|
|
36
|
+
* camelCase('pet.petId', { isFile: true }) // 'pet/petId'
|
|
37
|
+
*/
|
|
38
|
+
function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
39
|
+
if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
|
|
40
|
+
prefix,
|
|
41
|
+
suffix
|
|
42
|
+
} : {}));
|
|
43
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Converts `text` to PascalCase.
|
|
47
|
+
* When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.
|
|
48
|
+
*
|
|
49
|
+
* @example
|
|
50
|
+
* pascalCase('hello-world') // 'HelloWorld'
|
|
51
|
+
* pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'
|
|
52
|
+
*/
|
|
53
|
+
function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
|
|
54
|
+
if (isFile) return applyToFileParts(text, (part, isLast) => isLast ? pascalCase(part, {
|
|
55
|
+
prefix,
|
|
56
|
+
suffix
|
|
57
|
+
}) : camelCase(part));
|
|
58
|
+
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
|
|
59
|
+
}
|
|
60
|
+
//#endregion
|
|
61
|
+
//#region ../../internals/utils/src/jsdoc.ts
|
|
62
|
+
/**
|
|
63
|
+
* Builds a JSDoc comment block from an array of lines.
|
|
64
|
+
* Returns `fallback` when `comments` is empty so callers always get a usable string.
|
|
65
|
+
*/
|
|
66
|
+
function buildJSDoc(comments, options = {}) {
|
|
67
|
+
const { indent = " * ", suffix = "\n ", fallback = " " } = options;
|
|
68
|
+
if (comments.length === 0) return fallback;
|
|
69
|
+
return `/**\n${comments.map((c) => `${indent}${c}`).join("\n")}\n */${suffix}`;
|
|
70
|
+
}
|
|
71
|
+
//#endregion
|
|
72
|
+
//#region ../../internals/utils/src/reserved.ts
|
|
73
|
+
/**
|
|
74
|
+
* Returns `true` when `name` is a syntactically valid JavaScript variable name.
|
|
75
|
+
*/
|
|
76
|
+
function isValidVarName(name) {
|
|
77
|
+
try {
|
|
78
|
+
new Function(`var ${name}`);
|
|
79
|
+
} catch {
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
return true;
|
|
83
|
+
}
|
|
84
|
+
//#endregion
|
|
85
|
+
//#region ../../internals/utils/src/urlPath.ts
|
|
86
|
+
/**
|
|
87
|
+
* Parses and transforms an OpenAPI/Swagger path string into various URL formats.
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* const p = new URLPath('/pet/{petId}')
|
|
91
|
+
* p.URL // '/pet/:petId'
|
|
92
|
+
* p.template // '`/pet/${petId}`'
|
|
93
|
+
*/
|
|
94
|
+
var URLPath = class {
|
|
95
|
+
/** The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`. */
|
|
96
|
+
path;
|
|
97
|
+
#options;
|
|
98
|
+
constructor(path, options = {}) {
|
|
99
|
+
this.path = path;
|
|
100
|
+
this.#options = options;
|
|
101
|
+
}
|
|
102
|
+
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
|
|
103
|
+
get URL() {
|
|
104
|
+
return this.toURLPath();
|
|
105
|
+
}
|
|
106
|
+
/** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`). */
|
|
107
|
+
get isURL() {
|
|
108
|
+
try {
|
|
109
|
+
return !!new URL(this.path).href;
|
|
110
|
+
} catch {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
116
|
+
*
|
|
117
|
+
* @example
|
|
118
|
+
* new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
|
|
119
|
+
* new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
|
|
120
|
+
*/
|
|
121
|
+
get template() {
|
|
122
|
+
return this.toTemplateString();
|
|
123
|
+
}
|
|
124
|
+
/** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set. */
|
|
125
|
+
get object() {
|
|
126
|
+
return this.toObject();
|
|
127
|
+
}
|
|
128
|
+
/** Returns a map of path parameter names, or `undefined` when the path has no parameters. */
|
|
129
|
+
get params() {
|
|
130
|
+
return this.getParams();
|
|
131
|
+
}
|
|
132
|
+
#transformParam(raw) {
|
|
133
|
+
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
134
|
+
return this.#options.casing === "camelcase" ? camelCase(param) : param;
|
|
135
|
+
}
|
|
136
|
+
/** Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name. */
|
|
137
|
+
#eachParam(fn) {
|
|
138
|
+
for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
|
|
139
|
+
const raw = match[1];
|
|
140
|
+
fn(raw, this.#transformParam(raw));
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
toObject({ type = "path", replacer, stringify } = {}) {
|
|
144
|
+
const object = {
|
|
145
|
+
url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
|
|
146
|
+
params: this.getParams()
|
|
147
|
+
};
|
|
148
|
+
if (stringify) {
|
|
149
|
+
if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
|
|
150
|
+
if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
|
|
151
|
+
return `{ url: '${object.url}' }`;
|
|
152
|
+
}
|
|
153
|
+
return object;
|
|
154
|
+
}
|
|
155
|
+
/**
|
|
156
|
+
* Converts the OpenAPI path to a TypeScript template literal string.
|
|
157
|
+
* An optional `replacer` can transform each extracted parameter name before interpolation.
|
|
158
|
+
*
|
|
159
|
+
* @example
|
|
160
|
+
* new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
|
|
161
|
+
*/
|
|
162
|
+
toTemplateString({ prefix = "", replacer } = {}) {
|
|
163
|
+
return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
|
|
164
|
+
if (i % 2 === 0) return part;
|
|
165
|
+
const param = this.#transformParam(part);
|
|
166
|
+
return `\${${replacer ? replacer(param) : param}}`;
|
|
167
|
+
}).join("")}\``;
|
|
168
|
+
}
|
|
169
|
+
/**
|
|
170
|
+
* Extracts all `{param}` segments from the path and returns them as a key-value map.
|
|
171
|
+
* An optional `replacer` transforms each parameter name in both key and value positions.
|
|
172
|
+
* Returns `undefined` when no path parameters are found.
|
|
173
|
+
*/
|
|
174
|
+
getParams(replacer) {
|
|
175
|
+
const params = {};
|
|
176
|
+
this.#eachParam((_raw, param) => {
|
|
177
|
+
const key = replacer ? replacer(param) : param;
|
|
178
|
+
params[key] = key;
|
|
179
|
+
});
|
|
180
|
+
return Object.keys(params).length > 0 ? params : void 0;
|
|
181
|
+
}
|
|
182
|
+
/** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`. */
|
|
183
|
+
toURLPath() {
|
|
184
|
+
return this.path.replace(/\{([^}]+)\}/g, ":$1");
|
|
185
|
+
}
|
|
186
|
+
};
|
|
187
|
+
//#endregion
|
|
188
|
+
//#region src/components/Url.tsx
|
|
189
|
+
function getParams$1({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
|
|
190
|
+
if (paramsType === "object") {
|
|
191
|
+
const pathParams = getPathParams(typeSchemas.pathParams, {
|
|
192
|
+
typed: true,
|
|
193
|
+
casing: paramsCasing
|
|
194
|
+
});
|
|
195
|
+
return FunctionParams.factory({ data: {
|
|
196
|
+
mode: "object",
|
|
197
|
+
children: { ...pathParams }
|
|
198
|
+
} });
|
|
199
|
+
}
|
|
200
|
+
return FunctionParams.factory({ pathParams: typeSchemas.pathParams?.name ? {
|
|
201
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
202
|
+
children: getPathParams(typeSchemas.pathParams, {
|
|
203
|
+
typed: true,
|
|
204
|
+
casing: paramsCasing
|
|
205
|
+
}),
|
|
206
|
+
default: getDefaultValue(typeSchemas.pathParams?.schema)
|
|
207
|
+
} : void 0 });
|
|
208
|
+
}
|
|
209
|
+
__name(getParams$1, "getParams");
|
|
210
|
+
function Url({ name, isExportable = true, isIndexable = true, typeSchemas, baseURL, paramsType, paramsCasing, pathParamsType, operation }) {
|
|
211
|
+
const path = new URLPath(operation.path);
|
|
212
|
+
const params = getParams$1({
|
|
213
|
+
paramsType,
|
|
214
|
+
paramsCasing,
|
|
215
|
+
pathParamsType,
|
|
216
|
+
typeSchemas
|
|
217
|
+
});
|
|
218
|
+
const pathParamsMapping = paramsCasing ? getParamsMapping(typeSchemas.pathParams, { casing: paramsCasing }) : void 0;
|
|
219
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
220
|
+
name,
|
|
221
|
+
isExportable,
|
|
222
|
+
isIndexable,
|
|
223
|
+
children: /* @__PURE__ */ jsxs(Function$1, {
|
|
224
|
+
name,
|
|
225
|
+
export: isExportable,
|
|
226
|
+
params: params.toConstructor(),
|
|
227
|
+
children: [
|
|
228
|
+
pathParamsMapping && Object.entries(pathParamsMapping).filter(([originalName, camelCaseName]) => originalName !== camelCaseName && isValidVarName(originalName)).map(([originalName, camelCaseName]) => `const ${originalName} = ${camelCaseName}`).join("\n"),
|
|
229
|
+
pathParamsMapping && /* @__PURE__ */ jsx("br", {}),
|
|
230
|
+
/* @__PURE__ */ jsx(Const, {
|
|
231
|
+
name: "res",
|
|
232
|
+
children: `{ method: '${operation.method.toUpperCase()}', url: ${path.toTemplateString({ prefix: baseURL })} as const }`
|
|
233
|
+
}),
|
|
234
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
235
|
+
"return res"
|
|
236
|
+
]
|
|
237
|
+
})
|
|
238
|
+
});
|
|
239
|
+
}
|
|
240
|
+
Url.getParams = getParams$1;
|
|
241
|
+
//#endregion
|
|
242
|
+
//#region src/components/Client.tsx
|
|
243
|
+
function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable }) {
|
|
244
|
+
if (paramsType === "object") {
|
|
245
|
+
const children = {
|
|
246
|
+
...getPathParams(typeSchemas.pathParams, {
|
|
247
|
+
typed: true,
|
|
248
|
+
casing: paramsCasing
|
|
249
|
+
}),
|
|
250
|
+
data: typeSchemas.request?.name ? {
|
|
251
|
+
type: typeSchemas.request?.name,
|
|
252
|
+
optional: isOptional(typeSchemas.request?.schema)
|
|
253
|
+
} : void 0,
|
|
254
|
+
params: typeSchemas.queryParams?.name ? {
|
|
255
|
+
type: typeSchemas.queryParams?.name,
|
|
256
|
+
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
257
|
+
} : void 0,
|
|
258
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
259
|
+
type: typeSchemas.headerParams?.name,
|
|
260
|
+
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
261
|
+
} : void 0
|
|
262
|
+
};
|
|
263
|
+
const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
|
|
264
|
+
return FunctionParams.factory({
|
|
265
|
+
data: {
|
|
266
|
+
mode: "object",
|
|
267
|
+
children,
|
|
268
|
+
default: allChildrenAreOptional ? "{}" : void 0
|
|
269
|
+
},
|
|
270
|
+
config: isConfigurable ? {
|
|
271
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
|
|
272
|
+
default: "{}"
|
|
273
|
+
} : void 0
|
|
274
|
+
});
|
|
275
|
+
}
|
|
276
|
+
return FunctionParams.factory({
|
|
277
|
+
pathParams: typeSchemas.pathParams?.name ? {
|
|
278
|
+
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
279
|
+
children: getPathParams(typeSchemas.pathParams, {
|
|
280
|
+
typed: true,
|
|
281
|
+
casing: paramsCasing
|
|
282
|
+
}),
|
|
283
|
+
default: getDefaultValue(typeSchemas.pathParams?.schema)
|
|
284
|
+
} : void 0,
|
|
285
|
+
data: typeSchemas.request?.name ? {
|
|
286
|
+
type: typeSchemas.request?.name,
|
|
287
|
+
optional: isOptional(typeSchemas.request?.schema)
|
|
288
|
+
} : void 0,
|
|
289
|
+
params: typeSchemas.queryParams?.name ? {
|
|
290
|
+
type: typeSchemas.queryParams?.name,
|
|
291
|
+
optional: isOptional(typeSchemas.queryParams?.schema)
|
|
292
|
+
} : void 0,
|
|
293
|
+
headers: typeSchemas.headerParams?.name ? {
|
|
294
|
+
type: typeSchemas.headerParams?.name,
|
|
295
|
+
optional: isOptional(typeSchemas.headerParams?.schema)
|
|
296
|
+
} : void 0,
|
|
297
|
+
config: isConfigurable ? {
|
|
298
|
+
type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
|
|
299
|
+
default: "{}"
|
|
300
|
+
} : void 0
|
|
301
|
+
});
|
|
302
|
+
}
|
|
303
|
+
function Client({ name, isExportable = true, isIndexable = true, returnType, typeSchemas, baseURL, dataReturnType, parser, zodSchemas, paramsType, paramsCasing, pathParamsType, operation, urlName, children, isConfigurable = true }) {
|
|
304
|
+
const path = new URLPath(operation.path);
|
|
305
|
+
const contentType = operation.getContentType();
|
|
306
|
+
const isFormData = contentType === "multipart/form-data";
|
|
307
|
+
const pathParamsMapping = paramsCasing ? getParamsMapping(typeSchemas.pathParams, { casing: paramsCasing }) : void 0;
|
|
308
|
+
const queryParamsMapping = paramsCasing ? getParamsMapping(typeSchemas.queryParams, { casing: paramsCasing }) : void 0;
|
|
309
|
+
const headerParamsMapping = paramsCasing ? getParamsMapping(typeSchemas.headerParams, { casing: paramsCasing }) : void 0;
|
|
310
|
+
const headers = [contentType !== "application/json" && contentType !== "multipart/form-data" ? `'Content-Type': '${contentType}'` : void 0, typeSchemas.headerParams?.name ? headerParamsMapping ? "...mappedHeaders" : "...headers" : void 0].filter(Boolean);
|
|
311
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
312
|
+
const generics = [
|
|
313
|
+
typeSchemas.response.name,
|
|
314
|
+
TError,
|
|
315
|
+
typeSchemas.request?.name || "unknown"
|
|
316
|
+
].filter(Boolean);
|
|
317
|
+
const params = getParams({
|
|
318
|
+
paramsType,
|
|
319
|
+
paramsCasing,
|
|
320
|
+
pathParamsType,
|
|
321
|
+
typeSchemas,
|
|
322
|
+
isConfigurable
|
|
323
|
+
});
|
|
324
|
+
const urlParams = Url.getParams({
|
|
325
|
+
paramsType,
|
|
326
|
+
paramsCasing,
|
|
327
|
+
pathParamsType,
|
|
328
|
+
typeSchemas
|
|
329
|
+
});
|
|
330
|
+
const clientParams = FunctionParams.factory({ config: {
|
|
331
|
+
mode: "object",
|
|
332
|
+
children: {
|
|
333
|
+
method: { value: JSON.stringify(operation.method.toUpperCase()) },
|
|
334
|
+
url: { value: urlName ? `${urlName}(${urlParams.toCall()}).url.toString()` : path.template },
|
|
335
|
+
baseURL: baseURL && !urlName ? { value: `\`${baseURL}\`` } : void 0,
|
|
336
|
+
params: typeSchemas.queryParams?.name ? queryParamsMapping ? { value: "mappedParams" } : {} : void 0,
|
|
337
|
+
data: typeSchemas.request?.name ? { value: isFormData ? "formData as FormData" : "requestData" } : void 0,
|
|
338
|
+
requestConfig: isConfigurable ? { mode: "inlineSpread" } : void 0,
|
|
339
|
+
headers: headers.length ? { value: isConfigurable ? `{ ${headers.join(", ")}, ...requestConfig.headers }` : `{ ${headers.join(", ")} }` } : void 0
|
|
340
|
+
}
|
|
341
|
+
} });
|
|
342
|
+
const childrenElement = children ? children : /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
343
|
+
dataReturnType === "full" && parser === "zod" && zodSchemas && `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`,
|
|
344
|
+
dataReturnType === "data" && parser === "zod" && zodSchemas && `return ${zodSchemas.response.name}.parse(res.data)`,
|
|
345
|
+
dataReturnType === "full" && parser === "client" && "return res",
|
|
346
|
+
dataReturnType === "data" && parser === "client" && "return res.data"
|
|
347
|
+
] });
|
|
348
|
+
return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx(File.Source, {
|
|
349
|
+
name,
|
|
350
|
+
isExportable,
|
|
351
|
+
isIndexable,
|
|
352
|
+
children: /* @__PURE__ */ jsxs(Function$1, {
|
|
353
|
+
name,
|
|
354
|
+
async: true,
|
|
355
|
+
export: isExportable,
|
|
356
|
+
params: params.toConstructor(),
|
|
357
|
+
JSDoc: { comments: getComments(operation) },
|
|
358
|
+
returnType,
|
|
359
|
+
children: [
|
|
360
|
+
isConfigurable ? "const { client: request = fetch, ...requestConfig } = config" : "",
|
|
361
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
362
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
363
|
+
!urlName && pathParamsMapping && Object.entries(pathParamsMapping).filter(([originalName, camelCaseName]) => originalName !== camelCaseName && isValidVarName(originalName)).map(([originalName, camelCaseName]) => `const ${originalName} = ${camelCaseName}`).join("\n"),
|
|
364
|
+
!urlName && pathParamsMapping && /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx("br", {}), /* @__PURE__ */ jsx("br", {})] }),
|
|
365
|
+
queryParamsMapping && typeSchemas.queryParams?.name && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
366
|
+
`const mappedParams = params ? { ${Object.entries(queryParamsMapping).map(([originalName, camelCaseName]) => `"${originalName}": params.${camelCaseName}`).join(", ")} } : undefined`,
|
|
367
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
368
|
+
/* @__PURE__ */ jsx("br", {})
|
|
369
|
+
] }),
|
|
370
|
+
headerParamsMapping && typeSchemas.headerParams?.name && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
371
|
+
`const mappedHeaders = headers ? { ${Object.entries(headerParamsMapping).map(([originalName, camelCaseName]) => `"${originalName}": headers.${camelCaseName}`).join(", ")} } : undefined`,
|
|
372
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
373
|
+
/* @__PURE__ */ jsx("br", {})
|
|
374
|
+
] }),
|
|
375
|
+
parser === "zod" && zodSchemas?.request?.name ? `const requestData = ${zodSchemas.request.name}.parse(data)` : typeSchemas?.request?.name && "const requestData = data",
|
|
376
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
377
|
+
isFormData && typeSchemas?.request?.name && "const formData = buildFormData(requestData)",
|
|
378
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
379
|
+
isConfigurable ? `const res = await request<${generics.join(", ")}>(${clientParams.toCall()})` : `const res = await fetch<${generics.join(", ")}>(${clientParams.toCall()})`,
|
|
380
|
+
/* @__PURE__ */ jsx("br", {}),
|
|
381
|
+
childrenElement
|
|
382
|
+
]
|
|
383
|
+
})
|
|
384
|
+
})] });
|
|
385
|
+
}
|
|
386
|
+
Client.getParams = getParams;
|
|
387
|
+
//#endregion
|
|
388
|
+
//#region src/components/ClassClient.tsx
|
|
389
|
+
function buildHeaders$1(contentType, hasHeaderParams) {
|
|
390
|
+
return [contentType !== "application/json" && contentType !== "multipart/form-data" ? `'Content-Type': '${contentType}'` : void 0, hasHeaderParams ? "...headers" : void 0].filter(Boolean);
|
|
391
|
+
}
|
|
392
|
+
__name(buildHeaders$1, "buildHeaders");
|
|
393
|
+
function buildGenerics$1(typeSchemas) {
|
|
394
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
395
|
+
return [
|
|
396
|
+
typeSchemas.response.name,
|
|
397
|
+
TError,
|
|
398
|
+
typeSchemas.request?.name || "unknown"
|
|
399
|
+
].filter(Boolean);
|
|
400
|
+
}
|
|
401
|
+
__name(buildGenerics$1, "buildGenerics");
|
|
402
|
+
function buildClientParams$1({ operation, path, baseURL, typeSchemas, isFormData, headers }) {
|
|
403
|
+
return FunctionParams.factory({ config: {
|
|
404
|
+
mode: "object",
|
|
405
|
+
children: {
|
|
406
|
+
requestConfig: { mode: "inlineSpread" },
|
|
407
|
+
method: { value: JSON.stringify(operation.method.toUpperCase()) },
|
|
408
|
+
url: { value: path.template },
|
|
409
|
+
baseURL: baseURL ? { value: JSON.stringify(baseURL) } : void 0,
|
|
410
|
+
params: typeSchemas.queryParams?.name ? {} : void 0,
|
|
411
|
+
data: typeSchemas.request?.name ? { value: isFormData ? "formData as FormData" : "requestData" } : void 0,
|
|
412
|
+
headers: headers.length ? { value: `{ ${headers.join(", ")}, ...requestConfig.headers }` } : void 0
|
|
413
|
+
}
|
|
414
|
+
} });
|
|
415
|
+
}
|
|
416
|
+
__name(buildClientParams$1, "buildClientParams");
|
|
417
|
+
function buildRequestDataLine$1({ parser, zodSchemas, typeSchemas }) {
|
|
418
|
+
if (parser === "zod" && zodSchemas?.request?.name) return `const requestData = ${zodSchemas.request.name}.parse(data)`;
|
|
419
|
+
if (typeSchemas?.request?.name) return "const requestData = data";
|
|
420
|
+
return "";
|
|
421
|
+
}
|
|
422
|
+
__name(buildRequestDataLine$1, "buildRequestDataLine");
|
|
423
|
+
function buildFormDataLine$1(isFormData, hasRequest) {
|
|
424
|
+
return isFormData && hasRequest ? "const formData = buildFormData(requestData)" : "";
|
|
425
|
+
}
|
|
426
|
+
__name(buildFormDataLine$1, "buildFormDataLine");
|
|
427
|
+
function buildReturnStatement$1({ dataReturnType, parser, zodSchemas }) {
|
|
428
|
+
if (dataReturnType === "full" && parser === "zod" && zodSchemas) return `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`;
|
|
429
|
+
if (dataReturnType === "data" && parser === "zod" && zodSchemas) return `return ${zodSchemas.response.name}.parse(res.data)`;
|
|
430
|
+
if (dataReturnType === "full" && parser === "client") return "return res";
|
|
431
|
+
return "return res.data";
|
|
432
|
+
}
|
|
433
|
+
__name(buildReturnStatement$1, "buildReturnStatement");
|
|
434
|
+
function generateMethod$1({ operation, name, typeSchemas, zodSchemas, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType }) {
|
|
435
|
+
const path = new URLPath(operation.path, { casing: paramsCasing });
|
|
436
|
+
const contentType = operation.getContentType();
|
|
437
|
+
const isFormData = contentType === "multipart/form-data";
|
|
438
|
+
const headers = buildHeaders$1(contentType, !!typeSchemas.headerParams?.name);
|
|
439
|
+
const generics = buildGenerics$1(typeSchemas);
|
|
440
|
+
const params = ClassClient.getParams({
|
|
441
|
+
paramsType,
|
|
442
|
+
paramsCasing,
|
|
443
|
+
pathParamsType,
|
|
444
|
+
typeSchemas,
|
|
445
|
+
isConfigurable: true
|
|
446
|
+
});
|
|
447
|
+
const clientParams = buildClientParams$1({
|
|
448
|
+
operation,
|
|
449
|
+
path,
|
|
450
|
+
baseURL,
|
|
451
|
+
typeSchemas,
|
|
452
|
+
isFormData,
|
|
453
|
+
headers
|
|
454
|
+
});
|
|
455
|
+
const jsdoc = buildJSDoc(getComments(operation));
|
|
456
|
+
const requestDataLine = buildRequestDataLine$1({
|
|
457
|
+
parser,
|
|
458
|
+
zodSchemas,
|
|
459
|
+
typeSchemas
|
|
460
|
+
});
|
|
461
|
+
const formDataLine = buildFormDataLine$1(isFormData, !!typeSchemas?.request?.name);
|
|
462
|
+
const returnStatement = buildReturnStatement$1({
|
|
463
|
+
dataReturnType,
|
|
464
|
+
parser,
|
|
465
|
+
zodSchemas
|
|
466
|
+
});
|
|
467
|
+
const methodBody = [
|
|
468
|
+
"const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)",
|
|
469
|
+
"",
|
|
470
|
+
requestDataLine,
|
|
471
|
+
formDataLine,
|
|
472
|
+
`const res = await request<${generics.join(", ")}>(${clientParams.toCall()})`,
|
|
473
|
+
returnStatement
|
|
474
|
+
].filter(Boolean).map((line) => ` ${line}`).join("\n");
|
|
475
|
+
return `${jsdoc}async ${name}(${params.toConstructor()}) {\n${methodBody}\n }`;
|
|
476
|
+
}
|
|
477
|
+
__name(generateMethod$1, "generateMethod");
|
|
478
|
+
function ClassClient({ name, isExportable = true, isIndexable = true, operations, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType, children }) {
|
|
479
|
+
const classCode = `export class ${name} {
|
|
480
|
+
#config: Partial<RequestConfig> & { client?: Client }
|
|
481
|
+
|
|
482
|
+
constructor(config: Partial<RequestConfig> & { client?: Client } = {}) {
|
|
483
|
+
this.#config = config
|
|
484
|
+
}
|
|
485
|
+
|
|
486
|
+
${operations.map(({ operation, name: methodName, typeSchemas, zodSchemas }) => generateMethod$1({
|
|
487
|
+
operation,
|
|
488
|
+
name: methodName,
|
|
489
|
+
typeSchemas,
|
|
490
|
+
zodSchemas,
|
|
491
|
+
baseURL,
|
|
492
|
+
dataReturnType,
|
|
493
|
+
parser,
|
|
494
|
+
paramsType,
|
|
495
|
+
paramsCasing,
|
|
496
|
+
pathParamsType
|
|
497
|
+
})).join("\n\n")}
|
|
498
|
+
}`;
|
|
499
|
+
return /* @__PURE__ */ jsxs(File.Source, {
|
|
500
|
+
name,
|
|
501
|
+
isExportable,
|
|
502
|
+
isIndexable,
|
|
503
|
+
children: [classCode, children]
|
|
504
|
+
});
|
|
505
|
+
}
|
|
506
|
+
ClassClient.getParams = Client.getParams;
|
|
507
|
+
//#endregion
|
|
508
|
+
//#region src/components/Operations.tsx
|
|
509
|
+
function Operations({ name, operations }) {
|
|
510
|
+
const operationsObject = {};
|
|
511
|
+
operations.forEach((operation) => {
|
|
512
|
+
operationsObject[operation.getOperationId()] = {
|
|
513
|
+
path: new URLPath(operation.path).URL,
|
|
514
|
+
method: operation.method
|
|
515
|
+
};
|
|
516
|
+
});
|
|
517
|
+
return /* @__PURE__ */ jsx(File.Source, {
|
|
518
|
+
name,
|
|
519
|
+
isExportable: true,
|
|
520
|
+
isIndexable: true,
|
|
521
|
+
children: /* @__PURE__ */ jsx(Const, {
|
|
522
|
+
name,
|
|
523
|
+
export: true,
|
|
524
|
+
children: JSON.stringify(operationsObject, void 0, 2)
|
|
525
|
+
})
|
|
526
|
+
});
|
|
527
|
+
}
|
|
528
|
+
//#endregion
|
|
529
|
+
//#region src/components/StaticClassClient.tsx
|
|
530
|
+
function buildHeaders(contentType, hasHeaderParams) {
|
|
531
|
+
return [contentType !== "application/json" && contentType !== "multipart/form-data" ? `'Content-Type': '${contentType}'` : void 0, hasHeaderParams ? "...headers" : void 0].filter(Boolean);
|
|
532
|
+
}
|
|
533
|
+
function buildGenerics(typeSchemas) {
|
|
534
|
+
const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
|
|
535
|
+
return [
|
|
536
|
+
typeSchemas.response.name,
|
|
537
|
+
TError,
|
|
538
|
+
typeSchemas.request?.name || "unknown"
|
|
539
|
+
].filter(Boolean);
|
|
540
|
+
}
|
|
541
|
+
function buildClientParams({ operation, path, baseURL, typeSchemas, isFormData, headers }) {
|
|
542
|
+
return FunctionParams.factory({ config: {
|
|
543
|
+
mode: "object",
|
|
544
|
+
children: {
|
|
545
|
+
requestConfig: { mode: "inlineSpread" },
|
|
546
|
+
method: { value: JSON.stringify(operation.method.toUpperCase()) },
|
|
547
|
+
url: { value: path.template },
|
|
548
|
+
baseURL: baseURL ? { value: JSON.stringify(baseURL) } : void 0,
|
|
549
|
+
params: typeSchemas.queryParams?.name ? {} : void 0,
|
|
550
|
+
data: typeSchemas.request?.name ? { value: isFormData ? "formData as FormData" : "requestData" } : void 0,
|
|
551
|
+
headers: headers.length ? { value: `{ ${headers.join(", ")}, ...requestConfig.headers }` } : void 0
|
|
552
|
+
}
|
|
553
|
+
} });
|
|
554
|
+
}
|
|
555
|
+
function buildRequestDataLine({ parser, zodSchemas, typeSchemas }) {
|
|
556
|
+
if (parser === "zod" && zodSchemas?.request?.name) return `const requestData = ${zodSchemas.request.name}.parse(data)`;
|
|
557
|
+
if (typeSchemas?.request?.name) return "const requestData = data";
|
|
558
|
+
return "";
|
|
559
|
+
}
|
|
560
|
+
function buildFormDataLine(isFormData, hasRequest) {
|
|
561
|
+
return isFormData && hasRequest ? "const formData = buildFormData(requestData)" : "";
|
|
562
|
+
}
|
|
563
|
+
function buildReturnStatement({ dataReturnType, parser, zodSchemas }) {
|
|
564
|
+
if (dataReturnType === "full" && parser === "zod" && zodSchemas) return `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`;
|
|
565
|
+
if (dataReturnType === "data" && parser === "zod" && zodSchemas) return `return ${zodSchemas.response.name}.parse(res.data)`;
|
|
566
|
+
if (dataReturnType === "full" && parser === "client") return "return res";
|
|
567
|
+
return "return res.data";
|
|
568
|
+
}
|
|
569
|
+
function generateMethod({ operation, name, typeSchemas, zodSchemas, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType }) {
|
|
570
|
+
const path = new URLPath(operation.path, { casing: paramsCasing });
|
|
571
|
+
const contentType = operation.getContentType();
|
|
572
|
+
const isFormData = contentType === "multipart/form-data";
|
|
573
|
+
const headers = buildHeaders(contentType, !!typeSchemas.headerParams?.name);
|
|
574
|
+
const generics = buildGenerics(typeSchemas);
|
|
575
|
+
const params = Client.getParams({
|
|
576
|
+
paramsType,
|
|
577
|
+
paramsCasing,
|
|
578
|
+
pathParamsType,
|
|
579
|
+
typeSchemas,
|
|
580
|
+
isConfigurable: true
|
|
581
|
+
});
|
|
582
|
+
const clientParams = buildClientParams({
|
|
583
|
+
operation,
|
|
584
|
+
path,
|
|
585
|
+
baseURL,
|
|
586
|
+
typeSchemas,
|
|
587
|
+
isFormData,
|
|
588
|
+
headers
|
|
589
|
+
});
|
|
590
|
+
const jsdoc = buildJSDoc(getComments(operation));
|
|
591
|
+
const requestDataLine = buildRequestDataLine({
|
|
592
|
+
parser,
|
|
593
|
+
zodSchemas,
|
|
594
|
+
typeSchemas
|
|
595
|
+
});
|
|
596
|
+
const formDataLine = buildFormDataLine(isFormData, !!typeSchemas?.request?.name);
|
|
597
|
+
const returnStatement = buildReturnStatement({
|
|
598
|
+
dataReturnType,
|
|
599
|
+
parser,
|
|
600
|
+
zodSchemas
|
|
601
|
+
});
|
|
602
|
+
const methodBody = [
|
|
603
|
+
"const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)",
|
|
604
|
+
"",
|
|
605
|
+
requestDataLine,
|
|
606
|
+
formDataLine,
|
|
607
|
+
`const res = await request<${generics.join(", ")}>(${clientParams.toCall()})`,
|
|
608
|
+
returnStatement
|
|
609
|
+
].filter(Boolean).map((line) => ` ${line}`).join("\n");
|
|
610
|
+
return `${jsdoc} static async ${name}(${params.toConstructor()}) {\n${methodBody}\n }`;
|
|
611
|
+
}
|
|
612
|
+
function StaticClassClient({ name, isExportable = true, isIndexable = true, operations, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType, children }) {
|
|
613
|
+
const classCode = `export class ${name} {\n static #config: Partial<RequestConfig> & { client?: Client } = {}\n\n${operations.map(({ operation, name: methodName, typeSchemas, zodSchemas }) => generateMethod({
|
|
614
|
+
operation,
|
|
615
|
+
name: methodName,
|
|
616
|
+
typeSchemas,
|
|
617
|
+
zodSchemas,
|
|
618
|
+
baseURL,
|
|
619
|
+
dataReturnType,
|
|
620
|
+
parser,
|
|
621
|
+
paramsType,
|
|
622
|
+
paramsCasing,
|
|
623
|
+
pathParamsType
|
|
624
|
+
})).join("\n\n")}\n}`;
|
|
625
|
+
return /* @__PURE__ */ jsxs(File.Source, {
|
|
626
|
+
name,
|
|
627
|
+
isExportable,
|
|
628
|
+
isIndexable,
|
|
629
|
+
children: [classCode, children]
|
|
630
|
+
});
|
|
631
|
+
}
|
|
632
|
+
StaticClassClient.getParams = Client.getParams;
|
|
633
|
+
//#endregion
|
|
634
|
+
export { Url as a, Client as i, Operations as n, camelCase as o, ClassClient as r, pascalCase as s, StaticClassClient as t };
|
|
635
|
+
|
|
636
|
+
//# sourceMappingURL=StaticClassClient-bCe7RG_w.js.map
|