axios-annotations 2.2.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/LICENSE +21 -21
- package/README.md +977 -944
- 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 +2 -11
- 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 +40 -25
- package/lib/plugins/auth/storage.js +2 -2
- package/package.json +51 -16
- 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
|
@@ -1,28 +1,36 @@
|
|
|
1
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
|
+
};
|
|
2
12
|
Object.defineProperty(exports, "__esModule", {
|
|
3
13
|
value: true
|
|
4
14
|
});
|
|
5
15
|
exports["default"] = RequestBody;
|
|
6
|
-
|
|
7
|
-
function RequestBody(
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
}
|
|
23
|
-
|
|
24
|
-
return fn_1.apply(this, args);
|
|
25
|
-
};
|
|
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
|
+
}
|
|
26
34
|
}
|
|
27
35
|
};
|
|
28
36
|
}
|
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
|
|
4
|
-
|
|
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>;
|
|
5
7
|
export {};
|
|
@@ -3,21 +3,28 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports["default"] = RequestConfig;
|
|
6
|
-
|
|
6
|
+
var config_1 = require("../core/config");
|
|
7
|
+
var common_1 = require("../core/common");
|
|
7
8
|
function RequestConfig(config) {
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
}
|
|
22
|
-
}
|
|
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
|
+
}
|
|
23
30
|
}
|
|
@@ -1,2 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
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;
|
|
@@ -3,19 +3,17 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports["default"] = RequestHeader;
|
|
6
|
-
|
|
7
|
-
function RequestHeader(
|
|
8
|
-
return function(_target,
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
return fn_1.apply(this, args);
|
|
18
|
-
};
|
|
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
|
+
}
|
|
19
17
|
}
|
|
20
18
|
};
|
|
21
19
|
}
|
|
@@ -1,3 +1,6 @@
|
|
|
1
|
-
type
|
|
2
|
-
|
|
3
|
-
export {
|
|
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;
|
|
@@ -3,56 +3,59 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports["default"] = RequestMapping;
|
|
6
|
-
var config_1 = require("../core/config");
|
|
7
6
|
var common_1 = require("../core/common");
|
|
7
|
+
// Implementation
|
|
8
8
|
function RequestMapping(path, method) {
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
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 运行时不确定 因此后续需要重新绑定
|
|
16
42
|
descriptor.value = function() {
|
|
17
|
-
var _this = this;
|
|
18
43
|
var args = [];
|
|
19
44
|
for(var _i = 0; _i < arguments.length; _i++){
|
|
20
45
|
args[_i] = arguments[_i];
|
|
21
46
|
}
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
data.then(function(d) {
|
|
33
|
-
var _a = _this.createRequestConfig(name, _this.pathVariable(path || "", d), d, args, args), p = _a.path, body = _a.body, config = _a.config, query = _a.query;
|
|
34
|
-
if (withConfig) {
|
|
35
|
-
withConfig.requestAxiosInstance().then(function(axios) {
|
|
36
|
-
(0, common_1.forward)(axios, withConfig.origin, withConfig.prefix, _this.path, path, (0, common_1.mapToDefaultMethod)(method, "GET"), query, body, config).then(resolve)["catch"](reject);
|
|
37
|
-
});
|
|
38
|
-
} else {
|
|
39
|
-
_this.request((0, common_1.mapToDefaultMethod)(method, "GET"), p, body, config).then(resolve)["catch"](reject);
|
|
40
|
-
}
|
|
41
|
-
});
|
|
42
|
-
});
|
|
43
|
-
} else {
|
|
44
|
-
var _a = this.createRequestConfig(name, this.pathVariable(path || "", data), data, args, args), p = _a.path, body_1 = _a.body, config_2 = _a.config, query_1 = _a.query;
|
|
45
|
-
if (withConfig) {
|
|
46
|
-
return new Promise(function(resolve, reject) {
|
|
47
|
-
withConfig.requestAxiosInstance().then(function(axios) {
|
|
48
|
-
return (0, common_1.forward)(axios, withConfig.origin, withConfig.prefix, _this.path, path, (0, common_1.mapToDefaultMethod)(method, "GET"), query_1, body_1, config_2).then(resolve)["catch"](reject);
|
|
49
|
-
});
|
|
50
|
-
});
|
|
51
|
-
} else {
|
|
52
|
-
return this.request((0, common_1.mapToDefaultMethod)(method, "GET"), p, body_1, config_2);
|
|
53
|
-
}
|
|
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;
|
|
54
57
|
}
|
|
55
58
|
};
|
|
56
|
-
}
|
|
57
|
-
}
|
|
59
|
+
};
|
|
60
|
+
}
|
|
58
61
|
}
|
|
@@ -1 +1,4 @@
|
|
|
1
|
-
|
|
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;
|
|
@@ -3,25 +3,18 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports["default"] = RequestParam;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
var args = [];
|
|
19
|
-
for(var _i = 0; _i < arguments.length; _i++){
|
|
20
|
-
args[_i] = arguments[_i];
|
|
21
|
-
}
|
|
22
|
-
this.params(method, name, cfg_1);
|
|
23
|
-
return fn_1.apply(this, args);
|
|
24
|
-
};
|
|
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
|
+
}
|
|
25
18
|
}
|
|
26
19
|
};
|
|
27
20
|
}
|
|
@@ -1 +1,3 @@
|
|
|
1
|
-
|
|
1
|
+
import type Service from "../core/service";
|
|
2
|
+
import Config from "../core/config";
|
|
3
|
+
export default function RequestWith(config: Config): <T extends Service>(_target: T, propertyKey: string, descriptor: PropertyDescriptor) => void;
|
|
@@ -3,18 +3,11 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
3
3
|
value: true
|
|
4
4
|
});
|
|
5
5
|
exports["default"] = RequestWith;
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
for(var _i = 0; _i < arguments.length; _i++){
|
|
13
|
-
args[_i] = arguments[_i];
|
|
14
|
-
}
|
|
15
|
-
this["for"](name, configName);
|
|
16
|
-
return fn_1.apply(this, args);
|
|
17
|
-
};
|
|
18
|
-
}
|
|
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;
|
|
19
12
|
};
|
|
20
13
|
}
|
package/lib/index.d.ts
CHANGED
|
@@ -1,20 +1,13 @@
|
|
|
1
1
|
export { default as Config } from "./core/config";
|
|
2
2
|
export { config } from "./core/config";
|
|
3
3
|
export { default as Expect } from "./core/expect";
|
|
4
|
-
export { default as URLSearchParamsParser } from "./core/parser";
|
|
5
4
|
export { default as Service } from "./core/service";
|
|
6
|
-
export { default as AbortControllerAdapter } from "./core/cancel";
|
|
7
5
|
export { default as AxiosStaticInstanceProvider } from "./core/provider";
|
|
8
|
-
export { default as AbortSource } from "./decorator/abort-source";
|
|
9
|
-
export { default as DeleteMapping } from "./decorator/delete-mapping";
|
|
10
|
-
export { default as GetMapping } from "./decorator/get-mapping";
|
|
11
|
-
export { default as IgnoreResidualParams } from "./decorator/ignore-residual-params";
|
|
12
|
-
export { default as PatchMapping } from "./decorator/patch-mapping";
|
|
13
|
-
export { default as PostMapping } from "./decorator/post-mapping";
|
|
14
|
-
export { default as PutMapping } from "./decorator/put-mapping";
|
|
15
|
-
export { default as RequestBody } from "./decorator/request-body";
|
|
16
6
|
export { default as RequestConfig } from "./decorator/request-config";
|
|
17
|
-
export { default as RequestHeader } from "./decorator/request-header";
|
|
18
7
|
export { default as RequestMapping } from "./decorator/request-mapping";
|
|
19
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";
|
|
20
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";
|
package/lib/index.js
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", {
|
|
4
4
|
value: true
|
|
5
5
|
});
|
|
6
|
-
exports.
|
|
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
7
|
var config_1 = require("./core/config");
|
|
8
8
|
Object.defineProperty(exports, "Config", {
|
|
9
9
|
enumerable: true,
|
|
@@ -25,13 +25,6 @@ Object.defineProperty(exports, "Expect", {
|
|
|
25
25
|
return expect_1["default"];
|
|
26
26
|
}
|
|
27
27
|
});
|
|
28
|
-
var parser_1 = require("./core/parser");
|
|
29
|
-
Object.defineProperty(exports, "URLSearchParamsParser", {
|
|
30
|
-
enumerable: true,
|
|
31
|
-
get: function get() {
|
|
32
|
-
return parser_1["default"];
|
|
33
|
-
}
|
|
34
|
-
});
|
|
35
28
|
var service_1 = require("./core/service");
|
|
36
29
|
Object.defineProperty(exports, "Service", {
|
|
37
30
|
enumerable: true,
|
|
@@ -39,13 +32,6 @@ Object.defineProperty(exports, "Service", {
|
|
|
39
32
|
return service_1["default"];
|
|
40
33
|
}
|
|
41
34
|
});
|
|
42
|
-
var cancel_1 = require("./core/cancel");
|
|
43
|
-
Object.defineProperty(exports, "AbortControllerAdapter", {
|
|
44
|
-
enumerable: true,
|
|
45
|
-
get: function get() {
|
|
46
|
-
return cancel_1["default"];
|
|
47
|
-
}
|
|
48
|
-
});
|
|
49
35
|
var provider_1 = require("./core/provider");
|
|
50
36
|
Object.defineProperty(exports, "AxiosStaticInstanceProvider", {
|
|
51
37
|
enumerable: true,
|
|
@@ -53,53 +39,25 @@ Object.defineProperty(exports, "AxiosStaticInstanceProvider", {
|
|
|
53
39
|
return provider_1["default"];
|
|
54
40
|
}
|
|
55
41
|
});
|
|
56
|
-
var
|
|
57
|
-
Object.defineProperty(exports, "
|
|
58
|
-
enumerable: true,
|
|
59
|
-
get: function get() {
|
|
60
|
-
return abort_source_1["default"];
|
|
61
|
-
}
|
|
62
|
-
});
|
|
63
|
-
var delete_mapping_1 = require("./decorator/delete-mapping");
|
|
64
|
-
Object.defineProperty(exports, "DeleteMapping", {
|
|
65
|
-
enumerable: true,
|
|
66
|
-
get: function get() {
|
|
67
|
-
return delete_mapping_1["default"];
|
|
68
|
-
}
|
|
69
|
-
});
|
|
70
|
-
var get_mapping_1 = require("./decorator/get-mapping");
|
|
71
|
-
Object.defineProperty(exports, "GetMapping", {
|
|
72
|
-
enumerable: true,
|
|
73
|
-
get: function get() {
|
|
74
|
-
return get_mapping_1["default"];
|
|
75
|
-
}
|
|
76
|
-
});
|
|
77
|
-
var ignore_residual_params_1 = require("./decorator/ignore-residual-params");
|
|
78
|
-
Object.defineProperty(exports, "IgnoreResidualParams", {
|
|
79
|
-
enumerable: true,
|
|
80
|
-
get: function get() {
|
|
81
|
-
return ignore_residual_params_1["default"];
|
|
82
|
-
}
|
|
83
|
-
});
|
|
84
|
-
var patch_mapping_1 = require("./decorator/patch-mapping");
|
|
85
|
-
Object.defineProperty(exports, "PatchMapping", {
|
|
42
|
+
var request_config_1 = require("./decorator/request-config");
|
|
43
|
+
Object.defineProperty(exports, "RequestConfig", {
|
|
86
44
|
enumerable: true,
|
|
87
45
|
get: function get() {
|
|
88
|
-
return
|
|
46
|
+
return request_config_1["default"];
|
|
89
47
|
}
|
|
90
48
|
});
|
|
91
|
-
var
|
|
92
|
-
Object.defineProperty(exports, "
|
|
49
|
+
var request_mapping_1 = require("./decorator/request-mapping");
|
|
50
|
+
Object.defineProperty(exports, "RequestMapping", {
|
|
93
51
|
enumerable: true,
|
|
94
52
|
get: function get() {
|
|
95
|
-
return
|
|
53
|
+
return request_mapping_1["default"];
|
|
96
54
|
}
|
|
97
55
|
});
|
|
98
|
-
var
|
|
99
|
-
Object.defineProperty(exports, "
|
|
56
|
+
var request_param_1 = require("./decorator/request-param");
|
|
57
|
+
Object.defineProperty(exports, "RequestParam", {
|
|
100
58
|
enumerable: true,
|
|
101
59
|
get: function get() {
|
|
102
|
-
return
|
|
60
|
+
return request_param_1["default"];
|
|
103
61
|
}
|
|
104
62
|
});
|
|
105
63
|
var request_body_1 = require("./decorator/request-body");
|
|
@@ -109,13 +67,6 @@ Object.defineProperty(exports, "RequestBody", {
|
|
|
109
67
|
return request_body_1["default"];
|
|
110
68
|
}
|
|
111
69
|
});
|
|
112
|
-
var request_config_1 = require("./decorator/request-config");
|
|
113
|
-
Object.defineProperty(exports, "RequestConfig", {
|
|
114
|
-
enumerable: true,
|
|
115
|
-
get: function get() {
|
|
116
|
-
return request_config_1["default"];
|
|
117
|
-
}
|
|
118
|
-
});
|
|
119
70
|
var request_header_1 = require("./decorator/request-header");
|
|
120
71
|
Object.defineProperty(exports, "RequestHeader", {
|
|
121
72
|
enumerable: true,
|
|
@@ -123,24 +74,24 @@ Object.defineProperty(exports, "RequestHeader", {
|
|
|
123
74
|
return request_header_1["default"];
|
|
124
75
|
}
|
|
125
76
|
});
|
|
126
|
-
var
|
|
127
|
-
Object.defineProperty(exports, "
|
|
77
|
+
var request_with_1 = require("./decorator/request-with");
|
|
78
|
+
Object.defineProperty(exports, "RequestWith", {
|
|
128
79
|
enumerable: true,
|
|
129
80
|
get: function get() {
|
|
130
|
-
return
|
|
81
|
+
return request_with_1["default"];
|
|
131
82
|
}
|
|
132
83
|
});
|
|
133
|
-
var
|
|
134
|
-
Object.defineProperty(exports, "
|
|
84
|
+
var path_variables_1 = require("./decorator/path-variables");
|
|
85
|
+
Object.defineProperty(exports, "PathVariables", {
|
|
135
86
|
enumerable: true,
|
|
136
87
|
get: function get() {
|
|
137
|
-
return
|
|
88
|
+
return path_variables_1["default"];
|
|
138
89
|
}
|
|
139
90
|
});
|
|
140
|
-
var
|
|
141
|
-
Object.defineProperty(exports, "
|
|
91
|
+
var builder_1 = require("./core/builder");
|
|
92
|
+
Object.defineProperty(exports, "RequestBuilder", {
|
|
142
93
|
enumerable: true,
|
|
143
94
|
get: function get() {
|
|
144
|
-
return
|
|
95
|
+
return builder_1["default"];
|
|
145
96
|
}
|
|
146
97
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
import type { InternalAxiosRequestConfig, AxiosResponse } from 'axios';
|
|
1
2
|
import SessionStorage from "./storage";
|
|
2
3
|
import SessionHistory from "./history";
|
|
3
|
-
import
|
|
4
|
+
import { BasicSession } from "./index";
|
|
4
5
|
export default class Authorizer {
|
|
5
6
|
private _sessionKey;
|
|
6
7
|
private _sessionStorage;
|
|
@@ -12,10 +13,10 @@ export default class Authorizer {
|
|
|
12
13
|
get sessionHistory(): SessionHistory;
|
|
13
14
|
set sessionHistory(value: SessionHistory);
|
|
14
15
|
getSession(): Promise<any>;
|
|
15
|
-
storageSession(session:
|
|
16
|
-
refreshSession(_session:
|
|
17
|
-
withAuthentication(request: InternalAxiosRequestConfig, session:
|
|
18
|
-
checkSession(request: InternalAxiosRequestConfig, session:
|
|
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;
|
|
19
20
|
checkResponse(response: AxiosResponse): boolean;
|
|
20
21
|
onAuthorizedDenied(error: unknown): Promise<void>;
|
|
21
22
|
onSessionInvalidated(): void;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __awaiter =
|
|
2
|
+
var __awaiter = (void 0) && (void 0).__awaiter || function(thisArg, _arguments, P, generator) {
|
|
3
3
|
function adopt(value) {
|
|
4
4
|
return value instanceof P ? value : new P(function(resolve) {
|
|
5
5
|
resolve(value);
|
|
@@ -26,7 +26,7 @@ var __awaiter = this && this.__awaiter || function(thisArg, _arguments, P, gener
|
|
|
26
26
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
27
|
});
|
|
28
28
|
};
|
|
29
|
-
var __generator =
|
|
29
|
+
var __generator = (void 0) && (void 0).__generator || function(thisArg, body) {
|
|
30
30
|
var _ = {
|
|
31
31
|
label: 0,
|
|
32
32
|
sent: function sent() {
|
|
@@ -215,6 +215,7 @@ var Authorizer = /** @class */ function() {
|
|
|
215
215
|
}
|
|
216
216
|
}
|
|
217
217
|
};
|
|
218
|
+
// 匹配队列中的请求头token跟会话token是否一致
|
|
218
219
|
Authorizer.prototype.checkSession = function(request, session) {
|
|
219
220
|
var header = (request.headers || {})["Authorization"] || (request.headers || {})["authorization"];
|
|
220
221
|
var jwt = typeof header === "string" ? header.split(" ")[1] || "" : "";
|
|
@@ -1,14 +1,15 @@
|
|
|
1
|
+
import { BasicSession } from "./index";
|
|
1
2
|
/**
|
|
2
3
|
* 缓存过期会话,判断请求是否过期
|
|
3
4
|
*/
|
|
4
5
|
export default class SessionHistory {
|
|
5
|
-
_history: (
|
|
6
|
+
_history: (BasicSession | null)[];
|
|
6
7
|
_position: number;
|
|
7
8
|
_size: number;
|
|
8
9
|
get size(): number;
|
|
9
|
-
add(session:
|
|
10
|
+
add(session: BasicSession): void;
|
|
10
11
|
check(jwt: string): boolean;
|
|
11
|
-
deprecate(session:
|
|
12
|
+
deprecate(session: BasicSession): void;
|
|
12
13
|
clean(): void;
|
|
13
|
-
isDeprecated(session:
|
|
14
|
+
isDeprecated(session: BasicSession): boolean;
|
|
14
15
|
}
|
|
@@ -21,6 +21,8 @@ var common_1 = require("../../core/common");
|
|
|
21
21
|
configurable: true
|
|
22
22
|
});
|
|
23
23
|
// store primary keys for session
|
|
24
|
+
// 缓存 session 历史,这里只是添加并未作废,防止同时存在多个有效 session,这里允许存放有效 session
|
|
25
|
+
// 使用 invalid 作为标记
|
|
24
26
|
SessionHistory.prototype.add = function(session) {
|
|
25
27
|
if (Object.keys(session).every(function(i) {
|
|
26
28
|
return (0, common_1.isNullOrEmpty)(session[i]);
|
|
@@ -2,6 +2,13 @@ import Authorizer from "./authorizer";
|
|
|
2
2
|
import type { ConfigPlugin } from "../../core/config";
|
|
3
3
|
export { default as Authorizer } from "./authorizer";
|
|
4
4
|
export { default as SessionStorage } from "./storage";
|
|
5
|
+
export type BasicSession = {
|
|
6
|
+
access_token?: string;
|
|
7
|
+
accessToken?: string;
|
|
8
|
+
token?: string;
|
|
9
|
+
refreshToken?: string;
|
|
10
|
+
refresh_token?: string;
|
|
11
|
+
} & Record<string, any>;
|
|
5
12
|
export default function AuthorizationPlugin(authorizer: Authorizer, options?: {
|
|
6
13
|
minTryRetryInterval: number;
|
|
7
14
|
maxTryRetryInterval: number;
|