@kubb/plugin-react-query 5.0.0-beta.104 → 5.0.0-beta.105
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 +75 -33
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +75 -33
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -43,6 +43,26 @@ function operationFileEntry(node, name, extname = ".ts") {
|
|
|
43
43
|
path: node.path
|
|
44
44
|
};
|
|
45
45
|
}
|
|
46
|
+
/**
|
|
47
|
+
* Resolves a dependency plugin's generated file for `node.operationId`, cached in `cache` (the
|
|
48
|
+
* current node's `ctx.cache`) under the resolver's own plugin name. Several dependents reading the
|
|
49
|
+
* same dependency for the same operation in one pass (a query plugin's several hook generators, the
|
|
50
|
+
* MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.
|
|
51
|
+
*
|
|
52
|
+
* @example Cache `plugin-ts`'s file for the current operation
|
|
53
|
+
* ```ts
|
|
54
|
+
* const fileTs = resolveDependencyOperationFile({ cache: ctx.cache, node, resolver: tsResolver, root, output })
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
function resolveDependencyOperationFile(options) {
|
|
58
|
+
const { cache, node, resolver, root, output, group } = options;
|
|
59
|
+
return cache.getOrSet(`${resolver.pluginName}:operationFile`, () => resolver.file({
|
|
60
|
+
...operationFileEntry(node, node.operationId),
|
|
61
|
+
root,
|
|
62
|
+
output,
|
|
63
|
+
group: group ?? void 0
|
|
64
|
+
}));
|
|
65
|
+
}
|
|
46
66
|
function getOperationLink(node, link) {
|
|
47
67
|
if (!link) return null;
|
|
48
68
|
if (typeof link === "function") return link(node) ?? null;
|
|
@@ -391,23 +411,30 @@ function resolveContractClient(options) {
|
|
|
391
411
|
* (plugin-fetch or plugin-axios). Returns `null` when no contract plugin is in play (the inline
|
|
392
412
|
* path). The plugin injects `.kubb/client.ts` at the global output root, the same path consumers
|
|
393
413
|
* read `RequestConfig` / `ResponseErrorConfig` from.
|
|
414
|
+
*
|
|
415
|
+
* The result is cached in the current node's `cache` (`ctx.cache`) under the client plugin's name,
|
|
416
|
+
* so several dependents reading the same client plugin for one operation in a single pass
|
|
417
|
+
* (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
|
|
418
|
+
* one computed result instead of each re-deriving the name and path.
|
|
394
419
|
*/
|
|
395
420
|
function resolveClientOperation(options) {
|
|
396
|
-
const { clientPlugin, driver, node, root, output } = options;
|
|
421
|
+
const { clientPlugin, driver, node, root, output, cache } = options;
|
|
397
422
|
if (!clientPlugin) return null;
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
|
|
423
|
+
return cache.getOrSet(`${clientPlugin.pluginName}:clientOperation`, () => {
|
|
424
|
+
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
425
|
+
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
426
|
+
const file = resolver.file({
|
|
427
|
+
...operationFileEntry(node, node.operationId),
|
|
428
|
+
root,
|
|
429
|
+
output: plugin?.options?.output ?? output,
|
|
430
|
+
group: plugin?.options?.group ?? void 0
|
|
431
|
+
});
|
|
432
|
+
return {
|
|
433
|
+
name: resolver.name(node.operationId),
|
|
434
|
+
path: file.path,
|
|
435
|
+
clientPath: path.resolve(root, ".kubb/client.ts")
|
|
436
|
+
};
|
|
405
437
|
});
|
|
406
|
-
return {
|
|
407
|
-
name: resolver.name(node.operationId),
|
|
408
|
-
path: file.path,
|
|
409
|
-
clientPath: path.resolve(root, ".kubb/client.ts")
|
|
410
|
-
};
|
|
411
438
|
}
|
|
412
439
|
//#endregion
|
|
413
440
|
//#region ../../internals/tanstack-query/src/utils.ts
|
|
@@ -1460,7 +1487,8 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1460
1487
|
driver,
|
|
1461
1488
|
node,
|
|
1462
1489
|
root,
|
|
1463
|
-
output
|
|
1490
|
+
output,
|
|
1491
|
+
cache: ctx.cache
|
|
1464
1492
|
});
|
|
1465
1493
|
if (!contractOp) return null;
|
|
1466
1494
|
const queryName = resolver.infiniteQuery.name(node);
|
|
@@ -1474,11 +1502,13 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1474
1502
|
output,
|
|
1475
1503
|
group: group ?? void 0
|
|
1476
1504
|
}),
|
|
1477
|
-
fileTs:
|
|
1478
|
-
|
|
1505
|
+
fileTs: resolveDependencyOperationFile({
|
|
1506
|
+
cache: ctx.cache,
|
|
1507
|
+
node,
|
|
1508
|
+
resolver: tsResolver,
|
|
1479
1509
|
root,
|
|
1480
1510
|
output: pluginTs.options?.output ?? output,
|
|
1481
|
-
group: pluginTs.options?.group
|
|
1511
|
+
group: pluginTs.options?.group
|
|
1482
1512
|
})
|
|
1483
1513
|
};
|
|
1484
1514
|
const { queryParamsTypeName } = resolvePageParamType(node, {
|
|
@@ -1627,7 +1657,8 @@ const mutationGenerator = defineGenerator({
|
|
|
1627
1657
|
driver,
|
|
1628
1658
|
node,
|
|
1629
1659
|
root,
|
|
1630
|
-
output
|
|
1660
|
+
output,
|
|
1661
|
+
cache: ctx.cache
|
|
1631
1662
|
});
|
|
1632
1663
|
if (!contractOp) return null;
|
|
1633
1664
|
const mutationHookName = resolver.mutation.name(node);
|
|
@@ -1641,11 +1672,13 @@ const mutationGenerator = defineGenerator({
|
|
|
1641
1672
|
output,
|
|
1642
1673
|
group: group ?? void 0
|
|
1643
1674
|
}),
|
|
1644
|
-
fileTs:
|
|
1645
|
-
|
|
1675
|
+
fileTs: resolveDependencyOperationFile({
|
|
1676
|
+
cache: ctx.cache,
|
|
1677
|
+
node,
|
|
1678
|
+
resolver: tsResolver,
|
|
1646
1679
|
root,
|
|
1647
1680
|
output: pluginTs.options?.output ?? output,
|
|
1648
|
-
group: pluginTs.options?.group
|
|
1681
|
+
group: pluginTs.options?.group
|
|
1649
1682
|
})
|
|
1650
1683
|
};
|
|
1651
1684
|
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
@@ -1772,7 +1805,8 @@ const queryGenerator = defineGenerator({
|
|
|
1772
1805
|
driver,
|
|
1773
1806
|
node,
|
|
1774
1807
|
root,
|
|
1775
|
-
output
|
|
1808
|
+
output,
|
|
1809
|
+
cache: ctx.cache
|
|
1776
1810
|
});
|
|
1777
1811
|
if (!contractOp) return null;
|
|
1778
1812
|
const queryName = resolver.query.name(node);
|
|
@@ -1786,11 +1820,13 @@ const queryGenerator = defineGenerator({
|
|
|
1786
1820
|
output,
|
|
1787
1821
|
group: group ?? void 0
|
|
1788
1822
|
}),
|
|
1789
|
-
fileTs:
|
|
1790
|
-
|
|
1823
|
+
fileTs: resolveDependencyOperationFile({
|
|
1824
|
+
cache: ctx.cache,
|
|
1825
|
+
node,
|
|
1826
|
+
resolver: tsResolver,
|
|
1791
1827
|
root,
|
|
1792
1828
|
output: pluginTs.options?.output ?? output,
|
|
1793
|
-
group: pluginTs.options?.group
|
|
1829
|
+
group: pluginTs.options?.group
|
|
1794
1830
|
})
|
|
1795
1831
|
};
|
|
1796
1832
|
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
@@ -1927,7 +1963,8 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
|
1927
1963
|
driver,
|
|
1928
1964
|
node,
|
|
1929
1965
|
root,
|
|
1930
|
-
output
|
|
1966
|
+
output,
|
|
1967
|
+
cache: ctx.cache
|
|
1931
1968
|
});
|
|
1932
1969
|
if (!contractOp) return null;
|
|
1933
1970
|
const queryName = resolver.suspenseInfiniteQuery.name(node);
|
|
@@ -1941,11 +1978,13 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
|
1941
1978
|
output,
|
|
1942
1979
|
group: group ?? void 0
|
|
1943
1980
|
}),
|
|
1944
|
-
fileTs:
|
|
1945
|
-
|
|
1981
|
+
fileTs: resolveDependencyOperationFile({
|
|
1982
|
+
cache: ctx.cache,
|
|
1983
|
+
node,
|
|
1984
|
+
resolver: tsResolver,
|
|
1946
1985
|
root,
|
|
1947
1986
|
output: pluginTs.options?.output ?? output,
|
|
1948
|
-
group: pluginTs.options?.group
|
|
1987
|
+
group: pluginTs.options?.group
|
|
1949
1988
|
})
|
|
1950
1989
|
};
|
|
1951
1990
|
const rawQueryParams = getOperationParameters(node).query;
|
|
@@ -2094,7 +2133,8 @@ const suspenseQueryGenerator = defineGenerator({
|
|
|
2094
2133
|
driver,
|
|
2095
2134
|
node,
|
|
2096
2135
|
root,
|
|
2097
|
-
output
|
|
2136
|
+
output,
|
|
2137
|
+
cache: ctx.cache
|
|
2098
2138
|
});
|
|
2099
2139
|
if (!contractOp) return null;
|
|
2100
2140
|
const queryName = resolver.suspenseQuery.name(node);
|
|
@@ -2108,11 +2148,13 @@ const suspenseQueryGenerator = defineGenerator({
|
|
|
2108
2148
|
output,
|
|
2109
2149
|
group: group ?? void 0
|
|
2110
2150
|
}),
|
|
2111
|
-
fileTs:
|
|
2112
|
-
|
|
2151
|
+
fileTs: resolveDependencyOperationFile({
|
|
2152
|
+
cache: ctx.cache,
|
|
2153
|
+
node,
|
|
2154
|
+
resolver: tsResolver,
|
|
2113
2155
|
root,
|
|
2114
2156
|
output: pluginTs.options?.output ?? output,
|
|
2115
|
-
group: pluginTs.options?.group
|
|
2157
|
+
group: pluginTs.options?.group
|
|
2116
2158
|
})
|
|
2117
2159
|
};
|
|
2118
2160
|
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|