@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.cjs
CHANGED
|
@@ -690,6 +690,24 @@ function resolveOperationOverrides(node, override) {
|
|
|
690
690
|
return override.find((ov) => matchesPattern(node, ov))?.options ?? {};
|
|
691
691
|
}
|
|
692
692
|
/**
|
|
693
|
+
* The request groups a query key is built from, matching `buildQueryKeyParams`. Headers are
|
|
694
|
+
* deliberately absent: they do not identify a cache entry, so the key factory takes no parameter
|
|
695
|
+
* for an operation that only carries headers.
|
|
696
|
+
*/
|
|
697
|
+
const queryKeyGroupOrder = [
|
|
698
|
+
"path",
|
|
699
|
+
"query",
|
|
700
|
+
"body"
|
|
701
|
+
];
|
|
702
|
+
/**
|
|
703
|
+
* Whether the generated query key factory declares a parameter, so a call site passes an argument
|
|
704
|
+
* only when one is accepted.
|
|
705
|
+
*/
|
|
706
|
+
function hasQueryKeyParams(node) {
|
|
707
|
+
const groups = getRequestGroups(node);
|
|
708
|
+
return queryKeyGroupOrder.some((key) => groups[key]);
|
|
709
|
+
}
|
|
710
|
+
/**
|
|
693
711
|
* Build QueryKey params as the grouped `{ path, query, body }` object (NO headers, NO config),
|
|
694
712
|
* typed from the operation's `Options` minus `url`. The query key transformer reads the
|
|
695
713
|
* grouped `path`/`query`/`body` bindings.
|
|
@@ -698,11 +716,7 @@ function buildQueryKeyParams(node, options) {
|
|
|
698
716
|
const { resolver } = options;
|
|
699
717
|
const groupedParam = buildGroupedRequestParam(node, {
|
|
700
718
|
resolver,
|
|
701
|
-
keys:
|
|
702
|
-
"path",
|
|
703
|
-
"query",
|
|
704
|
-
"body"
|
|
705
|
-
]
|
|
719
|
+
keys: queryKeyGroupOrder
|
|
706
720
|
});
|
|
707
721
|
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
|
|
708
722
|
}
|
|
@@ -719,11 +733,7 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
719
733
|
});
|
|
720
734
|
const groupedKeyParam = buildGroupedRequestParam(node, {
|
|
721
735
|
resolver: tsResolver,
|
|
722
|
-
keys:
|
|
723
|
-
"path",
|
|
724
|
-
"query",
|
|
725
|
-
"body"
|
|
726
|
-
],
|
|
736
|
+
keys: queryKeyGroupOrder,
|
|
727
737
|
memberTypeWrapper
|
|
728
738
|
});
|
|
729
739
|
const queryKeyParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedKeyParam ? [groupedKeyParam] : [] });
|
|
@@ -733,12 +743,11 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
733
743
|
memberTypeWrapper
|
|
734
744
|
});
|
|
735
745
|
const paramsSignature = declarationPrinter$7.print(paramsNode) ?? "";
|
|
736
|
-
const queryFnBody = `
|
|
746
|
+
const queryFnBody = `return ${buildClientCall(node, {
|
|
737
747
|
clientName,
|
|
738
748
|
signal: true,
|
|
739
749
|
unwrapName
|
|
740
|
-
})}
|
|
741
|
-
return data`;
|
|
750
|
+
})}.unwrap()`;
|
|
742
751
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
743
752
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
744
753
|
if (hasNewParams) {
|
|
@@ -1219,7 +1228,7 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1219
1228
|
`TPageParam = ${pageParamType}`
|
|
1220
1229
|
];
|
|
1221
1230
|
const resolvedParams = buildResolvedRequestParams(node);
|
|
1222
|
-
const queryKeyArgs = resolvedParams ? "resolvedParams" : "";
|
|
1231
|
+
const queryKeyArgs = resolvedParams && hasQueryKeyParams(node) ? "resolvedParams" : "";
|
|
1223
1232
|
const queryOptionsArgs = resolvedParams ? "resolvedParams, config" : "config";
|
|
1224
1233
|
const paramsNode = buildInfiniteQueryParamsNode(node, {
|
|
1225
1234
|
resolver: tsResolver,
|
|
@@ -1276,11 +1285,10 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }
|
|
|
1276
1285
|
const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
|
|
1277
1286
|
const TRequest = hasMutationParams ? tsResolver.response.options(node) : "undefined";
|
|
1278
1287
|
const argBindingStr = hasMutationParams ? callPrinter$2.print(groupedParamsNode) ?? "" : "_";
|
|
1279
|
-
const mutationFnBody = `
|
|
1288
|
+
const mutationFnBody = `return ${buildClientCall(node, {
|
|
1280
1289
|
clientName,
|
|
1281
1290
|
signal: false
|
|
1282
|
-
})}
|
|
1283
|
-
return data`;
|
|
1291
|
+
})}.unwrap()`;
|
|
1284
1292
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1285
1293
|
name,
|
|
1286
1294
|
isExportable: true,
|
|
@@ -1408,7 +1416,7 @@ function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, t
|
|
|
1408
1416
|
`TQueryKey extends QueryKey = ${queryKeyTypeName}`
|
|
1409
1417
|
];
|
|
1410
1418
|
const resolvedParams = buildResolvedRequestParams(node);
|
|
1411
|
-
const queryKeyArgs = resolvedParams ? "resolvedParams" : "";
|
|
1419
|
+
const queryKeyArgs = resolvedParams && hasQueryKeyParams(node) ? "resolvedParams" : "";
|
|
1412
1420
|
const queryOptionsArgs = resolvedParams ? "resolvedParams, config" : "config";
|
|
1413
1421
|
const paramsNode = buildQueryParamsNode(node, {
|
|
1414
1422
|
resolver: tsResolver,
|
|
@@ -1454,11 +1462,10 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
|
|
|
1454
1462
|
const queryKeyParamsCall = callPrinter.print(queryKeyParamsNode) ?? "";
|
|
1455
1463
|
const paramsNode = buildQueryOptionsParams(node, { resolver: tsResolver });
|
|
1456
1464
|
const paramsSignature = declarationPrinter.print(paramsNode) ?? "";
|
|
1457
|
-
const queryFnBody = `
|
|
1465
|
+
const queryFnBody = `return ${buildClientCall(node, {
|
|
1458
1466
|
clientName,
|
|
1459
1467
|
signal: true
|
|
1460
|
-
})}
|
|
1461
|
-
return data`;
|
|
1468
|
+
})}.unwrap()`;
|
|
1462
1469
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
1463
1470
|
name,
|
|
1464
1471
|
isExportable: true,
|