@kubb/plugin-react-query 5.1.0-canary.20260907T104725 → 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 +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.js
CHANGED
|
@@ -416,6 +416,9 @@ function resolveContractClient(options) {
|
|
|
416
416
|
* so several dependents reading the same client plugin for one operation in a single pass
|
|
417
417
|
* (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
|
|
418
418
|
* one computed result instead of each re-deriving the name and path.
|
|
419
|
+
*
|
|
420
|
+
* `returnType` mirrors the client plugin's own `returnType` option (`'full'` when unset), so a
|
|
421
|
+
* dependent's generated call body can match it instead of assuming the full `RequestResult` shape.
|
|
419
422
|
*/
|
|
420
423
|
function resolveClientOperation(options) {
|
|
421
424
|
const { clientPlugin, driver, node, root, output, cache } = options;
|
|
@@ -432,7 +435,8 @@ function resolveClientOperation(options) {
|
|
|
432
435
|
return {
|
|
433
436
|
name: resolver.name(node.operationId),
|
|
434
437
|
path: file.path,
|
|
435
|
-
clientPath: path.resolve(root, ".kubb/client.ts")
|
|
438
|
+
clientPath: path.resolve(root, ".kubb/client.ts"),
|
|
439
|
+
returnType: plugin?.options?.returnType ?? "full"
|
|
436
440
|
};
|
|
437
441
|
});
|
|
438
442
|
}
|
|
@@ -542,6 +546,24 @@ function buildClientCall(node, options) {
|
|
|
542
546
|
].filter((part) => part !== null).join(", ")} })`;
|
|
543
547
|
}
|
|
544
548
|
/**
|
|
549
|
+
* Builds the query/mutation body that resolves a `buildClientCall` expression down to the bare
|
|
550
|
+
* success body. `returnType` mirrors the registered client plugin's own `returnType` option: with
|
|
551
|
+
* `'data'` the call already resolves to the bare body, so it is returned directly; with `'full'`
|
|
552
|
+
* (the default) the call carries `unwrap()`, so the body calls it instead of destructuring `data`
|
|
553
|
+
* off the full result by hand.
|
|
554
|
+
*
|
|
555
|
+
* @example
|
|
556
|
+
* ```ts
|
|
557
|
+
* buildCallResultBody(buildClientCall(node, { clientName: 'getPetById' }))
|
|
558
|
+
* // return getPetById({ ...config, throwOnError: true }).unwrap()
|
|
559
|
+
* ```
|
|
560
|
+
*/
|
|
561
|
+
function buildCallResultBody(call, options = {}) {
|
|
562
|
+
const { returnType = "full" } = options;
|
|
563
|
+
if (returnType === "data") return `return await ${call}`;
|
|
564
|
+
return `return ${call}.unwrap()`;
|
|
565
|
+
}
|
|
566
|
+
/**
|
|
545
567
|
* Builds the `TData` / `TError` type expressions shared by every generated hook, joining the resolved
|
|
546
568
|
* success responses into `TData` and wrapping the error responses in `ResponseErrorConfig<...>`.
|
|
547
569
|
*/
|
|
@@ -697,7 +719,7 @@ function buildQueryKeyParams(node, options) {
|
|
|
697
719
|
//#region ../../internals/tanstack-query/src/components/InfiniteQueryOptions.tsx
|
|
698
720
|
const declarationPrinter$7 = functionPrinter({ mode: "declaration" });
|
|
699
721
|
const callPrinter$3 = functionPrinter({ mode: "call" });
|
|
700
|
-
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName }) {
|
|
722
|
+
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName, queryKeyType = "typeof queryKey", memberTypeWrapper, unwrapName, returnType = "full" }) {
|
|
701
723
|
const { TData: queryFnDataType, TError: errorType } = buildResponseTypes(node, tsResolver);
|
|
702
724
|
const { queryParamsTypeName, pageParamType } = resolvePageParamType(node, {
|
|
703
725
|
resolver: tsResolver,
|
|
@@ -716,11 +738,11 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
716
738
|
memberTypeWrapper
|
|
717
739
|
});
|
|
718
740
|
const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
|
|
719
|
-
const queryFnBody =
|
|
741
|
+
const queryFnBody = buildCallResultBody(buildClientCall(node, {
|
|
720
742
|
clientName,
|
|
721
743
|
signal: true,
|
|
722
744
|
unwrapName
|
|
723
|
-
})}
|
|
745
|
+
}), { returnType });
|
|
724
746
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
725
747
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
726
748
|
if (hasNewParams) {
|
|
@@ -1249,7 +1271,7 @@ function buildMutationConfigParamsNode(node) {
|
|
|
1249
1271
|
default: "{}"
|
|
1250
1272
|
})] });
|
|
1251
1273
|
}
|
|
1252
|
-
function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }) {
|
|
1274
|
+
function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName, returnType = "full" }) {
|
|
1253
1275
|
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1254
1276
|
const configParamsNode = buildMutationConfigParamsNode(node);
|
|
1255
1277
|
const paramsSignature = declarationPrinter$3.print(configParamsNode) ?? "";
|
|
@@ -1258,10 +1280,10 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }
|
|
|
1258
1280
|
const groupedParamsNode = createFunctionParameters({ params: groupedParam ? [groupedParam] : [] });
|
|
1259
1281
|
const TRequest = hasMutationParams ? tsResolver.response.options(node) : "undefined";
|
|
1260
1282
|
const argBindingStr = hasMutationParams ? callPrinter$2.print(groupedParamsNode) ?? "" : "_";
|
|
1261
|
-
const mutationFnBody =
|
|
1283
|
+
const mutationFnBody = buildCallResultBody(buildClientCall(node, {
|
|
1262
1284
|
clientName,
|
|
1263
1285
|
signal: false
|
|
1264
|
-
})}
|
|
1286
|
+
}), { returnType });
|
|
1265
1287
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
1266
1288
|
name,
|
|
1267
1289
|
isExportable: true,
|
|
@@ -1429,16 +1451,16 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1429
1451
|
//#region src/components/QueryOptions.tsx
|
|
1430
1452
|
const declarationPrinter = functionPrinter({ mode: "declaration" });
|
|
1431
1453
|
const callPrinter = functionPrinter({ mode: "call" });
|
|
1432
|
-
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
|
|
1454
|
+
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName, returnType = "full" }) {
|
|
1433
1455
|
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
1434
1456
|
const queryKeyParamsNode = buildQueryKeyParams(node, { resolver: tsResolver });
|
|
1435
1457
|
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
|
|
1436
1458
|
const paramsNode = buildQueryOptionsParams(node, { resolver: tsResolver });
|
|
1437
1459
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
1438
|
-
const queryFnBody =
|
|
1460
|
+
const queryFnBody = buildCallResultBody(buildClientCall(node, {
|
|
1439
1461
|
clientName,
|
|
1440
1462
|
signal: true
|
|
1441
|
-
})}
|
|
1463
|
+
}), { returnType });
|
|
1442
1464
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
1443
1465
|
name,
|
|
1444
1466
|
isExportable: true,
|
|
@@ -1606,7 +1628,8 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1606
1628
|
nextParam: infiniteOptions.nextParam,
|
|
1607
1629
|
previousParam: infiniteOptions.previousParam,
|
|
1608
1630
|
initialPageParam: infiniteOptions.initialPageParam,
|
|
1609
|
-
queryParam: infiniteOptions.queryParam
|
|
1631
|
+
queryParam: infiniteOptions.queryParam,
|
|
1632
|
+
returnType: contractOp.returnType
|
|
1610
1633
|
}),
|
|
1611
1634
|
/* @__PURE__ */ jsx(File.Import, {
|
|
1612
1635
|
name: ["useInfiniteQuery"],
|
|
@@ -1754,7 +1777,8 @@ const mutationGenerator = defineGenerator({
|
|
|
1754
1777
|
clientName: calledClientName,
|
|
1755
1778
|
mutationKeyName,
|
|
1756
1779
|
node,
|
|
1757
|
-
tsResolver
|
|
1780
|
+
tsResolver,
|
|
1781
|
+
returnType: contractOp.returnType
|
|
1758
1782
|
}),
|
|
1759
1783
|
mutation && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1760
1784
|
/* @__PURE__ */ jsx(File.Import, {
|
|
@@ -1905,7 +1929,8 @@ const queryGenerator = defineGenerator({
|
|
|
1905
1929
|
clientName: calledClientName,
|
|
1906
1930
|
queryKeyName,
|
|
1907
1931
|
node,
|
|
1908
|
-
tsResolver
|
|
1932
|
+
tsResolver,
|
|
1933
|
+
returnType: contractOp.returnType
|
|
1909
1934
|
}),
|
|
1910
1935
|
query && hooks && /* @__PURE__ */ jsxs(Fragment, { children: [
|
|
1911
1936
|
/* @__PURE__ */ jsx(File.Import, {
|
|
@@ -2078,7 +2103,8 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
|
2078
2103
|
nextParam: infiniteOptions.nextParam,
|
|
2079
2104
|
previousParam: infiniteOptions.previousParam,
|
|
2080
2105
|
initialPageParam: infiniteOptions.initialPageParam,
|
|
2081
|
-
queryParam: infiniteOptions.queryParam
|
|
2106
|
+
queryParam: infiniteOptions.queryParam,
|
|
2107
|
+
returnType: contractOp.returnType
|
|
2082
2108
|
}),
|
|
2083
2109
|
/* @__PURE__ */ jsx(File.Import, {
|
|
2084
2110
|
name: ["useSuspenseInfiniteQuery"],
|
|
@@ -2233,7 +2259,8 @@ const suspenseQueryGenerator = defineGenerator({
|
|
|
2233
2259
|
clientName: calledClientName,
|
|
2234
2260
|
queryKeyName,
|
|
2235
2261
|
node,
|
|
2236
|
-
tsResolver
|
|
2262
|
+
tsResolver,
|
|
2263
|
+
returnType: contractOp.returnType
|
|
2237
2264
|
}),
|
|
2238
2265
|
/* @__PURE__ */ jsx(File.Import, {
|
|
2239
2266
|
name: ["useSuspenseQuery"],
|