@kubb/plugin-react-query 5.1.0-canary.20260907T133428 → 5.2.0-canary.20260907T164903
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 +42 -15
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +42 -15
- package/dist/index.js.map +1 -1
- package/package.json +8 -8
package/dist/index.cjs
CHANGED
|
@@ -443,6 +443,9 @@ function resolveContractClient(options) {
|
|
|
443
443
|
* so several dependents reading the same client plugin for one operation in a single pass
|
|
444
444
|
* (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
|
|
445
445
|
* one computed result instead of each re-deriving the name and path.
|
|
446
|
+
*
|
|
447
|
+
* `returnType` mirrors the client plugin's own `returnType` option (`'full'` when unset), so a
|
|
448
|
+
* dependent's generated call body can match it instead of assuming the full `RequestResult` shape.
|
|
446
449
|
*/
|
|
447
450
|
function resolveClientOperation(options) {
|
|
448
451
|
const { clientPlugin, driver, node, root, output, cache } = options;
|
|
@@ -459,7 +462,8 @@ function resolveClientOperation(options) {
|
|
|
459
462
|
return {
|
|
460
463
|
name: resolver.name(node.operationId),
|
|
461
464
|
path: file.path,
|
|
462
|
-
clientPath: node_path.default.resolve(root, ".kubb/client.ts")
|
|
465
|
+
clientPath: node_path.default.resolve(root, ".kubb/client.ts"),
|
|
466
|
+
returnType: plugin?.options?.returnType ?? "full"
|
|
463
467
|
};
|
|
464
468
|
});
|
|
465
469
|
}
|
|
@@ -569,6 +573,24 @@ function buildClientCall(node, options) {
|
|
|
569
573
|
].filter((part) => part !== null).join(", ")} })`;
|
|
570
574
|
}
|
|
571
575
|
/**
|
|
576
|
+
* Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
|
|
577
|
+
* success body. `returnType` mirrors the registered client plugin's own `returnType` option: with
|
|
578
|
+
* `'data'` the call already resolves to the bare body, so it is returned directly; with `'full'`
|
|
579
|
+
* (the default) the call carries `unwrap()`, so the body calls it instead of destructuring `data`
|
|
580
|
+
* off the full result by hand.
|
|
581
|
+
*
|
|
582
|
+
* @example
|
|
583
|
+
* ```ts
|
|
584
|
+
* buildCallResultBody(buildClientCall(node, { clientName: 'getPetById' }))
|
|
585
|
+
* // return getPetById({ ...config, throwOnError: true }).unwrap()
|
|
586
|
+
* ```
|
|
587
|
+
*/
|
|
588
|
+
function buildCallResultBody(call, options = {}) {
|
|
589
|
+
const { returnType = "full" } = options;
|
|
590
|
+
if (returnType === "data") return `return await ${call}`;
|
|
591
|
+
return `return ${call}.unwrap()`;
|
|
592
|
+
}
|
|
593
|
+
/**
|
|
572
594
|
* Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
|
|
573
595
|
* success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
|
|
574
596
|
*/
|
|
@@ -724,7 +746,7 @@ function buildQueryKeyParams(node, options) {
|
|
|
724
746
|
//#region ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
|
|
725
747
|
const declarationPrinter$7 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
726
748
|
const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
727
|
-
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName }) {
|
|
749
|
+
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, returnType = "full" }) {
|
|
728
750
|
const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
|
|
729
751
|
const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
|
|
730
752
|
resolver: tsResolver,
|
|
@@ -743,11 +765,11 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
743
765
|
memberTypeWrapper
|
|
744
766
|
});
|
|
745
767
|
const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
|
|
746
|
-
const queryFnBody =
|
|
768
|
+
const queryFnBody = buildCallResultBody(buildClientCall(node, {
|
|
747
769
|
clientName,
|
|
748
770
|
signal: true,
|
|
749
771
|
unwrapName
|
|
750
|
-
})}
|
|
772
|
+
}), { returnType });
|
|
751
773
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
752
774
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
753
775
|
if (hasNewParams) {
|
|
@@ -1276,7 +1298,7 @@ function buildMutationConfigParamsNode(node) {
|
|
|
1276
1298
|
default: "{}"
|
|
1277
1299
|
})] });
|
|
1278
1300
|
}
|
|
1279
|
-
function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }) {
|
|
1301
|
+
function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName, returnType = "full" }) {
|
|
1280
1302
|
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1281
1303
|
const configParamsNode = buildMutationConfigParamsNode(node);
|
|
1282
1304
|
const paramsSignature = declarationPrinter$3.print(configParamsNode) ?? "";
|
|
@@ -1285,10 +1307,10 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }
|
|
|
1285
1307
|
const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
|
|
1286
1308
|
const TRequest = hasMutationParams ? tsResolver.response.options(node) : "undefined";
|
|
1287
1309
|
const argBindingStr = hasMutationParams ? callPrinter$2.print(groupedParamsNode) ?? "" : "_";
|
|
1288
|
-
const mutationFnBody =
|
|
1310
|
+
const mutationFnBody = buildCallResultBody(buildClientCall(node, {
|
|
1289
1311
|
clientName,
|
|
1290
1312
|
signal: false
|
|
1291
|
-
})}
|
|
1313
|
+
}), { returnType });
|
|
1292
1314
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1293
1315
|
name,
|
|
1294
1316
|
isExportable: true,
|
|
@@ -1456,16 +1478,16 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1456
1478
|
//#region src/components/QueryOptions.tsx
|
|
1457
1479
|
const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1458
1480
|
const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1459
|
-
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
|
|
1481
|
+
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, returnType = "full" }) {
|
|
1460
1482
|
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1461
1483
|
const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
|
|
1462
1484
|
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
|
|
1463
1485
|
const paramsNode = buildQueryOptionsParams(node, { resolver: tsResolver });
|
|
1464
1486
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
1465
|
-
const queryFnBody =
|
|
1487
|
+
const queryFnBody = buildCallResultBody(buildClientCall(node, {
|
|
1466
1488
|
clientName,
|
|
1467
1489
|
signal: true
|
|
1468
|
-
})}
|
|
1490
|
+
}), { returnType });
|
|
1469
1491
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1470
1492
|
name,
|
|
1471
1493
|
isExportable: true,
|
|
@@ -1633,7 +1655,8 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1633
1655
|
nextParam: infiniteOptions.nextParam,
|
|
1634
1656
|
previousParam: infiniteOptions.previousParam,
|
|
1635
1657
|
initialPageParam: infiniteOptions.initialPageParam,
|
|
1636
|
-
queryParam: infiniteOptions.queryParam
|
|
1658
|
+
queryParam: infiniteOptions.queryParam,
|
|
1659
|
+
returnType: contractOp.returnType
|
|
1637
1660
|
}),
|
|
1638
1661
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
1639
1662
|
name: ["useInfiniteQuery"],
|
|
@@ -1781,7 +1804,8 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1781
1804
|
clientName: calledClientName,
|
|
1782
1805
|
mutationKeyName,
|
|
1783
1806
|
node,
|
|
1784
|
-
tsResolver
|
|
1807
|
+
tsResolver,
|
|
1808
|
+
returnType: contractOp.returnType
|
|
1785
1809
|
}),
|
|
1786
1810
|
mutation && hooks && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [
|
|
1787
1811
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
@@ -1932,7 +1956,8 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1932
1956
|
clientName: calledClientName,
|
|
1933
1957
|
queryKeyName,
|
|
1934
1958
|
node,
|
|
1935
|
-
tsResolver
|
|
1959
|
+
tsResolver,
|
|
1960
|
+
returnType: contractOp.returnType
|
|
1936
1961
|
}),
|
|
1937
1962
|
query && hooks && /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsxs)(kubb_jsx_jsx_runtime.Fragment, { children: [
|
|
1938
1963
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
@@ -2105,7 +2130,8 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2105
2130
|
nextParam: infiniteOptions.nextParam,
|
|
2106
2131
|
previousParam: infiniteOptions.previousParam,
|
|
2107
2132
|
initialPageParam: infiniteOptions.initialPageParam,
|
|
2108
|
-
queryParam: infiniteOptions.queryParam
|
|
2133
|
+
queryParam: infiniteOptions.queryParam,
|
|
2134
|
+
returnType: contractOp.returnType
|
|
2109
2135
|
}),
|
|
2110
2136
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2111
2137
|
name: ["useSuspenseInfiniteQuery"],
|
|
@@ -2260,7 +2286,8 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2260
2286
|
clientName: calledClientName,
|
|
2261
2287
|
queryKeyName,
|
|
2262
2288
|
node,
|
|
2263
|
-
tsResolver
|
|
2289
|
+
tsResolver,
|
|
2290
|
+
returnType: contractOp.returnType
|
|
2264
2291
|
}),
|
|
2265
2292
|
/* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Import, {
|
|
2266
2293
|
name: ["useSuspenseQuery"],
|