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