@orval/swr 7.11.2 → 7.12.1
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.d.ts +4 -2
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +361 -575
- package/dist/index.js.map +1 -1
- package/package.json +19 -8
package/dist/index.js
CHANGED
|
@@ -1,333 +1,225 @@
|
|
|
1
|
-
|
|
1
|
+
Object.defineProperty(exports, '__esModule', { value: true });
|
|
2
|
+
//#region rolldown:runtime
|
|
3
|
+
var __create = Object.create;
|
|
2
4
|
var __defProp = Object.defineProperty;
|
|
3
5
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
6
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
7
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
8
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
|
-
var __export = (target, all) => {
|
|
7
|
-
for (var name in all)
|
|
8
|
-
__defProp(target, name, { get: all[name], enumerable: true });
|
|
9
|
-
};
|
|
10
9
|
var __copyProps = (to, from, except, desc) => {
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
10
|
+
if (from && typeof from === "object" || typeof from === "function") for (var keys = __getOwnPropNames(from), i = 0, n = keys.length, key; i < n; i++) {
|
|
11
|
+
key = keys[i];
|
|
12
|
+
if (!__hasOwnProp.call(to, key) && key !== except) __defProp(to, key, {
|
|
13
|
+
get: ((k) => from[k]).bind(null, key),
|
|
14
|
+
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable
|
|
15
|
+
});
|
|
16
|
+
}
|
|
17
|
+
return to;
|
|
17
18
|
};
|
|
18
|
-
var
|
|
19
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", {
|
|
20
|
+
value: mod,
|
|
21
|
+
enumerable: true
|
|
22
|
+
}) : target, mod));
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
generateSwr: () => generateSwr,
|
|
26
|
-
generateSwrHeader: () => generateSwrHeader,
|
|
27
|
-
getSwrDependencies: () => getSwrDependencies
|
|
28
|
-
});
|
|
29
|
-
module.exports = __toCommonJS(index_exports);
|
|
30
|
-
var import_core2 = require("@orval/core");
|
|
24
|
+
//#endregion
|
|
25
|
+
let __orval_core = require("@orval/core");
|
|
26
|
+
__orval_core = __toESM(__orval_core);
|
|
27
|
+
let __orval_fetch = require("@orval/fetch");
|
|
28
|
+
__orval_fetch = __toESM(__orval_fetch);
|
|
31
29
|
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
}
|
|
50
|
-
];
|
|
51
|
-
var generateSwrRequestFunction = (verbOptions, options) => {
|
|
52
|
-
if (options.context.output.httpClient === import_core.OutputHttpClient.AXIOS) {
|
|
53
|
-
return generateAxiosRequestFunction(verbOptions, options);
|
|
54
|
-
} else {
|
|
55
|
-
return (0, import_fetch.generateRequestFunction)(verbOptions, options);
|
|
56
|
-
}
|
|
30
|
+
//#region src/client.ts
|
|
31
|
+
const AXIOS_DEPENDENCIES = [{
|
|
32
|
+
exports: [
|
|
33
|
+
{
|
|
34
|
+
name: "axios",
|
|
35
|
+
default: true,
|
|
36
|
+
values: true,
|
|
37
|
+
syntheticDefaultImport: true
|
|
38
|
+
},
|
|
39
|
+
{ name: "AxiosRequestConfig" },
|
|
40
|
+
{ name: "AxiosResponse" },
|
|
41
|
+
{ name: "AxiosError" }
|
|
42
|
+
],
|
|
43
|
+
dependency: "axios"
|
|
44
|
+
}];
|
|
45
|
+
const generateSwrRequestFunction = (verbOptions, options) => {
|
|
46
|
+
return options.context.output.httpClient === __orval_core.OutputHttpClient.AXIOS ? generateAxiosRequestFunction(verbOptions, options) : (0, __orval_fetch.generateRequestFunction)(verbOptions, options);
|
|
57
47
|
};
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
if (mutator) {
|
|
88
|
-
const mutatorConfig = (0, import_core.generateMutatorConfig)({
|
|
89
|
-
route,
|
|
90
|
-
body,
|
|
91
|
-
headers,
|
|
92
|
-
queryParams,
|
|
93
|
-
response,
|
|
94
|
-
verb,
|
|
95
|
-
isFormData,
|
|
96
|
-
isFormUrlEncoded,
|
|
97
|
-
hasSignal: false,
|
|
98
|
-
isExactOptionalPropertyTypes
|
|
99
|
-
});
|
|
100
|
-
const propsImplementation = (mutator == null ? void 0 : mutator.bodyTypeName) && body.definition ? (0, import_core.toObjectString)(props, "implementation").replace(
|
|
101
|
-
new RegExp(`(\\w*):\\s?${body.definition}`),
|
|
102
|
-
`$1: ${mutator.bodyTypeName}<${body.definition}>`
|
|
103
|
-
) : (0, import_core.toObjectString)(props, "implementation");
|
|
104
|
-
const requestOptions = isRequestOptions ? (0, import_core.generateMutatorRequestOptions)(
|
|
105
|
-
override == null ? void 0 : override.requestOptions,
|
|
106
|
-
mutator.hasSecondArg
|
|
107
|
-
) : "";
|
|
108
|
-
const requestImplementation = `export const ${operationName} = (
|
|
109
|
-
${propsImplementation}
|
|
110
|
-
${isRequestOptions && mutator.hasSecondArg ? `options${context.output.optionsParamRequired ? "" : "?"}: SecondParameter<typeof ${mutator.name}>` : ""}) => {${bodyForm}
|
|
48
|
+
const generateAxiosRequestFunction = ({ headers, queryParams, operationName, response, mutator, body, props, verb, formData, formUrlEncoded, override, paramsSerializer }, { route, context }) => {
|
|
49
|
+
const isRequestOptions = override?.requestOptions !== false;
|
|
50
|
+
const isFormData = !override?.formData.disabled;
|
|
51
|
+
const isFormUrlEncoded = override?.formUrlEncoded !== false;
|
|
52
|
+
const isExactOptionalPropertyTypes = !!context.output.tsconfig?.compilerOptions?.exactOptionalPropertyTypes;
|
|
53
|
+
const isSyntheticDefaultImportsAllowed = (0, __orval_core.isSyntheticDefaultImportsAllow)(context.output.tsconfig);
|
|
54
|
+
const bodyForm = (0, __orval_core.generateFormDataAndUrlEncodedFunction)({
|
|
55
|
+
formData,
|
|
56
|
+
formUrlEncoded,
|
|
57
|
+
body,
|
|
58
|
+
isFormData,
|
|
59
|
+
isFormUrlEncoded
|
|
60
|
+
});
|
|
61
|
+
if (mutator) {
|
|
62
|
+
const mutatorConfig = (0, __orval_core.generateMutatorConfig)({
|
|
63
|
+
route,
|
|
64
|
+
body,
|
|
65
|
+
headers,
|
|
66
|
+
queryParams,
|
|
67
|
+
response,
|
|
68
|
+
verb,
|
|
69
|
+
isFormData,
|
|
70
|
+
isFormUrlEncoded,
|
|
71
|
+
hasSignal: false,
|
|
72
|
+
isExactOptionalPropertyTypes
|
|
73
|
+
});
|
|
74
|
+
const propsImplementation = mutator?.bodyTypeName && body.definition ? (0, __orval_core.toObjectString)(props, "implementation").replace(/* @__PURE__ */ new RegExp(`(\\w*):\\s?${body.definition}`), `$1: ${mutator.bodyTypeName}<${body.definition}>`) : (0, __orval_core.toObjectString)(props, "implementation");
|
|
75
|
+
const requestOptions = isRequestOptions ? (0, __orval_core.generateMutatorRequestOptions)(override?.requestOptions, mutator.hasSecondArg) : "";
|
|
76
|
+
return `export const ${operationName} = (\n ${propsImplementation}\n ${isRequestOptions && mutator.hasSecondArg ? `options${context.output.optionsParamRequired ? "" : "?"}: SecondParameter<typeof ${mutator.name}>` : ""}) => {${bodyForm}
|
|
111
77
|
return ${mutator.name}<${response.definition.success || "unknown"}>(
|
|
112
78
|
${mutatorConfig},
|
|
113
79
|
${requestOptions});
|
|
114
80
|
}
|
|
115
81
|
`;
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
${(0, import_core.toObjectString)(
|
|
135
|
-
props,
|
|
136
|
-
"implementation"
|
|
137
|
-
)} ${isRequestOptions ? `options?: AxiosRequestConfig
|
|
138
|
-
` : ""} ): Promise<AxiosResponse<${response.definition.success || "unknown"}>> => {${bodyForm}
|
|
139
|
-
return axios${!isSyntheticDefaultImportsAllowed ? ".default" : ""}.${verb}(${options});
|
|
82
|
+
}
|
|
83
|
+
const options = (0, __orval_core.generateOptions)({
|
|
84
|
+
route,
|
|
85
|
+
body,
|
|
86
|
+
headers,
|
|
87
|
+
queryParams,
|
|
88
|
+
response,
|
|
89
|
+
verb,
|
|
90
|
+
requestOptions: override?.requestOptions,
|
|
91
|
+
isFormData,
|
|
92
|
+
isFormUrlEncoded,
|
|
93
|
+
paramsSerializer,
|
|
94
|
+
paramsSerializerOptions: override?.paramsSerializerOptions,
|
|
95
|
+
isExactOptionalPropertyTypes,
|
|
96
|
+
hasSignal: false
|
|
97
|
+
});
|
|
98
|
+
return `export const ${operationName} = (\n ${(0, __orval_core.toObjectString)(props, "implementation")} ${isRequestOptions ? `options?: AxiosRequestConfig\n` : ""} ): Promise<AxiosResponse<${response.definition.success || "unknown"}>> => {${bodyForm}
|
|
99
|
+
return axios${isSyntheticDefaultImportsAllowed ? "" : ".default"}.${verb}(${options});
|
|
140
100
|
}
|
|
141
101
|
`;
|
|
142
102
|
};
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
return `request?: SecondParameter<typeof ${mutator.name}>`;
|
|
148
|
-
} else {
|
|
149
|
-
return "";
|
|
150
|
-
}
|
|
103
|
+
const getSwrRequestOptions = (httpClient, mutator) => {
|
|
104
|
+
if (!mutator) return httpClient === __orval_core.OutputHttpClient.AXIOS ? "axios?: AxiosRequestConfig" : "fetch?: RequestInit";
|
|
105
|
+
else if (mutator?.hasSecondArg) return `request?: SecondParameter<typeof ${mutator.name}>`;
|
|
106
|
+
else return "";
|
|
151
107
|
};
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
} else {
|
|
156
|
-
const errorType = httpClient === import_core.OutputHttpClient.AXIOS ? "AxiosError" : "Promise";
|
|
157
|
-
return `${errorType}<${response.definition.errors || "unknown"}>`;
|
|
158
|
-
}
|
|
108
|
+
const getSwrErrorType = (response, httpClient, mutator) => {
|
|
109
|
+
if (mutator) return mutator.hasErrorType ? `ErrorType<${response.definition.errors || "unknown"}>` : response.definition.errors || "unknown";
|
|
110
|
+
else return `${httpClient === __orval_core.OutputHttpClient.AXIOS ? "AxiosError" : "Promise"}<${response.definition.errors || "unknown"}>`;
|
|
159
111
|
};
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
return "request: requestOptions";
|
|
165
|
-
} else {
|
|
166
|
-
return "";
|
|
167
|
-
}
|
|
112
|
+
const getSwrRequestSecondArg = (httpClient, mutator) => {
|
|
113
|
+
if (!mutator) return httpClient === __orval_core.OutputHttpClient.AXIOS ? "axios: axiosOptions" : "fetch: fetchOptions";
|
|
114
|
+
else if (mutator?.hasSecondArg) return "request: requestOptions";
|
|
115
|
+
else return "";
|
|
168
116
|
};
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
return "requestOptions";
|
|
174
|
-
} else {
|
|
175
|
-
return "";
|
|
176
|
-
}
|
|
117
|
+
const getHttpRequestSecondArg = (httpClient, mutator) => {
|
|
118
|
+
if (!mutator) return httpClient === __orval_core.OutputHttpClient.AXIOS ? `axiosOptions` : `fetchOptions`;
|
|
119
|
+
else if (mutator?.hasSecondArg) return "requestOptions";
|
|
120
|
+
else return "";
|
|
177
121
|
};
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
return `SecondParameter<typeof ${mutator.name}>`;
|
|
183
|
-
} else {
|
|
184
|
-
return "";
|
|
185
|
-
}
|
|
122
|
+
const getSwrMutationFetcherOptionType = (httpClient, mutator) => {
|
|
123
|
+
if (!mutator) return httpClient === __orval_core.OutputHttpClient.AXIOS ? "AxiosRequestConfig" : "RequestInit";
|
|
124
|
+
else if (mutator.hasSecondArg) return `SecondParameter<typeof ${mutator.name}>`;
|
|
125
|
+
else return "";
|
|
186
126
|
};
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
response.definition.success,
|
|
192
|
-
operationName
|
|
193
|
-
);
|
|
194
|
-
return `Promise<${responseType}>`;
|
|
195
|
-
} else if (mutator) {
|
|
196
|
-
return `Promise<${response.definition.success || "unknown"}>`;
|
|
197
|
-
} else {
|
|
198
|
-
return `Promise<AxiosResponse<${response.definition.success || "unknown"}>>`;
|
|
199
|
-
}
|
|
127
|
+
const getSwrMutationFetcherType = (response, httpClient, includeHttpResponseReturnType, operationName, mutator) => {
|
|
128
|
+
if (httpClient === __orval_core.OutputHttpClient.FETCH) return `Promise<${(0, __orval_fetch.fetchResponseTypeName)(includeHttpResponseReturnType, response.definition.success, operationName)}>`;
|
|
129
|
+
else if (mutator) return `Promise<${response.definition.success || "unknown"}>`;
|
|
130
|
+
else return `Promise<AxiosResponse<${response.definition.success || "unknown"}>>`;
|
|
200
131
|
};
|
|
201
|
-
|
|
202
|
-
|
|
132
|
+
const getSwrHeader = (params) => {
|
|
133
|
+
return params.output.httpClient === __orval_core.OutputHttpClient.FETCH ? (0, __orval_fetch.generateFetchHeader)(params) : "";
|
|
203
134
|
};
|
|
204
135
|
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
254
|
-
|
|
255
|
-
|
|
136
|
+
//#endregion
|
|
137
|
+
//#region src/index.ts
|
|
138
|
+
const PARAMS_SERIALIZER_DEPENDENCIES = [{
|
|
139
|
+
exports: [{
|
|
140
|
+
name: "qs",
|
|
141
|
+
default: true,
|
|
142
|
+
values: true,
|
|
143
|
+
syntheticDefaultImport: true
|
|
144
|
+
}],
|
|
145
|
+
dependency: "qs"
|
|
146
|
+
}];
|
|
147
|
+
const SWR_DEPENDENCIES = [{
|
|
148
|
+
exports: [
|
|
149
|
+
{
|
|
150
|
+
name: "useSwr",
|
|
151
|
+
values: true,
|
|
152
|
+
default: true
|
|
153
|
+
},
|
|
154
|
+
{ name: "SWRConfiguration" },
|
|
155
|
+
{ name: "Key" },
|
|
156
|
+
{ name: "Arguments" }
|
|
157
|
+
],
|
|
158
|
+
dependency: "swr"
|
|
159
|
+
}];
|
|
160
|
+
const SWR_INFINITE_DEPENDENCIES = [{
|
|
161
|
+
exports: [
|
|
162
|
+
{
|
|
163
|
+
name: "useSWRInfinite",
|
|
164
|
+
values: true,
|
|
165
|
+
default: true
|
|
166
|
+
},
|
|
167
|
+
{ name: "SWRInfiniteConfiguration" },
|
|
168
|
+
{ name: "SWRInfiniteKeyLoader" }
|
|
169
|
+
],
|
|
170
|
+
dependency: "swr/infinite"
|
|
171
|
+
}];
|
|
172
|
+
const SWR_MUTATION_DEPENDENCIES = [{
|
|
173
|
+
exports: [
|
|
174
|
+
{
|
|
175
|
+
name: "useSWRMutation",
|
|
176
|
+
values: true,
|
|
177
|
+
default: true
|
|
178
|
+
},
|
|
179
|
+
{ name: "SWRMutationConfiguration" },
|
|
180
|
+
{ name: "SWRMutationKey" }
|
|
181
|
+
],
|
|
182
|
+
dependency: "swr/mutation"
|
|
183
|
+
}];
|
|
184
|
+
const getSwrDependencies = (hasGlobalMutator, hasParamsSerializerOptions, _packageJson, httpClient) => [
|
|
185
|
+
...!hasGlobalMutator && httpClient === __orval_core.OutputHttpClient.AXIOS ? AXIOS_DEPENDENCIES : [],
|
|
186
|
+
...hasParamsSerializerOptions ? PARAMS_SERIALIZER_DEPENDENCIES : [],
|
|
187
|
+
...SWR_DEPENDENCIES,
|
|
188
|
+
...SWR_INFINITE_DEPENDENCIES,
|
|
189
|
+
...SWR_MUTATION_DEPENDENCIES
|
|
256
190
|
];
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
isInfinite,
|
|
262
|
-
httpClient
|
|
263
|
-
}) => {
|
|
264
|
-
const configType = isInfinite ? "SWRInfiniteConfiguration" : "SWRConfiguration";
|
|
265
|
-
const optionsType = isInfinite ? "{ swrKeyLoader?: SWRInfiniteKeyLoader, enabled?: boolean }" : "{ swrKey?: Key, enabled?: boolean }";
|
|
266
|
-
const definition = `${configType}<Awaited<ReturnType<typeof ${operationName}>>, TError> & ${optionsType}`;
|
|
267
|
-
if (!isRequestOptions) {
|
|
268
|
-
return `swrOptions?: ${definition}`;
|
|
269
|
-
}
|
|
270
|
-
return `options?: { swr?:${definition}, ${getSwrRequestOptions(httpClient, mutator)} }
|
|
271
|
-
`;
|
|
191
|
+
const generateSwrArguments = ({ operationName, mutator, isRequestOptions, isInfinite, httpClient }) => {
|
|
192
|
+
const definition = `${isInfinite ? "SWRInfiniteConfiguration" : "SWRConfiguration"}<Awaited<ReturnType<typeof ${operationName}>>, TError> & ${isInfinite ? "{ swrKeyLoader?: SWRInfiniteKeyLoader, enabled?: boolean }" : "{ swrKey?: Key, enabled?: boolean }"}`;
|
|
193
|
+
if (!isRequestOptions) return `swrOptions?: ${definition}`;
|
|
194
|
+
return `options?: { swr?:${definition}, ${getSwrRequestOptions(httpClient, mutator)} }\n`;
|
|
272
195
|
};
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
swrBodyType,
|
|
278
|
-
httpClient
|
|
279
|
-
}) => {
|
|
280
|
-
const definition = `SWRMutationConfiguration<Awaited<ReturnType<typeof ${operationName}>>, TError, Key, ${swrBodyType}, Awaited<ReturnType<typeof ${operationName}>>> & { swrKey?: string }`;
|
|
281
|
-
if (!isRequestOptions) {
|
|
282
|
-
return `swrOptions?: ${definition}`;
|
|
283
|
-
}
|
|
284
|
-
return `options?: { swr?:${definition}, ${getSwrRequestOptions(httpClient, mutator)}}
|
|
285
|
-
`;
|
|
196
|
+
const generateSwrMutationArguments = ({ operationName, isRequestOptions, mutator, swrBodyType, httpClient }) => {
|
|
197
|
+
const definition = `SWRMutationConfiguration<Awaited<ReturnType<typeof ${operationName}>>, TError, Key, ${swrBodyType}, Awaited<ReturnType<typeof ${operationName}>>> & { swrKey?: string }`;
|
|
198
|
+
if (!isRequestOptions) return `swrOptions?: ${definition}`;
|
|
199
|
+
return `options?: { swr?:${definition}, ${getSwrRequestOptions(httpClient, mutator)}}\n`;
|
|
286
200
|
};
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
|
|
291
|
-
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
httpClient
|
|
301
|
-
}) => {
|
|
302
|
-
var _a, _b;
|
|
303
|
-
const swrProps = (0, import_core2.toObjectString)(props, "implementation");
|
|
304
|
-
const hasParamReservedWord = props.some(
|
|
305
|
-
(prop) => prop.name === "query"
|
|
306
|
-
);
|
|
307
|
-
const queryResultVarName = hasParamReservedWord ? "_query" : "query";
|
|
308
|
-
const httpFunctionProps = swrProperties;
|
|
309
|
-
const enabledImplementation = `const isEnabled = swrOptions?.enabled !== false${params.length ? ` && !!(${params.map(({ name }) => name).join(" && ")})` : ""}`;
|
|
310
|
-
const swrKeyImplementation = `const swrKey = swrOptions?.swrKey ?? (() => isEnabled ? ${swrKeyFnName}(${swrKeyProperties}) : null);`;
|
|
311
|
-
const swrKeyLoaderImplementation = `const swrKeyLoader = swrOptions?.swrKeyLoader ?? (() => isEnabled ? ${swrKeyLoaderFnName}(${swrKeyProperties}) : null);`;
|
|
312
|
-
const errorType = getSwrErrorType(response, httpClient, mutator);
|
|
313
|
-
const swrRequestSecondArg = getSwrRequestSecondArg(httpClient, mutator);
|
|
314
|
-
const httpRequestSecondArg = getHttpRequestSecondArg(httpClient, mutator);
|
|
315
|
-
const useSWRInfiniteImplementation = swrOptions.useInfinite ? `
|
|
316
|
-
export type ${(0, import_core2.pascal)(
|
|
317
|
-
operationName
|
|
318
|
-
)}InfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof ${operationName}>>>
|
|
319
|
-
export type ${(0, import_core2.pascal)(operationName)}InfiniteError = ${errorType}
|
|
201
|
+
const generateSwrImplementation = ({ operationName, swrKeyFnName, swrKeyLoaderFnName, swrProperties, swrKeyProperties, params, mutator, isRequestOptions, response, swrOptions, props, doc, httpClient }) => {
|
|
202
|
+
const swrProps = (0, __orval_core.toObjectString)(props, "implementation");
|
|
203
|
+
const queryResultVarName = props.some((prop) => prop.name === "query") ? "_query" : "query";
|
|
204
|
+
const httpFunctionProps = swrProperties;
|
|
205
|
+
const enabledImplementation = `const isEnabled = swrOptions?.enabled !== false${params.length ? ` && !!(${params.map(({ name }) => name).join(" && ")})` : ""}`;
|
|
206
|
+
const swrKeyImplementation = `const swrKey = swrOptions?.swrKey ?? (() => isEnabled ? ${swrKeyFnName}(${swrKeyProperties}) : null);`;
|
|
207
|
+
const swrKeyLoaderImplementation = `const swrKeyLoader = swrOptions?.swrKeyLoader ?? (() => isEnabled ? ${swrKeyLoaderFnName}(${swrKeyProperties}) : null);`;
|
|
208
|
+
const errorType = getSwrErrorType(response, httpClient, mutator);
|
|
209
|
+
const swrRequestSecondArg = getSwrRequestSecondArg(httpClient, mutator);
|
|
210
|
+
const httpRequestSecondArg = getHttpRequestSecondArg(httpClient, mutator);
|
|
211
|
+
const useSWRInfiniteImplementation = swrOptions.useInfinite ? `
|
|
212
|
+
export type ${(0, __orval_core.pascal)(operationName)}InfiniteQueryResult = NonNullable<Awaited<ReturnType<typeof ${operationName}>>>
|
|
213
|
+
export type ${(0, __orval_core.pascal)(operationName)}InfiniteError = ${errorType}
|
|
320
214
|
|
|
321
|
-
${doc}export const ${(0,
|
|
322
|
-
`use-${operationName}-infinite`
|
|
323
|
-
)} = <TError = ${errorType}>(
|
|
215
|
+
${doc}export const ${(0, __orval_core.camel)(`use-${operationName}-infinite`)} = <TError = ${errorType}>(
|
|
324
216
|
${swrProps} ${generateSwrArguments({
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
217
|
+
operationName,
|
|
218
|
+
mutator,
|
|
219
|
+
isRequestOptions,
|
|
220
|
+
isInfinite: true,
|
|
221
|
+
httpClient
|
|
222
|
+
})}) => {
|
|
331
223
|
${isRequestOptions ? `const {swr: swrOptions${swrRequestSecondArg ? `, ${swrRequestSecondArg}` : ""}} = options ?? {}` : ""}
|
|
332
224
|
|
|
333
225
|
${enabledImplementation}
|
|
@@ -335,7 +227,7 @@ ${doc}export const ${(0, import_core2.camel)(
|
|
|
335
227
|
const swrFn = () => ${operationName}(${httpFunctionProps}${httpFunctionProps && httpRequestSecondArg ? ", " : ""}${httpRequestSecondArg})
|
|
336
228
|
|
|
337
229
|
const ${queryResultVarName} = useSWRInfinite<Awaited<ReturnType<typeof swrFn>>, TError>(swrKeyLoader, swrFn, ${swrOptions.swrInfiniteOptions ? `{
|
|
338
|
-
${(
|
|
230
|
+
${(0, __orval_core.stringify)(swrOptions.swrInfiniteOptions)?.slice(1, -1)}
|
|
339
231
|
...swrOptions
|
|
340
232
|
}` : "swrOptions"})
|
|
341
233
|
|
|
@@ -343,22 +235,19 @@ ${doc}export const ${(0, import_core2.camel)(
|
|
|
343
235
|
swrKeyLoader,
|
|
344
236
|
...${queryResultVarName}
|
|
345
237
|
}
|
|
346
|
-
}
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
export type ${(0,
|
|
350
|
-
operationName
|
|
351
|
-
)}QueryResult = NonNullable<Awaited<ReturnType<typeof ${operationName}>>>
|
|
352
|
-
export type ${(0, import_core2.pascal)(operationName)}QueryError = ${errorType}
|
|
238
|
+
}\n` : "";
|
|
239
|
+
const useSwrImplementation = `
|
|
240
|
+
export type ${(0, __orval_core.pascal)(operationName)}QueryResult = NonNullable<Awaited<ReturnType<typeof ${operationName}>>>
|
|
241
|
+
export type ${(0, __orval_core.pascal)(operationName)}QueryError = ${errorType}
|
|
353
242
|
|
|
354
|
-
${doc}export const ${(0,
|
|
243
|
+
${doc}export const ${(0, __orval_core.camel)(`use-${operationName}`)} = <TError = ${errorType}>(
|
|
355
244
|
${swrProps} ${generateSwrArguments({
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
245
|
+
operationName,
|
|
246
|
+
mutator,
|
|
247
|
+
isRequestOptions,
|
|
248
|
+
isInfinite: false,
|
|
249
|
+
httpClient
|
|
250
|
+
})}) => {
|
|
362
251
|
${isRequestOptions ? `const {swr: swrOptions${swrRequestSecondArg ? `, ${swrRequestSecondArg}` : ""}} = options ?? {}` : ""}
|
|
363
252
|
|
|
364
253
|
${enabledImplementation}
|
|
@@ -366,7 +255,7 @@ ${doc}export const ${(0, import_core2.camel)(`use-${operationName}`)} = <TError
|
|
|
366
255
|
const swrFn = () => ${operationName}(${httpFunctionProps}${httpFunctionProps && httpRequestSecondArg ? ", " : ""}${httpRequestSecondArg})
|
|
367
256
|
|
|
368
257
|
const ${queryResultVarName} = useSwr<Awaited<ReturnType<typeof swrFn>>, TError>(swrKey, swrFn, ${swrOptions.swrOptions ? `{
|
|
369
|
-
${(
|
|
258
|
+
${(0, __orval_core.stringify)(swrOptions.swrOptions)?.slice(1, -1)}
|
|
370
259
|
...swrOptions
|
|
371
260
|
}` : "swrOptions"})
|
|
372
261
|
|
|
@@ -374,50 +263,27 @@ ${doc}export const ${(0, import_core2.camel)(`use-${operationName}`)} = <TError
|
|
|
374
263
|
swrKey,
|
|
375
264
|
...${queryResultVarName}
|
|
376
265
|
}
|
|
377
|
-
}
|
|
378
|
-
|
|
379
|
-
return useSWRInfiniteImplementation + useSwrImplementation;
|
|
266
|
+
}\n`;
|
|
267
|
+
return useSWRInfiniteImplementation + useSwrImplementation;
|
|
380
268
|
};
|
|
381
|
-
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
389
|
-
|
|
390
|
-
response,
|
|
391
|
-
mutator,
|
|
392
|
-
swrOptions,
|
|
393
|
-
doc,
|
|
394
|
-
swrBodyType,
|
|
395
|
-
httpClient,
|
|
396
|
-
verb
|
|
397
|
-
}) => {
|
|
398
|
-
var _a;
|
|
399
|
-
const hasParamReservedWord = props.some(
|
|
400
|
-
(prop) => prop.name === "query"
|
|
401
|
-
);
|
|
402
|
-
const queryResultVarName = hasParamReservedWord ? "_query" : "query";
|
|
403
|
-
const swrKeyImplementation = `const swrKey = swrOptions?.swrKey ?? ${swrKeyFnName}(${swrKeyProperties});`;
|
|
404
|
-
const errorType = getSwrErrorType(response, httpClient, mutator);
|
|
405
|
-
const swrRequestSecondArg = getSwrRequestSecondArg(httpClient, mutator);
|
|
406
|
-
const httpRequestSecondArg = getHttpRequestSecondArg(httpClient, mutator);
|
|
407
|
-
const useSwrImplementation = `
|
|
408
|
-
export type ${(0, import_core2.pascal)(
|
|
409
|
-
operationName
|
|
410
|
-
)}MutationResult = NonNullable<Awaited<ReturnType<typeof ${operationName}>>>
|
|
411
|
-
export type ${(0, import_core2.pascal)(operationName)}MutationError = ${errorType}
|
|
269
|
+
const generateSwrMutationImplementation = ({ isRequestOptions, operationName, swrKeyFnName, swrMutationFetcherName, swrKeyProperties, swrMutationFetcherProperties, swrProps, props, response, mutator, swrOptions, doc, swrBodyType, httpClient, verb }) => {
|
|
270
|
+
const queryResultVarName = props.some((prop) => prop.name === "query") ? "_query" : "query";
|
|
271
|
+
const swrKeyImplementation = `const swrKey = swrOptions?.swrKey ?? ${swrKeyFnName}(${swrKeyProperties});`;
|
|
272
|
+
const errorType = getSwrErrorType(response, httpClient, mutator);
|
|
273
|
+
const swrRequestSecondArg = getSwrRequestSecondArg(httpClient, mutator);
|
|
274
|
+
const httpRequestSecondArg = getHttpRequestSecondArg(httpClient, mutator);
|
|
275
|
+
return `
|
|
276
|
+
export type ${(0, __orval_core.pascal)(operationName)}MutationResult = NonNullable<Awaited<ReturnType<typeof ${operationName}>>>
|
|
277
|
+
export type ${(0, __orval_core.pascal)(operationName)}MutationError = ${errorType}
|
|
412
278
|
|
|
413
|
-
${doc}export const ${(0,
|
|
279
|
+
${doc}export const ${(0, __orval_core.camel)(`use-${operationName}${verb === __orval_core.Verbs.GET ? "-mutation" : ""}`)} = <TError = ${errorType}>(
|
|
414
280
|
${swrProps} ${generateSwrMutationArguments({
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
281
|
+
operationName,
|
|
282
|
+
isRequestOptions,
|
|
283
|
+
mutator,
|
|
284
|
+
swrBodyType,
|
|
285
|
+
httpClient
|
|
286
|
+
})}) => {
|
|
421
287
|
|
|
422
288
|
${isRequestOptions ? `const {swr: swrOptions${swrRequestSecondArg ? `, ${swrRequestSecondArg}` : ""}} = options ?? {}` : ""}
|
|
423
289
|
|
|
@@ -425,7 +291,7 @@ ${doc}export const ${(0, import_core2.camel)(`use-${operationName}${verb === imp
|
|
|
425
291
|
const swrFn = ${swrMutationFetcherName}(${swrMutationFetcherProperties}${swrMutationFetcherProperties && httpRequestSecondArg ? ", " : ""}${httpRequestSecondArg});
|
|
426
292
|
|
|
427
293
|
const ${queryResultVarName} = useSWRMutation(swrKey, swrFn, ${swrOptions.swrMutationOptions ? `{
|
|
428
|
-
${(
|
|
294
|
+
${(0, __orval_core.stringify)(swrOptions.swrMutationOptions)?.slice(1, -1)}
|
|
429
295
|
...swrOptions
|
|
430
296
|
}` : "swrOptions"})
|
|
431
297
|
|
|
@@ -433,242 +299,162 @@ ${doc}export const ${(0, import_core2.camel)(`use-${operationName}${verb === imp
|
|
|
433
299
|
swrKey,
|
|
434
300
|
...${queryResultVarName}
|
|
435
301
|
}
|
|
436
|
-
}
|
|
437
|
-
`;
|
|
438
|
-
return useSwrImplementation;
|
|
302
|
+
}\n`;
|
|
439
303
|
};
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
|
|
445
|
-
|
|
446
|
-
|
|
447
|
-
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
},
|
|
453
|
-
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
|
|
462
|
-
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
|
|
471
|
-
).map((param) => {
|
|
472
|
-
if (param.type === import_core2.GetterPropType.NAMED_PATH_PARAMS) {
|
|
473
|
-
return param.destructured;
|
|
474
|
-
} else {
|
|
475
|
-
return param.name;
|
|
476
|
-
}
|
|
477
|
-
}).join(",");
|
|
478
|
-
const swrKeyProperties = props.filter(
|
|
479
|
-
(prop) => prop.type === import_core2.GetterPropType.PARAM || prop.type === import_core2.GetterPropType.NAMED_PATH_PARAMS || prop.type === import_core2.GetterPropType.QUERY_PARAM
|
|
480
|
-
).map((prop) => {
|
|
481
|
-
if (prop.type === import_core2.GetterPropType.NAMED_PATH_PARAMS) {
|
|
482
|
-
return prop.destructured;
|
|
483
|
-
} else {
|
|
484
|
-
return prop.name;
|
|
485
|
-
}
|
|
486
|
-
}).join(",");
|
|
487
|
-
const swrMutationFetcherName = (0, import_core2.camel)(`get-${operationName}-mutation-fetcher`);
|
|
488
|
-
if (verb === import_core2.Verbs.GET) {
|
|
489
|
-
const swrKeyProperties2 = props.filter((prop) => prop.type !== import_core2.GetterPropType.HEADER).map((param) => {
|
|
490
|
-
if (param.type === import_core2.GetterPropType.NAMED_PATH_PARAMS)
|
|
491
|
-
return param.destructured;
|
|
492
|
-
return param.type === import_core2.GetterPropType.BODY ? body.implementation : param.name;
|
|
493
|
-
}).join(",");
|
|
494
|
-
const swrProperties = props.map((param) => {
|
|
495
|
-
if (param.type === import_core2.GetterPropType.NAMED_PATH_PARAMS)
|
|
496
|
-
return param.destructured;
|
|
497
|
-
return param.type === import_core2.GetterPropType.BODY ? body.implementation : param.name;
|
|
498
|
-
}).join(",");
|
|
499
|
-
const queryKeyProps2 = (0, import_core2.toObjectString)(
|
|
500
|
-
props.filter((prop) => prop.type !== import_core2.GetterPropType.HEADER),
|
|
501
|
-
"implementation"
|
|
502
|
-
);
|
|
503
|
-
const swrKeyFnName = (0, import_core2.camel)(`get-${operationName}-key`);
|
|
504
|
-
const swrKeyFn = `
|
|
505
|
-
export const ${swrKeyFnName} = (${queryKeyProps2}) => [\`${route}\`${queryParams ? ", ...(params ? [params]: [])" : ""}] as const;
|
|
304
|
+
const generateSwrHook = ({ queryParams, operationName, body, props, verb, params, override, mutator, response, summary, deprecated }, { route, context }) => {
|
|
305
|
+
const isRequestOptions = override?.requestOptions !== false;
|
|
306
|
+
const httpClient = context.output.httpClient;
|
|
307
|
+
const doc = (0, __orval_core.jsDoc)({
|
|
308
|
+
summary,
|
|
309
|
+
deprecated
|
|
310
|
+
});
|
|
311
|
+
const queryKeyProps = (0, __orval_core.toObjectString)(props.filter((prop) => prop.type === __orval_core.GetterPropType.PARAM || prop.type === __orval_core.GetterPropType.NAMED_PATH_PARAMS || prop.type === __orval_core.GetterPropType.QUERY_PARAM), "implementation");
|
|
312
|
+
const swrProps = (0, __orval_core.toObjectString)(props.filter((prop) => prop.type === __orval_core.GetterPropType.PARAM || prop.type === __orval_core.GetterPropType.QUERY_PARAM || prop.type === __orval_core.GetterPropType.NAMED_PATH_PARAMS), "implementation");
|
|
313
|
+
const swrMutationFetcherProperties = props.filter((prop) => prop.type === __orval_core.GetterPropType.PARAM || prop.type === __orval_core.GetterPropType.QUERY_PARAM || prop.type === __orval_core.GetterPropType.NAMED_PATH_PARAMS).map((param) => {
|
|
314
|
+
if (param.type === __orval_core.GetterPropType.NAMED_PATH_PARAMS) return param.destructured;
|
|
315
|
+
else return param.name;
|
|
316
|
+
}).join(",");
|
|
317
|
+
const swrKeyProperties = props.filter((prop) => prop.type === __orval_core.GetterPropType.PARAM || prop.type === __orval_core.GetterPropType.NAMED_PATH_PARAMS || prop.type === __orval_core.GetterPropType.QUERY_PARAM).map((prop) => {
|
|
318
|
+
if (prop.type === __orval_core.GetterPropType.NAMED_PATH_PARAMS) return prop.destructured;
|
|
319
|
+
else return prop.name;
|
|
320
|
+
}).join(",");
|
|
321
|
+
const swrMutationFetcherName = (0, __orval_core.camel)(`get-${operationName}-mutation-fetcher`);
|
|
322
|
+
if (verb === __orval_core.Verbs.GET) {
|
|
323
|
+
const swrKeyProperties$1 = props.filter((prop) => prop.type !== __orval_core.GetterPropType.HEADER).map((param) => {
|
|
324
|
+
if (param.type === __orval_core.GetterPropType.NAMED_PATH_PARAMS) return param.destructured;
|
|
325
|
+
return param.type === __orval_core.GetterPropType.BODY ? body.implementation : param.name;
|
|
326
|
+
}).join(",");
|
|
327
|
+
const swrProperties = props.map((param) => {
|
|
328
|
+
if (param.type === __orval_core.GetterPropType.NAMED_PATH_PARAMS) return param.destructured;
|
|
329
|
+
return param.type === __orval_core.GetterPropType.BODY ? body.implementation : param.name;
|
|
330
|
+
}).join(",");
|
|
331
|
+
const queryKeyProps$1 = (0, __orval_core.toObjectString)(props.filter((prop) => prop.type !== __orval_core.GetterPropType.HEADER), "implementation");
|
|
332
|
+
const swrKeyFnName = (0, __orval_core.camel)(`get-${operationName}-key`);
|
|
333
|
+
const swrKeyFn = `
|
|
334
|
+
export const ${swrKeyFnName} = (${queryKeyProps$1}) => [\`${route}\`${queryParams ? ", ...(params ? [params]: [])" : ""}] as const;
|
|
506
335
|
`;
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
);
|
|
510
|
-
const swrKeyLoader = override.swr.useInfinite ? `export const ${swrKeyLoaderFnName} = (${queryKeyProps2}) => {
|
|
336
|
+
const swrKeyLoaderFnName = (0, __orval_core.camel)(`get-${operationName}-infinite-key-loader`);
|
|
337
|
+
const swrKeyLoader = override.swr.useInfinite ? `export const ${swrKeyLoaderFnName} = (${queryKeyProps$1}) => {
|
|
511
338
|
return (page: number, previousPageData: Awaited<ReturnType<typeof ${operationName}>>) => {
|
|
512
339
|
if (previousPageData && !previousPageData.data) return null
|
|
513
340
|
|
|
514
341
|
return [\`${route}\`${queryParams ? ", ...(params ? [{...params,page}]: [{page}])" : ""}${body.implementation ? `, ${body.implementation}` : ""}] as const;
|
|
515
342
|
}
|
|
516
|
-
}
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
}).join(", ");
|
|
543
|
-
const swrMutationFetcherType = getSwrMutationFetcherType(
|
|
544
|
-
response,
|
|
545
|
-
httpClient,
|
|
546
|
-
(_a = override.fetch) == null ? void 0 : _a.includeHttpResponseReturnType,
|
|
547
|
-
operationName,
|
|
548
|
-
mutator
|
|
549
|
-
);
|
|
550
|
-
const swrMutationFetcherOptionType = getSwrMutationFetcherOptionType(
|
|
551
|
-
httpClient,
|
|
552
|
-
mutator
|
|
553
|
-
);
|
|
554
|
-
const swrMutationFetcherOptions = isRequestOptions && swrMutationFetcherOptionType ? `options${context.output.optionsParamRequired ? "" : "?"}: ${swrMutationFetcherOptionType}` : "";
|
|
555
|
-
const swrMutationFetcherFn = `
|
|
556
|
-
export const ${swrMutationFetcherName} = (${queryKeyProps2} ${swrMutationFetcherOptions}) => {
|
|
343
|
+
}\n` : "";
|
|
344
|
+
const swrImplementation = generateSwrImplementation({
|
|
345
|
+
operationName,
|
|
346
|
+
swrKeyFnName,
|
|
347
|
+
swrKeyLoaderFnName,
|
|
348
|
+
swrProperties,
|
|
349
|
+
swrKeyProperties: swrKeyProperties$1,
|
|
350
|
+
params,
|
|
351
|
+
props,
|
|
352
|
+
mutator,
|
|
353
|
+
isRequestOptions,
|
|
354
|
+
response,
|
|
355
|
+
swrOptions: override.swr,
|
|
356
|
+
doc,
|
|
357
|
+
httpClient
|
|
358
|
+
});
|
|
359
|
+
if (!override.swr.useSWRMutationForGet) return swrKeyFn + swrKeyLoader + swrImplementation;
|
|
360
|
+
const httpFnPropertiesForGet = props.filter((prop) => prop.type !== __orval_core.GetterPropType.HEADER).map((prop) => {
|
|
361
|
+
if (prop.type === __orval_core.GetterPropType.NAMED_PATH_PARAMS) return prop.destructured;
|
|
362
|
+
else return prop.name;
|
|
363
|
+
}).join(", ");
|
|
364
|
+
const swrMutationFetcherType = getSwrMutationFetcherType(response, httpClient, override.fetch?.includeHttpResponseReturnType, operationName, mutator);
|
|
365
|
+
const swrMutationFetcherOptionType = getSwrMutationFetcherOptionType(httpClient, mutator);
|
|
366
|
+
const swrMutationFetcherOptions = isRequestOptions && swrMutationFetcherOptionType ? `options${context.output.optionsParamRequired ? "" : "?"}: ${swrMutationFetcherOptionType}` : "";
|
|
367
|
+
const swrMutationFetcherFn = `
|
|
368
|
+
export const ${swrMutationFetcherName} = (${queryKeyProps$1} ${swrMutationFetcherOptions}) => {
|
|
557
369
|
return (_: Key, __: { arg?: never }): ${swrMutationFetcherType} => {
|
|
558
370
|
return ${operationName}(${httpFnPropertiesForGet}${swrMutationFetcherOptions.length ? (httpFnPropertiesForGet.length ? ", " : "") + "options" : ""});
|
|
559
371
|
}
|
|
560
372
|
}
|
|
561
373
|
`;
|
|
562
|
-
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
|
|
568
|
-
|
|
569
|
-
|
|
570
|
-
|
|
571
|
-
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
|
|
575
|
-
|
|
576
|
-
|
|
577
|
-
|
|
578
|
-
|
|
579
|
-
|
|
580
|
-
|
|
581
|
-
|
|
582
|
-
|
|
583
|
-
|
|
584
|
-
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
|
|
588
|
-
}
|
|
589
|
-
}).join(", ");
|
|
590
|
-
const swrKeyFnName = (0, import_core2.camel)(`get-${operationName}-mutation-key`);
|
|
591
|
-
const swrMutationKeyFn = `export const ${swrKeyFnName} = (${queryKeyProps}) => [\`${route}\`${queryParams ? ", ...(params ? [params]: [])" : ""}] as const;
|
|
374
|
+
const swrMutationImplementation = generateSwrMutationImplementation({
|
|
375
|
+
operationName,
|
|
376
|
+
swrKeyFnName,
|
|
377
|
+
swrMutationFetcherName,
|
|
378
|
+
swrKeyProperties: swrKeyProperties$1,
|
|
379
|
+
swrMutationFetcherProperties,
|
|
380
|
+
swrProps,
|
|
381
|
+
props,
|
|
382
|
+
isRequestOptions,
|
|
383
|
+
response,
|
|
384
|
+
mutator,
|
|
385
|
+
swrOptions: override.swr,
|
|
386
|
+
doc,
|
|
387
|
+
swrBodyType: "never",
|
|
388
|
+
httpClient,
|
|
389
|
+
verb: __orval_core.Verbs.GET
|
|
390
|
+
});
|
|
391
|
+
return swrKeyFn + swrKeyLoader + swrImplementation + swrMutationFetcherFn + swrMutationImplementation;
|
|
392
|
+
} else {
|
|
393
|
+
const httpFnProperties = props.filter((prop) => prop.type !== __orval_core.GetterPropType.HEADER).map((prop) => {
|
|
394
|
+
if (prop.type === __orval_core.GetterPropType.NAMED_PATH_PARAMS) return prop.destructured;
|
|
395
|
+
else if (prop.type === __orval_core.GetterPropType.BODY) return `arg`;
|
|
396
|
+
else return prop.name;
|
|
397
|
+
}).join(", ");
|
|
398
|
+
const swrKeyFnName = (0, __orval_core.camel)(`get-${operationName}-mutation-key`);
|
|
399
|
+
const swrMutationKeyFn = `export const ${swrKeyFnName} = (${queryKeyProps}) => [\`${route}\`${queryParams ? ", ...(params ? [params]: [])" : ""}] as const;
|
|
592
400
|
`;
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
);
|
|
600
|
-
const swrMutationFetcherOptionType = getSwrMutationFetcherOptionType(
|
|
601
|
-
httpClient,
|
|
602
|
-
mutator
|
|
603
|
-
);
|
|
604
|
-
const swrMutationFetcherOptions = isRequestOptions && swrMutationFetcherOptionType ? `options${context.output.optionsParamRequired ? "" : "?"}: ${swrMutationFetcherOptionType}` : "";
|
|
605
|
-
const swrMutationFetcherArg = props.some(
|
|
606
|
-
(prop) => prop.type === import_core2.GetterPropType.BODY
|
|
607
|
-
) ? "{ arg }" : "__";
|
|
608
|
-
const swrBodyType = (_d = (_c = props.find((prop) => prop.type === import_core2.GetterPropType.BODY)) == null ? void 0 : _c.implementation.split(": ")[1]) != null ? _d : "Arguments";
|
|
609
|
-
const swrMutationFetcherFn = `
|
|
401
|
+
getSwrMutationFetcherType(response, httpClient, override.fetch?.includeHttpResponseReturnType, operationName, mutator);
|
|
402
|
+
const swrMutationFetcherOptionType = getSwrMutationFetcherOptionType(httpClient, mutator);
|
|
403
|
+
const swrMutationFetcherOptions = isRequestOptions && swrMutationFetcherOptionType ? `options${context.output.optionsParamRequired ? "" : "?"}: ${swrMutationFetcherOptionType}` : "";
|
|
404
|
+
const swrMutationFetcherArg = props.some((prop) => prop.type === __orval_core.GetterPropType.BODY) ? "{ arg }" : "__";
|
|
405
|
+
const swrBodyType = props.find((prop) => prop.type === __orval_core.GetterPropType.BODY)?.implementation.split(": ")[1] ?? "Arguments";
|
|
406
|
+
const swrMutationFetcherFn = `
|
|
610
407
|
export const ${swrMutationFetcherName} = (${swrProps} ${swrMutationFetcherOptions}) => {
|
|
611
|
-
return (_: Key, ${swrMutationFetcherArg}: { arg: ${swrBodyType} })
|
|
408
|
+
return (_: Key, ${swrMutationFetcherArg}: { arg: ${swrBodyType} }) => {
|
|
612
409
|
return ${operationName}(${httpFnProperties}${swrMutationFetcherOptions.length ? (httpFnProperties.length ? ", " : "") + "options" : ""});
|
|
613
410
|
}
|
|
614
|
-
}
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
623
|
-
|
|
624
|
-
|
|
625
|
-
|
|
626
|
-
|
|
627
|
-
|
|
628
|
-
|
|
629
|
-
|
|
630
|
-
|
|
631
|
-
|
|
632
|
-
|
|
633
|
-
}
|
|
411
|
+
}\n`;
|
|
412
|
+
const swrImplementation = generateSwrMutationImplementation({
|
|
413
|
+
operationName,
|
|
414
|
+
swrKeyFnName,
|
|
415
|
+
swrMutationFetcherName,
|
|
416
|
+
swrKeyProperties,
|
|
417
|
+
swrMutationFetcherProperties,
|
|
418
|
+
swrProps,
|
|
419
|
+
props,
|
|
420
|
+
isRequestOptions,
|
|
421
|
+
response,
|
|
422
|
+
mutator,
|
|
423
|
+
swrOptions: override.swr,
|
|
424
|
+
doc,
|
|
425
|
+
swrBodyType,
|
|
426
|
+
httpClient: context.output.httpClient
|
|
427
|
+
});
|
|
428
|
+
return swrMutationFetcherFn + swrMutationKeyFn + swrImplementation;
|
|
429
|
+
}
|
|
634
430
|
};
|
|
635
|
-
|
|
636
|
-
${!params.hasAwaitedType ? `type AwaitedInput<T> = PromiseLike<T> | T
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
` : ""}
|
|
641
|
-
${params.isRequestOptions && params.isMutator ? `type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];
|
|
642
|
-
|
|
643
|
-
` : ""}
|
|
431
|
+
const generateSwrHeader = (params) => `
|
|
432
|
+
${!params.hasAwaitedType ? `type AwaitedInput<T> = PromiseLike<T> | T;\n
|
|
433
|
+
type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;\n\n` : ""}
|
|
434
|
+
${params.isRequestOptions && params.isMutator ? `type SecondParameter<T extends (...args: never) => unknown> = Parameters<T>[1];\n\n` : ""}
|
|
644
435
|
${getSwrHeader(params)}
|
|
645
436
|
`;
|
|
646
|
-
|
|
647
|
-
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
|
|
653
|
-
|
|
654
|
-
implementation: `${functionImplementation}
|
|
655
|
-
|
|
656
|
-
${hookImplementation}`,
|
|
657
|
-
imports
|
|
658
|
-
};
|
|
437
|
+
const generateSwr = (verbOptions, options) => {
|
|
438
|
+
const imports = (0, __orval_core.generateVerbImports)(verbOptions);
|
|
439
|
+
const functionImplementation = generateSwrRequestFunction(verbOptions, options);
|
|
440
|
+
const hookImplementation = generateSwrHook(verbOptions, options);
|
|
441
|
+
return {
|
|
442
|
+
implementation: `${functionImplementation}\n\n${hookImplementation}`,
|
|
443
|
+
imports
|
|
444
|
+
};
|
|
659
445
|
};
|
|
660
|
-
|
|
661
|
-
|
|
662
|
-
|
|
663
|
-
|
|
446
|
+
const swrClientBuilder = {
|
|
447
|
+
client: generateSwr,
|
|
448
|
+
header: generateSwrHeader,
|
|
449
|
+
dependencies: getSwrDependencies
|
|
664
450
|
};
|
|
665
|
-
|
|
666
|
-
var
|
|
667
|
-
|
|
668
|
-
|
|
669
|
-
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
451
|
+
const builder = () => () => swrClientBuilder;
|
|
452
|
+
var src_default = builder;
|
|
453
|
+
|
|
454
|
+
//#endregion
|
|
455
|
+
exports.builder = builder;
|
|
456
|
+
exports.default = src_default;
|
|
457
|
+
exports.generateSwr = generateSwr;
|
|
458
|
+
exports.generateSwrHeader = generateSwrHeader;
|
|
459
|
+
exports.getSwrDependencies = getSwrDependencies;
|
|
674
460
|
//# sourceMappingURL=index.js.map
|