@kubb/plugin-react-query 5.0.0-beta.94 → 5.0.0-beta.98

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
@@ -24,9 +24,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  enumerable: true
25
25
  }) : target, mod));
26
26
  //#endregion
27
- let kubb_kit = require("kubb/kit");
28
27
  let node_path = require("node:path");
29
28
  node_path = __toESM(node_path, 1);
29
+ let kubb_kit = require("kubb/kit");
30
30
  let _kubb_plugin_ts = require("@kubb/plugin-ts");
31
31
  let kubb_jsx = require("kubb/jsx");
32
32
  let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
@@ -58,6 +58,16 @@ function toCamelOrPascal(text, pascal) {
58
58
  function camelCase(text, { prefix = "", suffix = "" } = {}) {
59
59
  return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
60
60
  }
61
+ /**
62
+ * Uppercases only the first character of `text`, leaving the rest untouched.
63
+ * Unlike {@link pascalCase} it never re-splits word boundaries or strips characters.
64
+ *
65
+ * @example
66
+ * `capitalize('getPetById') // 'GetPetById'`
67
+ */
68
+ function capitalize(text) {
69
+ return `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
70
+ }
61
71
  //#endregion
62
72
  //#region ../../internals/utils/src/reserved.ts
63
73
  /**
@@ -627,6 +637,20 @@ function resolveClient(options) {
627
637
  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."
628
638
  };
629
639
  }
640
+ /**
641
+ * Resolves the contract client during a consumer plugin's setup hook. Extracts the plugin names
642
+ * from the raw `plugins` config, applies {@link resolveClient}, and throws the diagnostic on a
643
+ * misconfiguration so every consumer fails fast with the same message.
644
+ */
645
+ function resolveContractClient(options) {
646
+ const { client, plugins = [] } = options;
647
+ const resolved = resolveClient({
648
+ client,
649
+ pluginNames: plugins.map((plugin) => plugin.name).filter((name) => Boolean(name))
650
+ });
651
+ if (resolved.kind === "error") throw new Error(resolved.message);
652
+ return resolved;
653
+ }
630
654
  //#endregion
631
655
  //#region ../../internals/client/src/resolveClientOperation.ts
632
656
  /**
@@ -654,33 +678,6 @@ function resolveClientOperation(options) {
654
678
  };
655
679
  }
656
680
  //#endregion
657
- //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
658
- const declarationPrinter$10 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
659
- const mutationKeyTransformer = ({ node }) => {
660
- if (!node.path) return [];
661
- return [`{ url: '${Url.toPath(node.path)}' }`];
662
- };
663
- function MutationKey({ name, node, transformer }) {
664
- const paramsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: [] });
665
- const paramsSignature = declarationPrinter$10.print(paramsNode) ?? "";
666
- const keys = (transformer ?? mutationKeyTransformer)({
667
- node,
668
- casing: "camelcase"
669
- });
670
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
671
- name,
672
- isExportable: true,
673
- isIndexable: true,
674
- children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function.Arrow, {
675
- name,
676
- export: true,
677
- params: paramsSignature,
678
- singleLine: true,
679
- children: `[${keys.join(", ")}] as const`
680
- })
681
- });
682
- }
683
- //#endregion
684
681
  //#region ../../internals/tanstack-query/src/utils.ts
685
682
  /**
686
683
  * The grouped request options, ordered for both the destructured signature and the
@@ -764,6 +761,9 @@ function buildQueryOptionsParams(node, options) {
764
761
  * shorthand alongside the spread `config`, with `throwOnError: true` pinned last so a caller's config
765
762
  * can't flip the query's error semantics. Queries thread the TanStack `signal`; mutations omit it.
766
763
  *
764
+ * When `unwrapName` is set, each request group is passed as an explicit member unwrapped through it,
765
+ * used by vue-query to resolve refs and getters with `toValue(...)` at call time.
766
+ *
767
767
  * @example
768
768
  * ```ts
769
769
  * buildClientCall(node, { clientName: 'getPetById', signal: true })
@@ -771,15 +771,101 @@ function buildQueryOptionsParams(node, options) {
771
771
  * ```
772
772
  */
773
773
  function buildClientCall(node, options) {
774
- const { clientName, signal = false } = options;
774
+ const { clientName, signal = false, unwrapName } = options;
775
775
  const { groups } = getRequestGroupOptionality(node);
776
776
  return `${clientName}({ ${[
777
777
  "...config",
778
- ...requestGroupOrder$1.filter((key) => groups[key]),
778
+ ...requestGroupOrder$1.filter((key) => groups[key]).map((name) => unwrapName ? `${name}: ${unwrapName(name)}` : name),
779
779
  signal ? "signal: config.signal ?? signal" : null,
780
780
  "throwOnError: true"
781
781
  ].filter((part) => part !== null).join(", ")} })`;
782
782
  }
783
+ /**
784
+ * Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
785
+ * success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
786
+ */
787
+ function buildResponseTypes(node, resolver) {
788
+ const successNames = resolveSuccessNames(node, resolver);
789
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
790
+ const errorNames = resolveErrorNames(node, resolver);
791
+ return {
792
+ TData: responseName,
793
+ TError: `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`
794
+ };
795
+ }
796
+ function resolveFallbackPageParamType(initialPageParam) {
797
+ if (typeof initialPageParam === "number") return "number";
798
+ if (typeof initialPageParam === "boolean") return "boolean";
799
+ if (typeof initialPageParam !== "string") return "unknown";
800
+ if (!initialPageParam.includes(" as ")) return "string";
801
+ return initialPageParam.split(" as ").at(-1) ?? "unknown";
802
+ }
803
+ /**
804
+ * Resolves the `TPageParam` generic for the infinite-query hooks. Prefers the type read from the
805
+ * configured `queryParam` on the operation's query object, and falls back to the type inferred from
806
+ * `initialPageParam` when that parameter type is unavailable. Also returns the query params type name
807
+ * so callers can reuse it when rewriting the paginated request.
808
+ */
809
+ function resolvePageParamType(node, { resolver, initialPageParam, queryParam }) {
810
+ const firstQueryParam = getOperationParameters(node, { paramsCasing: "original" }).query[0];
811
+ const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
812
+ const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
813
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
814
+ if (!queryParamType) return {
815
+ queryParamsTypeName,
816
+ pageParamType: resolveFallbackPageParamType(initialPageParam)
817
+ };
818
+ return {
819
+ queryParamsTypeName,
820
+ pageParamType: initialPageParam !== void 0 && initialPageParam !== null ? `NonNullable<${queryParamType}>` : queryParamType
821
+ };
822
+ }
823
+ /**
824
+ * Applies the shared query defaults during plugin setup: `false` disables query generation, and an
825
+ * object merges over `methods: ['GET']` and the plugin's runtime `importPath`.
826
+ */
827
+ function resolveQueryConfig(query, options) {
828
+ if (query === false) return false;
829
+ return {
830
+ importPath: options.importPath,
831
+ methods: ["GET"],
832
+ ...query
833
+ };
834
+ }
835
+ /**
836
+ * Applies the shared mutation defaults during plugin setup: `false` disables mutation generation,
837
+ * and an object merges over `methods: ['POST', 'PUT', 'PATCH', 'DELETE']` and the plugin's runtime
838
+ * `importPath`.
839
+ */
840
+ function resolveMutationConfig(mutation, options) {
841
+ if (mutation === false) return false;
842
+ return {
843
+ importPath: options.importPath,
844
+ methods: [
845
+ "POST",
846
+ "PUT",
847
+ "PATCH",
848
+ "DELETE"
849
+ ],
850
+ ...mutation
851
+ };
852
+ }
853
+ /**
854
+ * Applies the shared infinite-query defaults during plugin setup: a falsy value disables infinite
855
+ * queries, and an object merges over `queryParam: 'id'` and `initialPageParam: 0` with the cursor
856
+ * paths cleared.
857
+ */
858
+ function resolveInfiniteConfig(infinite) {
859
+ if (!infinite) return false;
860
+ return {
861
+ queryParam: "id",
862
+ initialPageParam: 0,
863
+ cursorParam: null,
864
+ nextParam: null,
865
+ previousParam: null,
866
+ ...infinite
867
+ };
868
+ }
783
869
  function matchesPattern(node, ov) {
784
870
  const { type, pattern } = ov;
785
871
  const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
@@ -820,8 +906,163 @@ function buildQueryKeyParams(node, options) {
820
906
  return (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
821
907
  }
822
908
  //#endregion
909
+ //#region ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
910
+ const declarationPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
911
+ const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
912
+ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName }) {
913
+ const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
914
+ const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
915
+ resolver: tsResolver,
916
+ initialPageParam,
917
+ queryParam
918
+ });
919
+ const groupedKeyParam = buildGroupedRequestParam(node, {
920
+ resolver: tsResolver,
921
+ keys: [
922
+ "path",
923
+ "query",
924
+ "body"
925
+ ],
926
+ memberTypeWrapper
927
+ });
928
+ const queryKeyParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedKeyParam ? [groupedKeyParam] : [] });
929
+ const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
930
+ const paramsNode = buildQueryOptionsParams(node, {
931
+ resolver: tsResolver,
932
+ memberTypeWrapper
933
+ });
934
+ const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
935
+ const queryFnBody = `const { data } = await ${buildClientCall(node, {
936
+ clientName,
937
+ signal: true,
938
+ unwrapName
939
+ })}
940
+ return data`;
941
+ const hasNewParams = nextParam != null || previousParam != null;
942
+ const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
943
+ if (hasNewParams) {
944
+ const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
945
+ const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
946
+ return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
947
+ }
948
+ if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
949
+ return ["getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1", "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1"];
950
+ })();
951
+ const queryOptionsArr = [
952
+ `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
953
+ getNextPageParamExpr,
954
+ getPreviousPageParamExpr
955
+ ].filter(Boolean);
956
+ const infiniteOverrideParams = queryParam && queryParamsTypeName ? `query = {
957
+ ...(query ?? {}),
958
+ ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
959
+ } as ${queryParamsTypeName}` : "";
960
+ const queryFnArgs = infiniteOverrideParams ? "{ signal, pageParam }" : "{ signal }";
961
+ const queryFnStatements = infiniteOverrideParams ? `${infiniteOverrideParams}\n ${queryFnBody}` : queryFnBody;
962
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
963
+ name,
964
+ isExportable: true,
965
+ isIndexable: true,
966
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
967
+ name,
968
+ export: true,
969
+ params: paramsSignature,
970
+ children: `
971
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
972
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, ${queryKeyType}, ${pageParamType}>({
973
+ queryKey,
974
+ queryFn: async (${queryFnArgs}) => {
975
+ ${queryFnStatements}
976
+ },
977
+ ${queryOptionsArr.join(",\n ")}
978
+ })
979
+ `
980
+ })
981
+ });
982
+ }
983
+ //#endregion
984
+ //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
985
+ const declarationPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
986
+ const mutationKeyTransformer = ({ node }) => {
987
+ if (!node.path) return [];
988
+ return [`{ url: '${Url.toPath(node.path)}' }`];
989
+ };
990
+ function MutationKey({ name, node, transformer }) {
991
+ const paramsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: [] });
992
+ const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
993
+ const keys = (transformer ?? mutationKeyTransformer)({
994
+ node,
995
+ casing: "camelcase"
996
+ });
997
+ return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
998
+ name,
999
+ isExportable: true,
1000
+ isIndexable: true,
1001
+ children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function.Arrow, {
1002
+ name,
1003
+ export: true,
1004
+ params: paramsSignature,
1005
+ singleLine: true,
1006
+ children: `[${keys.join(", ")}] as const`
1007
+ })
1008
+ });
1009
+ }
1010
+ //#endregion
1011
+ //#region ../../internals/tanstack-query/src/resolver.ts
1012
+ /**
1013
+ * Builds the shared query namespace for a variant. Spread the result into
1014
+ * `createResolver` once per variant the plugin supports.
1015
+ *
1016
+ * @example
1017
+ * ```ts
1018
+ * createResolver<PluginReactQuery>({
1019
+ * query: createQueryResolver(),
1020
+ * suspenseQuery: createQueryResolver('Suspense'),
1021
+ * })
1022
+ * ```
1023
+ */
1024
+ function createQueryResolver(variant = "") {
1025
+ return {
1026
+ name(node) {
1027
+ return `use${capitalize(this.name(node.operationId))}${variant}`;
1028
+ },
1029
+ optionsName(node) {
1030
+ return `${this.name(node.operationId)}${variant}QueryOptions`;
1031
+ },
1032
+ keyName(node) {
1033
+ return `${this.name(node.operationId)}${variant}QueryKey`;
1034
+ },
1035
+ keyTypeName(node) {
1036
+ return `${capitalize(this.name(node.operationId))}${variant}QueryKey`;
1037
+ },
1038
+ clientName(node) {
1039
+ return `${this.name(node.operationId)}${variant}`;
1040
+ }
1041
+ };
1042
+ }
1043
+ /**
1044
+ * Builds the shared mutation namespace. Spread the result into
1045
+ * `createResolver` and add plugin-specific methods (`optionsName`,
1046
+ * `typeName`, `argTypeName`) next to it.
1047
+ *
1048
+ * @example
1049
+ * ```ts
1050
+ * createResolver<PluginSwr>({ mutation: { ...createMutationResolver(), argTypeName(node) {...} } })
1051
+ * ```
1052
+ */
1053
+ function createMutationResolver() {
1054
+ return {
1055
+ name(node) {
1056
+ return `use${capitalize(this.name(node.operationId))}`;
1057
+ },
1058
+ keyName(node) {
1059
+ return `${this.name(node.operationId)}MutationKey`;
1060
+ }
1061
+ };
1062
+ }
1063
+ //#endregion
823
1064
  //#region ../../internals/tanstack-query/src/components/QueryKey.tsx
824
- const declarationPrinter$9 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1065
+ const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
825
1066
  const queryKeyTransformer = ({ node }) => {
826
1067
  if (!node.path) return [];
827
1068
  const hasPathParams = getOperationParameters(node).path.length > 0;
@@ -835,7 +1076,7 @@ const queryKeyTransformer = ({ node }) => {
835
1076
  };
836
1077
  function QueryKey({ name, node, tsResolver, typeName, transformer }) {
837
1078
  const paramsNode = buildQueryKeyParams(node, { resolver: tsResolver });
838
- const paramsSignature = declarationPrinter$9.print(paramsNode) ?? "";
1079
+ const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
839
1080
  const keys = (transformer ?? queryKeyTransformer)({
840
1081
  node,
841
1082
  casing: "camelcase"
@@ -992,46 +1233,6 @@ function classifyOperation(node, { query, mutation }) {
992
1233
  isMutation: mutation !== false && !isQuery && (mutation ? mutation.methods : []).some((method) => !queryMethods.has(method) && node.method.toLowerCase() === method.toLowerCase())
993
1234
  };
994
1235
  }
995
- /**
996
- * Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
997
- * success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
998
- */
999
- function buildResponseTypes(node, resolver) {
1000
- const successNames = resolveSuccessNames(node, resolver);
1001
- const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
1002
- const errorNames = resolveErrorNames(node, resolver);
1003
- return {
1004
- TData: responseName,
1005
- TError: `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`
1006
- };
1007
- }
1008
- function resolveFallbackPageParamType(initialPageParam) {
1009
- if (typeof initialPageParam === "number") return "number";
1010
- if (typeof initialPageParam === "boolean") return "boolean";
1011
- if (typeof initialPageParam !== "string") return "unknown";
1012
- if (!initialPageParam.includes(" as ")) return "string";
1013
- return initialPageParam.split(" as ").at(-1) ?? "unknown";
1014
- }
1015
- /**
1016
- * Resolves the `TPageParam` generic for the infinite-query hooks. Prefers the type read from the
1017
- * configured `queryParam` on the operation's query object, and falls back to the type inferred from
1018
- * `initialPageParam` when that parameter type is unavailable. Also returns the query params type name
1019
- * so callers can reuse it when rewriting the paginated request.
1020
- */
1021
- function resolvePageParamType(node, { resolver, initialPageParam, queryParam }) {
1022
- const firstQueryParam = getOperationParameters(node, { paramsCasing: "original" }).query[0];
1023
- const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
1024
- const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
1025
- const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
1026
- if (!queryParamType) return {
1027
- queryParamsTypeName,
1028
- pageParamType: resolveFallbackPageParamType(initialPageParam)
1029
- };
1030
- return {
1031
- queryParamsTypeName,
1032
- pageParamType: initialPageParam !== void 0 && initialPageParam !== null ? `NonNullable<${queryParamType}>` : queryParamType
1033
- };
1034
- }
1035
1236
  //#endregion
1036
1237
  //#region src/generators/hookOptionsGenerator.tsx
1037
1238
  /**
@@ -1195,13 +1396,13 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
1195
1396
  });
1196
1397
  //#endregion
1197
1398
  //#region src/components/InfiniteQuery.tsx
1198
- const declarationPrinter$8 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1399
+ const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1199
1400
  function buildInfiniteQueryParamsNode(node, options) {
1200
- const { resolver, pageParamGeneric } = options;
1401
+ const { resolver, pageParamGeneric, observerOptionsName } = options;
1201
1402
  const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
1202
1403
  name: "options",
1203
1404
  type: `{
1204
- query?: Partial<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
1405
+ query?: Partial<${observerOptionsName}<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
1205
1406
  client?: ${buildClientOptionType()}
1206
1407
  }`,
1207
1408
  default: "{}"
@@ -1211,14 +1412,16 @@ function buildInfiniteQueryParamsNode(node, options) {
1211
1412
  memberTypeWrapper: maybeValueOrGetter
1212
1413
  }), optionsParam].filter((param) => param !== null) });
1213
1414
  }
1214
- function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, initialPageParam, queryParam, customOptions }) {
1415
+ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, initialPageParam, queryParam, customOptions, suspense }) {
1215
1416
  const { TData: responseType, TError: errorType } = buildResponseTypes(node, tsResolver);
1216
1417
  const { pageParamType } = resolvePageParamType(node, {
1217
1418
  resolver: tsResolver,
1218
1419
  initialPageParam,
1219
1420
  queryParam
1220
1421
  });
1221
- const returnType = "UseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
1422
+ const hookName = suspense ? "useSuspenseInfiniteQuery" : "useInfiniteQuery";
1423
+ const observerOptionsName = suspense ? "UseSuspenseInfiniteQueryOptions" : "InfiniteQueryObserverOptions";
1424
+ const returnType = `${suspense ? "UseSuspenseInfiniteQueryResult" : "UseInfiniteQueryResult"}<TData, TError> & { queryKey: TQueryKey }`;
1222
1425
  const generics = [
1223
1426
  `TQueryFnData = ${responseType}`,
1224
1427
  `TError = ${errorType}`,
@@ -1231,9 +1434,10 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
1231
1434
  const queryOptionsArgs = resolvedParams ? "resolvedParams, config" : "config";
1232
1435
  const paramsNode = buildInfiniteQueryParamsNode(node, {
1233
1436
  resolver: tsResolver,
1234
- pageParamGeneric: "TPageParam"
1437
+ pageParamGeneric: "TPageParam",
1438
+ observerOptionsName
1235
1439
  });
1236
- const paramsSignature = declarationPrinter$8.print(paramsNode) ?? "";
1440
+ const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
1237
1441
  return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1238
1442
  name,
1239
1443
  isExportable: true,
@@ -1250,141 +1454,22 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
1250
1454
  const { client: queryClient, ...resolvedOptions } = queryConfig${resolvedParams ? `\n const resolvedParams = ${resolvedParams}` : ""}
1251
1455
  const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyArgs})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1252
1456
 
1253
- const queryResult = useInfiniteQuery({
1457
+ const queryResult = ${hookName}({
1254
1458
  ...${queryOptionsName}(${queryOptionsArgs}),${customOptions ? "\n ...customOptions," : ""}
1255
1459
  ...resolvedOptions,
1256
1460
  queryKey,
1257
- } as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
1461
+ } as unknown as ${observerOptionsName}<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
1258
1462
 
1259
1463
  queryResult.queryKey = queryKey as TQueryKey
1260
1464
 
1261
- return queryResult
1262
- `
1263
- })
1264
- });
1265
- }
1266
- //#endregion
1267
- //#region src/components/QueryOptions.tsx
1268
- const declarationPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1269
- const callPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1270
- function getQueryOptionsParams(node, options) {
1271
- return buildQueryOptionsParams(node, options);
1272
- }
1273
- function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
1274
- const { TData, TError } = buildResponseTypes(node, tsResolver);
1275
- const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
1276
- const queryKeyParamsCall = callPrinter$4.print(queryKeyParamsNode) ?? "";
1277
- const paramsNode = getQueryOptionsParams(node, { resolver: tsResolver });
1278
- const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
1279
- const queryFnBody = `const { data } = await ${buildClientCall(node, {
1280
- clientName,
1281
- signal: true
1282
- })}
1283
- return data`;
1284
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1285
- name,
1286
- isExportable: true,
1287
- isIndexable: true,
1288
- children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
1289
- name,
1290
- export: true,
1291
- params: paramsSignature,
1292
- children: `
1293
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1294
- return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
1295
- queryKey,
1296
- queryFn: async ({ signal }) => {
1297
- ${queryFnBody}
1298
- },
1299
- })
1300
- `
1301
- })
1302
- });
1303
- }
1304
- //#endregion
1305
- //#region src/components/InfiniteQueryOptions.tsx
1306
- const declarationPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1307
- const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1308
- function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName }) {
1309
- const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
1310
- const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
1311
- resolver: tsResolver,
1312
- initialPageParam,
1313
- queryParam
1314
- });
1315
- const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
1316
- const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
1317
- const paramsNode = getQueryOptionsParams(node, { resolver: tsResolver });
1318
- const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
1319
- const queryFnBody = `const { data } = await ${buildClientCall(node, {
1320
- clientName,
1321
- signal: true
1322
- })}
1323
- return data`;
1324
- const hasNewParams = nextParam != null || previousParam != null;
1325
- const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
1326
- if (hasNewParams) {
1327
- const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
1328
- const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
1329
- return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
1330
- }
1331
- if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
1332
- return ["getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1", "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1"];
1333
- })();
1334
- const queryOptionsArr = [
1335
- `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
1336
- getNextPageParamExpr,
1337
- getPreviousPageParamExpr
1338
- ].filter(Boolean);
1339
- const infiniteOverrideParams = queryParam && queryParamsTypeName ? `query = {
1340
- ...(query ?? {}),
1341
- ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
1342
- } as ${queryParamsTypeName}` : "";
1343
- if (infiniteOverrideParams) return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1344
- name,
1345
- isExportable: true,
1346
- isIndexable: true,
1347
- children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
1348
- name,
1349
- export: true,
1350
- params: paramsSignature,
1351
- children: `
1352
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1353
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1354
- queryKey,
1355
- queryFn: async ({ signal, pageParam }) => {
1356
- ${infiniteOverrideParams}
1357
- ${queryFnBody}
1358
- },
1359
- ${queryOptionsArr.join(",\n ")}
1360
- })
1361
- `
1362
- })
1363
- });
1364
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1365
- name,
1366
- isExportable: true,
1367
- isIndexable: true,
1368
- children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
1369
- name,
1370
- export: true,
1371
- params: paramsSignature,
1372
- children: `
1373
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1374
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1375
- queryKey,
1376
- queryFn: async ({ signal }) => {
1377
- ${queryFnBody}
1378
- },
1379
- ${queryOptionsArr.join(",\n ")}
1380
- })
1381
- `
1465
+ return queryResult
1466
+ `
1382
1467
  })
1383
1468
  });
1384
1469
  }
1385
1470
  //#endregion
1386
1471
  //#region src/components/MutationOptions.tsx
1387
- const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1472
+ const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1388
1473
  const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1389
1474
  function buildMutationConfigParamsNode(node) {
1390
1475
  return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [(0, _kubb_plugin_ts.createFunctionParameter)({
@@ -1396,7 +1481,7 @@ function buildMutationConfigParamsNode(node) {
1396
1481
  function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }) {
1397
1482
  const { TData, TError } = buildResponseTypes(node, tsResolver);
1398
1483
  const configParamsNode = buildMutationConfigParamsNode(node);
1399
- const paramsSignature = declarationPrinter$5.print(configParamsNode) ?? "";
1484
+ const paramsSignature = declarationPrinter$3.print(configParamsNode) ?? "";
1400
1485
  const groupedParam = buildGroupedRequestParam(node, { resolver: tsResolver });
1401
1486
  const hasMutationParams = groupedParam !== null;
1402
1487
  const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
@@ -1430,7 +1515,7 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }
1430
1515
  }
1431
1516
  //#endregion
1432
1517
  //#region src/components/Mutation.tsx
1433
- const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1518
+ const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1434
1519
  const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1435
1520
  function resolveMutationRequestType(node, resolver) {
1436
1521
  return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
@@ -1464,7 +1549,7 @@ function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName
1464
1549
  const mutationOptionsConfigNode = buildMutationConfigParamsNode(node);
1465
1550
  const mutationOptionsParamsCall = callPrinter$1.print(mutationOptionsConfigNode) ?? "";
1466
1551
  const paramsNode = buildMutationParamsNode(node, { resolver: tsResolver });
1467
- const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
1552
+ const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
1468
1553
  return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1469
1554
  name,
1470
1555
  isExportable: true,
@@ -1493,20 +1578,13 @@ function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName
1493
1578
  }
1494
1579
  //#endregion
1495
1580
  //#region src/components/Query.tsx
1496
- const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1581
+ const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1497
1582
  function buildQueryParamsNode(node, options) {
1498
- const { resolver } = options;
1499
- const { TData, TError } = buildResponseTypes(node, resolver);
1583
+ const { resolver, observerOptionsType } = options;
1500
1584
  const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
1501
1585
  name: "options",
1502
1586
  type: `{
1503
- query?: Partial<QueryObserverOptions<${[
1504
- TData,
1505
- TError,
1506
- "TData",
1507
- "TQueryData",
1508
- "TQueryKey"
1509
- ].join(", ")}>> & { client?: QueryClient },
1587
+ query?: Partial<${observerOptionsType}> & { client?: QueryClient },
1510
1588
  client?: ${buildClientOptionType()}
1511
1589
  }`,
1512
1590
  default: "{}"
@@ -1516,10 +1594,24 @@ function buildQueryParamsNode(node, options) {
1516
1594
  memberTypeWrapper: maybeValueOrGetter
1517
1595
  }), optionsParam].filter((param) => param !== null) });
1518
1596
  }
1519
- function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions }) {
1597
+ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions, suspense }) {
1520
1598
  const { TData, TError } = buildResponseTypes(node, tsResolver);
1521
- const returnType = `UseQueryResult<TData, ${TError}> & { queryKey: TQueryKey }`;
1522
- const generics = [
1599
+ const hookName = suspense ? "useSuspenseQuery" : "useQuery";
1600
+ const observerOptionsName = suspense ? "UseSuspenseQueryOptions" : "QueryObserverOptions";
1601
+ const observerOptionsType = suspense ? `${observerOptionsName}<${[
1602
+ TData,
1603
+ TError,
1604
+ "TData",
1605
+ "TQueryKey"
1606
+ ].join(", ")}>` : `${observerOptionsName}<${[
1607
+ TData,
1608
+ TError,
1609
+ "TData",
1610
+ "TQueryData",
1611
+ "TQueryKey"
1612
+ ].join(", ")}>`;
1613
+ const returnType = `${suspense ? "UseSuspenseQueryResult" : "UseQueryResult"}<TData, ${TError}> & { queryKey: TQueryKey }`;
1614
+ const generics = suspense ? [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`] : [
1523
1615
  `TData = ${TData}`,
1524
1616
  `TQueryData = ${TData}`,
1525
1617
  `TQueryKey extends QueryKey = ${queryKeyTypeName}`
@@ -1527,78 +1619,11 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1527
1619
  const resolvedParams = buildResolvedRequestParams(node);
1528
1620
  const queryKeyArgs = resolvedParams ? "resolvedParams" : "";
1529
1621
  const queryOptionsArgs = resolvedParams ? "resolvedParams, config" : "config";
1530
- const paramsNode = buildQueryParamsNode(node, { resolver: tsResolver });
1531
- const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
1532
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1533
- name,
1534
- isExportable: true,
1535
- isIndexable: true,
1536
- children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
1537
- name,
1538
- export: true,
1539
- generics: generics.join(", "),
1540
- params: paramsSignature,
1541
- returnType: void 0,
1542
- JSDoc: { comments: buildOperationComments(node) },
1543
- children: `
1544
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
1545
- const { client: queryClient, ...resolvedOptions } = queryConfig${resolvedParams ? `\n const resolvedParams = ${resolvedParams}` : ""}
1546
- const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyArgs})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1547
-
1548
- const queryResult = useQuery({
1549
- ...${queryOptionsName}(${queryOptionsArgs}),${customOptions ? "\n ...customOptions," : ""}
1550
- ...resolvedOptions,
1551
- queryKey,
1552
- } as unknown as QueryObserverOptions, queryClient) as ${returnType}
1553
-
1554
- queryResult.queryKey = queryKey as TQueryKey
1555
-
1556
- return queryResult
1557
- `
1558
- })
1559
- });
1560
- }
1561
- //#endregion
1562
- //#region src/components/SuspenseInfiniteQuery.tsx
1563
- const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1564
- function buildSuspenseInfiniteQueryParamsNode(node, options) {
1565
- const { resolver, pageParamGeneric } = options;
1566
- const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
1567
- name: "options",
1568
- type: `{
1569
- query?: Partial<UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
1570
- client?: ${buildClientOptionType()}
1571
- }`,
1572
- default: "{}"
1573
- });
1574
- return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [buildGroupedRequestParam(node, {
1575
- resolver,
1576
- memberTypeWrapper: maybeValueOrGetter
1577
- }), optionsParam].filter((param) => param !== null) });
1578
- }
1579
- function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions, initialPageParam, queryParam }) {
1580
- const { TData: responseType, TError: errorType } = buildResponseTypes(node, tsResolver);
1581
- const { pageParamType } = resolvePageParamType(node, {
1582
- resolver: tsResolver,
1583
- initialPageParam,
1584
- queryParam
1585
- });
1586
- const returnType = "UseSuspenseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
1587
- const generics = [
1588
- `TQueryFnData = ${responseType}`,
1589
- `TError = ${errorType}`,
1590
- "TData = InfiniteData<TQueryFnData>",
1591
- `TQueryKey extends QueryKey = ${queryKeyTypeName}`,
1592
- `TPageParam = ${pageParamType}`
1593
- ];
1594
- const resolvedParams = buildResolvedRequestParams(node);
1595
- const queryKeyArgs = resolvedParams ? "resolvedParams" : "";
1596
- const queryOptionsArgs = resolvedParams ? "resolvedParams, config" : "config";
1597
- const paramsNode = buildSuspenseInfiniteQueryParamsNode(node, {
1622
+ const paramsNode = buildQueryParamsNode(node, {
1598
1623
  resolver: tsResolver,
1599
- pageParamGeneric: "TPageParam"
1624
+ observerOptionsType
1600
1625
  });
1601
- const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
1626
+ const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
1602
1627
  return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1603
1628
  name,
1604
1629
  isExportable: true,
@@ -1615,11 +1640,11 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
1615
1640
  const { client: queryClient, ...resolvedOptions } = queryConfig${resolvedParams ? `\n const resolvedParams = ${resolvedParams}` : ""}
1616
1641
  const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyArgs})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1617
1642
 
1618
- const queryResult = useSuspenseInfiniteQuery({
1643
+ const queryResult = ${hookName}({
1619
1644
  ...${queryOptionsName}(${queryOptionsArgs}),${customOptions ? "\n ...customOptions," : ""}
1620
1645
  ...resolvedOptions,
1621
1646
  queryKey,
1622
- } as unknown as UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
1647
+ } as unknown as ${observerOptionsName}, queryClient) as ${returnType}
1623
1648
 
1624
1649
  queryResult.queryKey = queryKey as TQueryKey
1625
1650
 
@@ -1629,65 +1654,23 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
1629
1654
  });
1630
1655
  }
1631
1656
  //#endregion
1632
- //#region src/components/SuspenseInfiniteQueryOptions.tsx
1633
- const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1657
+ //#region src/components/QueryOptions.tsx
1658
+ const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1634
1659
  const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
1635
- function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName }) {
1636
- const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
1637
- const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
1638
- resolver: tsResolver,
1639
- initialPageParam,
1640
- queryParam
1641
- });
1660
+ function getQueryOptionsParams(node, options) {
1661
+ return buildQueryOptionsParams(node, options);
1662
+ }
1663
+ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
1664
+ const { TData, TError } = buildResponseTypes(node, tsResolver);
1665
+ const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
1666
+ const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
1642
1667
  const paramsNode = getQueryOptionsParams(node, { resolver: tsResolver });
1643
- const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
1668
+ const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1644
1669
  const queryFnBody = `const { data } = await ${buildClientCall(node, {
1645
1670
  clientName,
1646
1671
  signal: true
1647
1672
  })}
1648
- return data`;
1649
- const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
1650
- const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
1651
- const hasNewParams = nextParam != null || previousParam != null;
1652
- const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
1653
- if (hasNewParams) {
1654
- const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
1655
- const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
1656
- return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
1657
- }
1658
- if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
1659
- return ["getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1", "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1"];
1660
- })();
1661
- const queryOptionsArr = [
1662
- `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
1663
- getNextPageParamExpr,
1664
- getPreviousPageParamExpr
1665
- ].filter(Boolean);
1666
- const infiniteOverrideParams = queryParam && queryParamsTypeName ? `query = {
1667
- ...(query ?? {}),
1668
- ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
1669
- } as ${queryParamsTypeName}` : "";
1670
- if (infiniteOverrideParams) return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1671
- name,
1672
- isExportable: true,
1673
- isIndexable: true,
1674
- children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
1675
- name,
1676
- export: true,
1677
- params: paramsSignature,
1678
- children: `
1679
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1680
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1681
- queryKey,
1682
- queryFn: async ({ signal, pageParam }) => {
1683
- ${infiniteOverrideParams}
1684
- ${queryFnBody}
1685
- },
1686
- ${queryOptionsArr.join(",\n ")}
1687
- })
1688
- `
1689
- })
1690
- });
1673
+ return data`;
1691
1674
  return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1692
1675
  name,
1693
1676
  isExportable: true,
@@ -1697,81 +1680,18 @@ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${que
1697
1680
  export: true,
1698
1681
  params: paramsSignature,
1699
1682
  children: `
1700
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1701
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1702
- queryKey,
1703
- queryFn: async ({ signal }) => {
1704
- ${queryFnBody}
1705
- },
1706
- ${queryOptionsArr.join(",\n ")}
1707
- })
1683
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1684
+ return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
1685
+ queryKey,
1686
+ queryFn: async ({ signal }) => {
1687
+ ${queryFnBody}
1688
+ },
1689
+ })
1708
1690
  `
1709
1691
  })
1710
1692
  });
1711
1693
  }
1712
1694
  //#endregion
1713
- //#region src/components/SuspenseQuery.tsx
1714
- const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
1715
- function buildSuspenseQueryParamsNode(node, options) {
1716
- const { resolver } = options;
1717
- const { TData, TError } = buildResponseTypes(node, resolver);
1718
- const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
1719
- name: "options",
1720
- type: `{
1721
- query?: Partial<UseSuspenseQueryOptions<${[
1722
- TData,
1723
- TError,
1724
- "TData",
1725
- "TQueryKey"
1726
- ].join(", ")}>> & { client?: QueryClient },
1727
- client?: ${buildClientOptionType()}
1728
- }`,
1729
- default: "{}"
1730
- });
1731
- return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [buildGroupedRequestParam(node, {
1732
- resolver,
1733
- memberTypeWrapper: maybeValueOrGetter
1734
- }), optionsParam].filter((param) => param !== null) });
1735
- }
1736
- function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions }) {
1737
- const { TData, TError } = buildResponseTypes(node, tsResolver);
1738
- const returnType = `UseSuspenseQueryResult<TData, ${TError}> & { queryKey: TQueryKey }`;
1739
- const generics = [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
1740
- const resolvedParams = buildResolvedRequestParams(node);
1741
- const queryKeyArgs = resolvedParams ? "resolvedParams" : "";
1742
- const queryOptionsArgs = resolvedParams ? "resolvedParams, config" : "config";
1743
- const paramsNode = buildSuspenseQueryParamsNode(node, { resolver: tsResolver });
1744
- const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1745
- return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
1746
- name,
1747
- isExportable: true,
1748
- isIndexable: true,
1749
- children: /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.Function, {
1750
- name,
1751
- export: true,
1752
- generics: generics.join(", "),
1753
- params: paramsSignature,
1754
- returnType: void 0,
1755
- JSDoc: { comments: buildOperationComments(node) },
1756
- children: `
1757
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
1758
- const { client: queryClient, ...resolvedOptions } = queryConfig${resolvedParams ? `\n const resolvedParams = ${resolvedParams}` : ""}
1759
- const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyArgs})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1760
-
1761
- const queryResult = useSuspenseQuery({
1762
- ...${queryOptionsName}(${queryOptionsArgs}),${customOptions ? "\n ...customOptions," : ""}
1763
- ...resolvedOptions,
1764
- queryKey,
1765
- } as unknown as UseSuspenseQueryOptions, queryClient) as ${returnType}
1766
-
1767
- queryResult.queryKey = queryKey as TQueryKey
1768
-
1769
- return queryResult
1770
- `
1771
- })
1772
- });
1773
- }
1774
- //#endregion
1775
1695
  //#region src/generators/infiniteQueryGenerator.tsx
1776
1696
  /**
1777
1697
  * Built-in generator for `useInfiniteQuery` hooks. Enabled when
@@ -2346,7 +2266,7 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
2346
2266
  name: ["infiniteQueryOptions"],
2347
2267
  path: importPath
2348
2268
  }),
2349
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(SuspenseInfiniteQueryOptions, {
2269
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(InfiniteQueryOptions, {
2350
2270
  name: queryOptionsName,
2351
2271
  clientName: calledClientName,
2352
2272
  queryKeyName,
@@ -2373,7 +2293,7 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
2373
2293
  path: importPath,
2374
2294
  isTypeOnly: true
2375
2295
  }),
2376
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(SuspenseInfiniteQuery, {
2296
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(InfiniteQuery, {
2377
2297
  name: queryName,
2378
2298
  queryOptionsName,
2379
2299
  queryKeyName,
@@ -2382,7 +2302,8 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
2382
2302
  tsResolver,
2383
2303
  initialPageParam: infiniteOptions.initialPageParam,
2384
2304
  queryParam: infiniteOptions.queryParam,
2385
- customOptions
2305
+ customOptions,
2306
+ suspense: true
2386
2307
  })
2387
2308
  ] })
2388
2309
  ]
@@ -2520,14 +2441,15 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
2520
2441
  path: importPath,
2521
2442
  isTypeOnly: true
2522
2443
  }),
2523
- /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(SuspenseQuery, {
2444
+ /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(Query, {
2524
2445
  name: queryName,
2525
2446
  queryOptionsName,
2526
2447
  queryKeyName,
2527
2448
  queryKeyTypeName,
2528
2449
  node,
2529
2450
  tsResolver,
2530
- customOptions
2451
+ customOptions,
2452
+ suspense: true
2531
2453
  })
2532
2454
  ] })
2533
2455
  ]
@@ -2536,9 +2458,6 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
2536
2458
  });
2537
2459
  //#endregion
2538
2460
  //#region src/resolvers/resolverReactQuery.ts
2539
- function capitalize(name) {
2540
- return `${name.charAt(0).toUpperCase()}${name.slice(1)}`;
2541
- }
2542
2461
  /**
2543
2462
  * Default resolver used by `@kubb/plugin-react-query`. Decides the names and
2544
2463
  * file paths for every generated TanStack Query hook (`useFoo`,
@@ -2560,84 +2479,15 @@ function capitalize(name) {
2560
2479
  */
2561
2480
  const resolverReactQuery = (0, kubb_kit.createResolver)({
2562
2481
  pluginName: "plugin-react-query",
2563
- query: {
2564
- name(node) {
2565
- return `use${capitalize(this.name(node.operationId))}`;
2566
- },
2567
- optionsName(node) {
2568
- return `${this.name(node.operationId)}QueryOptions`;
2569
- },
2570
- keyName(node) {
2571
- return `${this.name(node.operationId)}QueryKey`;
2572
- },
2573
- keyTypeName(node) {
2574
- return `${capitalize(this.name(node.operationId))}QueryKey`;
2575
- },
2576
- clientName(node) {
2577
- return this.name(node.operationId);
2578
- }
2579
- },
2580
- suspenseQuery: {
2581
- name(node) {
2582
- return `use${capitalize(this.name(node.operationId))}Suspense`;
2583
- },
2584
- optionsName(node) {
2585
- return `${this.name(node.operationId)}SuspenseQueryOptions`;
2586
- },
2587
- keyName(node) {
2588
- return `${this.name(node.operationId)}SuspenseQueryKey`;
2589
- },
2590
- keyTypeName(node) {
2591
- return `${capitalize(this.name(node.operationId))}SuspenseQueryKey`;
2592
- },
2593
- clientName(node) {
2594
- return `${this.name(node.operationId)}Suspense`;
2595
- }
2596
- },
2597
- infiniteQuery: {
2598
- name(node) {
2599
- return `use${capitalize(this.name(node.operationId))}Infinite`;
2600
- },
2601
- optionsName(node) {
2602
- return `${this.name(node.operationId)}InfiniteQueryOptions`;
2603
- },
2604
- keyName(node) {
2605
- return `${this.name(node.operationId)}InfiniteQueryKey`;
2606
- },
2607
- keyTypeName(node) {
2608
- return `${capitalize(this.name(node.operationId))}InfiniteQueryKey`;
2609
- },
2610
- clientName(node) {
2611
- return `${this.name(node.operationId)}Infinite`;
2612
- }
2613
- },
2614
- suspenseInfiniteQuery: {
2615
- name(node) {
2616
- return `use${capitalize(this.name(node.operationId))}SuspenseInfinite`;
2617
- },
2618
- optionsName(node) {
2619
- return `${this.name(node.operationId)}SuspenseInfiniteQueryOptions`;
2620
- },
2621
- keyName(node) {
2622
- return `${this.name(node.operationId)}SuspenseInfiniteQueryKey`;
2623
- },
2624
- keyTypeName(node) {
2625
- return `${capitalize(this.name(node.operationId))}SuspenseInfiniteQueryKey`;
2626
- },
2627
- clientName(node) {
2628
- return `${this.name(node.operationId)}SuspenseInfinite`;
2629
- }
2630
- },
2482
+ query: createQueryResolver(),
2483
+ suspenseQuery: createQueryResolver("Suspense"),
2484
+ infiniteQuery: createQueryResolver("Infinite"),
2485
+ suspenseInfiniteQuery: createQueryResolver("SuspenseInfinite"),
2631
2486
  mutation: {
2632
- name(node) {
2633
- return `use${capitalize(this.name(node.operationId))}`;
2634
- },
2487
+ ...createMutationResolver(),
2635
2488
  optionsName(node) {
2636
2489
  return `${this.name(node.operationId)}MutationOptions`;
2637
2490
  },
2638
- keyName(node) {
2639
- return `${this.name(node.operationId)}MutationKey`;
2640
- },
2641
2491
  typeName(node) {
2642
2492
  return capitalize(this.name(node.operationId));
2643
2493
  }
@@ -2704,43 +2554,17 @@ const pluginReactQuery = (0, kubb_kit.definePlugin)((options) => {
2704
2554
  dependencies: [_kubb_plugin_ts.pluginTsName],
2705
2555
  hooks: { "kubb:plugin:setup"(ctx) {
2706
2556
  const resolver = userResolver ? kubb_kit.Resolver.merge(resolverReactQuery, userResolver) : resolverReactQuery;
2707
- const resolvedClient = resolveClient({
2708
- client,
2709
- pluginNames: (ctx.config.plugins ?? []).map((p) => p.name).filter((name) => Boolean(name))
2710
- });
2711
- if (resolvedClient.kind === "error") throw new Error(resolvedClient.message);
2712
- const resolvedClientDescriptor = {
2713
- kind: "contract",
2714
- pluginName: resolvedClient.pluginName
2715
- };
2716
2557
  ctx.setOptions({
2717
2558
  output,
2718
- client: resolvedClientDescriptor,
2559
+ client: resolveContractClient({
2560
+ client,
2561
+ plugins: ctx.config.plugins
2562
+ }),
2719
2563
  queryKey,
2720
- query: query === false ? false : {
2721
- importPath: "@tanstack/react-query",
2722
- methods: ["GET"],
2723
- ...query
2724
- },
2564
+ query: resolveQueryConfig(query, { importPath: "@tanstack/react-query" }),
2725
2565
  mutationKey,
2726
- mutation: mutation === false ? false : {
2727
- importPath: "@tanstack/react-query",
2728
- methods: [
2729
- "POST",
2730
- "PUT",
2731
- "PATCH",
2732
- "DELETE"
2733
- ],
2734
- ...mutation
2735
- },
2736
- infinite: infinite ? {
2737
- queryParam: "id",
2738
- initialPageParam: 0,
2739
- cursorParam: null,
2740
- nextParam: null,
2741
- previousParam: null,
2742
- ...infinite
2743
- } : false,
2566
+ mutation: resolveMutationConfig(mutation, { importPath: "@tanstack/react-query" }),
2567
+ infinite: resolveInfiniteConfig(infinite),
2744
2568
  suspense,
2745
2569
  customOptions: customOptions ? {
2746
2570
  name: "useCustomHookOptions",
@@ -2763,5 +2587,6 @@ const pluginReactQuery = (0, kubb_kit.definePlugin)((options) => {
2763
2587
  exports.default = pluginReactQuery;
2764
2588
  exports.pluginReactQuery = pluginReactQuery;
2765
2589
  exports.pluginReactQueryName = pluginReactQueryName;
2590
+ exports.resolverReactQuery = resolverReactQuery;
2766
2591
 
2767
2592
  //# sourceMappingURL=index.cjs.map