@kubb/plugin-vue-query 5.1.0-canary.20260907T104727 → 5.1.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 +38 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +38 -13
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -437,6 +437,24 @@ function buildClientCall(node, options) {
|
|
|
437
437
|
].filter((part) => part !== null).join(", ")} })`;
|
|
438
438
|
}
|
|
439
439
|
/**
|
|
440
|
+
* Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
|
|
441
|
+
* success body. `returnType` mirrors the registered client plugin's own `returnType` option: with
|
|
442
|
+
* `'data'` the call already resolves to the bare body, so it is returned directly; with `'full'`
|
|
443
|
+
* (the default) the call carries `unwrap()`, so the body calls it instead of destructuring `data`
|
|
444
|
+
* off the full result by hand.
|
|
445
|
+
*
|
|
446
|
+
* @example
|
|
447
|
+
* ```ts
|
|
448
|
+
* buildCallResultBody(buildClientCall(node, { clientName: 'getPetById' }))
|
|
449
|
+
* // return getPetById({ ...config, throwOnError: true }).unwrap()
|
|
450
|
+
* ```
|
|
451
|
+
*/
|
|
452
|
+
function buildCallResultBody(call, options = {}) {
|
|
453
|
+
const { returnType = "full" } = options;
|
|
454
|
+
if (returnType === "data") return `return await ${call}`;
|
|
455
|
+
return `return ${call}.unwrap()`;
|
|
456
|
+
}
|
|
457
|
+
/**
|
|
440
458
|
* Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
|
|
441
459
|
* success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
|
|
442
460
|
*/
|
|
@@ -549,7 +567,7 @@ const queryKeyGroupOrder = [
|
|
|
549
567
|
//#region ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
|
|
550
568
|
const declarationPrinter$7 = functionPrinter({ mode: "declaration" });
|
|
551
569
|
const callPrinter$4 = functionPrinter({ mode: "call" });
|
|
552
|
-
function InfiniteQueryOptions$1({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName }) {
|
|
570
|
+
function InfiniteQueryOptions$1({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, returnType = "full" }) {
|
|
553
571
|
const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
|
|
554
572
|
const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
|
|
555
573
|
resolver: tsResolver,
|
|
@@ -568,11 +586,11 @@ function InfiniteQueryOptions$1({ name, clientName, initialPageParam, cursorPara
|
|
|
568
586
|
memberTypeWrapper
|
|
569
587
|
});
|
|
570
588
|
const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
|
|
571
|
-
const queryFnBody =
|
|
589
|
+
const queryFnBody = buildCallResultBody(buildClientCall(node, {
|
|
572
590
|
clientName,
|
|
573
591
|
signal: true,
|
|
574
592
|
unwrapName
|
|
575
|
-
})}
|
|
593
|
+
}), { returnType });
|
|
576
594
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
577
595
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
578
596
|
if (hasNewParams) {
|
|
@@ -802,6 +820,9 @@ function resolveContractClient(options) {
|
|
|
802
820
|
* so several dependents reading the same client plugin for one operation in a single pass
|
|
803
821
|
* (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
|
|
804
822
|
* one computed result instead of each re-deriving the name and path.
|
|
823
|
+
*
|
|
824
|
+
* `returnType` mirrors the client plugin's own `returnType` option (`'full'` when unset), so a
|
|
825
|
+
* dependent's generated call body can match it instead of assuming the full `RequestResult` shape.
|
|
805
826
|
*/
|
|
806
827
|
function resolveClientOperation(options) {
|
|
807
828
|
const { clientPlugin, driver, node, root, output, cache } = options;
|
|
@@ -818,7 +839,8 @@ function resolveClientOperation(options) {
|
|
|
818
839
|
return {
|
|
819
840
|
name: resolver.name(node.operationId),
|
|
820
841
|
path: file.path,
|
|
821
|
-
clientPath: path.resolve(root, ".kubb/client.ts")
|
|
842
|
+
clientPath: path.resolve(root, ".kubb/client.ts"),
|
|
843
|
+
returnType: plugin?.options?.returnType ?? "full"
|
|
822
844
|
};
|
|
823
845
|
});
|
|
824
846
|
}
|
|
@@ -888,16 +910,16 @@ function getQueryOptionsParams(node, options) {
|
|
|
888
910
|
memberTypeWrapper: maybeRefOrGetter
|
|
889
911
|
});
|
|
890
912
|
}
|
|
891
|
-
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
|
|
913
|
+
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, returnType = "full" }) {
|
|
892
914
|
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
893
915
|
const queryKeyParamsNode = buildQueryKeyParamsNode(node, { resolver: tsResolver });
|
|
894
916
|
const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
|
|
895
917
|
const paramsNode = getQueryOptionsParams(node, { resolver: tsResolver });
|
|
896
918
|
const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
|
|
897
|
-
const queryFnBody =
|
|
919
|
+
const queryFnBody = buildCallResultBody(buildVueClientCall(node, {
|
|
898
920
|
clientName,
|
|
899
921
|
signal: true
|
|
900
|
-
})}
|
|
922
|
+
}), { returnType });
|
|
901
923
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
902
924
|
name,
|
|
903
925
|
isExportable: true,
|
|
@@ -1027,16 +1049,16 @@ function buildMutationParamsNode(node, options) {
|
|
|
1027
1049
|
default: "{}"
|
|
1028
1050
|
})] });
|
|
1029
1051
|
}
|
|
1030
|
-
function Mutation({ name, clientName, node, tsResolver, mutationKeyName }) {
|
|
1052
|
+
function Mutation({ name, clientName, node, tsResolver, mutationKeyName, returnType = "full" }) {
|
|
1031
1053
|
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1032
1054
|
const groupedParam = buildGroupedRequestParam(node, { resolver: tsResolver });
|
|
1033
1055
|
const hasMutationParams = groupedParam !== null;
|
|
1034
1056
|
const groupedParamsNode = createFunctionParameters({ params: groupedParam ? [groupedParam] : [] });
|
|
1035
1057
|
const argBindingStr = hasMutationParams ? callPrinter$1.print(groupedParamsNode) ?? "" : "";
|
|
1036
|
-
const mutationFnBody =
|
|
1058
|
+
const mutationFnBody = buildCallResultBody(buildVueClientCall(node, {
|
|
1037
1059
|
clientName,
|
|
1038
1060
|
signal: false
|
|
1039
|
-
})}
|
|
1061
|
+
}), { returnType });
|
|
1040
1062
|
const generics = [
|
|
1041
1063
|
TData,
|
|
1042
1064
|
TError,
|
|
@@ -1285,7 +1307,8 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1285
1307
|
nextParam: infiniteOptions.nextParam,
|
|
1286
1308
|
previousParam: infiniteOptions.previousParam,
|
|
1287
1309
|
initialPageParam: infiniteOptions.initialPageParam,
|
|
1288
|
-
queryParam: infiniteOptions.queryParam
|
|
1310
|
+
queryParam: infiniteOptions.queryParam,
|
|
1311
|
+
returnType: contractOp.returnType
|
|
1289
1312
|
}),
|
|
1290
1313
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1291
1314
|
name: ["useInfiniteQuery"],
|
|
@@ -1441,7 +1464,8 @@ const mutationGenerator = defineGenerator({
|
|
|
1441
1464
|
typeName: mutationTypeName,
|
|
1442
1465
|
node,
|
|
1443
1466
|
tsResolver,
|
|
1444
|
-
mutationKeyName
|
|
1467
|
+
mutationKeyName,
|
|
1468
|
+
returnType: contractOp.returnType
|
|
1445
1469
|
})
|
|
1446
1470
|
] })
|
|
1447
1471
|
]
|
|
@@ -1569,7 +1593,8 @@ const queryGenerator = defineGenerator({
|
|
|
1569
1593
|
clientName: calledClientName,
|
|
1570
1594
|
queryKeyName,
|
|
1571
1595
|
node,
|
|
1572
|
-
tsResolver
|
|
1596
|
+
tsResolver,
|
|
1597
|
+
returnType: contractOp.returnType
|
|
1573
1598
|
}),
|
|
1574
1599
|
query && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1575
1600
|
/* @__PURE__ */ jsx(File.Import, {
|