axios-annotations 2.3.0 → 3.1.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.
Files changed (140) hide show
  1. package/README.md +774 -741
  2. package/es/core/builder.d.ts +33 -0
  3. package/es/core/builder.js +515 -0
  4. package/es/core/common.d.ts +36 -0
  5. package/es/core/common.js +148 -0
  6. package/es/core/config.d.ts +60 -0
  7. package/es/core/config.js +357 -0
  8. package/es/core/core-expect.js +3 -0
  9. package/es/core/expect.d.ts +2 -0
  10. package/es/core/expect.js +2 -0
  11. package/es/core/provider.d.ts +6 -0
  12. package/es/core/provider.js +172 -0
  13. package/es/core/service.d.ts +5 -0
  14. package/es/core/service.js +57 -0
  15. package/es/decorator/path-variables.d.ts +7 -0
  16. package/es/decorator/path-variables.js +32 -0
  17. package/es/decorator/request-body.d.ts +7 -0
  18. package/es/decorator/request-body.js +31 -0
  19. package/es/decorator/request-config.d.ts +7 -0
  20. package/es/decorator/request-config.js +25 -0
  21. package/es/decorator/request-header.d.ts +4 -0
  22. package/es/decorator/request-header.js +14 -0
  23. package/es/decorator/request-mapping.d.ts +6 -0
  24. package/es/decorator/request-mapping.js +56 -0
  25. package/es/decorator/request-param.d.ts +4 -0
  26. package/es/decorator/request-param.js +15 -0
  27. package/es/decorator/request-with.d.ts +3 -0
  28. package/es/decorator/request-with.js +8 -0
  29. package/es/index.d.ts +13 -0
  30. package/es/index.js +14 -0
  31. package/es/plugins/auth/authorizer.d.ts +24 -0
  32. package/es/plugins/auth/authorizer.js +268 -0
  33. package/es/plugins/auth/history.d.ts +15 -0
  34. package/es/plugins/auth/history.js +94 -0
  35. package/es/plugins/auth/index.d.ts +16 -0
  36. package/es/plugins/auth/index.js +358 -0
  37. package/es/plugins/auth/queue.d.ts +29 -0
  38. package/es/plugins/auth/queue.js +281 -0
  39. package/es/plugins/auth/storage.d.ts +6 -0
  40. package/es/plugins/auth/storage.js +203 -0
  41. package/lib/core/builder.d.ts +33 -0
  42. package/lib/core/builder.js +520 -0
  43. package/lib/core/common.d.ts +34 -4
  44. package/lib/core/common.js +139 -147
  45. package/lib/core/config.d.ts +15 -15
  46. package/lib/core/config.js +44 -14
  47. package/lib/core/core-expect.js +8 -0
  48. package/lib/core/expect.d.ts +2 -4
  49. package/lib/core/expect.js +6 -15
  50. package/lib/core/provider.d.ts +5 -5
  51. package/lib/core/provider.js +2 -2
  52. package/lib/core/service.d.ts +3 -151
  53. package/lib/core/service.js +43 -544
  54. package/lib/decorator/path-variables.d.ts +7 -0
  55. package/lib/decorator/path-variables.js +37 -0
  56. package/lib/decorator/request-body.d.ts +7 -1
  57. package/lib/decorator/request-body.js +28 -20
  58. package/lib/decorator/request-config.d.ts +6 -4
  59. package/lib/decorator/request-config.js +23 -16
  60. package/lib/decorator/request-header.d.ts +4 -2
  61. package/lib/decorator/request-header.js +11 -13
  62. package/lib/decorator/request-mapping.d.ts +6 -3
  63. package/lib/decorator/request-mapping.js +46 -43
  64. package/lib/decorator/request-param.d.ts +4 -1
  65. package/lib/decorator/request-param.js +12 -19
  66. package/lib/decorator/request-with.d.ts +3 -1
  67. package/lib/decorator/request-with.js +6 -13
  68. package/lib/index.d.ts +4 -11
  69. package/lib/index.js +19 -68
  70. package/lib/plugins/auth/authorizer.d.ts +6 -5
  71. package/lib/plugins/auth/authorizer.js +3 -2
  72. package/lib/plugins/auth/history.d.ts +5 -4
  73. package/lib/plugins/auth/history.js +2 -0
  74. package/lib/plugins/auth/index.d.ts +7 -0
  75. package/lib/plugins/auth/index.js +11 -3
  76. package/lib/plugins/auth/queue.d.ts +3 -2
  77. package/lib/plugins/auth/queue.js +31 -24
  78. package/lib/plugins/auth/storage.js +2 -2
  79. package/package.json +42 -7
  80. package/wechat-mp/core/builder.d.ts +33 -0
  81. package/wechat-mp/core/builder.js +520 -0
  82. package/wechat-mp/core/common.d.ts +36 -0
  83. package/wechat-mp/core/common.js +158 -0
  84. package/wechat-mp/core/config.d.ts +60 -0
  85. package/wechat-mp/core/config.js +362 -0
  86. package/wechat-mp/core/core-expect.js +8 -0
  87. package/wechat-mp/core/expect.d.ts +2 -0
  88. package/wechat-mp/core/expect.js +6 -0
  89. package/wechat-mp/core/provider.d.ts +6 -0
  90. package/wechat-mp/core/provider.js +178 -0
  91. package/wechat-mp/core/service.d.ts +5 -0
  92. package/wechat-mp/core/service.js +61 -0
  93. package/wechat-mp/decorator/path-variables.d.ts +7 -0
  94. package/wechat-mp/decorator/path-variables.js +37 -0
  95. package/wechat-mp/decorator/request-body.d.ts +7 -0
  96. package/wechat-mp/decorator/request-body.js +36 -0
  97. package/wechat-mp/decorator/request-config.d.ts +7 -0
  98. package/wechat-mp/decorator/request-config.js +30 -0
  99. package/wechat-mp/decorator/request-header.d.ts +4 -0
  100. package/wechat-mp/decorator/request-header.js +19 -0
  101. package/wechat-mp/decorator/request-mapping.d.ts +6 -0
  102. package/wechat-mp/decorator/request-mapping.js +61 -0
  103. package/wechat-mp/decorator/request-param.d.ts +4 -0
  104. package/wechat-mp/decorator/request-param.js +20 -0
  105. package/wechat-mp/decorator/request-with.d.ts +3 -0
  106. package/wechat-mp/decorator/request-with.js +13 -0
  107. package/wechat-mp/index.d.ts +13 -0
  108. package/wechat-mp/index.js +97 -0
  109. package/wechat-mp/plugins/auth/authorizer.d.ts +24 -0
  110. package/wechat-mp/plugins/auth/authorizer.js +272 -0
  111. package/wechat-mp/plugins/auth/history.d.ts +15 -0
  112. package/wechat-mp/plugins/auth/history.js +98 -0
  113. package/wechat-mp/plugins/auth/index.d.ts +16 -0
  114. package/wechat-mp/plugins/auth/index.js +376 -0
  115. package/wechat-mp/plugins/auth/queue.d.ts +29 -0
  116. package/wechat-mp/plugins/auth/queue.js +285 -0
  117. package/wechat-mp/plugins/auth/storage.d.ts +6 -0
  118. package/wechat-mp/plugins/auth/storage.js +207 -0
  119. package/index.d.ts +0 -1
  120. package/index.js +0 -127
  121. package/lib/core/cancel.d.ts +0 -30
  122. package/lib/core/cancel.js +0 -56
  123. package/lib/core/parser.d.ts +0 -19
  124. package/lib/core/parser.js +0 -79
  125. package/lib/decorator/abort-source.d.ts +0 -3
  126. package/lib/decorator/abort-source.js +0 -25
  127. package/lib/decorator/delete-mapping.d.ts +0 -1
  128. package/lib/decorator/delete-mapping.js +0 -13
  129. package/lib/decorator/get-mapping.d.ts +0 -1
  130. package/lib/decorator/get-mapping.js +0 -13
  131. package/lib/decorator/ignore-residual-params.d.ts +0 -1
  132. package/lib/decorator/ignore-residual-params.js +0 -24
  133. package/lib/decorator/patch-mapping.d.ts +0 -1
  134. package/lib/decorator/patch-mapping.js +0 -13
  135. package/lib/decorator/post-mapping.d.ts +0 -1
  136. package/lib/decorator/post-mapping.js +0 -13
  137. package/lib/decorator/put-mapping.d.ts +0 -1
  138. package/lib/decorator/put-mapping.js +0 -13
  139. package/plugins/auth/index.d.ts +0 -4
  140. 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
- // noinspection JSUnusedGlobalSymbols
7
- function RequestBody(name) {
8
- if (name === void 0) {
9
- name = "body";
10
- }
11
- return function(_target, method, descriptor) {
12
- if (descriptor) {
13
- var fn_1 = descriptor.value;
14
- var cfg_1 = {
15
- required: false,
16
- body: true
17
- };
18
- descriptor.value = function() {
19
- var args = [];
20
- for(var _i = 0; _i < arguments.length; _i++){
21
- args[_i] = arguments[_i];
22
- }
23
- this.params(method, name, cfg_1);
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 { AxiosConfigOptionMappingType } from "../core/service";
2
- import { Config } from "../index";
3
- type DecoratorTargetType<D> = D extends Config ? ClassDecorator : PropertyDecorator;
4
- export default function RequestConfig<T = AxiosConfigOptionMappingType | Config>(config: T): DecoratorTargetType<T>;
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
- // noinspection JSUnusedGlobalSymbols
6
+ var config_1 = require("../core/config");
7
+ var common_1 = require("../core/common");
7
8
  function RequestConfig(config) {
8
- return function(target, name, descriptor) {
9
- if (descriptor) {
10
- var fn_1 = descriptor.value;
11
- descriptor.value = function() {
12
- var args = [];
13
- for(var _i = 0; _i < arguments.length; _i++){
14
- args[_i] = arguments[_i];
15
- }
16
- this.configs(name, config);
17
- return fn_1.apply(this, args);
18
- };
19
- } else {
20
- target.prototype._config = config;
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 { HeaderMappingValueType } from "../core/service";
2
- export default function RequestHeader(header: string, value: HeaderMappingValueType): MethodDecorator;
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
- // noinspection JSUnusedGlobalSymbols
7
- function RequestHeader(header, value) {
8
- return function(_target, method, descriptor) {
9
- if (descriptor) {
10
- var fn_1 = descriptor.value;
11
- descriptor.value = function() {
12
- var args = [];
13
- for(var _i = 0; _i < arguments.length; _i++){
14
- args[_i] = arguments[_i];
15
- }
16
- this.headers(method, header, value);
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 DecoratorTargetType<M> = M extends string ? MethodDecorator : ClassDecorator;
2
- export default function RequestMapping<M = undefined>(path: string, method?: M | string): DecoratorTargetType<M>;
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
- return function(target, name, descriptor) {
10
- if (!descriptor) {
11
- // 注解类
12
- target.prototype._path = path;
13
- } else {
14
- // 不可能为空
15
- var fn_1 = descriptor.value;
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
- var data = fn_1.apply(this, args) || {};
23
- if (typeof this["for"] !== "function") {
24
- throw new Error("Make sure your service inherited \"core/Service\".");
25
- }
26
- // 当前方法是否重定向到其他配置
27
- var withConfigName = this["for"](name);
28
- // 根据名称获取配置
29
- var withConfig = config_1["default"].forName(withConfigName || "");
30
- if (data && data.then && typeof data.then === "function") {
31
- return new Promise(function(resolve, reject) {
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
- export default function RequestParam(name: string, required?: boolean): MethodDecorator;
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
- // noinspection JSUnusedGlobalSymbols
7
- function RequestParam(name, required) {
8
- return function(_target, method, descriptor) {
9
- if (descriptor) {
10
- var fn_1 = descriptor.value;
11
- var cfg_1 = Object.assign({
12
- required: false,
13
- body: false
14
- }, {
15
- required: required === true
16
- });
17
- descriptor.value = function() {
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
- export default function RequestWith(configName: string): MethodDecorator;
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
- function RequestWith(configName) {
7
- return function(_target, name, descriptor) {
8
- if (descriptor) {
9
- var fn_1 = descriptor.value;
10
- descriptor.value = function() {
11
- var args = [];
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.RequestWith = exports.RequestParam = exports.RequestMapping = exports.RequestHeader = exports.RequestConfig = exports.RequestBody = exports.PutMapping = exports.PostMapping = exports.PatchMapping = exports.IgnoreResidualParams = exports.GetMapping = exports.DeleteMapping = exports.AbortSource = exports.AxiosStaticInstanceProvider = exports.AbortControllerAdapter = exports.Service = exports.URLSearchParamsParser = exports.Expect = exports.config = exports.Config = void 0;
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 abort_source_1 = require("./decorator/abort-source");
57
- Object.defineProperty(exports, "AbortSource", {
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 patch_mapping_1["default"];
46
+ return request_config_1["default"];
89
47
  }
90
48
  });
91
- var post_mapping_1 = require("./decorator/post-mapping");
92
- Object.defineProperty(exports, "PostMapping", {
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 post_mapping_1["default"];
53
+ return request_mapping_1["default"];
96
54
  }
97
55
  });
98
- var put_mapping_1 = require("./decorator/put-mapping");
99
- Object.defineProperty(exports, "PutMapping", {
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 put_mapping_1["default"];
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 request_mapping_1 = require("./decorator/request-mapping");
127
- Object.defineProperty(exports, "RequestMapping", {
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 request_mapping_1["default"];
81
+ return request_with_1["default"];
131
82
  }
132
83
  });
133
- var request_param_1 = require("./decorator/request-param");
134
- Object.defineProperty(exports, "RequestParam", {
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 request_param_1["default"];
88
+ return path_variables_1["default"];
138
89
  }
139
90
  });
140
- var request_with_1 = require("./decorator/request-with");
141
- Object.defineProperty(exports, "RequestWith", {
91
+ var builder_1 = require("./core/builder");
92
+ Object.defineProperty(exports, "RequestBuilder", {
142
93
  enumerable: true,
143
94
  get: function get() {
144
- return request_with_1["default"];
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 type { AxiosResponse, InternalAxiosRequestConfig } from "axios";
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: Record<string, any>): Promise<void>;
16
- refreshSession(_session: Record<string, any>): Promise<any>;
17
- withAuthentication(request: InternalAxiosRequestConfig, session: Record<string, any>): void;
18
- checkSession(request: InternalAxiosRequestConfig, session: Record<string, any>): boolean;
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 = this && this.__awaiter || function(thisArg, _arguments, P, generator) {
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 = this && this.__generator || function(thisArg, body) {
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: (Record<string, any> | null)[];
6
+ _history: (BasicSession | null)[];
6
7
  _position: number;
7
8
  _size: number;
8
9
  get size(): number;
9
- add(session: Record<string, any>): void;
10
+ add(session: BasicSession): void;
10
11
  check(jwt: string): boolean;
11
- deprecate(session: Record<string, any>): void;
12
+ deprecate(session: BasicSession): void;
12
13
  clean(): void;
13
- isDeprecated(session: Record<string, any>): boolean;
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;