@kubb/plugin-react-query 5.0.0-beta.64 → 5.0.0-beta.73

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