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

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 (41) hide show
  1. package/README.md +26 -5
  2. package/dist/{components-qfOFRSoM.cjs → components-B6lPYyOP.cjs} +367 -381
  3. package/dist/components-B6lPYyOP.cjs.map +1 -0
  4. package/dist/{components-D1UhYFgY.js → components-BZqujNQv.js} +336 -380
  5. package/dist/components-BZqujNQv.js.map +1 -0
  6. package/dist/components.cjs +1 -1
  7. package/dist/components.d.ts +3 -67
  8. package/dist/components.js +1 -1
  9. package/dist/{generators-CbnIVBgY.js → generators-C-3isXzW.js} +158 -203
  10. package/dist/generators-C-3isXzW.js.map +1 -0
  11. package/dist/{generators-C4gs_P1i.cjs → generators-QHQkbNnm.cjs} +157 -202
  12. package/dist/generators-QHQkbNnm.cjs.map +1 -0
  13. package/dist/generators.cjs +1 -1
  14. package/dist/generators.d.ts +17 -1
  15. package/dist/generators.js +1 -1
  16. package/dist/index.cjs +136 -23
  17. package/dist/index.cjs.map +1 -1
  18. package/dist/index.d.ts +29 -1
  19. package/dist/index.js +136 -23
  20. package/dist/index.js.map +1 -1
  21. package/dist/types-D-LjzI_Q.d.ts +270 -0
  22. package/extension.yaml +1273 -0
  23. package/package.json +16 -18
  24. package/src/components/InfiniteQuery.tsx +16 -48
  25. package/src/components/InfiniteQueryOptions.tsx +43 -58
  26. package/src/components/Mutation.tsx +33 -42
  27. package/src/components/Query.tsx +16 -49
  28. package/src/components/QueryKey.tsx +9 -61
  29. package/src/components/QueryOptions.tsx +20 -76
  30. package/src/generators/infiniteQueryGenerator.tsx +55 -63
  31. package/src/generators/mutationGenerator.tsx +50 -61
  32. package/src/generators/queryGenerator.tsx +52 -61
  33. package/src/plugin.ts +46 -30
  34. package/src/resolvers/resolverVueQuery.ts +61 -4
  35. package/src/types.ts +129 -53
  36. package/src/utils.ts +44 -25
  37. package/dist/components-D1UhYFgY.js.map +0 -1
  38. package/dist/components-qfOFRSoM.cjs.map +0 -1
  39. package/dist/generators-C4gs_P1i.cjs.map +0 -1
  40. package/dist/generators-CbnIVBgY.js.map +0 -1
  41. package/dist/types-nVDTfuS1.d.ts +0 -194
@@ -228,16 +228,16 @@ var URLPath = class {
228
228
  get object() {
229
229
  return this.toObject();
230
230
  }
231
- /** Returns a map of path parameter names, or `undefined` when the path has no parameters.
231
+ /** Returns a map of path parameter names, or `null` when the path has no parameters.
232
232
  *
233
233
  * @example
234
234
  * ```ts
235
235
  * new URLPath('/pet/{petId}').params // { petId: 'petId' }
236
- * new URLPath('/pet').params // undefined
236
+ * new URLPath('/pet').params // null
237
237
  * ```
238
238
  */
239
239
  get params() {
240
- return this.getParams();
240
+ return this.toParamsObject();
241
241
  }
242
242
  #transformParam(raw) {
243
243
  const param = isValidVarName(raw) ? raw : camelCase(raw);
@@ -255,7 +255,7 @@ var URLPath = class {
255
255
  toObject({ type = "path", replacer, stringify } = {}) {
256
256
  const object = {
257
257
  url: type === "path" ? this.toURLPath() : this.toTemplateString({ replacer }),
258
- params: this.getParams()
258
+ params: this.toParamsObject()
259
259
  };
260
260
  if (stringify) {
261
261
  if (type === "template") return JSON.stringify(object).replaceAll("'", "").replaceAll(`"`, "");
@@ -271,12 +271,13 @@ var URLPath = class {
271
271
  * @example
272
272
  * new URLPath('/pet/{petId}').toTemplateString() // '`/pet/${petId}`'
273
273
  */
274
- toTemplateString({ prefix = "", replacer } = {}) {
275
- return `\`${prefix}${this.path.split(/\{([^}]+)\}/).map((part, i) => {
274
+ toTemplateString({ prefix, replacer } = {}) {
275
+ const result = this.path.split(/\{([^}]+)\}/).map((part, i) => {
276
276
  if (i % 2 === 0) return part;
277
277
  const param = this.#transformParam(part);
278
278
  return `\${${replacer ? replacer(param) : param}}`;
279
- }).join("")}\``;
279
+ }).join("");
280
+ return `\`${prefix ?? ""}${result}\``;
280
281
  }
281
282
  /**
282
283
  * Extracts all `{param}` segments from the path and returns them as a key-value map.
@@ -285,17 +286,17 @@ var URLPath = class {
285
286
  *
286
287
  * @example
287
288
  * ```ts
288
- * new URLPath('/pet/{petId}/tag/{tagId}').getParams()
289
+ * new URLPath('/pet/{petId}/tag/{tagId}').toParamsObject()
289
290
  * // { petId: 'petId', tagId: 'tagId' }
290
291
  * ```
291
292
  */
292
- getParams(replacer) {
293
+ toParamsObject(replacer) {
293
294
  const params = {};
294
295
  this.#eachParam((_raw, param) => {
295
296
  const key = replacer ? replacer(param) : param;
296
297
  params[key] = key;
297
298
  });
298
- return Object.keys(params).length > 0 ? params : void 0;
299
+ return Object.keys(params).length > 0 ? params : null;
299
300
  }
300
301
  /** Converts the OpenAPI path to Express-style colon syntax.
301
302
  *
@@ -309,19 +310,138 @@ var URLPath = class {
309
310
  }
310
311
  };
311
312
  //#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: [] });
313
+ //#region ../../internals/shared/src/operation.ts
314
+ /**
315
+ * Builds the `ResolverFileParams` every operation generator passes to
316
+ * `resolver.resolveFile`: a file named `name`, tagged by the operation's first
317
+ * tag (or `'default'`), at the operation's path. Centralizes the entry object
318
+ * that was repeated at dozens of call sites across the client and query plugins.
319
+ *
320
+ * @example
321
+ * ```ts
322
+ * resolver.resolveFile(operationFileEntry(node, node.operationId), { root, output, group })
323
+ * ```
324
+ */
325
+ function operationFileEntry(node, name, extname = ".ts") {
326
+ return {
327
+ name,
328
+ extname,
329
+ tag: node.tags[0] ?? "default",
330
+ path: node.path
331
+ };
332
+ }
333
+ function getOperationLink(node, link) {
334
+ if (!link) return null;
335
+ if (typeof link === "function") return link(node) ?? null;
336
+ if (link === "urlPath") return node.path ? `{@link ${new URLPath(node.path).URL}}` : null;
337
+ return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
338
+ }
339
+ function getContentTypeInfo(node) {
340
+ const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
341
+ const isMultipleContentTypes = contentTypes.length > 1;
342
+ return {
343
+ contentTypes,
344
+ isMultipleContentTypes,
345
+ contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
346
+ defaultContentType: contentTypes[0] ?? "application/json",
347
+ hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
348
+ };
349
+ }
350
+ function buildRequestConfigType(node, resolver) {
351
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
352
+ const { isMultipleContentTypes, contentTypeUnion } = getContentTypeInfo(node);
353
+ return `${requestName ? `Partial<RequestConfig<${requestName}>>` : "Partial<RequestConfig>"} & { ${["client?: Client", isMultipleContentTypes ? `contentType?: ${contentTypeUnion}` : null].filter(Boolean).join("; ")} }`;
354
+ }
355
+ function buildOperationComments(node, options = {}) {
356
+ const { link = "pathTemplate", linkPosition = "afterDeprecated", splitLines = false } = options;
357
+ const linkComment = getOperationLink(node, link);
358
+ const filteredComments = (linkPosition === "beforeDeprecated" ? [
359
+ node.description && `@description ${node.description}`,
360
+ node.summary && `@summary ${node.summary}`,
361
+ linkComment,
362
+ node.deprecated && "@deprecated"
363
+ ] : [
364
+ node.description && `@description ${node.description}`,
365
+ node.summary && `@summary ${node.summary}`,
366
+ node.deprecated && "@deprecated",
367
+ linkComment
368
+ ]).filter((comment) => Boolean(comment));
369
+ if (!splitLines) return filteredComments;
370
+ return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
371
+ }
372
+ function getOperationParameters(node, options = {}) {
373
+ const params = ast.caseParams(node.parameters, options.paramsCasing);
374
+ return {
375
+ path: params.filter((param) => param.in === "path"),
376
+ query: params.filter((param) => param.in === "query"),
377
+ header: params.filter((param) => param.in === "header"),
378
+ cookie: params.filter((param) => param.in === "cookie")
379
+ };
380
+ }
381
+ function getStatusCodeNumber(statusCode) {
382
+ const code = Number(statusCode);
383
+ return Number.isNaN(code) ? null : code;
384
+ }
385
+ function isSuccessStatusCode(statusCode) {
386
+ const code = getStatusCodeNumber(statusCode);
387
+ return code !== null && code >= 200 && code < 300;
388
+ }
389
+ function isErrorStatusCode(statusCode) {
390
+ const code = getStatusCodeNumber(statusCode);
391
+ return code !== null && code >= 400;
392
+ }
393
+ function resolveErrorNames(node, resolver) {
394
+ return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
395
+ }
396
+ function resolveSuccessNames(node, resolver) {
397
+ return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
316
398
  }
317
- __name(getParams$4, "getParams");
318
- const getTransformer$1 = /* @__PURE__ */ __name(({ node, casing }) => {
399
+ function resolveStatusCodeNames(node, resolver) {
400
+ return node.responses.map((response) => resolver.resolveResponseStatusName(node, response.statusCode));
401
+ }
402
+ const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
403
+ function resolveOperationTypeNames(node, resolver, options = {}) {
404
+ const cacheKey = `${node.operationId}\0${options.paramsCasing ?? ""}\0${options.order ?? ""}\0${options.responseStatusNames ?? ""}\0${(options.exclude ?? []).join(",")}`;
405
+ let byResolver = typeNamesByResolver.get(resolver);
406
+ if (byResolver) {
407
+ const cached = byResolver.get(cacheKey);
408
+ if (cached) return cached;
409
+ } else {
410
+ byResolver = /* @__PURE__ */ new Map();
411
+ typeNamesByResolver.set(resolver, byResolver);
412
+ }
413
+ const { path, query, header } = getOperationParameters(node, { paramsCasing: options.paramsCasing });
414
+ const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
415
+ const exclude = new Set(options.exclude ?? []);
416
+ const paramNames = [
417
+ ...path.map((param) => resolver.resolvePathParamsName(node, param)),
418
+ ...query.map((param) => resolver.resolveQueryParamsName(node, param)),
419
+ ...header.map((param) => resolver.resolveHeaderParamsName(node, param))
420
+ ];
421
+ const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null, resolver.resolveResponseName(node)];
422
+ const result = (options.order === "body-response-first" ? [
423
+ ...bodyAndResponseNames,
424
+ ...paramNames,
425
+ ...responseStatusNames
426
+ ] : [
427
+ ...paramNames,
428
+ ...bodyAndResponseNames,
429
+ ...responseStatusNames
430
+ ]).filter((name) => Boolean(name) && !exclude.has(name));
431
+ byResolver.set(cacheKey, result);
432
+ return result;
433
+ }
434
+ //#endregion
435
+ //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
436
+ const declarationPrinter$7 = functionPrinter({ mode: "declaration" });
437
+ const mutationKeyTransformer = ({ node, casing }) => {
438
+ if (!node.path) return [];
319
439
  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({
440
+ };
441
+ function MutationKey({ name, paramsCasing, node, transformer }) {
442
+ const paramsNode = ast.createFunctionParameters({ params: [] });
443
+ const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
444
+ const keys = (transformer ?? mutationKeyTransformer)({
325
445
  node,
326
446
  casing: paramsCasing
327
447
  });
@@ -338,28 +458,16 @@ function MutationKey({ name, paramsCasing, node, transformer = getTransformer$1
338
458
  })
339
459
  });
340
460
  }
341
- MutationKey.getParams = getParams$4;
342
- MutationKey.getTransformer = getTransformer$1;
343
461
  //#endregion
344
462
  //#region ../../internals/tanstack-query/src/utils.ts
345
463
  /**
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.
464
+ * Collects the Zod schema import names for an operation (response + request body).
465
+ *
466
+ * Returns an empty array when no resolver is provided or the operation has no request body schema.
358
467
  */
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));
468
+ function resolveZodSchemaNames(node, zodResolver) {
469
+ if (!zodResolver) return [];
470
+ return [zodResolver.resolveResponseName?.(node), node.requestBody?.content?.[0]?.schema ? zodResolver.resolveDataName?.(node) : null].filter((n) => Boolean(n));
363
471
  }
364
472
  /**
365
473
  * Resolve the type for a single path parameter.
@@ -383,30 +491,14 @@ function resolvePathParamType(node, param, resolver) {
383
491
  }
384
492
  /**
385
493
  * Derive a query-params group type from the resolver.
386
- * Returns `undefined` when no query params exist or when the group name
494
+ * Returns `null` when no query params exist or when the group name
387
495
  * equals the individual param name (no real group).
388
496
  */
389
497
  function resolveQueryGroupType(node, params, resolver) {
390
- if (!params.length) return void 0;
498
+ if (!params.length) return null;
391
499
  const firstParam = params[0];
392
500
  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;
501
+ if (groupName === resolver.resolveParamName(node, firstParam)) return null;
410
502
  return {
411
503
  type: ast.createParamsType({
412
504
  variant: "reference",
@@ -456,7 +548,7 @@ function buildQueryKeyParams(node, options) {
456
548
  const bodyType = node.requestBody?.content?.[0]?.schema ? ast.createParamsType({
457
549
  variant: "reference",
458
550
  name: resolver.resolveDataName(node)
459
- }) : void 0;
551
+ }) : null;
460
552
  const bodyRequired = node.requestBody?.required ?? false;
461
553
  const params = [];
462
554
  if (pathParams.length) {
@@ -481,47 +573,84 @@ function buildQueryKeyParams(node, options) {
481
573
  return ast.createFunctionParameters({ params });
482
574
  }
483
575
  /**
484
- * Build mutation arg params for paramsToTrigger mode.
485
- * Contains pathParams + data + queryParams + headers (all flattened, for type alias).
576
+ * Collect the names of the required params (no default) that drive the `enabled`
577
+ * guard. These are exactly the params that should be made optional in the
578
+ * generated signatures so callers can pass `undefined` to reach the disabled state.
486
579
  */
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));
580
+ function getEnabledParamNames(paramsNode) {
581
+ const required = [];
582
+ for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
583
+ const group = param;
584
+ for (const child of group.properties) if (!child.optional && child.default === void 0) required.push(child.name);
585
+ } else {
586
+ const fp = param;
587
+ if (!fp.optional && fp.default === void 0) required.push(fp.name);
588
+ }
589
+ return required;
590
+ }
591
+ /**
592
+ * Return a copy of `paramsNode` with the named params marked optional.
593
+ *
594
+ * Used to align signatures with the `enabled` guard: the guard already disables
595
+ * the query while a param is falsy, so the param should accept `undefined`. The
596
+ * change is type-only the `queryFn` keeps calling the client with a non-null
597
+ * assertion (see `injectNonNullAssertions`), so the emitted runtime is unchanged.
598
+ */
599
+ function markParamsOptional(paramsNode, names) {
600
+ if (names.length === 0) return paramsNode;
601
+ const nameSet = new Set(names);
602
+ const params = paramsNode.params.map((param) => {
603
+ if ("kind" in param && param.kind === "ParameterGroup") {
604
+ const group = param;
605
+ return {
606
+ ...group,
607
+ properties: group.properties.map((child) => nameSet.has(child.name) ? ast.createFunctionParameter({
608
+ name: child.name,
609
+ type: child.type,
610
+ rest: child.rest,
611
+ optional: true
612
+ }) : child)
613
+ };
614
+ }
615
+ const fp = param;
616
+ return nameSet.has(fp.name) ? ast.createFunctionParameter({
617
+ name: fp.name,
618
+ type: fp.type,
619
+ rest: fp.rest,
620
+ optional: true
621
+ }) : fp;
622
+ });
513
623
  return ast.createFunctionParameters({ params });
514
624
  }
625
+ functionPrinter({ mode: "declaration" });
626
+ const queryKeyTransformer = ({ node, casing }) => {
627
+ if (!node.path) return [];
628
+ const path = new URLPath(node.path, { casing });
629
+ const hasQueryParams = getOperationParameters(node).query.length > 0;
630
+ const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
631
+ return [
632
+ path.toObject({
633
+ type: "path",
634
+ stringify: true
635
+ }),
636
+ hasQueryParams ? "...(params ? [params] : [])" : null,
637
+ hasRequestBody ? "...(data ? [data] : [])" : null
638
+ ].filter(Boolean);
639
+ };
515
640
  //#endregion
516
641
  //#region src/utils.ts
517
- function transformName(name, type, transformers) {
518
- return transformers?.name?.(name, type) || name;
642
+ function printType(typeNode) {
643
+ if (!typeNode) return "unknown";
644
+ if (typeNode.variant === "reference") return typeNode.name;
645
+ if (typeNode.variant === "member") return `${typeNode.base}['${typeNode.key}']`;
646
+ if (typeNode.variant === "struct") return `{ ${typeNode.properties.map((p) => {
647
+ const typeStr = printType(p.type);
648
+ const key = /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(p.name) ? p.name : JSON.stringify(p.name);
649
+ return p.optional ? `${key}?: ${typeStr}` : `${key}: ${typeStr}`;
650
+ }).join("; ")} }`;
651
+ return "unknown";
519
652
  }
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) {
653
+ function wrapWithMaybeRefOrGetter(paramsNode, skip) {
525
654
  const wrappedParams = paramsNode.params.map((param) => {
526
655
  if ("kind" in param && param.kind === "ParameterGroup") {
527
656
  const group = param;
@@ -531,59 +660,38 @@ function wrapWithMaybeRefOrGetter(paramsNode) {
531
660
  ...p,
532
661
  type: p.type ? ast.createParamsType({
533
662
  variant: "reference",
534
- name: `MaybeRefOrGetter<${printType$4(p.type)}>`
663
+ name: `MaybeRefOrGetter<${printType(p.type)}>`
535
664
  }) : p.type
536
665
  }))
537
666
  };
538
667
  }
539
668
  const fp = param;
669
+ if (skip?.(fp.name)) return fp;
540
670
  return {
541
671
  ...fp,
542
672
  type: fp.type ? ast.createParamsType({
543
673
  variant: "reference",
544
- name: `MaybeRefOrGetter<${printType$4(fp.type)}>`
674
+ name: `MaybeRefOrGetter<${printType(fp.type)}>`
545
675
  }) : fp.type
546
676
  };
547
677
  });
548
678
  return ast.createFunctionParameters({ params: wrappedParams });
549
679
  }
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) {
680
+ //#endregion
681
+ //#region src/components/QueryKey.tsx
682
+ const declarationPrinter$5 = functionPrinter({ mode: "declaration" });
683
+ function buildQueryKeyParamsNode(node, options) {
563
684
  return wrapWithMaybeRefOrGetter(buildQueryKeyParams(node, options));
564
685
  }
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, {
686
+ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }) {
687
+ const baseParamsNode = buildQueryKeyParamsNode(node, {
581
688
  pathParamsType,
582
689
  paramsCasing,
583
690
  resolver: tsResolver
584
691
  });
692
+ const paramsNode = markParamsOptional(baseParamsNode, getEnabledParamNames(baseParamsNode));
585
693
  const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
586
- const keys = transformer({
694
+ const keys = (transformer ?? queryKeyTransformer)({
587
695
  node,
588
696
  casing: paramsCasing
589
697
  });
@@ -610,17 +718,14 @@ function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeNa
610
718
  })
611
719
  })] });
612
720
  }
613
- QueryKey.getParams = getParams$3;
614
- QueryKey.getTransformer = getTransformer;
615
- QueryKey.callPrinter = callPrinter$5;
616
721
  //#endregion
617
722
  //#region src/components/QueryOptions.tsx
618
723
  const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
619
724
  const callPrinter$4 = functionPrinter({ mode: "call" });
620
725
  function getQueryOptionsParams(node, options) {
621
726
  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, {
727
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
728
+ return wrapWithMaybeRefOrGetter(ast.createOperationParams(node, {
624
729
  paramsType,
625
730
  pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
626
731
  paramsCasing,
@@ -633,80 +738,30 @@ function getQueryOptionsParams(node, options) {
633
738
  }),
634
739
  default: "{}"
635
740
  })]
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(" && ");
741
+ }), (name) => name === "config");
688
742
  }
689
743
  function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
690
- const responseName = tsResolver.resolveResponseName(node);
744
+ const successNames = resolveSuccessNames(node, tsResolver);
745
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
691
746
  const errorNames = resolveErrorNames(node, tsResolver);
692
747
  const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
693
748
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
694
- const paramsNode = getQueryOptionsParams(node, {
749
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
750
+ pathParamsType,
751
+ paramsCasing,
752
+ resolver: tsResolver
753
+ });
754
+ const queryKeyParamsCall = callPrinter$4.print(queryKeyParamsNode) ?? "";
755
+ const enabledNames = getEnabledParamNames(queryKeyParamsNode);
756
+ const enabledText = enabledNames.length ? `enabled: () => ${enabledNames.map((n) => `!!toValue(${n})`).join(" && ")},` : "";
757
+ const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
695
758
  paramsType,
696
759
  paramsCasing,
697
760
  pathParamsType,
698
761
  resolver: tsResolver
699
- });
762
+ }), enabledNames);
700
763
  const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
701
764
  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
765
  return /* @__PURE__ */ jsx(File.Source, {
711
766
  name,
712
767
  isExportable: true,
@@ -721,7 +776,7 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
721
776
  ${enabledText}
722
777
  queryKey,
723
778
  queryFn: async ({ signal }) => {
724
- return ${clientName}(${addToValueCalls$1(clientCallStr)})
779
+ return ${clientName}(${addToValueCalls$1(clientCallStr, enabledNames)})
725
780
  },
726
781
  })
727
782
  `
@@ -735,28 +790,29 @@ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, para
735
790
  * Handles both inline params (`petId, config`) and object shorthand
736
791
  * params (`{ petId }, config`) by expanding to `{ petId: toValue(petId) }`.
737
792
  */
738
- function addToValueCalls$1(callStr) {
793
+ function addToValueCalls$1(callStr, enabledNames = []) {
794
+ const optional = new Set(enabledNames);
739
795
  let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
740
796
  if (inner.includes(":") || inner.includes("...")) return match;
741
- return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${k})`).join(", ")} }`;
797
+ return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${optional.has(k) ? `${k}!` : k})`).join(", ")} }`;
742
798
  });
743
799
  result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => {
744
800
  if (name === "config" || name === "signal" || name === "undefined") return match;
745
801
  if (match.includes("toValue(")) return match;
746
- return `toValue(${name})`;
802
+ return `toValue(${optional.has(name) ? `${name}!` : name})`;
747
803
  });
748
804
  return result;
749
805
  }
750
806
  __name(addToValueCalls$1, "addToValueCalls");
751
- QueryOptions.getParams = getQueryOptionsParams;
752
807
  //#endregion
753
808
  //#region src/components/InfiniteQuery.tsx
754
809
  const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
755
810
  const callPrinter$3 = functionPrinter({ mode: "call" });
756
- function getParams$2(node, options) {
811
+ function buildInfiniteQueryParamsNode(node, options) {
757
812
  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;
813
+ const successNames = resolveSuccessNames(node, resolver);
814
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
815
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
760
816
  const errorNames = resolveErrorNames(node, resolver);
761
817
  const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
762
818
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
@@ -777,57 +833,17 @@ function getParams$2(node, options) {
777
833
  }),
778
834
  default: "{}"
779
835
  });
780
- return wrapOperationParamsWithMaybeRef$1(ast.createOperationParams(node, {
836
+ return wrapWithMaybeRefOrGetter(ast.createOperationParams(node, {
781
837
  paramsType,
782
838
  pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
783
839
  paramsCasing,
784
840
  resolver,
785
841
  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";
842
+ }), (name) => name === "options");
827
843
  }
828
- __name(printType$2, "printType");
829
844
  function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
830
- const responseName = tsResolver.resolveResponseName(node);
845
+ const successNames = resolveSuccessNames(node, tsResolver);
846
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
831
847
  const errorNames = resolveErrorNames(node, tsResolver);
832
848
  const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
833
849
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
@@ -837,12 +853,13 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
837
853
  `TQueryData = ${TData}`,
838
854
  `TQueryKey extends QueryKey = ${queryKeyTypeName}`
839
855
  ];
840
- const queryKeyParamsNode = QueryKey.getParams(node, {
856
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
841
857
  pathParamsType,
842
858
  paramsCasing,
843
859
  resolver: tsResolver
844
860
  });
845
861
  const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
862
+ const enabledNames = getEnabledParamNames(queryKeyParamsNode);
846
863
  const queryOptionsParamsNode = getQueryOptionsParams(node, {
847
864
  paramsType,
848
865
  paramsCasing,
@@ -850,13 +867,13 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
850
867
  resolver: tsResolver
851
868
  });
852
869
  const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
853
- const paramsNode = getParams$2(node, {
870
+ const paramsNode = markParamsOptional(buildInfiniteQueryParamsNode(node, {
854
871
  paramsType,
855
872
  paramsCasing,
856
873
  pathParamsType,
857
874
  dataReturnType,
858
875
  resolver: tsResolver
859
- });
876
+ }), enabledNames);
860
877
  const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
861
878
  return /* @__PURE__ */ jsx(File.Source, {
862
879
  name,
@@ -867,7 +884,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
867
884
  export: true,
868
885
  generics: generics.join(", "),
869
886
  params: paramsSignature,
870
- JSDoc: { comments: getComments(node) },
887
+ JSDoc: { comments: buildOperationComments(node) },
871
888
  children: `
872
889
  const { query: queryConfig = {}, client: config = {} } = options ?? {}
873
890
  const { client: queryClient, ...resolvedOptions } = queryConfig
@@ -886,13 +903,13 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
886
903
  })
887
904
  });
888
905
  }
889
- InfiniteQuery.getParams = getParams$2;
890
906
  //#endregion
891
907
  //#region src/components/InfiniteQueryOptions.tsx
892
908
  const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
893
909
  const callPrinter$2 = functionPrinter({ mode: "call" });
894
910
  function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, paramsCasing, paramsType, dataReturnType, pathParamsType, queryParam, queryKeyName }) {
895
- const responseName = tsResolver.resolveResponseName(node);
911
+ const successNames = resolveSuccessNames(node, tsResolver);
912
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
896
913
  const queryFnDataType = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
897
914
  const errorNames = resolveErrorNames(node, tsResolver);
898
915
  const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
@@ -901,49 +918,39 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
901
918
  const parts = initialPageParam.split(" as ");
902
919
  return parts[parts.length - 1] ?? "unknown";
903
920
  })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
904
- const rawQueryParams = node.parameters.filter((p) => p.in === "query");
921
+ const rawQueryParams = getOperationParameters(node).query;
905
922
  const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
906
923
  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;
924
+ return groupName !== tsResolver.resolveParamName(node, rawQueryParams[0]) ? groupName : null;
925
+ })() : null;
926
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
910
927
  const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
911
- const paramsNode = getQueryOptionsParams(node, {
928
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
929
+ pathParamsType,
930
+ paramsCasing,
931
+ resolver: tsResolver
932
+ });
933
+ const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
934
+ const enabledNames = getEnabledParamNames(queryKeyParamsNode);
935
+ const enabledText = enabledNames.length ? `enabled: () => ${enabledNames.map((n) => `!!toValue(${n})`).join(" && ")},` : "";
936
+ const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
912
937
  paramsType,
913
938
  paramsCasing,
914
939
  pathParamsType,
915
940
  resolver: tsResolver
916
- });
941
+ }), enabledNames);
917
942
  const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
918
943
  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}`;
944
+ const hasNewParams = nextParam != null || previousParam != null;
945
+ const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
946
+ if (hasNewParams) {
947
+ const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
948
+ const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
949
+ return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
934
950
  }
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
- }
951
+ if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
952
+ 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"];
953
+ })();
947
954
  const queryOptionsArr = [
948
955
  `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
949
956
  getNextPageParamExpr,
@@ -969,7 +976,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
969
976
  queryKey,
970
977
  queryFn: async ({ signal, pageParam }) => {
971
978
  ${infiniteOverrideParams}
972
- return ${clientName}(${addToValueCalls(clientCallStr)})
979
+ return ${clientName}(${addToValueCalls(clientCallStr, enabledNames)})
973
980
  },
974
981
  ${queryOptionsArr.join(",\n")}
975
982
  })
@@ -990,7 +997,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
990
997
  ${enabledText}
991
998
  queryKey,
992
999
  queryFn: async ({ signal }) => {
993
- return ${clientName}(${addToValueCalls(clientCallStr)})
1000
+ return ${clientName}(${addToValueCalls(clientCallStr, enabledNames)})
994
1001
  },
995
1002
  ${queryOptionsArr.join(",\n")}
996
1003
  })
@@ -998,45 +1005,43 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
998
1005
  })
999
1006
  });
1000
1007
  }
1001
- function addToValueCalls(callStr) {
1008
+ function addToValueCalls(callStr, enabledNames = []) {
1009
+ const optional = new Set(enabledNames);
1002
1010
  let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
1003
1011
  if (inner.includes(":") || inner.includes("...")) return match;
1004
- return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${k})`).join(", ")} }`;
1012
+ return `{ ${inner.split(",").map((k) => k.trim()).filter(Boolean).map((k) => `${k}: toValue(${optional.has(k) ? `${k}!` : k})`).join(", ")} }`;
1005
1013
  });
1006
1014
  result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => {
1007
1015
  if (name === "config" || name === "signal" || name === "undefined") return match;
1008
1016
  if (match.includes("toValue(")) return match;
1009
- return `toValue(${name})`;
1017
+ return `toValue(${optional.has(name) ? `${name}!` : name})`;
1010
1018
  });
1011
1019
  return result;
1012
1020
  }
1013
- InfiniteQueryOptions.getParams = (node, options) => getQueryOptionsParams(node, options);
1014
1021
  //#endregion
1015
1022
  //#region src/components/Mutation.tsx
1016
1023
  const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
1017
1024
  const callPrinter$1 = functionPrinter({ mode: "call" });
1018
1025
  const keysPrinter = functionPrinter({ mode: "keys" });
1019
- function getParams$1(node, options) {
1026
+ function createMutationArgParams(node, options) {
1027
+ return ast.createOperationParams(node, {
1028
+ paramsType: "inline",
1029
+ pathParamsType: "inline",
1030
+ paramsCasing: options.paramsCasing,
1031
+ resolver: options.resolver
1032
+ });
1033
+ }
1034
+ function buildMutationParamsNode(node, options) {
1020
1035
  const { paramsCasing, dataReturnType, resolver } = options;
1021
- const responseName = resolver.resolveResponseName(node);
1022
- const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : void 0;
1036
+ const successNames = resolveSuccessNames(node, resolver);
1037
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
1023
1038
  const errorNames = resolveErrorNames(node, resolver);
1024
1039
  const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1025
1040
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1026
- const mutationArgWrapped = buildMutationArgParams(node, {
1041
+ const wrappedParamsNode = wrapWithMaybeRefOrGetter(createMutationArgParams(node, {
1027
1042
  paramsCasing,
1028
1043
  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 });
1044
+ }));
1040
1045
  const TRequestWrapped = wrappedParamsNode.params.length > 0 ? declarationPrinter$1.print(wrappedParamsNode) ?? "" : "";
1041
1046
  return ast.createFunctionParameters({ params: [ast.createFunctionParameter({
1042
1047
  name: "options",
@@ -1046,34 +1051,22 @@ function getParams$1(node, options) {
1046
1051
  mutation?: MutationObserverOptions<${[
1047
1052
  TData,
1048
1053
  TError,
1049
- TRequestWrapped ? `{${TRequestWrapped}}` : "void",
1054
+ TRequestWrapped ? `{${TRequestWrapped}}` : "undefined",
1050
1055
  "TContext"
1051
1056
  ].join(", ")}> & { client?: QueryClient },
1052
- client?: ${requestName ? `Partial<RequestConfig<${requestName}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"},
1057
+ client?: ${buildRequestConfigType(node, resolver)},
1053
1058
  }`
1054
1059
  }),
1055
1060
  default: "{}"
1056
1061
  })] });
1057
1062
  }
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
1063
  function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType, dataReturnType, node, tsResolver, mutationKeyName }) {
1072
- const responseName = tsResolver.resolveResponseName(node);
1064
+ const successNames = resolveSuccessNames(node, tsResolver);
1065
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
1073
1066
  const errorNames = resolveErrorNames(node, tsResolver);
1074
1067
  const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1075
1068
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1076
- const mutationArgParamsNode = buildMutationArgParams(node, {
1069
+ const mutationArgParamsNode = createMutationArgParams(node, {
1077
1070
  paramsCasing,
1078
1071
  resolver: tsResolver
1079
1072
  });
@@ -1083,10 +1076,10 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
1083
1076
  const generics = [
1084
1077
  TData,
1085
1078
  TError,
1086
- TRequest ? `{${TRequest}}` : "void",
1079
+ TRequest ? `{${TRequest}}` : "undefined",
1087
1080
  "TContext"
1088
1081
  ].join(", ");
1089
- const mutationKeyParamsNode = MutationKey.getParams();
1082
+ const mutationKeyParamsNode = ast.createFunctionParameters({ params: [] });
1090
1083
  const mutationKeyParamsCall = callPrinter$1.print(mutationKeyParamsNode) ?? "";
1091
1084
  const clientCallParamsNode = ast.createOperationParams(node, {
1092
1085
  paramsType,
@@ -1097,13 +1090,13 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
1097
1090
  name: "config",
1098
1091
  type: ast.createParamsType({
1099
1092
  variant: "reference",
1100
- name: node.requestBody?.content?.[0]?.schema ? `Partial<RequestConfig<${tsResolver.resolveDataName(node)}>> & { client?: Client }` : "Partial<RequestConfig> & { client?: Client }"
1093
+ name: buildRequestConfigType(node, tsResolver)
1101
1094
  }),
1102
1095
  default: "{}"
1103
1096
  })]
1104
1097
  });
1105
1098
  const clientCallStr = callPrinter$1.print(clientCallParamsNode) ?? "";
1106
- const paramsNode = getParams$1(node, {
1099
+ const paramsNode = buildMutationParamsNode(node, {
1107
1100
  paramsCasing,
1108
1101
  dataReturnType,
1109
1102
  resolver: tsResolver
@@ -1117,7 +1110,7 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
1117
1110
  name,
1118
1111
  export: true,
1119
1112
  params: paramsSignature,
1120
- JSDoc: { comments: getComments(node) },
1113
+ JSDoc: { comments: buildOperationComments(node) },
1121
1114
  generics: ["TContext"],
1122
1115
  children: `
1123
1116
  const { mutation = {}, client: config = {} } = options ?? {}
@@ -1135,15 +1128,15 @@ function Mutation({ name, clientName, paramsCasing, paramsType, pathParamsType,
1135
1128
  })
1136
1129
  });
1137
1130
  }
1138
- Mutation.getParams = getParams$1;
1139
1131
  //#endregion
1140
1132
  //#region src/components/Query.tsx
1141
1133
  const declarationPrinter = functionPrinter({ mode: "declaration" });
1142
1134
  const callPrinter = functionPrinter({ mode: "call" });
1143
- function getParams(node, options) {
1135
+ function buildQueryParamsNode(node, options) {
1144
1136
  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;
1137
+ const successNames = resolveSuccessNames(node, resolver);
1138
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.resolveResponseName(node);
1139
+ const requestName = node.requestBody?.content?.[0]?.schema ? resolver.resolveDataName(node) : null;
1147
1140
  const errorNames = resolveErrorNames(node, resolver);
1148
1141
  const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1149
1142
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
@@ -1164,54 +1157,17 @@ function getParams(node, options) {
1164
1157
  }),
1165
1158
  default: "{}"
1166
1159
  });
1167
- return wrapOperationParamsWithMaybeRef(ast.createOperationParams(node, {
1160
+ return wrapWithMaybeRefOrGetter(ast.createOperationParams(node, {
1168
1161
  paramsType,
1169
1162
  pathParamsType: paramsType === "object" ? "object" : pathParamsType === "object" ? "object" : "inline",
1170
1163
  paramsCasing,
1171
1164
  resolver,
1172
1165
  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";
1166
+ }), (name) => name === "options");
1212
1167
  }
1213
1168
  function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsType, paramsCasing, pathParamsType, dataReturnType, node, tsResolver }) {
1214
- const responseName = tsResolver.resolveResponseName(node);
1169
+ const successNames = resolveSuccessNames(node, tsResolver);
1170
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
1215
1171
  const errorNames = resolveErrorNames(node, tsResolver);
1216
1172
  const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
1217
1173
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
@@ -1221,12 +1177,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
1221
1177
  `TQueryData = ${TData}`,
1222
1178
  `TQueryKey extends QueryKey = ${queryKeyTypeName}`
1223
1179
  ];
1224
- const queryKeyParamsNode = QueryKey.getParams(node, {
1180
+ const queryKeyParamsNode = buildQueryKeyParamsNode(node, {
1225
1181
  pathParamsType,
1226
1182
  paramsCasing,
1227
1183
  resolver: tsResolver
1228
1184
  });
1229
1185
  const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
1186
+ const enabledNames = getEnabledParamNames(queryKeyParamsNode);
1230
1187
  const queryOptionsParamsNode = getQueryOptionsParams(node, {
1231
1188
  paramsType,
1232
1189
  paramsCasing,
@@ -1234,13 +1191,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
1234
1191
  resolver: tsResolver
1235
1192
  });
1236
1193
  const queryOptionsParamsCall = callPrinter.print(queryOptionsParamsNode) ?? "";
1237
- const paramsNode = getParams(node, {
1194
+ const paramsNode = markParamsOptional(buildQueryParamsNode(node, {
1238
1195
  paramsType,
1239
1196
  paramsCasing,
1240
1197
  pathParamsType,
1241
1198
  dataReturnType,
1242
1199
  resolver: tsResolver
1243
- });
1200
+ }), enabledNames);
1244
1201
  const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1245
1202
  return /* @__PURE__ */ jsx(File.Source, {
1246
1203
  name,
@@ -1251,7 +1208,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
1251
1208
  export: true,
1252
1209
  generics: generics.join(", "),
1253
1210
  params: paramsSignature,
1254
- JSDoc: { comments: getComments(node) },
1211
+ JSDoc: { comments: buildOperationComments(node) },
1255
1212
  children: `
1256
1213
  const { query: queryConfig = {}, client: config = {} } = options ?? {}
1257
1214
  const { client: queryClient, ...resolvedOptions } = queryConfig
@@ -1270,8 +1227,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
1270
1227
  })
1271
1228
  });
1272
1229
  }
1273
- Query.getParams = getParams;
1274
1230
  //#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 };
1231
+ 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
1232
 
1277
- //# sourceMappingURL=components-D1UhYFgY.js.map
1233
+ //# sourceMappingURL=components-BZqujNQv.js.map