idb-wrapper
Advanced tools
Comparing version 1.6.1 to 1.6.2
@@ -5,4 +5,4 @@ { | ||
"main": "idbstore.js", | ||
"version": "1.6.1", | ||
"version": "1.6.2", | ||
"dependencies": {} | ||
} |
@@ -5,4 +5,4 @@ /*global window:false, self:false, define:false, module:false */ | ||
* @license IDBWrapper - A cross-browser wrapper for IndexedDB | ||
* Version 1.6.1 | ||
* Copyright (c) 2011 - 2015 Jens Arps | ||
* Version 1.6.2 | ||
* Copyright (c) 2011 - 2016 Jens Arps | ||
* http://jensarps.de/ | ||
@@ -14,2 +14,5 @@ * | ||
(function (name, definition, global) { | ||
'use strict'; | ||
if (typeof define === 'function') { | ||
@@ -55,3 +58,3 @@ define(definition); | ||
* @name IDBStore | ||
* @version 1.6.1 | ||
* @version 1.6.2 | ||
* | ||
@@ -149,3 +152,4 @@ * @param {Object} [kwArgs] An options object used to configure the store and | ||
IDBStore.prototype = /** @lends IDBStore */ { | ||
/** @lends IDBStore.prototype */ | ||
var proto = { | ||
@@ -157,2 +161,3 @@ /** | ||
* @type {Function} | ||
* @constructs | ||
*/ | ||
@@ -166,3 +171,3 @@ constructor: IDBStore, | ||
*/ | ||
version: '1.6.1', | ||
version: '1.6.2', | ||
@@ -602,2 +607,7 @@ /** | ||
} | ||
var count = dataArray.length; | ||
var called = false; | ||
var hasSuccess = false; | ||
var batchTransaction = this.db.transaction([this.storeName] , this.consts.READ_WRITE); | ||
@@ -610,7 +620,4 @@ batchTransaction.oncomplete = function () { | ||
batchTransaction.onerror = onError; | ||
var count = dataArray.length; | ||
var called = false; | ||
var hasSuccess = false; | ||
var onItemSuccess = function () { | ||
@@ -709,2 +716,9 @@ count--; | ||
} | ||
var keyField = options.keyField || this.keyPath; | ||
var count = dataArray.length; | ||
var called = false; | ||
var hasSuccess = false; | ||
var index = 0; // assume success callbacks are executed in order | ||
var batchTransaction = this.db.transaction([this.storeName], this.consts.READ_WRITE); | ||
@@ -721,8 +735,2 @@ batchTransaction.oncomplete = function () { | ||
var keyField = options.keyField || this.keyPath; | ||
var count = dataArray.length; | ||
var called = false; | ||
var hasSuccess = false; | ||
var index = 0; // assume success callbacks are executed in order | ||
var onItemSuccess = function (event) { | ||
@@ -850,2 +858,9 @@ var record = dataArray[index++]; | ||
} | ||
var data = []; | ||
var count = keyArray.length; | ||
var called = false; | ||
var hasSuccess = false; | ||
var result = null; | ||
var batchTransaction = this.db.transaction([this.storeName] , this.consts.READ_ONLY); | ||
@@ -859,8 +874,2 @@ batchTransaction.oncomplete = function () { | ||
var data = []; | ||
var count = keyArray.length; | ||
var called = false; | ||
var hasSuccess = false; | ||
var result = null; | ||
var onItemSuccess = function (event) { | ||
@@ -1358,3 +1367,3 @@ if (event.target.result || arrayType == 'dense') { | ||
var empty = {}; | ||
var mixin = function (target, source) { | ||
function mixin (target, source) { | ||
var name, s; | ||
@@ -1368,5 +1377,6 @@ for (name in source) { | ||
return target; | ||
}; | ||
} | ||
IDBStore.version = IDBStore.prototype.version; | ||
IDBStore.prototype = proto; | ||
IDBStore.version = proto.version; | ||
@@ -1373,0 +1383,0 @@ return IDBStore; |
/* | ||
IDBWrapper - A cross-browser wrapper for IndexedDB | ||
Version 1.6.1 | ||
Copyright (c) 2011 - 2015 Jens Arps | ||
Version 1.6.2 | ||
Copyright (c) 2011 - 2016 Jens Arps | ||
http://jensarps.de/ | ||
@@ -9,23 +9,23 @@ | ||
*/ | ||
(function(h,i,l){"function"===typeof define?define(i):"undefined"!==typeof module&&module.exports?module.exports=i():l[h]=i()})("IDBStore",function(){var h=function(a){throw a;},i=function(){},l={storeName:"Store",storePrefix:"IDBWrapper-",dbVersion:1,keyPath:"id",autoIncrement:!0,onStoreReady:function(){},onError:h,indexes:[],implementationPreference:["indexedDB","webkitIndexedDB","mozIndexedDB","shimIndexedDB"]},j=function(a,b){"undefined"==typeof b&&"function"==typeof a&&(b=a);"[object Object]"!= | ||
Object.prototype.toString.call(a)&&(a={});for(var c in l)this[c]="undefined"!=typeof a[c]?a[c]:l[c];this.dbName=this.storePrefix+this.storeName;this.dbVersion=parseInt(this.dbVersion,10)||1;b&&(this.onStoreReady=b);var d="object"==typeof window?window:self;this.implementation=this.implementationPreference.filter(function(a){return a in d})[0];this.idb=d[this.implementation];this.keyRange=d.IDBKeyRange||d.webkitIDBKeyRange||d.mozIDBKeyRange;this.consts={READ_ONLY:"readonly",READ_WRITE:"readwrite", | ||
VERSION_CHANGE:"versionchange",NEXT:"next",NEXT_NO_DUPLICATE:"nextunique",PREV:"prev",PREV_NO_DUPLICATE:"prevunique"};this.openDB()};j.prototype={constructor:j,version:"1.6.1",db:null,dbName:null,dbVersion:null,store:null,storeName:null,storePrefix:null,keyPath:null,autoIncrement:null,indexes:null,implementationPreference:null,implementation:"",onStoreReady:null,onError:null,_insertIdCount:0,openDB:function(){var a=this.idb.open(this.dbName,this.dbVersion),b=!1;a.onerror=function(a){var b=!1;"error"in | ||
a.target?b="VersionError"==a.target.error.name:"errorCode"in a.target&&(b=12==a.target.errorCode);if(b)this.onError(Error("The version number provided is lower than the existing one."));else this.onError(a)}.bind(this);a.onsuccess=function(a){if(!b)if(this.db)this.onStoreReady();else if(this.db=a.target.result,"string"==typeof this.db.version)this.onError(Error("The IndexedDB implementation in this browser is outdated. Please upgrade your browser."));else if(this.db.objectStoreNames.contains(this.storeName)){this.store= | ||
this.db.transaction([this.storeName],this.consts.READ_ONLY).objectStore(this.storeName);var d=Array.prototype.slice.call(this.getIndexList());this.indexes.forEach(function(a){var c=a.name;c?(this.normalizeIndexData(a),this.hasIndex(c)?(this.indexComplies(this.store.index(c),a)||(b=!0,this.onError(Error('Cannot modify index "'+c+'" for current version. Please bump version number to '+(this.dbVersion+1)+"."))),d.splice(d.indexOf(c),1)):(b=!0,this.onError(Error('Cannot create new index "'+c+'" for current version. Please bump version number to '+ | ||
(this.dbVersion+1)+".")))):(b=!0,this.onError(Error("Cannot create index: No index name given.")))},this);d.length&&(b=!0,this.onError(Error('Cannot delete index(es) "'+d.toString()+'" for current version. Please bump version number to '+(this.dbVersion+1)+".")));b||this.onStoreReady()}else this.onError(Error("Object store couldn't be created."))}.bind(this);a.onupgradeneeded=function(a){this.db=a.target.result;if(this.db.objectStoreNames.contains(this.storeName))this.store=a.target.transaction.objectStore(this.storeName); | ||
else{a={autoIncrement:this.autoIncrement};if(null!==this.keyPath)a.keyPath=this.keyPath;this.store=this.db.createObjectStore(this.storeName,a)}var d=Array.prototype.slice.call(this.getIndexList());this.indexes.forEach(function(a){var c=a.name;c||(b=!0,this.onError(Error("Cannot create index: No index name given.")));this.normalizeIndexData(a);this.hasIndex(c)?(this.indexComplies(this.store.index(c),a)||(this.store.deleteIndex(c),this.store.createIndex(c,a.keyPath,{unique:a.unique,multiEntry:a.multiEntry})), | ||
d.splice(d.indexOf(c),1)):this.store.createIndex(c,a.keyPath,{unique:a.unique,multiEntry:a.multiEntry})},this);d.length&&d.forEach(function(a){this.store.deleteIndex(a)},this)}.bind(this)},deleteDatabase:function(a,b){if(this.idb.deleteDatabase){this.db.close();var c=this.idb.deleteDatabase(this.dbName);c.onsuccess=a;c.onerror=b}else b(Error("Browser does not support IndexedDB deleteDatabase!"))},put:function(a,b,c,d){null!==this.keyPath&&(d=c,c=b,b=a);d||(d=h);c||(c=i);var e=!1,f=null,g=this.db.transaction([this.storeName], | ||
this.consts.READ_WRITE);g.oncomplete=function(){(e?c:d)(f)};g.onabort=d;g.onerror=d;null!==this.keyPath?(this._addIdPropertyIfNeeded(b),a=g.objectStore(this.storeName).put(b)):a=g.objectStore(this.storeName).put(b,a);a.onsuccess=function(a){e=!0;f=a.target.result};a.onerror=d;return g},get:function(a,b,c){c||(c=h);b||(b=i);var d=!1,e=null,f=this.db.transaction([this.storeName],this.consts.READ_ONLY);f.oncomplete=function(){(d?b:c)(e)};f.onabort=c;f.onerror=c;a=f.objectStore(this.storeName).get(a); | ||
a.onsuccess=function(a){d=!0;e=a.target.result};a.onerror=c;return f},remove:function(a,b,c){c||(c=h);b||(b=i);var d=!1,e=null,f=this.db.transaction([this.storeName],this.consts.READ_WRITE);f.oncomplete=function(){(d?b:c)(e)};f.onabort=c;f.onerror=c;a=f.objectStore(this.storeName)["delete"](a);a.onsuccess=function(a){d=!0;e=a.target.result};a.onerror=c;return f},batch:function(a,b,c){c||(c=h);b||(b=i);if("[object Array]"!=Object.prototype.toString.call(a))c(Error("dataArray argument must be of type Array.")); | ||
else if(0===a.length)return b(!0);var d=this.db.transaction([this.storeName],this.consts.READ_WRITE);d.oncomplete=function(){(g?b:c)(g)};d.onabort=c;d.onerror=c;var e=a.length,f=!1,g=!1,k=function(){e--;0===e&&!f&&(g=f=!0)};a.forEach(function(a){var b=a.type,e=a.key,g=a.value,a=function(a){d.abort();f||(f=!0,c(a,b,e))};if("remove"==b)g=d.objectStore(this.storeName)["delete"](e),g.onsuccess=k,g.onerror=a;else if("put"==b)null!==this.keyPath?(this._addIdPropertyIfNeeded(g),g=d.objectStore(this.storeName).put(g)): | ||
g=d.objectStore(this.storeName).put(g,e),g.onsuccess=k,g.onerror=a},this);return d},putBatch:function(a,b,c){return this.batch(a.map(function(a){return{type:"put",value:a}}),b,c)},upsertBatch:function(a,b,c,d){"function"==typeof b&&(d=c=b,b={});d||(d=h);c||(c=i);b||(b={});"[object Array]"!=Object.prototype.toString.call(a)&&d(Error("dataArray argument must be of type Array."));var e=this.db.transaction([this.storeName],this.consts.READ_WRITE);e.oncomplete=function(){m?c(a):d(!1)};e.onabort=d;e.onerror= | ||
d;var f=b.keyField||this.keyPath,g=a.length,k=!1,m=!1,j=0,o=function(b){a[j++][f]=b.target.result;g--;0===g&&!k&&(m=k=!0)};a.forEach(function(a){var b=a.key;null!==this.keyPath?(this._addIdPropertyIfNeeded(a),a=e.objectStore(this.storeName).put(a)):a=e.objectStore(this.storeName).put(a,b);a.onsuccess=o;a.onerror=function(a){e.abort();k||(k=!0,d(a))}},this);return e},removeBatch:function(a,b,c){return this.batch(a.map(function(a){return{type:"remove",key:a}}),b,c)},getBatch:function(a,b,c,d){c||(c= | ||
h);b||(b=i);d||(d="sparse");if("[object Array]"!=Object.prototype.toString.call(a))c(Error("keyArray argument must be of type Array."));else if(0===a.length)return b([]);var e=this.db.transaction([this.storeName],this.consts.READ_ONLY);e.oncomplete=function(){(k?b:c)(j)};e.onabort=c;e.onerror=c;var f=[],g=a.length,k=!1,j=null,l=function(a){a.target.result||"dense"==d?f.push(a.target.result):"sparse"==d&&f.length++;g--;0===g&&(k=!0,j=f)};a.forEach(function(a){a=e.objectStore(this.storeName).get(a); | ||
a.onsuccess=l;a.onerror=function(a){j=a;c(a);e.abort()}},this);return e},getAll:function(a,b){b||(b=h);a||(a=i);var c=this.db.transaction([this.storeName],this.consts.READ_ONLY),d=c.objectStore(this.storeName);d.getAll?this._getAllNative(c,d,a,b):this._getAllCursor(c,d,a,b);return c},_getAllNative:function(a,b,c,d){var e=!1,f=null;a.oncomplete=function(){(e?c:d)(f)};a.onabort=d;a.onerror=d;a=b.getAll();a.onsuccess=function(a){e=!0;f=a.target.result};a.onerror=d},_getAllCursor:function(a,b,c,d){var e= | ||
[],f=!1,g=null;a.oncomplete=function(){(f?c:d)(g)};a.onabort=d;a.onerror=d;a=b.openCursor();a.onsuccess=function(a){(a=a.target.result)?(e.push(a.value),a["continue"]()):(f=!0,g=e)};a.onError=d},clear:function(a,b){b||(b=h);a||(a=i);var c=!1,d=null,e=this.db.transaction([this.storeName],this.consts.READ_WRITE);e.oncomplete=function(){(c?a:b)(d)};e.onabort=b;e.onerror=b;var f=e.objectStore(this.storeName).clear();f.onsuccess=function(a){c=!0;d=a.target.result};f.onerror=b;return e},_addIdPropertyIfNeeded:function(a){"undefined"== | ||
typeof a[this.keyPath]&&(a[this.keyPath]=this._insertIdCount++ +Date.now())},getIndexList:function(){return this.store.indexNames},hasIndex:function(a){return this.store.indexNames.contains(a)},normalizeIndexData:function(a){a.keyPath=a.keyPath||a.name;a.unique=!!a.unique;a.multiEntry=!!a.multiEntry},indexComplies:function(a,b){return["keyPath","unique","multiEntry"].every(function(c){if("multiEntry"==c&&void 0===a[c]&&!1===b[c])return!0;if("keyPath"==c&&"[object Array]"==Object.prototype.toString.call(b[c])){var c= | ||
b.keyPath,d=a.keyPath;if("string"==typeof d)return c.toString()==d;if(!("function"==typeof d.contains||"function"==typeof d.indexOf)||d.length!==c.length)return!1;for(var e=0,f=c.length;e<f;e++)if(!(d.contains&&d.contains(c[e])||d.indexOf(-1!==c[e])))return!1;return!0}return b[c]==a[c]})},iterate:function(a,b){var b=n({index:null,order:"ASC",autoContinue:!0,filterDuplicates:!1,keyRange:null,writeAccess:!1,onEnd:null,onError:h,limit:Infinity,offset:0},b||{}),c="desc"==b.order.toLowerCase()?"PREV": | ||
"NEXT";b.filterDuplicates&&(c+="_NO_DUPLICATE");var d=!1,e=this.db.transaction([this.storeName],this.consts[b.writeAccess?"READ_WRITE":"READ_ONLY"]),f=e.objectStore(this.storeName);b.index&&(f=f.index(b.index));var g=0;e.oncomplete=function(){if(d)if(b.onEnd)b.onEnd();else a(null);else b.onError(null)};e.onabort=b.onError;e.onerror=b.onError;c=f.openCursor(b.keyRange,this.consts[c]);c.onerror=b.onError;c.onsuccess=function(c){if(c=c.target.result)if(b.offset)c.advance(b.offset),b.offset=0;else{if(a(c.value, | ||
c,e),g++,b.autoContinue)if(g+b.offset<b.limit)c["continue"]();else d=!0}else d=!0};return e},query:function(a,b){var c=[],b=b||{};b.autoContinue=!0;b.writeAccess=!1;b.onEnd=function(){a(c)};return this.iterate(function(a){c.push(a)},b)},count:function(a,b){var b=n({index:null,keyRange:null},b||{}),c=b.onError||h,d=!1,e=null,f=this.db.transaction([this.storeName],this.consts.READ_ONLY);f.oncomplete=function(){(d?a:c)(e)};f.onabort=c;f.onerror=c;var g=f.objectStore(this.storeName);b.index&&(g=g.index(b.index)); | ||
g=g.count(b.keyRange);g.onsuccess=function(a){d=!0;e=a.target.result};g.onError=c;return f},makeKeyRange:function(a){var b="undefined"!=typeof a.lower,c="undefined"!=typeof a.upper,d="undefined"!=typeof a.only;switch(!0){case d:a=this.keyRange.only(a.only);break;case b&&c:a=this.keyRange.bound(a.lower,a.upper,a.excludeLower,a.excludeUpper);break;case b:a=this.keyRange.lowerBound(a.lower,a.excludeLower);break;case c:a=this.keyRange.upperBound(a.upper,a.excludeUpper);break;default:throw Error('Cannot create KeyRange. Provide one or both of "lower" or "upper" value, or an "only" value.'); | ||
}return a}};var p={},n=function(a,b){var c,d;for(c in b)d=b[c],d!==p[c]&&d!==a[c]&&(a[c]=d);return a};j.version=j.prototype.version;return j},this); | ||
(function(p,h,k){"function"===typeof define?define(h):"undefined"!==typeof module&&module.exports?module.exports=h():k[p]=h()})("IDBStore",function(){function p(a,b){var c,d;for(c in b)d=b[c],d!==u[c]&&d!==a[c]&&(a[c]=d);return a}var h=function(a){throw a;},k=function(){},r={storeName:"Store",storePrefix:"IDBWrapper-",dbVersion:1,keyPath:"id",autoIncrement:!0,onStoreReady:function(){},onError:h,indexes:[],implementationPreference:["indexedDB","webkitIndexedDB","mozIndexedDB","shimIndexedDB"]},q=function(a, | ||
b){"undefined"==typeof b&&"function"==typeof a&&(b=a);"[object Object]"!=Object.prototype.toString.call(a)&&(a={});for(var c in r)this[c]="undefined"!=typeof a[c]?a[c]:r[c];this.dbName=this.storePrefix+this.storeName;this.dbVersion=parseInt(this.dbVersion,10)||1;b&&(this.onStoreReady=b);var d="object"==typeof window?window:self;this.implementation=this.implementationPreference.filter(function(a){return a in d})[0];this.idb=d[this.implementation];this.keyRange=d.IDBKeyRange||d.webkitIDBKeyRange||d.mozIDBKeyRange; | ||
this.consts={READ_ONLY:"readonly",READ_WRITE:"readwrite",VERSION_CHANGE:"versionchange",NEXT:"next",NEXT_NO_DUPLICATE:"nextunique",PREV:"prev",PREV_NO_DUPLICATE:"prevunique"};this.openDB()},t={constructor:q,version:"1.6.2",db:null,dbName:null,dbVersion:null,store:null,storeName:null,storePrefix:null,keyPath:null,autoIncrement:null,indexes:null,implementationPreference:null,implementation:"",onStoreReady:null,onError:null,_insertIdCount:0,openDB:function(){var a=this.idb.open(this.dbName,this.dbVersion), | ||
b=!1;a.onerror=function(a){var b=!1;"error"in a.target?b="VersionError"==a.target.error.name:"errorCode"in a.target&&(b=12==a.target.errorCode);if(b)this.onError(Error("The version number provided is lower than the existing one."));else this.onError(a)}.bind(this);a.onsuccess=function(a){if(!b)if(this.db)this.onStoreReady();else if(this.db=a.target.result,"string"==typeof this.db.version)this.onError(Error("The IndexedDB implementation in this browser is outdated. Please upgrade your browser.")); | ||
else if(this.db.objectStoreNames.contains(this.storeName)){this.store=this.db.transaction([this.storeName],this.consts.READ_ONLY).objectStore(this.storeName);var d=Array.prototype.slice.call(this.getIndexList());this.indexes.forEach(function(a){var c=a.name;if(c)if(this.normalizeIndexData(a),this.hasIndex(c)){var g=this.store.index(c);this.indexComplies(g,a)||(b=!0,this.onError(Error('Cannot modify index "'+c+'" for current version. Please bump version number to '+(this.dbVersion+1)+".")));d.splice(d.indexOf(c), | ||
1)}else b=!0,this.onError(Error('Cannot create new index "'+c+'" for current version. Please bump version number to '+(this.dbVersion+1)+"."));else b=!0,this.onError(Error("Cannot create index: No index name given."))},this);d.length&&(b=!0,this.onError(Error('Cannot delete index(es) "'+d.toString()+'" for current version. Please bump version number to '+(this.dbVersion+1)+".")));b||this.onStoreReady()}else this.onError(Error("Object store couldn't be created."))}.bind(this);a.onupgradeneeded=function(a){this.db= | ||
a.target.result;this.db.objectStoreNames.contains(this.storeName)?this.store=a.target.transaction.objectStore(this.storeName):(a={autoIncrement:this.autoIncrement},null!==this.keyPath&&(a.keyPath=this.keyPath),this.store=this.db.createObjectStore(this.storeName,a));var d=Array.prototype.slice.call(this.getIndexList());this.indexes.forEach(function(a){var c=a.name;c||(b=!0,this.onError(Error("Cannot create index: No index name given.")));this.normalizeIndexData(a);if(this.hasIndex(c)){var g=this.store.index(c); | ||
this.indexComplies(g,a)||(this.store.deleteIndex(c),this.store.createIndex(c,a.keyPath,{unique:a.unique,multiEntry:a.multiEntry}));d.splice(d.indexOf(c),1)}else this.store.createIndex(c,a.keyPath,{unique:a.unique,multiEntry:a.multiEntry})},this);d.length&&d.forEach(function(a){this.store.deleteIndex(a)},this)}.bind(this)},deleteDatabase:function(a,b){if(this.idb.deleteDatabase){this.db.close();var c=this.idb.deleteDatabase(this.dbName);c.onsuccess=a;c.onerror=b}else b(Error("Browser does not support IndexedDB deleteDatabase!"))}, | ||
put:function(a,b,c,d){null!==this.keyPath&&(d=c,c=b,b=a);d||(d=h);c||(c=k);var f=!1,e=null,g=this.db.transaction([this.storeName],this.consts.READ_WRITE);g.oncomplete=function(){(f?c:d)(e)};g.onabort=d;g.onerror=d;null!==this.keyPath?(this._addIdPropertyIfNeeded(b),a=g.objectStore(this.storeName).put(b)):a=g.objectStore(this.storeName).put(b,a);a.onsuccess=function(a){f=!0;e=a.target.result};a.onerror=d;return g},get:function(a,b,c){c||(c=h);b||(b=k);var d=!1,f=null,e=this.db.transaction([this.storeName], | ||
this.consts.READ_ONLY);e.oncomplete=function(){(d?b:c)(f)};e.onabort=c;e.onerror=c;a=e.objectStore(this.storeName).get(a);a.onsuccess=function(a){d=!0;f=a.target.result};a.onerror=c;return e},remove:function(a,b,c){c||(c=h);b||(b=k);var d=!1,f=null,e=this.db.transaction([this.storeName],this.consts.READ_WRITE);e.oncomplete=function(){(d?b:c)(f)};e.onabort=c;e.onerror=c;a=e.objectStore(this.storeName)["delete"](a);a.onsuccess=function(a){d=!0;f=a.target.result};a.onerror=c;return e},batch:function(a, | ||
b,c){c||(c=h);b||(b=k);if("[object Array]"!=Object.prototype.toString.call(a))c(Error("dataArray argument must be of type Array."));else if(0===a.length)return b(!0);var d=a.length,f=!1,e=!1,g=this.db.transaction([this.storeName],this.consts.READ_WRITE);g.oncomplete=function(){(e?b:c)(e)};g.onabort=c;g.onerror=c;var l=function(){d--;0!==d||f||(e=f=!0)};a.forEach(function(a){var b=a.type,d=a.key,e=a.value;a=function(a){g.abort();f||(f=!0,c(a,b,d))};"remove"==b?(e=g.objectStore(this.storeName)["delete"](d), | ||
e.onsuccess=l,e.onerror=a):"put"==b&&(null!==this.keyPath?(this._addIdPropertyIfNeeded(e),e=g.objectStore(this.storeName).put(e)):e=g.objectStore(this.storeName).put(e,d),e.onsuccess=l,e.onerror=a)},this);return g},putBatch:function(a,b,c){a=a.map(function(a){return{type:"put",value:a}});return this.batch(a,b,c)},upsertBatch:function(a,b,c,d){"function"==typeof b&&(d=c=b,b={});d||(d=h);c||(c=k);b||(b={});"[object Array]"!=Object.prototype.toString.call(a)&&d(Error("dataArray argument must be of type Array.")); | ||
var f=b.keyField||this.keyPath,e=a.length,g=!1,l=!1,n=0,m=this.db.transaction([this.storeName],this.consts.READ_WRITE);m.oncomplete=function(){l?c(a):d(!1)};m.onabort=d;m.onerror=d;var v=function(b){a[n++][f]=b.target.result;e--;0!==e||g||(l=g=!0)};a.forEach(function(a){var b=a.key;null!==this.keyPath?(this._addIdPropertyIfNeeded(a),a=m.objectStore(this.storeName).put(a)):a=m.objectStore(this.storeName).put(a,b);a.onsuccess=v;a.onerror=function(a){m.abort();g||(g=!0,d(a))}},this);return m},removeBatch:function(a, | ||
b,c){a=a.map(function(a){return{type:"remove",key:a}});return this.batch(a,b,c)},getBatch:function(a,b,c,d){c||(c=h);b||(b=k);d||(d="sparse");if("[object Array]"!=Object.prototype.toString.call(a))c(Error("keyArray argument must be of type Array."));else if(0===a.length)return b([]);var f=[],e=a.length,g=!1,l=null,n=this.db.transaction([this.storeName],this.consts.READ_ONLY);n.oncomplete=function(){(g?b:c)(l)};n.onabort=c;n.onerror=c;var m=function(a){a.target.result||"dense"==d?f.push(a.target.result): | ||
"sparse"==d&&f.length++;e--;0===e&&(g=!0,l=f)};a.forEach(function(a){a=n.objectStore(this.storeName).get(a);a.onsuccess=m;a.onerror=function(a){l=a;c(a);n.abort()}},this);return n},getAll:function(a,b){b||(b=h);a||(a=k);var c=this.db.transaction([this.storeName],this.consts.READ_ONLY),d=c.objectStore(this.storeName);d.getAll?this._getAllNative(c,d,a,b):this._getAllCursor(c,d,a,b);return c},_getAllNative:function(a,b,c,d){var f=!1,e=null;a.oncomplete=function(){(f?c:d)(e)};a.onabort=d;a.onerror=d; | ||
a=b.getAll();a.onsuccess=function(a){f=!0;e=a.target.result};a.onerror=d},_getAllCursor:function(a,b,c,d){var f=[],e=!1,g=null;a.oncomplete=function(){(e?c:d)(g)};a.onabort=d;a.onerror=d;a=b.openCursor();a.onsuccess=function(a){(a=a.target.result)?(f.push(a.value),a["continue"]()):(e=!0,g=f)};a.onError=d},clear:function(a,b){b||(b=h);a||(a=k);var c=!1,d=null,f=this.db.transaction([this.storeName],this.consts.READ_WRITE);f.oncomplete=function(){(c?a:b)(d)};f.onabort=b;f.onerror=b;var e=f.objectStore(this.storeName).clear(); | ||
e.onsuccess=function(a){c=!0;d=a.target.result};e.onerror=b;return f},_addIdPropertyIfNeeded:function(a){"undefined"==typeof a[this.keyPath]&&(a[this.keyPath]=this._insertIdCount++ +Date.now())},getIndexList:function(){return this.store.indexNames},hasIndex:function(a){return this.store.indexNames.contains(a)},normalizeIndexData:function(a){a.keyPath=a.keyPath||a.name;a.unique=!!a.unique;a.multiEntry=!!a.multiEntry},indexComplies:function(a,b){return["keyPath","unique","multiEntry"].every(function(c){if("multiEntry"== | ||
c&&void 0===a[c]&&!1===b[c])return!0;if("keyPath"==c&&"[object Array]"==Object.prototype.toString.call(b[c])){c=b.keyPath;var d=a.keyPath;if("string"==typeof d)return c.toString()==d;if("function"!=typeof d.contains&&"function"!=typeof d.indexOf||d.length!==c.length)return!1;for(var f=0,e=c.length;f<e;f++)if(!(d.contains&&d.contains(c[f])||d.indexOf(-1!==c[f])))return!1;return!0}return b[c]==a[c]})},iterate:function(a,b){b=p({index:null,order:"ASC",autoContinue:!0,filterDuplicates:!1,keyRange:null, | ||
writeAccess:!1,onEnd:null,onError:h,limit:Infinity,offset:0},b||{});var c="desc"==b.order.toLowerCase()?"PREV":"NEXT";b.filterDuplicates&&(c+="_NO_DUPLICATE");var d=!1,f=this.db.transaction([this.storeName],this.consts[b.writeAccess?"READ_WRITE":"READ_ONLY"]),e=f.objectStore(this.storeName);b.index&&(e=e.index(b.index));var g=0;f.oncomplete=function(){if(d)if(b.onEnd)b.onEnd();else a(null);else b.onError(null)};f.onabort=b.onError;f.onerror=b.onError;c=e.openCursor(b.keyRange,this.consts[c]);c.onerror= | ||
b.onError;c.onsuccess=function(c){if(c=c.target.result)if(b.offset)c.advance(b.offset),b.offset=0;else{if(a(c.value,c,f),g++,b.autoContinue)if(g+b.offset<b.limit)c["continue"]();else d=!0}else d=!0};return f},query:function(a,b){var c=[];b=b||{};b.autoContinue=!0;b.writeAccess=!1;b.onEnd=function(){a(c)};return this.iterate(function(a){c.push(a)},b)},count:function(a,b){b=p({index:null,keyRange:null},b||{});var c=b.onError||h,d=!1,f=null,e=this.db.transaction([this.storeName],this.consts.READ_ONLY); | ||
e.oncomplete=function(){(d?a:c)(f)};e.onabort=c;e.onerror=c;var g=e.objectStore(this.storeName);b.index&&(g=g.index(b.index));g=g.count(b.keyRange);g.onsuccess=function(a){d=!0;f=a.target.result};g.onError=c;return e},makeKeyRange:function(a){var b="undefined"!=typeof a.lower,c="undefined"!=typeof a.upper,d="undefined"!=typeof a.only;switch(!0){case d:a=this.keyRange.only(a.only);break;case b&&c:a=this.keyRange.bound(a.lower,a.upper,a.excludeLower,a.excludeUpper);break;case b:a=this.keyRange.lowerBound(a.lower, | ||
a.excludeLower);break;case c:a=this.keyRange.upperBound(a.upper,a.excludeUpper);break;default:throw Error('Cannot create KeyRange. Provide one or both of "lower" or "upper" value, or an "only" value.');}return a}},u={};q.prototype=t;q.version=t.version;return q},this); |
{ | ||
"name": "idb-wrapper", | ||
"version": "1.6.1", | ||
"version": "1.6.2", | ||
"description": "A cross-browser wrapper for IndexedDB", | ||
@@ -12,3 +12,3 @@ "keywords": [ | ||
"repository": "git://github.com/jensarps/IDBWrapper.git", | ||
"main": "idbstore", | ||
"main": "idbstore.js", | ||
"homepage": "https://github.com/jensarps/IDBWrapper", | ||
@@ -24,4 +24,16 @@ "contributors": [ | ||
"devDependencies": { | ||
"mocha": "~2.3.3", | ||
"chai": "~3.3.0" | ||
"chai": "^3.5", | ||
"grunt": "^0.4.5", | ||
"grunt-closurecompiler": "^0.9.9", | ||
"grunt-contrib-copy": "^0.8.2", | ||
"grunt-contrib-jshint": "^1.0.0", | ||
"grunt-jsdoc": "^1.0.0", | ||
"grunt-karma": "^0.12.1", | ||
"jsdoc-oblivion": "0.0.4", | ||
"karma": "^0.13.15", | ||
"karma-chai": "^0.1.0", | ||
"karma-chrome-launcher": "^0.2.1", | ||
"karma-firefox-launcher": "^0.1.7", | ||
"karma-mocha": "^0.2.1", | ||
"mocha": "^2.3.3" | ||
}, | ||
@@ -28,0 +40,0 @@ "licenses": [ |
@@ -7,3 +7,4 @@ [![NPM version](https://badge.fury.io/js/idb-wrapper.svg)](http://badge.fury.io/js/idb-wrapper) [![Dependency Status](https://gemnasium.com/jensarps/IDBWrapper.png)](https://gemnasium.com/jensarps/IDBWrapper) | ||
##Browser Support | ||
Browser Support | ||
--- | ||
@@ -41,6 +42,9 @@ IDBWrapper works on all browsers supporting the IndexedDB API, which are: | ||
* Safari has buggy support, which can be fixed by using the above mentioned shim | ||
* Details on how to change the implementation being used can be found in the [wiki](https://github.com/jensarps/IDBWrapper/wiki/Usage#defining-implementation-preference-aka-make-idbwrapper-use-the-shim) | ||
#Using IDBWrapper | ||
Using IDBWrapper | ||
=== | ||
##Tutorials | ||
Tutorials | ||
--- | ||
@@ -55,28 +59,31 @@ There are two tutorials to get you up and running: | ||
##Examples | ||
Examples | ||
--- | ||
There are some examples to run right in your browser over here: http://jensarps.github.com/IDBWrapper/example/ | ||
There are some examples to run right in your browser over here: http://jensarps.github.io/IDBWrapper/example/ | ||
The source for these examples are in the `example` folder of this repository. | ||
##Wiki | ||
Wiki | ||
--- | ||
For usage instructions, details about mothods for reading and writing | ||
data, setting up indexes and runnoing queries, please refer to the | ||
data, setting up indexes and running queries, please refer to the | ||
[Wiki](https://github.com/jensarps/IDBWrapper/wiki). | ||
##API Reference | ||
API Reference | ||
--- | ||
There's an API reference over here: http://jensarps.github.com/IDBWrapper/jsdoc/IDBStore.html | ||
There's an API reference over here: http://jensarps.github.io/IDBWrapper/doc/latest/IDBStore.html | ||
#Obtaining IDBWrapper | ||
For references of older versions, please refer to this index: http://jensarps.github.io/IDBWrapper/doc/ | ||
##git | ||
Obtaining IDBWrapper | ||
=== | ||
You can git clone the repository, or download a zip file here: https://github.com/jensarps/IDBWrapper/tags | ||
cdnjs | ||
--- | ||
##cdnjs | ||
IDBWrapper is also available on [cdnjs](http://cdnjs.com/). You can directly | ||
point a script tag there, or require() it from there. cdnjs supports http, | ||
point a script tag there, or `require()` it from there. cdnjs supports http, | ||
https and spdy, so you can just leave the protocol off. The URLs for the | ||
@@ -86,3 +93,4 @@ different versions of IDBWrapper can be found here: | ||
##Package Managers | ||
Package Managers | ||
--- | ||
@@ -108,4 +116,10 @@ If you use NPM as your package manager, you can get it from there, too, by | ||
#License | ||
git | ||
--- | ||
You can git clone the repository, or download a zip file here: https://github.com/jensarps/IDBWrapper/releases | ||
License | ||
=== | ||
[MIT style (X11)](https://github.com/jensarps/IDBWrapper/blob/master/LICENSE) |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
Filesystem access
Supply chain riskAccesses the file system, and could potentially read sensitive data.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Native code
Supply chain riskContains native code (e.g., compiled binaries or shared libraries). Including native code can obscure malicious behavior.
Found 12 instances in 1 package
Uses eval
Supply chain riskPackage uses dynamic code execution (e.g., eval()), which is a dangerous practice. This can prevent the code from running in certain environments and increases the risk that the code may contain exploits or malicious behavior.
Found 1 instance in 1 package
Dynamic require
Supply chain riskDynamic require can indicate the package is performing dangerous or unsafe dynamic code execution.
Found 1 instance in 1 package
Mixed license
License(Experimental) Package contains multiple licenses.
Found 1 instance in 1 package
0
121
2
1
70924
14
12
1421