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

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