@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.cjs
CHANGED
|
@@ -70,6 +70,26 @@ function operationFileEntry(node, name, extname = ".ts") {
|
|
|
70
70
|
path: node.path
|
|
71
71
|
};
|
|
72
72
|
}
|
|
73
|
+
/**
|
|
74
|
+
* Resolves a dependency plugin's generated file for `node.operationId`, cached in `cache` (the
|
|
75
|
+
* current node's `ctx.cache`) under the resolver's own plugin name. Several dependents reading the
|
|
76
|
+
* same dependency for the same operation in one pass (a query plugin's several hook generators, the
|
|
77
|
+
* MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.
|
|
78
|
+
*
|
|
79
|
+
* @example Cache `plugin-ts`'s file for the current operation
|
|
80
|
+
* ```ts
|
|
81
|
+
* const fileTs = resolveDependencyOperationFile({ cache: ctx.cache, node, resolver: tsResolver, root, output })
|
|
82
|
+
* ```
|
|
83
|
+
*/
|
|
84
|
+
function resolveDependencyOperationFile(options) {
|
|
85
|
+
const { cache, node, resolver, root, output, group } = options;
|
|
86
|
+
return cache.getOrSet(`${resolver.pluginName}:operationFile`, () => resolver.file({
|
|
87
|
+
...operationFileEntry(node, node.operationId),
|
|
88
|
+
root,
|
|
89
|
+
output,
|
|
90
|
+
group: group ?? void 0
|
|
91
|
+
}));
|
|
92
|
+
}
|
|
73
93
|
function getOperationLink(node, link) {
|
|
74
94
|
if (!link) return null;
|
|
75
95
|
if (typeof link === "function") return link(node) ?? null;
|
|
@@ -418,23 +438,30 @@ function resolveContractClient(options) {
|
|
|
418
438
|
* (plugin-fetch or plugin-axios). Returns `null` when no contract plugin is in play (the inline
|
|
419
439
|
* path). The plugin injects `.kubb/client.ts` at the global output root, the same path consumers
|
|
420
440
|
* read `RequestConfig` / `ResponseErrorConfig` from.
|
|
441
|
+
*
|
|
442
|
+
* The result is cached in the current node's `cache` (`ctx.cache`) under the client plugin's name,
|
|
443
|
+
* so several dependents reading the same client plugin for one operation in a single pass
|
|
444
|
+
* (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
|
|
445
|
+
* one computed result instead of each re-deriving the name and path.
|
|
421
446
|
*/
|
|
422
447
|
function resolveClientOperation(options) {
|
|
423
|
-
const { clientPlugin, driver, node, root, output } = options;
|
|
448
|
+
const { clientPlugin, driver, node, root, output, cache } = options;
|
|
424
449
|
if (!clientPlugin) return null;
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
450
|
+
return cache.getOrSet(`${clientPlugin.pluginName}:clientOperation`, () => {
|
|
451
|
+
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
452
|
+
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
453
|
+
const file = resolver.file({
|
|
454
|
+
...operationFileEntry(node, node.operationId),
|
|
455
|
+
root,
|
|
456
|
+
output: plugin?.options?.output ?? output,
|
|
457
|
+
group: plugin?.options?.group ?? void 0
|
|
458
|
+
});
|
|
459
|
+
return {
|
|
460
|
+
name: resolver.name(node.operationId),
|
|
461
|
+
path: file.path,
|
|
462
|
+
clientPath: node_path.default.resolve(root, ".kubb/client.ts")
|
|
463
|
+
};
|
|
432
464
|
});
|
|
433
|
-
return {
|
|
434
|
-
name: resolver.name(node.operationId),
|
|
435
|
-
path: file.path,
|
|
436
|
-
clientPath: node_path.default.resolve(root, ".kubb/client.ts")
|
|
437
|
-
};
|
|
438
465
|
}
|
|
439
466
|
//#endregion
|
|
440
467
|
//#region ../../internals/tanstack-query/src/utils.ts
|
|
@@ -1487,7 +1514,8 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1487
1514
|
driver,
|
|
1488
1515
|
node,
|
|
1489
1516
|
root,
|
|
1490
|
-
output
|
|
1517
|
+
output,
|
|
1518
|
+
cache: ctx.cache
|
|
1491
1519
|
});
|
|
1492
1520
|
if (!contractOp) return null;
|
|
1493
1521
|
const queryName = resolver.infiniteQuery.name(node);
|
|
@@ -1501,11 +1529,13 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1501
1529
|
output,
|
|
1502
1530
|
group: group ?? void 0
|
|
1503
1531
|
}),
|
|
1504
|
-
fileTs:
|
|
1505
|
-
|
|
1532
|
+
fileTs: resolveDependencyOperationFile({
|
|
1533
|
+
cache: ctx.cache,
|
|
1534
|
+
node,
|
|
1535
|
+
resolver: tsResolver,
|
|
1506
1536
|
root,
|
|
1507
1537
|
output: pluginTs.options?.output ?? output,
|
|
1508
|
-
group: pluginTs.options?.group
|
|
1538
|
+
group: pluginTs.options?.group
|
|
1509
1539
|
})
|
|
1510
1540
|
};
|
|
1511
1541
|
const { queryParamsTypeName } = resolvePageParamType(node, {
|
|
@@ -1654,7 +1684,8 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1654
1684
|
driver,
|
|
1655
1685
|
node,
|
|
1656
1686
|
root,
|
|
1657
|
-
output
|
|
1687
|
+
output,
|
|
1688
|
+
cache: ctx.cache
|
|
1658
1689
|
});
|
|
1659
1690
|
if (!contractOp) return null;
|
|
1660
1691
|
const mutationHookName = resolver.mutation.name(node);
|
|
@@ -1668,11 +1699,13 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1668
1699
|
output,
|
|
1669
1700
|
group: group ?? void 0
|
|
1670
1701
|
}),
|
|
1671
|
-
fileTs:
|
|
1672
|
-
|
|
1702
|
+
fileTs: resolveDependencyOperationFile({
|
|
1703
|
+
cache: ctx.cache,
|
|
1704
|
+
node,
|
|
1705
|
+
resolver: tsResolver,
|
|
1673
1706
|
root,
|
|
1674
1707
|
output: pluginTs.options?.output ?? output,
|
|
1675
|
-
group: pluginTs.options?.group
|
|
1708
|
+
group: pluginTs.options?.group
|
|
1676
1709
|
})
|
|
1677
1710
|
};
|
|
1678
1711
|
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
@@ -1799,7 +1832,8 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1799
1832
|
driver,
|
|
1800
1833
|
node,
|
|
1801
1834
|
root,
|
|
1802
|
-
output
|
|
1835
|
+
output,
|
|
1836
|
+
cache: ctx.cache
|
|
1803
1837
|
});
|
|
1804
1838
|
if (!contractOp) return null;
|
|
1805
1839
|
const queryName = resolver.query.name(node);
|
|
@@ -1813,11 +1847,13 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1813
1847
|
output,
|
|
1814
1848
|
group: group ?? void 0
|
|
1815
1849
|
}),
|
|
1816
|
-
fileTs:
|
|
1817
|
-
|
|
1850
|
+
fileTs: resolveDependencyOperationFile({
|
|
1851
|
+
cache: ctx.cache,
|
|
1852
|
+
node,
|
|
1853
|
+
resolver: tsResolver,
|
|
1818
1854
|
root,
|
|
1819
1855
|
output: pluginTs.options?.output ?? output,
|
|
1820
|
-
group: pluginTs.options?.group
|
|
1856
|
+
group: pluginTs.options?.group
|
|
1821
1857
|
})
|
|
1822
1858
|
};
|
|
1823
1859
|
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
@@ -1954,7 +1990,8 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1954
1990
|
driver,
|
|
1955
1991
|
node,
|
|
1956
1992
|
root,
|
|
1957
|
-
output
|
|
1993
|
+
output,
|
|
1994
|
+
cache: ctx.cache
|
|
1958
1995
|
});
|
|
1959
1996
|
if (!contractOp) return null;
|
|
1960
1997
|
const queryName = resolver.suspenseInfiniteQuery.name(node);
|
|
@@ -1968,11 +2005,13 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1968
2005
|
output,
|
|
1969
2006
|
group: group ?? void 0
|
|
1970
2007
|
}),
|
|
1971
|
-
fileTs:
|
|
1972
|
-
|
|
2008
|
+
fileTs: resolveDependencyOperationFile({
|
|
2009
|
+
cache: ctx.cache,
|
|
2010
|
+
node,
|
|
2011
|
+
resolver: tsResolver,
|
|
1973
2012
|
root,
|
|
1974
2013
|
output: pluginTs.options?.output ?? output,
|
|
1975
|
-
group: pluginTs.options?.group
|
|
2014
|
+
group: pluginTs.options?.group
|
|
1976
2015
|
})
|
|
1977
2016
|
};
|
|
1978
2017
|
const rawQueryParams = getOperationParameters(node).query;
|
|
@@ -2121,7 +2160,8 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2121
2160
|
driver,
|
|
2122
2161
|
node,
|
|
2123
2162
|
root,
|
|
2124
|
-
output
|
|
2163
|
+
output,
|
|
2164
|
+
cache: ctx.cache
|
|
2125
2165
|
});
|
|
2126
2166
|
if (!contractOp) return null;
|
|
2127
2167
|
const queryName = resolver.suspenseQuery.name(node);
|
|
@@ -2135,11 +2175,13 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2135
2175
|
output,
|
|
2136
2176
|
group: group ?? void 0
|
|
2137
2177
|
}),
|
|
2138
|
-
fileTs:
|
|
2139
|
-
|
|
2178
|
+
fileTs: resolveDependencyOperationFile({
|
|
2179
|
+
cache: ctx.cache,
|
|
2180
|
+
node,
|
|
2181
|
+
resolver: tsResolver,
|
|
2140
2182
|
root,
|
|
2141
2183
|
output: pluginTs.options?.output ?? output,
|
|
2142
|
-
group: pluginTs.options?.group
|
|
2184
|
+
group: pluginTs.options?.group
|
|
2143
2185
|
})
|
|
2144
2186
|
};
|
|
2145
2187
|
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|