@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.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import "./rolldown-runtime-C0LytTxp.js";
|
|
2
|
+
import { Resolver, ast, createResolver, defineGenerator, definePlugin } from "kubb/kit";
|
|
2
3
|
import path from "node:path";
|
|
3
|
-
import { ast, defineGenerator, definePlugin, defineResolver } from "kubb/kit";
|
|
4
4
|
import { createFunctionParameter, createFunctionParameters, createObjectBindingPattern, createTypeLiteral, functionPrinter, pluginTsName } from "@kubb/plugin-ts";
|
|
5
5
|
import { File, Function, Type, jsxRenderer } from "kubb/jsx";
|
|
6
6
|
import { Fragment, jsx, jsxs } from "kubb/jsx/jsx-runtime";
|
|
@@ -32,31 +32,6 @@ function camelCase(text, { prefix = "", suffix = "" } = {}) {
|
|
|
32
32
|
return toCamelOrPascal(`${prefix} ${text} ${suffix}`, false);
|
|
33
33
|
}
|
|
34
34
|
//#endregion
|
|
35
|
-
//#region ../../internals/utils/src/fs.ts
|
|
36
|
-
/**
|
|
37
|
-
* Builds a nested file path from a dotted name. Splits on dots that precede a letter
|
|
38
|
-
* (so version numbers embedded in operationIds like `v2025.0` stay intact), camelCases
|
|
39
|
-
* every earlier segment, applies `caseLast` to the final segment, and joins with `/`.
|
|
40
|
-
*
|
|
41
|
-
* Empty segments are dropped before joining. They arise when the name starts with a dot
|
|
42
|
-
* followed by a letter (e.g. `..Schema` splits into `['..', 'Schema']` and `'..'` cases to
|
|
43
|
-
* an empty string). Without this a leading `/` would form, which `path.resolve` reads as an
|
|
44
|
-
* absolute path, letting generated files escape the configured output directory.
|
|
45
|
-
*
|
|
46
|
-
* @example Nested path from a dotted name
|
|
47
|
-
* `toFilePath('pet.petId') // 'pet/petId'`
|
|
48
|
-
*
|
|
49
|
-
* @example PascalCase the final segment
|
|
50
|
-
* `toFilePath('pet.Pet', pascalCase) // 'pet/Pet'`
|
|
51
|
-
*
|
|
52
|
-
* @example Suffix applied to the final segment only
|
|
53
|
-
* `toFilePath('tag.tag', (part) => camelCase(part, { suffix: 'schema' })) // 'tag/tagSchema'`
|
|
54
|
-
*/
|
|
55
|
-
function toFilePath(name, caseLast = camelCase) {
|
|
56
|
-
const parts = name.split(/\.(?=[a-zA-Z])/);
|
|
57
|
-
return parts.map((part, i) => i === parts.length - 1 ? caseLast(part) : camelCase(part)).filter(Boolean).join("/");
|
|
58
|
-
}
|
|
59
|
-
//#endregion
|
|
60
35
|
//#region ../../internals/utils/src/reserved.ts
|
|
61
36
|
/**
|
|
62
37
|
* JavaScript and Java reserved words.
|
|
@@ -160,6 +135,23 @@ function isValidVarName(name) {
|
|
|
160
135
|
return /^[a-zA-Z_$][a-zA-Z0-9_$]*$/.test(name);
|
|
161
136
|
}
|
|
162
137
|
//#endregion
|
|
138
|
+
//#region ../../internals/utils/src/strings.ts
|
|
139
|
+
/**
|
|
140
|
+
* Renders a dotted path or string array as an optional-chaining accessor expression rooted at
|
|
141
|
+
* `accessor`. Returns `null` for an empty path.
|
|
142
|
+
*
|
|
143
|
+
* @example
|
|
144
|
+
* ```ts
|
|
145
|
+
* getNestedAccessor('pagination.next.id', 'lastPage')
|
|
146
|
+
* // "lastPage?.['pagination']?.['next']?.['id']"
|
|
147
|
+
* ```
|
|
148
|
+
*/
|
|
149
|
+
function getNestedAccessor(param, accessor) {
|
|
150
|
+
const parts = Array.isArray(param) ? param : param.split(".");
|
|
151
|
+
if (parts.length === 0 || parts.length === 1 && parts[0] === "") return null;
|
|
152
|
+
return `${accessor}?.['${`${parts.join("']?.['")}']`}`;
|
|
153
|
+
}
|
|
154
|
+
//#endregion
|
|
163
155
|
//#region ../../internals/utils/src/url.ts
|
|
164
156
|
function transformParam(raw, casing) {
|
|
165
157
|
const param = isValidVarName(raw) ? raw : camelCase(raw);
|
|
@@ -312,13 +304,13 @@ function dedupeByCasedName(params) {
|
|
|
312
304
|
//#region ../../internals/shared/src/operation.ts
|
|
313
305
|
/**
|
|
314
306
|
* Builds the `ResolverFileParams` every operation generator passes to
|
|
315
|
-
* `resolver.
|
|
307
|
+
* `resolver.file`: a file named `name`, tagged by the operation's first
|
|
316
308
|
* tag (or `'default'`), at the operation's path. Centralizes the entry object
|
|
317
309
|
* that was repeated at dozens of call sites across the client and query plugins.
|
|
318
310
|
*
|
|
319
311
|
* @example
|
|
320
312
|
* ```ts
|
|
321
|
-
* resolver.
|
|
313
|
+
* resolver.file(operationFileEntry(node, node.operationId), { root, output, group })
|
|
322
314
|
* ```
|
|
323
315
|
*/
|
|
324
316
|
function operationFileEntry(node, name, extname = ".ts") {
|
|
@@ -456,13 +448,13 @@ function getPrimarySuccessResponse(node) {
|
|
|
456
448
|
return getOperationSuccessResponses(node)[0] ?? null;
|
|
457
449
|
}
|
|
458
450
|
function resolveErrorNames(node, resolver) {
|
|
459
|
-
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.
|
|
451
|
+
return node.responses.filter((response) => isErrorStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
|
|
460
452
|
}
|
|
461
453
|
function resolveSuccessNames(node, resolver) {
|
|
462
|
-
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.
|
|
454
|
+
return node.responses.filter((response) => isSuccessStatusCode(response.statusCode)).map((response) => resolver.response.status(node, response.statusCode));
|
|
463
455
|
}
|
|
464
456
|
function resolveStatusCodeNames(node, resolver) {
|
|
465
|
-
return node.responses.map((response) => resolver.
|
|
457
|
+
return node.responses.map((response) => resolver.response.status(node, response.statusCode));
|
|
466
458
|
}
|
|
467
459
|
const typeNamesByResolver = /* @__PURE__ */ new WeakMap();
|
|
468
460
|
function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
@@ -479,11 +471,11 @@ function resolveOperationTypeNames(node, resolver, options = {}) {
|
|
|
479
471
|
const responseStatusNames = options.responseStatusNames === "error" ? resolveErrorNames(node, resolver) : options.responseStatusNames === false ? [] : resolveStatusCodeNames(node, resolver);
|
|
480
472
|
const exclude = new Set(options.exclude ?? []);
|
|
481
473
|
const paramNames = options.includeParams === false ? [] : [
|
|
482
|
-
...path.map((param) => resolver.
|
|
483
|
-
...query.map((param) => resolver.
|
|
484
|
-
...header.map((param) => resolver.
|
|
474
|
+
...path.map((param) => resolver.param.path(node, param)),
|
|
475
|
+
...query.map((param) => resolver.param.query(node, param)),
|
|
476
|
+
...header.map((param) => resolver.param.headers(node, param))
|
|
485
477
|
];
|
|
486
|
-
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.
|
|
478
|
+
const bodyAndResponseNames = [node.requestBody?.content?.[0]?.schema ? resolver.response.body(node) : null, resolver.response.response(node)];
|
|
487
479
|
const result = (options.order === "body-response-first" ? [
|
|
488
480
|
...bodyAndResponseNames,
|
|
489
481
|
...paramNames,
|
|
@@ -607,15 +599,15 @@ function resolveClientOperation(options) {
|
|
|
607
599
|
const { clientPlugin, driver, node, root, output } = options;
|
|
608
600
|
if (!clientPlugin) return null;
|
|
609
601
|
const resolver = driver.getResolver(clientPlugin.pluginName);
|
|
610
|
-
if (!resolver) return null;
|
|
611
602
|
const plugin = driver.getPlugin(clientPlugin.pluginName);
|
|
612
|
-
const file = resolver.
|
|
603
|
+
const file = resolver.file({
|
|
604
|
+
...operationFileEntry(node, node.operationId),
|
|
613
605
|
root,
|
|
614
606
|
output: plugin?.options?.output ?? output,
|
|
615
607
|
group: plugin?.options?.group ?? void 0
|
|
616
608
|
});
|
|
617
609
|
return {
|
|
618
|
-
name: resolver.
|
|
610
|
+
name: resolver.name(node.operationId),
|
|
619
611
|
path: file.path,
|
|
620
612
|
clientPath: path.resolve(root, ".kubb/client.ts")
|
|
621
613
|
};
|
|
@@ -665,12 +657,12 @@ function maybeValueOrGetter(type) {
|
|
|
665
657
|
/**
|
|
666
658
|
* Builds the grouped `{ path, query, body, headers }` parameter that mirrors the client
|
|
667
659
|
* function signature. Only the groups the operation carries are emitted, typed from the
|
|
668
|
-
* operation's `
|
|
660
|
+
* operation's `Options`. `keys` narrows the emitted groups, used by the query key which
|
|
669
661
|
* never carries `headers`.
|
|
670
662
|
*
|
|
671
|
-
* By default the whole group is typed as the single `
|
|
663
|
+
* By default the whole group is typed as the single `Options` reference. When
|
|
672
664
|
* `memberTypeWrapper` is set, each group is emitted as its own member typed from the matching
|
|
673
|
-
* `
|
|
665
|
+
* `Options['<group>']` slice and wrapped, used by vue-query to apply
|
|
674
666
|
* `MaybeRefOrGetter` per group.
|
|
675
667
|
*/
|
|
676
668
|
function buildGroupedRequestParam(node, options) {
|
|
@@ -685,13 +677,13 @@ function buildGroupedRequestParam(node, options) {
|
|
|
685
677
|
headers: hasRequiredHeader
|
|
686
678
|
};
|
|
687
679
|
const isOptional = names.every((name) => !requiredByGroup[name]);
|
|
688
|
-
const
|
|
680
|
+
const optionsName = resolver.response.options(node);
|
|
689
681
|
const omittedKeys = requestGroupOrder$1.filter((key) => !keys.includes(key));
|
|
690
|
-
const
|
|
682
|
+
const optionsType = omittedKeys.length > 0 ? `Omit<${optionsName}, ${omittedKeys.map((key) => `'${key}'`).join(" | ")}>` : optionsName;
|
|
691
683
|
if (memberTypeWrapper) {
|
|
692
684
|
const members = names.map((name) => ({
|
|
693
685
|
name,
|
|
694
|
-
type: memberTypeWrapper(`${
|
|
686
|
+
type: memberTypeWrapper(`${optionsType}['${name}']`),
|
|
695
687
|
optional: !requiredByGroup[name]
|
|
696
688
|
}));
|
|
697
689
|
return createFunctionParameter({
|
|
@@ -703,7 +695,7 @@ function buildGroupedRequestParam(node, options) {
|
|
|
703
695
|
}
|
|
704
696
|
return createFunctionParameter({
|
|
705
697
|
name: createObjectBindingPattern({ elements: names.map((name) => ({ name })) }),
|
|
706
|
-
type:
|
|
698
|
+
type: optionsType,
|
|
707
699
|
optional: false,
|
|
708
700
|
...isOptional ? { default: "{}" } : {}
|
|
709
701
|
});
|
|
@@ -771,7 +763,7 @@ function resolveOperationOverrides(node, override) {
|
|
|
771
763
|
}
|
|
772
764
|
/**
|
|
773
765
|
* Build QueryKey params as the grouped `{ path, query, body }` object (NO headers, NO config),
|
|
774
|
-
* typed from the operation's `
|
|
766
|
+
* typed from the operation's `Options` minus `url`. The query key transformer reads the
|
|
775
767
|
* grouped `path`/`query`/`body` bindings.
|
|
776
768
|
*/
|
|
777
769
|
function buildQueryKeyParams(node, options) {
|
|
@@ -843,19 +835,18 @@ const customHookOptionsFileGenerator = defineGenerator({
|
|
|
843
835
|
const { output, customOptions, query, group } = ctx.options;
|
|
844
836
|
if (!customOptions) return null;
|
|
845
837
|
const { importPath, name } = customOptions;
|
|
846
|
-
const hookOptionsName = resolver.
|
|
847
|
-
const customHookOptionsName = resolver.
|
|
838
|
+
const hookOptionsName = resolver.hook.optionsName();
|
|
839
|
+
const customHookOptionsName = resolver.hook.customOptionsName();
|
|
848
840
|
const reactQueryImportPath = query ? query.importPath : "@tanstack/react-query";
|
|
849
841
|
let hookFilePath;
|
|
850
842
|
const firstNode = nodes[0];
|
|
851
843
|
if (firstNode) {
|
|
852
|
-
const hookName = resolver.
|
|
853
|
-
hookFilePath = resolver.
|
|
844
|
+
const hookName = resolver.query.name(firstNode);
|
|
845
|
+
hookFilePath = resolver.file({
|
|
854
846
|
name: hookName,
|
|
855
847
|
extname: ".ts",
|
|
856
848
|
tag: firstNode.tags[0] ?? "default",
|
|
857
|
-
path: firstNode.path
|
|
858
|
-
}, {
|
|
849
|
+
path: firstNode.path,
|
|
859
850
|
root,
|
|
860
851
|
output,
|
|
861
852
|
group: group ?? void 0
|
|
@@ -962,11 +953,10 @@ const hookOptionsGenerator = defineGenerator({
|
|
|
962
953
|
const { resolver, config, root } = ctx;
|
|
963
954
|
const { output, customOptions, query, mutation, suspense, infinite, group, override, hooks } = ctx.options;
|
|
964
955
|
if (!customOptions || !hooks) return null;
|
|
965
|
-
const name = resolver.
|
|
966
|
-
const resolvedFile = resolver.
|
|
956
|
+
const name = resolver.hook.optionsName();
|
|
957
|
+
const resolvedFile = resolver.file({
|
|
967
958
|
name,
|
|
968
|
-
extname: ".ts"
|
|
969
|
-
}, {
|
|
959
|
+
extname: ".ts",
|
|
970
960
|
root,
|
|
971
961
|
output,
|
|
972
962
|
group: group ?? void 0
|
|
@@ -991,9 +981,10 @@ const hookOptionsGenerator = defineGenerator({
|
|
|
991
981
|
const isSuspenseOp = !!suspense;
|
|
992
982
|
const isInfiniteOp = !!nodeInfiniteOptions;
|
|
993
983
|
if (isQueryOp) {
|
|
994
|
-
const queryOptionsName = resolver.
|
|
995
|
-
const queryHookName = resolver.
|
|
996
|
-
const queryHookFile = resolver.
|
|
984
|
+
const queryOptionsName = resolver.query.optionsName(node);
|
|
985
|
+
const queryHookName = resolver.query.name(node);
|
|
986
|
+
const queryHookFile = resolver.file({
|
|
987
|
+
...operationFileEntry(node, queryHookName),
|
|
997
988
|
root,
|
|
998
989
|
output,
|
|
999
990
|
group: group ?? void 0
|
|
@@ -1005,9 +996,10 @@ const hookOptionsGenerator = defineGenerator({
|
|
|
1005
996
|
}));
|
|
1006
997
|
hookOptions[queryHookName] = `Partial<ReturnType<typeof ${queryOptionsName}>>`;
|
|
1007
998
|
if (isSuspenseOp) {
|
|
1008
|
-
const suspenseOptionsName = resolver.
|
|
1009
|
-
const suspenseHookName = resolver.
|
|
1010
|
-
const suspenseHookFile = resolver.
|
|
999
|
+
const suspenseOptionsName = resolver.suspenseQuery.optionsName(node);
|
|
1000
|
+
const suspenseHookName = resolver.suspenseQuery.name(node);
|
|
1001
|
+
const suspenseHookFile = resolver.file({
|
|
1002
|
+
...operationFileEntry(node, suspenseHookName),
|
|
1011
1003
|
root,
|
|
1012
1004
|
output,
|
|
1013
1005
|
group: group ?? void 0
|
|
@@ -1023,9 +1015,10 @@ const hookOptionsGenerator = defineGenerator({
|
|
|
1023
1015
|
const normalizeKey = (key) => key.replace(/\?$/, "");
|
|
1024
1016
|
const queryParamKeys = getOperationParameters(node, { paramsCasing: "original" }).query.map((p) => p.name);
|
|
1025
1017
|
if (nodeInfiniteOptions.queryParam ? queryParamKeys.some((k) => normalizeKey(k) === nodeInfiniteOptions.queryParam) : false) {
|
|
1026
|
-
const infiniteOptionsName = resolver.
|
|
1027
|
-
const infiniteHookName = resolver.
|
|
1028
|
-
const infiniteHookFile = resolver.
|
|
1018
|
+
const infiniteOptionsName = resolver.infiniteQuery.optionsName(node);
|
|
1019
|
+
const infiniteHookName = resolver.infiniteQuery.name(node);
|
|
1020
|
+
const infiniteHookFile = resolver.file({
|
|
1021
|
+
...operationFileEntry(node, infiniteHookName),
|
|
1029
1022
|
root,
|
|
1030
1023
|
output,
|
|
1031
1024
|
group: group ?? void 0
|
|
@@ -1037,9 +1030,10 @@ const hookOptionsGenerator = defineGenerator({
|
|
|
1037
1030
|
}));
|
|
1038
1031
|
hookOptions[infiniteHookName] = `Partial<ReturnType<typeof ${infiniteOptionsName}>>`;
|
|
1039
1032
|
if (isSuspenseOp) {
|
|
1040
|
-
const suspenseInfiniteOptionsName = resolver.
|
|
1041
|
-
const suspenseInfiniteHookName = resolver.
|
|
1042
|
-
const suspenseInfiniteHookFile = resolver.
|
|
1033
|
+
const suspenseInfiniteOptionsName = resolver.suspenseInfiniteQuery.optionsName(node);
|
|
1034
|
+
const suspenseInfiniteHookName = resolver.suspenseInfiniteQuery.name(node);
|
|
1035
|
+
const suspenseInfiniteHookFile = resolver.file({
|
|
1036
|
+
...operationFileEntry(node, suspenseInfiniteHookName),
|
|
1043
1037
|
root,
|
|
1044
1038
|
output,
|
|
1045
1039
|
group: group ?? void 0
|
|
@@ -1055,9 +1049,10 @@ const hookOptionsGenerator = defineGenerator({
|
|
|
1055
1049
|
}
|
|
1056
1050
|
}
|
|
1057
1051
|
if (isMutationOp) {
|
|
1058
|
-
const mutationOptionsName = resolver.
|
|
1059
|
-
const mutationHookName = resolver.
|
|
1060
|
-
const mutationHookFile = resolver.
|
|
1052
|
+
const mutationOptionsName = resolver.mutation.optionsName(node);
|
|
1053
|
+
const mutationHookName = resolver.mutation.name(node);
|
|
1054
|
+
const mutationHookFile = resolver.file({
|
|
1055
|
+
...operationFileEntry(node, mutationHookName),
|
|
1061
1056
|
root,
|
|
1062
1057
|
output,
|
|
1063
1058
|
group: group ?? void 0
|
|
@@ -1074,7 +1069,7 @@ const hookOptionsGenerator = defineGenerator({
|
|
|
1074
1069
|
baseName: hookOptionsFile.baseName,
|
|
1075
1070
|
path: hookOptionsFile.path,
|
|
1076
1071
|
meta: hookOptionsFile.meta,
|
|
1077
|
-
banner: resolver.
|
|
1072
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1078
1073
|
output,
|
|
1079
1074
|
config,
|
|
1080
1075
|
file: {
|
|
@@ -1082,7 +1077,7 @@ const hookOptionsGenerator = defineGenerator({
|
|
|
1082
1077
|
baseName: hookOptionsFile.baseName
|
|
1083
1078
|
}
|
|
1084
1079
|
}),
|
|
1085
|
-
footer: resolver.
|
|
1080
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1086
1081
|
output,
|
|
1087
1082
|
config,
|
|
1088
1083
|
file: {
|
|
@@ -1124,7 +1119,7 @@ function buildInfiniteQueryParamsNode(node, options) {
|
|
|
1124
1119
|
}
|
|
1125
1120
|
function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, initialPageParam, queryParam, customOptions }) {
|
|
1126
1121
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1127
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1122
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1128
1123
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1129
1124
|
const responseType = responseName;
|
|
1130
1125
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1135,8 +1130,8 @@ function InfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName,
|
|
|
1135
1130
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1136
1131
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1137
1132
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1138
|
-
const groupName = tsResolver.
|
|
1139
|
-
return groupName !== tsResolver.
|
|
1133
|
+
const groupName = tsResolver.param.query(node, rawQueryParams[0]);
|
|
1134
|
+
return groupName !== tsResolver.param.name(node, rawQueryParams[0]) ? groupName : null;
|
|
1140
1135
|
})() : null;
|
|
1141
1136
|
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1142
1137
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
@@ -1194,7 +1189,7 @@ function getQueryOptionsParams(node, options) {
|
|
|
1194
1189
|
}
|
|
1195
1190
|
function QueryOptions({ name, clientName, node, tsResolver, queryKeyName }) {
|
|
1196
1191
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1197
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1192
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1198
1193
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1199
1194
|
const TData = responseName;
|
|
1200
1195
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1233,7 +1228,7 @@ const declarationPrinter$6 = functionPrinter({ mode: "declaration" });
|
|
|
1233
1228
|
const callPrinter$3 = functionPrinter({ mode: "call" });
|
|
1234
1229
|
function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName }) {
|
|
1235
1230
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1236
|
-
const queryFnDataType = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1231
|
+
const queryFnDataType = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1237
1232
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1238
1233
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1239
1234
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -1243,8 +1238,8 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
1243
1238
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1244
1239
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1245
1240
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1246
|
-
const groupName = tsResolver.
|
|
1247
|
-
return groupName !== tsResolver.
|
|
1241
|
+
const groupName = tsResolver.param.query(node, rawQueryParams[0]);
|
|
1242
|
+
return groupName !== tsResolver.param.name(node, rawQueryParams[0]) ? groupName : null;
|
|
1248
1243
|
})() : null;
|
|
1249
1244
|
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1250
1245
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
@@ -1260,8 +1255,8 @@ function InfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam,
|
|
|
1260
1255
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
1261
1256
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
1262
1257
|
if (hasNewParams) {
|
|
1263
|
-
const nextAccessor = nextParam ?
|
|
1264
|
-
const prevAccessor = previousParam ?
|
|
1258
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
1259
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
1265
1260
|
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1266
1261
|
}
|
|
1267
1262
|
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
@@ -1331,7 +1326,7 @@ function buildMutationConfigParamsNode(node) {
|
|
|
1331
1326
|
}
|
|
1332
1327
|
function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }) {
|
|
1333
1328
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1334
|
-
const TData = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1329
|
+
const TData = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1335
1330
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1336
1331
|
const TError = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1337
1332
|
const configParamsNode = buildMutationConfigParamsNode(node);
|
|
@@ -1339,7 +1334,7 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }
|
|
|
1339
1334
|
const groupedParam = buildGroupedRequestParam(node, { resolver: tsResolver });
|
|
1340
1335
|
const hasMutationParams = groupedParam !== null;
|
|
1341
1336
|
const groupedParamsNode = createFunctionParameters({ params: groupedParam ? [groupedParam] : [] });
|
|
1342
|
-
const TRequest = hasMutationParams ? tsResolver.
|
|
1337
|
+
const TRequest = hasMutationParams ? tsResolver.response.options(node) : "undefined";
|
|
1343
1338
|
const argBindingStr = hasMutationParams ? callPrinter$2.print(groupedParamsNode) ?? "" : "_";
|
|
1344
1339
|
const mutationFnBody = `const { data } = await ${buildClientCall(node, {
|
|
1345
1340
|
clientName,
|
|
@@ -1372,12 +1367,12 @@ function MutationOptions({ name, clientName, node, tsResolver, mutationKeyName }
|
|
|
1372
1367
|
const declarationPrinter$4 = functionPrinter({ mode: "declaration" });
|
|
1373
1368
|
const callPrinter$1 = functionPrinter({ mode: "call" });
|
|
1374
1369
|
function resolveMutationRequestType(node, resolver) {
|
|
1375
|
-
return buildGroupedRequestParam(node, { resolver }) ? resolver.
|
|
1370
|
+
return buildGroupedRequestParam(node, { resolver }) ? resolver.response.options(node) : "undefined";
|
|
1376
1371
|
}
|
|
1377
1372
|
function buildMutationParamsNode(node, options) {
|
|
1378
1373
|
const { resolver } = options;
|
|
1379
1374
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1380
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.
|
|
1375
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
1381
1376
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1382
1377
|
return createFunctionParameters({ params: [createFunctionParameter({
|
|
1383
1378
|
name: "options",
|
|
@@ -1395,7 +1390,7 @@ function buildMutationParamsNode(node, options) {
|
|
|
1395
1390
|
}
|
|
1396
1391
|
function Mutation({ name, mutationOptionsName, node, tsResolver, mutationKeyName, customOptions }) {
|
|
1397
1392
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1398
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1393
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1399
1394
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1400
1395
|
const generics = [
|
|
1401
1396
|
responseName,
|
|
@@ -1440,7 +1435,7 @@ const declarationPrinter$3 = functionPrinter({ mode: "declaration" });
|
|
|
1440
1435
|
function buildQueryParamsNode(node, options) {
|
|
1441
1436
|
const { resolver } = options;
|
|
1442
1437
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1443
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.
|
|
1438
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
1444
1439
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1445
1440
|
const optionsParam = createFunctionParameter({
|
|
1446
1441
|
name: "options",
|
|
@@ -1463,7 +1458,7 @@ function buildQueryParamsNode(node, options) {
|
|
|
1463
1458
|
}
|
|
1464
1459
|
function Query({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions }) {
|
|
1465
1460
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1466
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1461
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1467
1462
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1468
1463
|
const TData = responseName;
|
|
1469
1464
|
const returnType = `UseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
@@ -1526,7 +1521,7 @@ function buildSuspenseInfiniteQueryParamsNode(node, options) {
|
|
|
1526
1521
|
}
|
|
1527
1522
|
function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions, initialPageParam, queryParam }) {
|
|
1528
1523
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1529
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1524
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1530
1525
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1531
1526
|
const responseType = responseName;
|
|
1532
1527
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
@@ -1537,8 +1532,8 @@ function SuspenseInfiniteQuery({ name, queryKeyTypeName, queryOptionsName, query
|
|
|
1537
1532
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1538
1533
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1539
1534
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1540
|
-
const groupName = tsResolver.
|
|
1541
|
-
return groupName !== tsResolver.
|
|
1535
|
+
const groupName = tsResolver.param.query(node, rawQueryParams[0]);
|
|
1536
|
+
return groupName !== tsResolver.param.name(node, rawQueryParams[0]) ? groupName : null;
|
|
1542
1537
|
})() : null;
|
|
1543
1538
|
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1544
1539
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
@@ -1593,7 +1588,7 @@ const declarationPrinter$1 = functionPrinter({ mode: "declaration" });
|
|
|
1593
1588
|
const callPrinter = functionPrinter({ mode: "call" });
|
|
1594
1589
|
function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, cursorParam, nextParam, previousParam, node, tsResolver, queryParam, queryKeyName }) {
|
|
1595
1590
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1596
|
-
const queryFnDataType = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1591
|
+
const queryFnDataType = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1597
1592
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1598
1593
|
const errorType = `ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`;
|
|
1599
1594
|
const isInitialPageParamDefined = initialPageParam !== void 0 && initialPageParam !== null;
|
|
@@ -1603,8 +1598,8 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1603
1598
|
})() : "string" : typeof initialPageParam === "boolean" ? "boolean" : "unknown";
|
|
1604
1599
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1605
1600
|
const queryParamsTypeName = rawQueryParams.length > 0 ? (() => {
|
|
1606
|
-
const groupName = tsResolver.
|
|
1607
|
-
return groupName !== tsResolver.
|
|
1601
|
+
const groupName = tsResolver.param.query(node, rawQueryParams[0]);
|
|
1602
|
+
return groupName !== tsResolver.param.name(node, rawQueryParams[0]) ? groupName : null;
|
|
1608
1603
|
})() : null;
|
|
1609
1604
|
const queryParamType = queryParam && queryParamsTypeName ? `${queryParamsTypeName}['${queryParam}']` : null;
|
|
1610
1605
|
const pageParamType = queryParamType ? isInitialPageParamDefined ? `NonNullable<${queryParamType}>` : queryParamType : fallbackPageParamType;
|
|
@@ -1620,8 +1615,8 @@ function SuspenseInfiniteQueryOptions({ name, clientName, initialPageParam, curs
|
|
|
1620
1615
|
const hasNewParams = nextParam != null || previousParam != null;
|
|
1621
1616
|
const [getNextPageParamExpr, getPreviousPageParamExpr] = (() => {
|
|
1622
1617
|
if (hasNewParams) {
|
|
1623
|
-
const nextAccessor = nextParam ?
|
|
1624
|
-
const prevAccessor = previousParam ?
|
|
1618
|
+
const nextAccessor = nextParam ? getNestedAccessor(nextParam, "lastPage") : null;
|
|
1619
|
+
const prevAccessor = previousParam ? getNestedAccessor(previousParam, "firstPage") : null;
|
|
1625
1620
|
return [nextAccessor ? `getNextPageParam: (lastPage) => ${nextAccessor}` : null, prevAccessor ? `getPreviousPageParam: (firstPage) => ${prevAccessor}` : null];
|
|
1626
1621
|
}
|
|
1627
1622
|
if (cursorParam) return [`getNextPageParam: (lastPage) => lastPage['${cursorParam}']`, `getPreviousPageParam: (firstPage) => firstPage['${cursorParam}']`];
|
|
@@ -1684,7 +1679,7 @@ const declarationPrinter = functionPrinter({ mode: "declaration" });
|
|
|
1684
1679
|
function buildSuspenseQueryParamsNode(node, options) {
|
|
1685
1680
|
const { resolver } = options;
|
|
1686
1681
|
const successNames = resolveSuccessNames(node, resolver);
|
|
1687
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.
|
|
1682
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : resolver.response.response(node);
|
|
1688
1683
|
const errorNames = resolveErrorNames(node, resolver);
|
|
1689
1684
|
const optionsParam = createFunctionParameter({
|
|
1690
1685
|
name: "options",
|
|
@@ -1706,7 +1701,7 @@ function buildSuspenseQueryParamsNode(node, options) {
|
|
|
1706
1701
|
}
|
|
1707
1702
|
function SuspenseQuery({ name, queryKeyTypeName, queryOptionsName, queryKeyName, node, tsResolver, customOptions }) {
|
|
1708
1703
|
const successNames = resolveSuccessNames(node, tsResolver);
|
|
1709
|
-
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.
|
|
1704
|
+
const responseName = successNames.length > 0 ? successNames.join(" | ") : tsResolver.response.response(node);
|
|
1710
1705
|
const errorNames = resolveErrorNames(node, tsResolver);
|
|
1711
1706
|
const TData = responseName;
|
|
1712
1707
|
const returnType = `UseSuspenseQueryResult<TData, ${`ResponseErrorConfig<${errorNames.length > 0 ? errorNames.join(" | ") : "Error"}>`}> & { queryKey: TQueryKey }`;
|
|
@@ -1782,26 +1777,28 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1782
1777
|
output
|
|
1783
1778
|
});
|
|
1784
1779
|
if (!contractOp) return null;
|
|
1785
|
-
const queryName = resolver.
|
|
1786
|
-
const queryOptionsName = resolver.
|
|
1787
|
-
const queryKeyName = resolver.
|
|
1788
|
-
const queryKeyTypeName = resolver.
|
|
1780
|
+
const queryName = resolver.infiniteQuery.name(node);
|
|
1781
|
+
const queryOptionsName = resolver.infiniteQuery.optionsName(node);
|
|
1782
|
+
const queryKeyName = resolver.infiniteQuery.keyName(node);
|
|
1783
|
+
const queryKeyTypeName = resolver.infiniteQuery.keyTypeName(node);
|
|
1789
1784
|
const meta = {
|
|
1790
|
-
file: resolver.
|
|
1785
|
+
file: resolver.file({
|
|
1786
|
+
...operationFileEntry(node, queryName),
|
|
1791
1787
|
root,
|
|
1792
1788
|
output,
|
|
1793
1789
|
group: group ?? void 0
|
|
1794
1790
|
}),
|
|
1795
|
-
fileTs: tsResolver.
|
|
1791
|
+
fileTs: tsResolver.file({
|
|
1792
|
+
...operationFileEntry(node, node.operationId),
|
|
1796
1793
|
root,
|
|
1797
1794
|
output: pluginTs.options?.output ?? output,
|
|
1798
1795
|
group: pluginTs.options?.group ?? void 0
|
|
1799
1796
|
})
|
|
1800
1797
|
};
|
|
1801
1798
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
1802
|
-
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.
|
|
1799
|
+
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.param.query(node, rawQueryParams[0]) !== tsResolver.param.name(node, rawQueryParams[0]) ? tsResolver.param.query(node, rawQueryParams[0]) : null;
|
|
1803
1800
|
const importedTypeNames = [
|
|
1804
|
-
tsResolver.
|
|
1801
|
+
tsResolver.response.options(node),
|
|
1805
1802
|
queryParamsTypeName,
|
|
1806
1803
|
...resolveOperationTypeNames(node, tsResolver, {
|
|
1807
1804
|
exclude: [queryKeyTypeName],
|
|
@@ -1814,7 +1811,7 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1814
1811
|
baseName: meta.file.baseName,
|
|
1815
1812
|
path: meta.file.path,
|
|
1816
1813
|
meta: meta.file.meta,
|
|
1817
|
-
banner: resolver.
|
|
1814
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1818
1815
|
output,
|
|
1819
1816
|
config,
|
|
1820
1817
|
file: {
|
|
@@ -1822,7 +1819,7 @@ const infiniteQueryGenerator = defineGenerator({
|
|
|
1822
1819
|
baseName: meta.file.baseName
|
|
1823
1820
|
}
|
|
1824
1821
|
}),
|
|
1825
|
-
footer: resolver.
|
|
1822
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1826
1823
|
output,
|
|
1827
1824
|
config,
|
|
1828
1825
|
file: {
|
|
@@ -1940,23 +1937,25 @@ const mutationGenerator = defineGenerator({
|
|
|
1940
1937
|
output
|
|
1941
1938
|
});
|
|
1942
1939
|
if (!contractOp) return null;
|
|
1943
|
-
const mutationHookName = resolver.
|
|
1944
|
-
const mutationTypeName = resolver.
|
|
1945
|
-
const mutationOptionsName = resolver.
|
|
1946
|
-
const mutationKeyName = resolver.
|
|
1940
|
+
const mutationHookName = resolver.mutation.name(node);
|
|
1941
|
+
const mutationTypeName = resolver.mutation.typeName(node);
|
|
1942
|
+
const mutationOptionsName = resolver.mutation.optionsName(node);
|
|
1943
|
+
const mutationKeyName = resolver.mutation.keyName(node);
|
|
1947
1944
|
const meta = {
|
|
1948
|
-
file: resolver.
|
|
1945
|
+
file: resolver.file({
|
|
1946
|
+
...operationFileEntry(node, mutationHookName),
|
|
1949
1947
|
root,
|
|
1950
1948
|
output,
|
|
1951
1949
|
group: group ?? void 0
|
|
1952
1950
|
}),
|
|
1953
|
-
fileTs: tsResolver.
|
|
1951
|
+
fileTs: tsResolver.file({
|
|
1952
|
+
...operationFileEntry(node, node.operationId),
|
|
1954
1953
|
root,
|
|
1955
1954
|
output: pluginTs.options?.output ?? output,
|
|
1956
1955
|
group: pluginTs.options?.group ?? void 0
|
|
1957
1956
|
})
|
|
1958
1957
|
};
|
|
1959
|
-
const importedTypeNames = [tsResolver.
|
|
1958
|
+
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
1960
1959
|
order: "body-response-first",
|
|
1961
1960
|
includeParams: false
|
|
1962
1961
|
})].filter((name) => Boolean(name));
|
|
@@ -1965,7 +1964,7 @@ const mutationGenerator = defineGenerator({
|
|
|
1965
1964
|
baseName: meta.file.baseName,
|
|
1966
1965
|
path: meta.file.path,
|
|
1967
1966
|
meta: meta.file.meta,
|
|
1968
|
-
banner: resolver.
|
|
1967
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
1969
1968
|
output,
|
|
1970
1969
|
config,
|
|
1971
1970
|
file: {
|
|
@@ -1973,7 +1972,7 @@ const mutationGenerator = defineGenerator({
|
|
|
1973
1972
|
baseName: meta.file.baseName
|
|
1974
1973
|
}
|
|
1975
1974
|
}),
|
|
1976
|
-
footer: resolver.
|
|
1975
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
1977
1976
|
output,
|
|
1978
1977
|
config,
|
|
1979
1978
|
file: {
|
|
@@ -2077,23 +2076,25 @@ const queryGenerator = defineGenerator({
|
|
|
2077
2076
|
output
|
|
2078
2077
|
});
|
|
2079
2078
|
if (!contractOp) return null;
|
|
2080
|
-
const queryName = resolver.
|
|
2081
|
-
const queryOptionsName = resolver.
|
|
2082
|
-
const queryKeyName = resolver.
|
|
2083
|
-
const queryKeyTypeName = resolver.
|
|
2079
|
+
const queryName = resolver.query.name(node);
|
|
2080
|
+
const queryOptionsName = resolver.query.optionsName(node);
|
|
2081
|
+
const queryKeyName = resolver.query.keyName(node);
|
|
2082
|
+
const queryKeyTypeName = resolver.query.keyTypeName(node);
|
|
2084
2083
|
const meta = {
|
|
2085
|
-
file: resolver.
|
|
2084
|
+
file: resolver.file({
|
|
2085
|
+
...operationFileEntry(node, queryName),
|
|
2086
2086
|
root,
|
|
2087
2087
|
output,
|
|
2088
2088
|
group: group ?? void 0
|
|
2089
2089
|
}),
|
|
2090
|
-
fileTs: tsResolver.
|
|
2090
|
+
fileTs: tsResolver.file({
|
|
2091
|
+
...operationFileEntry(node, node.operationId),
|
|
2091
2092
|
root,
|
|
2092
2093
|
output: pluginTs.options?.output ?? output,
|
|
2093
2094
|
group: pluginTs.options?.group ?? void 0
|
|
2094
2095
|
})
|
|
2095
2096
|
};
|
|
2096
|
-
const importedTypeNames = [tsResolver.
|
|
2097
|
+
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
2097
2098
|
exclude: [queryKeyTypeName],
|
|
2098
2099
|
order: "body-response-first",
|
|
2099
2100
|
includeParams: false
|
|
@@ -2103,7 +2104,7 @@ const queryGenerator = defineGenerator({
|
|
|
2103
2104
|
baseName: meta.file.baseName,
|
|
2104
2105
|
path: meta.file.path,
|
|
2105
2106
|
meta: meta.file.meta,
|
|
2106
|
-
banner: resolver.
|
|
2107
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
2107
2108
|
output,
|
|
2108
2109
|
config,
|
|
2109
2110
|
file: {
|
|
@@ -2111,7 +2112,7 @@ const queryGenerator = defineGenerator({
|
|
|
2111
2112
|
baseName: meta.file.baseName
|
|
2112
2113
|
}
|
|
2113
2114
|
}),
|
|
2114
|
-
footer: resolver.
|
|
2115
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
2115
2116
|
output,
|
|
2116
2117
|
config,
|
|
2117
2118
|
file: {
|
|
@@ -2226,26 +2227,28 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
|
2226
2227
|
output
|
|
2227
2228
|
});
|
|
2228
2229
|
if (!contractOp) return null;
|
|
2229
|
-
const queryName = resolver.
|
|
2230
|
-
const queryOptionsName = resolver.
|
|
2231
|
-
const queryKeyName = resolver.
|
|
2232
|
-
const queryKeyTypeName = resolver.
|
|
2230
|
+
const queryName = resolver.suspenseInfiniteQuery.name(node);
|
|
2231
|
+
const queryOptionsName = resolver.suspenseInfiniteQuery.optionsName(node);
|
|
2232
|
+
const queryKeyName = resolver.suspenseInfiniteQuery.keyName(node);
|
|
2233
|
+
const queryKeyTypeName = resolver.suspenseInfiniteQuery.keyTypeName(node);
|
|
2233
2234
|
const meta = {
|
|
2234
|
-
file: resolver.
|
|
2235
|
+
file: resolver.file({
|
|
2236
|
+
...operationFileEntry(node, queryName),
|
|
2235
2237
|
root,
|
|
2236
2238
|
output,
|
|
2237
2239
|
group: group ?? void 0
|
|
2238
2240
|
}),
|
|
2239
|
-
fileTs: tsResolver.
|
|
2241
|
+
fileTs: tsResolver.file({
|
|
2242
|
+
...operationFileEntry(node, node.operationId),
|
|
2240
2243
|
root,
|
|
2241
2244
|
output: pluginTs.options?.output ?? output,
|
|
2242
2245
|
group: pluginTs.options?.group ?? void 0
|
|
2243
2246
|
})
|
|
2244
2247
|
};
|
|
2245
2248
|
const rawQueryParams = getOperationParameters(node, { paramsCasing: "original" }).query;
|
|
2246
|
-
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.
|
|
2249
|
+
const queryParamsTypeName = rawQueryParams.length > 0 && tsResolver.param.query(node, rawQueryParams[0]) !== tsResolver.param.name(node, rawQueryParams[0]) ? tsResolver.param.query(node, rawQueryParams[0]) : null;
|
|
2247
2250
|
const importedTypeNames = [
|
|
2248
|
-
tsResolver.
|
|
2251
|
+
tsResolver.response.options(node),
|
|
2249
2252
|
queryParamsTypeName,
|
|
2250
2253
|
...resolveOperationTypeNames(node, tsResolver, {
|
|
2251
2254
|
order: "body-response-first",
|
|
@@ -2257,7 +2260,7 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
|
2257
2260
|
baseName: meta.file.baseName,
|
|
2258
2261
|
path: meta.file.path,
|
|
2259
2262
|
meta: meta.file.meta,
|
|
2260
|
-
banner: resolver.
|
|
2263
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
2261
2264
|
output,
|
|
2262
2265
|
config,
|
|
2263
2266
|
file: {
|
|
@@ -2265,7 +2268,7 @@ const suspenseInfiniteQueryGenerator = defineGenerator({
|
|
|
2265
2268
|
baseName: meta.file.baseName
|
|
2266
2269
|
}
|
|
2267
2270
|
}),
|
|
2268
|
-
footer: resolver.
|
|
2271
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
2269
2272
|
output,
|
|
2270
2273
|
config,
|
|
2271
2274
|
file: {
|
|
@@ -2385,23 +2388,25 @@ const suspenseQueryGenerator = defineGenerator({
|
|
|
2385
2388
|
output
|
|
2386
2389
|
});
|
|
2387
2390
|
if (!contractOp) return null;
|
|
2388
|
-
const queryName = resolver.
|
|
2389
|
-
const queryOptionsName = resolver.
|
|
2390
|
-
const queryKeyName = resolver.
|
|
2391
|
-
const queryKeyTypeName = resolver.
|
|
2391
|
+
const queryName = resolver.suspenseQuery.name(node);
|
|
2392
|
+
const queryOptionsName = resolver.suspenseQuery.optionsName(node);
|
|
2393
|
+
const queryKeyName = resolver.suspenseQuery.keyName(node);
|
|
2394
|
+
const queryKeyTypeName = resolver.suspenseQuery.keyTypeName(node);
|
|
2392
2395
|
const meta = {
|
|
2393
|
-
file: resolver.
|
|
2396
|
+
file: resolver.file({
|
|
2397
|
+
...operationFileEntry(node, queryName),
|
|
2394
2398
|
root,
|
|
2395
2399
|
output,
|
|
2396
2400
|
group: group ?? void 0
|
|
2397
2401
|
}),
|
|
2398
|
-
fileTs: tsResolver.
|
|
2402
|
+
fileTs: tsResolver.file({
|
|
2403
|
+
...operationFileEntry(node, node.operationId),
|
|
2399
2404
|
root,
|
|
2400
2405
|
output: pluginTs.options?.output ?? output,
|
|
2401
2406
|
group: pluginTs.options?.group ?? void 0
|
|
2402
2407
|
})
|
|
2403
2408
|
};
|
|
2404
|
-
const importedTypeNames = [tsResolver.
|
|
2409
|
+
const importedTypeNames = [tsResolver.response.options(node), ...resolveOperationTypeNames(node, tsResolver, {
|
|
2405
2410
|
exclude: [queryKeyTypeName],
|
|
2406
2411
|
order: "body-response-first",
|
|
2407
2412
|
includeParams: false
|
|
@@ -2411,7 +2416,7 @@ const suspenseQueryGenerator = defineGenerator({
|
|
|
2411
2416
|
baseName: meta.file.baseName,
|
|
2412
2417
|
path: meta.file.path,
|
|
2413
2418
|
meta: meta.file.meta,
|
|
2414
|
-
banner: resolver.
|
|
2419
|
+
banner: resolver.default.banner(ctx.meta, {
|
|
2415
2420
|
output,
|
|
2416
2421
|
config,
|
|
2417
2422
|
file: {
|
|
@@ -2419,7 +2424,7 @@ const suspenseQueryGenerator = defineGenerator({
|
|
|
2419
2424
|
baseName: meta.file.baseName
|
|
2420
2425
|
}
|
|
2421
2426
|
}),
|
|
2422
|
-
footer: resolver.
|
|
2427
|
+
footer: resolver.default.footer(ctx.meta, {
|
|
2423
2428
|
output,
|
|
2424
2429
|
config,
|
|
2425
2430
|
file: {
|
|
@@ -2507,110 +2512,112 @@ function capitalize(name) {
|
|
|
2507
2512
|
* `useFooSuspense`, `useFooInfinite`, ...) and its companion helpers
|
|
2508
2513
|
* (`fooQueryKey`, `fooQueryOptions`).
|
|
2509
2514
|
*
|
|
2510
|
-
* Functions and files use camelCase; hooks get the `use`
|
|
2511
|
-
* infinite variants are suffixed with `Suspense`/`Infinite`.
|
|
2515
|
+
* Functions and files use the built-in camelCase casing; hooks get the `use`
|
|
2516
|
+
* prefix; suspense and infinite variants are suffixed with `Suspense`/`Infinite`.
|
|
2512
2517
|
*
|
|
2513
2518
|
* @example Resolve hook and helper names
|
|
2514
2519
|
* ```ts
|
|
2515
2520
|
* import { resolverReactQuery } from '@kubb/plugin-react-query'
|
|
2516
2521
|
*
|
|
2517
|
-
* resolverReactQuery.
|
|
2518
|
-
* resolverReactQuery.
|
|
2519
|
-
* resolverReactQuery.
|
|
2520
|
-
* resolverReactQuery.
|
|
2522
|
+
* resolverReactQuery.query.name(operationNode) // 'useGetPetById'
|
|
2523
|
+
* resolverReactQuery.mutation.name(operationNode) // 'useUpdatePet'
|
|
2524
|
+
* resolverReactQuery.query.keyName(operationNode) // 'getPetByIdQueryKey'
|
|
2525
|
+
* resolverReactQuery.query.optionsName(operationNode) // 'getPetByIdQueryOptions'
|
|
2521
2526
|
* ```
|
|
2522
2527
|
*/
|
|
2523
|
-
const resolverReactQuery =
|
|
2524
|
-
name: "default",
|
|
2528
|
+
const resolverReactQuery = createResolver({
|
|
2525
2529
|
pluginName: "plugin-react-query",
|
|
2526
|
-
|
|
2527
|
-
|
|
2528
|
-
|
|
2529
|
-
|
|
2530
|
-
|
|
2531
|
-
|
|
2532
|
-
|
|
2533
|
-
|
|
2534
|
-
|
|
2535
|
-
|
|
2536
|
-
|
|
2537
|
-
|
|
2538
|
-
|
|
2539
|
-
|
|
2540
|
-
|
|
2541
|
-
|
|
2542
|
-
return `use${capitalize(this.resolveName(node.operationId))}Infinite`;
|
|
2543
|
-
},
|
|
2544
|
-
resolveSuspenseInfiniteQueryName(node) {
|
|
2545
|
-
return `use${capitalize(this.resolveName(node.operationId))}SuspenseInfinite`;
|
|
2546
|
-
},
|
|
2547
|
-
resolveMutationName(node) {
|
|
2548
|
-
return `use${capitalize(this.resolveName(node.operationId))}`;
|
|
2549
|
-
},
|
|
2550
|
-
resolveQueryOptionsName(node) {
|
|
2551
|
-
return `${this.resolveName(node.operationId)}QueryOptions`;
|
|
2552
|
-
},
|
|
2553
|
-
resolveSuspenseQueryOptionsName(node) {
|
|
2554
|
-
return `${this.resolveName(node.operationId)}SuspenseQueryOptions`;
|
|
2555
|
-
},
|
|
2556
|
-
resolveInfiniteQueryOptionsName(node) {
|
|
2557
|
-
return `${this.resolveName(node.operationId)}InfiniteQueryOptions`;
|
|
2558
|
-
},
|
|
2559
|
-
resolveSuspenseInfiniteQueryOptionsName(node) {
|
|
2560
|
-
return `${this.resolveName(node.operationId)}SuspenseInfiniteQueryOptions`;
|
|
2561
|
-
},
|
|
2562
|
-
resolveMutationOptionsName(node) {
|
|
2563
|
-
return `${this.resolveName(node.operationId)}MutationOptions`;
|
|
2564
|
-
},
|
|
2565
|
-
resolveQueryKeyName(node) {
|
|
2566
|
-
return `${this.resolveName(node.operationId)}QueryKey`;
|
|
2567
|
-
},
|
|
2568
|
-
resolveSuspenseQueryKeyName(node) {
|
|
2569
|
-
return `${this.resolveName(node.operationId)}SuspenseQueryKey`;
|
|
2570
|
-
},
|
|
2571
|
-
resolveInfiniteQueryKeyName(node) {
|
|
2572
|
-
return `${this.resolveName(node.operationId)}InfiniteQueryKey`;
|
|
2573
|
-
},
|
|
2574
|
-
resolveSuspenseInfiniteQueryKeyName(node) {
|
|
2575
|
-
return `${this.resolveName(node.operationId)}SuspenseInfiniteQueryKey`;
|
|
2576
|
-
},
|
|
2577
|
-
resolveMutationKeyName(node) {
|
|
2578
|
-
return `${this.resolveName(node.operationId)}MutationKey`;
|
|
2579
|
-
},
|
|
2580
|
-
resolveQueryKeyTypeName(node) {
|
|
2581
|
-
return `${capitalize(this.resolveName(node.operationId))}QueryKey`;
|
|
2582
|
-
},
|
|
2583
|
-
resolveSuspenseQueryKeyTypeName(node) {
|
|
2584
|
-
return `${capitalize(this.resolveName(node.operationId))}SuspenseQueryKey`;
|
|
2585
|
-
},
|
|
2586
|
-
resolveInfiniteQueryKeyTypeName(node) {
|
|
2587
|
-
return `${capitalize(this.resolveName(node.operationId))}InfiniteQueryKey`;
|
|
2588
|
-
},
|
|
2589
|
-
resolveSuspenseInfiniteQueryKeyTypeName(node) {
|
|
2590
|
-
return `${capitalize(this.resolveName(node.operationId))}SuspenseInfiniteQueryKey`;
|
|
2591
|
-
},
|
|
2592
|
-
resolveMutationTypeName(node) {
|
|
2593
|
-
return capitalize(this.resolveName(node.operationId));
|
|
2594
|
-
},
|
|
2595
|
-
resolveClientName(node) {
|
|
2596
|
-
return this.resolveName(node.operationId);
|
|
2530
|
+
query: {
|
|
2531
|
+
name(node) {
|
|
2532
|
+
return `use${capitalize(this.name(node.operationId))}`;
|
|
2533
|
+
},
|
|
2534
|
+
optionsName(node) {
|
|
2535
|
+
return `${this.name(node.operationId)}QueryOptions`;
|
|
2536
|
+
},
|
|
2537
|
+
keyName(node) {
|
|
2538
|
+
return `${this.name(node.operationId)}QueryKey`;
|
|
2539
|
+
},
|
|
2540
|
+
keyTypeName(node) {
|
|
2541
|
+
return `${capitalize(this.name(node.operationId))}QueryKey`;
|
|
2542
|
+
},
|
|
2543
|
+
clientName(node) {
|
|
2544
|
+
return this.name(node.operationId);
|
|
2545
|
+
}
|
|
2597
2546
|
},
|
|
2598
|
-
|
|
2599
|
-
|
|
2547
|
+
suspenseQuery: {
|
|
2548
|
+
name(node) {
|
|
2549
|
+
return `use${capitalize(this.name(node.operationId))}Suspense`;
|
|
2550
|
+
},
|
|
2551
|
+
optionsName(node) {
|
|
2552
|
+
return `${this.name(node.operationId)}SuspenseQueryOptions`;
|
|
2553
|
+
},
|
|
2554
|
+
keyName(node) {
|
|
2555
|
+
return `${this.name(node.operationId)}SuspenseQueryKey`;
|
|
2556
|
+
},
|
|
2557
|
+
keyTypeName(node) {
|
|
2558
|
+
return `${capitalize(this.name(node.operationId))}SuspenseQueryKey`;
|
|
2559
|
+
},
|
|
2560
|
+
clientName(node) {
|
|
2561
|
+
return `${this.name(node.operationId)}Suspense`;
|
|
2562
|
+
}
|
|
2600
2563
|
},
|
|
2601
|
-
|
|
2602
|
-
|
|
2564
|
+
infiniteQuery: {
|
|
2565
|
+
name(node) {
|
|
2566
|
+
return `use${capitalize(this.name(node.operationId))}Infinite`;
|
|
2567
|
+
},
|
|
2568
|
+
optionsName(node) {
|
|
2569
|
+
return `${this.name(node.operationId)}InfiniteQueryOptions`;
|
|
2570
|
+
},
|
|
2571
|
+
keyName(node) {
|
|
2572
|
+
return `${this.name(node.operationId)}InfiniteQueryKey`;
|
|
2573
|
+
},
|
|
2574
|
+
keyTypeName(node) {
|
|
2575
|
+
return `${capitalize(this.name(node.operationId))}InfiniteQueryKey`;
|
|
2576
|
+
},
|
|
2577
|
+
clientName(node) {
|
|
2578
|
+
return `${this.name(node.operationId)}Infinite`;
|
|
2579
|
+
}
|
|
2603
2580
|
},
|
|
2604
|
-
|
|
2605
|
-
|
|
2581
|
+
suspenseInfiniteQuery: {
|
|
2582
|
+
name(node) {
|
|
2583
|
+
return `use${capitalize(this.name(node.operationId))}SuspenseInfinite`;
|
|
2584
|
+
},
|
|
2585
|
+
optionsName(node) {
|
|
2586
|
+
return `${this.name(node.operationId)}SuspenseInfiniteQueryOptions`;
|
|
2587
|
+
},
|
|
2588
|
+
keyName(node) {
|
|
2589
|
+
return `${this.name(node.operationId)}SuspenseInfiniteQueryKey`;
|
|
2590
|
+
},
|
|
2591
|
+
keyTypeName(node) {
|
|
2592
|
+
return `${capitalize(this.name(node.operationId))}SuspenseInfiniteQueryKey`;
|
|
2593
|
+
},
|
|
2594
|
+
clientName(node) {
|
|
2595
|
+
return `${this.name(node.operationId)}SuspenseInfinite`;
|
|
2596
|
+
}
|
|
2606
2597
|
},
|
|
2607
|
-
|
|
2608
|
-
|
|
2598
|
+
mutation: {
|
|
2599
|
+
name(node) {
|
|
2600
|
+
return `use${capitalize(this.name(node.operationId))}`;
|
|
2601
|
+
},
|
|
2602
|
+
optionsName(node) {
|
|
2603
|
+
return `${this.name(node.operationId)}MutationOptions`;
|
|
2604
|
+
},
|
|
2605
|
+
keyName(node) {
|
|
2606
|
+
return `${this.name(node.operationId)}MutationKey`;
|
|
2607
|
+
},
|
|
2608
|
+
typeName(node) {
|
|
2609
|
+
return capitalize(this.name(node.operationId));
|
|
2610
|
+
}
|
|
2609
2611
|
},
|
|
2610
|
-
|
|
2611
|
-
|
|
2612
|
+
hook: {
|
|
2613
|
+
optionsName() {
|
|
2614
|
+
return "HookOptions";
|
|
2615
|
+
},
|
|
2616
|
+
customOptionsName() {
|
|
2617
|
+
return "getCustomHookOptions";
|
|
2618
|
+
}
|
|
2612
2619
|
}
|
|
2613
|
-
})
|
|
2620
|
+
});
|
|
2614
2621
|
//#endregion
|
|
2615
2622
|
//#region src/plugin.ts
|
|
2616
2623
|
/**
|
|
@@ -2663,10 +2670,7 @@ const pluginReactQuery = definePlugin((options) => {
|
|
|
2663
2670
|
options,
|
|
2664
2671
|
dependencies: [pluginTsName],
|
|
2665
2672
|
hooks: { "kubb:plugin:setup"(ctx) {
|
|
2666
|
-
const resolver = userResolver ?
|
|
2667
|
-
...resolverReactQuery,
|
|
2668
|
-
...userResolver
|
|
2669
|
-
} : resolverReactQuery;
|
|
2673
|
+
const resolver = userResolver ? Resolver.merge(resolverReactQuery, userResolver) : resolverReactQuery;
|
|
2670
2674
|
const resolvedClient = resolveClient({
|
|
2671
2675
|
client,
|
|
2672
2676
|
pluginNames: (ctx.config.plugins ?? []).map((p) => p.name).filter((name) => Boolean(name))
|