@kubb/plugin-vue-query 5.0.0-beta.85 → 5.0.0-beta.87
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 +164 -161
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +70 -61
- package/dist/index.js +164 -161
- package/dist/index.js.map +1 -1
- package/package.json +6 -6
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.
|
|
@@ -182,9 +157,42 @@ const reservedWords = /* @__PURE__ */ new Set([
|
|
|
182
157
|
*/
|
|
183
158
|
function isValidVarName(name) {
|
|
184
159
|
if (!name || reservedWords.has(name)) return false;
|
|
160
|
+
return isIdentifier(name);
|
|
161
|
+
}
|
|
162
|
+
/**
|
|
163
|
+
* Returns `true` when `name` is syntactically a valid identifier, ignoring reserved words.
|
|
164
|
+
*
|
|
165
|
+
* Reserved words and globals (`class`, `name`, `Date`, …) are valid as bare object-literal keys
|
|
166
|
+
* even though they are not valid variable names, so use this (not {@link isValidVarName}) when
|
|
167
|
+
* deciding whether an object key needs quoting.
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```ts
|
|
171
|
+
* isIdentifier('name') // true
|
|
172
|
+
* isIdentifier('x-total')// false
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
function isIdentifier(name) {
|
|
185
176
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
186
177
|
}
|
|
187
178
|
//#endregion
|
|
179
|
+
//#region ../../internals/utils/src/strings.ts
|
|
180
|
+
/**
|
|
181
|
+
* Renders a dotted path or string array as an optional-chaining accessor expression rooted at
|
|
182
|
+
* `accessor`. Returns `null` for an empty path.
|
|
183
|
+
*
|
|
184
|
+
* @example
|
|
185
|
+
* ```ts
|
|
186
|
+
* getNestedAccessor('pagination.next.id', 'lastPage')
|
|
187
|
+
* // "lastPage?.['pagination']?.['next']?.['id']"
|
|
188
|
+
* ```
|
|
189
|
+
*/
|
|
190
|
+
function getNestedAccessor(param, accessor) {
|
|
191
|
+
const parts = Array.isArray(param) ? param : param.split(".");
|
|
192
|
+
if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
|
|
193
|
+
return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
|
|
194
|
+
}
|
|
195
|
+
//#endregion
|
|
188
196
|
//#region ../../internals/utils/src/url.ts
|
|
189
197
|
function transformParam(raw, casing) {
|
|
190
198
|
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
@@ -337,13 +345,13 @@ function dedupeByCasedName(params) {
|
|
|
337
345
|
//#region ../../internals/shared/src/operation.ts
|
|
338
346
|
/**
|
|
339
347
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
340
|
-
* `resolver.
|
|
348
|
+
* `resolver.file`: a file named `name`, tagged by the operation's first
|
|
341
349
|
* tag (or `'default'`), at the operation's path. Centralizes the entry object
|
|
342
350
|
* that was repeated at dozens of call sites across the client and query plugins.
|
|
343
351
|
*
|
|
344
352
|
* @example
|
|
345
353
|
* ```ts
|
|
346
|
-
* resolver.
|
|
354
|
+
* resolver.file(operationFileEntry(node, node.operationId), { root, output, group })
|
|
347
355
|
* ```
|
|
348
356
|
*/
|
|
349
357
|
function operationFileEntry(node, name, extname = ".ts") {
|
|
@@ -360,8 +368,11 @@ function getOperationLink(node, link) {
|
|
|
360
368
|
if (link === "urlPath") return node.path ? `{@link ${Url.toPath(node.path)}}` : null;
|
|
361
369
|
return node.path ? `{@link ${node.path.replaceAll("{", ":").replaceAll("}", "")}}` : null;
|
|
362
370
|
}
|
|
363
|
-
|
|
364
|
-
|
|
371
|
+
/**
|
|
372
|
+
* Derives the shared `ContentTypeInfo` shape from a list of content types, tracking whether several
|
|
373
|
+
* are present and the union, default, and form-data flags the client uses to pick one.
|
|
374
|
+
*/
|
|
375
|
+
function buildContentTypeInfo(contentTypes) {
|
|
365
376
|
const isMultipleContentTypes = contentTypes.length > 1;
|
|
366
377
|
return {
|
|
367
378
|
contentTypes,
|
|
@@ -371,20 +382,15 @@ function getContentTypeInfo(node) {
|
|
|
371
382
|
hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
|
|
372
383
|
};
|
|
373
384
|
}
|
|
385
|
+
function getContentTypeInfo(node) {
|
|
386
|
+
return buildContentTypeInfo(node.requestBody?.content?.map((e) => e.contentType) ?? []);
|
|
387
|
+
}
|
|
374
388
|
/**
|
|
375
389
|
* The request-body counterpart for the primary success response: the content types it documents and
|
|
376
390
|
* whether several are present, so the client can let a caller pick which one to accept.
|
|
377
391
|
*/
|
|
378
392
|
function getResponseContentTypeInfo(node) {
|
|
379
|
-
|
|
380
|
-
const isMultipleContentTypes = contentTypes.length > 1;
|
|
381
|
-
return {
|
|
382
|
-
contentTypes,
|
|
383
|
-
isMultipleContentTypes,
|
|
384
|
-
contentTypeUnion: isMultipleContentTypes ? contentTypes.map((ct) => JSON.stringify(ct)).join(" | ") : "",
|
|
385
|
-
defaultContentType: contentTypes[0] ?? "application/json",
|
|
386
|
-
hasFormData: contentTypes.some((ct) => ct === "multipart/form-data")
|
|
387
|
-
};
|
|
393
|
+
return buildContentTypeInfo(getPrimarySuccessResponse(node)?.content?.map((e) => e.contentType) ?? []);
|
|
388
394
|
}
|
|
389
395
|
function buildRequestConfigType(node) {
|
|
390
396
|
const request = getContentTypeInfo(node);
|
|
@@ -481,13 +487,13 @@ function getPrimarySuccessResponse(node) {
|
|
|
481
487
|
return getOperationSuccessResponses(node)[0] ?? null;
|
|
482
488
|
}
|
|
483
489
|
function resolveErrorNames(node, resolver) {
|
|
484
|
-
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.
|
|
490
|
+
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
|
|
485
491
|
}
|
|
486
492
|
function resolveSuccessNames(node, resolver) {
|
|
487
|
-
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.
|
|
493
|
+
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
|
|
488
494
|
}
|
|
489
495
|
function resolveStatusCodeNames(node, resolver) {
|
|
490
|
-
return node.responses.map((response) => resolver.
|
|
496
|
+
return node.responses.map((response) => resolver.response.status(node, response.statusCode));
|
|
491
497
|
}
|
|
492
498
|
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
493
499
|
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
@@ -504,11 +510,11 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
|
504
510
|
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
505
511
|
const exclude = new Set(options.exclude ?? []);
|
|
506
512
|
const paramNames = options.includeParams === false ? [] : [
|
|
507
|
-
...path.map((param) => resolver.
|
|
508
|
-
...query.map((param) => resolver.
|
|
509
|
-
...header.map((param) => resolver.
|
|
513
|
+
...path.map((param) => resolver.param.path(node, param)),
|
|
514
|
+
...query.map((param) => resolver.param.query(node, param)),
|
|
515
|
+
...header.map((param) => resolver.param.headers(node, param))
|
|
510
516
|
];
|
|
511
|
-
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.
|
|
517
|
+
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)];
|
|
512
518
|
const result = (options.order === "body-response-first" ? [
|
|
513
519
|
...bodyAndResponseNames,
|
|
514
520
|
...paramNames,
|
|
@@ -607,12 +613,12 @@ function maybeRefOrGetter(type) {
|
|
|
607
613
|
/**
|
|
608
614
|
* Builds the grouped `{ path, query, body, headers }` parameter that mirrors the client
|
|
609
615
|
* function signature. Only the groups the operation carries are emitted, typed from the
|
|
610
|
-
* operation's `
|
|
616
|
+
* operation's `Options`. `keys` narrows the emitted groups, used by the query key which
|
|
611
617
|
* never carries `headers`.
|
|
612
618
|
*
|
|
613
|
-
* By default the whole group is typed as the single `
|
|
619
|
+
* By default the whole group is typed as the single `Options` reference. When
|
|
614
620
|
* `memberTypeWrapper` is set, each group is emitted as its own member typed from the matching
|
|
615
|
-
* `
|
|
621
|
+
* `Options['<group>']` slice and wrapped, used by vue-query to apply
|
|
616
622
|
* `MaybeRefOrGetter` per group.
|
|
617
623
|
*/
|
|
618
624
|
function buildGroupedRequestParam(node, options) {
|
|
@@ -627,13 +633,13 @@ function buildGroupedRequestParam(node, options) {
|
|
|
627
633
|
headers: hasRequiredHeader
|
|
628
634
|
};
|
|
629
635
|
const isOptional = names.every((name) => !requiredByGroup[name]);
|
|
630
|
-
const
|
|
636
|
+
const optionsName = resolver.response.options(node);
|
|
631
637
|
const omittedKeys = requestGroupOrder$1.filter((key) => !keys.includes(key));
|
|
632
|
-
const
|
|
638
|
+
const optionsType = omittedKeys.length > 0 ? `Omit<${optionsName}, ${omittedKeys.map((key) => `'${key}'`).join(" | ")}>` : optionsName;
|
|
633
639
|
if (memberTypeWrapper) {
|
|
634
640
|
const members = names.map((name) => ({
|
|
635
641
|
name,
|
|
636
|
-
type: memberTypeWrapper(`${
|
|
642
|
+
type: memberTypeWrapper(`${optionsType}['${name}']`),
|
|
637
643
|
optional: !requiredByGroup[name]
|
|
638
644
|
}));
|
|
639
645
|
return (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
@@ -645,7 +651,7 @@ function buildGroupedRequestParam(node, options) {
|
|
|
645
651
|
}
|
|
646
652
|
return (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
647
653
|
name: (0, _kubb_plugin_ts.createObjectBindingPattern)({ elements: names.map((name) => ({ name })) }),
|
|
648
|
-
type:
|
|
654
|
+
type: optionsType,
|
|
649
655
|
optional: false,
|
|
650
656
|
...isOptional ? { default: "{}" } : {}
|
|
651
657
|
});
|
|
@@ -759,15 +765,15 @@ function resolveClientOperation(options) {
|
|
|
759
765
|
const { clientPlugin, driver, node, root, output } = options;
|
|
760
766
|
if (!clientPlugin) return null;
|
|
761
767
|
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
762
|
-
if (!resolver) return null;
|
|
763
768
|
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
764
|
-
const file = resolver.
|
|
769
|
+
const file = resolver.file({
|
|
770
|
+
...operationFileEntry(node, node.operationId),
|
|
765
771
|
root,
|
|
766
772
|
output: plugin?.options?.output ?? output,
|
|
767
773
|
group: plugin?.options?.group ?? void 0
|
|
768
774
|
});
|
|
769
775
|
return {
|
|
770
|
-
name: resolver.
|
|
776
|
+
name: resolver.name(node.operationId),
|
|
771
777
|
path: file.path,
|
|
772
778
|
clientPath: node_path.default.resolve(root, ".kubb/client.ts")
|
|
773
779
|
};
|
|
@@ -854,7 +860,7 @@ function getQueryOptionsParams(node, options) {
|
|
|
854
860
|
}
|
|
855
861
|
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
|
|
856
862
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
857
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
863
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
858
864
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
859
865
|
const TData = responseName;
|
|
860
866
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -894,7 +900,7 @@ const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
|
894
900
|
function buildInfiniteQueryParamsNode(node, options) {
|
|
895
901
|
const { resolver } = options;
|
|
896
902
|
const successNames = resolveSuccessNames(node, resolver);
|
|
897
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.
|
|
903
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
898
904
|
const errorNames = resolveErrorNames(node, resolver);
|
|
899
905
|
const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
900
906
|
name: "options",
|
|
@@ -917,7 +923,7 @@ function buildInfiniteQueryParamsNode(node, options) {
|
|
|
917
923
|
}
|
|
918
924
|
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
|
|
919
925
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
920
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
926
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
921
927
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
922
928
|
const TData = responseName;
|
|
923
929
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -967,7 +973,7 @@ const declarationPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "decla
|
|
|
967
973
|
const callPrinter$2 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
968
974
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName }) {
|
|
969
975
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
970
|
-
const queryFnDataType = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
976
|
+
const queryFnDataType = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
971
977
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
972
978
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
973
979
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -977,8 +983,8 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
977
983
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
978
984
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
979
985
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
980
|
-
const groupName = tsResolver.
|
|
981
|
-
return groupName !== tsResolver.
|
|
986
|
+
const groupName = tsResolver.param.query(node, rawQueryParams[0]);
|
|
987
|
+
return groupName !== tsResolver.param.name(node, rawQueryParams[0]) ? groupName : null;
|
|
982
988
|
})() : null;
|
|
983
989
|
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
984
990
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
@@ -994,8 +1000,8 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
994
1000
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
995
1001
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
996
1002
|
if (hasNewParams) {
|
|
997
|
-
const nextAccessor = nextParam ?
|
|
998
|
-
const prevAccessor = previousParam ?
|
|
1003
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
1004
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
999
1005
|
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1000
1006
|
}
|
|
1001
1007
|
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
@@ -1057,12 +1063,12 @@ return infiniteQueryOptions<${queryFnDataType}, ${errorType}, InfiniteData<${que
|
|
|
1057
1063
|
const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1058
1064
|
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1059
1065
|
function resolveMutationRequestType(node, resolver) {
|
|
1060
|
-
return buildGroupedRequestParam(node, { resolver }) ? resolver.
|
|
1066
|
+
return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
|
|
1061
1067
|
}
|
|
1062
1068
|
function buildMutationParamsNode(node, options) {
|
|
1063
1069
|
const { resolver } = options;
|
|
1064
1070
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1065
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.
|
|
1071
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
1066
1072
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1067
1073
|
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [(0, _kubb_plugin_ts.createFunctionParameter)({
|
|
1068
1074
|
name: "options",
|
|
@@ -1080,7 +1086,7 @@ function buildMutationParamsNode(node, options) {
|
|
|
1080
1086
|
}
|
|
1081
1087
|
function Mutation({ name, clientName, node, tsResolver, mutationKeyName }) {
|
|
1082
1088
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1083
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1089
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1084
1090
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1085
1091
|
const TData = responseName;
|
|
1086
1092
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1099,8 +1105,6 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName }) {
|
|
|
1099
1105
|
resolveMutationRequestType(node, tsResolver),
|
|
1100
1106
|
"TContext"
|
|
1101
1107
|
].join(", ");
|
|
1102
|
-
const mutationKeyParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: [] });
|
|
1103
|
-
const mutationKeyParamsCall = callPrinter$1.print(mutationKeyParamsNode) ?? "";
|
|
1104
1108
|
const paramsNode = buildMutationParamsNode(node, { resolver: tsResolver });
|
|
1105
1109
|
const paramsSignature = declarationPrinter$1.print(paramsNode) ?? "";
|
|
1106
1110
|
return /* @__PURE__ */ (0, kubb_jsx_jsx_runtime.jsx)(kubb_jsx.File.Source, {
|
|
@@ -1116,10 +1120,10 @@ function Mutation({ name, clientName, node, tsResolver, mutationKeyName }) {
|
|
|
1116
1120
|
children: `
|
|
1117
1121
|
const { mutation = {}, client: config = {} } = options ?? {}
|
|
1118
1122
|
const { client: queryClient, ...mutationOptions } = mutation;
|
|
1119
|
-
const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}(
|
|
1123
|
+
const mutationKey = mutationOptions?.mutationKey ?? ${mutationKeyName}()
|
|
1120
1124
|
|
|
1121
1125
|
return useMutation<${generics}>({
|
|
1122
|
-
mutationFn: async(${
|
|
1126
|
+
mutationFn: async(${argBindingStr}) => {
|
|
1123
1127
|
${mutationFnBody}
|
|
1124
1128
|
},
|
|
1125
1129
|
mutationKey,
|
|
@@ -1136,7 +1140,7 @@ const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
|
1136
1140
|
function buildQueryParamsNode(node, options) {
|
|
1137
1141
|
const { resolver } = options;
|
|
1138
1142
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1139
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.
|
|
1143
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
1140
1144
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1141
1145
|
const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
1142
1146
|
name: "options",
|
|
@@ -1159,7 +1163,7 @@ function buildQueryParamsNode(node, options) {
|
|
|
1159
1163
|
}
|
|
1160
1164
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver }) {
|
|
1161
1165
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1162
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1166
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1163
1167
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1164
1168
|
const TData = responseName;
|
|
1165
1169
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1228,9 +1232,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1228
1232
|
if (!isQuery || isMutation || !infiniteOptions) return null;
|
|
1229
1233
|
const normalizeKey = (key) => key.replace(/\?$/, "");
|
|
1230
1234
|
const queryParamKeys = getOperationParameters(node, { paramsCasing: "original" }).query.map((p) => p.name);
|
|
1231
|
-
|
|
1232
|
-
const hasCursorParam = !infiniteOptions.cursorParam || true;
|
|
1233
|
-
if (!hasQueryParam || !hasCursorParam) return null;
|
|
1235
|
+
if (!(infiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === infiniteOptions.queryParam) : false)) return null;
|
|
1234
1236
|
const importPath = query ? query.importPath : "@tanstack/vue-query";
|
|
1235
1237
|
const contractOp = resolveClientOperation({
|
|
1236
1238
|
clientPlugin: { pluginName: client.pluginName },
|
|
@@ -1240,26 +1242,28 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1240
1242
|
output
|
|
1241
1243
|
});
|
|
1242
1244
|
if (!contractOp) return null;
|
|
1243
|
-
const queryName = resolver.
|
|
1244
|
-
const queryOptionsName = resolver.
|
|
1245
|
-
const queryKeyName = resolver.
|
|
1246
|
-
const queryKeyTypeName = resolver.
|
|
1245
|
+
const queryName = resolver.infiniteQuery.name(node);
|
|
1246
|
+
const queryOptionsName = resolver.infiniteQuery.optionsName(node);
|
|
1247
|
+
const queryKeyName = resolver.infiniteQuery.keyName(node);
|
|
1248
|
+
const queryKeyTypeName = resolver.infiniteQuery.keyTypeName(node);
|
|
1247
1249
|
const meta = {
|
|
1248
|
-
file: resolver.
|
|
1250
|
+
file: resolver.file({
|
|
1251
|
+
...operationFileEntry(node, queryName),
|
|
1249
1252
|
root,
|
|
1250
1253
|
output,
|
|
1251
1254
|
group: group ?? void 0
|
|
1252
1255
|
}),
|
|
1253
|
-
fileTs: tsResolver.
|
|
1256
|
+
fileTs: tsResolver.file({
|
|
1257
|
+
...operationFileEntry(node, node.operationId),
|
|
1254
1258
|
root,
|
|
1255
1259
|
output: pluginTs.options?.output ?? output,
|
|
1256
1260
|
group: pluginTs.options?.group ?? void 0
|
|
1257
1261
|
})
|
|
1258
1262
|
};
|
|
1259
1263
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1260
|
-
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.
|
|
1264
|
+
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
1265
|
const importedTypeNames = [
|
|
1262
|
-
tsResolver.
|
|
1266
|
+
tsResolver.response.options(node),
|
|
1263
1267
|
queryParamsTypeName,
|
|
1264
1268
|
...resolveOperationTypeNames(node, tsResolver, {
|
|
1265
1269
|
exclude: [queryKeyTypeName],
|
|
@@ -1272,7 +1276,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1272
1276
|
baseName: meta.file.baseName,
|
|
1273
1277
|
path: meta.file.path,
|
|
1274
1278
|
meta: meta.file.meta,
|
|
1275
|
-
banner: resolver.
|
|
1279
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1276
1280
|
output,
|
|
1277
1281
|
config,
|
|
1278
1282
|
file: {
|
|
@@ -1280,7 +1284,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1280
1284
|
baseName: meta.file.baseName
|
|
1281
1285
|
}
|
|
1282
1286
|
}),
|
|
1283
|
-
footer: resolver.
|
|
1287
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1284
1288
|
output,
|
|
1285
1289
|
config,
|
|
1286
1290
|
file: {
|
|
@@ -1402,22 +1406,24 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1402
1406
|
output
|
|
1403
1407
|
});
|
|
1404
1408
|
if (!contractOp) return null;
|
|
1405
|
-
const mutationHookName = resolver.
|
|
1406
|
-
const mutationTypeName = resolver.
|
|
1407
|
-
const mutationKeyName = resolver.
|
|
1409
|
+
const mutationHookName = resolver.mutation.name(node);
|
|
1410
|
+
const mutationTypeName = resolver.mutation.typeName(node);
|
|
1411
|
+
const mutationKeyName = resolver.mutation.keyName(node);
|
|
1408
1412
|
const meta = {
|
|
1409
|
-
file: resolver.
|
|
1413
|
+
file: resolver.file({
|
|
1414
|
+
...operationFileEntry(node, mutationHookName),
|
|
1410
1415
|
root,
|
|
1411
1416
|
output,
|
|
1412
1417
|
group: group ?? void 0
|
|
1413
1418
|
}),
|
|
1414
|
-
fileTs: tsResolver.
|
|
1419
|
+
fileTs: tsResolver.file({
|
|
1420
|
+
...operationFileEntry(node, node.operationId),
|
|
1415
1421
|
root,
|
|
1416
1422
|
output: pluginTs.options?.output ?? output,
|
|
1417
1423
|
group: pluginTs.options?.group ?? void 0
|
|
1418
1424
|
})
|
|
1419
1425
|
};
|
|
1420
|
-
const importedTypeNames = [tsResolver.
|
|
1426
|
+
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
1421
1427
|
order: "body-response-first",
|
|
1422
1428
|
includeParams: false
|
|
1423
1429
|
})].filter((name) => Boolean(name));
|
|
@@ -1428,7 +1434,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1428
1434
|
baseName: meta.file.baseName,
|
|
1429
1435
|
path: meta.file.path,
|
|
1430
1436
|
meta: meta.file.meta,
|
|
1431
|
-
banner: resolver.
|
|
1437
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1432
1438
|
output,
|
|
1433
1439
|
config,
|
|
1434
1440
|
file: {
|
|
@@ -1436,7 +1442,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1436
1442
|
baseName: meta.file.baseName
|
|
1437
1443
|
}
|
|
1438
1444
|
}),
|
|
1439
|
-
footer: resolver.
|
|
1445
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1440
1446
|
output,
|
|
1441
1447
|
config,
|
|
1442
1448
|
file: {
|
|
@@ -1529,23 +1535,25 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1529
1535
|
output
|
|
1530
1536
|
});
|
|
1531
1537
|
if (!contractOp) return null;
|
|
1532
|
-
const queryName = resolver.
|
|
1533
|
-
const queryOptionsName = resolver.
|
|
1534
|
-
const queryKeyName = resolver.
|
|
1535
|
-
const queryKeyTypeName = resolver.
|
|
1538
|
+
const queryName = resolver.query.name(node);
|
|
1539
|
+
const queryOptionsName = resolver.query.optionsName(node);
|
|
1540
|
+
const queryKeyName = resolver.query.keyName(node);
|
|
1541
|
+
const queryKeyTypeName = resolver.query.keyTypeName(node);
|
|
1536
1542
|
const meta = {
|
|
1537
|
-
file: resolver.
|
|
1543
|
+
file: resolver.file({
|
|
1544
|
+
...operationFileEntry(node, queryName),
|
|
1538
1545
|
root,
|
|
1539
1546
|
output,
|
|
1540
1547
|
group: group ?? void 0
|
|
1541
1548
|
}),
|
|
1542
|
-
fileTs: tsResolver.
|
|
1549
|
+
fileTs: tsResolver.file({
|
|
1550
|
+
...operationFileEntry(node, node.operationId),
|
|
1543
1551
|
root,
|
|
1544
1552
|
output: pluginTs.options?.output ?? output,
|
|
1545
1553
|
group: pluginTs.options?.group ?? void 0
|
|
1546
1554
|
})
|
|
1547
1555
|
};
|
|
1548
|
-
const importedTypeNames = [tsResolver.
|
|
1556
|
+
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
1549
1557
|
exclude: [queryKeyTypeName],
|
|
1550
1558
|
order: "body-response-first",
|
|
1551
1559
|
includeParams: false
|
|
@@ -1555,7 +1563,7 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1555
1563
|
baseName: meta.file.baseName,
|
|
1556
1564
|
path: meta.file.path,
|
|
1557
1565
|
meta: meta.file.meta,
|
|
1558
|
-
banner: resolver.
|
|
1566
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1559
1567
|
output,
|
|
1560
1568
|
config,
|
|
1561
1569
|
file: {
|
|
@@ -1563,7 +1571,7 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1563
1571
|
baseName: meta.file.baseName
|
|
1564
1572
|
}
|
|
1565
1573
|
}),
|
|
1566
|
-
footer: resolver.
|
|
1574
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1567
1575
|
output,
|
|
1568
1576
|
config,
|
|
1569
1577
|
file: {
|
|
@@ -1654,69 +1662,67 @@ function capitalize(name) {
|
|
|
1654
1662
|
* file paths for every generated TanStack Query composable (`useFoo`,
|
|
1655
1663
|
* `useFooInfinite`) and its companion helpers.
|
|
1656
1664
|
*
|
|
1657
|
-
* Functions and files use camelCase;
|
|
1665
|
+
* The `default` helpers are supplied by `createResolver`. Functions and files use camelCase;
|
|
1666
|
+
* composables get the `use` prefix. Operation-specific naming is grouped under the `query`,
|
|
1667
|
+
* `infiniteQuery`, and `mutation` namespaces.
|
|
1658
1668
|
*
|
|
1659
1669
|
* @example Resolve composable and helper names
|
|
1660
1670
|
* ```ts
|
|
1661
1671
|
* import { resolverVueQuery } from '@kubb/plugin-vue-query'
|
|
1662
1672
|
*
|
|
1663
|
-
* resolverVueQuery.
|
|
1664
|
-
* resolverVueQuery.
|
|
1665
|
-
* resolverVueQuery.
|
|
1673
|
+
* resolverVueQuery.query.name(operationNode) // 'useGetPetById'
|
|
1674
|
+
* resolverVueQuery.query.keyName(operationNode) // 'getPetByIdQueryKey'
|
|
1675
|
+
* resolverVueQuery.query.optionsName(operationNode) // 'getPetByIdQueryOptions'
|
|
1666
1676
|
* ```
|
|
1667
1677
|
*/
|
|
1668
|
-
const resolverVueQuery = (0, kubb_kit.
|
|
1669
|
-
name: "default",
|
|
1678
|
+
const resolverVueQuery = (0, kubb_kit.createResolver)({
|
|
1670
1679
|
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));
|
|
1680
|
+
query: {
|
|
1681
|
+
name(node) {
|
|
1682
|
+
return `use${capitalize(this.name(node.operationId))}`;
|
|
1683
|
+
},
|
|
1684
|
+
keyName(node) {
|
|
1685
|
+
return `${this.name(node.operationId)}QueryKey`;
|
|
1686
|
+
},
|
|
1687
|
+
keyTypeName(node) {
|
|
1688
|
+
return `${capitalize(this.name(node.operationId))}QueryKey`;
|
|
1689
|
+
},
|
|
1690
|
+
optionsName(node) {
|
|
1691
|
+
return `${this.name(node.operationId)}QueryOptions`;
|
|
1692
|
+
},
|
|
1693
|
+
clientName(node) {
|
|
1694
|
+
return this.name(node.operationId);
|
|
1695
|
+
}
|
|
1712
1696
|
},
|
|
1713
|
-
|
|
1714
|
-
|
|
1697
|
+
infiniteQuery: {
|
|
1698
|
+
name(node) {
|
|
1699
|
+
return `use${capitalize(this.name(node.operationId))}Infinite`;
|
|
1700
|
+
},
|
|
1701
|
+
keyName(node) {
|
|
1702
|
+
return `${this.name(node.operationId)}InfiniteQueryKey`;
|
|
1703
|
+
},
|
|
1704
|
+
keyTypeName(node) {
|
|
1705
|
+
return `${capitalize(this.name(node.operationId))}InfiniteQueryKey`;
|
|
1706
|
+
},
|
|
1707
|
+
optionsName(node) {
|
|
1708
|
+
return `${this.name(node.operationId)}InfiniteQueryOptions`;
|
|
1709
|
+
},
|
|
1710
|
+
clientName(node) {
|
|
1711
|
+
return `${this.name(node.operationId)}Infinite`;
|
|
1712
|
+
}
|
|
1715
1713
|
},
|
|
1716
|
-
|
|
1717
|
-
|
|
1714
|
+
mutation: {
|
|
1715
|
+
name(node) {
|
|
1716
|
+
return `use${capitalize(this.name(node.operationId))}`;
|
|
1717
|
+
},
|
|
1718
|
+
keyName(node) {
|
|
1719
|
+
return `${this.name(node.operationId)}MutationKey`;
|
|
1720
|
+
},
|
|
1721
|
+
typeName(node) {
|
|
1722
|
+
return capitalize(this.name(node.operationId));
|
|
1723
|
+
}
|
|
1718
1724
|
}
|
|
1719
|
-
})
|
|
1725
|
+
});
|
|
1720
1726
|
//#endregion
|
|
1721
1727
|
//#region src/plugin.ts
|
|
1722
1728
|
/**
|
|
@@ -1757,17 +1763,14 @@ const pluginVueQuery = (0, kubb_kit.definePlugin)((options) => {
|
|
|
1757
1763
|
queryGenerator,
|
|
1758
1764
|
infiniteQueryGenerator,
|
|
1759
1765
|
mutationGenerator
|
|
1760
|
-
]
|
|
1766
|
+
];
|
|
1761
1767
|
const groupConfig = createGroupConfig(group);
|
|
1762
1768
|
return {
|
|
1763
1769
|
name: pluginVueQueryName,
|
|
1764
1770
|
options,
|
|
1765
1771
|
dependencies: [_kubb_plugin_ts.pluginTsName],
|
|
1766
1772
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
1767
|
-
const resolver = userResolver ?
|
|
1768
|
-
...resolverVueQuery,
|
|
1769
|
-
...userResolver
|
|
1770
|
-
} : resolverVueQuery;
|
|
1773
|
+
const resolver = userResolver ? kubb_kit.Resolver.merge(resolverVueQuery, userResolver) : resolverVueQuery;
|
|
1771
1774
|
const resolvedClient = resolveClient({
|
|
1772
1775
|
client,
|
|
1773
1776
|
pluginNames: (ctx.config.plugins ?? []).map((p) => p.name).filter((name) => Boolean(name))
|