@kubb/plugin-client 5.0.0-alpha.27 → 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
@@ -1,723 +0,0 @@
1
- import "./chunk--u3MIqq1.js";
2
- import { a as Url, i as Client, n as Operations, o as camelCase, r as ClassClient, s as pascalCase, t as StaticClassClient } from "./StaticClassClient-D6v3vhZL.js";
3
- import path from "node:path";
4
- import { pluginZodName } from "@kubb/plugin-zod";
5
- import { useDriver } from "@kubb/core/hooks";
6
- import { createReactGenerator } from "@kubb/plugin-oas/generators";
7
- import { useOas, useOperationManager } from "@kubb/plugin-oas/hooks";
8
- import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
9
- import { pluginTsName } from "@kubb/plugin-ts";
10
- import { File, Function } from "@kubb/react-fabric";
11
- import { Fragment, jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
12
- //#region src/components/WrapperClient.tsx
13
- function WrapperClient({ name, classNames, isExportable = true, isIndexable = true }) {
14
- const classCode = `export class ${name} {
15
- ${classNames.map((className) => ` readonly ${camelCase(className)}: ${className}`).join("\n")}
16
-
17
- constructor(config: Partial<RequestConfig> & { client?: Client } = {}) {
18
- ${classNames.map((className) => ` this.${camelCase(className)} = new ${className}(config)`).join("\n")}
19
- }
20
- }`;
21
- return /* @__PURE__ */ jsx(File.Source, {
22
- name,
23
- isExportable,
24
- isIndexable,
25
- children: classCode
26
- });
27
- }
28
- //#endregion
29
- //#region src/generators/classClientGenerator.tsx
30
- const classClientGenerator = createReactGenerator({
31
- name: "classClient",
32
- Operations({ operations, generator, plugin, config }) {
33
- const { options, name: pluginName } = plugin;
34
- const driver = useDriver();
35
- const oas = useOas();
36
- const { getName, getFile, getGroup, getSchemas } = useOperationManager(generator);
37
- function renderOperationData(operation) {
38
- const type = {
39
- file: getFile(operation, { pluginName: pluginTsName }),
40
- schemas: getSchemas(operation, {
41
- pluginName: pluginTsName,
42
- type: "type"
43
- })
44
- };
45
- const zod = {
46
- file: getFile(operation, { pluginName: pluginZodName }),
47
- schemas: getSchemas(operation, {
48
- pluginName: pluginZodName,
49
- type: "function"
50
- })
51
- };
52
- return {
53
- operation,
54
- name: getName(operation, { type: "function" }),
55
- typeSchemas: type.schemas,
56
- zodSchemas: zod.schemas,
57
- typeFile: type.file,
58
- zodFile: zod.file
59
- };
60
- }
61
- const controllers = operations.reduce((acc, operation) => {
62
- const group = getGroup(operation);
63
- const groupName = group?.tag ? options.group?.name?.({ group: camelCase(group.tag) }) ?? pascalCase(group.tag) : "Client";
64
- if (!group?.tag && !options.group) {
65
- const name = "ApiClient";
66
- const file = driver.getFile({
67
- name,
68
- extname: ".ts",
69
- pluginName
70
- });
71
- const operationData = renderOperationData(operation);
72
- const previousFile = acc.find((item) => item.file.path === file.path);
73
- if (previousFile) previousFile.operations.push(operationData);
74
- else acc.push({
75
- name,
76
- file,
77
- operations: [operationData]
78
- });
79
- } else if (group?.tag) {
80
- const name = groupName;
81
- const file = driver.getFile({
82
- name,
83
- extname: ".ts",
84
- pluginName,
85
- options: { group }
86
- });
87
- const operationData = renderOperationData(operation);
88
- const previousFile = acc.find((item) => item.file.path === file.path);
89
- if (previousFile) previousFile.operations.push(operationData);
90
- else acc.push({
91
- name,
92
- file,
93
- operations: [operationData]
94
- });
95
- }
96
- return acc;
97
- }, []);
98
- function collectTypeImports(ops) {
99
- const typeImportsByFile = /* @__PURE__ */ new Map();
100
- const typeFilesByPath = /* @__PURE__ */ new Map();
101
- ops.forEach((op) => {
102
- const { typeSchemas, typeFile } = op;
103
- if (!typeImportsByFile.has(typeFile.path)) typeImportsByFile.set(typeFile.path, /* @__PURE__ */ new Set());
104
- const typeImports = typeImportsByFile.get(typeFile.path);
105
- if (typeSchemas.request?.name) typeImports.add(typeSchemas.request.name);
106
- if (typeSchemas.response?.name) typeImports.add(typeSchemas.response.name);
107
- if (typeSchemas.pathParams?.name) typeImports.add(typeSchemas.pathParams.name);
108
- if (typeSchemas.queryParams?.name) typeImports.add(typeSchemas.queryParams.name);
109
- if (typeSchemas.headerParams?.name) typeImports.add(typeSchemas.headerParams.name);
110
- typeSchemas.statusCodes?.forEach((item) => {
111
- if (item?.name) typeImports.add(item.name);
112
- });
113
- typeFilesByPath.set(typeFile.path, typeFile);
114
- });
115
- return {
116
- typeImportsByFile,
117
- typeFilesByPath
118
- };
119
- }
120
- function collectZodImports(ops) {
121
- const zodImportsByFile = /* @__PURE__ */ new Map();
122
- const zodFilesByPath = /* @__PURE__ */ new Map();
123
- ops.forEach((op) => {
124
- const { zodSchemas, zodFile } = op;
125
- if (!zodImportsByFile.has(zodFile.path)) zodImportsByFile.set(zodFile.path, /* @__PURE__ */ new Set());
126
- const zodImports = zodImportsByFile.get(zodFile.path);
127
- if (zodSchemas?.response?.name) zodImports.add(zodSchemas.response.name);
128
- if (zodSchemas?.request?.name) zodImports.add(zodSchemas.request.name);
129
- zodFilesByPath.set(zodFile.path, zodFile);
130
- });
131
- return {
132
- zodImportsByFile,
133
- zodFilesByPath
134
- };
135
- }
136
- const files = controllers.map(({ name, file, operations: ops }) => {
137
- const { typeImportsByFile, typeFilesByPath } = collectTypeImports(ops);
138
- const { zodImportsByFile, zodFilesByPath } = options.parser === "zod" ? collectZodImports(ops) : {
139
- zodImportsByFile: /* @__PURE__ */ new Map(),
140
- zodFilesByPath: /* @__PURE__ */ new Map()
141
- };
142
- const hasFormData = ops.some((op) => op.operation.getContentType() === "multipart/form-data");
143
- return /* @__PURE__ */ jsxs(File, {
144
- baseName: file.baseName,
145
- path: file.path,
146
- meta: file.meta,
147
- banner: getBanner({
148
- oas,
149
- output: options.output,
150
- config: driver.config
151
- }),
152
- footer: getFooter({
153
- oas,
154
- output: options.output
155
- }),
156
- children: [
157
- options.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
158
- /* @__PURE__ */ jsx(File.Import, {
159
- name: "fetch",
160
- path: options.importPath
161
- }),
162
- /* @__PURE__ */ jsx(File.Import, {
163
- name: ["mergeConfig"],
164
- path: options.importPath
165
- }),
166
- /* @__PURE__ */ jsx(File.Import, {
167
- name: [
168
- "Client",
169
- "RequestConfig",
170
- "ResponseErrorConfig"
171
- ],
172
- path: options.importPath,
173
- isTypeOnly: true
174
- })
175
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
176
- /* @__PURE__ */ jsx(File.Import, {
177
- name: ["fetch"],
178
- root: file.path,
179
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts")
180
- }),
181
- /* @__PURE__ */ jsx(File.Import, {
182
- name: ["mergeConfig"],
183
- root: file.path,
184
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts")
185
- }),
186
- /* @__PURE__ */ jsx(File.Import, {
187
- name: [
188
- "Client",
189
- "RequestConfig",
190
- "ResponseErrorConfig"
191
- ],
192
- root: file.path,
193
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
194
- isTypeOnly: true
195
- })
196
- ] }),
197
- hasFormData && /* @__PURE__ */ jsx(File.Import, {
198
- name: ["buildFormData"],
199
- root: file.path,
200
- path: path.resolve(config.root, config.output.path, ".kubb/config.ts")
201
- }),
202
- Array.from(typeImportsByFile.entries()).map(([filePath, imports]) => {
203
- const typeFile = typeFilesByPath.get(filePath);
204
- if (!typeFile) return null;
205
- const importNames = Array.from(imports).filter(Boolean);
206
- if (importNames.length === 0) return null;
207
- return /* @__PURE__ */ jsx(File.Import, {
208
- name: importNames,
209
- root: file.path,
210
- path: typeFile.path,
211
- isTypeOnly: true
212
- }, filePath);
213
- }),
214
- options.parser === "zod" && Array.from(zodImportsByFile.entries()).map(([filePath, imports]) => {
215
- const zodFile = zodFilesByPath.get(filePath);
216
- if (!zodFile) return null;
217
- const importNames = Array.from(imports).filter(Boolean);
218
- if (importNames.length === 0) return null;
219
- return /* @__PURE__ */ jsx(File.Import, {
220
- name: importNames,
221
- root: file.path,
222
- path: zodFile.path
223
- }, filePath);
224
- }),
225
- /* @__PURE__ */ jsx(ClassClient, {
226
- name,
227
- operations: ops,
228
- baseURL: options.baseURL,
229
- dataReturnType: options.dataReturnType,
230
- pathParamsType: options.pathParamsType,
231
- paramsCasing: options.paramsCasing,
232
- paramsType: options.paramsType,
233
- parser: options.parser
234
- })
235
- ]
236
- }, file.path);
237
- });
238
- if (options.wrapper) {
239
- const wrapperFile = driver.getFile({
240
- name: options.wrapper.className,
241
- extname: ".ts",
242
- pluginName
243
- });
244
- files.push(/* @__PURE__ */ jsxs(File, {
245
- baseName: wrapperFile.baseName,
246
- path: wrapperFile.path,
247
- meta: wrapperFile.meta,
248
- banner: getBanner({
249
- oas,
250
- output: options.output,
251
- config: driver.config
252
- }),
253
- footer: getFooter({
254
- oas,
255
- output: options.output
256
- }),
257
- children: [
258
- options.importPath ? /* @__PURE__ */ jsx(File.Import, {
259
- name: ["Client", "RequestConfig"],
260
- path: options.importPath,
261
- isTypeOnly: true
262
- }) : /* @__PURE__ */ jsx(File.Import, {
263
- name: ["Client", "RequestConfig"],
264
- root: wrapperFile.path,
265
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
266
- isTypeOnly: true
267
- }),
268
- controllers.map(({ name, file }) => /* @__PURE__ */ jsx(File.Import, {
269
- name: [name],
270
- root: wrapperFile.path,
271
- path: file.path
272
- }, name)),
273
- /* @__PURE__ */ jsx(WrapperClient, {
274
- name: options.wrapper.className,
275
- classNames: controllers.map(({ name }) => name)
276
- })
277
- ]
278
- }, wrapperFile.path));
279
- }
280
- return files;
281
- }
282
- });
283
- //#endregion
284
- //#region src/generators/clientGenerator.tsx
285
- const clientGenerator = createReactGenerator({
286
- name: "client",
287
- Operation({ config, plugin, operation, generator }) {
288
- const driver = useDriver();
289
- const { options, options: { output, urlType } } = plugin;
290
- const oas = useOas();
291
- const { getSchemas, getName, getFile } = useOperationManager(generator);
292
- const client = {
293
- name: getName(operation, { type: "function" }),
294
- file: getFile(operation)
295
- };
296
- const url = {
297
- name: getName(operation, {
298
- type: "function",
299
- suffix: "url",
300
- prefix: "get"
301
- }),
302
- file: getFile(operation)
303
- };
304
- const type = {
305
- file: getFile(operation, { pluginName: pluginTsName }),
306
- schemas: getSchemas(operation, {
307
- pluginName: pluginTsName,
308
- type: "type"
309
- })
310
- };
311
- const zod = {
312
- file: getFile(operation, { pluginName: pluginZodName }),
313
- schemas: getSchemas(operation, {
314
- pluginName: pluginZodName,
315
- type: "function"
316
- })
317
- };
318
- const isFormData = operation.getContentType() === "multipart/form-data";
319
- return /* @__PURE__ */ jsxs(File, {
320
- baseName: client.file.baseName,
321
- path: client.file.path,
322
- meta: client.file.meta,
323
- banner: getBanner({
324
- oas,
325
- output,
326
- config: driver.config
327
- }),
328
- footer: getFooter({
329
- oas,
330
- output
331
- }),
332
- children: [
333
- options.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
334
- name: "fetch",
335
- path: options.importPath
336
- }), /* @__PURE__ */ jsx(File.Import, {
337
- name: [
338
- "Client",
339
- "RequestConfig",
340
- "ResponseErrorConfig"
341
- ],
342
- path: options.importPath,
343
- isTypeOnly: true
344
- })] }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
345
- name: ["fetch"],
346
- root: client.file.path,
347
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts")
348
- }), /* @__PURE__ */ jsx(File.Import, {
349
- name: [
350
- "Client",
351
- "RequestConfig",
352
- "ResponseErrorConfig"
353
- ],
354
- root: client.file.path,
355
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
356
- isTypeOnly: true
357
- })] }),
358
- isFormData && type.schemas.request?.name && /* @__PURE__ */ jsx(File.Import, {
359
- name: ["buildFormData"],
360
- root: client.file.path,
361
- path: path.resolve(config.root, config.output.path, ".kubb/config.ts")
362
- }),
363
- options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, {
364
- name: [zod.schemas.response.name, zod.schemas.request?.name].filter((x) => Boolean(x)),
365
- root: client.file.path,
366
- path: zod.file.path
367
- }),
368
- /* @__PURE__ */ jsx(File.Import, {
369
- name: [
370
- type.schemas.request?.name,
371
- type.schemas.response.name,
372
- type.schemas.pathParams?.name,
373
- type.schemas.queryParams?.name,
374
- type.schemas.headerParams?.name,
375
- ...type.schemas.statusCodes?.map((item) => item.name) || []
376
- ].filter((x) => Boolean(x)),
377
- root: client.file.path,
378
- path: type.file.path,
379
- isTypeOnly: true
380
- }),
381
- /* @__PURE__ */ jsx(Url, {
382
- name: url.name,
383
- baseURL: options.baseURL,
384
- pathParamsType: options.pathParamsType,
385
- paramsCasing: options.paramsCasing,
386
- paramsType: options.paramsType,
387
- typeSchemas: type.schemas,
388
- operation,
389
- isIndexable: urlType === "export",
390
- isExportable: urlType === "export"
391
- }),
392
- /* @__PURE__ */ jsx(Client, {
393
- name: client.name,
394
- urlName: url.name,
395
- baseURL: options.baseURL,
396
- dataReturnType: options.dataReturnType,
397
- pathParamsType: options.pathParamsType,
398
- paramsCasing: options.paramsCasing,
399
- paramsType: options.paramsType,
400
- typeSchemas: type.schemas,
401
- operation,
402
- parser: options.parser,
403
- zodSchemas: zod.schemas
404
- })
405
- ]
406
- });
407
- }
408
- });
409
- //#endregion
410
- //#region src/generators/groupedClientGenerator.tsx
411
- const groupedClientGenerator = createReactGenerator({
412
- name: "groupedClient",
413
- Operations({ operations, generator, plugin }) {
414
- const { options, name: pluginName } = plugin;
415
- const driver = useDriver();
416
- const oas = useOas();
417
- const { getName, getFile, getGroup } = useOperationManager(generator);
418
- return operations.reduce((acc, operation) => {
419
- if (options.group?.type === "tag") {
420
- const group = getGroup(operation);
421
- const name = group?.tag ? options.group?.name?.({ group: camelCase(group.tag) }) : void 0;
422
- if (!group?.tag || !name) return acc;
423
- const file = driver.getFile({
424
- name,
425
- extname: ".ts",
426
- pluginName,
427
- options: { group }
428
- });
429
- const client = {
430
- name: getName(operation, { type: "function" }),
431
- file: getFile(operation)
432
- };
433
- const previousFile = acc.find((item) => item.file.path === file.path);
434
- if (previousFile) previousFile.clients.push(client);
435
- else acc.push({
436
- name,
437
- file,
438
- clients: [client]
439
- });
440
- }
441
- return acc;
442
- }, []).map(({ name, file, clients }) => {
443
- return /* @__PURE__ */ jsxs(File, {
444
- baseName: file.baseName,
445
- path: file.path,
446
- meta: file.meta,
447
- banner: getBanner({
448
- oas,
449
- output: options.output,
450
- config: driver.config
451
- }),
452
- footer: getFooter({
453
- oas,
454
- output: options.output
455
- }),
456
- children: [clients.map((client) => /* @__PURE__ */ jsx(File.Import, {
457
- name: [client.name],
458
- root: file.path,
459
- path: client.file.path
460
- }, client.name)), /* @__PURE__ */ jsx(File.Source, {
461
- name,
462
- isExportable: true,
463
- isIndexable: true,
464
- children: /* @__PURE__ */ jsx(Function, {
465
- export: true,
466
- name,
467
- children: `return { ${clients.map((client) => client.name).join(", ")} }`
468
- })
469
- })]
470
- }, file.path);
471
- });
472
- }
473
- });
474
- //#endregion
475
- //#region src/generators/operationsGenerator.tsx
476
- const operationsGenerator = createReactGenerator({
477
- name: "client",
478
- Operations({ operations, plugin }) {
479
- const { name: pluginName, options: { output } } = plugin;
480
- const driver = useDriver();
481
- const oas = useOas();
482
- const name = "operations";
483
- const file = driver.getFile({
484
- name,
485
- extname: ".ts",
486
- pluginName
487
- });
488
- return /* @__PURE__ */ jsx(File, {
489
- baseName: file.baseName,
490
- path: file.path,
491
- meta: file.meta,
492
- banner: getBanner({
493
- oas,
494
- output,
495
- config: driver.config
496
- }),
497
- footer: getFooter({
498
- oas,
499
- output
500
- }),
501
- children: /* @__PURE__ */ jsx(Operations, {
502
- name,
503
- operations
504
- })
505
- });
506
- }
507
- });
508
- //#endregion
509
- //#region src/generators/staticClassClientGenerator.tsx
510
- const staticClassClientGenerator = createReactGenerator({
511
- name: "staticClassClient",
512
- Operations({ operations, generator, plugin, config }) {
513
- const { options, name: pluginName } = plugin;
514
- const driver = useDriver();
515
- const oas = useOas();
516
- const { getName, getFile, getGroup, getSchemas } = useOperationManager(generator);
517
- function renderOperationData(operation) {
518
- const type = {
519
- file: getFile(operation, { pluginName: pluginTsName }),
520
- schemas: getSchemas(operation, {
521
- pluginName: pluginTsName,
522
- type: "type"
523
- })
524
- };
525
- const zod = {
526
- file: getFile(operation, { pluginName: pluginZodName }),
527
- schemas: getSchemas(operation, {
528
- pluginName: pluginZodName,
529
- type: "function"
530
- })
531
- };
532
- return {
533
- operation,
534
- name: getName(operation, { type: "function" }),
535
- typeSchemas: type.schemas,
536
- zodSchemas: zod.schemas,
537
- typeFile: type.file,
538
- zodFile: zod.file
539
- };
540
- }
541
- const controllers = operations.reduce((acc, operation) => {
542
- const group = getGroup(operation);
543
- const groupName = group?.tag ? options.group?.name?.({ group: camelCase(group.tag) }) ?? pascalCase(group.tag) : "Client";
544
- if (!group?.tag && !options.group) {
545
- const name = "ApiClient";
546
- const file = driver.getFile({
547
- name,
548
- extname: ".ts",
549
- pluginName
550
- });
551
- const operationData = renderOperationData(operation);
552
- const previousFile = acc.find((item) => item.file.path === file.path);
553
- if (previousFile) previousFile.operations.push(operationData);
554
- else acc.push({
555
- name,
556
- file,
557
- operations: [operationData]
558
- });
559
- } else if (group?.tag) {
560
- const name = groupName;
561
- const file = driver.getFile({
562
- name,
563
- extname: ".ts",
564
- pluginName,
565
- options: { group }
566
- });
567
- const operationData = renderOperationData(operation);
568
- const previousFile = acc.find((item) => item.file.path === file.path);
569
- if (previousFile) previousFile.operations.push(operationData);
570
- else acc.push({
571
- name,
572
- file,
573
- operations: [operationData]
574
- });
575
- }
576
- return acc;
577
- }, []);
578
- function collectTypeImports(ops) {
579
- const typeImportsByFile = /* @__PURE__ */ new Map();
580
- const typeFilesByPath = /* @__PURE__ */ new Map();
581
- ops.forEach((op) => {
582
- const { typeSchemas, typeFile } = op;
583
- if (!typeImportsByFile.has(typeFile.path)) typeImportsByFile.set(typeFile.path, /* @__PURE__ */ new Set());
584
- const typeImports = typeImportsByFile.get(typeFile.path);
585
- if (typeSchemas.request?.name) typeImports.add(typeSchemas.request.name);
586
- if (typeSchemas.response?.name) typeImports.add(typeSchemas.response.name);
587
- if (typeSchemas.pathParams?.name) typeImports.add(typeSchemas.pathParams.name);
588
- if (typeSchemas.queryParams?.name) typeImports.add(typeSchemas.queryParams.name);
589
- if (typeSchemas.headerParams?.name) typeImports.add(typeSchemas.headerParams.name);
590
- typeSchemas.statusCodes?.forEach((item) => {
591
- if (item?.name) typeImports.add(item.name);
592
- });
593
- typeFilesByPath.set(typeFile.path, typeFile);
594
- });
595
- return {
596
- typeImportsByFile,
597
- typeFilesByPath
598
- };
599
- }
600
- function collectZodImports(ops) {
601
- const zodImportsByFile = /* @__PURE__ */ new Map();
602
- const zodFilesByPath = /* @__PURE__ */ new Map();
603
- ops.forEach((op) => {
604
- const { zodSchemas, zodFile } = op;
605
- if (!zodImportsByFile.has(zodFile.path)) zodImportsByFile.set(zodFile.path, /* @__PURE__ */ new Set());
606
- const zodImports = zodImportsByFile.get(zodFile.path);
607
- if (zodSchemas?.response?.name) zodImports.add(zodSchemas.response.name);
608
- if (zodSchemas?.request?.name) zodImports.add(zodSchemas.request.name);
609
- zodFilesByPath.set(zodFile.path, zodFile);
610
- });
611
- return {
612
- zodImportsByFile,
613
- zodFilesByPath
614
- };
615
- }
616
- return controllers.map(({ name, file, operations: ops }) => {
617
- const { typeImportsByFile, typeFilesByPath } = collectTypeImports(ops);
618
- const { zodImportsByFile, zodFilesByPath } = options.parser === "zod" ? collectZodImports(ops) : {
619
- zodImportsByFile: /* @__PURE__ */ new Map(),
620
- zodFilesByPath: /* @__PURE__ */ new Map()
621
- };
622
- const hasFormData = ops.some((op) => op.operation.getContentType() === "multipart/form-data");
623
- return /* @__PURE__ */ jsxs(File, {
624
- baseName: file.baseName,
625
- path: file.path,
626
- meta: file.meta,
627
- banner: getBanner({
628
- oas,
629
- output: options.output,
630
- config: driver.config
631
- }),
632
- footer: getFooter({
633
- oas,
634
- output: options.output
635
- }),
636
- children: [
637
- options.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
638
- /* @__PURE__ */ jsx(File.Import, {
639
- name: "fetch",
640
- path: options.importPath
641
- }),
642
- /* @__PURE__ */ jsx(File.Import, {
643
- name: ["mergeConfig"],
644
- path: options.importPath
645
- }),
646
- /* @__PURE__ */ jsx(File.Import, {
647
- name: [
648
- "Client",
649
- "RequestConfig",
650
- "ResponseErrorConfig"
651
- ],
652
- path: options.importPath,
653
- isTypeOnly: true
654
- })
655
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
656
- /* @__PURE__ */ jsx(File.Import, {
657
- name: ["fetch"],
658
- root: file.path,
659
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts")
660
- }),
661
- /* @__PURE__ */ jsx(File.Import, {
662
- name: ["mergeConfig"],
663
- root: file.path,
664
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts")
665
- }),
666
- /* @__PURE__ */ jsx(File.Import, {
667
- name: [
668
- "Client",
669
- "RequestConfig",
670
- "ResponseErrorConfig"
671
- ],
672
- root: file.path,
673
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
674
- isTypeOnly: true
675
- })
676
- ] }),
677
- hasFormData && /* @__PURE__ */ jsx(File.Import, {
678
- name: ["buildFormData"],
679
- root: file.path,
680
- path: path.resolve(config.root, config.output.path, ".kubb/config.ts")
681
- }),
682
- Array.from(typeImportsByFile.entries()).map(([filePath, imports]) => {
683
- const typeFile = typeFilesByPath.get(filePath);
684
- if (!typeFile) return null;
685
- const importNames = Array.from(imports).filter(Boolean);
686
- if (importNames.length === 0) return null;
687
- return /* @__PURE__ */ jsx(File.Import, {
688
- name: importNames,
689
- root: file.path,
690
- path: typeFile.path,
691
- isTypeOnly: true
692
- }, filePath);
693
- }),
694
- options.parser === "zod" && Array.from(zodImportsByFile.entries()).map(([filePath, imports]) => {
695
- const zodFile = zodFilesByPath.get(filePath);
696
- if (!zodFile) return null;
697
- const importNames = Array.from(imports).filter(Boolean);
698
- if (importNames.length === 0) return null;
699
- return /* @__PURE__ */ jsx(File.Import, {
700
- name: importNames,
701
- root: file.path,
702
- path: zodFile.path
703
- }, filePath);
704
- }),
705
- /* @__PURE__ */ jsx(StaticClassClient, {
706
- name,
707
- operations: ops,
708
- baseURL: options.baseURL,
709
- dataReturnType: options.dataReturnType,
710
- pathParamsType: options.pathParamsType,
711
- paramsCasing: options.paramsCasing,
712
- paramsType: options.paramsType,
713
- parser: options.parser
714
- })
715
- ]
716
- }, file.path);
717
- });
718
- }
719
- });
720
- //#endregion
721
- export { classClientGenerator as a, clientGenerator as i, operationsGenerator as n, groupedClientGenerator as r, staticClassClientGenerator as t };
722
-
723
- //# sourceMappingURL=generators-C0t5dIvZ.js.map