@kubb/plugin-vue-query 5.0.0-beta.94 → 5.0.0-beta.95

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.
package/dist/index.cjs CHANGED
@@ -5,6 +5,10 @@ Object.defineProperties(exports, {
5
5
  //#region \0rolldown/runtime.js
6
6
  var __create = Object.create;
7
7
  var __defProp = Object.defineProperty;
8
+ var __name = (target, value) => __defProp(target, "name", {
9
+ value,
10
+ configurable: true
11
+ });
8
12
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
9
13
  var __getOwnPropNames = Object.getOwnPropertyNames;
10
14
  var __getProtoOf = Object.getPrototypeOf;
@@ -56,6 +60,16 @@ function toCamelOrPascal(text, pascal) {
56
60
  function camelCase(text, { prefix = "", suffix = "" } = {}) {
57
61
  return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
58
62
  }
63
+ /**
64
+ * Uppercases only the first character of `text`, leaving the rest untouched.
65
+ * Unlike {@link pascalCase} it never re-splits word boundaries or strips characters.
66
+ *
67
+ * @example
68
+ * `capitalize('getPetById') // 'GetPetById'`
69
+ */
70
+ function capitalize(text) {
71
+ return `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
72
+ }
59
73
  //#endregion
60
74
  //#region ../../internals/utils/src/reserved.ts
61
75
  /**
@@ -559,39 +573,12 @@ function createGroupConfig(group) {
559
573
  };
560
574
  }
561
575
  //#endregion
562
- //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
563
- const declarationPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
564
- const mutationKeyTransformer = ({ node }) => {
565
- if (!node.path) return [];
566
- return [`{ url: '${Url.toPath(node.path)}' }`];
567
- };
568
- function MutationKey({ name, node, transformer }) {
569
- const paramsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: [] });
570
- const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
571
- const keys = (transformer ?? mutationKeyTransformer)({
572
- node,
573
- casing: "camelcase"
574
- });
575
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
576
- name,
577
- isExportable: true,
578
- isIndexable: true,
579
- children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function.Arrow, {
580
- name,
581
- export: true,
582
- params: paramsSignature,
583
- singleLine: true,
584
- children: `[${keys.join(", ")}] as const`
585
- })
586
- });
587
- }
588
- //#endregion
589
576
  //#region ../../internals/tanstack-query/src/utils.ts
590
577
  /**
591
578
  * The grouped request options, ordered for both the destructured signature and the
592
579
  * call passed to the underlying client.
593
580
  */
594
- const requestGroupOrder$1 = [
581
+ const requestGroupOrder = [
595
582
  "path",
596
583
  "query",
597
584
  "body",
@@ -622,7 +609,7 @@ function maybeRefOrGetter(type) {
622
609
  * `MaybeRefOrGetter` per group.
623
610
  */
624
611
  function buildGroupedRequestParam(node, options) {
625
- const { resolver, keys = requestGroupOrder$1, memberTypeWrapper } = options;
612
+ const { resolver, keys = requestGroupOrder, memberTypeWrapper } = options;
626
613
  const { groups, hasRequiredPath, hasRequiredQuery, hasRequiredHeader } = getRequestGroupOptionality(node);
627
614
  const names = keys.filter((key) => groups[key]);
628
615
  if (names.length === 0) return null;
@@ -634,7 +621,7 @@ function buildGroupedRequestParam(node, options) {
634
621
  };
635
622
  const isOptional = names.every((name) => !requiredByGroup[name]);
636
623
  const optionsName = resolver.response.options(node);
637
- const omittedKeys = requestGroupOrder$1.filter((key) => !keys.includes(key));
624
+ const omittedKeys = requestGroupOrder.filter((key) => !keys.includes(key));
638
625
  const optionsType = omittedKeys.length > 0 ? `Omit<${optionsName}, ${omittedKeys.map((key) => `'${key}'`).join(" | ")}>` : optionsName;
639
626
  if (memberTypeWrapper) {
640
627
  const members = names.map((name) => ({
@@ -673,6 +660,273 @@ function buildQueryOptionsParams(node, options) {
673
660
  default: "{}"
674
661
  })].filter((param) => param !== null) });
675
662
  }
663
+ /**
664
+ * Builds the call to a client `<op>` function inside a query/mutation hook body. The function takes
665
+ * a single grouped options object, so the operation's request groups are passed as
666
+ * shorthand alongside the spread `config`, with `throwOnError: true` pinned last so a caller's config
667
+ * can't flip the query's error semantics. Queries thread the TanStack `signal`; mutations omit it.
668
+ *
669
+ * When `unwrapName` is set, each request group is passed as an explicit member unwrapped through it,
670
+ * used by vue-query to resolve refs and getters with `toValue(...)` at call time.
671
+ *
672
+ * @example
673
+ * ```ts
674
+ * buildClientCall(node, { clientName: 'getPetById', signal: true })
675
+ * // getPetById({ path, ...config, signal: config.signal ?? signal, throwOnError: true })
676
+ * ```
677
+ */
678
+ function buildClientCall(node, options) {
679
+ const { clientName, signal = false, unwrapName } = options;
680
+ const { groups } = getRequestGroupOptionality(node);
681
+ return `${clientName}({ ${[
682
+ "...config",
683
+ ...requestGroupOrder.filter((key) => groups[key]).map((name) => unwrapName ? `${name}: ${unwrapName(name)}` : name),
684
+ signal ? "signal: config.signal ?? signal" : null,
685
+ "throwOnError: true"
686
+ ].filter((part) => part !== null).join(", ")} })`;
687
+ }
688
+ /**
689
+ * Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
690
+ * success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
691
+ */
692
+ function buildResponseTypes(node, resolver) {
693
+ const successNames = resolveSuccessNames(node, resolver);
694
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
695
+ const errorNames = resolveErrorNames(node, resolver);
696
+ return {
697
+ TData: responseName,
698
+ TError: `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`
699
+ };
700
+ }
701
+ function resolveFallbackPageParamType(initialPageParam) {
702
+ if (typeof initialPageParam === "number") return "number";
703
+ if (typeof initialPageParam === "boolean") return "boolean";
704
+ if (typeof initialPageParam !== "string") return "unknown";
705
+ if (!initialPageParam.includes(" as ")) return "string";
706
+ return initialPageParam.split(" as ").at(-1) ?? "unknown";
707
+ }
708
+ /**
709
+ * Resolves the `TPageParam` generic for the infinite-query hooks. Prefers the type read from the
710
+ * configured `queryParam` on the operation's query object, and falls back to the type inferred from
711
+ * `initialPageParam` when that parameter type is unavailable. Also returns the query params type name
712
+ * so callers can reuse it when rewriting the paginated request.
713
+ */
714
+ function resolvePageParamType(node, { resolver, initialPageParam, queryParam }) {
715
+ const firstQueryParam = getOperationParameters(node, { paramsCasing: "original" }).query[0];
716
+ const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
717
+ const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
718
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
719
+ if (!queryParamType) return {
720
+ queryParamsTypeName,
721
+ pageParamType: resolveFallbackPageParamType(initialPageParam)
722
+ };
723
+ return {
724
+ queryParamsTypeName,
725
+ pageParamType: initialPageParam !== void 0 && initialPageParam !== null ? `NonNullable<${queryParamType}>` : queryParamType
726
+ };
727
+ }
728
+ /**
729
+ * Applies the shared query defaults during plugin setup: `false` disables query generation, and an
730
+ * object merges over `methods: ['GET']` and the plugin's runtime `importPath`.
731
+ */
732
+ function resolveQueryConfig(query, options) {
733
+ if (query === false) return false;
734
+ return {
735
+ importPath: options.importPath,
736
+ methods: ["GET"],
737
+ ...query
738
+ };
739
+ }
740
+ /**
741
+ * Applies the shared mutation defaults during plugin setup: `false` disables mutation generation,
742
+ * and an object merges over `methods: ['POST', 'PUT', 'PATCH', 'DELETE']` and the plugin's runtime
743
+ * `importPath`.
744
+ */
745
+ function resolveMutationConfig(mutation, options) {
746
+ if (mutation === false) return false;
747
+ return {
748
+ importPath: options.importPath,
749
+ methods: [
750
+ "POST",
751
+ "PUT",
752
+ "PATCH",
753
+ "DELETE"
754
+ ],
755
+ ...mutation
756
+ };
757
+ }
758
+ /**
759
+ * Applies the shared infinite-query defaults during plugin setup: a falsy value disables infinite
760
+ * queries, and an object merges over `queryParam: 'id'` and `initialPageParam: 0` with the cursor
761
+ * paths cleared.
762
+ */
763
+ function resolveInfiniteConfig(infinite) {
764
+ if (!infinite) return false;
765
+ return {
766
+ queryParam: "id",
767
+ initialPageParam: 0,
768
+ cursorParam: null,
769
+ nextParam: null,
770
+ previousParam: null,
771
+ ...infinite
772
+ };
773
+ }
774
+ //#endregion
775
+ //#region ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
776
+ const declarationPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
777
+ const callPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
778
+ function InfiniteQueryOptions$1({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName }) {
779
+ const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
780
+ const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
781
+ resolver: tsResolver,
782
+ initialPageParam,
783
+ queryParam
784
+ });
785
+ const groupedKeyParam = buildGroupedRequestParam(node, {
786
+ resolver: tsResolver,
787
+ keys: [
788
+ "path",
789
+ "query",
790
+ "body"
791
+ ],
792
+ memberTypeWrapper
793
+ });
794
+ const queryKeyParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedKeyParam ? [groupedKeyParam] : [] });
795
+ const queryKeyParamsCall = callPrinter$4.print(queryKeyParamsNode) ?? "";
796
+ const paramsNode = buildQueryOptionsParams(node, {
797
+ resolver: tsResolver,
798
+ memberTypeWrapper
799
+ });
800
+ const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
801
+ const queryFnBody = `const { data } = await ${buildClientCall(node, {
802
+ clientName,
803
+ signal: true,
804
+ unwrapName
805
+ })}
806
+ return data`;
807
+ const hasNewParams = nextParam != null || previousParam != null;
808
+ const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
809
+ if (hasNewParams) {
810
+ const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
811
+ const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
812
+ return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
813
+ }
814
+ if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
815
+ return ["getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1", "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1"];
816
+ })();
817
+ const queryOptionsArr = [
818
+ `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
819
+ getNextPageParamExpr,
820
+ getPreviousPageParamExpr
821
+ ].filter(Boolean);
822
+ const infiniteOverrideParams = queryParam && queryParamsTypeName ? `query = {
823
+ ...(query ?? {}),
824
+ ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
825
+ } as ${queryParamsTypeName}` : "";
826
+ const queryFnArgs = infiniteOverrideParams ? "{ signal, pageParam }" : "{ signal }";
827
+ const queryFnStatements = infiniteOverrideParams ? `${infiniteOverrideParams}\n ${queryFnBody}` : queryFnBody;
828
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
829
+ name,
830
+ isExportable: true,
831
+ isIndexable: true,
832
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
833
+ name,
834
+ export: true,
835
+ params: paramsSignature,
836
+ children: `
837
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
838
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, ${queryKeyType}, ${pageParamType}>({
839
+ queryKey,
840
+ queryFn: async (${queryFnArgs}) => {
841
+ ${queryFnStatements}
842
+ },
843
+ ${queryOptionsArr.join(",\n ")}
844
+ })
845
+ `
846
+ })
847
+ });
848
+ }
849
+ __name(InfiniteQueryOptions$1, "InfiniteQueryOptions");
850
+ //#endregion
851
+ //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
852
+ const declarationPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
853
+ const mutationKeyTransformer = ({ node }) => {
854
+ if (!node.path) return [];
855
+ return [`{ url: '${Url.toPath(node.path)}' }`];
856
+ };
857
+ function MutationKey({ name, node, transformer }) {
858
+ const paramsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: [] });
859
+ const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
860
+ const keys = (transformer ?? mutationKeyTransformer)({
861
+ node,
862
+ casing: "camelcase"
863
+ });
864
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
865
+ name,
866
+ isExportable: true,
867
+ isIndexable: true,
868
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function.Arrow, {
869
+ name,
870
+ export: true,
871
+ params: paramsSignature,
872
+ singleLine: true,
873
+ children: `[${keys.join(", ")}] as const`
874
+ })
875
+ });
876
+ }
877
+ //#endregion
878
+ //#region ../../internals/tanstack-query/src/resolver.ts
879
+ /**
880
+ * Builds the shared query namespace for a variant. Spread the result into
881
+ * `createResolver` once per variant the plugin supports.
882
+ *
883
+ * @example
884
+ * ```ts
885
+ * createResolver<PluginReactQuery>({
886
+ * query: createQueryResolver(),
887
+ * suspenseQuery: createQueryResolver('Suspense'),
888
+ * })
889
+ * ```
890
+ */
891
+ function createQueryResolver(variant = "") {
892
+ return {
893
+ name(node) {
894
+ return `use${capitalize(this.name(node.operationId))}${variant}`;
895
+ },
896
+ optionsName(node) {
897
+ return `${this.name(node.operationId)}${variant}QueryOptions`;
898
+ },
899
+ keyName(node) {
900
+ return `${this.name(node.operationId)}${variant}QueryKey`;
901
+ },
902
+ keyTypeName(node) {
903
+ return `${capitalize(this.name(node.operationId))}${variant}QueryKey`;
904
+ },
905
+ clientName(node) {
906
+ return `${this.name(node.operationId)}${variant}`;
907
+ }
908
+ };
909
+ }
910
+ /**
911
+ * Builds the shared mutation namespace. Spread the result into
912
+ * `createResolver` and add plugin-specific methods (`optionsName`,
913
+ * `typeName`, `argTypeName`) next to it.
914
+ *
915
+ * @example
916
+ * ```ts
917
+ * createResolver<PluginSwr>({ mutation: { ...createMutationResolver(), argTypeName(node) {...} } })
918
+ * ```
919
+ */
920
+ function createMutationResolver() {
921
+ return {
922
+ name(node) {
923
+ return `use${capitalize(this.name(node.operationId))}`;
924
+ },
925
+ keyName(node) {
926
+ return `${this.name(node.operationId)}MutationKey`;
927
+ }
928
+ };
929
+ }
676
930
  (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
677
931
  const queryKeyTransformer = ({ node }) => {
678
932
  if (!node.path) return [];
@@ -752,6 +1006,20 @@ function resolveClient(options) {
752
1006
  message: "No client plugin is registered. Add `@kubb/plugin-axios` or `@kubb/plugin-fetch` to `plugins` so the generated code has an HTTP client to call."
753
1007
  };
754
1008
  }
1009
+ /**
1010
+ * Resolves the contract client during a consumer plugin's setup hook. Extracts the plugin names
1011
+ * from the raw `plugins` config, applies {@link resolveClient}, and throws the diagnostic on a
1012
+ * misconfiguration so every consumer fails fast with the same message.
1013
+ */
1014
+ function resolveContractClient(options) {
1015
+ const { client, plugins = [] } = options;
1016
+ const resolved = resolveClient({
1017
+ client,
1018
+ pluginNames: plugins.map((plugin) => plugin.name).filter((name) => Boolean(name))
1019
+ });
1020
+ if (resolved.kind === "error") throw new Error(resolved.message);
1021
+ return resolved;
1022
+ }
755
1023
  //#endregion
756
1024
  //#region ../../internals/client/src/resolveClientOperation.ts
757
1025
  /**
@@ -780,12 +1048,6 @@ function resolveClientOperation(options) {
780
1048
  }
781
1049
  //#endregion
782
1050
  //#region src/utils.ts
783
- const requestGroupOrder = [
784
- "path",
785
- "query",
786
- "body",
787
- "headers"
788
- ];
789
1051
  /**
790
1052
  * Builds the call to a contract client `<op>` function inside a vue-query composable body. The
791
1053
  * function takes a single grouped options object, so `config` is spread first, then the operation's
@@ -794,18 +1056,14 @@ const requestGroupOrder = [
794
1056
  * Mutations omit the `signal`.
795
1057
  */
796
1058
  function buildVueClientCall(node, options) {
797
- const { clientName, signal = false } = options;
798
- const groups = getRequestGroups(node);
799
- return `${clientName}({ ${[
800
- "...config",
801
- ...requestGroupOrder.filter((key) => groups[key]).map((name) => `${name}: toValue(${name})`),
802
- signal ? "signal: config.signal ?? signal" : null,
803
- "throwOnError: true"
804
- ].filter((part) => part !== null).join(", ")} })`;
1059
+ return buildClientCall(node, {
1060
+ ...options,
1061
+ unwrapName: (name) => `toValue(${name})`
1062
+ });
805
1063
  }
806
1064
  //#endregion
807
1065
  //#region src/components/QueryKey.tsx
808
- const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1066
+ const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
809
1067
  function buildQueryKeyParamsNode(node, options) {
810
1068
  const groupedParam = buildGroupedRequestParam(node, {
811
1069
  resolver: options.resolver,
@@ -820,7 +1078,7 @@ function buildQueryKeyParamsNode(node, options) {
820
1078
  }
821
1079
  function QueryKey({ name, node, tsResolver, typeName, transformer }) {
822
1080
  const paramsNode = buildQueryKeyParamsNode(node, { resolver: tsResolver });
823
- const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
1081
+ const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
824
1082
  const keys = (transformer ?? queryKeyTransformer)({
825
1083
  node,
826
1084
  casing: "camelcase"
@@ -850,8 +1108,8 @@ function QueryKey({ name, node, tsResolver, typeName, transformer }) {
850
1108
  }
851
1109
  //#endregion
852
1110
  //#region src/components/QueryOptions.tsx
853
- const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
854
- const callPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1111
+ const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1112
+ const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
855
1113
  function getQueryOptionsParams(node, options) {
856
1114
  return buildQueryOptionsParams(node, {
857
1115
  resolver: options.resolver,
@@ -859,15 +1117,11 @@ function getQueryOptionsParams(node, options) {
859
1117
  });
860
1118
  }
861
1119
  function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
862
- const successNames = resolveSuccessNames(node, tsResolver);
863
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
864
- const errorNames = resolveErrorNames(node, tsResolver);
865
- const TData = responseName;
866
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1120
+ const { TData, TError } = buildResponseTypes(node, tsResolver);
867
1121
  const queryKeyParamsNode = buildQueryKeyParamsNode(node, { resolver: tsResolver });
868
- const queryKeyParamsCall = callPrinter$4.print(queryKeyParamsNode) ?? "";
1122
+ const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
869
1123
  const paramsNode = getQueryOptionsParams(node, { resolver: tsResolver });
870
- const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
1124
+ const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
871
1125
  const queryFnBody = `const { data } = await ${buildVueClientCall(node, {
872
1126
  clientName,
873
1127
  signal: true
@@ -895,19 +1149,17 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
895
1149
  }
896
1150
  //#endregion
897
1151
  //#region src/components/InfiniteQuery.tsx
898
- const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
899
- const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1152
+ const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1153
+ const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
900
1154
  function buildInfiniteQueryParamsNode(node, options) {
901
1155
  const { resolver } = options;
902
- const successNames = resolveSuccessNames(node, resolver);
903
- const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
904
- const errorNames = resolveErrorNames(node, resolver);
1156
+ const { TData, TError } = buildResponseTypes(node, resolver);
905
1157
  const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
906
1158
  name: "options",
907
1159
  type: `{
908
1160
  query?: Partial<UseInfiniteQueryOptions<${[
909
- responseName,
910
- `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`,
1161
+ TData,
1162
+ TError,
911
1163
  "TQueryData",
912
1164
  "TQueryKey",
913
1165
  "TQueryData"
@@ -922,11 +1174,7 @@ function buildInfiniteQueryParamsNode(node, options) {
922
1174
  }), optionsParam].filter((param) => param !== null) });
923
1175
  }
924
1176
  function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
925
- const successNames = resolveSuccessNames(node, tsResolver);
926
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
927
- const errorNames = resolveErrorNames(node, tsResolver);
928
- const TData = responseName;
929
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1177
+ const { TData, TError } = buildResponseTypes(node, tsResolver);
930
1178
  const returnType = `UseInfiniteQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
931
1179
  const generics = [
932
1180
  `TData = InfiniteData<${TData}>`,
@@ -934,11 +1182,11 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
934
1182
  `TQueryKey extends QueryKey = ${queryKeyTypeName}`
935
1183
  ];
936
1184
  const queryKeyParamsNode = buildQueryKeyParamsNode(node, { resolver: tsResolver });
937
- const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
1185
+ const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
938
1186
  const queryOptionsParamsNode = getQueryOptionsParams(node, { resolver: tsResolver });
939
- const queryOptionsParamsCall = callPrinter$3.print(queryOptionsParamsNode) ?? "";
1187
+ const queryOptionsParamsCall = callPrinter$2.print(queryOptionsParamsNode) ?? "";
940
1188
  const paramsNode = buildInfiniteQueryParamsNode(node, { resolver: tsResolver });
941
- const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
1189
+ const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
942
1190
  return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
943
1191
  name,
944
1192
  isExportable: true,
@@ -969,93 +1217,17 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
969
1217
  }
970
1218
  //#endregion
971
1219
  //#region src/components/InfiniteQueryOptions.tsx
972
- const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
973
- const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
974
- function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName }) {
975
- const successNames = resolveSuccessNames(node, tsResolver);
976
- const queryFnDataType = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
977
- const errorNames = resolveErrorNames(node, tsResolver);
978
- const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
979
- const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
980
- const fallbackPageParamType = typeof initialPageParam === "number" ? "number" : typeof initialPageParam === "string" ? initialPageParam.includes(" as ") ? (() => {
981
- const parts = initialPageParam.split(" as ");
982
- return parts[parts.length - 1] ?? "unknown";
983
- })() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
984
- const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
985
- const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
986
- const groupName = tsResolver.param.query(node, rawQueryParams[0]);
987
- return groupName !== tsResolver.param.name(node, rawQueryParams[0]) ? groupName : null;
988
- })() : null;
989
- const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
990
- const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
991
- const queryKeyParamsNode = buildQueryKeyParamsNode(node, { resolver: tsResolver });
992
- const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
993
- const paramsNode = getQueryOptionsParams(node, { resolver: tsResolver });
994
- const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
995
- const queryFnBody = `const { data } = await ${buildVueClientCall(node, {
996
- clientName,
997
- signal: true
998
- })}
999
- return data`;
1000
- const hasNewParams = nextParam != null || previousParam != null;
1001
- const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
1002
- if (hasNewParams) {
1003
- const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
1004
- const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
1005
- return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
1006
- }
1007
- if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
1008
- return ["getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1", "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1"];
1009
- })();
1010
- const queryOptionsArr = [
1011
- `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
1012
- getNextPageParamExpr,
1013
- getPreviousPageParamExpr
1014
- ].filter(Boolean);
1015
- const infiniteOverrideParams = queryParam && queryParamsTypeName ? `query = {
1016
- ...(query ?? {}),
1017
- ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
1018
- } as ${queryParamsTypeName}` : "";
1019
- if (infiniteOverrideParams) return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1020
- name,
1021
- isExportable: true,
1022
- isIndexable: true,
1023
- children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
1024
- name,
1025
- export: true,
1026
- params: paramsSignature,
1027
- children: `
1028
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1029
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, QueryKey, ${pageParamType}>({
1030
- queryKey,
1031
- queryFn: async ({ signal, pageParam }) => {
1032
- ${infiniteOverrideParams}
1033
- ${queryFnBody}
1034
- },
1035
- ${queryOptionsArr.join(",\n ")}
1036
- })
1037
- `
1038
- })
1039
- });
1040
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1041
- name,
1042
- isExportable: true,
1043
- isIndexable: true,
1044
- children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
1045
- name,
1046
- export: true,
1047
- params: paramsSignature,
1048
- children: `
1049
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1050
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, QueryKey, ${pageParamType}>({
1051
- queryKey,
1052
- queryFn: async ({ signal }) => {
1053
- ${queryFnBody}
1054
- },
1055
- ${queryOptionsArr.join(",\n ")}
1056
- })
1057
- `
1058
- })
1220
+ /**
1221
+ * The vue-query flavor of the shared `infiniteQueryOptions` component: request groups accept
1222
+ * `MaybeRefOrGetter` values, are unwrapped with `toValue(...)` in the client call, and the emitted
1223
+ * `TQueryKey` generic is the imported `QueryKey` type instead of `typeof queryKey`.
1224
+ */
1225
+ function InfiniteQueryOptions(props) {
1226
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(InfiniteQueryOptions$1, {
1227
+ ...props,
1228
+ queryKeyType: "QueryKey",
1229
+ memberTypeWrapper: maybeRefOrGetter,
1230
+ unwrapName: (name) => `toValue(${name})`
1059
1231
  });
1060
1232
  }
1061
1233
  //#endregion
@@ -1067,15 +1239,13 @@ function resolveMutationRequestType(node, resolver) {
1067
1239
  }
1068
1240
  function buildMutationParamsNode(node, options) {
1069
1241
  const { resolver } = options;
1070
- const successNames = resolveSuccessNames(node, resolver);
1071
- const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
1072
- const errorNames = resolveErrorNames(node, resolver);
1242
+ const { TData, TError } = buildResponseTypes(node, resolver);
1073
1243
  return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [(0, _kubb_plugin_ts.createFunctionParameter)({
1074
1244
  name: "options",
1075
1245
  type: `{
1076
1246
  mutation?: MutationObserverOptions<${[
1077
- responseName,
1078
- `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`,
1247
+ TData,
1248
+ TError,
1079
1249
  resolveMutationRequestType(node, resolver),
1080
1250
  "TContext"
1081
1251
  ].join(", ")}> & { client?: QueryClient },
@@ -1085,11 +1255,7 @@ function buildMutationParamsNode(node, options) {
1085
1255
  })] });
1086
1256
  }
1087
1257
  function Mutation({ name, clientName, node, tsResolver, mutationKeyName }) {
1088
- const successNames = resolveSuccessNames(node, tsResolver);
1089
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
1090
- const errorNames = resolveErrorNames(node, tsResolver);
1091
- const TData = responseName;
1092
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1258
+ const { TData, TError } = buildResponseTypes(node, tsResolver);
1093
1259
  const groupedParam = buildGroupedRequestParam(node, { resolver: tsResolver });
1094
1260
  const hasMutationParams = groupedParam !== null;
1095
1261
  const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
@@ -1139,15 +1305,13 @@ const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declara
1139
1305
  const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1140
1306
  function buildQueryParamsNode(node, options) {
1141
1307
  const { resolver } = options;
1142
- const successNames = resolveSuccessNames(node, resolver);
1143
- const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
1144
- const errorNames = resolveErrorNames(node, resolver);
1308
+ const { TData, TError } = buildResponseTypes(node, resolver);
1145
1309
  const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
1146
1310
  name: "options",
1147
1311
  type: `{
1148
1312
  query?: Partial<UseQueryOptions<${[
1149
- responseName,
1150
- `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`,
1313
+ TData,
1314
+ TError,
1151
1315
  "TData",
1152
1316
  "TQueryData",
1153
1317
  "TQueryKey"
@@ -1162,11 +1326,7 @@ function buildQueryParamsNode(node, options) {
1162
1326
  }), optionsParam].filter((param) => param !== null) });
1163
1327
  }
1164
1328
  function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
1165
- const successNames = resolveSuccessNames(node, tsResolver);
1166
- const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
1167
- const errorNames = resolveErrorNames(node, tsResolver);
1168
- const TData = responseName;
1169
- const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
1329
+ const { TData, TError } = buildResponseTypes(node, tsResolver);
1170
1330
  const returnType = `UseQueryReturnType<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
1171
1331
  const generics = [
1172
1332
  `TData = ${TData}`,
@@ -1654,9 +1814,6 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
1654
1814
  });
1655
1815
  //#endregion
1656
1816
  //#region src/resolvers/resolverVueQuery.ts
1657
- function capitalize(name) {
1658
- return `${name.charAt(0).toUpperCase()}${name.slice(1)}`;
1659
- }
1660
1817
  /**
1661
1818
  * Default resolver used by `@kubb/plugin-vue-query`. Decides the names and
1662
1819
  * file paths for every generated TanStack Query composable (`useFoo`,
@@ -1677,47 +1834,10 @@ function capitalize(name) {
1677
1834
  */
1678
1835
  const resolverVueQuery = (0, kubb_kit.createResolver)({
1679
1836
  pluginName: "plugin-vue-query",
1680
- query: {
1681
- name(node) {
1682
- return `use${capitalize(this.name(node.operationId))}`;
1683
- },
1684
- keyName(node) {
1685
- return `${this.name(node.operationId)}QueryKey`;
1686
- },
1687
- keyTypeName(node) {
1688
- return `${capitalize(this.name(node.operationId))}QueryKey`;
1689
- },
1690
- optionsName(node) {
1691
- return `${this.name(node.operationId)}QueryOptions`;
1692
- },
1693
- clientName(node) {
1694
- return this.name(node.operationId);
1695
- }
1696
- },
1697
- infiniteQuery: {
1698
- name(node) {
1699
- return `use${capitalize(this.name(node.operationId))}Infinite`;
1700
- },
1701
- keyName(node) {
1702
- return `${this.name(node.operationId)}InfiniteQueryKey`;
1703
- },
1704
- keyTypeName(node) {
1705
- return `${capitalize(this.name(node.operationId))}InfiniteQueryKey`;
1706
- },
1707
- optionsName(node) {
1708
- return `${this.name(node.operationId)}InfiniteQueryOptions`;
1709
- },
1710
- clientName(node) {
1711
- return `${this.name(node.operationId)}Infinite`;
1712
- }
1713
- },
1837
+ query: createQueryResolver(),
1838
+ infiniteQuery: createQueryResolver("Infinite"),
1714
1839
  mutation: {
1715
- name(node) {
1716
- return `use${capitalize(this.name(node.operationId))}`;
1717
- },
1718
- keyName(node) {
1719
- return `${this.name(node.operationId)}MutationKey`;
1720
- },
1840
+ ...createMutationResolver(),
1721
1841
  typeName(node) {
1722
1842
  return capitalize(this.name(node.operationId));
1723
1843
  }
@@ -1771,43 +1891,17 @@ const pluginVueQuery = (0, kubb_kit.definePlugin)((options) => {
1771
1891
  dependencies: [_kubb_plugin_ts.pluginTsName],
1772
1892
  hooks: { "kubb:plugin:setup"(ctx) {
1773
1893
  const resolver = userResolver ? kubb_kit.Resolver.merge(resolverVueQuery, userResolver) : resolverVueQuery;
1774
- const resolvedClient = resolveClient({
1775
- client,
1776
- pluginNames: (ctx.config.plugins ?? []).map((p) => p.name).filter((name) => Boolean(name))
1777
- });
1778
- if (resolvedClient.kind === "error") throw new Error(resolvedClient.message);
1779
- const resolvedClientDescriptor = {
1780
- kind: "contract",
1781
- pluginName: resolvedClient.pluginName
1782
- };
1783
1894
  ctx.setOptions({
1784
1895
  output,
1785
- client: resolvedClientDescriptor,
1896
+ client: resolveContractClient({
1897
+ client,
1898
+ plugins: ctx.config.plugins
1899
+ }),
1786
1900
  queryKey,
1787
- query: query === false ? false : {
1788
- importPath: "@tanstack/vue-query",
1789
- methods: ["GET"],
1790
- ...query
1791
- },
1901
+ query: resolveQueryConfig(query, { importPath: "@tanstack/vue-query" }),
1792
1902
  mutationKey,
1793
- mutation: mutation === false ? false : {
1794
- importPath: "@tanstack/vue-query",
1795
- methods: [
1796
- "POST",
1797
- "PUT",
1798
- "PATCH",
1799
- "DELETE"
1800
- ],
1801
- ...mutation
1802
- },
1803
- infinite: infinite ? {
1804
- queryParam: "id",
1805
- initialPageParam: 0,
1806
- cursorParam: null,
1807
- nextParam: null,
1808
- previousParam: null,
1809
- ...infinite
1810
- } : false,
1903
+ mutation: resolveMutationConfig(mutation, { importPath: "@tanstack/vue-query" }),
1904
+ infinite: resolveInfiniteConfig(infinite),
1811
1905
  hooks,
1812
1906
  group: groupConfig,
1813
1907
  exclude,
@@ -1825,5 +1919,6 @@ const pluginVueQuery = (0, kubb_kit.definePlugin)((options) => {
1825
1919
  exports.default = pluginVueQuery;
1826
1920
  exports.pluginVueQuery = pluginVueQuery;
1827
1921
  exports.pluginVueQueryName = pluginVueQueryName;
1922
+ exports.resolverVueQuery = resolverVueQuery;
1828
1923
 
1829
1924
  //# sourceMappingURL=index.cjs.map