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,178 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = (void 0) && (void 0).__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 = (void 0) && (void 0).__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
|
+
Object.defineProperty(exports, "__esModule", {
|
|
121
|
+
value: true
|
|
122
|
+
});
|
|
123
|
+
var AxiosStaticInstanceProvider = /** @class */ function() {
|
|
124
|
+
function AxiosStaticInstanceProvider() {
|
|
125
|
+
this.__instance = null;
|
|
126
|
+
}
|
|
127
|
+
AxiosStaticInstanceProvider.prototype.provide = function() {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
129
|
+
var lib;
|
|
130
|
+
return __generator(this, function(_a) {
|
|
131
|
+
switch(_a.label){
|
|
132
|
+
case 0:
|
|
133
|
+
return [
|
|
134
|
+
4 /*yield*/ ,
|
|
135
|
+
Promise.resolve().then(function() {
|
|
136
|
+
return require("axios");
|
|
137
|
+
})
|
|
138
|
+
];
|
|
139
|
+
case 1:
|
|
140
|
+
lib = _a.sent();
|
|
141
|
+
return [
|
|
142
|
+
2 /*return*/ ,
|
|
143
|
+
lib["default"]
|
|
144
|
+
];
|
|
145
|
+
}
|
|
146
|
+
});
|
|
147
|
+
});
|
|
148
|
+
};
|
|
149
|
+
AxiosStaticInstanceProvider.prototype.get = function() {
|
|
150
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
151
|
+
var _a;
|
|
152
|
+
return __generator(this, function(_b) {
|
|
153
|
+
switch(_b.label){
|
|
154
|
+
case 0:
|
|
155
|
+
if (this.__instance) {
|
|
156
|
+
return [
|
|
157
|
+
2 /*return*/ ,
|
|
158
|
+
this.__instance
|
|
159
|
+
];
|
|
160
|
+
}
|
|
161
|
+
_a = this;
|
|
162
|
+
return [
|
|
163
|
+
4 /*yield*/ ,
|
|
164
|
+
this.provide()
|
|
165
|
+
];
|
|
166
|
+
case 1:
|
|
167
|
+
_a.__instance = _b.sent();
|
|
168
|
+
return [
|
|
169
|
+
2 /*return*/ ,
|
|
170
|
+
this.__instance
|
|
171
|
+
];
|
|
172
|
+
}
|
|
173
|
+
});
|
|
174
|
+
});
|
|
175
|
+
};
|
|
176
|
+
return AxiosStaticInstanceProvider;
|
|
177
|
+
}();
|
|
178
|
+
exports["default"] = AxiosStaticInstanceProvider;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
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
|
+
};
|
|
12
|
+
}
|
|
13
|
+
};
|
|
14
|
+
throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", {
|
|
17
|
+
value: true
|
|
18
|
+
});
|
|
19
|
+
var config_1 = require("./config");
|
|
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);
|
|
34
|
+
}
|
|
35
|
+
}
|
|
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;
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
if (target.__path) {
|
|
49
|
+
this.path = target.__path;
|
|
50
|
+
}
|
|
51
|
+
if (target.__config) {
|
|
52
|
+
this.config = target.__config;
|
|
53
|
+
}
|
|
54
|
+
Reflect.deleteProperty(target, '__path');
|
|
55
|
+
Reflect.deleteProperty(target, '__config');
|
|
56
|
+
Reflect.deleteProperty(target, '__decoratedMethods');
|
|
57
|
+
}
|
|
58
|
+
return Service;
|
|
59
|
+
}();
|
|
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
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
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 {};
|
|
@@ -0,0 +1,36 @@
|
|
|
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"] = RequestBody;
|
|
16
|
+
var common_1 = require("../core/common");
|
|
17
|
+
function RequestBody(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.body({
|
|
24
|
+
key: typeof keyOrMapping === 'string' ? keyOrMapping : 'body',
|
|
25
|
+
required: false,
|
|
26
|
+
value: undefined
|
|
27
|
+
});
|
|
28
|
+
} else {
|
|
29
|
+
builder.body(__assign(__assign({}, keyOrMapping), {
|
|
30
|
+
key: typeof keyOrMapping.key === 'string' ? keyOrMapping.key : 'body',
|
|
31
|
+
required: false
|
|
32
|
+
}));
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import type { AxiosRequestConfig } from 'axios';
|
|
2
|
+
import Config from "../core/config";
|
|
3
|
+
import { AxiosConfigMapper } from "../core/builder";
|
|
4
|
+
type ConfigType = Config | AxiosRequestConfig | AxiosConfigMapper;
|
|
5
|
+
type Decorator<T> = T extends Config ? ClassDecorator : PropertyDecorator;
|
|
6
|
+
export default function RequestConfig<T = ConfigType>(config: T): Decorator<T>;
|
|
7
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports["default"] = RequestConfig;
|
|
6
|
+
var config_1 = require("../core/config");
|
|
7
|
+
var common_1 = require("../core/common");
|
|
8
|
+
function RequestConfig(config) {
|
|
9
|
+
if (config instanceof config_1["default"]) {
|
|
10
|
+
// --- Class Decorator Logic ---
|
|
11
|
+
return function(constructor) {
|
|
12
|
+
var target = constructor.prototype;
|
|
13
|
+
if (config) {
|
|
14
|
+
Object.defineProperty(target, '__config', {
|
|
15
|
+
value: config,
|
|
16
|
+
enumerable: false,
|
|
17
|
+
configurable: true,
|
|
18
|
+
writable: false
|
|
19
|
+
});
|
|
20
|
+
}
|
|
21
|
+
return constructor;
|
|
22
|
+
};
|
|
23
|
+
} else {
|
|
24
|
+
// --- Method Decorator Logic ---
|
|
25
|
+
return function(target, propertyKey, descriptor) {
|
|
26
|
+
var metaDescriptor = (0, common_1.castToMetaDescriptor)(descriptor);
|
|
27
|
+
metaDescriptor.builder.config(config);
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type Service from "../core/service";
|
|
2
|
+
import { ParamsMapping } from "../core/builder";
|
|
3
|
+
export default function RequestHeader(mapping: ParamsMapping): (target: Service, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
4
|
+
export default function RequestHeader(key: string, required?: boolean): (target: Service, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports["default"] = RequestHeader;
|
|
6
|
+
var common_1 = require("../core/common");
|
|
7
|
+
function RequestHeader(keyOrMapping, required) {
|
|
8
|
+
return function(_target, propertyKey, descriptor) {
|
|
9
|
+
var metaDescriptor = (0, common_1.castToMetaDescriptor)(descriptor);
|
|
10
|
+
var builder = metaDescriptor.builder;
|
|
11
|
+
if (builder) {
|
|
12
|
+
if (typeof keyOrMapping === 'string') {
|
|
13
|
+
builder.header(keyOrMapping, required === true);
|
|
14
|
+
} else {
|
|
15
|
+
builder.header(keyOrMapping);
|
|
16
|
+
}
|
|
17
|
+
}
|
|
18
|
+
};
|
|
19
|
+
}
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
import type { Method } from 'axios';
|
|
2
|
+
import type Service from "../core/service";
|
|
3
|
+
export default function RequestMapping(path: string): <T extends {
|
|
4
|
+
new (...args: any[]): Service;
|
|
5
|
+
}>(constructor: T) => void;
|
|
6
|
+
export default function RequestMapping(path: string, method: Method): (target: Service, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports["default"] = RequestMapping;
|
|
6
|
+
var common_1 = require("../core/common");
|
|
7
|
+
// Implementation
|
|
8
|
+
function RequestMapping(path, method) {
|
|
9
|
+
if (method === undefined) {
|
|
10
|
+
// Class Decorator logic remains the same
|
|
11
|
+
return function(constructor) {
|
|
12
|
+
// 这里不用继承 extends constructor, 无法转换到 ES5
|
|
13
|
+
// 获取原型对象
|
|
14
|
+
var target = constructor.prototype;
|
|
15
|
+
if (path) {
|
|
16
|
+
Object.defineProperty(target, '__path', {
|
|
17
|
+
value: path,
|
|
18
|
+
enumerable: false,
|
|
19
|
+
configurable: true,
|
|
20
|
+
writable: false
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
return constructor;
|
|
24
|
+
};
|
|
25
|
+
} else {
|
|
26
|
+
// Method Decorator logic
|
|
27
|
+
return function(target, propertyKey, descriptor) {
|
|
28
|
+
// 在原型链上标记方法被替换,在 RequestConfig 中会重新绑定 this 指针。
|
|
29
|
+
// target 是类的原型对象
|
|
30
|
+
if (!Object.prototype.hasOwnProperty.call(target, '__decoratedMethods')) {
|
|
31
|
+
Object.defineProperty(target, '__decoratedMethods', {
|
|
32
|
+
value: [],
|
|
33
|
+
enumerable: false,
|
|
34
|
+
configurable: true,
|
|
35
|
+
writable: false
|
|
36
|
+
});
|
|
37
|
+
}
|
|
38
|
+
target.__decoratedMethods.push(propertyKey);
|
|
39
|
+
var originalMethod = descriptor.value;
|
|
40
|
+
var metaDescriptor = (0, common_1.castToMetaDescriptor)(descriptor);
|
|
41
|
+
// 这里没有使用箭头函数,this 运行时不确定 因此后续需要重新绑定
|
|
42
|
+
descriptor.value = function() {
|
|
43
|
+
var args = [];
|
|
44
|
+
for(var _i = 0; _i < arguments.length; _i++){
|
|
45
|
+
args[_i] = arguments[_i];
|
|
46
|
+
}
|
|
47
|
+
try {
|
|
48
|
+
var source = originalMethod.apply(this, args);
|
|
49
|
+
var service = this;
|
|
50
|
+
var usingConfig = metaDescriptor.config ? metaDescriptor.config : service.config;
|
|
51
|
+
var servicePrefix = service.path;
|
|
52
|
+
var requestPath = (0, common_1.normalizePath)("".concat(servicePrefix, "/").concat(path));
|
|
53
|
+
return metaDescriptor.builder.buildWith(usingConfig, requestPath, method, source);
|
|
54
|
+
} catch (error) {
|
|
55
|
+
console.error("Error in method '".concat(propertyKey, "'"), error);
|
|
56
|
+
throw error;
|
|
57
|
+
}
|
|
58
|
+
};
|
|
59
|
+
};
|
|
60
|
+
}
|
|
61
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type Service from "../core/service";
|
|
2
|
+
import { ParamsMapping } from "../core/builder";
|
|
3
|
+
export default function RequestParam(mapping: ParamsMapping): (target: Service, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
4
|
+
export default function RequestParam(key: string, required?: boolean): (target: Service, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports["default"] = RequestParam;
|
|
6
|
+
var common_1 = require("../core/common");
|
|
7
|
+
// 声明查询串参数
|
|
8
|
+
function RequestParam(keyOrMapping, required) {
|
|
9
|
+
return function(_target, propertyKey, descriptor) {
|
|
10
|
+
var metaDescriptor = (0, common_1.castToMetaDescriptor)(descriptor);
|
|
11
|
+
var builder = metaDescriptor.builder;
|
|
12
|
+
if (builder) {
|
|
13
|
+
if (typeof keyOrMapping === 'string') {
|
|
14
|
+
builder.param(keyOrMapping, required === true);
|
|
15
|
+
} else {
|
|
16
|
+
builder.param(keyOrMapping);
|
|
17
|
+
}
|
|
18
|
+
}
|
|
19
|
+
};
|
|
20
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports["default"] = RequestWith;
|
|
6
|
+
var common_1 = require("../core/common");
|
|
7
|
+
// 重定向方法的配置
|
|
8
|
+
function RequestWith(config) {
|
|
9
|
+
return function(_target, propertyKey, descriptor) {
|
|
10
|
+
var metaDescriptor = (0, common_1.castToMetaDescriptor)(descriptor);
|
|
11
|
+
metaDescriptor.config = config;
|
|
12
|
+
};
|
|
13
|
+
}
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
export { default as Config } from "./core/config";
|
|
2
|
+
export { config } from "./core/config";
|
|
3
|
+
export { default as Expect } from "./core/expect";
|
|
4
|
+
export { default as Service } from "./core/service";
|
|
5
|
+
export { default as AxiosStaticInstanceProvider } from "./core/provider";
|
|
6
|
+
export { default as RequestConfig } from "./decorator/request-config";
|
|
7
|
+
export { default as RequestMapping } from "./decorator/request-mapping";
|
|
8
|
+
export { default as RequestParam } from "./decorator/request-param";
|
|
9
|
+
export { default as RequestBody } from "./decorator/request-body";
|
|
10
|
+
export { default as RequestHeader } from "./decorator/request-header";
|
|
11
|
+
export { default as RequestWith } from "./decorator/request-with";
|
|
12
|
+
export { default as PathVariables } from "./decorator/path-variables";
|
|
13
|
+
export { default as RequestBuilder } from "./core/builder";
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// noinspection JSUnusedGlobalSymbols
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.RequestBuilder = exports.PathVariables = exports.RequestWith = exports.RequestHeader = exports.RequestBody = exports.RequestParam = exports.RequestMapping = exports.RequestConfig = exports.AxiosStaticInstanceProvider = exports.Service = exports.Expect = exports.config = exports.Config = void 0;
|
|
7
|
+
var config_1 = require("./core/config");
|
|
8
|
+
Object.defineProperty(exports, "Config", {
|
|
9
|
+
enumerable: true,
|
|
10
|
+
get: function get() {
|
|
11
|
+
return config_1["default"];
|
|
12
|
+
}
|
|
13
|
+
});
|
|
14
|
+
var config_2 = require("./core/config");
|
|
15
|
+
Object.defineProperty(exports, "config", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function get() {
|
|
18
|
+
return config_2.config;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
var expect_1 = require("./core/expect");
|
|
22
|
+
Object.defineProperty(exports, "Expect", {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function get() {
|
|
25
|
+
return expect_1["default"];
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
var service_1 = require("./core/service");
|
|
29
|
+
Object.defineProperty(exports, "Service", {
|
|
30
|
+
enumerable: true,
|
|
31
|
+
get: function get() {
|
|
32
|
+
return service_1["default"];
|
|
33
|
+
}
|
|
34
|
+
});
|
|
35
|
+
var provider_1 = require("./core/provider");
|
|
36
|
+
Object.defineProperty(exports, "AxiosStaticInstanceProvider", {
|
|
37
|
+
enumerable: true,
|
|
38
|
+
get: function get() {
|
|
39
|
+
return provider_1["default"];
|
|
40
|
+
}
|
|
41
|
+
});
|
|
42
|
+
var request_config_1 = require("./decorator/request-config");
|
|
43
|
+
Object.defineProperty(exports, "RequestConfig", {
|
|
44
|
+
enumerable: true,
|
|
45
|
+
get: function get() {
|
|
46
|
+
return request_config_1["default"];
|
|
47
|
+
}
|
|
48
|
+
});
|
|
49
|
+
var request_mapping_1 = require("./decorator/request-mapping");
|
|
50
|
+
Object.defineProperty(exports, "RequestMapping", {
|
|
51
|
+
enumerable: true,
|
|
52
|
+
get: function get() {
|
|
53
|
+
return request_mapping_1["default"];
|
|
54
|
+
}
|
|
55
|
+
});
|
|
56
|
+
var request_param_1 = require("./decorator/request-param");
|
|
57
|
+
Object.defineProperty(exports, "RequestParam", {
|
|
58
|
+
enumerable: true,
|
|
59
|
+
get: function get() {
|
|
60
|
+
return request_param_1["default"];
|
|
61
|
+
}
|
|
62
|
+
});
|
|
63
|
+
var request_body_1 = require("./decorator/request-body");
|
|
64
|
+
Object.defineProperty(exports, "RequestBody", {
|
|
65
|
+
enumerable: true,
|
|
66
|
+
get: function get() {
|
|
67
|
+
return request_body_1["default"];
|
|
68
|
+
}
|
|
69
|
+
});
|
|
70
|
+
var request_header_1 = require("./decorator/request-header");
|
|
71
|
+
Object.defineProperty(exports, "RequestHeader", {
|
|
72
|
+
enumerable: true,
|
|
73
|
+
get: function get() {
|
|
74
|
+
return request_header_1["default"];
|
|
75
|
+
}
|
|
76
|
+
});
|
|
77
|
+
var request_with_1 = require("./decorator/request-with");
|
|
78
|
+
Object.defineProperty(exports, "RequestWith", {
|
|
79
|
+
enumerable: true,
|
|
80
|
+
get: function get() {
|
|
81
|
+
return request_with_1["default"];
|
|
82
|
+
}
|
|
83
|
+
});
|
|
84
|
+
var path_variables_1 = require("./decorator/path-variables");
|
|
85
|
+
Object.defineProperty(exports, "PathVariables", {
|
|
86
|
+
enumerable: true,
|
|
87
|
+
get: function get() {
|
|
88
|
+
return path_variables_1["default"];
|
|
89
|
+
}
|
|
90
|
+
});
|
|
91
|
+
var builder_1 = require("./core/builder");
|
|
92
|
+
Object.defineProperty(exports, "RequestBuilder", {
|
|
93
|
+
enumerable: true,
|
|
94
|
+
get: function get() {
|
|
95
|
+
return builder_1["default"];
|
|
96
|
+
}
|
|
97
|
+
});
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
import type { InternalAxiosRequestConfig, AxiosResponse } from 'axios';
|
|
2
|
+
import SessionStorage from "./storage";
|
|
3
|
+
import SessionHistory from "./history";
|
|
4
|
+
import { BasicSession } from "./index";
|
|
5
|
+
export default class Authorizer {
|
|
6
|
+
private _sessionKey;
|
|
7
|
+
private _sessionStorage;
|
|
8
|
+
private _sessionHistory;
|
|
9
|
+
get sessionKey(): string;
|
|
10
|
+
set sessionKey(value: string);
|
|
11
|
+
get sessionStorage(): SessionStorage;
|
|
12
|
+
set sessionStorage(value: SessionStorage);
|
|
13
|
+
get sessionHistory(): SessionHistory;
|
|
14
|
+
set sessionHistory(value: SessionHistory);
|
|
15
|
+
getSession(): Promise<any>;
|
|
16
|
+
storageSession(session: BasicSession | null): Promise<void>;
|
|
17
|
+
refreshSession(_session: BasicSession): Promise<any>;
|
|
18
|
+
withAuthentication(request: InternalAxiosRequestConfig, session: BasicSession): void;
|
|
19
|
+
checkSession(request: InternalAxiosRequestConfig, session: BasicSession): boolean;
|
|
20
|
+
checkResponse(response: AxiosResponse): boolean;
|
|
21
|
+
onAuthorizedDenied(error: unknown): Promise<void>;
|
|
22
|
+
onSessionInvalidated(): void;
|
|
23
|
+
invalidateSession(): Promise<void>;
|
|
24
|
+
}
|