@kubb/plugin-react-query 5.0.0-beta.30 → 5.0.0-beta.33

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 (35) hide show
  1. package/dist/{components-CDmg-RPi.js → components-BVmVgpLX.js} +142 -62
  2. package/dist/components-BVmVgpLX.js.map +1 -0
  3. package/dist/{components-MPBTffPl.cjs → components-DLUeLMsz.cjs} +147 -61
  4. package/dist/components-DLUeLMsz.cjs.map +1 -0
  5. package/dist/components.cjs +1 -1
  6. package/dist/components.d.ts +3 -1
  7. package/dist/components.js +1 -1
  8. package/dist/{generators-BtsWNz-6.cjs → generators--AcF4Y4n.cjs} +35 -153
  9. package/dist/generators--AcF4Y4n.cjs.map +1 -0
  10. package/dist/{generators-Bma51Uar.js → generators-BFn9CLBS.js} +36 -154
  11. package/dist/generators-BFn9CLBS.js.map +1 -0
  12. package/dist/generators.cjs +1 -1
  13. package/dist/generators.js +1 -1
  14. package/dist/index.cjs +40 -10
  15. package/dist/index.cjs.map +1 -1
  16. package/dist/index.js +40 -10
  17. package/dist/index.js.map +1 -1
  18. package/extension.yaml +9 -32
  19. package/package.json +8 -8
  20. package/src/components/InfiniteQuery.tsx +13 -8
  21. package/src/components/InfiniteQueryOptions.tsx +8 -8
  22. package/src/components/Query.tsx +6 -1
  23. package/src/components/QueryOptions.tsx +12 -8
  24. package/src/components/SuspenseInfiniteQueryOptions.tsx +0 -6
  25. package/src/generators/hookOptionsGenerator.tsx +12 -22
  26. package/src/generators/infiniteQueryGenerator.tsx +19 -22
  27. package/src/generators/mutationGenerator.tsx +19 -22
  28. package/src/generators/queryGenerator.tsx +19 -22
  29. package/src/generators/suspenseInfiniteQueryGenerator.tsx +19 -22
  30. package/src/generators/suspenseQueryGenerator.tsx +20 -22
  31. package/src/plugin.ts +4 -16
  32. package/dist/components-CDmg-RPi.js.map +0 -1
  33. package/dist/components-MPBTffPl.cjs.map +0 -1
  34. package/dist/generators-Bma51Uar.js.map +0 -1
  35. package/dist/generators-BtsWNz-6.cjs.map +0 -1
@@ -310,38 +310,31 @@ var URLPath = class {
310
310
  }
311
311
  };
312
312
  //#endregion
313
- //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
314
- const declarationPrinter$10 = functionPrinter({ mode: "declaration" });
315
- const mutationKeyTransformer = ({ node, casing }) => {
316
- return [`{ url: '${new URLPath(node.path, { casing }).toURLPath()}' }`];
317
- };
318
- function MutationKey({ name, paramsCasing, node, transformer }) {
319
- const paramsNode = ast.createFunctionParameters({ params: [] });
320
- const paramsSignature = declarationPrinter$10.print(paramsNode) ?? "";
321
- const keys = (transformer ?? mutationKeyTransformer)({
322
- node,
323
- casing: paramsCasing
324
- });
325
- return /* @__PURE__ */ jsx(File.Source, {
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 {
326
327
  name,
327
- isExportable: true,
328
- isIndexable: true,
329
- children: /* @__PURE__ */ jsx(Function.Arrow, {
330
- name,
331
- export: true,
332
- params: paramsSignature,
333
- singleLine: true,
334
- children: `[${keys.join(", ")}] as const`
335
- })
336
- });
328
+ extname,
329
+ tag: node.tags[0] ?? "default",
330
+ path: node.path
331
+ };
337
332
  }
338
- //#endregion
339
- //#region ../../internals/shared/src/operation.ts
340
333
  function getOperationLink(node, link) {
341
334
  if (!link) return null;
342
335
  if (typeof link === "function") return link(node) ?? null;
343
336
  if (link === "urlPath") return node.path ? `{@link ${new URLPath(node.path).URL}}` : null;
344
- return `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}`;
337
+ return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
345
338
  }
346
339
  function getContentTypeInfo(node) {
347
340
  const contentTypes = node.requestBody?.content?.map((e) => e.contentType) ?? [];
@@ -439,14 +432,41 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
439
432
  return result;
440
433
  }
441
434
  //#endregion
435
+ //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
436
+ const declarationPrinter$10 = functionPrinter({ mode: "declaration" });
437
+ const mutationKeyTransformer = ({ node, casing }) => {
438
+ if (!node.path) return [];
439
+ return [`{ url: '${new URLPath(node.path, { casing }).toURLPath()}' }`];
440
+ };
441
+ function MutationKey({ name, paramsCasing, node, transformer }) {
442
+ const paramsNode = ast.createFunctionParameters({ params: [] });
443
+ const paramsSignature = declarationPrinter$10.print(paramsNode) ?? "";
444
+ const keys = (transformer ?? mutationKeyTransformer)({
445
+ node,
446
+ casing: paramsCasing
447
+ });
448
+ return /* @__PURE__ */ jsx(File.Source, {
449
+ name,
450
+ isExportable: true,
451
+ isIndexable: true,
452
+ children: /* @__PURE__ */ jsx(Function.Arrow, {
453
+ name,
454
+ export: true,
455
+ params: paramsSignature,
456
+ singleLine: true,
457
+ children: `[${keys.join(", ")}] as const`
458
+ })
459
+ });
460
+ }
461
+ //#endregion
442
462
  //#region ../../internals/tanstack-query/src/utils.ts
443
463
  function matchesPattern(node, ov) {
444
464
  const { type, pattern } = ov;
445
465
  const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
446
466
  if (type === "operationId") return matches(node.operationId);
447
467
  if (type === "tag") return node.tags.some((t) => matches(t));
448
- if (type === "path") return matches(node.path);
449
- if (type === "method") return matches(node.method);
468
+ if (type === "path") return node.path !== void 0 && matches(node.path);
469
+ if (type === "method") return node.method !== void 0 && matches(node.method);
450
470
  return false;
451
471
  }
452
472
  /**
@@ -574,7 +594,12 @@ function buildQueryKeyParams(node, options) {
574
594
  params.push(...buildGroupParam("params", node, queryParams, queryGroupType, resolver));
575
595
  return ast.createFunctionParameters({ params });
576
596
  }
577
- function buildEnabledCheck(paramsNode) {
597
+ /**
598
+ * Collect the names of the required params (no default) that drive the `enabled`
599
+ * guard. These are exactly the params that should be made optional in the
600
+ * generated signatures so callers can pass `undefined` to reach the disabled state.
601
+ */
602
+ function getEnabledParamNames(paramsNode) {
578
603
  const required = [];
579
604
  for (const param of paramsNode.params) if ("kind" in param && param.kind === "ParameterGroup") {
580
605
  const group = param;
@@ -583,12 +608,67 @@ function buildEnabledCheck(paramsNode) {
583
608
  const fp = param;
584
609
  if (!fp.optional && fp.default === void 0) required.push(fp.name);
585
610
  }
586
- return required.join(" && ");
611
+ return required;
612
+ }
613
+ /**
614
+ * Return a copy of `paramsNode` with the named params marked optional.
615
+ *
616
+ * Used to align signatures with the `enabled` guard: the guard already disables
617
+ * the query while a param is falsy, so the param should accept `undefined`. The
618
+ * change is type-only — the `queryFn` keeps calling the client with a non-null
619
+ * assertion (see `injectNonNullAssertions`), so the emitted runtime is unchanged.
620
+ */
621
+ function markParamsOptional(paramsNode, names) {
622
+ if (names.length === 0) return paramsNode;
623
+ const nameSet = new Set(names);
624
+ const params = paramsNode.params.map((param) => {
625
+ if ("kind" in param && param.kind === "ParameterGroup") {
626
+ const group = param;
627
+ return {
628
+ ...group,
629
+ properties: group.properties.map((child) => nameSet.has(child.name) ? ast.createFunctionParameter({
630
+ name: child.name,
631
+ type: child.type,
632
+ rest: child.rest,
633
+ optional: true
634
+ }) : child)
635
+ };
636
+ }
637
+ const fp = param;
638
+ return nameSet.has(fp.name) ? ast.createFunctionParameter({
639
+ name: fp.name,
640
+ type: fp.type,
641
+ rest: fp.rest,
642
+ optional: true
643
+ }) : fp;
644
+ });
645
+ return ast.createFunctionParameters({ params });
646
+ }
647
+ /**
648
+ * Add a non-null assertion (`!`) to the named params inside a printed client-call
649
+ * string. Bridges the type gap created by `markParamsOptional` while keeping the
650
+ * runtime identical (the `!` is erased at compile time).
651
+ *
652
+ * Handles destructured shorthand groups (`{ petId }` → `{ petId: petId! }`) and
653
+ * standalone identifiers (`params` → `params!`).
654
+ */
655
+ function injectNonNullAssertions(callStr, names) {
656
+ if (names.length === 0) return callStr;
657
+ const nameSet = new Set(names);
658
+ let result = callStr.replace(/\{\s*([\w,\s]+)\s*\}(?=\s*,)/g, (match, inner) => {
659
+ if (inner.includes(":") || inner.includes("...")) return match;
660
+ const keys = inner.split(",").map((k) => k.trim()).filter(Boolean);
661
+ if (!keys.some((k) => nameSet.has(k))) return match;
662
+ return `{ ${keys.map((k) => nameSet.has(k) ? `${k}: ${k}!` : k).join(", ")} }`;
663
+ });
664
+ result = result.replace(/(?<![{.:?])\b(\w+)\b(?=\s*,)/g, (match, name) => nameSet.has(name) ? `${name}!` : match);
665
+ return result;
587
666
  }
588
667
  //#endregion
589
668
  //#region ../../internals/tanstack-query/src/components/QueryKey.tsx
590
669
  const declarationPrinter$9 = functionPrinter({ mode: "declaration" });
591
670
  const queryKeyTransformer = ({ node, casing }) => {
671
+ if (!node.path) return [];
592
672
  const path = new URLPath(node.path, { casing });
593
673
  const hasQueryParams = getOperationParameters(node).query.length > 0;
594
674
  const hasRequestBody = !!node.requestBody?.content?.[0]?.schema;
@@ -602,11 +682,12 @@ const queryKeyTransformer = ({ node, casing }) => {
602
682
  ].filter(Boolean);
603
683
  };
604
684
  function QueryKey({ name, node, tsResolver, paramsCasing, pathParamsType, typeName, transformer }) {
605
- const paramsNode = buildQueryKeyParams(node, {
685
+ const baseParamsNode = buildQueryKeyParams(node, {
606
686
  pathParamsType,
607
687
  paramsCasing,
608
688
  resolver: tsResolver
609
689
  });
690
+ const paramsNode = markParamsOptional(baseParamsNode, getEnabledParamNames(baseParamsNode));
610
691
  const paramsSignature = declarationPrinter$9.print(paramsNode) ?? "";
611
692
  const keys = (transformer ?? queryKeyTransformer)({
612
693
  node,
@@ -654,28 +735,29 @@ function getQueryOptionsParams(node, options) {
654
735
  })]
655
736
  });
656
737
  }
657
- function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName }) {
738
+ function QueryOptions({ name, clientName, dataReturnType, node, tsResolver, paramsCasing, paramsType, pathParamsType, queryKeyName, suspense }) {
658
739
  const successNames = resolveSuccessNames(node, tsResolver);
659
740
  const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.resolveResponseName(node);
660
741
  const errorNames = resolveErrorNames(node, tsResolver);
661
742
  const TData = dataReturnType === "data" ? responseName : `ResponseConfig<${responseName}>`;
662
743
  const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
663
- const paramsNode = getQueryOptionsParams(node, {
664
- paramsType,
665
- paramsCasing,
666
- pathParamsType,
667
- resolver: tsResolver
668
- });
669
- const paramsSignature = declarationPrinter$8.print(paramsNode) ?? "";
670
- const clientCallStr = (callPrinter$8.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
671
744
  const queryKeyParamsNode = buildQueryKeyParams(node, {
672
745
  pathParamsType,
673
746
  paramsCasing,
674
747
  resolver: tsResolver
675
748
  });
676
749
  const queryKeyParamsCall = callPrinter$8.print(queryKeyParamsNode) ?? "";
677
- const enabledSource = buildEnabledCheck(queryKeyParamsNode);
678
- const enabledText = enabledSource ? `enabled: !!(${enabledSource}),` : "";
750
+ const enabledNames = getEnabledParamNames(queryKeyParamsNode);
751
+ const optionalNames = suspense ? [] : enabledNames;
752
+ const enabledText = suspense ? "" : enabledNames.length ? `enabled: !!(${enabledNames.join(" && ")}),` : "";
753
+ const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
754
+ paramsType,
755
+ paramsCasing,
756
+ pathParamsType,
757
+ resolver: tsResolver
758
+ }), optionalNames);
759
+ const paramsSignature = declarationPrinter$8.print(paramsNode) ?? "";
760
+ const clientCallStr = injectNonNullAssertions((callPrinter$8.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }"), optionalNames);
679
761
  return /* @__PURE__ */ jsx(File.Source, {
680
762
  name,
681
763
  isExportable: true,
@@ -755,6 +837,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
755
837
  resolver: tsResolver
756
838
  });
757
839
  const queryKeyParamsCall = callPrinter$7.print(queryKeyParamsNode) ?? "";
840
+ const enabledNames = getEnabledParamNames(queryKeyParamsNode);
758
841
  const queryOptionsParamsNode = getQueryOptionsParams(node, {
759
842
  paramsType,
760
843
  paramsCasing,
@@ -762,14 +845,14 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
762
845
  resolver: tsResolver
763
846
  });
764
847
  const queryOptionsParamsCall = callPrinter$7.print(queryOptionsParamsNode) ?? "";
765
- const paramsNode = buildInfiniteQueryParamsNode(node, {
848
+ const paramsNode = markParamsOptional(buildInfiniteQueryParamsNode(node, {
766
849
  paramsType,
767
850
  paramsCasing,
768
851
  pathParamsType,
769
852
  dataReturnType,
770
853
  resolver: tsResolver,
771
854
  pageParamGeneric: "TPageParam"
772
- });
855
+ }), enabledNames);
773
856
  const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
774
857
  return /* @__PURE__ */ jsx(File.Source, {
775
858
  name,
@@ -823,22 +906,22 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
823
906
  })() : null;
824
907
  const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
825
908
  const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
826
- const paramsNode = getQueryOptionsParams(node, {
827
- paramsType,
828
- paramsCasing,
829
- pathParamsType,
830
- resolver: tsResolver
831
- });
832
- const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
833
- const clientCallStr = (callPrinter$6.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }");
834
909
  const queryKeyParamsNode = buildQueryKeyParams(node, {
835
910
  pathParamsType,
836
911
  paramsCasing,
837
912
  resolver: tsResolver
838
913
  });
839
914
  const queryKeyParamsCall = callPrinter$6.print(queryKeyParamsNode) ?? "";
840
- const enabledSource = buildEnabledCheck(queryKeyParamsNode);
841
- const enabledText = enabledSource ? `enabled: !!(${enabledSource}),` : "";
915
+ const enabledNames = getEnabledParamNames(queryKeyParamsNode);
916
+ const enabledText = enabledNames.length ? `enabled: !!(${enabledNames.join(" && ")}),` : "";
917
+ const paramsNode = markParamsOptional(getQueryOptionsParams(node, {
918
+ paramsType,
919
+ paramsCasing,
920
+ pathParamsType,
921
+ resolver: tsResolver
922
+ }), enabledNames);
923
+ const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
924
+ const clientCallStr = injectNonNullAssertions((callPrinter$6.print(paramsNode) ?? "").replace(/\bconfig\b(?=[^,]*$)/, "{ ...config, signal: config.signal ?? signal }"), enabledNames);
842
925
  const hasNewParams = nextParam != null || previousParam != null;
843
926
  const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
844
927
  if (hasNewParams) {
@@ -1120,6 +1203,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
1120
1203
  resolver: tsResolver
1121
1204
  });
1122
1205
  const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
1206
+ const enabledNames = getEnabledParamNames(queryKeyParamsNode);
1123
1207
  const queryOptionsParamsNode = getQueryOptionsParams(node, {
1124
1208
  paramsType,
1125
1209
  paramsCasing,
@@ -1127,13 +1211,13 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, paramsT
1127
1211
  resolver: tsResolver
1128
1212
  });
1129
1213
  const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
1130
- const paramsNode = buildQueryParamsNode(node, {
1214
+ const paramsNode = markParamsOptional(buildQueryParamsNode(node, {
1131
1215
  paramsType,
1132
1216
  paramsCasing,
1133
1217
  pathParamsType,
1134
1218
  dataReturnType,
1135
1219
  resolver: tsResolver
1136
- });
1220
+ }), enabledNames);
1137
1221
  const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
1138
1222
  return /* @__PURE__ */ jsx(File.Source, {
1139
1223
  name,
@@ -1305,8 +1389,6 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
1305
1389
  resolver: tsResolver
1306
1390
  });
1307
1391
  const queryKeyParamsCall = callPrinter$1.print(queryKeyParamsNode) ?? "";
1308
- const enabledSource = buildEnabledCheck(queryKeyParamsNode);
1309
- const enabledText = enabledSource ? `enabled: !!(${enabledSource}),` : "";
1310
1392
  const hasNewParams = nextParam != null || previousParam != null;
1311
1393
  const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
1312
1394
  if (hasNewParams) {
@@ -1338,7 +1420,6 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
1338
1420
  children: `
1339
1421
  const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1340
1422
  return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1341
- ${enabledText}
1342
1423
  queryKey,
1343
1424
  queryFn: async ({ signal, pageParam }) => {
1344
1425
  ${infiniteOverrideParams}
@@ -1360,7 +1441,6 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
1360
1441
  children: `
1361
1442
  const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1362
1443
  return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1363
- ${enabledText}
1364
1444
  queryKey,
1365
1445
  queryFn: async ({ signal }) => {
1366
1446
  return ${clientName}(${clientCallStr})
@@ -1466,6 +1546,6 @@ function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
1466
1546
  });
1467
1547
  }
1468
1548
  //#endregion
1469
- export { mutationKeyTransformer as _, Mutation as a, InfiniteQuery as c, queryKeyTransformer as d, resolveOperationOverrides as f, MutationKey as g, resolveOperationTypeNames as h, Query as i, QueryOptions as l, getOperationParameters as m, SuspenseInfiniteQueryOptions as n, MutationOptions as o, resolveZodSchemaNames as p, SuspenseInfiniteQuery as r, InfiniteQueryOptions as s, SuspenseQuery as t, QueryKey as u, camelCase as v };
1549
+ export { operationFileEntry as _, Mutation as a, InfiniteQuery as c, queryKeyTransformer as d, resolveOperationOverrides as f, getOperationParameters as g, mutationKeyTransformer as h, Query as i, QueryOptions as l, MutationKey as m, SuspenseInfiniteQueryOptions as n, MutationOptions as o, resolveZodSchemaNames as p, SuspenseInfiniteQuery as r, InfiniteQueryOptions as s, SuspenseQuery as t, QueryKey as u, resolveOperationTypeNames as v, camelCase as y };
1470
1550
 
1471
- //# sourceMappingURL=components-CDmg-RPi.js.map
1551
+ //# sourceMappingURL=components-BVmVgpLX.js.map