@kubb/plugin-client 5.0.0-alpha.3 → 5.0.0-alpha.30
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/clients/axios.d.ts +2 -2
- package/dist/index.cjs +1893 -74
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +480 -4
- package/dist/index.js +1885 -77
- package/dist/index.js.map +1 -1
- package/package.json +10 -25
- package/src/components/ClassClient.tsx +42 -138
- package/src/components/Client.tsx +85 -124
- package/src/components/ClientLegacy.tsx +501 -0
- package/src/components/Operations.tsx +8 -8
- package/src/components/StaticClassClient.tsx +41 -135
- package/src/components/Url.tsx +37 -46
- package/src/generators/classClientGenerator.tsx +129 -152
- package/src/generators/clientGenerator.tsx +93 -82
- package/src/generators/groupedClientGenerator.tsx +48 -51
- package/src/generators/operationsGenerator.tsx +9 -17
- package/src/generators/staticClassClientGenerator.tsx +163 -168
- package/src/index.ts +11 -1
- package/src/plugin.ts +115 -108
- package/src/presets.ts +25 -0
- package/src/resolvers/resolverClient.ts +26 -0
- package/src/resolvers/resolverClientLegacy.ts +26 -0
- package/src/types.ts +105 -40
- package/src/utils.ts +148 -0
- package/dist/StaticClassClient-By-aMAe4.cjs +0 -677
- package/dist/StaticClassClient-By-aMAe4.cjs.map +0 -1
- package/dist/StaticClassClient-CCn9g9eF.js +0 -636
- package/dist/StaticClassClient-CCn9g9eF.js.map +0 -1
- package/dist/components.cjs +0 -7
- package/dist/components.d.ts +0 -216
- package/dist/components.js +0 -2
- package/dist/generators-C2jT7XCH.js +0 -723
- package/dist/generators-C2jT7XCH.js.map +0 -1
- package/dist/generators-qkDW17Hf.cjs +0 -753
- package/dist/generators-qkDW17Hf.cjs.map +0 -1
- package/dist/generators.cjs +0 -7
- package/dist/generators.d.ts +0 -512
- package/dist/generators.js +0 -2
- package/dist/types-CdM4DK1M.d.ts +0 -169
- package/src/components/index.ts +0 -5
- package/src/generators/index.ts +0 -5
|
@@ -1,677 +0,0 @@
|
|
|
1
|
-
const require_chunk = require("./chunk-ByKO4r7w.cjs");
|
|
2
|
-
let _kubb_plugin_oas_utils = require("@kubb/plugin-oas/utils");
|
|
3
|
-
let _kubb_react_fabric = require("@kubb/react-fabric");
|
|
4
|
-
let _kubb_oas = require("@kubb/oas");
|
|
5
|
-
let _kubb_react_fabric_jsx_runtime = require("@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 = (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
192
|
-
typed: true,
|
|
193
|
-
casing: paramsCasing
|
|
194
|
-
});
|
|
195
|
-
return _kubb_react_fabric.FunctionParams.factory({ data: {
|
|
196
|
-
mode: "object",
|
|
197
|
-
children: { ...pathParams }
|
|
198
|
-
} });
|
|
199
|
-
}
|
|
200
|
-
return _kubb_react_fabric.FunctionParams.factory({ pathParams: typeSchemas.pathParams?.name ? {
|
|
201
|
-
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
202
|
-
children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
203
|
-
typed: true,
|
|
204
|
-
casing: paramsCasing
|
|
205
|
-
}),
|
|
206
|
-
default: (0, _kubb_oas.getDefaultValue)(typeSchemas.pathParams?.schema)
|
|
207
|
-
} : void 0 });
|
|
208
|
-
}
|
|
209
|
-
require_chunk.__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 ? (0, _kubb_plugin_oas_utils.getParamsMapping)(typeSchemas.pathParams, { casing: paramsCasing }) : void 0;
|
|
219
|
-
return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
220
|
-
name,
|
|
221
|
-
isExportable,
|
|
222
|
-
isIndexable,
|
|
223
|
-
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.Function, {
|
|
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__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
|
|
230
|
-
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Const, {
|
|
231
|
-
name: "res",
|
|
232
|
-
children: `{ method: '${operation.method.toUpperCase()}', url: ${path.toTemplateString({ prefix: baseURL })} as const }`
|
|
233
|
-
}),
|
|
234
|
-
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.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
|
-
...(0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
247
|
-
typed: true,
|
|
248
|
-
casing: paramsCasing
|
|
249
|
-
}),
|
|
250
|
-
data: typeSchemas.request?.name ? {
|
|
251
|
-
type: typeSchemas.request?.name,
|
|
252
|
-
optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
|
|
253
|
-
} : void 0,
|
|
254
|
-
params: typeSchemas.queryParams?.name ? {
|
|
255
|
-
type: typeSchemas.queryParams?.name,
|
|
256
|
-
optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
257
|
-
} : void 0,
|
|
258
|
-
headers: typeSchemas.headerParams?.name ? {
|
|
259
|
-
type: typeSchemas.headerParams?.name,
|
|
260
|
-
optional: (0, _kubb_oas.isOptional)(typeSchemas.headerParams?.schema)
|
|
261
|
-
} : void 0
|
|
262
|
-
};
|
|
263
|
-
const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
|
|
264
|
-
return _kubb_react_fabric.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 _kubb_react_fabric.FunctionParams.factory({
|
|
277
|
-
pathParams: typeSchemas.pathParams?.name ? {
|
|
278
|
-
mode: pathParamsType === "object" ? "object" : "inlineSpread",
|
|
279
|
-
children: (0, _kubb_plugin_oas_utils.getPathParams)(typeSchemas.pathParams, {
|
|
280
|
-
typed: true,
|
|
281
|
-
casing: paramsCasing
|
|
282
|
-
}),
|
|
283
|
-
default: (0, _kubb_oas.getDefaultValue)(typeSchemas.pathParams?.schema)
|
|
284
|
-
} : void 0,
|
|
285
|
-
data: typeSchemas.request?.name ? {
|
|
286
|
-
type: typeSchemas.request?.name,
|
|
287
|
-
optional: (0, _kubb_oas.isOptional)(typeSchemas.request?.schema)
|
|
288
|
-
} : void 0,
|
|
289
|
-
params: typeSchemas.queryParams?.name ? {
|
|
290
|
-
type: typeSchemas.queryParams?.name,
|
|
291
|
-
optional: (0, _kubb_oas.isOptional)(typeSchemas.queryParams?.schema)
|
|
292
|
-
} : void 0,
|
|
293
|
-
headers: typeSchemas.headerParams?.name ? {
|
|
294
|
-
type: typeSchemas.headerParams?.name,
|
|
295
|
-
optional: (0, _kubb_oas.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 ? (0, _kubb_plugin_oas_utils.getParamsMapping)(typeSchemas.pathParams, { casing: paramsCasing }) : void 0;
|
|
308
|
-
const queryParamsMapping = paramsCasing ? (0, _kubb_plugin_oas_utils.getParamsMapping)(typeSchemas.queryParams, { casing: paramsCasing }) : void 0;
|
|
309
|
-
const headerParamsMapping = paramsCasing ? (0, _kubb_plugin_oas_utils.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 = _kubb_react_fabric.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__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.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__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
349
|
-
name,
|
|
350
|
-
isExportable,
|
|
351
|
-
isIndexable,
|
|
352
|
-
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.Function, {
|
|
353
|
-
name,
|
|
354
|
-
async: true,
|
|
355
|
-
export: isExportable,
|
|
356
|
-
params: params.toConstructor(),
|
|
357
|
-
JSDoc: { comments: (0, _kubb_plugin_oas_utils.getComments)(operation) },
|
|
358
|
-
returnType,
|
|
359
|
-
children: [
|
|
360
|
-
isConfigurable ? "const { client: request = fetch, ...requestConfig } = config" : "",
|
|
361
|
-
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
|
|
362
|
-
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
|
|
363
|
-
pathParamsMapping && Object.entries(pathParamsMapping).filter(([originalName, camelCaseName]) => originalName !== camelCaseName && isValidVarName(originalName)).map(([originalName, camelCaseName]) => `const ${originalName} = ${camelCaseName}`).join("\n"),
|
|
364
|
-
pathParamsMapping && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {})] }),
|
|
365
|
-
queryParamsMapping && typeSchemas.queryParams?.name && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
|
|
366
|
-
`const mappedParams = params ? { ${Object.entries(queryParamsMapping).map(([originalName, camelCaseName]) => `"${originalName}": params.${camelCaseName}`).join(", ")} } : undefined`,
|
|
367
|
-
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
|
|
368
|
-
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {})
|
|
369
|
-
] }),
|
|
370
|
-
headerParamsMapping && typeSchemas.headerParams?.name && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
|
|
371
|
-
`const mappedHeaders = headers ? { ${Object.entries(headerParamsMapping).map(([originalName, camelCaseName]) => `"${originalName}": headers.${camelCaseName}`).join(", ")} } : undefined`,
|
|
372
|
-
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
|
|
373
|
-
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {})
|
|
374
|
-
] }),
|
|
375
|
-
parser === "zod" && zodSchemas?.request?.name ? `const requestData = ${zodSchemas.request.name}.parse(data)` : typeSchemas?.request?.name && "const requestData = data",
|
|
376
|
-
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
|
|
377
|
-
isFormData && typeSchemas?.request?.name && "const formData = buildFormData(requestData)",
|
|
378
|
-
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
|
|
379
|
-
isConfigurable ? `const res = await request<${generics.join(", ")}>(${clientParams.toCall()})` : `const res = await fetch<${generics.join(", ")}>(${clientParams.toCall()})`,
|
|
380
|
-
/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.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
|
-
require_chunk.__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
|
-
require_chunk.__name(buildGenerics$1, "buildGenerics");
|
|
402
|
-
function buildClientParams$1({ operation, path, baseURL, typeSchemas, isFormData, headers }) {
|
|
403
|
-
return _kubb_react_fabric.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
|
-
require_chunk.__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
|
-
require_chunk.__name(buildRequestDataLine$1, "buildRequestDataLine");
|
|
423
|
-
function buildFormDataLine$1(isFormData, hasRequest) {
|
|
424
|
-
return isFormData && hasRequest ? "const formData = buildFormData(requestData)" : "";
|
|
425
|
-
}
|
|
426
|
-
require_chunk.__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
|
-
require_chunk.__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((0, _kubb_plugin_oas_utils.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
|
-
require_chunk.__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__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.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__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
|
|
518
|
-
name,
|
|
519
|
-
isExportable: true,
|
|
520
|
-
isIndexable: true,
|
|
521
|
-
children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.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 _kubb_react_fabric.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((0, _kubb_plugin_oas_utils.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__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File.Source, {
|
|
626
|
-
name,
|
|
627
|
-
isExportable,
|
|
628
|
-
isIndexable,
|
|
629
|
-
children: [classCode, children]
|
|
630
|
-
});
|
|
631
|
-
}
|
|
632
|
-
StaticClassClient.getParams = Client.getParams;
|
|
633
|
-
//#endregion
|
|
634
|
-
Object.defineProperty(exports, "ClassClient", {
|
|
635
|
-
enumerable: true,
|
|
636
|
-
get: function() {
|
|
637
|
-
return ClassClient;
|
|
638
|
-
}
|
|
639
|
-
});
|
|
640
|
-
Object.defineProperty(exports, "Client", {
|
|
641
|
-
enumerable: true,
|
|
642
|
-
get: function() {
|
|
643
|
-
return Client;
|
|
644
|
-
}
|
|
645
|
-
});
|
|
646
|
-
Object.defineProperty(exports, "Operations", {
|
|
647
|
-
enumerable: true,
|
|
648
|
-
get: function() {
|
|
649
|
-
return Operations;
|
|
650
|
-
}
|
|
651
|
-
});
|
|
652
|
-
Object.defineProperty(exports, "StaticClassClient", {
|
|
653
|
-
enumerable: true,
|
|
654
|
-
get: function() {
|
|
655
|
-
return StaticClassClient;
|
|
656
|
-
}
|
|
657
|
-
});
|
|
658
|
-
Object.defineProperty(exports, "Url", {
|
|
659
|
-
enumerable: true,
|
|
660
|
-
get: function() {
|
|
661
|
-
return Url;
|
|
662
|
-
}
|
|
663
|
-
});
|
|
664
|
-
Object.defineProperty(exports, "camelCase", {
|
|
665
|
-
enumerable: true,
|
|
666
|
-
get: function() {
|
|
667
|
-
return camelCase;
|
|
668
|
-
}
|
|
669
|
-
});
|
|
670
|
-
Object.defineProperty(exports, "pascalCase", {
|
|
671
|
-
enumerable: true,
|
|
672
|
-
get: function() {
|
|
673
|
-
return pascalCase;
|
|
674
|
-
}
|
|
675
|
-
});
|
|
676
|
-
|
|
677
|
-
//# sourceMappingURL=StaticClassClient-By-aMAe4.cjs.map
|