@kubb/plugin-react-query 5.0.0-beta.85 → 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 +244 -240
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +170 -117
- package/dist/index.js +244 -240
- package/dist/index.js.map +1 -1
- package/package.json +4 -4
package/dist/index.cjs
CHANGED
|
@@ -24,9 +24,9 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
|
|
|
24
24
|
enumerable: true
|
|
25
25
|
}) : target, mod));
|
|
26
26
|
//#endregion
|
|
27
|
+
let kubb_kit = require("kubb/kit");
|
|
27
28
|
let node_path = require("node:path");
|
|
28
29
|
node_path = __toESM(node_path, 1);
|
|
29
|
-
let kubb_kit = require("kubb/kit");
|
|
30
30
|
let _kubb_plugin_ts = require("@kubb/plugin-ts");
|
|
31
31
|
let kubb_jsx = require("kubb/jsx");
|
|
32
32
|
let kubb_jsx_jsx_runtime = require("kubb/jsx/jsx-runtime");
|
|
@@ -59,31 +59,6 @@ function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
|
59
59
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
60
60
|
}
|
|
61
61
|
//#endregion
|
|
62
|
-
//#region ../../internals/utils/src/fs.ts
|
|
63
|
-
/**
|
|
64
|
-
* Builds a nested file path from a dotted name. Splits on dots that precede a letter
|
|
65
|
-
* (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
|
|
66
|
-
* every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
|
|
67
|
-
*
|
|
68
|
-
* Empty segments are dropped before joining. They arise when the name starts with a dot
|
|
69
|
-
* followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
|
|
70
|
-
* an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
|
|
71
|
-
* absolute path, letting generated files escape the configured output directory.
|
|
72
|
-
*
|
|
73
|
-
* @example Nested path from a dotted name
|
|
74
|
-
* `toFilePath('pet.petId') // 'pet/petId'`
|
|
75
|
-
*
|
|
76
|
-
* @example PascalCase the final segment
|
|
77
|
-
* `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
|
|
78
|
-
*
|
|
79
|
-
* @example Suffix applied to the final segment only
|
|
80
|
-
* `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
|
|
81
|
-
*/
|
|
82
|
-
function toFilePath(name, caseLast = camelCase) {
|
|
83
|
-
const parts = name.split(/\.(?=[a-zA-Z])/);
|
|
84
|
-
return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : camelCase(part)).filter(Boolean).join("/");
|
|
85
|
-
}
|
|
86
|
-
//#endregion
|
|
87
62
|
//#region ../../internals/utils/src/reserved.ts
|
|
88
63
|
/**
|
|
89
64
|
* JavaScript and Java reserved words.
|
|
@@ -187,6 +162,23 @@ function isValidVarName(name) {
|
|
|
187
162
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
188
163
|
}
|
|
189
164
|
//#endregion
|
|
165
|
+
//#region ../../internals/utils/src/strings.ts
|
|
166
|
+
/**
|
|
167
|
+
* Renders a dotted path or string array as an optional-chaining accessor expression rooted at
|
|
168
|
+
* `accessor`. Returns `null` for an empty path.
|
|
169
|
+
*
|
|
170
|
+
* @example
|
|
171
|
+
* ```ts
|
|
172
|
+
* getNestedAccessor('pagination.next.id', 'lastPage')
|
|
173
|
+
* // "lastPage?.['pagination']?.['next']?.['id']"
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
function getNestedAccessor(param, accessor) {
|
|
177
|
+
const parts = Array.isArray(param) ? param : param.split(".");
|
|
178
|
+
if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
|
|
179
|
+
return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
|
|
180
|
+
}
|
|
181
|
+
//#endregion
|
|
190
182
|
//#region ../../internals/utils/src/url.ts
|
|
191
183
|
function transformParam(raw, casing) {
|
|
192
184
|
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
@@ -339,13 +331,13 @@ function dedupeByCasedName(params) {
|
|
|
339
331
|
//#region ../../internals/shared/src/operation.ts
|
|
340
332
|
/**
|
|
341
333
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
342
|
-
* `resolver.
|
|
334
|
+
* `resolver.file`: a file named `name`, tagged by the operation's first
|
|
343
335
|
* tag (or `'default'`), at the operation's path. Centralizes the entry object
|
|
344
336
|
* that was repeated at dozens of call sites across the client and query plugins.
|
|
345
337
|
*
|
|
346
338
|
* @example
|
|
347
339
|
* ```ts
|
|
348
|
-
* resolver.
|
|
340
|
+
* resolver.file(operationFileEntry(node, node.operationId), { root, output, group })
|
|
349
341
|
* ```
|
|
350
342
|
*/
|
|
351
343
|
function operationFileEntry(node, name, extname = ".ts") {
|
|
@@ -483,13 +475,13 @@ function getPrimarySuccessResponse(node) {
|
|
|
483
475
|
return getOperationSuccessResponses(node)[0] ?? null;
|
|
484
476
|
}
|
|
485
477
|
function resolveErrorNames(node, resolver) {
|
|
486
|
-
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.
|
|
478
|
+
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
|
|
487
479
|
}
|
|
488
480
|
function resolveSuccessNames(node, resolver) {
|
|
489
|
-
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.
|
|
481
|
+
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
|
|
490
482
|
}
|
|
491
483
|
function resolveStatusCodeNames(node, resolver) {
|
|
492
|
-
return node.responses.map((response) => resolver.
|
|
484
|
+
return node.responses.map((response) => resolver.response.status(node, response.statusCode));
|
|
493
485
|
}
|
|
494
486
|
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
495
487
|
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
@@ -506,11 +498,11 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
|
506
498
|
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
507
499
|
const exclude = new Set(options.exclude ?? []);
|
|
508
500
|
const paramNames = options.includeParams === false ? [] : [
|
|
509
|
-
...path.map((param) => resolver.
|
|
510
|
-
...query.map((param) => resolver.
|
|
511
|
-
...header.map((param) => resolver.
|
|
501
|
+
...path.map((param) => resolver.param.path(node, param)),
|
|
502
|
+
...query.map((param) => resolver.param.query(node, param)),
|
|
503
|
+
...header.map((param) => resolver.param.headers(node, param))
|
|
512
504
|
];
|
|
513
|
-
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.
|
|
505
|
+
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)];
|
|
514
506
|
const result = (options.order === "body-response-first" ? [
|
|
515
507
|
...bodyAndResponseNames,
|
|
516
508
|
...paramNames,
|
|
@@ -634,15 +626,15 @@ function resolveClientOperation(options) {
|
|
|
634
626
|
const { clientPlugin, driver, node, root, output } = options;
|
|
635
627
|
if (!clientPlugin) return null;
|
|
636
628
|
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
637
|
-
if (!resolver) return null;
|
|
638
629
|
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
639
|
-
const file = resolver.
|
|
630
|
+
const file = resolver.file({
|
|
631
|
+
...operationFileEntry(node, node.operationId),
|
|
640
632
|
root,
|
|
641
633
|
output: plugin?.options?.output ?? output,
|
|
642
634
|
group: plugin?.options?.group ?? void 0
|
|
643
635
|
});
|
|
644
636
|
return {
|
|
645
|
-
name: resolver.
|
|
637
|
+
name: resolver.name(node.operationId),
|
|
646
638
|
path: file.path,
|
|
647
639
|
clientPath: node_path.default.resolve(root, ".kubb/client.ts")
|
|
648
640
|
};
|
|
@@ -692,12 +684,12 @@ function maybeValueOrGetter(type) {
|
|
|
692
684
|
/**
|
|
693
685
|
* Builds the grouped `{ path, query, body, headers }` parameter that mirrors the client
|
|
694
686
|
* function signature. Only the groups the operation carries are emitted, typed from the
|
|
695
|
-
* operation's `
|
|
687
|
+
* operation's `Options`. `keys` narrows the emitted groups, used by the query key which
|
|
696
688
|
* never carries `headers`.
|
|
697
689
|
*
|
|
698
|
-
* By default the whole group is typed as the single `
|
|
690
|
+
* By default the whole group is typed as the single `Options` reference. When
|
|
699
691
|
* `memberTypeWrapper` is set, each group is emitted as its own member typed from the matching
|
|
700
|
-
* `
|
|
692
|
+
* `Options['<group>']` slice and wrapped, used by vue-query to apply
|
|
701
693
|
* `MaybeRefOrGetter` per group.
|
|
702
694
|
*/
|
|
703
695
|
function buildGroupedRequestParam(node, options) {
|
|
@@ -712,13 +704,13 @@ function buildGroupedRequestParam(node, options) {
|
|
|
712
704
|
headers: hasRequiredHeader
|
|
713
705
|
};
|
|
714
706
|
const isOptional = names.every((name) => !requiredByGroup[name]);
|
|
715
|
-
const
|
|
707
|
+
const optionsName = resolver.response.options(node);
|
|
716
708
|
const omittedKeys = requestGroupOrder$1.filter((key) => !keys.includes(key));
|
|
717
|
-
const
|
|
709
|
+
const optionsType = omittedKeys.length > 0 ? `Omit<${optionsName}, ${omittedKeys.map((key) => `'${key}'`).join(" | ")}>` : optionsName;
|
|
718
710
|
if (memberTypeWrapper) {
|
|
719
711
|
const members = names.map((name) => ({
|
|
720
712
|
name,
|
|
721
|
-
type: memberTypeWrapper(`${
|
|
713
|
+
type: memberTypeWrapper(`${optionsType}['${name}']`),
|
|
722
714
|
optional: !requiredByGroup[name]
|
|
723
715
|
}));
|
|
724
716
|
return (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
@@ -730,7 +722,7 @@ function buildGroupedRequestParam(node, options) {
|
|
|
730
722
|
}
|
|
731
723
|
return (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
732
724
|
name: (0, _kubb_plugin_ts.createObjectBindingPattern)({ elements: names.map((name) => ({ name })) }),
|
|
733
|
-
type:
|
|
725
|
+
type: optionsType,
|
|
734
726
|
optional: false,
|
|
735
727
|
...isOptional ? { default: "{}" } : {}
|
|
736
728
|
});
|
|
@@ -798,7 +790,7 @@ function resolveOperationOverrides(node, override) {
|
|
|
798
790
|
}
|
|
799
791
|
/**
|
|
800
792
|
* Build QueryKey params as the grouped `{ path, query, body }` object (NO headers, NO config),
|
|
801
|
-
* typed from the operation's `
|
|
793
|
+
* typed from the operation's `Options` minus `url`. The query key transformer reads the
|
|
802
794
|
* grouped `path`/`query`/`body` bindings.
|
|
803
795
|
*/
|
|
804
796
|
function buildQueryKeyParams(node, options) {
|
|
@@ -870,19 +862,18 @@ const customHookOptionsFileGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
870
862
|
const { output, customOptions, query, group } = ctx.options;
|
|
871
863
|
if (!customOptions) return null;
|
|
872
864
|
const { importPath, name } = customOptions;
|
|
873
|
-
const hookOptionsName = resolver.
|
|
874
|
-
const customHookOptionsName = resolver.
|
|
865
|
+
const hookOptionsName = resolver.hook.optionsName();
|
|
866
|
+
const customHookOptionsName = resolver.hook.customOptionsName();
|
|
875
867
|
const reactQueryImportPath = query ? query.importPath : "@tanstack/react-query";
|
|
876
868
|
let hookFilePath;
|
|
877
869
|
const firstNode = nodes[0];
|
|
878
870
|
if (firstNode) {
|
|
879
|
-
const hookName = resolver.
|
|
880
|
-
hookFilePath = resolver.
|
|
871
|
+
const hookName = resolver.query.name(firstNode);
|
|
872
|
+
hookFilePath = resolver.file({
|
|
881
873
|
name: hookName,
|
|
882
874
|
extname: ".ts",
|
|
883
875
|
tag: firstNode.tags[0] ?? "default",
|
|
884
|
-
path: firstNode.path
|
|
885
|
-
}, {
|
|
876
|
+
path: firstNode.path,
|
|
886
877
|
root,
|
|
887
878
|
output,
|
|
888
879
|
group: group ?? void 0
|
|
@@ -989,11 +980,10 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
989
980
|
const { resolver, config, root } = ctx;
|
|
990
981
|
const { output, customOptions, query, mutation, suspense, infinite, group, override, hooks } = ctx.options;
|
|
991
982
|
if (!customOptions || !hooks) return null;
|
|
992
|
-
const name = resolver.
|
|
993
|
-
const resolvedFile = resolver.
|
|
983
|
+
const name = resolver.hook.optionsName();
|
|
984
|
+
const resolvedFile = resolver.file({
|
|
994
985
|
name,
|
|
995
|
-
extname: ".ts"
|
|
996
|
-
}, {
|
|
986
|
+
extname: ".ts",
|
|
997
987
|
root,
|
|
998
988
|
output,
|
|
999
989
|
group: group ?? void 0
|
|
@@ -1018,9 +1008,10 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1018
1008
|
const isSuspenseOp = !!suspense;
|
|
1019
1009
|
const isInfiniteOp = !!nodeInfiniteOptions;
|
|
1020
1010
|
if (isQueryOp) {
|
|
1021
|
-
const queryOptionsName = resolver.
|
|
1022
|
-
const queryHookName = resolver.
|
|
1023
|
-
const queryHookFile = resolver.
|
|
1011
|
+
const queryOptionsName = resolver.query.optionsName(node);
|
|
1012
|
+
const queryHookName = resolver.query.name(node);
|
|
1013
|
+
const queryHookFile = resolver.file({
|
|
1014
|
+
...operationFileEntry(node, queryHookName),
|
|
1024
1015
|
root,
|
|
1025
1016
|
output,
|
|
1026
1017
|
group: group ?? void 0
|
|
@@ -1032,9 +1023,10 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1032
1023
|
}));
|
|
1033
1024
|
hookOptions[queryHookName] = `Partial<ReturnType<typeof ${queryOptionsName}>>`;
|
|
1034
1025
|
if (isSuspenseOp) {
|
|
1035
|
-
const suspenseOptionsName = resolver.
|
|
1036
|
-
const suspenseHookName = resolver.
|
|
1037
|
-
const suspenseHookFile = resolver.
|
|
1026
|
+
const suspenseOptionsName = resolver.suspenseQuery.optionsName(node);
|
|
1027
|
+
const suspenseHookName = resolver.suspenseQuery.name(node);
|
|
1028
|
+
const suspenseHookFile = resolver.file({
|
|
1029
|
+
...operationFileEntry(node, suspenseHookName),
|
|
1038
1030
|
root,
|
|
1039
1031
|
output,
|
|
1040
1032
|
group: group ?? void 0
|
|
@@ -1050,9 +1042,10 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1050
1042
|
const normalizeKey = (key) => key.replace(/\?$/, "");
|
|
1051
1043
|
const queryParamKeys = getOperationParameters(node, { paramsCasing: "original" }).query.map((p) => p.name);
|
|
1052
1044
|
if (nodeInfiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === nodeInfiniteOptions.queryParam) : false) {
|
|
1053
|
-
const infiniteOptionsName = resolver.
|
|
1054
|
-
const infiniteHookName = resolver.
|
|
1055
|
-
const infiniteHookFile = resolver.
|
|
1045
|
+
const infiniteOptionsName = resolver.infiniteQuery.optionsName(node);
|
|
1046
|
+
const infiniteHookName = resolver.infiniteQuery.name(node);
|
|
1047
|
+
const infiniteHookFile = resolver.file({
|
|
1048
|
+
...operationFileEntry(node, infiniteHookName),
|
|
1056
1049
|
root,
|
|
1057
1050
|
output,
|
|
1058
1051
|
group: group ?? void 0
|
|
@@ -1064,9 +1057,10 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1064
1057
|
}));
|
|
1065
1058
|
hookOptions[infiniteHookName] = `Partial<ReturnType<typeof ${infiniteOptionsName}>>`;
|
|
1066
1059
|
if (isSuspenseOp) {
|
|
1067
|
-
const suspenseInfiniteOptionsName = resolver.
|
|
1068
|
-
const suspenseInfiniteHookName = resolver.
|
|
1069
|
-
const suspenseInfiniteHookFile = resolver.
|
|
1060
|
+
const suspenseInfiniteOptionsName = resolver.suspenseInfiniteQuery.optionsName(node);
|
|
1061
|
+
const suspenseInfiniteHookName = resolver.suspenseInfiniteQuery.name(node);
|
|
1062
|
+
const suspenseInfiniteHookFile = resolver.file({
|
|
1063
|
+
...operationFileEntry(node, suspenseInfiniteHookName),
|
|
1070
1064
|
root,
|
|
1071
1065
|
output,
|
|
1072
1066
|
group: group ?? void 0
|
|
@@ -1082,9 +1076,10 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1082
1076
|
}
|
|
1083
1077
|
}
|
|
1084
1078
|
if (isMutationOp) {
|
|
1085
|
-
const mutationOptionsName = resolver.
|
|
1086
|
-
const mutationHookName = resolver.
|
|
1087
|
-
const mutationHookFile = resolver.
|
|
1079
|
+
const mutationOptionsName = resolver.mutation.optionsName(node);
|
|
1080
|
+
const mutationHookName = resolver.mutation.name(node);
|
|
1081
|
+
const mutationHookFile = resolver.file({
|
|
1082
|
+
...operationFileEntry(node, mutationHookName),
|
|
1088
1083
|
root,
|
|
1089
1084
|
output,
|
|
1090
1085
|
group: group ?? void 0
|
|
@@ -1101,7 +1096,7 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1101
1096
|
baseName: hookOptionsFile.baseName,
|
|
1102
1097
|
path: hookOptionsFile.path,
|
|
1103
1098
|
meta: hookOptionsFile.meta,
|
|
1104
|
-
banner: resolver.
|
|
1099
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1105
1100
|
output,
|
|
1106
1101
|
config,
|
|
1107
1102
|
file: {
|
|
@@ -1109,7 +1104,7 @@ const hookOptionsGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1109
1104
|
baseName: hookOptionsFile.baseName
|
|
1110
1105
|
}
|
|
1111
1106
|
}),
|
|
1112
|
-
footer: resolver.
|
|
1107
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1113
1108
|
output,
|
|
1114
1109
|
config,
|
|
1115
1110
|
file: {
|
|
@@ -1151,7 +1146,7 @@ function buildInfiniteQueryParamsNode(node, options) {
|
|
|
1151
1146
|
}
|
|
1152
1147
|
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, initialPageParam, queryParam, customOptions }) {
|
|
1153
1148
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1154
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1149
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1155
1150
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1156
1151
|
const responseType = responseName;
|
|
1157
1152
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1162,8 +1157,8 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1162
1157
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1163
1158
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1164
1159
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1165
|
-
const groupName = tsResolver.
|
|
1166
|
-
return groupName !== tsResolver.
|
|
1160
|
+
const groupName = tsResolver.param.query(node, rawQueryParams[0]);
|
|
1161
|
+
return groupName !== tsResolver.param.name(node, rawQueryParams[0]) ? groupName : null;
|
|
1167
1162
|
})() : null;
|
|
1168
1163
|
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1169
1164
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
@@ -1221,7 +1216,7 @@ function getQueryOptionsParams(node, options) {
|
|
|
1221
1216
|
}
|
|
1222
1217
|
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
|
|
1223
1218
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1224
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1219
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1225
1220
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1226
1221
|
const TData = responseName;
|
|
1227
1222
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1260,7 +1255,7 @@ const declarationPrinter$6 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "decla
|
|
|
1260
1255
|
const callPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1261
1256
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName }) {
|
|
1262
1257
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1263
|
-
const queryFnDataType = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1258
|
+
const queryFnDataType = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1264
1259
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1265
1260
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1266
1261
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -1270,8 +1265,8 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
1270
1265
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1271
1266
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1272
1267
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1273
|
-
const groupName = tsResolver.
|
|
1274
|
-
return groupName !== tsResolver.
|
|
1268
|
+
const groupName = tsResolver.param.query(node, rawQueryParams[0]);
|
|
1269
|
+
return groupName !== tsResolver.param.name(node, rawQueryParams[0]) ? groupName : null;
|
|
1275
1270
|
})() : null;
|
|
1276
1271
|
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1277
1272
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
@@ -1287,8 +1282,8 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
1287
1282
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
1288
1283
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
1289
1284
|
if (hasNewParams) {
|
|
1290
|
-
const nextAccessor = nextParam ?
|
|
1291
|
-
const prevAccessor = previousParam ?
|
|
1285
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
1286
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
1292
1287
|
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1293
1288
|
}
|
|
1294
1289
|
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
@@ -1358,7 +1353,7 @@ function buildMutationConfigParamsNode(node) {
|
|
|
1358
1353
|
}
|
|
1359
1354
|
function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }) {
|
|
1360
1355
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1361
|
-
const TData = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1356
|
+
const TData = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1362
1357
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1363
1358
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1364
1359
|
const configParamsNode = buildMutationConfigParamsNode(node);
|
|
@@ -1366,7 +1361,7 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }
|
|
|
1366
1361
|
const groupedParam = buildGroupedRequestParam(node, { resolver: tsResolver });
|
|
1367
1362
|
const hasMutationParams = groupedParam !== null;
|
|
1368
1363
|
const groupedParamsNode = (0, _kubb_plugin_ts.createFunctionParameters)({ params: groupedParam ? [groupedParam] : [] });
|
|
1369
|
-
const TRequest = hasMutationParams ? tsResolver.
|
|
1364
|
+
const TRequest = hasMutationParams ? tsResolver.response.options(node) : "undefined";
|
|
1370
1365
|
const argBindingStr = hasMutationParams ? callPrinter$2.print(groupedParamsNode) ?? "" : "_";
|
|
1371
1366
|
const mutationFnBody = `const { data } = await ${buildClientCall(node, {
|
|
1372
1367
|
clientName,
|
|
@@ -1399,12 +1394,12 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }
|
|
|
1399
1394
|
const declarationPrinter$4 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declaration" });
|
|
1400
1395
|
const callPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1401
1396
|
function resolveMutationRequestType(node, resolver) {
|
|
1402
|
-
return buildGroupedRequestParam(node, { resolver }) ? resolver.
|
|
1397
|
+
return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
|
|
1403
1398
|
}
|
|
1404
1399
|
function buildMutationParamsNode(node, options) {
|
|
1405
1400
|
const { resolver } = options;
|
|
1406
1401
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1407
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.
|
|
1402
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
1408
1403
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1409
1404
|
return (0, _kubb_plugin_ts.createFunctionParameters)({ params: [(0, _kubb_plugin_ts.createFunctionParameter)({
|
|
1410
1405
|
name: "options",
|
|
@@ -1422,7 +1417,7 @@ function buildMutationParamsNode(node, options) {
|
|
|
1422
1417
|
}
|
|
1423
1418
|
function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName, customOptions }) {
|
|
1424
1419
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1425
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1420
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1426
1421
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1427
1422
|
const generics = [
|
|
1428
1423
|
responseName,
|
|
@@ -1467,7 +1462,7 @@ const declarationPrinter$3 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "decla
|
|
|
1467
1462
|
function buildQueryParamsNode(node, options) {
|
|
1468
1463
|
const { resolver } = options;
|
|
1469
1464
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1470
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.
|
|
1465
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
1471
1466
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1472
1467
|
const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
1473
1468
|
name: "options",
|
|
@@ -1490,7 +1485,7 @@ function buildQueryParamsNode(node, options) {
|
|
|
1490
1485
|
}
|
|
1491
1486
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions }) {
|
|
1492
1487
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1493
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1488
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1494
1489
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1495
1490
|
const TData = responseName;
|
|
1496
1491
|
const returnType = `UseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
@@ -1553,7 +1548,7 @@ function buildSuspenseInfiniteQueryParamsNode(node, options) {
|
|
|
1553
1548
|
}
|
|
1554
1549
|
function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions, initialPageParam, queryParam }) {
|
|
1555
1550
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1556
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1551
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1557
1552
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1558
1553
|
const responseType = responseName;
|
|
1559
1554
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1564,8 +1559,8 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1564
1559
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1565
1560
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1566
1561
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1567
|
-
const groupName = tsResolver.
|
|
1568
|
-
return groupName !== tsResolver.
|
|
1562
|
+
const groupName = tsResolver.param.query(node, rawQueryParams[0]);
|
|
1563
|
+
return groupName !== tsResolver.param.name(node, rawQueryParams[0]) ? groupName : null;
|
|
1569
1564
|
})() : null;
|
|
1570
1565
|
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1571
1566
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
@@ -1620,7 +1615,7 @@ const declarationPrinter$1 = (0, _kubb_plugin_ts.functionPrinter)({ mode: "decla
|
|
|
1620
1615
|
const callPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "call" });
|
|
1621
1616
|
function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName }) {
|
|
1622
1617
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1623
|
-
const queryFnDataType = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1618
|
+
const queryFnDataType = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1624
1619
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1625
1620
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1626
1621
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -1630,8 +1625,8 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1630
1625
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1631
1626
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1632
1627
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1633
|
-
const groupName = tsResolver.
|
|
1634
|
-
return groupName !== tsResolver.
|
|
1628
|
+
const groupName = tsResolver.param.query(node, rawQueryParams[0]);
|
|
1629
|
+
return groupName !== tsResolver.param.name(node, rawQueryParams[0]) ? groupName : null;
|
|
1635
1630
|
})() : null;
|
|
1636
1631
|
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1637
1632
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
@@ -1647,8 +1642,8 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1647
1642
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
1648
1643
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
1649
1644
|
if (hasNewParams) {
|
|
1650
|
-
const nextAccessor = nextParam ?
|
|
1651
|
-
const prevAccessor = previousParam ?
|
|
1645
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
1646
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
1652
1647
|
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1653
1648
|
}
|
|
1654
1649
|
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
@@ -1711,7 +1706,7 @@ const declarationPrinter = (0, _kubb_plugin_ts.functionPrinter)({ mode: "declara
|
|
|
1711
1706
|
function buildSuspenseQueryParamsNode(node, options) {
|
|
1712
1707
|
const { resolver } = options;
|
|
1713
1708
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1714
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.
|
|
1709
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
1715
1710
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1716
1711
|
const optionsParam = (0, _kubb_plugin_ts.createFunctionParameter)({
|
|
1717
1712
|
name: "options",
|
|
@@ -1733,7 +1728,7 @@ function buildSuspenseQueryParamsNode(node, options) {
|
|
|
1733
1728
|
}
|
|
1734
1729
|
function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions }) {
|
|
1735
1730
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1736
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1731
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1737
1732
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1738
1733
|
const TData = responseName;
|
|
1739
1734
|
const returnType = `UseSuspenseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
@@ -1809,26 +1804,28 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1809
1804
|
output
|
|
1810
1805
|
});
|
|
1811
1806
|
if (!contractOp) return null;
|
|
1812
|
-
const queryName = resolver.
|
|
1813
|
-
const queryOptionsName = resolver.
|
|
1814
|
-
const queryKeyName = resolver.
|
|
1815
|
-
const queryKeyTypeName = resolver.
|
|
1807
|
+
const queryName = resolver.infiniteQuery.name(node);
|
|
1808
|
+
const queryOptionsName = resolver.infiniteQuery.optionsName(node);
|
|
1809
|
+
const queryKeyName = resolver.infiniteQuery.keyName(node);
|
|
1810
|
+
const queryKeyTypeName = resolver.infiniteQuery.keyTypeName(node);
|
|
1816
1811
|
const meta = {
|
|
1817
|
-
file: resolver.
|
|
1812
|
+
file: resolver.file({
|
|
1813
|
+
...operationFileEntry(node, queryName),
|
|
1818
1814
|
root,
|
|
1819
1815
|
output,
|
|
1820
1816
|
group: group ?? void 0
|
|
1821
1817
|
}),
|
|
1822
|
-
fileTs: tsResolver.
|
|
1818
|
+
fileTs: tsResolver.file({
|
|
1819
|
+
...operationFileEntry(node, node.operationId),
|
|
1823
1820
|
root,
|
|
1824
1821
|
output: pluginTs.options?.output ?? output,
|
|
1825
1822
|
group: pluginTs.options?.group ?? void 0
|
|
1826
1823
|
})
|
|
1827
1824
|
};
|
|
1828
1825
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1829
|
-
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.
|
|
1826
|
+
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.param.query(node, rawQueryParams[0]) !== tsResolver.param.name(node, rawQueryParams[0]) ? tsResolver.param.query(node, rawQueryParams[0]) : null;
|
|
1830
1827
|
const importedTypeNames = [
|
|
1831
|
-
tsResolver.
|
|
1828
|
+
tsResolver.response.options(node),
|
|
1832
1829
|
queryParamsTypeName,
|
|
1833
1830
|
...resolveOperationTypeNames(node, tsResolver, {
|
|
1834
1831
|
exclude: [queryKeyTypeName],
|
|
@@ -1841,7 +1838,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1841
1838
|
baseName: meta.file.baseName,
|
|
1842
1839
|
path: meta.file.path,
|
|
1843
1840
|
meta: meta.file.meta,
|
|
1844
|
-
banner: resolver.
|
|
1841
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1845
1842
|
output,
|
|
1846
1843
|
config,
|
|
1847
1844
|
file: {
|
|
@@ -1849,7 +1846,7 @@ const infiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1849
1846
|
baseName: meta.file.baseName
|
|
1850
1847
|
}
|
|
1851
1848
|
}),
|
|
1852
|
-
footer: resolver.
|
|
1849
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1853
1850
|
output,
|
|
1854
1851
|
config,
|
|
1855
1852
|
file: {
|
|
@@ -1967,23 +1964,25 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1967
1964
|
output
|
|
1968
1965
|
});
|
|
1969
1966
|
if (!contractOp) return null;
|
|
1970
|
-
const mutationHookName = resolver.
|
|
1971
|
-
const mutationTypeName = resolver.
|
|
1972
|
-
const mutationOptionsName = resolver.
|
|
1973
|
-
const mutationKeyName = resolver.
|
|
1967
|
+
const mutationHookName = resolver.mutation.name(node);
|
|
1968
|
+
const mutationTypeName = resolver.mutation.typeName(node);
|
|
1969
|
+
const mutationOptionsName = resolver.mutation.optionsName(node);
|
|
1970
|
+
const mutationKeyName = resolver.mutation.keyName(node);
|
|
1974
1971
|
const meta = {
|
|
1975
|
-
file: resolver.
|
|
1972
|
+
file: resolver.file({
|
|
1973
|
+
...operationFileEntry(node, mutationHookName),
|
|
1976
1974
|
root,
|
|
1977
1975
|
output,
|
|
1978
1976
|
group: group ?? void 0
|
|
1979
1977
|
}),
|
|
1980
|
-
fileTs: tsResolver.
|
|
1978
|
+
fileTs: tsResolver.file({
|
|
1979
|
+
...operationFileEntry(node, node.operationId),
|
|
1981
1980
|
root,
|
|
1982
1981
|
output: pluginTs.options?.output ?? output,
|
|
1983
1982
|
group: pluginTs.options?.group ?? void 0
|
|
1984
1983
|
})
|
|
1985
1984
|
};
|
|
1986
|
-
const importedTypeNames = [tsResolver.
|
|
1985
|
+
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
1987
1986
|
order: "body-response-first",
|
|
1988
1987
|
includeParams: false
|
|
1989
1988
|
})].filter((name) => Boolean(name));
|
|
@@ -1992,7 +1991,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
1992
1991
|
baseName: meta.file.baseName,
|
|
1993
1992
|
path: meta.file.path,
|
|
1994
1993
|
meta: meta.file.meta,
|
|
1995
|
-
banner: resolver.
|
|
1994
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1996
1995
|
output,
|
|
1997
1996
|
config,
|
|
1998
1997
|
file: {
|
|
@@ -2000,7 +1999,7 @@ const mutationGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2000
1999
|
baseName: meta.file.baseName
|
|
2001
2000
|
}
|
|
2002
2001
|
}),
|
|
2003
|
-
footer: resolver.
|
|
2002
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
2004
2003
|
output,
|
|
2005
2004
|
config,
|
|
2006
2005
|
file: {
|
|
@@ -2104,23 +2103,25 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2104
2103
|
output
|
|
2105
2104
|
});
|
|
2106
2105
|
if (!contractOp) return null;
|
|
2107
|
-
const queryName = resolver.
|
|
2108
|
-
const queryOptionsName = resolver.
|
|
2109
|
-
const queryKeyName = resolver.
|
|
2110
|
-
const queryKeyTypeName = resolver.
|
|
2106
|
+
const queryName = resolver.query.name(node);
|
|
2107
|
+
const queryOptionsName = resolver.query.optionsName(node);
|
|
2108
|
+
const queryKeyName = resolver.query.keyName(node);
|
|
2109
|
+
const queryKeyTypeName = resolver.query.keyTypeName(node);
|
|
2111
2110
|
const meta = {
|
|
2112
|
-
file: resolver.
|
|
2111
|
+
file: resolver.file({
|
|
2112
|
+
...operationFileEntry(node, queryName),
|
|
2113
2113
|
root,
|
|
2114
2114
|
output,
|
|
2115
2115
|
group: group ?? void 0
|
|
2116
2116
|
}),
|
|
2117
|
-
fileTs: tsResolver.
|
|
2117
|
+
fileTs: tsResolver.file({
|
|
2118
|
+
...operationFileEntry(node, node.operationId),
|
|
2118
2119
|
root,
|
|
2119
2120
|
output: pluginTs.options?.output ?? output,
|
|
2120
2121
|
group: pluginTs.options?.group ?? void 0
|
|
2121
2122
|
})
|
|
2122
2123
|
};
|
|
2123
|
-
const importedTypeNames = [tsResolver.
|
|
2124
|
+
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
2124
2125
|
exclude: [queryKeyTypeName],
|
|
2125
2126
|
order: "body-response-first",
|
|
2126
2127
|
includeParams: false
|
|
@@ -2130,7 +2131,7 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2130
2131
|
baseName: meta.file.baseName,
|
|
2131
2132
|
path: meta.file.path,
|
|
2132
2133
|
meta: meta.file.meta,
|
|
2133
|
-
banner: resolver.
|
|
2134
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
2134
2135
|
output,
|
|
2135
2136
|
config,
|
|
2136
2137
|
file: {
|
|
@@ -2138,7 +2139,7 @@ const queryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2138
2139
|
baseName: meta.file.baseName
|
|
2139
2140
|
}
|
|
2140
2141
|
}),
|
|
2141
|
-
footer: resolver.
|
|
2142
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
2142
2143
|
output,
|
|
2143
2144
|
config,
|
|
2144
2145
|
file: {
|
|
@@ -2253,26 +2254,28 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2253
2254
|
output
|
|
2254
2255
|
});
|
|
2255
2256
|
if (!contractOp) return null;
|
|
2256
|
-
const queryName = resolver.
|
|
2257
|
-
const queryOptionsName = resolver.
|
|
2258
|
-
const queryKeyName = resolver.
|
|
2259
|
-
const queryKeyTypeName = resolver.
|
|
2257
|
+
const queryName = resolver.suspenseInfiniteQuery.name(node);
|
|
2258
|
+
const queryOptionsName = resolver.suspenseInfiniteQuery.optionsName(node);
|
|
2259
|
+
const queryKeyName = resolver.suspenseInfiniteQuery.keyName(node);
|
|
2260
|
+
const queryKeyTypeName = resolver.suspenseInfiniteQuery.keyTypeName(node);
|
|
2260
2261
|
const meta = {
|
|
2261
|
-
file: resolver.
|
|
2262
|
+
file: resolver.file({
|
|
2263
|
+
...operationFileEntry(node, queryName),
|
|
2262
2264
|
root,
|
|
2263
2265
|
output,
|
|
2264
2266
|
group: group ?? void 0
|
|
2265
2267
|
}),
|
|
2266
|
-
fileTs: tsResolver.
|
|
2268
|
+
fileTs: tsResolver.file({
|
|
2269
|
+
...operationFileEntry(node, node.operationId),
|
|
2267
2270
|
root,
|
|
2268
2271
|
output: pluginTs.options?.output ?? output,
|
|
2269
2272
|
group: pluginTs.options?.group ?? void 0
|
|
2270
2273
|
})
|
|
2271
2274
|
};
|
|
2272
2275
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
2273
|
-
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.
|
|
2276
|
+
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.param.query(node, rawQueryParams[0]) !== tsResolver.param.name(node, rawQueryParams[0]) ? tsResolver.param.query(node, rawQueryParams[0]) : null;
|
|
2274
2277
|
const importedTypeNames = [
|
|
2275
|
-
tsResolver.
|
|
2278
|
+
tsResolver.response.options(node),
|
|
2276
2279
|
queryParamsTypeName,
|
|
2277
2280
|
...resolveOperationTypeNames(node, tsResolver, {
|
|
2278
2281
|
order: "body-response-first",
|
|
@@ -2284,7 +2287,7 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2284
2287
|
baseName: meta.file.baseName,
|
|
2285
2288
|
path: meta.file.path,
|
|
2286
2289
|
meta: meta.file.meta,
|
|
2287
|
-
banner: resolver.
|
|
2290
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
2288
2291
|
output,
|
|
2289
2292
|
config,
|
|
2290
2293
|
file: {
|
|
@@ -2292,7 +2295,7 @@ const suspenseInfiniteQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2292
2295
|
baseName: meta.file.baseName
|
|
2293
2296
|
}
|
|
2294
2297
|
}),
|
|
2295
|
-
footer: resolver.
|
|
2298
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
2296
2299
|
output,
|
|
2297
2300
|
config,
|
|
2298
2301
|
file: {
|
|
@@ -2412,23 +2415,25 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2412
2415
|
output
|
|
2413
2416
|
});
|
|
2414
2417
|
if (!contractOp) return null;
|
|
2415
|
-
const queryName = resolver.
|
|
2416
|
-
const queryOptionsName = resolver.
|
|
2417
|
-
const queryKeyName = resolver.
|
|
2418
|
-
const queryKeyTypeName = resolver.
|
|
2418
|
+
const queryName = resolver.suspenseQuery.name(node);
|
|
2419
|
+
const queryOptionsName = resolver.suspenseQuery.optionsName(node);
|
|
2420
|
+
const queryKeyName = resolver.suspenseQuery.keyName(node);
|
|
2421
|
+
const queryKeyTypeName = resolver.suspenseQuery.keyTypeName(node);
|
|
2419
2422
|
const meta = {
|
|
2420
|
-
file: resolver.
|
|
2423
|
+
file: resolver.file({
|
|
2424
|
+
...operationFileEntry(node, queryName),
|
|
2421
2425
|
root,
|
|
2422
2426
|
output,
|
|
2423
2427
|
group: group ?? void 0
|
|
2424
2428
|
}),
|
|
2425
|
-
fileTs: tsResolver.
|
|
2429
|
+
fileTs: tsResolver.file({
|
|
2430
|
+
...operationFileEntry(node, node.operationId),
|
|
2426
2431
|
root,
|
|
2427
2432
|
output: pluginTs.options?.output ?? output,
|
|
2428
2433
|
group: pluginTs.options?.group ?? void 0
|
|
2429
2434
|
})
|
|
2430
2435
|
};
|
|
2431
|
-
const importedTypeNames = [tsResolver.
|
|
2436
|
+
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
2432
2437
|
exclude: [queryKeyTypeName],
|
|
2433
2438
|
order: "body-response-first",
|
|
2434
2439
|
includeParams: false
|
|
@@ -2438,7 +2443,7 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2438
2443
|
baseName: meta.file.baseName,
|
|
2439
2444
|
path: meta.file.path,
|
|
2440
2445
|
meta: meta.file.meta,
|
|
2441
|
-
banner: resolver.
|
|
2446
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
2442
2447
|
output,
|
|
2443
2448
|
config,
|
|
2444
2449
|
file: {
|
|
@@ -2446,7 +2451,7 @@ const suspenseQueryGenerator = (0, kubb_kit.defineGenerator)({
|
|
|
2446
2451
|
baseName: meta.file.baseName
|
|
2447
2452
|
}
|
|
2448
2453
|
}),
|
|
2449
|
-
footer: resolver.
|
|
2454
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
2450
2455
|
output,
|
|
2451
2456
|
config,
|
|
2452
2457
|
file: {
|
|
@@ -2534,110 +2539,112 @@ function capitalize(name) {
|
|
|
2534
2539
|
* `useFooSuspense`, `useFooInfinite`, ...) and its companion helpers
|
|
2535
2540
|
* (`fooQueryKey`, `fooQueryOptions`).
|
|
2536
2541
|
*
|
|
2537
|
-
* Functions and files use camelCase; hooks get the `use`
|
|
2538
|
-
* infinite variants are suffixed with `Suspense`/`Infinite`.
|
|
2542
|
+
* Functions and files use the built-in camelCase casing; hooks get the `use`
|
|
2543
|
+
* prefix; suspense and infinite variants are suffixed with `Suspense`/`Infinite`.
|
|
2539
2544
|
*
|
|
2540
2545
|
* @example Resolve hook and helper names
|
|
2541
2546
|
* ```ts
|
|
2542
2547
|
* import { resolverReactQuery } from '@kubb/plugin-react-query'
|
|
2543
2548
|
*
|
|
2544
|
-
* resolverReactQuery.
|
|
2545
|
-
* resolverReactQuery.
|
|
2546
|
-
* resolverReactQuery.
|
|
2547
|
-
* resolverReactQuery.
|
|
2549
|
+
* resolverReactQuery.query.name(operationNode) // 'useGetPetById'
|
|
2550
|
+
* resolverReactQuery.mutation.name(operationNode) // 'useUpdatePet'
|
|
2551
|
+
* resolverReactQuery.query.keyName(operationNode) // 'getPetByIdQueryKey'
|
|
2552
|
+
* resolverReactQuery.query.optionsName(operationNode) // 'getPetByIdQueryOptions'
|
|
2548
2553
|
* ```
|
|
2549
2554
|
*/
|
|
2550
|
-
const resolverReactQuery = (0, kubb_kit.
|
|
2551
|
-
name: "default",
|
|
2555
|
+
const resolverReactQuery = (0, kubb_kit.createResolver)({
|
|
2552
2556
|
pluginName: "plugin-react-query",
|
|
2553
|
-
|
|
2554
|
-
|
|
2555
|
-
|
|
2556
|
-
|
|
2557
|
-
|
|
2558
|
-
|
|
2559
|
-
|
|
2560
|
-
|
|
2561
|
-
|
|
2562
|
-
|
|
2563
|
-
|
|
2564
|
-
|
|
2565
|
-
|
|
2566
|
-
|
|
2567
|
-
|
|
2568
|
-
|
|
2569
|
-
return `use${capitalize(this.resolveName(node.operationId))}Infinite`;
|
|
2570
|
-
},
|
|
2571
|
-
resolveSuspenseInfiniteQueryName(node) {
|
|
2572
|
-
return `use${capitalize(this.resolveName(node.operationId))}SuspenseInfinite`;
|
|
2573
|
-
},
|
|
2574
|
-
resolveMutationName(node) {
|
|
2575
|
-
return `use${capitalize(this.resolveName(node.operationId))}`;
|
|
2576
|
-
},
|
|
2577
|
-
resolveQueryOptionsName(node) {
|
|
2578
|
-
return `${this.resolveName(node.operationId)}QueryOptions`;
|
|
2579
|
-
},
|
|
2580
|
-
resolveSuspenseQueryOptionsName(node) {
|
|
2581
|
-
return `${this.resolveName(node.operationId)}SuspenseQueryOptions`;
|
|
2582
|
-
},
|
|
2583
|
-
resolveInfiniteQueryOptionsName(node) {
|
|
2584
|
-
return `${this.resolveName(node.operationId)}InfiniteQueryOptions`;
|
|
2585
|
-
},
|
|
2586
|
-
resolveSuspenseInfiniteQueryOptionsName(node) {
|
|
2587
|
-
return `${this.resolveName(node.operationId)}SuspenseInfiniteQueryOptions`;
|
|
2588
|
-
},
|
|
2589
|
-
resolveMutationOptionsName(node) {
|
|
2590
|
-
return `${this.resolveName(node.operationId)}MutationOptions`;
|
|
2591
|
-
},
|
|
2592
|
-
resolveQueryKeyName(node) {
|
|
2593
|
-
return `${this.resolveName(node.operationId)}QueryKey`;
|
|
2594
|
-
},
|
|
2595
|
-
resolveSuspenseQueryKeyName(node) {
|
|
2596
|
-
return `${this.resolveName(node.operationId)}SuspenseQueryKey`;
|
|
2597
|
-
},
|
|
2598
|
-
resolveInfiniteQueryKeyName(node) {
|
|
2599
|
-
return `${this.resolveName(node.operationId)}InfiniteQueryKey`;
|
|
2600
|
-
},
|
|
2601
|
-
resolveSuspenseInfiniteQueryKeyName(node) {
|
|
2602
|
-
return `${this.resolveName(node.operationId)}SuspenseInfiniteQueryKey`;
|
|
2603
|
-
},
|
|
2604
|
-
resolveMutationKeyName(node) {
|
|
2605
|
-
return `${this.resolveName(node.operationId)}MutationKey`;
|
|
2606
|
-
},
|
|
2607
|
-
resolveQueryKeyTypeName(node) {
|
|
2608
|
-
return `${capitalize(this.resolveName(node.operationId))}QueryKey`;
|
|
2609
|
-
},
|
|
2610
|
-
resolveSuspenseQueryKeyTypeName(node) {
|
|
2611
|
-
return `${capitalize(this.resolveName(node.operationId))}SuspenseQueryKey`;
|
|
2612
|
-
},
|
|
2613
|
-
resolveInfiniteQueryKeyTypeName(node) {
|
|
2614
|
-
return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`;
|
|
2615
|
-
},
|
|
2616
|
-
resolveSuspenseInfiniteQueryKeyTypeName(node) {
|
|
2617
|
-
return `${capitalize(this.resolveName(node.operationId))}SuspenseInfiniteQueryKey`;
|
|
2618
|
-
},
|
|
2619
|
-
resolveMutationTypeName(node) {
|
|
2620
|
-
return capitalize(this.resolveName(node.operationId));
|
|
2621
|
-
},
|
|
2622
|
-
resolveClientName(node) {
|
|
2623
|
-
return this.resolveName(node.operationId);
|
|
2557
|
+
query: {
|
|
2558
|
+
name(node) {
|
|
2559
|
+
return `use${capitalize(this.name(node.operationId))}`;
|
|
2560
|
+
},
|
|
2561
|
+
optionsName(node) {
|
|
2562
|
+
return `${this.name(node.operationId)}QueryOptions`;
|
|
2563
|
+
},
|
|
2564
|
+
keyName(node) {
|
|
2565
|
+
return `${this.name(node.operationId)}QueryKey`;
|
|
2566
|
+
},
|
|
2567
|
+
keyTypeName(node) {
|
|
2568
|
+
return `${capitalize(this.name(node.operationId))}QueryKey`;
|
|
2569
|
+
},
|
|
2570
|
+
clientName(node) {
|
|
2571
|
+
return this.name(node.operationId);
|
|
2572
|
+
}
|
|
2624
2573
|
},
|
|
2625
|
-
|
|
2626
|
-
|
|
2574
|
+
suspenseQuery: {
|
|
2575
|
+
name(node) {
|
|
2576
|
+
return `use${capitalize(this.name(node.operationId))}Suspense`;
|
|
2577
|
+
},
|
|
2578
|
+
optionsName(node) {
|
|
2579
|
+
return `${this.name(node.operationId)}SuspenseQueryOptions`;
|
|
2580
|
+
},
|
|
2581
|
+
keyName(node) {
|
|
2582
|
+
return `${this.name(node.operationId)}SuspenseQueryKey`;
|
|
2583
|
+
},
|
|
2584
|
+
keyTypeName(node) {
|
|
2585
|
+
return `${capitalize(this.name(node.operationId))}SuspenseQueryKey`;
|
|
2586
|
+
},
|
|
2587
|
+
clientName(node) {
|
|
2588
|
+
return `${this.name(node.operationId)}Suspense`;
|
|
2589
|
+
}
|
|
2627
2590
|
},
|
|
2628
|
-
|
|
2629
|
-
|
|
2591
|
+
infiniteQuery: {
|
|
2592
|
+
name(node) {
|
|
2593
|
+
return `use${capitalize(this.name(node.operationId))}Infinite`;
|
|
2594
|
+
},
|
|
2595
|
+
optionsName(node) {
|
|
2596
|
+
return `${this.name(node.operationId)}InfiniteQueryOptions`;
|
|
2597
|
+
},
|
|
2598
|
+
keyName(node) {
|
|
2599
|
+
return `${this.name(node.operationId)}InfiniteQueryKey`;
|
|
2600
|
+
},
|
|
2601
|
+
keyTypeName(node) {
|
|
2602
|
+
return `${capitalize(this.name(node.operationId))}InfiniteQueryKey`;
|
|
2603
|
+
},
|
|
2604
|
+
clientName(node) {
|
|
2605
|
+
return `${this.name(node.operationId)}Infinite`;
|
|
2606
|
+
}
|
|
2630
2607
|
},
|
|
2631
|
-
|
|
2632
|
-
|
|
2608
|
+
suspenseInfiniteQuery: {
|
|
2609
|
+
name(node) {
|
|
2610
|
+
return `use${capitalize(this.name(node.operationId))}SuspenseInfinite`;
|
|
2611
|
+
},
|
|
2612
|
+
optionsName(node) {
|
|
2613
|
+
return `${this.name(node.operationId)}SuspenseInfiniteQueryOptions`;
|
|
2614
|
+
},
|
|
2615
|
+
keyName(node) {
|
|
2616
|
+
return `${this.name(node.operationId)}SuspenseInfiniteQueryKey`;
|
|
2617
|
+
},
|
|
2618
|
+
keyTypeName(node) {
|
|
2619
|
+
return `${capitalize(this.name(node.operationId))}SuspenseInfiniteQueryKey`;
|
|
2620
|
+
},
|
|
2621
|
+
clientName(node) {
|
|
2622
|
+
return `${this.name(node.operationId)}SuspenseInfinite`;
|
|
2623
|
+
}
|
|
2633
2624
|
},
|
|
2634
|
-
|
|
2635
|
-
|
|
2625
|
+
mutation: {
|
|
2626
|
+
name(node) {
|
|
2627
|
+
return `use${capitalize(this.name(node.operationId))}`;
|
|
2628
|
+
},
|
|
2629
|
+
optionsName(node) {
|
|
2630
|
+
return `${this.name(node.operationId)}MutationOptions`;
|
|
2631
|
+
},
|
|
2632
|
+
keyName(node) {
|
|
2633
|
+
return `${this.name(node.operationId)}MutationKey`;
|
|
2634
|
+
},
|
|
2635
|
+
typeName(node) {
|
|
2636
|
+
return capitalize(this.name(node.operationId));
|
|
2637
|
+
}
|
|
2636
2638
|
},
|
|
2637
|
-
|
|
2638
|
-
|
|
2639
|
+
hook: {
|
|
2640
|
+
optionsName() {
|
|
2641
|
+
return "HookOptions";
|
|
2642
|
+
},
|
|
2643
|
+
customOptionsName() {
|
|
2644
|
+
return "getCustomHookOptions";
|
|
2645
|
+
}
|
|
2639
2646
|
}
|
|
2640
|
-
})
|
|
2647
|
+
});
|
|
2641
2648
|
//#endregion
|
|
2642
2649
|
//#region src/plugin.ts
|
|
2643
2650
|
/**
|
|
@@ -2690,10 +2697,7 @@ const pluginReactQuery = (0, kubb_kit.definePlugin)((options) => {
|
|
|
2690
2697
|
options,
|
|
2691
2698
|
dependencies: [_kubb_plugin_ts.pluginTsName],
|
|
2692
2699
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
2693
|
-
const resolver = userResolver ?
|
|
2694
|
-
...resolverReactQuery,
|
|
2695
|
-
...userResolver
|
|
2696
|
-
} : resolverReactQuery;
|
|
2700
|
+
const resolver = userResolver ? kubb_kit.Resolver.merge(resolverReactQuery, userResolver) : resolverReactQuery;
|
|
2697
2701
|
const resolvedClient = resolveClient({
|
|
2698
2702
|
client,
|
|
2699
2703
|
pluginNames: (ctx.config.plugins ?? []).map((p) => p.name).filter((name) => Boolean(name))
|