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

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (54) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +34 -85
  3. package/dist/components-Dow6tde8.js +1459 -0
  4. package/dist/components-Dow6tde8.js.map +1 -0
  5. package/dist/components-HwdCDefj.cjs +1603 -0
  6. package/dist/components-HwdCDefj.cjs.map +1 -0
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +49 -179
  9. package/dist/components.js +1 -1
  10. package/dist/generators-CcOmnTPa.cjs +1454 -0
  11. package/dist/generators-CcOmnTPa.cjs.map +1 -0
  12. package/dist/generators-yfZr_qfT.js +1412 -0
  13. package/dist/generators-yfZr_qfT.js.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +9 -505
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +197 -126
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +193 -126
  21. package/dist/index.js.map +1 -1
  22. package/dist/types-DG_OxOym.d.ts +363 -0
  23. package/extension.yaml +911 -0
  24. package/package.json +59 -64
  25. package/src/components/InfiniteQuery.tsx +79 -138
  26. package/src/components/InfiniteQueryOptions.tsx +55 -166
  27. package/src/components/Mutation.tsx +74 -111
  28. package/src/components/MutationOptions.tsx +61 -80
  29. package/src/components/Query.tsx +66 -142
  30. package/src/components/QueryOptions.tsx +56 -138
  31. package/src/components/SuspenseInfiniteQuery.tsx +79 -138
  32. package/src/components/SuspenseInfiniteQueryOptions.tsx +55 -166
  33. package/src/components/SuspenseQuery.tsx +66 -152
  34. package/src/generators/customHookOptionsFileGenerator.tsx +37 -51
  35. package/src/generators/hookOptionsGenerator.tsx +111 -174
  36. package/src/generators/infiniteQueryGenerator.tsx +158 -178
  37. package/src/generators/mutationGenerator.tsx +112 -139
  38. package/src/generators/queryGenerator.tsx +128 -142
  39. package/src/generators/suspenseInfiniteQueryGenerator.tsx +157 -156
  40. package/src/generators/suspenseQueryGenerator.tsx +126 -152
  41. package/src/index.ts +1 -1
  42. package/src/plugin.ts +134 -187
  43. package/src/resolvers/resolverReactQuery.ts +107 -0
  44. package/src/types.ts +172 -49
  45. package/src/utils.ts +10 -0
  46. package/dist/components-BHQT9ZLc.cjs +0 -1634
  47. package/dist/components-BHQT9ZLc.cjs.map +0 -1
  48. package/dist/components-CpyHYGOw.js +0 -1520
  49. package/dist/components-CpyHYGOw.js.map +0 -1
  50. package/dist/generators-DP07m3rH.cjs +0 -1469
  51. package/dist/generators-DP07m3rH.cjs.map +0 -1
  52. package/dist/generators-DkQwKTc2.js +0 -1427
  53. package/dist/generators-DkQwKTc2.js.map +0 -1
  54. package/dist/types-D5S7Ny9r.d.ts +0 -270
@@ -0,0 +1,1603 @@
1
+ //#region \0rolldown/runtime.js
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __name = (target, value) => __defProp(target, "name", {
5
+ value,
6
+ configurable: true
7
+ });
8
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
+ var __getOwnPropNames = Object.getOwnPropertyNames;
10
+ var __getProtoOf = Object.getPrototypeOf;
11
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
14
+ key = keys[i];
15
+ if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
16
+ get: ((k) => from[k]).bind(null, key),
17
+ enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
18
+ });
19
+ }
20
+ return to;
21
+ };
22
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
23
+ value: mod,
24
+ enumerable: true
25
+ }) : target, mod));
26
+ //#endregion
27
+ let _kubb_core = require("@kubb/core");
28
+ let _kubb_plugin_ts = require("@kubb/plugin-ts");
29
+ let _kubb_renderer_jsx = require("@kubb/renderer-jsx");
30
+ let _kubb_renderer_jsx_jsx_runtime = require("@kubb/renderer-jsx/jsx-runtime");
31
+ //#region ../../internals/utils/src/casing.ts
32
+ /**
33
+ * Shared implementation for camelCase and PascalCase conversion.
34
+ * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
35
+ * and capitalizes each word according to `pascal`.
36
+ *
37
+ * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
38
+ */
39
+ function toCamelOrPascal(text, pascal) {
40
+ return text.trim().replace(/([a-z\d])([A-Z])/g, "$1 $2").replace(/([A-Z]+)([A-Z][a-z])/g, "$1 $2").replace(/(\d)([a-z])/g, "$1 $2").split(/[\s\-_./\\:]+/).filter(Boolean).map((word, i) => {
41
+ if (word.length > 1 && word === word.toUpperCase()) return word;
42
+ if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
43
+ return word.charAt(0).toUpperCase() + word.slice(1);
44
+ }).join("").replace(/[^a-zA-Z0-9]/g, "");
45
+ }
46
+ /**
47
+ * Splits `text` on `.` and applies `transformPart` to each segment.
48
+ * The last segment receives `isLast = true`, all earlier segments receive `false`.
49
+ * Segments are joined with `/` to form a file path.
50
+ *
51
+ * Only splits on dots followed by a letter so that version numbers
52
+ * embedded in operationIds (e.g. `v2025.0`) are kept intact.
53
+ */
54
+ function applyToFileParts(text, transformPart) {
55
+ const parts = text.split(/\.(?=[a-zA-Z])/);
56
+ return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
57
+ }
58
+ /**
59
+ * Converts `text` to camelCase.
60
+ * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
61
+ *
62
+ * @example
63
+ * camelCase('hello-world') // 'helloWorld'
64
+ * camelCase('pet.petId', { isFile: true }) // 'pet/petId'
65
+ */
66
+ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
67
+ if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
68
+ prefix,
69
+ suffix
70
+ } : {}));
71
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
72
+ }
73
+ //#endregion
74
+ //#region ../../internals/utils/src/object.ts
75
+ /**
76
+ * Converts a dot-notation path or string array into an optional-chaining accessor expression.
77
+ *
78
+ * @example
79
+ * getNestedAccessor('pagination.next.id', 'lastPage')
80
+ * // → "lastPage?.['pagination']?.['next']?.['id']"
81
+ */
82
+ function getNestedAccessor(param, accessor) {
83
+ const parts = Array.isArray(param) ? param : param.split(".");
84
+ if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
85
+ return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
86
+ }
87
+ //#endregion
88
+ //#region ../../internals/utils/src/reserved.ts
89
+ /**
90
+ * JavaScript and Java reserved words.
91
+ * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
92
+ */
93
+ const reservedWords = new Set([
94
+ "abstract",
95
+ "arguments",
96
+ "boolean",
97
+ "break",
98
+ "byte",
99
+ "case",
100
+ "catch",
101
+ "char",
102
+ "class",
103
+ "const",
104
+ "continue",
105
+ "debugger",
106
+ "default",
107
+ "delete",
108
+ "do",
109
+ "double",
110
+ "else",
111
+ "enum",
112
+ "eval",
113
+ "export",
114
+ "extends",
115
+ "false",
116
+ "final",
117
+ "finally",
118
+ "float",
119
+ "for",
120
+ "function",
121
+ "goto",
122
+ "if",
123
+ "implements",
124
+ "import",
125
+ "in",
126
+ "instanceof",
127
+ "int",
128
+ "interface",
129
+ "let",
130
+ "long",
131
+ "native",
132
+ "new",
133
+ "null",
134
+ "package",
135
+ "private",
136
+ "protected",
137
+ "public",
138
+ "return",
139
+ "short",
140
+ "static",
141
+ "super",
142
+ "switch",
143
+ "synchronized",
144
+ "this",
145
+ "throw",
146
+ "throws",
147
+ "transient",
148
+ "true",
149
+ "try",
150
+ "typeof",
151
+ "var",
152
+ "void",
153
+ "volatile",
154
+ "while",
155
+ "with",
156
+ "yield",
157
+ "Array",
158
+ "Date",
159
+ "hasOwnProperty",
160
+ "Infinity",
161
+ "isFinite",
162
+ "isNaN",
163
+ "isPrototypeOf",
164
+ "length",
165
+ "Math",
166
+ "name",
167
+ "NaN",
168
+ "Number",
169
+ "Object",
170
+ "prototype",
171
+ "String",
172
+ "toString",
173
+ "undefined",
174
+ "valueOf"
175
+ ]);
176
+ /**
177
+ * Returns `true` when `name` is a syntactically valid JavaScript variable name.
178
+ *
179
+ * @example
180
+ * ```ts
181
+ * isValidVarName('status') // true
182
+ * isValidVarName('class') // false (reserved word)
183
+ * isValidVarName('42foo') // false (starts with digit)
184
+ * ```
185
+ */
186
+ function isValidVarName(name) {
187
+ if (!name || reservedWords.has(name)) return false;
188
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
189
+ }
190
+ //#endregion
191
+ //#region ../../internals/utils/src/urlPath.ts
192
+ /**
193
+ * Parses and transforms an OpenAPI/Swagger path string into various URL formats.
194
+ *
195
+ * @example
196
+ * const p = new URLPath('/pet/{petId}')
197
+ * p.URL // '/pet/:petId'
198
+ * p.template // '`/pet/${petId}`'
199
+ */
200
+ var URLPath = class {
201
+ /**
202
+ * The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
203
+ */
204
+ path;
205
+ #options;
206
+ constructor(path, options = {}) {
207
+ this.path = path;
208
+ this.#options = options;
209
+ }
210
+ /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
211
+ *
212
+ * @example
213
+ * ```ts
214
+ * new URLPath('/pet/{petId}').URL // '/pet/:petId'
215
+ * ```
216
+ */
217
+ get URL() {
218
+ return this.toURLPath();
219
+ }
220
+ /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
221
+ *
222
+ * @example
223
+ * ```ts
224
+ * new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
225
+ * new URLPath('/pet/{petId}').isURL // false
226
+ * ```
227
+ */
228
+ get isURL() {
229
+ try {
230
+ return !!new URL(this.path).href;
231
+ } catch {
232
+ return false;
233
+ }
234
+ }
235
+ /**
236
+ * Converts the OpenAPI path to a TypeScript template literal string.
237
+ *
238
+ * @example
239
+ * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
240
+ * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
241
+ */
242
+ get template() {
243
+ return this.toTemplateString();
244
+ }
245
+ /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
246
+ *
247
+ * @example
248
+ * ```ts
249
+ * new URLPath('/pet/{petId}').object
250
+ * // { url: '/pet/:petId', params: { petId: 'petId' } }
251
+ * ```
252
+ */
253
+ get object() {
254
+ return this.toObject();
255
+ }
256
+ /** Returns a map of path parameter names, or `undefined` when the path has no parameters.
257
+ *
258
+ * @example
259
+ * ```ts
260
+ * new URLPath('/pet/{petId}').params // { petId: 'petId' }
261
+ * new URLPath('/pet').params // undefined
262
+ * ```
263
+ */
264
+ get params() {
265
+ return this.toParamsObject();
266
+ }
267
+ #transformParam(raw) {
268
+ const param = isValidVarName(raw) ? raw : camelCase(raw);
269
+ return this.#options.casing === "camelcase" ? camelCase(param) : param;
270
+ }
271
+ /**
272
+ * Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
273
+ */
274
+ #eachParam(fn) {
275
+ for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
276
+ const raw = match[1];
277
+ fn(raw, this.#transformParam(raw));
278
+ }
279
+ }
280
+ toObject({ type = "path", replacer, stringify } = {}) {
281
+ const object = {
282
+ url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
283
+ params: this.toParamsObject()
284
+ };
285
+ if (stringify) {
286
+ if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
287
+ if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
288
+ return `{ url: '${object.url}' }`;
289
+ }
290
+ return object;
291
+ }
292
+ /**
293
+ * Converts the OpenAPI path to a TypeScript template literal string.
294
+ * An optional `replacer` can transform each extracted parameter name before interpolation.
295
+ *
296
+ * @example
297
+ * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
298
+ */
299
+ toTemplateString({ prefix = "", replacer } = {}) {
300
+ return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
301
+ if (i % 2 === 0) return part;
302
+ const param = this.#transformParam(part);
303
+ return `\${${replacer ? replacer(param) : param}}`;
304
+ }).join("")}\``;
305
+ }
306
+ /**
307
+ * Extracts all `{param}` segments from the path and returns them as a key-value map.
308
+ * An optional `replacer` transforms each parameter name in both key and value positions.
309
+ * Returns `undefined` when no path parameters are found.
310
+ *
311
+ * @example
312
+ * ```ts
313
+ * new URLPath('/pet/{petId}/tag/{tagId}').toParamsObject()
314
+ * // { petId: 'petId', tagId: 'tagId' }
315
+ * ```
316
+ */
317
+ toParamsObject(replacer) {
318
+ const params = {};
319
+ this.#eachParam((_raw, param) => {
320
+ const key = replacer ? replacer(param) : param;
321
+ params[key] = key;
322
+ });
323
+ return Object.keys(params).length > 0 ? params : void 0;
324
+ }
325
+ /** Converts the OpenAPI path to Express-style colon syntax.
326
+ *
327
+ * @example
328
+ * ```ts
329
+ * new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
330
+ * ```
331
+ */
332
+ toURLPath() {
333
+ return this.path.replace(/\{([^}]+)\}/g, ":$1");
334
+ }
335
+ };
336
+ //#endregion
337
+ //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
338
+ const declarationPrinter$10 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
339
+ const mutationKeyTransformer = ({ node, casing }) => {
340
+ return [`{ url: '${new URLPath(node.path, { casing }).toURLPath()}' }`];
341
+ };
342
+ function MutationKey({ name, paramsCasing, node, transformer = mutationKeyTransformer }) {
343
+ const paramsNode = _kubb_core.ast.createFunctionParameters({ params: [] });
344
+ const paramsSignature = declarationPrinter$10.print(paramsNode) ?? "";
345
+ const keys = transformer({
346
+ node,
347
+ casing: paramsCasing
348
+ });
349
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
350
+ name,
351
+ isExportable: true,
352
+ isIndexable: true,
353
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function.Arrow, {
354
+ name,
355
+ export: true,
356
+ params: paramsSignature,
357
+ singleLine: true,
358
+ children: `[${keys.join(", ")}] as const`
359
+ })
360
+ });
361
+ }
362
+ //#endregion
363
+ //#region ../../internals/shared/src/operation.ts
364
+ function getOperationLink(node, link) {
365
+ if (!link) return;
366
+ if (typeof link === "function") return link(node);
367
+ if (link === "urlPath") return node.path ? `{@link ${new URLPath(node.path).URL}}` : void 0;
368
+ return `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}`;
369
+ }
370
+ function getContentTypeInfo(node) {
371
+ const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
372
+ const isMultipleContentTypes = contentTypes.length > 1;
373
+ return {
374
+ contentTypes,
375
+ isMultipleContentTypes,
376
+ contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
377
+ defaultContentType: contentTypes[0] ?? "application/json",
378
+ hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
379
+ };
380
+ }
381
+ function buildRequestConfigType(node, resolver) {
382
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
383
+ const { isMultipleContentTypes, contentTypeUnion } = getContentTypeInfo(node);
384
+ return `${requestName ? `Partial<RequestConfig<${requestName}>>` : "Partial<RequestConfig>"} & { ${["client?: Client", isMultipleContentTypes ? `contentType?: ${contentTypeUnion}` : void 0].filter(Boolean).join("; ")} }`;
385
+ }
386
+ function buildOperationComments(node, options = {}) {
387
+ const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
388
+ const linkComment = getOperationLink(node, link);
389
+ const filteredComments = (linkPosition === "beforeDeprecated" ? [
390
+ node.description && `@description ${node.description}`,
391
+ node.summary && `@summary ${node.summary}`,
392
+ linkComment,
393
+ node.deprecated && "@deprecated"
394
+ ] : [
395
+ node.description && `@description ${node.description}`,
396
+ node.summary && `@summary ${node.summary}`,
397
+ node.deprecated && "@deprecated",
398
+ linkComment
399
+ ]).filter((comment) => Boolean(comment));
400
+ if (!splitLines) return filteredComments;
401
+ return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
402
+ }
403
+ function getOperationParameters(node, options = {}) {
404
+ const params = _kubb_core.ast.caseParams(node.parameters, options.paramsCasing);
405
+ return {
406
+ path: params.filter((param) => param.in === "path"),
407
+ query: params.filter((param) => param.in === "query"),
408
+ header: params.filter((param) => param.in === "header"),
409
+ cookie: params.filter((param) => param.in === "cookie")
410
+ };
411
+ }
412
+ function getStatusCodeNumber(statusCode) {
413
+ const code = Number(statusCode);
414
+ return Number.isNaN(code) ? void 0 : code;
415
+ }
416
+ function isErrorStatusCode(statusCode) {
417
+ const code = getStatusCodeNumber(statusCode);
418
+ return code !== void 0 && code >= 400;
419
+ }
420
+ function resolveErrorNames(node, resolver) {
421
+ return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
422
+ }
423
+ function resolveStatusCodeNames(node, resolver) {
424
+ return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
425
+ }
426
+ function resolveOperationTypeNames(node, resolver, options = {}) {
427
+ const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
428
+ const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
429
+ const exclude = new Set(options.exclude ?? []);
430
+ const paramNames = [
431
+ ...path.map((param) => resolver.resolvePathParamsName(node, param)),
432
+ ...query.map((param) => resolver.resolveQueryParamsName(node, param)),
433
+ ...header.map((param) => resolver.resolveHeaderParamsName(node, param))
434
+ ];
435
+ const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0, resolver.resolveResponseName(node)];
436
+ return (options.order === "body-response-first" ? [
437
+ ...bodyAndResponseNames,
438
+ ...paramNames,
439
+ ...responseStatusNames
440
+ ] : [
441
+ ...paramNames,
442
+ ...bodyAndResponseNames,
443
+ ...responseStatusNames
444
+ ]).filter((name) => Boolean(name) && !exclude.has(name));
445
+ }
446
+ //#endregion
447
+ //#region ../../internals/tanstack-query/src/utils.ts
448
+ function matchesPattern(node, ov) {
449
+ const { type, pattern } = ov;
450
+ const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
451
+ if (type === "operationId") return matches(node.operationId);
452
+ if (type === "tag") return node.tags.some((t) => matches(t));
453
+ if (type === "path") return matches(node.path);
454
+ if (type === "method") return matches(node.method);
455
+ return false;
456
+ }
457
+ /**
458
+ * Resolves per-operation overrides (first matching override wins).
459
+ *
460
+ * @example
461
+ * ```ts
462
+ * const opts = resolveOperationOverrides(node, override)
463
+ * const queryOpts = 'query' in opts ? opts.query : defaultQuery
464
+ * ```
465
+ */
466
+ function resolveOperationOverrides(node, override) {
467
+ if (!override) return {};
468
+ return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
469
+ }
470
+ /**
471
+ * Collects the Zod schema import names for an operation (response + request body).
472
+ *
473
+ * Returns an empty array when no resolver is provided or the operation has no request body schema.
474
+ */
475
+ function resolveZodSchemaNames(node, zodResolver) {
476
+ if (!zodResolver) return [];
477
+ return [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : void 0].filter((n) => Boolean(n));
478
+ }
479
+ /**
480
+ * Resolve the type for a single path parameter.
481
+ *
482
+ * - When the resolver's group name differs from the individual param name
483
+ * (e.g. kubbV4) → `GroupName['paramName']` (member access).
484
+ * - When they match (v5 default) → `TypeName` (direct reference).
485
+ */
486
+ function resolvePathParamType(node, param, resolver) {
487
+ const individualName = resolver.resolveParamName(node, param);
488
+ const groupName = resolver.resolvePathParamsName(node, param);
489
+ if (groupName !== individualName) return _kubb_core.ast.createParamsType({
490
+ variant: "member",
491
+ base: groupName,
492
+ key: param.name
493
+ });
494
+ return _kubb_core.ast.createParamsType({
495
+ variant: "reference",
496
+ name: individualName
497
+ });
498
+ }
499
+ /**
500
+ * Derive a query-params group type from the resolver.
501
+ * Returns `undefined` when no query params exist or when the group name
502
+ * equals the individual param name (no real group).
503
+ */
504
+ function resolveQueryGroupType(node, params, resolver) {
505
+ if (!params.length) return void 0;
506
+ const firstParam = params[0];
507
+ const groupName = resolver.resolveQueryParamsName(node, firstParam);
508
+ if (groupName === resolver.resolveParamName(node, firstParam)) return void 0;
509
+ return {
510
+ type: _kubb_core.ast.createParamsType({
511
+ variant: "reference",
512
+ name: groupName
513
+ }),
514
+ optional: params.every((p) => !p.required)
515
+ };
516
+ }
517
+ /**
518
+ * Build a single `FunctionParameterNode` for a query or header group.
519
+ */
520
+ function buildGroupParam(name, node, params, groupType, resolver) {
521
+ if (groupType) return [_kubb_core.ast.createFunctionParameter({
522
+ name,
523
+ type: groupType.type,
524
+ optional: groupType.optional
525
+ })];
526
+ if (params.length) {
527
+ const structProps = params.map((p) => ({
528
+ name: p.name,
529
+ type: _kubb_core.ast.createParamsType({
530
+ variant: "reference",
531
+ name: resolver.resolveParamName(node, p)
532
+ }),
533
+ optional: !p.required
534
+ }));
535
+ return [_kubb_core.ast.createFunctionParameter({
536
+ name,
537
+ type: _kubb_core.ast.createParamsType({
538
+ variant: "struct",
539
+ properties: structProps
540
+ }),
541
+ optional: params.every((p) => !p.required)
542
+ })];
543
+ }
544
+ return [];
545
+ }
546
+ /**
547
+ * Build QueryKey params: pathParams + data + queryParams (NO headers, NO config).
548
+ */
549
+ function buildQueryKeyParams(node, options) {
550
+ const { pathParamsType, paramsCasing, resolver } = options;
551
+ const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
552
+ const pathParams = casedParams.filter((p) => p.in === "path");
553
+ const queryParams = casedParams.filter((p) => p.in === "query");
554
+ const queryGroupType = resolveQueryGroupType(node, queryParams, resolver);
555
+ const bodyType = node.requestBody?.content?.[0]?.schema ? _kubb_core.ast.createParamsType({
556
+ variant: "reference",
557
+ name: resolver.resolveDataName(node)
558
+ }) : void 0;
559
+ const bodyRequired = node.requestBody?.required ?? false;
560
+ const params = [];
561
+ if (pathParams.length) {
562
+ const pathChildren = pathParams.map((p) => _kubb_core.ast.createFunctionParameter({
563
+ name: p.name,
564
+ type: resolvePathParamType(node, p, resolver),
565
+ optional: !p.required
566
+ }));
567
+ params.push({
568
+ kind: "ParameterGroup",
569
+ properties: pathChildren,
570
+ inline: pathParamsType === "inline",
571
+ default: pathChildren.every((c) => c.optional) ? "{}" : void 0
572
+ });
573
+ }
574
+ if (bodyType) params.push(_kubb_core.ast.createFunctionParameter({
575
+ name: "data",
576
+ type: bodyType,
577
+ optional: !bodyRequired
578
+ }));
579
+ params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
580
+ return _kubb_core.ast.createFunctionParameters({ params });
581
+ }
582
+ function buildEnabledCheck(paramsNode) {
583
+ const required = [];
584
+ for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
585
+ const group = param;
586
+ for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
587
+ } else {
588
+ const fp = param;
589
+ if (!fp.optional && fp.default === void 0) required.push(fp.name);
590
+ }
591
+ return required.join(" && ");
592
+ }
593
+ //#endregion
594
+ //#region ../../internals/tanstack-query/src/components/QueryKey.tsx
595
+ const declarationPrinter$9 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
596
+ const queryKeyTransformer = ({ node, casing }) => {
597
+ const path = new URLPath(node.path, { casing });
598
+ const hasQueryParams = getOperationParameters(node).query.length > 0;
599
+ const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
600
+ return [
601
+ path.toObject({
602
+ type: "path",
603
+ stringify: true
604
+ }),
605
+ hasQueryParams ? "...(params ? [params] : [])" : void 0,
606
+ hasRequestBody ? "...(data ? [data] : [])" : void 0
607
+ ].filter(Boolean);
608
+ };
609
+ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer = queryKeyTransformer }) {
610
+ const paramsNode = buildQueryKeyParams(node, {
611
+ pathParamsType,
612
+ paramsCasing,
613
+ resolver: tsResolver
614
+ });
615
+ const paramsSignature = declarationPrinter$9.print(paramsNode) ?? "";
616
+ const keys = transformer({
617
+ node,
618
+ casing: paramsCasing
619
+ });
620
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
621
+ name,
622
+ isExportable: true,
623
+ isIndexable: true,
624
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function.Arrow, {
625
+ name,
626
+ export: true,
627
+ params: paramsSignature,
628
+ singleLine: true,
629
+ children: `[${keys.join(", ")}] as const`
630
+ })
631
+ }), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
632
+ name: typeName,
633
+ isTypeOnly: true,
634
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
635
+ name: typeName,
636
+ children: `ReturnType<typeof ${name}>`
637
+ })
638
+ })] });
639
+ }
640
+ //#endregion
641
+ //#region src/components/QueryOptions.tsx
642
+ const declarationPrinter$8 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
643
+ const callPrinter$8 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
644
+ function getQueryOptionsParams(node, options) {
645
+ const { paramsType, paramsCasing, pathParamsType, resolver } = options;
646
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
647
+ return _kubb_core.ast.createOperationParams(node, {
648
+ paramsType,
649
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
650
+ paramsCasing,
651
+ resolver,
652
+ extraParams: [_kubb_core.ast.createFunctionParameter({
653
+ name: "config",
654
+ type: _kubb_core.ast.createParamsType({
655
+ variant: "reference",
656
+ name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
657
+ }),
658
+ default: "{}"
659
+ })]
660
+ });
661
+ }
662
+ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
663
+ const responseName = tsResolver.resolveResponseName(node);
664
+ const errorNames = resolveErrorNames(node, tsResolver);
665
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
666
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
667
+ const paramsNode = getQueryOptionsParams(node, {
668
+ paramsType,
669
+ paramsCasing,
670
+ pathParamsType,
671
+ resolver: tsResolver
672
+ });
673
+ const paramsSignature = declarationPrinter$8.print(paramsNode) ?? "";
674
+ const clientCallStr = (callPrinter$8.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
675
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
676
+ pathParamsType,
677
+ paramsCasing,
678
+ resolver: tsResolver
679
+ });
680
+ const queryKeyParamsCall = callPrinter$8.print(queryKeyParamsNode) ?? "";
681
+ const enabledSource = buildEnabledCheck(queryKeyParamsNode);
682
+ const enabledText = enabledSource ? `enabled: !!(${enabledSource}),` : "";
683
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
684
+ name,
685
+ isExportable: true,
686
+ isIndexable: true,
687
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
688
+ name,
689
+ export: true,
690
+ params: paramsSignature,
691
+ children: `
692
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
693
+ return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
694
+ ${enabledText}
695
+ queryKey,
696
+ queryFn: async ({ signal }) => {
697
+ return ${clientName}(${clientCallStr})
698
+ },
699
+ })
700
+ `
701
+ })
702
+ });
703
+ }
704
+ //#endregion
705
+ //#region src/components/InfiniteQuery.tsx
706
+ const declarationPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
707
+ const callPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
708
+ function buildInfiniteQueryParamsNode(node, options) {
709
+ const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options;
710
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
711
+ const optionsParam = _kubb_core.ast.createFunctionParameter({
712
+ name: "options",
713
+ type: _kubb_core.ast.createParamsType({
714
+ variant: "reference",
715
+ name: `{
716
+ query?: Partial<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
717
+ client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
718
+ }`
719
+ }),
720
+ default: "{}"
721
+ });
722
+ return _kubb_core.ast.createOperationParams(node, {
723
+ paramsType,
724
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
725
+ paramsCasing,
726
+ resolver,
727
+ extraParams: [optionsParam]
728
+ });
729
+ }
730
+ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, initialPageParam, queryParam, customOptions }) {
731
+ const responseName = tsResolver.resolveResponseName(node);
732
+ const errorNames = resolveErrorNames(node, tsResolver);
733
+ const responseType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
734
+ const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
735
+ const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
736
+ const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
737
+ const parts = initialPageParam.split(" as ");
738
+ return parts[parts.length - 1] ?? "unknown";
739
+ })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
740
+ const rawQueryParams = getOperationParameters(node).query;
741
+ const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
742
+ const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
743
+ return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : void 0;
744
+ })() : void 0;
745
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : void 0;
746
+ const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
747
+ const returnType = "UseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
748
+ const generics = [
749
+ `TQueryFnData = ${responseType}`,
750
+ `TError = ${errorType}`,
751
+ "TData = InfiniteData<TQueryFnData>",
752
+ `TQueryKey extends QueryKey = ${queryKeyTypeName}`,
753
+ `TPageParam = ${pageParamType}`
754
+ ];
755
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
756
+ pathParamsType,
757
+ paramsCasing,
758
+ resolver: tsResolver
759
+ });
760
+ const queryKeyParamsCall = callPrinter$7.print(queryKeyParamsNode) ?? "";
761
+ const queryOptionsParamsNode = getQueryOptionsParams(node, {
762
+ paramsType,
763
+ paramsCasing,
764
+ pathParamsType,
765
+ resolver: tsResolver
766
+ });
767
+ const queryOptionsParamsCall = callPrinter$7.print(queryOptionsParamsNode) ?? "";
768
+ const paramsNode = buildInfiniteQueryParamsNode(node, {
769
+ paramsType,
770
+ paramsCasing,
771
+ pathParamsType,
772
+ dataReturnType,
773
+ resolver: tsResolver,
774
+ pageParamGeneric: "TPageParam"
775
+ });
776
+ const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
777
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
778
+ name,
779
+ isExportable: true,
780
+ isIndexable: true,
781
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
782
+ name,
783
+ export: true,
784
+ generics: generics.join(", "),
785
+ params: paramsSignature,
786
+ returnType: void 0,
787
+ JSDoc: { comments: buildOperationComments(node) },
788
+ children: `
789
+ const { query: queryConfig = {}, client: config = {} } = options ?? {}
790
+ const { client: queryClient, ...resolvedOptions } = queryConfig
791
+ const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
792
+ ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
793
+
794
+ const query = useInfiniteQuery({
795
+ ...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
796
+ ...resolvedOptions,
797
+ queryKey,
798
+ } as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
799
+
800
+ query.queryKey = queryKey as TQueryKey
801
+
802
+ return query
803
+ `
804
+ })
805
+ });
806
+ }
807
+ //#endregion
808
+ //#region src/components/InfiniteQueryOptions.tsx
809
+ const declarationPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
810
+ const callPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
811
+ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
812
+ const responseName = tsResolver.resolveResponseName(node);
813
+ const queryFnDataType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
814
+ const errorNames = resolveErrorNames(node, tsResolver);
815
+ const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
816
+ const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
817
+ const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
818
+ const parts = initialPageParam.split(" as ");
819
+ return parts[parts.length - 1] ?? "unknown";
820
+ })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
821
+ const rawQueryParams = getOperationParameters(node).query;
822
+ const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
823
+ const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
824
+ return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : void 0;
825
+ })() : void 0;
826
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : void 0;
827
+ const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
828
+ const paramsNode = getQueryOptionsParams(node, {
829
+ paramsType,
830
+ paramsCasing,
831
+ pathParamsType,
832
+ resolver: tsResolver
833
+ });
834
+ const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
835
+ const clientCallStr = (callPrinter$6.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
836
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
837
+ pathParamsType,
838
+ paramsCasing,
839
+ resolver: tsResolver
840
+ });
841
+ const queryKeyParamsCall = callPrinter$6.print(queryKeyParamsNode) ?? "";
842
+ const enabledSource = buildEnabledCheck(queryKeyParamsNode);
843
+ const enabledText = enabledSource ? `enabled: !!(${enabledSource}),` : "";
844
+ const hasNewParams = nextParam !== void 0 || previousParam !== void 0;
845
+ let getNextPageParamExpr;
846
+ let getPreviousPageParamExpr;
847
+ if (hasNewParams) {
848
+ if (nextParam) {
849
+ const accessor = getNestedAccessor(nextParam, "lastPage");
850
+ if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
851
+ }
852
+ if (previousParam) {
853
+ const accessor = getNestedAccessor(previousParam, "firstPage");
854
+ if (accessor) getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`;
855
+ }
856
+ } else if (cursorParam) {
857
+ getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
858
+ getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
859
+ } else {
860
+ if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
861
+ else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
862
+ getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
863
+ }
864
+ const queryOptionsArr = [
865
+ `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
866
+ getNextPageParamExpr,
867
+ getPreviousPageParamExpr
868
+ ].filter(Boolean);
869
+ const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
870
+ params = {
871
+ ...(params ?? {}),
872
+ ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
873
+ } as ${queryParamsTypeName}` : "";
874
+ if (infiniteOverrideParams) return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
875
+ name,
876
+ isExportable: true,
877
+ isIndexable: true,
878
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
879
+ name,
880
+ export: true,
881
+ params: paramsSignature,
882
+ children: `
883
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
884
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
885
+ ${enabledText}
886
+ queryKey,
887
+ queryFn: async ({ signal, pageParam }) => {
888
+ ${infiniteOverrideParams}
889
+ return ${clientName}(${clientCallStr})
890
+ },
891
+ ${queryOptionsArr.join(",\n")}
892
+ })
893
+ `
894
+ })
895
+ });
896
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
897
+ name,
898
+ isExportable: true,
899
+ isIndexable: true,
900
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
901
+ name,
902
+ export: true,
903
+ params: paramsSignature,
904
+ children: `
905
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
906
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
907
+ ${enabledText}
908
+ queryKey,
909
+ queryFn: async ({ signal }) => {
910
+ return ${clientName}(${clientCallStr})
911
+ },
912
+ ${queryOptionsArr.join(",\n")}
913
+ })
914
+ `
915
+ })
916
+ });
917
+ }
918
+ //#endregion
919
+ //#region src/components/MutationOptions.tsx
920
+ const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
921
+ const callPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
922
+ const keysPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "keys" });
923
+ function buildMutationConfigParamsNode(node, resolver) {
924
+ return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
925
+ name: "config",
926
+ type: _kubb_core.ast.createParamsType({
927
+ variant: "reference",
928
+ name: buildRequestConfigType(node, resolver)
929
+ }),
930
+ default: "{}"
931
+ })] });
932
+ }
933
+ function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, mutationKeyName }) {
934
+ const responseName = tsResolver.resolveResponseName(node);
935
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
936
+ const errorNames = resolveErrorNames(node, tsResolver);
937
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
938
+ const configParamsNode = buildMutationConfigParamsNode(node, tsResolver);
939
+ const paramsSignature = declarationPrinter$5.print(configParamsNode) ?? "";
940
+ const mutationArgParamsNode = _kubb_core.ast.createOperationParams(node, {
941
+ paramsType: "inline",
942
+ pathParamsType: "inline",
943
+ paramsCasing,
944
+ resolver: tsResolver
945
+ });
946
+ const hasMutationParams = mutationArgParamsNode.params.length > 0;
947
+ const TRequest = hasMutationParams ? declarationPrinter$5.print(mutationArgParamsNode) ?? "" : "";
948
+ const argKeysStr = hasMutationParams ? keysPrinter.print(mutationArgParamsNode) ?? "" : "";
949
+ const clientCallParamsNode = _kubb_core.ast.createOperationParams(node, {
950
+ paramsType,
951
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
952
+ paramsCasing,
953
+ resolver: tsResolver,
954
+ extraParams: [_kubb_core.ast.createFunctionParameter({
955
+ name: "config",
956
+ type: _kubb_core.ast.createParamsType({
957
+ variant: "reference",
958
+ name: buildRequestConfigType(node, tsResolver)
959
+ }),
960
+ default: "{}"
961
+ })]
962
+ });
963
+ const clientCallStr = callPrinter$5.print(clientCallParamsNode) ?? "";
964
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
965
+ name,
966
+ isExportable: true,
967
+ isIndexable: true,
968
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
969
+ name,
970
+ export: true,
971
+ params: paramsSignature,
972
+ generics: ["TContext = unknown"],
973
+ children: `
974
+ const mutationKey = ${mutationKeyName}()
975
+ return mutationOptions<${TData}, ${TError}, ${TRequest ? `{${TRequest}}` : "void"}, TContext>({
976
+ mutationKey,
977
+ mutationFn: async(${hasMutationParams ? `{ ${argKeysStr} }` : "_"}) => {
978
+ return ${clientName}(${clientCallStr})
979
+ },
980
+ })
981
+ `
982
+ })
983
+ });
984
+ }
985
+ //#endregion
986
+ //#region src/components/Mutation.tsx
987
+ const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
988
+ const callPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
989
+ function createMutationArgParams(node, options) {
990
+ return _kubb_core.ast.createOperationParams(node, {
991
+ paramsType: "inline",
992
+ pathParamsType: "inline",
993
+ paramsCasing: options.paramsCasing,
994
+ resolver: options.resolver
995
+ });
996
+ }
997
+ function buildMutationParamsNode(node, options) {
998
+ const { paramsCasing, dataReturnType, resolver } = options;
999
+ const responseName = resolver.resolveResponseName(node);
1000
+ const errorNames = resolveErrorNames(node, resolver);
1001
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1002
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1003
+ const mutationArgParamsNode = createMutationArgParams(node, {
1004
+ paramsCasing,
1005
+ resolver
1006
+ });
1007
+ const TRequest = mutationArgParamsNode.params.length > 0 ? declarationPrinter$4.print(mutationArgParamsNode) ?? "" : "";
1008
+ const generics = [
1009
+ TData,
1010
+ TError,
1011
+ TRequest ? `{${TRequest}}` : "void",
1012
+ "TContext"
1013
+ ].join(", ");
1014
+ return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
1015
+ name: "options",
1016
+ type: _kubb_core.ast.createParamsType({
1017
+ variant: "reference",
1018
+ name: `{
1019
+ mutation?: UseMutationOptions<${generics}> & { client?: QueryClient },
1020
+ client?: ${buildRequestConfigType(node, resolver)},
1021
+ }`
1022
+ }),
1023
+ default: "{}"
1024
+ })] });
1025
+ }
1026
+ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, node, tsResolver, mutationKeyName, customOptions }) {
1027
+ const responseName = tsResolver.resolveResponseName(node);
1028
+ const errorNames = resolveErrorNames(node, tsResolver);
1029
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1030
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1031
+ const mutationArgParamsNode = createMutationArgParams(node, {
1032
+ paramsCasing,
1033
+ resolver: tsResolver
1034
+ });
1035
+ const TRequest = mutationArgParamsNode.params.length > 0 ? declarationPrinter$4.print(mutationArgParamsNode) ?? "" : "";
1036
+ const generics = [
1037
+ TData,
1038
+ TError,
1039
+ TRequest ? `{${TRequest}}` : "void",
1040
+ "TContext"
1041
+ ].join(", ");
1042
+ const returnType = `UseMutationResult<${generics}>`;
1043
+ const mutationOptionsConfigNode = buildMutationConfigParamsNode(node, tsResolver);
1044
+ const mutationOptionsParamsCall = callPrinter$4.print(mutationOptionsConfigNode) ?? "";
1045
+ const paramsNode = buildMutationParamsNode(node, {
1046
+ paramsCasing,
1047
+ dataReturnType,
1048
+ resolver: tsResolver
1049
+ });
1050
+ const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
1051
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1052
+ name,
1053
+ isExportable: true,
1054
+ isIndexable: true,
1055
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1056
+ name,
1057
+ export: true,
1058
+ params: paramsSignature,
1059
+ JSDoc: { comments: buildOperationComments(node) },
1060
+ generics: ["TContext"],
1061
+ children: `
1062
+ const { mutation = {}, client: config = {} } = options ?? {}
1063
+ const { client: queryClient, ...mutationOptions } = mutation;
1064
+ const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}()
1065
+
1066
+ const baseOptions = ${mutationOptionsName}(${mutationOptionsParamsCall}) as UseMutationOptions<${generics}>
1067
+ ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' }) as UseMutationOptions<${generics}>` : ""}
1068
+
1069
+ return useMutation<${generics}>({
1070
+ ...baseOptions,${customOptions ? "\n...customOptions," : ""}
1071
+ mutationKey,
1072
+ ...mutationOptions,
1073
+ }, queryClient) as ${returnType}
1074
+ `
1075
+ })
1076
+ });
1077
+ }
1078
+ //#endregion
1079
+ //#region src/components/Query.tsx
1080
+ const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1081
+ const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1082
+ function buildQueryParamsNode(node, options) {
1083
+ const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
1084
+ const responseName = resolver.resolveResponseName(node);
1085
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
1086
+ const errorNames = resolveErrorNames(node, resolver);
1087
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1088
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1089
+ const optionsParam = _kubb_core.ast.createFunctionParameter({
1090
+ name: "options",
1091
+ type: _kubb_core.ast.createParamsType({
1092
+ variant: "reference",
1093
+ name: `{
1094
+ query?: Partial<QueryObserverOptions<${[
1095
+ TData,
1096
+ TError,
1097
+ "TData",
1098
+ "TQueryData",
1099
+ "TQueryKey"
1100
+ ].join(", ")}>> & { client?: QueryClient },
1101
+ client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1102
+ }`
1103
+ }),
1104
+ default: "{}"
1105
+ });
1106
+ return _kubb_core.ast.createOperationParams(node, {
1107
+ paramsType,
1108
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
1109
+ paramsCasing,
1110
+ resolver,
1111
+ extraParams: [optionsParam]
1112
+ });
1113
+ }
1114
+ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions }) {
1115
+ const responseName = tsResolver.resolveResponseName(node);
1116
+ const errorNames = resolveErrorNames(node, tsResolver);
1117
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1118
+ const returnType = `UseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
1119
+ const generics = [
1120
+ `TData = ${TData}`,
1121
+ `TQueryData = ${TData}`,
1122
+ `TQueryKey extends QueryKey = ${queryKeyTypeName}`
1123
+ ];
1124
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
1125
+ pathParamsType,
1126
+ paramsCasing,
1127
+ resolver: tsResolver
1128
+ });
1129
+ const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
1130
+ const queryOptionsParamsNode = getQueryOptionsParams(node, {
1131
+ paramsType,
1132
+ paramsCasing,
1133
+ pathParamsType,
1134
+ resolver: tsResolver
1135
+ });
1136
+ const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
1137
+ const paramsNode = buildQueryParamsNode(node, {
1138
+ paramsType,
1139
+ paramsCasing,
1140
+ pathParamsType,
1141
+ dataReturnType,
1142
+ resolver: tsResolver
1143
+ });
1144
+ const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
1145
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1146
+ name,
1147
+ isExportable: true,
1148
+ isIndexable: true,
1149
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1150
+ name,
1151
+ export: true,
1152
+ generics: generics.join(", "),
1153
+ params: paramsSignature,
1154
+ returnType: void 0,
1155
+ JSDoc: { comments: buildOperationComments(node) },
1156
+ children: `
1157
+ const { query: queryConfig = {}, client: config = {} } = options ?? {}
1158
+ const { client: queryClient, ...resolvedOptions } = queryConfig
1159
+ const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
1160
+ ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1161
+
1162
+ const query = useQuery({
1163
+ ...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
1164
+ ...resolvedOptions,
1165
+ queryKey,
1166
+ } as unknown as QueryObserverOptions, queryClient) as ${returnType}
1167
+
1168
+ query.queryKey = queryKey as TQueryKey
1169
+
1170
+ return query
1171
+ `
1172
+ })
1173
+ });
1174
+ }
1175
+ //#endregion
1176
+ //#region src/components/SuspenseInfiniteQuery.tsx
1177
+ const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1178
+ const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1179
+ function buildSuspenseInfiniteQueryParamsNode(node, options) {
1180
+ const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options;
1181
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
1182
+ const optionsParam = _kubb_core.ast.createFunctionParameter({
1183
+ name: "options",
1184
+ type: _kubb_core.ast.createParamsType({
1185
+ variant: "reference",
1186
+ name: `{
1187
+ query?: Partial<UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
1188
+ client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1189
+ }`
1190
+ }),
1191
+ default: "{}"
1192
+ });
1193
+ return _kubb_core.ast.createOperationParams(node, {
1194
+ paramsType,
1195
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
1196
+ paramsCasing,
1197
+ resolver,
1198
+ extraParams: [optionsParam]
1199
+ });
1200
+ }
1201
+ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions, initialPageParam, queryParam }) {
1202
+ const responseName = tsResolver.resolveResponseName(node);
1203
+ const errorNames = resolveErrorNames(node, tsResolver);
1204
+ const responseType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1205
+ const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1206
+ const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
1207
+ const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
1208
+ const parts = initialPageParam.split(" as ");
1209
+ return parts[parts.length - 1] ?? "unknown";
1210
+ })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
1211
+ const rawQueryParams = getOperationParameters(node).query;
1212
+ const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
1213
+ const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
1214
+ return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : void 0;
1215
+ })() : void 0;
1216
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : void 0;
1217
+ const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
1218
+ const returnType = "UseSuspenseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
1219
+ const generics = [
1220
+ `TQueryFnData = ${responseType}`,
1221
+ `TError = ${errorType}`,
1222
+ "TData = InfiniteData<TQueryFnData>",
1223
+ `TQueryKey extends QueryKey = ${queryKeyTypeName}`,
1224
+ `TPageParam = ${pageParamType}`
1225
+ ];
1226
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
1227
+ pathParamsType,
1228
+ paramsCasing,
1229
+ resolver: tsResolver
1230
+ });
1231
+ const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
1232
+ const queryOptionsParamsNode = getQueryOptionsParams(node, {
1233
+ paramsType,
1234
+ paramsCasing,
1235
+ pathParamsType,
1236
+ resolver: tsResolver
1237
+ });
1238
+ const queryOptionsParamsCall = callPrinter$2.print(queryOptionsParamsNode) ?? "";
1239
+ const paramsNode = buildSuspenseInfiniteQueryParamsNode(node, {
1240
+ paramsType,
1241
+ paramsCasing,
1242
+ pathParamsType,
1243
+ dataReturnType,
1244
+ resolver: tsResolver,
1245
+ pageParamGeneric: "TPageParam"
1246
+ });
1247
+ const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
1248
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1249
+ name,
1250
+ isExportable: true,
1251
+ isIndexable: true,
1252
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1253
+ name,
1254
+ export: true,
1255
+ generics: generics.join(", "),
1256
+ params: paramsSignature,
1257
+ returnType: void 0,
1258
+ JSDoc: { comments: buildOperationComments(node) },
1259
+ children: `
1260
+ const { query: queryConfig = {}, client: config = {} } = options ?? {}
1261
+ const { client: queryClient, ...resolvedOptions } = queryConfig
1262
+ const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
1263
+ ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1264
+
1265
+ const query = useSuspenseInfiniteQuery({
1266
+ ...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
1267
+ ...resolvedOptions,
1268
+ queryKey,
1269
+ } as unknown as UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
1270
+
1271
+ query.queryKey = queryKey as TQueryKey
1272
+
1273
+ return query
1274
+ `
1275
+ })
1276
+ });
1277
+ }
1278
+ //#endregion
1279
+ //#region src/components/SuspenseInfiniteQueryOptions.tsx
1280
+ const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1281
+ const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1282
+ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
1283
+ const responseName = tsResolver.resolveResponseName(node);
1284
+ const queryFnDataType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1285
+ const errorNames = resolveErrorNames(node, tsResolver);
1286
+ const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1287
+ const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
1288
+ const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
1289
+ const parts = initialPageParam.split(" as ");
1290
+ return parts[parts.length - 1] ?? "unknown";
1291
+ })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
1292
+ const rawQueryParams = getOperationParameters(node).query;
1293
+ const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
1294
+ const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
1295
+ return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : void 0;
1296
+ })() : void 0;
1297
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : void 0;
1298
+ const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
1299
+ const paramsNode = getQueryOptionsParams(node, {
1300
+ paramsType,
1301
+ paramsCasing,
1302
+ pathParamsType,
1303
+ resolver: tsResolver
1304
+ });
1305
+ const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
1306
+ const clientCallStr = (callPrinter$1.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
1307
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
1308
+ pathParamsType,
1309
+ paramsCasing,
1310
+ resolver: tsResolver
1311
+ });
1312
+ const queryKeyParamsCall = callPrinter$1.print(queryKeyParamsNode) ?? "";
1313
+ const enabledSource = buildEnabledCheck(queryKeyParamsNode);
1314
+ const enabledText = enabledSource ? `enabled: !!(${enabledSource}),` : "";
1315
+ const hasNewParams = nextParam !== void 0 || previousParam !== void 0;
1316
+ let getNextPageParamExpr;
1317
+ let getPreviousPageParamExpr;
1318
+ if (hasNewParams) {
1319
+ if (nextParam) {
1320
+ const accessor = getNestedAccessor(nextParam, "lastPage");
1321
+ if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
1322
+ }
1323
+ if (previousParam) {
1324
+ const accessor = getNestedAccessor(previousParam, "firstPage");
1325
+ if (accessor) getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`;
1326
+ }
1327
+ } else if (cursorParam) {
1328
+ getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
1329
+ getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
1330
+ } else {
1331
+ if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
1332
+ else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
1333
+ getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
1334
+ }
1335
+ const queryOptionsArr = [
1336
+ `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
1337
+ getNextPageParamExpr,
1338
+ getPreviousPageParamExpr
1339
+ ].filter(Boolean);
1340
+ const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
1341
+ params = {
1342
+ ...(params ?? {}),
1343
+ ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
1344
+ } as ${queryParamsTypeName}` : "";
1345
+ if (infiniteOverrideParams) return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1346
+ name,
1347
+ isExportable: true,
1348
+ isIndexable: true,
1349
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1350
+ name,
1351
+ export: true,
1352
+ params: paramsSignature,
1353
+ children: `
1354
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1355
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1356
+ ${enabledText}
1357
+ queryKey,
1358
+ queryFn: async ({ signal, pageParam }) => {
1359
+ ${infiniteOverrideParams}
1360
+ return ${clientName}(${clientCallStr})
1361
+ },
1362
+ ${queryOptionsArr.join(",\n")}
1363
+ })
1364
+ `
1365
+ })
1366
+ });
1367
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1368
+ name,
1369
+ isExportable: true,
1370
+ isIndexable: true,
1371
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1372
+ name,
1373
+ export: true,
1374
+ params: paramsSignature,
1375
+ children: `
1376
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1377
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1378
+ ${enabledText}
1379
+ queryKey,
1380
+ queryFn: async ({ signal }) => {
1381
+ return ${clientName}(${clientCallStr})
1382
+ },
1383
+ ${queryOptionsArr.join(",\n")}
1384
+ })
1385
+ `
1386
+ })
1387
+ });
1388
+ }
1389
+ //#endregion
1390
+ //#region src/components/SuspenseQuery.tsx
1391
+ const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1392
+ const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1393
+ function buildSuspenseQueryParamsNode(node, options) {
1394
+ const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
1395
+ const responseName = resolver.resolveResponseName(node);
1396
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
1397
+ const errorNames = resolveErrorNames(node, resolver);
1398
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1399
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1400
+ const optionsParam = _kubb_core.ast.createFunctionParameter({
1401
+ name: "options",
1402
+ type: _kubb_core.ast.createParamsType({
1403
+ variant: "reference",
1404
+ name: `{
1405
+ query?: Partial<UseSuspenseQueryOptions<${[
1406
+ TData,
1407
+ TError,
1408
+ "TData",
1409
+ "TQueryKey"
1410
+ ].join(", ")}>> & { client?: QueryClient },
1411
+ client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1412
+ }`
1413
+ }),
1414
+ default: "{}"
1415
+ });
1416
+ return _kubb_core.ast.createOperationParams(node, {
1417
+ paramsType,
1418
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
1419
+ paramsCasing,
1420
+ resolver,
1421
+ extraParams: [optionsParam]
1422
+ });
1423
+ }
1424
+ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions }) {
1425
+ const responseName = tsResolver.resolveResponseName(node);
1426
+ const errorNames = resolveErrorNames(node, tsResolver);
1427
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1428
+ const returnType = `UseSuspenseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
1429
+ const generics = [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
1430
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
1431
+ pathParamsType,
1432
+ paramsCasing,
1433
+ resolver: tsResolver
1434
+ });
1435
+ const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
1436
+ const queryOptionsParamsNode = getQueryOptionsParams(node, {
1437
+ paramsType,
1438
+ paramsCasing,
1439
+ pathParamsType,
1440
+ resolver: tsResolver
1441
+ });
1442
+ const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
1443
+ const paramsNode = buildSuspenseQueryParamsNode(node, {
1444
+ paramsType,
1445
+ paramsCasing,
1446
+ pathParamsType,
1447
+ dataReturnType,
1448
+ resolver: tsResolver
1449
+ });
1450
+ const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1451
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1452
+ name,
1453
+ isExportable: true,
1454
+ isIndexable: true,
1455
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1456
+ name,
1457
+ export: true,
1458
+ generics: generics.join(", "),
1459
+ params: paramsSignature,
1460
+ returnType: void 0,
1461
+ JSDoc: { comments: buildOperationComments(node) },
1462
+ children: `
1463
+ const { query: queryConfig = {}, client: config = {} } = options ?? {}
1464
+ const { client: queryClient, ...resolvedOptions } = queryConfig
1465
+ const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
1466
+ ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1467
+
1468
+ const query = useSuspenseQuery({
1469
+ ...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
1470
+ ...resolvedOptions,
1471
+ queryKey,
1472
+ } as unknown as UseSuspenseQueryOptions, queryClient) as ${returnType}
1473
+
1474
+ query.queryKey = queryKey as TQueryKey
1475
+
1476
+ return query
1477
+ `
1478
+ })
1479
+ });
1480
+ }
1481
+ //#endregion
1482
+ Object.defineProperty(exports, "InfiniteQuery", {
1483
+ enumerable: true,
1484
+ get: function() {
1485
+ return InfiniteQuery;
1486
+ }
1487
+ });
1488
+ Object.defineProperty(exports, "InfiniteQueryOptions", {
1489
+ enumerable: true,
1490
+ get: function() {
1491
+ return InfiniteQueryOptions;
1492
+ }
1493
+ });
1494
+ Object.defineProperty(exports, "Mutation", {
1495
+ enumerable: true,
1496
+ get: function() {
1497
+ return Mutation;
1498
+ }
1499
+ });
1500
+ Object.defineProperty(exports, "MutationKey", {
1501
+ enumerable: true,
1502
+ get: function() {
1503
+ return MutationKey;
1504
+ }
1505
+ });
1506
+ Object.defineProperty(exports, "MutationOptions", {
1507
+ enumerable: true,
1508
+ get: function() {
1509
+ return MutationOptions;
1510
+ }
1511
+ });
1512
+ Object.defineProperty(exports, "Query", {
1513
+ enumerable: true,
1514
+ get: function() {
1515
+ return Query;
1516
+ }
1517
+ });
1518
+ Object.defineProperty(exports, "QueryKey", {
1519
+ enumerable: true,
1520
+ get: function() {
1521
+ return QueryKey;
1522
+ }
1523
+ });
1524
+ Object.defineProperty(exports, "QueryOptions", {
1525
+ enumerable: true,
1526
+ get: function() {
1527
+ return QueryOptions;
1528
+ }
1529
+ });
1530
+ Object.defineProperty(exports, "SuspenseInfiniteQuery", {
1531
+ enumerable: true,
1532
+ get: function() {
1533
+ return SuspenseInfiniteQuery;
1534
+ }
1535
+ });
1536
+ Object.defineProperty(exports, "SuspenseInfiniteQueryOptions", {
1537
+ enumerable: true,
1538
+ get: function() {
1539
+ return SuspenseInfiniteQueryOptions;
1540
+ }
1541
+ });
1542
+ Object.defineProperty(exports, "SuspenseQuery", {
1543
+ enumerable: true,
1544
+ get: function() {
1545
+ return SuspenseQuery;
1546
+ }
1547
+ });
1548
+ Object.defineProperty(exports, "__name", {
1549
+ enumerable: true,
1550
+ get: function() {
1551
+ return __name;
1552
+ }
1553
+ });
1554
+ Object.defineProperty(exports, "__toESM", {
1555
+ enumerable: true,
1556
+ get: function() {
1557
+ return __toESM;
1558
+ }
1559
+ });
1560
+ Object.defineProperty(exports, "camelCase", {
1561
+ enumerable: true,
1562
+ get: function() {
1563
+ return camelCase;
1564
+ }
1565
+ });
1566
+ Object.defineProperty(exports, "getOperationParameters", {
1567
+ enumerable: true,
1568
+ get: function() {
1569
+ return getOperationParameters;
1570
+ }
1571
+ });
1572
+ Object.defineProperty(exports, "mutationKeyTransformer", {
1573
+ enumerable: true,
1574
+ get: function() {
1575
+ return mutationKeyTransformer;
1576
+ }
1577
+ });
1578
+ Object.defineProperty(exports, "queryKeyTransformer", {
1579
+ enumerable: true,
1580
+ get: function() {
1581
+ return queryKeyTransformer;
1582
+ }
1583
+ });
1584
+ Object.defineProperty(exports, "resolveOperationOverrides", {
1585
+ enumerable: true,
1586
+ get: function() {
1587
+ return resolveOperationOverrides;
1588
+ }
1589
+ });
1590
+ Object.defineProperty(exports, "resolveOperationTypeNames", {
1591
+ enumerable: true,
1592
+ get: function() {
1593
+ return resolveOperationTypeNames;
1594
+ }
1595
+ });
1596
+ Object.defineProperty(exports, "resolveZodSchemaNames", {
1597
+ enumerable: true,
1598
+ get: function() {
1599
+ return resolveZodSchemaNames;
1600
+ }
1601
+ });
1602
+
1603
+ //# sourceMappingURL=components-HwdCDefj.cjs.map