@kubb/plugin-react-query 5.0.0 → 5.0.2
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 +28 -21
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +28 -21
- package/dist/index.js.map +1 -1
- package/package.json +15 -4
package/dist/index.js
CHANGED
|
@@ -663,6 +663,24 @@ function resolveOperationOverrides(node, override) {
|
|
|
663
663
|
return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
|
|
664
664
|
}
|
|
665
665
|
/**
|
|
666
|
+
* The request groups a query key is built from, matching `buildQueryKeyParams`. Headers are
|
|
667
|
+
* deliberately absent: they do not identify a cache entry, so the key factory takes no parameter
|
|
668
|
+
* for an operation that only carries headers.
|
|
669
|
+
*/
|
|
670
|
+
const queryKeyGroupOrder = [
|
|
671
|
+
"path",
|
|
672
|
+
"query",
|
|
673
|
+
"body"
|
|
674
|
+
];
|
|
675
|
+
/**
|
|
676
|
+
* Whether the generated query key factory declares a parameter, so a call site passes an argument
|
|
677
|
+
* only when one is accepted.
|
|
678
|
+
*/
|
|
679
|
+
function hasQueryKeyParams(node) {
|
|
680
|
+
const groups = getRequestGroups(node);
|
|
681
|
+
return queryKeyGroupOrder.some((key) => groups[key]);
|
|
682
|
+
}
|
|
683
|
+
/**
|
|
666
684
|
* Build QueryKey params as the grouped `{ path, query, body }` object (NO headers, NO config),
|
|
667
685
|
* typed from the operation's `Options` minus `url`. The query key transformer reads the
|
|
668
686
|
* grouped `path`/`query`/`body` bindings.
|
|
@@ -671,11 +689,7 @@ function buildQueryKeyParams(node, options) {
|
|
|
671
689
|
const { resolver } = options;
|
|
672
690
|
const groupedParam = buildGroupedRequestParam(node, {
|
|
673
691
|
resolver,
|
|
674
|
-
keys:
|
|
675
|
-
"path",
|
|
676
|
-
"query",
|
|
677
|
-
"body"
|
|
678
|
-
]
|
|
692
|
+
keys: queryKeyGroupOrder
|
|
679
693
|
});
|
|
680
694
|
return createFunctionParameters({ params: groupedParam ? [groupedParam] : [] });
|
|
681
695
|
}
|
|
@@ -692,11 +706,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
692
706
|
});
|
|
693
707
|
const groupedKeyParam = buildGroupedRequestParam(node, {
|
|
694
708
|
resolver: tsResolver,
|
|
695
|
-
keys:
|
|
696
|
-
"path",
|
|
697
|
-
"query",
|
|
698
|
-
"body"
|
|
699
|
-
],
|
|
709
|
+
keys: queryKeyGroupOrder,
|
|
700
710
|
memberTypeWrapper
|
|
701
711
|
});
|
|
702
712
|
const queryKeyParamsNode = createFunctionParameters({ params: groupedKeyParam ? [groupedKeyParam] : [] });
|
|
@@ -706,12 +716,11 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
706
716
|
memberTypeWrapper
|
|
707
717
|
});
|
|
708
718
|
const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
|
|
709
|
-
const queryFnBody = `
|
|
719
|
+
const queryFnBody = `return ${buildClientCall(node, {
|
|
710
720
|
clientName,
|
|
711
721
|
signal: true,
|
|
712
722
|
unwrapName
|
|
713
|
-
})}
|
|
714
|
-
return data`;
|
|
723
|
+
})}.unwrap()`;
|
|
715
724
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
716
725
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
717
726
|
if (hasNewParams) {
|
|
@@ -1192,7 +1201,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1192
1201
|
`TPageParam = ${pageParamType}`
|
|
1193
1202
|
];
|
|
1194
1203
|
const resolvedParams = buildResolvedRequestParams(node);
|
|
1195
|
-
const queryKeyArgs = resolvedParams ? "resolvedParams" : "";
|
|
1204
|
+
const queryKeyArgs = resolvedParams && hasQueryKeyParams(node) ? "resolvedParams" : "";
|
|
1196
1205
|
const queryOptionsArgs = resolvedParams ? "resolvedParams, config" : "config";
|
|
1197
1206
|
const paramsNode = buildInfiniteQueryParamsNode(node, {
|
|
1198
1207
|
resolver: tsResolver,
|
|
@@ -1249,11 +1258,10 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }
|
|
|
1249
1258
|
const groupedParamsNode = createFunctionParameters({ params: groupedParam ? [groupedParam] : [] });
|
|
1250
1259
|
const TRequest = hasMutationParams ? tsResolver.response.options(node) : "undefined";
|
|
1251
1260
|
const argBindingStr = hasMutationParams ? callPrinter$2.print(groupedParamsNode) ?? "" : "_";
|
|
1252
|
-
const mutationFnBody = `
|
|
1261
|
+
const mutationFnBody = `return ${buildClientCall(node, {
|
|
1253
1262
|
clientName,
|
|
1254
1263
|
signal: false
|
|
1255
|
-
})}
|
|
1256
|
-
return data`;
|
|
1264
|
+
})}.unwrap()`;
|
|
1257
1265
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
1258
1266
|
name,
|
|
1259
1267
|
isExportable: true,
|
|
@@ -1381,7 +1389,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1381
1389
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
1382
1390
|
];
|
|
1383
1391
|
const resolvedParams = buildResolvedRequestParams(node);
|
|
1384
|
-
const queryKeyArgs = resolvedParams ? "resolvedParams" : "";
|
|
1392
|
+
const queryKeyArgs = resolvedParams && hasQueryKeyParams(node) ? "resolvedParams" : "";
|
|
1385
1393
|
const queryOptionsArgs = resolvedParams ? "resolvedParams, config" : "config";
|
|
1386
1394
|
const paramsNode = buildQueryParamsNode(node, {
|
|
1387
1395
|
resolver: tsResolver,
|
|
@@ -1427,11 +1435,10 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
|
|
|
1427
1435
|
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
|
|
1428
1436
|
const paramsNode = buildQueryOptionsParams(node, { resolver: tsResolver });
|
|
1429
1437
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
1430
|
-
const queryFnBody = `
|
|
1438
|
+
const queryFnBody = `return ${buildClientCall(node, {
|
|
1431
1439
|
clientName,
|
|
1432
1440
|
signal: true
|
|
1433
|
-
})}
|
|
1434
|
-
return data`;
|
|
1441
|
+
})}.unwrap()`;
|
|
1435
1442
|
return /* @__PURE__ */ jsx(File.Source, {
|
|
1436
1443
|
name,
|
|
1437
1444
|
isExportable: true,
|