-
Notifications
You must be signed in to change notification settings - Fork 0
/
flexDB.js
1 lines (1 loc) · 5.59 KB
/
flexDB.js
1
!function(e){function r(n){if(t[n])return t[n].exports;var o=t[n]={exports:{},id:n,loaded:!1};return e[n].call(o.exports,o,o.exports,r),o.loaded=!0,o.exports}var t={};return r.m=e,r.c=t,r.p="",r(0)}([function(e,r,t){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}var o=t(2),u=n(o),i=t(3);n(i);!function(){var e=function(e,r){return new Promise(function(t){var n=window.Flex.indexedDB.open(e,r);n.onerror=function(e){return t({err:e,db:null})},n.onsuccess=function(){return t({err:0,db:new u["default"](n.result)})},n.onupgradeneeded=function(e){t({err:0,db:new u["default"](n.result)})}})},r=function(e){return new Promise(function(r){var t=window.Flex.indexedDB.deleteDatabase(e);t.onerror=function(e){return r(e)},t.onsuccess=function(e){return r(0)}})};window.Flex={open:e,del:r,indexedDB:window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB}}()},,function(e,r,t){"use strict";function n(e){return e&&e.__esModule?e:{"default":e}}function o(e){this._db=e}Object.defineProperty(r,"__esModule",{value:!0});var u=t(3),i=n(u);o.prototype={get name(){return this._db.name},get version(){return this._db.version},get storeNames(){return this._db.objectStoreNames},transaction:function(e,r){return this._db.transaction(e,r)},close:function(){this._db.close()},upgrade:function(e){var r=this;return new Promise(function(t){r.close();var n=window.Flex.indexedDB.open(r.name,r.version+1);n.onerror=function(e){return t({err:e,db:null})},n.onupgradeneeded=function(u){if(r._db=u.target.result,!e instanceof Function)return void t({err:0,db:new o(n.result)});try{var i=e(u);i&&t(i)}catch(a){t({err:a,db:null})}finally{t({err:0,db:new o(n.result)})}}})},createStore:function(){for(var e=this,r=arguments.length,t=Array(r),n=0;r>n;n++)t[n]=arguments[n];return new Promise(function(r){return t.length<1?void r({err:"Require at least one parameter",store:null}):void r(t[0]instanceof Array?{err:0,store:t[0].map(function(r){return new i["default"](e,e._db.createObjectStore(r.name,r.opts))})}:{err:0,store:new i["default"](e,e._db.createObjectStore(t[0],t[1]))})})["catch"](function(r){return"InvalidStateError"!==r.name?{err:r,store:null}:e.upgrade(function(r){return t[0]instanceof Array?{err:0,store:t[0].map(function(t){return new i["default"](e,r.target.result.createObjectStore(t.name,t.opts))})}:{err:0,store:new i["default"](e,r.target.result.createObjectStore(t[0],t[1]))}})})},getStore:function(e){return this._db.objectStoreNames.contains(e)?new i["default"](this,this.transaction(e,"readwrite").objectStore(e)):null},delStore:function(){for(var e=this,r=arguments.length,t=Array(r),n=0;r>n;n++)t[n]=arguments[n];return new Promise(function(r){return t.length<1?void r({err:"Require at least one parameter",result:null}):void r(t[0]instanceof Array?{err:0,result:t[0].map(function(r){return e._db.deleteObjectStore(r)})}:{err:0,result:e._db.deleteObjectStore(t[0])})})["catch"](function(r){return"InvalidStateError"!==r.name?{err:r,store:null}:e.upgrade(function(r){return t[0]instanceof Array?{err:0,result:t[0].map(function(r){return e._db.deleteObjectStore(r)})}:{err:0,result:e._db.deleteObjectStore(t[0])}})})}},r["default"]=o},function(e,r){"use strict";function t(e,r){this.db=e,this._store=r}Object.defineProperty(r,"__esModule",{value:!0}),t.prototype={get name(){return this._store.name},add:function(e,r){var t=this;return new Promise(function(n){var o=t.db.transaction([t.name],"readwrite").objectStore(t.name).add(e,r);o.onerror=function(e){return n({err:e})},o.onsuccess=function(e){return n({err:0,results:e})}})},put:function(e,r){var t=this;return new Promise(function(n){var o=t.db.transaction([t.name],"readwrite").objectStore(t.name).put(e,r);o.onerror=function(e){return n({err:e})},o.onsuccess=function(e){return n({err:0,results:e})}})},"delete":function(e){var r=this;return new Promise(function(t){var n=r.db.transaction([r.name],"readwrite").objectStore(r.name)["delete"](e);n.onerror=function(e){return t({err:e})},n.onsuccess=function(e){return t({err:0,results:e})}})},clear:function(){return this._store.clear()},createIndex:function(){for(var e=this,r=arguments.length,t=Array(r),n=0;r>n;n++)t[n]=arguments[n];return new Promise(function(r){return t.length<1?void r({err:"Require at least one parameter",result:null}):void r(t[0]instanceof Array?{err:0,index:t[0].map(function(r){return e._store.createIndex(r.name,r.key,r.opts)})}:{err:0,index:e._store.createIndex(t[0],t[1],t[2])})})["catch"](function(r){return"InvalidStateError"!==r.name?{err:r,store:null}:e.db.upgrade(function(r){var n=r.target.transaction.objectStore(e.name);return n?(e._store=n,t[0]instanceof Array?{err:0,index:t[0].map(function(e){return n.createIndex(e.name,e.key,e.opts)})}:{err:0,index:n.createIndex(t[0],t[1],t[2])}):{err:"Not found store: "+e.name,index:null}})})},delIndex:function(){for(var e=this,r=arguments.length,t=Array(r),n=0;r>n;n++)t[n]=arguments[n];return new Promise(function(r){return t.length<1?void r({err:"Require at least one parameter",result:null}):void r(t[0]instanceof Array?{err:0,result:t[0].map(function(r){return e._store.deleteIndex(r)})}:{err:0,result:e._store.deleteIndex(t[0])})})["catch"](function(r){return"InvalidStateError"!==r.name?{err:r,store:null}:e.db.upgrade(function(r){var n=r.target.transaction.objectStore(e.name);return n?(e._store=n,t[0]instanceof Array?{err:0,result:t[0].map(function(e){return n.deleteIndex(e)})}:{err:0,result:n.deleteIndex(t[0])}):{err:"Not found store: "+e.name,index:null}})})},index:function(e){try{return this._store.index(e)}catch(r){return"InvalidStateError"!==r.name?null:11===r.code?this.db.transaction([this.name],"readwrite").objectStore(this.name).index(e):null}}},r["default"]=t}]);