@kubb/plugin-react-query 5.0.0-beta.104 → 5.0.0-beta.106
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 +94 -47
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +93 -46
- package/dist/index.js.map +1 -1
- package/package.json +7 -7
package/dist/index.cjs
CHANGED
|
@@ -19,7 +19,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
19
19
|
}
|
|
20
20
|
return to;
|
|
21
21
|
};
|
|
22
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
22
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
23
23
|
value: mod,
|
|
24
24
|
enumerable: true
|
|
25
25
|
}) : target, mod));
|
|
@@ -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
|
|
@@ -505,14 +532,16 @@ function buildGroupedRequestParam(node, options) {
|
|
|
505
532
|
*/
|
|
506
533
|
function buildQueryOptionsParams(node, options) {
|
|
507
534
|
const { resolver, memberTypeWrapper } = options;
|
|
508
|
-
|
|
535
|
+
const groupedParam = buildGroupedRequestParam(node, {
|
|
509
536
|
resolver,
|
|
510
537
|
memberTypeWrapper
|
|
511
|
-
})
|
|
538
|
+
});
|
|
539
|
+
const configParam = (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
512
540
|
name: "config",
|
|
513
541
|
type: `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`,
|
|
514
542
|
default: "{}"
|
|
515
|
-
})
|
|
543
|
+
});
|
|
544
|
+
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [groupedParam, configParam].filter((param) => param !== null) });
|
|
516
545
|
}
|
|
517
546
|
/**
|
|
518
547
|
* Builds the call to a client `<op>` function inside a query/mutation hook body. The function takes
|
|
@@ -1166,10 +1195,11 @@ function buildInfiniteQueryParamsNode(node, options) {
|
|
|
1166
1195
|
}`,
|
|
1167
1196
|
default: "{}"
|
|
1168
1197
|
});
|
|
1169
|
-
|
|
1198
|
+
const groupedParam = buildGroupedRequestParam(node, {
|
|
1170
1199
|
resolver,
|
|
1171
1200
|
memberTypeWrapper: maybeValueOrGetter
|
|
1172
|
-
})
|
|
1201
|
+
});
|
|
1202
|
+
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [groupedParam, optionsParam].filter((param) => param !== null) });
|
|
1173
1203
|
}
|
|
1174
1204
|
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, initialPageParam, queryParam, customOptions, suspense }) {
|
|
1175
1205
|
const { TData: responseType, TError: errorType } = buildResponseTypes(node, tsResolver);
|
|
@@ -1282,15 +1312,16 @@ function resolveMutationRequestType(node, resolver) {
|
|
|
1282
1312
|
function buildMutationParamsNode(node, options) {
|
|
1283
1313
|
const { resolver } = options;
|
|
1284
1314
|
const { TData, TError } = buildResponseTypes(node, resolver);
|
|
1315
|
+
const generics = [
|
|
1316
|
+
TData,
|
|
1317
|
+
TError,
|
|
1318
|
+
resolveMutationRequestType(node, resolver),
|
|
1319
|
+
"TContext"
|
|
1320
|
+
].join(", ");
|
|
1285
1321
|
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [(0, _kubb_plugin_ts.createFunctionParameter)({
|
|
1286
1322
|
name: "options",
|
|
1287
1323
|
type: `{
|
|
1288
|
-
mutation?: UseMutationOptions<${
|
|
1289
|
-
TData,
|
|
1290
|
-
TError,
|
|
1291
|
-
resolveMutationRequestType(node, resolver),
|
|
1292
|
-
"TContext"
|
|
1293
|
-
].join(", ")}> & { client?: QueryClient },
|
|
1324
|
+
mutation?: UseMutationOptions<${generics}> & { client?: QueryClient },
|
|
1294
1325
|
client?: ${buildRequestConfigType(node)},
|
|
1295
1326
|
}`,
|
|
1296
1327
|
default: "{}"
|
|
@@ -1348,10 +1379,11 @@ function buildQueryParamsNode(node, options) {
|
|
|
1348
1379
|
}`,
|
|
1349
1380
|
default: "{}"
|
|
1350
1381
|
});
|
|
1351
|
-
|
|
1382
|
+
const groupedParam = buildGroupedRequestParam(node, {
|
|
1352
1383
|
resolver,
|
|
1353
1384
|
memberTypeWrapper: maybeValueOrGetter
|
|
1354
|
-
})
|
|
1385
|
+
});
|
|
1386
|
+
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [groupedParam, optionsParam].filter((param) => param !== null) });
|
|
1355
1387
|
}
|
|
1356
1388
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions, suspense }) {
|
|
1357
1389
|
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
@@ -1487,7 +1519,8 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1487
1519
|
driver,
|
|
1488
1520
|
node,
|
|
1489
1521
|
root,
|
|
1490
|
-
output
|
|
1522
|
+
output,
|
|
1523
|
+
cache: ctx.cache
|
|
1491
1524
|
});
|
|
1492
1525
|
if (!contractOp) return null;
|
|
1493
1526
|
const queryName = resolver.infiniteQuery.name(node);
|
|
@@ -1501,11 +1534,13 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1501
1534
|
output,
|
|
1502
1535
|
group: group ?? void 0
|
|
1503
1536
|
}),
|
|
1504
|
-
fileTs:
|
|
1505
|
-
|
|
1537
|
+
fileTs: resolveDependencyOperationFile({
|
|
1538
|
+
cache: ctx.cache,
|
|
1539
|
+
node,
|
|
1540
|
+
resolver: tsResolver,
|
|
1506
1541
|
root,
|
|
1507
1542
|
output: pluginTs.options?.output ?? output,
|
|
1508
|
-
group: pluginTs.options?.group
|
|
1543
|
+
group: pluginTs.options?.group
|
|
1509
1544
|
})
|
|
1510
1545
|
};
|
|
1511
1546
|
const { queryParamsTypeName } = resolvePageParamType(node, {
|
|
@@ -1654,7 +1689,8 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1654
1689
|
driver,
|
|
1655
1690
|
node,
|
|
1656
1691
|
root,
|
|
1657
|
-
output
|
|
1692
|
+
output,
|
|
1693
|
+
cache: ctx.cache
|
|
1658
1694
|
});
|
|
1659
1695
|
if (!contractOp) return null;
|
|
1660
1696
|
const mutationHookName = resolver.mutation.name(node);
|
|
@@ -1668,11 +1704,13 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1668
1704
|
output,
|
|
1669
1705
|
group: group ?? void 0
|
|
1670
1706
|
}),
|
|
1671
|
-
fileTs:
|
|
1672
|
-
|
|
1707
|
+
fileTs: resolveDependencyOperationFile({
|
|
1708
|
+
cache: ctx.cache,
|
|
1709
|
+
node,
|
|
1710
|
+
resolver: tsResolver,
|
|
1673
1711
|
root,
|
|
1674
1712
|
output: pluginTs.options?.output ?? output,
|
|
1675
|
-
group: pluginTs.options?.group
|
|
1713
|
+
group: pluginTs.options?.group
|
|
1676
1714
|
})
|
|
1677
1715
|
};
|
|
1678
1716
|
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
@@ -1799,7 +1837,8 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1799
1837
|
driver,
|
|
1800
1838
|
node,
|
|
1801
1839
|
root,
|
|
1802
|
-
output
|
|
1840
|
+
output,
|
|
1841
|
+
cache: ctx.cache
|
|
1803
1842
|
});
|
|
1804
1843
|
if (!contractOp) return null;
|
|
1805
1844
|
const queryName = resolver.query.name(node);
|
|
@@ -1813,11 +1852,13 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1813
1852
|
output,
|
|
1814
1853
|
group: group ?? void 0
|
|
1815
1854
|
}),
|
|
1816
|
-
fileTs:
|
|
1817
|
-
|
|
1855
|
+
fileTs: resolveDependencyOperationFile({
|
|
1856
|
+
cache: ctx.cache,
|
|
1857
|
+
node,
|
|
1858
|
+
resolver: tsResolver,
|
|
1818
1859
|
root,
|
|
1819
1860
|
output: pluginTs.options?.output ?? output,
|
|
1820
|
-
group: pluginTs.options?.group
|
|
1861
|
+
group: pluginTs.options?.group
|
|
1821
1862
|
})
|
|
1822
1863
|
};
|
|
1823
1864
|
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
@@ -1954,7 +1995,8 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1954
1995
|
driver,
|
|
1955
1996
|
node,
|
|
1956
1997
|
root,
|
|
1957
|
-
output
|
|
1998
|
+
output,
|
|
1999
|
+
cache: ctx.cache
|
|
1958
2000
|
});
|
|
1959
2001
|
if (!contractOp) return null;
|
|
1960
2002
|
const queryName = resolver.suspenseInfiniteQuery.name(node);
|
|
@@ -1968,11 +2010,13 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1968
2010
|
output,
|
|
1969
2011
|
group: group ?? void 0
|
|
1970
2012
|
}),
|
|
1971
|
-
fileTs:
|
|
1972
|
-
|
|
2013
|
+
fileTs: resolveDependencyOperationFile({
|
|
2014
|
+
cache: ctx.cache,
|
|
2015
|
+
node,
|
|
2016
|
+
resolver: tsResolver,
|
|
1973
2017
|
root,
|
|
1974
2018
|
output: pluginTs.options?.output ?? output,
|
|
1975
|
-
group: pluginTs.options?.group
|
|
2019
|
+
group: pluginTs.options?.group
|
|
1976
2020
|
})
|
|
1977
2021
|
};
|
|
1978
2022
|
const rawQueryParams = getOperationParameters(node).query;
|
|
@@ -2121,7 +2165,8 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2121
2165
|
driver,
|
|
2122
2166
|
node,
|
|
2123
2167
|
root,
|
|
2124
|
-
output
|
|
2168
|
+
output,
|
|
2169
|
+
cache: ctx.cache
|
|
2125
2170
|
});
|
|
2126
2171
|
if (!contractOp) return null;
|
|
2127
2172
|
const queryName = resolver.suspenseQuery.name(node);
|
|
@@ -2135,11 +2180,13 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2135
2180
|
output,
|
|
2136
2181
|
group: group ?? void 0
|
|
2137
2182
|
}),
|
|
2138
|
-
fileTs:
|
|
2139
|
-
|
|
2183
|
+
fileTs: resolveDependencyOperationFile({
|
|
2184
|
+
cache: ctx.cache,
|
|
2185
|
+
node,
|
|
2186
|
+
resolver: tsResolver,
|
|
2140
2187
|
root,
|
|
2141
2188
|
output: pluginTs.options?.output ?? output,
|
|
2142
|
-
group: pluginTs.options?.group
|
|
2189
|
+
group: pluginTs.options?.group
|
|
2143
2190
|
})
|
|
2144
2191
|
};
|
|
2145
2192
|
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|