idb-keyval-cjs-compat.min.js
2.23 KB
"use strict";var _createClass=function(){function e(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)}}return function(t,r,n){return r&&e(t.prototype,r),n&&e(t,n),t}}();function _classCallCheck(e,t){if(!(e instanceof t))throw new TypeError("Cannot call a class as a function")}Object.defineProperty(exports,"__esModule",{value:!0});var Store=function(){function e(){var t=arguments.length>0&&void 0!==arguments[0]?arguments[0]:"keyval-store",r=arguments.length>1&&void 0!==arguments[1]?arguments[1]:"keyval";_classCallCheck(this,e),this.storeName=r,this._dbp=new Promise(function(e,n){var o=indexedDB.open(t,1);o.onerror=function(){return n(o.error)},o.onsuccess=function(){return e(o.result)},o.onupgradeneeded=function(){o.result.createObjectStore(r)}})}return _createClass(e,[{key:"_withIDBStore",value:function(e,t){var r=this;return this._dbp.then(function(n){return new Promise(function(o,u){var i=n.transaction(r.storeName,e);i.oncomplete=function(){return o()},i.onabort=i.onerror=function(){return u(i.error)},t(i.objectStore(r.storeName))})})}}]),e}(),store=void 0;function getDefaultStore(){return store||(store=new Store),store}function get(e){var t=void 0;return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:getDefaultStore())._withIDBStore("readonly",function(r){t=r.get(e)}).then(function(){return t.result})}function set(e,t){return(arguments.length>2&&void 0!==arguments[2]?arguments[2]:getDefaultStore())._withIDBStore("readwrite",function(r){r.put(t,e)})}function del(e){return(arguments.length>1&&void 0!==arguments[1]?arguments[1]:getDefaultStore())._withIDBStore("readwrite",function(t){t.delete(e)})}function clear(){return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:getDefaultStore())._withIDBStore("readwrite",function(e){e.clear()})}function keys(){var e=[];return(arguments.length>0&&void 0!==arguments[0]?arguments[0]:getDefaultStore())._withIDBStore("readonly",function(t){(t.openKeyCursor||t.openCursor).call(t).onsuccess=function(){this.result&&(e.push(this.result.key),this.result.continue())}}).then(function(){return e})}exports.Store=Store,exports.get=get,exports.set=set,exports.del=del,exports.clear=clear,exports.keys=keys;