@kubb/plugin-react-query 5.0.0-beta.101 → 5.0.0-beta.104
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 +74 -38
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +74 -38
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -163,13 +163,24 @@ function buildOperationComments(node, options = {}) {
|
|
|
163
163
|
if (!splitLines) return filteredComments;
|
|
164
164
|
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
165
165
|
}
|
|
166
|
+
const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
167
|
+
/**
|
|
168
|
+
* Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
|
|
169
|
+
* group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
|
|
170
|
+
* (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
|
|
171
|
+
* same parameters once per plugin.
|
|
172
|
+
*/
|
|
166
173
|
function getOperationParameters(node) {
|
|
167
|
-
|
|
174
|
+
const cached = operationParameterGroupsByNode.get(node);
|
|
175
|
+
if (cached) return cached;
|
|
176
|
+
const groups = {
|
|
168
177
|
path: dedupeParams(node.parameters.filter((param) => param.in === "path")),
|
|
169
178
|
query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
|
|
170
179
|
header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
|
|
171
180
|
cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
|
|
172
181
|
};
|
|
182
|
+
operationParameterGroupsByNode.set(node, groups);
|
|
183
|
+
return groups;
|
|
173
184
|
}
|
|
174
185
|
function getStatusCodeNumber(statusCode) {
|
|
175
186
|
const code = Number(statusCode);
|
|
@@ -1448,22 +1459,28 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
|
|
|
1448
1459
|
const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
1449
1460
|
name: "react-infinite-query",
|
|
1450
1461
|
renderer: kubb_jsx.jsxRenderer,
|
|
1462
|
+
match(node, ctx) {
|
|
1463
|
+
const operationNode = node;
|
|
1464
|
+
if (!kubb_kit.ast.isHttpOperationNode(operationNode)) return false;
|
|
1465
|
+
const { query, mutation, infinite, hooks } = ctx.options;
|
|
1466
|
+
const { isQuery, isMutation } = classifyOperation(operationNode, {
|
|
1467
|
+
query,
|
|
1468
|
+
mutation
|
|
1469
|
+
});
|
|
1470
|
+
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
1471
|
+
if (!isQuery || isMutation || !infiniteOptions || !hooks) return false;
|
|
1472
|
+
const queryParamKeys = getOperationParameters(operationNode).query.map((p) => p.name);
|
|
1473
|
+
return infiniteOptions.queryParam ? queryParamKeys.includes(infiniteOptions.queryParam) || queryParamKeys.includes(`${infiniteOptions.queryParam}?`) : false;
|
|
1474
|
+
},
|
|
1451
1475
|
operation(node, ctx) {
|
|
1452
1476
|
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1453
1477
|
const { config, driver, resolver, root } = ctx;
|
|
1454
|
-
const { output, query,
|
|
1478
|
+
const { output, query, infinite, client, group, customOptions } = ctx.options;
|
|
1455
1479
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
1456
1480
|
if (!pluginTs) return null;
|
|
1457
1481
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
1458
|
-
const { isQuery, isMutation } = classifyOperation(node, {
|
|
1459
|
-
query,
|
|
1460
|
-
mutation
|
|
1461
|
-
});
|
|
1462
1482
|
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
1463
|
-
if (!
|
|
1464
|
-
const normalizeKey = (key) => key.replace(/\?$/, "");
|
|
1465
|
-
const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
|
|
1466
|
-
if (!(infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false)) return null;
|
|
1483
|
+
if (!infiniteOptions) return null;
|
|
1467
1484
|
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
1468
1485
|
const contractOp = resolveClientOperation({
|
|
1469
1486
|
clientPlugin: { pluginName: client.pluginName },
|
|
@@ -1615,18 +1632,22 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1615
1632
|
const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
1616
1633
|
name: "react-query-mutation",
|
|
1617
1634
|
renderer: kubb_jsx.jsxRenderer,
|
|
1635
|
+
match(node, ctx) {
|
|
1636
|
+
const operationNode = node;
|
|
1637
|
+
if (!kubb_kit.ast.isHttpOperationNode(operationNode)) return false;
|
|
1638
|
+
const { query, mutation } = ctx.options;
|
|
1639
|
+
return classifyOperation(operationNode, {
|
|
1640
|
+
query,
|
|
1641
|
+
mutation
|
|
1642
|
+
}).isMutation;
|
|
1643
|
+
},
|
|
1618
1644
|
operation(node, ctx) {
|
|
1619
1645
|
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1620
1646
|
const { config, driver, resolver, root } = ctx;
|
|
1621
|
-
const { output,
|
|
1647
|
+
const { output, mutation, client, group, customOptions, hooks } = ctx.options;
|
|
1622
1648
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
1623
1649
|
if (!pluginTs) return null;
|
|
1624
1650
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
1625
|
-
const { isMutation } = classifyOperation(node, {
|
|
1626
|
-
query,
|
|
1627
|
-
mutation
|
|
1628
|
-
});
|
|
1629
|
-
if (!isMutation) return null;
|
|
1630
1651
|
const importPath = mutation ? mutation.importPath : "@tanstack/react-query";
|
|
1631
1652
|
const contractOp = resolveClientOperation({
|
|
1632
1653
|
clientPlugin: { pluginName: client.pluginName },
|
|
@@ -1755,18 +1776,23 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1755
1776
|
const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
1756
1777
|
name: "react-query",
|
|
1757
1778
|
renderer: kubb_jsx.jsxRenderer,
|
|
1779
|
+
match(node, ctx) {
|
|
1780
|
+
const operationNode = node;
|
|
1781
|
+
if (!kubb_kit.ast.isHttpOperationNode(operationNode)) return false;
|
|
1782
|
+
const { query, mutation } = ctx.options;
|
|
1783
|
+
const { isQuery, isMutation } = classifyOperation(operationNode, {
|
|
1784
|
+
query,
|
|
1785
|
+
mutation
|
|
1786
|
+
});
|
|
1787
|
+
return isQuery && !isMutation;
|
|
1788
|
+
},
|
|
1758
1789
|
operation(node, ctx) {
|
|
1759
1790
|
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1760
1791
|
const { config, driver, resolver, root } = ctx;
|
|
1761
|
-
const { output, query,
|
|
1792
|
+
const { output, query, client, group, customOptions, hooks } = ctx.options;
|
|
1762
1793
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
1763
1794
|
if (!pluginTs) return null;
|
|
1764
1795
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
1765
|
-
const { isQuery, isMutation } = classifyOperation(node, {
|
|
1766
|
-
query,
|
|
1767
|
-
mutation
|
|
1768
|
-
});
|
|
1769
|
-
if (!isQuery || isMutation) return null;
|
|
1770
1796
|
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
1771
1797
|
const contractOp = resolveClientOperation({
|
|
1772
1798
|
clientPlugin: { pluginName: client.pluginName },
|
|
@@ -1900,23 +1926,28 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1900
1926
|
const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
1901
1927
|
name: "react-suspense-infinite-query",
|
|
1902
1928
|
renderer: kubb_jsx.jsxRenderer,
|
|
1929
|
+
match(node, ctx) {
|
|
1930
|
+
const operationNode = node;
|
|
1931
|
+
if (!kubb_kit.ast.isHttpOperationNode(operationNode)) return false;
|
|
1932
|
+
const { query, mutation, infinite, suspense, hooks } = ctx.options;
|
|
1933
|
+
const { isQuery, isMutation } = classifyOperation(operationNode, {
|
|
1934
|
+
query,
|
|
1935
|
+
mutation
|
|
1936
|
+
});
|
|
1937
|
+
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
1938
|
+
if (!isQuery || isMutation || !suspense || !infiniteOptions || !hooks) return false;
|
|
1939
|
+
const queryParamKeys = getOperationParameters(operationNode).query.map((p) => p.name);
|
|
1940
|
+
return infiniteOptions.queryParam ? queryParamKeys.includes(infiniteOptions.queryParam) || queryParamKeys.includes(`${infiniteOptions.queryParam}?`) : false;
|
|
1941
|
+
},
|
|
1903
1942
|
operation(node, ctx) {
|
|
1904
1943
|
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
1905
1944
|
const { config, driver, resolver, root } = ctx;
|
|
1906
|
-
const { output, query,
|
|
1945
|
+
const { output, query, infinite, client, group, customOptions } = ctx.options;
|
|
1907
1946
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
1908
1947
|
if (!pluginTs) return null;
|
|
1909
1948
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
1910
|
-
const { isQuery, isMutation } = classifyOperation(node, {
|
|
1911
|
-
query,
|
|
1912
|
-
mutation
|
|
1913
|
-
});
|
|
1914
|
-
const isSuspense = !!suspense;
|
|
1915
1949
|
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
1916
|
-
if (!
|
|
1917
|
-
const normalizeKey = (key) => key.replace(/\?$/, "");
|
|
1918
|
-
const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
|
|
1919
|
-
if (!(infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false)) return null;
|
|
1950
|
+
if (!infiniteOptions) return null;
|
|
1920
1951
|
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
1921
1952
|
const contractOp = resolveClientOperation({
|
|
1922
1953
|
clientPlugin: { pluginName: client.pluginName },
|
|
@@ -2067,18 +2098,23 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2067
2098
|
const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
2068
2099
|
name: "react-suspense-query",
|
|
2069
2100
|
renderer: kubb_jsx.jsxRenderer,
|
|
2101
|
+
match(node, ctx) {
|
|
2102
|
+
const operationNode = node;
|
|
2103
|
+
if (!kubb_kit.ast.isHttpOperationNode(operationNode)) return false;
|
|
2104
|
+
const { query, mutation, suspense, hooks } = ctx.options;
|
|
2105
|
+
const { isQuery, isMutation } = classifyOperation(operationNode, {
|
|
2106
|
+
query,
|
|
2107
|
+
mutation
|
|
2108
|
+
});
|
|
2109
|
+
return isQuery && !isMutation && !!suspense && hooks;
|
|
2110
|
+
},
|
|
2070
2111
|
operation(node, ctx) {
|
|
2071
2112
|
if (!kubb_kit.ast.isHttpOperationNode(node)) return null;
|
|
2072
2113
|
const { config, driver, resolver, root } = ctx;
|
|
2073
|
-
const { output, query,
|
|
2114
|
+
const { output, query, client, group, customOptions } = ctx.options;
|
|
2074
2115
|
const pluginTs = driver.getPlugin(_kubb_plugin_ts.pluginTsName);
|
|
2075
2116
|
if (!pluginTs) return null;
|
|
2076
2117
|
const tsResolver = driver.getResolver(_kubb_plugin_ts.pluginTsName);
|
|
2077
|
-
const { isQuery, isMutation } = classifyOperation(node, {
|
|
2078
|
-
query,
|
|
2079
|
-
mutation
|
|
2080
|
-
});
|
|
2081
|
-
if (!isQuery || isMutation || !!!suspense || !hooks) return null;
|
|
2082
2118
|
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
2083
2119
|
const contractOp = resolveClientOperation({
|
|
2084
2120
|
clientPlugin: { pluginName: client.pluginName },
|