@kubb/plugin-vue-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 +73 -26
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +73 -26
- package/dist/index.js.map +1 -1
- package/package.json +5 -5
package/dist/index.cjs
CHANGED
|
@@ -72,6 +72,26 @@ function operationFileEntry(node, name, extname = ".ts") {
|
|
|
72
72
|
path: node.path
|
|
73
73
|
};
|
|
74
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Resolves a dependency plugin's generated file for `node.operationId`, cached in `cache` (the
|
|
77
|
+
* current node's `ctx.cache`) under the resolver's own plugin name. Several dependents reading the
|
|
78
|
+
* same dependency for the same operation in one pass (a query plugin's several hook generators, the
|
|
79
|
+
* MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.
|
|
80
|
+
*
|
|
81
|
+
* @example Cache `plugin-ts`'s file for the current operation
|
|
82
|
+
* ```ts
|
|
83
|
+
* const fileTs = resolveDependencyOperationFile({ cache: ctx.cache, node, resolver: tsResolver, root, output })
|
|
84
|
+
* ```
|
|
85
|
+
*/
|
|
86
|
+
function resolveDependencyOperationFile(options) {
|
|
87
|
+
const { cache, node, resolver, root, output, group } = options;
|
|
88
|
+
return cache.getOrSet(`${resolver.pluginName}:operationFile`, () => resolver.file({
|
|
89
|
+
...operationFileEntry(node, node.operationId),
|
|
90
|
+
root,
|
|
91
|
+
output,
|
|
92
|
+
group: group ?? void 0
|
|
93
|
+
}));
|
|
94
|
+
}
|
|
75
95
|
function getOperationLink(node, link) {
|
|
76
96
|
if (!link) return null;
|
|
77
97
|
if (typeof link === "function") return link(node) ?? null;
|
|
@@ -165,13 +185,24 @@ function buildOperationComments(node, options = {}) {
|
|
|
165
185
|
if (!splitLines) return filteredComments;
|
|
166
186
|
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
167
187
|
}
|
|
188
|
+
const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
189
|
+
/**
|
|
190
|
+
* Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
|
|
191
|
+
* group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
|
|
192
|
+
* (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
|
|
193
|
+
* same parameters once per plugin.
|
|
194
|
+
*/
|
|
168
195
|
function getOperationParameters(node) {
|
|
169
|
-
|
|
196
|
+
const cached = operationParameterGroupsByNode.get(node);
|
|
197
|
+
if (cached) return cached;
|
|
198
|
+
const groups = {
|
|
170
199
|
path: dedupeParams(node.parameters.filter((param) => param.in === "path")),
|
|
171
200
|
query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
|
|
172
201
|
header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
|
|
173
202
|
cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
|
|
174
203
|
};
|
|
204
|
+
operationParameterGroupsByNode.set(node, groups);
|
|
205
|
+
return groups;
|
|
175
206
|
}
|
|
176
207
|
function getStatusCodeNumber(statusCode) {
|
|
177
208
|
const code = Number(statusCode);
|
|
@@ -789,23 +820,30 @@ function resolveContractClient(options) {
|
|
|
789
820
|
* (plugin-fetch or plugin-axios). Returns `null` when no contract plugin is in play (the inline
|
|
790
821
|
* path). The plugin injects `.kubb/client.ts` at the global output root, the same path consumers
|
|
791
822
|
* read `RequestConfig` / `ResponseErrorConfig` from.
|
|
823
|
+
*
|
|
824
|
+
* The result is cached in the current node's `cache` (`ctx.cache`) under the client plugin's name,
|
|
825
|
+
* so several dependents reading the same client plugin for one operation in a single pass
|
|
826
|
+
* (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
|
|
827
|
+
* one computed result instead of each re-deriving the name and path.
|
|
792
828
|
*/
|
|
793
829
|
function resolveClientOperation(options) {
|
|
794
|
-
const { clientPlugin, driver, node, root, output } = options;
|
|
830
|
+
const { clientPlugin, driver, node, root, output, cache } = options;
|
|
795
831
|
if (!clientPlugin) return null;
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
832
|
+
return cache.getOrSet(`${clientPlugin.pluginName}:clientOperation`, () => {
|
|
833
|
+
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
834
|
+
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
835
|
+
const file = resolver.file({
|
|
836
|
+
...operationFileEntry(node, node.operationId),
|
|
837
|
+
root,
|
|
838
|
+
output: plugin?.options?.output ?? output,
|
|
839
|
+
group: plugin?.options?.group ?? void 0
|
|
840
|
+
});
|
|
841
|
+
return {
|
|
842
|
+
name: resolver.name(node.operationId),
|
|
843
|
+
path: file.path,
|
|
844
|
+
clientPath: node_path.default.resolve(root, ".kubb/client.ts")
|
|
845
|
+
};
|
|
803
846
|
});
|
|
804
|
-
return {
|
|
805
|
-
name: resolver.name(node.operationId),
|
|
806
|
-
path: file.path,
|
|
807
|
-
clientPath: node_path.default.resolve(root, ".kubb/client.ts")
|
|
808
|
-
};
|
|
809
847
|
}
|
|
810
848
|
//#endregion
|
|
811
849
|
//#region src/utils.ts
|
|
@@ -1161,7 +1199,8 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1161
1199
|
driver,
|
|
1162
1200
|
node,
|
|
1163
1201
|
root,
|
|
1164
|
-
output
|
|
1202
|
+
output,
|
|
1203
|
+
cache: ctx.cache
|
|
1165
1204
|
});
|
|
1166
1205
|
if (!contractOp) return null;
|
|
1167
1206
|
const queryName = resolver.infiniteQuery.name(node);
|
|
@@ -1175,11 +1214,13 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1175
1214
|
output,
|
|
1176
1215
|
group: group ?? void 0
|
|
1177
1216
|
}),
|
|
1178
|
-
fileTs:
|
|
1179
|
-
|
|
1217
|
+
fileTs: resolveDependencyOperationFile({
|
|
1218
|
+
cache: ctx.cache,
|
|
1219
|
+
node,
|
|
1220
|
+
resolver: tsResolver,
|
|
1180
1221
|
root,
|
|
1181
1222
|
output: pluginTs.options?.output ?? output,
|
|
1182
|
-
group: pluginTs.options?.group
|
|
1223
|
+
group: pluginTs.options?.group
|
|
1183
1224
|
})
|
|
1184
1225
|
};
|
|
1185
1226
|
const { queryParamsTypeName } = resolvePageParamType(node, {
|
|
@@ -1328,7 +1369,8 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1328
1369
|
driver,
|
|
1329
1370
|
node,
|
|
1330
1371
|
root,
|
|
1331
|
-
output
|
|
1372
|
+
output,
|
|
1373
|
+
cache: ctx.cache
|
|
1332
1374
|
});
|
|
1333
1375
|
if (!contractOp) return null;
|
|
1334
1376
|
const mutationHookName = resolver.mutation.name(node);
|
|
@@ -1341,11 +1383,13 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1341
1383
|
output,
|
|
1342
1384
|
group: group ?? void 0
|
|
1343
1385
|
}),
|
|
1344
|
-
fileTs:
|
|
1345
|
-
|
|
1386
|
+
fileTs: resolveDependencyOperationFile({
|
|
1387
|
+
cache: ctx.cache,
|
|
1388
|
+
node,
|
|
1389
|
+
resolver: tsResolver,
|
|
1346
1390
|
root,
|
|
1347
1391
|
output: pluginTs.options?.output ?? output,
|
|
1348
|
-
group: pluginTs.options?.group
|
|
1392
|
+
group: pluginTs.options?.group
|
|
1349
1393
|
})
|
|
1350
1394
|
};
|
|
1351
1395
|
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
@@ -1458,7 +1502,8 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1458
1502
|
driver,
|
|
1459
1503
|
node,
|
|
1460
1504
|
root,
|
|
1461
|
-
output
|
|
1505
|
+
output,
|
|
1506
|
+
cache: ctx.cache
|
|
1462
1507
|
});
|
|
1463
1508
|
if (!contractOp) return null;
|
|
1464
1509
|
const queryName = resolver.query.name(node);
|
|
@@ -1472,11 +1517,13 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1472
1517
|
output,
|
|
1473
1518
|
group: group ?? void 0
|
|
1474
1519
|
}),
|
|
1475
|
-
fileTs:
|
|
1476
|
-
|
|
1520
|
+
fileTs: resolveDependencyOperationFile({
|
|
1521
|
+
cache: ctx.cache,
|
|
1522
|
+
node,
|
|
1523
|
+
resolver: tsResolver,
|
|
1477
1524
|
root,
|
|
1478
1525
|
output: pluginTs.options?.output ?? output,
|
|
1479
|
-
group: pluginTs.options?.group
|
|
1526
|
+
group: pluginTs.options?.group
|
|
1480
1527
|
})
|
|
1481
1528
|
};
|
|
1482
1529
|
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|