@kubb/plugin-vue-query 5.1.0-canary.20260907T133429 → 5.1.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 +38 -13
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +38 -13
- package/dist/index.js.map +1 -1
- package/package.json +12 -8
package/dist/index.cjs
CHANGED
|
@@ -467,6 +467,24 @@ function buildClientCall(node, options) {
|
|
|
467
467
|
].filter((part) => part !== null).join(", ")} })`;
|
|
468
468
|
}
|
|
469
469
|
/**
|
|
470
|
+
* Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
|
|
471
|
+
* success body. `returnType` mirrors the registered client plugin's own `returnType` option: with
|
|
472
|
+
* `'data'` the call already resolves to the bare body, so it is returned directly; with `'full'`
|
|
473
|
+
* (the default) the call carries `unwrap()`, so the body calls it instead of destructuring `data`
|
|
474
|
+
* off the full result by hand.
|
|
475
|
+
*
|
|
476
|
+
* @example
|
|
477
|
+
* ```ts
|
|
478
|
+
* buildCallResultBody(buildClientCall(node, { clientName: 'getPetById' }))
|
|
479
|
+
* // return getPetById({ ...config, throwOnError: true }).unwrap()
|
|
480
|
+
* ```
|
|
481
|
+
*/
|
|
482
|
+
function buildCallResultBody(call, options = {}) {
|
|
483
|
+
const { returnType = "full" } = options;
|
|
484
|
+
if (returnType === "data") return `return await ${call}`;
|
|
485
|
+
return `return ${call}.unwrap()`;
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
470
488
|
* Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
|
|
471
489
|
* success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
|
|
472
490
|
*/
|
|
@@ -579,7 +597,7 @@ const queryKeyGroupOrder = [
|
|
|
579
597
|
//#region ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
|
|
580
598
|
const declarationPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
581
599
|
const callPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
582
|
-
function InfiniteQueryOptions$1({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName }) {
|
|
600
|
+
function InfiniteQueryOptions$1({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, returnType = "full" }) {
|
|
583
601
|
const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
|
|
584
602
|
const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
|
|
585
603
|
resolver: tsResolver,
|
|
@@ -598,11 +616,11 @@ function InfiniteQueryOptions$1({ name, clientName, initialPageParam, cursorPara
|
|
|
598
616
|
memberTypeWrapper
|
|
599
617
|
});
|
|
600
618
|
const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
|
|
601
|
-
const queryFnBody =
|
|
619
|
+
const queryFnBody = buildCallResultBody(buildClientCall(node, {
|
|
602
620
|
clientName,
|
|
603
621
|
signal: true,
|
|
604
622
|
unwrapName
|
|
605
|
-
})}
|
|
623
|
+
}), { returnType });
|
|
606
624
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
607
625
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
608
626
|
if (hasNewParams) {
|
|
@@ -832,6 +850,9 @@ function resolveContractClient(options) {
|
|
|
832
850
|
* so several dependents reading the same client plugin for one operation in a single pass
|
|
833
851
|
* (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
|
|
834
852
|
* one computed result instead of each re-deriving the name and path.
|
|
853
|
+
*
|
|
854
|
+
* `returnType` mirrors the client plugin's own `returnType` option (`'full'` when unset), so a
|
|
855
|
+
* dependent's generated call body can match it instead of assuming the full `RequestResult` shape.
|
|
835
856
|
*/
|
|
836
857
|
function resolveClientOperation(options) {
|
|
837
858
|
const { clientPlugin, driver, node, root, output, cache } = options;
|
|
@@ -848,7 +869,8 @@ function resolveClientOperation(options) {
|
|
|
848
869
|
return {
|
|
849
870
|
name: resolver.name(node.operationId),
|
|
850
871
|
path: file.path,
|
|
851
|
-
clientPath: node_path.default.resolve(root, ".kubb/client.ts")
|
|
872
|
+
clientPath: node_path.default.resolve(root, ".kubb/client.ts"),
|
|
873
|
+
returnType: plugin?.options?.returnType ?? "full"
|
|
852
874
|
};
|
|
853
875
|
});
|
|
854
876
|
}
|
|
@@ -918,16 +940,16 @@ function getQueryOptionsParams(node, options) {
|
|
|
918
940
|
memberTypeWrapper: maybeRefOrGetter
|
|
919
941
|
});
|
|
920
942
|
}
|
|
921
|
-
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
|
|
943
|
+
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, returnType = "full" }) {
|
|
922
944
|
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
923
945
|
const queryKeyParamsNode = buildQueryKeyParamsNode(node, { resolver: tsResolver });
|
|
924
946
|
const queryKeyParamsCall = callPrinter$3.print(queryKeyParamsNode) ?? "";
|
|
925
947
|
const paramsNode = getQueryOptionsParams(node, { resolver: tsResolver });
|
|
926
948
|
const paramsSignature = declarationPrinter$3.print(paramsNode) ?? "";
|
|
927
|
-
const queryFnBody =
|
|
949
|
+
const queryFnBody = buildCallResultBody(buildVueClientCall(node, {
|
|
928
950
|
clientName,
|
|
929
951
|
signal: true
|
|
930
|
-
})}
|
|
952
|
+
}), { returnType });
|
|
931
953
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
932
954
|
name,
|
|
933
955
|
isExportable: true,
|
|
@@ -1057,16 +1079,16 @@ function buildMutationParamsNode(node, options) {
|
|
|
1057
1079
|
default: "{}"
|
|
1058
1080
|
})] });
|
|
1059
1081
|
}
|
|
1060
|
-
function Mutation({ name, clientName, node, tsResolver, mutationKeyName }) {
|
|
1082
|
+
function Mutation({ name, clientName, node, tsResolver, mutationKeyName, returnType = "full" }) {
|
|
1061
1083
|
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1062
1084
|
const groupedParam = buildGroupedRequestParam(node, { resolver: tsResolver });
|
|
1063
1085
|
const hasMutationParams = groupedParam !== null;
|
|
1064
1086
|
const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
|
|
1065
1087
|
const argBindingStr = hasMutationParams ? callPrinter$1.print(groupedParamsNode) ?? "" : "";
|
|
1066
|
-
const mutationFnBody =
|
|
1088
|
+
const mutationFnBody = buildCallResultBody(buildVueClientCall(node, {
|
|
1067
1089
|
clientName,
|
|
1068
1090
|
signal: false
|
|
1069
|
-
})}
|
|
1091
|
+
}), { returnType });
|
|
1070
1092
|
const generics = [
|
|
1071
1093
|
TData,
|
|
1072
1094
|
TError,
|
|
@@ -1315,7 +1337,8 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1315
1337
|
nextParam: infiniteOptions.nextParam,
|
|
1316
1338
|
previousParam: infiniteOptions.previousParam,
|
|
1317
1339
|
initialPageParam: infiniteOptions.initialPageParam,
|
|
1318
|
-
queryParam: infiniteOptions.queryParam
|
|
1340
|
+
queryParam: infiniteOptions.queryParam,
|
|
1341
|
+
returnType: contractOp.returnType
|
|
1319
1342
|
}),
|
|
1320
1343
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1321
1344
|
name: ["useInfiniteQuery"],
|
|
@@ -1471,7 +1494,8 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1471
1494
|
typeName: mutationTypeName,
|
|
1472
1495
|
node,
|
|
1473
1496
|
tsResolver,
|
|
1474
|
-
mutationKeyName
|
|
1497
|
+
mutationKeyName,
|
|
1498
|
+
returnType: contractOp.returnType
|
|
1475
1499
|
})
|
|
1476
1500
|
] })
|
|
1477
1501
|
]
|
|
@@ -1599,7 +1623,8 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1599
1623
|
clientName: calledClientName,
|
|
1600
1624
|
queryKeyName,
|
|
1601
1625
|
node,
|
|
1602
|
-
tsResolver
|
|
1626
|
+
tsResolver,
|
|
1627
|
+
returnType: contractOp.returnType
|
|
1603
1628
|
}),
|
|
1604
1629
|
query && hooks && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [
|
|
1605
1630
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|