@orval/axios 6.19.0 → 6.20.0
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.js +237 -18
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -1,17 +1,173 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __defProp = Object.defineProperty;
|
|
3
|
+
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
|
+
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
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
|
+
var __copyProps = (to, from, except, desc) => {
|
|
11
|
+
if (from && typeof from === "object" || typeof from === "function") {
|
|
12
|
+
for (let key of __getOwnPropNames(from))
|
|
13
|
+
if (!__hasOwnProp.call(to, key) && key !== except)
|
|
14
|
+
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
|
|
15
|
+
}
|
|
16
|
+
return to;
|
|
17
|
+
};
|
|
18
|
+
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
|
+
|
|
20
|
+
// src/index.ts
|
|
21
|
+
var src_exports = {};
|
|
22
|
+
__export(src_exports, {
|
|
23
|
+
builder: () => builder,
|
|
24
|
+
default: () => src_default,
|
|
25
|
+
generateAxios: () => generateAxios,
|
|
26
|
+
generateAxiosFooter: () => generateAxiosFooter,
|
|
27
|
+
generateAxiosFunctions: () => generateAxiosFunctions,
|
|
28
|
+
generateAxiosHeader: () => generateAxiosHeader,
|
|
29
|
+
generateAxiosTitle: () => generateAxiosTitle,
|
|
30
|
+
getAxiosDependencies: () => getAxiosDependencies
|
|
31
|
+
});
|
|
32
|
+
module.exports = __toCommonJS(src_exports);
|
|
33
|
+
var import_core = require("@orval/core");
|
|
34
|
+
var AXIOS_DEPENDENCIES = [
|
|
35
|
+
{
|
|
36
|
+
exports: [
|
|
37
|
+
{
|
|
38
|
+
name: "axios",
|
|
39
|
+
default: true,
|
|
40
|
+
values: true,
|
|
41
|
+
syntheticDefaultImport: true
|
|
42
|
+
},
|
|
43
|
+
{ name: "AxiosRequestConfig" },
|
|
44
|
+
{ name: "AxiosResponse" }
|
|
45
|
+
],
|
|
46
|
+
dependency: "axios"
|
|
47
|
+
}
|
|
48
|
+
];
|
|
49
|
+
var PARAMS_SERIALIZER_DEPENDENCIES = [
|
|
50
|
+
{
|
|
51
|
+
exports: [
|
|
52
|
+
{
|
|
53
|
+
name: "qs",
|
|
54
|
+
default: true,
|
|
55
|
+
values: true,
|
|
56
|
+
syntheticDefaultImport: true
|
|
57
|
+
}
|
|
58
|
+
],
|
|
59
|
+
dependency: "qs"
|
|
60
|
+
}
|
|
61
|
+
];
|
|
62
|
+
var returnTypesToWrite = /* @__PURE__ */ new Map();
|
|
63
|
+
var getAxiosDependencies = (hasGlobalMutator, hasParamsSerializerOptions) => [
|
|
64
|
+
...!hasGlobalMutator ? AXIOS_DEPENDENCIES : [],
|
|
65
|
+
...hasParamsSerializerOptions ? PARAMS_SERIALIZER_DEPENDENCIES : []
|
|
66
|
+
];
|
|
67
|
+
var generateAxiosImplementation = ({
|
|
68
|
+
headers,
|
|
69
|
+
queryParams,
|
|
70
|
+
operationName,
|
|
71
|
+
response,
|
|
72
|
+
mutator,
|
|
73
|
+
body,
|
|
74
|
+
props,
|
|
75
|
+
verb,
|
|
76
|
+
override,
|
|
77
|
+
formData,
|
|
78
|
+
formUrlEncoded,
|
|
79
|
+
paramsSerializer
|
|
80
|
+
}, { route, context }) => {
|
|
81
|
+
var _a, _b;
|
|
82
|
+
const isRequestOptions = (override == null ? void 0 : override.requestOptions) !== false;
|
|
83
|
+
const isFormData = (override == null ? void 0 : override.formData) !== false;
|
|
84
|
+
const isFormUrlEncoded = (override == null ? void 0 : override.formUrlEncoded) !== false;
|
|
85
|
+
const isExactOptionalPropertyTypes = !!((_b = (_a = context.tsconfig) == null ? void 0 : _a.compilerOptions) == null ? void 0 : _b.exactOptionalPropertyTypes);
|
|
86
|
+
const isSyntheticDefaultImportsAllowed = (0, import_core.isSyntheticDefaultImportsAllow)(
|
|
87
|
+
context.tsconfig
|
|
88
|
+
);
|
|
89
|
+
const bodyForm = (0, import_core.generateFormDataAndUrlEncodedFunction)({
|
|
90
|
+
formData,
|
|
91
|
+
formUrlEncoded,
|
|
92
|
+
body,
|
|
93
|
+
isFormData,
|
|
94
|
+
isFormUrlEncoded
|
|
95
|
+
});
|
|
96
|
+
const isBodyVerb = import_core.VERBS_WITH_BODY.includes(verb);
|
|
97
|
+
if (mutator) {
|
|
98
|
+
const mutatorConfig = (0, import_core.generateMutatorConfig)({
|
|
99
|
+
route,
|
|
100
|
+
body,
|
|
101
|
+
headers,
|
|
102
|
+
queryParams,
|
|
103
|
+
response,
|
|
104
|
+
verb,
|
|
105
|
+
isFormData,
|
|
106
|
+
isFormUrlEncoded,
|
|
107
|
+
isBodyVerb,
|
|
108
|
+
hasSignal: false,
|
|
109
|
+
isExactOptionalPropertyTypes
|
|
110
|
+
});
|
|
111
|
+
const requestOptions = isRequestOptions ? (0, import_core.generateMutatorRequestOptions)(
|
|
112
|
+
override == null ? void 0 : override.requestOptions,
|
|
113
|
+
mutator.hasSecondArg
|
|
114
|
+
) : "";
|
|
115
|
+
returnTypesToWrite.set(
|
|
116
|
+
operationName,
|
|
117
|
+
(title) => `export type ${(0, import_core.pascal)(
|
|
118
|
+
operationName
|
|
119
|
+
)}Result = NonNullable<Awaited<ReturnType<${title ? `ReturnType<typeof ${title}>['${operationName}']` : `typeof ${operationName}`}>>>`
|
|
120
|
+
);
|
|
121
|
+
const propsImplementation = mutator.bodyTypeName && body.definition ? (0, import_core.toObjectString)(props, "implementation").replace(
|
|
122
|
+
new RegExp(`(\\w*):\\s?${body.definition}`),
|
|
123
|
+
`$1: ${mutator.bodyTypeName}<${body.definition}>`
|
|
124
|
+
) : (0, import_core.toObjectString)(props, "implementation");
|
|
125
|
+
return `const ${operationName} = (
|
|
126
|
+
${propsImplementation}
|
|
127
|
+
${isRequestOptions && mutator.hasSecondArg ? `options?: SecondParameter<typeof ${mutator.name}>,` : ""}) => {${bodyForm}
|
|
128
|
+
return ${mutator.name}<${response.definition.success || "unknown"}>(
|
|
129
|
+
${mutatorConfig},
|
|
130
|
+
${requestOptions});
|
|
7
131
|
}
|
|
8
|
-
|
|
9
|
-
${_core.toObjectString.call(void 0, l,"implementation")} ${p?`options?: AxiosRequestConfig
|
|
10
|
-
`:""} ): Promise<TData> => {${y}
|
|
11
|
-
return axios${E?"":".default"}.${r}(${I});
|
|
132
|
+
`;
|
|
12
133
|
}
|
|
13
|
-
|
|
14
|
-
|
|
134
|
+
const options = (0, import_core.generateOptions)({
|
|
135
|
+
route,
|
|
136
|
+
body,
|
|
137
|
+
headers,
|
|
138
|
+
queryParams,
|
|
139
|
+
response,
|
|
140
|
+
verb,
|
|
141
|
+
requestOptions: override == null ? void 0 : override.requestOptions,
|
|
142
|
+
isFormData,
|
|
143
|
+
isFormUrlEncoded,
|
|
144
|
+
paramsSerializer,
|
|
145
|
+
paramsSerializerOptions: override == null ? void 0 : override.paramsSerializerOptions,
|
|
146
|
+
isExactOptionalPropertyTypes,
|
|
147
|
+
hasSignal: false
|
|
148
|
+
});
|
|
149
|
+
returnTypesToWrite.set(
|
|
150
|
+
operationName,
|
|
151
|
+
() => `export type ${(0, import_core.pascal)(operationName)}Result = AxiosResponse<${response.definition.success || "unknown"}>`
|
|
152
|
+
);
|
|
153
|
+
return `const ${operationName} = <TData = AxiosResponse<${response.definition.success || "unknown"}>>(
|
|
154
|
+
${(0, import_core.toObjectString)(props, "implementation")} ${isRequestOptions ? `options?: AxiosRequestConfig
|
|
155
|
+
` : ""} ): Promise<TData> => {${bodyForm}
|
|
156
|
+
return axios${!isSyntheticDefaultImportsAllowed ? ".default" : ""}.${verb}(${options});
|
|
157
|
+
}
|
|
158
|
+
`;
|
|
159
|
+
};
|
|
160
|
+
var generateAxiosTitle = (title) => {
|
|
161
|
+
const sanTitle = (0, import_core.sanitize)(title);
|
|
162
|
+
return `get${(0, import_core.pascal)(sanTitle)}`;
|
|
163
|
+
};
|
|
164
|
+
var generateAxiosHeader = ({
|
|
165
|
+
title,
|
|
166
|
+
isRequestOptions,
|
|
167
|
+
isMutator,
|
|
168
|
+
noFunction
|
|
169
|
+
}) => `
|
|
170
|
+
${isRequestOptions && isMutator ? `// eslint-disable-next-line
|
|
15
171
|
type SecondParameter<T extends (...args: any) => any> = T extends (
|
|
16
172
|
config: any,
|
|
17
173
|
args: infer P,
|
|
@@ -19,13 +175,76 @@ ${s&&n?`// eslint-disable-next-line
|
|
|
19
175
|
? P
|
|
20
176
|
: never;
|
|
21
177
|
|
|
22
|
-
|
|
23
|
-
${
|
|
24
|
-
`
|
|
25
|
-
|
|
178
|
+
` : ""}
|
|
179
|
+
${!noFunction ? `export const ${title} = () => {
|
|
180
|
+
` : ""}`;
|
|
181
|
+
var generateAxiosFooter = ({
|
|
182
|
+
operationNames,
|
|
183
|
+
title,
|
|
184
|
+
noFunction,
|
|
185
|
+
hasMutator,
|
|
186
|
+
hasAwaitedType
|
|
187
|
+
}) => {
|
|
188
|
+
let footer = "";
|
|
189
|
+
if (!noFunction) {
|
|
190
|
+
footer += `return {${operationNames.join(",")}}};
|
|
191
|
+
`;
|
|
192
|
+
}
|
|
193
|
+
if (hasMutator && !hasAwaitedType) {
|
|
194
|
+
footer += `
|
|
26
195
|
type AwaitedInput<T> = PromiseLike<T> | T;
|
|
27
196
|
|
|
28
197
|
type Awaited<O> = O extends AwaitedInput<infer T> ? T : never;
|
|
29
198
|
|
|
30
|
-
|
|
31
|
-
|
|
199
|
+
`;
|
|
200
|
+
}
|
|
201
|
+
operationNames.forEach((operationName) => {
|
|
202
|
+
if (returnTypesToWrite.has(operationName)) {
|
|
203
|
+
const func = returnTypesToWrite.get(operationName);
|
|
204
|
+
footer += func(!noFunction ? title : void 0) + "\n";
|
|
205
|
+
}
|
|
206
|
+
});
|
|
207
|
+
return footer;
|
|
208
|
+
};
|
|
209
|
+
var generateAxios = (verbOptions, options) => {
|
|
210
|
+
const imports = (0, import_core.generateVerbImports)(verbOptions);
|
|
211
|
+
const implementation = generateAxiosImplementation(verbOptions, options);
|
|
212
|
+
return { implementation, imports };
|
|
213
|
+
};
|
|
214
|
+
var generateAxiosFunctions = async (verbOptions, options) => {
|
|
215
|
+
const { implementation, imports } = generateAxios(verbOptions, options);
|
|
216
|
+
return {
|
|
217
|
+
implementation: "export " + implementation,
|
|
218
|
+
imports
|
|
219
|
+
};
|
|
220
|
+
};
|
|
221
|
+
var axiosClientBuilder = {
|
|
222
|
+
client: generateAxios,
|
|
223
|
+
header: generateAxiosHeader,
|
|
224
|
+
dependencies: getAxiosDependencies,
|
|
225
|
+
footer: generateAxiosFooter,
|
|
226
|
+
title: generateAxiosTitle
|
|
227
|
+
};
|
|
228
|
+
var axiosFunctionsClientBuilder = {
|
|
229
|
+
client: generateAxiosFunctions,
|
|
230
|
+
header: (options) => generateAxiosHeader({ ...options, noFunction: true }),
|
|
231
|
+
dependencies: getAxiosDependencies,
|
|
232
|
+
footer: (options) => generateAxiosFooter({ ...options, noFunction: true }),
|
|
233
|
+
title: generateAxiosTitle
|
|
234
|
+
};
|
|
235
|
+
var builders = {
|
|
236
|
+
axios: axiosClientBuilder,
|
|
237
|
+
"axios-functions": axiosFunctionsClientBuilder
|
|
238
|
+
};
|
|
239
|
+
var builder = ({ type = "axios-functions" } = {}) => () => builders[type];
|
|
240
|
+
var src_default = builder;
|
|
241
|
+
// Annotate the CommonJS export names for ESM import in node:
|
|
242
|
+
0 && (module.exports = {
|
|
243
|
+
builder,
|
|
244
|
+
generateAxios,
|
|
245
|
+
generateAxiosFooter,
|
|
246
|
+
generateAxiosFunctions,
|
|
247
|
+
generateAxiosHeader,
|
|
248
|
+
generateAxiosTitle,
|
|
249
|
+
getAxiosDependencies
|
|
250
|
+
});
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@orval/axios",
|
|
3
|
-
"version": "6.
|
|
3
|
+
"version": "6.20.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"main": "./dist/index.js",
|
|
6
6
|
"types": "./dist/index.d.ts",
|
|
@@ -8,11 +8,11 @@
|
|
|
8
8
|
"dist"
|
|
9
9
|
],
|
|
10
10
|
"scripts": {
|
|
11
|
-
"build": "tsup ./src/index.ts --target node12 --
|
|
11
|
+
"build": "tsup ./src/index.ts --target node12 --clean --dts",
|
|
12
12
|
"dev": "tsup ./src/index.ts --target node12 --clean --watch src",
|
|
13
13
|
"lint": "eslint src/**/*.ts"
|
|
14
14
|
},
|
|
15
15
|
"dependencies": {
|
|
16
|
-
"@orval/core": "6.
|
|
16
|
+
"@orval/core": "6.20.0"
|
|
17
17
|
}
|
|
18
18
|
}
|