@kubb/plugin-react-query 5.9.0-canary.20261029T145027 → 5.9.1

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.d.cts CHANGED
@@ -415,6 +415,11 @@ type Options = OutputOptions & {
415
415
  * A client plugin must be registered. The hooks always call its `<op>`.
416
416
  */
417
417
  client?: ClientSelector;
418
+ /**
419
+ * Shape of the value the hooks resolve to: `'data'` is the success body, `'full'` the client's whole `RequestResult` so a hook can read response headers. `'full'` needs a client plugin whose own `returnType` is `'full'` or `'plain'`.
420
+ * @default 'data'
421
+ */
422
+ returnType?: 'data' | 'full';
418
423
  /**
419
424
  * Skip operations matching at least one entry in the list.
420
425
  */
@@ -502,6 +507,7 @@ type ResolvedOptions = {
502
507
  * The resolved contract client the generators import and call.
503
508
  */
504
509
  client: ResolvedClient;
510
+ returnType?: 'data' | 'full';
505
511
  /**
506
512
  * Resolved infinite query configuration, or `false` when infinite queries are disabled.
507
513
  */
package/dist/index.d.ts CHANGED
@@ -415,6 +415,11 @@ type Options = OutputOptions & {
415
415
  * A client plugin must be registered. The hooks always call its `<op>`.
416
416
  */
417
417
  client?: ClientSelector;
418
+ /**
419
+ * Shape of the value the hooks resolve to: `'data'` is the success body, `'full'` the client's whole `RequestResult` so a hook can read response headers. `'full'` needs a client plugin whose own `returnType` is `'full'` or `'plain'`.
420
+ * @default 'data'
421
+ */
422
+ returnType?: 'data' | 'full';
418
423
  /**
419
424
  * Skip operations matching at least one entry in the list.
420
425
  */
@@ -502,6 +507,7 @@ type ResolvedOptions = {
502
507
  * The resolved contract client the generators import and call.
503
508
  */
504
509
  client: ResolvedClient;
510
+ returnType?: 'data' | 'full';
505
511
  /**
506
512
  * Resolved infinite query configuration, or `false` when infinite queries are disabled.
507
513
  */
package/dist/index.js CHANGED
@@ -85,12 +85,18 @@ function getPrimarySuccessContentType(node) {
85
85
  return contentTypes[0].split(";")[0].trim().toLowerCase();
86
86
  }
87
87
  /**
88
- * Whether an operation streams its primary success response as Server-Sent Events
89
- * (`text/event-stream`). The client generator uses this to return a typed event stream instead of a
90
- * one-shot `RequestResult`.
88
+ * The `text/event-stream` content of the primary success response, when it is the only content type. A response that also
89
+ * declares another type stays a normal call with its query hooks.
90
+ */
91
+ function getEventStreamContent(node) {
92
+ return getPrimarySuccessContentType(node) === "text/event-stream" ? getPrimarySuccessResponse(node)?.content?.[0] : void 0;
93
+ }
94
+ /**
95
+ * Whether an operation streams its primary success response as Server-Sent Events (`text/event-stream`). The client
96
+ * generator uses this to return a typed event stream instead of a one-shot `RequestResult`.
91
97
  */
92
98
  function isEventStream(node) {
93
- return getPrimarySuccessContentType(node) === "text/event-stream";
99
+ return getEventStreamContent(node) !== void 0;
94
100
  }
95
101
  const requestConfigBaseType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
96
102
  function buildRequestConfigType(node) {
@@ -158,6 +164,22 @@ function buildOperationComments(node, options = {}) {
158
164
  }
159
165
  const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
160
166
  /**
167
+ * An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter
168
+ * per property, typed and serialized like any other.
169
+ * Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.
170
+ */
171
+ function spreadQuerystring(param) {
172
+ const schema = param.schema.type === "ref" ? param.schema.schema : param.schema;
173
+ const formEncoded = !param.contentType || param.contentType.split(";")[0].trim().toLowerCase() === "application/x-www-form-urlencoded";
174
+ if (schema?.type !== "object" || !formEncoded) return [param];
175
+ return schema.properties.map((property) => ast.factory.createParameter({
176
+ name: property.name,
177
+ in: "query",
178
+ schema: property.schema,
179
+ required: param.required && property.required
180
+ }));
181
+ }
182
+ /**
161
183
  * Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
162
184
  * group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
163
185
  * (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
@@ -166,17 +188,18 @@ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
166
188
  function getOperationParameters(node) {
167
189
  const cached = operationParameterGroupsByNode.get(node);
168
190
  if (cached) return cached;
169
- const group = (location) => {
191
+ const dedupe = (params) => {
170
192
  const seen = /* @__PURE__ */ new Set();
171
- return node.parameters.filter((param) => {
172
- if (param.in !== location || seen.has(param.name)) return false;
193
+ return params.filter((param) => {
194
+ if (seen.has(param.name)) return false;
173
195
  seen.add(param.name);
174
196
  return true;
175
197
  });
176
198
  };
199
+ const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
177
200
  const groups = {
178
201
  path: group("path"),
179
- query: group("query"),
202
+ query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
180
203
  header: group("header"),
181
204
  cookie: group("cookie")
182
205
  };
@@ -479,11 +502,11 @@ function createGroupConfig(group) {
479
502
  }
480
503
  // kubb-extension.json
481
504
  var compatibility = {
482
- "kubb": ">=5.14.6",
505
+ "kubb": ">=5.16.0",
483
506
  "node": ">=22.22"
484
507
  };
485
508
  // package.json
486
- var version = "5.9.0-canary.20261029T145027";
509
+ var version = "5.9.1";
487
510
  // ../../internals/client/src/resolveOperationTypes.ts
488
511
  /**
489
512
  * A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
@@ -732,8 +755,16 @@ function resolveClientOperation(options) {
732
755
  * `pluginZod({ inferred: 'codec' })`), banner and footer.
733
756
  */
734
757
  function resolveHookFile(node, ctx, options) {
735
- const { name, output, group, contractOp, keyTypeName, extraTypeNames = [] } = options;
758
+ const { name, output, group, contractOp, keyTypeName, extraTypeNames = [], returnType = "data" } = options;
736
759
  const { config, root, resolver } = ctx;
760
+ if (returnType !== "data" && contractOp.returnType === "data") throw new Diagnostics.Error({
761
+ code: Diagnostics.code.invalidPluginOptions,
762
+ severity: "error",
763
+ message: `Option \`returnType\` is '${returnType}' for ${node.operationId}, but the client plugin has \`returnType: 'data'\` and only returns the response body.`,
764
+ help: "Set the client plugin's `returnType` to 'full', or set the hook plugin's `returnType` to 'data'.",
765
+ location: { kind: "config" },
766
+ plugin: resolver.pluginName
767
+ });
737
768
  const types = resolveOperationTypes(ctx.driver, resolver.pluginName);
738
769
  const tsResolver = types.resolver;
739
770
  const file = resolver.file({
@@ -752,9 +783,10 @@ function resolveHookFile(node, ctx, options) {
752
783
  });
753
784
  const importedTypeNames = [
754
785
  tsResolver.response.options(node),
786
+ tsResolver.response.responses(node),
755
787
  ...extraTypeNames,
756
788
  ...resolveOperationTypeNames(node, tsResolver, {
757
- exclude: keyTypeName ? [keyTypeName] : void 0,
789
+ exclude: [keyTypeName, returnType !== "data" ? tsResolver.response.response(node) : null].filter((name) => Boolean(name)),
758
790
  order: "body-response-first",
759
791
  includeParams: false
760
792
  })
@@ -769,6 +801,7 @@ function resolveHookFile(node, ctx, options) {
769
801
  tsResolver,
770
802
  contractOp,
771
803
  importedTypeNames,
804
+ returnType,
772
805
  banner: resolver.default.banner(ctx.meta, {
773
806
  output,
774
807
  config,
@@ -799,7 +832,11 @@ function HookFile({ hook, imports, children }) {
799
832
  path: contractOp.path
800
833
  }),
801
834
  /* @__PURE__ */ jsx(File.Import, {
802
- name: ["RequestConfig", "ResponseErrorConfig"],
835
+ name: [
836
+ "RequestConfig",
837
+ "ResponseErrorConfig",
838
+ "RequestResult"
839
+ ],
803
840
  root: contractOp.clientPathIsFile ? file.path : void 0,
804
841
  path: contractOp.clientPath,
805
842
  isTypeOnly: true
@@ -929,11 +966,12 @@ function buildClientCall(node, options) {
929
966
  }
930
967
  /**
931
968
  * Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
932
- * success body. `returnType` mirrors the registered client plugin's own `returnType` option: with
969
+ * success body. `clientReturnType` mirrors the registered client plugin's own `returnType` option: with
933
970
  * `'data'` the call already resolves to the bare body, so it is returned directly; with `'full'`
934
971
  * (the default) the call carries `unwrap()`, so the body calls it instead of destructuring `data`
935
972
  * off the full result by hand. With `'plain'` (plugin-client) the call resolves to the user's
936
- * `RequestResult`, so the body awaits it and reads `data`.
973
+ * `RequestResult`, so the body awaits it and reads `data`. With `returnType` `'full'` the body
974
+ * resolves to the whole `RequestResult`; `resolveHookFile` rejects that for a client that already stripped it.
937
975
  *
938
976
  * @example
939
977
  * ```ts
@@ -942,22 +980,24 @@ function buildClientCall(node, options) {
942
980
  * ```
943
981
  */
944
982
  function buildCallResultBody(call, options = {}) {
945
- const { returnType = "full" } = options;
946
- if (returnType === "data") return `return await ${call}`;
947
- if (returnType === "plain") return `return (await ${call}).data`;
983
+ const { clientReturnType = "full", returnType = "data" } = options;
984
+ if (returnType !== "data" || clientReturnType === "data") return `return ${call}`;
985
+ if (clientReturnType === "plain") return `return (await ${call}).data`;
948
986
  return `return ${call}.unwrap()`;
949
987
  }
950
988
  /**
951
989
  * Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
952
990
  * success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
991
+ * With `returnType` `'full'`, `TData` is the client's `RequestResult` over the operation's responses record.
953
992
  */
954
- function buildResponseTypes(node, resolver) {
955
- return resolver.memo(`responseTypes:${node.method}\0${node.path}`, () => {
993
+ function buildResponseTypes(node, resolver, options = {}) {
994
+ const { returnType = "data" } = options;
995
+ return resolver.memo(`responseTypes:${returnType}:${node.method}\0${node.path}`, () => {
956
996
  const successNames = resolveSuccessNames(node, resolver);
957
997
  const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
958
998
  const errorNames = resolveErrorNames(node, resolver);
959
999
  return {
960
- TData: responseName,
1000
+ TData: returnType !== "data" ? `RequestResult<${resolver.response.responses(node)}, true>` : responseName,
961
1001
  TError: `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`
962
1002
  };
963
1003
  });
@@ -1186,8 +1226,9 @@ function buildResolvedRequestParams(node) {
1186
1226
  // ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
1187
1227
  const declarationPrinter$6 = functionPrinter({ mode: "declaration" });
1188
1228
  const callPrinter$3 = functionPrinter({ mode: "call" });
1189
- function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, returnType = "full" }) {
1190
- const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
1229
+ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, clientReturnType, returnType }) {
1230
+ const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver, { returnType });
1231
+ const dataSuffix = returnType === "data" ? "" : ".data";
1191
1232
  const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
1192
1233
  resolver: tsResolver,
1193
1234
  initialPageParam,
@@ -1209,21 +1250,24 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
1209
1250
  clientName,
1210
1251
  signal: true,
1211
1252
  unwrapName
1212
- }), { returnType });
1253
+ }), {
1254
+ clientReturnType,
1255
+ returnType
1256
+ });
1213
1257
  const initialPageParamLiteral = typeof initialPageParam === "string" || typeof initialPageParam === "object" && initialPageParam !== null ? JSON.stringify(initialPageParam) : String(initialPageParam === void 0 ? 0 : initialPageParam);
1214
1258
  const serializedGetNextPageParam = typeof getNextPageParam === "function" ? getNextPageParam.toString() : getNextPageParam;
1215
1259
  const getNextPageParamExpr = (() => {
1216
1260
  if (serializedGetNextPageParam) return `getNextPageParam: ${serializedGetNextPageParam}`;
1217
- if (nextParam) return `getNextPageParam: (lastPage) => ${getNestedAccessor(nextParam, "lastPage")}`;
1218
- if (cursorParam) return `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
1219
- return "getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage) && lastPage.length === 0 ? undefined : lastPageParam + 1";
1261
+ if (nextParam) return `getNextPageParam: (lastPage) => ${getNestedAccessor(nextParam, `lastPage${dataSuffix}`)}`;
1262
+ if (cursorParam) return `getNextPageParam: (lastPage) => lastPage${dataSuffix}['${cursorParam}']`;
1263
+ return `getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage${dataSuffix}) && lastPage${dataSuffix}.length === 0 ? undefined : lastPageParam + 1`;
1220
1264
  })();
1221
1265
  const serializedGetPreviousPageParam = typeof getPreviousPageParam === "function" ? getPreviousPageParam.toString() : getPreviousPageParam;
1222
1266
  const defaultPreviousThreshold = hasExplicitInitialPageParam ? initialPageParamLiteral : "1";
1223
1267
  const getPreviousPageParamExpr = (() => {
1224
1268
  if (serializedGetPreviousPageParam) return `getPreviousPageParam: ${serializedGetPreviousPageParam}`;
1225
- if (previousParam) return `getPreviousPageParam: (firstPage) => ${getNestedAccessor(previousParam, "firstPage")}`;
1226
- if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
1269
+ if (previousParam) return `getPreviousPageParam: (firstPage) => ${getNestedAccessor(previousParam, `firstPage${dataSuffix}`)}`;
1270
+ if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage${dataSuffix}['${cursorParam}']`;
1227
1271
  if (serializedGetNextPageParam || nextParam) return null;
1228
1272
  return `getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= ${defaultPreviousThreshold} ? undefined : firstPageParam - 1`;
1229
1273
  })();
@@ -1663,7 +1707,7 @@ function buildHookTypes({ node, tsResolver, infinite, suspense, TData, TError, q
1663
1707
  `TPageParam = ${pageParamType}`
1664
1708
  ],
1665
1709
  observerOptionsType: `${observerOptionsName}<TQueryFnData, TError, TData, TQueryKey, TPageParam>`,
1666
- returnType: `${resultTypeName}<TData, TError> & { queryKey: TQueryKey }`
1710
+ resultType: `${resultTypeName}<TData, TError> & { queryKey: TQueryKey }`
1667
1711
  };
1668
1712
  }
1669
1713
  return {
@@ -1684,15 +1728,15 @@ function buildHookTypes({ node, tsResolver, infinite, suspense, TData, TError, q
1684
1728
  "TQueryData",
1685
1729
  "TQueryKey"
1686
1730
  ]).join(", ")}>`,
1687
- returnType: `${resultTypeName}<TData, ${TError}> & { queryKey: TQueryKey }`
1731
+ resultType: `${resultTypeName}<TData, ${TError}> & { queryKey: TQueryKey }`
1688
1732
  };
1689
1733
  }
1690
- function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions, suspense, infinite }) {
1691
- const { TData, TError } = buildResponseTypes(node, tsResolver);
1734
+ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions, suspense, infinite, returnType }) {
1735
+ const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
1692
1736
  const prefix = suspense ? "UseSuspense" : "Use";
1693
1737
  const hookName = `${suspense ? "useSuspense" : "use"}${infinite ? "InfiniteQuery" : "Query"}`;
1694
1738
  const observerOptionsName = OBSERVER_OPTIONS_NAMES[infinite ? "infinite" : "plain"][suspense ? "suspense" : "standard"];
1695
- const { generics, observerOptionsType, returnType } = buildHookTypes({
1739
+ const { generics, observerOptionsType, resultType } = buildHookTypes({
1696
1740
  node,
1697
1741
  tsResolver,
1698
1742
  infinite,
@@ -1736,7 +1780,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1736
1780
  ...${queryOptionsName}(${queryOptionsArgs}),${customOptions ? "\n ...customOptions," : ""}
1737
1781
  ...resolvedOptions,
1738
1782
  queryKey,
1739
- } as unknown as ${castType}, queryClient) as ${returnType}
1783
+ } as unknown as ${castType}, queryClient) as ${resultType}
1740
1784
 
1741
1785
  queryResult.queryKey = queryKey as TQueryKey
1742
1786
 
@@ -1748,8 +1792,8 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
1748
1792
  // src/components/QueryOptions.tsx
1749
1793
  const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
1750
1794
  const callPrinter$2 = functionPrinter({ mode: "call" });
1751
- function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, returnType = "full" }) {
1752
- const { TData, TError } = buildResponseTypes(node, tsResolver);
1795
+ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, clientReturnType, returnType }) {
1796
+ const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
1753
1797
  const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
1754
1798
  const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
1755
1799
  const paramsNode = buildQueryOptionsParams(node, { resolver: tsResolver });
@@ -1757,7 +1801,10 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, return
1757
1801
  const queryFnBody = buildCallResultBody(buildClientCall(node, {
1758
1802
  clientName,
1759
1803
  signal: true
1760
- }), { returnType });
1804
+ }), {
1805
+ clientReturnType,
1806
+ returnType
1807
+ });
1761
1808
  return /* @__PURE__ */ jsx(File.Source, {
1762
1809
  name,
1763
1810
  isExportable: true,
@@ -1844,6 +1891,7 @@ function createQueryGenerator({ name, variant }) {
1844
1891
  output,
1845
1892
  group,
1846
1893
  contractOp,
1894
+ returnType: ctx.options.returnType,
1847
1895
  keyTypeName: queryKeyTypeName,
1848
1896
  extraTypeNames: infiniteOptions ? [resolvePageParamType(node, {
1849
1897
  resolver: tsResolver,
@@ -1890,7 +1938,8 @@ function createQueryGenerator({ name, variant }) {
1890
1938
  initialPageParam: infiniteOptions.initialPageParam,
1891
1939
  hasExplicitInitialPageParam: infiniteOptions.hasExplicitInitialPageParam,
1892
1940
  queryParam: infiniteOptions.queryParam,
1893
- returnType: contractOp.returnType
1941
+ clientReturnType: contractOp.returnType,
1942
+ returnType: hook.returnType
1894
1943
  })
1895
1944
  ] }) : /* @__PURE__ */ jsxs(Fragment, { children: [/* @__PURE__ */ jsx(File.Import, {
1896
1945
  name: ["queryOptions"],
@@ -1901,7 +1950,8 @@ function createQueryGenerator({ name, variant }) {
1901
1950
  queryKeyName,
1902
1951
  node,
1903
1952
  tsResolver: hook.tsResolver,
1904
- returnType: contractOp.returnType
1953
+ clientReturnType: contractOp.returnType,
1954
+ returnType: hook.returnType
1905
1955
  })] }),
1906
1956
  (variant !== "query" || query && hooks) && /* @__PURE__ */ jsxs(Fragment, { children: [
1907
1957
  /* @__PURE__ */ jsx(File.Import, {
@@ -1925,6 +1975,7 @@ function createQueryGenerator({ name, variant }) {
1925
1975
  node,
1926
1976
  tsResolver: hook.tsResolver,
1927
1977
  customOptions,
1978
+ returnType: hook.returnType,
1928
1979
  suspense,
1929
1980
  infinite: infiniteOptions ? {
1930
1981
  initialPageParam: infiniteOptions.initialPageParam,
@@ -1959,8 +2010,8 @@ function buildMutationConfigParamsNode(node) {
1959
2010
  default: "{}"
1960
2011
  })] });
1961
2012
  }
1962
- function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName, returnType = "full" }) {
1963
- const { TData, TError } = buildResponseTypes(node, tsResolver);
2013
+ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName, clientReturnType, returnType }) {
2014
+ const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
1964
2015
  const configParamsNode = buildMutationConfigParamsNode(node);
1965
2016
  const paramsSignature = declarationPrinter$1.print(configParamsNode) ?? "";
1966
2017
  const groupedParam = buildGroupedRequestParam(node, {
@@ -1975,8 +2026,11 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName,
1975
2026
  clientName,
1976
2027
  signal: false,
1977
2028
  withContentType: true,
2029
+ returnType: clientReturnType
2030
+ }), {
2031
+ clientReturnType,
1978
2032
  returnType
1979
- }), { returnType });
2033
+ });
1980
2034
  return /* @__PURE__ */ jsx(File.Source, {
1981
2035
  name,
1982
2036
  isExportable: true,
@@ -2002,8 +2056,8 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName,
2002
2056
  const declarationPrinter = functionPrinter({ mode: "declaration" });
2003
2057
  const callPrinter = functionPrinter({ mode: "call" });
2004
2058
  function buildMutationParamsNode(node, options) {
2005
- const { resolver } = options;
2006
- const { TData, TError } = buildResponseTypes(node, resolver);
2059
+ const { resolver, returnType } = options;
2060
+ const { TData, TError } = buildResponseTypes(node, resolver, { returnType });
2007
2061
  return buildHookParams(node, {
2008
2062
  resolver,
2009
2063
  withRequest: false,
@@ -2018,18 +2072,21 @@ function buildMutationParamsNode(node, options) {
2018
2072
  }`
2019
2073
  });
2020
2074
  }
2021
- function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName, customOptions }) {
2022
- const { TData, TError } = buildResponseTypes(node, tsResolver);
2075
+ function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName, customOptions, returnType }) {
2076
+ const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
2023
2077
  const generics = [
2024
2078
  TData,
2025
2079
  TError,
2026
2080
  resolveMutationRequestType(node, tsResolver),
2027
2081
  "TContext"
2028
2082
  ].join(", ");
2029
- const returnType = `UseMutationResult<${generics}>`;
2083
+ const resultType = `UseMutationResult<${generics}>`;
2030
2084
  const mutationOptionsConfigNode = buildMutationConfigParamsNode(node);
2031
2085
  const mutationOptionsParamsCall = callPrinter.print(mutationOptionsConfigNode) ?? "";
2032
- const paramsNode = buildMutationParamsNode(node, { resolver: tsResolver });
2086
+ const paramsNode = buildMutationParamsNode(node, {
2087
+ resolver: tsResolver,
2088
+ returnType
2089
+ });
2033
2090
  const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
2034
2091
  return /* @__PURE__ */ jsx(File.Source, {
2035
2092
  name,
@@ -2052,7 +2109,7 @@ function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName
2052
2109
  ...baseOptions,${customOptions ? "\n ...customOptions," : ""}
2053
2110
  mutationKey,
2054
2111
  ...mutationOptions,
2055
- }, queryClient) as ${returnType}
2112
+ }, queryClient) as ${resultType}
2056
2113
  `
2057
2114
  })
2058
2115
  });
@@ -2096,7 +2153,8 @@ const mutationGenerator = defineGenerator({
2096
2153
  name: mutationHookName,
2097
2154
  output,
2098
2155
  group,
2099
- contractOp
2156
+ contractOp,
2157
+ returnType: ctx.options.returnType
2100
2158
  });
2101
2159
  const { tsResolver } = hook;
2102
2160
  return /* @__PURE__ */ jsxs(HookFile, {
@@ -2121,7 +2179,8 @@ const mutationGenerator = defineGenerator({
2121
2179
  mutationKeyName,
2122
2180
  node,
2123
2181
  tsResolver,
2124
- returnType: contractOp.returnType
2182
+ clientReturnType: contractOp.returnType,
2183
+ returnType: hook.returnType
2125
2184
  }),
2126
2185
  mutation && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [
2127
2186
  /* @__PURE__ */ jsx(File.Import, {
@@ -2143,7 +2202,8 @@ const mutationGenerator = defineGenerator({
2143
2202
  mutationKeyName,
2144
2203
  node,
2145
2204
  tsResolver,
2146
- customOptions
2205
+ customOptions,
2206
+ returnType: hook.returnType
2147
2207
  })
2148
2208
  ] })
2149
2209
  ]
@@ -2278,7 +2338,7 @@ const pluginReactQuery = defineExtension({
2278
2338
  const { output = {
2279
2339
  path: "hooks",
2280
2340
  barrel: { type: "named" }
2281
- }, group, exclude = [], include, override = [], suspense = false, infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, customOptions, hooks = false, client, resolver: userResolver, macros: userMacros } = options;
2341
+ }, group, exclude = [], include, override = [], suspense = false, infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, customOptions, hooks = false, client, returnType = "data", resolver: userResolver, macros: userMacros } = options;
2282
2342
  const resolver = userResolver ? Resolver.merge(resolverReactQuery, userResolver) : resolverReactQuery;
2283
2343
  setResolver(resolver);
2284
2344
  if (userMacros?.length) setMacros(userMacros);
@@ -2290,6 +2350,7 @@ const pluginReactQuery = defineExtension({
2290
2350
  client,
2291
2351
  plugins: useConfig().plugins
2292
2352
  }),
2353
+ returnType,
2293
2354
  queryKey,
2294
2355
  query: resolveQueryConfig(query, { importPath: "@tanstack/react-query" }),
2295
2356
  mutationKey,