@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.cjs +115 -54
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +6 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +115 -54
- package/dist/index.js.map +1 -1
- package/docs/options.md +32 -0
- package/kubb-extension.json +1 -1
- package/package.json +9 -9
package/dist/index.cjs
CHANGED
|
@@ -112,12 +112,18 @@ function getPrimarySuccessContentType(node) {
|
|
|
112
112
|
return contentTypes[0].split(";")[0].trim().toLowerCase();
|
|
113
113
|
}
|
|
114
114
|
/**
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
|
|
115
|
+
* The `text/event-stream` content of the primary success response, when it is the only content type. A response that also
|
|
116
|
+
* declares another type stays a normal call with its query hooks.
|
|
117
|
+
*/
|
|
118
|
+
function getEventStreamContent(node) {
|
|
119
|
+
return getPrimarySuccessContentType(node) === "text/event-stream" ? getPrimarySuccessResponse(node)?.content?.[0] : void 0;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Whether an operation streams its primary success response as Server-Sent Events (`text/event-stream`). The client
|
|
123
|
+
* generator uses this to return a typed event stream instead of a one-shot `RequestResult`.
|
|
118
124
|
*/
|
|
119
125
|
function isEventStream(node) {
|
|
120
|
-
return
|
|
126
|
+
return getEventStreamContent(node) !== void 0;
|
|
121
127
|
}
|
|
122
128
|
const requestConfigBaseType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
|
|
123
129
|
function buildRequestConfigType(node) {
|
|
@@ -185,6 +191,22 @@ function buildOperationComments(node, options = {}) {
|
|
|
185
191
|
}
|
|
186
192
|
const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
187
193
|
/**
|
|
194
|
+
* An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter
|
|
195
|
+
* per property, typed and serialized like any other.
|
|
196
|
+
* Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.
|
|
197
|
+
*/
|
|
198
|
+
function spreadQuerystring(param) {
|
|
199
|
+
const schema = param.schema.type === "ref" ? param.schema.schema : param.schema;
|
|
200
|
+
const formEncoded = !param.contentType || param.contentType.split(";")[0].trim().toLowerCase() === "application/x-www-form-urlencoded";
|
|
201
|
+
if (schema?.type !== "object" || !formEncoded) return [param];
|
|
202
|
+
return schema.properties.map((property) => _kubb_kit.ast.factory.createParameter({
|
|
203
|
+
name: property.name,
|
|
204
|
+
in: "query",
|
|
205
|
+
schema: property.schema,
|
|
206
|
+
required: param.required && property.required
|
|
207
|
+
}));
|
|
208
|
+
}
|
|
209
|
+
/**
|
|
188
210
|
* Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
|
|
189
211
|
* group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
|
|
190
212
|
* (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
|
|
@@ -193,17 +215,18 @@ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
|
193
215
|
function getOperationParameters(node) {
|
|
194
216
|
const cached = operationParameterGroupsByNode.get(node);
|
|
195
217
|
if (cached) return cached;
|
|
196
|
-
const
|
|
218
|
+
const dedupe = (params) => {
|
|
197
219
|
const seen = /* @__PURE__ */ new Set();
|
|
198
|
-
return
|
|
199
|
-
if (
|
|
220
|
+
return params.filter((param) => {
|
|
221
|
+
if (seen.has(param.name)) return false;
|
|
200
222
|
seen.add(param.name);
|
|
201
223
|
return true;
|
|
202
224
|
});
|
|
203
225
|
};
|
|
226
|
+
const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
|
|
204
227
|
const groups = {
|
|
205
228
|
path: group("path"),
|
|
206
|
-
query: group("query"),
|
|
229
|
+
query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
|
|
207
230
|
header: group("header"),
|
|
208
231
|
cookie: group("cookie")
|
|
209
232
|
};
|
|
@@ -506,11 +529,11 @@ function createGroupConfig(group) {
|
|
|
506
529
|
}
|
|
507
530
|
// kubb-extension.json
|
|
508
531
|
var compatibility = {
|
|
509
|
-
"kubb": ">=5.
|
|
532
|
+
"kubb": ">=5.16.0",
|
|
510
533
|
"node": ">=22.22"
|
|
511
534
|
};
|
|
512
535
|
// package.json
|
|
513
|
-
var version = "5.9.
|
|
536
|
+
var version = "5.9.1";
|
|
514
537
|
// ../../internals/client/src/resolveOperationTypes.ts
|
|
515
538
|
/**
|
|
516
539
|
* A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
|
|
@@ -759,8 +782,16 @@ function resolveClientOperation(options) {
|
|
|
759
782
|
* `pluginZod({ inferred: 'codec' })`), banner and footer.
|
|
760
783
|
*/
|
|
761
784
|
function resolveHookFile(node, ctx, options) {
|
|
762
|
-
const { name, output, group, contractOp, keyTypeName, extraTypeNames = [] } = options;
|
|
785
|
+
const { name, output, group, contractOp, keyTypeName, extraTypeNames = [], returnType = "data" } = options;
|
|
763
786
|
const { config, root, resolver } = ctx;
|
|
787
|
+
if (returnType !== "data" && contractOp.returnType === "data") throw new _kubb_kit.Diagnostics.Error({
|
|
788
|
+
code: _kubb_kit.Diagnostics.code.invalidPluginOptions,
|
|
789
|
+
severity: "error",
|
|
790
|
+
message: `Option \`returnType\` is '${returnType}' for ${node.operationId}, but the client plugin has \`returnType: 'data'\` and only returns the response body.`,
|
|
791
|
+
help: "Set the client plugin's `returnType` to 'full', or set the hook plugin's `returnType` to 'data'.",
|
|
792
|
+
location: { kind: "config" },
|
|
793
|
+
plugin: resolver.pluginName
|
|
794
|
+
});
|
|
764
795
|
const types = resolveOperationTypes(ctx.driver, resolver.pluginName);
|
|
765
796
|
const tsResolver = types.resolver;
|
|
766
797
|
const file = resolver.file({
|
|
@@ -779,9 +810,10 @@ function resolveHookFile(node, ctx, options) {
|
|
|
779
810
|
});
|
|
780
811
|
const importedTypeNames = [
|
|
781
812
|
tsResolver.response.options(node),
|
|
813
|
+
tsResolver.response.responses(node),
|
|
782
814
|
...extraTypeNames,
|
|
783
815
|
...resolveOperationTypeNames(node, tsResolver, {
|
|
784
|
-
exclude: keyTypeName ?
|
|
816
|
+
exclude: [keyTypeName, returnType !== "data" ? tsResolver.response.response(node) : null].filter((name) => Boolean(name)),
|
|
785
817
|
order: "body-response-first",
|
|
786
818
|
includeParams: false
|
|
787
819
|
})
|
|
@@ -796,6 +828,7 @@ function resolveHookFile(node, ctx, options) {
|
|
|
796
828
|
tsResolver,
|
|
797
829
|
contractOp,
|
|
798
830
|
importedTypeNames,
|
|
831
|
+
returnType,
|
|
799
832
|
banner: resolver.default.banner(ctx.meta, {
|
|
800
833
|
output,
|
|
801
834
|
config,
|
|
@@ -826,7 +859,11 @@ function HookFile({ hook, imports, children }) {
|
|
|
826
859
|
path: contractOp.path
|
|
827
860
|
}),
|
|
828
861
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
829
|
-
name: [
|
|
862
|
+
name: [
|
|
863
|
+
"RequestConfig",
|
|
864
|
+
"ResponseErrorConfig",
|
|
865
|
+
"RequestResult"
|
|
866
|
+
],
|
|
830
867
|
root: contractOp.clientPathIsFile ? file.path : void 0,
|
|
831
868
|
path: contractOp.clientPath,
|
|
832
869
|
isTypeOnly: true
|
|
@@ -956,11 +993,12 @@ function buildClientCall(node, options) {
|
|
|
956
993
|
}
|
|
957
994
|
/**
|
|
958
995
|
* Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
|
|
959
|
-
* success body. `
|
|
996
|
+
* success body. `clientReturnType` mirrors the registered client plugin's own `returnType` option: with
|
|
960
997
|
* `'data'` the call already resolves to the bare body, so it is returned directly; with `'full'`
|
|
961
998
|
* (the default) the call carries `unwrap()`, so the body calls it instead of destructuring `data`
|
|
962
999
|
* off the full result by hand. With `'plain'` (plugin-client) the call resolves to the user's
|
|
963
|
-
* `RequestResult`, so the body awaits it and reads `data`.
|
|
1000
|
+
* `RequestResult`, so the body awaits it and reads `data`. With `returnType` `'full'` the body
|
|
1001
|
+
* resolves to the whole `RequestResult`; `resolveHookFile` rejects that for a client that already stripped it.
|
|
964
1002
|
*
|
|
965
1003
|
* @example
|
|
966
1004
|
* ```ts
|
|
@@ -969,22 +1007,24 @@ function buildClientCall(node, options) {
|
|
|
969
1007
|
* ```
|
|
970
1008
|
*/
|
|
971
1009
|
function buildCallResultBody(call, options = {}) {
|
|
972
|
-
const {
|
|
973
|
-
if (returnType === "data") return `return
|
|
974
|
-
if (
|
|
1010
|
+
const { clientReturnType = "full", returnType = "data" } = options;
|
|
1011
|
+
if (returnType !== "data" || clientReturnType === "data") return `return ${call}`;
|
|
1012
|
+
if (clientReturnType === "plain") return `return (await ${call}).data`;
|
|
975
1013
|
return `return ${call}.unwrap()`;
|
|
976
1014
|
}
|
|
977
1015
|
/**
|
|
978
1016
|
* Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
|
|
979
1017
|
* success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
|
|
1018
|
+
* With `returnType` `'full'`, `TData` is the client's `RequestResult` over the operation's responses record.
|
|
980
1019
|
*/
|
|
981
|
-
function buildResponseTypes(node, resolver) {
|
|
982
|
-
|
|
1020
|
+
function buildResponseTypes(node, resolver, options = {}) {
|
|
1021
|
+
const { returnType = "data" } = options;
|
|
1022
|
+
return resolver.memo(`responseTypes:${returnType}:${node.method}\0${node.path}`, () => {
|
|
983
1023
|
const successNames = resolveSuccessNames(node, resolver);
|
|
984
1024
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
985
1025
|
const errorNames = resolveErrorNames(node, resolver);
|
|
986
1026
|
return {
|
|
987
|
-
TData: responseName,
|
|
1027
|
+
TData: returnType !== "data" ? `RequestResult<${resolver.response.responses(node)}, true>` : responseName,
|
|
988
1028
|
TError: `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`
|
|
989
1029
|
};
|
|
990
1030
|
});
|
|
@@ -1213,8 +1253,9 @@ function buildResolvedRequestParams(node) {
|
|
|
1213
1253
|
// ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
|
|
1214
1254
|
const declarationPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1215
1255
|
const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1216
|
-
function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, returnType
|
|
1217
|
-
const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
|
|
1256
|
+
function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, clientReturnType, returnType }) {
|
|
1257
|
+
const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver, { returnType });
|
|
1258
|
+
const dataSuffix = returnType === "data" ? "" : ".data";
|
|
1218
1259
|
const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
|
|
1219
1260
|
resolver: tsResolver,
|
|
1220
1261
|
initialPageParam,
|
|
@@ -1236,21 +1277,24 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
|
|
|
1236
1277
|
clientName,
|
|
1237
1278
|
signal: true,
|
|
1238
1279
|
unwrapName
|
|
1239
|
-
}), {
|
|
1280
|
+
}), {
|
|
1281
|
+
clientReturnType,
|
|
1282
|
+
returnType
|
|
1283
|
+
});
|
|
1240
1284
|
const initialPageParamLiteral = typeof initialPageParam === "string" || typeof initialPageParam === "object" && initialPageParam !== null ? JSON.stringify(initialPageParam) : String(initialPageParam === void 0 ? 0 : initialPageParam);
|
|
1241
1285
|
const serializedGetNextPageParam = typeof getNextPageParam === "function" ? getNextPageParam.toString() : getNextPageParam;
|
|
1242
1286
|
const getNextPageParamExpr = (() => {
|
|
1243
1287
|
if (serializedGetNextPageParam) return `getNextPageParam: ${serializedGetNextPageParam}`;
|
|
1244
|
-
if (nextParam) return `getNextPageParam: (lastPage) => ${getNestedAccessor(nextParam,
|
|
1245
|
-
if (cursorParam) return `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
|
|
1246
|
-
return
|
|
1288
|
+
if (nextParam) return `getNextPageParam: (lastPage) => ${getNestedAccessor(nextParam, `lastPage${dataSuffix}`)}`;
|
|
1289
|
+
if (cursorParam) return `getNextPageParam: (lastPage) => lastPage${dataSuffix}['${cursorParam}']`;
|
|
1290
|
+
return `getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage${dataSuffix}) && lastPage${dataSuffix}.length === 0 ? undefined : lastPageParam + 1`;
|
|
1247
1291
|
})();
|
|
1248
1292
|
const serializedGetPreviousPageParam = typeof getPreviousPageParam === "function" ? getPreviousPageParam.toString() : getPreviousPageParam;
|
|
1249
1293
|
const defaultPreviousThreshold = hasExplicitInitialPageParam ? initialPageParamLiteral : "1";
|
|
1250
1294
|
const getPreviousPageParamExpr = (() => {
|
|
1251
1295
|
if (serializedGetPreviousPageParam) return `getPreviousPageParam: ${serializedGetPreviousPageParam}`;
|
|
1252
|
-
if (previousParam) return `getPreviousPageParam: (firstPage) => ${getNestedAccessor(previousParam,
|
|
1253
|
-
if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
|
|
1296
|
+
if (previousParam) return `getPreviousPageParam: (firstPage) => ${getNestedAccessor(previousParam, `firstPage${dataSuffix}`)}`;
|
|
1297
|
+
if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage${dataSuffix}['${cursorParam}']`;
|
|
1254
1298
|
if (serializedGetNextPageParam || nextParam) return null;
|
|
1255
1299
|
return `getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= ${defaultPreviousThreshold} ? undefined : firstPageParam - 1`;
|
|
1256
1300
|
})();
|
|
@@ -1690,7 +1734,7 @@ function buildHookTypes({ node, tsResolver, infinite, suspense, TData, TError, q
|
|
|
1690
1734
|
`TPageParam = ${pageParamType}`
|
|
1691
1735
|
],
|
|
1692
1736
|
observerOptionsType: `${observerOptionsName}<TQueryFnData, TError, TData, TQueryKey, TPageParam>`,
|
|
1693
|
-
|
|
1737
|
+
resultType: `${resultTypeName}<TData, TError> & { queryKey: TQueryKey }`
|
|
1694
1738
|
};
|
|
1695
1739
|
}
|
|
1696
1740
|
return {
|
|
@@ -1711,15 +1755,15 @@ function buildHookTypes({ node, tsResolver, infinite, suspense, TData, TError, q
|
|
|
1711
1755
|
"TQueryData",
|
|
1712
1756
|
"TQueryKey"
|
|
1713
1757
|
]).join(", ")}>`,
|
|
1714
|
-
|
|
1758
|
+
resultType: `${resultTypeName}<TData, ${TError}> & { queryKey: TQueryKey }`
|
|
1715
1759
|
};
|
|
1716
1760
|
}
|
|
1717
|
-
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions, suspense, infinite }) {
|
|
1718
|
-
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1761
|
+
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions, suspense, infinite, returnType }) {
|
|
1762
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
|
|
1719
1763
|
const prefix = suspense ? "UseSuspense" : "Use";
|
|
1720
1764
|
const hookName = `${suspense ? "useSuspense" : "use"}${infinite ? "InfiniteQuery" : "Query"}`;
|
|
1721
1765
|
const observerOptionsName = OBSERVER_OPTIONS_NAMES[infinite ? "infinite" : "plain"][suspense ? "suspense" : "standard"];
|
|
1722
|
-
const { generics, observerOptionsType,
|
|
1766
|
+
const { generics, observerOptionsType, resultType } = buildHookTypes({
|
|
1723
1767
|
node,
|
|
1724
1768
|
tsResolver,
|
|
1725
1769
|
infinite,
|
|
@@ -1763,7 +1807,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1763
1807
|
...${queryOptionsName}(${queryOptionsArgs}),${customOptions ? "\n ...customOptions," : ""}
|
|
1764
1808
|
...resolvedOptions,
|
|
1765
1809
|
queryKey,
|
|
1766
|
-
} as unknown as ${castType}, queryClient) as ${
|
|
1810
|
+
} as unknown as ${castType}, queryClient) as ${resultType}
|
|
1767
1811
|
|
|
1768
1812
|
queryResult.queryKey = queryKey as TQueryKey
|
|
1769
1813
|
|
|
@@ -1775,8 +1819,8 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1775
1819
|
// src/components/QueryOptions.tsx
|
|
1776
1820
|
const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1777
1821
|
const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1778
|
-
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, returnType
|
|
1779
|
-
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1822
|
+
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, clientReturnType, returnType }) {
|
|
1823
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
|
|
1780
1824
|
const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
|
|
1781
1825
|
const queryKeyParamsCall = callPrinter$2.print(queryKeyParamsNode) ?? "";
|
|
1782
1826
|
const paramsNode = buildQueryOptionsParams(node, { resolver: tsResolver });
|
|
@@ -1784,7 +1828,10 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, return
|
|
|
1784
1828
|
const queryFnBody = buildCallResultBody(buildClientCall(node, {
|
|
1785
1829
|
clientName,
|
|
1786
1830
|
signal: true
|
|
1787
|
-
}), {
|
|
1831
|
+
}), {
|
|
1832
|
+
clientReturnType,
|
|
1833
|
+
returnType
|
|
1834
|
+
});
|
|
1788
1835
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1789
1836
|
name,
|
|
1790
1837
|
isExportable: true,
|
|
@@ -1871,6 +1918,7 @@ function createQueryGenerator({ name, variant }) {
|
|
|
1871
1918
|
output,
|
|
1872
1919
|
group,
|
|
1873
1920
|
contractOp,
|
|
1921
|
+
returnType: ctx.options.returnType,
|
|
1874
1922
|
keyTypeName: queryKeyTypeName,
|
|
1875
1923
|
extraTypeNames: infiniteOptions ? [resolvePageParamType(node, {
|
|
1876
1924
|
resolver: tsResolver,
|
|
@@ -1917,7 +1965,8 @@ function createQueryGenerator({ name, variant }) {
|
|
|
1917
1965
|
initialPageParam: infiniteOptions.initialPageParam,
|
|
1918
1966
|
hasExplicitInitialPageParam: infiniteOptions.hasExplicitInitialPageParam,
|
|
1919
1967
|
queryParam: infiniteOptions.queryParam,
|
|
1920
|
-
|
|
1968
|
+
clientReturnType: contractOp.returnType,
|
|
1969
|
+
returnType: hook.returnType
|
|
1921
1970
|
})
|
|
1922
1971
|
] }) : /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
1923
1972
|
name: ["queryOptions"],
|
|
@@ -1928,7 +1977,8 @@ function createQueryGenerator({ name, variant }) {
|
|
|
1928
1977
|
queryKeyName,
|
|
1929
1978
|
node,
|
|
1930
1979
|
tsResolver: hook.tsResolver,
|
|
1931
|
-
|
|
1980
|
+
clientReturnType: contractOp.returnType,
|
|
1981
|
+
returnType: hook.returnType
|
|
1932
1982
|
})] }),
|
|
1933
1983
|
(variant !== "query" || query && hooks) && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
|
|
1934
1984
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
@@ -1952,6 +2002,7 @@ function createQueryGenerator({ name, variant }) {
|
|
|
1952
2002
|
node,
|
|
1953
2003
|
tsResolver: hook.tsResolver,
|
|
1954
2004
|
customOptions,
|
|
2005
|
+
returnType: hook.returnType,
|
|
1955
2006
|
suspense,
|
|
1956
2007
|
infinite: infiniteOptions ? {
|
|
1957
2008
|
initialPageParam: infiniteOptions.initialPageParam,
|
|
@@ -1986,8 +2037,8 @@ function buildMutationConfigParamsNode(node) {
|
|
|
1986
2037
|
default: "{}"
|
|
1987
2038
|
})] });
|
|
1988
2039
|
}
|
|
1989
|
-
function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName, returnType
|
|
1990
|
-
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
2040
|
+
function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName, clientReturnType, returnType }) {
|
|
2041
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
|
|
1991
2042
|
const configParamsNode = buildMutationConfigParamsNode(node);
|
|
1992
2043
|
const paramsSignature = declarationPrinter$1.print(configParamsNode) ?? "";
|
|
1993
2044
|
const groupedParam = buildGroupedRequestParam(node, {
|
|
@@ -2002,8 +2053,11 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName,
|
|
|
2002
2053
|
clientName,
|
|
2003
2054
|
signal: false,
|
|
2004
2055
|
withContentType: true,
|
|
2056
|
+
returnType: clientReturnType
|
|
2057
|
+
}), {
|
|
2058
|
+
clientReturnType,
|
|
2005
2059
|
returnType
|
|
2006
|
-
})
|
|
2060
|
+
});
|
|
2007
2061
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
2008
2062
|
name,
|
|
2009
2063
|
isExportable: true,
|
|
@@ -2029,8 +2083,8 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName,
|
|
|
2029
2083
|
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
2030
2084
|
const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
2031
2085
|
function buildMutationParamsNode(node, options) {
|
|
2032
|
-
const { resolver } = options;
|
|
2033
|
-
const { TData, TError } = buildResponseTypes(node, resolver);
|
|
2086
|
+
const { resolver, returnType } = options;
|
|
2087
|
+
const { TData, TError } = buildResponseTypes(node, resolver, { returnType });
|
|
2034
2088
|
return buildHookParams(node, {
|
|
2035
2089
|
resolver,
|
|
2036
2090
|
withRequest: false,
|
|
@@ -2045,18 +2099,21 @@ function buildMutationParamsNode(node, options) {
|
|
|
2045
2099
|
}`
|
|
2046
2100
|
});
|
|
2047
2101
|
}
|
|
2048
|
-
function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName, customOptions }) {
|
|
2049
|
-
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
2102
|
+
function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName, customOptions, returnType }) {
|
|
2103
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
|
|
2050
2104
|
const generics = [
|
|
2051
2105
|
TData,
|
|
2052
2106
|
TError,
|
|
2053
2107
|
resolveMutationRequestType(node, tsResolver),
|
|
2054
2108
|
"TContext"
|
|
2055
2109
|
].join(", ");
|
|
2056
|
-
const
|
|
2110
|
+
const resultType = `UseMutationResult<${generics}>`;
|
|
2057
2111
|
const mutationOptionsConfigNode = buildMutationConfigParamsNode(node);
|
|
2058
2112
|
const mutationOptionsParamsCall = callPrinter.print(mutationOptionsConfigNode) ?? "";
|
|
2059
|
-
const paramsNode = buildMutationParamsNode(node, {
|
|
2113
|
+
const paramsNode = buildMutationParamsNode(node, {
|
|
2114
|
+
resolver: tsResolver,
|
|
2115
|
+
returnType
|
|
2116
|
+
});
|
|
2060
2117
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
2061
2118
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
2062
2119
|
name,
|
|
@@ -2079,7 +2136,7 @@ function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName
|
|
|
2079
2136
|
...baseOptions,${customOptions ? "\n ...customOptions," : ""}
|
|
2080
2137
|
mutationKey,
|
|
2081
2138
|
...mutationOptions,
|
|
2082
|
-
}, queryClient) as ${
|
|
2139
|
+
}, queryClient) as ${resultType}
|
|
2083
2140
|
`
|
|
2084
2141
|
})
|
|
2085
2142
|
});
|
|
@@ -2123,7 +2180,8 @@ const mutationGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
2123
2180
|
name: mutationHookName,
|
|
2124
2181
|
output,
|
|
2125
2182
|
group,
|
|
2126
|
-
contractOp
|
|
2183
|
+
contractOp,
|
|
2184
|
+
returnType: ctx.options.returnType
|
|
2127
2185
|
});
|
|
2128
2186
|
const { tsResolver } = hook;
|
|
2129
2187
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(HookFile, {
|
|
@@ -2148,7 +2206,8 @@ const mutationGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
2148
2206
|
mutationKeyName,
|
|
2149
2207
|
node,
|
|
2150
2208
|
tsResolver,
|
|
2151
|
-
|
|
2209
|
+
clientReturnType: contractOp.returnType,
|
|
2210
|
+
returnType: hook.returnType
|
|
2152
2211
|
}),
|
|
2153
2212
|
mutation && hooks && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
|
|
2154
2213
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
@@ -2170,7 +2229,8 @@ const mutationGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
2170
2229
|
mutationKeyName,
|
|
2171
2230
|
node,
|
|
2172
2231
|
tsResolver,
|
|
2173
|
-
customOptions
|
|
2232
|
+
customOptions,
|
|
2233
|
+
returnType: hook.returnType
|
|
2174
2234
|
})
|
|
2175
2235
|
] })
|
|
2176
2236
|
]
|
|
@@ -2305,7 +2365,7 @@ const pluginReactQuery = (0, _kubb_kit.defineExtension)({
|
|
|
2305
2365
|
const { output = {
|
|
2306
2366
|
path: "hooks",
|
|
2307
2367
|
barrel: { type: "named" }
|
|
2308
|
-
}, group, exclude = [], include, override = [], suspense = false, infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, customOptions, hooks = false, client, resolver: userResolver, macros: userMacros } = options;
|
|
2368
|
+
}, 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;
|
|
2309
2369
|
const resolver = userResolver ? _kubb_kit.Resolver.merge(resolverReactQuery, userResolver) : resolverReactQuery;
|
|
2310
2370
|
(0, _kubb_kit.setResolver)(resolver);
|
|
2311
2371
|
if (userMacros?.length) (0, _kubb_kit.setMacros)(userMacros);
|
|
@@ -2317,6 +2377,7 @@ const pluginReactQuery = (0, _kubb_kit.defineExtension)({
|
|
|
2317
2377
|
client,
|
|
2318
2378
|
plugins: (0, _kubb_kit.useConfig)().plugins
|
|
2319
2379
|
}),
|
|
2380
|
+
returnType,
|
|
2320
2381
|
queryKey,
|
|
2321
2382
|
query: resolveQueryConfig(query, { importPath: "@tanstack/react-query" }),
|
|
2322
2383
|
mutationKey,
|