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

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