@kubb/plugin-vue-query 5.0.0-beta.103 → 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 +87 -35
- package/dist/index.cjs.map +1 -1
- package/dist/index.js +86 -34
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
package/dist/index.cjs
CHANGED
|
@@ -23,7 +23,7 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
23
23
|
}
|
|
24
24
|
return to;
|
|
25
25
|
};
|
|
26
|
-
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
26
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule || !__hasOwnProp.call(mod, "default") ? __defProp(target, "default", {
|
|
27
27
|
value: mod,
|
|
28
28
|
enumerable: true
|
|
29
29
|
}) : target, mod));
|
|
@@ -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);
|
|
@@ -399,14 +430,16 @@ function buildGroupedRequestParam(node, options) {
|
|
|
399
430
|
*/
|
|
400
431
|
function buildQueryOptionsParams(node, options) {
|
|
401
432
|
const { resolver, memberTypeWrapper } = options;
|
|
402
|
-
|
|
433
|
+
const groupedParam = buildGroupedRequestParam(node, {
|
|
403
434
|
resolver,
|
|
404
435
|
memberTypeWrapper
|
|
405
|
-
})
|
|
436
|
+
});
|
|
437
|
+
const configParam = (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
406
438
|
name: "config",
|
|
407
439
|
type: `Partial<Omit<RequestConfig, 'path' | 'query' | 'body' | 'headers' | 'url'>>`,
|
|
408
440
|
default: "{}"
|
|
409
|
-
})
|
|
441
|
+
});
|
|
442
|
+
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [groupedParam, configParam].filter((param) => param !== null) });
|
|
410
443
|
}
|
|
411
444
|
/**
|
|
412
445
|
* Builds the call to a client `<op>` function inside a query/mutation hook body. The function takes
|
|
@@ -789,23 +822,30 @@ function resolveContractClient(options) {
|
|
|
789
822
|
* (plugin-fetch or plugin-axios). Returns `null` when no contract plugin is in play (the inline
|
|
790
823
|
* path). The plugin injects `.kubb/client.ts` at the global output root, the same path consumers
|
|
791
824
|
* read `RequestConfig` / `ResponseErrorConfig` from.
|
|
825
|
+
*
|
|
826
|
+
* The result is cached in the current node's `cache` (`ctx.cache`) under the client plugin's name,
|
|
827
|
+
* so several dependents reading the same client plugin for one operation in a single pass
|
|
828
|
+
* (react-query's query/mutation/infinite generators, vue-query, swr, the MCP handler, ...) share
|
|
829
|
+
* one computed result instead of each re-deriving the name and path.
|
|
792
830
|
*/
|
|
793
831
|
function resolveClientOperation(options) {
|
|
794
|
-
const { clientPlugin, driver, node, root, output } = options;
|
|
832
|
+
const { clientPlugin, driver, node, root, output, cache } = options;
|
|
795
833
|
if (!clientPlugin) return null;
|
|
796
|
-
|
|
797
|
-
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
|
|
802
|
-
|
|
834
|
+
return cache.getOrSet(`${clientPlugin.pluginName}:clientOperation`, () => {
|
|
835
|
+
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
836
|
+
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
837
|
+
const file = resolver.file({
|
|
838
|
+
...operationFileEntry(node, node.operationId),
|
|
839
|
+
root,
|
|
840
|
+
output: plugin?.options?.output ?? output,
|
|
841
|
+
group: plugin?.options?.group ?? void 0
|
|
842
|
+
});
|
|
843
|
+
return {
|
|
844
|
+
name: resolver.name(node.operationId),
|
|
845
|
+
path: file.path,
|
|
846
|
+
clientPath: node_path.default.resolve(root, ".kubb/client.ts")
|
|
847
|
+
};
|
|
803
848
|
});
|
|
804
|
-
return {
|
|
805
|
-
name: resolver.name(node.operationId),
|
|
806
|
-
path: file.path,
|
|
807
|
-
clientPath: node_path.default.resolve(root, ".kubb/client.ts")
|
|
808
|
-
};
|
|
809
849
|
}
|
|
810
850
|
//#endregion
|
|
811
851
|
//#region src/utils.ts
|
|
@@ -929,10 +969,11 @@ function buildInfiniteQueryParamsNode(node, options) {
|
|
|
929
969
|
}`,
|
|
930
970
|
default: "{}"
|
|
931
971
|
});
|
|
932
|
-
|
|
972
|
+
const groupedParam = buildGroupedRequestParam(node, {
|
|
933
973
|
resolver,
|
|
934
974
|
memberTypeWrapper: maybeRefOrGetter
|
|
935
|
-
})
|
|
975
|
+
});
|
|
976
|
+
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [groupedParam, optionsParam].filter((param) => param !== null) });
|
|
936
977
|
}
|
|
937
978
|
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
|
|
938
979
|
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
@@ -1001,13 +1042,14 @@ function resolveMutationRequestType(node, resolver) {
|
|
|
1001
1042
|
function buildMutationParamsNode(node, options) {
|
|
1002
1043
|
const { resolver } = options;
|
|
1003
1044
|
const { TData, TError } = buildResponseTypes(node, resolver);
|
|
1045
|
+
const TRequest = resolveMutationRequestType(node, resolver);
|
|
1004
1046
|
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [(0, _kubb_plugin_ts.createFunctionParameter)({
|
|
1005
1047
|
name: "options",
|
|
1006
1048
|
type: `{
|
|
1007
1049
|
mutation?: MutationObserverOptions<${[
|
|
1008
1050
|
TData,
|
|
1009
1051
|
TError,
|
|
1010
|
-
|
|
1052
|
+
TRequest,
|
|
1011
1053
|
"TContext"
|
|
1012
1054
|
].join(", ")}> & { client?: QueryClient },
|
|
1013
1055
|
client?: ${buildRequestConfigType(node)},
|
|
@@ -1081,10 +1123,11 @@ function buildQueryParamsNode(node, options) {
|
|
|
1081
1123
|
}`,
|
|
1082
1124
|
default: "{}"
|
|
1083
1125
|
});
|
|
1084
|
-
|
|
1126
|
+
const groupedParam = buildGroupedRequestParam(node, {
|
|
1085
1127
|
resolver,
|
|
1086
1128
|
memberTypeWrapper: maybeRefOrGetter
|
|
1087
|
-
})
|
|
1129
|
+
});
|
|
1130
|
+
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [groupedParam, optionsParam].filter((param) => param !== null) });
|
|
1088
1131
|
}
|
|
1089
1132
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
|
|
1090
1133
|
const { TData, TError } = buildResponseTypes(node, tsResolver);
|
|
@@ -1161,7 +1204,8 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1161
1204
|
driver,
|
|
1162
1205
|
node,
|
|
1163
1206
|
root,
|
|
1164
|
-
output
|
|
1207
|
+
output,
|
|
1208
|
+
cache: ctx.cache
|
|
1165
1209
|
});
|
|
1166
1210
|
if (!contractOp) return null;
|
|
1167
1211
|
const queryName = resolver.infiniteQuery.name(node);
|
|
@@ -1175,11 +1219,13 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1175
1219
|
output,
|
|
1176
1220
|
group: group ?? void 0
|
|
1177
1221
|
}),
|
|
1178
|
-
fileTs:
|
|
1179
|
-
|
|
1222
|
+
fileTs: resolveDependencyOperationFile({
|
|
1223
|
+
cache: ctx.cache,
|
|
1224
|
+
node,
|
|
1225
|
+
resolver: tsResolver,
|
|
1180
1226
|
root,
|
|
1181
1227
|
output: pluginTs.options?.output ?? output,
|
|
1182
|
-
group: pluginTs.options?.group
|
|
1228
|
+
group: pluginTs.options?.group
|
|
1183
1229
|
})
|
|
1184
1230
|
};
|
|
1185
1231
|
const { queryParamsTypeName } = resolvePageParamType(node, {
|
|
@@ -1328,7 +1374,8 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1328
1374
|
driver,
|
|
1329
1375
|
node,
|
|
1330
1376
|
root,
|
|
1331
|
-
output
|
|
1377
|
+
output,
|
|
1378
|
+
cache: ctx.cache
|
|
1332
1379
|
});
|
|
1333
1380
|
if (!contractOp) return null;
|
|
1334
1381
|
const mutationHookName = resolver.mutation.name(node);
|
|
@@ -1341,11 +1388,13 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1341
1388
|
output,
|
|
1342
1389
|
group: group ?? void 0
|
|
1343
1390
|
}),
|
|
1344
|
-
fileTs:
|
|
1345
|
-
|
|
1391
|
+
fileTs: resolveDependencyOperationFile({
|
|
1392
|
+
cache: ctx.cache,
|
|
1393
|
+
node,
|
|
1394
|
+
resolver: tsResolver,
|
|
1346
1395
|
root,
|
|
1347
1396
|
output: pluginTs.options?.output ?? output,
|
|
1348
|
-
group: pluginTs.options?.group
|
|
1397
|
+
group: pluginTs.options?.group
|
|
1349
1398
|
})
|
|
1350
1399
|
};
|
|
1351
1400
|
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
@@ -1458,7 +1507,8 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1458
1507
|
driver,
|
|
1459
1508
|
node,
|
|
1460
1509
|
root,
|
|
1461
|
-
output
|
|
1510
|
+
output,
|
|
1511
|
+
cache: ctx.cache
|
|
1462
1512
|
});
|
|
1463
1513
|
if (!contractOp) return null;
|
|
1464
1514
|
const queryName = resolver.query.name(node);
|
|
@@ -1472,11 +1522,13 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1472
1522
|
output,
|
|
1473
1523
|
group: group ?? void 0
|
|
1474
1524
|
}),
|
|
1475
|
-
fileTs:
|
|
1476
|
-
|
|
1525
|
+
fileTs: resolveDependencyOperationFile({
|
|
1526
|
+
cache: ctx.cache,
|
|
1527
|
+
node,
|
|
1528
|
+
resolver: tsResolver,
|
|
1477
1529
|
root,
|
|
1478
1530
|
output: pluginTs.options?.output ?? output,
|
|
1479
|
-
group: pluginTs.options?.group
|
|
1531
|
+
group: pluginTs.options?.group
|
|
1480
1532
|
})
|
|
1481
1533
|
};
|
|
1482
1534
|
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|