@kubb/plugin-react-query 5.0.0-beta.103 → 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 +4 -4
package/dist/index.js
CHANGED
|
@@ -136,13 +136,24 @@ function buildOperationComments(node, options = {}) {
|
|
|
136
136
|
if (!splitLines) return filteredComments;
|
|
137
137
|
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
138
138
|
}
|
|
139
|
+
const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
140
|
+
/**
|
|
141
|
+
* Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
|
|
142
|
+
* group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
|
|
143
|
+
* (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
|
|
144
|
+
* same parameters once per plugin.
|
|
145
|
+
*/
|
|
139
146
|
function getOperationParameters(node) {
|
|
140
|
-
|
|
147
|
+
const cached = operationParameterGroupsByNode.get(node);
|
|
148
|
+
if (cached) return cached;
|
|
149
|
+
const groups = {
|
|
141
150
|
path: dedupeParams(node.parameters.filter((param) => param.in === "path")),
|
|
142
151
|
query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
|
|
143
152
|
header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
|
|
144
153
|
cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
|
|
145
154
|
};
|
|
155
|
+
operationParameterGroupsByNode.set(node, groups);
|
|
156
|
+
return groups;
|
|
146
157
|
}
|
|
147
158
|
function getStatusCodeNumber(statusCode) {
|
|
148
159
|
const code = Number(statusCode);
|
|
@@ -1421,22 +1432,28 @@ function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
|
|
|
1421
1432
|
const infiniteQueryGenerator = defineGenerator({
|
|
1422
1433
|
name: "react-infinite-query",
|
|
1423
1434
|
renderer: jsxRenderer,
|
|
1435
|
+
match(node, ctx) {
|
|
1436
|
+
const operationNode = node;
|
|
1437
|
+
if (!ast.isHttpOperationNode(operationNode)) return false;
|
|
1438
|
+
const { query, mutation, infinite, hooks } = ctx.options;
|
|
1439
|
+
const { isQuery, isMutation } = classifyOperation(operationNode, {
|
|
1440
|
+
query,
|
|
1441
|
+
mutation
|
|
1442
|
+
});
|
|
1443
|
+
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
1444
|
+
if (!isQuery || isMutation || !infiniteOptions || !hooks) return false;
|
|
1445
|
+
const queryParamKeys = getOperationParameters(operationNode).query.map((p) => p.name);
|
|
1446
|
+
return infiniteOptions.queryParam ? queryParamKeys.includes(infiniteOptions.queryParam) || queryParamKeys.includes(`${infiniteOptions.queryParam}?`) : false;
|
|
1447
|
+
},
|
|
1424
1448
|
operation(node, ctx) {
|
|
1425
1449
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1426
1450
|
const { config, driver, resolver, root } = ctx;
|
|
1427
|
-
const { output, query,
|
|
1451
|
+
const { output, query, infinite, client, group, customOptions } = ctx.options;
|
|
1428
1452
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1429
1453
|
if (!pluginTs) return null;
|
|
1430
1454
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
1431
|
-
const { isQuery, isMutation } = classifyOperation(node, {
|
|
1432
|
-
query,
|
|
1433
|
-
mutation
|
|
1434
|
-
});
|
|
1435
1455
|
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
1436
|
-
if (!
|
|
1437
|
-
const normalizeKey = (key) => key.replace(/\?$/, "");
|
|
1438
|
-
const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
|
|
1439
|
-
if (!(infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false)) return null;
|
|
1456
|
+
if (!infiniteOptions) return null;
|
|
1440
1457
|
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
1441
1458
|
const contractOp = resolveClientOperation({
|
|
1442
1459
|
clientPlugin: { pluginName: client.pluginName },
|
|
@@ -1588,18 +1605,22 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1588
1605
|
const mutationGenerator = defineGenerator({
|
|
1589
1606
|
name: "react-query-mutation",
|
|
1590
1607
|
renderer: jsxRenderer,
|
|
1608
|
+
match(node, ctx) {
|
|
1609
|
+
const operationNode = node;
|
|
1610
|
+
if (!ast.isHttpOperationNode(operationNode)) return false;
|
|
1611
|
+
const { query, mutation } = ctx.options;
|
|
1612
|
+
return classifyOperation(operationNode, {
|
|
1613
|
+
query,
|
|
1614
|
+
mutation
|
|
1615
|
+
}).isMutation;
|
|
1616
|
+
},
|
|
1591
1617
|
operation(node, ctx) {
|
|
1592
1618
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1593
1619
|
const { config, driver, resolver, root } = ctx;
|
|
1594
|
-
const { output,
|
|
1620
|
+
const { output, mutation, client, group, customOptions, hooks } = ctx.options;
|
|
1595
1621
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1596
1622
|
if (!pluginTs) return null;
|
|
1597
1623
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
1598
|
-
const { isMutation } = classifyOperation(node, {
|
|
1599
|
-
query,
|
|
1600
|
-
mutation
|
|
1601
|
-
});
|
|
1602
|
-
if (!isMutation) return null;
|
|
1603
1624
|
const importPath = mutation ? mutation.importPath : "@tanstack/react-query";
|
|
1604
1625
|
const contractOp = resolveClientOperation({
|
|
1605
1626
|
clientPlugin: { pluginName: client.pluginName },
|
|
@@ -1728,18 +1749,23 @@ const mutationGenerator = defineGenerator({
|
|
|
1728
1749
|
const queryGenerator = defineGenerator({
|
|
1729
1750
|
name: "react-query",
|
|
1730
1751
|
renderer: jsxRenderer,
|
|
1752
|
+
match(node, ctx) {
|
|
1753
|
+
const operationNode = node;
|
|
1754
|
+
if (!ast.isHttpOperationNode(operationNode)) return false;
|
|
1755
|
+
const { query, mutation } = ctx.options;
|
|
1756
|
+
const { isQuery, isMutation } = classifyOperation(operationNode, {
|
|
1757
|
+
query,
|
|
1758
|
+
mutation
|
|
1759
|
+
});
|
|
1760
|
+
return isQuery && !isMutation;
|
|
1761
|
+
},
|
|
1731
1762
|
operation(node, ctx) {
|
|
1732
1763
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1733
1764
|
const { config, driver, resolver, root } = ctx;
|
|
1734
|
-
const { output, query,
|
|
1765
|
+
const { output, query, client, group, customOptions, hooks } = ctx.options;
|
|
1735
1766
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1736
1767
|
if (!pluginTs) return null;
|
|
1737
1768
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
1738
|
-
const { isQuery, isMutation } = classifyOperation(node, {
|
|
1739
|
-
query,
|
|
1740
|
-
mutation
|
|
1741
|
-
});
|
|
1742
|
-
if (!isQuery || isMutation) return null;
|
|
1743
1769
|
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
1744
1770
|
const contractOp = resolveClientOperation({
|
|
1745
1771
|
clientPlugin: { pluginName: client.pluginName },
|
|
@@ -1873,23 +1899,28 @@ const queryGenerator = defineGenerator({
|
|
|
1873
1899
|
const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
1874
1900
|
name: "react-suspense-infinite-query",
|
|
1875
1901
|
renderer: jsxRenderer,
|
|
1902
|
+
match(node, ctx) {
|
|
1903
|
+
const operationNode = node;
|
|
1904
|
+
if (!ast.isHttpOperationNode(operationNode)) return false;
|
|
1905
|
+
const { query, mutation, infinite, suspense, hooks } = ctx.options;
|
|
1906
|
+
const { isQuery, isMutation } = classifyOperation(operationNode, {
|
|
1907
|
+
query,
|
|
1908
|
+
mutation
|
|
1909
|
+
});
|
|
1910
|
+
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
1911
|
+
if (!isQuery || isMutation || !suspense || !infiniteOptions || !hooks) return false;
|
|
1912
|
+
const queryParamKeys = getOperationParameters(operationNode).query.map((p) => p.name);
|
|
1913
|
+
return infiniteOptions.queryParam ? queryParamKeys.includes(infiniteOptions.queryParam) || queryParamKeys.includes(`${infiniteOptions.queryParam}?`) : false;
|
|
1914
|
+
},
|
|
1876
1915
|
operation(node, ctx) {
|
|
1877
1916
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
1878
1917
|
const { config, driver, resolver, root } = ctx;
|
|
1879
|
-
const { output, query,
|
|
1918
|
+
const { output, query, infinite, client, group, customOptions } = ctx.options;
|
|
1880
1919
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
1881
1920
|
if (!pluginTs) return null;
|
|
1882
1921
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
1883
|
-
const { isQuery, isMutation } = classifyOperation(node, {
|
|
1884
|
-
query,
|
|
1885
|
-
mutation
|
|
1886
|
-
});
|
|
1887
|
-
const isSuspense = !!suspense;
|
|
1888
1922
|
const infiniteOptions = infinite && typeof infinite === "object" ? infinite : null;
|
|
1889
|
-
if (!
|
|
1890
|
-
const normalizeKey = (key) => key.replace(/\?$/, "");
|
|
1891
|
-
const queryParamKeys = getOperationParameters(node).query.map((p) => p.name);
|
|
1892
|
-
if (!(infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false)) return null;
|
|
1923
|
+
if (!infiniteOptions) return null;
|
|
1893
1924
|
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
1894
1925
|
const contractOp = resolveClientOperation({
|
|
1895
1926
|
clientPlugin: { pluginName: client.pluginName },
|
|
@@ -2040,18 +2071,23 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
|
2040
2071
|
const suspenseQueryGenerator = defineGenerator({
|
|
2041
2072
|
name: "react-suspense-query",
|
|
2042
2073
|
renderer: jsxRenderer,
|
|
2074
|
+
match(node, ctx) {
|
|
2075
|
+
const operationNode = node;
|
|
2076
|
+
if (!ast.isHttpOperationNode(operationNode)) return false;
|
|
2077
|
+
const { query, mutation, suspense, hooks } = ctx.options;
|
|
2078
|
+
const { isQuery, isMutation } = classifyOperation(operationNode, {
|
|
2079
|
+
query,
|
|
2080
|
+
mutation
|
|
2081
|
+
});
|
|
2082
|
+
return isQuery && !isMutation && !!suspense && hooks;
|
|
2083
|
+
},
|
|
2043
2084
|
operation(node, ctx) {
|
|
2044
2085
|
if (!ast.isHttpOperationNode(node)) return null;
|
|
2045
2086
|
const { config, driver, resolver, root } = ctx;
|
|
2046
|
-
const { output, query,
|
|
2087
|
+
const { output, query, client, group, customOptions } = ctx.options;
|
|
2047
2088
|
const pluginTs = driver.getPlugin(pluginTsName);
|
|
2048
2089
|
if (!pluginTs) return null;
|
|
2049
2090
|
const tsResolver = driver.getResolver(pluginTsName);
|
|
2050
|
-
const { isQuery, isMutation } = classifyOperation(node, {
|
|
2051
|
-
query,
|
|
2052
|
-
mutation
|
|
2053
|
-
});
|
|
2054
|
-
if (!isQuery || isMutation || !!!suspense || !hooks) return null;
|
|
2055
2091
|
const importPath = query ? query.importPath : "@tanstack/react-query";
|
|
2056
2092
|
const contractOp = resolveClientOperation({
|
|
2057
2093
|
clientPlugin: { pluginName: client.pluginName },
|