@kubb/plugin-vue-query 5.0.0-beta.84 → 5.0.0-beta.86
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 +135 -142
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +70 -61
- package/dist/index.js +135 -142
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -24,12 +24,12 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
enumerable: true
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
//#endregion
|
|
27
|
-
let node_path = require("node:path");
|
|
28
|
-
node_path = __toESM(node_path, 1);
|
|
29
27
|
let kubb_kit = require("kubb/kit");
|
|
30
28
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
31
29
|
let kubb_jsx = require("kubb/jsx");
|
|
32
30
|
let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
|
|
31
|
+
let node_path = require("node:path");
|
|
32
|
+
node_path = __toESM(node_path, 1);
|
|
33
33
|
//#region ../../internals/utils/src/casing.ts
|
|
34
34
|
/**
|
|
35
35
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -57,31 +57,6 @@ function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
|
57
57
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
58
58
|
}
|
|
59
59
|
//#endregion
|
|
60
|
-
//#region ../../internals/utils/src/fs.ts
|
|
61
|
-
/**
|
|
62
|
-
* Builds a nested file path from a dotted name. Splits on dots that precede a letter
|
|
63
|
-
* (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
|
|
64
|
-
* every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
|
|
65
|
-
*
|
|
66
|
-
* Empty segments are dropped before joining. They arise when the name starts with a dot
|
|
67
|
-
* followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
|
|
68
|
-
* an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
|
|
69
|
-
* absolute path, letting generated files escape the configured output directory.
|
|
70
|
-
*
|
|
71
|
-
* @example Nested path from a dotted name
|
|
72
|
-
* `toFilePath('pet.petId') // 'pet/petId'`
|
|
73
|
-
*
|
|
74
|
-
* @example PascalCase the final segment
|
|
75
|
-
* `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
|
|
76
|
-
*
|
|
77
|
-
* @example Suffix applied to the final segment only
|
|
78
|
-
* `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
|
|
79
|
-
*/
|
|
80
|
-
function toFilePath(name, caseLast = camelCase) {
|
|
81
|
-
const parts = name.split(/\.(?=[a-zA-Z])/);
|
|
82
|
-
return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : camelCase(part)).filter(Boolean).join("/");
|
|
83
|
-
}
|
|
84
|
-
//#endregion
|
|
85
60
|
//#region ../../internals/utils/src/reserved.ts
|
|
86
61
|
/**
|
|
87
62
|
* JavaScript and Java reserved words.
|
|
@@ -185,6 +160,23 @@ function isValidVarName(name) {
|
|
|
185
160
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
186
161
|
}
|
|
187
162
|
//#endregion
|
|
163
|
+
//#region ../../internals/utils/src/strings.ts
|
|
164
|
+
/**
|
|
165
|
+
* Renders a dotted path or string array as an optional-chaining accessor expression rooted at
|
|
166
|
+
* `accessor`. Returns `null` for an empty path.
|
|
167
|
+
*
|
|
168
|
+
* @example
|
|
169
|
+
* ```ts
|
|
170
|
+
* getNestedAccessor('pagination.next.id', 'lastPage')
|
|
171
|
+
* // "lastPage?.['pagination']?.['next']?.['id']"
|
|
172
|
+
* ```
|
|
173
|
+
*/
|
|
174
|
+
function getNestedAccessor(param, accessor) {
|
|
175
|
+
const parts = Array.isArray(param) ? param : param.split(".");
|
|
176
|
+
if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
|
|
177
|
+
return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
|
|
178
|
+
}
|
|
179
|
+
//#endregion
|
|
188
180
|
//#region ../../internals/utils/src/url.ts
|
|
189
181
|
function transformParam(raw, casing) {
|
|
190
182
|
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
@@ -337,13 +329,13 @@ function dedupeByCasedName(params) {
|
|
|
337
329
|
//#region ../../internals/shared/src/operation.ts
|
|
338
330
|
/**
|
|
339
331
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
340
|
-
* `resolver.
|
|
332
|
+
* `resolver.file`: a file named `name`, tagged by the operation's first
|
|
341
333
|
* tag (or `'default'`), at the operation's path. Centralizes the entry object
|
|
342
334
|
* that was repeated at dozens of call sites across the client and query plugins.
|
|
343
335
|
*
|
|
344
336
|
* @example
|
|
345
337
|
* ```ts
|
|
346
|
-
* resolver.
|
|
338
|
+
* resolver.file(operationFileEntry(node, node.operationId), { root, output, group })
|
|
347
339
|
* ```
|
|
348
340
|
*/
|
|
349
341
|
function operationFileEntry(node, name, extname = ".ts") {
|
|
@@ -481,13 +473,13 @@ function getPrimarySuccessResponse(node) {
|
|
|
481
473
|
return getOperationSuccessResponses(node)[0] ?? null;
|
|
482
474
|
}
|
|
483
475
|
function resolveErrorNames(node, resolver) {
|
|
484
|
-
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.
|
|
476
|
+
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
|
|
485
477
|
}
|
|
486
478
|
function resolveSuccessNames(node, resolver) {
|
|
487
|
-
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.
|
|
479
|
+
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
|
|
488
480
|
}
|
|
489
481
|
function resolveStatusCodeNames(node, resolver) {
|
|
490
|
-
return node.responses.map((response) => resolver.
|
|
482
|
+
return node.responses.map((response) => resolver.response.status(node, response.statusCode));
|
|
491
483
|
}
|
|
492
484
|
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
493
485
|
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
@@ -504,11 +496,11 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
|
504
496
|
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
505
497
|
const exclude = new Set(options.exclude ?? []);
|
|
506
498
|
const paramNames = options.includeParams === false ? [] : [
|
|
507
|
-
...path.map((param) => resolver.
|
|
508
|
-
...query.map((param) => resolver.
|
|
509
|
-
...header.map((param) => resolver.
|
|
499
|
+
...path.map((param) => resolver.param.path(node, param)),
|
|
500
|
+
...query.map((param) => resolver.param.query(node, param)),
|
|
501
|
+
...header.map((param) => resolver.param.headers(node, param))
|
|
510
502
|
];
|
|
511
|
-
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.
|
|
503
|
+
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)];
|
|
512
504
|
const result = (options.order === "body-response-first" ? [
|
|
513
505
|
...bodyAndResponseNames,
|
|
514
506
|
...paramNames,
|
|
@@ -607,12 +599,12 @@ function maybeRefOrGetter(type) {
|
|
|
607
599
|
/**
|
|
608
600
|
* Builds the grouped `{ path, query, body, headers }` parameter that mirrors the client
|
|
609
601
|
* function signature. Only the groups the operation carries are emitted, typed from the
|
|
610
|
-
* operation's `
|
|
602
|
+
* operation's `Options`. `keys` narrows the emitted groups, used by the query key which
|
|
611
603
|
* never carries `headers`.
|
|
612
604
|
*
|
|
613
|
-
* By default the whole group is typed as the single `
|
|
605
|
+
* By default the whole group is typed as the single `Options` reference. When
|
|
614
606
|
* `memberTypeWrapper` is set, each group is emitted as its own member typed from the matching
|
|
615
|
-
* `
|
|
607
|
+
* `Options['<group>']` slice and wrapped, used by vue-query to apply
|
|
616
608
|
* `MaybeRefOrGetter` per group.
|
|
617
609
|
*/
|
|
618
610
|
function buildGroupedRequestParam(node, options) {
|
|
@@ -627,13 +619,13 @@ function buildGroupedRequestParam(node, options) {
|
|
|
627
619
|
headers: hasRequiredHeader
|
|
628
620
|
};
|
|
629
621
|
const isOptional = names.every((name) => !requiredByGroup[name]);
|
|
630
|
-
const
|
|
622
|
+
const optionsName = resolver.response.options(node);
|
|
631
623
|
const omittedKeys = requestGroupOrder$1.filter((key) => !keys.includes(key));
|
|
632
|
-
const
|
|
624
|
+
const optionsType = omittedKeys.length > 0 ? `Omit<${optionsName}, ${omittedKeys.map((key) => `'${key}'`).join(" | ")}>` : optionsName;
|
|
633
625
|
if (memberTypeWrapper) {
|
|
634
626
|
const members = names.map((name) => ({
|
|
635
627
|
name,
|
|
636
|
-
type: memberTypeWrapper(`${
|
|
628
|
+
type: memberTypeWrapper(`${optionsType}['${name}']`),
|
|
637
629
|
optional: !requiredByGroup[name]
|
|
638
630
|
}));
|
|
639
631
|
return (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
@@ -645,7 +637,7 @@ function buildGroupedRequestParam(node, options) {
|
|
|
645
637
|
}
|
|
646
638
|
return (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
647
639
|
name: (0, _kubb_plugin_ts.createObjectBindingPattern)({ elements: names.map((name) => ({ name })) }),
|
|
648
|
-
type:
|
|
640
|
+
type: optionsType,
|
|
649
641
|
optional: false,
|
|
650
642
|
...isOptional ? { default: "{}" } : {}
|
|
651
643
|
});
|
|
@@ -759,15 +751,15 @@ function resolveClientOperation(options) {
|
|
|
759
751
|
const { clientPlugin, driver, node, root, output } = options;
|
|
760
752
|
if (!clientPlugin) return null;
|
|
761
753
|
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
762
|
-
if (!resolver) return null;
|
|
763
754
|
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
764
|
-
const file = resolver.
|
|
755
|
+
const file = resolver.file({
|
|
756
|
+
...operationFileEntry(node, node.operationId),
|
|
765
757
|
root,
|
|
766
758
|
output: plugin?.options?.output ?? output,
|
|
767
759
|
group: plugin?.options?.group ?? void 0
|
|
768
760
|
});
|
|
769
761
|
return {
|
|
770
|
-
name: resolver.
|
|
762
|
+
name: resolver.name(node.operationId),
|
|
771
763
|
path: file.path,
|
|
772
764
|
clientPath: node_path.default.resolve(root, ".kubb/client.ts")
|
|
773
765
|
};
|
|
@@ -854,7 +846,7 @@ function getQueryOptionsParams(node, options) {
|
|
|
854
846
|
}
|
|
855
847
|
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
|
|
856
848
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
857
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
849
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
858
850
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
859
851
|
const TData = responseName;
|
|
860
852
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -894,7 +886,7 @@ const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
|
894
886
|
function buildInfiniteQueryParamsNode(node, options) {
|
|
895
887
|
const { resolver } = options;
|
|
896
888
|
const successNames = resolveSuccessNames(node, resolver);
|
|
897
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.
|
|
889
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
898
890
|
const errorNames = resolveErrorNames(node, resolver);
|
|
899
891
|
const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
900
892
|
name: "options",
|
|
@@ -917,7 +909,7 @@ function buildInfiniteQueryParamsNode(node, options) {
|
|
|
917
909
|
}
|
|
918
910
|
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
|
|
919
911
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
920
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
912
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
921
913
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
922
914
|
const TData = responseName;
|
|
923
915
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -967,7 +959,7 @@ const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "decla
|
|
|
967
959
|
const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
968
960
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName }) {
|
|
969
961
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
970
|
-
const queryFnDataType = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
962
|
+
const queryFnDataType = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
971
963
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
972
964
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
973
965
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -977,8 +969,8 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
977
969
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
978
970
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
979
971
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
980
|
-
const groupName = tsResolver.
|
|
981
|
-
return groupName !== tsResolver.
|
|
972
|
+
const groupName = tsResolver.param.query(node, rawQueryParams[0]);
|
|
973
|
+
return groupName !== tsResolver.param.name(node, rawQueryParams[0]) ? groupName : null;
|
|
982
974
|
})() : null;
|
|
983
975
|
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
984
976
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
@@ -994,8 +986,8 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
994
986
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
995
987
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
996
988
|
if (hasNewParams) {
|
|
997
|
-
const nextAccessor = nextParam ?
|
|
998
|
-
const prevAccessor = previousParam ?
|
|
989
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
990
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
999
991
|
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1000
992
|
}
|
|
1001
993
|
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
@@ -1057,12 +1049,12 @@ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${que
|
|
|
1057
1049
|
const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1058
1050
|
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1059
1051
|
function resolveMutationRequestType(node, resolver) {
|
|
1060
|
-
return buildGroupedRequestParam(node, { resolver }) ? resolver.
|
|
1052
|
+
return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
|
|
1061
1053
|
}
|
|
1062
1054
|
function buildMutationParamsNode(node, options) {
|
|
1063
1055
|
const { resolver } = options;
|
|
1064
1056
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1065
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.
|
|
1057
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
1066
1058
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1067
1059
|
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [(0, _kubb_plugin_ts.createFunctionParameter)({
|
|
1068
1060
|
name: "options",
|
|
@@ -1080,7 +1072,7 @@ function buildMutationParamsNode(node, options) {
|
|
|
1080
1072
|
}
|
|
1081
1073
|
function Mutation({ name, clientName, node, tsResolver, mutationKeyName }) {
|
|
1082
1074
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1083
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1075
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1084
1076
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1085
1077
|
const TData = responseName;
|
|
1086
1078
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1136,7 +1128,7 @@ const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
|
1136
1128
|
function buildQueryParamsNode(node, options) {
|
|
1137
1129
|
const { resolver } = options;
|
|
1138
1130
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1139
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.
|
|
1131
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
1140
1132
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1141
1133
|
const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
1142
1134
|
name: "options",
|
|
@@ -1159,7 +1151,7 @@ function buildQueryParamsNode(node, options) {
|
|
|
1159
1151
|
}
|
|
1160
1152
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
|
|
1161
1153
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1162
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1154
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1163
1155
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1164
1156
|
const TData = responseName;
|
|
1165
1157
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1240,26 +1232,28 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1240
1232
|
output
|
|
1241
1233
|
});
|
|
1242
1234
|
if (!contractOp) return null;
|
|
1243
|
-
const queryName = resolver.
|
|
1244
|
-
const queryOptionsName = resolver.
|
|
1245
|
-
const queryKeyName = resolver.
|
|
1246
|
-
const queryKeyTypeName = resolver.
|
|
1235
|
+
const queryName = resolver.infiniteQuery.name(node);
|
|
1236
|
+
const queryOptionsName = resolver.infiniteQuery.optionsName(node);
|
|
1237
|
+
const queryKeyName = resolver.infiniteQuery.keyName(node);
|
|
1238
|
+
const queryKeyTypeName = resolver.infiniteQuery.keyTypeName(node);
|
|
1247
1239
|
const meta = {
|
|
1248
|
-
file: resolver.
|
|
1240
|
+
file: resolver.file({
|
|
1241
|
+
...operationFileEntry(node, queryName),
|
|
1249
1242
|
root,
|
|
1250
1243
|
output,
|
|
1251
1244
|
group: group ?? void 0
|
|
1252
1245
|
}),
|
|
1253
|
-
fileTs: tsResolver.
|
|
1246
|
+
fileTs: tsResolver.file({
|
|
1247
|
+
...operationFileEntry(node, node.operationId),
|
|
1254
1248
|
root,
|
|
1255
1249
|
output: pluginTs.options?.output ?? output,
|
|
1256
1250
|
group: pluginTs.options?.group ?? void 0
|
|
1257
1251
|
})
|
|
1258
1252
|
};
|
|
1259
1253
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1260
|
-
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.
|
|
1254
|
+
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.param.query(node, rawQueryParams[0]) !== tsResolver.param.name(node, rawQueryParams[0]) ? tsResolver.param.query(node, rawQueryParams[0]) : null;
|
|
1261
1255
|
const importedTypeNames = [
|
|
1262
|
-
tsResolver.
|
|
1256
|
+
tsResolver.response.options(node),
|
|
1263
1257
|
queryParamsTypeName,
|
|
1264
1258
|
...resolveOperationTypeNames(node, tsResolver, {
|
|
1265
1259
|
exclude: [queryKeyTypeName],
|
|
@@ -1272,7 +1266,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1272
1266
|
baseName: meta.file.baseName,
|
|
1273
1267
|
path: meta.file.path,
|
|
1274
1268
|
meta: meta.file.meta,
|
|
1275
|
-
banner: resolver.
|
|
1269
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1276
1270
|
output,
|
|
1277
1271
|
config,
|
|
1278
1272
|
file: {
|
|
@@ -1280,7 +1274,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1280
1274
|
baseName: meta.file.baseName
|
|
1281
1275
|
}
|
|
1282
1276
|
}),
|
|
1283
|
-
footer: resolver.
|
|
1277
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1284
1278
|
output,
|
|
1285
1279
|
config,
|
|
1286
1280
|
file: {
|
|
@@ -1402,22 +1396,24 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1402
1396
|
output
|
|
1403
1397
|
});
|
|
1404
1398
|
if (!contractOp) return null;
|
|
1405
|
-
const mutationHookName = resolver.
|
|
1406
|
-
const mutationTypeName = resolver.
|
|
1407
|
-
const mutationKeyName = resolver.
|
|
1399
|
+
const mutationHookName = resolver.mutation.name(node);
|
|
1400
|
+
const mutationTypeName = resolver.mutation.typeName(node);
|
|
1401
|
+
const mutationKeyName = resolver.mutation.keyName(node);
|
|
1408
1402
|
const meta = {
|
|
1409
|
-
file: resolver.
|
|
1403
|
+
file: resolver.file({
|
|
1404
|
+
...operationFileEntry(node, mutationHookName),
|
|
1410
1405
|
root,
|
|
1411
1406
|
output,
|
|
1412
1407
|
group: group ?? void 0
|
|
1413
1408
|
}),
|
|
1414
|
-
fileTs: tsResolver.
|
|
1409
|
+
fileTs: tsResolver.file({
|
|
1410
|
+
...operationFileEntry(node, node.operationId),
|
|
1415
1411
|
root,
|
|
1416
1412
|
output: pluginTs.options?.output ?? output,
|
|
1417
1413
|
group: pluginTs.options?.group ?? void 0
|
|
1418
1414
|
})
|
|
1419
1415
|
};
|
|
1420
|
-
const importedTypeNames = [tsResolver.
|
|
1416
|
+
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
1421
1417
|
order: "body-response-first",
|
|
1422
1418
|
includeParams: false
|
|
1423
1419
|
})].filter((name) => Boolean(name));
|
|
@@ -1428,7 +1424,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1428
1424
|
baseName: meta.file.baseName,
|
|
1429
1425
|
path: meta.file.path,
|
|
1430
1426
|
meta: meta.file.meta,
|
|
1431
|
-
banner: resolver.
|
|
1427
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1432
1428
|
output,
|
|
1433
1429
|
config,
|
|
1434
1430
|
file: {
|
|
@@ -1436,7 +1432,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1436
1432
|
baseName: meta.file.baseName
|
|
1437
1433
|
}
|
|
1438
1434
|
}),
|
|
1439
|
-
footer: resolver.
|
|
1435
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1440
1436
|
output,
|
|
1441
1437
|
config,
|
|
1442
1438
|
file: {
|
|
@@ -1529,23 +1525,25 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1529
1525
|
output
|
|
1530
1526
|
});
|
|
1531
1527
|
if (!contractOp) return null;
|
|
1532
|
-
const queryName = resolver.
|
|
1533
|
-
const queryOptionsName = resolver.
|
|
1534
|
-
const queryKeyName = resolver.
|
|
1535
|
-
const queryKeyTypeName = resolver.
|
|
1528
|
+
const queryName = resolver.query.name(node);
|
|
1529
|
+
const queryOptionsName = resolver.query.optionsName(node);
|
|
1530
|
+
const queryKeyName = resolver.query.keyName(node);
|
|
1531
|
+
const queryKeyTypeName = resolver.query.keyTypeName(node);
|
|
1536
1532
|
const meta = {
|
|
1537
|
-
file: resolver.
|
|
1533
|
+
file: resolver.file({
|
|
1534
|
+
...operationFileEntry(node, queryName),
|
|
1538
1535
|
root,
|
|
1539
1536
|
output,
|
|
1540
1537
|
group: group ?? void 0
|
|
1541
1538
|
}),
|
|
1542
|
-
fileTs: tsResolver.
|
|
1539
|
+
fileTs: tsResolver.file({
|
|
1540
|
+
...operationFileEntry(node, node.operationId),
|
|
1543
1541
|
root,
|
|
1544
1542
|
output: pluginTs.options?.output ?? output,
|
|
1545
1543
|
group: pluginTs.options?.group ?? void 0
|
|
1546
1544
|
})
|
|
1547
1545
|
};
|
|
1548
|
-
const importedTypeNames = [tsResolver.
|
|
1546
|
+
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
1549
1547
|
exclude: [queryKeyTypeName],
|
|
1550
1548
|
order: "body-response-first",
|
|
1551
1549
|
includeParams: false
|
|
@@ -1555,7 +1553,7 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1555
1553
|
baseName: meta.file.baseName,
|
|
1556
1554
|
path: meta.file.path,
|
|
1557
1555
|
meta: meta.file.meta,
|
|
1558
|
-
banner: resolver.
|
|
1556
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1559
1557
|
output,
|
|
1560
1558
|
config,
|
|
1561
1559
|
file: {
|
|
@@ -1563,7 +1561,7 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1563
1561
|
baseName: meta.file.baseName
|
|
1564
1562
|
}
|
|
1565
1563
|
}),
|
|
1566
|
-
footer: resolver.
|
|
1564
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1567
1565
|
output,
|
|
1568
1566
|
config,
|
|
1569
1567
|
file: {
|
|
@@ -1654,69 +1652,67 @@ function capitalize(name) {
|
|
|
1654
1652
|
* file paths for every generated TanStack Query composable (`useFoo`,
|
|
1655
1653
|
* `useFooInfinite`) and its companion helpers.
|
|
1656
1654
|
*
|
|
1657
|
-
* Functions and files use camelCase;
|
|
1655
|
+
* The `default` helpers are supplied by `createResolver`. Functions and files use camelCase;
|
|
1656
|
+
* composables get the `use` prefix. Operation-specific naming is grouped under the `query`,
|
|
1657
|
+
* `infiniteQuery`, and `mutation` namespaces.
|
|
1658
1658
|
*
|
|
1659
1659
|
* @example Resolve composable and helper names
|
|
1660
1660
|
* ```ts
|
|
1661
1661
|
* import { resolverVueQuery } from '@kubb/plugin-vue-query'
|
|
1662
1662
|
*
|
|
1663
|
-
* resolverVueQuery.
|
|
1664
|
-
* resolverVueQuery.
|
|
1665
|
-
* resolverVueQuery.
|
|
1663
|
+
* resolverVueQuery.query.name(operationNode) // 'useGetPetById'
|
|
1664
|
+
* resolverVueQuery.query.keyName(operationNode) // 'getPetByIdQueryKey'
|
|
1665
|
+
* resolverVueQuery.query.optionsName(operationNode) // 'getPetByIdQueryOptions'
|
|
1666
1666
|
* ```
|
|
1667
1667
|
*/
|
|
1668
|
-
const resolverVueQuery = (0, kubb_kit.
|
|
1669
|
-
name: "default",
|
|
1668
|
+
const resolverVueQuery = (0, kubb_kit.createResolver)({
|
|
1670
1669
|
pluginName: "plugin-vue-query",
|
|
1671
|
-
|
|
1672
|
-
|
|
1673
|
-
|
|
1674
|
-
|
|
1675
|
-
|
|
1676
|
-
|
|
1677
|
-
|
|
1678
|
-
|
|
1679
|
-
|
|
1680
|
-
|
|
1681
|
-
|
|
1682
|
-
|
|
1683
|
-
|
|
1684
|
-
|
|
1685
|
-
|
|
1686
|
-
|
|
1687
|
-
return `use${capitalize(this.resolveName(node.operationId))}`;
|
|
1688
|
-
},
|
|
1689
|
-
resolveQueryOptionsName(node) {
|
|
1690
|
-
return `${this.resolveName(node.operationId)}QueryOptions`;
|
|
1691
|
-
},
|
|
1692
|
-
resolveInfiniteQueryOptionsName(node) {
|
|
1693
|
-
return `${this.resolveName(node.operationId)}InfiniteQueryOptions`;
|
|
1694
|
-
},
|
|
1695
|
-
resolveQueryKeyName(node) {
|
|
1696
|
-
return `${this.resolveName(node.operationId)}QueryKey`;
|
|
1697
|
-
},
|
|
1698
|
-
resolveInfiniteQueryKeyName(node) {
|
|
1699
|
-
return `${this.resolveName(node.operationId)}InfiniteQueryKey`;
|
|
1700
|
-
},
|
|
1701
|
-
resolveMutationKeyName(node) {
|
|
1702
|
-
return `${this.resolveName(node.operationId)}MutationKey`;
|
|
1703
|
-
},
|
|
1704
|
-
resolveQueryKeyTypeName(node) {
|
|
1705
|
-
return `${capitalize(this.resolveName(node.operationId))}QueryKey`;
|
|
1706
|
-
},
|
|
1707
|
-
resolveInfiniteQueryKeyTypeName(node) {
|
|
1708
|
-
return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`;
|
|
1709
|
-
},
|
|
1710
|
-
resolveMutationTypeName(node) {
|
|
1711
|
-
return capitalize(this.resolveName(node.operationId));
|
|
1670
|
+
query: {
|
|
1671
|
+
name(node) {
|
|
1672
|
+
return `use${capitalize(this.name(node.operationId))}`;
|
|
1673
|
+
},
|
|
1674
|
+
keyName(node) {
|
|
1675
|
+
return `${this.name(node.operationId)}QueryKey`;
|
|
1676
|
+
},
|
|
1677
|
+
keyTypeName(node) {
|
|
1678
|
+
return `${capitalize(this.name(node.operationId))}QueryKey`;
|
|
1679
|
+
},
|
|
1680
|
+
optionsName(node) {
|
|
1681
|
+
return `${this.name(node.operationId)}QueryOptions`;
|
|
1682
|
+
},
|
|
1683
|
+
clientName(node) {
|
|
1684
|
+
return this.name(node.operationId);
|
|
1685
|
+
}
|
|
1712
1686
|
},
|
|
1713
|
-
|
|
1714
|
-
|
|
1687
|
+
infiniteQuery: {
|
|
1688
|
+
name(node) {
|
|
1689
|
+
return `use${capitalize(this.name(node.operationId))}Infinite`;
|
|
1690
|
+
},
|
|
1691
|
+
keyName(node) {
|
|
1692
|
+
return `${this.name(node.operationId)}InfiniteQueryKey`;
|
|
1693
|
+
},
|
|
1694
|
+
keyTypeName(node) {
|
|
1695
|
+
return `${capitalize(this.name(node.operationId))}InfiniteQueryKey`;
|
|
1696
|
+
},
|
|
1697
|
+
optionsName(node) {
|
|
1698
|
+
return `${this.name(node.operationId)}InfiniteQueryOptions`;
|
|
1699
|
+
},
|
|
1700
|
+
clientName(node) {
|
|
1701
|
+
return `${this.name(node.operationId)}Infinite`;
|
|
1702
|
+
}
|
|
1715
1703
|
},
|
|
1716
|
-
|
|
1717
|
-
|
|
1704
|
+
mutation: {
|
|
1705
|
+
name(node) {
|
|
1706
|
+
return `use${capitalize(this.name(node.operationId))}`;
|
|
1707
|
+
},
|
|
1708
|
+
keyName(node) {
|
|
1709
|
+
return `${this.name(node.operationId)}MutationKey`;
|
|
1710
|
+
},
|
|
1711
|
+
typeName(node) {
|
|
1712
|
+
return capitalize(this.name(node.operationId));
|
|
1713
|
+
}
|
|
1718
1714
|
}
|
|
1719
|
-
})
|
|
1715
|
+
});
|
|
1720
1716
|
//#endregion
|
|
1721
1717
|
//#region src/plugin.ts
|
|
1722
1718
|
/**
|
|
@@ -1764,10 +1760,7 @@ const pluginVueQuery = (0, kubb_kit.definePlugin)((options) => {
|
|
|
1764
1760
|
options,
|
|
1765
1761
|
dependencies: [_kubb_plugin_ts.pluginTsName],
|
|
1766
1762
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
1767
|
-
const resolver = userResolver ?
|
|
1768
|
-
...resolverVueQuery,
|
|
1769
|
-
...userResolver
|
|
1770
|
-
} : resolverVueQuery;
|
|
1763
|
+
const resolver = userResolver ? kubb_kit.Resolver.merge(resolverVueQuery, userResolver) : resolverVueQuery;
|
|
1771
1764
|
const resolvedClient = resolveClient({
|
|
1772
1765
|
client,
|
|
1773
1766
|
pluginNames: (ctx.config.plugins ?? []).map((p) => p.name).filter((name) => Boolean(name))
|