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