axios-annotations 1.3.4 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +248 -105
- package/index.d.ts +1 -0
- package/index.js +121 -0
- package/lib/core/cancel.d.ts +30 -0
- package/lib/core/cancel.js +56 -0
- package/lib/core/common.d.ts +6 -0
- package/lib/core/common.js +166 -1
- package/lib/core/config.d.ts +60 -29
- package/lib/core/config.js +332 -1
- package/lib/core/parser.d.ts +19 -15
- package/lib/core/parser.js +79 -1
- package/lib/core/provider.d.ts +6 -0
- package/lib/core/provider.js +172 -0
- package/lib/core/service.d.ts +153 -33
- package/lib/core/service.js +562 -1
- package/lib/decorator/abort-source.d.ts +3 -9
- package/lib/decorator/abort-source.js +25 -1
- package/lib/decorator/delete-mapping.d.ts +1 -3
- package/lib/decorator/delete-mapping.js +13 -1
- package/lib/decorator/get-mapping.d.ts +1 -3
- package/lib/decorator/get-mapping.js +13 -1
- package/lib/decorator/ignore-residual-params.d.ts +1 -3
- package/lib/decorator/ignore-residual-params.js +24 -1
- package/lib/decorator/patch-mapping.d.ts +1 -3
- package/lib/decorator/patch-mapping.js +13 -1
- package/lib/decorator/post-mapping.d.ts +1 -3
- package/lib/decorator/post-mapping.js +13 -1
- package/lib/decorator/put-mapping.d.ts +1 -3
- package/lib/decorator/put-mapping.js +13 -1
- package/lib/decorator/request-body.d.ts +1 -3
- package/lib/decorator/request-body.js +28 -1
- package/lib/decorator/request-config.d.ts +5 -7
- package/lib/decorator/request-config.js +23 -1
- package/lib/decorator/request-header.d.ts +2 -5
- package/lib/decorator/request-header.js +21 -1
- package/lib/decorator/request-mapping.d.ts +3 -6
- package/lib/decorator/request-mapping.js +58 -1
- package/lib/decorator/request-param.d.ts +1 -3
- package/lib/decorator/request-param.js +27 -1
- package/lib/decorator/request-with.d.ts +1 -3
- package/lib/decorator/request-with.js +20 -1
- package/lib/index.d.ts +19 -0
- package/lib/index.js +139 -0
- package/lib/plugins/auth/authorizer.d.ts +23 -49
- package/lib/plugins/auth/authorizer.js +271 -1
- package/lib/plugins/auth/history.d.ts +14 -15
- package/lib/plugins/auth/history.js +96 -1
- package/lib/plugins/auth/index.d.ts +9 -4
- package/lib/plugins/auth/index.js +368 -1
- package/lib/plugins/auth/queue.d.ts +28 -16
- package/lib/plugins/auth/queue.js +270 -1
- package/lib/plugins/auth/storage.d.ts +6 -7
- package/lib/plugins/auth/storage.js +207 -1
- package/package.json +16 -16
- package/plugins/auth/index.d.ts +4 -4
- package/plugins/auth/index.js +26 -1
- package/core/config.d.ts +0 -29
- package/core/config.js +0 -1
- package/core/parser.d.ts +0 -15
- package/core/parser.js +0 -1
- package/core/service.d.ts +0 -33
- package/core/service.js +0 -1
- package/decorator/abort-source.d.ts +0 -9
- package/decorator/abort-source.js +0 -1
- package/decorator/delete-mapping.d.ts +0 -1
- package/decorator/delete-mapping.js +0 -1
- package/decorator/get-mapping.d.ts +0 -1
- package/decorator/get-mapping.js +0 -1
- package/decorator/ignore-residual-params.d.ts +0 -1
- package/decorator/ignore-residual-params.js +0 -1
- package/decorator/patch-mapping.d.ts +0 -1
- package/decorator/patch-mapping.js +0 -1
- package/decorator/post-mapping.d.ts +0 -1
- package/decorator/post-mapping.js +0 -1
- package/decorator/put-mapping.d.ts +0 -3
- package/decorator/put-mapping.js +0 -1
- package/decorator/request-body.d.ts +0 -3
- package/decorator/request-body.js +0 -1
- package/decorator/request-config.d.ts +0 -29
- package/decorator/request-config.js +0 -1
- package/decorator/request-header.d.ts +0 -1
- package/decorator/request-header.js +0 -1
- package/decorator/request-mapping.d.ts +0 -1
- package/decorator/request-mapping.js +0 -1
- package/decorator/request-param.d.ts +0 -1
- package/decorator/request-param.js +0 -1
- package/decorator/request-with.d.ts +0 -1
- package/decorator/request-with.js +0 -1
- package/lib/plugins/cache/index.js +0 -1
- package/plugins/auth/authorizer.d.ts +0 -49
- package/plugins/auth/authorizer.js +0 -1
- package/plugins/auth/history.d.ts +0 -15
- package/plugins/auth/history.js +0 -1
- package/plugins/auth/queue.d.ts +0 -16
- package/plugins/auth/queue.js +0 -1
- package/plugins/auth/storage.d.ts +0 -7
- package/plugins/auth/storage.js +0 -1
- package/plugins/cache/index.js +0 -1
|
@@ -1 +1,270 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = this && this.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) {
|
|
4
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
5
|
+
resolve(value);
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
9
|
+
function fulfilled(value) {
|
|
10
|
+
try {
|
|
11
|
+
step(generator.next(value));
|
|
12
|
+
} catch (e) {
|
|
13
|
+
reject(e);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function rejected(value) {
|
|
17
|
+
try {
|
|
18
|
+
step(generator["throw"](value));
|
|
19
|
+
} catch (e) {
|
|
20
|
+
reject(e);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function step(result) {
|
|
24
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
25
|
+
}
|
|
26
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
30
|
+
var _ = {
|
|
31
|
+
label: 0,
|
|
32
|
+
sent: function sent() {
|
|
33
|
+
if (t[0] & 1) throw t[1];
|
|
34
|
+
return t[1];
|
|
35
|
+
},
|
|
36
|
+
trys: [],
|
|
37
|
+
ops: []
|
|
38
|
+
}, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
39
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
40
|
+
return this;
|
|
41
|
+
}), g;
|
|
42
|
+
function verb(n) {
|
|
43
|
+
return function(v) {
|
|
44
|
+
return step([
|
|
45
|
+
n,
|
|
46
|
+
v
|
|
47
|
+
]);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function step(op) {
|
|
51
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
52
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
53
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
54
|
+
if (y = 0, t) op = [
|
|
55
|
+
op[0] & 2,
|
|
56
|
+
t.value
|
|
57
|
+
];
|
|
58
|
+
switch(op[0]){
|
|
59
|
+
case 0:
|
|
60
|
+
case 1:
|
|
61
|
+
t = op;
|
|
62
|
+
break;
|
|
63
|
+
case 4:
|
|
64
|
+
_.label++;
|
|
65
|
+
return {
|
|
66
|
+
value: op[1],
|
|
67
|
+
done: false
|
|
68
|
+
};
|
|
69
|
+
case 5:
|
|
70
|
+
_.label++;
|
|
71
|
+
y = op[1];
|
|
72
|
+
op = [
|
|
73
|
+
0
|
|
74
|
+
];
|
|
75
|
+
continue;
|
|
76
|
+
case 7:
|
|
77
|
+
op = _.ops.pop();
|
|
78
|
+
_.trys.pop();
|
|
79
|
+
continue;
|
|
80
|
+
default:
|
|
81
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
82
|
+
_ = 0;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
86
|
+
_.label = op[1];
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
90
|
+
_.label = t[1];
|
|
91
|
+
t = op;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (t && _.label < t[2]) {
|
|
95
|
+
_.label = t[2];
|
|
96
|
+
_.ops.push(op);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (t[2]) _.ops.pop();
|
|
100
|
+
_.trys.pop();
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
op = body.call(thisArg, _);
|
|
104
|
+
} catch (e) {
|
|
105
|
+
op = [
|
|
106
|
+
6,
|
|
107
|
+
e
|
|
108
|
+
];
|
|
109
|
+
y = 0;
|
|
110
|
+
} finally{
|
|
111
|
+
f = t = 0;
|
|
112
|
+
}
|
|
113
|
+
if (op[0] & 5) throw op[1];
|
|
114
|
+
return {
|
|
115
|
+
value: op[0] ? op[1] : void 0,
|
|
116
|
+
done: true
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
Object.defineProperty(exports, "__esModule", {
|
|
121
|
+
value: true
|
|
122
|
+
});
|
|
123
|
+
function random(min, max) {
|
|
124
|
+
return (Math.random() * (max - min + 1) | 0) + min;
|
|
125
|
+
}
|
|
126
|
+
function sleep(time) {
|
|
127
|
+
return new Promise(function(resolve) {
|
|
128
|
+
var t = setTimeout(function() {
|
|
129
|
+
clearTimeout(t);
|
|
130
|
+
t = undefined;
|
|
131
|
+
resolve();
|
|
132
|
+
}, time);
|
|
133
|
+
});
|
|
134
|
+
}
|
|
135
|
+
var PendingQueue = /** @class */ function() {
|
|
136
|
+
/**
|
|
137
|
+
* @param {Authorizer} authorizer
|
|
138
|
+
* @param {Config} config
|
|
139
|
+
* @param {number} minTryRetryInterval
|
|
140
|
+
* @param {number} maxTryRetryInterval
|
|
141
|
+
* @param retryTimes
|
|
142
|
+
*/ function PendingQueue(authorizer, config, minTryRetryInterval, maxTryRetryInterval, retryTimes) {
|
|
143
|
+
if (minTryRetryInterval === void 0) {
|
|
144
|
+
minTryRetryInterval = 3000;
|
|
145
|
+
}
|
|
146
|
+
if (maxTryRetryInterval === void 0) {
|
|
147
|
+
maxTryRetryInterval = 5000;
|
|
148
|
+
}
|
|
149
|
+
if (retryTimes === void 0) {
|
|
150
|
+
retryTimes = 3;
|
|
151
|
+
}
|
|
152
|
+
this._queue = [];
|
|
153
|
+
this._authorizer = authorizer;
|
|
154
|
+
this._config = config;
|
|
155
|
+
this._minTryRetryInterval = minTryRetryInterval;
|
|
156
|
+
this._maxTryRetryInterval = maxTryRetryInterval;
|
|
157
|
+
this._retryTimes = retryTimes;
|
|
158
|
+
}
|
|
159
|
+
PendingQueue.prototype.resend = function(error_1) {
|
|
160
|
+
return __awaiter(this, arguments, void 0, function(error, retries) {
|
|
161
|
+
var i, session, axios, e_1;
|
|
162
|
+
if (retries === void 0) {
|
|
163
|
+
retries = 3;
|
|
164
|
+
}
|
|
165
|
+
return __generator(this, function(_a) {
|
|
166
|
+
switch(_a.label){
|
|
167
|
+
case 0:
|
|
168
|
+
i = 0;
|
|
169
|
+
_a.label = 1;
|
|
170
|
+
case 1:
|
|
171
|
+
if (!(i < this._retryTimes)) return [
|
|
172
|
+
3 /*break*/ ,
|
|
173
|
+
9
|
|
174
|
+
];
|
|
175
|
+
if (!(i > 0)) return [
|
|
176
|
+
3 /*break*/ ,
|
|
177
|
+
3
|
|
178
|
+
];
|
|
179
|
+
return [
|
|
180
|
+
4 /*yield*/ ,
|
|
181
|
+
sleep(random(this._minTryRetryInterval, this._maxTryRetryInterval))
|
|
182
|
+
];
|
|
183
|
+
case 2:
|
|
184
|
+
_a.sent();
|
|
185
|
+
_a.label = 3;
|
|
186
|
+
case 3:
|
|
187
|
+
return [
|
|
188
|
+
4 /*yield*/ ,
|
|
189
|
+
this._authorizer.getSession()
|
|
190
|
+
];
|
|
191
|
+
case 4:
|
|
192
|
+
session = _a.sent();
|
|
193
|
+
if (this._authorizer.sessionHistory.isDeprecated(session)) {
|
|
194
|
+
// without re-login again, residual invalid session
|
|
195
|
+
throw error;
|
|
196
|
+
}
|
|
197
|
+
_a.label = 5;
|
|
198
|
+
case 5:
|
|
199
|
+
_a.trys.push([
|
|
200
|
+
5,
|
|
201
|
+
7,
|
|
202
|
+
,
|
|
203
|
+
8
|
|
204
|
+
]);
|
|
205
|
+
return [
|
|
206
|
+
4 /*yield*/ ,
|
|
207
|
+
this._config.requestAxiosInstance()
|
|
208
|
+
];
|
|
209
|
+
case 6:
|
|
210
|
+
axios = _a.sent();
|
|
211
|
+
this._authorizer.withAuthentication(error.config, session);
|
|
212
|
+
return [
|
|
213
|
+
2 /*return*/ ,
|
|
214
|
+
axios.request(error.config)
|
|
215
|
+
];
|
|
216
|
+
case 7:
|
|
217
|
+
e_1 = _a.sent();
|
|
218
|
+
if (i >= retries - 1) {
|
|
219
|
+
throw e_1;
|
|
220
|
+
}
|
|
221
|
+
return [
|
|
222
|
+
3 /*break*/ ,
|
|
223
|
+
8
|
|
224
|
+
];
|
|
225
|
+
case 8:
|
|
226
|
+
++i;
|
|
227
|
+
return [
|
|
228
|
+
3 /*break*/ ,
|
|
229
|
+
1
|
|
230
|
+
];
|
|
231
|
+
case 9:
|
|
232
|
+
throw error;
|
|
233
|
+
}
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
};
|
|
237
|
+
PendingQueue.prototype.push = function(error) {
|
|
238
|
+
var _this = this;
|
|
239
|
+
return new Promise(function(resolve, reject) {
|
|
240
|
+
_this._queue.push({
|
|
241
|
+
error: error,
|
|
242
|
+
resolve: resolve,
|
|
243
|
+
reject: reject
|
|
244
|
+
});
|
|
245
|
+
});
|
|
246
|
+
};
|
|
247
|
+
PendingQueue.prototype.pop = function() {
|
|
248
|
+
var requestSaved = this._queue.shift();
|
|
249
|
+
if (!requestSaved) {
|
|
250
|
+
return;
|
|
251
|
+
}
|
|
252
|
+
var error = requestSaved.error, resolve = requestSaved.resolve, reject = requestSaved.reject;
|
|
253
|
+
this.resend(error).then(resolve)["catch"](reject);
|
|
254
|
+
};
|
|
255
|
+
PendingQueue.prototype.clear = function() {
|
|
256
|
+
this._queue.splice(0).forEach(function(_a) {
|
|
257
|
+
var error = _a.error, reject = _a.reject;
|
|
258
|
+
reject(error);
|
|
259
|
+
});
|
|
260
|
+
};
|
|
261
|
+
Object.defineProperty(PendingQueue.prototype, "size", {
|
|
262
|
+
get: function get() {
|
|
263
|
+
return this._queue.length;
|
|
264
|
+
},
|
|
265
|
+
enumerable: false,
|
|
266
|
+
configurable: true
|
|
267
|
+
});
|
|
268
|
+
return PendingQueue;
|
|
269
|
+
}();
|
|
270
|
+
exports["default"] = PendingQueue;
|
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
export default class SessionStorage {
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
get(key: string): Promise<any>;
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
}
|
|
1
|
+
export default class SessionStorage {
|
|
2
|
+
_inMemoryStorage: Record<string, any>;
|
|
3
|
+
set(key: string, value: any): Promise<void>;
|
|
4
|
+
get(key: string): Promise<any>;
|
|
5
|
+
remove(key: string): Promise<void>;
|
|
6
|
+
}
|
|
@@ -1 +1,207 @@
|
|
|
1
|
-
function _typeof(t){return(_typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(t){return typeof t}:function(t){return t&&"function"==typeof Symbol&&t.constructor===Symbol&&t!==Symbol.prototype?"symbol":typeof t})(t)}function _regeneratorRuntime(){_regeneratorRuntime=function(){return a};var u,a={},t=Object.prototype,s=t.hasOwnProperty,f=Object.defineProperty||function(t,e,r){t[e]=r.value},e="function"==typeof Symbol?Symbol:{},n=e.iterator||"@@iterator",r=e.asyncIterator||"@@asyncIterator",o=e.toStringTag||"@@toStringTag";function i(t,e,r){return Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}),t[e]}try{i({},"")}catch(u){i=function(t,e,r){return t[e]=r}}function c(t,e,r,n){var o,i,a,c,e=e&&e.prototype instanceof v?e:v,e=Object.create(e.prototype),n=new P(n||[]);return f(e,"_invoke",{value:(o=t,i=r,a=n,c=y,function(t,e){if(c===p)throw Error("Generator is already running");if(c===g){if("throw"===t)throw e;return{value:u,done:!0}}for(a.method=t,a.arg=e;;){var r=a.delegate;if(r){r=function t(e,r){var n=r.method,o=e.iterator[n];if(o===u)return r.delegate=null,"throw"===n&&e.iterator.return&&(r.method="return",r.arg=u,t(e,r),"throw"===r.method)||"return"!==n&&(r.method="throw",r.arg=new TypeError("The iterator does not provide a '"+n+"' method")),m;n=l(o,e.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,m;o=n.arg;return o?o.done?(r[e.resultName]=o.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=u),r.delegate=null,m):o:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,m)}(r,a);if(r){if(r===m)continue;return r}}if("next"===a.method)a.sent=a._sent=a.arg;else if("throw"===a.method){if(c===y)throw c=g,a.arg;a.dispatchException(a.arg)}else"return"===a.method&&a.abrupt("return",a.arg);c=p;r=l(o,i,a);if("normal"===r.type){if(c=a.done?g:h,r.arg===m)continue;return{value:r.arg,done:a.done}}"throw"===r.type&&(c=g,a.method="throw",a.arg=r.arg)}})}),e}function l(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}a.wrap=c;var y="suspendedStart",h="suspendedYield",p="executing",g="completed",m={};function v(){}function d(){}function w(){}var e={},S=(i(e,n,function(){return this}),Object.getPrototypeOf),S=S&&S(S(k([]))),b=(S&&S!==t&&s.call(S,n)&&(e=S),w.prototype=v.prototype=Object.create(e));function _(t){["next","throw","return"].forEach(function(e){i(t,e,function(t){return this._invoke(e,t)})})}function x(a,c){var e;f(this,"_invoke",{value:function(r,n){function t(){return new c(function(t,e){!function e(t,r,n,o){var i,t=l(a[t],a,r);if("throw"!==t.type)return(r=(i=t.arg).value)&&"object"==_typeof(r)&&s.call(r,"__await")?c.resolve(r.__await).then(function(t){e("next",t,n,o)},function(t){e("throw",t,n,o)}):c.resolve(r).then(function(t){i.value=t,n(i)},function(t){return e("throw",t,n,o)});o(t.arg)}(r,n,t,e)})}return e=e?e.then(t,t):t()}})}function L(t){var e={tryLoc:t[0]};1 in t&&(e.catchLoc=t[1]),2 in t&&(e.finallyLoc=t[2],e.afterLoc=t[3]),this.tryEntries.push(e)}function E(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function P(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(L,this),this.reset(!0)}function k(e){if(e||""===e){var r,t=e[n];if(t)return t.call(e);if("function"==typeof e.next)return e;if(!isNaN(e.length))return r=-1,(t=function t(){for(;++r<e.length;)if(s.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=u,t.done=!0,t}).next=t}throw new TypeError(_typeof(e)+" is not iterable")}return f(b,"constructor",{value:d.prototype=w,configurable:!0}),f(w,"constructor",{value:d,configurable:!0}),d.displayName=i(w,o,"GeneratorFunction"),a.isGeneratorFunction=function(t){t="function"==typeof t&&t.constructor;return!!t&&(t===d||"GeneratorFunction"===(t.displayName||t.name))},a.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,w):(t.__proto__=w,i(t,o,"GeneratorFunction")),t.prototype=Object.create(b),t},a.awrap=function(t){return{__await:t}},_(x.prototype),i(x.prototype,r,function(){return this}),a.AsyncIterator=x,a.async=function(t,e,r,n,o){void 0===o&&(o=Promise);var i=new x(c(t,e,r,n),o);return a.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},_(b),i(b,o,"Generator"),i(b,n,function(){return this}),i(b,"toString",function(){return"[object Generator]"}),a.keys=function(t){var e,r=Object(t),n=[];for(e in r)n.push(e);return n.reverse(),function t(){for(;n.length;){var e=n.pop();if(e in r)return t.value=e,t.done=!1,t}return t.done=!0,t}},a.values=k,P.prototype={constructor:P,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=u,this.done=!1,this.delegate=null,this.method="next",this.arg=u,this.tryEntries.forEach(E),!t)for(var e in this)"t"===e.charAt(0)&&s.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=u)},stop:function(){this.done=!0;var t=this.tryEntries[0].completion;if("throw"===t.type)throw t.arg;return this.rval},dispatchException:function(r){if(this.done)throw r;var n=this;function t(t,e){return i.type="throw",i.arg=r,n.next=t,e&&(n.method="next",n.arg=u),!!e}for(var e=this.tryEntries.length-1;0<=e;--e){var o=this.tryEntries[e],i=o.completion;if("root"===o.tryLoc)return t("end");if(o.tryLoc<=this.prev){var a=s.call(o,"catchLoc"),c=s.call(o,"finallyLoc");if(a&&c){if(this.prev<o.catchLoc)return t(o.catchLoc,!0);if(this.prev<o.finallyLoc)return t(o.finallyLoc)}else if(a){if(this.prev<o.catchLoc)return t(o.catchLoc,!0)}else{if(!c)throw Error("try statement without catch or finally");if(this.prev<o.finallyLoc)return t(o.finallyLoc)}}}},abrupt:function(t,e){for(var r=this.tryEntries.length-1;0<=r;--r){var n=this.tryEntries[r];if(n.tryLoc<=this.prev&&s.call(n,"finallyLoc")&&this.prev<n.finallyLoc){var o=n;break}}var i=(o=o&&("break"===t||"continue"===t)&&o.tryLoc<=e&&e<=o.finallyLoc?null:o)?o.completion:{};return i.type=t,i.arg=e,o?(this.method="next",this.next=o.finallyLoc,m):this.complete(i)},complete:function(t,e){if("throw"===t.type)throw t.arg;return"break"===t.type||"continue"===t.type?this.next=t.arg:"return"===t.type?(this.rval=this.arg=t.arg,this.method="return",this.next="end"):"normal"===t.type&&e&&(this.next=e),m},finish:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var r=this.tryEntries[e];if(r.finallyLoc===t)return this.complete(r.completion,r.afterLoc),E(r),m}},catch:function(t){for(var e=this.tryEntries.length-1;0<=e;--e){var r,n,o=this.tryEntries[e];if(o.tryLoc===t)return"throw"===(r=o.completion).type&&(n=r.arg,E(o)),n}throw Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:k(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=u),m}},a}function asyncGeneratorStep(t,e,r,n,o,i,a){try{var c=t[i](a),u=c.value}catch(t){return void r(t)}c.done?e(u):Promise.resolve(u).then(n,o)}function _asyncToGenerator(c){return function(){var t=this,a=arguments;return new Promise(function(e,r){var n=c.apply(t,a);function o(t){asyncGeneratorStep(n,e,r,o,i,"next",t)}function i(t){asyncGeneratorStep(n,e,r,o,i,"throw",t)}o(void 0)})}}function _classCallCheck(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function _defineProperties(t,e){for(var r=0;r<e.length;r++){var n=e[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(t,_toPropertyKey(n.key),n)}}function _createClass(t,e,r){return e&&_defineProperties(t.prototype,e),r&&_defineProperties(t,r),Object.defineProperty(t,"prototype",{writable:!1}),t}function _defineProperty(t,e,r){return(e=_toPropertyKey(e))in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}function _toPropertyKey(t){t=_toPrimitive(t,"string");return"symbol"==_typeof(t)?t:t+""}function _toPrimitive(t,e){if("object"!=_typeof(t)||!t)return t;var r=t[Symbol.toPrimitive];if(void 0===r)return("string"===e?String:Number)(t);r=r.call(t,e||"default");if("object"!=_typeof(r))return r;throw new TypeError("@@toPrimitive must return a primitive value.")}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var SessionStorage=exports.default=(()=>{return _createClass(function t(){_classCallCheck(this,t),_defineProperty(this,"_inMemoryStorage",{})},[{key:"set",value:(n=_asyncToGenerator(_regeneratorRuntime().mark(function t(e,r){return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:window&&window.sessionStorage?window.sessionStorage.setItem(e,JSON.stringify(r)):wx&&wx.setStorageSync?wx.setStorageSync(e,r):my&&my.setStorageSync?my.setStorageSync(e,r):tt&&tt.setStorageSync?tt.setStorageSync(e,r):this._inMemoryStorage[e]=r;case 1:case"end":return t.stop()}},t,this)})),function(t,e){return n.apply(this,arguments)})},{key:"get",value:(r=_asyncToGenerator(_regeneratorRuntime().mark(function t(e){var r;return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:if(window&&window.sessionStorage)return r=window.sessionStorage.getItem(e),t.abrupt("return",JSON.parse(r));t.next=5;break;case 5:if(wx&&wx.getStorageSync)return t.abrupt("return",wx.getStorageSync(e));t.next=9;break;case 9:if(my&&my.getStorageSync)return t.abrupt("return",my.getStorageSync(e));t.next=13;break;case 13:if(tt&&tt.getStorageSync)return t.abrupt("return",tt.getStorageSync(e));t.next=17;break;case 17:return t.abrupt("return",this._inMemoryStorage[e]);case 18:case"end":return t.stop()}},t,this)})),function(t){return r.apply(this,arguments)})},{key:"remove",value:(e=_asyncToGenerator(_regeneratorRuntime().mark(function t(e){return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:window&&window.sessionStorage?window.sessionStorage.removeItem(e):wx&&wx.removeStorageSync?wx.removeStorageSync(e):my&&my.removeStorageSync?my.removeStorageSync(e):tt&&tt.removeStorageSync?tt.removeStorageSync(e):delete this._inMemoryStorage[e];case 1:case"end":return t.stop()}},t,this)})),function(t){return e.apply(this,arguments)})}]);var e,r,n})();
|
|
1
|
+
"use strict";
|
|
2
|
+
var __awaiter = this && this.__awaiter || function(thisArg, _arguments, P, generator) {
|
|
3
|
+
function adopt(value) {
|
|
4
|
+
return value instanceof P ? value : new P(function(resolve) {
|
|
5
|
+
resolve(value);
|
|
6
|
+
});
|
|
7
|
+
}
|
|
8
|
+
return new (P || (P = Promise))(function(resolve, reject) {
|
|
9
|
+
function fulfilled(value) {
|
|
10
|
+
try {
|
|
11
|
+
step(generator.next(value));
|
|
12
|
+
} catch (e) {
|
|
13
|
+
reject(e);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
function rejected(value) {
|
|
17
|
+
try {
|
|
18
|
+
step(generator["throw"](value));
|
|
19
|
+
} catch (e) {
|
|
20
|
+
reject(e);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
function step(result) {
|
|
24
|
+
result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected);
|
|
25
|
+
}
|
|
26
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
27
|
+
});
|
|
28
|
+
};
|
|
29
|
+
var __generator = this && this.__generator || function(thisArg, body) {
|
|
30
|
+
var _ = {
|
|
31
|
+
label: 0,
|
|
32
|
+
sent: function sent() {
|
|
33
|
+
if (t[0] & 1) throw t[1];
|
|
34
|
+
return t[1];
|
|
35
|
+
},
|
|
36
|
+
trys: [],
|
|
37
|
+
ops: []
|
|
38
|
+
}, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
|
|
39
|
+
return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() {
|
|
40
|
+
return this;
|
|
41
|
+
}), g;
|
|
42
|
+
function verb(n) {
|
|
43
|
+
return function(v) {
|
|
44
|
+
return step([
|
|
45
|
+
n,
|
|
46
|
+
v
|
|
47
|
+
]);
|
|
48
|
+
};
|
|
49
|
+
}
|
|
50
|
+
function step(op) {
|
|
51
|
+
if (f) throw new TypeError("Generator is already executing.");
|
|
52
|
+
while(g && (g = 0, op[0] && (_ = 0)), _)try {
|
|
53
|
+
if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
|
|
54
|
+
if (y = 0, t) op = [
|
|
55
|
+
op[0] & 2,
|
|
56
|
+
t.value
|
|
57
|
+
];
|
|
58
|
+
switch(op[0]){
|
|
59
|
+
case 0:
|
|
60
|
+
case 1:
|
|
61
|
+
t = op;
|
|
62
|
+
break;
|
|
63
|
+
case 4:
|
|
64
|
+
_.label++;
|
|
65
|
+
return {
|
|
66
|
+
value: op[1],
|
|
67
|
+
done: false
|
|
68
|
+
};
|
|
69
|
+
case 5:
|
|
70
|
+
_.label++;
|
|
71
|
+
y = op[1];
|
|
72
|
+
op = [
|
|
73
|
+
0
|
|
74
|
+
];
|
|
75
|
+
continue;
|
|
76
|
+
case 7:
|
|
77
|
+
op = _.ops.pop();
|
|
78
|
+
_.trys.pop();
|
|
79
|
+
continue;
|
|
80
|
+
default:
|
|
81
|
+
if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) {
|
|
82
|
+
_ = 0;
|
|
83
|
+
continue;
|
|
84
|
+
}
|
|
85
|
+
if (op[0] === 3 && (!t || op[1] > t[0] && op[1] < t[3])) {
|
|
86
|
+
_.label = op[1];
|
|
87
|
+
break;
|
|
88
|
+
}
|
|
89
|
+
if (op[0] === 6 && _.label < t[1]) {
|
|
90
|
+
_.label = t[1];
|
|
91
|
+
t = op;
|
|
92
|
+
break;
|
|
93
|
+
}
|
|
94
|
+
if (t && _.label < t[2]) {
|
|
95
|
+
_.label = t[2];
|
|
96
|
+
_.ops.push(op);
|
|
97
|
+
break;
|
|
98
|
+
}
|
|
99
|
+
if (t[2]) _.ops.pop();
|
|
100
|
+
_.trys.pop();
|
|
101
|
+
continue;
|
|
102
|
+
}
|
|
103
|
+
op = body.call(thisArg, _);
|
|
104
|
+
} catch (e) {
|
|
105
|
+
op = [
|
|
106
|
+
6,
|
|
107
|
+
e
|
|
108
|
+
];
|
|
109
|
+
y = 0;
|
|
110
|
+
} finally{
|
|
111
|
+
f = t = 0;
|
|
112
|
+
}
|
|
113
|
+
if (op[0] & 5) throw op[1];
|
|
114
|
+
return {
|
|
115
|
+
value: op[0] ? op[1] : void 0,
|
|
116
|
+
done: true
|
|
117
|
+
};
|
|
118
|
+
}
|
|
119
|
+
};
|
|
120
|
+
Object.defineProperty(exports, "__esModule", {
|
|
121
|
+
value: true
|
|
122
|
+
});
|
|
123
|
+
var SessionStorage = /** @class */ function() {
|
|
124
|
+
function SessionStorage() {
|
|
125
|
+
this._inMemoryStorage = {};
|
|
126
|
+
}
|
|
127
|
+
SessionStorage.prototype.set = function(key, value) {
|
|
128
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
129
|
+
return __generator(this, function(_a) {
|
|
130
|
+
if (window && window.sessionStorage) {
|
|
131
|
+
window.sessionStorage.setItem(key, JSON.stringify(value));
|
|
132
|
+
} else if (wx && wx.setStorageSync) {
|
|
133
|
+
wx.setStorageSync(key, value);
|
|
134
|
+
} else if (my && my.setStorageSync) {
|
|
135
|
+
my.setStorageSync(key, value);
|
|
136
|
+
} else if (tt && tt.setStorageSync) {
|
|
137
|
+
tt.setStorageSync(key, value);
|
|
138
|
+
} else {
|
|
139
|
+
// 使用内存环境
|
|
140
|
+
this._inMemoryStorage[key] = value;
|
|
141
|
+
}
|
|
142
|
+
return [
|
|
143
|
+
2 /*return*/
|
|
144
|
+
];
|
|
145
|
+
});
|
|
146
|
+
});
|
|
147
|
+
};
|
|
148
|
+
SessionStorage.prototype.get = function(key) {
|
|
149
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
150
|
+
var value;
|
|
151
|
+
return __generator(this, function(_a) {
|
|
152
|
+
if (window && window.sessionStorage) {
|
|
153
|
+
value = window.sessionStorage.getItem(key);
|
|
154
|
+
return [
|
|
155
|
+
2 /*return*/ ,
|
|
156
|
+
value ? JSON.parse(value) : value
|
|
157
|
+
];
|
|
158
|
+
} else if (wx && wx.getStorageSync) {
|
|
159
|
+
return [
|
|
160
|
+
2 /*return*/ ,
|
|
161
|
+
wx.getStorageSync(key)
|
|
162
|
+
];
|
|
163
|
+
} else if (my && my.getStorageSync) {
|
|
164
|
+
return [
|
|
165
|
+
2 /*return*/ ,
|
|
166
|
+
my.getStorageSync(key)
|
|
167
|
+
];
|
|
168
|
+
} else if (tt && tt.getStorageSync) {
|
|
169
|
+
return [
|
|
170
|
+
2 /*return*/ ,
|
|
171
|
+
tt.getStorageSync(key)
|
|
172
|
+
];
|
|
173
|
+
} else {
|
|
174
|
+
return [
|
|
175
|
+
2 /*return*/ ,
|
|
176
|
+
this._inMemoryStorage[key]
|
|
177
|
+
];
|
|
178
|
+
}
|
|
179
|
+
return [
|
|
180
|
+
2 /*return*/
|
|
181
|
+
];
|
|
182
|
+
});
|
|
183
|
+
});
|
|
184
|
+
};
|
|
185
|
+
SessionStorage.prototype.remove = function(key) {
|
|
186
|
+
return __awaiter(this, void 0, void 0, function() {
|
|
187
|
+
return __generator(this, function(_a) {
|
|
188
|
+
if (window && window.sessionStorage) {
|
|
189
|
+
window.sessionStorage.removeItem(key);
|
|
190
|
+
} else if (wx && wx.removeStorageSync) {
|
|
191
|
+
wx.removeStorageSync(key);
|
|
192
|
+
} else if (my && my.removeStorageSync) {
|
|
193
|
+
my.removeStorageSync(key);
|
|
194
|
+
} else if (tt && tt.removeStorageSync) {
|
|
195
|
+
tt.removeStorageSync(key);
|
|
196
|
+
} else {
|
|
197
|
+
delete this._inMemoryStorage[key];
|
|
198
|
+
}
|
|
199
|
+
return [
|
|
200
|
+
2 /*return*/
|
|
201
|
+
];
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
};
|
|
205
|
+
return SessionStorage;
|
|
206
|
+
}();
|
|
207
|
+
exports["default"] = SessionStorage;
|
package/package.json
CHANGED
|
@@ -1,16 +1,16 @@
|
|
|
1
|
-
{
|
|
2
|
-
"name": "axios-annotations",
|
|
3
|
-
"version": "
|
|
4
|
-
"
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
"
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
1
|
+
{
|
|
2
|
+
"name": "axios-annotations",
|
|
3
|
+
"version": "2.0.0",
|
|
4
|
+
"description": "HTTP client library uses Axios without Typescript.",
|
|
5
|
+
"main": "index.js",
|
|
6
|
+
"miniprogram": "lib",
|
|
7
|
+
"miniprogramRoot": "lib",
|
|
8
|
+
"keywords": [
|
|
9
|
+
"axios",
|
|
10
|
+
"axios-annotations",
|
|
11
|
+
"axios-decorators"
|
|
12
|
+
],
|
|
13
|
+
"author": "sitorhy",
|
|
14
|
+
"license": "MIT",
|
|
15
|
+
"homepage": "https://github.com/sitorhy/axios-annotations#readme"
|
|
16
|
+
}
|
package/plugins/auth/index.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
export default
|
|
1
|
+
/**
|
|
2
|
+
* 导出必须显示指定index文件,小程序包寻址没有默认文件
|
|
3
|
+
*/
|
|
4
|
+
export { Authorizer, SessionStorage, default as AuthorizationPlugin } from "../../lib/plugins/auth/index";
|
package/plugins/auth/index.js
CHANGED
|
@@ -1 +1,26 @@
|
|
|
1
|
-
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", {
|
|
3
|
+
value: true
|
|
4
|
+
});
|
|
5
|
+
exports.AuthorizationPlugin = exports.SessionStorage = exports.Authorizer = void 0;
|
|
6
|
+
/**
|
|
7
|
+
* 导出必须显示指定index文件,小程序包寻址没有默认文件
|
|
8
|
+
*/ var index_1 = require("../../lib/plugins/auth/index");
|
|
9
|
+
Object.defineProperty(exports, "Authorizer", {
|
|
10
|
+
enumerable: true,
|
|
11
|
+
get: function get() {
|
|
12
|
+
return index_1.Authorizer;
|
|
13
|
+
}
|
|
14
|
+
});
|
|
15
|
+
Object.defineProperty(exports, "SessionStorage", {
|
|
16
|
+
enumerable: true,
|
|
17
|
+
get: function get() {
|
|
18
|
+
return index_1.SessionStorage;
|
|
19
|
+
}
|
|
20
|
+
});
|
|
21
|
+
Object.defineProperty(exports, "AuthorizationPlugin", {
|
|
22
|
+
enumerable: true,
|
|
23
|
+
get: function get() {
|
|
24
|
+
return index_1["default"];
|
|
25
|
+
}
|
|
26
|
+
});
|
package/core/config.d.ts
DELETED
|
@@ -1,29 +0,0 @@
|
|
|
1
|
-
import {AxiosInstance} from "axios";
|
|
2
|
-
|
|
3
|
-
export default class Config {
|
|
4
|
-
constructor(protocol?: string, host?: string, port?: number, prefix?: string, plugins?: ((config: Config) => void)[]);
|
|
5
|
-
|
|
6
|
-
static forName(name: string): Config;
|
|
7
|
-
|
|
8
|
-
host: string;
|
|
9
|
-
|
|
10
|
-
port: number | null | string;
|
|
11
|
-
|
|
12
|
-
protocol: string;
|
|
13
|
-
|
|
14
|
-
prefix: string;
|
|
15
|
-
|
|
16
|
-
origin: string;
|
|
17
|
-
|
|
18
|
-
baseURL: string;
|
|
19
|
-
|
|
20
|
-
axios: AxiosInstance;
|
|
21
|
-
|
|
22
|
-
plugins: ((config: Config) => void)[];
|
|
23
|
-
|
|
24
|
-
register(name: string): Config;
|
|
25
|
-
|
|
26
|
-
unregister(): Config;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
export const config: Config;
|
package/core/config.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("../lib/core/config");
|
package/core/parser.d.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
declare const URLSearchParamsParser: {
|
|
2
|
-
encode: (encoder: object) => string;
|
|
3
|
-
|
|
4
|
-
decode: (data: object) => object;
|
|
5
|
-
|
|
6
|
-
has: (encoder: object, key: string) => boolean;
|
|
7
|
-
|
|
8
|
-
delete: (encoder: object, key: string) => void;
|
|
9
|
-
|
|
10
|
-
get: (encoder: object, key: string) => any;
|
|
11
|
-
|
|
12
|
-
append: (encoder: object, key: string, value: any) => void;
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default URLSearchParamsParser;
|
package/core/parser.js
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
module.exports = require("../lib/core/parser");
|