@kubb/plugin-vue-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 (47) hide show
  1. package/LICENSE +17 -10
  2. package/README.md +26 -7
  3. package/dist/components-1cEftHJm.cjs +1276 -0
  4. package/dist/components-1cEftHJm.cjs.map +1 -0
  5. package/dist/components-DTSvTMEo.js +1162 -0
  6. package/dist/components-DTSvTMEo.js.map +1 -0
  7. package/dist/components.cjs +1 -1
  8. package/dist/components.d.ts +66 -121
  9. package/dist/components.js +1 -1
  10. package/dist/generators-BEiWCS-U.cjs +698 -0
  11. package/dist/generators-BEiWCS-U.cjs.map +1 -0
  12. package/dist/generators-F6_EduRU.js +681 -0
  13. package/dist/generators-F6_EduRU.js.map +1 -0
  14. package/dist/generators.cjs +1 -1
  15. package/dist/generators.d.ts +5 -501
  16. package/dist/generators.js +1 -1
  17. package/dist/index.cjs +150 -121
  18. package/dist/index.cjs.map +1 -1
  19. package/dist/index.d.ts +4 -4
  20. package/dist/index.js +146 -121
  21. package/dist/index.js.map +1 -1
  22. package/dist/types-Bkm7bWT3.d.ts +243 -0
  23. package/extension.yaml +749 -0
  24. package/package.json +60 -65
  25. package/src/components/InfiniteQuery.tsx +71 -159
  26. package/src/components/InfiniteQueryOptions.tsx +120 -163
  27. package/src/components/Mutation.tsx +97 -134
  28. package/src/components/Query.tsx +68 -157
  29. package/src/components/QueryKey.tsx +23 -66
  30. package/src/components/QueryOptions.tsx +97 -143
  31. package/src/generators/infiniteQueryGenerator.tsx +152 -171
  32. package/src/generators/mutationGenerator.tsx +102 -125
  33. package/src/generators/queryGenerator.tsx +125 -137
  34. package/src/index.ts +1 -1
  35. package/src/plugin.ts +126 -177
  36. package/src/resolvers/resolverVueQuery.ts +65 -0
  37. package/src/types.ts +121 -52
  38. package/src/utils.ts +49 -0
  39. package/dist/components-Yjoe78Y7.cjs +0 -1119
  40. package/dist/components-Yjoe78Y7.cjs.map +0 -1
  41. package/dist/components-_AMBl0g-.js +0 -1029
  42. package/dist/components-_AMBl0g-.js.map +0 -1
  43. package/dist/generators-CR34GjVu.js +0 -661
  44. package/dist/generators-CR34GjVu.js.map +0 -1
  45. package/dist/generators-DH8VkK1q.cjs +0 -678
  46. package/dist/generators-DH8VkK1q.cjs.map +0 -1
  47. package/dist/types-CgDFUvfZ.d.ts +0 -211
@@ -0,0 +1,1276 @@
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$7 = (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$7.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
+ /**
461
+ * Collects the Zod schema import names for an operation (response + request body).
462
+ *
463
+ * Returns an empty array when no resolver is provided or the operation has no request body schema.
464
+ */
465
+ function resolveZodSchemaNames(node, zodResolver) {
466
+ if (!zodResolver) return [];
467
+ return [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : void 0].filter((n) => Boolean(n));
468
+ }
469
+ /**
470
+ * Resolve the type for a single path parameter.
471
+ *
472
+ * - When the resolver's group name differs from the individual param name
473
+ * (e.g. kubbV4) → `GroupName['paramName']` (member access).
474
+ * - When they match (v5 default) → `TypeName` (direct reference).
475
+ */
476
+ function resolvePathParamType(node, param, resolver) {
477
+ const individualName = resolver.resolveParamName(node, param);
478
+ const groupName = resolver.resolvePathParamsName(node, param);
479
+ if (groupName !== individualName) return _kubb_core.ast.createParamsType({
480
+ variant: "member",
481
+ base: groupName,
482
+ key: param.name
483
+ });
484
+ return _kubb_core.ast.createParamsType({
485
+ variant: "reference",
486
+ name: individualName
487
+ });
488
+ }
489
+ /**
490
+ * Derive a query-params group type from the resolver.
491
+ * Returns `undefined` when no query params exist or when the group name
492
+ * equals the individual param name (no real group).
493
+ */
494
+ function resolveQueryGroupType(node, params, resolver) {
495
+ if (!params.length) return void 0;
496
+ const firstParam = params[0];
497
+ const groupName = resolver.resolveQueryParamsName(node, firstParam);
498
+ if (groupName === resolver.resolveParamName(node, firstParam)) return void 0;
499
+ return {
500
+ type: _kubb_core.ast.createParamsType({
501
+ variant: "reference",
502
+ name: groupName
503
+ }),
504
+ optional: params.every((p) => !p.required)
505
+ };
506
+ }
507
+ /**
508
+ * Build a single `FunctionParameterNode` for a query or header group.
509
+ */
510
+ function buildGroupParam(name, node, params, groupType, resolver) {
511
+ if (groupType) return [_kubb_core.ast.createFunctionParameter({
512
+ name,
513
+ type: groupType.type,
514
+ optional: groupType.optional
515
+ })];
516
+ if (params.length) {
517
+ const structProps = params.map((p) => ({
518
+ name: p.name,
519
+ type: _kubb_core.ast.createParamsType({
520
+ variant: "reference",
521
+ name: resolver.resolveParamName(node, p)
522
+ }),
523
+ optional: !p.required
524
+ }));
525
+ return [_kubb_core.ast.createFunctionParameter({
526
+ name,
527
+ type: _kubb_core.ast.createParamsType({
528
+ variant: "struct",
529
+ properties: structProps
530
+ }),
531
+ optional: params.every((p) => !p.required)
532
+ })];
533
+ }
534
+ return [];
535
+ }
536
+ /**
537
+ * Build QueryKey params: pathParams + data + queryParams (NO headers, NO config).
538
+ */
539
+ function buildQueryKeyParams(node, options) {
540
+ const { pathParamsType, paramsCasing, resolver } = options;
541
+ const casedParams = _kubb_core.ast.caseParams(node.parameters, paramsCasing);
542
+ const pathParams = casedParams.filter((p) => p.in === "path");
543
+ const queryParams = casedParams.filter((p) => p.in === "query");
544
+ const queryGroupType = resolveQueryGroupType(node, queryParams, resolver);
545
+ const bodyType = node.requestBody?.content?.[0]?.schema ? _kubb_core.ast.createParamsType({
546
+ variant: "reference",
547
+ name: resolver.resolveDataName(node)
548
+ }) : void 0;
549
+ const bodyRequired = node.requestBody?.required ?? false;
550
+ const params = [];
551
+ if (pathParams.length) {
552
+ const pathChildren = pathParams.map((p) => _kubb_core.ast.createFunctionParameter({
553
+ name: p.name,
554
+ type: resolvePathParamType(node, p, resolver),
555
+ optional: !p.required
556
+ }));
557
+ params.push({
558
+ kind: "ParameterGroup",
559
+ properties: pathChildren,
560
+ inline: pathParamsType === "inline",
561
+ default: pathChildren.every((c) => c.optional) ? "{}" : void 0
562
+ });
563
+ }
564
+ if (bodyType) params.push(_kubb_core.ast.createFunctionParameter({
565
+ name: "data",
566
+ type: bodyType,
567
+ optional: !bodyRequired
568
+ }));
569
+ params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
570
+ return _kubb_core.ast.createFunctionParameters({ params });
571
+ }
572
+ function buildEnabledCheck(paramsNode) {
573
+ const required = [];
574
+ for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
575
+ const group = param;
576
+ for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
577
+ } else {
578
+ const fp = param;
579
+ if (!fp.optional && fp.default === void 0) required.push(fp.name);
580
+ }
581
+ return required.join(" && ");
582
+ }
583
+ (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
584
+ const queryKeyTransformer = ({ node, casing }) => {
585
+ const path = new URLPath(node.path, { casing });
586
+ const hasQueryParams = getOperationParameters(node).query.length > 0;
587
+ const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
588
+ return [
589
+ path.toObject({
590
+ type: "path",
591
+ stringify: true
592
+ }),
593
+ hasQueryParams ? "...(params ? [params] : [])" : void 0,
594
+ hasRequestBody ? "...(data ? [data] : [])" : void 0
595
+ ].filter(Boolean);
596
+ };
597
+ //#endregion
598
+ //#region src/utils.ts
599
+ function printType(typeNode) {
600
+ if (!typeNode) return "unknown";
601
+ if (typeNode.variant === "reference") return typeNode.name;
602
+ if (typeNode.variant === "member") return `${typeNode.base}['${typeNode.key}']`;
603
+ if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
604
+ const typeStr = printType(p.type);
605
+ const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
606
+ return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
607
+ }).join("; ")} }`;
608
+ return "unknown";
609
+ }
610
+ function wrapWithMaybeRefOrGetter(paramsNode, skip) {
611
+ const wrappedParams = paramsNode.params.map((param) => {
612
+ if ("kind" in param && param.kind === "ParameterGroup") {
613
+ const group = param;
614
+ return {
615
+ ...group,
616
+ properties: group.properties.map((p) => ({
617
+ ...p,
618
+ type: p.type ? _kubb_core.ast.createParamsType({
619
+ variant: "reference",
620
+ name: `MaybeRefOrGetter<${printType(p.type)}>`
621
+ }) : p.type
622
+ }))
623
+ };
624
+ }
625
+ const fp = param;
626
+ if (skip?.(fp.name)) return fp;
627
+ return {
628
+ ...fp,
629
+ type: fp.type ? _kubb_core.ast.createParamsType({
630
+ variant: "reference",
631
+ name: `MaybeRefOrGetter<${printType(fp.type)}>`
632
+ }) : fp.type
633
+ };
634
+ });
635
+ return _kubb_core.ast.createFunctionParameters({ params: wrappedParams });
636
+ }
637
+ //#endregion
638
+ //#region src/components/QueryKey.tsx
639
+ const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
640
+ function buildQueryKeyParamsNode(node, options) {
641
+ return wrapWithMaybeRefOrGetter(buildQueryKeyParams(node, options));
642
+ }
643
+ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer = queryKeyTransformer }) {
644
+ const paramsNode = buildQueryKeyParamsNode(node, {
645
+ pathParamsType,
646
+ paramsCasing,
647
+ resolver: tsResolver
648
+ });
649
+ const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
650
+ const keys = transformer({
651
+ node,
652
+ casing: paramsCasing
653
+ });
654
+ 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, {
655
+ name,
656
+ isExportable: true,
657
+ isIndexable: true,
658
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function.Arrow, {
659
+ name,
660
+ export: true,
661
+ params: paramsSignature,
662
+ singleLine: true,
663
+ children: `[${keys.join(", ")}] as const`
664
+ })
665
+ }), /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
666
+ name: typeName,
667
+ isExportable: true,
668
+ isIndexable: true,
669
+ isTypeOnly: true,
670
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Type, {
671
+ name: typeName,
672
+ export: true,
673
+ children: `ReturnType<typeof ${name}>`
674
+ })
675
+ })] });
676
+ }
677
+ //#endregion
678
+ //#region src/components/QueryOptions.tsx
679
+ const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
680
+ const callPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
681
+ function getQueryOptionsParams(node, options) {
682
+ const { paramsType, paramsCasing, pathParamsType, resolver } = options;
683
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
684
+ return wrapWithMaybeRefOrGetter(_kubb_core.ast.createOperationParams(node, {
685
+ paramsType,
686
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
687
+ paramsCasing,
688
+ resolver,
689
+ extraParams: [_kubb_core.ast.createFunctionParameter({
690
+ name: "config",
691
+ type: _kubb_core.ast.createParamsType({
692
+ variant: "reference",
693
+ name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
694
+ }),
695
+ default: "{}"
696
+ })]
697
+ }), (name) => name === "config");
698
+ }
699
+ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
700
+ const responseName = tsResolver.resolveResponseName(node);
701
+ const errorNames = resolveErrorNames(node, tsResolver);
702
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
703
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
704
+ const paramsNode = getQueryOptionsParams(node, {
705
+ paramsType,
706
+ paramsCasing,
707
+ pathParamsType,
708
+ resolver: tsResolver
709
+ });
710
+ const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
711
+ const clientCallStr = (callPrinter$4.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
712
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
713
+ pathParamsType,
714
+ paramsCasing,
715
+ resolver: tsResolver
716
+ });
717
+ const queryKeyParamsCall = callPrinter$4.print(queryKeyParamsNode) ?? "";
718
+ const enabledSource = buildEnabledCheck(queryKeyParamsNode);
719
+ const enabledText = enabledSource ? `enabled: () => ${enabledSource.split(" && ").map((n) => `!!toValue(${n.trim()})`).join(" && ")},` : "";
720
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
721
+ name,
722
+ isExportable: true,
723
+ isIndexable: true,
724
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
725
+ name,
726
+ export: true,
727
+ params: paramsSignature,
728
+ children: `
729
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
730
+ return queryOptions<${TData}, ${TError}, ${TData}>({
731
+ ${enabledText}
732
+ queryKey,
733
+ queryFn: async ({ signal }) => {
734
+ return ${clientName}(${addToValueCalls$1(clientCallStr)})
735
+ },
736
+ })
737
+ `
738
+ })
739
+ });
740
+ }
741
+ /**
742
+ * Wraps parameter names with `toValue()` in the client call string,
743
+ * except for 'config'-related params (which are already plain objects).
744
+ *
745
+ * Handles both inline params (`petId, config`) and object shorthand
746
+ * params (`{ petId }, config`) by expanding to `{ petId: toValue(petId) }`.
747
+ */
748
+ function addToValueCalls$1(callStr) {
749
+ let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
750
+ if (inner.includes(":") || inner.includes("...")) return match;
751
+ return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${k})`).join(", ")} }`;
752
+ });
753
+ result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => {
754
+ if (name === "config" || name === "signal" || name === "undefined") return match;
755
+ if (match.includes("toValue(")) return match;
756
+ return `toValue(${name})`;
757
+ });
758
+ return result;
759
+ }
760
+ __name(addToValueCalls$1, "addToValueCalls");
761
+ //#endregion
762
+ //#region src/components/InfiniteQuery.tsx
763
+ const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
764
+ const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
765
+ function buildInfiniteQueryParamsNode(node, options) {
766
+ const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
767
+ const responseName = resolver.resolveResponseName(node);
768
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
769
+ const errorNames = resolveErrorNames(node, resolver);
770
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
771
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
772
+ const optionsParam = _kubb_core.ast.createFunctionParameter({
773
+ name: "options",
774
+ type: _kubb_core.ast.createParamsType({
775
+ variant: "reference",
776
+ name: `{
777
+ query?: Partial<UseInfiniteQueryOptions<${[
778
+ TData,
779
+ TError,
780
+ "TQueryData",
781
+ "TQueryKey",
782
+ "TQueryData"
783
+ ].join(", ")}>> & { client?: QueryClient },
784
+ client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
785
+ }`
786
+ }),
787
+ default: "{}"
788
+ });
789
+ return wrapWithMaybeRefOrGetter(_kubb_core.ast.createOperationParams(node, {
790
+ paramsType,
791
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
792
+ paramsCasing,
793
+ resolver,
794
+ extraParams: [optionsParam]
795
+ }), (name) => name === "options");
796
+ }
797
+ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
798
+ const responseName = tsResolver.resolveResponseName(node);
799
+ const errorNames = resolveErrorNames(node, tsResolver);
800
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
801
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
802
+ const returnType = `UseInfiniteQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
803
+ const generics = [
804
+ `TData = InfiniteData<${TData}>`,
805
+ `TQueryData = ${TData}`,
806
+ `TQueryKey extends QueryKey = ${queryKeyTypeName}`
807
+ ];
808
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
809
+ pathParamsType,
810
+ paramsCasing,
811
+ resolver: tsResolver
812
+ });
813
+ const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
814
+ const queryOptionsParamsNode = getQueryOptionsParams(node, {
815
+ paramsType,
816
+ paramsCasing,
817
+ pathParamsType,
818
+ resolver: tsResolver
819
+ });
820
+ const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
821
+ const paramsNode = buildInfiniteQueryParamsNode(node, {
822
+ paramsType,
823
+ paramsCasing,
824
+ pathParamsType,
825
+ dataReturnType,
826
+ resolver: tsResolver
827
+ });
828
+ const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
829
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
830
+ name,
831
+ isExportable: true,
832
+ isIndexable: true,
833
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
834
+ name,
835
+ export: true,
836
+ generics: generics.join(", "),
837
+ params: paramsSignature,
838
+ JSDoc: { comments: buildOperationComments(node) },
839
+ children: `
840
+ const { query: queryConfig = {}, client: config = {} } = options ?? {}
841
+ const { client: queryClient, ...resolvedOptions } = queryConfig
842
+ const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParamsCall})
843
+
844
+ const query = useInfiniteQuery({
845
+ ...${queryOptionsName}(${queryOptionsParamsCall}),
846
+ ...resolvedOptions,
847
+ queryKey
848
+ } as unknown as UseInfiniteQueryOptions<${TData}, ${TError}, ${TData}, TQueryKey, ${TData}>, toValue(queryClient)) as ${returnType}
849
+
850
+ query.queryKey = queryKey as TQueryKey
851
+
852
+ return query
853
+ `
854
+ })
855
+ });
856
+ }
857
+ //#endregion
858
+ //#region src/components/InfiniteQueryOptions.tsx
859
+ const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
860
+ const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
861
+ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
862
+ const responseName = tsResolver.resolveResponseName(node);
863
+ const queryFnDataType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
864
+ const errorNames = resolveErrorNames(node, tsResolver);
865
+ const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
866
+ const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
867
+ const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
868
+ const parts = initialPageParam.split(" as ");
869
+ return parts[parts.length - 1] ?? "unknown";
870
+ })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
871
+ const rawQueryParams = getOperationParameters(node).query;
872
+ const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
873
+ const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
874
+ return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : void 0;
875
+ })() : void 0;
876
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : void 0;
877
+ const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
878
+ const paramsNode = getQueryOptionsParams(node, {
879
+ paramsType,
880
+ paramsCasing,
881
+ pathParamsType,
882
+ resolver: tsResolver
883
+ });
884
+ const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
885
+ const clientCallStr = (callPrinter$2.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
886
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
887
+ pathParamsType,
888
+ paramsCasing,
889
+ resolver: tsResolver
890
+ });
891
+ const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
892
+ const enabledSource = buildEnabledCheck(queryKeyParamsNode);
893
+ const enabledText = enabledSource ? `enabled: () => ${enabledSource.split(" && ").map((n) => `!!toValue(${n.trim()})`).join(" && ")},` : "";
894
+ const hasNewParams = nextParam !== void 0 || previousParam !== void 0;
895
+ let getNextPageParamExpr;
896
+ let getPreviousPageParamExpr;
897
+ if (hasNewParams) {
898
+ if (nextParam) {
899
+ const accessor = getNestedAccessor(nextParam, "lastPage");
900
+ if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
901
+ }
902
+ if (previousParam) {
903
+ const accessor = getNestedAccessor(previousParam, "firstPage");
904
+ if (accessor) getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`;
905
+ }
906
+ } else if (cursorParam) {
907
+ getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
908
+ getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
909
+ } else {
910
+ if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
911
+ else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
912
+ getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
913
+ }
914
+ const queryOptionsArr = [
915
+ `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
916
+ getNextPageParamExpr,
917
+ getPreviousPageParamExpr
918
+ ].filter(Boolean);
919
+ const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
920
+ params = {
921
+ ...(params ?? {}),
922
+ ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
923
+ } as ${queryParamsTypeName}` : "";
924
+ if (infiniteOverrideParams) return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
925
+ name,
926
+ isExportable: true,
927
+ isIndexable: true,
928
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
929
+ name,
930
+ export: true,
931
+ params: paramsSignature,
932
+ children: `
933
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
934
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, QueryKey, ${pageParamType}>({
935
+ ${enabledText}
936
+ queryKey,
937
+ queryFn: async ({ signal, pageParam }) => {
938
+ ${infiniteOverrideParams}
939
+ return ${clientName}(${addToValueCalls(clientCallStr)})
940
+ },
941
+ ${queryOptionsArr.join(",\n")}
942
+ })
943
+ `
944
+ })
945
+ });
946
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
947
+ name,
948
+ isExportable: true,
949
+ isIndexable: true,
950
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
951
+ name,
952
+ export: true,
953
+ params: paramsSignature,
954
+ children: `
955
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
956
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, QueryKey, ${pageParamType}>({
957
+ ${enabledText}
958
+ queryKey,
959
+ queryFn: async ({ signal }) => {
960
+ return ${clientName}(${addToValueCalls(clientCallStr)})
961
+ },
962
+ ${queryOptionsArr.join(",\n")}
963
+ })
964
+ `
965
+ })
966
+ });
967
+ }
968
+ function addToValueCalls(callStr) {
969
+ let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
970
+ if (inner.includes(":") || inner.includes("...")) return match;
971
+ return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${k})`).join(", ")} }`;
972
+ });
973
+ result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => {
974
+ if (name === "config" || name === "signal" || name === "undefined") return match;
975
+ if (match.includes("toValue(")) return match;
976
+ return `toValue(${name})`;
977
+ });
978
+ return result;
979
+ }
980
+ //#endregion
981
+ //#region src/components/Mutation.tsx
982
+ const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
983
+ const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
984
+ const keysPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "keys" });
985
+ function createMutationArgParams(node, options) {
986
+ return _kubb_core.ast.createOperationParams(node, {
987
+ paramsType: "inline",
988
+ pathParamsType: "inline",
989
+ paramsCasing: options.paramsCasing,
990
+ resolver: options.resolver
991
+ });
992
+ }
993
+ function buildMutationParamsNode(node, options) {
994
+ const { paramsCasing, dataReturnType, resolver } = options;
995
+ const responseName = resolver.resolveResponseName(node);
996
+ const errorNames = resolveErrorNames(node, resolver);
997
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
998
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
999
+ const wrappedParamsNode = wrapWithMaybeRefOrGetter(createMutationArgParams(node, {
1000
+ paramsCasing,
1001
+ resolver
1002
+ }));
1003
+ const TRequestWrapped = wrappedParamsNode.params.length > 0 ? declarationPrinter$1.print(wrappedParamsNode) ?? "" : "";
1004
+ return _kubb_core.ast.createFunctionParameters({ params: [_kubb_core.ast.createFunctionParameter({
1005
+ name: "options",
1006
+ type: _kubb_core.ast.createParamsType({
1007
+ variant: "reference",
1008
+ name: `{
1009
+ mutation?: MutationObserverOptions<${[
1010
+ TData,
1011
+ TError,
1012
+ TRequestWrapped ? `{${TRequestWrapped}}` : "void",
1013
+ "TContext"
1014
+ ].join(", ")}> & { client?: QueryClient },
1015
+ client?: ${buildRequestConfigType(node, resolver)},
1016
+ }`
1017
+ }),
1018
+ default: "{}"
1019
+ })] });
1020
+ }
1021
+ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType, dataReturnType, node, tsResolver, mutationKeyName }) {
1022
+ const responseName = tsResolver.resolveResponseName(node);
1023
+ const errorNames = resolveErrorNames(node, tsResolver);
1024
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1025
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1026
+ const mutationArgParamsNode = createMutationArgParams(node, {
1027
+ paramsCasing,
1028
+ resolver: tsResolver
1029
+ });
1030
+ const hasMutationParams = mutationArgParamsNode.params.length > 0;
1031
+ const TRequest = hasMutationParams ? declarationPrinter$1.print(mutationArgParamsNode) ?? "" : "";
1032
+ const argKeysStr = hasMutationParams ? keysPrinter.print(mutationArgParamsNode) ?? "" : "";
1033
+ const generics = [
1034
+ TData,
1035
+ TError,
1036
+ TRequest ? `{${TRequest}}` : "void",
1037
+ "TContext"
1038
+ ].join(", ");
1039
+ const mutationKeyParamsNode = _kubb_core.ast.createFunctionParameters({ params: [] });
1040
+ const mutationKeyParamsCall = callPrinter$1.print(mutationKeyParamsNode) ?? "";
1041
+ const clientCallParamsNode = _kubb_core.ast.createOperationParams(node, {
1042
+ paramsType,
1043
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
1044
+ paramsCasing,
1045
+ resolver: tsResolver,
1046
+ extraParams: [_kubb_core.ast.createFunctionParameter({
1047
+ name: "config",
1048
+ type: _kubb_core.ast.createParamsType({
1049
+ variant: "reference",
1050
+ name: buildRequestConfigType(node, tsResolver)
1051
+ }),
1052
+ default: "{}"
1053
+ })]
1054
+ });
1055
+ const clientCallStr = callPrinter$1.print(clientCallParamsNode) ?? "";
1056
+ const paramsNode = buildMutationParamsNode(node, {
1057
+ paramsCasing,
1058
+ dataReturnType,
1059
+ resolver: tsResolver
1060
+ });
1061
+ const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
1062
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1063
+ name,
1064
+ isExportable: true,
1065
+ isIndexable: true,
1066
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1067
+ name,
1068
+ export: true,
1069
+ params: paramsSignature,
1070
+ JSDoc: { comments: buildOperationComments(node) },
1071
+ generics: ["TContext"],
1072
+ children: `
1073
+ const { mutation = {}, client: config = {} } = options ?? {}
1074
+ const { client: queryClient, ...mutationOptions } = mutation;
1075
+ const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}(${mutationKeyParamsCall})
1076
+
1077
+ return useMutation<${generics}>({
1078
+ mutationFn: async(${hasMutationParams ? `{ ${argKeysStr} }` : ""}) => {
1079
+ return ${clientName}(${clientCallStr})
1080
+ },
1081
+ mutationKey,
1082
+ ...mutationOptions
1083
+ }, queryClient)
1084
+ `
1085
+ })
1086
+ });
1087
+ }
1088
+ //#endregion
1089
+ //#region src/components/Query.tsx
1090
+ const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1091
+ const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1092
+ function buildQueryParamsNode(node, options) {
1093
+ const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
1094
+ const responseName = resolver.resolveResponseName(node);
1095
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
1096
+ const errorNames = resolveErrorNames(node, resolver);
1097
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1098
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1099
+ const optionsParam = _kubb_core.ast.createFunctionParameter({
1100
+ name: "options",
1101
+ type: _kubb_core.ast.createParamsType({
1102
+ variant: "reference",
1103
+ name: `{
1104
+ query?: Partial<UseQueryOptions<${[
1105
+ TData,
1106
+ TError,
1107
+ "TData",
1108
+ "TQueryData",
1109
+ "TQueryKey"
1110
+ ].join(", ")}>> & { client?: QueryClient },
1111
+ client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1112
+ }`
1113
+ }),
1114
+ default: "{}"
1115
+ });
1116
+ return wrapWithMaybeRefOrGetter(_kubb_core.ast.createOperationParams(node, {
1117
+ paramsType,
1118
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
1119
+ paramsCasing,
1120
+ resolver,
1121
+ extraParams: [optionsParam]
1122
+ }), (name) => name === "options");
1123
+ }
1124
+ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
1125
+ const responseName = tsResolver.resolveResponseName(node);
1126
+ const errorNames = resolveErrorNames(node, tsResolver);
1127
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1128
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1129
+ const returnType = `UseQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
1130
+ const generics = [
1131
+ `TData = ${TData}`,
1132
+ `TQueryData = ${TData}`,
1133
+ `TQueryKey extends QueryKey = ${queryKeyTypeName}`
1134
+ ];
1135
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
1136
+ pathParamsType,
1137
+ paramsCasing,
1138
+ resolver: tsResolver
1139
+ });
1140
+ const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
1141
+ const queryOptionsParamsNode = getQueryOptionsParams(node, {
1142
+ paramsType,
1143
+ paramsCasing,
1144
+ pathParamsType,
1145
+ resolver: tsResolver
1146
+ });
1147
+ const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
1148
+ const paramsNode = buildQueryParamsNode(node, {
1149
+ paramsType,
1150
+ paramsCasing,
1151
+ pathParamsType,
1152
+ dataReturnType,
1153
+ resolver: tsResolver
1154
+ });
1155
+ const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1156
+ return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
1157
+ name,
1158
+ isExportable: true,
1159
+ isIndexable: true,
1160
+ children: /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.Function, {
1161
+ name,
1162
+ export: true,
1163
+ generics: generics.join(", "),
1164
+ params: paramsSignature,
1165
+ JSDoc: { comments: buildOperationComments(node) },
1166
+ children: `
1167
+ const { query: queryConfig = {}, client: config = {} } = options ?? {}
1168
+ const { client: queryClient, ...resolvedOptions } = queryConfig
1169
+ const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParamsCall})
1170
+
1171
+ const query = useQuery({
1172
+ ...${queryOptionsName}(${queryOptionsParamsCall}),
1173
+ ...resolvedOptions,
1174
+ queryKey
1175
+ } as unknown as UseQueryOptions<${TData}, ${TError}, TData, ${TData}, TQueryKey>, toValue(queryClient)) as ${returnType}
1176
+
1177
+ query.queryKey = queryKey as TQueryKey
1178
+
1179
+ return query
1180
+ `
1181
+ })
1182
+ });
1183
+ }
1184
+ //#endregion
1185
+ Object.defineProperty(exports, "InfiniteQuery", {
1186
+ enumerable: true,
1187
+ get: function() {
1188
+ return InfiniteQuery;
1189
+ }
1190
+ });
1191
+ Object.defineProperty(exports, "InfiniteQueryOptions", {
1192
+ enumerable: true,
1193
+ get: function() {
1194
+ return InfiniteQueryOptions;
1195
+ }
1196
+ });
1197
+ Object.defineProperty(exports, "Mutation", {
1198
+ enumerable: true,
1199
+ get: function() {
1200
+ return Mutation;
1201
+ }
1202
+ });
1203
+ Object.defineProperty(exports, "MutationKey", {
1204
+ enumerable: true,
1205
+ get: function() {
1206
+ return MutationKey;
1207
+ }
1208
+ });
1209
+ Object.defineProperty(exports, "Query", {
1210
+ enumerable: true,
1211
+ get: function() {
1212
+ return Query;
1213
+ }
1214
+ });
1215
+ Object.defineProperty(exports, "QueryKey", {
1216
+ enumerable: true,
1217
+ get: function() {
1218
+ return QueryKey;
1219
+ }
1220
+ });
1221
+ Object.defineProperty(exports, "QueryOptions", {
1222
+ enumerable: true,
1223
+ get: function() {
1224
+ return QueryOptions;
1225
+ }
1226
+ });
1227
+ Object.defineProperty(exports, "__name", {
1228
+ enumerable: true,
1229
+ get: function() {
1230
+ return __name;
1231
+ }
1232
+ });
1233
+ Object.defineProperty(exports, "__toESM", {
1234
+ enumerable: true,
1235
+ get: function() {
1236
+ return __toESM;
1237
+ }
1238
+ });
1239
+ Object.defineProperty(exports, "camelCase", {
1240
+ enumerable: true,
1241
+ get: function() {
1242
+ return camelCase;
1243
+ }
1244
+ });
1245
+ Object.defineProperty(exports, "getOperationParameters", {
1246
+ enumerable: true,
1247
+ get: function() {
1248
+ return getOperationParameters;
1249
+ }
1250
+ });
1251
+ Object.defineProperty(exports, "mutationKeyTransformer", {
1252
+ enumerable: true,
1253
+ get: function() {
1254
+ return mutationKeyTransformer;
1255
+ }
1256
+ });
1257
+ Object.defineProperty(exports, "queryKeyTransformer", {
1258
+ enumerable: true,
1259
+ get: function() {
1260
+ return queryKeyTransformer;
1261
+ }
1262
+ });
1263
+ Object.defineProperty(exports, "resolveOperationTypeNames", {
1264
+ enumerable: true,
1265
+ get: function() {
1266
+ return resolveOperationTypeNames;
1267
+ }
1268
+ });
1269
+ Object.defineProperty(exports, "resolveZodSchemaNames", {
1270
+ enumerable: true,
1271
+ get: function() {
1272
+ return resolveZodSchemaNames;
1273
+ }
1274
+ });
1275
+
1276
+ //# sourceMappingURL=components-1cEftHJm.cjs.map