@kubb/plugin-vue-query 5.0.0-alpha.8 → 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 -472
  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,1150 @@
1
+ import { t as __name } from "./chunk--u3MIqq1.js";
2
+ import { ast } from "@kubb/core";
3
+ import { functionPrinter } from "@kubb/plugin-ts";
4
+ import { File, Function, Type } from "@kubb/renderer-jsx";
5
+ import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
6
+ //#region ../../internals/utils/src/casing.ts
7
+ /**
8
+ * Shared implementation for camelCase and PascalCase conversion.
9
+ * Splits on common word boundaries (spaces, hyphens, underscores, dots, slashes, colons)
10
+ * and capitalizes each word according to `pascal`.
11
+ *
12
+ * When `pascal` is `true` the first word is also capitalized (PascalCase), otherwise only subsequent words are.
13
+ */
14
+ function toCamelOrPascal(text, pascal) {
15
+ 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) => {
16
+ if (word.length > 1 && word === word.toUpperCase()) return word;
17
+ if (i === 0 && !pascal) return word.charAt(0).toLowerCase() + word.slice(1);
18
+ return word.charAt(0).toUpperCase() + word.slice(1);
19
+ }).join("").replace(/[^a-zA-Z0-9]/g, "");
20
+ }
21
+ /**
22
+ * Splits `text` on `.` and applies `transformPart` to each segment.
23
+ * The last segment receives `isLast = true`, all earlier segments receive `false`.
24
+ * Segments are joined with `/` to form a file path.
25
+ *
26
+ * Only splits on dots followed by a letter so that version numbers
27
+ * embedded in operationIds (e.g. `v2025.0`) are kept intact.
28
+ */
29
+ function applyToFileParts(text, transformPart) {
30
+ const parts = text.split(/\.(?=[a-zA-Z])/);
31
+ return parts.map((part, i) => transformPart(part, i === parts.length - 1)).join("/");
32
+ }
33
+ /**
34
+ * Converts `text` to camelCase.
35
+ * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
36
+ *
37
+ * @example
38
+ * camelCase('hello-world') // 'helloWorld'
39
+ * camelCase('pet.petId', { isFile: true }) // 'pet/petId'
40
+ */
41
+ function camelCase(text, { isFile, prefix = "", suffix = "" } = {}) {
42
+ if (isFile) return applyToFileParts(text, (part, isLast) => camelCase(part, isLast ? {
43
+ prefix,
44
+ suffix
45
+ } : {}));
46
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
47
+ }
48
+ //#endregion
49
+ //#region ../../internals/utils/src/object.ts
50
+ /**
51
+ * Converts a dot-notation path or string array into an optional-chaining accessor expression.
52
+ *
53
+ * @example
54
+ * getNestedAccessor('pagination.next.id', 'lastPage')
55
+ * // → "lastPage?.['pagination']?.['next']?.['id']"
56
+ */
57
+ function getNestedAccessor(param, accessor) {
58
+ const parts = Array.isArray(param) ? param : param.split(".");
59
+ if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
60
+ return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
61
+ }
62
+ //#endregion
63
+ //#region ../../internals/utils/src/reserved.ts
64
+ /**
65
+ * JavaScript and Java reserved words.
66
+ * @link https://github.com/jonschlinkert/reserved/blob/master/index.js
67
+ */
68
+ const reservedWords = new Set([
69
+ "abstract",
70
+ "arguments",
71
+ "boolean",
72
+ "break",
73
+ "byte",
74
+ "case",
75
+ "catch",
76
+ "char",
77
+ "class",
78
+ "const",
79
+ "continue",
80
+ "debugger",
81
+ "default",
82
+ "delete",
83
+ "do",
84
+ "double",
85
+ "else",
86
+ "enum",
87
+ "eval",
88
+ "export",
89
+ "extends",
90
+ "false",
91
+ "final",
92
+ "finally",
93
+ "float",
94
+ "for",
95
+ "function",
96
+ "goto",
97
+ "if",
98
+ "implements",
99
+ "import",
100
+ "in",
101
+ "instanceof",
102
+ "int",
103
+ "interface",
104
+ "let",
105
+ "long",
106
+ "native",
107
+ "new",
108
+ "null",
109
+ "package",
110
+ "private",
111
+ "protected",
112
+ "public",
113
+ "return",
114
+ "short",
115
+ "static",
116
+ "super",
117
+ "switch",
118
+ "synchronized",
119
+ "this",
120
+ "throw",
121
+ "throws",
122
+ "transient",
123
+ "true",
124
+ "try",
125
+ "typeof",
126
+ "var",
127
+ "void",
128
+ "volatile",
129
+ "while",
130
+ "with",
131
+ "yield",
132
+ "Array",
133
+ "Date",
134
+ "hasOwnProperty",
135
+ "Infinity",
136
+ "isFinite",
137
+ "isNaN",
138
+ "isPrototypeOf",
139
+ "length",
140
+ "Math",
141
+ "name",
142
+ "NaN",
143
+ "Number",
144
+ "Object",
145
+ "prototype",
146
+ "String",
147
+ "toString",
148
+ "undefined",
149
+ "valueOf"
150
+ ]);
151
+ /**
152
+ * Returns `true` when `name` is a syntactically valid JavaScript variable name.
153
+ *
154
+ * @example
155
+ * ```ts
156
+ * isValidVarName('status') // true
157
+ * isValidVarName('class') // false (reserved word)
158
+ * isValidVarName('42foo') // false (starts with digit)
159
+ * ```
160
+ */
161
+ function isValidVarName(name) {
162
+ if (!name || reservedWords.has(name)) return false;
163
+ return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
164
+ }
165
+ //#endregion
166
+ //#region ../../internals/utils/src/urlPath.ts
167
+ /**
168
+ * Parses and transforms an OpenAPI/Swagger path string into various URL formats.
169
+ *
170
+ * @example
171
+ * const p = new URLPath('/pet/{petId}')
172
+ * p.URL // '/pet/:petId'
173
+ * p.template // '`/pet/${petId}`'
174
+ */
175
+ var URLPath = class {
176
+ /**
177
+ * The raw OpenAPI/Swagger path string, e.g. `/pet/{petId}`.
178
+ */
179
+ path;
180
+ #options;
181
+ constructor(path, options = {}) {
182
+ this.path = path;
183
+ this.#options = options;
184
+ }
185
+ /** Converts the OpenAPI path to Express-style colon syntax, e.g. `/pet/{petId}` → `/pet/:petId`.
186
+ *
187
+ * @example
188
+ * ```ts
189
+ * new URLPath('/pet/{petId}').URL // '/pet/:petId'
190
+ * ```
191
+ */
192
+ get URL() {
193
+ return this.toURLPath();
194
+ }
195
+ /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
196
+ *
197
+ * @example
198
+ * ```ts
199
+ * new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
200
+ * new URLPath('/pet/{petId}').isURL // false
201
+ * ```
202
+ */
203
+ get isURL() {
204
+ try {
205
+ return !!new URL(this.path).href;
206
+ } catch {
207
+ return false;
208
+ }
209
+ }
210
+ /**
211
+ * Converts the OpenAPI path to a TypeScript template literal string.
212
+ *
213
+ * @example
214
+ * new URLPath('/pet/{petId}').template // '`/pet/${petId}`'
215
+ * new URLPath('/account/monetary-accountID').template // '`/account/${monetaryAccountId}`'
216
+ */
217
+ get template() {
218
+ return this.toTemplateString();
219
+ }
220
+ /** Returns the path and its extracted params as a structured `URLObject`, or as a stringified expression when `stringify` is set.
221
+ *
222
+ * @example
223
+ * ```ts
224
+ * new URLPath('/pet/{petId}').object
225
+ * // { url: '/pet/:petId', params: { petId: 'petId' } }
226
+ * ```
227
+ */
228
+ get object() {
229
+ return this.toObject();
230
+ }
231
+ /** Returns a map of path parameter names, or `undefined` when the path has no parameters.
232
+ *
233
+ * @example
234
+ * ```ts
235
+ * new URLPath('/pet/{petId}').params // { petId: 'petId' }
236
+ * new URLPath('/pet').params // undefined
237
+ * ```
238
+ */
239
+ get params() {
240
+ return this.toParamsObject();
241
+ }
242
+ #transformParam(raw) {
243
+ const param = isValidVarName(raw) ? raw : camelCase(raw);
244
+ return this.#options.casing === "camelcase" ? camelCase(param) : param;
245
+ }
246
+ /**
247
+ * Iterates over every `{param}` token in `path`, calling `fn` with the raw token and transformed name.
248
+ */
249
+ #eachParam(fn) {
250
+ for (const match of this.path.matchAll(/\{([^}]+)\}/g)) {
251
+ const raw = match[1];
252
+ fn(raw, this.#transformParam(raw));
253
+ }
254
+ }
255
+ toObject({ type = "path", replacer, stringify } = {}) {
256
+ const object = {
257
+ url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
258
+ params: this.toParamsObject()
259
+ };
260
+ if (stringify) {
261
+ if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
262
+ if (object.params) return `{ url: '${object.url}', params: ${JSON.stringify(object.params).replaceAll("'", "").replaceAll(`"`, "")} }`;
263
+ return `{ url: '${object.url}' }`;
264
+ }
265
+ return object;
266
+ }
267
+ /**
268
+ * Converts the OpenAPI path to a TypeScript template literal string.
269
+ * An optional `replacer` can transform each extracted parameter name before interpolation.
270
+ *
271
+ * @example
272
+ * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
273
+ */
274
+ toTemplateString({ prefix = "", replacer } = {}) {
275
+ return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
276
+ if (i % 2 === 0) return part;
277
+ const param = this.#transformParam(part);
278
+ return `\${${replacer ? replacer(param) : param}}`;
279
+ }).join("")}\``;
280
+ }
281
+ /**
282
+ * Extracts all `{param}` segments from the path and returns them as a key-value map.
283
+ * An optional `replacer` transforms each parameter name in both key and value positions.
284
+ * Returns `undefined` when no path parameters are found.
285
+ *
286
+ * @example
287
+ * ```ts
288
+ * new URLPath('/pet/{petId}/tag/{tagId}').toParamsObject()
289
+ * // { petId: 'petId', tagId: 'tagId' }
290
+ * ```
291
+ */
292
+ toParamsObject(replacer) {
293
+ const params = {};
294
+ this.#eachParam((_raw, param) => {
295
+ const key = replacer ? replacer(param) : param;
296
+ params[key] = key;
297
+ });
298
+ return Object.keys(params).length > 0 ? params : void 0;
299
+ }
300
+ /** Converts the OpenAPI path to Express-style colon syntax.
301
+ *
302
+ * @example
303
+ * ```ts
304
+ * new URLPath('/pet/{petId}').toURLPath() // '/pet/:petId'
305
+ * ```
306
+ */
307
+ toURLPath() {
308
+ return this.path.replace(/\{([^}]+)\}/g, ":$1");
309
+ }
310
+ };
311
+ //#endregion
312
+ //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
313
+ const declarationPrinter$7 = functionPrinter({ mode: "declaration" });
314
+ const mutationKeyTransformer = ({ node, casing }) => {
315
+ return [`{ url: '${new URLPath(node.path, { casing }).toURLPath()}' }`];
316
+ };
317
+ function MutationKey({ name, paramsCasing, node, transformer = mutationKeyTransformer }) {
318
+ const paramsNode = ast.createFunctionParameters({ params: [] });
319
+ const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
320
+ const keys = transformer({
321
+ node,
322
+ casing: paramsCasing
323
+ });
324
+ return /* @__PURE__ */ jsx(File.Source, {
325
+ name,
326
+ isExportable: true,
327
+ isIndexable: true,
328
+ children: /* @__PURE__ */ jsx(Function.Arrow, {
329
+ name,
330
+ export: true,
331
+ params: paramsSignature,
332
+ singleLine: true,
333
+ children: `[${keys.join(", ")}] as const`
334
+ })
335
+ });
336
+ }
337
+ //#endregion
338
+ //#region ../../internals/shared/src/operation.ts
339
+ function getOperationLink(node, link) {
340
+ if (!link) return;
341
+ if (typeof link === "function") return link(node);
342
+ if (link === "urlPath") return node.path ? `{@link ${new URLPath(node.path).URL}}` : void 0;
343
+ return `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}`;
344
+ }
345
+ function getContentTypeInfo(node) {
346
+ const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
347
+ const isMultipleContentTypes = contentTypes.length > 1;
348
+ return {
349
+ contentTypes,
350
+ isMultipleContentTypes,
351
+ contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
352
+ defaultContentType: contentTypes[0] ?? "application/json",
353
+ hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
354
+ };
355
+ }
356
+ function buildRequestConfigType(node, resolver) {
357
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
358
+ const { isMultipleContentTypes, contentTypeUnion } = getContentTypeInfo(node);
359
+ return `${requestName ? `Partial<RequestConfig<${requestName}>>` : "Partial<RequestConfig>"} & { ${["client?: Client", isMultipleContentTypes ? `contentType?: ${contentTypeUnion}` : void 0].filter(Boolean).join("; ")} }`;
360
+ }
361
+ function buildOperationComments(node, options = {}) {
362
+ const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
363
+ const linkComment = getOperationLink(node, link);
364
+ const filteredComments = (linkPosition === "beforeDeprecated" ? [
365
+ node.description && `@description ${node.description}`,
366
+ node.summary && `@summary ${node.summary}`,
367
+ linkComment,
368
+ node.deprecated && "@deprecated"
369
+ ] : [
370
+ node.description && `@description ${node.description}`,
371
+ node.summary && `@summary ${node.summary}`,
372
+ node.deprecated && "@deprecated",
373
+ linkComment
374
+ ]).filter((comment) => Boolean(comment));
375
+ if (!splitLines) return filteredComments;
376
+ return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
377
+ }
378
+ function getOperationParameters(node, options = {}) {
379
+ const params = ast.caseParams(node.parameters, options.paramsCasing);
380
+ return {
381
+ path: params.filter((param) => param.in === "path"),
382
+ query: params.filter((param) => param.in === "query"),
383
+ header: params.filter((param) => param.in === "header"),
384
+ cookie: params.filter((param) => param.in === "cookie")
385
+ };
386
+ }
387
+ function getStatusCodeNumber(statusCode) {
388
+ const code = Number(statusCode);
389
+ return Number.isNaN(code) ? void 0 : code;
390
+ }
391
+ function isErrorStatusCode(statusCode) {
392
+ const code = getStatusCodeNumber(statusCode);
393
+ return code !== void 0 && code >= 400;
394
+ }
395
+ function resolveErrorNames(node, resolver) {
396
+ return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
397
+ }
398
+ function resolveStatusCodeNames(node, resolver) {
399
+ return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
400
+ }
401
+ function resolveOperationTypeNames(node, resolver, options = {}) {
402
+ const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
403
+ const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
404
+ const exclude = new Set(options.exclude ?? []);
405
+ const paramNames = [
406
+ ...path.map((param) => resolver.resolvePathParamsName(node, param)),
407
+ ...query.map((param) => resolver.resolveQueryParamsName(node, param)),
408
+ ...header.map((param) => resolver.resolveHeaderParamsName(node, param))
409
+ ];
410
+ const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0, resolver.resolveResponseName(node)];
411
+ return (options.order === "body-response-first" ? [
412
+ ...bodyAndResponseNames,
413
+ ...paramNames,
414
+ ...responseStatusNames
415
+ ] : [
416
+ ...paramNames,
417
+ ...bodyAndResponseNames,
418
+ ...responseStatusNames
419
+ ]).filter((name) => Boolean(name) && !exclude.has(name));
420
+ }
421
+ //#endregion
422
+ //#region ../../internals/tanstack-query/src/utils.ts
423
+ /**
424
+ * Collects the Zod schema import names for an operation (response + request body).
425
+ *
426
+ * Returns an empty array when no resolver is provided or the operation has no request body schema.
427
+ */
428
+ function resolveZodSchemaNames(node, zodResolver) {
429
+ if (!zodResolver) return [];
430
+ return [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : void 0].filter((n) => Boolean(n));
431
+ }
432
+ /**
433
+ * Resolve the type for a single path parameter.
434
+ *
435
+ * - When the resolver's group name differs from the individual param name
436
+ * (e.g. kubbV4) → `GroupName['paramName']` (member access).
437
+ * - When they match (v5 default) → `TypeName` (direct reference).
438
+ */
439
+ function resolvePathParamType(node, param, resolver) {
440
+ const individualName = resolver.resolveParamName(node, param);
441
+ const groupName = resolver.resolvePathParamsName(node, param);
442
+ if (groupName !== individualName) return ast.createParamsType({
443
+ variant: "member",
444
+ base: groupName,
445
+ key: param.name
446
+ });
447
+ return ast.createParamsType({
448
+ variant: "reference",
449
+ name: individualName
450
+ });
451
+ }
452
+ /**
453
+ * Derive a query-params group type from the resolver.
454
+ * Returns `undefined` when no query params exist or when the group name
455
+ * equals the individual param name (no real group).
456
+ */
457
+ function resolveQueryGroupType(node, params, resolver) {
458
+ if (!params.length) return void 0;
459
+ const firstParam = params[0];
460
+ const groupName = resolver.resolveQueryParamsName(node, firstParam);
461
+ if (groupName === resolver.resolveParamName(node, firstParam)) return void 0;
462
+ return {
463
+ type: ast.createParamsType({
464
+ variant: "reference",
465
+ name: groupName
466
+ }),
467
+ optional: params.every((p) => !p.required)
468
+ };
469
+ }
470
+ /**
471
+ * Build a single `FunctionParameterNode` for a query or header group.
472
+ */
473
+ function buildGroupParam(name, node, params, groupType, resolver) {
474
+ if (groupType) return [ast.createFunctionParameter({
475
+ name,
476
+ type: groupType.type,
477
+ optional: groupType.optional
478
+ })];
479
+ if (params.length) {
480
+ const structProps = params.map((p) => ({
481
+ name: p.name,
482
+ type: ast.createParamsType({
483
+ variant: "reference",
484
+ name: resolver.resolveParamName(node, p)
485
+ }),
486
+ optional: !p.required
487
+ }));
488
+ return [ast.createFunctionParameter({
489
+ name,
490
+ type: ast.createParamsType({
491
+ variant: "struct",
492
+ properties: structProps
493
+ }),
494
+ optional: params.every((p) => !p.required)
495
+ })];
496
+ }
497
+ return [];
498
+ }
499
+ /**
500
+ * Build QueryKey params: pathParams + data + queryParams (NO headers, NO config).
501
+ */
502
+ function buildQueryKeyParams(node, options) {
503
+ const { pathParamsType, paramsCasing, resolver } = options;
504
+ const casedParams = ast.caseParams(node.parameters, paramsCasing);
505
+ const pathParams = casedParams.filter((p) => p.in === "path");
506
+ const queryParams = casedParams.filter((p) => p.in === "query");
507
+ const queryGroupType = resolveQueryGroupType(node, queryParams, resolver);
508
+ const bodyType = node.requestBody?.content?.[0]?.schema ? ast.createParamsType({
509
+ variant: "reference",
510
+ name: resolver.resolveDataName(node)
511
+ }) : void 0;
512
+ const bodyRequired = node.requestBody?.required ?? false;
513
+ const params = [];
514
+ if (pathParams.length) {
515
+ const pathChildren = pathParams.map((p) => ast.createFunctionParameter({
516
+ name: p.name,
517
+ type: resolvePathParamType(node, p, resolver),
518
+ optional: !p.required
519
+ }));
520
+ params.push({
521
+ kind: "ParameterGroup",
522
+ properties: pathChildren,
523
+ inline: pathParamsType === "inline",
524
+ default: pathChildren.every((c) => c.optional) ? "{}" : void 0
525
+ });
526
+ }
527
+ if (bodyType) params.push(ast.createFunctionParameter({
528
+ name: "data",
529
+ type: bodyType,
530
+ optional: !bodyRequired
531
+ }));
532
+ params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
533
+ return ast.createFunctionParameters({ params });
534
+ }
535
+ function buildEnabledCheck(paramsNode) {
536
+ const required = [];
537
+ for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
538
+ const group = param;
539
+ for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
540
+ } else {
541
+ const fp = param;
542
+ if (!fp.optional && fp.default === void 0) required.push(fp.name);
543
+ }
544
+ return required.join(" && ");
545
+ }
546
+ functionPrinter({ mode: "declaration" });
547
+ const queryKeyTransformer = ({ node, casing }) => {
548
+ const path = new URLPath(node.path, { casing });
549
+ const hasQueryParams = getOperationParameters(node).query.length > 0;
550
+ const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
551
+ return [
552
+ path.toObject({
553
+ type: "path",
554
+ stringify: true
555
+ }),
556
+ hasQueryParams ? "...(params ? [params] : [])" : void 0,
557
+ hasRequestBody ? "...(data ? [data] : [])" : void 0
558
+ ].filter(Boolean);
559
+ };
560
+ //#endregion
561
+ //#region src/utils.ts
562
+ function printType(typeNode) {
563
+ if (!typeNode) return "unknown";
564
+ if (typeNode.variant === "reference") return typeNode.name;
565
+ if (typeNode.variant === "member") return `${typeNode.base}['${typeNode.key}']`;
566
+ if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
567
+ const typeStr = printType(p.type);
568
+ const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
569
+ return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
570
+ }).join("; ")} }`;
571
+ return "unknown";
572
+ }
573
+ function wrapWithMaybeRefOrGetter(paramsNode, skip) {
574
+ const wrappedParams = paramsNode.params.map((param) => {
575
+ if ("kind" in param && param.kind === "ParameterGroup") {
576
+ const group = param;
577
+ return {
578
+ ...group,
579
+ properties: group.properties.map((p) => ({
580
+ ...p,
581
+ type: p.type ? ast.createParamsType({
582
+ variant: "reference",
583
+ name: `MaybeRefOrGetter<${printType(p.type)}>`
584
+ }) : p.type
585
+ }))
586
+ };
587
+ }
588
+ const fp = param;
589
+ if (skip?.(fp.name)) return fp;
590
+ return {
591
+ ...fp,
592
+ type: fp.type ? ast.createParamsType({
593
+ variant: "reference",
594
+ name: `MaybeRefOrGetter<${printType(fp.type)}>`
595
+ }) : fp.type
596
+ };
597
+ });
598
+ return ast.createFunctionParameters({ params: wrappedParams });
599
+ }
600
+ //#endregion
601
+ //#region src/components/QueryKey.tsx
602
+ const declarationPrinter$5 = functionPrinter({ mode: "declaration" });
603
+ function buildQueryKeyParamsNode(node, options) {
604
+ return wrapWithMaybeRefOrGetter(buildQueryKeyParams(node, options));
605
+ }
606
+ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer = queryKeyTransformer }) {
607
+ const paramsNode = buildQueryKeyParamsNode(node, {
608
+ pathParamsType,
609
+ paramsCasing,
610
+ resolver: tsResolver
611
+ });
612
+ const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
613
+ const keys = transformer({
614
+ node,
615
+ casing: paramsCasing
616
+ });
617
+ return /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Source, {
618
+ name,
619
+ isExportable: true,
620
+ isIndexable: true,
621
+ children: /* @__PURE__ */ jsx(Function.Arrow, {
622
+ name,
623
+ export: true,
624
+ params: paramsSignature,
625
+ singleLine: true,
626
+ children: `[${keys.join(", ")}] as const`
627
+ })
628
+ }), /* @__PURE__ */ jsx(File.Source, {
629
+ name: typeName,
630
+ isExportable: true,
631
+ isIndexable: true,
632
+ isTypeOnly: true,
633
+ children: /* @__PURE__ */ jsx(Type, {
634
+ name: typeName,
635
+ export: true,
636
+ children: `ReturnType<typeof ${name}>`
637
+ })
638
+ })] });
639
+ }
640
+ //#endregion
641
+ //#region src/components/QueryOptions.tsx
642
+ const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
643
+ const callPrinter$4 = functionPrinter({ mode: "call" });
644
+ function getQueryOptionsParams(node, options) {
645
+ const { paramsType, paramsCasing, pathParamsType, resolver } = options;
646
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
647
+ return wrapWithMaybeRefOrGetter(ast.createOperationParams(node, {
648
+ paramsType,
649
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
650
+ paramsCasing,
651
+ resolver,
652
+ extraParams: [ast.createFunctionParameter({
653
+ name: "config",
654
+ type: ast.createParamsType({
655
+ variant: "reference",
656
+ name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
657
+ }),
658
+ default: "{}"
659
+ })]
660
+ }), (name) => name === "config");
661
+ }
662
+ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
663
+ const responseName = tsResolver.resolveResponseName(node);
664
+ const errorNames = resolveErrorNames(node, tsResolver);
665
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
666
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
667
+ const paramsNode = getQueryOptionsParams(node, {
668
+ paramsType,
669
+ paramsCasing,
670
+ pathParamsType,
671
+ resolver: tsResolver
672
+ });
673
+ const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
674
+ const clientCallStr = (callPrinter$4.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
675
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
676
+ pathParamsType,
677
+ paramsCasing,
678
+ resolver: tsResolver
679
+ });
680
+ const queryKeyParamsCall = callPrinter$4.print(queryKeyParamsNode) ?? "";
681
+ const enabledSource = buildEnabledCheck(queryKeyParamsNode);
682
+ const enabledText = enabledSource ? `enabled: () => !!(${enabledSource}),` : "";
683
+ return /* @__PURE__ */ jsx(File.Source, {
684
+ name,
685
+ isExportable: true,
686
+ isIndexable: true,
687
+ children: /* @__PURE__ */ jsx(Function, {
688
+ name,
689
+ export: true,
690
+ params: paramsSignature,
691
+ children: `
692
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
693
+ return queryOptions<${TData}, ${TError}, ${TData}>({
694
+ ${enabledText}
695
+ queryKey,
696
+ queryFn: async ({ signal }) => {
697
+ return ${clientName}(${addToValueCalls$1(clientCallStr)})
698
+ },
699
+ })
700
+ `
701
+ })
702
+ });
703
+ }
704
+ /**
705
+ * Wraps parameter names with `toValue()` in the client call string,
706
+ * except for 'config'-related params (which are already plain objects).
707
+ *
708
+ * Handles both inline params (`petId, config`) and object shorthand
709
+ * params (`{ petId }, config`) by expanding to `{ petId: toValue(petId) }`.
710
+ */
711
+ function addToValueCalls$1(callStr) {
712
+ let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
713
+ if (inner.includes(":") || inner.includes("...")) return match;
714
+ return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${k})`).join(", ")} }`;
715
+ });
716
+ result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => {
717
+ if (name === "config" || name === "signal" || name === "undefined") return match;
718
+ if (match.includes("toValue(")) return match;
719
+ return `toValue(${name})`;
720
+ });
721
+ return result;
722
+ }
723
+ __name(addToValueCalls$1, "addToValueCalls");
724
+ //#endregion
725
+ //#region src/components/InfiniteQuery.tsx
726
+ const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
727
+ const callPrinter$3 = functionPrinter({ mode: "call" });
728
+ function buildInfiniteQueryParamsNode(node, options) {
729
+ const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
730
+ const responseName = resolver.resolveResponseName(node);
731
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
732
+ const errorNames = resolveErrorNames(node, resolver);
733
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
734
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
735
+ const optionsParam = ast.createFunctionParameter({
736
+ name: "options",
737
+ type: ast.createParamsType({
738
+ variant: "reference",
739
+ name: `{
740
+ query?: Partial<UseInfiniteQueryOptions<${[
741
+ TData,
742
+ TError,
743
+ "TQueryData",
744
+ "TQueryKey",
745
+ "TQueryData"
746
+ ].join(", ")}>> & { client?: QueryClient },
747
+ client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
748
+ }`
749
+ }),
750
+ default: "{}"
751
+ });
752
+ return wrapWithMaybeRefOrGetter(ast.createOperationParams(node, {
753
+ paramsType,
754
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
755
+ paramsCasing,
756
+ resolver,
757
+ extraParams: [optionsParam]
758
+ }), (name) => name === "options");
759
+ }
760
+ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
761
+ const responseName = tsResolver.resolveResponseName(node);
762
+ const errorNames = resolveErrorNames(node, tsResolver);
763
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
764
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
765
+ const returnType = `UseInfiniteQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
766
+ const generics = [
767
+ `TData = InfiniteData<${TData}>`,
768
+ `TQueryData = ${TData}`,
769
+ `TQueryKey extends QueryKey = ${queryKeyTypeName}`
770
+ ];
771
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
772
+ pathParamsType,
773
+ paramsCasing,
774
+ resolver: tsResolver
775
+ });
776
+ const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
777
+ const queryOptionsParamsNode = getQueryOptionsParams(node, {
778
+ paramsType,
779
+ paramsCasing,
780
+ pathParamsType,
781
+ resolver: tsResolver
782
+ });
783
+ const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
784
+ const paramsNode = buildInfiniteQueryParamsNode(node, {
785
+ paramsType,
786
+ paramsCasing,
787
+ pathParamsType,
788
+ dataReturnType,
789
+ resolver: tsResolver
790
+ });
791
+ const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
792
+ return /* @__PURE__ */ jsx(File.Source, {
793
+ name,
794
+ isExportable: true,
795
+ isIndexable: true,
796
+ children: /* @__PURE__ */ jsx(Function, {
797
+ name,
798
+ export: true,
799
+ generics: generics.join(", "),
800
+ params: paramsSignature,
801
+ JSDoc: { comments: buildOperationComments(node) },
802
+ children: `
803
+ const { query: queryConfig = {}, client: config = {} } = options ?? {}
804
+ const { client: queryClient, ...resolvedOptions } = queryConfig
805
+ const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParamsCall})
806
+
807
+ const query = useInfiniteQuery({
808
+ ...${queryOptionsName}(${queryOptionsParamsCall}),
809
+ ...resolvedOptions,
810
+ queryKey
811
+ } as unknown as UseInfiniteQueryOptions<${TData}, ${TError}, ${TData}, TQueryKey, ${TData}>, toValue(queryClient)) as ${returnType}
812
+
813
+ query.queryKey = queryKey as TQueryKey
814
+
815
+ return query
816
+ `
817
+ })
818
+ });
819
+ }
820
+ //#endregion
821
+ //#region src/components/InfiniteQueryOptions.tsx
822
+ const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
823
+ const callPrinter$2 = functionPrinter({ mode: "call" });
824
+ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
825
+ const responseName = tsResolver.resolveResponseName(node);
826
+ const queryFnDataType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
827
+ const errorNames = resolveErrorNames(node, tsResolver);
828
+ const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
829
+ const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
830
+ const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
831
+ const parts = initialPageParam.split(" as ");
832
+ return parts[parts.length - 1] ?? "unknown";
833
+ })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
834
+ const rawQueryParams = getOperationParameters(node).query;
835
+ const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
836
+ const groupName = tsResolver.resolveQueryParamsName(node, rawQueryParams[0]);
837
+ return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : void 0;
838
+ })() : void 0;
839
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : void 0;
840
+ const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
841
+ const paramsNode = getQueryOptionsParams(node, {
842
+ paramsType,
843
+ paramsCasing,
844
+ pathParamsType,
845
+ resolver: tsResolver
846
+ });
847
+ const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
848
+ const clientCallStr = (callPrinter$2.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
849
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
850
+ pathParamsType,
851
+ paramsCasing,
852
+ resolver: tsResolver
853
+ });
854
+ const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
855
+ const enabledSource = buildEnabledCheck(queryKeyParamsNode);
856
+ const enabledText = enabledSource ? `enabled: () => !!(${enabledSource}),` : "";
857
+ const hasNewParams = nextParam !== void 0 || previousParam !== void 0;
858
+ let getNextPageParamExpr;
859
+ let getPreviousPageParamExpr;
860
+ if (hasNewParams) {
861
+ if (nextParam) {
862
+ const accessor = getNestedAccessor(nextParam, "lastPage");
863
+ if (accessor) getNextPageParamExpr = `getNextPageParam: (lastPage) => ${accessor}`;
864
+ }
865
+ if (previousParam) {
866
+ const accessor = getNestedAccessor(previousParam, "firstPage");
867
+ if (accessor) getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => ${accessor}`;
868
+ }
869
+ } else if (cursorParam) {
870
+ getNextPageParamExpr = `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
871
+ getPreviousPageParamExpr = `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
872
+ } else {
873
+ if (dataReturnType === "full") getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1";
874
+ else getNextPageParamExpr = "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
875
+ getPreviousPageParamExpr = "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1";
876
+ }
877
+ const queryOptionsArr = [
878
+ `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
879
+ getNextPageParamExpr,
880
+ getPreviousPageParamExpr
881
+ ].filter(Boolean);
882
+ const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
883
+ params = {
884
+ ...(params ?? {}),
885
+ ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
886
+ } as ${queryParamsTypeName}` : "";
887
+ if (infiniteOverrideParams) return /* @__PURE__ */ jsx(File.Source, {
888
+ name,
889
+ isExportable: true,
890
+ isIndexable: true,
891
+ children: /* @__PURE__ */ jsx(Function, {
892
+ name,
893
+ export: true,
894
+ params: paramsSignature,
895
+ children: `
896
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
897
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, QueryKey, ${pageParamType}>({
898
+ ${enabledText}
899
+ queryKey,
900
+ queryFn: async ({ signal, pageParam }) => {
901
+ ${infiniteOverrideParams}
902
+ return ${clientName}(${addToValueCalls(clientCallStr)})
903
+ },
904
+ ${queryOptionsArr.join(",\n")}
905
+ })
906
+ `
907
+ })
908
+ });
909
+ return /* @__PURE__ */ jsx(File.Source, {
910
+ name,
911
+ isExportable: true,
912
+ isIndexable: true,
913
+ children: /* @__PURE__ */ jsx(Function, {
914
+ name,
915
+ export: true,
916
+ params: paramsSignature,
917
+ children: `
918
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
919
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, QueryKey, ${pageParamType}>({
920
+ ${enabledText}
921
+ queryKey,
922
+ queryFn: async ({ signal }) => {
923
+ return ${clientName}(${addToValueCalls(clientCallStr)})
924
+ },
925
+ ${queryOptionsArr.join(",\n")}
926
+ })
927
+ `
928
+ })
929
+ });
930
+ }
931
+ function addToValueCalls(callStr) {
932
+ let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
933
+ if (inner.includes(":") || inner.includes("...")) return match;
934
+ return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${k})`).join(", ")} }`;
935
+ });
936
+ result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => {
937
+ if (name === "config" || name === "signal" || name === "undefined") return match;
938
+ if (match.includes("toValue(")) return match;
939
+ return `toValue(${name})`;
940
+ });
941
+ return result;
942
+ }
943
+ //#endregion
944
+ //#region src/components/Mutation.tsx
945
+ const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
946
+ const callPrinter$1 = functionPrinter({ mode: "call" });
947
+ const keysPrinter = functionPrinter({ mode: "keys" });
948
+ function createMutationArgParams(node, options) {
949
+ return ast.createOperationParams(node, {
950
+ paramsType: "inline",
951
+ pathParamsType: "inline",
952
+ paramsCasing: options.paramsCasing,
953
+ resolver: options.resolver
954
+ });
955
+ }
956
+ function buildMutationParamsNode(node, options) {
957
+ const { paramsCasing, dataReturnType, resolver } = options;
958
+ const responseName = resolver.resolveResponseName(node);
959
+ const errorNames = resolveErrorNames(node, resolver);
960
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
961
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
962
+ const wrappedParamsNode = wrapWithMaybeRefOrGetter(createMutationArgParams(node, {
963
+ paramsCasing,
964
+ resolver
965
+ }));
966
+ const TRequestWrapped = wrappedParamsNode.params.length > 0 ? declarationPrinter$1.print(wrappedParamsNode) ?? "" : "";
967
+ return ast.createFunctionParameters({ params: [ast.createFunctionParameter({
968
+ name: "options",
969
+ type: ast.createParamsType({
970
+ variant: "reference",
971
+ name: `{
972
+ mutation?: MutationObserverOptions<${[
973
+ TData,
974
+ TError,
975
+ TRequestWrapped ? `{${TRequestWrapped}}` : "void",
976
+ "TContext"
977
+ ].join(", ")}> & { client?: QueryClient },
978
+ client?: ${buildRequestConfigType(node, resolver)},
979
+ }`
980
+ }),
981
+ default: "{}"
982
+ })] });
983
+ }
984
+ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType, dataReturnType, node, tsResolver, mutationKeyName }) {
985
+ const responseName = tsResolver.resolveResponseName(node);
986
+ const errorNames = resolveErrorNames(node, tsResolver);
987
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
988
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
989
+ const mutationArgParamsNode = createMutationArgParams(node, {
990
+ paramsCasing,
991
+ resolver: tsResolver
992
+ });
993
+ const hasMutationParams = mutationArgParamsNode.params.length > 0;
994
+ const TRequest = hasMutationParams ? declarationPrinter$1.print(mutationArgParamsNode) ?? "" : "";
995
+ const argKeysStr = hasMutationParams ? keysPrinter.print(mutationArgParamsNode) ?? "" : "";
996
+ const generics = [
997
+ TData,
998
+ TError,
999
+ TRequest ? `{${TRequest}}` : "void",
1000
+ "TContext"
1001
+ ].join(", ");
1002
+ const mutationKeyParamsNode = ast.createFunctionParameters({ params: [] });
1003
+ const mutationKeyParamsCall = callPrinter$1.print(mutationKeyParamsNode) ?? "";
1004
+ const clientCallParamsNode = ast.createOperationParams(node, {
1005
+ paramsType,
1006
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
1007
+ paramsCasing,
1008
+ resolver: tsResolver,
1009
+ extraParams: [ast.createFunctionParameter({
1010
+ name: "config",
1011
+ type: ast.createParamsType({
1012
+ variant: "reference",
1013
+ name: buildRequestConfigType(node, tsResolver)
1014
+ }),
1015
+ default: "{}"
1016
+ })]
1017
+ });
1018
+ const clientCallStr = callPrinter$1.print(clientCallParamsNode) ?? "";
1019
+ const paramsNode = buildMutationParamsNode(node, {
1020
+ paramsCasing,
1021
+ dataReturnType,
1022
+ resolver: tsResolver
1023
+ });
1024
+ const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
1025
+ return /* @__PURE__ */ jsx(File.Source, {
1026
+ name,
1027
+ isExportable: true,
1028
+ isIndexable: true,
1029
+ children: /* @__PURE__ */ jsx(Function, {
1030
+ name,
1031
+ export: true,
1032
+ params: paramsSignature,
1033
+ JSDoc: { comments: buildOperationComments(node) },
1034
+ generics: ["TContext"],
1035
+ children: `
1036
+ const { mutation = {}, client: config = {} } = options ?? {}
1037
+ const { client: queryClient, ...mutationOptions } = mutation;
1038
+ const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}(${mutationKeyParamsCall})
1039
+
1040
+ return useMutation<${generics}>({
1041
+ mutationFn: async(${hasMutationParams ? `{ ${argKeysStr} }` : ""}) => {
1042
+ return ${clientName}(${clientCallStr})
1043
+ },
1044
+ mutationKey,
1045
+ ...mutationOptions
1046
+ }, queryClient)
1047
+ `
1048
+ })
1049
+ });
1050
+ }
1051
+ //#endregion
1052
+ //#region src/components/Query.tsx
1053
+ const declarationPrinter = functionPrinter({ mode: "declaration" });
1054
+ const callPrinter = functionPrinter({ mode: "call" });
1055
+ function buildQueryParamsNode(node, options) {
1056
+ const { paramsType, paramsCasing, pathParamsType, dataReturnType, resolver } = options;
1057
+ const responseName = resolver.resolveResponseName(node);
1058
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
1059
+ const errorNames = resolveErrorNames(node, resolver);
1060
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1061
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1062
+ const optionsParam = ast.createFunctionParameter({
1063
+ name: "options",
1064
+ type: ast.createParamsType({
1065
+ variant: "reference",
1066
+ name: `{
1067
+ query?: Partial<UseQueryOptions<${[
1068
+ TData,
1069
+ TError,
1070
+ "TData",
1071
+ "TQueryData",
1072
+ "TQueryKey"
1073
+ ].join(", ")}>> & { client?: QueryClient },
1074
+ client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"}
1075
+ }`
1076
+ }),
1077
+ default: "{}"
1078
+ });
1079
+ return wrapWithMaybeRefOrGetter(ast.createOperationParams(node, {
1080
+ paramsType,
1081
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
1082
+ paramsCasing,
1083
+ resolver,
1084
+ extraParams: [optionsParam]
1085
+ }), (name) => name === "options");
1086
+ }
1087
+ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
1088
+ const responseName = tsResolver.resolveResponseName(node);
1089
+ const errorNames = resolveErrorNames(node, tsResolver);
1090
+ const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1091
+ const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1092
+ const returnType = `UseQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
1093
+ const generics = [
1094
+ `TData = ${TData}`,
1095
+ `TQueryData = ${TData}`,
1096
+ `TQueryKey extends QueryKey = ${queryKeyTypeName}`
1097
+ ];
1098
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
1099
+ pathParamsType,
1100
+ paramsCasing,
1101
+ resolver: tsResolver
1102
+ });
1103
+ const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
1104
+ const queryOptionsParamsNode = getQueryOptionsParams(node, {
1105
+ paramsType,
1106
+ paramsCasing,
1107
+ pathParamsType,
1108
+ resolver: tsResolver
1109
+ });
1110
+ const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
1111
+ const paramsNode = buildQueryParamsNode(node, {
1112
+ paramsType,
1113
+ paramsCasing,
1114
+ pathParamsType,
1115
+ dataReturnType,
1116
+ resolver: tsResolver
1117
+ });
1118
+ const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1119
+ return /* @__PURE__ */ jsx(File.Source, {
1120
+ name,
1121
+ isExportable: true,
1122
+ isIndexable: true,
1123
+ children: /* @__PURE__ */ jsx(Function, {
1124
+ name,
1125
+ export: true,
1126
+ generics: generics.join(", "),
1127
+ params: paramsSignature,
1128
+ JSDoc: { comments: buildOperationComments(node) },
1129
+ children: `
1130
+ const { query: queryConfig = {}, client: config = {} } = options ?? {}
1131
+ const { client: queryClient, ...resolvedOptions } = queryConfig
1132
+ const queryKey = (resolvedOptions && 'queryKey' in resolvedOptions ? toValue(resolvedOptions.queryKey) : undefined) ?? ${queryKeyName}(${queryKeyParamsCall})
1133
+
1134
+ const query = useQuery({
1135
+ ...${queryOptionsName}(${queryOptionsParamsCall}),
1136
+ ...resolvedOptions,
1137
+ queryKey
1138
+ } as unknown as UseQueryOptions<${TData}, ${TError}, TData, ${TData}, TQueryKey>, toValue(queryClient)) as ${returnType}
1139
+
1140
+ query.queryKey = queryKey as TQueryKey
1141
+
1142
+ return query
1143
+ `
1144
+ })
1145
+ });
1146
+ }
1147
+ //#endregion
1148
+ export { QueryOptions as a, resolveZodSchemaNames as c, MutationKey as d, mutationKeyTransformer as f, InfiniteQuery as i, getOperationParameters as l, Mutation as n, QueryKey as o, camelCase as p, InfiniteQueryOptions as r, queryKeyTransformer as s, Query as t, resolveOperationTypeNames as u };
1149
+
1150
+ //# sourceMappingURL=components-B6jAb2as.js.map