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
|
@@ -0,0 +1,520 @@
|
|
|
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
|
+
var __awaiter = (void 0) && (void 0).__awaiter || function(thisArg, _arguments, P, generator) {
|
|
13
|
+
function adopt(value) {
|
|
14
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
15
|
+
resolve(value);
|
|
16
|
+
});
|
|
17
|
+
}
|
|
18
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
19
|
+
function fulfilled(value) {
|
|
20
|
+
try {
|
|
21
|
+
step(generator.next(value));
|
|
22
|
+
} catch (e) {
|
|
23
|
+
reject(e);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
function rejected(value) {
|
|
27
|
+
try {
|
|
28
|
+
step(generator["throw"](value));
|
|
29
|
+
} catch (e) {
|
|
30
|
+
reject(e);
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
function step(result) {
|
|
34
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
35
|
+
}
|
|
36
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
37
|
+
});
|
|
38
|
+
};
|
|
39
|
+
var __generator = (void 0) && (void 0).__generator || function(thisArg, body) {
|
|
40
|
+
var _ = {
|
|
41
|
+
label: 0,
|
|
42
|
+
sent: function sent() {
|
|
43
|
+
if (t[0] & 1) throw t[1];
|
|
44
|
+
return t[1];
|
|
45
|
+
},
|
|
46
|
+
trys: [],
|
|
47
|
+
ops: []
|
|
48
|
+
}, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
49
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
50
|
+
return this;
|
|
51
|
+
}), g;
|
|
52
|
+
function verb(n) {
|
|
53
|
+
return function(v) {
|
|
54
|
+
return step([
|
|
55
|
+
n,
|
|
56
|
+
v
|
|
57
|
+
]);
|
|
58
|
+
};
|
|
59
|
+
}
|
|
60
|
+
function step(op) {
|
|
61
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
62
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
63
|
+
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;
|
|
64
|
+
if (y = 0, t) op = [
|
|
65
|
+
op[0] & 2,
|
|
66
|
+
t.value
|
|
67
|
+
];
|
|
68
|
+
switch(op[0]){
|
|
69
|
+
case 0:
|
|
70
|
+
case 1:
|
|
71
|
+
t = op;
|
|
72
|
+
break;
|
|
73
|
+
case 4:
|
|
74
|
+
_.label++;
|
|
75
|
+
return {
|
|
76
|
+
value: op[1],
|
|
77
|
+
done: false
|
|
78
|
+
};
|
|
79
|
+
case 5:
|
|
80
|
+
_.label++;
|
|
81
|
+
y = op[1];
|
|
82
|
+
op = [
|
|
83
|
+
0
|
|
84
|
+
];
|
|
85
|
+
continue;
|
|
86
|
+
case 7:
|
|
87
|
+
op = _.ops.pop();
|
|
88
|
+
_.trys.pop();
|
|
89
|
+
continue;
|
|
90
|
+
default:
|
|
91
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
92
|
+
_ = 0;
|
|
93
|
+
continue;
|
|
94
|
+
}
|
|
95
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
96
|
+
_.label = op[1];
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
100
|
+
_.label = t[1];
|
|
101
|
+
t = op;
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
if (t && _.label < t[2]) {
|
|
105
|
+
_.label = t[2];
|
|
106
|
+
_.ops.push(op);
|
|
107
|
+
break;
|
|
108
|
+
}
|
|
109
|
+
if (t[2]) _.ops.pop();
|
|
110
|
+
_.trys.pop();
|
|
111
|
+
continue;
|
|
112
|
+
}
|
|
113
|
+
op = body.call(thisArg, _);
|
|
114
|
+
} catch (e) {
|
|
115
|
+
op = [
|
|
116
|
+
6,
|
|
117
|
+
e
|
|
118
|
+
];
|
|
119
|
+
y = 0;
|
|
120
|
+
} finally{
|
|
121
|
+
f = t = 0;
|
|
122
|
+
}
|
|
123
|
+
if (op[0] & 5) throw op[1];
|
|
124
|
+
return {
|
|
125
|
+
value: op[0] ? op[1] : void 0,
|
|
126
|
+
done: true
|
|
127
|
+
};
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
var __values = (void 0) && (void 0).__values || function(o) {
|
|
131
|
+
var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
|
|
132
|
+
if (m) return m.call(o);
|
|
133
|
+
if (o && typeof o.length === "number") return {
|
|
134
|
+
next: function next() {
|
|
135
|
+
if (o && i >= o.length) o = void 0;
|
|
136
|
+
return {
|
|
137
|
+
value: o && o[i++],
|
|
138
|
+
done: !o
|
|
139
|
+
};
|
|
140
|
+
}
|
|
141
|
+
};
|
|
142
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
143
|
+
};
|
|
144
|
+
var __read = (void 0) && (void 0).__read || function(o, n) {
|
|
145
|
+
var m = typeof Symbol === "function" && o[Symbol.iterator];
|
|
146
|
+
if (!m) return o;
|
|
147
|
+
var i = m.call(o), r, ar = [], e;
|
|
148
|
+
try {
|
|
149
|
+
while((n === void 0 || n-- > 0) && !(r = i.next()).done)ar.push(r.value);
|
|
150
|
+
} catch (error) {
|
|
151
|
+
e = {
|
|
152
|
+
error: error
|
|
153
|
+
};
|
|
154
|
+
} finally{
|
|
155
|
+
try {
|
|
156
|
+
if (r && !r.done && (m = i["return"])) m.call(i);
|
|
157
|
+
} finally{
|
|
158
|
+
if (e) throw e.error;
|
|
159
|
+
}
|
|
160
|
+
}
|
|
161
|
+
return ar;
|
|
162
|
+
};
|
|
163
|
+
var __spreadArray = (void 0) && (void 0).__spreadArray || function(to, from, pack) {
|
|
164
|
+
if (pack || arguments.length === 2) for(var i = 0, l = from.length, ar; i < l; i++){
|
|
165
|
+
if (ar || !(i in from)) {
|
|
166
|
+
if (!ar) ar = Array.prototype.slice.call(from, 0, i);
|
|
167
|
+
ar[i] = from[i];
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
return to.concat(ar || Array.prototype.slice.call(from));
|
|
171
|
+
};
|
|
172
|
+
Object.defineProperty(exports, "__esModule", {
|
|
173
|
+
value: true
|
|
174
|
+
});
|
|
175
|
+
exports.ParamsMappingType = void 0;
|
|
176
|
+
var common_1 = require("./common");
|
|
177
|
+
var ParamsMappingType;
|
|
178
|
+
(function(ParamsMappingType) {
|
|
179
|
+
// 请求头
|
|
180
|
+
ParamsMappingType["HEADER"] = "HEADER";
|
|
181
|
+
// 查询串
|
|
182
|
+
ParamsMappingType["PARAM"] = "PARAM";
|
|
183
|
+
// 请求体
|
|
184
|
+
ParamsMappingType["BODY"] = "BODY";
|
|
185
|
+
// 路径变量
|
|
186
|
+
ParamsMappingType["PATH_VARIABLE"] = "PATH_VARIABLE";
|
|
187
|
+
})(ParamsMappingType || (exports.ParamsMappingType = ParamsMappingType = {}));
|
|
188
|
+
var RequestBuilder = /** @class */ function() {
|
|
189
|
+
function RequestBuilder() {
|
|
190
|
+
this._configs = null;
|
|
191
|
+
this._mapping = new Map();
|
|
192
|
+
this._pathVariablesMapping = [];
|
|
193
|
+
}
|
|
194
|
+
RequestBuilder.prototype._addMapping = function(type, mapping) {
|
|
195
|
+
var scopeMapping = this._mapping.get(type);
|
|
196
|
+
if (!scopeMapping) {
|
|
197
|
+
scopeMapping = new Map();
|
|
198
|
+
this._mapping.set(type, scopeMapping);
|
|
199
|
+
}
|
|
200
|
+
scopeMapping.set(mapping.key, mapping);
|
|
201
|
+
};
|
|
202
|
+
RequestBuilder.prototype._addPathVariablesMapping = function(mapping) {
|
|
203
|
+
this._pathVariablesMapping.push(mapping);
|
|
204
|
+
};
|
|
205
|
+
RequestBuilder.prototype._clearMapping = function(type) {
|
|
206
|
+
var scopeMapping = this._mapping.get(type);
|
|
207
|
+
if (scopeMapping) {
|
|
208
|
+
scopeMapping.clear();
|
|
209
|
+
}
|
|
210
|
+
};
|
|
211
|
+
RequestBuilder.prototype.param = function(keyOrMapping, required) {
|
|
212
|
+
if (typeof keyOrMapping === 'string') {
|
|
213
|
+
this._addMapping(ParamsMappingType.PARAM, {
|
|
214
|
+
value: undefined,
|
|
215
|
+
key: keyOrMapping,
|
|
216
|
+
// 查询串为空默认不填充
|
|
217
|
+
required: required === true
|
|
218
|
+
});
|
|
219
|
+
} else {
|
|
220
|
+
if ((0, common_1.isNullOrEmpty)(keyOrMapping.key)) {
|
|
221
|
+
throw new Error('param mapping key is required');
|
|
222
|
+
}
|
|
223
|
+
this._addMapping(ParamsMappingType.PARAM, __assign(__assign({}, keyOrMapping), {
|
|
224
|
+
required: keyOrMapping.required === true
|
|
225
|
+
}));
|
|
226
|
+
}
|
|
227
|
+
return this;
|
|
228
|
+
};
|
|
229
|
+
RequestBuilder.prototype.header = function(keyOrMapping, required) {
|
|
230
|
+
if (typeof keyOrMapping === 'string') {
|
|
231
|
+
this._addMapping(ParamsMappingType.HEADER, {
|
|
232
|
+
value: undefined,
|
|
233
|
+
key: keyOrMapping,
|
|
234
|
+
// 请求头默认强制填充,找不到填充空字符串
|
|
235
|
+
required: required !== false
|
|
236
|
+
});
|
|
237
|
+
} else {
|
|
238
|
+
if ((0, common_1.isNullOrEmpty)(keyOrMapping.key)) {
|
|
239
|
+
throw new Error('header mapping key is required');
|
|
240
|
+
}
|
|
241
|
+
this._addMapping(ParamsMappingType.HEADER, __assign(__assign({}, keyOrMapping), {
|
|
242
|
+
required: keyOrMapping.required === true
|
|
243
|
+
}));
|
|
244
|
+
}
|
|
245
|
+
return this;
|
|
246
|
+
};
|
|
247
|
+
// 请求体只有一个规则,因为不同请求体类型无法合并,请求体自动不存在则设置 null
|
|
248
|
+
RequestBuilder.prototype.body = function(keyOrMapping) {
|
|
249
|
+
this._clearMapping(ParamsMappingType.BODY);
|
|
250
|
+
if (typeof keyOrMapping === 'string') {
|
|
251
|
+
this._addMapping(ParamsMappingType.BODY, {
|
|
252
|
+
value: undefined,
|
|
253
|
+
key: keyOrMapping,
|
|
254
|
+
// 请求体 required 不生效,无法给出不同类型的默认值
|
|
255
|
+
required: false
|
|
256
|
+
});
|
|
257
|
+
} else {
|
|
258
|
+
if ((0, common_1.isNullOrEmpty)(keyOrMapping.key)) {
|
|
259
|
+
throw new Error('body mapping key is required');
|
|
260
|
+
}
|
|
261
|
+
this._addMapping(ParamsMappingType.BODY, __assign(__assign({}, keyOrMapping), {
|
|
262
|
+
required: false
|
|
263
|
+
}));
|
|
264
|
+
}
|
|
265
|
+
return this;
|
|
266
|
+
};
|
|
267
|
+
// 路径参数集合
|
|
268
|
+
// 路径参数数据源要求可合并并且不需要指定key,单独数据集合
|
|
269
|
+
RequestBuilder.prototype.pathVariable = function(keyOrMapping) {
|
|
270
|
+
if (typeof keyOrMapping === 'string') {
|
|
271
|
+
this._addPathVariablesMapping({
|
|
272
|
+
value: undefined,
|
|
273
|
+
key: keyOrMapping,
|
|
274
|
+
required: false // 必填参数无意义,占位符是固定的字符
|
|
275
|
+
});
|
|
276
|
+
} else {
|
|
277
|
+
this._addPathVariablesMapping(__assign(__assign({}, keyOrMapping), {
|
|
278
|
+
required: false
|
|
279
|
+
}));
|
|
280
|
+
}
|
|
281
|
+
return this;
|
|
282
|
+
};
|
|
283
|
+
RequestBuilder.prototype.config = function(cfg) {
|
|
284
|
+
if (!this._configs) {
|
|
285
|
+
this._configs = [];
|
|
286
|
+
}
|
|
287
|
+
if (this._configs.indexOf(cfg) === -1) {
|
|
288
|
+
this._configs.push(cfg);
|
|
289
|
+
}
|
|
290
|
+
return this;
|
|
291
|
+
};
|
|
292
|
+
RequestBuilder.prototype.build = function(config, path, method, source) {
|
|
293
|
+
var e_1, _a, _b, _c, e_2, _d, _e, _f, e_3, _g, e_4, _h;
|
|
294
|
+
if (source === void 0) {
|
|
295
|
+
source = {};
|
|
296
|
+
}
|
|
297
|
+
var params = {};
|
|
298
|
+
var headers = {};
|
|
299
|
+
var url = path.indexOf("http") >= 0 ? path : config.baseURL + (0, common_1.normalizePath)("/".concat(path));
|
|
300
|
+
var body = null;
|
|
301
|
+
// 处理查询串
|
|
302
|
+
var paramMapping = this._mapping.get(ParamsMappingType.PARAM);
|
|
303
|
+
if (paramMapping) {
|
|
304
|
+
try {
|
|
305
|
+
for(var paramMapping_1 = __values(paramMapping), paramMapping_1_1 = paramMapping_1.next(); !paramMapping_1_1.done; paramMapping_1_1 = paramMapping_1.next()){
|
|
306
|
+
var _j = __read(paramMapping_1_1.value, 2), key = _j[0], mapping = _j[1];
|
|
307
|
+
if (typeof mapping.value === 'function') {
|
|
308
|
+
var mapper = mapping.value;
|
|
309
|
+
var result = mapper.call(undefined, source);
|
|
310
|
+
if ((0, common_1.isNullOrEmpty)(result)) {
|
|
311
|
+
if (mapping.required === false) {
|
|
312
|
+
continue;
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
Object.assign(params, (_b = {}, _b[key] = result, _b));
|
|
316
|
+
} else {
|
|
317
|
+
// 如果指定了静态值,则使用静态值
|
|
318
|
+
var value = mapping.value;
|
|
319
|
+
if ((0, common_1.isNullOrEmpty)(value)) {
|
|
320
|
+
// 没有指定静态值,查询数据源
|
|
321
|
+
value = source[key];
|
|
322
|
+
}
|
|
323
|
+
if ((0, common_1.isNullOrEmpty)(value)) {
|
|
324
|
+
if (mapping.required === false) {
|
|
325
|
+
continue;
|
|
326
|
+
} else {
|
|
327
|
+
value = '';
|
|
328
|
+
}
|
|
329
|
+
}
|
|
330
|
+
Object.assign(params, (_c = {}, _c[key] = value, _c));
|
|
331
|
+
}
|
|
332
|
+
}
|
|
333
|
+
} catch (e_1_1) {
|
|
334
|
+
e_1 = {
|
|
335
|
+
error: e_1_1
|
|
336
|
+
};
|
|
337
|
+
} finally{
|
|
338
|
+
try {
|
|
339
|
+
if (paramMapping_1_1 && !paramMapping_1_1.done && (_a = paramMapping_1["return"])) _a.call(paramMapping_1);
|
|
340
|
+
} finally{
|
|
341
|
+
if (e_1) throw e_1.error;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
// 处理请求头
|
|
346
|
+
var headerMapping = this._mapping.get(ParamsMappingType.HEADER);
|
|
347
|
+
if (headerMapping) {
|
|
348
|
+
try {
|
|
349
|
+
for(var headerMapping_1 = __values(headerMapping), headerMapping_1_1 = headerMapping_1.next(); !headerMapping_1_1.done; headerMapping_1_1 = headerMapping_1.next()){
|
|
350
|
+
var _k = __read(headerMapping_1_1.value, 2), key = _k[0], mapping = _k[1];
|
|
351
|
+
if (typeof mapping.value === 'function') {
|
|
352
|
+
var mapper = mapping.value;
|
|
353
|
+
var result = mapper.call(undefined, source);
|
|
354
|
+
if ((0, common_1.isNullOrEmpty)(result)) {
|
|
355
|
+
if (mapping.required === true) {
|
|
356
|
+
result = '';
|
|
357
|
+
} else {
|
|
358
|
+
continue;
|
|
359
|
+
}
|
|
360
|
+
}
|
|
361
|
+
Object.assign(headers, (_e = {}, _e[key] = result, _e));
|
|
362
|
+
} else {
|
|
363
|
+
var value = mapping.value;
|
|
364
|
+
if ((0, common_1.isNullOrEmpty)(value)) {
|
|
365
|
+
value = source[key];
|
|
366
|
+
}
|
|
367
|
+
if ((0, common_1.isNullOrEmpty)(value)) {
|
|
368
|
+
if (mapping.required === false) {
|
|
369
|
+
continue;
|
|
370
|
+
} else {
|
|
371
|
+
value = '';
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
Object.assign(headers, (_f = {}, _f[key] = value, _f));
|
|
375
|
+
}
|
|
376
|
+
}
|
|
377
|
+
} catch (e_2_1) {
|
|
378
|
+
e_2 = {
|
|
379
|
+
error: e_2_1
|
|
380
|
+
};
|
|
381
|
+
} finally{
|
|
382
|
+
try {
|
|
383
|
+
if (headerMapping_1_1 && !headerMapping_1_1.done && (_d = headerMapping_1["return"])) _d.call(headerMapping_1);
|
|
384
|
+
} finally{
|
|
385
|
+
if (e_2) throw e_2.error;
|
|
386
|
+
}
|
|
387
|
+
}
|
|
388
|
+
}
|
|
389
|
+
// 处理请求体
|
|
390
|
+
var bodyMapping = this._mapping.get(ParamsMappingType.BODY);
|
|
391
|
+
if (bodyMapping) {
|
|
392
|
+
try {
|
|
393
|
+
for(var bodyMapping_1 = __values(bodyMapping), bodyMapping_1_1 = bodyMapping_1.next(); !bodyMapping_1_1.done; bodyMapping_1_1 = bodyMapping_1.next()){
|
|
394
|
+
var _l = __read(bodyMapping_1_1.value, 2), key = _l[0], mapping = _l[1];
|
|
395
|
+
if (typeof mapping.value === 'function') {
|
|
396
|
+
var mapper = mapping.value;
|
|
397
|
+
var result = mapper.call(undefined, source);
|
|
398
|
+
if (result === undefined) {
|
|
399
|
+
result = null;
|
|
400
|
+
}
|
|
401
|
+
body = result;
|
|
402
|
+
} else {
|
|
403
|
+
var value = mapping.value;
|
|
404
|
+
if ((0, common_1.isNullOrEmpty)(value)) {
|
|
405
|
+
value = source[key];
|
|
406
|
+
}
|
|
407
|
+
if (value === undefined) {
|
|
408
|
+
value = null;
|
|
409
|
+
}
|
|
410
|
+
body = value;
|
|
411
|
+
}
|
|
412
|
+
}
|
|
413
|
+
} catch (e_3_1) {
|
|
414
|
+
e_3 = {
|
|
415
|
+
error: e_3_1
|
|
416
|
+
};
|
|
417
|
+
} finally{
|
|
418
|
+
try {
|
|
419
|
+
if (bodyMapping_1_1 && !bodyMapping_1_1.done && (_g = bodyMapping_1["return"])) _g.call(bodyMapping_1);
|
|
420
|
+
} finally{
|
|
421
|
+
if (e_3) throw e_3.error;
|
|
422
|
+
}
|
|
423
|
+
}
|
|
424
|
+
}
|
|
425
|
+
var mergeConfigs = {
|
|
426
|
+
headers: headers,
|
|
427
|
+
url: url,
|
|
428
|
+
method: method,
|
|
429
|
+
data: body,
|
|
430
|
+
params: params
|
|
431
|
+
};
|
|
432
|
+
if (this._configs) {
|
|
433
|
+
mergeConfigs = common_1.mergeAxiosConfigs.apply(void 0, __spreadArray([], __read(this._configs.map(function(cfg) {
|
|
434
|
+
return (0, common_1.mergeAxiosConfigs)(mergeConfigs, typeof cfg === 'function' ? cfg(source) : cfg);
|
|
435
|
+
})), false));
|
|
436
|
+
}
|
|
437
|
+
var pathVariables = null;
|
|
438
|
+
if (this._pathVariablesMapping.length) {
|
|
439
|
+
pathVariables = {};
|
|
440
|
+
try {
|
|
441
|
+
for(var _m = __values(this._pathVariablesMapping), _o = _m.next(); !_o.done; _o = _m.next()){
|
|
442
|
+
var mapping = _o.value;
|
|
443
|
+
if (typeof mapping.value === 'function') {
|
|
444
|
+
Object.assign(pathVariables, mapping.value(source));
|
|
445
|
+
} else {
|
|
446
|
+
var value = mapping.value;
|
|
447
|
+
if ((0, common_1.isNullOrEmpty)(value)) {
|
|
448
|
+
if (!mapping.key) {
|
|
449
|
+
// 如果不指定key,则使用 source 数据源本体
|
|
450
|
+
// 所以,如果需要开启路径参数功能至少配置一个 @PathVariables()
|
|
451
|
+
value = source;
|
|
452
|
+
} else {
|
|
453
|
+
value = source[mapping.key];
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
if (value === undefined) {
|
|
457
|
+
// 说明找不到
|
|
458
|
+
value = null;
|
|
459
|
+
} else {
|
|
460
|
+
if (!(0, common_1.isPlainObject)(value)) {
|
|
461
|
+
console.error('check path variables collection is plain object: ', value);
|
|
462
|
+
value = null;
|
|
463
|
+
}
|
|
464
|
+
}
|
|
465
|
+
Object.assign(pathVariables, value);
|
|
466
|
+
}
|
|
467
|
+
}
|
|
468
|
+
} catch (e_4_1) {
|
|
469
|
+
e_4 = {
|
|
470
|
+
error: e_4_1
|
|
471
|
+
};
|
|
472
|
+
} finally{
|
|
473
|
+
try {
|
|
474
|
+
if (_o && !_o.done && (_h = _m["return"])) _h.call(_m);
|
|
475
|
+
} finally{
|
|
476
|
+
if (e_4) throw e_4.error;
|
|
477
|
+
}
|
|
478
|
+
}
|
|
479
|
+
}
|
|
480
|
+
if (pathVariables) {
|
|
481
|
+
// 路径变量不为空,认为有意图使用占位符
|
|
482
|
+
var url_1 = mergeConfigs.url;
|
|
483
|
+
if (url_1) {
|
|
484
|
+
// url 的声明为 String?
|
|
485
|
+
mergeConfigs.url = (0, common_1.formatUrl)(url_1, pathVariables);
|
|
486
|
+
}
|
|
487
|
+
var baseUrl = mergeConfigs.baseURL;
|
|
488
|
+
if (baseUrl) {
|
|
489
|
+
// 一般不会对 baseUrl 使用占位符
|
|
490
|
+
mergeConfigs.baseURL = (0, common_1.formatUrl)(baseUrl, pathVariables);
|
|
491
|
+
}
|
|
492
|
+
}
|
|
493
|
+
return mergeConfigs;
|
|
494
|
+
};
|
|
495
|
+
RequestBuilder.prototype.buildWith = function(config_1, path_1, method_1) {
|
|
496
|
+
return __awaiter(this, arguments, void 0, function(config, path, method, source) {
|
|
497
|
+
var axiosInstance;
|
|
498
|
+
if (source === void 0) {
|
|
499
|
+
source = {};
|
|
500
|
+
}
|
|
501
|
+
return __generator(this, function(_a) {
|
|
502
|
+
switch(_a.label){
|
|
503
|
+
case 0:
|
|
504
|
+
return [
|
|
505
|
+
4 /*yield*/ ,
|
|
506
|
+
config.requestAxiosInstance()
|
|
507
|
+
];
|
|
508
|
+
case 1:
|
|
509
|
+
axiosInstance = _a.sent();
|
|
510
|
+
return [
|
|
511
|
+
2 /*return*/ ,
|
|
512
|
+
axiosInstance.request(this.build(config, path, method, source))
|
|
513
|
+
];
|
|
514
|
+
}
|
|
515
|
+
});
|
|
516
|
+
});
|
|
517
|
+
};
|
|
518
|
+
return RequestBuilder;
|
|
519
|
+
}();
|
|
520
|
+
exports["default"] = RequestBuilder;
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import type { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import RequestBuilder from "./builder";
|
|
3
|
+
import Config from "./config";
|
|
4
|
+
export declare function normalizePath(path: string): string;
|
|
5
|
+
export declare function isNullOrEmpty(param: any): boolean;
|
|
6
|
+
type MetaPropertyDescriptor = PropertyDescriptor & {
|
|
7
|
+
builder: RequestBuilder;
|
|
8
|
+
config?: Config;
|
|
9
|
+
};
|
|
10
|
+
export declare function castToMetaDescriptor(descriptor: PropertyDescriptor): MetaPropertyDescriptor;
|
|
11
|
+
/**
|
|
12
|
+
* Merges multiple Axios request configurations with specific logic for Axios.
|
|
13
|
+
* - `headers` and `params` are shallowly merged.
|
|
14
|
+
* - All other properties are replaced by the last provided value.
|
|
15
|
+
*
|
|
16
|
+
* @param sources A list of AxiosRequestConfig objects to merge.
|
|
17
|
+
* @returns A new, merged AxiosRequestConfig object.
|
|
18
|
+
*/
|
|
19
|
+
export declare function mergeAxiosConfigs(...sources: AxiosRequestConfig[]): AxiosRequestConfig;
|
|
20
|
+
/**
|
|
21
|
+
* 替换链接占位符,注意使用基本类型
|
|
22
|
+
* Replaces placeholders in a URL with values from a data object.
|
|
23
|
+
* e.g., formatUrl("http://a.com/{c}?d={e}", {c: 'x', e: 100}) -> "http://a.com/x?d=100"
|
|
24
|
+
*
|
|
25
|
+
* @param url The URL string with placeholders like {key}.
|
|
26
|
+
* @param data The plain object data source.
|
|
27
|
+
* @returns The formatted URL string.
|
|
28
|
+
*/
|
|
29
|
+
export declare function formatUrl(url: string, data: Record<string, any>): string;
|
|
30
|
+
/**
|
|
31
|
+
* Checks if a value is a plain object, i.e., an object created by `{}` or `new Object()`.
|
|
32
|
+
* @param value The value to check.
|
|
33
|
+
* @returns True if the value is a plain object, false otherwise.
|
|
34
|
+
*/
|
|
35
|
+
export declare function isPlainObject(value: any): value is Record<string, any>;
|
|
36
|
+
export {};
|