axios-annotations 1.3.4 → 2.0.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 +248 -105
- package/index.d.ts +1 -0
- package/index.js +121 -0
- package/lib/core/cancel.d.ts +30 -0
- package/lib/core/cancel.js +56 -0
- package/lib/core/common.d.ts +6 -0
- package/lib/core/common.js +166 -1
- package/lib/core/config.d.ts +60 -29
- package/lib/core/config.js +332 -1
- package/lib/core/parser.d.ts +19 -15
- package/lib/core/parser.js +79 -1
- package/lib/core/provider.d.ts +6 -0
- package/lib/core/provider.js +172 -0
- package/lib/core/service.d.ts +153 -33
- package/lib/core/service.js +562 -1
- package/lib/decorator/abort-source.d.ts +3 -9
- package/lib/decorator/abort-source.js +25 -1
- package/lib/decorator/delete-mapping.d.ts +1 -3
- package/lib/decorator/delete-mapping.js +13 -1
- package/lib/decorator/get-mapping.d.ts +1 -3
- package/lib/decorator/get-mapping.js +13 -1
- package/lib/decorator/ignore-residual-params.d.ts +1 -3
- package/lib/decorator/ignore-residual-params.js +24 -1
- package/lib/decorator/patch-mapping.d.ts +1 -3
- package/lib/decorator/patch-mapping.js +13 -1
- package/lib/decorator/post-mapping.d.ts +1 -3
- package/lib/decorator/post-mapping.js +13 -1
- package/lib/decorator/put-mapping.d.ts +1 -3
- package/lib/decorator/put-mapping.js +13 -1
- package/lib/decorator/request-body.d.ts +1 -3
- package/lib/decorator/request-body.js +28 -1
- package/lib/decorator/request-config.d.ts +5 -7
- package/lib/decorator/request-config.js +23 -1
- package/lib/decorator/request-header.d.ts +2 -5
- package/lib/decorator/request-header.js +21 -1
- package/lib/decorator/request-mapping.d.ts +3 -6
- package/lib/decorator/request-mapping.js +58 -1
- package/lib/decorator/request-param.d.ts +1 -3
- package/lib/decorator/request-param.js +27 -1
- package/lib/decorator/request-with.d.ts +1 -3
- package/lib/decorator/request-with.js +20 -1
- package/lib/index.d.ts +19 -0
- package/lib/index.js +139 -0
- package/lib/plugins/auth/authorizer.d.ts +23 -49
- package/lib/plugins/auth/authorizer.js +271 -1
- package/lib/plugins/auth/history.d.ts +14 -15
- package/lib/plugins/auth/history.js +96 -1
- package/lib/plugins/auth/index.d.ts +9 -4
- package/lib/plugins/auth/index.js +368 -1
- package/lib/plugins/auth/queue.d.ts +28 -16
- package/lib/plugins/auth/queue.js +270 -1
- package/lib/plugins/auth/storage.d.ts +6 -7
- package/lib/plugins/auth/storage.js +207 -1
- package/package.json +16 -16
- package/plugins/auth/index.d.ts +4 -4
- package/plugins/auth/index.js +26 -1
- package/core/config.d.ts +0 -29
- package/core/config.js +0 -1
- package/core/parser.d.ts +0 -15
- package/core/parser.js +0 -1
- package/core/service.d.ts +0 -33
- package/core/service.js +0 -1
- package/decorator/abort-source.d.ts +0 -9
- package/decorator/abort-source.js +0 -1
- package/decorator/delete-mapping.d.ts +0 -1
- package/decorator/delete-mapping.js +0 -1
- package/decorator/get-mapping.d.ts +0 -1
- package/decorator/get-mapping.js +0 -1
- package/decorator/ignore-residual-params.d.ts +0 -1
- package/decorator/ignore-residual-params.js +0 -1
- package/decorator/patch-mapping.d.ts +0 -1
- package/decorator/patch-mapping.js +0 -1
- package/decorator/post-mapping.d.ts +0 -1
- package/decorator/post-mapping.js +0 -1
- package/decorator/put-mapping.d.ts +0 -3
- package/decorator/put-mapping.js +0 -1
- package/decorator/request-body.d.ts +0 -3
- package/decorator/request-body.js +0 -1
- package/decorator/request-config.d.ts +0 -29
- package/decorator/request-config.js +0 -1
- package/decorator/request-header.d.ts +0 -1
- package/decorator/request-header.js +0 -1
- package/decorator/request-mapping.d.ts +0 -1
- package/decorator/request-mapping.js +0 -1
- package/decorator/request-param.d.ts +0 -1
- package/decorator/request-param.js +0 -1
- package/decorator/request-with.d.ts +0 -1
- package/decorator/request-with.js +0 -1
- package/lib/plugins/cache/index.js +0 -1
- package/plugins/auth/authorizer.d.ts +0 -49
- package/plugins/auth/authorizer.js +0 -1
- package/plugins/auth/history.d.ts +0 -15
- package/plugins/auth/history.js +0 -1
- package/plugins/auth/queue.d.ts +0 -16
- package/plugins/auth/queue.js +0 -1
- package/plugins/auth/storage.d.ts +0 -7
- package/plugins/auth/storage.js +0 -1
- package/plugins/cache/index.js +0 -1
package/lib/core/service.js
CHANGED
|
@@ -1 +1,562 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = this && this.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) {
|
|
4
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
5
|
+
resolve(value);
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
9
|
+
function fulfilled(value) {
|
|
10
|
+
try {
|
|
11
|
+
step(generator.next(value));
|
|
12
|
+
} catch (e) {
|
|
13
|
+
reject(e);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function rejected(value) {
|
|
17
|
+
try {
|
|
18
|
+
step(generator["throw"](value));
|
|
19
|
+
} catch (e) {
|
|
20
|
+
reject(e);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function step(result) {
|
|
24
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
25
|
+
}
|
|
26
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
30
|
+
var _ = {
|
|
31
|
+
label: 0,
|
|
32
|
+
sent: function sent() {
|
|
33
|
+
if (t[0] & 1) throw t[1];
|
|
34
|
+
return t[1];
|
|
35
|
+
},
|
|
36
|
+
trys: [],
|
|
37
|
+
ops: []
|
|
38
|
+
}, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
39
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
40
|
+
return this;
|
|
41
|
+
}), g;
|
|
42
|
+
function verb(n) {
|
|
43
|
+
return function(v) {
|
|
44
|
+
return step([
|
|
45
|
+
n,
|
|
46
|
+
v
|
|
47
|
+
]);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function step(op) {
|
|
51
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
52
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
53
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
54
|
+
if (y = 0, t) op = [
|
|
55
|
+
op[0] & 2,
|
|
56
|
+
t.value
|
|
57
|
+
];
|
|
58
|
+
switch(op[0]){
|
|
59
|
+
case 0:
|
|
60
|
+
case 1:
|
|
61
|
+
t = op;
|
|
62
|
+
break;
|
|
63
|
+
case 4:
|
|
64
|
+
_.label++;
|
|
65
|
+
return {
|
|
66
|
+
value: op[1],
|
|
67
|
+
done: false
|
|
68
|
+
};
|
|
69
|
+
case 5:
|
|
70
|
+
_.label++;
|
|
71
|
+
y = op[1];
|
|
72
|
+
op = [
|
|
73
|
+
0
|
|
74
|
+
];
|
|
75
|
+
continue;
|
|
76
|
+
case 7:
|
|
77
|
+
op = _.ops.pop();
|
|
78
|
+
_.trys.pop();
|
|
79
|
+
continue;
|
|
80
|
+
default:
|
|
81
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
82
|
+
_ = 0;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
86
|
+
_.label = op[1];
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
90
|
+
_.label = t[1];
|
|
91
|
+
t = op;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (t && _.label < t[2]) {
|
|
95
|
+
_.label = t[2];
|
|
96
|
+
_.ops.push(op);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (t[2]) _.ops.pop();
|
|
100
|
+
_.trys.pop();
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
op = body.call(thisArg, _);
|
|
104
|
+
} catch (e) {
|
|
105
|
+
op = [
|
|
106
|
+
6,
|
|
107
|
+
e
|
|
108
|
+
];
|
|
109
|
+
y = 0;
|
|
110
|
+
} finally{
|
|
111
|
+
f = t = 0;
|
|
112
|
+
}
|
|
113
|
+
if (op[0] & 5) throw op[1];
|
|
114
|
+
return {
|
|
115
|
+
value: op[0] ? op[1] : void 0,
|
|
116
|
+
done: true
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
var __spreadArray = this && this.__spreadArray || function(to, from, pack) {
|
|
121
|
+
if (pack || arguments.length === 2) for(var i = 0, l = from.length, ar; i < l; i++){
|
|
122
|
+
if (ar || !(i in from)) {
|
|
123
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
124
|
+
ar[i] = from[i];
|
|
125
|
+
}
|
|
126
|
+
}
|
|
127
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
128
|
+
};
|
|
129
|
+
Object.defineProperty(exports, "__esModule", {
|
|
130
|
+
value: true
|
|
131
|
+
});
|
|
132
|
+
exports.ConfigMapping = void 0;
|
|
133
|
+
var common_1 = require("./common");
|
|
134
|
+
var parser_1 = require("./parser");
|
|
135
|
+
var config_1 = require("./config");
|
|
136
|
+
exports.ConfigMapping = {
|
|
137
|
+
requestHeaders: function requestHeaders(rules, args) {
|
|
138
|
+
if (args === void 0) {
|
|
139
|
+
args = [];
|
|
140
|
+
}
|
|
141
|
+
var headers = {};
|
|
142
|
+
if (rules) {
|
|
143
|
+
for(var h in rules){
|
|
144
|
+
var value = rules[h];
|
|
145
|
+
if (typeof value === "function") {
|
|
146
|
+
headers[h] = value.apply(undefined, args);
|
|
147
|
+
} else {
|
|
148
|
+
headers[h] = value;
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
}
|
|
152
|
+
return headers;
|
|
153
|
+
},
|
|
154
|
+
axiosConfig: function axiosConfig(options, args) {
|
|
155
|
+
var config = {};
|
|
156
|
+
(options || []).forEach(function(o) {
|
|
157
|
+
if (typeof o === "function") {
|
|
158
|
+
Object.assign(config, o.apply(undefined, args));
|
|
159
|
+
} else {
|
|
160
|
+
Object.assign(config, o);
|
|
161
|
+
}
|
|
162
|
+
});
|
|
163
|
+
return config;
|
|
164
|
+
},
|
|
165
|
+
querystring: function querystring(features, rules, data) {
|
|
166
|
+
if (!data) {
|
|
167
|
+
return "";
|
|
168
|
+
}
|
|
169
|
+
if (rules) {
|
|
170
|
+
var encoder = parser_1["default"].decode(data);
|
|
171
|
+
for(var key in data){
|
|
172
|
+
var value = data[key];
|
|
173
|
+
var rule = rules[key];
|
|
174
|
+
if (rule) {
|
|
175
|
+
if (!rule.body) {
|
|
176
|
+
if (!rule.required) {
|
|
177
|
+
if ((0, common_1.isNullOrEmpty)(value)) {
|
|
178
|
+
if (parser_1["default"].has(encoder, key)) {
|
|
179
|
+
parser_1["default"]["delete"](encoder, key);
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
} else {
|
|
183
|
+
if ((0, common_1.isNullOrEmpty)(value)) {
|
|
184
|
+
if (!parser_1["default"].has(encoder, key)) {
|
|
185
|
+
parser_1["default"].append(encoder, key, "");
|
|
186
|
+
}
|
|
187
|
+
}
|
|
188
|
+
}
|
|
189
|
+
} else {
|
|
190
|
+
parser_1["default"]["delete"](encoder, key);
|
|
191
|
+
}
|
|
192
|
+
} else {
|
|
193
|
+
if (features && features.ignoreResidualParams === true) {
|
|
194
|
+
parser_1["default"]["delete"](encoder, key);
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
for(var key in rules){
|
|
199
|
+
var rule = rules[key];
|
|
200
|
+
if (rule && !rule.body && rule.required && !parser_1["default"].has(encoder, key)) {
|
|
201
|
+
parser_1["default"].append(encoder, key, "");
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return parser_1["default"].encode(encoder);
|
|
205
|
+
} else {
|
|
206
|
+
if (features && features.ignoreResidualParams === true) {
|
|
207
|
+
return "";
|
|
208
|
+
} else {
|
|
209
|
+
var encoder = parser_1["default"].decode(data);
|
|
210
|
+
return parser_1["default"].encode(encoder);
|
|
211
|
+
}
|
|
212
|
+
}
|
|
213
|
+
},
|
|
214
|
+
/**
|
|
215
|
+
* 从参数对象中提取 body 所属字段
|
|
216
|
+
* @param rules
|
|
217
|
+
* @param data
|
|
218
|
+
*/ body: function body(rules, data) {
|
|
219
|
+
if (rules) {
|
|
220
|
+
for(var r in rules){
|
|
221
|
+
var rule = rules[r];
|
|
222
|
+
if (rule.body === true) {
|
|
223
|
+
return !(0, common_1.isNullOrEmpty)(data) ? data[r] : undefined;
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
return null;
|
|
228
|
+
}
|
|
229
|
+
};
|
|
230
|
+
// noinspection JSUnusedGlobalSymbols
|
|
231
|
+
var Service = /** @class */ function() {
|
|
232
|
+
function Service(path) {
|
|
233
|
+
if (path === void 0) {
|
|
234
|
+
path = null;
|
|
235
|
+
}
|
|
236
|
+
this._path = "";
|
|
237
|
+
this._config = config_1.config;
|
|
238
|
+
this._headers = {};
|
|
239
|
+
this._params = {};
|
|
240
|
+
this._configs = {};
|
|
241
|
+
this._for = {};
|
|
242
|
+
this._features = {};
|
|
243
|
+
if (!this._path && path) {
|
|
244
|
+
this._path = path;
|
|
245
|
+
}
|
|
246
|
+
if (typeof Object.getPrototypeOf === "function") {
|
|
247
|
+
if (Object.getPrototypeOf(this)._path) {
|
|
248
|
+
this._path = Object.getPrototypeOf(this)._path;
|
|
249
|
+
}
|
|
250
|
+
if (Object.getPrototypeOf(this)._config) {
|
|
251
|
+
this._config = Object.getPrototypeOf(this)._config;
|
|
252
|
+
}
|
|
253
|
+
} else {
|
|
254
|
+
if (Object.getPrototypeOf(this)._path) {
|
|
255
|
+
this._path = Object.getPrototypeOf(this)._path;
|
|
256
|
+
}
|
|
257
|
+
if (Object.getPrototypeOf(this)._config) {
|
|
258
|
+
this._config = Object.getPrototypeOf(this)._config;
|
|
259
|
+
}
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
Object.defineProperty(Service.prototype, "config", {
|
|
263
|
+
get: function get() {
|
|
264
|
+
return this._config;
|
|
265
|
+
},
|
|
266
|
+
set: function set(value) {
|
|
267
|
+
this._config = value;
|
|
268
|
+
},
|
|
269
|
+
enumerable: false,
|
|
270
|
+
configurable: true
|
|
271
|
+
});
|
|
272
|
+
Object.defineProperty(Service.prototype, "path", {
|
|
273
|
+
get: function get() {
|
|
274
|
+
return this._path;
|
|
275
|
+
},
|
|
276
|
+
set: function set(value) {
|
|
277
|
+
this._path = value;
|
|
278
|
+
},
|
|
279
|
+
enumerable: false,
|
|
280
|
+
configurable: true
|
|
281
|
+
});
|
|
282
|
+
Service.prototype.params = function(id, name, config) {
|
|
283
|
+
var _a, _b;
|
|
284
|
+
if (config === void 0) {
|
|
285
|
+
config = {
|
|
286
|
+
required: false
|
|
287
|
+
};
|
|
288
|
+
}
|
|
289
|
+
if (!this._params || !this._params[id] || !Object.hasOwnProperty.call(this._params[id], name)) {
|
|
290
|
+
var cfg = Object.assign({
|
|
291
|
+
required: false,
|
|
292
|
+
body: false
|
|
293
|
+
}, config);
|
|
294
|
+
var root = this._params || {};
|
|
295
|
+
var rules = this._params ? this._params[id] || {} : {};
|
|
296
|
+
var rule = rules[name] || {};
|
|
297
|
+
if (cfg.body === true) {
|
|
298
|
+
for(var r in rules){
|
|
299
|
+
var rule_1 = rules[r];
|
|
300
|
+
rule_1.body = false;
|
|
301
|
+
}
|
|
302
|
+
}
|
|
303
|
+
this._params = Object.assign(root, (_a = {}, _a[id] = Object.assign(rules, (_b = {}, _b[name] = Object.assign(rule, cfg), _b)), _a));
|
|
304
|
+
}
|
|
305
|
+
};
|
|
306
|
+
Service.prototype.headers = function(id, header, value) {
|
|
307
|
+
var _a, _b;
|
|
308
|
+
var root = this._headers || {};
|
|
309
|
+
Object.assign(root, (_a = {}, _a[id] = Object.assign(root[id] || {}, (_b = {}, _b[header] = value, _b)), _a));
|
|
310
|
+
};
|
|
311
|
+
Service.prototype["for"] = function(id, registrationName) {
|
|
312
|
+
var _a;
|
|
313
|
+
if (arguments.length === 1) {
|
|
314
|
+
return this._for[id];
|
|
315
|
+
}
|
|
316
|
+
Object.assign(this._for, (_a = {}, _a[id] = registrationName, _a));
|
|
317
|
+
};
|
|
318
|
+
Service.prototype.abort = function(id, abortController) {
|
|
319
|
+
var cfg = Object.assign(this.features(id) || {}, {
|
|
320
|
+
abortController: abortController
|
|
321
|
+
});
|
|
322
|
+
this.features(id, cfg);
|
|
323
|
+
};
|
|
324
|
+
Service.prototype.features = function(id, options) {
|
|
325
|
+
var _a;
|
|
326
|
+
if (arguments.length === 1) {
|
|
327
|
+
return this._features[id];
|
|
328
|
+
}
|
|
329
|
+
Object.assign(this._features, (_a = {}, _a[id] = options, _a));
|
|
330
|
+
};
|
|
331
|
+
Service.prototype.configs = function(id, options) {
|
|
332
|
+
var _a;
|
|
333
|
+
var root = this._configs || {};
|
|
334
|
+
Object.assign(root, (_a = {}, _a[id] = (root[id] || []).concat(options), _a));
|
|
335
|
+
};
|
|
336
|
+
/**
|
|
337
|
+
* 填充路径占位符 <br/>
|
|
338
|
+
* override this method to custom placeholder replacement <br>
|
|
339
|
+
* default implement: data = { id: 111 }; <br/>
|
|
340
|
+
* "/path/{id}" -> return "/path/111"
|
|
341
|
+
* @param path
|
|
342
|
+
* @param data
|
|
343
|
+
*/ Service.prototype.pathVariable = function(path, data) {
|
|
344
|
+
var p = path || "";
|
|
345
|
+
var matchers = p.match(/{\w+}/g);
|
|
346
|
+
if (Array.isArray(matchers)) {
|
|
347
|
+
matchers.forEach(function(m) {
|
|
348
|
+
var field = m.substring(1, m.length - 1);
|
|
349
|
+
p = (0, common_1.replaceAllStr)(p, "{".concat(field, "}"), data[field]);
|
|
350
|
+
});
|
|
351
|
+
}
|
|
352
|
+
return p;
|
|
353
|
+
};
|
|
354
|
+
Service.prototype.createRequestConfig = function(id, path, data, headerArgs, configArgs) {
|
|
355
|
+
if (headerArgs === void 0) {
|
|
356
|
+
headerArgs = [];
|
|
357
|
+
}
|
|
358
|
+
if (configArgs === void 0) {
|
|
359
|
+
configArgs = [];
|
|
360
|
+
}
|
|
361
|
+
var query = exports.ConfigMapping.querystring(this._features[id], this._params[id], data);
|
|
362
|
+
var body = exports.ConfigMapping.body(this._params[id], data);
|
|
363
|
+
var headers = exports.ConfigMapping.requestHeaders(this._headers[id], headerArgs);
|
|
364
|
+
var config = exports.ConfigMapping.axiosConfig(this._configs[id], configArgs);
|
|
365
|
+
var p = "".concat(path).concat(query ? (path.lastIndexOf("?") >= 0 ? "&" : "?") + query : "");
|
|
366
|
+
if (this._features && this._features[id] && this._features[id].abortController) {
|
|
367
|
+
var abortController = this._features[id].abortController;
|
|
368
|
+
var __abortControllerInst = void 0;
|
|
369
|
+
if (typeof abortController === "function") {
|
|
370
|
+
__abortControllerInst = abortController.apply(undefined, configArgs);
|
|
371
|
+
} else {
|
|
372
|
+
__abortControllerInst = abortController;
|
|
373
|
+
}
|
|
374
|
+
if (__abortControllerInst) {
|
|
375
|
+
if (__abortControllerInst.source) {
|
|
376
|
+
config.cancelToken = __abortControllerInst.source.token;
|
|
377
|
+
} else {
|
|
378
|
+
config.signal = __abortControllerInst.signal;
|
|
379
|
+
}
|
|
380
|
+
}
|
|
381
|
+
}
|
|
382
|
+
Object.assign(config, {
|
|
383
|
+
headers: Object.assign(headers, config.headers || null)
|
|
384
|
+
});
|
|
385
|
+
return {
|
|
386
|
+
path: p,
|
|
387
|
+
body: body,
|
|
388
|
+
config: config,
|
|
389
|
+
query: query
|
|
390
|
+
};
|
|
391
|
+
};
|
|
392
|
+
Service.prototype.request = function(method_1, path_1) {
|
|
393
|
+
return __awaiter(this, arguments, void 0, function(method, path, data, config) {
|
|
394
|
+
var url, axios;
|
|
395
|
+
if (data === void 0) {
|
|
396
|
+
data = {};
|
|
397
|
+
}
|
|
398
|
+
if (config === void 0) {
|
|
399
|
+
config = {};
|
|
400
|
+
}
|
|
401
|
+
return __generator(this, function(_a) {
|
|
402
|
+
switch(_a.label){
|
|
403
|
+
case 0:
|
|
404
|
+
url = path.indexOf("http") >= 0 ? path : this.config.baseURL + (0, common_1.normalizePath)("/".concat(this.path || "", "/").concat(path));
|
|
405
|
+
return [
|
|
406
|
+
4 /*yield*/ ,
|
|
407
|
+
this.config.requestAxiosInstance()
|
|
408
|
+
];
|
|
409
|
+
case 1:
|
|
410
|
+
axios = _a.sent();
|
|
411
|
+
return [
|
|
412
|
+
2 /*return*/ ,
|
|
413
|
+
axios.request(Object.assign({
|
|
414
|
+
method: method,
|
|
415
|
+
url: url,
|
|
416
|
+
data: data
|
|
417
|
+
}, config))
|
|
418
|
+
];
|
|
419
|
+
}
|
|
420
|
+
});
|
|
421
|
+
});
|
|
422
|
+
};
|
|
423
|
+
Service.prototype.requestWith = function(method, path) {
|
|
424
|
+
var _this = this;
|
|
425
|
+
if (path === void 0) {
|
|
426
|
+
path = "";
|
|
427
|
+
}
|
|
428
|
+
var _params = {};
|
|
429
|
+
var _configs = [];
|
|
430
|
+
var _headers = {};
|
|
431
|
+
var _features = {};
|
|
432
|
+
var _withConfig = this.config;
|
|
433
|
+
var controller = {
|
|
434
|
+
"with": function _with(registration) {
|
|
435
|
+
var c = config_1["default"].forName(registration);
|
|
436
|
+
if (c) {
|
|
437
|
+
_withConfig = c;
|
|
438
|
+
}
|
|
439
|
+
return controller;
|
|
440
|
+
},
|
|
441
|
+
param: function param(key, required) {
|
|
442
|
+
var _a;
|
|
443
|
+
if (required === void 0) {
|
|
444
|
+
required = false;
|
|
445
|
+
}
|
|
446
|
+
var rule = _params[key] || {};
|
|
447
|
+
Object.assign(_params, (_a = {}, _a[key] = Object.assign(rule, {
|
|
448
|
+
required: required,
|
|
449
|
+
body: false
|
|
450
|
+
}), _a));
|
|
451
|
+
return controller;
|
|
452
|
+
},
|
|
453
|
+
abort: function abort(abortController) {
|
|
454
|
+
Object.assign(_features, {
|
|
455
|
+
abortController: abortController
|
|
456
|
+
});
|
|
457
|
+
return controller;
|
|
458
|
+
},
|
|
459
|
+
ignoreResidualParams: function ignoreResidualParams(ignore) {
|
|
460
|
+
if (ignore === void 0) {
|
|
461
|
+
ignore = true;
|
|
462
|
+
}
|
|
463
|
+
Object.assign(_features, {
|
|
464
|
+
ignoreResidualParams: ignore
|
|
465
|
+
});
|
|
466
|
+
return controller;
|
|
467
|
+
},
|
|
468
|
+
header: function header(header, value) {
|
|
469
|
+
var _a;
|
|
470
|
+
Object.assign(_headers, (_a = {}, _a[header] = value, _a));
|
|
471
|
+
return controller;
|
|
472
|
+
},
|
|
473
|
+
body: function body(key) {
|
|
474
|
+
var _a;
|
|
475
|
+
var rule = _params[key] || {};
|
|
476
|
+
for(var r in _params){
|
|
477
|
+
var rule_2 = _params[r];
|
|
478
|
+
rule_2.body = false;
|
|
479
|
+
}
|
|
480
|
+
Object.assign(_params, (_a = {}, _a[key] = Object.assign(rule, {
|
|
481
|
+
required: false,
|
|
482
|
+
body: true
|
|
483
|
+
}), _a));
|
|
484
|
+
return controller;
|
|
485
|
+
},
|
|
486
|
+
config: function config(cfg) {
|
|
487
|
+
_configs.push(cfg);
|
|
488
|
+
return controller;
|
|
489
|
+
},
|
|
490
|
+
send: function send() {
|
|
491
|
+
var args_1 = [];
|
|
492
|
+
for(var _i = 0; _i < arguments.length; _i++){
|
|
493
|
+
args_1[_i] = arguments[_i];
|
|
494
|
+
}
|
|
495
|
+
return __awaiter(_this, __spreadArray([], args_1, true), void 0, function(data) {
|
|
496
|
+
var query, body, headers, config, abortController, __abortControllerInst, axios, p;
|
|
497
|
+
if (data === void 0) {
|
|
498
|
+
data = {};
|
|
499
|
+
}
|
|
500
|
+
return __generator(this, function(_a) {
|
|
501
|
+
switch(_a.label){
|
|
502
|
+
case 0:
|
|
503
|
+
query = exports.ConfigMapping.querystring(_features, _params, data);
|
|
504
|
+
body = exports.ConfigMapping.body(_params, data);
|
|
505
|
+
headers = exports.ConfigMapping.requestHeaders(_headers, [
|
|
506
|
+
data
|
|
507
|
+
]);
|
|
508
|
+
config = exports.ConfigMapping.axiosConfig(_configs, [
|
|
509
|
+
data
|
|
510
|
+
]);
|
|
511
|
+
abortController = _features.abortController;
|
|
512
|
+
Object.assign(config, {
|
|
513
|
+
headers: Object.assign(headers, config.headers || null)
|
|
514
|
+
});
|
|
515
|
+
if (abortController) {
|
|
516
|
+
__abortControllerInst = void 0;
|
|
517
|
+
if (typeof abortController === "function") {
|
|
518
|
+
__abortControllerInst = abortController.apply(undefined, [
|
|
519
|
+
data
|
|
520
|
+
]);
|
|
521
|
+
} else {
|
|
522
|
+
__abortControllerInst = abortController;
|
|
523
|
+
}
|
|
524
|
+
if (__abortControllerInst) {
|
|
525
|
+
if (__abortControllerInst.source) {
|
|
526
|
+
config.cancelToken = __abortControllerInst.source.token;
|
|
527
|
+
} else {
|
|
528
|
+
config.signal = __abortControllerInst.signal;
|
|
529
|
+
}
|
|
530
|
+
}
|
|
531
|
+
}
|
|
532
|
+
return [
|
|
533
|
+
4 /*yield*/ ,
|
|
534
|
+
_withConfig.requestAxiosInstance()
|
|
535
|
+
];
|
|
536
|
+
case 1:
|
|
537
|
+
axios = _a.sent();
|
|
538
|
+
if (_withConfig) {
|
|
539
|
+
return [
|
|
540
|
+
2 /*return*/ ,
|
|
541
|
+
(0, common_1.forward)(axios, _withConfig.origin, _withConfig.prefix, this.path, path, method, query, body, config)
|
|
542
|
+
];
|
|
543
|
+
} else {
|
|
544
|
+
p = "".concat(this.pathVariable(path || "", data)).concat(query ? (path.lastIndexOf("?") >= 0 ? "&" : "?") + query : "");
|
|
545
|
+
return [
|
|
546
|
+
2 /*return*/ ,
|
|
547
|
+
this.request(method, p, body, config)
|
|
548
|
+
];
|
|
549
|
+
}
|
|
550
|
+
return [
|
|
551
|
+
2 /*return*/
|
|
552
|
+
];
|
|
553
|
+
}
|
|
554
|
+
});
|
|
555
|
+
});
|
|
556
|
+
}
|
|
557
|
+
};
|
|
558
|
+
return controller;
|
|
559
|
+
};
|
|
560
|
+
return Service;
|
|
561
|
+
}();
|
|
562
|
+
exports["default"] = Service;
|
|
@@ -1,9 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export
|
|
4
|
-
constructor(CancelToken: CancelToken);
|
|
5
|
-
|
|
6
|
-
abort(reason?: string): void;
|
|
7
|
-
}
|
|
8
|
-
|
|
9
|
-
export default function AbortSource(abortController: (AbortController | AbortControllerAdapter) | ((...args: any[]) => (AbortController | AbortControllerAdapter))): (() => AxiosPromise<any>);
|
|
1
|
+
import { AbortControllerGenerator } from "../core/service";
|
|
2
|
+
import { AbortControllerAdapter } from "../index";
|
|
3
|
+
export default function AbortSource(abortController: (AbortController | AbortControllerAdapter) | AbortControllerGenerator): MethodDecorator;
|
|
@@ -1 +1,25 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports["default"] = AbortSource;
|
|
6
|
+
// noinspection JSUnusedGlobalSymbols
|
|
7
|
+
function AbortSource(abortController) {
|
|
8
|
+
return function(_target, method, descriptor) {
|
|
9
|
+
if (descriptor) {
|
|
10
|
+
var fn_1 = descriptor.value;
|
|
11
|
+
descriptor.value = function() {
|
|
12
|
+
var args = [];
|
|
13
|
+
for(var _i = 0; _i < arguments.length; _i++){
|
|
14
|
+
args[_i] = arguments[_i];
|
|
15
|
+
}
|
|
16
|
+
var controller = abortController;
|
|
17
|
+
if (typeof abortController === "function") {
|
|
18
|
+
controller = abortController.apply(undefined, args);
|
|
19
|
+
}
|
|
20
|
+
this.abort(method, controller);
|
|
21
|
+
return fn_1.apply(this, args);
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
};
|
|
25
|
+
}
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports["default"] = DeleteMapping;
|
|
6
|
+
var request_mapping_1 = require("./request-mapping");
|
|
7
|
+
// noinspection JSUnusedGlobalSymbols
|
|
8
|
+
function DeleteMapping(path) {
|
|
9
|
+
if (path === void 0) {
|
|
10
|
+
path = "";
|
|
11
|
+
}
|
|
12
|
+
return (0, request_mapping_1["default"])(path, "DELETE");
|
|
13
|
+
}
|
|
@@ -1 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports["default"] = GetMapping;
|
|
6
|
+
var request_mapping_1 = require("./request-mapping");
|
|
7
|
+
// noinspection JSUnusedGlobalSymbols
|
|
8
|
+
function GetMapping(path) {
|
|
9
|
+
if (path === void 0) {
|
|
10
|
+
path = "";
|
|
11
|
+
}
|
|
12
|
+
return (0, request_mapping_1["default"])(path, "GET");
|
|
13
|
+
}
|