@kubb/plugin-vue-query 5.9.0-canary.20261029T142044 → 5.9.0
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 +93 -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 +93 -54
- package/dist/index.js.map +1 -1
- package/docs/options.md +32 -0
- package/package.json +8 -8
package/dist/index.d.cts
CHANGED
|
@@ -315,6 +315,11 @@ type Options = OutputOptions & {
|
|
|
315
315
|
* A client plugin must be registered. The composables always call its `<op>`.
|
|
316
316
|
*/
|
|
317
317
|
client?: ClientSelector;
|
|
318
|
+
/**
|
|
319
|
+
* 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'`.
|
|
320
|
+
* @default 'data'
|
|
321
|
+
*/
|
|
322
|
+
returnType?: 'data' | 'full';
|
|
318
323
|
/**
|
|
319
324
|
* Skip operations matching at least one entry in the list.
|
|
320
325
|
*/
|
|
@@ -382,6 +387,7 @@ type ResolvedOptions = {
|
|
|
382
387
|
* The resolved contract client the generators import and call.
|
|
383
388
|
*/
|
|
384
389
|
client: ResolvedClient;
|
|
390
|
+
returnType?: 'data' | 'full';
|
|
385
391
|
/**
|
|
386
392
|
* Resolved infinite query configuration, or `false` when infinite queries are disabled.
|
|
387
393
|
*/
|
package/dist/index.d.ts
CHANGED
|
@@ -315,6 +315,11 @@ type Options = OutputOptions & {
|
|
|
315
315
|
* A client plugin must be registered. The composables always call its `<op>`.
|
|
316
316
|
*/
|
|
317
317
|
client?: ClientSelector;
|
|
318
|
+
/**
|
|
319
|
+
* 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'`.
|
|
320
|
+
* @default 'data'
|
|
321
|
+
*/
|
|
322
|
+
returnType?: 'data' | 'full';
|
|
318
323
|
/**
|
|
319
324
|
* Skip operations matching at least one entry in the list.
|
|
320
325
|
*/
|
|
@@ -382,6 +387,7 @@ type ResolvedOptions = {
|
|
|
382
387
|
* The resolved contract client the generators import and call.
|
|
383
388
|
*/
|
|
384
389
|
client: ResolvedClient;
|
|
390
|
+
returnType?: 'data' | 'full';
|
|
385
391
|
/**
|
|
386
392
|
* Resolved infinite query configuration, or `false` when infinite queries are disabled.
|
|
387
393
|
*/
|
package/dist/index.js
CHANGED
|
@@ -25,19 +25,19 @@ function operationFileEntry(node, name, extname = ".ts") {
|
|
|
25
25
|
};
|
|
26
26
|
}
|
|
27
27
|
/**
|
|
28
|
-
* Resolves a dependency plugin's generated file for `node.operationId`, cached in `
|
|
29
|
-
*
|
|
28
|
+
* Resolves a dependency plugin's generated file for `node.operationId`, cached in `memo` (the
|
|
29
|
+
* build's `ctx.memo`) under the resolver's own plugin name and the operation. Several dependents reading the
|
|
30
30
|
* same dependency for the same operation in one pass (a query plugin's several hook generators, the
|
|
31
31
|
* MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.
|
|
32
32
|
*
|
|
33
33
|
* @example Cache `plugin-ts`'s file for the current operation
|
|
34
34
|
* ```ts
|
|
35
|
-
* const fileTs = resolveDependencyOperationFile({
|
|
35
|
+
* const fileTs = resolveDependencyOperationFile({ memo: ctx.memo, node, resolver: tsResolver, root, output })
|
|
36
36
|
* ```
|
|
37
37
|
*/
|
|
38
38
|
function resolveDependencyOperationFile(options) {
|
|
39
|
-
const {
|
|
40
|
-
return
|
|
39
|
+
const { memo, node, resolver, root, output, group } = options;
|
|
40
|
+
return memo(`${resolver.pluginName}:operationFile:${node.operationId}`, () => resolver.file({
|
|
41
41
|
...operationFileEntry(node, node.operationId),
|
|
42
42
|
root,
|
|
43
43
|
output,
|
|
@@ -482,7 +482,7 @@ var compatibility = {
|
|
|
482
482
|
"node": ">=22.22"
|
|
483
483
|
};
|
|
484
484
|
// package.json
|
|
485
|
-
var version = "5.9.0
|
|
485
|
+
var version = "5.9.0";
|
|
486
486
|
// ../../internals/client/src/resolveOperationTypes.ts
|
|
487
487
|
/**
|
|
488
488
|
* A `plugin-ts` shaped resolver whose operation type names point at the types `pluginZod({ inferred })`
|
|
@@ -679,7 +679,7 @@ function resolveImportPath(options) {
|
|
|
679
679
|
* output root, the same path consumers read `RequestConfig` / `ResponseErrorConfig` from.
|
|
680
680
|
* With plugin-client they come from the user's `importPath` module instead.
|
|
681
681
|
*
|
|
682
|
-
* The result is cached in the
|
|
682
|
+
* The result is cached in `memo` (the build's `ctx.memo`) under the client plugin's name and the operation,
|
|
683
683
|
* so several dependents reading the same client plugin for one operation in a single pass
|
|
684
684
|
* (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
|
|
685
685
|
* one computed result instead of each re-deriving the name and path.
|
|
@@ -689,9 +689,9 @@ function resolveImportPath(options) {
|
|
|
689
689
|
* and import path therefore match the `<op>` actually emitted, even when an `override` changes it.
|
|
690
690
|
*/
|
|
691
691
|
function resolveClientOperation(options) {
|
|
692
|
-
const { clientPlugin, driver, node, root, output,
|
|
692
|
+
const { clientPlugin, driver, node, root, output, memo } = options;
|
|
693
693
|
if (!clientPlugin) return null;
|
|
694
|
-
return
|
|
694
|
+
return memo(`${clientPlugin.pluginName}:clientOperation:${node.operationId}`, () => {
|
|
695
695
|
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
696
696
|
const pluginOptions = driver.getPlugin(clientPlugin.pluginName)?.options ?? {};
|
|
697
697
|
const { exclude, include, override } = pluginOptions;
|
|
@@ -731,8 +731,16 @@ function resolveClientOperation(options) {
|
|
|
731
731
|
* `pluginZod({ inferred: 'codec' })`), banner and footer.
|
|
732
732
|
*/
|
|
733
733
|
function resolveHookFile(node, ctx, options) {
|
|
734
|
-
const { name, output, group, contractOp, keyTypeName, extraTypeNames = [] } = options;
|
|
734
|
+
const { name, output, group, contractOp, keyTypeName, extraTypeNames = [], returnType = "data" } = options;
|
|
735
735
|
const { config, root, resolver } = ctx;
|
|
736
|
+
if (returnType !== "data" && contractOp.returnType === "data") throw new Diagnostics.Error({
|
|
737
|
+
code: Diagnostics.code.invalidPluginOptions,
|
|
738
|
+
severity: "error",
|
|
739
|
+
message: `Option \`returnType\` is '${returnType}' for ${node.operationId}, but the client plugin has \`returnType: 'data'\` and only returns the response body.`,
|
|
740
|
+
help: "Set the client plugin's `returnType` to 'full', or set the hook plugin's `returnType` to 'data'.",
|
|
741
|
+
location: { kind: "config" },
|
|
742
|
+
plugin: resolver.pluginName
|
|
743
|
+
});
|
|
736
744
|
const types = resolveOperationTypes(ctx.driver, resolver.pluginName);
|
|
737
745
|
const tsResolver = types.resolver;
|
|
738
746
|
const file = resolver.file({
|
|
@@ -742,7 +750,7 @@ function resolveHookFile(node, ctx, options) {
|
|
|
742
750
|
group: group ?? void 0
|
|
743
751
|
});
|
|
744
752
|
const fileTs = resolveDependencyOperationFile({
|
|
745
|
-
|
|
753
|
+
memo: ctx.memo,
|
|
746
754
|
node,
|
|
747
755
|
resolver: tsResolver,
|
|
748
756
|
root,
|
|
@@ -751,9 +759,10 @@ function resolveHookFile(node, ctx, options) {
|
|
|
751
759
|
});
|
|
752
760
|
const importedTypeNames = [
|
|
753
761
|
tsResolver.response.options(node),
|
|
762
|
+
tsResolver.response.responses(node),
|
|
754
763
|
...extraTypeNames,
|
|
755
764
|
...resolveOperationTypeNames(node, tsResolver, {
|
|
756
|
-
exclude: keyTypeName ?
|
|
765
|
+
exclude: [keyTypeName, returnType !== "data" ? tsResolver.response.response(node) : null].filter((name) => Boolean(name)),
|
|
757
766
|
order: "body-response-first",
|
|
758
767
|
includeParams: false
|
|
759
768
|
})
|
|
@@ -768,6 +777,7 @@ function resolveHookFile(node, ctx, options) {
|
|
|
768
777
|
tsResolver,
|
|
769
778
|
contractOp,
|
|
770
779
|
importedTypeNames,
|
|
780
|
+
returnType,
|
|
771
781
|
banner: resolver.default.banner(ctx.meta, {
|
|
772
782
|
output,
|
|
773
783
|
config,
|
|
@@ -798,7 +808,11 @@ function HookFile({ hook, imports, children }) {
|
|
|
798
808
|
path: contractOp.path
|
|
799
809
|
}),
|
|
800
810
|
/* @__PURE__ */ jsx(File.Import, {
|
|
801
|
-
name: [
|
|
811
|
+
name: [
|
|
812
|
+
"RequestConfig",
|
|
813
|
+
"ResponseErrorConfig",
|
|
814
|
+
"RequestResult"
|
|
815
|
+
],
|
|
802
816
|
root: contractOp.clientPathIsFile ? file.path : void 0,
|
|
803
817
|
path: contractOp.clientPath,
|
|
804
818
|
isTypeOnly: true
|
|
@@ -938,11 +952,12 @@ function buildClientCall(node, options) {
|
|
|
938
952
|
}
|
|
939
953
|
/**
|
|
940
954
|
* Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
|
|
941
|
-
* success body. `
|
|
955
|
+
* success body. `clientReturnType` mirrors the registered client plugin's own `returnType` option: with
|
|
942
956
|
* `'data'` the call already resolves to the bare body, so it is returned directly; with `'full'`
|
|
943
957
|
* (the default) the call carries `unwrap()`, so the body calls it instead of destructuring `data`
|
|
944
958
|
* off the full result by hand. With `'plain'` (plugin-client) the call resolves to the user's
|
|
945
|
-
* `RequestResult`, so the body awaits it and reads `data`.
|
|
959
|
+
* `RequestResult`, so the body awaits it and reads `data`. With `returnType` `'full'` the body
|
|
960
|
+
* resolves to the whole `RequestResult`; `resolveHookFile` rejects that for a client that already stripped it.
|
|
946
961
|
*
|
|
947
962
|
* @example
|
|
948
963
|
* ```ts
|
|
@@ -951,22 +966,24 @@ function buildClientCall(node, options) {
|
|
|
951
966
|
* ```
|
|
952
967
|
*/
|
|
953
968
|
function buildCallResultBody(call, options = {}) {
|
|
954
|
-
const {
|
|
955
|
-
if (returnType === "data") return `return
|
|
956
|
-
if (
|
|
969
|
+
const { clientReturnType = "full", returnType = "data" } = options;
|
|
970
|
+
if (returnType !== "data" || clientReturnType === "data") return `return ${call}`;
|
|
971
|
+
if (clientReturnType === "plain") return `return (await ${call}).data`;
|
|
957
972
|
return `return ${call}.unwrap()`;
|
|
958
973
|
}
|
|
959
974
|
/**
|
|
960
975
|
* Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
|
|
961
976
|
* success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
|
|
977
|
+
* With `returnType` `'full'`, `TData` is the client's `RequestResult` over the operation's responses record.
|
|
962
978
|
*/
|
|
963
|
-
function buildResponseTypes(node, resolver) {
|
|
964
|
-
|
|
979
|
+
function buildResponseTypes(node, resolver, options = {}) {
|
|
980
|
+
const { returnType = "data" } = options;
|
|
981
|
+
return resolver.memo(`responseTypes:${returnType}:${node.method}\0${node.path}`, () => {
|
|
965
982
|
const successNames = resolveSuccessNames(node, resolver);
|
|
966
983
|
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
967
984
|
const errorNames = resolveErrorNames(node, resolver);
|
|
968
985
|
return {
|
|
969
|
-
TData: responseName,
|
|
986
|
+
TData: returnType !== "data" ? `RequestResult<${resolver.response.responses(node)}, true>` : responseName,
|
|
970
987
|
TError: `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`
|
|
971
988
|
};
|
|
972
989
|
});
|
|
@@ -1151,8 +1168,9 @@ function resolveMutationRequestType(node, resolver) {
|
|
|
1151
1168
|
// ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
|
|
1152
1169
|
const declarationPrinter$5 = functionPrinter({ mode: "declaration" });
|
|
1153
1170
|
const callPrinter$3 = functionPrinter({ mode: "call" });
|
|
1154
|
-
function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, returnType
|
|
1155
|
-
const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
|
|
1171
|
+
function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitInitialPageParam, cursorParam, nextParam, previousParam, getNextPageParam, getPreviousPageParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, clientReturnType, returnType }) {
|
|
1172
|
+
const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver, { returnType });
|
|
1173
|
+
const dataSuffix = returnType === "data" ? "" : ".data";
|
|
1156
1174
|
const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
|
|
1157
1175
|
resolver: tsResolver,
|
|
1158
1176
|
initialPageParam,
|
|
@@ -1174,21 +1192,24 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, hasExplicitI
|
|
|
1174
1192
|
clientName,
|
|
1175
1193
|
signal: true,
|
|
1176
1194
|
unwrapName
|
|
1177
|
-
}), {
|
|
1195
|
+
}), {
|
|
1196
|
+
clientReturnType,
|
|
1197
|
+
returnType
|
|
1198
|
+
});
|
|
1178
1199
|
const initialPageParamLiteral = typeof initialPageParam === "string" || typeof initialPageParam === "object" && initialPageParam !== null ? JSON.stringify(initialPageParam) : String(initialPageParam === void 0 ? 0 : initialPageParam);
|
|
1179
1200
|
const serializedGetNextPageParam = typeof getNextPageParam === "function" ? getNextPageParam.toString() : getNextPageParam;
|
|
1180
1201
|
const getNextPageParamExpr = (() => {
|
|
1181
1202
|
if (serializedGetNextPageParam) return `getNextPageParam: ${serializedGetNextPageParam}`;
|
|
1182
|
-
if (nextParam) return `getNextPageParam: (lastPage) => ${getNestedAccessor(nextParam,
|
|
1183
|
-
if (cursorParam) return `getNextPageParam: (lastPage) => lastPage['${cursorParam}']`;
|
|
1184
|
-
return
|
|
1203
|
+
if (nextParam) return `getNextPageParam: (lastPage) => ${getNestedAccessor(nextParam, `lastPage${dataSuffix}`)}`;
|
|
1204
|
+
if (cursorParam) return `getNextPageParam: (lastPage) => lastPage${dataSuffix}['${cursorParam}']`;
|
|
1205
|
+
return `getNextPageParam: (lastPage, _allPages, lastPageParam) => Array.isArray(lastPage${dataSuffix}) && lastPage${dataSuffix}.length === 0 ? undefined : lastPageParam + 1`;
|
|
1185
1206
|
})();
|
|
1186
1207
|
const serializedGetPreviousPageParam = typeof getPreviousPageParam === "function" ? getPreviousPageParam.toString() : getPreviousPageParam;
|
|
1187
1208
|
const defaultPreviousThreshold = hasExplicitInitialPageParam ? initialPageParamLiteral : "1";
|
|
1188
1209
|
const getPreviousPageParamExpr = (() => {
|
|
1189
1210
|
if (serializedGetPreviousPageParam) return `getPreviousPageParam: ${serializedGetPreviousPageParam}`;
|
|
1190
|
-
if (previousParam) return `getPreviousPageParam: (firstPage) => ${getNestedAccessor(previousParam,
|
|
1191
|
-
if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`;
|
|
1211
|
+
if (previousParam) return `getPreviousPageParam: (firstPage) => ${getNestedAccessor(previousParam, `firstPage${dataSuffix}`)}`;
|
|
1212
|
+
if (cursorParam) return `getPreviousPageParam: (firstPage) => firstPage${dataSuffix}['${cursorParam}']`;
|
|
1192
1213
|
if (serializedGetNextPageParam || nextParam) return null;
|
|
1193
1214
|
return `getPreviousPageParam: (_firstPage, _allPages, firstPageParam) => firstPageParam <= ${defaultPreviousThreshold} ? undefined : firstPageParam - 1`;
|
|
1194
1215
|
})();
|
|
@@ -1411,8 +1432,8 @@ function getQueryOptionsParams(node, options) {
|
|
|
1411
1432
|
memberTypeWrapper: maybeRefOrGetter
|
|
1412
1433
|
});
|
|
1413
1434
|
}
|
|
1414
|
-
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, returnType
|
|
1415
|
-
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1435
|
+
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, clientReturnType, returnType }) {
|
|
1436
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
|
|
1416
1437
|
const queryKeyParamsNode = buildQueryKeyParams(node, {
|
|
1417
1438
|
resolver: tsResolver,
|
|
1418
1439
|
memberTypeWrapper: maybeRefOrGetter
|
|
@@ -1424,7 +1445,10 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, return
|
|
|
1424
1445
|
clientName,
|
|
1425
1446
|
signal: true,
|
|
1426
1447
|
unwrapName: (name) => `toValue(${name})`
|
|
1427
|
-
}), {
|
|
1448
|
+
}), {
|
|
1449
|
+
clientReturnType,
|
|
1450
|
+
returnType
|
|
1451
|
+
});
|
|
1428
1452
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
1429
1453
|
name,
|
|
1430
1454
|
isExportable: true,
|
|
@@ -1448,11 +1472,11 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, return
|
|
|
1448
1472
|
// src/components/Query.tsx
|
|
1449
1473
|
const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
|
|
1450
1474
|
const callPrinter$1 = functionPrinter({ mode: "call" });
|
|
1451
|
-
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, infinite }) {
|
|
1452
|
-
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1475
|
+
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, infinite, returnType }) {
|
|
1476
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
|
|
1453
1477
|
const optionsName = infinite ? "UseInfiniteQueryOptions" : "UseQueryOptions";
|
|
1454
1478
|
const hookName = infinite ? "useInfiniteQuery" : "useQuery";
|
|
1455
|
-
const
|
|
1479
|
+
const resultType = `${infinite ? "UseInfiniteQueryReturnType" : "UseQueryReturnType"}<${["TData", TError].join(", ")}> & { queryKey: TQueryKey }`;
|
|
1456
1480
|
const generics = [
|
|
1457
1481
|
infinite ? `TData = InfiniteData<${TData}>` : `TData = ${TData}`,
|
|
1458
1482
|
`TQueryData = ${TData}`,
|
|
@@ -1519,7 +1543,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1519
1543
|
...${queryOptionsName}(${queryOptionsParamsCall}),
|
|
1520
1544
|
...resolvedOptions,
|
|
1521
1545
|
queryKey
|
|
1522
|
-
} as unknown as ${optionsName}<${castGenerics.join(", ")}>, toValue(queryClient)) as ${
|
|
1546
|
+
} as unknown as ${optionsName}<${castGenerics.join(", ")}>, toValue(queryClient)) as ${resultType}
|
|
1523
1547
|
|
|
1524
1548
|
queryResult.queryKey = queryKey as TQueryKey
|
|
1525
1549
|
|
|
@@ -1565,7 +1589,7 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1565
1589
|
node,
|
|
1566
1590
|
root,
|
|
1567
1591
|
output,
|
|
1568
|
-
|
|
1592
|
+
memo: ctx.memo
|
|
1569
1593
|
});
|
|
1570
1594
|
if (!contractOp) return null;
|
|
1571
1595
|
const queryName = resolver.infiniteQuery.name(node);
|
|
@@ -1577,6 +1601,7 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1577
1601
|
output,
|
|
1578
1602
|
group,
|
|
1579
1603
|
contractOp,
|
|
1604
|
+
returnType: ctx.options.returnType,
|
|
1580
1605
|
keyTypeName: queryKeyTypeName,
|
|
1581
1606
|
extraTypeNames: [resolvePageParamType(node, {
|
|
1582
1607
|
resolver: resolveOperationTypes(ctx.driver, ctx.resolver.pluginName).resolver,
|
|
@@ -1629,7 +1654,8 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1629
1654
|
initialPageParam: infiniteOptions.initialPageParam,
|
|
1630
1655
|
hasExplicitInitialPageParam: infiniteOptions.hasExplicitInitialPageParam,
|
|
1631
1656
|
queryParam: infiniteOptions.queryParam,
|
|
1632
|
-
|
|
1657
|
+
clientReturnType: contractOp.returnType,
|
|
1658
|
+
returnType: hook.returnType,
|
|
1633
1659
|
queryKeyType: "QueryKey",
|
|
1634
1660
|
memberTypeWrapper: maybeRefOrGetter,
|
|
1635
1661
|
unwrapName: (name) => `toValue(${name})`
|
|
@@ -1655,7 +1681,8 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1655
1681
|
queryKeyTypeName,
|
|
1656
1682
|
node,
|
|
1657
1683
|
tsResolver,
|
|
1658
|
-
infinite: true
|
|
1684
|
+
infinite: true,
|
|
1685
|
+
returnType: hook.returnType
|
|
1659
1686
|
})
|
|
1660
1687
|
]
|
|
1661
1688
|
});
|
|
@@ -1665,8 +1692,8 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1665
1692
|
const declarationPrinter = functionPrinter({ mode: "declaration" });
|
|
1666
1693
|
const callPrinter = functionPrinter({ mode: "call" });
|
|
1667
1694
|
function buildMutationParamsNode(node, options) {
|
|
1668
|
-
const { resolver } = options;
|
|
1669
|
-
const { TData, TError } = buildResponseTypes(node, resolver);
|
|
1695
|
+
const { resolver, returnType } = options;
|
|
1696
|
+
const { TData, TError } = buildResponseTypes(node, resolver, { returnType });
|
|
1670
1697
|
return buildHookParams(node, {
|
|
1671
1698
|
resolver,
|
|
1672
1699
|
withRequest: false,
|
|
@@ -1681,8 +1708,8 @@ function buildMutationParamsNode(node, options) {
|
|
|
1681
1708
|
}`
|
|
1682
1709
|
});
|
|
1683
1710
|
}
|
|
1684
|
-
function Mutation({ name, clientName, node, tsResolver, mutationKeyName, returnType
|
|
1685
|
-
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1711
|
+
function Mutation({ name, clientName, node, tsResolver, mutationKeyName, clientReturnType, returnType }) {
|
|
1712
|
+
const { TData, TError } = buildResponseTypes(node, tsResolver, { returnType });
|
|
1686
1713
|
const groupedParam = buildGroupedRequestParam(node, {
|
|
1687
1714
|
resolver: tsResolver,
|
|
1688
1715
|
withContentType: true
|
|
@@ -1695,16 +1722,22 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName, returnT
|
|
|
1695
1722
|
clientName,
|
|
1696
1723
|
signal: false,
|
|
1697
1724
|
withContentType: true,
|
|
1698
|
-
returnType,
|
|
1725
|
+
returnType: clientReturnType,
|
|
1699
1726
|
unwrapName: (name) => `toValue<${TRequest}['${name}']>(${name})`
|
|
1700
|
-
}), {
|
|
1727
|
+
}), {
|
|
1728
|
+
clientReturnType,
|
|
1729
|
+
returnType
|
|
1730
|
+
});
|
|
1701
1731
|
const generics = [
|
|
1702
1732
|
TData,
|
|
1703
1733
|
TError,
|
|
1704
1734
|
TRequest,
|
|
1705
1735
|
"TContext"
|
|
1706
1736
|
].join(", ");
|
|
1707
|
-
const paramsNode = buildMutationParamsNode(node, {
|
|
1737
|
+
const paramsNode = buildMutationParamsNode(node, {
|
|
1738
|
+
resolver: tsResolver,
|
|
1739
|
+
returnType
|
|
1740
|
+
});
|
|
1708
1741
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
1709
1742
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
1710
1743
|
name,
|
|
@@ -1757,7 +1790,7 @@ const mutationGenerator = defineGenerator({
|
|
|
1757
1790
|
node,
|
|
1758
1791
|
root,
|
|
1759
1792
|
output,
|
|
1760
|
-
|
|
1793
|
+
memo: ctx.memo
|
|
1761
1794
|
});
|
|
1762
1795
|
if (!contractOp) return null;
|
|
1763
1796
|
const mutationHookName = resolver.mutation.name(node);
|
|
@@ -1766,7 +1799,8 @@ const mutationGenerator = defineGenerator({
|
|
|
1766
1799
|
name: mutationHookName,
|
|
1767
1800
|
output,
|
|
1768
1801
|
group,
|
|
1769
|
-
contractOp
|
|
1802
|
+
contractOp,
|
|
1803
|
+
returnType: ctx.options.returnType
|
|
1770
1804
|
});
|
|
1771
1805
|
const groups = getRequestGroups(node);
|
|
1772
1806
|
const hasRequestGroups = groups.path || groups.query || groups.body || groups.headers;
|
|
@@ -1800,7 +1834,8 @@ const mutationGenerator = defineGenerator({
|
|
|
1800
1834
|
node,
|
|
1801
1835
|
tsResolver: hook.tsResolver,
|
|
1802
1836
|
mutationKeyName,
|
|
1803
|
-
|
|
1837
|
+
clientReturnType: contractOp.returnType,
|
|
1838
|
+
returnType: hook.returnType
|
|
1804
1839
|
})
|
|
1805
1840
|
] })]
|
|
1806
1841
|
});
|
|
@@ -1831,7 +1866,7 @@ const queryGenerator = defineGenerator({
|
|
|
1831
1866
|
node,
|
|
1832
1867
|
root,
|
|
1833
1868
|
output,
|
|
1834
|
-
|
|
1869
|
+
memo: ctx.memo
|
|
1835
1870
|
});
|
|
1836
1871
|
if (!contractOp) return null;
|
|
1837
1872
|
const queryName = resolver.query.name(node);
|
|
@@ -1843,7 +1878,8 @@ const queryGenerator = defineGenerator({
|
|
|
1843
1878
|
output,
|
|
1844
1879
|
group,
|
|
1845
1880
|
contractOp,
|
|
1846
|
-
keyTypeName: queryKeyTypeName
|
|
1881
|
+
keyTypeName: queryKeyTypeName,
|
|
1882
|
+
returnType: ctx.options.returnType
|
|
1847
1883
|
});
|
|
1848
1884
|
const { tsResolver } = hook;
|
|
1849
1885
|
return /* @__PURE__ */ jsxs(HookFile, {
|
|
@@ -1877,7 +1913,8 @@ const queryGenerator = defineGenerator({
|
|
|
1877
1913
|
queryKeyName,
|
|
1878
1914
|
node,
|
|
1879
1915
|
tsResolver,
|
|
1880
|
-
|
|
1916
|
+
clientReturnType: contractOp.returnType,
|
|
1917
|
+
returnType: hook.returnType
|
|
1881
1918
|
}),
|
|
1882
1919
|
query && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1883
1920
|
/* @__PURE__ */ jsx(File.Import, {
|
|
@@ -1900,7 +1937,8 @@ const queryGenerator = defineGenerator({
|
|
|
1900
1937
|
queryKeyName,
|
|
1901
1938
|
queryKeyTypeName,
|
|
1902
1939
|
node,
|
|
1903
|
-
tsResolver
|
|
1940
|
+
tsResolver,
|
|
1941
|
+
returnType: hook.returnType
|
|
1904
1942
|
})
|
|
1905
1943
|
] })
|
|
1906
1944
|
]
|
|
@@ -1975,7 +2013,7 @@ const pluginVueQuery = defineExtension({
|
|
|
1975
2013
|
const { output = {
|
|
1976
2014
|
path: "hooks",
|
|
1977
2015
|
barrel: { type: "named" }
|
|
1978
|
-
}, group, exclude = [], include, override = [], infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, hooks = false, client, resolver: userResolver, macros: userMacros } = options;
|
|
2016
|
+
}, group, exclude = [], include, override = [], infinite = false, mutation = {}, query = {}, mutationKey = mutationKeyTransformer, queryKey = queryKeyTransformer, hooks = false, client, returnType = "data", resolver: userResolver, macros: userMacros } = options;
|
|
1979
2017
|
const resolver = userResolver ? Resolver.merge(resolverVueQuery, userResolver) : resolverVueQuery;
|
|
1980
2018
|
setResolver(resolver);
|
|
1981
2019
|
if (userMacros?.length) setMacros(userMacros);
|
|
@@ -1987,6 +2025,7 @@ const pluginVueQuery = defineExtension({
|
|
|
1987
2025
|
client,
|
|
1988
2026
|
plugins: useConfig().plugins
|
|
1989
2027
|
}),
|
|
2028
|
+
returnType,
|
|
1990
2029
|
queryKey,
|
|
1991
2030
|
query: resolveQueryConfig(query, { importPath: "@tanstack/vue-query" }),
|
|
1992
2031
|
mutationKey,
|