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

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