@kubb/plugin-vue-query 5.0.0-beta.101 → 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 +6 -6
package/dist/index.js
CHANGED
|
@@ -42,6 +42,26 @@ function operationFileEntry(node, name, extname = ".ts") {
|
|
|
42
42
|
path: node.path
|
|
43
43
|
};
|
|
44
44
|
}
|
|
45
|
+
/**
|
|
46
|
+
* Resolves a dependency plugin's generated file for `node.operationId`, cached in `cache` (the
|
|
47
|
+
* current node's `ctx.cache`) under the resolver's own plugin name. Several dependents reading the
|
|
48
|
+
* same dependency for the same operation in one pass (a query plugin's several hook generators, the
|
|
49
|
+
* MCP handler, ...) share one computed name and path instead of each calling `resolver.file` again.
|
|
50
|
+
*
|
|
51
|
+
* @example Cache `plugin-ts`'s file for the current operation
|
|
52
|
+
* ```ts
|
|
53
|
+
* const fileTs = resolveDependencyOperationFile({ cache: ctx.cache, node, resolver: tsResolver, root, output })
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
function resolveDependencyOperationFile(options) {
|
|
57
|
+
const { cache, node, resolver, root, output, group } = options;
|
|
58
|
+
return cache.getOrSet(`${resolver.pluginName}:operationFile`, () => resolver.file({
|
|
59
|
+
...operationFileEntry(node, node.operationId),
|
|
60
|
+
root,
|
|
61
|
+
output,
|
|
62
|
+
group: group ?? void 0
|
|
63
|
+
}));
|
|
64
|
+
}
|
|
45
65
|
function getOperationLink(node, link) {
|
|
46
66
|
if (!link) return null;
|
|
47
67
|
if (typeof link === "function") return link(node) ?? null;
|
|
@@ -135,13 +155,24 @@ function buildOperationComments(node, options = {}) {
|
|
|
135
155
|
if (!splitLines) return filteredComments;
|
|
136
156
|
return filteredComments.flatMap((text) => text.split(/\r?\n/).map((line) => line.trim())).filter((comment) => Boolean(comment));
|
|
137
157
|
}
|
|
158
|
+
const operationParameterGroupsByNode = /* @__PURE__ */ new WeakMap();
|
|
159
|
+
/**
|
|
160
|
+
* Groups an operation's parameters by location (`path`/`query`/`header`/`cookie`), deduping each
|
|
161
|
+
* group by name. Every plugin generator visiting the same `OperationNode` shares one AST instance
|
|
162
|
+
* (see `KubbDriver`), so the result is cached per node to avoid re-filtering and re-deduping the
|
|
163
|
+
* same parameters once per plugin.
|
|
164
|
+
*/
|
|
138
165
|
function getOperationParameters(node) {
|
|
139
|
-
|
|
166
|
+
const cached = operationParameterGroupsByNode.get(node);
|
|
167
|
+
if (cached) return cached;
|
|
168
|
+
const groups = {
|
|
140
169
|
path: dedupeParams(node.parameters.filter((param) => param.in === "path")),
|
|
141
170
|
query: dedupeParams(node.parameters.filter((param) => param.in === "query")),
|
|
142
171
|
header: dedupeParams(node.parameters.filter((param) => param.in === "header")),
|
|
143
172
|
cookie: dedupeParams(node.parameters.filter((param) => param.in === "cookie"))
|
|
144
173
|
};
|
|
174
|
+
operationParameterGroupsByNode.set(node, groups);
|
|
175
|
+
return groups;
|
|
145
176
|
}
|
|
146
177
|
function getStatusCodeNumber(statusCode) {
|
|
147
178
|
const code = Number(statusCode);
|
|
@@ -759,23 +790,30 @@ function resolveContractClient(options) {
|
|
|
759
790
|
* (plugin-fetch or plugin-axios). Returns `null` when no contract plugin is in play (the inline
|
|
760
791
|
* path). The plugin injects `.kubb/client.ts` at the global output root, the same path consumers
|
|
761
792
|
* read `RequestConfig` / `ResponseErrorConfig` from.
|
|
793
|
+
*
|
|
794
|
+
* The result is cached in the current node's `cache` (`ctx.cache`) under the client plugin's name,
|
|
795
|
+
* so several dependents reading the same client plugin for one operation in a single pass
|
|
796
|
+
* (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
|
|
797
|
+
* one computed result instead of each re-deriving the name and path.
|
|
762
798
|
*/
|
|
763
799
|
function resolveClientOperation(options) {
|
|
764
|
-
const { clientPlugin, driver, node, root, output } = options;
|
|
800
|
+
const { clientPlugin, driver, node, root, output, cache } = options;
|
|
765
801
|
if (!clientPlugin) return null;
|
|
766
|
-
|
|
767
|
-
|
|
768
|
-
|
|
769
|
-
|
|
770
|
-
|
|
771
|
-
|
|
772
|
-
|
|
802
|
+
return cache.getOrSet(`${clientPlugin.pluginName}:clientOperation`, () => {
|
|
803
|
+
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
804
|
+
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
805
|
+
const file = resolver.file({
|
|
806
|
+
...operationFileEntry(node, node.operationId),
|
|
807
|
+
root,
|
|
808
|
+
output: plugin?.options?.output ?? output,
|
|
809
|
+
group: plugin?.options?.group ?? void 0
|
|
810
|
+
});
|
|
811
|
+
return {
|
|
812
|
+
name: resolver.name(node.operationId),
|
|
813
|
+
path: file.path,
|
|
814
|
+
clientPath: path.resolve(root, ".kubb/client.ts")
|
|
815
|
+
};
|
|
773
816
|
});
|
|
774
|
-
return {
|
|
775
|
-
name: resolver.name(node.operationId),
|
|
776
|
-
path: file.path,
|
|
777
|
-
clientPath: path.resolve(root, ".kubb/client.ts")
|
|
778
|
-
};
|
|
779
817
|
}
|
|
780
818
|
//#endregion
|
|
781
819
|
//#region src/utils.ts
|
|
@@ -1131,7 +1169,8 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1131
1169
|
driver,
|
|
1132
1170
|
node,
|
|
1133
1171
|
root,
|
|
1134
|
-
output
|
|
1172
|
+
output,
|
|
1173
|
+
cache: ctx.cache
|
|
1135
1174
|
});
|
|
1136
1175
|
if (!contractOp) return null;
|
|
1137
1176
|
const queryName = resolver.infiniteQuery.name(node);
|
|
@@ -1145,11 +1184,13 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1145
1184
|
output,
|
|
1146
1185
|
group: group ?? void 0
|
|
1147
1186
|
}),
|
|
1148
|
-
fileTs:
|
|
1149
|
-
|
|
1187
|
+
fileTs: resolveDependencyOperationFile({
|
|
1188
|
+
cache: ctx.cache,
|
|
1189
|
+
node,
|
|
1190
|
+
resolver: tsResolver,
|
|
1150
1191
|
root,
|
|
1151
1192
|
output: pluginTs.options?.output ?? output,
|
|
1152
|
-
group: pluginTs.options?.group
|
|
1193
|
+
group: pluginTs.options?.group
|
|
1153
1194
|
})
|
|
1154
1195
|
};
|
|
1155
1196
|
const { queryParamsTypeName } = resolvePageParamType(node, {
|
|
@@ -1298,7 +1339,8 @@ const mutationGenerator = defineGenerator({
|
|
|
1298
1339
|
driver,
|
|
1299
1340
|
node,
|
|
1300
1341
|
root,
|
|
1301
|
-
output
|
|
1342
|
+
output,
|
|
1343
|
+
cache: ctx.cache
|
|
1302
1344
|
});
|
|
1303
1345
|
if (!contractOp) return null;
|
|
1304
1346
|
const mutationHookName = resolver.mutation.name(node);
|
|
@@ -1311,11 +1353,13 @@ const mutationGenerator = defineGenerator({
|
|
|
1311
1353
|
output,
|
|
1312
1354
|
group: group ?? void 0
|
|
1313
1355
|
}),
|
|
1314
|
-
fileTs:
|
|
1315
|
-
|
|
1356
|
+
fileTs: resolveDependencyOperationFile({
|
|
1357
|
+
cache: ctx.cache,
|
|
1358
|
+
node,
|
|
1359
|
+
resolver: tsResolver,
|
|
1316
1360
|
root,
|
|
1317
1361
|
output: pluginTs.options?.output ?? output,
|
|
1318
|
-
group: pluginTs.options?.group
|
|
1362
|
+
group: pluginTs.options?.group
|
|
1319
1363
|
})
|
|
1320
1364
|
};
|
|
1321
1365
|
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
@@ -1428,7 +1472,8 @@ const queryGenerator = defineGenerator({
|
|
|
1428
1472
|
driver,
|
|
1429
1473
|
node,
|
|
1430
1474
|
root,
|
|
1431
|
-
output
|
|
1475
|
+
output,
|
|
1476
|
+
cache: ctx.cache
|
|
1432
1477
|
});
|
|
1433
1478
|
if (!contractOp) return null;
|
|
1434
1479
|
const queryName = resolver.query.name(node);
|
|
@@ -1442,11 +1487,13 @@ const queryGenerator = defineGenerator({
|
|
|
1442
1487
|
output,
|
|
1443
1488
|
group: group ?? void 0
|
|
1444
1489
|
}),
|
|
1445
|
-
fileTs:
|
|
1446
|
-
|
|
1490
|
+
fileTs: resolveDependencyOperationFile({
|
|
1491
|
+
cache: ctx.cache,
|
|
1492
|
+
node,
|
|
1493
|
+
resolver: tsResolver,
|
|
1447
1494
|
root,
|
|
1448
1495
|
output: pluginTs.options?.output ?? output,
|
|
1449
|
-
group: pluginTs.options?.group
|
|
1496
|
+
group: pluginTs.options?.group
|
|
1450
1497
|
})
|
|
1451
1498
|
};
|
|
1452
1499
|
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|