idb-wrapper
Advanced tools
Comparing version 0.1.4 to 0.2.1
@@ -30,2 +30,5 @@ /* | ||
}, | ||
onError: function(error){ | ||
throw error; | ||
}, | ||
indexes: [] | ||
@@ -36,9 +39,2 @@ }; | ||
function fixupConstants (object, constants) { | ||
for (var prop in constants) { | ||
if (!(prop in object)) | ||
object[prop] = constants[prop]; | ||
} | ||
} | ||
for(var key in defaults){ | ||
@@ -57,14 +53,10 @@ this[key] = typeof kwArgs[key] != 'undefined' ? kwArgs[key] : defaults[key]; | ||
this.consts = { | ||
'READ_ONLY': 'readonly', | ||
'READ_WRITE': 'readwrite', | ||
'VERSION_CHANGE': 'versionchange' | ||
} | ||
this.cursor = window.IDBCursor || window.webkitIDBCursor; | ||
fixupConstants(this.cursor, { | ||
'NEXT': 'next', | ||
'READ_ONLY': 'readonly', | ||
'READ_WRITE': 'readwrite', | ||
'VERSION_CHANGE': 'versionchange', | ||
'NEXT': 'next', | ||
'NEXT_NO_DUPLICATE': 'nextunique', | ||
'PREV': 'prev', | ||
'PREV': 'prev', | ||
'PREV_NO_DUPLICATE': 'prevunique' | ||
}); | ||
}; | ||
@@ -96,2 +88,4 @@ this.openDB(); | ||
onError: null, | ||
openDB: function () { | ||
@@ -102,3 +96,3 @@ | ||
if(!this.newVersionAPI){ | ||
throw new Error('The IndexedDB implementation in this browser is outdated. Please upgrade your browser.'); | ||
this.onError(new Error('The IndexedDB implementation in this browser is outdated. Please upgrade your browser.')); | ||
} | ||
@@ -121,5 +115,5 @@ | ||
if (gotVersionErr) { | ||
console.error('Could not open database, version error:', error); | ||
this.onError(new Error('The version number provided is lower than the existing one.')); | ||
} else { | ||
console.error('Could not open database, error:', error); | ||
this.onError(error); | ||
} | ||
@@ -168,6 +162,6 @@ }.bind(this); | ||
if(!complies){ | ||
throw new Error('Cannot modify index "' + indexName + '" for current version. Please bump version number to ' + ( this.dbVersion + 1 ) + '.'); | ||
this.onError(new Error('Cannot modify index "' + indexName + '" for current version. Please bump version number to ' + ( this.dbVersion + 1 ) + '.')); | ||
} | ||
} else { | ||
throw new Error('Cannot create new index "' + indexName + '" for current version. Please bump version number to ' + ( this.dbVersion + 1 ) + '.'); | ||
this.onError(new Error('Cannot create new index "' + indexName + '" for current version. Please bump version number to ' + ( this.dbVersion + 1 ) + '.')); | ||
} | ||
@@ -180,3 +174,3 @@ | ||
// We should never get here. | ||
throw new Error('Cannot create a new store for current version. Please bump version number to ' + ( this.dbVersion + 1 ) + '.'); | ||
this.onError(new Error('Cannot create a new store for current version. Please bump version number to ' + ( this.dbVersion + 1 ) + '.')); | ||
} | ||
@@ -204,3 +198,3 @@ }.bind(this); | ||
if(!indexName){ | ||
throw new Error('Cannot create index: No index name given.'); | ||
this.onError(new Error('Cannot create index: No index name given.')); | ||
} | ||
@@ -251,3 +245,2 @@ | ||
} | ||
var putTransaction = this.db.transaction([this.storeName], this.consts.READ_WRITE); | ||
@@ -372,5 +365,5 @@ var putRequest = putTransaction.objectStore(this.storeName).put(dataObj); | ||
var directionType = options.order.toLowerCase() == 'desc' ? 'prev' : 'next'; | ||
var directionType = options.order.toLowerCase() == 'desc' ? 'PREV' : 'NEXT'; | ||
if (options.filterDuplicates) { | ||
directionType += 'unique'; | ||
directionType += '_NO_DUPLICATE'; | ||
} | ||
@@ -384,3 +377,3 @@ | ||
var cursorRequest = cursorTarget.openCursor(options.keyRange, directionType); | ||
var cursorRequest = cursorTarget.openCursor(options.keyRange, this.consts[directionType]); | ||
cursorRequest.onerror = options.onError; | ||
@@ -387,0 +380,0 @@ cursorRequest.onsuccess = function (event) { |
{ | ||
"name": "idb-wrapper", | ||
"version": "0.1.4", | ||
"description": "This is a wrapper for indexedDB.", | ||
"version": "0.2.1", | ||
"description": "A cross-browser wrapper for IndexedDB", | ||
"keywords": [], | ||
"author": "jensarps <mail@jensarps.de>", | ||
"author": "jensarps <mail@jensarps.de> (http://jensarps.de/)", | ||
"repository": "git://github.com/jensarps/IDBWrapper.git", | ||
"main": "IDBStore", | ||
"homepage": "https://github.com/jensarps/IDBWrapper", | ||
"contributors": [], | ||
"contributors": [ | ||
"Josh Matthews <josh@joshmatthews.net> (http://www.joshmatthews.net/blog/)", | ||
"Raynos <raynos2@gmail.com> (http://raynos.org)" | ||
], | ||
"bugs": { | ||
@@ -15,4 +18,6 @@ "url": "https://github.com/jensarps/IDBWrapper/issues", | ||
}, | ||
"dependencies": {}, | ||
"devDependencies": {}, | ||
"dependencies": { | ||
}, | ||
"devDependencies": { | ||
}, | ||
"licenses": [ | ||
@@ -24,3 +29,4 @@ { | ||
], | ||
"scripts": {} | ||
"scripts": { | ||
} | ||
} |
@@ -60,5 +60,5 @@ About | ||
Alternatively, you can use an AMD loader such as RequireJS to load the file, | ||
and you will receive the constructor in your load callback (the constructor | ||
will then, of course, have whatever name you call it). | ||
Alternatively, you can use an AMD loader such as RequireJS, or a CommonJS loader | ||
to load the module, and you will receive the constructor in your load callback | ||
(the constructor will then, of course, have whatever name you call it). | ||
@@ -83,3 +83,4 @@ You can then create an IDB store: | ||
indexes: [], | ||
onStoreReady: function(){} | ||
onStoreReady: function(){}, | ||
onError: function(error){ throw error; } | ||
} | ||
@@ -92,5 +93,10 @@ ``` | ||
You can also pass a callback function to the options object. If a callback is provided both as second | ||
parameter and inside of the options object, the function passed as second parameter will be used. | ||
'onError' gets called if an error occurred while trying to open the store. It | ||
receives the error instance as only argument. | ||
As an alternative to passing a ready handler as second argument, you can also | ||
pass it in the 'onStoreReady' property. If a callback is provided both as second | ||
parameter and inside of the options object, the function passed as second | ||
parameter will be used. | ||
Methods | ||
@@ -97,0 +103,0 @@ ======= |
New author
Supply chain riskA new npm collaborator published a version of the package for the first time. New collaborators are usually benign additions to a project, but do indicate a change to the security surface area of a package.
Found 1 instance in 1 package
160400
27
320
2871
3