@kubb/plugin-vue-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 +113 -51
- 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 +113 -51
- 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
|
@@ -110,12 +110,18 @@ function getPrimarySuccessContentType(node) {
|
|
|
110
110
|
return contentTypes[0].split(";")[0].trim().toLowerCase();
|
|
111
111
|
}
|
|
112
112
|
/**
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
|
|
113
|
+
* The `text/event-stream` content of the primary success response, when it is the only content type. A response that also
|
|
114
|
+
* declares another type stays a normal call with its query hooks.
|
|
115
|
+
*/
|
|
116
|
+
function getEventStreamContent(node) {
|
|
117
|
+
return getPrimarySuccessContentType(node) === "text/event-stream" ? getPrimarySuccessResponse(node)?.content?.[0] : void 0;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Whether an operation streams its primary success response as Server-Sent Events (`text/event-stream`). The client
|
|
121
|
+
* generator uses this to return a typed event stream instead of a one-shot `RequestResult`.
|
|
116
122
|
*/
|
|
117
123
|
function isEventStream(node) {
|
|
118
|
-
return
|
|
124
|
+
return getEventStreamContent(node) !== void 0;
|
|
119
125
|
}
|
|
120
126
|
const requestConfigBaseType = `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`;
|
|
121
127
|
function buildRequestConfigType(node) {
|
|
@@ -183,6 +189,22 @@ function buildOperationComments(node, options = {}) {
|
|
|
183
189
|
}
|
|
184
190
|
const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
185
191
|
/**
|
|
192
|
+
* An OpenAPI 3.2 `querystring` parameter is the whole query string, so a form-encoded object becomes one query parameter
|
|
193
|
+
* per property, typed and serialized like any other.
|
|
194
|
+
* Another content type, such as JSON, stays one parameter named after it, and the runtime sends its value as the whole query string.
|
|
195
|
+
*/
|
|
196
|
+
function spreadQuerystring(param) {
|
|
197
|
+
const schema = param.schema.type === "ref" ? param.schema.schema : param.schema;
|
|
198
|
+
const formEncoded = !param.contentType || param.contentType.split(";")[0].trim().toLowerCase() === "application/x-www-form-urlencoded";
|
|
199
|
+
if (schema?.type !== "object" || !formEncoded) return [param];
|
|
200
|
+
return schema.properties.map((property) => _kubb_kit.ast.factory.createParameter({
|
|
201
|
+
name: property.name,
|
|
202
|
+
in: "query",
|
|
203
|
+
schema: property.schema,
|
|
204
|
+
required: param.required && property.required
|
|
205
|
+
}));
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
186
208
|
* Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
|
|
187
209
|
* group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
|
|
188
210
|
* (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
|
|
@@ -191,17 +213,18 @@ const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
|
191
213
|
function getOperationParameters(node) {
|
|
192
214
|
const cached = operationParameterGroupsByNode.get(node);
|
|
193
215
|
if (cached) return cached;
|
|
194
|
-
const
|
|
216
|
+
const dedupe = (params) => {
|
|
195
217
|
const seen = /* @__PURE__ */ new Set();
|
|
196
|
-
return
|
|
197
|
-
if (
|
|
218
|
+
return params.filter((param) => {
|
|
219
|
+
if (seen.has(param.name)) return false;
|
|
198
220
|
seen.add(param.name);
|
|
199
221
|
return true;
|
|
200
222
|
});
|
|
201
223
|
};
|
|
224
|
+
const group = (location) => dedupe(node.parameters.filter((param) => param.in === location));
|
|
202
225
|
const groups = {
|
|
203
226
|
path: group("path"),
|
|
204
|
-
query: group("query"),
|
|
227
|
+
query: dedupe([...group("query"), ...group("querystring").flatMap(spreadQuerystring)]),
|
|
205
228
|
header: group("header"),
|
|
206
229
|
cookie: group("cookie")
|
|
207
230
|
};
|
|
@@ -504,11 +527,11 @@ function createGroupConfig(group) {
|
|
|
504
527
|
}
|
|
505
528
|
// kubb-extension.json
|
|
506
529
|
var compatibility = {
|
|
507
|
-
"kubb": ">=5.
|
|
530
|
+
"kubb": ">=5.16.0",
|
|
508
531
|
"node": ">=22.22"
|
|
509
532
|
};
|
|
510
533
|
// package.json
|
|
511
|
-
var version = "5.9.
|
|
534
|
+
var version = "5.9.1";
|
|
512
535
|
// ../../internals/client/src/resolveOperationTypes.ts
|
|
513
536
|
/**
|
|
514
537
|
* A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
|
|
@@ -757,8 +780,16 @@ function resolveClientOperation(options) {
|
|
|
757
780
|
* `pluginZod({ inferred: 'codec' })`), banner and footer.
|
|
758
781
|
*/
|
|
759
782
|
function resolveHookFile(node, ctx, options) {
|
|
760
|
-
const { name, output, group, contractOp, keyTypeName, extraTypeNames = [] } = options;
|
|
783
|
+
const { name, output, group, contractOp, keyTypeName, extraTypeNames = [], returnType = "data" } = options;
|
|
761
784
|
const { config, root, resolver } = ctx;
|
|
785
|
+
if (returnType !== "data" && contractOp.returnType === "data") throw new _kubb_kit.Diagnostics.Error({
|
|
786
|
+
code: _kubb_kit.Diagnostics.code.invalidPluginOptions,
|
|
787
|
+
severity: "error",
|
|
788
|
+
message: `Option \`returnType\` is '${returnType}' for ${node.operationId}, but the client plugin has \`returnType: 'data'\` and only returns the response body.`,
|
|
789
|
+
help: "Set the client plugin's `returnType` to 'full', or set the hook plugin's `returnType` to 'data'.",
|
|
790
|
+
location: { kind: "config" },
|
|
791
|
+
plugin: resolver.pluginName
|
|
792
|
+
});
|
|
762
793
|
const types = resolveOperationTypes(ctx.driver, resolver.pluginName);
|
|
763
794
|
const tsResolver = types.resolver;
|
|
764
795
|
const file = resolver.file({
|
|
@@ -777,9 +808,10 @@ function resolveHookFile(node, ctx, options) {
|
|
|
777
808
|
});
|
|
778
809
|
const importedTypeNames = [
|
|
779
810
|
tsResolver.response.options(node),
|
|
811
|
+
tsResolver.response.responses(node),
|
|
780
812
|
...extraTypeNames,
|
|
781
813
|
...resolveOperationTypeNames(node, tsResolver, {
|
|
782
|
-
exclude: keyTypeName ?
|
|
814
|
+
exclude: [keyTypeName, returnType !== "data" ? tsResolver.response.response(node) : null].filter((name) => Boolean(name)),
|
|
783
815
|
order: "body-response-first",
|
|
784
816
|
includeParams: false
|
|
785
817
|
})
|
|
@@ -794,6 +826,7 @@ function resolveHookFile(node, ctx, options) {
|
|
|
794
826
|
tsResolver,
|
|
795
827
|
contractOp,
|
|
796
828
|
importedTypeNames,
|
|
829
|
+
returnType,
|
|
797
830
|
banner: resolver.default.banner(ctx.meta, {
|
|
798
831
|
output,
|
|
799
832
|
config,
|
|
@@ -824,7 +857,11 @@ function HookFile({ hook, imports, children }) {
|
|
|
824
857
|
path: contractOp.path
|
|
825
858
|
}),
|
|
826
859
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
827
|
-
name: [
|
|
860
|
+
name: [
|
|
861
|
+
"RequestConfig",
|
|
862
|
+
"ResponseErrorConfig",
|
|
863
|
+
"RequestResult"
|
|
864
|
+
],
|
|
828
865
|
root: contractOp.clientPathIsFile ? file.path : void 0,
|
|
829
866
|
path: contractOp.clientPath,
|
|
830
867
|
isTypeOnly: true
|
|
@@ -964,11 +1001,12 @@ function buildClientCall(node, options) {
|
|
|
964
1001
|
}
|
|
965
1002
|
/**
|
|
966
1003
|
* Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
|
|
967
|
-
* success body. `
|
|
1004
|
+
* success body. `clientReturnType` mirrors the registered client plugin's own `returnType` option: with
|
|
968
1005
|
* `'data'` the call already resolves to the bare body, so it is returned directly; with `'full'`
|
|
969
1006
|
* (the default) the call carries `unwrap()`, so the body calls it instead of destructuring `data`
|
|
970
1007
|
* off the full result by hand. With `'plain'` (plugin-client) the call resolves to the user's
|
|
971
|
-
* `RequestResult`, so the body awaits it and reads `data`.
|
|
1008
|
+
* `RequestResult`, so the body awaits it and reads `data`. With `returnType` `'full'` the body
|
|
1009
|
+
* resolves to the whole `RequestResult`; `resolveHookFile` rejects that for a client that already stripped it.
|
|
972
1010
|
*
|
|
973
1011
|
* @example
|
|
974
1012
|
* ```ts
|
|
@@ -977,22 +1015,24 @@ function buildClientCall(node, options) {
|
|
|
977
1015
|
* ```
|
|
978
1016
|
*/
|
|
979
1017
|
function buildCallResultBody(call, options = {}) {
|
|
980
|
-
const {
|
|
981
|
-
if (returnType === "data") return `return
|
|
982
|
-
if (
|
|
1018
|
+
const { clientReturnType = "full", returnType = "data" } = options;
|
|
1019
|
+
if (returnType !== "data" || clientReturnType === "data") return `return ${call}`;
|
|
1020
|
+
if (clientReturnType === "plain") return `return (await ${call}).data`;
|
|
983
1021
|
return `return ${call}.unwrap()`;
|
|
984
1022
|
}
|
|
985
1023
|
/**
|
|
986
1024
|
* Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
|
|
987
1025
|
* success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
|
|
1026
|
+
* With `returnType` `'full'`, `TData` is the client's `RequestResult` over the operation's responses record.
|
|
988
1027
|
*/
|
|
989
|
-
function buildResponseTypes(node, resolver) {
|
|
990
|
-
|
|
1028
|
+
function buildResponseTypes(node, resolver, options = {}) {
|
|
1029
|
+
const { returnType = "data" } = options;
|
|
1030
|
+
return resolver.memo(`responseTypes:${returnType}:${node.method}\0${node.path}`, () => {
|
|
991
1031
|
const successNames = resolveSuccessNames(node, resolver);
|
|
992
1032
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
993
1033
|
const errorNames = resolveErrorNames(node, resolver);
|
|
994
1034
|
return {
|
|
995
|
-
TData: responseName,
|
|
1035
|
+
TData: returnType !== "data" ? `RequestResult<${resolver.response.responses(node)}, true>` : responseName,
|
|
996
1036
|
TError: `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`
|
|
997
1037
|
};
|
|
998
1038
|
});
|
|
@@ -1177,8 +1217,9 @@ function resolveMutationRequestType(node, resolver) {
|
|
|
1177
1217
|
// ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
|
|
1178
1218
|
const declarationPrinter$5 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1179
1219
|
const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1180
|
-
function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, returnType
|
|
1181
|
-
const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
|
|
1220
|
+
function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, clientReturnType, returnType }) {
|
|
1221
|
+
const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver, { returnType });
|
|
1222
|
+
const dataSuffix = returnType === "data" ? "" : ".data";
|
|
1182
1223
|
const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
|
|
1183
1224
|
resolver: tsResolver,
|
|
1184
1225
|
initialPageParam,
|
|
@@ -1200,21 +1241,24 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
|
|
|
1200
1241
|
clientName,
|
|
1201
1242
|
signal: true,
|
|
1202
1243
|
unwrapName
|
|
1203
|
-
}), {
|
|
1244
|
+
}), {
|
|
1245
|
+
clientReturnType,
|
|
1246
|
+
returnType
|
|
1247
|
+
});
|
|
1204
1248
|
const initialPageParamLiteral = typeof initialPageParam === "string" || typeof initialPageParam === "object" && initialPageParam !== null ? JSON.stringify(initialPageParam) : String(initialPageParam === void 0 ? 0 : initialPageParam);
|
|
1205
1249
|
const serializedGetNextPageParam = typeof getNextPageParam === "function" ? getNextPageParam.toString() : getNextPageParam;
|
|
1206
1250
|
const getNextPageParamExpr = (() => {
|
|
1207
1251
|
if (serializedGetNextPageParam) return `getNextPageParam: ${serializedGetNextPageParam}`;
|
|
1208
|
-
if (nextParam) return `getNextPageParam: (lastPage) => ${getNestedAccessor(nextParam,
|
|
1209
|
-
if (cursorParam) return `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
|
|
1210
|
-
return
|
|
1252
|
+
if (nextParam) return `getNextPageParam: (lastPage) => ${getNestedAccessor(nextParam, `lastPage${dataSuffix}`)}`;
|
|
1253
|
+
if (cursorParam) return `getNextPageParam: (lastPage) => lastPage${dataSuffix}['${cursorParam}']`;
|
|
1254
|
+
return `getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage${dataSuffix}) && lastPage${dataSuffix}.length === 0 ? undefined : lastPageParam + 1`;
|
|
1211
1255
|
})();
|
|
1212
1256
|
const serializedGetPreviousPageParam = typeof getPreviousPageParam === "function" ? getPreviousPageParam.toString() : getPreviousPageParam;
|
|
1213
1257
|
const defaultPreviousThreshold = hasExplicitInitialPageParam ? initialPageParamLiteral : "1";
|
|
1214
1258
|
const getPreviousPageParamExpr = (() => {
|
|
1215
1259
|
if (serializedGetPreviousPageParam) return `getPreviousPageParam: ${serializedGetPreviousPageParam}`;
|
|
1216
|
-
if (previousParam) return `getPreviousPageParam: (firstPage) => ${getNestedAccessor(previousParam,
|
|
1217
|
-
if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
|
|
1260
|
+
if (previousParam) return `getPreviousPageParam: (firstPage) => ${getNestedAccessor(previousParam, `firstPage${dataSuffix}`)}`;
|
|
1261
|
+
if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage${dataSuffix}['${cursorParam}']`;
|
|
1218
1262
|
if (serializedGetNextPageParam || nextParam) return null;
|
|
1219
1263
|
return `getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= ${defaultPreviousThreshold} ? undefined : firstPageParam - 1`;
|
|
1220
1264
|
})();
|
|
@@ -1437,8 +1481,8 @@ function getQueryOptionsParams(node, options) {
|
|
|
1437
1481
|
memberTypeWrapper: maybeRefOrGetter
|
|
1438
1482
|
});
|
|
1439
1483
|
}
|
|
1440
|
-
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, returnType
|
|
1441
|
-
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1484
|
+
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, clientReturnType, returnType }) {
|
|
1485
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
|
|
1442
1486
|
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1443
1487
|
resolver: tsResolver,
|
|
1444
1488
|
memberTypeWrapper: maybeRefOrGetter
|
|
@@ -1450,7 +1494,10 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, return
|
|
|
1450
1494
|
clientName,
|
|
1451
1495
|
signal: true,
|
|
1452
1496
|
unwrapName: (name) => `toValue(${name})`
|
|
1453
|
-
}), {
|
|
1497
|
+
}), {
|
|
1498
|
+
clientReturnType,
|
|
1499
|
+
returnType
|
|
1500
|
+
});
|
|
1454
1501
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1455
1502
|
name,
|
|
1456
1503
|
isExportable: true,
|
|
@@ -1474,11 +1521,11 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, return
|
|
|
1474
1521
|
// src/components/Query.tsx
|
|
1475
1522
|
const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1476
1523
|
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1477
|
-
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, infinite }) {
|
|
1478
|
-
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1524
|
+
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, infinite, returnType }) {
|
|
1525
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
|
|
1479
1526
|
const optionsName = infinite ? "UseInfiniteQueryOptions" : "UseQueryOptions";
|
|
1480
1527
|
const hookName = infinite ? "useInfiniteQuery" : "useQuery";
|
|
1481
|
-
const
|
|
1528
|
+
const resultType = `${infinite ? "UseInfiniteQueryReturnType" : "UseQueryReturnType"}<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
|
|
1482
1529
|
const generics = [
|
|
1483
1530
|
infinite ? `TData = InfiniteData<${TData}>` : `TData = ${TData}`,
|
|
1484
1531
|
`TQueryData = ${TData}`,
|
|
@@ -1545,7 +1592,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1545
1592
|
...${queryOptionsName}(${queryOptionsParamsCall}),
|
|
1546
1593
|
...resolvedOptions,
|
|
1547
1594
|
queryKey
|
|
1548
|
-
} as unknown as ${optionsName}<${castGenerics.join(", ")}>, toValue(queryClient)) as ${
|
|
1595
|
+
} as unknown as ${optionsName}<${castGenerics.join(", ")}>, toValue(queryClient)) as ${resultType}
|
|
1549
1596
|
|
|
1550
1597
|
queryResult.queryKey = queryKey as TQueryKey
|
|
1551
1598
|
|
|
@@ -1603,6 +1650,7 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1603
1650
|
output,
|
|
1604
1651
|
group,
|
|
1605
1652
|
contractOp,
|
|
1653
|
+
returnType: ctx.options.returnType,
|
|
1606
1654
|
keyTypeName: queryKeyTypeName,
|
|
1607
1655
|
extraTypeNames: [resolvePageParamType(node, {
|
|
1608
1656
|
resolver: resolveOperationTypes(ctx.driver, ctx.resolver.pluginName).resolver,
|
|
@@ -1655,7 +1703,8 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1655
1703
|
initialPageParam: infiniteOptions.initialPageParam,
|
|
1656
1704
|
hasExplicitInitialPageParam: infiniteOptions.hasExplicitInitialPageParam,
|
|
1657
1705
|
queryParam: infiniteOptions.queryParam,
|
|
1658
|
-
|
|
1706
|
+
clientReturnType: contractOp.returnType,
|
|
1707
|
+
returnType: hook.returnType,
|
|
1659
1708
|
queryKeyType: "QueryKey",
|
|
1660
1709
|
memberTypeWrapper: maybeRefOrGetter,
|
|
1661
1710
|
unwrapName: (name) => `toValue(${name})`
|
|
@@ -1681,7 +1730,8 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1681
1730
|
queryKeyTypeName,
|
|
1682
1731
|
node,
|
|
1683
1732
|
tsResolver,
|
|
1684
|
-
infinite: true
|
|
1733
|
+
infinite: true,
|
|
1734
|
+
returnType: hook.returnType
|
|
1685
1735
|
})
|
|
1686
1736
|
]
|
|
1687
1737
|
});
|
|
@@ -1691,8 +1741,8 @@ const infiniteQueryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1691
1741
|
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1692
1742
|
const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1693
1743
|
function buildMutationParamsNode(node, options) {
|
|
1694
|
-
const { resolver } = options;
|
|
1695
|
-
const { TData, TError } = buildResponseTypes(node, resolver);
|
|
1744
|
+
const { resolver, returnType } = options;
|
|
1745
|
+
const { TData, TError } = buildResponseTypes(node, resolver, { returnType });
|
|
1696
1746
|
return buildHookParams(node, {
|
|
1697
1747
|
resolver,
|
|
1698
1748
|
withRequest: false,
|
|
@@ -1707,8 +1757,8 @@ function buildMutationParamsNode(node, options) {
|
|
|
1707
1757
|
}`
|
|
1708
1758
|
});
|
|
1709
1759
|
}
|
|
1710
|
-
function Mutation({ name, clientName, node, tsResolver, mutationKeyName, returnType
|
|
1711
|
-
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1760
|
+
function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientReturnType, returnType }) {
|
|
1761
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
|
|
1712
1762
|
const groupedParam = buildGroupedRequestParam(node, {
|
|
1713
1763
|
resolver: tsResolver,
|
|
1714
1764
|
withContentType: true
|
|
@@ -1721,16 +1771,22 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, returnT
|
|
|
1721
1771
|
clientName,
|
|
1722
1772
|
signal: false,
|
|
1723
1773
|
withContentType: true,
|
|
1724
|
-
returnType,
|
|
1774
|
+
returnType: clientReturnType,
|
|
1725
1775
|
unwrapName: (name) => `toValue<${TRequest}['${name}']>(${name})`
|
|
1726
|
-
}), {
|
|
1776
|
+
}), {
|
|
1777
|
+
clientReturnType,
|
|
1778
|
+
returnType
|
|
1779
|
+
});
|
|
1727
1780
|
const generics = [
|
|
1728
1781
|
TData,
|
|
1729
1782
|
TError,
|
|
1730
1783
|
TRequest,
|
|
1731
1784
|
"TContext"
|
|
1732
1785
|
].join(", ");
|
|
1733
|
-
const paramsNode = buildMutationParamsNode(node, {
|
|
1786
|
+
const paramsNode = buildMutationParamsNode(node, {
|
|
1787
|
+
resolver: tsResolver,
|
|
1788
|
+
returnType
|
|
1789
|
+
});
|
|
1734
1790
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
1735
1791
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Source, {
|
|
1736
1792
|
name,
|
|
@@ -1792,7 +1848,8 @@ const mutationGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1792
1848
|
name: mutationHookName,
|
|
1793
1849
|
output,
|
|
1794
1850
|
group,
|
|
1795
|
-
contractOp
|
|
1851
|
+
contractOp,
|
|
1852
|
+
returnType: ctx.options.returnType
|
|
1796
1853
|
});
|
|
1797
1854
|
const groups = getRequestGroups(node);
|
|
1798
1855
|
const hasRequestGroups = groups.path || groups.query || groups.body || groups.headers;
|
|
@@ -1826,7 +1883,8 @@ const mutationGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1826
1883
|
node,
|
|
1827
1884
|
tsResolver: hook.tsResolver,
|
|
1828
1885
|
mutationKeyName,
|
|
1829
|
-
|
|
1886
|
+
clientReturnType: contractOp.returnType,
|
|
1887
|
+
returnType: hook.returnType
|
|
1830
1888
|
})
|
|
1831
1889
|
] })]
|
|
1832
1890
|
});
|
|
@@ -1869,7 +1927,8 @@ const queryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1869
1927
|
output,
|
|
1870
1928
|
group,
|
|
1871
1929
|
contractOp,
|
|
1872
|
-
keyTypeName: queryKeyTypeName
|
|
1930
|
+
keyTypeName: queryKeyTypeName,
|
|
1931
|
+
returnType: ctx.options.returnType
|
|
1873
1932
|
});
|
|
1874
1933
|
const { tsResolver } = hook;
|
|
1875
1934
|
return /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(HookFile, {
|
|
@@ -1903,7 +1962,8 @@ const queryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1903
1962
|
queryKeyName,
|
|
1904
1963
|
node,
|
|
1905
1964
|
tsResolver,
|
|
1906
|
-
|
|
1965
|
+
clientReturnType: contractOp.returnType,
|
|
1966
|
+
returnType: hook.returnType
|
|
1907
1967
|
}),
|
|
1908
1968
|
query && hooks && /* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsxs)(_kubb_renderer_jsx_jsx_runtime.Fragment, { children: [
|
|
1909
1969
|
/* @__PURE__ */ (0, _kubb_renderer_jsx_jsx_runtime.jsx)(_kubb_renderer_jsx.File.Import, {
|
|
@@ -1926,7 +1986,8 @@ const queryGenerator = (0, _kubb_kit.defineGenerator)({
|
|
|
1926
1986
|
queryKeyName,
|
|
1927
1987
|
queryKeyTypeName,
|
|
1928
1988
|
node,
|
|
1929
|
-
tsResolver
|
|
1989
|
+
tsResolver,
|
|
1990
|
+
returnType: hook.returnType
|
|
1930
1991
|
})
|
|
1931
1992
|
] })
|
|
1932
1993
|
]
|
|
@@ -2001,7 +2062,7 @@ const pluginVueQuery = (0, _kubb_kit.defineExtension)({
|
|
|
2001
2062
|
const { output = {
|
|
2002
2063
|
path: "hooks",
|
|
2003
2064
|
barrel: { type: "named" }
|
|
2004
|
-
}, group, exclude = [], include, override = [], infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, hooks = false, client, resolver: userResolver, macros: userMacros } = options;
|
|
2065
|
+
}, group, exclude = [], include, override = [], infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, hooks = false, client, returnType = "data", resolver: userResolver, macros: userMacros } = options;
|
|
2005
2066
|
const resolver = userResolver ? _kubb_kit.Resolver.merge(resolverVueQuery, userResolver) : resolverVueQuery;
|
|
2006
2067
|
(0, _kubb_kit.setResolver)(resolver);
|
|
2007
2068
|
if (userMacros?.length) (0, _kubb_kit.setMacros)(userMacros);
|
|
@@ -2013,6 +2074,7 @@ const pluginVueQuery = (0, _kubb_kit.defineExtension)({
|
|
|
2013
2074
|
client,
|
|
2014
2075
|
plugins: (0, _kubb_kit.useConfig)().plugins
|
|
2015
2076
|
}),
|
|
2077
|
+
returnType,
|
|
2016
2078
|
queryKey,
|
|
2017
2079
|
query: resolveQueryConfig(query, { importPath: "@tanstack/vue-query" }),
|
|
2018
2080
|
mutationKey,
|