forked from gilf/angular2-indexeddb
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathangular2-indexeddb.min.js
2 lines (2 loc) · 4.6 KB
/
angular2-indexeddb.min.js
1
2
"use strict";var __decorate=this&&this.__decorate||function(a,b,c,d){var e,f=arguments.length,g=f<3?b:null===d?d=Object.getOwnPropertyDescriptor(b,c):d;if("object"==typeof Reflect&&"function"==typeof Reflect.decorate)g=Reflect.decorate(a,b,c,d);else for(var h=a.length-1;h>=0;h--)(e=a[h])&&(g=(f<3?e(g):f>3?e(b,c,g):e(b,c))||g);return f>3&&g&&Object.defineProperty(b,c,g),g},__metadata=this&&this.__metadata||function(a,b){if("object"==typeof Reflect&&"function"==typeof Reflect.metadata)return Reflect.metadata(a,b)},core_1=require("@angular/core"),AngularIndexedDB=function(){function a(a,b){this.utils=new Utils,this.dbWrapper=new DbWrapper(a,b)}return a.prototype.createStore=function(a,b){var c=this,d=this,e=new Promise(function(e,f){c.dbWrapper.dbVersion=a;var g=c.utils.indexedDB.open(c.dbWrapper.dbName,a);g.onsuccess=function(a){d.dbWrapper.db=g.result,e()},g.onerror=function(a){f("IndexedDB error: "+a.target.errorCode)},g.onupgradeneeded=function(a){b(a,d.dbWrapper.db)}});return e},a.prototype.getByKey=function(a,b){var c=this,d=new Promise(function(d,e){c.dbWrapper.validateBeforeTransaction(a,e);var f,g=c.dbWrapper.createTransaction({storeName:a,dbMode:c.utils.dbMode.readOnly,error:function(a){e(a)},complete:function(a){}}),h=g.objectStore(a);f=h.get(b),f.onsuccess=function(a){d(a.target.result)}});return d},a.prototype.getAll=function(a,b,c){var d=this,e=new Promise(function(e,f){d.dbWrapper.validateBeforeTransaction(a,f);var g,h=d.dbWrapper.createTransaction({storeName:a,dbMode:d.utils.dbMode.readOnly,error:function(a){f(a)},complete:function(a){}}),i=h.objectStore(a),j=[];if(c){var k=i.index(c);g=k.openCursor(b)}else g=i.openCursor(b);g.onerror=function(a){f(a)},g.onsuccess=function(a){var b=a.target.result;b?(j.push(b.value),b.continue()):e(j)}});return e},a.prototype.add=function(a,b,c){var d=this,e=new Promise(function(e,f){d.dbWrapper.validateBeforeTransaction(a,f);var g=d.dbWrapper.createTransaction({storeName:a,dbMode:d.utils.dbMode.readWrite,error:function(a){f(a)},complete:function(a){e({key:c,value:b})}}),h=g.objectStore(a);h.add(b,c)});return e},a.prototype.update=function(a,b,c){var d=this,e=new Promise(function(e,f){d.dbWrapper.validateBeforeTransaction(a,f);var g=d.dbWrapper.createTransaction({storeName:a,dbMode:d.utils.dbMode.readWrite,error:function(a){f(a)},complete:function(a){e(b)},abort:function(a){f(a)}}),h=g.objectStore(a);h.put(b,c)});return e},a.prototype.delete=function(a,b){var c=this,d=new Promise(function(d,e){c.dbWrapper.validateBeforeTransaction(a,e);var f=c.dbWrapper.createTransaction({storeName:a,dbMode:c.utils.dbMode.readWrite,error:function(a){e(a)},complete:function(a){d()},abort:function(a){e(a)}}),g=f.objectStore(a);g.delete(b)});return d},a.prototype.openCursor=function(a,b,c){var d=this,e=new Promise(function(e,f){d.dbWrapper.validateBeforeTransaction(a,f);var g=d.dbWrapper.createTransaction({storeName:a,dbMode:d.utils.dbMode.readOnly,error:function(a){f(a)},complete:function(a){e()},abort:function(a){f(a)}}),h=g.objectStore(a),i=h.openCursor(c);i.onsuccess=function(a){b(a),e()}});return e},a.prototype.clear=function(a){var b=this,c=new Promise(function(c,d){b.dbWrapper.validateBeforeTransaction(a,d);var e=b.dbWrapper.createTransaction({storeName:a,dbMode:b.utils.dbMode.readWrite,error:function(a){d(a)},complete:function(a){c()},abort:function(a){d(a)}}),f=e.objectStore(a);f.clear(),c()});return c},a.prototype.getByIndex=function(a,b,c){var d=this,e=new Promise(function(e,f){d.dbWrapper.validateBeforeTransaction(a,f);var g=d.dbWrapper.createTransaction({storeName:a,dbMode:d.utils.dbMode.readOnly,error:function(a){f(a)},abort:function(a){f(a)},complete:function(a){}}),h=g.objectStore(a),i=h.index(b),j=i.get(c);j.onsuccess=function(a){e(a.target.result)}});return e},a=__decorate([core_1.Injectable(),__metadata("design:paramtypes",[String,Number])],a)}();exports.AngularIndexedDB=AngularIndexedDB;var Utils=function(){function a(){this.indexedDB=window.indexedDB||window.mozIndexedDB||window.webkitIndexedDB||window.msIndexedDB,this.dbMode={readOnly:"readonly",readWrite:"readwrite"}}return a}(),DbWrapper=function(){function a(a,b){this.dbName=a,this.dbVersion=b||1,this.db=null}return a.prototype.validateStoreName=function(a){return this.db.objectStoreNames.contains(a)},a.prototype.validateBeforeTransaction=function(a,b){this.db||b("You need to use the createStore function to create a database before you query it!"),this.validateStoreName(a)||b("objectStore does not exists: "+a)},a.prototype.createTransaction=function(a){var b=this.db.transaction(a.storeName,a.dbMode);return b.onerror=a.error,b.oncomplete=a.complete,b.onabort=a.abort,b},a}();
//# sourceMappingURL=angular2-indexeddb.min.js.map