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

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