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.
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 +56 -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 +42 -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 +60 -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,203 @@
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 SessionStorage = /** @class */ function() {
120
+ function SessionStorage() {
121
+ this._inMemoryStorage = {};
122
+ }
123
+ SessionStorage.prototype.set = function(key, value) {
124
+ return __awaiter(this, void 0, void 0, function() {
125
+ return __generator(this, function(_a) {
126
+ if (window && window.sessionStorage) {
127
+ window.sessionStorage.setItem(key, JSON.stringify(value));
128
+ } else if (wx && wx.setStorageSync) {
129
+ wx.setStorageSync(key, value);
130
+ } else if (my && my.setStorageSync) {
131
+ my.setStorageSync(key, value);
132
+ } else if (tt && tt.setStorageSync) {
133
+ tt.setStorageSync(key, value);
134
+ } else {
135
+ // 使用内存环境
136
+ this._inMemoryStorage[key] = value;
137
+ }
138
+ return [
139
+ 2 /*return*/
140
+ ];
141
+ });
142
+ });
143
+ };
144
+ SessionStorage.prototype.get = function(key) {
145
+ return __awaiter(this, void 0, void 0, function() {
146
+ var value;
147
+ return __generator(this, function(_a) {
148
+ if (window && window.sessionStorage) {
149
+ value = window.sessionStorage.getItem(key);
150
+ return [
151
+ 2 /*return*/ ,
152
+ value ? JSON.parse(value) : value
153
+ ];
154
+ } else if (wx && wx.getStorageSync) {
155
+ return [
156
+ 2 /*return*/ ,
157
+ wx.getStorageSync(key)
158
+ ];
159
+ } else if (my && my.getStorageSync) {
160
+ return [
161
+ 2 /*return*/ ,
162
+ my.getStorageSync(key)
163
+ ];
164
+ } else if (tt && tt.getStorageSync) {
165
+ return [
166
+ 2 /*return*/ ,
167
+ tt.getStorageSync(key)
168
+ ];
169
+ } else {
170
+ return [
171
+ 2 /*return*/ ,
172
+ this._inMemoryStorage[key]
173
+ ];
174
+ }
175
+ return [
176
+ 2 /*return*/
177
+ ];
178
+ });
179
+ });
180
+ };
181
+ SessionStorage.prototype.remove = function(key) {
182
+ return __awaiter(this, void 0, void 0, function() {
183
+ return __generator(this, function(_a) {
184
+ if (window && window.sessionStorage) {
185
+ window.sessionStorage.removeItem(key);
186
+ } else if (wx && wx.removeStorageSync) {
187
+ wx.removeStorageSync(key);
188
+ } else if (my && my.removeStorageSync) {
189
+ my.removeStorageSync(key);
190
+ } else if (tt && tt.removeStorageSync) {
191
+ tt.removeStorageSync(key);
192
+ } else {
193
+ delete this._inMemoryStorage[key];
194
+ }
195
+ return [
196
+ 2 /*return*/
197
+ ];
198
+ });
199
+ });
200
+ };
201
+ return SessionStorage;
202
+ }();
203
+ export default SessionStorage;
@@ -0,0 +1,33 @@
1
+ import type { AxiosResponse, Method } from 'axios';
2
+ import type Config from "./config";
3
+ import { AxiosRequestConfig } from "axios";
4
+ export type ParamsMapper<T = any> = (params: Record<string, any>) => T;
5
+ export declare enum ParamsMappingType {
6
+ HEADER = "HEADER",
7
+ PARAM = "PARAM",
8
+ BODY = "BODY",
9
+ PATH_VARIABLE = "PATH_VARIABLE"
10
+ }
11
+ export interface ParamsMapping<T = any> {
12
+ key: string;
13
+ value: T | ParamsMapper<T>;
14
+ required?: boolean;
15
+ }
16
+ export type AxiosConfigMapper = (params: Record<string, any>) => AxiosRequestConfig;
17
+ export default class RequestBuilder {
18
+ private _configs;
19
+ private readonly _mapping;
20
+ private readonly _pathVariablesMapping;
21
+ private _addMapping;
22
+ private _addPathVariablesMapping;
23
+ private _clearMapping;
24
+ param(key: string, required?: boolean): this;
25
+ param(mapping: ParamsMapping): this;
26
+ header(key: string, required?: boolean): this;
27
+ header(mapping: ParamsMapping): this;
28
+ body(keyOrMapping: string | ParamsMapping): this;
29
+ pathVariable(keyOrMapping: string | ParamsMapping): this;
30
+ config(cfg: AxiosRequestConfig | AxiosConfigMapper): this;
31
+ build(config: Config, path: string, method: Method, source?: Record<string, any>): AxiosRequestConfig;
32
+ buildWith(config: Config, path: string, method: Method, source?: Record<string, any>): Promise<AxiosResponse<any>>;
33
+ }