@kubb/plugin-react-query 5.0.0-alpha.8 → 5.0.0-beta.3

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 (52) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +1 -3
  3. package/dist/components-DTGLu4UV.js +1451 -0
  4. package/dist/components-DTGLu4UV.js.map +1 -0
  5. package/dist/components-dAKJEn9b.cjs +1571 -0
  6. package/dist/components-dAKJEn9b.cjs.map +1 -0
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +105 -161
  9. package/dist/components.js +1 -1
  10. package/dist/generators-CWEQsdO9.cjs +1502 -0
  11. package/dist/generators-CWEQsdO9.cjs.map +1 -0
  12. package/dist/generators-C_fbcjpG.js +1460 -0
  13. package/dist/generators-C_fbcjpG.js.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +9 -476
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +114 -126
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +110 -126
  21. package/dist/index.js.map +1 -1
  22. package/dist/{types-D5S7Ny9r.d.ts → types-DfaFRSBf.d.ts} +100 -86
  23. package/package.json +59 -62
  24. package/src/components/InfiniteQuery.tsx +75 -139
  25. package/src/components/InfiniteQueryOptions.tsx +62 -164
  26. package/src/components/Mutation.tsx +58 -113
  27. package/src/components/MutationOptions.tsx +61 -80
  28. package/src/components/Query.tsx +67 -140
  29. package/src/components/QueryOptions.tsx +75 -135
  30. package/src/components/SuspenseInfiniteQuery.tsx +75 -139
  31. package/src/components/SuspenseInfiniteQueryOptions.tsx +62 -164
  32. package/src/components/SuspenseQuery.tsx +67 -150
  33. package/src/generators/customHookOptionsFileGenerator.tsx +33 -45
  34. package/src/generators/hookOptionsGenerator.tsx +115 -175
  35. package/src/generators/infiniteQueryGenerator.tsx +183 -176
  36. package/src/generators/mutationGenerator.tsx +127 -138
  37. package/src/generators/queryGenerator.tsx +141 -141
  38. package/src/generators/suspenseInfiniteQueryGenerator.tsx +175 -155
  39. package/src/generators/suspenseQueryGenerator.tsx +149 -148
  40. package/src/index.ts +1 -1
  41. package/src/plugin.ts +133 -183
  42. package/src/resolvers/resolverReactQuery.ts +22 -0
  43. package/src/types.ts +67 -45
  44. package/src/utils.ts +40 -0
  45. package/dist/components-BHQT9ZLc.cjs +0 -1634
  46. package/dist/components-BHQT9ZLc.cjs.map +0 -1
  47. package/dist/components-CpyHYGOw.js +0 -1520
  48. package/dist/components-CpyHYGOw.js.map +0 -1
  49. package/dist/generators-DP07m3rH.cjs +0 -1469
  50. package/dist/generators-DP07m3rH.cjs.map +0 -1
  51. package/dist/generators-DkQwKTc2.js +0 -1427
  52. package/dist/generators-DkQwKTc2.js.map +0 -1
@@ -1,1427 +0,0 @@
1
- import "./chunk--u3MIqq1.js";
2
- import { a as Mutation, c as InfiniteQuery, d as MutationKey, i as Query, l as QueryOptions, n as SuspenseInfiniteQueryOptions, o as MutationOptions, r as SuspenseInfiniteQuery, s as InfiniteQueryOptions, t as SuspenseQuery, u as QueryKey } from "./components-CpyHYGOw.js";
3
- import path from "node:path";
4
- import fs from "node:fs";
5
- import { pluginClientName } from "@kubb/plugin-client";
6
- import { pluginTsName } from "@kubb/plugin-ts";
7
- import { pluginZodName } from "@kubb/plugin-zod";
8
- import { getBanner, getFooter } from "@kubb/plugin-oas/utils";
9
- import { File, Function, Type } from "@kubb/react-fabric";
10
- import { Fragment, jsx, jsxs } from "@kubb/react-fabric/jsx-runtime";
11
- import { Client } from "@kubb/plugin-client/components";
12
- import { usePluginDriver } from "@kubb/core/hooks";
13
- import { createReactGenerator } from "@kubb/plugin-oas/generators";
14
- import { useOas, useOperationManager } from "@kubb/plugin-oas/hooks";
15
- import { difference } from "remeda";
16
- //#region src/generators/customHookOptionsFileGenerator.tsx
17
- const customHookOptionsFileGenerator = createReactGenerator({
18
- name: "react-query-custom-hook-options-file",
19
- Operations({ operations, generator, plugin, config }) {
20
- const { options, options: { output }, name: pluginName } = plugin;
21
- const driver = usePluginDriver();
22
- const { getFile } = useOperationManager(generator);
23
- if (!options.customOptions) return null;
24
- const override = output.override ?? config.output.override ?? false;
25
- const { importPath, name } = options.customOptions;
26
- const root = path.resolve(config.root, config.output.path);
27
- const reactQueryImportPath = options.query ? options.query.importPath : "@tanstack/react-query";
28
- const getHookFilePath = (operations) => {
29
- const firstOperation = operations[0];
30
- if (firstOperation != null) return getFile(firstOperation, { prefix: "use" }).path;
31
- return driver.getFile({
32
- name: "index",
33
- extname: ".ts",
34
- pluginName
35
- }).path;
36
- };
37
- const ensureExtension = (filePath, extname) => {
38
- if (path.extname(filePath) === "") return filePath + extname;
39
- return filePath;
40
- };
41
- const getExternalFile = (filePath, rootPath) => {
42
- const actualFilePath = ensureExtension(filePath, ".ts");
43
- return {
44
- baseName: path.basename(actualFilePath),
45
- name: path.basename(actualFilePath, path.extname(actualFilePath)),
46
- path: path.resolve(rootPath, actualFilePath)
47
- };
48
- };
49
- const file = getExternalFile(importPath, path.dirname(getHookFilePath(operations)));
50
- if (fs.existsSync(file.path) && !override) return null;
51
- return /* @__PURE__ */ jsxs(File, {
52
- baseName: file.baseName,
53
- path: file.path,
54
- children: [
55
- /* @__PURE__ */ jsx(File.Import, {
56
- name: ["QueryClient"],
57
- path: reactQueryImportPath,
58
- isTypeOnly: true
59
- }),
60
- /* @__PURE__ */ jsx(File.Import, {
61
- name: ["useQueryClient"],
62
- path: reactQueryImportPath
63
- }),
64
- /* @__PURE__ */ jsx(File.Import, {
65
- name: ["HookOptions"],
66
- root: file.path,
67
- path: path.resolve(root, "./index.ts")
68
- }),
69
- /* @__PURE__ */ jsxs(File.Source, {
70
- name: file.name,
71
- isExportable: true,
72
- isIndexable: true,
73
- children: [/* @__PURE__ */ jsx(Function, {
74
- name: "getCustomHookOptions",
75
- params: "{ queryClient }: { queryClient: QueryClient }",
76
- returnType: "Partial<HookOptions>",
77
- children: `return {
78
- // TODO: Define custom hook options here
79
- // Example:
80
- // useUpdatePetHook: {
81
- // onSuccess: () => {
82
- // void queryClient.invalidateQueries({ queryKey: ['pet'] })
83
- // }
84
- // }
85
- }`
86
- }), /* @__PURE__ */ jsx(Function, {
87
- name,
88
- generics: "T extends keyof HookOptions",
89
- params: "{ hookName, operationId }: { hookName: T, operationId: string }",
90
- returnType: "HookOptions[T]",
91
- export: true,
92
- children: `const queryClient = useQueryClient()
93
- const customOptions = getCustomHookOptions({ queryClient })
94
- return customOptions[hookName] ?? {}`
95
- })]
96
- })
97
- ]
98
- });
99
- }
100
- });
101
- //#endregion
102
- //#region src/generators/hookOptionsGenerator.tsx
103
- const hookOptionsGenerator = createReactGenerator({
104
- name: "react-query-hook-options",
105
- Operations({ operations, plugin, generator }) {
106
- const { options, options: { output }, name: pluginName } = plugin;
107
- const driver = usePluginDriver();
108
- const oas = useOas();
109
- const { getName, getFile } = useOperationManager(generator);
110
- if (!options.customOptions) return null;
111
- const name = "HookOptions";
112
- const file = driver.getFile({
113
- name,
114
- extname: ".ts",
115
- pluginName
116
- });
117
- const getOperationOptions = (operation) => {
118
- const operationOptions = generator.getOptions(operation, operation.method);
119
- return {
120
- ...options,
121
- ...operationOptions
122
- };
123
- };
124
- const isQuery = (operation) => {
125
- const operationOptions = getOperationOptions(operation);
126
- return typeof operationOptions.query === "boolean" ? true : operationOptions.query?.methods.some((method) => operation.method === method);
127
- };
128
- const isMutation = (operation) => {
129
- const operationOptions = getOperationOptions(operation);
130
- return operationOptions.mutation !== false && !isQuery(operation) && difference(operationOptions.mutation ? operationOptions.mutation.methods : [], operationOptions.query ? operationOptions.query.methods : []).some((method) => operation.method === method);
131
- };
132
- const isSuspense = (operation) => {
133
- return !!getOperationOptions(operation).suspense;
134
- };
135
- const isInfinite = (operation) => {
136
- const operationOptions = getOperationOptions(operation);
137
- return !!(operationOptions.infinite && typeof operationOptions.infinite === "object" ? operationOptions.infinite : void 0);
138
- };
139
- const getHookName = (operation) => {
140
- return getName(operation, {
141
- type: "function",
142
- prefix: "use"
143
- });
144
- };
145
- const getHookFile = (operation) => {
146
- return getFile(operation, { prefix: "use" });
147
- };
148
- const getQueryHookOptions = (operation) => {
149
- return getName(operation, {
150
- type: "function",
151
- suffix: "QueryOptions"
152
- });
153
- };
154
- const getQueryHookOptionsImport = (operation) => {
155
- return /* @__PURE__ */ jsx(File.Import, {
156
- name: [getQueryHookOptions(operation)],
157
- root: file.path,
158
- path: getHookFile(operation).path
159
- });
160
- };
161
- const getMutationHookOptions = (operation) => {
162
- return getName(operation, {
163
- type: "function",
164
- suffix: "MutationOptions"
165
- });
166
- };
167
- const getMutationHookOptionsImport = (operation) => {
168
- return /* @__PURE__ */ jsx(File.Import, {
169
- name: [getMutationHookOptions(operation)],
170
- root: file.path,
171
- path: getHookFile(operation).path
172
- });
173
- };
174
- const getSuspenseHookName = (operation) => {
175
- return getName(operation, {
176
- type: "function",
177
- prefix: "use",
178
- suffix: "suspense"
179
- });
180
- };
181
- const getSuspenseHookFile = (operation) => {
182
- return getFile(operation, {
183
- prefix: "use",
184
- suffix: "suspense"
185
- });
186
- };
187
- const getSuspenseHookOptions = (operation) => {
188
- return getName(operation, {
189
- type: "function",
190
- suffix: "SuspenseQueryOptions"
191
- });
192
- };
193
- const getSuspenseHookOptionsImport = (operation) => {
194
- return /* @__PURE__ */ jsx(File.Import, {
195
- name: [getSuspenseHookOptions(operation)],
196
- root: file.path,
197
- path: getSuspenseHookFile(operation).path
198
- });
199
- };
200
- const getInfiniteHookName = (operation) => {
201
- return getName(operation, {
202
- type: "function",
203
- prefix: "use",
204
- suffix: "infinite"
205
- });
206
- };
207
- const getInfiniteHookFile = (operation) => {
208
- return getFile(operation, {
209
- prefix: "use",
210
- suffix: "infinite"
211
- });
212
- };
213
- const getInfiniteHookOptions = (operation) => {
214
- return getName(operation, {
215
- type: "function",
216
- suffix: "InfiniteQueryOptions"
217
- });
218
- };
219
- const getInfiniteHookOptionsImport = (operation) => {
220
- return /* @__PURE__ */ jsx(File.Import, {
221
- name: [getInfiniteHookOptions(operation)],
222
- root: file.path,
223
- path: getInfiniteHookFile(operation).path
224
- });
225
- };
226
- const getSuspenseInfiniteHookName = (operation) => {
227
- return getName(operation, {
228
- type: "function",
229
- prefix: "use",
230
- suffix: "suspenseInfinite"
231
- });
232
- };
233
- const getSuspenseInfiniteHookFile = (operation) => {
234
- return getFile(operation, {
235
- prefix: "use",
236
- suffix: "suspenseInfinite"
237
- });
238
- };
239
- const getSuspenseInfiniteHookOptions = (operation) => {
240
- return getName(operation, {
241
- type: "function",
242
- suffix: "SuspenseInfiniteQueryOptions"
243
- });
244
- };
245
- const getSuspenseInfiniteHookOptionsImport = (operation) => {
246
- return /* @__PURE__ */ jsx(File.Import, {
247
- name: [getSuspenseInfiniteHookOptions(operation)],
248
- root: file.path,
249
- path: getSuspenseInfiniteHookFile(operation).path
250
- });
251
- };
252
- const imports = operations.flatMap((operation) => {
253
- if (isQuery(operation)) return [
254
- getQueryHookOptionsImport(operation),
255
- isSuspense(operation) ? getSuspenseHookOptionsImport(operation) : void 0,
256
- isInfinite(operation) ? getInfiniteHookOptionsImport(operation) : void 0,
257
- isSuspense(operation) && isInfinite(operation) ? getSuspenseInfiniteHookOptionsImport(operation) : void 0
258
- ].filter(Boolean);
259
- if (isMutation(operation)) return [getMutationHookOptionsImport(operation)];
260
- return [];
261
- }).filter(Boolean);
262
- const hookOptions = operations.reduce((acc, operation) => {
263
- if (isQuery(operation)) {
264
- acc[getHookName(operation)] = `Partial<ReturnType<typeof ${getQueryHookOptions(operation)}>>`;
265
- if (isSuspense(operation)) acc[getSuspenseHookName(operation)] = `Partial<ReturnType<typeof ${getSuspenseHookOptions(operation)}>>`;
266
- if (isInfinite(operation)) acc[getInfiniteHookName(operation)] = `Partial<ReturnType<typeof ${getInfiniteHookOptions(operation)}>>`;
267
- if (isSuspense(operation) && isInfinite(operation)) acc[getSuspenseInfiniteHookName(operation)] = `Partial<ReturnType<typeof ${getSuspenseInfiniteHookOptions(operation)}>>`;
268
- }
269
- if (isMutation(operation)) acc[getHookName(operation)] = `Partial<ReturnType<typeof ${getMutationHookOptions(operation)}>>`;
270
- return acc;
271
- }, {});
272
- return /* @__PURE__ */ jsxs(File, {
273
- baseName: file.baseName,
274
- path: file.path,
275
- meta: file.meta,
276
- banner: getBanner({
277
- oas,
278
- output,
279
- config: driver.config
280
- }),
281
- footer: getFooter({
282
- oas,
283
- output
284
- }),
285
- children: [imports, /* @__PURE__ */ jsx(File.Source, {
286
- name,
287
- isExportable: true,
288
- isIndexable: true,
289
- isTypeOnly: true,
290
- children: /* @__PURE__ */ jsx(Type, {
291
- export: true,
292
- name,
293
- children: `{ ${Object.keys(hookOptions).map((key) => `${JSON.stringify(key)}: ${hookOptions[key]}`)} }`
294
- })
295
- })]
296
- });
297
- }
298
- });
299
- //#endregion
300
- //#region src/generators/infiniteQueryGenerator.tsx
301
- const infiniteQueryGenerator = createReactGenerator({
302
- name: "react-infinite-query",
303
- Operation({ config, operation, generator, plugin }) {
304
- const { options, options: { output } } = plugin;
305
- const driver = usePluginDriver();
306
- const oas = useOas();
307
- const { getSchemas, getName, getFile } = useOperationManager(generator);
308
- const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
309
- const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
310
- const infiniteOptions = options.infinite && typeof options.infinite === "object" ? options.infinite : void 0;
311
- const importPath = options.query ? options.query.importPath : "@tanstack/react-query";
312
- const query = {
313
- name: getName(operation, {
314
- type: "function",
315
- prefix: "use",
316
- suffix: "infinite"
317
- }),
318
- typeName: getName(operation, { type: "type" }),
319
- file: getFile(operation, {
320
- prefix: "use",
321
- suffix: "infinite"
322
- })
323
- };
324
- const shouldUseClientPlugin = !!driver.getPluginByName(pluginClientName) && options.client.clientType !== "class";
325
- const client = {
326
- name: shouldUseClientPlugin ? getName(operation, {
327
- type: "function",
328
- pluginName: pluginClientName
329
- }) : getName(operation, {
330
- type: "function",
331
- suffix: "infinite"
332
- }),
333
- file: getFile(operation, { pluginName: pluginClientName })
334
- };
335
- const queryOptions = { name: getName(operation, {
336
- type: "function",
337
- suffix: "InfiniteQueryOptions"
338
- }) };
339
- const queryKey = {
340
- name: getName(operation, {
341
- type: "const",
342
- suffix: "InfiniteQueryKey"
343
- }),
344
- typeName: getName(operation, {
345
- type: "type",
346
- suffix: "InfiniteQueryKey"
347
- })
348
- };
349
- const type = {
350
- file: getFile(operation, { pluginName: pluginTsName }),
351
- schemas: getSchemas(operation, {
352
- pluginName: pluginTsName,
353
- type: "type"
354
- })
355
- };
356
- const zod = {
357
- file: getFile(operation, { pluginName: pluginZodName }),
358
- schemas: getSchemas(operation, {
359
- pluginName: pluginZodName,
360
- type: "function"
361
- })
362
- };
363
- if (!isQuery || isMutation || !infiniteOptions) return null;
364
- const normalizeKey = (key) => (key ?? "").replace(/\?$/, "");
365
- const queryParam = infiniteOptions.queryParam;
366
- const cursorParam = infiniteOptions.cursorParam;
367
- const queryParamKeys = type.schemas.queryParams?.keys ?? [];
368
- const responseKeys = [...type.schemas.responses?.flatMap((item) => item.keys ?? []) ?? [], ...type.schemas.response?.keys ?? []];
369
- const hasQueryParam = queryParam ? queryParamKeys.some((key) => normalizeKey(key) === queryParam) : false;
370
- const hasCursorParam = cursorParam ? responseKeys.some((key) => normalizeKey(key) === cursorParam) : true;
371
- if (!hasQueryParam || !hasCursorParam) return null;
372
- return /* @__PURE__ */ jsxs(File, {
373
- baseName: query.file.baseName,
374
- path: query.file.path,
375
- meta: query.file.meta,
376
- banner: getBanner({
377
- oas,
378
- output,
379
- config: driver.config
380
- }),
381
- footer: getFooter({
382
- oas,
383
- output
384
- }),
385
- children: [
386
- options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, {
387
- name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
388
- root: query.file.path,
389
- path: zod.file.path
390
- }),
391
- options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
392
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
393
- name: "fetch",
394
- path: options.client.importPath
395
- }),
396
- /* @__PURE__ */ jsx(File.Import, {
397
- name: [
398
- "Client",
399
- "RequestConfig",
400
- "ResponseErrorConfig"
401
- ],
402
- path: options.client.importPath,
403
- isTypeOnly: true
404
- }),
405
- options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
406
- name: ["ResponseConfig"],
407
- path: options.client.importPath,
408
- isTypeOnly: true
409
- })
410
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
411
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
412
- name: ["fetch"],
413
- root: query.file.path,
414
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts")
415
- }),
416
- /* @__PURE__ */ jsx(File.Import, {
417
- name: [
418
- "Client",
419
- "RequestConfig",
420
- "ResponseErrorConfig"
421
- ],
422
- root: query.file.path,
423
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
424
- isTypeOnly: true
425
- }),
426
- options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
427
- name: ["ResponseConfig"],
428
- root: query.file.path,
429
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
430
- isTypeOnly: true
431
- })
432
- ] }),
433
- shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
434
- name: [client.name],
435
- root: query.file.path,
436
- path: client.file.path
437
- }),
438
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
439
- name: ["buildFormData"],
440
- root: query.file.path,
441
- path: path.resolve(config.root, config.output.path, ".kubb/config.ts")
442
- }),
443
- /* @__PURE__ */ jsx(File.Import, {
444
- name: [
445
- type.schemas.request?.name,
446
- type.schemas.response.name,
447
- type.schemas.pathParams?.name,
448
- type.schemas.queryParams?.name,
449
- type.schemas.headerParams?.name,
450
- ...type.schemas.statusCodes?.map((item) => item.name) || []
451
- ].filter(Boolean),
452
- root: query.file.path,
453
- path: type.file.path,
454
- isTypeOnly: true
455
- }),
456
- /* @__PURE__ */ jsx(QueryKey, {
457
- name: queryKey.name,
458
- typeName: queryKey.typeName,
459
- operation,
460
- paramsCasing: options.paramsCasing,
461
- pathParamsType: options.pathParamsType,
462
- typeSchemas: type.schemas,
463
- transformer: options.queryKey
464
- }),
465
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(Client, {
466
- name: client.name,
467
- baseURL: options.client.baseURL,
468
- operation,
469
- typeSchemas: type.schemas,
470
- zodSchemas: zod.schemas,
471
- dataReturnType: options.client.dataReturnType || "data",
472
- paramsCasing: options.client?.paramsCasing || options.paramsCasing,
473
- paramsType: options.paramsType,
474
- pathParamsType: options.pathParamsType,
475
- parser: options.parser
476
- }),
477
- options.customOptions && /* @__PURE__ */ jsx(File.Import, {
478
- name: [options.customOptions.name],
479
- path: options.customOptions.importPath
480
- }),
481
- infiniteOptions && /* @__PURE__ */ jsxs(Fragment, { children: [
482
- /* @__PURE__ */ jsx(File.Import, {
483
- name: ["InfiniteData"],
484
- isTypeOnly: true,
485
- path: importPath
486
- }),
487
- /* @__PURE__ */ jsx(File.Import, {
488
- name: ["infiniteQueryOptions"],
489
- path: importPath
490
- }),
491
- /* @__PURE__ */ jsx(InfiniteQueryOptions, {
492
- name: queryOptions.name,
493
- clientName: client.name,
494
- queryKeyName: queryKey.name,
495
- typeSchemas: type.schemas,
496
- paramsCasing: options.paramsCasing,
497
- paramsType: options.paramsType,
498
- pathParamsType: options.pathParamsType,
499
- dataReturnType: options.client.dataReturnType || "data",
500
- cursorParam: infiniteOptions.cursorParam,
501
- nextParam: infiniteOptions.nextParam,
502
- previousParam: infiniteOptions.previousParam,
503
- initialPageParam: infiniteOptions.initialPageParam,
504
- queryParam: infiniteOptions.queryParam
505
- })
506
- ] }),
507
- infiniteOptions && /* @__PURE__ */ jsxs(Fragment, { children: [
508
- /* @__PURE__ */ jsx(File.Import, {
509
- name: ["useInfiniteQuery"],
510
- path: importPath
511
- }),
512
- /* @__PURE__ */ jsx(File.Import, {
513
- name: [
514
- "QueryKey",
515
- "QueryClient",
516
- "InfiniteQueryObserverOptions",
517
- "UseInfiniteQueryResult"
518
- ],
519
- path: importPath,
520
- isTypeOnly: true
521
- }),
522
- /* @__PURE__ */ jsx(InfiniteQuery, {
523
- name: query.name,
524
- queryOptionsName: queryOptions.name,
525
- typeSchemas: type.schemas,
526
- paramsCasing: options.paramsCasing,
527
- paramsType: options.paramsType,
528
- pathParamsType: options.pathParamsType,
529
- operation,
530
- dataReturnType: options.client.dataReturnType || "data",
531
- queryKeyName: queryKey.name,
532
- queryKeyTypeName: queryKey.typeName,
533
- initialPageParam: infiniteOptions.initialPageParam,
534
- queryParam: infiniteOptions.queryParam,
535
- customOptions: options.customOptions
536
- })
537
- ] })
538
- ]
539
- });
540
- }
541
- });
542
- //#endregion
543
- //#region src/generators/mutationGenerator.tsx
544
- const mutationGenerator = createReactGenerator({
545
- name: "react-query",
546
- Operation({ config, plugin, operation, generator }) {
547
- const { options, options: { output } } = plugin;
548
- const driver = usePluginDriver();
549
- const oas = useOas();
550
- const { getSchemas, getName, getFile } = useOperationManager(generator);
551
- const isQuery = !!options.query && options.query?.methods.some((method) => operation.method === method);
552
- const isMutation = options.mutation !== false && !isQuery && difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
553
- const importPath = options.mutation ? options.mutation.importPath : "@tanstack/react-query";
554
- const mutation = {
555
- name: getName(operation, {
556
- type: "function",
557
- prefix: "use"
558
- }),
559
- typeName: getName(operation, { type: "type" }),
560
- file: getFile(operation, { prefix: "use" })
561
- };
562
- const type = {
563
- file: getFile(operation, { pluginName: pluginTsName }),
564
- schemas: getSchemas(operation, {
565
- pluginName: pluginTsName,
566
- type: "type"
567
- })
568
- };
569
- const zod = {
570
- file: getFile(operation, { pluginName: pluginZodName }),
571
- schemas: getSchemas(operation, {
572
- pluginName: pluginZodName,
573
- type: "function"
574
- })
575
- };
576
- const shouldUseClientPlugin = !!driver.getPluginByName(pluginClientName) && options.client.clientType !== "class";
577
- const client = {
578
- name: shouldUseClientPlugin ? getName(operation, {
579
- type: "function",
580
- pluginName: pluginClientName
581
- }) : getName(operation, { type: "function" }),
582
- file: getFile(operation, { pluginName: pluginClientName })
583
- };
584
- const mutationOptions = { name: getName(operation, {
585
- type: "function",
586
- suffix: "MutationOptions"
587
- }) };
588
- const mutationKey = {
589
- name: getName(operation, {
590
- type: "const",
591
- suffix: "MutationKey"
592
- }),
593
- typeName: getName(operation, {
594
- type: "type",
595
- suffix: "MutationKey"
596
- })
597
- };
598
- if (!isMutation) return null;
599
- return /* @__PURE__ */ jsxs(File, {
600
- baseName: mutation.file.baseName,
601
- path: mutation.file.path,
602
- meta: mutation.file.meta,
603
- banner: getBanner({
604
- oas,
605
- output,
606
- config: driver.config
607
- }),
608
- footer: getFooter({
609
- oas,
610
- output
611
- }),
612
- children: [
613
- options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, {
614
- name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
615
- root: mutation.file.path,
616
- path: zod.file.path
617
- }),
618
- options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
619
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
620
- name: "fetch",
621
- path: options.client.importPath
622
- }),
623
- /* @__PURE__ */ jsx(File.Import, {
624
- name: [
625
- "Client",
626
- "RequestConfig",
627
- "ResponseErrorConfig"
628
- ],
629
- path: options.client.importPath,
630
- isTypeOnly: true
631
- }),
632
- options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
633
- name: ["ResponseConfig"],
634
- path: options.client.importPath,
635
- isTypeOnly: true
636
- })
637
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
638
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
639
- name: ["fetch"],
640
- root: mutation.file.path,
641
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts")
642
- }),
643
- /* @__PURE__ */ jsx(File.Import, {
644
- name: [
645
- "Client",
646
- "RequestConfig",
647
- "ResponseErrorConfig"
648
- ],
649
- root: mutation.file.path,
650
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
651
- isTypeOnly: true
652
- }),
653
- options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
654
- name: ["ResponseConfig"],
655
- root: mutation.file.path,
656
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
657
- isTypeOnly: true
658
- })
659
- ] }),
660
- shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
661
- name: [client.name],
662
- root: mutation.file.path,
663
- path: client.file.path
664
- }),
665
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
666
- name: ["buildFormData"],
667
- root: mutation.file.path,
668
- path: path.resolve(config.root, config.output.path, ".kubb/config.ts")
669
- }),
670
- options.customOptions && /* @__PURE__ */ jsx(File.Import, {
671
- name: [options.customOptions.name],
672
- path: options.customOptions.importPath
673
- }),
674
- /* @__PURE__ */ jsx(File.Import, {
675
- name: [
676
- type.schemas.request?.name,
677
- type.schemas.response.name,
678
- type.schemas.pathParams?.name,
679
- type.schemas.queryParams?.name,
680
- type.schemas.headerParams?.name,
681
- ...type.schemas.statusCodes?.map((item) => item.name) || []
682
- ].filter(Boolean),
683
- root: mutation.file.path,
684
- path: type.file.path,
685
- isTypeOnly: true
686
- }),
687
- /* @__PURE__ */ jsx(MutationKey, {
688
- name: mutationKey.name,
689
- typeName: mutationKey.typeName,
690
- operation,
691
- pathParamsType: options.pathParamsType,
692
- typeSchemas: type.schemas,
693
- paramsCasing: options.paramsCasing,
694
- transformer: options.mutationKey
695
- }),
696
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(Client, {
697
- name: client.name,
698
- baseURL: options.client.baseURL,
699
- operation,
700
- typeSchemas: type.schemas,
701
- zodSchemas: zod.schemas,
702
- dataReturnType: options.client.dataReturnType || "data",
703
- paramsCasing: options.client?.paramsCasing || options.paramsCasing,
704
- paramsType: options.paramsType,
705
- pathParamsType: options.pathParamsType,
706
- parser: options.parser
707
- }),
708
- /* @__PURE__ */ jsx(File.Import, {
709
- name: ["mutationOptions"],
710
- path: importPath
711
- }),
712
- /* @__PURE__ */ jsx(MutationOptions, {
713
- name: mutationOptions.name,
714
- clientName: client.name,
715
- mutationKeyName: mutationKey.name,
716
- typeSchemas: type.schemas,
717
- paramsCasing: options.paramsCasing,
718
- paramsType: options.paramsType,
719
- pathParamsType: options.pathParamsType,
720
- dataReturnType: options.client.dataReturnType || "data"
721
- }),
722
- options.mutation && /* @__PURE__ */ jsxs(Fragment, { children: [
723
- /* @__PURE__ */ jsx(File.Import, {
724
- name: ["useMutation"],
725
- path: importPath
726
- }),
727
- /* @__PURE__ */ jsx(File.Import, {
728
- name: [
729
- "UseMutationOptions",
730
- "UseMutationResult",
731
- "QueryClient"
732
- ],
733
- path: importPath,
734
- isTypeOnly: true
735
- }),
736
- /* @__PURE__ */ jsx(Mutation, {
737
- name: mutation.name,
738
- mutationOptionsName: mutationOptions.name,
739
- typeName: mutation.typeName,
740
- typeSchemas: type.schemas,
741
- operation,
742
- dataReturnType: options.client.dataReturnType || "data",
743
- paramsCasing: options.paramsCasing,
744
- pathParamsType: options.pathParamsType,
745
- mutationKeyName: mutationKey.name,
746
- customOptions: options.customOptions
747
- })
748
- ] })
749
- ]
750
- });
751
- }
752
- });
753
- //#endregion
754
- //#region src/generators/queryGenerator.tsx
755
- const queryGenerator = createReactGenerator({
756
- name: "react-query",
757
- Operation({ config, plugin, operation, generator }) {
758
- const { options, options: { output } } = plugin;
759
- const driver = usePluginDriver();
760
- const oas = useOas();
761
- const { getSchemas, getName, getFile } = useOperationManager(generator);
762
- const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
763
- const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
764
- const importPath = options.query ? options.query.importPath : "@tanstack/react-query";
765
- const query = {
766
- name: getName(operation, {
767
- type: "function",
768
- prefix: "use"
769
- }),
770
- typeName: getName(operation, { type: "type" }),
771
- file: getFile(operation, { prefix: "use" })
772
- };
773
- const shouldUseClientPlugin = !!driver.getPluginByName(pluginClientName) && options.client.clientType !== "class";
774
- const client = {
775
- name: shouldUseClientPlugin ? getName(operation, {
776
- type: "function",
777
- pluginName: pluginClientName
778
- }) : getName(operation, { type: "function" }),
779
- file: getFile(operation, { pluginName: pluginClientName })
780
- };
781
- const queryOptions = { name: getName(operation, {
782
- type: "function",
783
- suffix: "QueryOptions"
784
- }) };
785
- const queryKey = {
786
- name: getName(operation, {
787
- type: "const",
788
- suffix: "QueryKey"
789
- }),
790
- typeName: getName(operation, {
791
- type: "type",
792
- suffix: "QueryKey"
793
- })
794
- };
795
- const type = {
796
- file: getFile(operation, { pluginName: pluginTsName }),
797
- schemas: getSchemas(operation, {
798
- pluginName: pluginTsName,
799
- type: "type"
800
- })
801
- };
802
- const zod = {
803
- file: getFile(operation, { pluginName: pluginZodName }),
804
- schemas: getSchemas(operation, {
805
- pluginName: pluginZodName,
806
- type: "function"
807
- })
808
- };
809
- if (!isQuery || isMutation) return null;
810
- return /* @__PURE__ */ jsxs(File, {
811
- baseName: query.file.baseName,
812
- path: query.file.path,
813
- meta: query.file.meta,
814
- banner: getBanner({
815
- oas,
816
- output,
817
- config: driver.config
818
- }),
819
- footer: getFooter({
820
- oas,
821
- output
822
- }),
823
- children: [
824
- options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, {
825
- name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
826
- root: query.file.path,
827
- path: zod.file.path
828
- }),
829
- options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
830
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
831
- name: "fetch",
832
- path: options.client.importPath
833
- }),
834
- /* @__PURE__ */ jsx(File.Import, {
835
- name: [
836
- "Client",
837
- "RequestConfig",
838
- "ResponseErrorConfig"
839
- ],
840
- path: options.client.importPath,
841
- isTypeOnly: true
842
- }),
843
- options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
844
- name: ["ResponseConfig"],
845
- path: options.client.importPath,
846
- isTypeOnly: true
847
- })
848
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
849
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
850
- name: ["fetch"],
851
- root: query.file.path,
852
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts")
853
- }),
854
- /* @__PURE__ */ jsx(File.Import, {
855
- name: [
856
- "Client",
857
- "RequestConfig",
858
- "ResponseErrorConfig"
859
- ],
860
- root: query.file.path,
861
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
862
- isTypeOnly: true
863
- }),
864
- options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
865
- name: ["ResponseConfig"],
866
- root: query.file.path,
867
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
868
- isTypeOnly: true
869
- })
870
- ] }),
871
- shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
872
- name: [client.name],
873
- root: query.file.path,
874
- path: client.file.path
875
- }),
876
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
877
- name: ["buildFormData"],
878
- root: query.file.path,
879
- path: path.resolve(config.root, config.output.path, ".kubb/config.ts")
880
- }),
881
- options.customOptions && /* @__PURE__ */ jsx(File.Import, {
882
- name: [options.customOptions.name],
883
- path: options.customOptions.importPath
884
- }),
885
- /* @__PURE__ */ jsx(File.Import, {
886
- name: [
887
- type.schemas.request?.name,
888
- type.schemas.response.name,
889
- type.schemas.pathParams?.name,
890
- type.schemas.queryParams?.name,
891
- type.schemas.headerParams?.name,
892
- ...type.schemas.statusCodes?.map((item) => item.name) || []
893
- ].filter(Boolean),
894
- root: query.file.path,
895
- path: type.file.path,
896
- isTypeOnly: true
897
- }),
898
- /* @__PURE__ */ jsx(QueryKey, {
899
- name: queryKey.name,
900
- typeName: queryKey.typeName,
901
- operation,
902
- pathParamsType: options.pathParamsType,
903
- typeSchemas: type.schemas,
904
- paramsCasing: options.paramsCasing,
905
- transformer: options.queryKey
906
- }),
907
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(Client, {
908
- name: client.name,
909
- baseURL: options.client.baseURL,
910
- operation,
911
- typeSchemas: type.schemas,
912
- zodSchemas: zod.schemas,
913
- dataReturnType: options.client.dataReturnType || "data",
914
- paramsType: options.paramsType,
915
- paramsCasing: options.client?.paramsCasing || options.paramsCasing,
916
- pathParamsType: options.pathParamsType,
917
- parser: options.parser
918
- }),
919
- /* @__PURE__ */ jsx(File.Import, {
920
- name: ["queryOptions"],
921
- path: importPath
922
- }),
923
- /* @__PURE__ */ jsx(QueryOptions, {
924
- name: queryOptions.name,
925
- clientName: client.name,
926
- queryKeyName: queryKey.name,
927
- typeSchemas: type.schemas,
928
- paramsCasing: options.paramsCasing,
929
- paramsType: options.paramsType,
930
- pathParamsType: options.pathParamsType,
931
- dataReturnType: options.client.dataReturnType || "data"
932
- }),
933
- options.query && /* @__PURE__ */ jsxs(Fragment, { children: [
934
- /* @__PURE__ */ jsx(File.Import, {
935
- name: ["useQuery"],
936
- path: importPath
937
- }),
938
- /* @__PURE__ */ jsx(File.Import, {
939
- name: [
940
- "QueryKey",
941
- "QueryClient",
942
- "QueryObserverOptions",
943
- "UseQueryResult",
944
- "QueryClient"
945
- ],
946
- path: importPath,
947
- isTypeOnly: true
948
- }),
949
- /* @__PURE__ */ jsx(Query, {
950
- name: query.name,
951
- queryOptionsName: queryOptions.name,
952
- typeSchemas: type.schemas,
953
- paramsCasing: options.paramsCasing,
954
- paramsType: options.paramsType,
955
- pathParamsType: options.pathParamsType,
956
- operation,
957
- dataReturnType: options.client.dataReturnType || "data",
958
- queryKeyName: queryKey.name,
959
- queryKeyTypeName: queryKey.typeName,
960
- customOptions: options.customOptions
961
- })
962
- ] })
963
- ]
964
- });
965
- }
966
- });
967
- //#endregion
968
- //#region src/generators/suspenseInfiniteQueryGenerator.tsx
969
- const suspenseInfiniteQueryGenerator = createReactGenerator({
970
- name: "react-suspense-infinite-query",
971
- Operation({ config, operation, generator, plugin }) {
972
- const { options, options: { output } } = plugin;
973
- const driver = usePluginDriver();
974
- const oas = useOas();
975
- const { getSchemas, getName, getFile } = useOperationManager(generator);
976
- const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
977
- const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
978
- const isSuspense = !!options.suspense;
979
- const infiniteOptions = options.infinite && typeof options.infinite === "object" ? options.infinite : void 0;
980
- const importPath = options.query ? options.query.importPath : "@tanstack/react-query";
981
- const query = {
982
- name: getName(operation, {
983
- type: "function",
984
- prefix: "use",
985
- suffix: "suspenseInfinite"
986
- }),
987
- typeName: getName(operation, { type: "type" }),
988
- file: getFile(operation, {
989
- prefix: "use",
990
- suffix: "suspenseInfinite"
991
- })
992
- };
993
- const shouldUseClientPlugin = !!driver.getPluginByName(pluginClientName) && options.client.clientType !== "class";
994
- const client = {
995
- name: shouldUseClientPlugin ? getName(operation, {
996
- type: "function",
997
- pluginName: pluginClientName
998
- }) : getName(operation, {
999
- type: "function",
1000
- suffix: "suspenseInfinite"
1001
- }),
1002
- file: getFile(operation, { pluginName: pluginClientName })
1003
- };
1004
- const queryOptions = { name: getName(operation, {
1005
- type: "function",
1006
- suffix: "SuspenseInfiniteQueryOptions"
1007
- }) };
1008
- const queryKey = {
1009
- name: getName(operation, {
1010
- type: "const",
1011
- suffix: "SuspenseInfiniteQueryKey"
1012
- }),
1013
- typeName: getName(operation, {
1014
- type: "type",
1015
- suffix: "SuspenseInfiniteQueryKey"
1016
- })
1017
- };
1018
- const type = {
1019
- file: getFile(operation, { pluginName: pluginTsName }),
1020
- schemas: getSchemas(operation, {
1021
- pluginName: pluginTsName,
1022
- type: "type"
1023
- })
1024
- };
1025
- const zod = {
1026
- file: getFile(operation, { pluginName: pluginZodName }),
1027
- schemas: getSchemas(operation, {
1028
- pluginName: pluginZodName,
1029
- type: "function"
1030
- })
1031
- };
1032
- if (!isQuery || isMutation || !isSuspense || !infiniteOptions) return null;
1033
- return /* @__PURE__ */ jsxs(File, {
1034
- baseName: query.file.baseName,
1035
- path: query.file.path,
1036
- meta: query.file.meta,
1037
- banner: getBanner({
1038
- oas,
1039
- output,
1040
- config: driver.config
1041
- }),
1042
- footer: getFooter({
1043
- oas,
1044
- output
1045
- }),
1046
- children: [
1047
- options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, {
1048
- name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
1049
- root: query.file.path,
1050
- path: zod.file.path
1051
- }),
1052
- options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
1053
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
1054
- name: "fetch",
1055
- path: options.client.importPath
1056
- }),
1057
- /* @__PURE__ */ jsx(File.Import, {
1058
- name: [
1059
- "Client",
1060
- "RequestConfig",
1061
- "ResponseErrorConfig"
1062
- ],
1063
- path: options.client.importPath,
1064
- isTypeOnly: true
1065
- }),
1066
- options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
1067
- name: ["ResponseConfig"],
1068
- path: options.client.importPath,
1069
- isTypeOnly: true
1070
- })
1071
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1072
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
1073
- name: ["fetch"],
1074
- root: query.file.path,
1075
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts")
1076
- }),
1077
- /* @__PURE__ */ jsx(File.Import, {
1078
- name: [
1079
- "Client",
1080
- "RequestConfig",
1081
- "ResponseErrorConfig"
1082
- ],
1083
- root: query.file.path,
1084
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
1085
- isTypeOnly: true
1086
- }),
1087
- options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
1088
- name: ["ResponseConfig"],
1089
- root: query.file.path,
1090
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
1091
- isTypeOnly: true
1092
- })
1093
- ] }),
1094
- shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
1095
- name: [client.name],
1096
- root: query.file.path,
1097
- path: client.file.path
1098
- }),
1099
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
1100
- name: ["buildFormData"],
1101
- root: query.file.path,
1102
- path: path.resolve(config.root, config.output.path, ".kubb/config.ts")
1103
- }),
1104
- options.customOptions && /* @__PURE__ */ jsx(File.Import, {
1105
- name: [options.customOptions.name],
1106
- path: options.customOptions.importPath
1107
- }),
1108
- /* @__PURE__ */ jsx(File.Import, {
1109
- name: [
1110
- type.schemas.request?.name,
1111
- type.schemas.response.name,
1112
- type.schemas.pathParams?.name,
1113
- type.schemas.queryParams?.name,
1114
- type.schemas.headerParams?.name,
1115
- ...type.schemas.statusCodes?.map((item) => item.name) || []
1116
- ].filter(Boolean),
1117
- root: query.file.path,
1118
- path: type.file.path,
1119
- isTypeOnly: true
1120
- }),
1121
- /* @__PURE__ */ jsx(QueryKey, {
1122
- name: queryKey.name,
1123
- typeName: queryKey.typeName,
1124
- operation,
1125
- paramsCasing: options.paramsCasing,
1126
- pathParamsType: options.pathParamsType,
1127
- typeSchemas: type.schemas,
1128
- transformer: options.queryKey
1129
- }),
1130
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(Client, {
1131
- name: client.name,
1132
- baseURL: options.client.baseURL,
1133
- operation,
1134
- typeSchemas: type.schemas,
1135
- zodSchemas: zod.schemas,
1136
- dataReturnType: options.client.dataReturnType || "data",
1137
- paramsCasing: options.client?.paramsCasing || options.paramsCasing,
1138
- paramsType: options.paramsType,
1139
- pathParamsType: options.pathParamsType,
1140
- parser: options.parser
1141
- }),
1142
- infiniteOptions && /* @__PURE__ */ jsxs(Fragment, { children: [
1143
- /* @__PURE__ */ jsx(File.Import, {
1144
- name: ["InfiniteData"],
1145
- isTypeOnly: true,
1146
- path: importPath
1147
- }),
1148
- /* @__PURE__ */ jsx(File.Import, {
1149
- name: ["infiniteQueryOptions"],
1150
- path: importPath
1151
- }),
1152
- /* @__PURE__ */ jsx(SuspenseInfiniteQueryOptions, {
1153
- name: queryOptions.name,
1154
- clientName: client.name,
1155
- queryKeyName: queryKey.name,
1156
- typeSchemas: type.schemas,
1157
- paramsCasing: options.paramsCasing,
1158
- paramsType: options.paramsType,
1159
- pathParamsType: options.pathParamsType,
1160
- dataReturnType: options.client.dataReturnType || "data",
1161
- cursorParam: infiniteOptions.cursorParam,
1162
- nextParam: infiniteOptions.nextParam,
1163
- previousParam: infiniteOptions.previousParam,
1164
- initialPageParam: infiniteOptions.initialPageParam,
1165
- queryParam: infiniteOptions.queryParam
1166
- })
1167
- ] }),
1168
- infiniteOptions && /* @__PURE__ */ jsxs(Fragment, { children: [
1169
- /* @__PURE__ */ jsx(File.Import, {
1170
- name: ["useSuspenseInfiniteQuery"],
1171
- path: importPath
1172
- }),
1173
- /* @__PURE__ */ jsx(File.Import, {
1174
- name: [
1175
- "QueryKey",
1176
- "QueryClient",
1177
- "UseSuspenseInfiniteQueryOptions",
1178
- "UseSuspenseInfiniteQueryResult"
1179
- ],
1180
- path: importPath,
1181
- isTypeOnly: true
1182
- }),
1183
- /* @__PURE__ */ jsx(SuspenseInfiniteQuery, {
1184
- name: query.name,
1185
- queryOptionsName: queryOptions.name,
1186
- typeSchemas: type.schemas,
1187
- paramsCasing: options.paramsCasing,
1188
- paramsType: options.paramsType,
1189
- pathParamsType: options.pathParamsType,
1190
- operation,
1191
- dataReturnType: options.client.dataReturnType || "data",
1192
- queryKeyName: queryKey.name,
1193
- queryKeyTypeName: queryKey.typeName,
1194
- customOptions: options.customOptions,
1195
- initialPageParam: infiniteOptions.initialPageParam,
1196
- queryParam: infiniteOptions.queryParam
1197
- })
1198
- ] })
1199
- ]
1200
- });
1201
- }
1202
- });
1203
- //#endregion
1204
- //#region src/generators/suspenseQueryGenerator.tsx
1205
- const suspenseQueryGenerator = createReactGenerator({
1206
- name: "react-suspense-query",
1207
- Operation({ config, operation, generator, plugin }) {
1208
- const { options, options: { output } } = plugin;
1209
- const driver = usePluginDriver();
1210
- const oas = useOas();
1211
- const { getSchemas, getName, getFile } = useOperationManager(generator);
1212
- const isQuery = typeof options.query === "boolean" ? true : options.query?.methods.some((method) => operation.method === method);
1213
- const isMutation = difference(options.mutation ? options.mutation.methods : [], options.query ? options.query.methods : []).some((method) => operation.method === method);
1214
- const isSuspense = !!options.suspense;
1215
- const importPath = options.query ? options.query.importPath : "@tanstack/react-query";
1216
- const query = {
1217
- name: getName(operation, {
1218
- type: "function",
1219
- prefix: "use",
1220
- suffix: "suspense"
1221
- }),
1222
- typeName: getName(operation, { type: "type" }),
1223
- file: getFile(operation, {
1224
- prefix: "use",
1225
- suffix: "suspense"
1226
- })
1227
- };
1228
- const shouldUseClientPlugin = !!driver.getPluginByName(pluginClientName) && options.client.clientType !== "class";
1229
- const client = {
1230
- name: shouldUseClientPlugin ? getName(operation, {
1231
- type: "function",
1232
- pluginName: pluginClientName
1233
- }) : getName(operation, {
1234
- type: "function",
1235
- suffix: "suspense"
1236
- }),
1237
- file: getFile(operation, { pluginName: pluginClientName })
1238
- };
1239
- const queryOptions = { name: getName(operation, {
1240
- type: "function",
1241
- suffix: "SuspenseQueryOptions"
1242
- }) };
1243
- const queryKey = {
1244
- name: getName(operation, {
1245
- type: "const",
1246
- suffix: "SuspenseQueryKey"
1247
- }),
1248
- typeName: getName(operation, {
1249
- type: "type",
1250
- suffix: "SuspenseQueryKey"
1251
- })
1252
- };
1253
- const type = {
1254
- file: getFile(operation, { pluginName: pluginTsName }),
1255
- schemas: getSchemas(operation, {
1256
- pluginName: pluginTsName,
1257
- type: "type"
1258
- })
1259
- };
1260
- const zod = {
1261
- file: getFile(operation, { pluginName: pluginZodName }),
1262
- schemas: getSchemas(operation, {
1263
- pluginName: pluginZodName,
1264
- type: "function"
1265
- })
1266
- };
1267
- if (!isQuery || isMutation || !isSuspense) return null;
1268
- return /* @__PURE__ */ jsxs(File, {
1269
- baseName: query.file.baseName,
1270
- path: query.file.path,
1271
- meta: query.file.meta,
1272
- banner: getBanner({
1273
- oas,
1274
- output,
1275
- config: driver.config
1276
- }),
1277
- footer: getFooter({
1278
- oas,
1279
- output
1280
- }),
1281
- children: [
1282
- options.parser === "zod" && /* @__PURE__ */ jsx(File.Import, {
1283
- name: [zod.schemas.response.name, zod.schemas.request?.name].filter(Boolean),
1284
- root: query.file.path,
1285
- path: zod.file.path
1286
- }),
1287
- options.client.importPath ? /* @__PURE__ */ jsxs(Fragment, { children: [
1288
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
1289
- name: "fetch",
1290
- path: options.client.importPath
1291
- }),
1292
- /* @__PURE__ */ jsx(File.Import, {
1293
- name: [
1294
- "Client",
1295
- "RequestConfig",
1296
- "ResponseErrorConfig"
1297
- ],
1298
- path: options.client.importPath,
1299
- isTypeOnly: true
1300
- }),
1301
- options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
1302
- name: ["ResponseConfig"],
1303
- path: options.client.importPath,
1304
- isTypeOnly: true
1305
- })
1306
- ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [
1307
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
1308
- name: ["fetch"],
1309
- root: query.file.path,
1310
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts")
1311
- }),
1312
- /* @__PURE__ */ jsx(File.Import, {
1313
- name: [
1314
- "Client",
1315
- "RequestConfig",
1316
- "ResponseErrorConfig"
1317
- ],
1318
- root: query.file.path,
1319
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
1320
- isTypeOnly: true
1321
- }),
1322
- options.client.dataReturnType === "full" && /* @__PURE__ */ jsx(File.Import, {
1323
- name: ["ResponseConfig"],
1324
- root: query.file.path,
1325
- path: path.resolve(config.root, config.output.path, ".kubb/fetch.ts"),
1326
- isTypeOnly: true
1327
- })
1328
- ] }),
1329
- shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
1330
- name: [client.name],
1331
- root: query.file.path,
1332
- path: client.file.path
1333
- }),
1334
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(File.Import, {
1335
- name: ["buildFormData"],
1336
- root: query.file.path,
1337
- path: path.resolve(config.root, config.output.path, ".kubb/config.ts")
1338
- }),
1339
- options.customOptions && /* @__PURE__ */ jsx(File.Import, {
1340
- name: [options.customOptions.name],
1341
- path: options.customOptions.importPath
1342
- }),
1343
- /* @__PURE__ */ jsx(File.Import, {
1344
- name: [
1345
- type.schemas.request?.name,
1346
- type.schemas.response.name,
1347
- type.schemas.pathParams?.name,
1348
- type.schemas.queryParams?.name,
1349
- type.schemas.headerParams?.name,
1350
- ...type.schemas.statusCodes?.map((item) => item.name) || []
1351
- ].filter(Boolean),
1352
- root: query.file.path,
1353
- path: type.file.path,
1354
- isTypeOnly: true
1355
- }),
1356
- /* @__PURE__ */ jsx(QueryKey, {
1357
- name: queryKey.name,
1358
- typeName: queryKey.typeName,
1359
- operation,
1360
- paramsCasing: options.paramsCasing,
1361
- pathParamsType: options.pathParamsType,
1362
- typeSchemas: type.schemas,
1363
- transformer: options.queryKey
1364
- }),
1365
- !shouldUseClientPlugin && /* @__PURE__ */ jsx(Client, {
1366
- name: client.name,
1367
- baseURL: options.client.baseURL,
1368
- operation,
1369
- typeSchemas: type.schemas,
1370
- zodSchemas: zod.schemas,
1371
- dataReturnType: options.client.dataReturnType || "data",
1372
- paramsCasing: options.client?.paramsCasing || options.paramsCasing,
1373
- paramsType: options.paramsType,
1374
- pathParamsType: options.pathParamsType,
1375
- parser: options.parser
1376
- }),
1377
- /* @__PURE__ */ jsx(File.Import, {
1378
- name: ["queryOptions"],
1379
- path: importPath
1380
- }),
1381
- /* @__PURE__ */ jsx(QueryOptions, {
1382
- name: queryOptions.name,
1383
- clientName: client.name,
1384
- queryKeyName: queryKey.name,
1385
- typeSchemas: type.schemas,
1386
- paramsCasing: options.paramsCasing,
1387
- paramsType: options.paramsType,
1388
- pathParamsType: options.pathParamsType,
1389
- dataReturnType: options.client.dataReturnType
1390
- }),
1391
- options.suspense && /* @__PURE__ */ jsxs(Fragment, { children: [
1392
- /* @__PURE__ */ jsx(File.Import, {
1393
- name: ["useSuspenseQuery"],
1394
- path: importPath
1395
- }),
1396
- /* @__PURE__ */ jsx(File.Import, {
1397
- name: [
1398
- "QueryKey",
1399
- "QueryClient",
1400
- "UseSuspenseQueryOptions",
1401
- "UseSuspenseQueryResult"
1402
- ],
1403
- path: importPath,
1404
- isTypeOnly: true
1405
- }),
1406
- /* @__PURE__ */ jsx(SuspenseQuery, {
1407
- name: query.name,
1408
- queryOptionsName: queryOptions.name,
1409
- typeSchemas: type.schemas,
1410
- paramsType: options.paramsType,
1411
- paramsCasing: options.paramsCasing,
1412
- pathParamsType: options.pathParamsType,
1413
- operation,
1414
- dataReturnType: options.client.dataReturnType || "data",
1415
- queryKeyName: queryKey.name,
1416
- queryKeyTypeName: queryKey.typeName,
1417
- customOptions: options.customOptions
1418
- })
1419
- ] })
1420
- ]
1421
- });
1422
- }
1423
- });
1424
- //#endregion
1425
- export { infiniteQueryGenerator as a, mutationGenerator as i, suspenseInfiniteQueryGenerator as n, hookOptionsGenerator as o, queryGenerator as r, customHookOptionsFileGenerator as s, suspenseQueryGenerator as t };
1426
-
1427
- //# sourceMappingURL=generators-DkQwKTc2.js.map