@kubb/plugin-client 5.0.0-alpha.28 → 5.0.0-alpha.29

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.
Files changed (41) hide show
  1. package/dist/index.cjs +1911 -62
  2. package/dist/index.cjs.map +1 -1
  3. package/dist/index.d.ts +468 -2
  4. package/dist/index.js +1903 -65
  5. package/dist/index.js.map +1 -1
  6. package/package.json +5 -20
  7. package/src/components/ClassClient.tsx +42 -138
  8. package/src/components/Client.tsx +85 -125
  9. package/src/components/ClientLegacy.tsx +501 -0
  10. package/src/components/Operations.tsx +8 -8
  11. package/src/components/StaticClassClient.tsx +41 -135
  12. package/src/components/Url.tsx +37 -46
  13. package/src/generators/classClientGenerator.tsx +121 -131
  14. package/src/generators/clientGenerator.tsx +104 -80
  15. package/src/generators/groupedClientGenerator.tsx +28 -30
  16. package/src/generators/operationsGenerator.tsx +11 -17
  17. package/src/generators/staticClassClientGenerator.tsx +115 -121
  18. package/src/index.ts +11 -1
  19. package/src/plugin.ts +121 -92
  20. package/src/presets.ts +25 -0
  21. package/src/resolvers/resolverClient.ts +26 -0
  22. package/src/resolvers/resolverClientLegacy.ts +26 -0
  23. package/src/types.ts +93 -39
  24. package/src/utils.ts +148 -0
  25. package/dist/StaticClassClient-D6v3vhZL.js +0 -695
  26. package/dist/StaticClassClient-D6v3vhZL.js.map +0 -1
  27. package/dist/StaticClassClient-GyNiWMHA.cjs +0 -736
  28. package/dist/StaticClassClient-GyNiWMHA.cjs.map +0 -1
  29. package/dist/components.cjs +0 -7
  30. package/dist/components.d.ts +0 -216
  31. package/dist/components.js +0 -2
  32. package/dist/generators-C0t5dIvZ.js +0 -723
  33. package/dist/generators-C0t5dIvZ.js.map +0 -1
  34. package/dist/generators-D8A8QE4S.cjs +0 -753
  35. package/dist/generators-D8A8QE4S.cjs.map +0 -1
  36. package/dist/generators.cjs +0 -7
  37. package/dist/generators.d.ts +0 -21
  38. package/dist/generators.js +0 -2
  39. package/dist/types-jdcuAELq.d.ts +0 -169
  40. package/src/components/index.ts +0 -5
  41. package/src/generators/index.ts +0 -5
package/dist/index.cjs CHANGED
@@ -1,81 +1,1909 @@
1
1
  Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
2
2
  const require_chunk = require("./chunk-ByKO4r7w.cjs");
3
- const require_StaticClassClient = require("./StaticClassClient-GyNiWMHA.cjs");
4
- const require_generators = require("./generators-D8A8QE4S.cjs");
5
3
  const require_templates_clients_axios_source = require("./templates/clients/axios.source.cjs");
6
4
  const require_templates_clients_fetch_source = require("./templates/clients/fetch.source.cjs");
7
5
  const require_templates_config_source = require("./templates/config.source.cjs");
8
6
  let node_path = require("node:path");
9
7
  node_path = require_chunk.__toESM(node_path);
8
+ let _kubb_ast = require("@kubb/ast");
9
+ let _kubb_plugin_ts = require("@kubb/plugin-ts");
10
+ let _kubb_react_fabric = require("@kubb/react-fabric");
11
+ let _kubb_react_fabric_jsx_runtime = require("@kubb/react-fabric/jsx-runtime");
10
12
  let _kubb_core = require("@kubb/core");
11
- let _kubb_plugin_oas = require("@kubb/plugin-oas");
12
13
  let _kubb_plugin_zod = require("@kubb/plugin-zod");
14
+ //#region ../../internals/utils/src/casing.ts
15
+ /**
16
+ * Shared implementation for camelCase and PascalCase conversion.
17
+ * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
18
+ * and capitalizes each word according to `pascal`.
19
+ *
20
+ * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
21
+ */
22
+ function toCamelOrPascal(text, pascal) {
23
+ 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) => {
24
+ if (word.length > 1 && word === word.toUpperCase()) return word;
25
+ if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
26
+ return word.charAt(0).toUpperCase() + word.slice(1);
27
+ }).join("").replace(/[^a-zA-Z0-9]/g, "");
28
+ }
29
+ /**
30
+ * Splits `text` on `.` and applies `transformPart` to each segment.
31
+ * The last segment receives `isLast = true`, all earlier segments receive `false`.
32
+ * Segments are joined with `/` to form a file path.
33
+ *
34
+ * Only splits on dots followed by a letter so that version numbers
35
+ * embedded in operationIds (e.g. `v2025.0`) are kept intact.
36
+ */
37
+ function applyToFileParts(text, transformPart) {
38
+ const parts = text.split(/\.(?=[a-zA-Z])/);
39
+ return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
40
+ }
41
+ /**
42
+ * Converts `text` to camelCase.
43
+ * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
44
+ *
45
+ * @example
46
+ * camelCase('hello-world') // 'helloWorld'
47
+ * camelCase('pet.petId', { isFile: true }) // 'pet/petId'
48
+ */
49
+ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
50
+ if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
51
+ prefix,
52
+ suffix
53
+ } : {}));
54
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
55
+ }
56
+ /**
57
+ * Converts `text` to PascalCase.
58
+ * When `isFile` is `true`, the last dot-separated segment is PascalCased and earlier segments are camelCased.
59
+ *
60
+ * @example
61
+ * pascalCase('hello-world') // 'HelloWorld'
62
+ * pascalCase('pet.petId', { isFile: true }) // 'pet/PetId'
63
+ */
64
+ function pascalCase(text, { isFile, prefix = "", suffix = "" } = {}) {
65
+ if (isFile) return applyToFileParts(text, (part, isLast) => isLast ? pascalCase(part, {
66
+ prefix,
67
+ suffix
68
+ }) : camelCase(part));
69
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, true);
70
+ }
71
+ //#endregion
72
+ //#region ../../internals/utils/src/jsdoc.ts
73
+ /**
74
+ * Builds a JSDoc comment block from an array of lines.
75
+ * Returns `fallback` when `comments` is empty so callers always get a usable string.
76
+ *
77
+ * @example
78
+ * ```ts
79
+ * buildJSDoc(['@type string', '@example hello'])
80
+ * // '/**\n * @type string\n * @example hello\n *\/\n '
81
+ * ```
82
+ */
83
+ function buildJSDoc(comments, options = {}) {
84
+ const { indent = " * ", suffix = "\n ", fallback = " " } = options;
85
+ if (comments.length === 0) return fallback;
86
+ return `/**\n${comments.map((c) => `${indent}${c}`).join("\n")}\n */${suffix}`;
87
+ }
88
+ //#endregion
89
+ //#region ../../internals/utils/src/reserved.ts
90
+ /**
91
+ * Returns `true` when `name` is a syntactically valid JavaScript variable name.
92
+ *
93
+ * @example
94
+ * ```ts
95
+ * isValidVarName('status') // true
96
+ * isValidVarName('class') // false (reserved word)
97
+ * isValidVarName('42foo') // false (starts with digit)
98
+ * ```
99
+ */
100
+ function isValidVarName(name) {
101
+ try {
102
+ new Function(`var ${name}`);
103
+ } catch {
104
+ return false;
105
+ }
106
+ return true;
107
+ }
108
+ //#endregion
109
+ //#region ../../internals/utils/src/urlPath.ts
110
+ /**
111
+ * Parses and transforms an OpenAPI/Swagger path string into various URL formats.
112
+ *
113
+ * @example
114
+ * const p = new URLPath('/pet/{petId}')
115
+ * p.URL // '/pet/:petId'
116
+ * p.template // '`/pet/${petId}`'
117
+ */
118
+ var URLPath = class {
119
+ /**
120
+ * The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
121
+ */
122
+ path;
123
+ #options;
124
+ constructor(path, options = {}) {
125
+ this.path = path;
126
+ this.#options = options;
127
+ }
128
+ /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
129
+ *
130
+ * @example
131
+ * ```ts
132
+ * new URLPath('/pet/{petId}').URL // '/pet/:petId'
133
+ * ```
134
+ */
135
+ get URL() {
136
+ return this.toURLPath();
137
+ }
138
+ /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
139
+ *
140
+ * @example
141
+ * ```ts
142
+ * new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
143
+ * new URLPath('/pet/{petId}').isURL // false
144
+ * ```
145
+ */
146
+ get isURL() {
147
+ try {
148
+ return !!new URL(this.path).href;
149
+ } catch {
150
+ return false;
151
+ }
152
+ }
153
+ /**
154
+ * Converts the OpenAPI path to a TypeScript template literal string.
155
+ *
156
+ * @example
157
+ * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
158
+ * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
159
+ */
160
+ get template() {
161
+ return this.toTemplateString();
162
+ }
163
+ /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
164
+ *
165
+ * @example
166
+ * ```ts
167
+ * new URLPath('/pet/{petId}').object
168
+ * // { url: '/pet/:petId', params: { petId: 'petId' } }
169
+ * ```
170
+ */
171
+ get object() {
172
+ return this.toObject();
173
+ }
174
+ /** Returns a map of path parameter names, or `undefined` when the path has no parameters.
175
+ *
176
+ * @example
177
+ * ```ts
178
+ * new URLPath('/pet/{petId}').params // { petId: 'petId' }
179
+ * new URLPath('/pet').params // undefined
180
+ * ```
181
+ */
182
+ get params() {
183
+ return this.getParams();
184
+ }
185
+ #transformParam(raw) {
186
+ const param = isValidVarName(raw) ? raw : camelCase(raw);
187
+ return this.#options.casing === "camelcase" ? camelCase(param) : param;
188
+ }
189
+ /**
190
+ * Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
191
+ */
192
+ #eachParam(fn) {
193
+ for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
194
+ const raw = match[1];
195
+ fn(raw, this.#transformParam(raw));
196
+ }
197
+ }
198
+ toObject({ type = "path", replacer, stringify } = {}) {
199
+ const object = {
200
+ url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
201
+ params: this.getParams()
202
+ };
203
+ if (stringify) {
204
+ if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
205
+ if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
206
+ return `{ url: '${object.url}' }`;
207
+ }
208
+ return object;
209
+ }
210
+ /**
211
+ * Converts the OpenAPI path to a TypeScript template literal string.
212
+ * An optional `replacer` can transform each extracted parameter name before interpolation.
213
+ *
214
+ * @example
215
+ * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
216
+ */
217
+ toTemplateString({ prefix = "", replacer } = {}) {
218
+ return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
219
+ if (i % 2 === 0) return part;
220
+ const param = this.#transformParam(part);
221
+ return `\${${replacer ? replacer(param) : param}}`;
222
+ }).join("")}\``;
223
+ }
224
+ /**
225
+ * Extracts all `{param}` segments from the path and returns them as a key-value map.
226
+ * An optional `replacer` transforms each parameter name in both key and value positions.
227
+ * Returns `undefined` when no path parameters are found.
228
+ *
229
+ * @example
230
+ * ```ts
231
+ * new URLPath('/pet/{petId}/tag/{tagId}').getParams()
232
+ * // { petId: 'petId', tagId: 'tagId' }
233
+ * ```
234
+ */
235
+ getParams(replacer) {
236
+ const params = {};
237
+ this.#eachParam((_raw, param) => {
238
+ const key = replacer ? replacer(param) : param;
239
+ params[key] = key;
240
+ });
241
+ return Object.keys(params).length > 0 ? params : void 0;
242
+ }
243
+ /** Converts the OpenAPI path to Express-style colon syntax.
244
+ *
245
+ * @example
246
+ * ```ts
247
+ * new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
248
+ * ```
249
+ */
250
+ toURLPath() {
251
+ return this.path.replace(/\{([^}]+)\}/g, ":$1");
252
+ }
253
+ };
254
+ //#endregion
255
+ //#region src/utils.ts
256
+ function getComments(node) {
257
+ return [
258
+ node.description && `@description ${node.description}`,
259
+ node.summary && `@summary ${node.summary}`,
260
+ node.path && `{@link ${new URLPath(node.path).URL}}`,
261
+ node.deprecated && "@deprecated"
262
+ ].filter((x) => Boolean(x)).flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((x) => Boolean(x));
263
+ }
264
+ function buildParamsMapping(originalParams, casedParams) {
265
+ const mapping = {};
266
+ let hasChanged = false;
267
+ originalParams.forEach((param, i) => {
268
+ const casedName = casedParams[i]?.name ?? param.name;
269
+ mapping[param.name] = casedName;
270
+ if (param.name !== casedName) hasChanged = true;
271
+ });
272
+ return hasChanged ? mapping : void 0;
273
+ }
274
+ function buildHeaders(contentType, hasHeaderParams) {
275
+ return [contentType !== "application/json" && contentType !== "multipart/form-data" ? `'Content-Type': '${contentType}'` : void 0, hasHeaderParams ? "...headers" : void 0].filter(Boolean);
276
+ }
277
+ function buildGenerics(node, tsResolver) {
278
+ const responseName = tsResolver.resolveResponseName(node);
279
+ const requestName = node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0;
280
+ const errorNames = node.responses.filter((r) => Number.parseInt(r.statusCode, 10) >= 400).map((r) => tsResolver.resolveResponseStatusName(node, r.statusCode));
281
+ return [
282
+ responseName,
283
+ `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`,
284
+ requestName || "unknown"
285
+ ].filter(Boolean);
286
+ }
287
+ function buildClassClientParams({ node, path, baseURL, tsResolver, isFormData, headers }) {
288
+ const queryParamsName = node.parameters.filter((p) => p.in === "query").length > 0 ? tsResolver.resolveQueryParamsName(node, node.parameters.filter((p) => p.in === "query")[0]) : void 0;
289
+ const requestName = node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0;
290
+ return _kubb_react_fabric.FunctionParams.factory({ config: {
291
+ mode: "object",
292
+ children: {
293
+ requestConfig: { mode: "inlineSpread" },
294
+ method: { value: JSON.stringify(node.method.toUpperCase()) },
295
+ url: { value: path.template },
296
+ baseURL: baseURL ? { value: JSON.stringify(baseURL) } : void 0,
297
+ params: queryParamsName ? {} : void 0,
298
+ data: requestName ? { value: isFormData ? "formData as FormData" : "requestData" } : void 0,
299
+ headers: headers.length ? { value: `{ ${headers.join(", ")}, ...requestConfig.headers }` } : void 0
300
+ }
301
+ } });
302
+ }
303
+ function buildRequestDataLine({ parser, node, zodResolver }) {
304
+ const zodRequestName = zodResolver && parser === "zod" && node.requestBody?.schema ? zodResolver.resolveDataName?.(node) : void 0;
305
+ if (parser === "zod" && zodRequestName) return `const requestData = ${zodRequestName}.parse(data)`;
306
+ if (node.requestBody?.schema) return "const requestData = data";
307
+ return "";
308
+ }
309
+ function buildFormDataLine(isFormData, hasRequest) {
310
+ return isFormData && hasRequest ? "const formData = buildFormData(requestData)" : "";
311
+ }
312
+ function buildReturnStatement({ dataReturnType, parser, node, zodResolver }) {
313
+ const zodResponseName = zodResolver && parser === "zod" ? zodResolver.resolveResponseName?.(node) : void 0;
314
+ if (dataReturnType === "full" && parser === "zod" && zodResponseName) return `return {...res, data: ${zodResponseName}.parse(res.data)}`;
315
+ if (dataReturnType === "data" && parser === "zod" && zodResponseName) return `return ${zodResponseName}.parse(res.data)`;
316
+ if (dataReturnType === "full" && parser === "client") return "return res";
317
+ return "return res.data";
318
+ }
319
+ //#endregion
320
+ //#region src/components/Url.tsx
321
+ const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
322
+ function getParams$2({ paramsType, paramsCasing, pathParamsType, node, tsResolver }) {
323
+ return (0, _kubb_ast.createOperationParams)({
324
+ ...node,
325
+ parameters: node.parameters.filter((p) => p.in === "path"),
326
+ requestBody: void 0
327
+ }, {
328
+ paramsType: paramsType === "object" ? "object" : "inline",
329
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
330
+ paramsCasing,
331
+ resolver: tsResolver
332
+ });
333
+ }
334
+ require_chunk.__name(getParams$2, "getParams");
335
+ function Url({ name, isExportable = true, isIndexable = true, baseURL, paramsType, paramsCasing, pathParamsType, node, tsResolver }) {
336
+ const path = new URLPath(node.path);
337
+ const paramsNode = getParams$2({
338
+ paramsType,
339
+ paramsCasing,
340
+ pathParamsType,
341
+ node,
342
+ tsResolver
343
+ });
344
+ const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
345
+ const originalPathParams = node.parameters.filter((p) => p.in === "path");
346
+ const casedPathParams = (0, _kubb_ast.caseParams)(originalPathParams, paramsCasing);
347
+ const pathParamsMapping = paramsCasing ? buildParamsMapping(originalPathParams, casedPathParams) : void 0;
348
+ return /* @__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
+ export: isExportable,
355
+ params: paramsSignature,
356
+ children: [
357
+ pathParamsMapping && Object.entries(pathParamsMapping).filter(([originalName, camelCaseName]) => isValidVarName(originalName) && originalName !== camelCaseName).map(([originalName, camelCaseName]) => `const ${originalName} = ${camelCaseName}`).join("\n"),
358
+ pathParamsMapping && Object.keys(pathParamsMapping).length > 0 && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
359
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Const, {
360
+ name: "res",
361
+ children: `{ method: '${node.method.toUpperCase()}', url: ${path.toTemplateString({ prefix: baseURL })} as const }`
362
+ }),
363
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
364
+ "return res"
365
+ ]
366
+ })
367
+ });
368
+ }
369
+ Url.getParams = getParams$2;
370
+ //#endregion
371
+ //#region src/components/Client.tsx
372
+ const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
373
+ function getParams$1({ paramsType, paramsCasing, pathParamsType, node, tsResolver, isConfigurable }) {
374
+ const requestName = node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0;
375
+ return (0, _kubb_ast.createOperationParams)(node, {
376
+ paramsType,
377
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
378
+ paramsCasing,
379
+ resolver: tsResolver,
380
+ extraParams: isConfigurable ? [(0, _kubb_ast.createFunctionParameter)({
381
+ name: "config",
382
+ type: (0, _kubb_ast.createTypeNode)({
383
+ variant: "reference",
384
+ name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
385
+ }),
386
+ default: "{}"
387
+ })] : []
388
+ });
389
+ }
390
+ require_chunk.__name(getParams$1, "getParams");
391
+ function Client({ name, isExportable = true, isIndexable = true, returnType, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType, node, tsResolver, zodResolver, urlName, children, isConfigurable = true }) {
392
+ const path = new URLPath(node.path);
393
+ const contentType = node.requestBody?.contentType ?? "application/json";
394
+ const isFormData = contentType === "multipart/form-data";
395
+ const originalPathParams = node.parameters.filter((p) => p.in === "path");
396
+ const casedPathParams = (0, _kubb_ast.caseParams)(originalPathParams, paramsCasing);
397
+ const originalQueryParams = node.parameters.filter((p) => p.in === "query");
398
+ const casedQueryParams = (0, _kubb_ast.caseParams)(originalQueryParams, paramsCasing);
399
+ const originalHeaderParams = node.parameters.filter((p) => p.in === "header");
400
+ const casedHeaderParams = (0, _kubb_ast.caseParams)(originalHeaderParams, paramsCasing);
401
+ const pathParamsMapping = paramsCasing && !urlName ? buildParamsMapping(originalPathParams, casedPathParams) : void 0;
402
+ const queryParamsMapping = paramsCasing ? buildParamsMapping(originalQueryParams, casedQueryParams) : void 0;
403
+ const headerParamsMapping = paramsCasing ? buildParamsMapping(originalHeaderParams, casedHeaderParams) : void 0;
404
+ const requestName = node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0;
405
+ const responseName = tsResolver.resolveResponseName(node);
406
+ const queryParamsName = originalQueryParams.length > 0 ? tsResolver.resolveQueryParamsName(node, originalQueryParams[0]) : void 0;
407
+ const headerParamsName = originalHeaderParams.length > 0 ? tsResolver.resolveHeaderParamsName(node, originalHeaderParams[0]) : void 0;
408
+ const zodResponseName = zodResolver && parser === "zod" ? zodResolver.resolveResponseName?.(node) : void 0;
409
+ const zodRequestName = zodResolver && parser === "zod" && node.requestBody?.schema ? zodResolver.resolveDataName?.(node) : void 0;
410
+ const errorNames = node.responses.filter((r) => {
411
+ return Number.parseInt(r.statusCode, 10) >= 400;
412
+ }).map((r) => tsResolver.resolveResponseStatusName(node, r.statusCode));
413
+ const headers = [contentType !== "application/json" && contentType !== "multipart/form-data" ? `'Content-Type': '${contentType}'` : void 0, headerParamsName ? headerParamsMapping ? "...mappedHeaders" : "...headers" : void 0].filter(Boolean);
414
+ const generics = [
415
+ responseName,
416
+ `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`,
417
+ requestName || "unknown"
418
+ ].filter(Boolean);
419
+ const paramsNode = getParams$1({
420
+ paramsType,
421
+ paramsCasing,
422
+ pathParamsType,
423
+ node,
424
+ tsResolver,
425
+ isConfigurable
426
+ });
427
+ const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
428
+ const urlParamsNode = Url.getParams({
429
+ paramsType,
430
+ paramsCasing,
431
+ pathParamsType,
432
+ node,
433
+ tsResolver
434
+ });
435
+ const urlParamsCall = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" }).print(urlParamsNode) ?? "";
436
+ const clientParams = _kubb_react_fabric.FunctionParams.factory({ config: {
437
+ mode: "object",
438
+ children: {
439
+ method: { value: JSON.stringify(node.method.toUpperCase()) },
440
+ url: { value: urlName ? `${urlName}(${urlParamsCall}).url.toString()` : path.template },
441
+ baseURL: baseURL && !urlName ? { value: `\`${baseURL}\`` } : void 0,
442
+ params: queryParamsName ? queryParamsMapping ? { value: "mappedParams" } : {} : void 0,
443
+ data: requestName ? { value: isFormData ? "formData as FormData" : "requestData" } : void 0,
444
+ requestConfig: isConfigurable ? { mode: "inlineSpread" } : void 0,
445
+ headers: headers.length ? { value: isConfigurable ? `{ ${headers.join(", ")}, ...requestConfig.headers }` : `{ ${headers.join(", ")} }` } : void 0
446
+ }
447
+ } });
448
+ const childrenElement = children ? children : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
449
+ dataReturnType === "full" && parser === "zod" && zodResponseName && `return {...res, data: ${zodResponseName}.parse(res.data)}`,
450
+ dataReturnType === "data" && parser === "zod" && zodResponseName && `return ${zodResponseName}.parse(res.data)`,
451
+ dataReturnType === "full" && parser === "client" && "return res",
452
+ dataReturnType === "data" && parser === "client" && "return res.data"
453
+ ] });
454
+ 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, {
455
+ name,
456
+ isExportable,
457
+ isIndexable,
458
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.Function, {
459
+ name,
460
+ async: true,
461
+ export: isExportable,
462
+ params: paramsSignature,
463
+ JSDoc: { comments: getComments(node) },
464
+ returnType,
465
+ children: [
466
+ isConfigurable ? "const { client: request = fetch, ...requestConfig } = config" : "",
467
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
468
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
469
+ pathParamsMapping && Object.entries(pathParamsMapping).filter(([originalName, camelCaseName]) => isValidVarName(originalName) && originalName !== camelCaseName).map(([originalName, camelCaseName]) => `const ${originalName} = ${camelCaseName}`).join("\n"),
470
+ 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", {})] }),
471
+ queryParamsMapping && queryParamsName && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
472
+ `const mappedParams = params ? { ${Object.entries(queryParamsMapping).map(([originalName, camelCaseName]) => `"${originalName}": params.${camelCaseName}`).join(", ")} } : undefined`,
473
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
474
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {})
475
+ ] }),
476
+ headerParamsMapping && headerParamsName && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
477
+ `const mappedHeaders = headers ? { ${Object.entries(headerParamsMapping).map(([originalName, camelCaseName]) => `"${originalName}": headers.${camelCaseName}`).join(", ")} } : undefined`,
478
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
479
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {})
480
+ ] }),
481
+ parser === "zod" && zodRequestName ? `const requestData = ${zodRequestName}.parse(data)` : requestName && "const requestData = data",
482
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
483
+ isFormData && requestName && "const formData = buildFormData(requestData)",
484
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
485
+ isConfigurable ? `const res = await request<${generics.join(", ")}>(${clientParams.toCall()})` : `const res = await fetch<${generics.join(", ")}>(${clientParams.toCall()})`,
486
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
487
+ childrenElement
488
+ ]
489
+ })
490
+ })] });
491
+ }
492
+ Client.getParams = getParams$1;
493
+ //#endregion
494
+ //#region src/components/ClientLegacy.tsx
495
+ function isSchemaRequired(schema) {
496
+ if (!schema) return false;
497
+ return Array.isArray(schema.required) ? !!schema.required.length : !!schema.required;
498
+ }
499
+ function isSchemaOptional(schema) {
500
+ return !isSchemaRequired(schema);
501
+ }
502
+ function isAllOptionalDeep(schema) {
503
+ if (!schema) return true;
504
+ if (Array.isArray(schema.required) && schema.required.length > 0) return false;
505
+ if (schema.allOf) return schema.allOf.every(isAllOptionalDeep);
506
+ return true;
507
+ }
508
+ function getSchemaDefaultValue(schema) {
509
+ if (!schema || !isSchemaOptional(schema)) return void 0;
510
+ if (schema.type === "array") return "[]";
511
+ if (schema.anyOf || schema.oneOf) {
512
+ const variants = schema.anyOf || schema.oneOf;
513
+ if (!Array.isArray(variants)) return void 0;
514
+ if (variants.some(isAllOptionalDeep)) return "{}";
515
+ return;
516
+ }
517
+ if (schema.type === "object" || schema.properties) return "{}";
518
+ }
519
+ function legacyGetPathParams(operationSchema, options = {}) {
520
+ if (!operationSchema?.schema?.properties || !operationSchema.name) return {};
521
+ const requiredFields = Array.isArray(operationSchema.schema.required) ? operationSchema.schema.required : [];
522
+ return Object.entries(operationSchema.schema.properties).reduce((acc, [name]) => {
523
+ if (!name) return acc;
524
+ let paramName = name;
525
+ if (options.casing === "camelcase") paramName = camelCase(name);
526
+ else if (!isValidVarName(name)) paramName = camelCase(name);
527
+ const accessName = options.casing === "camelcase" ? camelCase(name) : name;
528
+ acc[paramName] = {
529
+ default: void 0,
530
+ type: options.typed ? `${operationSchema.name}["${accessName}"]` : void 0,
531
+ optional: !requiredFields.includes(name)
532
+ };
533
+ return acc;
534
+ }, {});
535
+ }
536
+ function legacyGetParamsMapping(operationSchema, options = {}) {
537
+ if (!operationSchema?.schema?.properties) return void 0;
538
+ const allEntries = [];
539
+ let hasTransformation = false;
540
+ Object.entries(operationSchema.schema.properties).forEach(([originalName]) => {
541
+ let transformedName = originalName;
542
+ if (options.casing === "camelcase") transformedName = camelCase(originalName);
543
+ else if (!isValidVarName(originalName)) transformedName = camelCase(originalName);
544
+ allEntries.push([originalName, transformedName]);
545
+ if (transformedName !== originalName) hasTransformation = true;
546
+ });
547
+ if (options.casing === "camelcase" && hasTransformation) return Object.fromEntries(allEntries);
548
+ const mapping = {};
549
+ allEntries.forEach(([originalName, transformedName]) => {
550
+ if (transformedName !== originalName) mapping[originalName] = transformedName;
551
+ });
552
+ return Object.keys(mapping).length > 0 ? mapping : void 0;
553
+ }
554
+ function legacyGetComments(operation) {
555
+ return [
556
+ operation.getDescription?.() && `@description ${operation.getDescription()}`,
557
+ operation.getSummary?.() && `@summary ${operation.getSummary()}`,
558
+ operation.path && `{@link ${new URLPath(operation.path).URL}}`,
559
+ operation.isDeprecated?.() && "@deprecated"
560
+ ].filter((x) => Boolean(x)).flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((x) => Boolean(x));
561
+ }
562
+ function getParams({ paramsType, paramsCasing, pathParamsType, typeSchemas, isConfigurable }) {
563
+ if (paramsType === "object") {
564
+ const children = {
565
+ ...legacyGetPathParams(typeSchemas.pathParams, {
566
+ typed: true,
567
+ casing: paramsCasing
568
+ }),
569
+ data: typeSchemas.request?.name ? {
570
+ type: typeSchemas.request?.name,
571
+ optional: isSchemaOptional(typeSchemas.request?.schema)
572
+ } : void 0,
573
+ params: typeSchemas.queryParams?.name ? {
574
+ type: typeSchemas.queryParams?.name,
575
+ optional: isSchemaOptional(typeSchemas.queryParams?.schema)
576
+ } : void 0,
577
+ headers: typeSchemas.headerParams?.name ? {
578
+ type: typeSchemas.headerParams?.name,
579
+ optional: isSchemaOptional(typeSchemas.headerParams?.schema)
580
+ } : void 0
581
+ };
582
+ const allChildrenAreOptional = Object.values(children).every((child) => !child || child.optional);
583
+ return _kubb_react_fabric.FunctionParams.factory({
584
+ data: {
585
+ mode: "object",
586
+ children,
587
+ default: allChildrenAreOptional ? "{}" : void 0
588
+ },
589
+ config: isConfigurable ? {
590
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
591
+ default: "{}"
592
+ } : void 0
593
+ });
594
+ }
595
+ return _kubb_react_fabric.FunctionParams.factory({
596
+ pathParams: typeSchemas.pathParams?.name ? {
597
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
598
+ children: legacyGetPathParams(typeSchemas.pathParams, {
599
+ typed: true,
600
+ casing: paramsCasing
601
+ }),
602
+ default: getSchemaDefaultValue(typeSchemas.pathParams?.schema)
603
+ } : void 0,
604
+ data: typeSchemas.request?.name ? {
605
+ type: typeSchemas.request?.name,
606
+ optional: isSchemaOptional(typeSchemas.request?.schema)
607
+ } : void 0,
608
+ params: typeSchemas.queryParams?.name ? {
609
+ type: typeSchemas.queryParams?.name,
610
+ optional: isSchemaOptional(typeSchemas.queryParams?.schema)
611
+ } : void 0,
612
+ headers: typeSchemas.headerParams?.name ? {
613
+ type: typeSchemas.headerParams?.name,
614
+ optional: isSchemaOptional(typeSchemas.headerParams?.schema)
615
+ } : void 0,
616
+ config: isConfigurable ? {
617
+ type: typeSchemas.request?.name ? `Partial<RequestConfig<${typeSchemas.request?.name}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }",
618
+ default: "{}"
619
+ } : void 0
620
+ });
621
+ }
622
+ function ClientLegacy({ name, isExportable = true, isIndexable = true, returnType, typeSchemas, baseURL, dataReturnType, parser, zodSchemas, paramsType, paramsCasing, pathParamsType, operation, urlName, children, isConfigurable = true }) {
623
+ const path = new URLPath(operation.path);
624
+ const contentType = operation.getContentType?.() ?? "application/json";
625
+ const isFormData = contentType === "multipart/form-data";
626
+ const pathParamsMapping = paramsCasing && !urlName ? legacyGetParamsMapping(typeSchemas.pathParams, { casing: paramsCasing }) : void 0;
627
+ const queryParamsMapping = paramsCasing ? legacyGetParamsMapping(typeSchemas.queryParams, { casing: paramsCasing }) : void 0;
628
+ const headerParamsMapping = paramsCasing ? legacyGetParamsMapping(typeSchemas.headerParams, { casing: paramsCasing }) : void 0;
629
+ const headers = [contentType !== "application/json" && contentType !== "multipart/form-data" ? `'Content-Type': '${contentType}'` : void 0, typeSchemas.headerParams?.name ? headerParamsMapping ? "...mappedHeaders" : "...headers" : void 0].filter(Boolean);
630
+ const TError = `ResponseErrorConfig<${typeSchemas.errors?.map((item) => item.name).join(" | ") || "Error"}>`;
631
+ const generics = [
632
+ typeSchemas.response.name,
633
+ TError,
634
+ typeSchemas.request?.name || "unknown"
635
+ ].filter(Boolean);
636
+ const params = getParams({
637
+ paramsType,
638
+ paramsCasing,
639
+ pathParamsType,
640
+ typeSchemas,
641
+ isConfigurable
642
+ });
643
+ const urlParams = UrlLegacy.getParams({
644
+ paramsType,
645
+ paramsCasing,
646
+ pathParamsType,
647
+ typeSchemas
648
+ });
649
+ const clientParams = _kubb_react_fabric.FunctionParams.factory({ config: {
650
+ mode: "object",
651
+ children: {
652
+ method: { value: JSON.stringify(operation.method.toUpperCase()) },
653
+ url: { value: urlName ? `${urlName}(${urlParams.toCall()}).url.toString()` : path.template },
654
+ baseURL: baseURL && !urlName ? { value: `\`${baseURL}\`` } : void 0,
655
+ params: typeSchemas.queryParams?.name ? queryParamsMapping ? { value: "mappedParams" } : {} : void 0,
656
+ data: typeSchemas.request?.name ? { value: isFormData ? "formData as FormData" : "requestData" } : void 0,
657
+ requestConfig: isConfigurable ? { mode: "inlineSpread" } : void 0,
658
+ headers: headers.length ? { value: isConfigurable ? `{ ${headers.join(", ")}, ...requestConfig.headers }` : `{ ${headers.join(", ")} }` } : void 0
659
+ }
660
+ } });
661
+ const childrenElement = children ? children : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
662
+ dataReturnType === "full" && parser === "zod" && zodSchemas && `return {...res, data: ${zodSchemas.response.name}.parse(res.data)}`,
663
+ dataReturnType === "data" && parser === "zod" && zodSchemas && `return ${zodSchemas.response.name}.parse(res.data)`,
664
+ dataReturnType === "full" && parser === "client" && "return res",
665
+ dataReturnType === "data" && parser === "client" && "return res.data"
666
+ ] });
667
+ 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, {
668
+ name,
669
+ isExportable,
670
+ isIndexable,
671
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.Function, {
672
+ name,
673
+ async: true,
674
+ export: isExportable,
675
+ params: params.toConstructor(),
676
+ JSDoc: { comments: legacyGetComments(operation) },
677
+ returnType,
678
+ children: [
679
+ isConfigurable ? "const { client: request = fetch, ...requestConfig } = config" : "",
680
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
681
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
682
+ pathParamsMapping && Object.entries(pathParamsMapping).filter(([originalName, camelCaseName]) => originalName !== camelCaseName && isValidVarName(originalName)).map(([originalName, camelCaseName]) => `const ${originalName} = ${camelCaseName}`).join("\n"),
683
+ 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", {})] }),
684
+ queryParamsMapping && typeSchemas.queryParams?.name && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
685
+ `const mappedParams = params ? { ${Object.entries(queryParamsMapping).map(([originalName, camelCaseName]) => `"${originalName}": params.${camelCaseName}`).join(", ")} } : undefined`,
686
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
687
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {})
688
+ ] }),
689
+ headerParamsMapping && typeSchemas.headerParams?.name && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
690
+ `const mappedHeaders = headers ? { ${Object.entries(headerParamsMapping).map(([originalName, camelCaseName]) => `"${originalName}": headers.${camelCaseName}`).join(", ")} } : undefined`,
691
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
692
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {})
693
+ ] }),
694
+ parser === "zod" && zodSchemas?.request?.name ? `const requestData = ${zodSchemas.request.name}.parse(data)` : typeSchemas?.request?.name && "const requestData = data",
695
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
696
+ isFormData && typeSchemas?.request?.name && "const formData = buildFormData(requestData)",
697
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
698
+ isConfigurable ? `const res = await request<${generics.join(", ")}>(${clientParams.toCall()})` : `const res = await fetch<${generics.join(", ")}>(${clientParams.toCall()})`,
699
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
700
+ childrenElement
701
+ ]
702
+ })
703
+ })] });
704
+ }
705
+ ClientLegacy.getParams = getParams;
706
+ function getUrlParams({ paramsType, paramsCasing, pathParamsType, typeSchemas }) {
707
+ if (paramsType === "object") {
708
+ const pathParams = legacyGetPathParams(typeSchemas.pathParams, {
709
+ typed: true,
710
+ casing: paramsCasing
711
+ });
712
+ return _kubb_react_fabric.FunctionParams.factory({ data: {
713
+ mode: "object",
714
+ children: { ...pathParams }
715
+ } });
716
+ }
717
+ return _kubb_react_fabric.FunctionParams.factory({ pathParams: typeSchemas.pathParams?.name ? {
718
+ mode: pathParamsType === "object" ? "object" : "inlineSpread",
719
+ children: legacyGetPathParams(typeSchemas.pathParams, {
720
+ typed: true,
721
+ casing: paramsCasing
722
+ }),
723
+ default: getSchemaDefaultValue(typeSchemas.pathParams?.schema)
724
+ } : void 0 });
725
+ }
726
+ function UrlLegacy({ name, isExportable = true, isIndexable = true, typeSchemas, baseURL, paramsType, paramsCasing, pathParamsType, operation }) {
727
+ const path = new URLPath(operation.path);
728
+ const params = getUrlParams({
729
+ paramsType,
730
+ paramsCasing,
731
+ pathParamsType,
732
+ typeSchemas
733
+ });
734
+ const pathParamsMapping = paramsCasing ? legacyGetParamsMapping(typeSchemas.pathParams, { casing: paramsCasing }) : void 0;
735
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
736
+ name,
737
+ isExportable,
738
+ isIndexable,
739
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.Function, {
740
+ name,
741
+ export: isExportable,
742
+ params: params.toConstructor(),
743
+ children: [
744
+ pathParamsMapping && Object.entries(pathParamsMapping).filter(([originalName, camelCaseName]) => originalName !== camelCaseName && isValidVarName(originalName)).map(([originalName, camelCaseName]) => `const ${originalName} = ${camelCaseName}`).join("\n"),
745
+ pathParamsMapping && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
746
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Const, {
747
+ name: "res",
748
+ children: `{ method: '${operation.method.toUpperCase()}', url: ${path.toTemplateString({ prefix: baseURL })} as const }`
749
+ }),
750
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)("br", {}),
751
+ "return res"
752
+ ]
753
+ })
754
+ });
755
+ }
756
+ UrlLegacy.getParams = getUrlParams;
757
+ //#endregion
758
+ //#region src/components/ClassClient.tsx
759
+ const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
760
+ function generateMethod$1({ node, name, tsResolver, zodResolver, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType }) {
761
+ const path = new URLPath(node.path, { casing: paramsCasing });
762
+ const contentType = node.requestBody?.contentType ?? "application/json";
763
+ const isFormData = contentType === "multipart/form-data";
764
+ const headers = buildHeaders(contentType, !!(node.parameters.filter((p) => p.in === "header").length > 0 ? tsResolver.resolveHeaderParamsName(node, node.parameters.filter((p) => p.in === "header")[0]) : void 0));
765
+ const generics = buildGenerics(node, tsResolver);
766
+ const paramsNode = ClassClient.getParams({
767
+ paramsType,
768
+ paramsCasing,
769
+ pathParamsType,
770
+ node,
771
+ tsResolver,
772
+ isConfigurable: true
773
+ });
774
+ const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
775
+ const clientParams = buildClassClientParams({
776
+ node,
777
+ path,
778
+ baseURL,
779
+ tsResolver,
780
+ isFormData,
781
+ headers
782
+ });
783
+ const jsdoc = buildJSDoc(getComments(node));
784
+ const requestDataLine = buildRequestDataLine({
785
+ parser,
786
+ node,
787
+ zodResolver
788
+ });
789
+ const formDataLine = buildFormDataLine(isFormData, !!node.requestBody?.schema);
790
+ const returnStatement = buildReturnStatement({
791
+ dataReturnType,
792
+ parser,
793
+ node,
794
+ zodResolver
795
+ });
796
+ return `${jsdoc}async ${name}(${paramsSignature}) {\n${[
797
+ "const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)",
798
+ "",
799
+ requestDataLine,
800
+ formDataLine,
801
+ `const res = await request<${generics.join(", ")}>(${clientParams.toCall()})`,
802
+ returnStatement
803
+ ].filter(Boolean).map((line) => ` ${line}`).join("\n")}\n }`;
804
+ }
805
+ require_chunk.__name(generateMethod$1, "generateMethod");
806
+ function ClassClient({ name, isExportable = true, isIndexable = true, operations, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType, children }) {
807
+ const classCode = `export class ${name} {
808
+ #config: Partial<RequestConfig> & { client?: Client }
809
+
810
+ constructor(config: Partial<RequestConfig> & { client?: Client } = {}) {
811
+ this.#config = config
812
+ }
813
+
814
+ ${operations.map(({ node, name: methodName, tsResolver, zodResolver }) => generateMethod$1({
815
+ node,
816
+ name: methodName,
817
+ tsResolver,
818
+ zodResolver,
819
+ baseURL,
820
+ dataReturnType,
821
+ parser,
822
+ paramsType,
823
+ paramsCasing,
824
+ pathParamsType
825
+ })).join("\n\n")}
826
+ }`;
827
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File.Source, {
828
+ name,
829
+ isExportable,
830
+ isIndexable,
831
+ children: [classCode, children]
832
+ });
833
+ }
834
+ ClassClient.getParams = Client.getParams;
835
+ //#endregion
836
+ //#region src/components/WrapperClient.tsx
837
+ function WrapperClient({ name, classNames, isExportable = true, isIndexable = true }) {
838
+ const classCode = `export class ${name} {
839
+ ${classNames.map((className) => ` readonly ${camelCase(className)}: ${className}`).join("\n")}
840
+
841
+ constructor(config: Partial<RequestConfig> & { client?: Client } = {}) {
842
+ ${classNames.map((className) => ` this.${camelCase(className)} = new ${className}(config)`).join("\n")}
843
+ }
844
+ }`;
845
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
846
+ name,
847
+ isExportable,
848
+ isIndexable,
849
+ children: classCode
850
+ });
851
+ }
852
+ //#endregion
853
+ //#region src/generators/classClientGenerator.tsx
854
+ function resolveTypeImportNames$1(node, tsResolver) {
855
+ return [
856
+ node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0,
857
+ tsResolver.resolveResponseName(node),
858
+ ...node.parameters.filter((p) => p.in === "path").map((p) => tsResolver.resolvePathParamsName(node, p)),
859
+ ...node.parameters.filter((p) => p.in === "query").map((p) => tsResolver.resolveQueryParamsName(node, p)),
860
+ ...node.parameters.filter((p) => p.in === "header").map((p) => tsResolver.resolveHeaderParamsName(node, p)),
861
+ ...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode))
862
+ ].filter((n) => Boolean(n));
863
+ }
864
+ require_chunk.__name(resolveTypeImportNames$1, "resolveTypeImportNames");
865
+ function resolveZodImportNames$1(node, zodResolver) {
866
+ return [zodResolver.resolveResponseName?.(node), node.requestBody?.schema ? zodResolver.resolveDataName?.(node) : void 0].filter((n) => Boolean(n));
867
+ }
868
+ require_chunk.__name(resolveZodImportNames$1, "resolveZodImportNames");
869
+ const classClientGenerator = (0, _kubb_core.defineGenerator)({
870
+ name: "classClient",
871
+ type: "react",
872
+ Operations({ nodes, options, config, driver, resolver, adapter, plugin }) {
873
+ const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath, wrapper } = options;
874
+ const baseURL = options.baseURL ?? adapter.rootNode?.meta?.baseURL;
875
+ const root = node_path.default.resolve(config.root, config.output.path);
876
+ const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
877
+ if (!pluginTs?.resolver) return null;
878
+ const tsResolver = pluginTs.resolver;
879
+ const tsPluginOptions = pluginTs.options;
880
+ const pluginZod = parser === "zod" ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : void 0;
881
+ const zodResolver = pluginZod?.resolver;
882
+ function buildOperationData(node) {
883
+ const transformedNode = plugin.transformer ? (0, _kubb_ast.transform)(node, plugin.transformer) : node;
884
+ const typeFile = tsResolver.resolveFile({
885
+ name: transformedNode.operationId,
886
+ extname: ".ts",
887
+ tag: transformedNode.tags[0] ?? "default",
888
+ path: transformedNode.path
889
+ }, {
890
+ root,
891
+ output: tsPluginOptions?.output ?? output,
892
+ group: tsPluginOptions?.group
893
+ });
894
+ const zodFile = zodResolver && pluginZod?.options ? zodResolver.resolveFile({
895
+ name: transformedNode.operationId,
896
+ extname: ".ts",
897
+ tag: transformedNode.tags[0] ?? "default",
898
+ path: transformedNode.path
899
+ }, {
900
+ root,
901
+ output: pluginZod.options.output ?? output,
902
+ group: pluginZod.options.group
903
+ }) : void 0;
904
+ return {
905
+ node: transformedNode,
906
+ name: resolver.resolveName(transformedNode.operationId),
907
+ tsResolver,
908
+ zodResolver,
909
+ typeFile,
910
+ zodFile
911
+ };
912
+ }
913
+ const controllers = nodes.reduce((acc, operationNode) => {
914
+ const tag = operationNode.tags[0];
915
+ const groupName = tag ? group?.name?.({ group: camelCase(tag) }) ?? pascalCase(tag) : "Client";
916
+ if (!tag && !group) {
917
+ const name = "ApiClient";
918
+ const file = resolver.resolveFile({
919
+ name,
920
+ extname: ".ts"
921
+ }, {
922
+ root,
923
+ output,
924
+ group
925
+ });
926
+ const operationData = buildOperationData(operationNode);
927
+ const previous = acc.find((item) => item.file.path === file.path);
928
+ if (previous) previous.operations.push(operationData);
929
+ else acc.push({
930
+ name,
931
+ file,
932
+ operations: [operationData]
933
+ });
934
+ } else if (tag) {
935
+ const name = groupName;
936
+ const file = resolver.resolveFile({
937
+ name,
938
+ extname: ".ts",
939
+ tag
940
+ }, {
941
+ root,
942
+ output,
943
+ group
944
+ });
945
+ const operationData = buildOperationData(operationNode);
946
+ const previous = acc.find((item) => item.file.path === file.path);
947
+ if (previous) previous.operations.push(operationData);
948
+ else acc.push({
949
+ name,
950
+ file,
951
+ operations: [operationData]
952
+ });
953
+ }
954
+ return acc;
955
+ }, []);
956
+ function collectTypeImports(ops) {
957
+ const typeImportsByFile = /* @__PURE__ */ new Map();
958
+ const typeFilesByPath = /* @__PURE__ */ new Map();
959
+ ops.forEach((op) => {
960
+ const names = resolveTypeImportNames$1(op.node, tsResolver);
961
+ if (!typeImportsByFile.has(op.typeFile.path)) typeImportsByFile.set(op.typeFile.path, /* @__PURE__ */ new Set());
962
+ const imports = typeImportsByFile.get(op.typeFile.path);
963
+ names.forEach((n) => {
964
+ imports.add(n);
965
+ });
966
+ typeFilesByPath.set(op.typeFile.path, op.typeFile);
967
+ });
968
+ return {
969
+ typeImportsByFile,
970
+ typeFilesByPath
971
+ };
972
+ }
973
+ function collectZodImports(ops) {
974
+ const zodImportsByFile = /* @__PURE__ */ new Map();
975
+ const zodFilesByPath = /* @__PURE__ */ new Map();
976
+ ops.forEach((op) => {
977
+ if (!op.zodFile || !zodResolver) return;
978
+ const names = resolveZodImportNames$1(op.node, zodResolver);
979
+ if (!zodImportsByFile.has(op.zodFile.path)) zodImportsByFile.set(op.zodFile.path, /* @__PURE__ */ new Set());
980
+ const imports = zodImportsByFile.get(op.zodFile.path);
981
+ names.forEach((n) => {
982
+ imports.add(n);
983
+ });
984
+ zodFilesByPath.set(op.zodFile.path, op.zodFile);
985
+ });
986
+ return {
987
+ zodImportsByFile,
988
+ zodFilesByPath
989
+ };
990
+ }
991
+ const files = controllers.map(({ name, file, operations: ops }) => {
992
+ const { typeImportsByFile, typeFilesByPath } = collectTypeImports(ops);
993
+ const { zodImportsByFile, zodFilesByPath } = parser === "zod" ? collectZodImports(ops) : {
994
+ zodImportsByFile: /* @__PURE__ */ new Map(),
995
+ zodFilesByPath: /* @__PURE__ */ new Map()
996
+ };
997
+ const hasFormData = ops.some((op) => op.node.requestBody?.contentType === "multipart/form-data");
998
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
999
+ baseName: file.baseName,
1000
+ path: file.path,
1001
+ meta: file.meta,
1002
+ banner: resolver.resolveBanner(adapter.rootNode, {
1003
+ output,
1004
+ config
1005
+ }),
1006
+ footer: resolver.resolveFooter(adapter.rootNode, {
1007
+ output,
1008
+ config
1009
+ }),
1010
+ children: [
1011
+ importPath ? /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
1012
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1013
+ name: "fetch",
1014
+ path: importPath
1015
+ }),
1016
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1017
+ name: ["mergeConfig"],
1018
+ path: importPath
1019
+ }),
1020
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1021
+ name: [
1022
+ "Client",
1023
+ "RequestConfig",
1024
+ "ResponseErrorConfig"
1025
+ ],
1026
+ path: importPath,
1027
+ isTypeOnly: true
1028
+ })
1029
+ ] }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
1030
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1031
+ name: ["fetch"],
1032
+ root: file.path,
1033
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts")
1034
+ }),
1035
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1036
+ name: ["mergeConfig"],
1037
+ root: file.path,
1038
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts")
1039
+ }),
1040
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1041
+ name: [
1042
+ "Client",
1043
+ "RequestConfig",
1044
+ "ResponseErrorConfig"
1045
+ ],
1046
+ root: file.path,
1047
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
1048
+ isTypeOnly: true
1049
+ })
1050
+ ] }),
1051
+ hasFormData && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1052
+ name: ["buildFormData"],
1053
+ root: file.path,
1054
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/config.ts")
1055
+ }),
1056
+ Array.from(typeImportsByFile.entries()).map(([filePath, importSet]) => {
1057
+ const typeFile = typeFilesByPath.get(filePath);
1058
+ if (!typeFile) return null;
1059
+ const importNames = Array.from(importSet).filter(Boolean);
1060
+ if (importNames.length === 0) return null;
1061
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1062
+ name: importNames,
1063
+ root: file.path,
1064
+ path: typeFile.path,
1065
+ isTypeOnly: true
1066
+ }, filePath);
1067
+ }),
1068
+ parser === "zod" && Array.from(zodImportsByFile.entries()).map(([filePath, importSet]) => {
1069
+ const zodFile = zodFilesByPath.get(filePath);
1070
+ if (!zodFile) return null;
1071
+ const importNames = Array.from(importSet).filter(Boolean);
1072
+ if (importNames.length === 0) return null;
1073
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1074
+ name: importNames,
1075
+ root: file.path,
1076
+ path: zodFile.path
1077
+ }, filePath);
1078
+ }),
1079
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(ClassClient, {
1080
+ name,
1081
+ operations: ops,
1082
+ baseURL,
1083
+ dataReturnType,
1084
+ pathParamsType,
1085
+ paramsCasing,
1086
+ paramsType,
1087
+ parser
1088
+ })
1089
+ ]
1090
+ }, file.path);
1091
+ });
1092
+ if (wrapper) {
1093
+ const wrapperFile = resolver.resolveFile({
1094
+ name: wrapper.className,
1095
+ extname: ".ts"
1096
+ }, {
1097
+ root,
1098
+ output,
1099
+ group
1100
+ });
1101
+ files.push(/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
1102
+ baseName: wrapperFile.baseName,
1103
+ path: wrapperFile.path,
1104
+ meta: wrapperFile.meta,
1105
+ banner: resolver.resolveBanner(adapter.rootNode, {
1106
+ output,
1107
+ config
1108
+ }),
1109
+ footer: resolver.resolveFooter(adapter.rootNode, {
1110
+ output,
1111
+ config
1112
+ }),
1113
+ children: [
1114
+ importPath ? /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1115
+ name: ["Client", "RequestConfig"],
1116
+ path: importPath,
1117
+ isTypeOnly: true
1118
+ }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1119
+ name: ["Client", "RequestConfig"],
1120
+ root: wrapperFile.path,
1121
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
1122
+ isTypeOnly: true
1123
+ }),
1124
+ controllers.map(({ name, file }) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1125
+ name: [name],
1126
+ root: wrapperFile.path,
1127
+ path: file.path
1128
+ }, name)),
1129
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(WrapperClient, {
1130
+ name: wrapper.className,
1131
+ classNames: controllers.map(({ name }) => name)
1132
+ })
1133
+ ]
1134
+ }, wrapperFile.path));
1135
+ }
1136
+ return files;
1137
+ }
1138
+ });
1139
+ //#endregion
1140
+ //#region src/generators/clientGenerator.tsx
1141
+ const clientGenerator = (0, _kubb_core.defineGenerator)({
1142
+ name: "client",
1143
+ type: "react",
1144
+ Operation({ node, adapter, options, config, driver, resolver, plugin }) {
1145
+ const { output, urlType, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath, group } = options;
1146
+ const baseURL = options.baseURL ?? adapter.rootNode?.meta?.baseURL;
1147
+ const root = node_path.default.resolve(config.root, config.output.path);
1148
+ const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
1149
+ if (!pluginTs?.resolver) return null;
1150
+ const tsResolver = pluginTs.resolver;
1151
+ const pluginZod = parser === "zod" ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : void 0;
1152
+ const zodResolver = pluginZod?.resolver;
1153
+ const transformedNode = plugin.transformer ? (0, _kubb_ast.transform)(node, plugin.transformer) : node;
1154
+ const casedParams = (0, _kubb_ast.caseParams)(transformedNode.parameters, paramsCasing);
1155
+ const pathParams = casedParams.filter((p) => p.in === "path");
1156
+ const queryParams = casedParams.filter((p) => p.in === "query");
1157
+ const headerParams = casedParams.filter((p) => p.in === "header");
1158
+ const importedTypeNames = [
1159
+ ...pathParams.map((p) => tsResolver.resolvePathParamsName(transformedNode, p)),
1160
+ ...queryParams.map((p) => tsResolver.resolveQueryParamsName(transformedNode, p)),
1161
+ ...headerParams.map((p) => tsResolver.resolveHeaderParamsName(transformedNode, p)),
1162
+ transformedNode.requestBody?.schema ? tsResolver.resolveDataName(transformedNode) : void 0,
1163
+ tsResolver.resolveResponseName(transformedNode),
1164
+ ...transformedNode.responses.map((res) => tsResolver.resolveResponseStatusName(transformedNode, res.statusCode))
1165
+ ].filter(Boolean);
1166
+ const importedZodNames = zodResolver && parser === "zod" ? [zodResolver.resolveResponseName?.(transformedNode), transformedNode.requestBody?.schema ? zodResolver.resolveDataName?.(transformedNode) : void 0].filter(Boolean) : [];
1167
+ const meta = {
1168
+ name: resolver.resolveName(transformedNode.operationId),
1169
+ urlName: `get${resolver.resolveName(transformedNode.operationId).charAt(0).toUpperCase()}${resolver.resolveName(transformedNode.operationId).slice(1)}Url`,
1170
+ file: resolver.resolveFile({
1171
+ name: transformedNode.operationId,
1172
+ extname: ".ts",
1173
+ tag: transformedNode.tags[0] ?? "default",
1174
+ path: transformedNode.path
1175
+ }, {
1176
+ root,
1177
+ output,
1178
+ group
1179
+ }),
1180
+ fileTs: tsResolver.resolveFile({
1181
+ name: transformedNode.operationId,
1182
+ extname: ".ts",
1183
+ tag: transformedNode.tags[0] ?? "default",
1184
+ path: transformedNode.path
1185
+ }, {
1186
+ root,
1187
+ output: pluginTs.options?.output ?? output,
1188
+ group: pluginTs.options?.group
1189
+ }),
1190
+ fileZod: zodResolver && pluginZod?.options ? zodResolver.resolveFile({
1191
+ name: transformedNode.operationId,
1192
+ extname: ".ts",
1193
+ tag: transformedNode.tags[0] ?? "default",
1194
+ path: transformedNode.path
1195
+ }, {
1196
+ root,
1197
+ output: pluginZod.options.output ?? output,
1198
+ group: pluginZod.options.group
1199
+ }) : void 0
1200
+ };
1201
+ const isFormData = transformedNode.requestBody?.contentType === "multipart/form-data";
1202
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
1203
+ baseName: meta.file.baseName,
1204
+ path: meta.file.path,
1205
+ meta: meta.file.meta,
1206
+ banner: resolver.resolveBanner(adapter.rootNode, {
1207
+ output,
1208
+ config
1209
+ }),
1210
+ footer: resolver.resolveFooter(adapter.rootNode, {
1211
+ output,
1212
+ config
1213
+ }),
1214
+ children: [
1215
+ importPath ? /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1216
+ name: "fetch",
1217
+ path: importPath
1218
+ }), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1219
+ name: [
1220
+ "Client",
1221
+ "RequestConfig",
1222
+ "ResponseErrorConfig"
1223
+ ],
1224
+ path: importPath,
1225
+ isTypeOnly: true
1226
+ })] }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1227
+ name: ["fetch"],
1228
+ root: meta.file.path,
1229
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts")
1230
+ }), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1231
+ name: [
1232
+ "Client",
1233
+ "RequestConfig",
1234
+ "ResponseErrorConfig"
1235
+ ],
1236
+ root: meta.file.path,
1237
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
1238
+ isTypeOnly: true
1239
+ })] }),
1240
+ isFormData && transformedNode.requestBody?.schema && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1241
+ name: ["buildFormData"],
1242
+ root: meta.file.path,
1243
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/config.ts")
1244
+ }),
1245
+ meta.fileZod && importedZodNames.length > 0 && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1246
+ name: importedZodNames,
1247
+ root: meta.file.path,
1248
+ path: meta.fileZod.path
1249
+ }),
1250
+ meta.fileTs && importedTypeNames.length > 0 && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1251
+ name: Array.from(new Set(importedTypeNames)),
1252
+ root: meta.file.path,
1253
+ path: meta.fileTs.path,
1254
+ isTypeOnly: true
1255
+ }),
1256
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Url, {
1257
+ name: meta.urlName,
1258
+ baseURL,
1259
+ pathParamsType,
1260
+ paramsCasing,
1261
+ paramsType,
1262
+ node: transformedNode,
1263
+ tsResolver,
1264
+ isIndexable: urlType === "export",
1265
+ isExportable: urlType === "export"
1266
+ }),
1267
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Client, {
1268
+ name: meta.name,
1269
+ urlName: meta.urlName,
1270
+ baseURL,
1271
+ dataReturnType,
1272
+ pathParamsType,
1273
+ paramsCasing,
1274
+ paramsType,
1275
+ node: transformedNode,
1276
+ tsResolver,
1277
+ zodResolver,
1278
+ parser
1279
+ })
1280
+ ]
1281
+ });
1282
+ }
1283
+ });
1284
+ //#endregion
1285
+ //#region src/generators/groupedClientGenerator.tsx
1286
+ const groupedClientGenerator = (0, _kubb_core.defineGenerator)({
1287
+ name: "groupedClient",
1288
+ type: "react",
1289
+ Operations({ nodes, options, config, resolver, adapter, plugin }) {
1290
+ const { output, group } = options;
1291
+ const root = node_path.default.resolve(config.root, config.output.path);
1292
+ return nodes.reduce((acc, operationNode) => {
1293
+ if (group?.type === "tag") {
1294
+ const tag = operationNode.tags[0];
1295
+ const name = tag ? group?.name?.({ group: camelCase(tag) }) : void 0;
1296
+ if (!tag || !name) return acc;
1297
+ const transformedNode = plugin.transformer ? (0, _kubb_ast.transform)(operationNode, plugin.transformer) : operationNode;
1298
+ const file = resolver.resolveFile({
1299
+ name,
1300
+ extname: ".ts",
1301
+ tag
1302
+ }, {
1303
+ root,
1304
+ output,
1305
+ group
1306
+ });
1307
+ const clientFile = resolver.resolveFile({
1308
+ name: transformedNode.operationId,
1309
+ extname: ".ts",
1310
+ tag: transformedNode.tags[0] ?? "default",
1311
+ path: transformedNode.path
1312
+ }, {
1313
+ root,
1314
+ output,
1315
+ group
1316
+ });
1317
+ const client = {
1318
+ name: resolver.resolveName(transformedNode.operationId),
1319
+ file: clientFile
1320
+ };
1321
+ const previous = acc.find((item) => item.file.path === file.path);
1322
+ if (previous) previous.clients.push(client);
1323
+ else acc.push({
1324
+ name,
1325
+ file,
1326
+ clients: [client]
1327
+ });
1328
+ }
1329
+ return acc;
1330
+ }, []).map(({ name, file, clients }) => {
1331
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
1332
+ baseName: file.baseName,
1333
+ path: file.path,
1334
+ meta: file.meta,
1335
+ banner: resolver.resolveBanner(adapter.rootNode, {
1336
+ output,
1337
+ config
1338
+ }),
1339
+ footer: resolver.resolveFooter(adapter.rootNode, {
1340
+ output,
1341
+ config
1342
+ }),
1343
+ children: [clients.map((client) => /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1344
+ name: [client.name],
1345
+ root: file.path,
1346
+ path: client.file.path
1347
+ }, client.name)), /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
1348
+ name,
1349
+ isExportable: true,
1350
+ isIndexable: true,
1351
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Function, {
1352
+ export: true,
1353
+ name,
1354
+ children: `return { ${clients.map((client) => client.name).join(", ")} }`
1355
+ })
1356
+ })]
1357
+ }, file.path);
1358
+ });
1359
+ }
1360
+ });
1361
+ //#endregion
1362
+ //#region src/components/Operations.tsx
1363
+ function Operations({ name, nodes }) {
1364
+ const operationsObject = {};
1365
+ nodes.forEach((node) => {
1366
+ operationsObject[node.operationId] = {
1367
+ path: new URLPath(node.path).URL,
1368
+ method: node.method.toLowerCase()
1369
+ };
1370
+ });
1371
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Source, {
1372
+ name,
1373
+ isExportable: true,
1374
+ isIndexable: true,
1375
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.Const, {
1376
+ name,
1377
+ export: true,
1378
+ children: JSON.stringify(operationsObject, void 0, 2)
1379
+ })
1380
+ });
1381
+ }
1382
+ //#endregion
1383
+ //#region src/generators/operationsGenerator.tsx
1384
+ const operationsGenerator = (0, _kubb_core.defineGenerator)({
1385
+ name: "client",
1386
+ type: "react",
1387
+ Operations({ nodes, options, config, resolver, adapter }) {
1388
+ const { output, group } = options;
1389
+ const root = node_path.default.resolve(config.root, config.output.path);
1390
+ const name = "operations";
1391
+ const file = resolver.resolveFile({
1392
+ name,
1393
+ extname: ".ts"
1394
+ }, {
1395
+ root,
1396
+ output,
1397
+ group
1398
+ });
1399
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File, {
1400
+ baseName: file.baseName,
1401
+ path: file.path,
1402
+ meta: file.meta,
1403
+ banner: resolver.resolveBanner(adapter.rootNode, {
1404
+ output,
1405
+ config
1406
+ }),
1407
+ footer: resolver.resolveFooter(adapter.rootNode, {
1408
+ output,
1409
+ config
1410
+ }),
1411
+ children: /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(Operations, {
1412
+ name,
1413
+ nodes
1414
+ })
1415
+ });
1416
+ }
1417
+ });
1418
+ //#endregion
1419
+ //#region src/components/StaticClassClient.tsx
1420
+ const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1421
+ function generateMethod({ node, name, tsResolver, zodResolver, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType }) {
1422
+ const path = new URLPath(node.path, { casing: paramsCasing });
1423
+ const contentType = node.requestBody?.contentType ?? "application/json";
1424
+ const isFormData = contentType === "multipart/form-data";
1425
+ const headers = buildHeaders(contentType, !!(node.parameters.filter((p) => p.in === "header").length > 0 ? tsResolver.resolveHeaderParamsName(node, node.parameters.filter((p) => p.in === "header")[0]) : void 0));
1426
+ const generics = buildGenerics(node, tsResolver);
1427
+ const paramsNode = Client.getParams({
1428
+ paramsType,
1429
+ paramsCasing,
1430
+ pathParamsType,
1431
+ node,
1432
+ tsResolver,
1433
+ isConfigurable: true
1434
+ });
1435
+ const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1436
+ const clientParams = buildClassClientParams({
1437
+ node,
1438
+ path,
1439
+ baseURL,
1440
+ tsResolver,
1441
+ isFormData,
1442
+ headers
1443
+ });
1444
+ const jsdoc = buildJSDoc(getComments(node));
1445
+ const requestDataLine = buildRequestDataLine({
1446
+ parser,
1447
+ node,
1448
+ zodResolver
1449
+ });
1450
+ const formDataLine = buildFormDataLine(isFormData, !!node.requestBody?.schema);
1451
+ const returnStatement = buildReturnStatement({
1452
+ dataReturnType,
1453
+ parser,
1454
+ node,
1455
+ zodResolver
1456
+ });
1457
+ return `${jsdoc} static async ${name}(${paramsSignature}) {\n${[
1458
+ "const { client: request = fetch, ...requestConfig } = mergeConfig(this.#config, config)",
1459
+ "",
1460
+ requestDataLine,
1461
+ formDataLine,
1462
+ `const res = await request<${generics.join(", ")}>(${clientParams.toCall()})`,
1463
+ returnStatement
1464
+ ].filter(Boolean).map((line) => ` ${line}`).join("\n")}\n }`;
1465
+ }
1466
+ function StaticClassClient({ name, isExportable = true, isIndexable = true, operations, baseURL, dataReturnType, parser, paramsType, paramsCasing, pathParamsType, children }) {
1467
+ const classCode = `export class ${name} {\n static #config: Partial<RequestConfig> & { client?: Client } = {}\n\n${operations.map(({ node, name: methodName, tsResolver, zodResolver }) => generateMethod({
1468
+ node,
1469
+ name: methodName,
1470
+ tsResolver,
1471
+ zodResolver,
1472
+ baseURL,
1473
+ dataReturnType,
1474
+ parser,
1475
+ paramsType,
1476
+ paramsCasing,
1477
+ pathParamsType
1478
+ })).join("\n\n")}\n}`;
1479
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File.Source, {
1480
+ name,
1481
+ isExportable,
1482
+ isIndexable,
1483
+ children: [classCode, children]
1484
+ });
1485
+ }
1486
+ StaticClassClient.getParams = Client.getParams;
1487
+ //#endregion
1488
+ //#region src/generators/staticClassClientGenerator.tsx
1489
+ function resolveTypeImportNames(node, tsResolver) {
1490
+ return [
1491
+ node.requestBody?.schema ? tsResolver.resolveDataName(node) : void 0,
1492
+ tsResolver.resolveResponseName(node),
1493
+ ...node.parameters.filter((p) => p.in === "path").map((p) => tsResolver.resolvePathParamsName(node, p)),
1494
+ ...node.parameters.filter((p) => p.in === "query").map((p) => tsResolver.resolveQueryParamsName(node, p)),
1495
+ ...node.parameters.filter((p) => p.in === "header").map((p) => tsResolver.resolveHeaderParamsName(node, p)),
1496
+ ...node.responses.map((res) => tsResolver.resolveResponseStatusName(node, res.statusCode))
1497
+ ].filter((n) => Boolean(n));
1498
+ }
1499
+ function resolveZodImportNames(node, zodResolver) {
1500
+ return [zodResolver.resolveResponseName?.(node), node.requestBody?.schema ? zodResolver.resolveDataName?.(node) : void 0].filter((n) => Boolean(n));
1501
+ }
1502
+ const staticClassClientGenerator = (0, _kubb_core.defineGenerator)({
1503
+ name: "staticClassClient",
1504
+ type: "react",
1505
+ Operations({ nodes, options, config, driver, resolver, adapter, plugin }) {
1506
+ const { output, group, dataReturnType, paramsCasing, paramsType, pathParamsType, parser, importPath } = options;
1507
+ const baseURL = options.baseURL ?? adapter.rootNode?.meta?.baseURL;
1508
+ const root = node_path.default.resolve(config.root, config.output.path);
1509
+ const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
1510
+ if (!pluginTs?.resolver) return null;
1511
+ const tsResolver = pluginTs.resolver;
1512
+ const tsPluginOptions = pluginTs.options;
1513
+ const pluginZod = parser === "zod" ? driver.getPlugin(_kubb_plugin_zod.pluginZodName) : void 0;
1514
+ const zodResolver = pluginZod?.resolver;
1515
+ function buildOperationData(node) {
1516
+ const transformedNode = plugin.transformer ? (0, _kubb_ast.transform)(node, plugin.transformer) : node;
1517
+ const typeFile = tsResolver.resolveFile({
1518
+ name: transformedNode.operationId,
1519
+ extname: ".ts",
1520
+ tag: transformedNode.tags[0] ?? "default",
1521
+ path: transformedNode.path
1522
+ }, {
1523
+ root,
1524
+ output: tsPluginOptions?.output ?? output,
1525
+ group: tsPluginOptions?.group
1526
+ });
1527
+ const zodFile = zodResolver && pluginZod?.options ? zodResolver.resolveFile({
1528
+ name: transformedNode.operationId,
1529
+ extname: ".ts",
1530
+ tag: transformedNode.tags[0] ?? "default",
1531
+ path: transformedNode.path
1532
+ }, {
1533
+ root,
1534
+ output: pluginZod.options.output ?? output,
1535
+ group: pluginZod.options.group
1536
+ }) : void 0;
1537
+ return {
1538
+ node: transformedNode,
1539
+ name: resolver.resolveName(transformedNode.operationId),
1540
+ tsResolver,
1541
+ zodResolver,
1542
+ typeFile,
1543
+ zodFile
1544
+ };
1545
+ }
1546
+ const controllers = nodes.reduce((acc, operationNode) => {
1547
+ const tag = operationNode.tags[0];
1548
+ const groupName = tag ? group?.name?.({ group: camelCase(tag) }) ?? pascalCase(tag) : "Client";
1549
+ if (!tag && !group) {
1550
+ const name = "ApiClient";
1551
+ const file = resolver.resolveFile({
1552
+ name,
1553
+ extname: ".ts"
1554
+ }, {
1555
+ root,
1556
+ output,
1557
+ group
1558
+ });
1559
+ const operationData = buildOperationData(operationNode);
1560
+ const previous = acc.find((item) => item.file.path === file.path);
1561
+ if (previous) previous.operations.push(operationData);
1562
+ else acc.push({
1563
+ name,
1564
+ file,
1565
+ operations: [operationData]
1566
+ });
1567
+ } else if (tag) {
1568
+ const name = groupName;
1569
+ const file = resolver.resolveFile({
1570
+ name,
1571
+ extname: ".ts",
1572
+ tag
1573
+ }, {
1574
+ root,
1575
+ output,
1576
+ group
1577
+ });
1578
+ const operationData = buildOperationData(operationNode);
1579
+ const previous = acc.find((item) => item.file.path === file.path);
1580
+ if (previous) previous.operations.push(operationData);
1581
+ else acc.push({
1582
+ name,
1583
+ file,
1584
+ operations: [operationData]
1585
+ });
1586
+ }
1587
+ return acc;
1588
+ }, []);
1589
+ function collectTypeImports(ops) {
1590
+ const typeImportsByFile = /* @__PURE__ */ new Map();
1591
+ const typeFilesByPath = /* @__PURE__ */ new Map();
1592
+ ops.forEach((op) => {
1593
+ const names = resolveTypeImportNames(op.node, tsResolver);
1594
+ if (!typeImportsByFile.has(op.typeFile.path)) typeImportsByFile.set(op.typeFile.path, /* @__PURE__ */ new Set());
1595
+ const imports = typeImportsByFile.get(op.typeFile.path);
1596
+ names.forEach((n) => {
1597
+ imports.add(n);
1598
+ });
1599
+ typeFilesByPath.set(op.typeFile.path, op.typeFile);
1600
+ });
1601
+ return {
1602
+ typeImportsByFile,
1603
+ typeFilesByPath
1604
+ };
1605
+ }
1606
+ function collectZodImports(ops) {
1607
+ const zodImportsByFile = /* @__PURE__ */ new Map();
1608
+ const zodFilesByPath = /* @__PURE__ */ new Map();
1609
+ ops.forEach((op) => {
1610
+ if (!op.zodFile || !zodResolver) return;
1611
+ const names = resolveZodImportNames(op.node, zodResolver);
1612
+ if (!zodImportsByFile.has(op.zodFile.path)) zodImportsByFile.set(op.zodFile.path, /* @__PURE__ */ new Set());
1613
+ const imports = zodImportsByFile.get(op.zodFile.path);
1614
+ names.forEach((n) => {
1615
+ imports.add(n);
1616
+ });
1617
+ zodFilesByPath.set(op.zodFile.path, op.zodFile);
1618
+ });
1619
+ return {
1620
+ zodImportsByFile,
1621
+ zodFilesByPath
1622
+ };
1623
+ }
1624
+ return controllers.map(({ name, file, operations: ops }) => {
1625
+ const { typeImportsByFile, typeFilesByPath } = collectTypeImports(ops);
1626
+ const { zodImportsByFile, zodFilesByPath } = parser === "zod" ? collectZodImports(ops) : {
1627
+ zodImportsByFile: /* @__PURE__ */ new Map(),
1628
+ zodFilesByPath: /* @__PURE__ */ new Map()
1629
+ };
1630
+ const hasFormData = ops.some((op) => op.node.requestBody?.contentType === "multipart/form-data");
1631
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric.File, {
1632
+ baseName: file.baseName,
1633
+ path: file.path,
1634
+ meta: file.meta,
1635
+ banner: resolver.resolveBanner(adapter.rootNode, {
1636
+ output,
1637
+ config
1638
+ }),
1639
+ footer: resolver.resolveFooter(adapter.rootNode, {
1640
+ output,
1641
+ config
1642
+ }),
1643
+ children: [
1644
+ importPath ? /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
1645
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1646
+ name: "fetch",
1647
+ path: importPath
1648
+ }),
1649
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1650
+ name: ["mergeConfig"],
1651
+ path: importPath
1652
+ }),
1653
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1654
+ name: [
1655
+ "Client",
1656
+ "RequestConfig",
1657
+ "ResponseErrorConfig"
1658
+ ],
1659
+ path: importPath,
1660
+ isTypeOnly: true
1661
+ })
1662
+ ] }) : /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsxs)(_kubb_react_fabric_jsx_runtime.Fragment, { children: [
1663
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1664
+ name: ["fetch"],
1665
+ root: file.path,
1666
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts")
1667
+ }),
1668
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1669
+ name: ["mergeConfig"],
1670
+ root: file.path,
1671
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts")
1672
+ }),
1673
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1674
+ name: [
1675
+ "Client",
1676
+ "RequestConfig",
1677
+ "ResponseErrorConfig"
1678
+ ],
1679
+ root: file.path,
1680
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
1681
+ isTypeOnly: true
1682
+ })
1683
+ ] }),
1684
+ hasFormData && /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1685
+ name: ["buildFormData"],
1686
+ root: file.path,
1687
+ path: node_path.default.resolve(config.root, config.output.path, ".kubb/config.ts")
1688
+ }),
1689
+ Array.from(typeImportsByFile.entries()).map(([filePath, importSet]) => {
1690
+ const typeFile = typeFilesByPath.get(filePath);
1691
+ if (!typeFile) return null;
1692
+ const importNames = Array.from(importSet).filter(Boolean);
1693
+ if (importNames.length === 0) return null;
1694
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1695
+ name: importNames,
1696
+ root: file.path,
1697
+ path: typeFile.path,
1698
+ isTypeOnly: true
1699
+ }, filePath);
1700
+ }),
1701
+ parser === "zod" && Array.from(zodImportsByFile.entries()).map(([filePath, importSet]) => {
1702
+ const zodFile = zodFilesByPath.get(filePath);
1703
+ if (!zodFile) return null;
1704
+ const importNames = Array.from(importSet).filter(Boolean);
1705
+ if (importNames.length === 0) return null;
1706
+ return /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(_kubb_react_fabric.File.Import, {
1707
+ name: importNames,
1708
+ root: file.path,
1709
+ path: zodFile.path
1710
+ }, filePath);
1711
+ }),
1712
+ /* @__PURE__ */ (0, _kubb_react_fabric_jsx_runtime.jsx)(StaticClassClient, {
1713
+ name,
1714
+ operations: ops,
1715
+ baseURL,
1716
+ dataReturnType,
1717
+ pathParamsType,
1718
+ paramsCasing,
1719
+ paramsType,
1720
+ parser
1721
+ })
1722
+ ]
1723
+ }, file.path);
1724
+ });
1725
+ }
1726
+ });
1727
+ //#endregion
1728
+ //#region src/resolvers/resolverClient.ts
1729
+ /**
1730
+ * Resolver for `@kubb/plugin-client` that provides the default naming
1731
+ * and path-resolution helpers used by the plugin.
1732
+ *
1733
+ * @example
1734
+ * ```ts
1735
+ * import { resolverClient } from '@kubb/plugin-client'
1736
+ *
1737
+ * resolverClient.default('list pets', 'function') // -> 'listPets'
1738
+ * resolverClient.resolveName('show pet by id') // -> 'showPetById'
1739
+ * ```
1740
+ */
1741
+ const resolverClient = (0, _kubb_core.defineResolver)(() => ({
1742
+ name: "default",
1743
+ pluginName: "plugin-client",
1744
+ default(name, type) {
1745
+ return camelCase(name, { isFile: type === "file" });
1746
+ },
1747
+ resolveName(name) {
1748
+ return this.default(name, "function");
1749
+ }
1750
+ }));
1751
+ //#endregion
1752
+ //#region src/resolvers/resolverClientLegacy.ts
1753
+ /**
1754
+ * Legacy resolver for `@kubb/plugin-client` that provides backward-compatible
1755
+ * naming conventions matching the v4 behavior.
1756
+ *
1757
+ * @example
1758
+ * ```ts
1759
+ * import { resolverClientLegacy } from '@kubb/plugin-client'
1760
+ *
1761
+ * resolverClientLegacy.default('list pets', 'function') // -> 'listPets'
1762
+ * resolverClientLegacy.resolveName('show pet by id') // -> 'showPetById'
1763
+ * ```
1764
+ */
1765
+ const resolverClientLegacy = (0, _kubb_core.defineResolver)(() => ({
1766
+ name: "kubbV4",
1767
+ pluginName: "plugin-client",
1768
+ default(name, type) {
1769
+ return camelCase(name, { isFile: type === "file" });
1770
+ },
1771
+ resolveName(name) {
1772
+ return this.default(name, "function");
1773
+ }
1774
+ }));
1775
+ //#endregion
1776
+ //#region src/presets.ts
1777
+ /**
1778
+ * Built-in preset registry for `@kubb/plugin-client`.
1779
+ *
1780
+ * - `default` — uses `resolverClient` with v5 naming conventions.
1781
+ * - `kubbV4` — uses `resolverClientLegacy` with backward-compatible naming.
1782
+ *
1783
+ * Note: Unlike plugin-ts/plugin-zod, generators are not defined here because
1784
+ * plugin-client selects generators dynamically based on `clientType`, `group`,
1785
+ * and `operations` options. Generator selection happens in `plugin.ts`.
1786
+ */
1787
+ const presets = (0, _kubb_core.definePresets)({
1788
+ default: {
1789
+ name: "default",
1790
+ resolver: resolverClient
1791
+ },
1792
+ kubbV4: {
1793
+ name: "kubbV4",
1794
+ resolver: resolverClientLegacy
1795
+ }
1796
+ });
1797
+ //#endregion
13
1798
  //#region src/plugin.ts
1799
+ /**
1800
+ * Canonical plugin name for `@kubb/plugin-client`, used to identify the plugin
1801
+ * in driver lookups and warnings.
1802
+ */
14
1803
  const pluginClientName = "plugin-client";
1804
+ /**
1805
+ * The `@kubb/plugin-client` plugin factory.
1806
+ *
1807
+ * Generates type-safe HTTP client functions (or classes) from an OpenAPI/AST `RootNode`.
1808
+ * Walks operations, delegates rendering to the active generators,
1809
+ * and writes barrel files based on `output.barrelType`.
1810
+ *
1811
+ * @example
1812
+ * ```ts
1813
+ * import { pluginClient } from '@kubb/plugin-client'
1814
+ *
1815
+ * export default defineConfig({
1816
+ * plugins: [pluginClient({ output: { path: 'clients' } })],
1817
+ * })
1818
+ * ```
1819
+ */
15
1820
  const pluginClient = (0, _kubb_core.createPlugin)((options) => {
16
1821
  const { output = {
17
1822
  path: "clients",
18
1823
  barrelType: "named"
19
- }, group, urlType = false, exclude = [], include, override = [], transformers = {}, dataReturnType = "data", paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", operations = false, baseURL, paramsCasing, clientType = "function", parser = "client", client = "axios", importPath, contentType, bundle = false, wrapper } = options;
1824
+ }, group, urlType = false, exclude = [], include, override = [], dataReturnType = "data", paramsType = "inline", pathParamsType = paramsType === "object" ? "object" : options.pathParamsType || "inline", operations = false, paramsCasing, clientType = "function", parser = "client", client = "axios", importPath, bundle = false, wrapper, baseURL, compatibilityPreset = "default", resolver: userResolver, transformer: userTransformer } = options;
20
1825
  const resolvedImportPath = importPath ?? (!bundle ? `@kubb/plugin-client/clients/${client}` : void 0);
21
- const defaultGenerators = [
22
- clientType === "staticClass" ? require_generators.staticClassClientGenerator : clientType === "class" ? require_generators.classClientGenerator : require_generators.clientGenerator,
23
- group && clientType === "function" ? require_generators.groupedClientGenerator : void 0,
24
- operations ? require_generators.operationsGenerator : void 0
25
- ].filter((x) => Boolean(x));
26
- const generators = options.generators ?? defaultGenerators;
1826
+ const preset = (0, _kubb_core.getPreset)({
1827
+ preset: compatibilityPreset,
1828
+ presets,
1829
+ resolver: userResolver,
1830
+ transformer: userTransformer,
1831
+ generators: options.generators ?? [
1832
+ clientType === "staticClass" ? staticClassClientGenerator : clientType === "class" ? classClientGenerator : clientGenerator,
1833
+ group && clientType === "function" ? groupedClientGenerator : void 0,
1834
+ operations ? operationsGenerator : void 0
1835
+ ].filter((x) => Boolean(x))
1836
+ });
1837
+ let resolveNameWarning = false;
1838
+ let resolvePathWarning = false;
27
1839
  return {
28
1840
  name: pluginClientName,
29
- options: {
30
- client,
31
- clientType,
32
- bundle,
33
- output,
34
- group,
35
- parser,
36
- dataReturnType,
37
- importPath: resolvedImportPath,
38
- paramsType,
39
- paramsCasing,
40
- pathParamsType,
41
- baseURL,
42
- urlType,
43
- wrapper
1841
+ get resolver() {
1842
+ return preset.resolver;
1843
+ },
1844
+ get transformer() {
1845
+ return preset.transformer;
44
1846
  },
45
- pre: [_kubb_plugin_oas.pluginOasName, parser === "zod" ? _kubb_plugin_zod.pluginZodName : void 0].filter(Boolean),
1847
+ get options() {
1848
+ return {
1849
+ client,
1850
+ clientType,
1851
+ bundle,
1852
+ output,
1853
+ group: group ? {
1854
+ ...group,
1855
+ name: group.name ? group.name : (ctx) => {
1856
+ if (group.type === "path") return `${ctx.group.split("/")[1]}`;
1857
+ return `${camelCase(ctx.group)}Controller`;
1858
+ }
1859
+ } : void 0,
1860
+ parser,
1861
+ dataReturnType,
1862
+ importPath: resolvedImportPath,
1863
+ baseURL,
1864
+ paramsType,
1865
+ paramsCasing,
1866
+ pathParamsType,
1867
+ urlType,
1868
+ wrapper,
1869
+ resolver: preset.resolver
1870
+ };
1871
+ },
1872
+ pre: [_kubb_plugin_ts.pluginTsName, parser === "zod" ? _kubb_plugin_zod.pluginZodName : void 0].filter(Boolean),
46
1873
  resolvePath(baseName, pathMode, options) {
47
- const root = node_path.default.resolve(this.config.root, this.config.output.path);
48
- if ((pathMode ?? (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path))) === "single")
49
- /**
50
- * when output is a file then we will always append to the same file(output file), see fileManager.addOrAppend
51
- * Other plugins then need to call addOrAppend instead of just add from the fileManager class
52
- */
53
- return node_path.default.resolve(root, output.path);
54
- if (group && (options?.group?.path || options?.group?.tag)) {
55
- const groupName = group?.name ? group.name : (ctx) => {
56
- if (group?.type === "path") return `${ctx.group.split("/")[1]}`;
57
- return `${require_StaticClassClient.camelCase(ctx.group)}Controller`;
58
- };
59
- return node_path.default.resolve(root, output.path, groupName({ group: group.type === "path" ? options.group.path : options.group.tag }), baseName);
1874
+ if (!resolvePathWarning) {
1875
+ this.events.emit("warn", "Do not use resolvePath for pluginClient, use resolverClient.resolvePath instead");
1876
+ resolvePathWarning = true;
60
1877
  }
61
- return node_path.default.resolve(root, output.path, baseName);
1878
+ return this.plugin.resolver.resolvePath({
1879
+ baseName,
1880
+ pathMode,
1881
+ tag: options?.group?.tag,
1882
+ path: options?.group?.path
1883
+ }, {
1884
+ root: node_path.default.resolve(this.config.root, this.config.output.path),
1885
+ output,
1886
+ group: this.plugin.options.group
1887
+ });
62
1888
  },
63
1889
  resolveName(name, type) {
64
- const resolvedName = require_StaticClassClient.camelCase(name, { isFile: type === "file" });
65
- if (type) return transformers?.name?.(resolvedName, type) || resolvedName;
66
- return resolvedName;
1890
+ if (!resolveNameWarning) {
1891
+ this.events.emit("warn", "Do not use resolveName for pluginClient, use resolverClient.default instead");
1892
+ resolveNameWarning = true;
1893
+ }
1894
+ return this.plugin.resolver.default(name, type);
67
1895
  },
68
1896
  async install() {
69
- const root = node_path.default.resolve(this.config.root, this.config.output.path);
70
- const mode = (0, _kubb_core.getMode)(node_path.default.resolve(root, output.path));
71
- const oas = await this.getOas();
72
- const baseURL = await this.getBaseURL();
73
- if (bundle && !this.plugin.options.importPath) await this.addFile({
1897
+ const { config, fabric, plugin, adapter, rootNode, driver } = this;
1898
+ const root = node_path.default.resolve(config.root, config.output.path);
1899
+ const resolver = preset.resolver;
1900
+ if (!adapter) throw new Error("Plugin cannot work without adapter being set");
1901
+ if (bundle && !plugin.options.importPath) await this.addFile({
74
1902
  baseName: "fetch.ts",
75
1903
  path: node_path.default.resolve(root, ".kubb/fetch.ts"),
76
1904
  sources: [{
77
1905
  name: "fetch",
78
- value: this.plugin.options.client === "fetch" ? require_templates_clients_fetch_source.source : require_templates_clients_axios_source.source,
1906
+ value: plugin.options.client === "fetch" ? require_templates_clients_fetch_source.source : require_templates_clients_axios_source.source,
79
1907
  isExportable: true,
80
1908
  isIndexable: true
81
1909
  }],
@@ -94,22 +1922,32 @@ const pluginClient = (0, _kubb_core.createPlugin)((options) => {
94
1922
  imports: [],
95
1923
  exports: []
96
1924
  });
97
- const files = await new _kubb_plugin_oas.OperationGenerator(baseURL ? {
98
- ...this.plugin.options,
99
- baseURL
100
- } : this.plugin.options, {
101
- fabric: this.fabric,
102
- oas,
103
- driver: this.driver,
104
- events: this.events,
105
- plugin: this.plugin,
106
- contentType,
1925
+ const collectedOperations = [];
1926
+ const generatorContext = {
1927
+ generators: preset.generators,
1928
+ plugin,
1929
+ resolver,
107
1930
  exclude,
108
1931
  include,
109
1932
  override,
110
- mode
111
- }).build(...generators);
112
- await this.upsertFile(...files);
1933
+ fabric,
1934
+ adapter,
1935
+ config,
1936
+ driver
1937
+ };
1938
+ await (0, _kubb_ast.walk)(rootNode, {
1939
+ depth: "shallow",
1940
+ async operation(operationNode) {
1941
+ if (resolver.resolveOptions(operationNode, {
1942
+ options: plugin.options,
1943
+ exclude,
1944
+ include,
1945
+ override
1946
+ }) !== null) collectedOperations.push(operationNode);
1947
+ await (0, _kubb_core.runGeneratorOperation)(operationNode, generatorContext);
1948
+ }
1949
+ });
1950
+ await (0, _kubb_core.runGeneratorOperations)(collectedOperations, generatorContext);
113
1951
  const barrelFiles = await (0, _kubb_core.getBarrelFiles)(this.fabric.files, {
114
1952
  type: output.barrelType ?? "named",
115
1953
  root,
@@ -121,7 +1959,18 @@ const pluginClient = (0, _kubb_core.createPlugin)((options) => {
121
1959
  };
122
1960
  });
123
1961
  //#endregion
1962
+ exports.Client = Client;
1963
+ exports.ClientLegacy = ClientLegacy;
1964
+ exports.UrlLegacy = UrlLegacy;
1965
+ exports.classClientGenerator = classClientGenerator;
1966
+ exports.clientGenerator = clientGenerator;
1967
+ exports.groupedClientGenerator = groupedClientGenerator;
1968
+ exports.operationsGenerator = operationsGenerator;
124
1969
  exports.pluginClient = pluginClient;
125
1970
  exports.pluginClientName = pluginClientName;
1971
+ exports.presets = presets;
1972
+ exports.resolverClient = resolverClient;
1973
+ exports.resolverClientLegacy = resolverClientLegacy;
1974
+ exports.staticClassClientGenerator = staticClassClientGenerator;
126
1975
 
127
1976
  //# sourceMappingURL=index.cjs.map