axios-annotations 1.1.2 → 1.1.3
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.
|
@@ -0,0 +1 @@
|
|
|
1
|
+
module.exports = require("../lib/decorator/request-with");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";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)}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _storage=_interopRequireDefault(require("./storage")),_history=_interopRequireDefault(require("./history"));function _interopRequireDefault(t){return t&&t.__esModule?t:{default:t}}function _regeneratorRuntime(){_regeneratorRuntime=function(){return a};var a={},t=Object.prototype,u=t.hasOwnProperty,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(t){i=function(t,e,r){return t[e]=r}}function s(t,e,r,n){var o,i,a,s,e=e&&e.prototype instanceof h?e:h,e=Object.create(e.prototype),n=new w(n||[]);return e._invoke=(o=t,i=r,a=n,s="suspendedStart",function(t,e){if("executing"===s)throw new Error("Generator is already running");if("completed"===s){if("throw"===t)throw e;return x()}for(a.method=t,a.arg=e;;){var r=a.delegate;if(r){r=function t(e,r){var n=e.iterator[r.method];if(void 0===n){if(r.delegate=null,"throw"===r.method){if(e.iterator.return&&(r.method="return",r.arg=void 0,t(e,r),"throw"===r.method))return f;r.method="throw",r.arg=new TypeError("The iterator does not provide a 'throw' method")}return f}n=c(n,e.iterator,r.arg);if("throw"===n.type)return r.method="throw",r.arg=n.arg,r.delegate=null,f;n=n.arg;return n?n.done?(r[e.resultName]=n.value,r.next=e.nextLoc,"return"!==r.method&&(r.method="next",r.arg=void 0),r.delegate=null,f):n:(r.method="throw",r.arg=new TypeError("iterator result is not an object"),r.delegate=null,f)}(r,a);if(r){if(r===f)continue;return r}}if("next"===a.method)a.sent=a._sent=a.arg;else if("throw"===a.method){if("suspendedStart"===s)throw s="completed",a.arg;a.dispatchException(a.arg)}else"return"===a.method&&a.abrupt("return",a.arg);s="executing";r=c(o,i,a);if("normal"===r.type){if(s=a.done?"completed":"suspendedYield",r.arg===f)continue;return{value:r.arg,done:a.done}}"throw"===r.type&&(s="completed",a.method="throw",a.arg=r.arg)}}),e}function c(t,e,r){try{return{type:"normal",arg:t.call(e,r)}}catch(t){return{type:"throw",arg:t}}}a.wrap=s;var f={};function h(){}function l(){}function p(){}var e={},y=(i(e,n,function(){return this}),Object.getPrototypeOf),y=y&&y(y(b([]))),d=(y&&y!==t&&u.call(y,n)&&(e=y),p.prototype=h.prototype=Object.create(e));function v(t){["next","throw","return"].forEach(function(e){i(t,e,function(t){return this._invoke(e,t)})})}function g(a,s){var e;this._invoke=function(r,n){function t(){return new s(function(t,e){!function e(t,r,n,o){var i,t=c(a[t],a,r);if("throw"!==t.type)return(r=(i=t.arg).value)&&"object"==_typeof(r)&&u.call(r,"__await")?s.resolve(r.__await).then(function(t){e("next",t,n,o)},function(t){e("throw",t,n,o)}):s.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 m(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 _(t){var e=t.completion||{};e.type="normal",delete e.arg,t.completion=e}function w(t){this.tryEntries=[{tryLoc:"root"}],t.forEach(m,this),this.reset(!0)}function b(e){if(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(u.call(e,r))return t.value=e[r],t.done=!1,t;return t.value=void 0,t.done=!0,t}).next=t}return{next:x}}function x(){return{value:void 0,done:!0}}return i(d,"constructor",l.prototype=p),i(p,"constructor",l),l.displayName=i(p,o,"GeneratorFunction"),a.isGeneratorFunction=function(t){t="function"==typeof t&&t.constructor;return!!t&&(t===l||"GeneratorFunction"===(t.displayName||t.name))},a.mark=function(t){return Object.setPrototypeOf?Object.setPrototypeOf(t,p):(t.__proto__=p,i(t,o,"GeneratorFunction")),t.prototype=Object.create(d),t},a.awrap=function(t){return{__await:t}},v(g.prototype),i(g.prototype,r,function(){return this}),a.AsyncIterator=g,a.async=function(t,e,r,n,o){void 0===o&&(o=Promise);var i=new g(s(t,e,r,n),o);return a.isGeneratorFunction(e)?i:i.next().then(function(t){return t.done?t.value:i.next()})},v(d),i(d,o,"Generator"),i(d,n,function(){return this}),i(d,"toString",function(){return"[object Generator]"}),a.keys=function(r){var t,n=[];for(t in r)n.push(t);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=b,w.prototype={constructor:w,reset:function(t){if(this.prev=0,this.next=0,this.sent=this._sent=void 0,this.done=!1,this.delegate=null,this.method="next",this.arg=void 0,this.tryEntries.forEach(_),!t)for(var e in this)"t"===e.charAt(0)&&u.call(this,e)&&!isNaN(+e.slice(1))&&(this[e]=void 0)},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=void 0),!!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=u.call(o,"catchLoc"),s=u.call(o,"finallyLoc");if(a&&s){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(!s)throw new 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&&u.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,f):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),f},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),_(r),f}},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,_(o)),n}throw new Error("illegal catch attempt")},delegateYield:function(t,e,r){return this.delegate={iterator:b(t),resultName:e,nextLoc:r},"next"===this.method&&(this.arg=void 0),f}},a}function asyncGeneratorStep(t,e,r,n,o,i,a){try{var s=t[i](a),u=s.value}catch(t){return void r(t)}s.done?e(u):Promise.resolve(u).then(n,o)}function _asyncToGenerator(s){return function(){var t=this,a=arguments;return new Promise(function(e,r){var n=s.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,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 in t?Object.defineProperty(t,e,{value:r,enumerable:!0,configurable:!0,writable:!0}):t[e]=r,t}var Authorizer=function(){function t(){_classCallCheck(this,t),_defineProperty(this,"_sessionKey","$_SESSION"),_defineProperty(this,"_sessionStorage",new _storage.default),_defineProperty(this,"_sessionHistory",new _history.default)}var e,r,n,o,i;return _createClass(t,[{key:"sessionKey",get:function(){return this._sessionKey},set:function(t){this._sessionKey=t}},{key:"sessionStorage",get:function(){return this._sessionStorage},set:function(t){this._sessionStorage=t}},{key:"sessionHistory",get:function(){return this._sessionHistory},set:function(t){this._sessionHistory=t}},{key:"getSession",value:(i=_asyncToGenerator(_regeneratorRuntime().mark(function t(){return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.sessionStorage.get(this.sessionKey);case 2:return t.abrupt("return",t.sent);case 3:case"end":return t.stop()}},t,this)})),function(){return i.apply(this,arguments)})},{key:"storageSession",value:(o=_asyncToGenerator(_regeneratorRuntime().mark(function t(e){return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.sessionStorage.set(this.sessionKey,e);case 2:case"end":return t.stop()}},t,this)})),function(t){return o.apply(this,arguments)})},{key:"refreshSession",value:(n=_asyncToGenerator(_regeneratorRuntime().mark(function t(e){return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.abrupt("return",null);case 1:case"end":return t.stop()}},t)})),function(t){return n.apply(this,arguments)})},{key:"withAuthentication",value:function(t,e){var r,n;e&&(r=e.access_token,n=e.accessToken,e=e.token,(r||n||e)&&(t.headers.Authorization="Bearer "+(r||n||e)))}},{key:"checkSession",value:function(t,e){t=t.headers.Authorization||t.headers.authorization,t=t&&t.split(" ")[1]||"";return(e.access_token||e.accessToken||e.token)!==t&&(!this.sessionHistory.size||!this.sessionHistory.check(t))}},{key:"checkResponse",value:function(t){return 401!==(t||{status:0}).status}},{key:"onAuthorizedDenied",value:(r=_asyncToGenerator(_regeneratorRuntime().mark(function t(e){return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:throw e;case 1:case"end":return t.stop()}},t)})),function(t){return r.apply(this,arguments)})},{key:"onSessionInvalidated",value:function(){}},{key:"invalidateSession",value:(e=_asyncToGenerator(_regeneratorRuntime().mark(function t(){return _regeneratorRuntime().wrap(function(t){for(;;)switch(t.prev=t.next){case 0:return t.next=2,this.sessionStorage.remove(this.sessionKey);case 2:this.onSessionInvalidated();case 3:case"end":return t.stop()}},t,this)})),function(){return e.apply(this,arguments)})}]),t}();exports.default=Authorizer;
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _storage=_interopRequireDefault(require("./storage")),_history=_interopRequireDefault(require("./history"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function asyncGeneratorStep(e,t,n,r,s,o,i){try{var a=e[o](i),u=a.value}catch(e){return void n(e)}a.done?t(u):Promise.resolve(u).then(r,s)}function _asyncToGenerator(a){return function(){var e=this,i=arguments;return new Promise(function(t,n){var r=a.apply(e,i);function s(e){asyncGeneratorStep(r,t,n,s,o,"next",e)}function o(e){asyncGeneratorStep(r,t,n,s,o,"throw",e)}s(void 0)})}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var n=0;n<t.length;n++){var r=t[n];r.enumerable=r.enumerable||!1,r.configurable=!0,"value"in r&&(r.writable=!0),Object.defineProperty(e,r.key,r)}}function _createClass(e,t,n){return t&&_defineProperties(e.prototype,t),n&&_defineProperties(e,n),Object.defineProperty(e,"prototype",{writable:!1}),e}function _defineProperty(e,t,n){return t in e?Object.defineProperty(e,t,{value:n,enumerable:!0,configurable:!0,writable:!0}):e[t]=n,e}var Authorizer=function(){function e(){_classCallCheck(this,e),_defineProperty(this,"_sessionKey","$_SESSION"),_defineProperty(this,"_sessionStorage",new _storage.default),_defineProperty(this,"_sessionHistory",new _history.default)}var t,n,r,s,o;return _createClass(e,[{key:"sessionKey",get:function(){return this._sessionKey},set:function(e){this._sessionKey=e}},{key:"sessionStorage",get:function(){return this._sessionStorage},set:function(e){this._sessionStorage=e}},{key:"sessionHistory",get:function(){return this._sessionHistory},set:function(e){this._sessionHistory=e}},{key:"getSession",value:(o=_asyncToGenerator(regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sessionStorage.get(this.sessionKey);case 2:return e.abrupt("return",e.sent);case 3:case"end":return e.stop()}},e,this)})),function(){return o.apply(this,arguments)})},{key:"storageSession",value:(s=_asyncToGenerator(regeneratorRuntime.mark(function e(t){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sessionStorage.set(this.sessionKey,t);case 2:case"end":return e.stop()}},e,this)})),function(e){return s.apply(this,arguments)})},{key:"refreshSession",value:(r=_asyncToGenerator(regeneratorRuntime.mark(function e(t){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.abrupt("return",null);case 1:case"end":return e.stop()}},e)})),function(e){return r.apply(this,arguments)})},{key:"withAuthentication",value:function(e,t){var n,r;t&&(n=t.access_token,r=t.accessToken,t=t.token,(n||r||t)&&(e.headers.Authorization="Bearer "+(n||r||t)))}},{key:"checkSession",value:function(e,t){e=e.headers.Authorization||e.headers.authorization,e=e&&e.split(" ")[1]||"";return(t.access_token||t.accessToken||t.token)!==e&&(!this.sessionHistory.size||!this.sessionHistory.check(e))}},{key:"checkResponse",value:function(e){return 401!==(e||{status:0}).status}},{key:"onAuthorizedDenied",value:(n=_asyncToGenerator(regeneratorRuntime.mark(function e(t){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:throw t;case 1:case"end":return e.stop()}},e)})),function(e){return n.apply(this,arguments)})},{key:"onSessionInvalidated",value:function(){}},{key:"invalidateSession",value:(t=_asyncToGenerator(regeneratorRuntime.mark(function e(){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,this.sessionStorage.remove(this.sessionKey);case 2:this.onSessionInvalidated();case 3:case"end":return e.stop()}},e,this)})),function(){return t.apply(this,arguments)})}]),e}();exports.default=Authorizer;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=AuthorizationPlugin;var _queue=_interopRequireDefault(require("./queue"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function asyncGeneratorStep(e,r,t,n,s,a,o){try{var u=e[a](o),i=u.value}catch(e){return void t(e)}u.done?r(i):Promise.resolve(i).then(n,s)}function _asyncToGenerator(u){return function(){var e=this,o=arguments;return new Promise(function(r,t){var n=u.apply(e,o);function s(e){asyncGeneratorStep(n,r,t,s,a,"next",e)}function a(e){asyncGeneratorStep(n,r,t,s,a,"throw",e)}s(void 0)})}}function AuthorizationPlugin(u){return function(e){var r,t,s=!1,a=null,o=new _queue.default(u);e.axios.interceptors.response.use(function(e){return a&&(u.sessionHistory.add(a),a=null),e},(r=_asyncToGenerator(regeneratorRuntime.mark(function e(r){var t,n;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(t=r.response,u.checkResponse(t)){e.next=66;break}if(s){e.next=61;break}return s=!0,e.next=6,u.getSession();case 6:if(n=e.sent,u.sessionHistory.isDeprecated(n))return e.prev=8,e.next=11,u.onAuthorizedDenied(r);e.next=21;break;case 11:u.sessionHistory.clean(),e.next=17;break;case 14:throw e.prev=14,e.t0=e.catch(8),r;case 17:return e.prev=17,s=!1,o.clear(),e.finish(17);case 21:if(a=n,u.checkSession(r.config,n)){e.next=48;break}return e.prev=23,e.t1=u,e.next=27,u.refreshSession(n);case 27:return e.t2=e.sent,e.next=30,e.t1.storageSession.call(e.t1,e.t2);case 30:e.next=48;break;case 32:return e.prev=32,e.t3=e.catch(23),u.sessionHistory.deprecate(n),e.prev=35,e.next=38,u.onAuthorizedDenied(e.t3);case 38:u.sessionHistory.clean(),e.next=44;break;case 41:throw e.prev=41,e.t4=e.catch(35),r;case 44:return e.prev=44,s=!1,o.clear(),e.finish(44);case 48:for(s=!1;o.size;)o.pop();return e.prev=50,e.next=53,o.resend(r);case 53:return e.abrupt("return",e.sent);case 56:throw e.prev=56,e.t5=e.catch(50),e.t5;case 59:e.next=64;break;case 61:return e.next=63,o.push(r);case 63:return e.abrupt("return",e.sent);case 64:e.next=67;break;case 66:throw r;case 67:case"end":return e.stop()}},e,null,[[8,14,17,21],[23,32],[35,41,44,48],[50,56]])})),function(e){return r.apply(this,arguments)})),e.axios.interceptors.request.use((t=_asyncToGenerator(regeneratorRuntime.mark(function e(r){var t;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:return e.next=2,u.getSession();case 2:return t=e.sent,u.withAuthentication(r,t),e.abrupt("return",r);case 5:case"end":return e.stop()}},e)})),function(e){return t.apply(this,arguments)}))}}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";
|
|
1
|
+
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var _axios=_interopRequireDefault(require("axios"));function _interopRequireDefault(e){return e&&e.__esModule?e:{default:e}}function asyncGeneratorStep(e,r,t,n,i,o,a){try{var u=e[o](a),s=u.value}catch(e){return void t(e)}u.done?r(s):Promise.resolve(s).then(n,i)}function _asyncToGenerator(u){return function(){var e=this,a=arguments;return new Promise(function(r,t){var n=u.apply(e,a);function i(e){asyncGeneratorStep(n,r,t,i,o,"next",e)}function o(e){asyncGeneratorStep(n,r,t,i,o,"throw",e)}i(void 0)})}}function _classCallCheck(e,r){if(!(e instanceof r))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,r){for(var t=0;t<r.length;t++){var n=r[t];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _createClass(e,r,t){return r&&_defineProperties(e.prototype,r),t&&_defineProperties(e,t),Object.defineProperty(e,"prototype",{writable:!1}),e}function _defineProperty(e,r,t){return r in e?Object.defineProperty(e,r,{value:t,enumerable:!0,configurable:!0,writable:!0}):e[r]=t,e}function random(e,r){return(Math.random()*(r-e+1)|0)+e}function sleep(t){return new Promise(function(e){var r=setTimeout(function(){clearTimeout(r),r=void 0,e()},t)})}var PendingQueue=function(){function r(e){_classCallCheck(this,r),_defineProperty(this,"_queue",[]),_defineProperty(this,"_authorizer",null),_defineProperty(this,"_axios",_axios.default.create()),this._authorizer=e}var t;return _createClass(r,[{key:"resend",value:(t=_asyncToGenerator(regeneratorRuntime.mark(function e(r){var t,n,i,o=arguments;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:t=1<o.length&&void 0!==o[1]?o[1]:3,n=0;case 2:if(!(n<t)){e.next=25;break}if(0<n)return e.next=6,sleep(random(3e3,5e3));e.next=6;break;case 6:return e.next=8,this._authorizer.getSession();case 8:if(i=e.sent,this._authorizer.sessionHistory.isDeprecated(i))throw r;e.next=11;break;case 11:return e.prev=11,this._authorizer.withAuthentication(r.config,i),e.next=15,this._axios.request(r.config);case 15:return e.abrupt("return",e.sent);case 18:if(e.prev=18,e.t0=e.catch(11),t-1<=n)throw e.t0;e.next=22;break;case 22:++n,e.next=2;break;case 25:case"end":return e.stop()}},e,this,[[11,18]])})),function(e){return t.apply(this,arguments)})},{key:"push",value:function(t){var n=this;return new Promise(function(e,r){n._queue.push({error:t,resolve:e,reject:r})})}},{key:"pop",value:function(){var e=this._queue.shift(),r=e.error,t=e.resolve,e=e.reject;this.resend(r).then(t).catch(e)}},{key:"clear",value:function(){this._queue.splice(0).forEach(function(e){var r=e.error;(0,e.reject)(r)})}},{key:"size",get:function(){return this._queue.length}}]),r}();exports.default=PendingQueue;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";function
|
|
1
|
+
"use strict";function asyncGeneratorStep(e,t,r,n,o,a,i){try{var s=e[a](i),c=s.value}catch(e){return void r(e)}s.done?t(c):Promise.resolve(c).then(n,o)}function _asyncToGenerator(s){return function(){var e=this,i=arguments;return new Promise(function(t,r){var n=s.apply(e,i);function o(e){asyncGeneratorStep(n,t,r,o,a,"next",e)}function a(e){asyncGeneratorStep(n,t,r,o,a,"throw",e)}o(void 0)})}}function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}function _defineProperties(e,t){for(var r=0;r<t.length;r++){var n=t[r];n.enumerable=n.enumerable||!1,n.configurable=!0,"value"in n&&(n.writable=!0),Object.defineProperty(e,n.key,n)}}function _createClass(e,t,r){return t&&_defineProperties(e.prototype,t),r&&_defineProperties(e,r),Object.defineProperty(e,"prototype",{writable:!1}),e}function _defineProperty(e,t,r){return t in e?Object.defineProperty(e,t,{value:r,enumerable:!0,configurable:!0,writable:!0}):e[t]=r,e}Object.defineProperty(exports,"__esModule",{value:!0}),exports.default=void 0;var SessionStorage=function(){function e(){_classCallCheck(this,e),_defineProperty(this,"_inMemoryStorage",{})}var t,r,n;return _createClass(e,[{key:"set",value:(n=_asyncToGenerator(regeneratorRuntime.mark(function e(t,r){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:window&&window.sessionStorage?window.sessionStorage.setItem(t,JSON.stringify(r)):wx&&wx.setStorageSync?wx.setStorageSync(t,r):my&&my.setStorageSync?my.setStorageSync(t,r):tt&&tt.setStorageSync?tt.setStorageSync(t,r):this._inMemoryStorage[t]=r;case 1:case"end":return e.stop()}},e,this)})),function(e,t){return n.apply(this,arguments)})},{key:"get",value:(r=_asyncToGenerator(regeneratorRuntime.mark(function e(t){var r;return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:if(window&&window.sessionStorage)return r=window.sessionStorage.getItem(t),e.abrupt("return",JSON.parse(r));e.next=5;break;case 5:if(wx&&wx.getStorageSync)return e.abrupt("return",wx.getStorageSync(t));e.next=9;break;case 9:if(my&&my.getStorageSync)return e.abrupt("return",my.getStorageSync(t));e.next=13;break;case 13:if(tt&&tt.getStorageSync)return e.abrupt("return",tt.getStorageSync(t));e.next=17;break;case 17:return e.abrupt("return",this._inMemoryStorage[t]);case 18:case"end":return e.stop()}},e,this)})),function(e){return r.apply(this,arguments)})},{key:"remove",value:(t=_asyncToGenerator(regeneratorRuntime.mark(function e(t){return regeneratorRuntime.wrap(function(e){for(;;)switch(e.prev=e.next){case 0:window&&window.sessionStorage?window.sessionStorage.removeItem(t):wx&&wx.removeStorageSync?wx.removeStorageSync(t):my&&my.removeStorageSync?my.removeStorageSync(t):tt&&tt.removeStorageSync?tt.removeStorageSync(t):delete this._inMemoryStorage[t];case 1:case"end":return e.stop()}},e,this)})),function(e){return t.apply(this,arguments)})}]),e}();exports.default=SessionStorage;
|