axios-annotations 2.3.0 → 3.1.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/README.md +774 -741
- package/es/core/builder.d.ts +33 -0
- package/es/core/builder.js +515 -0
- package/es/core/common.d.ts +36 -0
- package/es/core/common.js +148 -0
- package/es/core/config.d.ts +60 -0
- package/es/core/config.js +357 -0
- package/es/core/core-expect.js +3 -0
- package/es/core/expect.d.ts +2 -0
- package/es/core/expect.js +2 -0
- package/es/core/provider.d.ts +6 -0
- package/es/core/provider.js +172 -0
- package/es/core/service.d.ts +5 -0
- package/es/core/service.js +57 -0
- package/es/decorator/path-variables.d.ts +7 -0
- package/es/decorator/path-variables.js +32 -0
- package/es/decorator/request-body.d.ts +7 -0
- package/es/decorator/request-body.js +31 -0
- package/es/decorator/request-config.d.ts +7 -0
- package/es/decorator/request-config.js +25 -0
- package/es/decorator/request-header.d.ts +4 -0
- package/es/decorator/request-header.js +14 -0
- package/es/decorator/request-mapping.d.ts +6 -0
- package/es/decorator/request-mapping.js +56 -0
- package/es/decorator/request-param.d.ts +4 -0
- package/es/decorator/request-param.js +15 -0
- package/es/decorator/request-with.d.ts +3 -0
- package/es/decorator/request-with.js +8 -0
- package/es/index.d.ts +13 -0
- package/es/index.js +14 -0
- package/es/plugins/auth/authorizer.d.ts +24 -0
- package/es/plugins/auth/authorizer.js +268 -0
- package/es/plugins/auth/history.d.ts +15 -0
- package/es/plugins/auth/history.js +94 -0
- package/es/plugins/auth/index.d.ts +16 -0
- package/es/plugins/auth/index.js +358 -0
- package/es/plugins/auth/queue.d.ts +29 -0
- package/es/plugins/auth/queue.js +281 -0
- package/es/plugins/auth/storage.d.ts +6 -0
- package/es/plugins/auth/storage.js +203 -0
- package/lib/core/builder.d.ts +33 -0
- package/lib/core/builder.js +520 -0
- package/lib/core/common.d.ts +34 -4
- package/lib/core/common.js +139 -147
- package/lib/core/config.d.ts +15 -15
- package/lib/core/config.js +44 -14
- package/lib/core/core-expect.js +8 -0
- package/lib/core/expect.d.ts +2 -4
- package/lib/core/expect.js +6 -15
- package/lib/core/provider.d.ts +5 -5
- package/lib/core/provider.js +2 -2
- package/lib/core/service.d.ts +3 -151
- package/lib/core/service.js +43 -544
- package/lib/decorator/path-variables.d.ts +7 -0
- package/lib/decorator/path-variables.js +37 -0
- package/lib/decorator/request-body.d.ts +7 -1
- package/lib/decorator/request-body.js +28 -20
- package/lib/decorator/request-config.d.ts +6 -4
- package/lib/decorator/request-config.js +23 -16
- package/lib/decorator/request-header.d.ts +4 -2
- package/lib/decorator/request-header.js +11 -13
- package/lib/decorator/request-mapping.d.ts +6 -3
- package/lib/decorator/request-mapping.js +46 -43
- package/lib/decorator/request-param.d.ts +4 -1
- package/lib/decorator/request-param.js +12 -19
- package/lib/decorator/request-with.d.ts +3 -1
- package/lib/decorator/request-with.js +6 -13
- package/lib/index.d.ts +4 -11
- package/lib/index.js +19 -68
- package/lib/plugins/auth/authorizer.d.ts +6 -5
- package/lib/plugins/auth/authorizer.js +3 -2
- package/lib/plugins/auth/history.d.ts +5 -4
- package/lib/plugins/auth/history.js +2 -0
- package/lib/plugins/auth/index.d.ts +7 -0
- package/lib/plugins/auth/index.js +11 -3
- package/lib/plugins/auth/queue.d.ts +3 -2
- package/lib/plugins/auth/queue.js +31 -24
- package/lib/plugins/auth/storage.js +2 -2
- package/package.json +42 -7
- package/wechat-mp/core/builder.d.ts +33 -0
- package/wechat-mp/core/builder.js +520 -0
- package/wechat-mp/core/common.d.ts +36 -0
- package/wechat-mp/core/common.js +158 -0
- package/wechat-mp/core/config.d.ts +60 -0
- package/wechat-mp/core/config.js +362 -0
- package/wechat-mp/core/core-expect.js +8 -0
- package/wechat-mp/core/expect.d.ts +2 -0
- package/wechat-mp/core/expect.js +6 -0
- package/wechat-mp/core/provider.d.ts +6 -0
- package/wechat-mp/core/provider.js +178 -0
- package/wechat-mp/core/service.d.ts +5 -0
- package/wechat-mp/core/service.js +61 -0
- package/wechat-mp/decorator/path-variables.d.ts +7 -0
- package/wechat-mp/decorator/path-variables.js +37 -0
- package/wechat-mp/decorator/request-body.d.ts +7 -0
- package/wechat-mp/decorator/request-body.js +36 -0
- package/wechat-mp/decorator/request-config.d.ts +7 -0
- package/wechat-mp/decorator/request-config.js +30 -0
- package/wechat-mp/decorator/request-header.d.ts +4 -0
- package/wechat-mp/decorator/request-header.js +19 -0
- package/wechat-mp/decorator/request-mapping.d.ts +6 -0
- package/wechat-mp/decorator/request-mapping.js +61 -0
- package/wechat-mp/decorator/request-param.d.ts +4 -0
- package/wechat-mp/decorator/request-param.js +20 -0
- package/wechat-mp/decorator/request-with.d.ts +3 -0
- package/wechat-mp/decorator/request-with.js +13 -0
- package/wechat-mp/index.d.ts +13 -0
- package/wechat-mp/index.js +97 -0
- package/wechat-mp/plugins/auth/authorizer.d.ts +24 -0
- package/wechat-mp/plugins/auth/authorizer.js +272 -0
- package/wechat-mp/plugins/auth/history.d.ts +15 -0
- package/wechat-mp/plugins/auth/history.js +98 -0
- package/wechat-mp/plugins/auth/index.d.ts +16 -0
- package/wechat-mp/plugins/auth/index.js +376 -0
- package/wechat-mp/plugins/auth/queue.d.ts +29 -0
- package/wechat-mp/plugins/auth/queue.js +285 -0
- package/wechat-mp/plugins/auth/storage.d.ts +6 -0
- package/wechat-mp/plugins/auth/storage.js +207 -0
- package/index.d.ts +0 -1
- package/index.js +0 -127
- package/lib/core/cancel.d.ts +0 -30
- package/lib/core/cancel.js +0 -56
- package/lib/core/parser.d.ts +0 -19
- package/lib/core/parser.js +0 -79
- package/lib/decorator/abort-source.d.ts +0 -3
- package/lib/decorator/abort-source.js +0 -25
- package/lib/decorator/delete-mapping.d.ts +0 -1
- package/lib/decorator/delete-mapping.js +0 -13
- package/lib/decorator/get-mapping.d.ts +0 -1
- package/lib/decorator/get-mapping.js +0 -13
- package/lib/decorator/ignore-residual-params.d.ts +0 -1
- package/lib/decorator/ignore-residual-params.js +0 -24
- package/lib/decorator/patch-mapping.d.ts +0 -1
- package/lib/decorator/patch-mapping.js +0 -13
- package/lib/decorator/post-mapping.d.ts +0 -1
- package/lib/decorator/post-mapping.js +0 -13
- package/lib/decorator/put-mapping.d.ts +0 -1
- package/lib/decorator/put-mapping.js +0 -13
- package/plugins/auth/index.d.ts +0 -4
- package/plugins/auth/index.js +0 -26
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter =
|
|
2
|
+
var __awaiter = (void 0) && (void 0).__awaiter || function(thisArg, _arguments, P, generator) {
|
|
3
3
|
function adopt(value) {
|
|
4
4
|
return value instanceof P ? value : new P(function(resolve) {
|
|
5
5
|
resolve(value);
|
|
@@ -26,7 +26,7 @@ var __awaiter = this && this.__awaiter || function(thisArg, _arguments, P, gener
|
|
|
26
26
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
|
-
var __generator =
|
|
29
|
+
var __generator = (void 0) && (void 0).__generator || function(thisArg, body) {
|
|
30
30
|
var _ = {
|
|
31
31
|
label: 0,
|
|
32
32
|
sent: function sent() {
|
|
@@ -142,10 +142,10 @@ function AuthorizationPlugin(authorizer, options) {
|
|
|
142
142
|
var unauthorized = false;
|
|
143
143
|
var expiredSession = null;
|
|
144
144
|
var queue = new queue_1["default"](authorizer, config, (options === null || options === void 0 ? void 0 : options.minTryRetryInterval) || 3000, (options === null || options === void 0 ? void 0 : options.maxTryRetryInterval) || 5000, (options === null || options === void 0 ? void 0 : options.retryTimes) || 3);
|
|
145
|
-
new queue_1["default"](authorizer, config, (options === null || options === void 0 ? void 0 : options.minTryRetryInterval) || 3000, (options === null || options === void 0 ? void 0 : options.maxTryRetryInterval) || 5000, (options === null || options === void 0 ? void 0 : options.retryTimes) || 3);
|
|
146
145
|
axios.interceptors.response.use(function(i) {
|
|
147
146
|
if (expiredSession) {
|
|
148
147
|
// Previously requests sent have been rejected, record and release it (will be resending)
|
|
148
|
+
// 会话过期加入过期队列,但未确认 refreshToken 是否失效
|
|
149
149
|
authorizer.sessionHistory.add(expiredSession);
|
|
150
150
|
expiredSession = null;
|
|
151
151
|
}
|
|
@@ -202,6 +202,7 @@ function AuthorizationPlugin(authorizer, options) {
|
|
|
202
202
|
throw e;
|
|
203
203
|
case 5:
|
|
204
204
|
unauthorized = false;
|
|
205
|
+
// 全部 reject 掉, 即抛出原始异常
|
|
205
206
|
queue.clear();
|
|
206
207
|
return [
|
|
207
208
|
7 /*endfinally*/
|
|
@@ -229,6 +230,7 @@ function AuthorizationPlugin(authorizer, options) {
|
|
|
229
230
|
// waiting for next accessToken refresh, on the server side, updates are synchronized.
|
|
230
231
|
// Note:
|
|
231
232
|
// even if the refreshing request send few times, the server side will only return the same token.
|
|
233
|
+
// 翻译:有效期内多次的刷新请求服务端应该保持 accessToken 不变,客户端不需要线程同步
|
|
232
234
|
return [
|
|
233
235
|
4 /*yield*/ ,
|
|
234
236
|
_b.apply(_a, [
|
|
@@ -239,6 +241,7 @@ function AuthorizationPlugin(authorizer, options) {
|
|
|
239
241
|
// waiting for next accessToken refresh, on the server side, updates are synchronized.
|
|
240
242
|
// Note:
|
|
241
243
|
// even if the refreshing request send few times, the server side will only return the same token.
|
|
244
|
+
// 翻译:有效期内多次的刷新请求服务端应该保持 accessToken 不变,客户端不需要线程同步
|
|
242
245
|
_c.sent();
|
|
243
246
|
return [
|
|
244
247
|
3 /*break*/ ,
|
|
@@ -247,6 +250,8 @@ function AuthorizationPlugin(authorizer, options) {
|
|
|
247
250
|
case 10:
|
|
248
251
|
e2_1 = _c.sent();
|
|
249
252
|
// invalid refresh_token
|
|
253
|
+
// 此处触发一般就是 refreshSession 刷新返回 401 / 500 等,非标准返回值需要自行抛出异常
|
|
254
|
+
// 作废会话,一般就是 refreshToken 失效
|
|
250
255
|
authorizer.sessionHistory.deprecate(session);
|
|
251
256
|
_c.label = 11;
|
|
252
257
|
case 11:
|
|
@@ -273,6 +278,7 @@ function AuthorizationPlugin(authorizer, options) {
|
|
|
273
278
|
case 14:
|
|
274
279
|
unauthorized = false;
|
|
275
280
|
// cancel all requests resending.
|
|
281
|
+
// clear 就是 全部 reject 掉
|
|
276
282
|
queue.clear();
|
|
277
283
|
return [
|
|
278
284
|
7 /*endfinally*/
|
|
@@ -285,6 +291,7 @@ function AuthorizationPlugin(authorizer, options) {
|
|
|
285
291
|
case 16:
|
|
286
292
|
unauthorized = false;
|
|
287
293
|
// the accessToken refreshed, send the request itself and startup resending queue cleaning.
|
|
294
|
+
// 清空 else 分支积压的请求(重发)
|
|
288
295
|
(function() {
|
|
289
296
|
while(queue.size){
|
|
290
297
|
queue.pop();
|
|
@@ -303,6 +310,7 @@ function AuthorizationPlugin(authorizer, options) {
|
|
|
303
310
|
queue.resend(e)
|
|
304
311
|
];
|
|
305
312
|
case 18:
|
|
313
|
+
// 重发当前请求,当前请求没有压入队列需要单独处理
|
|
306
314
|
return [
|
|
307
315
|
2 /*return*/ ,
|
|
308
316
|
_c.sent()
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import type { AxiosError } from
|
|
1
|
+
import type { AxiosInstance, AxiosError } from 'axios';
|
|
2
2
|
import Authorizer from "./authorizer";
|
|
3
|
-
import
|
|
3
|
+
import Config from "../../core/config";
|
|
4
4
|
export default class PendingQueue {
|
|
5
5
|
_queue: {
|
|
6
6
|
error: AxiosError;
|
|
@@ -12,6 +12,7 @@ export default class PendingQueue {
|
|
|
12
12
|
_minTryRetryInterval: number;
|
|
13
13
|
_maxTryRetryInterval: number;
|
|
14
14
|
_retryTimes: number;
|
|
15
|
+
_resendAxiosInstance: AxiosInstance | null;
|
|
15
16
|
/**
|
|
16
17
|
* @param {Authorizer} authorizer
|
|
17
18
|
* @param {Config} config
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter =
|
|
2
|
+
var __awaiter = (void 0) && (void 0).__awaiter || function(thisArg, _arguments, P, generator) {
|
|
3
3
|
function adopt(value) {
|
|
4
4
|
return value instanceof P ? value : new P(function(resolve) {
|
|
5
5
|
resolve(value);
|
|
@@ -26,7 +26,7 @@ var __awaiter = this && this.__awaiter || function(thisArg, _arguments, P, gener
|
|
|
26
26
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
|
-
var __generator =
|
|
29
|
+
var __generator = (void 0) && (void 0).__generator || function(thisArg, body) {
|
|
30
30
|
var _ = {
|
|
31
31
|
label: 0,
|
|
32
32
|
sent: function sent() {
|
|
@@ -150,6 +150,7 @@ var PendingQueue = /** @class */ function() {
|
|
|
150
150
|
retryTimes = 3;
|
|
151
151
|
}
|
|
152
152
|
this._queue = [];
|
|
153
|
+
this._resendAxiosInstance = null;
|
|
153
154
|
this._authorizer = authorizer;
|
|
154
155
|
this._config = config;
|
|
155
156
|
this._minTryRetryInterval = minTryRetryInterval;
|
|
@@ -158,21 +159,20 @@ var PendingQueue = /** @class */ function() {
|
|
|
158
159
|
}
|
|
159
160
|
PendingQueue.prototype.resend = function(error_1) {
|
|
160
161
|
return __awaiter(this, arguments, void 0, function(error, retries) {
|
|
161
|
-
var maxTimes, i, session,
|
|
162
|
+
var maxTimes, i, session, _a, e_1;
|
|
162
163
|
if (retries === void 0) {
|
|
163
164
|
retries = 3;
|
|
164
165
|
}
|
|
165
|
-
return __generator(this, function(
|
|
166
|
-
switch(
|
|
166
|
+
return __generator(this, function(_b) {
|
|
167
|
+
switch(_b.label){
|
|
167
168
|
case 0:
|
|
168
169
|
maxTimes = Math.max(this._retryTimes, retries, 1);
|
|
169
|
-
console.log(maxTimes);
|
|
170
170
|
i = 0;
|
|
171
|
-
|
|
171
|
+
_b.label = 1;
|
|
172
172
|
case 1:
|
|
173
173
|
if (!(i < maxTimes)) return [
|
|
174
174
|
3 /*break*/ ,
|
|
175
|
-
|
|
175
|
+
11
|
|
176
176
|
];
|
|
177
177
|
if (!(i > 0)) return [
|
|
178
178
|
3 /*break*/ ,
|
|
@@ -183,60 +183,67 @@ var PendingQueue = /** @class */ function() {
|
|
|
183
183
|
sleep(random(this._minTryRetryInterval, this._maxTryRetryInterval))
|
|
184
184
|
];
|
|
185
185
|
case 2:
|
|
186
|
-
|
|
187
|
-
|
|
186
|
+
_b.sent();
|
|
187
|
+
_b.label = 3;
|
|
188
188
|
case 3:
|
|
189
189
|
return [
|
|
190
190
|
4 /*yield*/ ,
|
|
191
191
|
this._authorizer.getSession()
|
|
192
192
|
];
|
|
193
193
|
case 4:
|
|
194
|
-
session =
|
|
194
|
+
session = _b.sent();
|
|
195
195
|
if (this._authorizer.sessionHistory.isDeprecated(session)) {
|
|
196
196
|
// without re-login again, residual invalid session
|
|
197
197
|
throw error;
|
|
198
198
|
}
|
|
199
|
-
|
|
199
|
+
_b.label = 5;
|
|
200
200
|
case 5:
|
|
201
|
-
|
|
201
|
+
_b.trys.push([
|
|
202
202
|
5,
|
|
203
|
-
|
|
203
|
+
9,
|
|
204
204
|
,
|
|
205
|
-
|
|
205
|
+
10
|
|
206
206
|
]);
|
|
207
|
+
if (!!this._resendAxiosInstance) return [
|
|
208
|
+
3 /*break*/ ,
|
|
209
|
+
7
|
|
210
|
+
];
|
|
211
|
+
_a = this;
|
|
207
212
|
return [
|
|
208
213
|
4 /*yield*/ ,
|
|
209
214
|
this._config.axiosProvider.get()
|
|
210
215
|
];
|
|
211
216
|
case 6:
|
|
212
|
-
|
|
217
|
+
_a._resendAxiosInstance = _b.sent().create();
|
|
218
|
+
_b.label = 7;
|
|
219
|
+
case 7:
|
|
213
220
|
this._authorizer.withAuthentication(error.config, session);
|
|
214
221
|
return [
|
|
215
222
|
4 /*yield*/ ,
|
|
216
|
-
|
|
223
|
+
this._resendAxiosInstance.request(error.config)
|
|
217
224
|
];
|
|
218
|
-
case
|
|
225
|
+
case 8:
|
|
219
226
|
// fix: 401 循环 忘了加 await
|
|
220
227
|
return [
|
|
221
228
|
2 /*return*/ ,
|
|
222
|
-
|
|
229
|
+
_b.sent()
|
|
223
230
|
];
|
|
224
|
-
case
|
|
225
|
-
e_1 =
|
|
231
|
+
case 9:
|
|
232
|
+
e_1 = _b.sent();
|
|
226
233
|
if (i >= maxTimes) {
|
|
227
234
|
throw e_1;
|
|
228
235
|
}
|
|
229
236
|
return [
|
|
230
237
|
3 /*break*/ ,
|
|
231
|
-
|
|
238
|
+
10
|
|
232
239
|
];
|
|
233
|
-
case
|
|
240
|
+
case 10:
|
|
234
241
|
i++;
|
|
235
242
|
return [
|
|
236
243
|
3 /*break*/ ,
|
|
237
244
|
1
|
|
238
245
|
];
|
|
239
|
-
case
|
|
246
|
+
case 11:
|
|
240
247
|
throw error;
|
|
241
248
|
}
|
|
242
249
|
});
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter =
|
|
2
|
+
var __awaiter = (void 0) && (void 0).__awaiter || function(thisArg, _arguments, P, generator) {
|
|
3
3
|
function adopt(value) {
|
|
4
4
|
return value instanceof P ? value : new P(function(resolve) {
|
|
5
5
|
resolve(value);
|
|
@@ -26,7 +26,7 @@ var __awaiter = this && this.__awaiter || function(thisArg, _arguments, P, gener
|
|
|
26
26
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
|
-
var __generator =
|
|
29
|
+
var __generator = (void 0) && (void 0).__generator || function(thisArg, body) {
|
|
30
30
|
var _ = {
|
|
31
31
|
label: 0,
|
|
32
32
|
sent: function sent() {
|
package/package.json
CHANGED
|
@@ -1,16 +1,51 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "axios-annotations",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "3.1.0",
|
|
4
4
|
"description": "HTTP client library uses Axios without Typescript.",
|
|
5
|
-
"
|
|
6
|
-
"
|
|
7
|
-
"
|
|
5
|
+
"author": "sitorhy",
|
|
6
|
+
"license": "MIT",
|
|
7
|
+
"homepage": "https://github.com/sitorhy/axios-annotations#readme",
|
|
8
8
|
"keywords": [
|
|
9
9
|
"axios",
|
|
10
10
|
"axios-annotations",
|
|
11
11
|
"axios-decorators"
|
|
12
12
|
],
|
|
13
|
-
|
|
14
|
-
"
|
|
15
|
-
|
|
13
|
+
|
|
14
|
+
"type": "module",
|
|
15
|
+
|
|
16
|
+
"main": "./lib/index.js",
|
|
17
|
+
"module": "./es/index.js",
|
|
18
|
+
"types": "./lib/index.d.ts",
|
|
19
|
+
|
|
20
|
+
"miniprogram": "wechat-mp",
|
|
21
|
+
"miniprogramRoot": "wechat-mp",
|
|
22
|
+
|
|
23
|
+
"files": [
|
|
24
|
+
"lib",
|
|
25
|
+
"es",
|
|
26
|
+
"wechat-mp"
|
|
27
|
+
],
|
|
28
|
+
|
|
29
|
+
"exports": {
|
|
30
|
+
".": {
|
|
31
|
+
"import": {
|
|
32
|
+
"types": "./es/index.d.ts",
|
|
33
|
+
"default": "./es/index.js"
|
|
34
|
+
},
|
|
35
|
+
"require": {
|
|
36
|
+
"types": "./lib/index.d.ts",
|
|
37
|
+
"default": "./lib/index.js"
|
|
38
|
+
}
|
|
39
|
+
},
|
|
40
|
+
"./plugins/auth": {
|
|
41
|
+
"import": {
|
|
42
|
+
"types": "./es/plugins/auth/index.d.ts",
|
|
43
|
+
"default": "./es/plugins/auth/index.js"
|
|
44
|
+
},
|
|
45
|
+
"require": {
|
|
46
|
+
"types": "./lib/plugins/auth/index.d.ts",
|
|
47
|
+
"default": "./lib/plugins/auth/index.js"
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
16
51
|
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import type { AxiosResponse, Method } from 'axios';
|
|
2
|
+
import type Config from "./config";
|
|
3
|
+
import { AxiosRequestConfig } from "axios";
|
|
4
|
+
export type ParamsMapper<T = any> = (params: Record<string, any>) => T;
|
|
5
|
+
export declare enum ParamsMappingType {
|
|
6
|
+
HEADER = "HEADER",
|
|
7
|
+
PARAM = "PARAM",
|
|
8
|
+
BODY = "BODY",
|
|
9
|
+
PATH_VARIABLE = "PATH_VARIABLE"
|
|
10
|
+
}
|
|
11
|
+
export interface ParamsMapping<T = any> {
|
|
12
|
+
key: string;
|
|
13
|
+
value: T | ParamsMapper<T>;
|
|
14
|
+
required?: boolean;
|
|
15
|
+
}
|
|
16
|
+
export type AxiosConfigMapper = (params: Record<string, any>) => AxiosRequestConfig;
|
|
17
|
+
export default class RequestBuilder {
|
|
18
|
+
private _configs;
|
|
19
|
+
private readonly _mapping;
|
|
20
|
+
private readonly _pathVariablesMapping;
|
|
21
|
+
private _addMapping;
|
|
22
|
+
private _addPathVariablesMapping;
|
|
23
|
+
private _clearMapping;
|
|
24
|
+
param(key: string, required?: boolean): this;
|
|
25
|
+
param(mapping: ParamsMapping): this;
|
|
26
|
+
header(key: string, required?: boolean): this;
|
|
27
|
+
header(mapping: ParamsMapping): this;
|
|
28
|
+
body(keyOrMapping: string | ParamsMapping): this;
|
|
29
|
+
pathVariable(keyOrMapping: string | ParamsMapping): this;
|
|
30
|
+
config(cfg: AxiosRequestConfig | AxiosConfigMapper): this;
|
|
31
|
+
build(config: Config, path: string, method: Method, source?: Record<string, any>): AxiosRequestConfig;
|
|
32
|
+
buildWith(config: Config, path: string, method: Method, source?: Record<string, any>): Promise<AxiosResponse<any>>;
|
|
33
|
+
}
|