@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.js CHANGED
@@ -1,6 +1,6 @@
1
1
  import "./rolldown-runtime-C0LytTxp.js";
2
- import { Resolver, ast, createResolver, defineGenerator, definePlugin } from "kubb/kit";
3
2
  import path from "node:path";
3
+ import { Resolver, ast, createResolver, defineGenerator, definePlugin } from "kubb/kit";
4
4
  import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
5
5
  import { File, Function, Type, jsxRenderer } from "kubb/jsx";
6
6
  import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
@@ -31,6 +31,16 @@ function toCamelOrPascal(text, pascal) {
31
31
  function camelCase(text, { prefix = "", suffix = "" } = {}) {
32
32
  return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
33
33
  }
34
+ /**
35
+ * Uppercases only the first character of `text`, leaving the rest untouched.
36
+ * Unlike {@link pascalCase} it never re-splits word boundaries or strips characters.
37
+ *
38
+ * @example
39
+ * `capitalize('getPetById') // 'GetPetById'`
40
+ */
41
+ function capitalize(text) {
42
+ return `${text.charAt(0).toUpperCase()}${text.slice(1)}`;
43
+ }
34
44
  //#endregion
35
45
  //#region ../../internals/utils/src/reserved.ts
36
46
  /**
@@ -600,6 +610,20 @@ function resolveClient(options) {
600
610
  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."
601
611
  };
602
612
  }
613
+ /**
614
+ * Resolves the contract client during a consumer plugin's setup hook. Extracts the plugin names
615
+ * from the raw `plugins` config, applies {@link resolveClient}, and throws the diagnostic on a
616
+ * misconfiguration so every consumer fails fast with the same message.
617
+ */
618
+ function resolveContractClient(options) {
619
+ const { client, plugins = [] } = options;
620
+ const resolved = resolveClient({
621
+ client,
622
+ pluginNames: plugins.map((plugin) => plugin.name).filter((name) => Boolean(name))
623
+ });
624
+ if (resolved.kind === "error") throw new Error(resolved.message);
625
+ return resolved;
626
+ }
603
627
  //#endregion
604
628
  //#region ../../internals/client/src/resolveClientOperation.ts
605
629
  /**
@@ -627,33 +651,6 @@ function resolveClientOperation(options) {
627
651
  };
628
652
  }
629
653
  //#endregion
630
- //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
631
- const declarationPrinter$10 = functionPrinter({ mode: "declaration" });
632
- const mutationKeyTransformer = ({ node }) => {
633
- if (!node.path) return [];
634
- return [`{ url: '${Url.toPath(node.path)}' }`];
635
- };
636
- function MutationKey({ name, node, transformer }) {
637
- const paramsNode = createFunctionParameters({ params: [] });
638
- const paramsSignature = declarationPrinter$10.print(paramsNode) ?? "";
639
- const keys = (transformer ?? mutationKeyTransformer)({
640
- node,
641
- casing: "camelcase"
642
- });
643
- return /* @__PURE__ */ jsx(File.Source, {
644
- name,
645
- isExportable: true,
646
- isIndexable: true,
647
- children: /* @__PURE__ */ jsx(Function.Arrow, {
648
- name,
649
- export: true,
650
- params: paramsSignature,
651
- singleLine: true,
652
- children: `[${keys.join(", ")}] as const`
653
- })
654
- });
655
- }
656
- //#endregion
657
654
  //#region ../../internals/tanstack-query/src/utils.ts
658
655
  /**
659
656
  * The grouped request options, ordered for both the destructured signature and the
@@ -737,6 +734,9 @@ function buildQueryOptionsParams(node, options) {
737
734
  * shorthand alongside the spread `config`, with `throwOnError: true` pinned last so a caller's config
738
735
  * can't flip the query's error semantics. Queries thread the TanStack `signal`; mutations omit it.
739
736
  *
737
+ * When `unwrapName` is set, each request group is passed as an explicit member unwrapped through it,
738
+ * used by vue-query to resolve refs and getters with `toValue(...)` at call time.
739
+ *
740
740
  * @example
741
741
  * ```ts
742
742
  * buildClientCall(node, { clientName: 'getPetById', signal: true })
@@ -744,15 +744,101 @@ function buildQueryOptionsParams(node, options) {
744
744
  * ```
745
745
  */
746
746
  function buildClientCall(node, options) {
747
- const { clientName, signal = false } = options;
747
+ const { clientName, signal = false, unwrapName } = options;
748
748
  const { groups } = getRequestGroupOptionality(node);
749
749
  return `${clientName}({ ${[
750
750
  "...config",
751
- ...requestGroupOrder$1.filter((key) => groups[key]),
751
+ ...requestGroupOrder$1.filter((key) => groups[key]).map((name) => unwrapName ? `${name}: ${unwrapName(name)}` : name),
752
752
  signal ? "signal: config.signal ?? signal" : null,
753
753
  "throwOnError: true"
754
754
  ].filter((part) => part !== null).join(", ")} })`;
755
755
  }
756
+ /**
757
+ * Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
758
+ * success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
759
+ */
760
+ function buildResponseTypes(node, resolver) {
761
+ const successNames = resolveSuccessNames(node, resolver);
762
+ const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
763
+ const errorNames = resolveErrorNames(node, resolver);
764
+ return {
765
+ TData: responseName,
766
+ TError: `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`
767
+ };
768
+ }
769
+ function resolveFallbackPageParamType(initialPageParam) {
770
+ if (typeof initialPageParam === "number") return "number";
771
+ if (typeof initialPageParam === "boolean") return "boolean";
772
+ if (typeof initialPageParam !== "string") return "unknown";
773
+ if (!initialPageParam.includes(" as ")) return "string";
774
+ return initialPageParam.split(" as ").at(-1) ?? "unknown";
775
+ }
776
+ /**
777
+ * Resolves the `TPageParam` generic for the infinite-query hooks. Prefers the type read from the
778
+ * configured `queryParam` on the operation's query object, and falls back to the type inferred from
779
+ * `initialPageParam` when that parameter type is unavailable. Also returns the query params type name
780
+ * so callers can reuse it when rewriting the paginated request.
781
+ */
782
+ function resolvePageParamType(node, { resolver, initialPageParam, queryParam }) {
783
+ const firstQueryParam = getOperationParameters(node, { paramsCasing: "original" }).query[0];
784
+ const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
785
+ const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
786
+ const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
787
+ if (!queryParamType) return {
788
+ queryParamsTypeName,
789
+ pageParamType: resolveFallbackPageParamType(initialPageParam)
790
+ };
791
+ return {
792
+ queryParamsTypeName,
793
+ pageParamType: initialPageParam !== void 0 && initialPageParam !== null ? `NonNullable<${queryParamType}>` : queryParamType
794
+ };
795
+ }
796
+ /**
797
+ * Applies the shared query defaults during plugin setup: `false` disables query generation, and an
798
+ * object merges over `methods: ['GET']` and the plugin's runtime `importPath`.
799
+ */
800
+ function resolveQueryConfig(query, options) {
801
+ if (query === false) return false;
802
+ return {
803
+ importPath: options.importPath,
804
+ methods: ["GET"],
805
+ ...query
806
+ };
807
+ }
808
+ /**
809
+ * Applies the shared mutation defaults during plugin setup: `false` disables mutation generation,
810
+ * and an object merges over `methods: ['POST', 'PUT', 'PATCH', 'DELETE']` and the plugin's runtime
811
+ * `importPath`.
812
+ */
813
+ function resolveMutationConfig(mutation, options) {
814
+ if (mutation === false) return false;
815
+ return {
816
+ importPath: options.importPath,
817
+ methods: [
818
+ "POST",
819
+ "PUT",
820
+ "PATCH",
821
+ "DELETE"
822
+ ],
823
+ ...mutation
824
+ };
825
+ }
826
+ /**
827
+ * Applies the shared infinite-query defaults during plugin setup: a falsy value disables infinite
828
+ * queries, and an object merges over `queryParam: 'id'` and `initialPageParam: 0` with the cursor
829
+ * paths cleared.
830
+ */
831
+ function resolveInfiniteConfig(infinite) {
832
+ if (!infinite) return false;
833
+ return {
834
+ queryParam: "id",
835
+ initialPageParam: 0,
836
+ cursorParam: null,
837
+ nextParam: null,
838
+ previousParam: null,
839
+ ...infinite
840
+ };
841
+ }
756
842
  function matchesPattern(node, ov) {
757
843
  const { type, pattern } = ov;
758
844
  const matches = (value) => typeof pattern === "string" ? value === pattern : pattern.test(value);
@@ -793,8 +879,163 @@ function buildQueryKeyParams(node, options) {
793
879
  return createFunctionParameters({ params: groupedParam ? [groupedParam] : [] });
794
880
  }
795
881
  //#endregion
882
+ //#region ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
883
+ const declarationPrinter$7 = functionPrinter({ mode: "declaration" });
884
+ const callPrinter$3 = functionPrinter({ mode: "call" });
885
+ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName }) {
886
+ const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
887
+ const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
888
+ resolver: tsResolver,
889
+ initialPageParam,
890
+ queryParam
891
+ });
892
+ const groupedKeyParam = buildGroupedRequestParam(node, {
893
+ resolver: tsResolver,
894
+ keys: [
895
+ "path",
896
+ "query",
897
+ "body"
898
+ ],
899
+ memberTypeWrapper
900
+ });
901
+ const queryKeyParamsNode = createFunctionParameters({ params: groupedKeyParam ? [groupedKeyParam] : [] });
902
+ const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
903
+ const paramsNode = buildQueryOptionsParams(node, {
904
+ resolver: tsResolver,
905
+ memberTypeWrapper
906
+ });
907
+ const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
908
+ const queryFnBody = `const { data } = await ${buildClientCall(node, {
909
+ clientName,
910
+ signal: true,
911
+ unwrapName
912
+ })}
913
+ return data`;
914
+ const hasNewParams = nextParam != null || previousParam != null;
915
+ const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
916
+ if (hasNewParams) {
917
+ const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
918
+ const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
919
+ return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
920
+ }
921
+ if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
922
+ return ["getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1", "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1"];
923
+ })();
924
+ const queryOptionsArr = [
925
+ `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
926
+ getNextPageParamExpr,
927
+ getPreviousPageParamExpr
928
+ ].filter(Boolean);
929
+ const infiniteOverrideParams = queryParam && queryParamsTypeName ? `query = {
930
+ ...(query ?? {}),
931
+ ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
932
+ } as ${queryParamsTypeName}` : "";
933
+ const queryFnArgs = infiniteOverrideParams ? "{ signal, pageParam }" : "{ signal }";
934
+ const queryFnStatements = infiniteOverrideParams ? `${infiniteOverrideParams}\n ${queryFnBody}` : queryFnBody;
935
+ return /* @__PURE__ */ jsx(File.Source, {
936
+ name,
937
+ isExportable: true,
938
+ isIndexable: true,
939
+ children: /* @__PURE__ */ jsx(Function, {
940
+ name,
941
+ export: true,
942
+ params: paramsSignature,
943
+ children: `
944
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
945
+ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, ${queryKeyType}, ${pageParamType}>({
946
+ queryKey,
947
+ queryFn: async (${queryFnArgs}) => {
948
+ ${queryFnStatements}
949
+ },
950
+ ${queryOptionsArr.join(",\n ")}
951
+ })
952
+ `
953
+ })
954
+ });
955
+ }
956
+ //#endregion
957
+ //#region ../../internals/tanstack-query/src/components/MutationKey.tsx
958
+ const declarationPrinter$6 = functionPrinter({ mode: "declaration" });
959
+ const mutationKeyTransformer = ({ node }) => {
960
+ if (!node.path) return [];
961
+ return [`{ url: '${Url.toPath(node.path)}' }`];
962
+ };
963
+ function MutationKey({ name, node, transformer }) {
964
+ const paramsNode = createFunctionParameters({ params: [] });
965
+ const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
966
+ const keys = (transformer ?? mutationKeyTransformer)({
967
+ node,
968
+ casing: "camelcase"
969
+ });
970
+ return /* @__PURE__ */ jsx(File.Source, {
971
+ name,
972
+ isExportable: true,
973
+ isIndexable: true,
974
+ children: /* @__PURE__ */ jsx(Function.Arrow, {
975
+ name,
976
+ export: true,
977
+ params: paramsSignature,
978
+ singleLine: true,
979
+ children: `[${keys.join(", ")}] as const`
980
+ })
981
+ });
982
+ }
983
+ //#endregion
984
+ //#region ../../internals/tanstack-query/src/resolver.ts
985
+ /**
986
+ * Builds the shared query namespace for a variant. Spread the result into
987
+ * `createResolver` once per variant the plugin supports.
988
+ *
989
+ * @example
990
+ * ```ts
991
+ * createResolver<PluginReactQuery>({
992
+ * query: createQueryResolver(),
993
+ * suspenseQuery: createQueryResolver('Suspense'),
994
+ * })
995
+ * ```
996
+ */
997
+ function createQueryResolver(variant = "") {
998
+ return {
999
+ name(node) {
1000
+ return `use${capitalize(this.name(node.operationId))}${variant}`;
1001
+ },
1002
+ optionsName(node) {
1003
+ return `${this.name(node.operationId)}${variant}QueryOptions`;
1004
+ },
1005
+ keyName(node) {
1006
+ return `${this.name(node.operationId)}${variant}QueryKey`;
1007
+ },
1008
+ keyTypeName(node) {
1009
+ return `${capitalize(this.name(node.operationId))}${variant}QueryKey`;
1010
+ },
1011
+ clientName(node) {
1012
+ return `${this.name(node.operationId)}${variant}`;
1013
+ }
1014
+ };
1015
+ }
1016
+ /**
1017
+ * Builds the shared mutation namespace. Spread the result into
1018
+ * `createResolver` and add plugin-specific methods (`optionsName`,
1019
+ * `typeName`, `argTypeName`) next to it.
1020
+ *
1021
+ * @example
1022
+ * ```ts
1023
+ * createResolver<PluginSwr>({ mutation: { ...createMutationResolver(), argTypeName(node) {...} } })
1024
+ * ```
1025
+ */
1026
+ function createMutationResolver() {
1027
+ return {
1028
+ name(node) {
1029
+ return `use${capitalize(this.name(node.operationId))}`;
1030
+ },
1031
+ keyName(node) {
1032
+ return `${this.name(node.operationId)}MutationKey`;
1033
+ }
1034
+ };
1035
+ }
1036
+ //#endregion
796
1037
  //#region ../../internals/tanstack-query/src/components/QueryKey.tsx
797
- const declarationPrinter$9 = functionPrinter({ mode: "declaration" });
1038
+ const declarationPrinter$5 = functionPrinter({ mode: "declaration" });
798
1039
  const queryKeyTransformer = ({ node }) => {
799
1040
  if (!node.path) return [];
800
1041
  const hasPathParams = getOperationParameters(node).path.length > 0;
@@ -808,7 +1049,7 @@ const queryKeyTransformer = ({ node }) => {
808
1049
  };
809
1050
  function QueryKey({ name, node, tsResolver, typeName, transformer }) {
810
1051
  const paramsNode = buildQueryKeyParams(node, { resolver: tsResolver });
811
- const paramsSignature = declarationPrinter$9.print(paramsNode) ?? "";
1052
+ const paramsSignature = declarationPrinter$5.print(paramsNode) ?? "";
812
1053
  const keys = (transformer ?? queryKeyTransformer)({
813
1054
  node,
814
1055
  casing: "camelcase"
@@ -965,46 +1206,6 @@ function classifyOperation(node, { query, mutation }) {
965
1206
  isMutation: mutation !== false && !isQuery && (mutation ? mutation.methods : []).some((method) => !queryMethods.has(method) && node.method.toLowerCase() === method.toLowerCase())
966
1207
  };
967
1208
  }
968
- /**
969
- * Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
970
- * success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
971
- */
972
- function buildResponseTypes(node, resolver) {
973
- const successNames = resolveSuccessNames(node, resolver);
974
- const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
975
- const errorNames = resolveErrorNames(node, resolver);
976
- return {
977
- TData: responseName,
978
- TError: `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`
979
- };
980
- }
981
- function resolveFallbackPageParamType(initialPageParam) {
982
- if (typeof initialPageParam === "number") return "number";
983
- if (typeof initialPageParam === "boolean") return "boolean";
984
- if (typeof initialPageParam !== "string") return "unknown";
985
- if (!initialPageParam.includes(" as ")) return "string";
986
- return initialPageParam.split(" as ").at(-1) ?? "unknown";
987
- }
988
- /**
989
- * Resolves the `TPageParam` generic for the infinite-query hooks. Prefers the type read from the
990
- * configured `queryParam` on the operation's query object, and falls back to the type inferred from
991
- * `initialPageParam` when that parameter type is unavailable. Also returns the query params type name
992
- * so callers can reuse it when rewriting the paginated request.
993
- */
994
- function resolvePageParamType(node, { resolver, initialPageParam, queryParam }) {
995
- const firstQueryParam = getOperationParameters(node, { paramsCasing: "original" }).query[0];
996
- const groupName = firstQueryParam ? resolver.param.query(node, firstQueryParam) : null;
997
- const queryParamsTypeName = groupName !== (firstQueryParam ? resolver.param.name(node, firstQueryParam) : null) ? groupName : null;
998
- const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
999
- if (!queryParamType) return {
1000
- queryParamsTypeName,
1001
- pageParamType: resolveFallbackPageParamType(initialPageParam)
1002
- };
1003
- return {
1004
- queryParamsTypeName,
1005
- pageParamType: initialPageParam !== void 0 && initialPageParam !== null ? `NonNullable<${queryParamType}>` : queryParamType
1006
- };
1007
- }
1008
1209
  //#endregion
1009
1210
  //#region src/generators/hookOptionsGenerator.tsx
1010
1211
  /**
@@ -1168,13 +1369,13 @@ const hookOptionsGenerator = defineGenerator({
1168
1369
  });
1169
1370
  //#endregion
1170
1371
  //#region src/components/InfiniteQuery.tsx
1171
- const declarationPrinter$8 = functionPrinter({ mode: "declaration" });
1372
+ const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
1172
1373
  function buildInfiniteQueryParamsNode(node, options) {
1173
- const { resolver, pageParamGeneric } = options;
1374
+ const { resolver, pageParamGeneric, observerOptionsName } = options;
1174
1375
  const optionsParam = createFunctionParameter({
1175
1376
  name: "options",
1176
1377
  type: `{
1177
- query?: Partial<InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
1378
+ query?: Partial<${observerOptionsName}<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
1178
1379
  client?: ${buildClientOptionType()}
1179
1380
  }`,
1180
1381
  default: "{}"
@@ -1184,14 +1385,16 @@ function buildInfiniteQueryParamsNode(node, options) {
1184
1385
  memberTypeWrapper: maybeValueOrGetter
1185
1386
  }), optionsParam].filter((param) => param !== null) });
1186
1387
  }
1187
- function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, initialPageParam, queryParam, customOptions }) {
1388
+ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, initialPageParam, queryParam, customOptions, suspense }) {
1188
1389
  const { TData: responseType, TError: errorType } = buildResponseTypes(node, tsResolver);
1189
1390
  const { pageParamType } = resolvePageParamType(node, {
1190
1391
  resolver: tsResolver,
1191
1392
  initialPageParam,
1192
1393
  queryParam
1193
1394
  });
1194
- const returnType = "UseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
1395
+ const hookName = suspense ? "useSuspenseInfiniteQuery" : "useInfiniteQuery";
1396
+ const observerOptionsName = suspense ? "UseSuspenseInfiniteQueryOptions" : "InfiniteQueryObserverOptions";
1397
+ const returnType = `${suspense ? "UseSuspenseInfiniteQueryResult" : "UseInfiniteQueryResult"}<TData, TError> & { queryKey: TQueryKey }`;
1195
1398
  const generics = [
1196
1399
  `TQueryFnData = ${responseType}`,
1197
1400
  `TError = ${errorType}`,
@@ -1204,9 +1407,10 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
1204
1407
  const queryOptionsArgs = resolvedParams ? "resolvedParams, config" : "config";
1205
1408
  const paramsNode = buildInfiniteQueryParamsNode(node, {
1206
1409
  resolver: tsResolver,
1207
- pageParamGeneric: "TPageParam"
1410
+ pageParamGeneric: "TPageParam",
1411
+ observerOptionsName
1208
1412
  });
1209
- const paramsSignature = declarationPrinter$8.print(paramsNode) ?? "";
1413
+ const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
1210
1414
  return /* @__PURE__ */ jsx(File.Source, {
1211
1415
  name,
1212
1416
  isExportable: true,
@@ -1223,141 +1427,22 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
1223
1427
  const { client: queryClient, ...resolvedOptions } = queryConfig${resolvedParams ? `\n const resolvedParams = ${resolvedParams}` : ""}
1224
1428
  const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyArgs})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1225
1429
 
1226
- const queryResult = useInfiniteQuery({
1430
+ const queryResult = ${hookName}({
1227
1431
  ...${queryOptionsName}(${queryOptionsArgs}),${customOptions ? "\n ...customOptions," : ""}
1228
1432
  ...resolvedOptions,
1229
1433
  queryKey,
1230
- } as unknown as InfiniteQueryObserverOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
1434
+ } as unknown as ${observerOptionsName}<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
1231
1435
 
1232
1436
  queryResult.queryKey = queryKey as TQueryKey
1233
1437
 
1234
- return queryResult
1235
- `
1236
- })
1237
- });
1238
- }
1239
- //#endregion
1240
- //#region src/components/QueryOptions.tsx
1241
- const declarationPrinter$7 = functionPrinter({ mode: "declaration" });
1242
- const callPrinter$4 = functionPrinter({ mode: "call" });
1243
- function getQueryOptionsParams(node, options) {
1244
- return buildQueryOptionsParams(node, options);
1245
- }
1246
- function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
1247
- const { TData, TError } = buildResponseTypes(node, tsResolver);
1248
- const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
1249
- const queryKeyParamsCall = callPrinter$4.print(queryKeyParamsNode) ?? "";
1250
- const paramsNode = getQueryOptionsParams(node, { resolver: tsResolver });
1251
- const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
1252
- const queryFnBody = `const { data } = await ${buildClientCall(node, {
1253
- clientName,
1254
- signal: true
1255
- })}
1256
- return data`;
1257
- return /* @__PURE__ */ jsx(File.Source, {
1258
- name,
1259
- isExportable: true,
1260
- isIndexable: true,
1261
- children: /* @__PURE__ */ jsx(Function, {
1262
- name,
1263
- export: true,
1264
- params: paramsSignature,
1265
- children: `
1266
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1267
- return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
1268
- queryKey,
1269
- queryFn: async ({ signal }) => {
1270
- ${queryFnBody}
1271
- },
1272
- })
1273
- `
1274
- })
1275
- });
1276
- }
1277
- //#endregion
1278
- //#region src/components/InfiniteQueryOptions.tsx
1279
- const declarationPrinter$6 = functionPrinter({ mode: "declaration" });
1280
- const callPrinter$3 = functionPrinter({ mode: "call" });
1281
- function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName }) {
1282
- const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
1283
- const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
1284
- resolver: tsResolver,
1285
- initialPageParam,
1286
- queryParam
1287
- });
1288
- const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
1289
- const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
1290
- const paramsNode = getQueryOptionsParams(node, { resolver: tsResolver });
1291
- const paramsSignature = declarationPrinter$6.print(paramsNode) ?? "";
1292
- const queryFnBody = `const { data } = await ${buildClientCall(node, {
1293
- clientName,
1294
- signal: true
1295
- })}
1296
- return data`;
1297
- const hasNewParams = nextParam != null || previousParam != null;
1298
- const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
1299
- if (hasNewParams) {
1300
- const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
1301
- const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
1302
- return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
1303
- }
1304
- if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
1305
- return ["getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1", "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1"];
1306
- })();
1307
- const queryOptionsArr = [
1308
- `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
1309
- getNextPageParamExpr,
1310
- getPreviousPageParamExpr
1311
- ].filter(Boolean);
1312
- const infiniteOverrideParams = queryParam && queryParamsTypeName ? `query = {
1313
- ...(query ?? {}),
1314
- ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
1315
- } as ${queryParamsTypeName}` : "";
1316
- if (infiniteOverrideParams) return /* @__PURE__ */ jsx(File.Source, {
1317
- name,
1318
- isExportable: true,
1319
- isIndexable: true,
1320
- children: /* @__PURE__ */ jsx(Function, {
1321
- name,
1322
- export: true,
1323
- params: paramsSignature,
1324
- children: `
1325
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1326
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1327
- queryKey,
1328
- queryFn: async ({ signal, pageParam }) => {
1329
- ${infiniteOverrideParams}
1330
- ${queryFnBody}
1331
- },
1332
- ${queryOptionsArr.join(",\n ")}
1333
- })
1334
- `
1335
- })
1336
- });
1337
- return /* @__PURE__ */ jsx(File.Source, {
1338
- name,
1339
- isExportable: true,
1340
- isIndexable: true,
1341
- children: /* @__PURE__ */ jsx(Function, {
1342
- name,
1343
- export: true,
1344
- params: paramsSignature,
1345
- children: `
1346
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1347
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1348
- queryKey,
1349
- queryFn: async ({ signal }) => {
1350
- ${queryFnBody}
1351
- },
1352
- ${queryOptionsArr.join(",\n ")}
1353
- })
1354
- `
1438
+ return queryResult
1439
+ `
1355
1440
  })
1356
1441
  });
1357
1442
  }
1358
1443
  //#endregion
1359
1444
  //#region src/components/MutationOptions.tsx
1360
- const declarationPrinter$5 = functionPrinter({ mode: "declaration" });
1445
+ const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
1361
1446
  const callPrinter$2 = functionPrinter({ mode: "call" });
1362
1447
  function buildMutationConfigParamsNode(node) {
1363
1448
  return createFunctionParameters({ params: [createFunctionParameter({
@@ -1369,7 +1454,7 @@ function buildMutationConfigParamsNode(node) {
1369
1454
  function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }) {
1370
1455
  const { TData, TError } = buildResponseTypes(node, tsResolver);
1371
1456
  const configParamsNode = buildMutationConfigParamsNode(node);
1372
- const paramsSignature = declarationPrinter$5.print(configParamsNode) ?? "";
1457
+ const paramsSignature = declarationPrinter$3.print(configParamsNode) ?? "";
1373
1458
  const groupedParam = buildGroupedRequestParam(node, { resolver: tsResolver });
1374
1459
  const hasMutationParams = groupedParam !== null;
1375
1460
  const groupedParamsNode = createFunctionParameters({ params: groupedParam ? [groupedParam] : [] });
@@ -1403,7 +1488,7 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }
1403
1488
  }
1404
1489
  //#endregion
1405
1490
  //#region src/components/Mutation.tsx
1406
- const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
1491
+ const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
1407
1492
  const callPrinter$1 = functionPrinter({ mode: "call" });
1408
1493
  function resolveMutationRequestType(node, resolver) {
1409
1494
  return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
@@ -1437,7 +1522,7 @@ function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName
1437
1522
  const mutationOptionsConfigNode = buildMutationConfigParamsNode(node);
1438
1523
  const mutationOptionsParamsCall = callPrinter$1.print(mutationOptionsConfigNode) ?? "";
1439
1524
  const paramsNode = buildMutationParamsNode(node, { resolver: tsResolver });
1440
- const paramsSignature = declarationPrinter$4.print(paramsNode) ?? "";
1525
+ const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
1441
1526
  return /* @__PURE__ */ jsx(File.Source, {
1442
1527
  name,
1443
1528
  isExportable: true,
@@ -1466,20 +1551,13 @@ function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName
1466
1551
  }
1467
1552
  //#endregion
1468
1553
  //#region src/components/Query.tsx
1469
- const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
1554
+ const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
1470
1555
  function buildQueryParamsNode(node, options) {
1471
- const { resolver } = options;
1472
- const { TData, TError } = buildResponseTypes(node, resolver);
1556
+ const { resolver, observerOptionsType } = options;
1473
1557
  const optionsParam = createFunctionParameter({
1474
1558
  name: "options",
1475
1559
  type: `{
1476
- query?: Partial<QueryObserverOptions<${[
1477
- TData,
1478
- TError,
1479
- "TData",
1480
- "TQueryData",
1481
- "TQueryKey"
1482
- ].join(", ")}>> & { client?: QueryClient },
1560
+ query?: Partial<${observerOptionsType}> & { client?: QueryClient },
1483
1561
  client?: ${buildClientOptionType()}
1484
1562
  }`,
1485
1563
  default: "{}"
@@ -1489,10 +1567,24 @@ function buildQueryParamsNode(node, options) {
1489
1567
  memberTypeWrapper: maybeValueOrGetter
1490
1568
  }), optionsParam].filter((param) => param !== null) });
1491
1569
  }
1492
- function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions }) {
1570
+ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions, suspense }) {
1493
1571
  const { TData, TError } = buildResponseTypes(node, tsResolver);
1494
- const returnType = `UseQueryResult<TData, ${TError}> & { queryKey: TQueryKey }`;
1495
- const generics = [
1572
+ const hookName = suspense ? "useSuspenseQuery" : "useQuery";
1573
+ const observerOptionsName = suspense ? "UseSuspenseQueryOptions" : "QueryObserverOptions";
1574
+ const observerOptionsType = suspense ? `${observerOptionsName}<${[
1575
+ TData,
1576
+ TError,
1577
+ "TData",
1578
+ "TQueryKey"
1579
+ ].join(", ")}>` : `${observerOptionsName}<${[
1580
+ TData,
1581
+ TError,
1582
+ "TData",
1583
+ "TQueryData",
1584
+ "TQueryKey"
1585
+ ].join(", ")}>`;
1586
+ const returnType = `${suspense ? "UseSuspenseQueryResult" : "UseQueryResult"}<TData, ${TError}> & { queryKey: TQueryKey }`;
1587
+ const generics = suspense ? [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`] : [
1496
1588
  `TData = ${TData}`,
1497
1589
  `TQueryData = ${TData}`,
1498
1590
  `TQueryKey extends QueryKey = ${queryKeyTypeName}`
@@ -1500,78 +1592,11 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1500
1592
  const resolvedParams = buildResolvedRequestParams(node);
1501
1593
  const queryKeyArgs = resolvedParams ? "resolvedParams" : "";
1502
1594
  const queryOptionsArgs = resolvedParams ? "resolvedParams, config" : "config";
1503
- const paramsNode = buildQueryParamsNode(node, { resolver: tsResolver });
1504
- const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
1505
- return /* @__PURE__ */ jsx(File.Source, {
1506
- name,
1507
- isExportable: true,
1508
- isIndexable: true,
1509
- children: /* @__PURE__ */ jsx(Function, {
1510
- name,
1511
- export: true,
1512
- generics: generics.join(", "),
1513
- params: paramsSignature,
1514
- returnType: void 0,
1515
- JSDoc: { comments: buildOperationComments(node) },
1516
- children: `
1517
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
1518
- const { client: queryClient, ...resolvedOptions } = queryConfig${resolvedParams ? `\n const resolvedParams = ${resolvedParams}` : ""}
1519
- const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyArgs})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1520
-
1521
- const queryResult = useQuery({
1522
- ...${queryOptionsName}(${queryOptionsArgs}),${customOptions ? "\n ...customOptions," : ""}
1523
- ...resolvedOptions,
1524
- queryKey,
1525
- } as unknown as QueryObserverOptions, queryClient) as ${returnType}
1526
-
1527
- queryResult.queryKey = queryKey as TQueryKey
1528
-
1529
- return queryResult
1530
- `
1531
- })
1532
- });
1533
- }
1534
- //#endregion
1535
- //#region src/components/SuspenseInfiniteQuery.tsx
1536
- const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
1537
- function buildSuspenseInfiniteQueryParamsNode(node, options) {
1538
- const { resolver, pageParamGeneric } = options;
1539
- const optionsParam = createFunctionParameter({
1540
- name: "options",
1541
- type: `{
1542
- query?: Partial<UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, ${pageParamGeneric}>> & { client?: QueryClient },
1543
- client?: ${buildClientOptionType()}
1544
- }`,
1545
- default: "{}"
1546
- });
1547
- return createFunctionParameters({ params: [buildGroupedRequestParam(node, {
1548
- resolver,
1549
- memberTypeWrapper: maybeValueOrGetter
1550
- }), optionsParam].filter((param) => param !== null) });
1551
- }
1552
- function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions, initialPageParam, queryParam }) {
1553
- const { TData: responseType, TError: errorType } = buildResponseTypes(node, tsResolver);
1554
- const { pageParamType } = resolvePageParamType(node, {
1555
- resolver: tsResolver,
1556
- initialPageParam,
1557
- queryParam
1558
- });
1559
- const returnType = "UseSuspenseInfiniteQueryResult<TData, TError> & { queryKey: TQueryKey }";
1560
- const generics = [
1561
- `TQueryFnData = ${responseType}`,
1562
- `TError = ${errorType}`,
1563
- "TData = InfiniteData<TQueryFnData>",
1564
- `TQueryKey extends QueryKey = ${queryKeyTypeName}`,
1565
- `TPageParam = ${pageParamType}`
1566
- ];
1567
- const resolvedParams = buildResolvedRequestParams(node);
1568
- const queryKeyArgs = resolvedParams ? "resolvedParams" : "";
1569
- const queryOptionsArgs = resolvedParams ? "resolvedParams, config" : "config";
1570
- const paramsNode = buildSuspenseInfiniteQueryParamsNode(node, {
1595
+ const paramsNode = buildQueryParamsNode(node, {
1571
1596
  resolver: tsResolver,
1572
- pageParamGeneric: "TPageParam"
1597
+ observerOptionsType
1573
1598
  });
1574
- const paramsSignature = declarationPrinter$2.print(paramsNode) ?? "";
1599
+ const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
1575
1600
  return /* @__PURE__ */ jsx(File.Source, {
1576
1601
  name,
1577
1602
  isExportable: true,
@@ -1588,11 +1613,11 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
1588
1613
  const { client: queryClient, ...resolvedOptions } = queryConfig${resolvedParams ? `\n const resolvedParams = ${resolvedParams}` : ""}
1589
1614
  const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyArgs})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1590
1615
 
1591
- const queryResult = useSuspenseInfiniteQuery({
1616
+ const queryResult = ${hookName}({
1592
1617
  ...${queryOptionsName}(${queryOptionsArgs}),${customOptions ? "\n ...customOptions," : ""}
1593
1618
  ...resolvedOptions,
1594
1619
  queryKey,
1595
- } as unknown as UseSuspenseInfiniteQueryOptions<TQueryFnData, TError, TData, TQueryKey, TPageParam>, queryClient) as ${returnType}
1620
+ } as unknown as ${observerOptionsName}, queryClient) as ${returnType}
1596
1621
 
1597
1622
  queryResult.queryKey = queryKey as TQueryKey
1598
1623
 
@@ -1602,65 +1627,23 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
1602
1627
  });
1603
1628
  }
1604
1629
  //#endregion
1605
- //#region src/components/SuspenseInfiniteQueryOptions.tsx
1606
- const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
1630
+ //#region src/components/QueryOptions.tsx
1631
+ const declarationPrinter = functionPrinter({ mode: "declaration" });
1607
1632
  const callPrinter = functionPrinter({ mode: "call" });
1608
- function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName }) {
1609
- const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
1610
- const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
1611
- resolver: tsResolver,
1612
- initialPageParam,
1613
- queryParam
1614
- });
1633
+ function getQueryOptionsParams(node, options) {
1634
+ return buildQueryOptionsParams(node, options);
1635
+ }
1636
+ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
1637
+ const { TData, TError } = buildResponseTypes(node, tsResolver);
1638
+ const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
1639
+ const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
1615
1640
  const paramsNode = getQueryOptionsParams(node, { resolver: tsResolver });
1616
- const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
1641
+ const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1617
1642
  const queryFnBody = `const { data } = await ${buildClientCall(node, {
1618
1643
  clientName,
1619
1644
  signal: true
1620
1645
  })}
1621
- return data`;
1622
- const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
1623
- const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
1624
- const hasNewParams = nextParam != null || previousParam != null;
1625
- const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
1626
- if (hasNewParams) {
1627
- const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
1628
- const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
1629
- return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
1630
- }
1631
- if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
1632
- return ["getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1", "getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= 1 ? undefined : firstPageParam - 1"];
1633
- })();
1634
- const queryOptionsArr = [
1635
- `initialPageParam: ${typeof initialPageParam === "string" ? JSON.stringify(initialPageParam) : initialPageParam}`,
1636
- getNextPageParamExpr,
1637
- getPreviousPageParamExpr
1638
- ].filter(Boolean);
1639
- const infiniteOverrideParams = queryParam && queryParamsTypeName ? `query = {
1640
- ...(query ?? {}),
1641
- ['${queryParam}']: pageParam as unknown as ${queryParamsTypeName}['${queryParam}'],
1642
- } as ${queryParamsTypeName}` : "";
1643
- if (infiniteOverrideParams) return /* @__PURE__ */ jsx(File.Source, {
1644
- name,
1645
- isExportable: true,
1646
- isIndexable: true,
1647
- children: /* @__PURE__ */ jsx(Function, {
1648
- name,
1649
- export: true,
1650
- params: paramsSignature,
1651
- children: `
1652
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1653
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1654
- queryKey,
1655
- queryFn: async ({ signal, pageParam }) => {
1656
- ${infiniteOverrideParams}
1657
- ${queryFnBody}
1658
- },
1659
- ${queryOptionsArr.join(",\n ")}
1660
- })
1661
- `
1662
- })
1663
- });
1646
+ return data`;
1664
1647
  return /* @__PURE__ */ jsx(File.Source, {
1665
1648
  name,
1666
1649
  isExportable: true,
@@ -1670,81 +1653,18 @@ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${que
1670
1653
  export: true,
1671
1654
  params: paramsSignature,
1672
1655
  children: `
1673
- const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1674
- return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${queryFnDataType}>, typeof queryKey, ${pageParamType}>({
1675
- queryKey,
1676
- queryFn: async ({ signal }) => {
1677
- ${queryFnBody}
1678
- },
1679
- ${queryOptionsArr.join(",\n ")}
1680
- })
1656
+ const queryKey = ${queryKeyName}(${queryKeyParamsCall})
1657
+ return queryOptions<${TData}, ${TError}, ${TData}, typeof queryKey>({
1658
+ queryKey,
1659
+ queryFn: async ({ signal }) => {
1660
+ ${queryFnBody}
1661
+ },
1662
+ })
1681
1663
  `
1682
1664
  })
1683
1665
  });
1684
1666
  }
1685
1667
  //#endregion
1686
- //#region src/components/SuspenseQuery.tsx
1687
- const declarationPrinter = functionPrinter({ mode: "declaration" });
1688
- function buildSuspenseQueryParamsNode(node, options) {
1689
- const { resolver } = options;
1690
- const { TData, TError } = buildResponseTypes(node, resolver);
1691
- const optionsParam = createFunctionParameter({
1692
- name: "options",
1693
- type: `{
1694
- query?: Partial<UseSuspenseQueryOptions<${[
1695
- TData,
1696
- TError,
1697
- "TData",
1698
- "TQueryKey"
1699
- ].join(", ")}>> & { client?: QueryClient },
1700
- client?: ${buildClientOptionType()}
1701
- }`,
1702
- default: "{}"
1703
- });
1704
- return createFunctionParameters({ params: [buildGroupedRequestParam(node, {
1705
- resolver,
1706
- memberTypeWrapper: maybeValueOrGetter
1707
- }), optionsParam].filter((param) => param !== null) });
1708
- }
1709
- function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions }) {
1710
- const { TData, TError } = buildResponseTypes(node, tsResolver);
1711
- const returnType = `UseSuspenseQueryResult<TData, ${TError}> & { queryKey: TQueryKey }`;
1712
- const generics = [`TData = ${TData}`, `TQueryKey extends QueryKey = ${queryKeyTypeName}`];
1713
- const resolvedParams = buildResolvedRequestParams(node);
1714
- const queryKeyArgs = resolvedParams ? "resolvedParams" : "";
1715
- const queryOptionsArgs = resolvedParams ? "resolvedParams, config" : "config";
1716
- const paramsNode = buildSuspenseQueryParamsNode(node, { resolver: tsResolver });
1717
- const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
1718
- return /* @__PURE__ */ jsx(File.Source, {
1719
- name,
1720
- isExportable: true,
1721
- isIndexable: true,
1722
- children: /* @__PURE__ */ jsx(Function, {
1723
- name,
1724
- export: true,
1725
- generics: generics.join(", "),
1726
- params: paramsSignature,
1727
- returnType: void 0,
1728
- JSDoc: { comments: buildOperationComments(node) },
1729
- children: `
1730
- const { query: queryConfig = {}, client: config = {} } = options ?? {}
1731
- const { client: queryClient, ...resolvedOptions } = queryConfig${resolvedParams ? `\n const resolvedParams = ${resolvedParams}` : ""}
1732
- const queryKey = resolvedOptions?.queryKey ?? ${queryKeyName}(${queryKeyArgs})${customOptions ? `\n const customOptions = ${customOptions.name}({ hookName: '${name}', operationId: '${node.operationId}' })` : ""}
1733
-
1734
- const queryResult = useSuspenseQuery({
1735
- ...${queryOptionsName}(${queryOptionsArgs}),${customOptions ? "\n ...customOptions," : ""}
1736
- ...resolvedOptions,
1737
- queryKey,
1738
- } as unknown as UseSuspenseQueryOptions, queryClient) as ${returnType}
1739
-
1740
- queryResult.queryKey = queryKey as TQueryKey
1741
-
1742
- return queryResult
1743
- `
1744
- })
1745
- });
1746
- }
1747
- //#endregion
1748
1668
  //#region src/generators/infiniteQueryGenerator.tsx
1749
1669
  /**
1750
1670
  * Built-in generator for `useInfiniteQuery` hooks. Enabled when
@@ -2319,7 +2239,7 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
2319
2239
  name: ["infiniteQueryOptions"],
2320
2240
  path: importPath
2321
2241
  }),
2322
- /* @__PURE__ */ jsx(SuspenseInfiniteQueryOptions, {
2242
+ /* @__PURE__ */ jsx(InfiniteQueryOptions, {
2323
2243
  name: queryOptionsName,
2324
2244
  clientName: calledClientName,
2325
2245
  queryKeyName,
@@ -2346,7 +2266,7 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
2346
2266
  path: importPath,
2347
2267
  isTypeOnly: true
2348
2268
  }),
2349
- /* @__PURE__ */ jsx(SuspenseInfiniteQuery, {
2269
+ /* @__PURE__ */ jsx(InfiniteQuery, {
2350
2270
  name: queryName,
2351
2271
  queryOptionsName,
2352
2272
  queryKeyName,
@@ -2355,7 +2275,8 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
2355
2275
  tsResolver,
2356
2276
  initialPageParam: infiniteOptions.initialPageParam,
2357
2277
  queryParam: infiniteOptions.queryParam,
2358
- customOptions
2278
+ customOptions,
2279
+ suspense: true
2359
2280
  })
2360
2281
  ] })
2361
2282
  ]
@@ -2493,14 +2414,15 @@ const suspenseQueryGenerator = defineGenerator({
2493
2414
  path: importPath,
2494
2415
  isTypeOnly: true
2495
2416
  }),
2496
- /* @__PURE__ */ jsx(SuspenseQuery, {
2417
+ /* @__PURE__ */ jsx(Query, {
2497
2418
  name: queryName,
2498
2419
  queryOptionsName,
2499
2420
  queryKeyName,
2500
2421
  queryKeyTypeName,
2501
2422
  node,
2502
2423
  tsResolver,
2503
- customOptions
2424
+ customOptions,
2425
+ suspense: true
2504
2426
  })
2505
2427
  ] })
2506
2428
  ]
@@ -2509,9 +2431,6 @@ const suspenseQueryGenerator = defineGenerator({
2509
2431
  });
2510
2432
  //#endregion
2511
2433
  //#region src/resolvers/resolverReactQuery.ts
2512
- function capitalize(name) {
2513
- return `${name.charAt(0).toUpperCase()}${name.slice(1)}`;
2514
- }
2515
2434
  /**
2516
2435
  * Default resolver used by `@kubb/plugin-react-query`. Decides the names and
2517
2436
  * file paths for every generated TanStack Query hook (`useFoo`,
@@ -2533,84 +2452,15 @@ function capitalize(name) {
2533
2452
  */
2534
2453
  const resolverReactQuery = createResolver({
2535
2454
  pluginName: "plugin-react-query",
2536
- query: {
2537
- name(node) {
2538
- return `use${capitalize(this.name(node.operationId))}`;
2539
- },
2540
- optionsName(node) {
2541
- return `${this.name(node.operationId)}QueryOptions`;
2542
- },
2543
- keyName(node) {
2544
- return `${this.name(node.operationId)}QueryKey`;
2545
- },
2546
- keyTypeName(node) {
2547
- return `${capitalize(this.name(node.operationId))}QueryKey`;
2548
- },
2549
- clientName(node) {
2550
- return this.name(node.operationId);
2551
- }
2552
- },
2553
- suspenseQuery: {
2554
- name(node) {
2555
- return `use${capitalize(this.name(node.operationId))}Suspense`;
2556
- },
2557
- optionsName(node) {
2558
- return `${this.name(node.operationId)}SuspenseQueryOptions`;
2559
- },
2560
- keyName(node) {
2561
- return `${this.name(node.operationId)}SuspenseQueryKey`;
2562
- },
2563
- keyTypeName(node) {
2564
- return `${capitalize(this.name(node.operationId))}SuspenseQueryKey`;
2565
- },
2566
- clientName(node) {
2567
- return `${this.name(node.operationId)}Suspense`;
2568
- }
2569
- },
2570
- infiniteQuery: {
2571
- name(node) {
2572
- return `use${capitalize(this.name(node.operationId))}Infinite`;
2573
- },
2574
- optionsName(node) {
2575
- return `${this.name(node.operationId)}InfiniteQueryOptions`;
2576
- },
2577
- keyName(node) {
2578
- return `${this.name(node.operationId)}InfiniteQueryKey`;
2579
- },
2580
- keyTypeName(node) {
2581
- return `${capitalize(this.name(node.operationId))}InfiniteQueryKey`;
2582
- },
2583
- clientName(node) {
2584
- return `${this.name(node.operationId)}Infinite`;
2585
- }
2586
- },
2587
- suspenseInfiniteQuery: {
2588
- name(node) {
2589
- return `use${capitalize(this.name(node.operationId))}SuspenseInfinite`;
2590
- },
2591
- optionsName(node) {
2592
- return `${this.name(node.operationId)}SuspenseInfiniteQueryOptions`;
2593
- },
2594
- keyName(node) {
2595
- return `${this.name(node.operationId)}SuspenseInfiniteQueryKey`;
2596
- },
2597
- keyTypeName(node) {
2598
- return `${capitalize(this.name(node.operationId))}SuspenseInfiniteQueryKey`;
2599
- },
2600
- clientName(node) {
2601
- return `${this.name(node.operationId)}SuspenseInfinite`;
2602
- }
2603
- },
2455
+ query: createQueryResolver(),
2456
+ suspenseQuery: createQueryResolver("Suspense"),
2457
+ infiniteQuery: createQueryResolver("Infinite"),
2458
+ suspenseInfiniteQuery: createQueryResolver("SuspenseInfinite"),
2604
2459
  mutation: {
2605
- name(node) {
2606
- return `use${capitalize(this.name(node.operationId))}`;
2607
- },
2460
+ ...createMutationResolver(),
2608
2461
  optionsName(node) {
2609
2462
  return `${this.name(node.operationId)}MutationOptions`;
2610
2463
  },
2611
- keyName(node) {
2612
- return `${this.name(node.operationId)}MutationKey`;
2613
- },
2614
2464
  typeName(node) {
2615
2465
  return capitalize(this.name(node.operationId));
2616
2466
  }
@@ -2677,43 +2527,17 @@ const pluginReactQuery = definePlugin((options) => {
2677
2527
  dependencies: [pluginTsName],
2678
2528
  hooks: { "kubb:plugin:setup"(ctx) {
2679
2529
  const resolver = userResolver ? Resolver.merge(resolverReactQuery, userResolver) : resolverReactQuery;
2680
- const resolvedClient = resolveClient({
2681
- client,
2682
- pluginNames: (ctx.config.plugins ?? []).map((p) => p.name).filter((name) => Boolean(name))
2683
- });
2684
- if (resolvedClient.kind === "error") throw new Error(resolvedClient.message);
2685
- const resolvedClientDescriptor = {
2686
- kind: "contract",
2687
- pluginName: resolvedClient.pluginName
2688
- };
2689
2530
  ctx.setOptions({
2690
2531
  output,
2691
- client: resolvedClientDescriptor,
2532
+ client: resolveContractClient({
2533
+ client,
2534
+ plugins: ctx.config.plugins
2535
+ }),
2692
2536
  queryKey,
2693
- query: query === false ? false : {
2694
- importPath: "@tanstack/react-query",
2695
- methods: ["GET"],
2696
- ...query
2697
- },
2537
+ query: resolveQueryConfig(query, { importPath: "@tanstack/react-query" }),
2698
2538
  mutationKey,
2699
- mutation: mutation === false ? false : {
2700
- importPath: "@tanstack/react-query",
2701
- methods: [
2702
- "POST",
2703
- "PUT",
2704
- "PATCH",
2705
- "DELETE"
2706
- ],
2707
- ...mutation
2708
- },
2709
- infinite: infinite ? {
2710
- queryParam: "id",
2711
- initialPageParam: 0,
2712
- cursorParam: null,
2713
- nextParam: null,
2714
- previousParam: null,
2715
- ...infinite
2716
- } : false,
2539
+ mutation: resolveMutationConfig(mutation, { importPath: "@tanstack/react-query" }),
2540
+ infinite: resolveInfiniteConfig(infinite),
2717
2541
  suspense,
2718
2542
  customOptions: customOptions ? {
2719
2543
  name: "useCustomHookOptions",
@@ -2733,6 +2557,6 @@ const pluginReactQuery = definePlugin((options) => {
2733
2557
  };
2734
2558
  });
2735
2559
  //#endregion
2736
- export { pluginReactQuery as default, pluginReactQuery, pluginReactQueryName };
2560
+ export { pluginReactQuery as default, pluginReactQuery, pluginReactQueryName, resolverReactQuery };
2737
2561
 
2738
2562
  //# sourceMappingURL=index.js.map