Comparing version 1.0.0 to 1.0.1
97
index.js
module.exports = Level | ||
var IDB = require('idb-wrapper') | ||
var AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN | ||
var util = require('util') | ||
var Iterator = require('./iterator') | ||
@@ -8,3 +10,3 @@ | ||
if (!(this instanceof Level)) return new Level(location) | ||
if (!location) throw new Error("leveldown() requires at least a location argument") | ||
if (!location) throw new Error("constructor requires at least a location argument") | ||
@@ -14,6 +16,6 @@ this.location = location | ||
Level.prototype.open = function(callback) { | ||
util.inherits(Level, AbstractLevelDOWN) | ||
Level.prototype._open = function(options, callback) { | ||
var self = this | ||
if (!callback || typeof callback !== 'function') throw new Error("open() requires a callback argument") | ||
this.idb = new IDB({ | ||
@@ -32,13 +34,2 @@ storeName: this.location, | ||
Level.prototype.get = function (key, options, callback) { | ||
if (typeof options == 'function') callback = options | ||
if (typeof callback != 'function') throw new Error('get() requires a callback argument') | ||
var err = checkKeyValue(key, 'key') | ||
if (err) return callback(err) | ||
if (!isBuffer(key)) key = String(key) | ||
if (typeof options != 'object') options = {} | ||
return this._get(key, options, callback) | ||
} | ||
Level.prototype._get = function (key, options, callback) { | ||
@@ -56,12 +47,2 @@ this.idb.get(key, function (value) { | ||
Level.prototype.del = function (key, options, callback) { | ||
if (typeof options == 'function') callback = options | ||
if (typeof callback != 'function') throw new Error('del() requires a callback argument') | ||
var err = checkKeyValue(key, 'key') | ||
if (err) return callback(err) | ||
if (!isBuffer(key)) key = String(key) | ||
if (typeof options != 'object') options = {} | ||
return this._del(key, options, callback) | ||
} | ||
Level.prototype._del = function(id, options, callback) { | ||
@@ -71,18 +52,2 @@ this.idb.remove(id, callback, callback) | ||
Level.prototype.put = function (key, value, options, callback) { | ||
if (typeof options == 'function') | ||
callback = options | ||
if (typeof callback != 'function') | ||
throw new Error('put() requires a callback argument') | ||
var err = checkKeyValue(value, 'value') | ||
if (err) return callback(err) | ||
err = checkKeyValue(key, 'key') | ||
if (err) return callback(err) | ||
if (!isBuffer(key)) key = String(key) | ||
if (!isBuffer(value)) value = String(value) | ||
if (typeof options != 'object') options = {} | ||
return this._put(key, value, options, callback) | ||
} | ||
Level.prototype._put = function (key, value, options, callback) { | ||
@@ -97,15 +62,2 @@ this.idb.put(key, value, function() { callback() }, callback) | ||
Level.prototype.batch = function (array, options, callback) { | ||
if (typeof options === 'function') callback = options | ||
if (!Array.isArray(array) && typeof array === 'object') { | ||
options = array | ||
array = undefined | ||
} | ||
if (typeof options != 'object') options = {} | ||
// TODO: if array == undefined && callback == function, derp | ||
return this._batch(array, options, callback) | ||
} | ||
Level.prototype._batch = function (array, options, callback) { | ||
@@ -115,7 +67,2 @@ return this.idb.batch(array, function(){ callback() }, callback) | ||
Level.prototype.close = function (callback) { | ||
if (typeof callback != 'function') throw new Error('close() requires a callback argument') | ||
return this._close(callback) | ||
} | ||
Level.prototype._close = function (callback) { | ||
@@ -126,6 +73,23 @@ this.idb.db.close() | ||
function isBuffer(buf) { | ||
Level.prototype._approximateSize = function() { | ||
throw new Error('Not implemented') | ||
} | ||
var isBuffer = Level.prototype._isBuffer = function (buf) { | ||
return buf instanceof ArrayBuffer | ||
} | ||
var checkKeyValue = Level.prototype._checkKeyValue = function (obj, type) { | ||
if (obj === null || obj === undefined) | ||
return new Error(type + ' cannot be `null` or `undefined`') | ||
if (obj === null || obj === undefined) | ||
return new Error(type + ' cannot be `null` or `undefined`') | ||
if (isBuffer(obj) && obj.byteLength === 0) | ||
return new Error(type + ' cannot be an empty ArrayBuffer') | ||
if (String(obj) === '') | ||
return new Error(type + ' cannot be an empty String') | ||
if (obj.length === 0) | ||
return new Error(type + ' cannot be an empty Array') | ||
} | ||
function ArrayBufferToString(buf) { | ||
@@ -142,15 +106,2 @@ return String.fromCharCode.apply(null, new Uint16Array(buf)) | ||
return buf | ||
} | ||
function checkKeyValue (obj, type) { | ||
if (obj === null || obj === undefined) | ||
return new Error(type + ' cannot be `null` or `undefined`') | ||
if (obj === null || obj === undefined) | ||
return new Error(type + ' cannot be `null` or `undefined`') | ||
if (isBuffer(obj) && obj.byteLength === 0) | ||
return new Error(type + ' cannot be an empty ArrayBuffer') | ||
if (String(obj) === '') | ||
return new Error(type + ' cannot be an empty String') | ||
if (obj.length === 0) | ||
return new Error(type + ' cannot be an empty Array') | ||
} |
@@ -69,3 +69,3 @@ var util = require('util') | ||
} | ||
if (this._limit) { | ||
if (this._limit && this._limit > 0) { | ||
if (this._limit > this._count) this.callback(false, cursor.key, cursor.value) | ||
@@ -72,0 +72,0 @@ } else { |
{ | ||
"name": "level-js", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "leveldown/leveldb library for browsers using IndexedDB", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "beefy test.js" | ||
"test": "beefy test.js test-levelup.js" | ||
}, | ||
@@ -20,10 +20,11 @@ "repository": { | ||
"devDependencies": { | ||
"abstract-leveldown": "~0.2.0", | ||
"tape": "~0.3.3", | ||
"beefy": "0.1.1", | ||
"browserify": "~2.13.2" | ||
"browserify": "~2.13.2", | ||
"beefy": "~0.3.0" | ||
}, | ||
"dependencies": { | ||
"idb-wrapper": "git://github.com/maxogden/IDBWrapper.git#autoContinueOption" | ||
"idb-wrapper": "git://github.com/maxogden/IDBWrapper.git#autoContinueOption", | ||
"abstract-leveldown": "~0.3.0", | ||
"levelup": "git://github.com/rvagg/node-levelup.git#0.9-wip" | ||
} | ||
} |
@@ -15,2 +15,4 @@ ![logo](logo.png) | ||
For example, there is experimental support in using the popular [levelup](http://github.com/rvagg/node-levelup) library on top of level.js. See `test-levelup.js` for details | ||
## install | ||
@@ -40,3 +42,3 @@ | ||
npm install | ||
npm start | ||
npm test | ||
open localhost:9966 | ||
@@ -43,0 +45,0 @@ ``` |
@@ -15,2 +15,3 @@ var tape = require('tape') | ||
require('abstract-leveldown/abstract/open-test').args(factory, tape, testCommon) | ||
require('abstract-leveldown/abstract/open-test').open(factory, tape, testCommon) | ||
require('abstract-leveldown/abstract/put-test').all(factory, tape, testCommon) | ||
@@ -22,1 +23,2 @@ require('abstract-leveldown/abstract/del-test').all(factory, tape, testCommon) | ||
require('abstract-leveldown/abstract/iterator-test').all(factory, tape, testCommon) | ||
@@ -12,7 +12,8 @@ var dbidx = 0 | ||
, cleanup = function (callback) { | ||
indexedDB.webkitGetDatabaseNames().onsuccess = function(e, list){ | ||
indexedDB.webkitGetDatabaseNames().onsuccess = function(e){ | ||
var list = e.target.result | ||
if (!list) return callback() | ||
list = list.filter(function (f) { | ||
return (/^_leveldown_test_db_/).test(f) | ||
list = Object.keys(list).map(function(k) { return list[k] }) | ||
list = list.filter(function(item) { | ||
if (item.toString().indexOf('_leveldown_test_db_') > -1) return true | ||
}) | ||
@@ -24,5 +25,4 @@ | ||
function done () { | ||
if (++ret == list.length) | ||
callback() | ||
function done (e) { | ||
if (++ret == list.length) callback() | ||
} | ||
@@ -29,0 +29,0 @@ |
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
Git dependency
Supply chain riskContains a dependency which resolves to a remote git URL. Dependencies fetched from git URLs are not immutable can be used to inject untrusted code or reduce the likelihood of a reproducible install.
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
15881
3
10
314
50
3
2
+ Addedabstract-leveldown@~0.3.0
+ Addedlevelup@git://github.com/rvagg/node-levelup.git#0.9-wip
+ Addedabstract-leveldown@0.3.0(transitive)