forked from dfahlander/idb-iegap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
idb-iegap.min.js
2 lines (2 loc) · 15.2 KB
/
idb-iegap.min.js
1
2
navigator.userAgent.indexOf("Trident/")!==-1&&function(n,t){function a(n,t){return typeof t!="object"&&(t=t()),Object.keys(t).forEach(function(i){n[i]=t[i]}),n}function b(n){return{from:function(t){return n.prototype=Object.create(t.prototype),n.prototype.constructor=n,{extend:function(i){a(n.prototype,typeof i!="object"?i(t.prototype):i)}}}}}function r(n,t){if(typeof n=="object")Object.keys(t).forEach(function(i){var u=Object.getOwnPropertyDescriptor(n,i),r=t[i](u);r.hasOwnProperty("value")&&r.writable!==!1&&(r.writable=!0);Object.defineProperty(n,i,a({configurable:!0,enumerable:!0},r))});else return t(n)}function s(n,i){var f,r,o,h,u,e;if(n.hasOwnProperty(i))return n[i];if(!i)return n;if(typeof i!="string"){for(f=[],r=0,o=i.length;r<o;++r)h=s(n,i[r]),f.push(h);return f}return(u=i.indexOf("."),u!==-1)?(e=n[i.substr(0,u)],e===t?t:s(e,i.substr(u+1))):t}function h(n,t){return function(i){return console.log("Warning: IEGap polyfill failed to "+(n.call?n():n)+": "+i.target.error),i.stopPropagation(),i.preventDefault(),t(),!1}}function nt(n,i,r,u,e,o){var c,l;try{if(c=s(r,i.keyPath),c===t)return o();l=n.add({fk:u,k:f(c)});l.onerror=h("add compound index",o);l.onsuccess=function(t){e&&e.push({store:n,del:!0,pk:t.target.result});o()}}catch(a){console.log("IEGap polyfill exception when adding compound index key");o()}}function tt(n,i,r,u,f,e){var o,c,l;try{if(o=s(r,i.keyPath),o===t)return e();if(Array.isArray(o)){o.forEach(function(t){var r=n.add({fk:u,k:t});r.onerror=h(function(){return"add multiEntry index "+t+" for "+i.storeName+"."+i.keyPath},a);r.onsuccess=function(t){f&&f.push({store:n,del:!0,pk:t.target.result});a()}});l=o.length;function a(){--l==0&&e()}}else c=n.add({fk:u,k:o}),c.onerror=h("add index",e),c.onsuccess=function(t){f&&f.push({store:n,del:!0,pk:t.target.result});e()}}catch(v){console.log("IEGap polyfill exception when adding multientry key")}}function it(n,t,i){function f(){function r(){--t==0&&i()}var f=n.objectStore,t;u.forEach(function(n){var t=f.delete(n);t.onerror=h("delete meta index",r);t.onsuccess=r});t=u.length;t===0&&i()}var r=n.openKeyCursor(t),u=[];r.onerror=h("list indexed references",i);r.onsuccess=function(){var n=r.result;if(!n)return f();u.push(n.primaryKey);n.continue()}}function ot(n,t,i){function r(){--u==0&&t&&t()}var u=n.length;n.forEach(function(n){var t=n.del?n.store.delete(n.pk):n.pk?n.store.add(n.obj,n.pk):n.store.add(n.obj);t.onerror=h(i||"executing bulk",r);t.onsuccess=r})}function st(){for(var n=4;n>=-4;--n)v[n]=Math.pow(32768,n)}function rt(n,t,i){for(var r=t-1,o=n<0?32767:0,s=n<0?-n:n,u="",f,e;r>=-i;)f=s/v[r]&32767^o,e=f<<1|1,u+=String.fromCharCode(e),--r;return u}function d(n,i,r,u){var e=0,o=i-1,h=n.length,f,s;if(i+r!=h)return t;for(f=0;f<h;++f)s=n.charCodeAt(f)-1>>1,u?e-=v[o]*(s^32767):e+=v[o]*s,--o;return e}function f(n){for(var t,r=n.length,u=new Array(r),i=0;i<r;++i)t=n[i],u[i]=t instanceof Date?"D"+rt(t.getTime(),4,0):typeof t=="string"?"S"+t:isNaN(t)?t?"J"+JSON.stringify(t):typeof t=="undefined"?"u":"0":(t<0?"N":"n")+rt(t,5,4);return JSON.stringify(u)}function c(n){for(var e=JSON.parse(n),o=e.length,s=new Array(o),f=0;f<o;++f){var h=e[f],r=h[0],u=h.substr(1),i=t;r==="D"?i=new Date(d(u,4,0)):r==="J"?i=JSON.parse(u):r==="S"?i=u:r==="N"?i=d(u,5,4,!0):r==="n"?i=d(u,5,4,!1):r==="u"?i=t:r==="0"&&(i=null);s[f]=i}return s}function p(n,t,i){n._iegapmeta=i;t.objectStore("$iegapmeta").put(i,1)}function l(n){if(Array.isArray(n))return f(n);if(n instanceof o){var t=Array.isArray(n.upper)?f(n.upper):n.upper,i=Array.isArray(n.lower)?f(n.lower):n.lower;return n.lower===null?u.upperBound(t,n.upperOpen):n.upper===null?u.lowerBound(i,n.lowerOpen):u.bound(i,t,!!n.lowerOpen,!!n.upperOpen)}return n}function g(n,t,i,r,u){this._idx=n;this._store=t;this._compound=Array.isArray(r);this._multiEntry=u;this.keyPath=r;this.name=i;this.objectStore=t;this.unique=n.unique}function w(n,t,i,r,u,f){this._cursor=n;this._store=i;this.direction=n.direction;this.key=u;this.primaryKey=r;this.source=t;arguments.length>=6&&(this.value=f)}function ut(){this._el={}}function e(n,t,i){this._el={};this.source=n;this.transaction=t;this.readyState="pending";var r=this,u={get:function(){return r}};i(function(n,t){r.result=t;Object.defineProperty(n,"target",u);r.readyState="done";r.dispatchEvent(n)},function(n,t){r.error=t||n.target.error;Object.defineProperty(n,"target",u);r.readyState="done";n.type!="error"&&Object.defineProperty(n,"type",{get:function(){return"error"}});r.dispatchEvent(n)},this)}function ft(){e.apply(this,arguments)}function o(n,t,i,r){this.lower=n;this.upper=t;this.lowerOpen=i;this.upperOpen=r}function et(n){return Object.defineProperties(n,{contains:{configurable:!0,writable:!0,value:function(t){return n.indexOf(t)!==-1}},item:{configurable:!0,writable:!0,value:function(t){return n[t]}}}),n}function ht(){var a=Object.getOwnPropertyDescriptor(y.prototype,"objectStoreNames").get,v=y.prototype.deleteObjectStore,t=y.prototype.createObjectStore;st();n.open=r(n.open,function(n){return function(){var i=n.apply(this,arguments);return new ft(this,null,function(n,r,u){i.onerror=r;i.onblocked=function(n){u.dispatchEvent(n)};i.onupgradeneeded=function(n){var r,f;u.transaction=i.transaction;r=u.result=i.result;r._upgradeTransaction=i.transaction;r._iegapmeta={stores:{}};a.apply(r).contains("$iegapmeta")||(f=t.call(r,"$iegapmeta"),f.add(r._iegapmeta,1));n.target=n.currentTarget=u;u.dispatchEvent(n)};i.onsuccess=function(t){var u=i.result,e,f;delete u._upgradeTransaction;u._iegapmeta={stores:{}};try{e=u.transaction(["$iegapmeta"],"readonly");f=e.objectStore("$iegapmeta").get(1);f.onerror=r;f.onsuccess=function(){u._iegapmeta=f.result;n(t,u)}}catch(o){r(t,o)}}})}});u.bound=r(u.bound,function(n){return function(t,i,r,u){return Array.isArray(t)?new o(t,i,r,u):n.apply(this,arguments)}});u.lowerBound=r(u.lowerBound,function(n){return function(t,i){return Array.isArray(t)?new o(t,null,i,null):n.apply(this,arguments)}});u.upperBound=r(u.upperBound,function(n){return function(t,i){return Array.isArray(t)?new o(null,t,null,i):n.apply(this,arguments)}});u.only=r(u.only,function(n){return function(t){return Array.isArray(t)?new o(t,t):n.apply(this,arguments)}});i.prototype.count=r(i.prototype.count,function(n){return function(t){return arguments.length>0&&(arguments[0]=l(t)),n.apply(this,arguments)}});i.prototype.get=r(i.prototype.get,function(n){return function(t){return arguments.length>0&&(arguments[0]=l(t)),n.apply(this,arguments)}});i.prototype.openCursor=r(i.prototype.openCursor,function(n){return function(t){var h=this.transaction.db._iegapmeta.stores[this.name],i,l,r,s;if(!h)return n.apply(this,arguments);if(Array.isArray(t)&&(t=new o(t,t)),i=h.compound,i&&t&&!(t instanceof o))throw new RangeError("Primary key is compound but given range is not.");return l=i&&t?u.bound(f(t.lower),f(t.upper),t.lowerOpen,t.upperOpen):t,arguments[0]=l,r=n.apply(this,arguments),s=this,new e(this,this.transaction,function(n,t){r.onerror=t;r.onsuccess=function(t){var r=t.target.result,u,f;r?(u=i?c(r.key):r.key,f=new w(r,s,s,u,u,r.value),n(t,f)):n(t,null)}})}});i.prototype.createIndex=r(i.prototype.createIndex,function(n){function i(n,i,r,u){var f=n.transaction.db,e="$iegap-"+n.name+"-"+i,o=f._iegapmeta,c;if(u.multiEntry&&Array.isArray(r)){t.call(f,"dummy",{keyPath:"",autoIncrement:!0});throw"invalid access";}var s=t.call(f,e,{autoIncrement:!0}),h=o.stores[n.name]||(o.stores[n.name]={indexes:{},metaStores:[]}),l={name:i,keyPath:r,multiEntry:u.multiEntry||!1,unique:u.unique||!1,compound:Array.isArray(r),storeName:n.name,idxStoreName:e};return h.indexes[i]=l,h.metaStores.push(e),s.createIndex("fk","fk",{unique:!1}),c=s.createIndex("k","k",{unique:u.unique||!1}),p(f,n.transaction,o),n._reindexing||(n._reindexing=!0,n.openCursor().onsuccess=function(t){delete n._reindexing;var i=t.target.result;i&&(i.update(i.value),i.continue())}),new g(c,n,i,r,u.multiEntry)}return function(t,r,u){return Array.isArray(r)||u&&u.multiEntry?i(this,t,r,u||{}):n.apply(this,arguments)}});i.prototype.deleteIndex=r(i.prototype.deleteIndex,function(n){return function(t){var i=this.transaction.db,f=i._iegapmeta,r=f.stores[this.name],u;if(!r||(u=r.indexes[t],!u))return n.apply(this,arguments);v.call(i,u.idxStoreName);delete r.indexes[t];p(i,this.transaction,f)}});i.prototype.index=r(i.prototype.index,function(n){return function(t){var r=this.transaction.db._iegapmeta.stores[this.name],i;return r?(i=r.indexes[t],i?new g(this.transaction.objectStore(i.idxStoreName).index("k"),this,i.name,i.keyPath,i.multiEntry):n.apply(this,arguments)):n.apply(this,arguments)}});i.prototype.add=r(i.prototype.add,function(n){return function(t,i){var u=this.transaction.db._iegapmeta.stores[this.name],r,h,o;if(!u)return n.apply(this,arguments);if(u.compound){if(i)return this.add(null);i=f(s(t,u.keyPath));r=n.call(this,t,i)}else r=n.apply(this,arguments);return(h=Object.keys(u.indexes),!u.compound&&h.length===0)?r:(o=this,new e(this,this.transaction,function(n,f){function v(){if(y&&(l||e))if(e){var t=!1;e.preventDefault=function(){t=!0};f(e);t||o.transaction.abort()}else n(l,u.compound?c(r.result):r.result)}function w(){function n(){--i==0&&(e?ot(p,function(){y=!0;v()},"rolling back index additions"):(y=!0,v()))}var i=h.length;h.forEach(function(i){var r=u.indexes[i],f=o.transaction.objectStore(r.idxStoreName);if(r.multiEntry)tt(f,r,t,a,p,n);else if(r.compound)nt(f,r,t,a,p,n);else throw"IEGap assert error";})}var l=null,e=null,y=!1,p=[],a=i||o.keyPath&&s(t,o.keyPath);a?(w(),r.onerror=function(n){e=n;n.preventDefault();v()},r.onsuccess=function(n){l=n;v()}):(r.onerror=f,r.onsuccess=function(n){l=n;a=r.result;w()})}))}});i.prototype.put=r(i.prototype.put,function(n){return function(t,i){var r=this.transaction.db._iegapmeta.stores[this.name],u,o,h;if(!r)return n.apply(this,arguments);if(r.compound){if(i)return this.add(null);i=f(s(t,r.keyPath));u=n.call(this,t,i)}else u=n.apply(this,arguments);return(o=Object.keys(r.indexes),!r.compound&&o.length===0)?u:(h=this,new e(this,this.transaction,function(n,i){function s(){function i(){--u==0&&n(e,r.compound?c(f):f)}var u=o.length;o.forEach(function(n){var u=r.indexes[n],e=h.transaction.objectStore(u.idxStoreName);it(e.index("fk"),f,function(){if(u.multiEntry)tt(e,u,t,f,null,i);else if(u.compound)nt(e,u,t,f,null,i);else{i();throw"IEGap assert error";}})})}var e=null,f;u.onerror=i;u.onsuccess=function(n){e=n;f=u.result;s()}}))}});i.prototype.delete=r(i.prototype.delete,function(n){return function(t){var i=this.transaction.db._iegapmeta.stores[this.name],r,u,o;return i?(i.compound&&(t=f(t)),r=n.call(this,t),u=Object.keys(i.indexes),u.length==0)?r:(o=this,new e(this,this.transaction,function(n,f){function s(){function f(){--r==0&&n(e)}var r=u.length;u.forEach(function(n){var r=i.indexes[n],u=o.transaction.objectStore(r.idxStoreName);it(u.index("fk"),t,f)})}var e=null;r.onerror=f;r.onsuccess=function(n){e=n;s()}})):n.apply(this,arguments)}});i.prototype.clear=r(i.prototype.clear,function(n){return function(){var t=n.apply(this,arguments),i=this.transaction.db._iegapmeta.stores[this.name],r;return i?(r=this,new e(this,this.transaction,function(n,u){function o(){function u(){--t==0&&n(f)}var t=e.length;if(t===0)return n(f);e.forEach(function(n){var f=i.indexes[n],e=r.transaction.objectStore(f.idxStoreName),t=e.clear();t.onerror=h("clearing meta store",u);t.onsuccess=u})}var e=Object.keys(i.indexes),f=null;t.onerror=u;t.onsuccess=function(n){f=n;o()}})):t}});r(i.prototype,{indexNames:function(n){return{get:function(){var t=[].slice.call(n.get.apply(this)),i=this.transaction.db._iegapmeta.stores[this.name];return i&&(t=t.concat(Object.keys(i.indexes))),new et(t)}}},autoIncrement:function(n){return{get:function(){var t=this.transaction.db._iegapmeta.stores[this.name];return t&&"autoIncrement"in t?t.autoIncrement:n.get.call(this)}}},keyPath:function(n){return{get:function(){var t=this.transaction.db._iegapmeta.stores[this.name];return t&&"keyPath"in t?t.keyPath:n.get.call(this)}}}});r(y.prototype,{transaction:function(n){return{value:function(t,i){t=typeof t=="string"?[t]:[].slice.call(t);var r=this._iegapmeta.stores;return t.forEach(function(n){var i=r[n];i&&(t=t.concat(i.metaStores))}),n.value.call(this,t,i||"readonly")}}},objectStoreNames:function(n){return{get:function(){return new et([].slice.call(n.get.apply(this)).filter(function(n){return n.indexOf("$iegap")!==0}))}}},createObjectStore:function(n){return{value:function(t,i){var r,e=!1,u,f;if(i&&Array.isArray(i.keyPath)){if(e=!0,i.autoIncrement)throw new RangeError("Cannot autoincrement compound key");r=n.value.call(this,t)}else r=n.value.apply(this,arguments);return u=this._iegapmeta,f=u.stores[t]||(u.stores[t]={indexes:{},metaStores:[]}),f.keyPath=i&&i.keyPath||null,f.compound=e,f.autoIncrement=i&&i.autoIncrement||!1,p(this,r.transaction,u),r}}},deleteObjectStore:function(n){return{value:function(t){n.value.call(this,t);var i=this._iegapmeta,r=i.stores[t];if(r){if(r.metaStores.forEach(function(t){n.value.call(this,t)}),delete i.stores[t],!this._upgradeTransaction)throw"assert error";p(this,this._upgradeTransaction,i)}}}}})}var v={},u=window.IDBKeyRange,i=window.IDBObjectStore,y=window.IDBDatabase;b(g).from(Object).extend(function(){function n(n,t,i,r){return new e(n,n.objectStore.transaction,function(e,s){var h=n._compound,v=Array.isArray(n.objectStore.keyPath),l,a;h&&Array.isArray(t)&&(t=new o(t,t));l=h&&t?u.bound(f(t.lower),f(t.upper),t.lowerOpen,t.upperOpen):t;typeof l=="undefined"&&(l=null);a=n._idx.openCursor(l,i);a.onerror=s;a.onsuccess=r?function(t){var i=t.target.result,r;i?(r=n._store.get(i.value.fk),r.onerror=s,r.onsuccess=function(){if(!r.result)return i.continue();var u=h?c(i.key):i.key,f=v?c(i.value.fk):i.value.fk;e(t,new w(i,n,n.objectStore,f,u,r.result))}):e(t,null)}:function(t){var i=t.target.result,r=h?c(i.key):i.key,u=v?c(i.value.fk):i.value.fk;e(t,i&&new w(i,n,n.objectStore,u,r))}})}return{count:function(n){return arguments.length>0&&(arguments[0]=l(n)),this._idx.count.apply(this._idx,arguments)},get:function(n){var i=this,t=this._idx.get(l(n));return new e(this,this.objectStore.transaction,function(n,r){t.onsuccess=function(u){var f=t.result&&t.result.fk;f?(t=i.objectStore.get(f),t.onsuccess=function(){n(u,t.result)},t.onerror=r):n(u)};t.onerror=r})},getKey:function(n){var i=this,t=this._idx.get(l(n));return new e(this,this.objectStore.transaction,function(n,i){t.onsuccess=function(t){var i=t.target.result;n(t,i&&i.fk)};t.onerror=i})},openKeyCursor:function(t,i){return n(this,t,i)},openCursor:function(t,i){return n(this,t,i,!0)}}});a(w.prototype,function(){return{advance:function(n){this._cursor.advance(n)},"continue":function(n){return n?Array.isArray(n)?this._cursor.continue(f(n)):this._cursor.continue(n):this._cursor.continue()},"delete":function(){return this._store.delete(this.primaryKey)},update:function(n){return this._store.keyPath?this._store.put(n):this._store.put(n,this.primaryKey)}}});a(ut.prototype,function(){return{addEventListener:function(n,t){this._el[n]?this._el[n].push(t):this._el[n]=[t]},removeEventListener:function(n,t){var i=this._el[n],r;i&&(r=i.indexOf(t),r!==-1&&i.splice(r,1))},dispatchEvent:function(n){var t=this["on"+n.type],i,r,u;if(t&&t(n)===!1)return!1;if(i=this._el[n.type],i){for(r=0,u=i.length;r<u;++r)if(t=i[r],(t.handleEvent||t)(n)===!1)return!1;return!0}}}});b(e).from(ut).extend({onsuccess:null,onerror:null});b(ft).from(e).extend({onblocked:null,onupgradeneeded:null});ht()}(window.indexedDB||window.msIndexedDB);
//# sourceMappingURL=idb-iegap.min.js.map