@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.js
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
-
import
|
|
3
|
-
import { ast, defineGenerator, definePlugin, defineResolver } from "kubb/kit";
|
|
2
|
+
import { Resolver, ast, createResolver, defineGenerator, definePlugin } from "kubb/kit";
|
|
4
3
|
import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
5
4
|
import { File, Function, Type, jsxRenderer } from "kubb/jsx";
|
|
6
5
|
import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
6
|
+
import path from "node:path";
|
|
7
7
|
//#region ../../internals/utils/src/casing.ts
|
|
8
8
|
/**
|
|
9
9
|
* Shared implementation for camelCase and PascalCase conversion.
|
|
@@ -31,31 +31,6 @@ function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
|
31
31
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
32
32
|
}
|
|
33
33
|
//#endregion
|
|
34
|
-
//#region ../../internals/utils/src/fs.ts
|
|
35
|
-
/**
|
|
36
|
-
* Builds a nested file path from a dotted name. Splits on dots that precede a letter
|
|
37
|
-
* (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
|
|
38
|
-
* every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
|
|
39
|
-
*
|
|
40
|
-
* Empty segments are dropped before joining. They arise when the name starts with a dot
|
|
41
|
-
* followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
|
|
42
|
-
* an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
|
|
43
|
-
* absolute path, letting generated files escape the configured output directory.
|
|
44
|
-
*
|
|
45
|
-
* @example Nested path from a dotted name
|
|
46
|
-
* `toFilePath('pet.petId') // 'pet/petId'`
|
|
47
|
-
*
|
|
48
|
-
* @example PascalCase the final segment
|
|
49
|
-
* `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
|
|
50
|
-
*
|
|
51
|
-
* @example Suffix applied to the final segment only
|
|
52
|
-
* `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
|
|
53
|
-
*/
|
|
54
|
-
function toFilePath(name, caseLast = camelCase) {
|
|
55
|
-
const parts = name.split(/\.(?=[a-zA-Z])/);
|
|
56
|
-
return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : camelCase(part)).filter(Boolean).join("/");
|
|
57
|
-
}
|
|
58
|
-
//#endregion
|
|
59
34
|
//#region ../../internals/utils/src/reserved.ts
|
|
60
35
|
/**
|
|
61
36
|
* JavaScript and Java reserved words.
|
|
@@ -159,6 +134,23 @@ function isValidVarName(name) {
|
|
|
159
134
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
160
135
|
}
|
|
161
136
|
//#endregion
|
|
137
|
+
//#region ../../internals/utils/src/strings.ts
|
|
138
|
+
/**
|
|
139
|
+
* Renders a dotted path or string array as an optional-chaining accessor expression rooted at
|
|
140
|
+
* `accessor`. Returns `null` for an empty path.
|
|
141
|
+
*
|
|
142
|
+
* @example
|
|
143
|
+
* ```ts
|
|
144
|
+
* getNestedAccessor('pagination.next.id', 'lastPage')
|
|
145
|
+
* // "lastPage?.['pagination']?.['next']?.['id']"
|
|
146
|
+
* ```
|
|
147
|
+
*/
|
|
148
|
+
function getNestedAccessor(param, accessor) {
|
|
149
|
+
const parts = Array.isArray(param) ? param : param.split(".");
|
|
150
|
+
if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
|
|
151
|
+
return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
|
|
152
|
+
}
|
|
153
|
+
//#endregion
|
|
162
154
|
//#region ../../internals/utils/src/url.ts
|
|
163
155
|
function transformParam(raw, casing) {
|
|
164
156
|
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
@@ -311,13 +303,13 @@ function dedupeByCasedName(params) {
|
|
|
311
303
|
//#region ../../internals/shared/src/operation.ts
|
|
312
304
|
/**
|
|
313
305
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
314
|
-
* `resolver.
|
|
306
|
+
* `resolver.file`: a file named `name`, tagged by the operation's first
|
|
315
307
|
* tag (or `'default'`), at the operation's path. Centralizes the entry object
|
|
316
308
|
* that was repeated at dozens of call sites across the client and query plugins.
|
|
317
309
|
*
|
|
318
310
|
* @example
|
|
319
311
|
* ```ts
|
|
320
|
-
* resolver.
|
|
312
|
+
* resolver.file(operationFileEntry(node, node.operationId), { root, output, group })
|
|
321
313
|
* ```
|
|
322
314
|
*/
|
|
323
315
|
function operationFileEntry(node, name, extname = ".ts") {
|
|
@@ -455,13 +447,13 @@ function getPrimarySuccessResponse(node) {
|
|
|
455
447
|
return getOperationSuccessResponses(node)[0] ?? null;
|
|
456
448
|
}
|
|
457
449
|
function resolveErrorNames(node, resolver) {
|
|
458
|
-
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.
|
|
450
|
+
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
|
|
459
451
|
}
|
|
460
452
|
function resolveSuccessNames(node, resolver) {
|
|
461
|
-
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.
|
|
453
|
+
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
|
|
462
454
|
}
|
|
463
455
|
function resolveStatusCodeNames(node, resolver) {
|
|
464
|
-
return node.responses.map((response) => resolver.
|
|
456
|
+
return node.responses.map((response) => resolver.response.status(node, response.statusCode));
|
|
465
457
|
}
|
|
466
458
|
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
467
459
|
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
@@ -478,11 +470,11 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
|
478
470
|
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
479
471
|
const exclude = new Set(options.exclude ?? []);
|
|
480
472
|
const paramNames = options.includeParams === false ? [] : [
|
|
481
|
-
...path.map((param) => resolver.
|
|
482
|
-
...query.map((param) => resolver.
|
|
483
|
-
...header.map((param) => resolver.
|
|
473
|
+
...path.map((param) => resolver.param.path(node, param)),
|
|
474
|
+
...query.map((param) => resolver.param.query(node, param)),
|
|
475
|
+
...header.map((param) => resolver.param.headers(node, param))
|
|
484
476
|
];
|
|
485
|
-
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.
|
|
477
|
+
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)];
|
|
486
478
|
const result = (options.order === "body-response-first" ? [
|
|
487
479
|
...bodyAndResponseNames,
|
|
488
480
|
...paramNames,
|
|
@@ -581,12 +573,12 @@ function maybeRefOrGetter(type) {
|
|
|
581
573
|
/**
|
|
582
574
|
* Builds the grouped `{ path, query, body, headers }` parameter that mirrors the client
|
|
583
575
|
* function signature. Only the groups the operation carries are emitted, typed from the
|
|
584
|
-
* operation's `
|
|
576
|
+
* operation's `Options`. `keys` narrows the emitted groups, used by the query key which
|
|
585
577
|
* never carries `headers`.
|
|
586
578
|
*
|
|
587
|
-
* By default the whole group is typed as the single `
|
|
579
|
+
* By default the whole group is typed as the single `Options` reference. When
|
|
588
580
|
* `memberTypeWrapper` is set, each group is emitted as its own member typed from the matching
|
|
589
|
-
* `
|
|
581
|
+
* `Options['<group>']` slice and wrapped, used by vue-query to apply
|
|
590
582
|
* `MaybeRefOrGetter` per group.
|
|
591
583
|
*/
|
|
592
584
|
function buildGroupedRequestParam(node, options) {
|
|
@@ -601,13 +593,13 @@ function buildGroupedRequestParam(node, options) {
|
|
|
601
593
|
headers: hasRequiredHeader
|
|
602
594
|
};
|
|
603
595
|
const isOptional = names.every((name) => !requiredByGroup[name]);
|
|
604
|
-
const
|
|
596
|
+
const optionsName = resolver.response.options(node);
|
|
605
597
|
const omittedKeys = requestGroupOrder$1.filter((key) => !keys.includes(key));
|
|
606
|
-
const
|
|
598
|
+
const optionsType = omittedKeys.length > 0 ? `Omit<${optionsName}, ${omittedKeys.map((key) => `'${key}'`).join(" | ")}>` : optionsName;
|
|
607
599
|
if (memberTypeWrapper) {
|
|
608
600
|
const members = names.map((name) => ({
|
|
609
601
|
name,
|
|
610
|
-
type: memberTypeWrapper(`${
|
|
602
|
+
type: memberTypeWrapper(`${optionsType}['${name}']`),
|
|
611
603
|
optional: !requiredByGroup[name]
|
|
612
604
|
}));
|
|
613
605
|
return createFunctionParameter({
|
|
@@ -619,7 +611,7 @@ function buildGroupedRequestParam(node, options) {
|
|
|
619
611
|
}
|
|
620
612
|
return createFunctionParameter({
|
|
621
613
|
name: createObjectBindingPattern({ elements: names.map((name) => ({ name })) }),
|
|
622
|
-
type:
|
|
614
|
+
type: optionsType,
|
|
623
615
|
optional: false,
|
|
624
616
|
...isOptional ? { default: "{}" } : {}
|
|
625
617
|
});
|
|
@@ -733,15 +725,15 @@ function resolveClientOperation(options) {
|
|
|
733
725
|
const { clientPlugin, driver, node, root, output } = options;
|
|
734
726
|
if (!clientPlugin) return null;
|
|
735
727
|
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
736
|
-
if (!resolver) return null;
|
|
737
728
|
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
738
|
-
const file = resolver.
|
|
729
|
+
const file = resolver.file({
|
|
730
|
+
...operationFileEntry(node, node.operationId),
|
|
739
731
|
root,
|
|
740
732
|
output: plugin?.options?.output ?? output,
|
|
741
733
|
group: plugin?.options?.group ?? void 0
|
|
742
734
|
});
|
|
743
735
|
return {
|
|
744
|
-
name: resolver.
|
|
736
|
+
name: resolver.name(node.operationId),
|
|
745
737
|
path: file.path,
|
|
746
738
|
clientPath: path.resolve(root, ".kubb/client.ts")
|
|
747
739
|
};
|
|
@@ -828,7 +820,7 @@ function getQueryOptionsParams(node, options) {
|
|
|
828
820
|
}
|
|
829
821
|
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
|
|
830
822
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
831
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
823
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
832
824
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
833
825
|
const TData = responseName;
|
|
834
826
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -868,7 +860,7 @@ const callPrinter$3 = functionPrinter({ mode: "call" });
|
|
|
868
860
|
function buildInfiniteQueryParamsNode(node, options) {
|
|
869
861
|
const { resolver } = options;
|
|
870
862
|
const successNames = resolveSuccessNames(node, resolver);
|
|
871
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.
|
|
863
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
872
864
|
const errorNames = resolveErrorNames(node, resolver);
|
|
873
865
|
const optionsParam = createFunctionParameter({
|
|
874
866
|
name: "options",
|
|
@@ -891,7 +883,7 @@ function buildInfiniteQueryParamsNode(node, options) {
|
|
|
891
883
|
}
|
|
892
884
|
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
|
|
893
885
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
894
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
886
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
895
887
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
896
888
|
const TData = responseName;
|
|
897
889
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -941,7 +933,7 @@ const declarationPrinter$2 = functionPrinter({ mode: "declaration" });
|
|
|
941
933
|
const callPrinter$2 = functionPrinter({ mode: "call" });
|
|
942
934
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName }) {
|
|
943
935
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
944
|
-
const queryFnDataType = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
936
|
+
const queryFnDataType = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
945
937
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
946
938
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
947
939
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -951,8 +943,8 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
951
943
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
952
944
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
953
945
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
954
|
-
const groupName = tsResolver.
|
|
955
|
-
return groupName !== tsResolver.
|
|
946
|
+
const groupName = tsResolver.param.query(node, rawQueryParams[0]);
|
|
947
|
+
return groupName !== tsResolver.param.name(node, rawQueryParams[0]) ? groupName : null;
|
|
956
948
|
})() : null;
|
|
957
949
|
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
958
950
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
@@ -968,8 +960,8 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
968
960
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
969
961
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
970
962
|
if (hasNewParams) {
|
|
971
|
-
const nextAccessor = nextParam ?
|
|
972
|
-
const prevAccessor = previousParam ?
|
|
963
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
964
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
973
965
|
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
974
966
|
}
|
|
975
967
|
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
@@ -1031,12 +1023,12 @@ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${que
|
|
|
1031
1023
|
const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
|
|
1032
1024
|
const callPrinter$1 = functionPrinter({ mode: "call" });
|
|
1033
1025
|
function resolveMutationRequestType(node, resolver) {
|
|
1034
|
-
return buildGroupedRequestParam(node, { resolver }) ? resolver.
|
|
1026
|
+
return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
|
|
1035
1027
|
}
|
|
1036
1028
|
function buildMutationParamsNode(node, options) {
|
|
1037
1029
|
const { resolver } = options;
|
|
1038
1030
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1039
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.
|
|
1031
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
1040
1032
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1041
1033
|
return createFunctionParameters({ params: [createFunctionParameter({
|
|
1042
1034
|
name: "options",
|
|
@@ -1054,7 +1046,7 @@ function buildMutationParamsNode(node, options) {
|
|
|
1054
1046
|
}
|
|
1055
1047
|
function Mutation({ name, clientName, node, tsResolver, mutationKeyName }) {
|
|
1056
1048
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1057
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1049
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1058
1050
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1059
1051
|
const TData = responseName;
|
|
1060
1052
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1110,7 +1102,7 @@ const callPrinter = functionPrinter({ mode: "call" });
|
|
|
1110
1102
|
function buildQueryParamsNode(node, options) {
|
|
1111
1103
|
const { resolver } = options;
|
|
1112
1104
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1113
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.
|
|
1105
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
1114
1106
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1115
1107
|
const optionsParam = createFunctionParameter({
|
|
1116
1108
|
name: "options",
|
|
@@ -1133,7 +1125,7 @@ function buildQueryParamsNode(node, options) {
|
|
|
1133
1125
|
}
|
|
1134
1126
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
|
|
1135
1127
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1136
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1128
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1137
1129
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1138
1130
|
const TData = responseName;
|
|
1139
1131
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1214,26 +1206,28 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1214
1206
|
output
|
|
1215
1207
|
});
|
|
1216
1208
|
if (!contractOp) return null;
|
|
1217
|
-
const queryName = resolver.
|
|
1218
|
-
const queryOptionsName = resolver.
|
|
1219
|
-
const queryKeyName = resolver.
|
|
1220
|
-
const queryKeyTypeName = resolver.
|
|
1209
|
+
const queryName = resolver.infiniteQuery.name(node);
|
|
1210
|
+
const queryOptionsName = resolver.infiniteQuery.optionsName(node);
|
|
1211
|
+
const queryKeyName = resolver.infiniteQuery.keyName(node);
|
|
1212
|
+
const queryKeyTypeName = resolver.infiniteQuery.keyTypeName(node);
|
|
1221
1213
|
const meta = {
|
|
1222
|
-
file: resolver.
|
|
1214
|
+
file: resolver.file({
|
|
1215
|
+
...operationFileEntry(node, queryName),
|
|
1223
1216
|
root,
|
|
1224
1217
|
output,
|
|
1225
1218
|
group: group ?? void 0
|
|
1226
1219
|
}),
|
|
1227
|
-
fileTs: tsResolver.
|
|
1220
|
+
fileTs: tsResolver.file({
|
|
1221
|
+
...operationFileEntry(node, node.operationId),
|
|
1228
1222
|
root,
|
|
1229
1223
|
output: pluginTs.options?.output ?? output,
|
|
1230
1224
|
group: pluginTs.options?.group ?? void 0
|
|
1231
1225
|
})
|
|
1232
1226
|
};
|
|
1233
1227
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1234
|
-
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.
|
|
1228
|
+
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.param.query(node, rawQueryParams[0]) !== tsResolver.param.name(node, rawQueryParams[0]) ? tsResolver.param.query(node, rawQueryParams[0]) : null;
|
|
1235
1229
|
const importedTypeNames = [
|
|
1236
|
-
tsResolver.
|
|
1230
|
+
tsResolver.response.options(node),
|
|
1237
1231
|
queryParamsTypeName,
|
|
1238
1232
|
...resolveOperationTypeNames(node, tsResolver, {
|
|
1239
1233
|
exclude: [queryKeyTypeName],
|
|
@@ -1246,7 +1240,7 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1246
1240
|
baseName: meta.file.baseName,
|
|
1247
1241
|
path: meta.file.path,
|
|
1248
1242
|
meta: meta.file.meta,
|
|
1249
|
-
banner: resolver.
|
|
1243
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1250
1244
|
output,
|
|
1251
1245
|
config,
|
|
1252
1246
|
file: {
|
|
@@ -1254,7 +1248,7 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1254
1248
|
baseName: meta.file.baseName
|
|
1255
1249
|
}
|
|
1256
1250
|
}),
|
|
1257
|
-
footer: resolver.
|
|
1251
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1258
1252
|
output,
|
|
1259
1253
|
config,
|
|
1260
1254
|
file: {
|
|
@@ -1376,22 +1370,24 @@ const mutationGenerator = defineGenerator({
|
|
|
1376
1370
|
output
|
|
1377
1371
|
});
|
|
1378
1372
|
if (!contractOp) return null;
|
|
1379
|
-
const mutationHookName = resolver.
|
|
1380
|
-
const mutationTypeName = resolver.
|
|
1381
|
-
const mutationKeyName = resolver.
|
|
1373
|
+
const mutationHookName = resolver.mutation.name(node);
|
|
1374
|
+
const mutationTypeName = resolver.mutation.typeName(node);
|
|
1375
|
+
const mutationKeyName = resolver.mutation.keyName(node);
|
|
1382
1376
|
const meta = {
|
|
1383
|
-
file: resolver.
|
|
1377
|
+
file: resolver.file({
|
|
1378
|
+
...operationFileEntry(node, mutationHookName),
|
|
1384
1379
|
root,
|
|
1385
1380
|
output,
|
|
1386
1381
|
group: group ?? void 0
|
|
1387
1382
|
}),
|
|
1388
|
-
fileTs: tsResolver.
|
|
1383
|
+
fileTs: tsResolver.file({
|
|
1384
|
+
...operationFileEntry(node, node.operationId),
|
|
1389
1385
|
root,
|
|
1390
1386
|
output: pluginTs.options?.output ?? output,
|
|
1391
1387
|
group: pluginTs.options?.group ?? void 0
|
|
1392
1388
|
})
|
|
1393
1389
|
};
|
|
1394
|
-
const importedTypeNames = [tsResolver.
|
|
1390
|
+
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
1395
1391
|
order: "body-response-first",
|
|
1396
1392
|
includeParams: false
|
|
1397
1393
|
})].filter((name) => Boolean(name));
|
|
@@ -1402,7 +1398,7 @@ const mutationGenerator = defineGenerator({
|
|
|
1402
1398
|
baseName: meta.file.baseName,
|
|
1403
1399
|
path: meta.file.path,
|
|
1404
1400
|
meta: meta.file.meta,
|
|
1405
|
-
banner: resolver.
|
|
1401
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1406
1402
|
output,
|
|
1407
1403
|
config,
|
|
1408
1404
|
file: {
|
|
@@ -1410,7 +1406,7 @@ const mutationGenerator = defineGenerator({
|
|
|
1410
1406
|
baseName: meta.file.baseName
|
|
1411
1407
|
}
|
|
1412
1408
|
}),
|
|
1413
|
-
footer: resolver.
|
|
1409
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1414
1410
|
output,
|
|
1415
1411
|
config,
|
|
1416
1412
|
file: {
|
|
@@ -1503,23 +1499,25 @@ const queryGenerator = defineGenerator({
|
|
|
1503
1499
|
output
|
|
1504
1500
|
});
|
|
1505
1501
|
if (!contractOp) return null;
|
|
1506
|
-
const queryName = resolver.
|
|
1507
|
-
const queryOptionsName = resolver.
|
|
1508
|
-
const queryKeyName = resolver.
|
|
1509
|
-
const queryKeyTypeName = resolver.
|
|
1502
|
+
const queryName = resolver.query.name(node);
|
|
1503
|
+
const queryOptionsName = resolver.query.optionsName(node);
|
|
1504
|
+
const queryKeyName = resolver.query.keyName(node);
|
|
1505
|
+
const queryKeyTypeName = resolver.query.keyTypeName(node);
|
|
1510
1506
|
const meta = {
|
|
1511
|
-
file: resolver.
|
|
1507
|
+
file: resolver.file({
|
|
1508
|
+
...operationFileEntry(node, queryName),
|
|
1512
1509
|
root,
|
|
1513
1510
|
output,
|
|
1514
1511
|
group: group ?? void 0
|
|
1515
1512
|
}),
|
|
1516
|
-
fileTs: tsResolver.
|
|
1513
|
+
fileTs: tsResolver.file({
|
|
1514
|
+
...operationFileEntry(node, node.operationId),
|
|
1517
1515
|
root,
|
|
1518
1516
|
output: pluginTs.options?.output ?? output,
|
|
1519
1517
|
group: pluginTs.options?.group ?? void 0
|
|
1520
1518
|
})
|
|
1521
1519
|
};
|
|
1522
|
-
const importedTypeNames = [tsResolver.
|
|
1520
|
+
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
1523
1521
|
exclude: [queryKeyTypeName],
|
|
1524
1522
|
order: "body-response-first",
|
|
1525
1523
|
includeParams: false
|
|
@@ -1529,7 +1527,7 @@ const queryGenerator = defineGenerator({
|
|
|
1529
1527
|
baseName: meta.file.baseName,
|
|
1530
1528
|
path: meta.file.path,
|
|
1531
1529
|
meta: meta.file.meta,
|
|
1532
|
-
banner: resolver.
|
|
1530
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1533
1531
|
output,
|
|
1534
1532
|
config,
|
|
1535
1533
|
file: {
|
|
@@ -1537,7 +1535,7 @@ const queryGenerator = defineGenerator({
|
|
|
1537
1535
|
baseName: meta.file.baseName
|
|
1538
1536
|
}
|
|
1539
1537
|
}),
|
|
1540
|
-
footer: resolver.
|
|
1538
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1541
1539
|
output,
|
|
1542
1540
|
config,
|
|
1543
1541
|
file: {
|
|
@@ -1628,69 +1626,67 @@ function capitalize(name) {
|
|
|
1628
1626
|
* file paths for every generated TanStack Query composable (`useFoo`,
|
|
1629
1627
|
* `useFooInfinite`) and its companion helpers.
|
|
1630
1628
|
*
|
|
1631
|
-
* Functions and files use camelCase;
|
|
1629
|
+
* The `default` helpers are supplied by `createResolver`. Functions and files use camelCase;
|
|
1630
|
+
* composables get the `use` prefix. Operation-specific naming is grouped under the `query`,
|
|
1631
|
+
* `infiniteQuery`, and `mutation` namespaces.
|
|
1632
1632
|
*
|
|
1633
1633
|
* @example Resolve composable and helper names
|
|
1634
1634
|
* ```ts
|
|
1635
1635
|
* import { resolverVueQuery } from '@kubb/plugin-vue-query'
|
|
1636
1636
|
*
|
|
1637
|
-
* resolverVueQuery.
|
|
1638
|
-
* resolverVueQuery.
|
|
1639
|
-
* resolverVueQuery.
|
|
1637
|
+
* resolverVueQuery.query.name(operationNode) // 'useGetPetById'
|
|
1638
|
+
* resolverVueQuery.query.keyName(operationNode) // 'getPetByIdQueryKey'
|
|
1639
|
+
* resolverVueQuery.query.optionsName(operationNode) // 'getPetByIdQueryOptions'
|
|
1640
1640
|
* ```
|
|
1641
1641
|
*/
|
|
1642
|
-
const resolverVueQuery =
|
|
1643
|
-
name: "default",
|
|
1642
|
+
const resolverVueQuery = createResolver({
|
|
1644
1643
|
pluginName: "plugin-vue-query",
|
|
1645
|
-
|
|
1646
|
-
|
|
1647
|
-
|
|
1648
|
-
|
|
1649
|
-
|
|
1650
|
-
|
|
1651
|
-
|
|
1652
|
-
|
|
1653
|
-
|
|
1654
|
-
|
|
1655
|
-
|
|
1656
|
-
|
|
1657
|
-
|
|
1658
|
-
|
|
1659
|
-
|
|
1660
|
-
|
|
1661
|
-
return `use${capitalize(this.resolveName(node.operationId))}`;
|
|
1662
|
-
},
|
|
1663
|
-
resolveQueryOptionsName(node) {
|
|
1664
|
-
return `${this.resolveName(node.operationId)}QueryOptions`;
|
|
1665
|
-
},
|
|
1666
|
-
resolveInfiniteQueryOptionsName(node) {
|
|
1667
|
-
return `${this.resolveName(node.operationId)}InfiniteQueryOptions`;
|
|
1668
|
-
},
|
|
1669
|
-
resolveQueryKeyName(node) {
|
|
1670
|
-
return `${this.resolveName(node.operationId)}QueryKey`;
|
|
1671
|
-
},
|
|
1672
|
-
resolveInfiniteQueryKeyName(node) {
|
|
1673
|
-
return `${this.resolveName(node.operationId)}InfiniteQueryKey`;
|
|
1674
|
-
},
|
|
1675
|
-
resolveMutationKeyName(node) {
|
|
1676
|
-
return `${this.resolveName(node.operationId)}MutationKey`;
|
|
1677
|
-
},
|
|
1678
|
-
resolveQueryKeyTypeName(node) {
|
|
1679
|
-
return `${capitalize(this.resolveName(node.operationId))}QueryKey`;
|
|
1680
|
-
},
|
|
1681
|
-
resolveInfiniteQueryKeyTypeName(node) {
|
|
1682
|
-
return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`;
|
|
1683
|
-
},
|
|
1684
|
-
resolveMutationTypeName(node) {
|
|
1685
|
-
return capitalize(this.resolveName(node.operationId));
|
|
1644
|
+
query: {
|
|
1645
|
+
name(node) {
|
|
1646
|
+
return `use${capitalize(this.name(node.operationId))}`;
|
|
1647
|
+
},
|
|
1648
|
+
keyName(node) {
|
|
1649
|
+
return `${this.name(node.operationId)}QueryKey`;
|
|
1650
|
+
},
|
|
1651
|
+
keyTypeName(node) {
|
|
1652
|
+
return `${capitalize(this.name(node.operationId))}QueryKey`;
|
|
1653
|
+
},
|
|
1654
|
+
optionsName(node) {
|
|
1655
|
+
return `${this.name(node.operationId)}QueryOptions`;
|
|
1656
|
+
},
|
|
1657
|
+
clientName(node) {
|
|
1658
|
+
return this.name(node.operationId);
|
|
1659
|
+
}
|
|
1686
1660
|
},
|
|
1687
|
-
|
|
1688
|
-
|
|
1661
|
+
infiniteQuery: {
|
|
1662
|
+
name(node) {
|
|
1663
|
+
return `use${capitalize(this.name(node.operationId))}Infinite`;
|
|
1664
|
+
},
|
|
1665
|
+
keyName(node) {
|
|
1666
|
+
return `${this.name(node.operationId)}InfiniteQueryKey`;
|
|
1667
|
+
},
|
|
1668
|
+
keyTypeName(node) {
|
|
1669
|
+
return `${capitalize(this.name(node.operationId))}InfiniteQueryKey`;
|
|
1670
|
+
},
|
|
1671
|
+
optionsName(node) {
|
|
1672
|
+
return `${this.name(node.operationId)}InfiniteQueryOptions`;
|
|
1673
|
+
},
|
|
1674
|
+
clientName(node) {
|
|
1675
|
+
return `${this.name(node.operationId)}Infinite`;
|
|
1676
|
+
}
|
|
1689
1677
|
},
|
|
1690
|
-
|
|
1691
|
-
|
|
1678
|
+
mutation: {
|
|
1679
|
+
name(node) {
|
|
1680
|
+
return `use${capitalize(this.name(node.operationId))}`;
|
|
1681
|
+
},
|
|
1682
|
+
keyName(node) {
|
|
1683
|
+
return `${this.name(node.operationId)}MutationKey`;
|
|
1684
|
+
},
|
|
1685
|
+
typeName(node) {
|
|
1686
|
+
return capitalize(this.name(node.operationId));
|
|
1687
|
+
}
|
|
1692
1688
|
}
|
|
1693
|
-
})
|
|
1689
|
+
});
|
|
1694
1690
|
//#endregion
|
|
1695
1691
|
//#region src/plugin.ts
|
|
1696
1692
|
/**
|
|
@@ -1738,10 +1734,7 @@ const pluginVueQuery = definePlugin((options) => {
|
|
|
1738
1734
|
options,
|
|
1739
1735
|
dependencies: [pluginTsName],
|
|
1740
1736
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
1741
|
-
const resolver = userResolver ?
|
|
1742
|
-
...resolverVueQuery,
|
|
1743
|
-
...userResolver
|
|
1744
|
-
} : resolverVueQuery;
|
|
1737
|
+
const resolver = userResolver ? Resolver.merge(resolverVueQuery, userResolver) : resolverVueQuery;
|
|
1745
1738
|
const resolvedClient = resolveClient({
|
|
1746
1739
|
client,
|
|
1747
1740
|
pluginNames: (ctx.config.plugins ?? []).map((p) => p.name).filter((name) => Boolean(name))
|