Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

idb-wrapper

Package Overview
Dependencies
Maintainers
2
Versions
21
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

idb-wrapper - npm Package Compare versions

Comparing version 1.6.0 to 1.6.1

index.html

2

bower.json

@@ -5,4 +5,4 @@ {

"main": "idbstore.js",
"version": "1.6.0",
"version": "1.6.1",
"dependencies": {}
}

@@ -5,3 +5,3 @@ /*global window:false, self:false, define:false, module:false */

* @license IDBWrapper - A cross-browser wrapper for IndexedDB
* Version 1.6.0
* Version 1.6.1
* Copyright (c) 2011 - 2015 Jens Arps

@@ -39,3 +39,9 @@ * http://jensarps.de/

onError: defaultErrorHandler,
indexes: []
indexes: [],
implementationPreference: [
'indexedDB',
'webkitIndexedDB',
'mozIndexedDB',
'shimIndexedDB'
]
};

@@ -49,3 +55,3 @@

* @name IDBStore
* @version 1.6.0
* @version 1.6.1
*

@@ -79,2 +85,3 @@ * @param {Object} [kwArgs] An options object used to configure the store and

* @param {Boolean} [kwArgs.indexes.indexData.multiEntry] Whether the index is multi entry
* @param {Array} [kwArgs.implementationPreference=['indexedDB','webkitIndexedDB','mozIndexedDB','shimIndexedDB']] An array of strings naming implementations to be used, in order or preference
* @param {Function} [onStoreReady] A callback to be called when the store

@@ -123,3 +130,7 @@ * is ready to be used.

var env = typeof window == 'object' ? window : self;
this.idb = env.shimIndexedDB || env.indexedDB || env.webkitIndexedDB || env.mozIndexedDB;
var availableImplementations = this.implementationPreference.filter(function (implName) {
return implName in env;
});
this.implementation = availableImplementations[0];
this.idb = env[this.implementation];
this.keyRange = env.IDBKeyRange || env.webkitIDBKeyRange || env.mozIDBKeyRange;

@@ -145,3 +156,4 @@

*
* @type IDBStore
* @private
* @type {Function}
*/

@@ -153,5 +165,5 @@ constructor: IDBStore,

*
* @type String
* @type {String}
*/
version: '1.6.0',
version: '1.6.1',

@@ -161,3 +173,3 @@ /**

*
* @type Object
* @type {Object}
*/

@@ -170,3 +182,3 @@ db: null,

*
* @type String
* @type {String}
*/

@@ -178,3 +190,3 @@ dbName: null,

*
* @type Number
* @type {Number}
*/

@@ -186,3 +198,3 @@ dbVersion: null,

*
* @type Object
* @type {Object}
*/

@@ -194,3 +206,3 @@ store: null,

*
* @type String
* @type {String}
*/

@@ -202,3 +214,3 @@ storeName: null,

*
* @type String
* @type {String}
*/

@@ -210,3 +222,3 @@ storePrefix: null,

*
* @type String
* @type {String}
*/

@@ -218,3 +230,3 @@ keyPath: null,

*
* @type Boolean
* @type {Boolean}
*/

@@ -226,3 +238,3 @@ autoIncrement: null,

*
* @type Array
* @type {Array}
*/

@@ -232,5 +244,19 @@ indexes: null,

/**
* The implemantations to try to use, in order of preference
*
* @type {Array}
*/
implementationPreference: null,
/**
* The actual implementation being used
*
* @type {String}
*/
implementation: '',
/**
* The callback to be called when the store is ready to be used
*
* @type Function
* @type {Function}
*/

@@ -243,3 +269,3 @@ onStoreReady: null,

*
* @type Function
* @type {Function}
*/

@@ -251,3 +277,3 @@ onError: null,

*
* @type Number
* @type {Number}
* @private

@@ -311,3 +337,3 @@ */

// Lets notify the user anyway.
this.onError(new Error('Something is wrong with the IndexedDB implementation in this browser. Please upgrade your browser.'));
this.onError(new Error('Object store couldn\'t be created.'));
return;

@@ -314,0 +340,0 @@ }

/*
IDBWrapper - A cross-browser wrapper for IndexedDB
Version 1.6.0
Version 1.6.1
Copyright (c) 2011 - 2015 Jens Arps

@@ -9,23 +9,23 @@ http://jensarps.de/

*/
(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:[]},j=function(a,c){"undefined"==typeof c&&"function"==typeof a&&(c=a);"[object Object]"!=Object.prototype.toString.call(a)&&(a={});for(var b in l)this[b]="undefined"!=typeof a[b]?
a[b]:l[b];this.dbName=this.storePrefix+this.storeName;this.dbVersion=parseInt(this.dbVersion,10)||1;c&&(this.onStoreReady=c);b="object"==typeof window?window:self;this.idb=b.shimIndexedDB||b.indexedDB||b.webkitIndexedDB||b.mozIndexedDB;this.keyRange=b.IDBKeyRange||b.webkitIDBKeyRange||b.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.0",db:null,dbName:null,dbVersion:null,store:null,storeName:null,storePrefix:null,keyPath:null,autoIncrement:null,indexes:null,onStoreReady:null,onError:null,_insertIdCount:0,openDB:function(){var a=this.idb.open(this.dbName,this.dbVersion),c=!1;a.onerror=function(b){var a=!1;"error"in b.target?a="VersionError"==b.target.error.name:"errorCode"in b.target&&(a=12==b.target.errorCode);if(a)this.onError(Error("The version number provided is lower than the existing one."));else this.onError(b)}.bind(this);
a.onsuccess=function(a){if(!c)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 b=a.name;b?(this.normalizeIndexData(a),
this.hasIndex(b)?(this.indexComplies(this.store.index(b),a)||(c=!0,this.onError(Error('Cannot modify index "'+b+'" for current version. Please bump version number to '+(this.dbVersion+1)+"."))),d.splice(d.indexOf(b),1)):(c=!0,this.onError(Error('Cannot create new index "'+b+'" for current version. Please bump version number to '+(this.dbVersion+1)+".")))):(c=!0,this.onError(Error("Cannot create index: No index name given.")))},this);d.length&&(c=!0,this.onError(Error('Cannot delete index(es) "'+d.toString()+
'" for current version. Please bump version number to '+(this.dbVersion+1)+".")));c||this.onStoreReady()}else this.onError(Error("Something is wrong with the IndexedDB implementation in this browser. Please upgrade your browser."))}.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 b=a.name;b||(c=!0,this.onError(Error("Cannot create index: No index name given.")));this.normalizeIndexData(a);this.hasIndex(b)?(this.indexComplies(this.store.index(b),a)||(this.store.deleteIndex(b),this.store.createIndex(b,a.keyPath,{unique:a.unique,multiEntry:a.multiEntry})),d.splice(d.indexOf(b),1)):this.store.createIndex(b,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,c){if(this.idb.deleteDatabase){this.db.close();var b=this.idb.deleteDatabase(this.dbName);b.onsuccess=a;b.onerror=c}else c(Error("Browser does not support IndexedDB deleteDatabase!"))},put:function(a,c,b,d){null!==this.keyPath&&(d=b,b=c,c=a);d||(d=h);b||(b=i);var e=!1,f=null,g=this.db.transaction([this.storeName],this.consts.READ_WRITE);g.oncomplete=function(){(e?b:d)(f)};g.onabort=d;g.onerror=
d;null!==this.keyPath?(this._addIdPropertyIfNeeded(c),a=g.objectStore(this.storeName).put(c)):a=g.objectStore(this.storeName).put(c,a);a.onsuccess=function(a){e=!0;f=a.target.result};a.onerror=d;return g},get:function(a,c,b){b||(b=h);c||(c=i);var d=!1,e=null,f=this.db.transaction([this.storeName],this.consts.READ_ONLY);f.oncomplete=function(){(d?c:b)(e)};f.onabort=b;f.onerror=b;a=f.objectStore(this.storeName).get(a);a.onsuccess=function(a){d=!0;e=a.target.result};a.onerror=b;return f},remove:function(a,
c,b){b||(b=h);c||(c=i);var d=!1,e=null,f=this.db.transaction([this.storeName],this.consts.READ_WRITE);f.oncomplete=function(){(d?c:b)(e)};f.onabort=b;f.onerror=b;a=f.objectStore(this.storeName)["delete"](a);a.onsuccess=function(a){d=!0;e=a.target.result};a.onerror=b;return f},batch:function(a,c,b){b||(b=h);c||(c=i);if("[object Array]"!=Object.prototype.toString.call(a))b(Error("dataArray argument must be of type Array."));else if(0===a.length)return c(!0);var d=this.db.transaction([this.storeName],
this.consts.READ_WRITE);d.oncomplete=function(){(g?c:b)(g)};d.onabort=b;d.onerror=b;var e=a.length,f=!1,g=!1,k=function(){e--;0===e&&!f&&(g=f=!0)};a.forEach(function(a){var c=a.type,e=a.key,g=a.value,a=function(a){d.abort();f||(f=!0,b(a,c,e))};if("remove"==c)g=d.objectStore(this.storeName)["delete"](e),g.onsuccess=k,g.onerror=a;else if("put"==c)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,c,b){return this.batch(a.map(function(a){return{type:"put",value:a}}),c,b)},upsertBatch:function(a,c,b,d){"function"==typeof c&&(d=b=c,c={});d||(d=h);b||(b=i);c||(c={});"[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?b(a):d(!1)};e.onabort=d;e.onerror=d;var f=c.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,c,b){return this.batch(a.map(function(a){return{type:"remove",key:a}}),c,b)},getBatch:function(a,c,b,d){b||(b=h);c||(c=i);d||(d="sparse");if("[object Array]"!=Object.prototype.toString.call(a))b(Error("keyArray argument must be of type Array."));
else if(0===a.length)return c([]);var e=this.db.transaction([this.storeName],this.consts.READ_ONLY);e.oncomplete=function(){(k?c:b)(j)};e.onabort=b;e.onerror=b;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;b(a);e.abort()}},this);return e},getAll:function(a,c){c||(c=h);a||(a=i);var b=this.db.transaction([this.storeName],
this.consts.READ_ONLY),d=b.objectStore(this.storeName);d.getAll?this._getAllNative(b,d,a,c):this._getAllCursor(b,d,a,c);return b},_getAllNative:function(a,c,b,d){var e=!1,f=null;a.oncomplete=function(){(e?b:d)(f)};a.onabort=d;a.onerror=d;a=c.getAll();a.onsuccess=function(a){e=!0;f=a.target.result};a.onerror=d},_getAllCursor:function(a,c,b,d){var e=[],f=!1,g=null;a.oncomplete=function(){(f?b:d)(g)};a.onabort=d;a.onerror=d;a=c.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,c){c||(c=h);a||(a=i);var b=!1,d=null,e=this.db.transaction([this.storeName],this.consts.READ_WRITE);e.oncomplete=function(){(b?a:c)(d)};e.onabort=c;e.onerror=c;var f=e.objectStore(this.storeName).clear();f.onsuccess=function(a){b=!0;d=a.target.result};f.onerror=c;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,c){return["keyPath","unique","multiEntry"].every(function(b){if("multiEntry"==b&&void 0===a[b]&&!1===c[b])return!0;if("keyPath"==b&&"[object Array]"==Object.prototype.toString.call(c[b])){var b=c.keyPath,d=a.keyPath;if("string"==typeof d)return b.toString()==d;if(!("function"==typeof d.contains||"function"==
typeof d.indexOf)||d.length!==b.length)return!1;for(var e=0,f=b.length;e<f;e++)if(!(d.contains&&d.contains(b[e])||d.indexOf(-1!==b[e])))return!1;return!0}return c[b]==a[b]})},iterate:function(a,c){var c=n({index:null,order:"ASC",autoContinue:!0,filterDuplicates:!1,keyRange:null,writeAccess:!1,onEnd:null,onError:h,limit:Infinity,offset:0},c||{}),b="desc"==c.order.toLowerCase()?"PREV":"NEXT";c.filterDuplicates&&(b+="_NO_DUPLICATE");var d=!1,e=this.db.transaction([this.storeName],this.consts[c.writeAccess?
"READ_WRITE":"READ_ONLY"]),f=e.objectStore(this.storeName);c.index&&(f=f.index(c.index));var g=0;e.oncomplete=function(){if(d)if(c.onEnd)c.onEnd();else a(null);else c.onError(null)};e.onabort=c.onError;e.onerror=c.onError;b=f.openCursor(c.keyRange,this.consts[b]);b.onerror=c.onError;b.onsuccess=function(b){if(b=b.target.result)if(c.offset)b.advance(c.offset),c.offset=0;else{if(a(b.value,b,e),g++,c.autoContinue)if(g+c.offset<c.limit)b["continue"]();else d=!0}else d=!0};return e},query:function(a,c){var b=
[],c=c||{};c.autoContinue=!0;c.writeAccess=!1;c.onEnd=function(){a(b)};return this.iterate(function(a){b.push(a)},c)},count:function(a,c){var c=n({index:null,keyRange:null},c||{}),b=c.onError||h,d=!1,e=null,f=this.db.transaction([this.storeName],this.consts.READ_ONLY);f.oncomplete=function(){(d?a:b)(e)};f.onabort=b;f.onerror=b;var g=f.objectStore(this.storeName);c.index&&(g=g.index(c.index));g=g.count(c.keyRange);g.onsuccess=function(a){d=!0;e=a.target.result};g.onError=b;return f},makeKeyRange:function(a){var c=
"undefined"!=typeof a.lower,b="undefined"!=typeof a.upper,d="undefined"!=typeof a.only;switch(!0){case d:a=this.keyRange.only(a.only);break;case c&&b:a=this.keyRange.bound(a.lower,a.upper,a.excludeLower,a.excludeUpper);break;case c:a=this.keyRange.lowerBound(a.lower,a.excludeLower);break;case b: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,
c){var b,d;for(b in c)d=c[b],d!==p[b]&&d!==a[b]&&(a[b]=d);return a};j.version=j.prototype.version;return j},this);
(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);
{
"name": "idb-wrapper",
"version": "1.6.0",
"version": "1.6.1",
"description": "A cross-browser wrapper for IndexedDB",

@@ -5,0 +5,0 @@ "keywords": [

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

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc