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

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-BZ3a2O0G.cjs +1615 -0
  4. package/dist/components-BZ3a2O0G.cjs.map +1 -0
  5. package/dist/components-DJqIUiZW.js +1471 -0
  6. package/dist/components-DJqIUiZW.js.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-BQ_vEksc.js +1412 -0
  11. package/dist/generators-BQ_vEksc.js.map +1 -0
  12. package/dist/generators-DSjer1xY.cjs +1454 -0
  13. package/dist/generators-DSjer1xY.cjs.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 +928 -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,1615 @@
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
+ const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
427
+ function resolveOperationTypeNames(node, resolver, options = {}) {
428
+ const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
429
+ let byResolver = typeNamesByResolver.get(resolver);
430
+ if (byResolver) {
431
+ const cached = byResolver.get(cacheKey);
432
+ if (cached) return cached;
433
+ } else {
434
+ byResolver = /* @__PURE__ */ new Map();
435
+ typeNamesByResolver.set(resolver, byResolver);
436
+ }
437
+ const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
438
+ const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
439
+ const exclude = new Set(options.exclude ?? []);
440
+ const paramNames = [
441
+ ...path.map((param) => resolver.resolvePathParamsName(node, param)),
442
+ ...query.map((param) => resolver.resolveQueryParamsName(node, param)),
443
+ ...header.map((param) => resolver.resolveHeaderParamsName(node, param))
444
+ ];
445
+ const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0, resolver.resolveResponseName(node)];
446
+ const result = (options.order === "body-response-first" ? [
447
+ ...bodyAndResponseNames,
448
+ ...paramNames,
449
+ ...responseStatusNames
450
+ ] : [
451
+ ...paramNames,
452
+ ...bodyAndResponseNames,
453
+ ...responseStatusNames
454
+ ]).filter((name) => Boolean(name) && !exclude.has(name));
455
+ byResolver.set(cacheKey, result);
456
+ return result;
457
+ }
458
+ //#endregion
459
+ //#region ../../internals/tanstack-query/src/utils.ts
460
+ function matchesPattern(node, ov) {
461
+ const { type, pattern } = ov;
462
+ const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
463
+ if (type === "operationId") return matches(node.operationId);
464
+ if (type === "tag") return node.tags.some((t) => matches(t));
465
+ if (type === "path") return matches(node.path);
466
+ if (type === "method") return matches(node.method);
467
+ return false;
468
+ }
469
+ /**
470
+ * Resolves per-operation overrides (first matching override wins).
471
+ *
472
+ * @example
473
+ * ```ts
474
+ * const opts = resolveOperationOverrides(node, override)
475
+ * const queryOpts = 'query' in opts ? opts.query : defaultQuery
476
+ * ```
477
+ */
478
+ function resolveOperationOverrides(node, override) {
479
+ if (!override) return {};
480
+ return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
481
+ }
482
+ /**
483
+ * Collects the Zod schema import names for an operation (response + request body).
484
+ *
485
+ * Returns an empty array when no resolver is provided or the operation has no request body schema.
486
+ */
487
+ function resolveZodSchemaNames(node, zodResolver) {
488
+ if (!zodResolver) return [];
489
+ return [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : void 0].filter((n) => Boolean(n));
490
+ }
491
+ /**
492
+ * Resolve the type for a single path parameter.
493
+ *
494
+ * - When the resolver's group name differs from the individual param name
495
+ * (e.g. kubbV4) → `GroupName['paramName']` (member access).
496
+ * - When they match (v5 default) → `TypeName` (direct reference).
497
+ */
498
+ function resolvePathParamType(node, param, resolver) {
499
+ const individualName = resolver.resolveParamName(node, param);
500
+ const groupName = resolver.resolvePathParamsName(node, param);
501
+ if (groupName !== individualName) return _kubb_core.ast.createParamsType({
502
+ variant: "member",
503
+ base: groupName,
504
+ key: param.name
505
+ });
506
+ return _kubb_core.ast.createParamsType({
507
+ variant: "reference",
508
+ name: individualName
509
+ });
510
+ }
511
+ /**
512
+ * Derive a query-params group type from the resolver.
513
+ * Returns `undefined` when no query params exist or when the group name
514
+ * equals the individual param name (no real group).
515
+ */
516
+ function resolveQueryGroupType(node, params, resolver) {
517
+ if (!params.length) return void 0;
518
+ const firstParam = params[0];
519
+ const groupName = resolver.resolveQueryParamsName(node, firstParam);
520
+ if (groupName === resolver.resolveParamName(node, firstParam)) return void 0;
521
+ return {
522
+ type: _kubb_core.ast.createParamsType({
523
+ variant: "reference",
524
+ name: groupName
525
+ }),
526
+ optional: params.every((p) => !p.required)
527
+ };
528
+ }
529
+ /**
530
+ * Build a single `FunctionParameterNode` for a query or header group.
531
+ */
532
+ function buildGroupParam(name, node, params, groupType, resolver) {
533
+ if (groupType) return [_kubb_core.ast.createFunctionParameter({
534
+ name,
535
+ type: groupType.type,
536
+ optional: groupType.optional
537
+ })];
538
+ if (params.length) {
539
+ const structProps = params.map((p) => ({
540
+ name: p.name,
541
+ type: _kubb_core.ast.createParamsType({
542
+ variant: "reference",
543
+ name: resolver.resolveParamName(node, p)
544
+ }),
545
+ optional: !p.required
546
+ }));
547
+ return [_kubb_core.ast.createFunctionParameter({
548
+ name,
549
+ type: _kubb_core.ast.createParamsType({
550
+ variant: "struct",
551
+ properties: structProps
552
+ }),
553
+ optional: params.every((p) => !p.required)
554
+ })];
555
+ }
556
+ return [];
557
+ }
558
+ /**
559
+ * Build QueryKey params: pathParams + data + queryParams (NO headers, NO config).
560
+ */
561
+ function buildQueryKeyParams(node, options) {
562
+ const { pathParamsType, paramsCasing, resolver } = options;
563
+ const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
564
+ const pathParams = casedParams.filter((p) => p.in === "path");
565
+ const queryParams = casedParams.filter((p) => p.in === "query");
566
+ const queryGroupType = resolveQueryGroupType(node, queryParams, resolver);
567
+ const bodyType = node.requestBody?.content?.[0]?.schema ? _kubb_core.ast.createParamsType({
568
+ variant: "reference",
569
+ name: resolver.resolveDataName(node)
570
+ }) : void 0;
571
+ const bodyRequired = node.requestBody?.required ?? false;
572
+ const params = [];
573
+ if (pathParams.length) {
574
+ const pathChildren = pathParams.map((p) => _kubb_core.ast.createFunctionParameter({
575
+ name: p.name,
576
+ type: resolvePathParamType(node, p, resolver),
577
+ optional: !p.required
578
+ }));
579
+ params.push({
580
+ kind: "ParameterGroup",
581
+ properties: pathChildren,
582
+ inline: pathParamsType === "inline",
583
+ default: pathChildren.every((c) => c.optional) ? "{}" : void 0
584
+ });
585
+ }
586
+ if (bodyType) params.push(_kubb_core.ast.createFunctionParameter({
587
+ name: "data",
588
+ type: bodyType,
589
+ optional: !bodyRequired
590
+ }));
591
+ params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
592
+ return _kubb_core.ast.createFunctionParameters({ params });
593
+ }
594
+ function buildEnabledCheck(paramsNode) {
595
+ const required = [];
596
+ for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
597
+ const group = param;
598
+ for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
599
+ } else {
600
+ const fp = param;
601
+ if (!fp.optional && fp.default === void 0) required.push(fp.name);
602
+ }
603
+ return required.join(" && ");
604
+ }
605
+ //#endregion
606
+ //#region ../../internals/tanstack-query/src/components/QueryKey.tsx
607
+ const declarationPrinter$9 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
608
+ const queryKeyTransformer = ({ node, casing }) => {
609
+ const path = new URLPath(node.path, { casing });
610
+ const hasQueryParams = getOperationParameters(node).query.length > 0;
611
+ const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
612
+ return [
613
+ path.toObject({
614
+ type: "path",
615
+ stringify: true
616
+ }),
617
+ hasQueryParams ? "...(params ? [params] : [])" : void 0,
618
+ hasRequestBody ? "...(data ? [data] : [])" : void 0
619
+ ].filter(Boolean);
620
+ };
621
+ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer = queryKeyTransformer }) {
622
+ const paramsNode = buildQueryKeyParams(node, {
623
+ pathParamsType,
624
+ paramsCasing,
625
+ resolver: tsResolver
626
+ });
627
+ const paramsSignature = declarationPrinter$9.print(paramsNode) ?? "";
628
+ const keys = transformer({
629
+ node,
630
+ casing: paramsCasing
631
+ });
632
+ 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, {
633
+ name,
634
+ isExportable: true,
635
+ isIndexable: true,
636
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function.Arrow, {
637
+ name,
638
+ export: true,
639
+ params: paramsSignature,
640
+ singleLine: true,
641
+ children: `[${keys.join(", ")}] as const`
642
+ })
643
+ }), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
644
+ name: typeName,
645
+ isTypeOnly: true,
646
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
647
+ name: typeName,
648
+ children: `ReturnType<typeof ${name}>`
649
+ })
650
+ })] });
651
+ }
652
+ //#endregion
653
+ //#region src/components/QueryOptions.tsx
654
+ const declarationPrinter$8 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
655
+ const callPrinter$8 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
656
+ function getQueryOptionsParams(node, options) {
657
+ const { paramsType, paramsCasing, pathParamsType, resolver } = options;
658
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
659
+ return _kubb_core.ast.createOperationParams(node, {
660
+ paramsType,
661
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
662
+ paramsCasing,
663
+ resolver,
664
+ extraParams: [_kubb_core.ast.createFunctionParameter({
665
+ name: "config",
666
+ type: _kubb_core.ast.createParamsType({
667
+ variant: "reference",
668
+ name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
669
+ }),
670
+ default: "{}"
671
+ })]
672
+ });
673
+ }
674
+ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
675
+ const responseName = tsResolver.resolveResponseName(node);
676
+ const errorNames = resolveErrorNames(node, tsResolver);
677
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
678
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
679
+ const paramsNode = getQueryOptionsParams(node, {
680
+ paramsType,
681
+ paramsCasing,
682
+ pathParamsType,
683
+ resolver: tsResolver
684
+ });
685
+ const paramsSignature = declarationPrinter$8.print(paramsNode) ?? "";
686
+ const clientCallStr = (callPrinter$8.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
687
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
688
+ pathParamsType,
689
+ paramsCasing,
690
+ resolver: tsResolver
691
+ });
692
+ const queryKeyParamsCall = callPrinter$8.print(queryKeyParamsNode) ?? "";
693
+ const enabledSource = buildEnabledCheck(queryKeyParamsNode);
694
+ const enabledText = enabledSource ? `enabled: !!(${enabledSource}),` : "";
695
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
696
+ name,
697
+ isExportable: true,
698
+ isIndexable: true,
699
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
700
+ name,
701
+ export: true,
702
+ params: paramsSignature,
703
+ children: `
704
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
705
+ return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
706
+ ${enabledText}
707
+ queryKey,
708
+ queryFn: async ({ signal }) => {
709
+ return ${clientName}(${clientCallStr})
710
+ },
711
+ })
712
+ `
713
+ })
714
+ });
715
+ }
716
+ //#endregion
717
+ //#region src/components/InfiniteQuery.tsx
718
+ const declarationPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
719
+ const callPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
720
+ function buildInfiniteQueryParamsNode(node, options) {
721
+ const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options;
722
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
723
+ const optionsParam = _kubb_core.ast.createFunctionParameter({
724
+ name: "options",
725
+ type: _kubb_core.ast.createParamsType({
726
+ variant: "reference",
727
+ name: `{
728
+ query?: Partial<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
729
+ client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
730
+ }`
731
+ }),
732
+ default: "{}"
733
+ });
734
+ return _kubb_core.ast.createOperationParams(node, {
735
+ paramsType,
736
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
737
+ paramsCasing,
738
+ resolver,
739
+ extraParams: [optionsParam]
740
+ });
741
+ }
742
+ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, initialPageParam, queryParam, customOptions }) {
743
+ const responseName = tsResolver.resolveResponseName(node);
744
+ const errorNames = resolveErrorNames(node, tsResolver);
745
+ const responseType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
746
+ const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
747
+ const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
748
+ const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
749
+ const parts = initialPageParam.split(" as ");
750
+ return parts[parts.length - 1] ?? "unknown";
751
+ })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
752
+ const rawQueryParams = getOperationParameters(node).query;
753
+ const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
754
+ const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
755
+ return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : void 0;
756
+ })() : void 0;
757
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : void 0;
758
+ const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
759
+ const returnType = "UseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
760
+ const generics = [
761
+ `TQueryFnData = ${responseType}`,
762
+ `TError = ${errorType}`,
763
+ "TData = InfiniteData<TQueryFnData>",
764
+ `TQueryKey extends QueryKey = ${queryKeyTypeName}`,
765
+ `TPageParam = ${pageParamType}`
766
+ ];
767
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
768
+ pathParamsType,
769
+ paramsCasing,
770
+ resolver: tsResolver
771
+ });
772
+ const queryKeyParamsCall = callPrinter$7.print(queryKeyParamsNode) ?? "";
773
+ const queryOptionsParamsNode = getQueryOptionsParams(node, {
774
+ paramsType,
775
+ paramsCasing,
776
+ pathParamsType,
777
+ resolver: tsResolver
778
+ });
779
+ const queryOptionsParamsCall = callPrinter$7.print(queryOptionsParamsNode) ?? "";
780
+ const paramsNode = buildInfiniteQueryParamsNode(node, {
781
+ paramsType,
782
+ paramsCasing,
783
+ pathParamsType,
784
+ dataReturnType,
785
+ resolver: tsResolver,
786
+ pageParamGeneric: "TPageParam"
787
+ });
788
+ const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
789
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
790
+ name,
791
+ isExportable: true,
792
+ isIndexable: true,
793
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
794
+ name,
795
+ export: true,
796
+ generics: generics.join(", "),
797
+ params: paramsSignature,
798
+ returnType: void 0,
799
+ JSDoc: { comments: buildOperationComments(node) },
800
+ children: `
801
+ const { query: queryConfig = {}, client: config = {} } = options ?? {}
802
+ const { client: queryClient, ...resolvedOptions } = queryConfig
803
+ const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
804
+ ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
805
+
806
+ const query = useInfiniteQuery({
807
+ ...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
808
+ ...resolvedOptions,
809
+ queryKey,
810
+ } as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
811
+
812
+ query.queryKey = queryKey as TQueryKey
813
+
814
+ return query
815
+ `
816
+ })
817
+ });
818
+ }
819
+ //#endregion
820
+ //#region src/components/InfiniteQueryOptions.tsx
821
+ const declarationPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
822
+ const callPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
823
+ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
824
+ const responseName = tsResolver.resolveResponseName(node);
825
+ const queryFnDataType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
826
+ const errorNames = resolveErrorNames(node, tsResolver);
827
+ const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
828
+ const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
829
+ const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
830
+ const parts = initialPageParam.split(" as ");
831
+ return parts[parts.length - 1] ?? "unknown";
832
+ })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
833
+ const rawQueryParams = getOperationParameters(node).query;
834
+ const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
835
+ const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
836
+ return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : void 0;
837
+ })() : void 0;
838
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : void 0;
839
+ const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
840
+ const paramsNode = getQueryOptionsParams(node, {
841
+ paramsType,
842
+ paramsCasing,
843
+ pathParamsType,
844
+ resolver: tsResolver
845
+ });
846
+ const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
847
+ const clientCallStr = (callPrinter$6.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
848
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
849
+ pathParamsType,
850
+ paramsCasing,
851
+ resolver: tsResolver
852
+ });
853
+ const queryKeyParamsCall = callPrinter$6.print(queryKeyParamsNode) ?? "";
854
+ const enabledSource = buildEnabledCheck(queryKeyParamsNode);
855
+ const enabledText = enabledSource ? `enabled: !!(${enabledSource}),` : "";
856
+ const hasNewParams = nextParam !== void 0 || previousParam !== void 0;
857
+ let getNextPageParamExpr;
858
+ let getPreviousPageParamExpr;
859
+ if (hasNewParams) {
860
+ if (nextParam) {
861
+ const accessor = getNestedAccessor(nextParam, "lastPage");
862
+ if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
863
+ }
864
+ if (previousParam) {
865
+ const accessor = getNestedAccessor(previousParam, "firstPage");
866
+ if (accessor) getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`;
867
+ }
868
+ } else if (cursorParam) {
869
+ getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
870
+ getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
871
+ } else {
872
+ if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
873
+ else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
874
+ getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
875
+ }
876
+ const queryOptionsArr = [
877
+ `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
878
+ getNextPageParamExpr,
879
+ getPreviousPageParamExpr
880
+ ].filter(Boolean);
881
+ const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
882
+ params = {
883
+ ...(params ?? {}),
884
+ ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
885
+ } as ${queryParamsTypeName}` : "";
886
+ if (infiniteOverrideParams) return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
887
+ name,
888
+ isExportable: true,
889
+ isIndexable: true,
890
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
891
+ name,
892
+ export: true,
893
+ params: paramsSignature,
894
+ children: `
895
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
896
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
897
+ ${enabledText}
898
+ queryKey,
899
+ queryFn: async ({ signal, pageParam }) => {
900
+ ${infiniteOverrideParams}
901
+ return ${clientName}(${clientCallStr})
902
+ },
903
+ ${queryOptionsArr.join(",\n")}
904
+ })
905
+ `
906
+ })
907
+ });
908
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
909
+ name,
910
+ isExportable: true,
911
+ isIndexable: true,
912
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
913
+ name,
914
+ export: true,
915
+ params: paramsSignature,
916
+ children: `
917
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
918
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
919
+ ${enabledText}
920
+ queryKey,
921
+ queryFn: async ({ signal }) => {
922
+ return ${clientName}(${clientCallStr})
923
+ },
924
+ ${queryOptionsArr.join(",\n")}
925
+ })
926
+ `
927
+ })
928
+ });
929
+ }
930
+ //#endregion
931
+ //#region src/components/MutationOptions.tsx
932
+ const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
933
+ const callPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
934
+ const keysPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "keys" });
935
+ function buildMutationConfigParamsNode(node, resolver) {
936
+ return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
937
+ name: "config",
938
+ type: _kubb_core.ast.createParamsType({
939
+ variant: "reference",
940
+ name: buildRequestConfigType(node, resolver)
941
+ }),
942
+ default: "{}"
943
+ })] });
944
+ }
945
+ function MutationOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, mutationKeyName }) {
946
+ const responseName = tsResolver.resolveResponseName(node);
947
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
948
+ const errorNames = resolveErrorNames(node, tsResolver);
949
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
950
+ const configParamsNode = buildMutationConfigParamsNode(node, tsResolver);
951
+ const paramsSignature = declarationPrinter$5.print(configParamsNode) ?? "";
952
+ const mutationArgParamsNode = _kubb_core.ast.createOperationParams(node, {
953
+ paramsType: "inline",
954
+ pathParamsType: "inline",
955
+ paramsCasing,
956
+ resolver: tsResolver
957
+ });
958
+ const hasMutationParams = mutationArgParamsNode.params.length > 0;
959
+ const TRequest = hasMutationParams ? declarationPrinter$5.print(mutationArgParamsNode) ?? "" : "";
960
+ const argKeysStr = hasMutationParams ? keysPrinter.print(mutationArgParamsNode) ?? "" : "";
961
+ const clientCallParamsNode = _kubb_core.ast.createOperationParams(node, {
962
+ paramsType,
963
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
964
+ paramsCasing,
965
+ resolver: tsResolver,
966
+ extraParams: [_kubb_core.ast.createFunctionParameter({
967
+ name: "config",
968
+ type: _kubb_core.ast.createParamsType({
969
+ variant: "reference",
970
+ name: buildRequestConfigType(node, tsResolver)
971
+ }),
972
+ default: "{}"
973
+ })]
974
+ });
975
+ const clientCallStr = callPrinter$5.print(clientCallParamsNode) ?? "";
976
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
977
+ name,
978
+ isExportable: true,
979
+ isIndexable: true,
980
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
981
+ name,
982
+ export: true,
983
+ params: paramsSignature,
984
+ generics: ["TContext = unknown"],
985
+ children: `
986
+ const mutationKey = ${mutationKeyName}()
987
+ return mutationOptions<${TData}, ${TError}, ${TRequest ? `{${TRequest}}` : "void"}, TContext>({
988
+ mutationKey,
989
+ mutationFn: async(${hasMutationParams ? `{ ${argKeysStr} }` : "_"}) => {
990
+ return ${clientName}(${clientCallStr})
991
+ },
992
+ })
993
+ `
994
+ })
995
+ });
996
+ }
997
+ //#endregion
998
+ //#region src/components/Mutation.tsx
999
+ const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1000
+ const callPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1001
+ function createMutationArgParams(node, options) {
1002
+ return _kubb_core.ast.createOperationParams(node, {
1003
+ paramsType: "inline",
1004
+ pathParamsType: "inline",
1005
+ paramsCasing: options.paramsCasing,
1006
+ resolver: options.resolver
1007
+ });
1008
+ }
1009
+ function buildMutationParamsNode(node, options) {
1010
+ const { paramsCasing, dataReturnType, resolver } = options;
1011
+ const responseName = resolver.resolveResponseName(node);
1012
+ const errorNames = resolveErrorNames(node, resolver);
1013
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1014
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1015
+ const mutationArgParamsNode = createMutationArgParams(node, {
1016
+ paramsCasing,
1017
+ resolver
1018
+ });
1019
+ const TRequest = mutationArgParamsNode.params.length > 0 ? declarationPrinter$4.print(mutationArgParamsNode) ?? "" : "";
1020
+ const generics = [
1021
+ TData,
1022
+ TError,
1023
+ TRequest ? `{${TRequest}}` : "void",
1024
+ "TContext"
1025
+ ].join(", ");
1026
+ return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
1027
+ name: "options",
1028
+ type: _kubb_core.ast.createParamsType({
1029
+ variant: "reference",
1030
+ name: `{
1031
+ mutation?: UseMutationOptions<${generics}> & { client?: QueryClient },
1032
+ client?: ${buildRequestConfigType(node, resolver)},
1033
+ }`
1034
+ }),
1035
+ default: "{}"
1036
+ })] });
1037
+ }
1038
+ function Mutation({ name, mutationOptionsName, paramsCasing, dataReturnType, node, tsResolver, mutationKeyName, customOptions }) {
1039
+ const responseName = tsResolver.resolveResponseName(node);
1040
+ const errorNames = resolveErrorNames(node, tsResolver);
1041
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1042
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1043
+ const mutationArgParamsNode = createMutationArgParams(node, {
1044
+ paramsCasing,
1045
+ resolver: tsResolver
1046
+ });
1047
+ const TRequest = mutationArgParamsNode.params.length > 0 ? declarationPrinter$4.print(mutationArgParamsNode) ?? "" : "";
1048
+ const generics = [
1049
+ TData,
1050
+ TError,
1051
+ TRequest ? `{${TRequest}}` : "void",
1052
+ "TContext"
1053
+ ].join(", ");
1054
+ const returnType = `UseMutationResult<${generics}>`;
1055
+ const mutationOptionsConfigNode = buildMutationConfigParamsNode(node, tsResolver);
1056
+ const mutationOptionsParamsCall = callPrinter$4.print(mutationOptionsConfigNode) ?? "";
1057
+ const paramsNode = buildMutationParamsNode(node, {
1058
+ paramsCasing,
1059
+ dataReturnType,
1060
+ resolver: tsResolver
1061
+ });
1062
+ const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
1063
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1064
+ name,
1065
+ isExportable: true,
1066
+ isIndexable: true,
1067
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1068
+ name,
1069
+ export: true,
1070
+ params: paramsSignature,
1071
+ JSDoc: { comments: buildOperationComments(node) },
1072
+ generics: ["TContext"],
1073
+ children: `
1074
+ const { mutation = {}, client: config = {} } = options ?? {}
1075
+ const { client: queryClient, ...mutationOptions } = mutation;
1076
+ const mutationKey = mutationOptions.mutationKey ?? ${mutationKeyName}()
1077
+
1078
+ const baseOptions = ${mutationOptionsName}(${mutationOptionsParamsCall}) as UseMutationOptions<${generics}>
1079
+ ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' }) as UseMutationOptions<${generics}>` : ""}
1080
+
1081
+ return useMutation<${generics}>({
1082
+ ...baseOptions,${customOptions ? "\n...customOptions," : ""}
1083
+ mutationKey,
1084
+ ...mutationOptions,
1085
+ }, queryClient) as ${returnType}
1086
+ `
1087
+ })
1088
+ });
1089
+ }
1090
+ //#endregion
1091
+ //#region src/components/Query.tsx
1092
+ const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1093
+ const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1094
+ function buildQueryParamsNode(node, options) {
1095
+ const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
1096
+ const responseName = resolver.resolveResponseName(node);
1097
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
1098
+ const errorNames = resolveErrorNames(node, resolver);
1099
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1100
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1101
+ const optionsParam = _kubb_core.ast.createFunctionParameter({
1102
+ name: "options",
1103
+ type: _kubb_core.ast.createParamsType({
1104
+ variant: "reference",
1105
+ name: `{
1106
+ query?: Partial<QueryObserverOptions<${[
1107
+ TData,
1108
+ TError,
1109
+ "TData",
1110
+ "TQueryData",
1111
+ "TQueryKey"
1112
+ ].join(", ")}>> & { client?: QueryClient },
1113
+ client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1114
+ }`
1115
+ }),
1116
+ default: "{}"
1117
+ });
1118
+ return _kubb_core.ast.createOperationParams(node, {
1119
+ paramsType,
1120
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
1121
+ paramsCasing,
1122
+ resolver,
1123
+ extraParams: [optionsParam]
1124
+ });
1125
+ }
1126
+ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions }) {
1127
+ const responseName = tsResolver.resolveResponseName(node);
1128
+ const errorNames = resolveErrorNames(node, tsResolver);
1129
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1130
+ const returnType = `UseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
1131
+ const generics = [
1132
+ `TData = ${TData}`,
1133
+ `TQueryData = ${TData}`,
1134
+ `TQueryKey extends QueryKey = ${queryKeyTypeName}`
1135
+ ];
1136
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
1137
+ pathParamsType,
1138
+ paramsCasing,
1139
+ resolver: tsResolver
1140
+ });
1141
+ const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
1142
+ const queryOptionsParamsNode = getQueryOptionsParams(node, {
1143
+ paramsType,
1144
+ paramsCasing,
1145
+ pathParamsType,
1146
+ resolver: tsResolver
1147
+ });
1148
+ const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
1149
+ const paramsNode = buildQueryParamsNode(node, {
1150
+ paramsType,
1151
+ paramsCasing,
1152
+ pathParamsType,
1153
+ dataReturnType,
1154
+ resolver: tsResolver
1155
+ });
1156
+ const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
1157
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1158
+ name,
1159
+ isExportable: true,
1160
+ isIndexable: true,
1161
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1162
+ name,
1163
+ export: true,
1164
+ generics: generics.join(", "),
1165
+ params: paramsSignature,
1166
+ returnType: void 0,
1167
+ JSDoc: { comments: buildOperationComments(node) },
1168
+ children: `
1169
+ const { query: queryConfig = {}, client: config = {} } = options ?? {}
1170
+ const { client: queryClient, ...resolvedOptions } = queryConfig
1171
+ const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
1172
+ ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1173
+
1174
+ const query = useQuery({
1175
+ ...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
1176
+ ...resolvedOptions,
1177
+ queryKey,
1178
+ } as unknown as QueryObserverOptions, queryClient) as ${returnType}
1179
+
1180
+ query.queryKey = queryKey as TQueryKey
1181
+
1182
+ return query
1183
+ `
1184
+ })
1185
+ });
1186
+ }
1187
+ //#endregion
1188
+ //#region src/components/SuspenseInfiniteQuery.tsx
1189
+ const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1190
+ const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1191
+ function buildSuspenseInfiniteQueryParamsNode(node, options) {
1192
+ const { paramsType, paramsCasing, pathParamsType, resolver, pageParamGeneric } = options;
1193
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
1194
+ const optionsParam = _kubb_core.ast.createFunctionParameter({
1195
+ name: "options",
1196
+ type: _kubb_core.ast.createParamsType({
1197
+ variant: "reference",
1198
+ name: `{
1199
+ query?: Partial<UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
1200
+ client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1201
+ }`
1202
+ }),
1203
+ default: "{}"
1204
+ });
1205
+ return _kubb_core.ast.createOperationParams(node, {
1206
+ paramsType,
1207
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
1208
+ paramsCasing,
1209
+ resolver,
1210
+ extraParams: [optionsParam]
1211
+ });
1212
+ }
1213
+ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions, initialPageParam, queryParam }) {
1214
+ const responseName = tsResolver.resolveResponseName(node);
1215
+ const errorNames = resolveErrorNames(node, tsResolver);
1216
+ const responseType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1217
+ const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1218
+ const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
1219
+ const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
1220
+ const parts = initialPageParam.split(" as ");
1221
+ return parts[parts.length - 1] ?? "unknown";
1222
+ })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
1223
+ const rawQueryParams = getOperationParameters(node).query;
1224
+ const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
1225
+ const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
1226
+ return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : void 0;
1227
+ })() : void 0;
1228
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : void 0;
1229
+ const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
1230
+ const returnType = "UseSuspenseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
1231
+ const generics = [
1232
+ `TQueryFnData = ${responseType}`,
1233
+ `TError = ${errorType}`,
1234
+ "TData = InfiniteData<TQueryFnData>",
1235
+ `TQueryKey extends QueryKey = ${queryKeyTypeName}`,
1236
+ `TPageParam = ${pageParamType}`
1237
+ ];
1238
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
1239
+ pathParamsType,
1240
+ paramsCasing,
1241
+ resolver: tsResolver
1242
+ });
1243
+ const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
1244
+ const queryOptionsParamsNode = getQueryOptionsParams(node, {
1245
+ paramsType,
1246
+ paramsCasing,
1247
+ pathParamsType,
1248
+ resolver: tsResolver
1249
+ });
1250
+ const queryOptionsParamsCall = callPrinter$2.print(queryOptionsParamsNode) ?? "";
1251
+ const paramsNode = buildSuspenseInfiniteQueryParamsNode(node, {
1252
+ paramsType,
1253
+ paramsCasing,
1254
+ pathParamsType,
1255
+ dataReturnType,
1256
+ resolver: tsResolver,
1257
+ pageParamGeneric: "TPageParam"
1258
+ });
1259
+ const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
1260
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1261
+ name,
1262
+ isExportable: true,
1263
+ isIndexable: true,
1264
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1265
+ name,
1266
+ export: true,
1267
+ generics: generics.join(", "),
1268
+ params: paramsSignature,
1269
+ returnType: void 0,
1270
+ JSDoc: { comments: buildOperationComments(node) },
1271
+ children: `
1272
+ const { query: queryConfig = {}, client: config = {} } = options ?? {}
1273
+ const { client: queryClient, ...resolvedOptions } = queryConfig
1274
+ const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
1275
+ ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1276
+
1277
+ const query = useSuspenseInfiniteQuery({
1278
+ ...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
1279
+ ...resolvedOptions,
1280
+ queryKey,
1281
+ } as unknown as UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
1282
+
1283
+ query.queryKey = queryKey as TQueryKey
1284
+
1285
+ return query
1286
+ `
1287
+ })
1288
+ });
1289
+ }
1290
+ //#endregion
1291
+ //#region src/components/SuspenseInfiniteQueryOptions.tsx
1292
+ const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1293
+ const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1294
+ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
1295
+ const responseName = tsResolver.resolveResponseName(node);
1296
+ const queryFnDataType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1297
+ const errorNames = resolveErrorNames(node, tsResolver);
1298
+ const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1299
+ const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
1300
+ const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
1301
+ const parts = initialPageParam.split(" as ");
1302
+ return parts[parts.length - 1] ?? "unknown";
1303
+ })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
1304
+ const rawQueryParams = getOperationParameters(node).query;
1305
+ const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
1306
+ const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
1307
+ return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : void 0;
1308
+ })() : void 0;
1309
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : void 0;
1310
+ const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
1311
+ const paramsNode = getQueryOptionsParams(node, {
1312
+ paramsType,
1313
+ paramsCasing,
1314
+ pathParamsType,
1315
+ resolver: tsResolver
1316
+ });
1317
+ const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
1318
+ const clientCallStr = (callPrinter$1.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
1319
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
1320
+ pathParamsType,
1321
+ paramsCasing,
1322
+ resolver: tsResolver
1323
+ });
1324
+ const queryKeyParamsCall = callPrinter$1.print(queryKeyParamsNode) ?? "";
1325
+ const enabledSource = buildEnabledCheck(queryKeyParamsNode);
1326
+ const enabledText = enabledSource ? `enabled: !!(${enabledSource}),` : "";
1327
+ const hasNewParams = nextParam !== void 0 || previousParam !== void 0;
1328
+ let getNextPageParamExpr;
1329
+ let getPreviousPageParamExpr;
1330
+ if (hasNewParams) {
1331
+ if (nextParam) {
1332
+ const accessor = getNestedAccessor(nextParam, "lastPage");
1333
+ if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
1334
+ }
1335
+ if (previousParam) {
1336
+ const accessor = getNestedAccessor(previousParam, "firstPage");
1337
+ if (accessor) getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`;
1338
+ }
1339
+ } else if (cursorParam) {
1340
+ getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
1341
+ getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
1342
+ } else {
1343
+ if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
1344
+ else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
1345
+ getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
1346
+ }
1347
+ const queryOptionsArr = [
1348
+ `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
1349
+ getNextPageParamExpr,
1350
+ getPreviousPageParamExpr
1351
+ ].filter(Boolean);
1352
+ const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
1353
+ params = {
1354
+ ...(params ?? {}),
1355
+ ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
1356
+ } as ${queryParamsTypeName}` : "";
1357
+ if (infiniteOverrideParams) return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1358
+ name,
1359
+ isExportable: true,
1360
+ isIndexable: true,
1361
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1362
+ name,
1363
+ export: true,
1364
+ params: paramsSignature,
1365
+ children: `
1366
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1367
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1368
+ ${enabledText}
1369
+ queryKey,
1370
+ queryFn: async ({ signal, pageParam }) => {
1371
+ ${infiniteOverrideParams}
1372
+ return ${clientName}(${clientCallStr})
1373
+ },
1374
+ ${queryOptionsArr.join(",\n")}
1375
+ })
1376
+ `
1377
+ })
1378
+ });
1379
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1380
+ name,
1381
+ isExportable: true,
1382
+ isIndexable: true,
1383
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1384
+ name,
1385
+ export: true,
1386
+ params: paramsSignature,
1387
+ children: `
1388
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1389
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1390
+ ${enabledText}
1391
+ queryKey,
1392
+ queryFn: async ({ signal }) => {
1393
+ return ${clientName}(${clientCallStr})
1394
+ },
1395
+ ${queryOptionsArr.join(",\n")}
1396
+ })
1397
+ `
1398
+ })
1399
+ });
1400
+ }
1401
+ //#endregion
1402
+ //#region src/components/SuspenseQuery.tsx
1403
+ const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1404
+ const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1405
+ function buildSuspenseQueryParamsNode(node, options) {
1406
+ const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
1407
+ const responseName = resolver.resolveResponseName(node);
1408
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
1409
+ const errorNames = resolveErrorNames(node, resolver);
1410
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1411
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1412
+ const optionsParam = _kubb_core.ast.createFunctionParameter({
1413
+ name: "options",
1414
+ type: _kubb_core.ast.createParamsType({
1415
+ variant: "reference",
1416
+ name: `{
1417
+ query?: Partial<UseSuspenseQueryOptions<${[
1418
+ TData,
1419
+ TError,
1420
+ "TData",
1421
+ "TQueryKey"
1422
+ ].join(", ")}>> & { client?: QueryClient },
1423
+ client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1424
+ }`
1425
+ }),
1426
+ default: "{}"
1427
+ });
1428
+ return _kubb_core.ast.createOperationParams(node, {
1429
+ paramsType,
1430
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
1431
+ paramsCasing,
1432
+ resolver,
1433
+ extraParams: [optionsParam]
1434
+ });
1435
+ }
1436
+ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver, customOptions }) {
1437
+ const responseName = tsResolver.resolveResponseName(node);
1438
+ const errorNames = resolveErrorNames(node, tsResolver);
1439
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1440
+ const returnType = `UseSuspenseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
1441
+ const generics = [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
1442
+ const queryKeyParamsNode = buildQueryKeyParams(node, {
1443
+ pathParamsType,
1444
+ paramsCasing,
1445
+ resolver: tsResolver
1446
+ });
1447
+ const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
1448
+ const queryOptionsParamsNode = getQueryOptionsParams(node, {
1449
+ paramsType,
1450
+ paramsCasing,
1451
+ pathParamsType,
1452
+ resolver: tsResolver
1453
+ });
1454
+ const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
1455
+ const paramsNode = buildSuspenseQueryParamsNode(node, {
1456
+ paramsType,
1457
+ paramsCasing,
1458
+ pathParamsType,
1459
+ dataReturnType,
1460
+ resolver: tsResolver
1461
+ });
1462
+ const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1463
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1464
+ name,
1465
+ isExportable: true,
1466
+ isIndexable: true,
1467
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1468
+ name,
1469
+ export: true,
1470
+ generics: generics.join(", "),
1471
+ params: paramsSignature,
1472
+ returnType: void 0,
1473
+ JSDoc: { comments: buildOperationComments(node) },
1474
+ children: `
1475
+ const { query: queryConfig = {}, client: config = {} } = options ?? {}
1476
+ const { client: queryClient, ...resolvedOptions } = queryConfig
1477
+ const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyParamsCall})
1478
+ ${customOptions ? `const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1479
+
1480
+ const query = useSuspenseQuery({
1481
+ ...${queryOptionsName}(${queryOptionsParamsCall}),${customOptions ? "\n...customOptions," : ""}
1482
+ ...resolvedOptions,
1483
+ queryKey,
1484
+ } as unknown as UseSuspenseQueryOptions, queryClient) as ${returnType}
1485
+
1486
+ query.queryKey = queryKey as TQueryKey
1487
+
1488
+ return query
1489
+ `
1490
+ })
1491
+ });
1492
+ }
1493
+ //#endregion
1494
+ Object.defineProperty(exports, "InfiniteQuery", {
1495
+ enumerable: true,
1496
+ get: function() {
1497
+ return InfiniteQuery;
1498
+ }
1499
+ });
1500
+ Object.defineProperty(exports, "InfiniteQueryOptions", {
1501
+ enumerable: true,
1502
+ get: function() {
1503
+ return InfiniteQueryOptions;
1504
+ }
1505
+ });
1506
+ Object.defineProperty(exports, "Mutation", {
1507
+ enumerable: true,
1508
+ get: function() {
1509
+ return Mutation;
1510
+ }
1511
+ });
1512
+ Object.defineProperty(exports, "MutationKey", {
1513
+ enumerable: true,
1514
+ get: function() {
1515
+ return MutationKey;
1516
+ }
1517
+ });
1518
+ Object.defineProperty(exports, "MutationOptions", {
1519
+ enumerable: true,
1520
+ get: function() {
1521
+ return MutationOptions;
1522
+ }
1523
+ });
1524
+ Object.defineProperty(exports, "Query", {
1525
+ enumerable: true,
1526
+ get: function() {
1527
+ return Query;
1528
+ }
1529
+ });
1530
+ Object.defineProperty(exports, "QueryKey", {
1531
+ enumerable: true,
1532
+ get: function() {
1533
+ return QueryKey;
1534
+ }
1535
+ });
1536
+ Object.defineProperty(exports, "QueryOptions", {
1537
+ enumerable: true,
1538
+ get: function() {
1539
+ return QueryOptions;
1540
+ }
1541
+ });
1542
+ Object.defineProperty(exports, "SuspenseInfiniteQuery", {
1543
+ enumerable: true,
1544
+ get: function() {
1545
+ return SuspenseInfiniteQuery;
1546
+ }
1547
+ });
1548
+ Object.defineProperty(exports, "SuspenseInfiniteQueryOptions", {
1549
+ enumerable: true,
1550
+ get: function() {
1551
+ return SuspenseInfiniteQueryOptions;
1552
+ }
1553
+ });
1554
+ Object.defineProperty(exports, "SuspenseQuery", {
1555
+ enumerable: true,
1556
+ get: function() {
1557
+ return SuspenseQuery;
1558
+ }
1559
+ });
1560
+ Object.defineProperty(exports, "__name", {
1561
+ enumerable: true,
1562
+ get: function() {
1563
+ return __name;
1564
+ }
1565
+ });
1566
+ Object.defineProperty(exports, "__toESM", {
1567
+ enumerable: true,
1568
+ get: function() {
1569
+ return __toESM;
1570
+ }
1571
+ });
1572
+ Object.defineProperty(exports, "camelCase", {
1573
+ enumerable: true,
1574
+ get: function() {
1575
+ return camelCase;
1576
+ }
1577
+ });
1578
+ Object.defineProperty(exports, "getOperationParameters", {
1579
+ enumerable: true,
1580
+ get: function() {
1581
+ return getOperationParameters;
1582
+ }
1583
+ });
1584
+ Object.defineProperty(exports, "mutationKeyTransformer", {
1585
+ enumerable: true,
1586
+ get: function() {
1587
+ return mutationKeyTransformer;
1588
+ }
1589
+ });
1590
+ Object.defineProperty(exports, "queryKeyTransformer", {
1591
+ enumerable: true,
1592
+ get: function() {
1593
+ return queryKeyTransformer;
1594
+ }
1595
+ });
1596
+ Object.defineProperty(exports, "resolveOperationOverrides", {
1597
+ enumerable: true,
1598
+ get: function() {
1599
+ return resolveOperationOverrides;
1600
+ }
1601
+ });
1602
+ Object.defineProperty(exports, "resolveOperationTypeNames", {
1603
+ enumerable: true,
1604
+ get: function() {
1605
+ return resolveOperationTypeNames;
1606
+ }
1607
+ });
1608
+ Object.defineProperty(exports, "resolveZodSchemaNames", {
1609
+ enumerable: true,
1610
+ get: function() {
1611
+ return resolveZodSchemaNames;
1612
+ }
1613
+ });
1614
+
1615
+ //# sourceMappingURL=components-BZ3a2O0G.cjs.map