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
@@ -0,0 +1,172 @@
1
+ var __awaiter = this && this.__awaiter || function(thisArg, _arguments, P, generator) {
2
+ function adopt(value) {
3
+ return value instanceof P ? value : new P(function(resolve) {
4
+ resolve(value);
5
+ });
6
+ }
7
+ return new (P || (P = Promise))(function(resolve, reject) {
8
+ function fulfilled(value) {
9
+ try {
10
+ step(generator.next(value));
11
+ } catch (e) {
12
+ reject(e);
13
+ }
14
+ }
15
+ function rejected(value) {
16
+ try {
17
+ step(generator["throw"](value));
18
+ } catch (e) {
19
+ reject(e);
20
+ }
21
+ }
22
+ function step(result) {
23
+ result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
24
+ }
25
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
26
+ });
27
+ };
28
+ var __generator = this && this.__generator || function(thisArg, body) {
29
+ var _ = {
30
+ label: 0,
31
+ sent: function sent() {
32
+ if (t[0] & 1) throw t[1];
33
+ return t[1];
34
+ },
35
+ trys: [],
36
+ ops: []
37
+ }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
38
+ return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
39
+ return this;
40
+ }), g;
41
+ function verb(n) {
42
+ return function(v) {
43
+ return step([
44
+ n,
45
+ v
46
+ ]);
47
+ };
48
+ }
49
+ function step(op) {
50
+ if (f) throw new TypeError("Generator is already executing.");
51
+ while(g && (g = 0, op[0] && (_ = 0)), _)try {
52
+ 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;
53
+ if (y = 0, t) op = [
54
+ op[0] & 2,
55
+ t.value
56
+ ];
57
+ switch(op[0]){
58
+ case 0:
59
+ case 1:
60
+ t = op;
61
+ break;
62
+ case 4:
63
+ _.label++;
64
+ return {
65
+ value: op[1],
66
+ done: false
67
+ };
68
+ case 5:
69
+ _.label++;
70
+ y = op[1];
71
+ op = [
72
+ 0
73
+ ];
74
+ continue;
75
+ case 7:
76
+ op = _.ops.pop();
77
+ _.trys.pop();
78
+ continue;
79
+ default:
80
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
81
+ _ = 0;
82
+ continue;
83
+ }
84
+ if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
85
+ _.label = op[1];
86
+ break;
87
+ }
88
+ if (op[0] === 6 && _.label < t[1]) {
89
+ _.label = t[1];
90
+ t = op;
91
+ break;
92
+ }
93
+ if (t && _.label < t[2]) {
94
+ _.label = t[2];
95
+ _.ops.push(op);
96
+ break;
97
+ }
98
+ if (t[2]) _.ops.pop();
99
+ _.trys.pop();
100
+ continue;
101
+ }
102
+ op = body.call(thisArg, _);
103
+ } catch (e) {
104
+ op = [
105
+ 6,
106
+ e
107
+ ];
108
+ y = 0;
109
+ } finally{
110
+ f = t = 0;
111
+ }
112
+ if (op[0] & 5) throw op[1];
113
+ return {
114
+ value: op[0] ? op[1] : void 0,
115
+ done: true
116
+ };
117
+ }
118
+ };
119
+ var AxiosStaticInstanceProvider = /** @class */ function() {
120
+ function AxiosStaticInstanceProvider() {
121
+ this.__instance = null;
122
+ }
123
+ AxiosStaticInstanceProvider.prototype.provide = function() {
124
+ return __awaiter(this, void 0, void 0, function() {
125
+ var lib;
126
+ return __generator(this, function(_a) {
127
+ switch(_a.label){
128
+ case 0:
129
+ return [
130
+ 4 /*yield*/ ,
131
+ import("axios")
132
+ ];
133
+ case 1:
134
+ lib = _a.sent();
135
+ return [
136
+ 2 /*return*/ ,
137
+ lib["default"]
138
+ ];
139
+ }
140
+ });
141
+ });
142
+ };
143
+ AxiosStaticInstanceProvider.prototype.get = function() {
144
+ return __awaiter(this, void 0, void 0, function() {
145
+ var _a;
146
+ return __generator(this, function(_b) {
147
+ switch(_b.label){
148
+ case 0:
149
+ if (this.__instance) {
150
+ return [
151
+ 2 /*return*/ ,
152
+ this.__instance
153
+ ];
154
+ }
155
+ _a = this;
156
+ return [
157
+ 4 /*yield*/ ,
158
+ this.provide()
159
+ ];
160
+ case 1:
161
+ _a.__instance = _b.sent();
162
+ return [
163
+ 2 /*return*/ ,
164
+ this.__instance
165
+ ];
166
+ }
167
+ });
168
+ });
169
+ };
170
+ return AxiosStaticInstanceProvider;
171
+ }();
172
+ export default AxiosStaticInstanceProvider;
@@ -0,0 +1,5 @@
1
+ export default class Service {
2
+ config: import("./config").default;
3
+ path: string;
4
+ constructor();
5
+ }
@@ -0,0 +1,57 @@
1
+ var __values = this && this.__values || function(o) {
2
+ var s = typeof Symbol === "function" && Symbol.iterator, m = s && o[s], i = 0;
3
+ if (m) return m.call(o);
4
+ if (o && typeof o.length === "number") return {
5
+ next: function next() {
6
+ if (o && i >= o.length) o = void 0;
7
+ return {
8
+ value: o && o[i++],
9
+ done: !o
10
+ };
11
+ }
12
+ };
13
+ throw new TypeError(s ? "Object is not iterable." : "Symbol.iterator is not defined.");
14
+ };
15
+ import { config } from "./config.js";
16
+ var Service = /** @class */ function() {
17
+ function Service() {
18
+ var e_1, _a;
19
+ this.config = config;
20
+ this.path = '';
21
+ var target = Object.getPrototypeOf(this);
22
+ // 获取被加入切面的方法
23
+ var methodsToBind = target.__decoratedMethods;
24
+ if (methodsToBind && Array.isArray(methodsToBind)) {
25
+ try {
26
+ for(var methodsToBind_1 = __values(methodsToBind), methodsToBind_1_1 = methodsToBind_1.next(); !methodsToBind_1_1.done; methodsToBind_1_1 = methodsToBind_1.next()){
27
+ var methodName = methodsToBind_1_1.value;
28
+ if (typeof this[methodName] === 'function') {
29
+ this[methodName] = this[methodName].bind(this);
30
+ }
31
+ }
32
+ } catch (e_1_1) {
33
+ e_1 = {
34
+ error: e_1_1
35
+ };
36
+ } finally{
37
+ try {
38
+ if (methodsToBind_1_1 && !methodsToBind_1_1.done && (_a = methodsToBind_1["return"])) _a.call(methodsToBind_1);
39
+ } finally{
40
+ if (e_1) throw e_1.error;
41
+ }
42
+ }
43
+ }
44
+ if (target.__path) {
45
+ this.path = target.__path;
46
+ }
47
+ if (target.__config) {
48
+ this.config = target.__config;
49
+ }
50
+ Reflect.deleteProperty(target, '__path');
51
+ // fix: 第二次构建新实例会丢失配置
52
+ // Reflect.deleteProperty(target, '__config');
53
+ Reflect.deleteProperty(target, '__decoratedMethods');
54
+ }
55
+ return Service;
56
+ }();
57
+ export 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,32 @@
1
+ var __assign = this && this.__assign || function() {
2
+ __assign = Object.assign || function(t) {
3
+ for(var s, i = 1, n = arguments.length; i < n; i++){
4
+ s = arguments[i];
5
+ for(var p in s)if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
6
+ }
7
+ return t;
8
+ };
9
+ return __assign.apply(this, arguments);
10
+ };
11
+ import { castToMetaDescriptor, isNullOrEmpty } from "../core/common.js";
12
+ export default function PathVariables(keyOrMapping) {
13
+ return function(_target, propertyKey, descriptor) {
14
+ var metaDescriptor = castToMetaDescriptor(descriptor);
15
+ var builder = metaDescriptor.builder;
16
+ if (builder) {
17
+ if (typeof keyOrMapping === 'string' || keyOrMapping === undefined || isNullOrEmpty(keyOrMapping)) {
18
+ builder.pathVariable({
19
+ // key 为空使用数据源本体
20
+ key: typeof keyOrMapping === 'string' ? keyOrMapping : '',
21
+ required: false,
22
+ value: undefined
23
+ });
24
+ } else {
25
+ builder.pathVariable(__assign(__assign({}, keyOrMapping), {
26
+ key: typeof keyOrMapping.key === 'string' ? keyOrMapping.key : '',
27
+ required: false
28
+ }));
29
+ }
30
+ }
31
+ };
32
+ }
@@ -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,31 @@
1
+ var __assign = this && this.__assign || function() {
2
+ __assign = Object.assign || function(t) {
3
+ for(var s, i = 1, n = arguments.length; i < n; i++){
4
+ s = arguments[i];
5
+ for(var p in s)if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p];
6
+ }
7
+ return t;
8
+ };
9
+ return __assign.apply(this, arguments);
10
+ };
11
+ import { castToMetaDescriptor, isNullOrEmpty } from "../core/common.js";
12
+ export default function RequestBody(keyOrMapping) {
13
+ return function(_target, propertyKey, descriptor) {
14
+ var metaDescriptor = castToMetaDescriptor(descriptor);
15
+ var builder = metaDescriptor.builder;
16
+ if (builder) {
17
+ if (typeof keyOrMapping === 'string' || keyOrMapping === undefined || isNullOrEmpty(keyOrMapping)) {
18
+ builder.body({
19
+ key: typeof keyOrMapping === 'string' ? keyOrMapping : 'body',
20
+ required: false,
21
+ value: undefined
22
+ });
23
+ } else {
24
+ builder.body(__assign(__assign({}, keyOrMapping), {
25
+ key: typeof keyOrMapping.key === 'string' ? keyOrMapping.key : 'body',
26
+ required: false
27
+ }));
28
+ }
29
+ }
30
+ };
31
+ }
@@ -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,25 @@
1
+ import Config from "../core/config.js";
2
+ import { castToMetaDescriptor } from "../core/common.js";
3
+ export default function RequestConfig(config) {
4
+ if (config instanceof Config) {
5
+ // --- Class Decorator Logic ---
6
+ return function(constructor) {
7
+ var target = constructor.prototype;
8
+ if (config) {
9
+ Object.defineProperty(target, '__config', {
10
+ value: config,
11
+ enumerable: false,
12
+ configurable: true,
13
+ writable: false
14
+ });
15
+ }
16
+ return constructor;
17
+ };
18
+ } else {
19
+ // --- Method Decorator Logic ---
20
+ return function(target, propertyKey, descriptor) {
21
+ var metaDescriptor = castToMetaDescriptor(descriptor);
22
+ metaDescriptor.builder.config(config);
23
+ };
24
+ }
25
+ }
@@ -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,14 @@
1
+ import { castToMetaDescriptor } from "../core/common.js";
2
+ export default function RequestHeader(keyOrMapping, required) {
3
+ return function(_target, propertyKey, descriptor) {
4
+ var metaDescriptor = castToMetaDescriptor(descriptor);
5
+ var builder = metaDescriptor.builder;
6
+ if (builder) {
7
+ if (typeof keyOrMapping === 'string') {
8
+ builder.header(keyOrMapping, required === true);
9
+ } else {
10
+ builder.header(keyOrMapping);
11
+ }
12
+ }
13
+ };
14
+ }
@@ -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,56 @@
1
+ import { castToMetaDescriptor, normalizePath } from "../core/common.js";
2
+ // Implementation
3
+ export default function RequestMapping(path, method) {
4
+ if (method === undefined) {
5
+ // Class Decorator logic remains the same
6
+ return function(constructor) {
7
+ // 这里不用继承 extends constructor, 无法转换到 ES5
8
+ // 获取原型对象
9
+ var target = constructor.prototype;
10
+ if (path) {
11
+ Object.defineProperty(target, '__path', {
12
+ value: path,
13
+ enumerable: false,
14
+ configurable: true,
15
+ writable: false
16
+ });
17
+ }
18
+ return constructor;
19
+ };
20
+ } else {
21
+ // Method Decorator logic
22
+ return function(target, propertyKey, descriptor) {
23
+ // 在原型链上标记方法被替换,在 RequestConfig 中会重新绑定 this 指针。
24
+ // target 是类的原型对象
25
+ if (!Object.prototype.hasOwnProperty.call(target, '__decoratedMethods')) {
26
+ Object.defineProperty(target, '__decoratedMethods', {
27
+ value: [],
28
+ enumerable: false,
29
+ configurable: true,
30
+ writable: false
31
+ });
32
+ }
33
+ target.__decoratedMethods.push(propertyKey);
34
+ var originalMethod = descriptor.value;
35
+ var metaDescriptor = castToMetaDescriptor(descriptor);
36
+ // 这里没有使用箭头函数,this 运行时不确定 因此后续需要重新绑定
37
+ descriptor.value = function() {
38
+ var args = [];
39
+ for(var _i = 0; _i < arguments.length; _i++){
40
+ args[_i] = arguments[_i];
41
+ }
42
+ try {
43
+ var source = originalMethod.apply(this, args);
44
+ var service = this;
45
+ var usingConfig = metaDescriptor.config ? metaDescriptor.config : service.config;
46
+ var servicePrefix = service.path;
47
+ var requestPath = normalizePath("".concat(servicePrefix, "/").concat(path));
48
+ return metaDescriptor.builder.buildWith(usingConfig, requestPath, method, source);
49
+ } catch (error) {
50
+ console.error("Error in method '".concat(propertyKey, "'"), error);
51
+ throw error;
52
+ }
53
+ };
54
+ };
55
+ }
56
+ }
@@ -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,15 @@
1
+ import { castToMetaDescriptor } from "../core/common.js";
2
+ // 声明查询串参数
3
+ export default function RequestParam(keyOrMapping, required) {
4
+ return function(_target, propertyKey, descriptor) {
5
+ var metaDescriptor = castToMetaDescriptor(descriptor);
6
+ var builder = metaDescriptor.builder;
7
+ if (builder) {
8
+ if (typeof keyOrMapping === 'string') {
9
+ builder.param(keyOrMapping, required === true);
10
+ } else {
11
+ builder.param(keyOrMapping);
12
+ }
13
+ }
14
+ };
15
+ }
@@ -0,0 +1,3 @@
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;
@@ -0,0 +1,8 @@
1
+ import { castToMetaDescriptor } from "../core/common.js";
2
+ // 重定向方法的配置
3
+ export default function RequestWith(config) {
4
+ return function(_target, propertyKey, descriptor) {
5
+ var metaDescriptor = castToMetaDescriptor(descriptor);
6
+ metaDescriptor.config = config;
7
+ };
8
+ }
package/es/index.d.ts ADDED
@@ -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";
package/es/index.js ADDED
@@ -0,0 +1,14 @@
1
+ // noinspection JSUnusedGlobalSymbols
2
+ export { default as Config } from "./core/config.js";
3
+ export { config } from "./core/config.js";
4
+ export { default as Expect } from "./core/expect.js";
5
+ export { default as Service } from "./core/service.js";
6
+ export { default as AxiosStaticInstanceProvider } from "./core/provider.js";
7
+ export { default as RequestConfig } from "./decorator/request-config.js";
8
+ export { default as RequestMapping } from "./decorator/request-mapping.js";
9
+ export { default as RequestParam } from "./decorator/request-param.js";
10
+ export { default as RequestBody } from "./decorator/request-body.js";
11
+ export { default as RequestHeader } from "./decorator/request-header.js";
12
+ export { default as RequestWith } from "./decorator/request-with.js";
13
+ export { default as PathVariables } from "./decorator/path-variables.js";
14
+ export { default as RequestBuilder } from "./core/builder.js";
@@ -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
+ }