axios-annotations 2.3.0 → 3.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 +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 +56 -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 +42 -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 +60 -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
package/lib/core/service.js
CHANGED
|
@@ -1,562 +1,60 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var
|
|
3
|
-
function
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
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];
|
|
2
|
+
var __values = (void 0) && (void 0).__values || function(o) {
|
|
3
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
4
|
+
if (m) return m.call(o);
|
|
5
|
+
if (o && typeof o.length === "number") return {
|
|
6
|
+
next: function next() {
|
|
7
|
+
if (o && i >= o.length) o = void 0;
|
|
8
|
+
return {
|
|
9
|
+
value: o && o[i++],
|
|
10
|
+
done: !o
|
|
11
|
+
};
|
|
125
12
|
}
|
|
126
|
-
}
|
|
127
|
-
|
|
13
|
+
};
|
|
14
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
128
15
|
};
|
|
129
16
|
Object.defineProperty(exports, "__esModule", {
|
|
130
17
|
value: true
|
|
131
18
|
});
|
|
132
|
-
exports.ConfigMapping = void 0;
|
|
133
|
-
var common_1 = require("./common");
|
|
134
|
-
var parser_1 = require("./parser");
|
|
135
19
|
var config_1 = require("./config");
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
var
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
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);
|
|
20
|
+
var Service = /** @class */ function() {
|
|
21
|
+
function Service() {
|
|
22
|
+
var e_1, _a;
|
|
23
|
+
this.config = config_1.config;
|
|
24
|
+
this.path = '';
|
|
25
|
+
var target = Object.getPrototypeOf(this);
|
|
26
|
+
// 获取被加入切面的方法
|
|
27
|
+
var methodsToBind = target.__decoratedMethods;
|
|
28
|
+
if (methodsToBind && Array.isArray(methodsToBind)) {
|
|
29
|
+
try {
|
|
30
|
+
for(var methodsToBind_1 = __values(methodsToBind), methodsToBind_1_1 = methodsToBind_1.next(); !methodsToBind_1_1.done; methodsToBind_1_1 = methodsToBind_1.next()){
|
|
31
|
+
var methodName = methodsToBind_1_1.value;
|
|
32
|
+
if (typeof this[methodName] === 'function') {
|
|
33
|
+
this[methodName] = this[methodName].bind(this);
|
|
195
34
|
}
|
|
196
35
|
}
|
|
197
|
-
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
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;
|
|
36
|
+
} catch (e_1_1) {
|
|
37
|
+
e_1 = {
|
|
38
|
+
error: e_1_1
|
|
39
|
+
};
|
|
40
|
+
} finally{
|
|
41
|
+
try {
|
|
42
|
+
if (methodsToBind_1_1 && !methodsToBind_1_1.done && (_a = methodsToBind_1["return"])) _a.call(methodsToBind_1);
|
|
43
|
+
} finally{
|
|
44
|
+
if (e_1) throw e_1.error;
|
|
224
45
|
}
|
|
225
46
|
}
|
|
226
47
|
}
|
|
227
|
-
|
|
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;
|
|
48
|
+
if (target.__path) {
|
|
49
|
+
this.path = target.__path;
|
|
245
50
|
}
|
|
246
|
-
if (
|
|
247
|
-
|
|
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
|
-
}
|
|
51
|
+
if (target.__config) {
|
|
52
|
+
this.config = target.__config;
|
|
260
53
|
}
|
|
54
|
+
Reflect.deleteProperty(target, '__path');
|
|
55
|
+
Reflect.deleteProperty(target, '__config');
|
|
56
|
+
Reflect.deleteProperty(target, '__decoratedMethods');
|
|
261
57
|
}
|
|
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
58
|
return Service;
|
|
561
59
|
}();
|
|
562
60
|
exports["default"] = Service;
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ParamsMapping } from "../core/builder";
|
|
2
|
+
import type Service from "../core/service";
|
|
3
|
+
type PathVariablesParamsMapping = Omit<ParamsMapping, 'key'> & {
|
|
4
|
+
key?: string;
|
|
5
|
+
};
|
|
6
|
+
export default function PathVariables(keyOrMapping?: string | PathVariablesParamsMapping): <T extends Service>(_target: T, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (void 0) && (void 0).__assign || function() {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for(var s, i = 1, n = arguments.length; i < n; i++){
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for(var p in s)if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
|
|
7
|
+
}
|
|
8
|
+
return t;
|
|
9
|
+
};
|
|
10
|
+
return __assign.apply(this, arguments);
|
|
11
|
+
};
|
|
12
|
+
Object.defineProperty(exports, "__esModule", {
|
|
13
|
+
value: true
|
|
14
|
+
});
|
|
15
|
+
exports["default"] = PathVariables;
|
|
16
|
+
var common_1 = require("../core/common");
|
|
17
|
+
function PathVariables(keyOrMapping) {
|
|
18
|
+
return function(_target, propertyKey, descriptor) {
|
|
19
|
+
var metaDescriptor = (0, common_1.castToMetaDescriptor)(descriptor);
|
|
20
|
+
var builder = metaDescriptor.builder;
|
|
21
|
+
if (builder) {
|
|
22
|
+
if (typeof keyOrMapping === 'string' || keyOrMapping === undefined || (0, common_1.isNullOrEmpty)(keyOrMapping)) {
|
|
23
|
+
builder.pathVariable({
|
|
24
|
+
// key 为空使用数据源本体
|
|
25
|
+
key: typeof keyOrMapping === 'string' ? keyOrMapping : '',
|
|
26
|
+
required: false,
|
|
27
|
+
value: undefined
|
|
28
|
+
});
|
|
29
|
+
} else {
|
|
30
|
+
builder.pathVariable(__assign(__assign({}, keyOrMapping), {
|
|
31
|
+
key: typeof keyOrMapping.key === 'string' ? keyOrMapping.key : '',
|
|
32
|
+
required: false
|
|
33
|
+
}));
|
|
34
|
+
}
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import type Service from "../core/service";
|
|
2
|
+
import { ParamsMapping } from "../core/builder";
|
|
3
|
+
type RequestBodyParamsMapping = Omit<ParamsMapping, 'key'> & {
|
|
4
|
+
key?: string;
|
|
5
|
+
};
|
|
6
|
+
export default function RequestBody(keyOrMapping?: string | RequestBodyParamsMapping): <T extends Service>(_target: T, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
7
|
+
export {};
|