@kubb/plugin-vue-query 5.0.0-beta.4 → 5.0.0-beta.56

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 (43) hide show
  1. package/README.md +39 -22
  2. package/dist/{components-D1UhYFgY.js → components-B79Gljyl.js} +483 -565
  3. package/dist/components-B79Gljyl.js.map +1 -0
  4. package/dist/{components-qfOFRSoM.cjs → components-D3xIZ9FA.cjs} +513 -565
  5. package/dist/components-D3xIZ9FA.cjs.map +1 -0
  6. package/dist/components.cjs +1 -1
  7. package/dist/components.d.ts +4 -68
  8. package/dist/components.js +1 -1
  9. package/dist/{generators-C4gs_P1i.cjs → generators-BTtcGtUY.cjs} +225 -314
  10. package/dist/generators-BTtcGtUY.cjs.map +1 -0
  11. package/dist/generators-D95ddIFV.js +620 -0
  12. package/dist/generators-D95ddIFV.js.map +1 -0
  13. package/dist/generators.cjs +1 -1
  14. package/dist/generators.d.ts +21 -6
  15. package/dist/generators.js +1 -1
  16. package/dist/index.cjs +158 -25
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.ts +31 -4
  19. package/dist/index.js +160 -27
  20. package/dist/index.js.map +1 -1
  21. package/dist/types-CwabLiFK.d.ts +266 -0
  22. package/package.json +18 -27
  23. package/src/components/InfiniteQuery.tsx +18 -50
  24. package/src/components/InfiniteQueryOptions.tsx +64 -82
  25. package/src/components/Mutation.tsx +35 -44
  26. package/src/components/Query.tsx +18 -51
  27. package/src/components/QueryKey.tsx +9 -61
  28. package/src/components/QueryOptions.tsx +22 -99
  29. package/src/generators/infiniteQueryGenerator.tsx +55 -67
  30. package/src/generators/mutationGenerator.tsx +53 -65
  31. package/src/generators/queryGenerator.tsx +52 -65
  32. package/src/plugin.ts +48 -32
  33. package/src/resolvers/resolverVueQuery.ts +63 -6
  34. package/src/types.ts +132 -60
  35. package/src/utils.ts +45 -25
  36. package/dist/components-D1UhYFgY.js.map +0 -1
  37. package/dist/components-qfOFRSoM.cjs.map +0 -1
  38. package/dist/generators-C4gs_P1i.cjs.map +0 -1
  39. package/dist/generators-CbnIVBgY.js +0 -709
  40. package/dist/generators-CbnIVBgY.js.map +0 -1
  41. package/dist/types-nVDTfuS1.d.ts +0 -194
  42. package/extension.yaml +0 -793
  43. /package/dist/{chunk--u3MIqq1.js → chunk-C0LytTxp.js} +0 -0
@@ -1,8 +1,9 @@
1
- import { t as __name } from "./chunk--u3MIqq1.js";
1
+ import { t as __name } from "./chunk-C0LytTxp.js";
2
2
  import { ast } from "@kubb/core";
3
3
  import { functionPrinter } from "@kubb/plugin-ts";
4
4
  import { File, Function, Type } from "@kubb/renderer-jsx";
5
5
  import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
6
+ import { getNestedAccessor } from "@kubb/ast/utils";
6
7
  //#region ../../internals/utils/src/casing.ts
7
8
  /**
8
9
  * Shared implementation for camelCase and PascalCase conversion.
@@ -14,50 +15,20 @@ import { Fragment, jsx, jsxs } from "@kubb/renderer-jsx/jsx-runtime";
14
15
  function toCamelOrPascal(text, pascal) {
15
16
  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
17
  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);
18
+ return (i === 0 && !pascal ? word.charAt(0).toLowerCase() : word.charAt(0).toUpperCase()) + word.slice(1);
19
19
  }).join("").replace(/[^a-zA-Z0-9]/g, "");
20
20
  }
21
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
22
  * Converts `text` to camelCase.
35
- * When `isFile` is `true`, dot-separated segments are each cased independently and joined with `/`.
36
23
  *
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.
24
+ * @example Word boundaries
25
+ * `camelCase('hello-world') // 'helloWorld'`
52
26
  *
53
- * @example
54
- * getNestedAccessor('pagination.next.id', 'lastPage')
55
- * // → "lastPage?.['pagination']?.['next']?.['id']"
27
+ * @example With a prefix
28
+ * `camelCase('tag', { prefix: 'create' }) // 'createTag'`
56
29
  */
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("']?.['")}']`}`;
30
+ function camelCase(text, { prefix = "", suffix = "" } = {}) {
31
+ return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
61
32
  }
62
33
  //#endregion
63
34
  //#region ../../internals/utils/src/reserved.ts
@@ -163,99 +134,80 @@ function isValidVarName(name) {
163
134
  return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
164
135
  }
165
136
  //#endregion
166
- //#region ../../internals/utils/src/urlPath.ts
137
+ //#region ../../internals/utils/src/url.ts
138
+ function transformParam(raw, casing) {
139
+ const param = isValidVarName(raw) ? raw : camelCase(raw);
140
+ return casing === "camelcase" ? camelCase(param) : param;
141
+ }
142
+ function toParamsObject(path, { replacer, casing } = {}) {
143
+ const params = {};
144
+ for (const match of path.matchAll(/\{([^}]+)\}/g)) {
145
+ const param = transformParam(match[1], casing);
146
+ const key = replacer ? replacer(param) : param;
147
+ params[key] = key;
148
+ }
149
+ return Object.keys(params).length > 0 ? params : null;
150
+ }
167
151
  /**
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}`'
152
+ * Helpers for OpenAPI/Swagger paths, plus a thin wrapper over the native `URL`.
174
153
  */
175
- var URLPath = class {
154
+ var Url = class Url {
176
155
  /**
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`.
156
+ * Reports whether `url` is a parseable absolute URL. Delegates to the native `URL.canParse`.
186
157
  *
187
158
  * @example
188
- * ```ts
189
- * new URLPath('/pet/{petId}').URL // '/pet/:petId'
190
- * ```
159
+ * Url.canParse('https://petstore.swagger.io/v2') // true
160
+ * Url.canParse('/pet/{petId}') // false
191
161
  */
192
- get URL() {
193
- return this.toURLPath();
162
+ static canParse(url, base) {
163
+ return URL.canParse(url, base);
194
164
  }
195
- /** Returns `true` when `path` is a fully-qualified URL (e.g. starts with `https://`).
165
+ /**
166
+ * Converts an OpenAPI/Swagger path to Express-style colon syntax.
196
167
  *
197
168
  * @example
198
- * ```ts
199
- * new URLPath('https://petstore.swagger.io/v2/pet').isURL // true
200
- * new URLPath('/pet/{petId}').isURL // false
201
- * ```
169
+ * Url.toPath('/pet/{petId}') // '/pet/:petId'
202
170
  */
203
- get isURL() {
204
- try {
205
- return !!new URL(this.path).href;
206
- } catch {
207
- return false;
208
- }
171
+ static toPath(path) {
172
+ return path.replace(/\{([^}]+)\}/g, ":$1");
209
173
  }
210
174
  /**
211
- * Converts the OpenAPI path to a TypeScript template literal string.
175
+ * Converts an OpenAPI/Swagger path to a TypeScript template literal string.
176
+ * `prefix` is prepended inside the literal, `replacer` transforms each parameter name,
177
+ * and `casing` controls parameter identifier casing.
212
178
  *
213
179
  * @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.
180
+ * Url.toTemplateString('/pet/{petId}') // '`/pet/${petId}`'
221
181
  *
222
182
  * @example
223
- * ```ts
224
- * new URLPath('/pet/{petId}').object
225
- * // { url: '/pet/:petId', params: { petId: 'petId' } }
226
- * ```
183
+ * Url.toTemplateString('/pet/{petId}', { prefix: 'https://api' }) // '`https://api/pet/${petId}`'
227
184
  */
228
- get object() {
229
- return this.toObject();
185
+ static toTemplateString(path, { prefix, replacer, casing } = {}) {
186
+ const result = path.split(/\{([^}]+)\}/).map((part, i) => {
187
+ if (i % 2 === 0) return part;
188
+ const param = transformParam(part, casing);
189
+ return `\${${replacer ? replacer(param) : param}}`;
190
+ }).join("");
191
+ return `\`${prefix ?? ""}${result}\``;
230
192
  }
231
- /** Returns a map of path parameter names, or `undefined` when the path has no parameters.
193
+ /**
194
+ * Returns the path and its extracted params as a structured `URLObject`, or as a stringified
195
+ * expression when `stringify` is set.
232
196
  *
233
197
  * @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.
198
+ * Url.toObject('/pet/{petId}')
199
+ * // { url: '/pet/:petId', params: { petId: 'petId' } }
248
200
  */
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 } = {}) {
201
+ static toObject(path, { type = "path", replacer, stringify, casing } = {}) {
256
202
  const object = {
257
- url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
258
- params: this.getParams()
203
+ url: type === "path" ? Url.toPath(path) : Url.toTemplateString(path, {
204
+ replacer,
205
+ casing
206
+ }),
207
+ params: toParamsObject(path, {
208
+ replacer,
209
+ casing
210
+ })
259
211
  };
260
212
  if (stringify) {
261
213
  if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
@@ -264,64 +216,153 @@ var URLPath = class {
264
216
  }
265
217
  return object;
266
218
  }
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
219
  };
311
220
  //#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: [] });
221
+ //#region ../../internals/shared/src/operation.ts
222
+ /**
223
+ * Builds the `ResolverFileParams` every operation generator passes to
224
+ * `resolver.resolveFile`: a file named `name`, tagged by the operation's first
225
+ * tag (or `'default'`), at the operation's path. Centralizes the entry object
226
+ * that was repeated at dozens of call sites across the client and query plugins.
227
+ *
228
+ * @example
229
+ * ```ts
230
+ * resolver.resolveFile(operationFileEntry(node, node.operationId), { root, output, group })
231
+ * ```
232
+ */
233
+ function operationFileEntry(node, name, extname = ".ts") {
234
+ return {
235
+ name,
236
+ extname,
237
+ tag: node.tags[0] ?? "default",
238
+ path: node.path
239
+ };
240
+ }
241
+ function getOperationLink(node, link) {
242
+ if (!link) return null;
243
+ if (typeof link === "function") return link(node) ?? null;
244
+ if (link === "urlPath") return node.path ? `{@link ${Url.toPath(node.path)}}` : null;
245
+ return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
316
246
  }
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({
247
+ function getContentTypeInfo(node) {
248
+ const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
249
+ const isMultipleContentTypes = contentTypes.length > 1;
250
+ return {
251
+ contentTypes,
252
+ isMultipleContentTypes,
253
+ contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
254
+ defaultContentType: contentTypes[0] ?? "application/json",
255
+ hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
256
+ };
257
+ }
258
+ function buildRequestConfigType(node, resolver) {
259
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
260
+ const { isMultipleContentTypes, contentTypeUnion } = getContentTypeInfo(node);
261
+ return `${requestName ? `Partial<RequestConfig<${requestName}>>` : "Partial<RequestConfig>"} & { ${["client?: Client", isMultipleContentTypes ? `contentType?: ${contentTypeUnion}` : null].filter(Boolean).join("; ")} }`;
262
+ }
263
+ function buildOperationComments(node, options = {}) {
264
+ const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
265
+ const linkComment = getOperationLink(node, link);
266
+ const filteredComments = (linkPosition === "beforeDeprecated" ? [
267
+ node.description && `@description ${node.description}`,
268
+ node.summary && `@summary ${node.summary}`,
269
+ linkComment,
270
+ node.deprecated && "@deprecated"
271
+ ] : [
272
+ node.description && `@description ${node.description}`,
273
+ node.summary && `@summary ${node.summary}`,
274
+ node.deprecated && "@deprecated",
275
+ linkComment
276
+ ]).filter((comment) => Boolean(comment));
277
+ if (!splitLines) return filteredComments;
278
+ return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
279
+ }
280
+ function getOperationParameters(node, options = {}) {
281
+ const params = ast.caseParams(node.parameters, options.paramsCasing);
282
+ return {
283
+ path: params.filter((param) => param.in === "path"),
284
+ query: params.filter((param) => param.in === "query"),
285
+ header: params.filter((param) => param.in === "header"),
286
+ cookie: params.filter((param) => param.in === "cookie")
287
+ };
288
+ }
289
+ function getStatusCodeNumber(statusCode) {
290
+ const code = Number(statusCode);
291
+ return Number.isNaN(code) ? null : code;
292
+ }
293
+ function isSuccessStatusCode(statusCode) {
294
+ const code = getStatusCodeNumber(statusCode);
295
+ return code !== null && code >= 200 && code < 300;
296
+ }
297
+ function isErrorStatusCode(statusCode) {
298
+ const code = getStatusCodeNumber(statusCode);
299
+ return code !== null && code >= 400;
300
+ }
301
+ function resolveErrorNames(node, resolver) {
302
+ return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
303
+ }
304
+ function resolveSuccessNames(node, resolver) {
305
+ return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
306
+ }
307
+ function resolveStatusCodeNames(node, resolver) {
308
+ return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
309
+ }
310
+ /**
311
+ * Builds the discriminated union type string for `dataReturnType: 'full'` return shapes.
312
+ * Each member is `{ status: N; data: StatusNType; statusText: string }`.
313
+ */
314
+ function buildStatusUnionType(node, resolver) {
315
+ const members = node.responses.map((r) => {
316
+ const typeName = resolver.resolveResponseStatusName(node, r.statusCode);
317
+ const statusCode = Number.parseInt(r.statusCode, 10);
318
+ return `{ status: ${Number.isNaN(statusCode) ? "number" : String(statusCode)}; data: ${typeName}; statusText: string }`;
319
+ });
320
+ if (members.length === 1) return members[0];
321
+ return `(${members.join(" | ")})`;
322
+ }
323
+ const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
324
+ function resolveOperationTypeNames(node, resolver, options = {}) {
325
+ const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
326
+ let byResolver = typeNamesByResolver.get(resolver);
327
+ if (byResolver) {
328
+ const cached = byResolver.get(cacheKey);
329
+ if (cached) return cached;
330
+ } else {
331
+ byResolver = /* @__PURE__ */ new Map();
332
+ typeNamesByResolver.set(resolver, byResolver);
333
+ }
334
+ const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
335
+ const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
336
+ const exclude = new Set(options.exclude ?? []);
337
+ const paramNames = [
338
+ ...path.map((param) => resolver.resolvePathParamsName(node, param)),
339
+ ...query.map((param) => resolver.resolveQueryParamsName(node, param)),
340
+ ...header.map((param) => resolver.resolveHeaderParamsName(node, param))
341
+ ];
342
+ const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null, resolver.resolveResponseName(node)];
343
+ const result = (options.order === "body-response-first" ? [
344
+ ...bodyAndResponseNames,
345
+ ...paramNames,
346
+ ...responseStatusNames
347
+ ] : [
348
+ ...paramNames,
349
+ ...bodyAndResponseNames,
350
+ ...responseStatusNames
351
+ ]).filter((name) => Boolean(name) && !exclude.has(name));
352
+ byResolver.set(cacheKey, result);
353
+ return result;
354
+ }
355
+ //#endregion
356
+ //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
357
+ const declarationPrinter$7 = functionPrinter({ mode: "declaration" });
358
+ const mutationKeyTransformer = ({ node }) => {
359
+ if (!node.path) return [];
360
+ return [`{ url: '${Url.toPath(node.path)}' }`];
361
+ };
362
+ function MutationKey({ name, paramsCasing, node, transformer }) {
363
+ const paramsNode = ast.createFunctionParameters({ params: [] });
364
+ const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
365
+ const keys = (transformer ?? mutationKeyTransformer)({
325
366
  node,
326
367
  casing: paramsCasing
327
368
  });
@@ -338,28 +379,76 @@ function MutationKey({ name, paramsCasing, node, transformer = getTransformer$1
338
379
  })
339
380
  });
340
381
  }
341
- MutationKey.getParams = getParams$4;
342
- MutationKey.getTransformer = getTransformer$1;
343
382
  //#endregion
344
383
  //#region ../../internals/tanstack-query/src/utils.ts
345
384
  /**
346
- * Build JSDoc comment lines from an OperationNode.
385
+ * Builds the shared `(…params, config = {})` parameter list for a TanStack
386
+ * query-options function. The trailing `config` parameter is typed as a partial
387
+ * `RequestConfig` with an optional `client`. Framework plugins wrap the result
388
+ * when needed, for example vue-query applies `MaybeRefOrGetter`.
347
389
  */
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));
390
+ function buildQueryOptionsParams(node, options) {
391
+ const { paramsType, paramsCasing, pathParamsType, resolver } = options;
392
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
393
+ return ast.createOperationParams(node, {
394
+ paramsType,
395
+ pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
396
+ paramsCasing,
397
+ resolver,
398
+ extraParams: [ast.createFunctionParameter({
399
+ name: "config",
400
+ type: ast.createParamsType({
401
+ variant: "reference",
402
+ name: requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
403
+ }),
404
+ default: "{}"
405
+ })]
406
+ });
407
+ }
408
+ /**
409
+ * Returns `'zod'` when response-direction parsing is enabled.
410
+ * The string shorthand `'zod'` also enables response parsing.
411
+ */
412
+ function resolveResponseParser(parser) {
413
+ if (!parser) return null;
414
+ if (parser === "zod") return "zod";
415
+ return parser.response ?? null;
416
+ }
417
+ /**
418
+ * Returns `'zod'` when request body parsing is enabled.
419
+ * The string shorthand `'zod'` also enables request body parsing (existing behavior).
420
+ */
421
+ function resolveRequestParser(parser) {
422
+ if (!parser) return null;
423
+ if (parser === "zod") return "zod";
424
+ return parser.request ?? null;
355
425
  }
356
426
  /**
357
- * Resolve error type names from operation responses.
427
+ * Returns `'zod'` when query-params parsing is enabled.
428
+ * Only the object form `{ request: 'zod' }` enables this. `parser: 'zod'` does not.
358
429
  */
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));
430
+ function resolveQueryParamsParser(parser) {
431
+ if (!parser || parser === "zod") return null;
432
+ return parser.request ?? null;
433
+ }
434
+ /**
435
+ * Collects the Zod schema import names for an operation based on the active parser directions.
436
+ *
437
+ * - `parser: 'zod'`: response and request body names (backward-compatible behavior).
438
+ * - `parser: { request: 'zod' }`: request body and query params names.
439
+ * - `parser: { response: 'zod' }`: response name only.
440
+ * - `parser: { request: 'zod', response: 'zod' }`: all three.
441
+ *
442
+ * Returns an empty array when no resolver is provided or `parser` is falsy.
443
+ */
444
+ function resolveZodSchemaNames(node, zodResolver, parser) {
445
+ if (!zodResolver || !parser) return [];
446
+ const { query: queryParams } = getOperationParameters(node);
447
+ return [
448
+ resolveResponseParser(parser) === "zod" ? zodResolver.resolveResponseName?.(node) : null,
449
+ resolveRequestParser(parser) === "zod" && node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null,
450
+ resolveQueryParamsParser(parser) === "zod" && queryParams.length > 0 ? zodResolver.resolveQueryParamsName?.(node, queryParams[0]) : null
451
+ ].filter((n) => Boolean(n));
363
452
  }
364
453
  /**
365
454
  * Resolve the type for a single path parameter.
@@ -383,30 +472,14 @@ function resolvePathParamType(node, param, resolver) {
383
472
  }
384
473
  /**
385
474
  * Derive a query-params group type from the resolver.
386
- * Returns `undefined` when no query params exist or when the group name
475
+ * Returns `null` when no query params exist or when the group name
387
476
  * equals the individual param name (no real group).
388
477
  */
389
478
  function resolveQueryGroupType(node, params, resolver) {
390
- if (!params.length) return void 0;
479
+ if (!params.length) return null;
391
480
  const firstParam = params[0];
392
481
  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;
482
+ if (groupName === resolver.resolveParamName(node, firstParam)) return null;
410
483
  return {
411
484
  type: ast.createParamsType({
412
485
  variant: "reference",
@@ -456,7 +529,7 @@ function buildQueryKeyParams(node, options) {
456
529
  const bodyType = node.requestBody?.content?.[0]?.schema ? ast.createParamsType({
457
530
  variant: "reference",
458
531
  name: resolver.resolveDataName(node)
459
- }) : void 0;
532
+ }) : null;
460
533
  const bodyRequired = node.requestBody?.required ?? false;
461
534
  const params = [];
462
535
  if (pathParams.length) {
@@ -481,47 +554,84 @@ function buildQueryKeyParams(node, options) {
481
554
  return ast.createFunctionParameters({ params });
482
555
  }
483
556
  /**
484
- * Build mutation arg params for paramsToTrigger mode.
485
- * Contains pathParams + data + queryParams + headers (all flattened, for type alias).
557
+ * Collect the names of the required params (no default) that drive the `enabled`
558
+ * guard. These are exactly the params that should be made optional in the
559
+ * generated signatures so callers can pass `undefined` to reach the disabled state.
486
560
  */
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));
561
+ function getEnabledParamNames(paramsNode) {
562
+ const required = [];
563
+ for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
564
+ const group = param;
565
+ for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
566
+ } else {
567
+ const fp = param;
568
+ if (!fp.optional && fp.default === void 0) required.push(fp.name);
569
+ }
570
+ return required;
571
+ }
572
+ /**
573
+ * Return a copy of `paramsNode` with the named params marked optional.
574
+ *
575
+ * Used to align signatures with the `enabled` guard: the guard already disables
576
+ * the query while a param is falsy, so the param should accept `undefined`. The
577
+ * change is type-only the `queryFn` keeps calling the client with a non-null
578
+ * assertion (see `injectNonNullAssertions`), so the emitted runtime is unchanged.
579
+ */
580
+ function markParamsOptional(paramsNode, names) {
581
+ if (names.length === 0) return paramsNode;
582
+ const nameSet = new Set(names);
583
+ const params = paramsNode.params.map((param) => {
584
+ if ("kind" in param && param.kind === "ParameterGroup") {
585
+ const group = param;
586
+ return {
587
+ ...group,
588
+ properties: group.properties.map((child) => nameSet.has(child.name) ? ast.createFunctionParameter({
589
+ name: child.name,
590
+ type: child.type,
591
+ rest: child.rest,
592
+ optional: true
593
+ }) : child)
594
+ };
595
+ }
596
+ const fp = param;
597
+ return nameSet.has(fp.name) ? ast.createFunctionParameter({
598
+ name: fp.name,
599
+ type: fp.type,
600
+ rest: fp.rest,
601
+ optional: true
602
+ }) : fp;
603
+ });
513
604
  return ast.createFunctionParameters({ params });
514
605
  }
606
+ functionPrinter({ mode: "declaration" });
607
+ const queryKeyTransformer = ({ node, casing }) => {
608
+ if (!node.path) return [];
609
+ const hasQueryParams = getOperationParameters(node).query.length > 0;
610
+ const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
611
+ return [
612
+ Url.toObject(node.path, {
613
+ type: "path",
614
+ stringify: true,
615
+ casing
616
+ }),
617
+ hasQueryParams ? "...(params ? [params] : [])" : null,
618
+ hasRequestBody ? "...(data ? [data] : [])" : null
619
+ ].filter(Boolean);
620
+ };
515
621
  //#endregion
516
622
  //#region src/utils.ts
517
- function transformName(name, type, transformers) {
518
- return transformers?.name?.(name, type) || name;
623
+ function printType(typeNode) {
624
+ if (!typeNode) return "unknown";
625
+ if (typeNode.variant === "reference") return typeNode.name;
626
+ if (typeNode.variant === "member") return `${typeNode.base}['${typeNode.key}']`;
627
+ if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
628
+ const typeStr = printType(p.type);
629
+ const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
630
+ return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
631
+ }).join("; ")} }`;
632
+ return "unknown";
519
633
  }
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) {
634
+ function wrapWithMaybeRefOrGetter(paramsNode, skip) {
525
635
  const wrappedParams = paramsNode.params.map((param) => {
526
636
  if ("kind" in param && param.kind === "ParameterGroup") {
527
637
  const group = param;
@@ -531,59 +641,38 @@ function wrapWithMaybeRefOrGetter(paramsNode) {
531
641
  ...p,
532
642
  type: p.type ? ast.createParamsType({
533
643
  variant: "reference",
534
- name: `MaybeRefOrGetter<${printType$4(p.type)}>`
644
+ name: `MaybeRefOrGetter<${printType(p.type)}>`
535
645
  }) : p.type
536
646
  }))
537
647
  };
538
648
  }
539
649
  const fp = param;
650
+ if (skip?.(fp.name)) return fp;
540
651
  return {
541
652
  ...fp,
542
653
  type: fp.type ? ast.createParamsType({
543
654
  variant: "reference",
544
- name: `MaybeRefOrGetter<${printType$4(fp.type)}>`
655
+ name: `MaybeRefOrGetter<${printType(fp.type)}>`
545
656
  }) : fp.type
546
657
  };
547
658
  });
548
659
  return ast.createFunctionParameters({ params: wrappedParams });
549
660
  }
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) {
661
+ //#endregion
662
+ //#region src/components/QueryKey.tsx
663
+ const declarationPrinter$5 = functionPrinter({ mode: "declaration" });
664
+ function buildQueryKeyParamsNode(node, options) {
563
665
  return wrapWithMaybeRefOrGetter(buildQueryKeyParams(node, options));
564
666
  }
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, {
667
+ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }) {
668
+ const baseParamsNode = buildQueryKeyParamsNode(node, {
581
669
  pathParamsType,
582
670
  paramsCasing,
583
671
  resolver: tsResolver
584
672
  });
673
+ const paramsNode = markParamsOptional(baseParamsNode, getEnabledParamNames(baseParamsNode));
585
674
  const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
586
- const keys = transformer({
675
+ const keys = (transformer ?? queryKeyTransformer)({
587
676
  node,
588
677
  casing: paramsCasing
589
678
  });
@@ -610,103 +699,35 @@ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeNa
610
699
  })
611
700
  })] });
612
701
  }
613
- QueryKey.getParams = getParams$3;
614
- QueryKey.getTransformer = getTransformer;
615
- QueryKey.callPrinter = callPrinter$5;
616
702
  //#endregion
617
703
  //#region src/components/QueryOptions.tsx
618
704
  const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
619
705
  const callPrinter$4 = functionPrinter({ mode: "call" });
620
706
  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(" && ");
707
+ return wrapWithMaybeRefOrGetter(buildQueryOptionsParams(node, options), (name) => name === "config");
688
708
  }
689
709
  function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
690
- const responseName = tsResolver.resolveResponseName(node);
710
+ const successNames = resolveSuccessNames(node, tsResolver);
711
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
691
712
  const errorNames = resolveErrorNames(node, tsResolver);
692
- const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
713
+ const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
693
714
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
694
- const paramsNode = getQueryOptionsParams(node, {
715
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
716
+ pathParamsType,
717
+ paramsCasing,
718
+ resolver: tsResolver
719
+ });
720
+ const queryKeyParamsCall = callPrinter$4.print(queryKeyParamsNode) ?? "";
721
+ const enabledNames = getEnabledParamNames(queryKeyParamsNode);
722
+ const enabledText = enabledNames.length ? `enabled: () => ${enabledNames.map((n) => `!!toValue(${n})`).join(" && ")},` : "";
723
+ const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
695
724
  paramsType,
696
725
  paramsCasing,
697
726
  pathParamsType,
698
727
  resolver: tsResolver
699
- });
728
+ }), enabledNames);
700
729
  const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
701
730
  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
731
  return /* @__PURE__ */ jsx(File.Source, {
711
732
  name,
712
733
  isExportable: true,
@@ -717,11 +738,10 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
717
738
  params: paramsSignature,
718
739
  children: `
719
740
  const queryKey = ${queryKeyName}(${queryKeyParamsCall})
720
- return queryOptions<${TData}, ${TError}, ${TData}>({
721
- ${enabledText}
741
+ return queryOptions<${TData}, ${TError}, ${TData}>({${enabledText ? `\n ${enabledText}` : ""}
722
742
  queryKey,
723
743
  queryFn: async ({ signal }) => {
724
- return ${clientName}(${addToValueCalls$1(clientCallStr)})
744
+ return ${clientName}(${addToValueCalls$1(clientCallStr, enabledNames)})
725
745
  },
726
746
  })
727
747
  `
@@ -735,30 +755,31 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
735
755
  * Handles both inline params (`petId, config`) and object shorthand
736
756
  * params (`{ petId }, config`) by expanding to `{ petId: toValue(petId) }`.
737
757
  */
738
- function addToValueCalls$1(callStr) {
758
+ function addToValueCalls$1(callStr, enabledNames = []) {
759
+ const optional = new Set(enabledNames);
739
760
  let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
740
761
  if (inner.includes(":") || inner.includes("...")) return match;
741
- return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${k})`).join(", ")} }`;
762
+ return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${optional.has(k) ? `${k}!` : k})`).join(", ")} }`;
742
763
  });
743
764
  result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => {
744
765
  if (name === "config" || name === "signal" || name === "undefined") return match;
745
766
  if (match.includes("toValue(")) return match;
746
- return `toValue(${name})`;
767
+ return `toValue(${optional.has(name) ? `${name}!` : name})`;
747
768
  });
748
769
  return result;
749
770
  }
750
771
  __name(addToValueCalls$1, "addToValueCalls");
751
- QueryOptions.getParams = getQueryOptionsParams;
752
772
  //#endregion
753
773
  //#region src/components/InfiniteQuery.tsx
754
774
  const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
755
775
  const callPrinter$3 = functionPrinter({ mode: "call" });
756
- function getParams$2(node, options) {
776
+ function buildInfiniteQueryParamsNode(node, options) {
757
777
  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;
778
+ const successNames = resolveSuccessNames(node, resolver);
779
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
780
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
760
781
  const errorNames = resolveErrorNames(node, resolver);
761
- const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
782
+ const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
762
783
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
763
784
  const optionsParam = ast.createFunctionParameter({
764
785
  name: "options",
@@ -777,59 +798,19 @@ function getParams$2(node, options) {
777
798
  }),
778
799
  default: "{}"
779
800
  });
780
- return wrapOperationParamsWithMaybeRef$1(ast.createOperationParams(node, {
801
+ return wrapWithMaybeRefOrGetter(ast.createOperationParams(node, {
781
802
  paramsType,
782
803
  pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
783
804
  paramsCasing,
784
805
  resolver,
785
806
  extraParams: [optionsParam]
786
- }));
807
+ }), (name) => name === "options");
787
808
  }
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
809
  function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
830
- const responseName = tsResolver.resolveResponseName(node);
810
+ const successNames = resolveSuccessNames(node, tsResolver);
811
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
831
812
  const errorNames = resolveErrorNames(node, tsResolver);
832
- const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
813
+ const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
833
814
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
834
815
  const returnType = `UseInfiniteQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
835
816
  const generics = [
@@ -837,12 +818,13 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
837
818
  `TQueryData = ${TData}`,
838
819
  `TQueryKey extends QueryKey = ${queryKeyTypeName}`
839
820
  ];
840
- const queryKeyParamsNode = QueryKey.getParams(node, {
821
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
841
822
  pathParamsType,
842
823
  paramsCasing,
843
824
  resolver: tsResolver
844
825
  });
845
826
  const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
827
+ const enabledNames = getEnabledParamNames(queryKeyParamsNode);
846
828
  const queryOptionsParamsNode = getQueryOptionsParams(node, {
847
829
  paramsType,
848
830
  paramsCasing,
@@ -850,13 +832,13 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
850
832
  resolver: tsResolver
851
833
  });
852
834
  const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
853
- const paramsNode = getParams$2(node, {
835
+ const paramsNode = markParamsOptional(buildInfiniteQueryParamsNode(node, {
854
836
  paramsType,
855
837
  paramsCasing,
856
838
  pathParamsType,
857
839
  dataReturnType,
858
840
  resolver: tsResolver
859
- });
841
+ }), enabledNames);
860
842
  const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
861
843
  return /* @__PURE__ */ jsx(File.Source, {
862
844
  name,
@@ -867,7 +849,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
867
849
  export: true,
868
850
  generics: generics.join(", "),
869
851
  params: paramsSignature,
870
- JSDoc: { comments: getComments(node) },
852
+ JSDoc: { comments: buildOperationComments(node) },
871
853
  children: `
872
854
  const { query: queryConfig = {}, client: config = {} } = options ?? {}
873
855
  const { client: queryClient, ...resolvedOptions } = queryConfig
@@ -886,14 +868,14 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
886
868
  })
887
869
  });
888
870
  }
889
- InfiniteQuery.getParams = getParams$2;
890
871
  //#endregion
891
872
  //#region src/components/InfiniteQueryOptions.tsx
892
873
  const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
893
874
  const callPrinter$2 = functionPrinter({ mode: "call" });
894
875
  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}>`;
876
+ const successNames = resolveSuccessNames(node, tsResolver);
877
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
878
+ const queryFnDataType = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
897
879
  const errorNames = resolveErrorNames(node, tsResolver);
898
880
  const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
899
881
  const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
@@ -901,59 +883,48 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
901
883
  const parts = initialPageParam.split(" as ");
902
884
  return parts[parts.length - 1] ?? "unknown";
903
885
  })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
904
- const rawQueryParams = node.parameters.filter((p) => p.in === "query");
886
+ const rawQueryParams = getOperationParameters(node).query;
905
887
  const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
906
888
  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;
889
+ return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
890
+ })() : null;
891
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
910
892
  const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
911
- const paramsNode = getQueryOptionsParams(node, {
893
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
894
+ pathParamsType,
895
+ paramsCasing,
896
+ resolver: tsResolver
897
+ });
898
+ const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
899
+ const enabledNames = getEnabledParamNames(queryKeyParamsNode);
900
+ const enabledText = enabledNames.length ? `enabled: () => ${enabledNames.map((n) => `!!toValue(${n})`).join(" && ")},` : "";
901
+ const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
912
902
  paramsType,
913
903
  paramsCasing,
914
904
  pathParamsType,
915
905
  resolver: tsResolver
916
- });
906
+ }), enabledNames);
917
907
  const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
918
908
  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}`;
909
+ const hasNewParams = nextParam != null || previousParam != null;
910
+ const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
911
+ if (hasNewParams) {
912
+ const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
913
+ const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
914
+ return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
934
915
  }
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
- }
916
+ if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
917
+ return [dataReturnType === "full" ? "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage.data) && lastPage.data.length === 0 ? undefined : lastPageParam + 1" : "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1", "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1"];
918
+ })();
947
919
  const queryOptionsArr = [
948
920
  `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
949
921
  getNextPageParamExpr,
950
922
  getPreviousPageParamExpr
951
923
  ].filter(Boolean);
952
- const infiniteOverrideParams = queryParam && queryParamsTypeName ? `
953
- params = {
954
- ...(params ?? {}),
955
- ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
956
- } as ${queryParamsTypeName}` : "";
924
+ const infiniteOverrideParams = queryParam && queryParamsTypeName ? `params = {
925
+ ...(params ?? {}),
926
+ ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
927
+ } as ${queryParamsTypeName}` : "";
957
928
  if (infiniteOverrideParams) return /* @__PURE__ */ jsx(File.Source, {
958
929
  name,
959
930
  isExportable: true,
@@ -963,16 +934,15 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
963
934
  export: true,
964
935
  params: paramsSignature,
965
936
  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
- })
937
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
938
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, QueryKey, ${pageParamType}>({${enabledText ? `\n ${enabledText}` : ""}
939
+ queryKey,
940
+ queryFn: async ({ signal, pageParam }) => {
941
+ ${infiniteOverrideParams}
942
+ return ${clientName}(${addToValueCalls(clientCallStr, enabledNames)})
943
+ },
944
+ ${queryOptionsArr.join(",\n ")}
945
+ })
976
946
  `
977
947
  })
978
948
  });
@@ -985,58 +955,55 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
985
955
  export: true,
986
956
  params: paramsSignature,
987
957
  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
- })
958
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
959
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, QueryKey, ${pageParamType}>({${enabledText ? `\n ${enabledText}` : ""}
960
+ queryKey,
961
+ queryFn: async ({ signal }) => {
962
+ return ${clientName}(${addToValueCalls(clientCallStr, enabledNames)})
963
+ },
964
+ ${queryOptionsArr.join(",\n ")}
965
+ })
997
966
  `
998
967
  })
999
968
  });
1000
969
  }
1001
- function addToValueCalls(callStr) {
970
+ function addToValueCalls(callStr, enabledNames = []) {
971
+ const optional = new Set(enabledNames);
1002
972
  let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
1003
973
  if (inner.includes(":") || inner.includes("...")) return match;
1004
- return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${k})`).join(", ")} }`;
974
+ return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${optional.has(k) ? `${k}!` : k})`).join(", ")} }`;
1005
975
  });
1006
976
  result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => {
1007
977
  if (name === "config" || name === "signal" || name === "undefined") return match;
1008
978
  if (match.includes("toValue(")) return match;
1009
- return `toValue(${name})`;
979
+ return `toValue(${optional.has(name) ? `${name}!` : name})`;
1010
980
  });
1011
981
  return result;
1012
982
  }
1013
- InfiniteQueryOptions.getParams = (node, options) => getQueryOptionsParams(node, options);
1014
983
  //#endregion
1015
984
  //#region src/components/Mutation.tsx
1016
985
  const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
1017
986
  const callPrinter$1 = functionPrinter({ mode: "call" });
1018
987
  const keysPrinter = functionPrinter({ mode: "keys" });
1019
- function getParams$1(node, options) {
988
+ function createMutationArgParams(node, options) {
989
+ return ast.createOperationParams(node, {
990
+ paramsType: "inline",
991
+ pathParamsType: "inline",
992
+ paramsCasing: options.paramsCasing,
993
+ resolver: options.resolver
994
+ });
995
+ }
996
+ function buildMutationParamsNode(node, options) {
1020
997
  const { paramsCasing, dataReturnType, resolver } = options;
1021
- const responseName = resolver.resolveResponseName(node);
1022
- const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
998
+ const successNames = resolveSuccessNames(node, resolver);
999
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
1023
1000
  const errorNames = resolveErrorNames(node, resolver);
1024
- const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1001
+ const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
1025
1002
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1026
- const mutationArgWrapped = buildMutationArgParams(node, {
1003
+ const wrappedParamsNode = wrapWithMaybeRefOrGetter(createMutationArgParams(node, {
1027
1004
  paramsCasing,
1028
1005
  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 });
1006
+ }));
1040
1007
  const TRequestWrapped = wrappedParamsNode.params.length > 0 ? declarationPrinter$1.print(wrappedParamsNode) ?? "" : "";
1041
1008
  return ast.createFunctionParameters({ params: [ast.createFunctionParameter({
1042
1009
  name: "options",
@@ -1046,34 +1013,22 @@ function getParams$1(node, options) {
1046
1013
  mutation?: MutationObserverOptions<${[
1047
1014
  TData,
1048
1015
  TError,
1049
- TRequestWrapped ? `{${TRequestWrapped}}` : "void",
1016
+ TRequestWrapped ? `{${TRequestWrapped}}` : "undefined",
1050
1017
  "TContext"
1051
1018
  ].join(", ")}> & { client?: QueryClient },
1052
- client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
1019
+ client?: ${buildRequestConfigType(node, resolver)},
1053
1020
  }`
1054
1021
  }),
1055
1022
  default: "{}"
1056
1023
  })] });
1057
1024
  }
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
1025
  function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType, dataReturnType, node, tsResolver, mutationKeyName }) {
1072
- const responseName = tsResolver.resolveResponseName(node);
1026
+ const successNames = resolveSuccessNames(node, tsResolver);
1027
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
1073
1028
  const errorNames = resolveErrorNames(node, tsResolver);
1074
- const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1029
+ const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
1075
1030
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1076
- const mutationArgParamsNode = buildMutationArgParams(node, {
1031
+ const mutationArgParamsNode = createMutationArgParams(node, {
1077
1032
  paramsCasing,
1078
1033
  resolver: tsResolver
1079
1034
  });
@@ -1083,10 +1038,10 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
1083
1038
  const generics = [
1084
1039
  TData,
1085
1040
  TError,
1086
- TRequest ? `{${TRequest}}` : "void",
1041
+ TRequest ? `{${TRequest}}` : "undefined",
1087
1042
  "TContext"
1088
1043
  ].join(", ");
1089
- const mutationKeyParamsNode = MutationKey.getParams();
1044
+ const mutationKeyParamsNode = ast.createFunctionParameters({ params: [] });
1090
1045
  const mutationKeyParamsCall = callPrinter$1.print(mutationKeyParamsNode) ?? "";
1091
1046
  const clientCallParamsNode = ast.createOperationParams(node, {
1092
1047
  paramsType,
@@ -1097,13 +1052,13 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
1097
1052
  name: "config",
1098
1053
  type: ast.createParamsType({
1099
1054
  variant: "reference",
1100
- name: node.requestBody?.content?.[0]?.schema ? `Partial<RequestConfig<${tsResolver.resolveDataName(node)}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
1055
+ name: buildRequestConfigType(node, tsResolver)
1101
1056
  }),
1102
1057
  default: "{}"
1103
1058
  })]
1104
1059
  });
1105
1060
  const clientCallStr = callPrinter$1.print(clientCallParamsNode) ?? "";
1106
- const paramsNode = getParams$1(node, {
1061
+ const paramsNode = buildMutationParamsNode(node, {
1107
1062
  paramsCasing,
1108
1063
  dataReturnType,
1109
1064
  resolver: tsResolver
@@ -1117,7 +1072,7 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
1117
1072
  name,
1118
1073
  export: true,
1119
1074
  params: paramsSignature,
1120
- JSDoc: { comments: getComments(node) },
1075
+ JSDoc: { comments: buildOperationComments(node) },
1121
1076
  generics: ["TContext"],
1122
1077
  children: `
1123
1078
  const { mutation = {}, client: config = {} } = options ?? {}
@@ -1135,17 +1090,17 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
1135
1090
  })
1136
1091
  });
1137
1092
  }
1138
- Mutation.getParams = getParams$1;
1139
1093
  //#endregion
1140
1094
  //#region src/components/Query.tsx
1141
1095
  const declarationPrinter = functionPrinter({ mode: "declaration" });
1142
1096
  const callPrinter = functionPrinter({ mode: "call" });
1143
- function getParams(node, options) {
1097
+ function buildQueryParamsNode(node, options) {
1144
1098
  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;
1099
+ const successNames = resolveSuccessNames(node, resolver);
1100
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
1101
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
1147
1102
  const errorNames = resolveErrorNames(node, resolver);
1148
- const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1103
+ const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, resolver);
1149
1104
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1150
1105
  const optionsParam = ast.createFunctionParameter({
1151
1106
  name: "options",
@@ -1164,56 +1119,19 @@ function getParams(node, options) {
1164
1119
  }),
1165
1120
  default: "{}"
1166
1121
  });
1167
- return wrapOperationParamsWithMaybeRef(ast.createOperationParams(node, {
1122
+ return wrapWithMaybeRefOrGetter(ast.createOperationParams(node, {
1168
1123
  paramsType,
1169
1124
  pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
1170
1125
  paramsCasing,
1171
1126
  resolver,
1172
1127
  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";
1128
+ }), (name) => name === "options");
1212
1129
  }
1213
1130
  function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
1214
- const responseName = tsResolver.resolveResponseName(node);
1131
+ const successNames = resolveSuccessNames(node, tsResolver);
1132
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
1215
1133
  const errorNames = resolveErrorNames(node, tsResolver);
1216
- const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1134
+ const TData = dataReturnType === "data" ? responseName : buildStatusUnionType(node, tsResolver);
1217
1135
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1218
1136
  const returnType = `UseQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
1219
1137
  const generics = [
@@ -1221,12 +1139,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
1221
1139
  `TQueryData = ${TData}`,
1222
1140
  `TQueryKey extends QueryKey = ${queryKeyTypeName}`
1223
1141
  ];
1224
- const queryKeyParamsNode = QueryKey.getParams(node, {
1142
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
1225
1143
  pathParamsType,
1226
1144
  paramsCasing,
1227
1145
  resolver: tsResolver
1228
1146
  });
1229
1147
  const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
1148
+ const enabledNames = getEnabledParamNames(queryKeyParamsNode);
1230
1149
  const queryOptionsParamsNode = getQueryOptionsParams(node, {
1231
1150
  paramsType,
1232
1151
  paramsCasing,
@@ -1234,13 +1153,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
1234
1153
  resolver: tsResolver
1235
1154
  });
1236
1155
  const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
1237
- const paramsNode = getParams(node, {
1156
+ const paramsNode = markParamsOptional(buildQueryParamsNode(node, {
1238
1157
  paramsType,
1239
1158
  paramsCasing,
1240
1159
  pathParamsType,
1241
1160
  dataReturnType,
1242
1161
  resolver: tsResolver
1243
- });
1162
+ }), enabledNames);
1244
1163
  const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1245
1164
  return /* @__PURE__ */ jsx(File.Source, {
1246
1165
  name,
@@ -1251,7 +1170,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
1251
1170
  export: true,
1252
1171
  generics: generics.join(", "),
1253
1172
  params: paramsSignature,
1254
- JSDoc: { comments: getComments(node) },
1173
+ JSDoc: { comments: buildOperationComments(node) },
1255
1174
  children: `
1256
1175
  const { query: queryConfig = {}, client: config = {} } = options ?? {}
1257
1176
  const { client: queryClient, ...resolvedOptions } = queryConfig
@@ -1270,8 +1189,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
1270
1189
  })
1271
1190
  });
1272
1191
  }
1273
- Query.getParams = getParams;
1274
1192
  //#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 };
1193
+ export { QueryOptions as a, resolveZodSchemaNames as c, getOperationParameters as d, operationFileEntry as f, InfiniteQuery as i, MutationKey as l, camelCase as m, Mutation as n, QueryKey as o, resolveOperationTypeNames as p, InfiniteQueryOptions as r, queryKeyTransformer as s, Query as t, mutationKeyTransformer as u };
1276
1194
 
1277
- //# sourceMappingURL=components-D1UhYFgY.js.map
1195
+ //# sourceMappingURL=components-B79Gljyl.js.map