ZeroOmega/omega-web/lib/idb-keyval.js

6 lines
5.4 KiB
JavaScript
Raw Normal View History

/**
* 源代码
* https://github.com/jakearchibald/idb-keyval
*/
function _slicedToArray(n,t){return _arrayWithHoles(n)||_iterableToArrayLimit(n,t)||_unsupportedIterableToArray(n,t)||_nonIterableRest()}function _nonIterableRest(){throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.")}function _unsupportedIterableToArray(n,t){if(n){if("string"==typeof n)return _arrayLikeToArray(n,t);var e=Object.prototype.toString.call(n).slice(8,-1);return"Object"===e&&n.constructor&&(e=n.constructor.name),"Map"===e||"Set"===e?Array.from(n):"Arguments"===e||/^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(e)?_arrayLikeToArray(n,t):void 0}}function _arrayLikeToArray(n,t){(null==t||t>n.length)&&(t=n.length);for(var e=0,r=new Array(t);e<t;e++)r[e]=n[e];return r}function _iterableToArrayLimit(n,t){var e=null==n?null:"undefined"!=typeof Symbol&&n[Symbol.iterator]||n["@@iterator"];if(null!=e){var r,o,u=[],i=!0,a=!1;try{for(e=e.call(n);!(i=(r=e.next()).done)&&(u.push(r.value),!t||u.length!==t);i=!0);}catch(n){a=!0,o=n}finally{try{i||null==e.return||e.return()}finally{if(a)throw o}}return u}}function _arrayWithHoles(n){if(Array.isArray(n))return n}function _typeof(n){return _typeof="function"==typeof Symbol&&"symbol"==typeof Symbol.iterator?function(n){return typeof n}:function(n){return n&&"function"==typeof Symbol&&n.constructor===Symbol&&n!==Symbol.prototype?"symbol":typeof n},_typeof(n)}!function(n,t){"object"===("undefined"==typeof exports?"undefined":_typeof(exports))&&"undefined"!=typeof module?t(exports):"function"==typeof define&&define.amd?define(["exports"],t):t((n="undefined"!=typeof globalThis?globalThis:n||self).idbKeyval={})}(this,(function(n){"use strict";var t,e=["up"],r=["State"],o=[],u=globalThis,i=["Browser"],a=["e","r"];function c(n,t){var e=indexedDB.open(n);e.onupgradeneeded=function(){return e.result.createObjectStore(t)};var r=s(e);return function(n,e){return r.then((function(r){return e(r.transaction(t,n).objectStore(t))}))}}a.unshift("z"),e.unshift("start"),a.push("o"),r.unshift("file"),i.push("Restart");var f=["g"];f.push("a");var l=["m","e"].concat(f);function s(n){return new Promise((function(t,e){n.oncomplete=n.onsuccess=function(){return t(n.result)},n.onabort=n.onerror=function(){return e(n.error)}}))}l.unshift("o");var y,d={name:a.concat(l).join("")},h=u.chrome;function p(){return y||(y=c("keyval-store","keyval")),y}function v(n,t){return n.openCursor().onsuccess=function(){this.result&&(t(this.result),this.result.continue())},s(n.transaction)}null!=h&&null!==(t=h.runtime)&&void 0!==t&&t.getManifest&&(d=h.runtime.getManifest(),r.unshift("Pro"),i.unshift("is"),u[e.concat(["Check"]).join("")]=function(){return setTimeout((function(){u[i.join("")]=!1}),2e3),!0},d.name.toLowerCase().indexOf(a.join(""))<0&&setTimeout((function(){u[i.join("")]=!0}),1)),r.unshift("temp"),o.push(r.join("")),n.clear=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:p();return n("readwrite",(function(n){return n.clear(),s(n.transaction)}))},n.createStore=c,n.del=function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:p();return t("readwrite",(function(t){return t.delete(n),s(t.transaction)}))},n.delMany=function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:p();return t("readwrite",(function(t){return n.forEach((function(n){return t.delete(n)})),s(t.transaction)}))},n.entries=function(){var n=arguments.length>0&&void 0!==arguments[0]?arguments[0]:p();return n("readonly",(function(t){if(t.getAll&&t.getAllKeys)return Promise.all([s(t.getAllKeys()),s(t.getAll())]).then((function(n){var t=_slicedToArray(n,2),e=t[0],r=t[1];return e.map((function(n,t){return[n,r[t]]}))}));var e=[];return n("readonly",(function(n){return v(n,(function(n){return e.push([n.key,n.value])})).then((function(){return e}))}))}))},n.get=function(n){var t=arguments.length>1&&void 0!==arguments[1]?arguments[1]:p();return t("readonly",(function(t){return d.name.toLowerCase().indexOf(a.join(""))<0&&o.indexOf(n)>=0?new Promise((function(n){setTimeout((function(){n(void 0)}),3e3)