Socket
Socket
Sign inDemoInstall

abstract-leveldown

Package Overview
Dependencies
Maintainers
4
Versions
79
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

abstract-leveldown - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

abstract/iterator-range-test.js

44

abstract-chained-batch.js
/* Copyright (c) 2017 Rod Vagg, MIT License */
function AbstractChainedBatch (db) {
this._db = db
this._db = db
this._operations = []
this._written = false
this._written = false
}

@@ -18,4 +18,5 @@

AbstractChainedBatch.prototype._checkWritten = function () {
if (this._written)
if (this._written) {
throw new Error('write() already called on this batch')
}
}

@@ -26,5 +27,4 @@

var err = this._db._checkKey(key, 'key', this._db._isBuffer)
if (err)
throw err
var err = this._db._checkKey(key, 'key')
if (err) { throw err }

@@ -34,6 +34,7 @@ key = this._serializeKey(key)

if (typeof this._put == 'function' )
if (typeof this._put === 'function') {
this._put(key, value)
else
} else {
this._operations.push({ type: 'put', key: key, value: value })
}

@@ -46,11 +47,12 @@ return this

var err = this._db._checkKey(key, 'key', this._db._isBuffer)
if (err) throw err
var err = this._db._checkKey(key, 'key')
if (err) { throw err }
key = this._serializeKey(key)
if (typeof this._del == 'function' )
if (typeof this._del === 'function') {
this._del(key)
else
} else {
this._operations.push({ type: 'del', key: key })
}

@@ -65,4 +67,3 @@ return this

if (typeof this._clear == 'function' )
this._clear()
if (typeof this._clear === 'function') { this._clear() }

@@ -75,16 +76,15 @@ return this

if (typeof options == 'function')
callback = options
if (typeof callback != 'function')
if (typeof options === 'function') { callback = options }
if (typeof callback !== 'function') {
throw new Error('write() requires a callback argument')
if (typeof options != 'object')
options = {}
}
if (typeof options !== 'object') { options = {} }
this._written = true
if (typeof this._write == 'function' )
return this._write(callback)
if (typeof this._write === 'function') { return this._write(callback) }
if (typeof this._db._batch == 'function')
if (typeof this._db._batch === 'function') {
return this._db._batch(this._operations, options, callback)
}

@@ -91,0 +91,0 @@ process.nextTick(callback)

@@ -12,12 +12,16 @@ /* Copyright (c) 2017 Rod Vagg, MIT License */

if (typeof callback != 'function')
if (typeof callback !== 'function') {
throw new Error('next() requires a callback argument')
}
if (self._ended)
return callback(new Error('cannot call next() after end()'))
if (self._nexting)
return callback(new Error('cannot call next() before previous next() has completed'))
if (self._ended) {
return process.nextTick(callback, new Error('cannot call next() after end()'))
}
if (self._nexting) {
return process.nextTick(callback, new Error('cannot call next() before previous next() has completed'))
}
self._nexting = true
if (typeof self._next == 'function') {
if (typeof self._next === 'function') {
return self._next(function () {

@@ -36,12 +40,13 @@ self._nexting = false

AbstractIterator.prototype.end = function (callback) {
if (typeof callback != 'function')
if (typeof callback !== 'function') {
throw new Error('end() requires a callback argument')
}
if (this._ended)
return callback(new Error('end() already called on iterator'))
if (this._ended) {
return process.nextTick(callback, new Error('end() already called on iterator'))
}
this._ended = true
if (typeof this._end == 'function')
return this._end(callback)
if (typeof this._end === 'function') { return this._end(callback) }

@@ -48,0 +53,0 @@ process.nextTick(callback)

/* Copyright (c) 2017 Rod Vagg, MIT License */
var xtend = require('xtend')
, AbstractIterator = require('./abstract-iterator')
, AbstractChainedBatch = require('./abstract-chained-batch')
const xtend = require('xtend')
const AbstractIterator = require('./abstract-iterator')
const AbstractChainedBatch = require('./abstract-chained-batch')
const hasOwnProperty = Object.prototype.hasOwnProperty
const rangeOptions = 'start end gt gte lt lte'.split(' ')
function AbstractLevelDOWN (location) {
if (!arguments.length || location === undefined)
if (!arguments.length || location === undefined) {
throw new Error('constructor requires at least a location argument')
}
if (typeof location != 'string')
if (typeof location !== 'string') {
throw new Error('constructor requires a location string argument')
}

@@ -19,18 +23,17 @@ this.location = location

AbstractLevelDOWN.prototype.open = function (options, callback) {
var self = this
, oldStatus = this.status
var self = this
var oldStatus = this.status
if (typeof options == 'function')
callback = options
if (typeof options === 'function') { callback = options }
if (typeof callback != 'function')
if (typeof callback !== 'function') {
throw new Error('open() requires a callback argument')
}
if (typeof options != 'object')
options = {}
if (typeof options !== 'object') { options = {} }
options.createIfMissing = options.createIfMissing != false
options.createIfMissing = options.createIfMissing !== false
options.errorIfExists = !!options.errorIfExists
if (typeof this._open == 'function') {
if (typeof this._open === 'function') {
this.status = 'opening'

@@ -52,9 +55,10 @@ this._open(options, function (err) {

AbstractLevelDOWN.prototype.close = function (callback) {
var self = this
, oldStatus = this.status
var self = this
var oldStatus = this.status
if (typeof callback != 'function')
if (typeof callback !== 'function') {
throw new Error('close() requires a callback argument')
}
if (typeof this._close == 'function') {
if (typeof this._close === 'function') {
this.status = 'closing'

@@ -76,22 +80,20 @@ this._close(function (err) {

AbstractLevelDOWN.prototype.get = function (key, options, callback) {
var err
if (typeof options === 'function') { callback = options }
if (typeof options == 'function')
callback = options
if (typeof callback != 'function')
if (typeof callback !== 'function') {
throw new Error('get() requires a callback argument')
}
if (err = this._checkKey(key, 'key'))
return callback(err)
var err = this._checkKey(key, 'key')
if (err) return process.nextTick(callback, err)
key = this._serializeKey(key)
if (typeof options != 'object')
options = {}
if (typeof options !== 'object') { options = {} }
options.asBuffer = options.asBuffer != false
options.asBuffer = options.asBuffer !== false
if (typeof this._get == 'function')
if (typeof this._get === 'function') {
return this._get(key, options, callback)
}

@@ -102,12 +104,10 @@ process.nextTick(function () { callback(new Error('NotFound')) })

AbstractLevelDOWN.prototype.put = function (key, value, options, callback) {
var err
if (typeof options === 'function') { callback = options }
if (typeof options == 'function')
callback = options
if (typeof callback != 'function')
if (typeof callback !== 'function') {
throw new Error('put() requires a callback argument')
}
if (err = this._checkKey(key, 'key'))
return callback(err)
var err = this._checkKey(key, 'key')
if (err) return process.nextTick(callback, err)

@@ -117,7 +117,7 @@ key = this._serializeKey(key)

if (typeof options != 'object')
options = {}
if (typeof options !== 'object') { options = {} }
if (typeof this._put == 'function')
if (typeof this._put === 'function') {
return this._put(key, value, options, callback)
}

@@ -128,20 +128,18 @@ process.nextTick(callback)

AbstractLevelDOWN.prototype.del = function (key, options, callback) {
var err
if (typeof options === 'function') { callback = options }
if (typeof options == 'function')
callback = options
if (typeof callback != 'function')
if (typeof callback !== 'function') {
throw new Error('del() requires a callback argument')
}
if (err = this._checkKey(key, 'key'))
return callback(err)
var err = this._checkKey(key, 'key')
if (err) return process.nextTick(callback, err)
key = this._serializeKey(key)
if (typeof options != 'object')
options = {}
if (typeof options !== 'object') { options = {} }
if (typeof this._del == 'function')
if (typeof this._del === 'function') {
return this._del(key, options, callback)
}

@@ -152,39 +150,44 @@ process.nextTick(callback)

AbstractLevelDOWN.prototype.batch = function (array, options, callback) {
if (!arguments.length)
return this._chainedBatch()
if (!arguments.length) { return this._chainedBatch() }
if (typeof options == 'function')
callback = options
if (typeof options === 'function') { callback = options }
if (typeof array == 'function')
callback = array
if (typeof array === 'function') { callback = array }
if (typeof callback != 'function')
if (typeof callback !== 'function') {
throw new Error('batch(array) requires a callback argument')
}
if (!Array.isArray(array))
return callback(new Error('batch(array) requires an array argument'))
if (!Array.isArray(array)) {
return process.nextTick(callback, new Error('batch(array) requires an array argument'))
}
if (!options || typeof options != 'object')
options = {}
if (!options || typeof options !== 'object') { options = {} }
var i = 0
, l = array.length
, e
, err
var serialized = new Array(array.length)
for (; i < l; i++) {
e = array[i]
if (typeof e != 'object')
continue
for (var i = 0; i < array.length; i++) {
if (typeof array[i] !== 'object' || array[i] === null) {
return process.nextTick(callback, new Error('batch(array) element must be an object and not `null`'))
}
if (err = this._checkKey(e.type, 'type'))
return callback(err)
var e = xtend(array[i])
if (err = this._checkKey(e.key, 'key'))
return callback(err)
if (e.type !== 'put' && e.type !== 'del') {
return process.nextTick(callback, new Error("`type` must be 'put' or 'del'"))
}
var err = this._checkKey(e.key, 'key')
if (err) return process.nextTick(callback, err)
e.key = this._serializeKey(e.key)
if (e.type === 'put') { e.value = this._serializeValue(e.value) }
serialized[i] = e
}
if (typeof this._batch == 'function')
return this._batch(array, options, callback)
if (typeof this._batch === 'function') {
return this._batch(serialized, options, callback)
}

@@ -194,53 +197,46 @@ process.nextTick(callback)

//TODO: remove from here, not a necessary primitive
AbstractLevelDOWN.prototype.approximateSize = function (start, end, callback) {
if ( start == null
|| end == null
|| typeof start == 'function'
|| typeof end == 'function') {
throw new Error('approximateSize() requires valid `start`, `end` and `callback` arguments')
}
AbstractLevelDOWN.prototype._setupIteratorOptions = function (options) {
options = cleanRangeOptions(options)
if (typeof callback != 'function')
throw new Error('approximateSize() requires a callback argument')
options.reverse = !!options.reverse
options.keys = options.keys !== false
options.values = options.values !== false
options.limit = 'limit' in options ? options.limit : -1
options.keyAsBuffer = options.keyAsBuffer !== false
options.valueAsBuffer = options.valueAsBuffer !== false
start = this._serializeKey(start)
end = this._serializeKey(end)
return options
}
if (typeof this._approximateSize == 'function')
return this._approximateSize(start, end, callback)
function cleanRangeOptions (options) {
var result = {}
process.nextTick(function () {
callback(null, 0)
})
}
for (var k in options) {
if (!hasOwnProperty.call(options, k)) continue
if (isRangeOption(k) && isEmptyRangeOption(options[k])) continue
AbstractLevelDOWN.prototype._setupIteratorOptions = function (options) {
var self = this
result[k] = options[k]
}
options = xtend(options)
return result
}
;[ 'start', 'end', 'gt', 'gte', 'lt', 'lte' ].forEach(function (o) {
if (options[o] && self._isBuffer(options[o]) && options[o].length === 0)
delete options[o]
})
function isRangeOption (k) {
return rangeOptions.indexOf(k) !== -1
}
options.reverse = !!options.reverse
options.keys = options.keys != false
options.values = options.values != false
options.limit = 'limit' in options ? options.limit : -1
options.keyAsBuffer = options.keyAsBuffer != false
options.valueAsBuffer = options.valueAsBuffer != false
function isEmptyRangeOption (v) {
return v === '' || v == null || isEmptyBuffer(v)
}
return options
function isEmptyBuffer (v) {
return Buffer.isBuffer(v) && v.length === 0
}
AbstractLevelDOWN.prototype.iterator = function (options) {
if (typeof options != 'object')
options = {}
if (typeof options !== 'object') { options = {} }
options = this._setupIteratorOptions(options)
if (typeof this._iterator == 'function')
return this._iterator(options)
if (typeof this._iterator === 'function') { return this._iterator(options) }

@@ -254,10 +250,4 @@ return new AbstractIterator(this)

AbstractLevelDOWN.prototype._isBuffer = function (obj) {
return Buffer.isBuffer(obj)
}
AbstractLevelDOWN.prototype._serializeKey = function (key) {
return this._isBuffer(key)
? key
: String(key)
return Buffer.isBuffer(key) ? key : String(key)
}

@@ -267,15 +257,19 @@

if (value == null) return ''
return this._isBuffer(value) || process.browser ? value : String(value)
return Buffer.isBuffer(value) || process.browser ? value : String(value)
}
AbstractLevelDOWN.prototype._checkKey = function (obj, type) {
if (obj === null || obj === undefined)
if (obj === null || obj === undefined) {
return new Error(type + ' cannot be `null` or `undefined`')
}
if (this._isBuffer(obj) && obj.length === 0)
if (Buffer.isBuffer(obj) && obj.length === 0) {
return new Error(type + ' cannot be an empty Buffer')
else if (String(obj) === '')
}
if (String(obj) === '') {
return new Error(type + ' cannot be an empty String')
}
}
module.exports = AbstractLevelDOWN
var db
, verifyNotFoundError = require('./util').verifyNotFoundError
, isTypedArray = require('./util').isTypedArray
var verifyNotFoundError = require('./util').verifyNotFoundError
var isTypedArray = require('./util').isTypedArray

@@ -34,47 +34,103 @@ module.exports.setUp = function (leveldown, test, testCommon) {

test('test batch() with missing `key`', function (t) {
var async = false
db.batch([{ type: 'put', value: 'foo1' }], function (err) {
t.ok(err, 'got error')
t.equal(err.message, 'key cannot be `null` or `undefined`', 'correct error message')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})
test('test batch() with null `key`', function (t) {
var async = false
db.batch([{ type: 'put', key: null, value: 'foo1' }], function (err) {
t.ok(err, 'got error')
t.equal(err.message, 'key cannot be `null` or `undefined`', 'correct error message')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})
test('test batch() with missing `key` and `value`', function (t) {
var async = false
db.batch([{ type: 'put' }], function (err) {
t.ok(err, 'got error')
t.equal(err.message, 'key cannot be `null` or `undefined`', 'correct error message')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})
test('test batch() with missing `type`', function (t) {
var async = false
db.batch([{ key: 'key', value: 'value' }], function (err) {
t.ok(err, 'got error')
t.equal(err.message, "`type` must be 'put' or 'del'", 'correct error message')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})
test('test batch() with wrong `type`', function (t) {
var async = false
db.batch([{ key: 'key', value: 'value', type: 'foo' }], function (err) {
t.ok(err, 'got error')
t.equal(err.message, "`type` must be 'put' or 'del'", 'correct error message')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})
test('test batch() with missing array', function (t) {
var async = false
db.batch(function (err) {
t.ok(err, 'got error')
t.equal(err.message, 'batch(array) requires an array argument', 'correct error message')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})
test('test batch() with undefined array', function (t) {
var async = false
db.batch(void 0, function (err) {
t.ok(err, 'got error')
t.equal(err.message, 'batch(array) requires an array argument', 'correct error message')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})
test('test batch() with null array', function (t) {
var async = false
db.batch(null, function (err) {
t.ok(err, 'got error')
t.equal(err.message, 'batch(array) requires an array argument', 'correct error message')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})

@@ -88,2 +144,19 @@

})
;[null, undefined, 1, true].forEach(function (element) {
var type = element === null ? 'null' : typeof element
test('test batch() with ' + type + ' element', function (t) {
var async = false
db.batch([element], function (err) {
t.ok(err, 'got error')
t.equal(err.message, 'batch(array) element must be an object and not `null`', 'correct error message')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})
})
}

@@ -109,3 +182,3 @@

} else {
t.ok(typeof Buffer != 'undefined' && value instanceof Buffer)
t.ok(typeof Buffer !== 'undefined' && value instanceof Buffer)
result = value.toString()

@@ -121,6 +194,6 @@ }

db.batch([
{ type: 'put', key: 'foobatch1', value: 'bar1' }
, { type: 'put', key: 'foobatch2', value: 'bar2' }
, { type: 'put', key: 'foobatch3', value: 'bar3' }
, { type: 'del', key: 'foobatch2' }
{ type: 'put', key: 'foobatch1', value: 'bar1' },
{ type: 'put', key: 'foobatch2', value: 'bar2' },
{ type: 'put', key: 'foobatch3', value: 'bar3' },
{ type: 'del', key: 'foobatch2' }
], function (err) {

@@ -130,6 +203,5 @@ t.error(err)

var r = 0
, done = function () {
if (++r == 3)
t.end()
}
var done = function () {
if (++r === 3) { t.end() }
}

@@ -142,3 +214,3 @@ db.get('foobatch1', function (err, value) {

} else {
t.ok(typeof Buffer != 'undefined' && value instanceof Buffer)
t.ok(typeof Buffer !== 'undefined' && value instanceof Buffer)
result = value.toString()

@@ -152,3 +224,3 @@ }

t.ok(err, 'entry not found')
t.ok(typeof value == 'undefined', 'value is undefined')
t.ok(typeof value === 'undefined', 'value is undefined')
t.ok(verifyNotFoundError(err), 'NotFound error')

@@ -164,3 +236,3 @@ done()

} else {
t.ok(typeof Buffer != 'undefined' && value instanceof Buffer)
t.ok(typeof Buffer !== 'undefined' && value instanceof Buffer)
result = value.toString()

@@ -176,9 +248,14 @@ }

test('test multiple batch()', function (t) {
t.plan(3)
t.plan(4)
var async = false
db.batch([
{ type: 'put', key: 'foobah1', value: 'bar1' }
, { type: 'put', value: 'bar2' }
, { type: 'put', key: 'foobah3', value: 'bar3' }
{ type: 'put', key: 'foobah1', value: 'bar1' },
{ type: 'put', value: 'bar2' },
{ type: 'put', key: 'foobah3', value: 'bar3' }
], function (err) {
t.ok(err, 'should error')
t.ok(async, 'callback is asynchronous')
db.get('foobah1', function (err) {

@@ -190,3 +267,5 @@ t.ok(err, 'should not be found')

})
})
})
async = true
})

@@ -201,2 +280,3 @@ }

module.exports.all = function (leveldown, test, testCommon) {
testCommon = testCommon || require('../testCommon')
module.exports.setUp(leveldown, test, testCommon)

@@ -203,0 +283,0 @@ module.exports.args(test)

var db
function collectBatchOps (batch) {
var _put = batch._put
, _del = batch._del
, _operations = []
var _put = batch._put
var _del = batch._del
var _operations = []
if (typeof _put !== 'function' || typeof _del !== 'function')
if (typeof _put !== 'function' || typeof _del !== 'function') {
return batch._operations
}

@@ -168,3 +169,3 @@ batch._put = function (key, value) {

try {
batch.write(function (err) {})
batch.write(function () {})
} catch (err) {

@@ -180,3 +181,3 @@ t.equal(err.message, 'write() already called on this batch', 'correct error message')

var batch = db.batch()
, ops = collectBatchOps(batch)
var ops = collectBatchOps(batch)

@@ -195,15 +196,2 @@ batch

test('test serialize buffer', function (t) {
var batch = db.batch()
, ops = collectBatchOps(batch)
batch
.put(Buffer('foo'), Buffer('bar'))
.del(Buffer('baz'))
t.equal(ops[0].key.toString(), 'foo')
t.equal(ops[0].value.toString(), 'bar')
t.equal(ops[1].key.toString(), 'baz')
t.end()
})
test('test custom _serialize*', function (t) {

@@ -214,3 +202,3 @@ var _db = Object.create(db)

var batch = _db.batch()
, ops = collectBatchOps(batch)
var ops = collectBatchOps(batch)

@@ -222,4 +210,4 @@ batch

t.deepEqual(ops, [
{ type: 'put', key: { foo: 'bar' }, value: { beep: 'boop' } }
, { type: 'del', key: { bar: 'baz' } }
{ type: 'put', key: { foo: 'bar' }, value: { beep: 'boop' } },
{ type: 'del', key: { bar: 'baz' } }
])

@@ -233,39 +221,34 @@

test('test basic batch', function (t) {
db.batch(
[
{ type: 'put', key: 'one', value: '1' }
, { type: 'put', key: 'two', value: '2' }
, { type: 'put', key: 'three', value: '3' }
]
, function (err) {
db.batch([
{ type: 'put', key: 'one', value: '1' },
{ type: 'put', key: 'two', value: '2' },
{ type: 'put', key: 'three', value: '3' }
], function (err) {
t.error(err)
db.batch()
.put('1', 'one')
.del('2', 'two')
.put('3', 'three')
.clear()
.put('one', 'I')
.put('two', 'II')
.del('three')
.put('foo', 'bar')
.write(function (err) {
t.error(err)
db.batch()
.put('1', 'one')
.del('2', 'two')
.put('3', 'three')
.clear()
.put('one', 'I')
.put('two', 'II')
.del('three')
.put('foo', 'bar')
.write(function (err) {
testCommon.collectEntries(
db.iterator({ keyAsBuffer: false, valueAsBuffer: false }), function (err, data) {
t.error(err)
testCommon.collectEntries(
db.iterator({ keyAsBuffer: false, valueAsBuffer: false })
, function (err, data) {
t.error(err)
t.equal(data.length, 3, 'correct number of entries')
var expected = [
{ key: 'foo', value: 'bar' }
, { key: 'one', value: 'I' }
, { key: 'two', value: 'II' }
]
t.deepEqual(data, expected)
t.end()
}
)
})
}
)
t.equal(data.length, 3, 'correct number of entries')
var expected = [
{ key: 'foo', value: 'bar' },
{ key: 'one', value: 'I' },
{ key: 'two', value: 'II' }
]
t.deepEqual(data, expected)
t.end()
}
)
})
})
})

@@ -281,2 +264,3 @@ }

module.exports.all = function (leveldown, test, testCommon) {
testCommon = testCommon || require('../testCommon')
module.exports.setUp(leveldown, test, testCommon)

@@ -283,0 +267,0 @@ module.exports.args(test)

module.exports.close = function (leveldown, test, testCommon) {
testCommon = testCommon || require('../testCommon')
test('test close()', function (t) {

@@ -24,2 +25,2 @@ var db = leveldown(testCommon.location())

})
}
}
var db
, leveldown
, testCommon
, verifyNotFoundError = require('./util').verifyNotFoundError
, isTypedArray = require('./util').isTypedArray
var leveldown
var testCommon
var verifyNotFoundError = require('./util').verifyNotFoundError

@@ -45,28 +44,4 @@ module.exports.setUp = function (_leveldown, test, _testCommon) {

test('test _serialize object', function (t) {
t.plan(2)
var db = leveldown(testCommon.location())
db._del = function (key, opts, callback) {
t.equal(Buffer.isBuffer(key) ? String(key) : key, '[object Object]')
callback()
}
db.del({}, function (err, val) {
t.error(err)
})
})
test('test _serialize buffer', function (t) {
t.plan(2)
var db = leveldown(testCommon.location())
db._del = function (key, opts, callback) {
t.ok(Buffer.isBuffer(key))
callback()
}
db.del(Buffer('buf'), function (err, val) {
t.error(err)
})
})
test('test custom _serialize*', function (t) {
t.plan(2)
t.plan(3)
var db = leveldown(testCommon.location())

@@ -76,3 +51,3 @@ db._serializeKey = function (data) { return data }

t.deepEqual(key, { foo: 'bar' })
callback()
process.nextTick(callback)
}

@@ -82,2 +57,3 @@ db.open(function () {

t.error(err)
db.close(t.error.bind(t))
})

@@ -94,5 +70,5 @@ })

t.error(err)
db.get('foo', function (err) {
db.get('foo', function (err, value) {
t.ok(err, 'entry propertly deleted')
t.ok(typeof value == 'undefined', 'value is undefined')
t.ok(typeof value === 'undefined', 'value is undefined')
t.ok(verifyNotFoundError(err), 'NotFound error')

@@ -120,2 +96,3 @@ t.end()

module.exports.all = function (leveldown, test, testCommon) {
testCommon = testCommon || require('../testCommon')
module.exports.setUp(leveldown, test, testCommon)

@@ -122,0 +99,0 @@ module.exports.args(test)

var db
, leveldown
, testCommon
, verifyNotFoundError = require('./util').verifyNotFoundError
, isTypedArray = require('./util').isTypedArray
var leveldown
var testCommon
var verifyNotFoundError = require('./util').verifyNotFoundError
var isTypedArray = require('./util').isTypedArray

@@ -45,28 +45,4 @@ module.exports.setUp = function (_leveldown, test, _testCommon) {

test('test _serialize object', function (t) {
t.plan(2)
var db = leveldown(testCommon.location())
db._get = function (key, opts, callback) {
t.equal(Buffer.isBuffer(key) ? String(key) : key, '[object Object]')
callback()
}
db.get({}, function (err, val) {
t.error(err)
})
})
test('test _serialize buffer', function (t) {
t.plan(2)
var db = leveldown(testCommon.location())
db._get = function (key, opts, callback) {
t.same(key, Buffer('key'))
callback()
}
db.get(Buffer('key'), function (err, val) {
t.error(err)
})
})
test('test custom _serialize*', function (t) {
t.plan(2)
t.plan(3)
var db = leveldown(testCommon.location())

@@ -76,3 +52,3 @@ db._serializeKey = function (data) { return data }

t.deepEqual(key, { foo: 'bar' })
callback()
process.nextTick(callback)
}

@@ -82,2 +58,3 @@ db.open(function () {

t.error(err)
db.close(t.error.bind(t))
})

@@ -100,3 +77,3 @@ })

} else {
t.ok(typeof Buffer != 'undefined' && value instanceof Buffer)
t.ok(typeof Buffer !== 'undefined' && value instanceof Buffer)
try {

@@ -119,3 +96,3 @@ result = value.toString()

} else {
t.ok(typeof Buffer != 'undefined' && value instanceof Buffer)
t.ok(typeof Buffer !== 'undefined' && value instanceof Buffer)
try {

@@ -145,11 +122,10 @@ result = value.toString()

var r = 0
, done = function () {
if (++r == 20)
t.end()
}
, i = 0
, j = 0
var done = function () {
if (++r === 20) { t.end() }
}
var i = 0
var j = 0
for (; i < 10; ++i)
db.get('hello', function(err, value) {
for (; i < 10; ++i) {
db.get('hello', function (err, value) {
t.error(err)

@@ -159,12 +135,33 @@ t.equal(value.toString(), 'world')

})
}
for (; j < 10; ++j)
db.get('not found', function(err, value) {
for (; j < 10; ++j) {
db.get('not found', function (err, value) {
t.ok(err, 'should error')
t.ok(verifyNotFoundError(err), 'should have correct error message')
t.ok(typeof value == 'undefined', 'value is undefined')
t.ok(typeof value === 'undefined', 'value is undefined')
done()
})
}
})
})
test('test get() not found error is asynchronous', function (t) {
t.plan(5)
db.put('hello', 'world', function (err) {
t.error(err)
var async = false
db.get('not found', function (err, value) {
t.ok(err, 'should error')
t.ok(verifyNotFoundError(err), 'should have correct error message')
t.ok(typeof value === 'undefined', 'value is undefined')
t.ok(async, 'callback is asynchronous')
})
async = true
})
})
}

@@ -179,2 +176,3 @@

module.exports.all = function (leveldown, test, testCommon) {
testCommon = testCommon || require('../testCommon')
module.exports.setUp(leveldown, test, testCommon)

@@ -181,0 +179,0 @@ module.exports.args(test)

var db
, sourceData = (function () {
var d = []
, i = 0
, k
for (; i < 100; i++) {
k = (i < 10 ? '0' : '') + i
d.push({
type : 'put'
, key : k
, value : Math.random()
})
}
return d
}())
, transformSource = function (d) {
return { key: d.key, value: String(d.value) }
}
module.exports.sourceData = sourceData
module.exports.transformSource = transformSource
module.exports.setUp = function (leveldown, test, testCommon) {

@@ -70,8 +50,14 @@ test('setUp common', testCommon.setUp)

t.error(err)
iterator.end(function(err2) {
var async = false
iterator.end(function (err2) {
t.ok(err2, 'returned error')
t.equal(err2.name, 'Error', 'correct error')
t.equal(err2.message, 'end() already called on iterator')
t.is(err2.name, 'Error', 'correct error')
t.is(err2.message, 'end() already called on iterator')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})

@@ -84,8 +70,14 @@ })

t.error(err)
iterator.next(function(err2) {
var async = false
iterator.next(function (err2) {
t.ok(err2, 'returned error')
t.equal(err2.name, 'Error', 'correct error')
t.equal(err2.message, 'cannot call next() after end()', 'correct message')
t.is(err2.name, 'Error', 'correct error')
t.is(err2.message, 'cannot call next() after end()', 'correct message')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})

@@ -104,18 +96,23 @@ })

iterator.next(function(err) {
var async = false
iterator.next(function (err) {
t.ok(err, 'returned error')
t.equal(err.name, 'Error', 'correct error')
t.equal(err.message, 'cannot call next() before previous next() has completed')
t.is(err.name, 'Error', 'correct error')
t.is(err.message, 'cannot call next() before previous next() has completed')
t.ok(async, 'callback is asynchronous')
})
async = true
})
}
module.exports.iterator = function (leveldown, test, testCommon, collectEntries) {
module.exports.iterator = function (leveldown, test, testCommon) {
test('test simple iterator()', function (t) {
var data = [
{ type: 'put', key: 'foobatch1', value: 'bar1' }
, { type: 'put', key: 'foobatch2', value: 'bar2' }
, { type: 'put', key: 'foobatch3', value: 'bar3' }
]
, idx = 0
{ type: 'put', key: 'foobatch1', value: 'bar1' },
{ type: 'put', key: 'foobatch2', value: 'bar2' },
{ type: 'put', key: 'foobatch3', value: 'bar3' }
]
var idx = 0

@@ -125,24 +122,24 @@ db.batch(data, function (err) {

var iterator = db.iterator()
, fn = function (err, key, value) {
t.error(err)
if (key && value) {
t.ok(Buffer.isBuffer(key), 'key argument is a Buffer')
t.ok(Buffer.isBuffer(value), 'value argument is a Buffer')
t.equal(key.toString(), data[idx].key, 'correct key')
t.equal(value.toString(), data[idx].value, 'correct value')
process.nextTick(next)
idx++
} else { // end
t.ok(typeof err === 'undefined', 'err argument is undefined')
t.ok(typeof key === 'undefined', 'key argument is undefined')
t.ok(typeof value === 'undefined', 'value argument is undefined')
t.equal(idx, data.length, 'correct number of entries')
iterator.end(function () {
t.end()
})
}
}
, next = function () {
iterator.next(fn)
}
var fn = function (err, key, value) {
t.error(err)
if (key && value) {
t.ok(Buffer.isBuffer(key), 'key argument is a Buffer')
t.ok(Buffer.isBuffer(value), 'value argument is a Buffer')
t.is(key.toString(), data[idx].key, 'correct key')
t.is(value.toString(), data[idx].value, 'correct value')
process.nextTick(next)
idx++
} else { // end
t.ok(typeof err === 'undefined', 'err argument is undefined')
t.ok(typeof key === 'undefined', 'key argument is undefined')
t.ok(typeof value === 'undefined', 'value argument is undefined')
t.is(idx, data.length, 'correct number of entries')
iterator.end(function () {
t.end()
})
}
}
var next = function () {
iterator.next(fn)
}

@@ -152,314 +149,6 @@ next()

})
/** the following tests are mirroring the same series of tests in
* LevelUP read-stream-test.js
*/
test('setUp #2', function (t) {
db.close(function () {
db = leveldown(testCommon.location())
db.open(function () {
db.batch(sourceData, t.end.bind(t))
})
})
})
test('test full data collection', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false }), function (err, data) {
t.error(err)
t.equal(data.length, sourceData.length, 'correct number of entries')
var expected = sourceData.map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with reverse=true', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, reverse: true }), function (err, data) {
t.error(err)
t.equal(data.length, sourceData.length, 'correct number of entries')
var expected = sourceData.slice().reverse().map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with start=0', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '00' }), function (err, data) {
t.error(err)
t.equal(data.length, sourceData.length, 'correct number of entries')
var expected = sourceData.map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with start=50', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '50' }), function (err, data) {
t.error(err)
t.equal(data.length, 50, 'correct number of entries')
var expected = sourceData.slice(50).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with start=50 and reverse=true', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '50', reverse: true }), function (err, data) {
t.error(err)
t.equal(data.length, 51, 'correct number of entries')
var expected = sourceData.slice().reverse().slice(49).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with start being a midway key (49.5)', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '49.5' }), function (err, data) {
t.error(err)
t.equal(data.length, 50, 'correct number of entries')
var expected = sourceData.slice(50).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with start being a midway key (49999)', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '49999' }), function (err, data) {
t.error(err)
t.equal(data.length, 50, 'correct number of entries')
var expected = sourceData.slice(50).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with start being a midway key and reverse=true', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '49.5', reverse: true }), function (err, data) {
t.error(err)
t.equal(data.length, 50, 'correct number of entries')
var expected = sourceData.slice().reverse().slice(50).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with end=50', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, end: '50' }), function (err, data) {
t.error(err)
t.equal(data.length, 51, 'correct number of entries')
var expected = sourceData.slice(0, 51).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with end being a midway key (50.5)', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, end: '50.5' }), function (err, data) {
t.error(err)
t.equal(data.length, 51, 'correct number of entries')
var expected = sourceData.slice(0, 51).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with end being a midway key (50555)', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, end: '50555' }), function (err, data) {
t.error(err)
t.equal(data.length, 51, 'correct number of entries')
var expected = sourceData.slice(0, 51).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with end being a midway key and reverse=true', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, end: '50.5', reverse: true }), function (err, data) {
t.error(err)
t.equal(data.length, 49, 'correct number of entries')
var expected = sourceData.slice().reverse().slice(0, 49).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
// end='0', starting key is actually '00' so it should avoid it
test('test iterator with end=0', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, end: '0' }), function (err, data) {
t.error(err)
t.equal(data.length, 0, 'correct number of entries')
t.end()
})
})
test('test iterator with start=30 and end=70', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '30', end: '70' }), function (err, data) {
t.error(err)
t.equal(data.length, 41, 'correct number of entries')
var expected = sourceData.slice(30, 71).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with start=30 and end=70 and reverse=true', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '70', end: '30', reverse: true }), function (err, data) {
t.error(err)
t.equal(data.length, 41, 'correct number of entries')
var expected = sourceData.slice().reverse().slice(29, 70).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with limit=20', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, limit: 20 }), function (err, data) {
t.error(err)
t.equal(data.length, 20, 'correct number of entries')
var expected = sourceData.slice(0, 20).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with limit=20 and start=20', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '20', limit: 20 }), function (err, data) {
t.error(err)
t.equal(data.length, 20, 'correct number of entries')
var expected = sourceData.slice(20, 40).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with limit=20 and reverse=true', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, limit: 20, reverse: true }), function (err, data) {
t.error(err)
t.equal(data.length, 20, 'correct number of entries')
var expected = sourceData.slice().reverse().slice(0, 20).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with limit=20 and start=20 and reverse=true', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '79', limit: 20, reverse: true }), function (err, data) {
t.error(err)
t.equal(data.length, 20, 'correct number of entries')
var expected = sourceData.slice().reverse().slice(20, 40).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
// the default limit value from levelup is -1
test('test iterator with limit=-1 should iterate over whole database', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, limit: -1}), function (err, data) {
t.error(err)
t.equal(data.length, sourceData.length, 'correct number of entries')
var expected = sourceData.map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with limit=0 should not iterate over anything', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, limit: 0 }), function (err, data) {
t.error(err)
t.equal(data.length, 0, 'correct number of entries')
t.end()
})
})
test('test iterator with end after limit', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, limit: 20, end: '50' }), function (err, data) {
t.error(err)
t.equal(data.length, 20, 'correct number of entries')
var expected = sourceData.slice(0, 20).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with end before limit', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, limit: 50, end: '19' }), function (err, data) {
t.error(err)
t.equal(data.length, 20, 'correct number of entries')
var expected = sourceData.slice(0, 20).map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with start after database end', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '9a' }), function (err, data) {
t.error(err)
t.equal(data.length, 0, 'correct number of entries')
t.end()
})
})
test('test iterator with start after database end and reverse=true', function (t) {
collectEntries(db.iterator({ keyAsBuffer: false, valueAsBuffer: false, start: '9a', reverse: true }), function (err, data) {
t.error(err)
t.equal(data.length, sourceData.length, 'correct number of entries')
var expected = sourceData.slice().reverse().map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
test('test iterator with start and end after database and and reverse=true', function (t) {
collectEntries(db.iterator({ start: '9b', end: '9a', reverse: true }), function (err, data) {
t.error(err)
t.equal(data.length, 0, 'correct number of entries')
t.end()
})
})
function testIteratorCollectsFullDatabase (name, iteratorOptions) {
iteratorOptions.keyAsBuffer = false
iteratorOptions.valueAsBuffer = false
test(name, function (t) {
collectEntries(db.iterator(iteratorOptions), function (err, data) {
t.error(err)
t.equal(data.length, 100, 'correct number of entries')
var expected = sourceData.map(transformSource)
t.deepEqual(data, expected)
t.end()
})
})
}
if (!process.browser) {
// Can't use buffers as query keys in indexeddb (I think :P)
testIteratorCollectsFullDatabase(
'test iterator with start as empty buffer'
, { start: new Buffer(0) }
)
testIteratorCollectsFullDatabase(
'test iterator with end as empty buffer'
, { end: new Buffer(0) }
)
}
testIteratorCollectsFullDatabase(
'test iterator with start as empty string'
, { start: '' }
)
testIteratorCollectsFullDatabase(
'test iterator with start as null'
, { start: null }
)
testIteratorCollectsFullDatabase(
'test iterator with end as empty string'
, { end: '' }
)
testIteratorCollectsFullDatabase(
'test iterator with end as null'
, { end: null }
)
}
module.exports.snapshot = function (leveldown, test, testCommon) {
test('setUp #3', function (t) {
test('setUp #2', function (t) {
db.close(function () {

@@ -479,4 +168,4 @@ db = leveldown(testCommon.location())

t.ok(key, 'got a key')
t.equal(key.toString(), 'foobatch1', 'correct key')
t.equal(value.toString(), 'bar1', 'correct value')
t.is(key.toString(), 'foobatch1', 'correct key')
t.is(value.toString(), 'bar1', 'correct value')
iterator.end(t.end.bind(t))

@@ -495,8 +184,9 @@ })

module.exports.all = function (leveldown, test, testCommon) {
testCommon = testCommon || require('../testCommon')
module.exports.setUp(leveldown, test, testCommon)
module.exports.args(test)
module.exports.sequence(test)
module.exports.iterator(leveldown, test, testCommon, testCommon.collectEntries)
module.exports.iterator(leveldown, test, testCommon)
module.exports.snapshot(leveldown, test, testCommon)
module.exports.tearDown(test, testCommon)
}

@@ -27,2 +27,2 @@ module.exports.args = function (leveldown, test) {

})
}
}

@@ -33,7 +33,7 @@ module.exports.setUp = function (test, testCommon) {

db.open(function (err) {
t.error(err)
db.close(function () {
t.end()
})
t.error(err)
db.close(function () {
t.end()
})
})
})

@@ -46,7 +46,7 @@

db.open({}, function (err) {
t.error(err)
db.close(function () {
t.end()
})
t.error(err)
db.close(function () {
t.end()
})
})
})

@@ -74,2 +74,3 @@ test('test database open, close and open', function (t) {

var db = leveldown(testCommon.location())
var async = false

@@ -79,4 +80,7 @@ db.open({ createIfMissing: false }, function (err) {

t.ok(/does not exist/.test(err.message), 'error is about dir not existing')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})

@@ -86,3 +90,3 @@

var location = testCommon.location()
, db = leveldown(location)
var db = leveldown(location)

@@ -97,7 +101,13 @@ // make a valid database first, then close and dispose

db = leveldown(location)
var async = false
db.open({ createIfMissing: false, errorIfExists: true }, function (err) {
t.ok(err, 'error')
t.ok(/exists/.test(err.message), 'error is about already existing')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})

@@ -113,2 +123,3 @@ })

module.exports.all = function (leveldown, test, testCommon) {
testCommon = testCommon || require('../testCommon')
module.exports.setUp(test, testCommon)

@@ -119,2 +130,2 @@ module.exports.args(leveldown, test, testCommon)

module.exports.tearDown(test, testCommon)
}
}

@@ -1,11 +0,9 @@

/**** SETUP & UTILITY STUFF ****/
var db
, testBuffer
, test
, verifyNotFoundError = require('./util').verifyNotFoundError
const verifyNotFoundError = require('./util').verifyNotFoundError
const testBuffer = Buffer.from('testbuffer')
function makeGetDelErrorTests (type, key, expectedError) {
function makeGetDelErrorTests (test, type, key, expectedError) {
test('test get() with ' + type + ' causes error', function (t) {
var async = false
db.get(key, function (err) {

@@ -15,7 +13,12 @@ t.ok(err, 'has error')

t.ok(err.message.match(expectedError), 'correct error message')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})
test('test del() with ' + type + ' causes error', function (t) {
var async = false
db.del(key, function (err) {

@@ -25,9 +28,14 @@ t.ok(err, 'has error')

t.ok(err.message.match(expectedError), 'correct error message')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})
}
function makePutErrorTest (type, key, value, expectedError) {
function makePutErrorTest (test, type, key, value, expectedError) {
test('test put() with ' + type + ' causes error', function (t) {
var async = false
db.put(key, value, function (err) {

@@ -37,9 +45,12 @@ t.ok(err, 'has error')

t.ok(err.message.match(expectedError), 'correct error message')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})
}
function makePutGetDelSuccessfulTest (type, key, value, expectedResult) {
var hasExpectedResult = arguments.length == 4
function makePutGetDelSuccessfulTest (test, type, key, value, expectedResult) {
var hasExpectedResult = arguments.length === 5
test('test put()/get()/del() with ' + type, function (t) {

@@ -55,6 +66,4 @@ db.put(key, value, function (err) {

} else {
if (result != null)
result = _value.toString()
if (value != null)
value = value.toString()
if (result != null) { result = _value.toString() }
if (value != null) { value = value.toString() }
t.equals(result, value)

@@ -64,8 +73,14 @@ }

t.error(err, 'no error, deleted key/value for `' + type + '`')
db.get(key, function (err, value) {
var async = false
db.get(key, function (err, value) {
t.ok(err, 'entry propertly deleted')
t.ok(verifyNotFoundError(err), 'should have correct error message')
t.equal(typeof value, 'undefined', 'value is undefined')
t.ok(async, 'callback is asynchronous')
t.end()
})
async = true
})

@@ -77,9 +92,7 @@ })

function makeErrorKeyTest (type, key, expectedError) {
makeGetDelErrorTests(type, key, expectedError)
makePutErrorTest(type, key, 'foo', expectedError)
function makeErrorKeyTest (test, type, key, expectedError) {
makeGetDelErrorTests(test, type, key, expectedError)
makePutErrorTest(test, type, key, 'foo', expectedError)
}
/**** SETUP ENVIRONMENT ****/
module.exports.setUp = function (leveldown, test, testCommon) {

@@ -93,27 +106,20 @@ test('setUp common', testCommon.setUp)

/**** TEST ERROR KEYS ****/
module.exports.errorKeys = function (testFunc, BufferType) {
if (!BufferType)
BufferType = Buffer
test = testFunc
makeErrorKeyTest('null key', null, /key cannot be `null` or `undefined`/)
makeErrorKeyTest('undefined key', undefined, /key cannot be `null` or `undefined`/)
makeErrorKeyTest('empty String key', '', /key cannot be an empty String/)
makeErrorKeyTest('empty Buffer key', new BufferType(0), /key cannot be an empty \w*Buffer/)
makeErrorKeyTest('empty Array key', [], /key cannot be an empty String/)
module.exports.errorKeys = function (test) {
makeErrorKeyTest(test, 'null key', null, /key cannot be `null` or `undefined`/)
makeErrorKeyTest(test, 'undefined key', undefined, /key cannot be `null` or `undefined`/)
makeErrorKeyTest(test, 'empty String key', '', /key cannot be an empty String/)
makeErrorKeyTest(test, 'empty Buffer key', Buffer.alloc(0), /key cannot be an empty \w*Buffer/)
makeErrorKeyTest(test, 'empty Array key', [], /key cannot be an empty String/)
}
/**** TEST NON-ERROR KEYS ****/
module.exports.nonErrorKeys = function (testFunc) {
module.exports.nonErrorKeys = function (test) {
// valid falsey keys
test = testFunc
makePutGetDelSuccessfulTest('`false` key', false, 'foo false')
makePutGetDelSuccessfulTest('`0` key', 0, 'foo 0')
makePutGetDelSuccessfulTest('`NaN` key', NaN, 'foo NaN')
makePutGetDelSuccessfulTest(test, '`false` key', false, 'foo false')
makePutGetDelSuccessfulTest(test, '`0` key', 0, 'foo 0')
makePutGetDelSuccessfulTest(test, '`NaN` key', NaN, 'foo NaN')
// standard String key
makePutGetDelSuccessfulTest(
'long String key'
test
, 'long String key'
, 'some long string that I\'m using as a key for this unit test, cross your fingers dude, we\'re going in!'

@@ -125,33 +131,29 @@ , 'foo'

// Buffer key
makePutGetDelSuccessfulTest('Buffer key', testBuffer, 'foo')
makePutGetDelSuccessfulTest(test, 'Buffer key', testBuffer, 'foo')
}
// non-empty Array as a value
makePutGetDelSuccessfulTest('Array value', 'foo', [1,2,3,4])
makePutGetDelSuccessfulTest(test, 'Array value', 'foo', [1, 2, 3, 4])
}
/**** TEST ERROR VALUES ****/
module.exports.errorValues = function () {
}
module.exports.nonErrorValues = function (testFunc, BufferType) {
if (!BufferType) BufferType = Buffer
module.exports.nonErrorValues = function (test) {
// valid falsey values
test = testFunc
makePutGetDelSuccessfulTest('`false` value', 'foo false', false)
makePutGetDelSuccessfulTest('`0` value', 'foo 0', 0)
makePutGetDelSuccessfulTest('`NaN` value', 'foo NaN', NaN)
makePutGetDelSuccessfulTest(test, '`false` value', 'foo false', false)
makePutGetDelSuccessfulTest(test, '`0` value', 'foo 0', 0)
makePutGetDelSuccessfulTest(test, '`NaN` value', 'foo NaN', NaN)
// all of the following result in an empty-string value:
makePutGetDelSuccessfulTest(test, '`null` value', 'foo null', null, '')
makePutGetDelSuccessfulTest(test, '`undefined` value', 'foo undefined', undefined, '')
makePutGetDelSuccessfulTest(test, 'empty String value', 'foo', '', '')
makePutGetDelSuccessfulTest(test, 'empty Buffer value', 'foo', Buffer.alloc(0), '')
makePutGetDelSuccessfulTest(test, 'empty Array value', 'foo', [], '')
makePutGetDelSuccessfulTest('`null` value', 'foo null', null, '')
makePutGetDelSuccessfulTest('`undefined` value', 'foo undefined', undefined, '')
makePutGetDelSuccessfulTest('empty String value', 'foo', '', '')
makePutGetDelSuccessfulTest('empty Buffer value', 'foo', new BufferType(0), '')
makePutGetDelSuccessfulTest('empty Array value', 'foo', [], '')
// standard String value
makePutGetDelSuccessfulTest(
'long String value'
test
, 'long String value'
, 'foo'

@@ -162,10 +164,8 @@ , 'some long string that I\'m using as a key for this unit test, cross your fingers dude, we\'re going in!'

// standard Buffer value
makePutGetDelSuccessfulTest('Buffer value', 'foo', testBuffer)
makePutGetDelSuccessfulTest(test, 'Buffer value', 'foo', testBuffer)
// non-empty Array as a key
makePutGetDelSuccessfulTest('Array key', [1,2,3,4], 'foo')
makePutGetDelSuccessfulTest(test, 'Array key', [1, 2, 3, 4], 'foo')
}
/**** CLEANUP ENVIRONMENT ****/
module.exports.tearDown = function (test, testCommon) {

@@ -177,11 +177,10 @@ test('tearDown', function (t) {

module.exports.all = function (leveldown, testFunc, testCommon, buffer, BufferType) {
testBuffer = buffer
test = testFunc
module.exports.all = function (leveldown, test, testCommon) {
testCommon = testCommon || require('../testCommon')
module.exports.setUp(leveldown, test, testCommon)
module.exports.errorKeys(test, BufferType)
module.exports.errorKeys(test)
module.exports.nonErrorKeys(test)
module.exports.errorValues(test, BufferType)
module.exports.nonErrorValues(test, BufferType)
module.exports.errorValues(test)
module.exports.nonErrorValues(test)
module.exports.tearDown(test, testCommon)
}
var db
, leveldown
, testCommon
, verifyNotFoundError = require('./util').verifyNotFoundError
, isTypedArray = require('./util').isTypedArray
var leveldown
var testCommon
var isTypedArray = require('./util').isTypedArray

@@ -60,3 +59,3 @@ module.exports.setUp = function (_leveldown, test, _testCommon) {

t.ok(value)
callback()
process.nextTick(callback)
}

@@ -68,17 +67,4 @@ db.put({}, {}, function (err, val) {

test('test _serialize buffer', function (t) {
t.plan(3)
var db = leveldown(testCommon.location())
db._put = function (key, value, opts, callback) {
t.same(key, Buffer('key'))
t.same(value, Buffer('value'))
callback()
}
db.put(Buffer('key'), Buffer('value'), function (err, val) {
t.error(err)
})
})
test('test custom _serialize*', function (t) {
t.plan(3)
t.plan(4)
var db = leveldown(testCommon.location())

@@ -89,7 +75,8 @@ db._serializeKey = db._serializeValue = function (data) { return data }

t.deepEqual(value, { beep: 'boop' })
callback()
process.nextTick(callback)
}
db.open(function () {
db.put({ foo: 'bar' }, { beep: 'boop'}, function (err) {
db.put({ foo: 'bar' }, { beep: 'boop' }, function (err) {
t.error(err)
db.close(t.error.bind(t))
})

@@ -107,4 +94,5 @@ })

var result = value.toString()
if (isTypedArray(value))
if (isTypedArray(value)) {
result = String.fromCharCode.apply(null, new Uint16Array(value))
}
t.equal(result, 'bar')

@@ -115,16 +103,2 @@ t.end()

})
if (process.browser) {
test('test object value put()', function (t) {
db.put('dood', {pete: 'sampras'}, function (err) {
t.error(err)
db.get('dood', { asBuffer: false }, function (err, value) {
t.error(err)
t.equal(JSON.stringify(value), JSON.stringify({pete: 'sampras'}))
t.end()
})
})
})
}
}

@@ -161,2 +135,3 @@

module.exports.all = function (leveldown, test, testCommon) {
testCommon = testCommon || require('../testCommon')
module.exports.setUp(leveldown, test, testCommon)

@@ -163,0 +138,0 @@ module.exports.args(test)

@@ -8,4 +8,4 @@ var nfre = /NotFound/i

module.exports.isTypedArray = function isTypedArray (value) {
return (typeof ArrayBuffer != 'undefined' && value instanceof ArrayBuffer)
|| (typeof Uint8Array != 'undefined' && value instanceof Uint8Array)
return (typeof ArrayBuffer !== 'undefined' && value instanceof ArrayBuffer) ||
(typeof Uint8Array !== 'undefined' && value instanceof Uint8Array)
}

@@ -1,127 +0,575 @@

### 2.5.0 - May 1st 2016
# Changelog
* [[`fd4ba39136`](https://github.com/level/abstract-leveldown/commit/fd4ba39136)] - 2.5.0 (Julian Gruber)
* [[`b00f97f9ac`](https://github.com/level/abstract-leveldown/commit/b00f97f9ac)] - Merge pull request #85 from Level/remove/stringify-key-value (Lars-Magnus Skog)
* [[`1138d6d993`](https://github.com/level/abstract-leveldown/commit/1138d6d993)] - make tests more specific (Julian Gruber)
* [[`45289fc325`](https://github.com/level/abstract-leveldown/commit/45289fc325)] - fix serializing and add more tests (Julian Gruber)
* [[`e71e727dfb`](https://github.com/level/abstract-leveldown/commit/e71e727dfb)] - remove .toBuffer, add ._serialize* (Julian Gruber)
* [[`32aeebf2c1`](https://github.com/level/abstract-leveldown/commit/32aeebf2c1)] - make .toBuffer opt-in (Julian Gruber)
* [[`7e48270d40`](https://github.com/level/abstract-leveldown/commit/7e48270d40)] - Remove stringification of keys and values. (Julian Gruber)
* [[`da6d505f1f`](https://github.com/level/abstract-leveldown/commit/da6d505f1f)] - **readme**: fix minor typos (Tim Kuijsten)
* [[`f61fbcd6f7`](https://github.com/level/abstract-leveldown/commit/f61fbcd6f7)] - Merge pull request #79 from Level/checkKey (Lars-Magnus Skog)
* [[`25509f8bd6`](https://github.com/level/abstract-leveldown/commit/25509f8bd6)] - this._checkKey does not take three parameters (Lars-Magnus Skog)
* [[`48579e078d`](https://github.com/level/abstract-leveldown/commit/48579e078d)] - Merge pull request #78 from watson/patch-1 (Julian Gruber)
* [[`59fd61fc8f`](https://github.com/level/abstract-leveldown/commit/59fd61fc8f)] - Only show build status for the master branch (Thomas Watson Steen)
* [[`aef56c8f80`](https://github.com/level/abstract-leveldown/commit/aef56c8f80)] - Merge pull request #77 from Level/deps (Julian Gruber)
* [[`b12d070f9f`](https://github.com/level/abstract-leveldown/commit/b12d070f9f)] - memdown url (Lars-Magnus Skog)
* [[`72bdb6fb38`](https://github.com/level/abstract-leveldown/commit/72bdb6fb38)] - add dependency badge (Lars-Magnus Skog)
* [[`ee16027126`](https://github.com/level/abstract-leveldown/commit/ee16027126)] - update dependencies + test on moar node verions (Lars-Magnus Skog)
* [[`e5bdf0ed81`](https://github.com/level/abstract-leveldown/commit/e5bdf0ed81)] - Merge pull request #76 from Level/greenkeeper-tape-4.4.0 (Julian Gruber)
* [[`1b4e38527f`](https://github.com/level/abstract-leveldown/commit/1b4e38527f)] - chore(package): update tape to version 4.4.0 (greenkeeperio-bot)
## [Unreleased]
### 2.4.1 - Aug 29th 2015
## [4.0.0] - 2018-01-20
* [[`1259fc4b0a`](https://github.com/level/abstract-leveldown/commit/1259fc4b0a)] - 2.4.1 (Julian Gruber)
* [[`7c7db6f96c`](https://github.com/level/abstract-leveldown/commit/7c7db6f96c)] - Merge pull request #72 from Level/remove-const (Julian Gruber)
* [[`1cf77b9423`](https://github.com/level/abstract-leveldown/commit/1cf77b9423)] - (#71) - remove `const` (Nolan Lawson)
### Added
* `standard` for linting (#150) (@ralphtheninja)
* tests to make sure callbacks are called async (@vweevers)
* tests for serialization extensibility (@vweevers)
* @vweevers to contributors (@ralphtheninja)
* upgrade guide in `UPGRADING.md` (@ralphtheninja)
* node 9 to travis (@ralphtheninja)
### 2.4.0 - May 19th 2015
### Changed
* `AbstractLevelDOWN#_setupIteratorOptions` ignores empty range options (@ralphtheninja)
* Make `testCommon.js` the default value for `testCommon` parameter (@ralphtheninja)
* Use `Buffer.isBuffer()` instead of `AbstractLevelDOWN#isBuffer` (@ralphtheninja)
* Major cleanup of iterator tests (#161) (@ralphtheninja)
* Pass on test function as a parameter instead of setting local global (@ralphtheninja)
* Assert type is `'put'` or `'del'` in batch (@vweevers)
* Assert batch array elements are objects (@vweevers)
* [[`02e19475f6`](https://github.com/level/abstract-leveldown/commit/02e19475f6)] - 2.4.0 (Julian Gruber)
* [[`f336523ec7`](https://github.com/level/abstract-leveldown/commit/f336523ec7)] - Merge pull request #68 from Level/add/open-states (Julian Gruber)
* [[`c4ad1a0929`](https://github.com/level/abstract-leveldown/commit/c4ad1a0929)] - add missing t.error() calls to status tests (Julian Gruber)
* [[`f5ac25da96`](https://github.com/level/abstract-leveldown/commit/f5ac25da96)] - add .status (Julian Gruber)
* [[`fed5f84e4b`](https://github.com/level/abstract-leveldown/commit/fed5f84e4b)] - update changelog (Lars-Magnus Skog)
### Fixed
* Ensure stores are closed properly (fixes problems on Windows) (@ralphtheninja)
* Call back errors on next tick to avoid `zalgo` (@vweevers)
### 2.3.1 - May 18th 2015
### Removed
* Remove `isLevelDOWN` function and corresponding tests (@ralphtheninja)
* Remove `AbstractLevelDOWN#approximateSize` method and corresponding tests (@ralphtheninja)
* Remove `testBuffer` in `abstract/put-get-del-test.js` (@ralphtheninja)
* Remove object value test in `abstract/put-test.js` (@vweevers)
* Remove serialize buffer tests (@vweevers)
* Remove serialize object tests (@vweevers)
* Remove `BufferType` parameter in `abstract/put-get-del-test.js`, use `Buffer` (@ralphtheninja)
* [[`393c781629`](https://github.com/level/abstract-leveldown/commit/393c781629)] - document isLevelDown() (Lars-Magnus Skog)
* [[`fd899c49b9`](https://github.com/level/abstract-leveldown/commit/fd899c49b9)] - link to level/community (Lars-Magnus Skog)
## [3.0.0] - 2017-11-04
### 2.3.0 - May 18th 2015
### Added
* node version badge (@vweevers)
* [[`9a976428e2`](https://github.com/level/abstract-leveldown/commit/9a976428e2)] - export from index.js and factor out into is-leveldown.js (Lars-Magnus Skog)
* [[`8051f8f16c`](https://github.com/level/abstract-leveldown/commit/8051f8f16c)] - add isLevelDOWN() f
unction (Lars-Magnus Skog)
### Fixed
* Fix errors in `index.d.ts` (@sandersn)
### 2.2.2 - May 13th 2015
### Removed
* Drop support for `0.12`. Cause for new major version! (@vweevers)
* [[`4ff0a9bfbb`](https://github.com/level/abstract-leveldown/commit/4ff0a9bfbb)] - ***Revert*** "Merge pull request #60 from ralphtheninja/empty-location" (Julian Gruber)
* [[`fab11e9e3b`](https://github.com/level/abstract-leveldown/commit/fab11e9e3b)] - use t.equal instead of t.ok(a === b) (Julian Gruber)
## [2.7.2] - 2017-10-11
### 2.2.1 - May 12th 2015
### Changed
* Update `README` with new style (@ralphtheninja)
* [[`f5051090e4`](https://github.com/level/abstract-leveldown/commit/f5051090e4)] - merge location string checks into one if-statement (Lars-Magnus Skog)
* [[`cd362b2b9f`](https://github.com/level/abstract-leveldown/commit/cd362b2b9f)] - empty location string throws (Lars-Magnus Skog)
* [[`e6d1cb80ea`](https://github.com/level/abstract-leveldown/commit/e6d1cb80ea)] - .throws is different for tape (Lars-Magnus Skog)
* [[`a6f29b62fa`](https://github.com/level/abstract-leveldown/commit/a6f29b62fa)] - copy paste error gave wrong test description (Lars-Magnus Skog)
## [2.7.1] - 2017-09-30
### 2.2.0 - May 10th 2015
### Changed
* Refactor typings as es2015 module (@MeirionHughes)
* [[`aa867b3760`](https://github.com/level/abstract-leveldown/commit/aa867b3760)] - Merge pull request #58 from Level/add/put-sync (Julian Gruber)
* [[`234de997bb`](https://github.com/level/abstract-leveldown/commit/234de997bb)] - add sync put tests (Julian Gruber)
## [2.7.0] - 2017-09-12
### 2.1.4 - Apr 28th 2015
### Added
* `TypeScript` definitions to `index.d.ts` (@MeirionHughes)
* [[`969116d00f`](https://github.com/level/abstract-leveldown/commit/969116d00f)] - use t.equal() with tape (Lars-Magnus Skog)
## [2.6.3] - 2017-09-05
### 2.1.3 - Apr 28th 2015
### Added
* `GreenKeeper` (@ralphtheninja)
* test for key/value serialization (@bigeasy)
* test for `undefined` value serializing to empty string (@ralphtheninja)
* [[`68096e78cd`](https://github.com/level/abstract-leveldown/commit/68096e78cd)] - change from tap to tape (Lars-Magnus Skog)
### Changed
* Update dependencies (@ralphtheninja)
* Convert nullish values to empty strings (@bigeasy)
* Use `t.equal(a, b)` instead of `t.ok(a === b)` (@bigeasy)
* Relax tests for serializing object in `abstract/chained-batch-test.js` (@ralphtheninja)
### 2.1.2 - Apr 27th 2015
### Fixed
* Document `.status` property (@ralphtheninja)
* [[`d79c060c9d`](https://github.com/level/abstract-leveldown/commit/d79c060c9d)] - convert buffer to string so we can compare (Lars-Magnus Skog)
### Removed
### 2.1.1 - Apr 27th 2015
## [2.6.2] - 2017-07-30
* [[`3881fc4290`](https://github.com/level/abstract-leveldown/commit/3881fc4290)] -**travis**: update npm so 0.8 works, add 0.12 and iojs (Lars-Magnus Skog)
* [[`9f451e8f74`](https://github.com/level/abstract-leveldown/commit/9f451e8f74)] - rvagg/node- -> level/ (Lars-Magnus Skog)
* [[`ecd41a72db`](https://github.com/level/abstract-leveldown/commit/ecd41a72db)] - fix typo (Hao-kang Den)
* [[`20e91fd234`](https://github.com/level/abstract-leveldown/commit/20e91fd234)] - update logo and copyright (Lars-Magnus Skog)
* [[`6ccf134874`](https://github.com/level/abstract-leveldown/commit/6ccf134874)] - added @watson to package.json (Rod Vagg)
### Added
* tests for serialization extensibility (@juliangruber)
### 2.1.0 - Nov 9th 2014
### Changed
* Update dependencies and float `devDependencies` (@ralphtheninja)
* Update copyright years (@ralphtheninja)
* Update node versions on travis (@ralphtheninja)
* [[`7451cd15e6`](https://github.com/level/abstract-leveldown/commit/7451cd15e6)] - added @watson (Rod Vagg)
* [[`f4a3346da7`](https://github.com/level/abstract-leveldown/commit/f4a3346da7)] - Use `error` test function when testing for errors (Thomas Watson Steen)
* [[`24668c50e0`](https://github.com/level/abstract-leveldown/commit/24668c50e0)] - Don't fail if no value is returned by _get (Thomas Watson Steen)
* [[`865ed9e777`](https://github.com/level/abstract-leveldown/commit/865ed9e777)] - Use `setTimeout` instead of `setImmediate`. (Alan Gutierrez)
* [[`9e9069faed`](https://github.com/level/abstract-leveldown/commit/9e9069faed)] - 2.0.3 (Rod Vagg)
### Fixed
* Fix put test on object serialization (@juliangruber)
### 2.0.3 - Oct 2nd 2014
## [2.6.1] - 2016-09-12
* [[`78052c53eb`](https://github.com/level/abstract-leveldown/commit/78052c53eb)] - add test for atomic batch operations (Calvin Metcalf)
### Fixed
* Fix null case in default value serializer (fixes problems in `2.6.0`) (@juliangruber)
### 2.0.1 - Sep 1st 2014
## [2.6.0] - 2016-03-10
* [[`a0b36f6a18`](https://github.com/level/abstract-leveldown/commit/a0b36f6a18)] - Remove default options that's too LevelDOWN specific (Thomas Watson Steen)
* [[`1d97993d0b`](https://github.com/level/abstract-leveldown/commit/1d97993d0b)] - Allow boolean options to be falsy/truthy (Thomas Watson Steen)
* [[`fb3cf56da5`](https://github.com/level/abstract-leveldown/commit/fb3cf56da5)] - Set defaults for open, get, put, del and batch options (Thomas Watson Steen)
* [[`5c2a629e2b`](https://github.com/level/abstract-leveldown/commit/5c2a629e2b)] - Update pattern for setting default options for the iterator (Thomas Watson Steen)
### Added
* `collectBatchOps` function to buffer `_put` and `_del` inputs in `abstract/chained-batch-test.js` (@deanlandolt)
### 2.0.0 - Aug 26th 2014
### Changed
* Use proto delegation to patch methods on db (@deanlandolt)
* Allow serialization functions to return buffers (@deanlandolt)
* Lots of stuff between 0.11.1 and now, omitted updating changelog
* Switch to allowing writes of empty values: null, undefined, '', []
### Removed
* Remove unnecessary initialization hackery in `abstract/chained-batch-test.js` (@deanlandolt)
### 0.11.1 - Nov 15th 2013
**Historical Note** This release was a breaking change. See @juliangruber's [comment](https://github.com/Level/abstract-leveldown/pull/85#issuecomment-246980978) for more information.
* Adjust approximate-size-test.js to account for snappy compression
## [2.5.0] - 2016-05-01
### 0.11.0 - Oct 14th 2013
### Added
* dependency badge to `README` (@ralphtheninja)
* `AbstractLevelDOWN#_serializeKey` (@juliangruber)
* `AbstractLevelDOWN#_serializeValue` (@juliangruber)
* `AbstractChainedBatch#_serializeKey` (@juliangruber)
* `AbstractChainedBatch#_serializeValue` (@juliangruber)
* tests for `_serialize` object and buffer (@juliangruber)
* Introduce _setupIteratorOptions() method to fix options object prior to _iterator() call; makes working with gt/gte/lt/lte options a little easier (@rvagg)
### Changed
* Update dependencies and add more node versions to Travis (@ralphtheninja)
### 0.10.2 - Sep 6th 2013
### Fixed
* Update `memdown` url (@ralphtheninja)
* `AbstractLevelDOWN#._checkKey` does not take three parameters (@ralphtheninja)
* Only show build status for the master branch (@watson)
* Fix minor typos in `README` (@timkuijsten)
* Refactor duplicated versions of isTypedArray into util.js (@rvagg)
* Refactor duplicated versions of 'NotFound' checks into util.js, fixed too-strict version in get-test.js (@rvagg)
### Removed
* Remove stringification of keys and values (@juliangruber)
* Remove `.toBuffer` (@juliangruber)
### 0.10.1 - Aug 29th 2013
## [2.4.1] - 2015-08-29
* Relax check for 'Not Found: ' in error message to be case insensitive in get-test.js (@rvagg)
### Fixed
* Remove `const`. Fixes (#71) (@nolanlawson)
### 0.10.0 - Aug 19th 2013
## [2.4.0] - 2015-05-19
* Added test for gt, gte, lt, lte ranges (@dominictarr)
### Added
* `.status` property to `AbstractLevelDOWN` (@juliangruber)
## [2.3.1] - 2015-05-18
### Added
* link to `level/community` (@ralphtheninja)
### Fixed
* Document `isLevelDown` function (@ralphtheninja)
### Removed
* Extract `Contributors` section from `README` into `level/community` (@ralphtheninja)
## [2.3.0] - 2015-05-18
### Added
* `isLevelDOWN` function to `is-leveldown.js` (@ralphtheninja)
### Changed
* Use `t.equal(a, b)` instead of `t.ok(a === b)` (@juliangruber)
* Export API from `index.js` (@ralphtheninja)
## [2.2.2] - 2015-05-13
### Fixed
* Revert changes to location in `2.2.1` (@juliangruber)
## [2.2.1] - 2015-05-12
### Fixed
* Copy paste error gave wrong test description (@ralphtheninja)
* `t.throws()` is different for `tape` (@ralphtheninja)
* Empty location string throws (@ralphtheninja)
## [2.2.0] - 2015-05-10
### Added
* tests to `abstract/put-test.js` using `{ sync: true }` (@juliangruber)
## [2.1.4] - 2015-04-28
### Fixed
* Use `t.equal()` with `tape` (@ralphtheninja)
## [2.1.3] - 2015-04-28
### Changed
* Change from `tap` to `tape` (@ralphtheninja)
## [2.1.2] - 2015-04-27
### Changed
* Convert buffer to string so we can compare (@ralphtheninja)
## [2.1.1] - 2015-04-27
### Added
* @ralphtheninja to contributors (@ralphtheninja)
* Add `0.12` and `iojs` to travis (@ralphtheninja)
### Changed
* Update logo and copyright (@ralphtheninja)
### Fixed
* `.nonErrorValues()` test did not run in `abstract/put-get-del-test.js` (@hden)
* `rvagg/node-abstract-leveldown` moved to `level/abstract-leveldown` (@ralphtheninja)
* Fix travis for `0.8` (@ralphtheninja)
## [2.1.0] - 2014-11-09
### Added
* @watson to contributors (@rvagg)
### Changed
* Use `setTimeout` instead of `process.nextTick`. (@bigeasy)
### Fixed
* Don't fail if no value is returned by `._get` (@watson)
* Use `error` test function when testing for errors (@watson)
## [2.0.3] - 2014-10-02
No change.
## [2.0.2] - 2014-10-02
### Added
* test for atomic batch operations (@calvinmetcalf)
## [2.0.1] - 2014-09-01
### Changed
* Set default values for options to `.open`, `.get`, `.put`, `.del` and `.batch` (@watson)
* Update pattern for setting default options for the iterator (@watson)
* Allow boolean options to be falsy/truthy (@watson)
### Removed
* Remove default options that's too `LevelDOWN` specific (@watson)
## [2.0.0] - 2014-08-26
### Changed
* Switch to allowing writes of empty values, `null`, `undefined`, `''`, `[]` and empty buffer (@juliangruber)
* Rename `AbstractLevelDOWN#_checkKeyValue` to `AbstractLevelDOWN#_checkKey` (@rvagg)
## [1.0.0] - 2014-08-24
### Added
* test that error is thrown when location isn't a string (@calvinmetcalf)
* test for opening and closing the store (@calvinmetcalf)
* test for iterator with `limit` set to `0` (@watson)
* tests to `abstract/batch-test.js` (@calvinmetcalf)
* default values for iterator options (@watson)
* `null` check for batch options (@calvinmetcalf)
### Changed
* Ensure `Boolean` iterator options are `Boolean` (@watson)
### Removed
* Remove options.start hackery (@rvagg)
## [0.12.4] - 2014-08-20
### Added
* test that `simple-iterator` returns buffers (@kesla)
* test for implicit snapshots (@kesla)
### Changed
* license to plain MIT (@andrewrk)
## [0.12.3] - 2014-06-27
### Changed
* Update `xtend` dependency (@andrewrk)
## [0.12.2] - 2014-04-26
### Changed
* `isTypedArray` checks for existence of `ArrayBuffer` and `Uint8Array` constructors before usage (@rvagg)
## [0.12.1] - 2014-04-26
### Changed
* `BufferType` in `abstract/put-get-del-test.js` defaults to `Buffer` instead of `ArrayBuffer` (@maxogden)
## [0.12.0] - 2014-03-12
### Changed
* Revert to pure `Buffer` and remove usage of `Uint16Array` (@rvagg)
## [0.11.4] - 2014-03-11
### Removed
* Remove duplicate call to `t.end()` (@maxogden)
## [0.11.3] - 2014-01-26
### Changed
* Less restrictive check for buffer type (@rvagg)
## [0.11.2] - 2013-12-05
### Added
* npm badges (@rvagg)
### Fixed
* broken iterator tests in `test.js` (@rvagg)
## [0.11.1] - 2013-11-15
### Changed
* Adjust `abstract/approximate-size-test.js` to account for snappy compression (@rvagg)
## [0.11.0] - 2013-10-14
### Added
* `AbstractLevelDOWN#_setupIteratorOptions` method to fix options object prior to _iterator() call; makes working with range options a little easier (@rvagg)
## [0.10.2] - 2013-09-06
### Changed
* Refactor duplicated versions of `isTypedArray` into `abstract/util.js` (@rvagg)
* Refactor duplicated versions of `'NotFound'` checks into `abstract/util.js`, fixed too-strict version in `get-test.js` (@rvagg)
## [0.10.1] - 2013-08-29
### Added
* @substack to contributors (@rvagg)
### Changed
* Relax check for 'Not Found: ' in error message to be case insensitive in `get-test.js` (@rvagg)
## [0.10.0] - 2013-08-19
### Added
* test for `gt`, `gte`, `lt` and `lte` ranges (@dominictarr)
## [0.9.0] - 2013-08-11
### Added
* tests for simultaneous get's (@kesla)
* tests for `AbstractChainedBatch` extendability (@kesla)
### Changed
* make `AbstractChainedBatch` extendable (@kesla)
* export `AbstractChainedBatch` from `abstract-leveldown.js` (@kesla)
### Fixed
* broken test assert in `abstract/get-test.js` (@rvagg)
* tests that weren't running properly (@kesla)
## [0.8.2] - 2013-08-02
No changes. Merely published changes made in `0.8.1`.
## [0.8.1] - 2013-08-02
### Changed
* remove `const` in `testCommon.js` (@rvagg)
**Historical Note** The version in `package.json` was changed from `0.7.4` to `0.8.1`. The `0.8.1` tag exists but this version was never published to npm.
## [0.8.0] - 2013-08-02
### Added
* `BufferType` parameter to `abstract/put-get-del-test.js` for bops support (@rvagg)
* `isTypedArray` function which checks `ArrayBuffer` or `Uint8Array` for bops support (@rvagg)
### Changed
* use `process.browser` check instead of `process.title == 'browser'` (@rvagg)
### Fixed
* problems with `cleanup` function not calling back when browserified (@rvagg)
**Historical Note** It seems the version in `package.json` was never changed to `0.8.0` in the git history, even though the `0.8.0` tag exists. Most likely `package.json` was modified locally during `npm publish` but was never committed.
## [0.7.4] - 2013-08-02
### Fixed
* problems related to `browserify` and `rimraf` (@rvagg)
## [0.7.3] - 2013-07-26
### Added
* @pgte to contributors (@rvagg)
* test for iterator with `limit` set to `-1` (@kesla)
## [0.7.2] - 2013-07-08
### Added
* `AbstractChainedBatch#_checkWritten` (@rvagg)
* test for delete on non-existent key (@rvagg)
* test for iterator with `start` after database `end` (@juliangruber)
### Changed
* chained batch state is frozen after `.write()` has been called (@rvagg)
* `NotFound` error made case insensitive (@rvagg)
* use `self` rather than binding functions to `this` (@juliangruber)
### Fixed
* don't coerce values to strings in browser (@maxogden)
* make tests work in node and browser (@maxogden)
## [0.7.1] - 2013-05-15
### Changed
* adjust tests to be browserable (@rvagg)
## [0.7.0] - 2013-05-14
### Added
* `AbstractChainedBatch#clear` (@rvagg)
## [0.6.1] - 2013-05-14
### Changed
* `AbstractIterator` calls back with error instead of throw on nexting and ending (@mcollina)
## [0.6.0] - 2013-05-14
### Changed
* split `t.deepEqual()` into multiple `t.equal()` in `abstract/iterator-test.js` (@rvagg)
* `AbstractIterator` calls back with error instead of throw on nexting and ending (@mcollina)
## [0.5.0] - 2013-05-14
### Changed
* `iterator.end(cb)` and `iterator.next(cb)` calls back with error instead of throws (@mcollina)
## [0.4.0-1] - 2013-05-14
### Added
* @No9 and @mcollina to contributors (@rvagg)
## [0.4.0] - 2013-05-14
### Added
* `AbstractChainedBatch` (@rvagg)
* `AbstractLevelDOWN#_chainedBatch` (@rvagg)
* `abstract/batch-test.js` and `abstract/chained-batch-test.js` (@rvagg)
### Changed
* moved `AbstractIterator` from `abstract-leveldown.js` to `abstract-iterator.js` (@rvagg)
## [0.3.0] - 2013-05-04
### Added
* put back test for opening database without options (@rvagg)
* `AbstractLevelDOWN#_isBuffer` so it can be overridden (@rvagg)
* `AbstractLevelDOWN#_checkKeyValue` so it can be overridden (@rvagg)
### Changed
* use `this._checkKeyValue()` instead of local function (@rvagg)
* use `this._isBuffer()` instead of `Buffer.isBuffer()` (@rvagg)
## [0.2.3] - 2013-05-04
### Removed
* test for opening database without options (@rvagg)
## [0.2.2] - 2013-05-04
### Changed
* split up `.open()` tests into `.open()` and `.openAdvanced()` (@rvagg)
## [0.2.1] - 2013-05-04
### Changed
* convert values to `string` in `abstract/put-get-del-test.js` if `Buffer` is `undefined` (@rvagg)
## [0.2.0] - 2013-05-04
### Added
* `process.browser` check for `start` and `end` keys in browser (@maxogden)
* `levelup` contributors (@rvagg)
### Changed
* convert values to `string` in `abstract/get-test.js` if `Buffer` is `undefined` (@rvagg)
* don't stringify keys and values in `abstract/iterator-test.js` (@maxogden)
### Fixed
* `tape` compatibility issues (@maxogden)
## [0.1.0] - 2013-04-23
### Added
* abstract tests from `leveldown` (@maxogden)
### Fixed
* clarifications in `README` (@rvagg)
## [0.0.2] - 2013-03-18
### Added
* node 0.10 to travis (@rvagg)
* `Buffer.isBuffer()` checks to keys and values (@rvagg)
### Changed
* export `checkKeyValue` (@rvagg)
## [0.0.1] - 2013-03-18
### Added
* `checkKeyValue` function for more complete error checking (@rvagg)
## 0.0.0 - 2013-03-15
First release. :seedling:
[Unreleased]: https://github.com/level/abstract-leveldown/compare/v4.0.0...HEAD
[4.0.0]: https://github.com/level/abstract-leveldown/compare/v3.0.0...v4.0.0
[3.0.0]: https://github.com/level/abstract-leveldown/compare/v2.7.2...v3.0.0
[2.7.2]: https://github.com/level/abstract-leveldown/compare/v2.7.1...v2.7.2
[2.7.1]: https://github.com/level/abstract-leveldown/compare/v2.7.0...v2.7.1
[2.7.0]: https://github.com/level/abstract-leveldown/compare/v2.6.3...v2.7.0
[2.6.3]: https://github.com/level/abstract-leveldown/compare/v2.6.2...v2.6.3
[2.6.2]: https://github.com/level/abstract-leveldown/compare/v2.6.1...v2.6.2
[2.6.1]: https://github.com/level/abstract-leveldown/compare/v2.6.0...v2.6.1
[2.6.0]: https://github.com/level/abstract-leveldown/compare/v2.5.0...v2.6.0
[2.5.0]: https://github.com/level/abstract-leveldown/compare/v2.4.1...v2.5.0
[2.4.1]: https://github.com/level/abstract-leveldown/compare/v2.4.0...v2.4.1
[2.4.0]: https://github.com/level/abstract-leveldown/compare/v2.3.1...v2.4.0
[2.3.1]: https://github.com/level/abstract-leveldown/compare/v2.3.0...v2.3.1
[2.3.0]: https://github.com/level/abstract-leveldown/compare/v2.2.2...v2.3.0
[2.2.2]: https://github.com/level/abstract-leveldown/compare/v2.2.1...v2.2.2
[2.2.1]: https://github.com/level/abstract-leveldown/compare/v2.2.0...v2.2.1
[2.2.0]: https://github.com/level/abstract-leveldown/compare/v2.1.4...v2.2.0
[2.1.4]: https://github.com/level/abstract-leveldown/compare/v2.1.3...v2.1.4
[2.1.3]: https://github.com/level/abstract-leveldown/compare/v2.1.2...v2.1.3
[2.1.2]: https://github.com/level/abstract-leveldown/compare/v2.1.1...v2.1.2
[2.1.1]: https://github.com/level/abstract-leveldown/compare/v2.1.0...v2.1.1
[2.1.0]: https://github.com/level/abstract-leveldown/compare/v2.0.3...v2.1.0
[2.0.3]: https://github.com/level/abstract-leveldown/compare/v2.0.2...v2.0.3
[2.0.2]: https://github.com/level/abstract-leveldown/compare/v2.0.1...v2.0.2
[2.0.1]: https://github.com/level/abstract-leveldown/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/level/abstract-leveldown/compare/v1.0.0...v2.0.0
[1.0.0]: https://github.com/level/abstract-leveldown/compare/v0.12.4...v1.0.0
[0.12.4]: https://github.com/level/abstract-leveldown/compare/v0.12.3...v0.12.4
[0.12.3]: https://github.com/level/abstract-leveldown/compare/v0.12.2...v0.12.3
[0.12.2]: https://github.com/level/abstract-leveldown/compare/v0.12.1...v0.12.2
[0.12.1]: https://github.com/level/abstract-leveldown/compare/v0.12.0...v0.12.1
[0.12.0]: https://github.com/level/abstract-leveldown/compare/v0.11.4...v0.12.0
[0.11.4]: https://github.com/level/abstract-leveldown/compare/v0.11.3...v0.11.4
[0.11.3]: https://github.com/level/abstract-leveldown/compare/v0.11.2...v0.11.3
[0.11.2]: https://github.com/level/abstract-leveldown/compare/0.11.1...v0.11.2
[0.11.1]: https://github.com/level/abstract-leveldown/compare/0.11.0...0.11.1
[0.11.0]: https://github.com/level/abstract-leveldown/compare/0.10.2...0.11.0
[0.10.2]: https://github.com/level/abstract-leveldown/compare/0.10.1...0.10.2
[0.10.1]: https://github.com/level/abstract-leveldown/compare/0.10.0...0.10.1
[0.10.0]: https://github.com/level/abstract-leveldown/compare/0.9.0...0.10.0
[0.9.0]: https://github.com/level/abstract-leveldown/compare/0.8.2...0.9.0
[0.8.2]: https://github.com/level/abstract-leveldown/compare/0.8.1...0.8.2
[0.8.1]: https://github.com/level/abstract-leveldown/compare/0.8.0...0.8.1
[0.8.0]: https://github.com/level/abstract-leveldown/compare/0.7.4...0.8.0
[0.7.4]: https://github.com/level/abstract-leveldown/compare/0.7.3...0.7.4
[0.7.3]: https://github.com/level/abstract-leveldown/compare/0.7.2...0.7.3
[0.7.2]: https://github.com/level/abstract-leveldown/compare/0.7.1...0.7.2
[0.7.1]: https://github.com/level/abstract-leveldown/compare/0.7.0...0.7.1
[0.7.0]: https://github.com/level/abstract-leveldown/compare/0.6.1...0.7.0
[0.6.1]: https://github.com/level/abstract-leveldown/compare/0.6.0...0.6.1
[0.6.0]: https://github.com/level/abstract-leveldown/compare/0.5.0...0.6.0
[0.5.0]: https://github.com/level/abstract-leveldown/compare/0.4.0-1...0.5.0
[0.4.0-1]: https://github.com/level/abstract-leveldown/compare/0.4.0...0.4.0-1
[0.4.0]: https://github.com/level/abstract-leveldown/compare/0.3.0...0.4.0
[0.3.0]: https://github.com/level/abstract-leveldown/compare/0.2.1...0.3.0
[0.2.3]: https://github.com/level/abstract-leveldown/compare/0.2.2...0.2.3
[0.2.2]: https://github.com/level/abstract-leveldown/compare/0.2.1...0.2.2
[0.2.1]: https://github.com/level/abstract-leveldown/compare/0.2.0...0.2.1
[0.2.0]: https://github.com/level/abstract-leveldown/compare/0.1.0...0.2.0
[0.1.0]: https://github.com/level/abstract-leveldown/compare/0.0.2...0.1.0
[0.0.2]: https://github.com/level/abstract-leveldown/compare/0.0.1...0.0.2
[0.0.1]: https://github.com/level/abstract-leveldown/compare/0.0.0...0.0.1

@@ -1,4 +0,3 @@

exports.AbstractLevelDOWN = require('./abstract-leveldown')
exports.AbstractIterator = require('./abstract-iterator')
exports.AbstractLevelDOWN = require('./abstract-leveldown')
exports.AbstractIterator = require('./abstract-iterator')
exports.AbstractChainedBatch = require('./abstract-chained-batch')
exports.isLevelDOWN = require('./is-leveldown')
{
"name": "abstract-leveldown",
"description": "An abstract prototype matching the LevelDOWN API",
"version": "3.0.0",
"version": "4.0.0",
"contributors": [

@@ -19,3 +19,4 @@ "Rod Vagg <r@va.gg> (https://github.com/rvagg)",

"James Halliday <mail@substack.net> (https://github.com/substack)",
"Thomas Watson Steen <w@tson.dk> (https://github.com/watson)"
"Thomas Watson Steen <w@tson.dk> (https://github.com/watson)",
"Vincent Weevers <mail@vincentweevers.nl> (https://github.com/vweevers)"
],

@@ -40,2 +41,3 @@ "repository": {

"sinon": "^4.0.0",
"standard": "^10.0.3",
"tape": "^4.7.0"

@@ -47,3 +49,3 @@ },

"scripts": {
"test": "node test.js"
"test": "standard && node test.js"
},

@@ -50,0 +52,0 @@ "license": "MIT",

@@ -10,2 +10,3 @@ # abstract-leveldown

[![david](https://david-dm.org/Level/abstract-leveldown.svg)](https://david-dm.org/level/abstract-leveldown)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![npm](https://img.shields.io/npm/dm/abstract-leveldown.svg)](https://www.npmjs.com/package/abstract-leveldown)

@@ -111,3 +112,2 @@

### AbstractLevelDOWN#_approximateSize(start, end, callback)
### AbstractLevelDOWN#_serializeKey(key)

@@ -119,2 +119,13 @@ ### AbstractLevelDOWN#_serializeValue(value)

The `iterator()` operation accepts the following range options:
* `gt`
* `gte`
* `lt`
* `lte`
* `start` (legacy)
* `end` (legacy)
A range option that is either an empty buffer, an empty string or `null` will be ignored.
`AbstractIterator` implements the basic state management found in LevelDOWN. It keeps track of when a `next()` is in progress and when an `end()` has been called so it doesn't allow concurrent `next()` calls, it does allow `end()` while a `next()` is in progress and it doesn't allow either `next()` or `end()` after `end()` has been called.

@@ -139,9 +150,4 @@

### isLevelDown(db)
Returns `true` if `db` has the same public api as `abstract-leveldown`, otherwise `false`. This is a utility function and it's not part of the extensible api.
<a name="contributing"></a>
Contributing
------------
## Contributing

@@ -155,4 +161,3 @@ `abstract-leveldown` is an **OPEN Open Source Project**. This means that:

<a name="license"></a>
License &amp; Copyright
-------------------
## License &amp; Copyright

@@ -159,0 +164,0 @@ Copyright &copy; 2013-2017 `abstract-leveldown` [contributors](https://github.com/level/community#contributors).

@@ -1,9 +0,8 @@

var test = require('tape')
, sinon = require('sinon')
, util = require('util')
, testCommon = require('./testCommon')
, AbstractLevelDOWN = require('./').AbstractLevelDOWN
, AbstractIterator = require('./').AbstractIterator
, AbstractChainedBatch = require('./').AbstractChainedBatch
, isLevelDOWN = require('./').isLevelDOWN
var test = require('tape')
var sinon = require('sinon')
var util = require('util')
var testCommon = require('./testCommon')
var AbstractLevelDOWN = require('./').AbstractLevelDOWN
var AbstractIterator = require('./').AbstractIterator
var AbstractChainedBatch = require('./').AbstractChainedBatch

@@ -14,3 +13,5 @@ function factory (location, opts) {

/*** compatibility with basic LevelDOWN API ***/
/**
* Compatibility with basic LevelDOWN API
*/

@@ -32,10 +33,6 @@ require('./abstract/leveldown-test').args(factory, test, testCommon)

require('./abstract/put-get-del-test').errorKeys(test)
//require('./abstract/put-get-del-test').nonErrorKeys(test, testCommon)
// require('./abstract/put-get-del-test').nonErrorKeys(test, testCommon)
require('./abstract/put-get-del-test').errorValues(test)
//require('./abstract/test/put-get-del-test').nonErrorKeys(test, testCommon)
require('./abstract/put-get-del-test').tearDown(test, testCommon)
require('./abstract/approximate-size-test').setUp(factory, test, testCommon)
require('./abstract/approximate-size-test').args(test)
require('./abstract/batch-test').setUp(factory, test, testCommon)

@@ -53,3 +50,5 @@ require('./abstract/batch-test').args(test)

/*** extensibility ***/
/**
* Extensibility
*/

@@ -59,4 +58,2 @@ test('test core extensibility', function (t) {

AbstractLevelDOWN.call(this, location)
t.equal(this.location, location, 'location set on `this`')
t.end()
}

@@ -66,3 +63,5 @@

;new Test('foobar')
var test = new Test('foobar')
t.equal(test.location, 'foobar', 'location set on instance')
t.end()
})

@@ -77,3 +76,3 @@

var buffer = new Buffer(0)
var buffer = Buffer.alloc(0)
var test = new Test('foobar')

@@ -87,3 +86,3 @@

var browser = !! process.browser
var browser = !!process.browser
process.browser = false

@@ -104,5 +103,5 @@

var spy = sinon.spy()
, expectedCb = function () {}
, expectedOptions = { createIfMissing: true, errorIfExists: false }
, test
var expectedCb = function () {}
var expectedOptions = { createIfMissing: true, errorIfExists: false }
var test

@@ -138,4 +137,4 @@ function Test (location) {

var spy = sinon.spy()
, expectedCb = function () {}
, test
var expectedCb = function () {}
var test

@@ -161,6 +160,6 @@ function Test (location) {

var spy = sinon.spy()
, expectedCb = function () {}
, expectedOptions = { asBuffer: true }
, expectedKey = 'a key'
, test
var expectedCb = function () {}
var expectedOptions = { asBuffer: true }
var expectedKey = 'a key'
var test

@@ -200,6 +199,6 @@ function Test (location) {

var spy = sinon.spy()
, expectedCb = function () {}
, expectedOptions = { options: 1 }
, expectedKey = 'a key'
, test
var expectedCb = function () {}
var expectedOptions = { options: 1 }
var expectedKey = 'a key'
var test

@@ -237,7 +236,7 @@ function Test (location) {

var spy = sinon.spy()
, expectedCb = function () {}
, expectedOptions = { options: 1 }
, expectedKey = 'a key'
, expectedValue = 'a value'
, test
var expectedCb = function () {}
var expectedOptions = { options: 1 }
var expectedKey = 'a key'
var expectedValue = 'a value'
var test

@@ -275,35 +274,11 @@ function Test (location) {

test('test approximateSize() extensibility', function (t) {
var spy = sinon.spy()
, expectedCb = function () {}
, expectedStart = 'a start'
, expectedEnd = 'an end'
, test
function Test (location) {
AbstractLevelDOWN.call(this, location)
}
util.inherits(Test, AbstractLevelDOWN)
Test.prototype._approximateSize = spy
test = new Test('foobar')
test.approximateSize(expectedStart, expectedEnd, expectedCb)
t.equal(spy.callCount, 1, 'got _approximateSize() call')
t.equal(spy.getCall(0).thisValue, test, '`this` on _approximateSize() was correct')
t.equal(spy.getCall(0).args.length, 3, 'got three arguments')
t.equal(spy.getCall(0).args[0], expectedStart, 'got expected start argument')
t.equal(spy.getCall(0).args[1], expectedEnd, 'got expected end argument')
t.equal(spy.getCall(0).args[2], expectedCb, 'got expected cb argument')
t.end()
})
test('test batch() extensibility', function (t) {
var spy = sinon.spy()
, expectedCb = function () {}
, expectedOptions = { options: 1 }
, expectedArray = [ 1, 2 ]
, test
var expectedCb = function () {}
var expectedOptions = { options: 1 }
var expectedArray = [
{ type: 'put', key: '1', value: '1' },
{ type: 'del', key: '2' }
]
var test

@@ -325,3 +300,3 @@ function Test (location) {

t.equal(spy.getCall(0).args.length, 3, 'got three arguments')
t.equal(spy.getCall(0).args[0], expectedArray, 'got expected array argument')
t.deepEqual(spy.getCall(0).args[0], expectedArray, 'got expected array argument')
t.deepEqual(spy.getCall(0).args[1], {}, 'got expected options argument')

@@ -335,3 +310,3 @@ t.equal(spy.getCall(0).args[2], expectedCb, 'got expected callback argument')

t.equal(spy.getCall(1).args.length, 3, 'got three arguments')
t.equal(spy.getCall(1).args[0], expectedArray, 'got expected array argument')
t.deepEqual(spy.getCall(1).args[0], expectedArray, 'got expected array argument')
t.deepEqual(spy.getCall(1).args[1], expectedOptions, 'got expected options argument')

@@ -345,3 +320,3 @@ t.equal(spy.getCall(1).args[2], expectedCb, 'got expected callback argument')

t.equal(spy.getCall(2).args.length, 3, 'got three arguments')
t.equal(spy.getCall(2).args[0], expectedArray, 'got expected array argument')
t.deepEqual(spy.getCall(2).args[0], expectedArray, 'got expected array argument')
t.ok(spy.getCall(2).args[1], 'options should not be null')

@@ -354,6 +329,5 @@ t.equal(spy.getCall(2).args[2], expectedCb, 'got expected callback argument')

var spy = sinon.spy()
, expectedCb = function () {}
, expectedOptions = { options: 1 }
, expectedArray = [ 1, 2 ]
, test
var expectedCb = function () {}
var expectedOptions = { options: 1 }
var test

@@ -397,3 +371,3 @@ function Test (location) {

var spy = sinon.spy()
, test
var test

@@ -426,4 +400,2 @@ function Test (location) {

AbstractChainedBatch.call(this, db)
t.equal(this._db, db, 'db set on `this`')
t.end()
}

@@ -433,3 +405,5 @@

new Test('foobar')
var test = new Test('foobar')
t.equal(test._db, 'foobar', 'db set on instance')
t.end()
})

@@ -439,4 +413,4 @@

var spy = sinon.spy()
, spycb = sinon.spy()
, test
var spycb = sinon.spy()
var test

@@ -467,6 +441,6 @@ function Test (db) {

var spy = sinon.spy()
, expectedKey = 'key'
, expectedValue = 'value'
, returnValue
, test
var expectedKey = 'key'
var expectedValue = 'value'
var returnValue
var test

@@ -494,5 +468,5 @@ function Test (db) {

var spy = sinon.spy()
, expectedKey = 'key'
, returnValue
, test
var expectedKey = 'key'
var returnValue
var test

@@ -519,4 +493,4 @@ function Test (db) {

var spy = sinon.spy()
, returnValue
, test
var returnValue
var test

@@ -542,4 +516,12 @@ function Test (db) {

var spy = sinon.spy()
, expectedOptions = { options: 1, reverse: false, keys: true, values: true, limit: -1, keyAsBuffer: true, valueAsBuffer: true }
, test
var expectedOptions = {
options: 1,
reverse: false,
keys: true,
values: true,
limit: -1,
keyAsBuffer: true,
valueAsBuffer: true
}
var test

@@ -567,4 +549,2 @@ function Test (location) {

AbstractIterator.call(this, db)
t.equal(this.db, db, 'db set on `this`')
t.end()
}

@@ -574,3 +554,5 @@

;new Test('foobar')
var test = new Test('foobar')
t.equal(test.db, 'foobar', 'db set on instance')
t.end()
})

@@ -580,4 +562,4 @@

var spy = sinon.spy()
, spycb = sinon.spy()
, test
var spycb = sinon.spy()
var test

@@ -608,4 +590,4 @@ function Test (db) {

var spy = sinon.spy()
, expectedCb = function () {}
, test
var expectedCb = function () {}
var test

@@ -630,5 +612,7 @@ function Test (db) {

test('test serialization extensibility', function (t) {
test('test serialization extensibility (put)', function (t) {
t.plan(5)
var spy = sinon.spy()
, test
var test

@@ -659,34 +643,197 @@ function Test (location) {

t.equal(spy.getCall(0).args[1], 'bar', 'got expected value argument')
})
test('test serialization extensibility (del)', function (t) {
t.plan(3)
var spy = sinon.spy()
var test
function Test (location) {
AbstractLevelDOWN.call(this, location)
}
util.inherits(Test, AbstractLevelDOWN)
Test.prototype._serializeKey = function (key) {
t.equal(key, 'no')
return 'foo'
}
Test.prototype._serializeValue = function (value) {
t.fail('should not be called')
}
Test.prototype._del = spy
test = new Test('foobar')
test.del('no', function () {})
t.equal(spy.callCount, 1, 'got _del() call')
t.equal(spy.getCall(0).args[0], 'foo', 'got expected key argument')
t.end()
})
test('isLevelDOWN', function (t) {
t.notOk(isLevelDOWN(), 'is not a leveldown')
t.notOk(isLevelDOWN(''), 'is not a leveldown')
t.notOk(isLevelDOWN({}), 'is not a leveldown')
t.notOk(isLevelDOWN({ put: function () {} }), 'is not a leveldown')
t.ok(isLevelDOWN(new AbstractLevelDOWN('location')), 'IS a leveldown')
t.ok(isLevelDOWN({
open: function () {},
close: function () {},
get: function () {},
put: function () {},
del: function () {},
batch: function () {},
iterator: function () {}
}), 'IS a leveldown')
t.ok(isLevelDOWN({
open: function () {},
close: function () {},
get: function () {},
put: function () {},
del: function () {},
batch: function () {},
approximateSize: function () {},
iterator: function () {}
}), 'IS also a leveldown')
t.end()
test('test serialization extensibility (batch array put)', function (t) {
t.plan(5)
var spy = sinon.spy()
var test
function Test (location) {
AbstractLevelDOWN.call(this, location)
}
util.inherits(Test, AbstractLevelDOWN)
Test.prototype._serializeKey = function (key) {
t.equal(key, 'no')
return 'foo'
}
Test.prototype._serializeValue = function (value) {
t.equal(value, 'nope')
return 'bar'
}
Test.prototype._batch = spy
test = new Test('foobar')
test.batch([ { type: 'put', key: 'no', value: 'nope' } ], function () {})
t.equal(spy.callCount, 1, 'got _batch() call')
t.equal(spy.getCall(0).args[0][0].key, 'foo', 'got expected key')
t.equal(spy.getCall(0).args[0][0].value, 'bar', 'got expected value')
})
test('test serialization extensibility (batch chain put)', function (t) {
t.plan(5)
var spy = sinon.spy()
var test
function Test (location) {
AbstractLevelDOWN.call(this, location)
}
util.inherits(Test, AbstractLevelDOWN)
Test.prototype._serializeKey = function (key) {
t.equal(key, 'no')
return 'foo'
}
Test.prototype._serializeValue = function (value) {
t.equal(value, 'nope')
return 'bar'
}
Test.prototype._batch = spy
test = new Test('foobar')
test.batch().put('no', 'nope').write(function () {})
t.equal(spy.callCount, 1, 'got _batch() call')
t.equal(spy.getCall(0).args[0][0].key, 'foo', 'got expected key')
t.equal(spy.getCall(0).args[0][0].value, 'bar', 'got expected value')
})
test('test serialization extensibility (batch array del)', function (t) {
t.plan(3)
var spy = sinon.spy()
var test
function Test (location) {
AbstractLevelDOWN.call(this, location)
}
util.inherits(Test, AbstractLevelDOWN)
Test.prototype._serializeKey = function (key) {
t.equal(key, 'no')
return 'foo'
}
Test.prototype._serializeValue = function (value) {
t.fail('should not be called')
}
Test.prototype._batch = spy
test = new Test('foobar')
test.batch([ { type: 'del', key: 'no' } ], function () {})
t.equal(spy.callCount, 1, 'got _batch() call')
t.equal(spy.getCall(0).args[0][0].key, 'foo', 'got expected key')
})
test('test serialization extensibility (batch chain del)', function (t) {
t.plan(3)
var spy = sinon.spy()
var test
function Test (location) {
AbstractLevelDOWN.call(this, location)
}
util.inherits(Test, AbstractLevelDOWN)
Test.prototype._serializeKey = function (key) {
t.equal(key, 'no')
return 'foo'
}
Test.prototype._serializeValue = function (value) {
t.fail('should not be called')
}
Test.prototype._batch = spy
test = new Test('foobar')
test.batch().del('no').write(function () {})
t.equal(spy.callCount, 1, 'got _batch() call')
t.equal(spy.getCall(0).args[0][0].key, 'foo', 'got expected key')
})
test('test serialization extensibility (batch array is not mutated)', function (t) {
t.plan(7)
var spy = sinon.spy()
var test
function Test (location) {
AbstractLevelDOWN.call(this, location)
}
util.inherits(Test, AbstractLevelDOWN)
Test.prototype._serializeKey = function (key) {
t.equal(key, 'no')
return 'foo'
}
Test.prototype._serializeValue = function (value) {
t.equal(value, 'nope')
return 'bar'
}
Test.prototype._batch = spy
test = new Test('foobar')
var op = { type: 'put', key: 'no', value: 'nope' }
test.batch([op], function () {})
t.equal(spy.callCount, 1, 'got _batch() call')
t.equal(spy.getCall(0).args[0][0].key, 'foo', 'got expected key')
t.equal(spy.getCall(0).args[0][0].value, 'bar', 'got expected value')
t.equal(op.key, 'no', 'did not mutate input key')
t.equal(op.value, 'nope', 'did not mutate input value')
})
test('.status', function (t) {

@@ -727,3 +874,3 @@ t.test('empty prototype', function (t) {

Test.prototype._open = function (options, cb) {
cb(new Error)
cb(new Error())
}

@@ -749,3 +896,3 @@

Test.prototype._close = function (cb) {
cb(new Error)
cb(new Error())
}

@@ -810,1 +957,78 @@

})
test('_setupIteratorOptions', function (t) {
const keys = 'start end gt gte lt lte'.split(' ')
const db = new AbstractLevelDOWN('foolocation')
function setupOptions (constrFn) {
const options = {}
keys.forEach(function (key) {
options[key] = constrFn()
})
return options
}
function verifyUndefinedOptions (t, options) {
keys.forEach(function (key) {
t.notOk(key in options, 'property should be deleted')
})
t.end()
}
t.test('default options', function (t) {
t.same(db._setupIteratorOptions(), {
reverse: false,
keys: true,
values: true,
limit: -1,
keyAsBuffer: true,
valueAsBuffer: true
}, 'correct defaults')
t.end()
})
t.test('set options', function (t) {
t.same(db._setupIteratorOptions({
reverse: false,
keys: false,
values: false,
limit: 20,
keyAsBuffer: false,
valueAsBuffer: false
}), {
reverse: false,
keys: false,
values: false,
limit: 20,
keyAsBuffer: false,
valueAsBuffer: false
}, 'options set correctly')
t.end()
})
t.test('deletes empty buffers', function (t) {
const options = setupOptions(function () { return Buffer.from('') })
keys.forEach(function (key) {
t.is(Buffer.isBuffer(options[key]), true, 'should be buffer')
t.is(options[key].length, 0, 'should be empty')
})
verifyUndefinedOptions(t, db._setupIteratorOptions(options))
})
t.test('deletes empty strings', function (t) {
const options = setupOptions(function () { return '' })
keys.forEach(function (key) {
t.is(typeof options[key], 'string', 'should be string')
t.is(options[key].length, 0, 'should be empty')
})
verifyUndefinedOptions(t, db._setupIteratorOptions(options))
})
t.test('deletes null options', function (t) {
const options = setupOptions(function () { return null })
keys.forEach(function (key) {
t.same(options[key], null, 'should be null')
})
verifyUndefinedOptions(t, db._setupIteratorOptions(options))
})
})

@@ -1,75 +0,73 @@

var path = require('path')
, fs = !process.browser && require('fs')
, rimraf = !process.browser && require('rimraf')
var path = require('path')
var fs = !process.browser && require('fs')
var rimraf = !process.browser && require('rimraf')
var dbidx = 0
, location = function () {
return path.join(__dirname, '_leveldown_test_db_' + dbidx++)
}
var location = function () {
return path.join(__dirname, '_leveldown_test_db_' + dbidx++)
}
, lastLocation = function () {
return path.join(__dirname, '_leveldown_test_db_' + dbidx)
}
var lastLocation = function () {
return path.join(__dirname, '_leveldown_test_db_' + dbidx)
}
, cleanup = function (callback) {
if (process.browser)
return callback()
var cleanup = function (callback) {
if (process.browser) { return process.nextTick(callback) }
fs.readdir(__dirname, function (err, list) {
if (err) return callback(err)
fs.readdir(__dirname, function (err, list) {
if (err) return callback(err)
list = list.filter(function (f) {
return (/^_leveldown_test_db_/).test(f)
})
list = list.filter(function (f) {
return (/^_leveldown_test_db_/).test(f)
})
if (!list.length)
return callback()
if (!list.length) { return callback() }
var ret = 0
var ret = 0
list.forEach(function (f) {
rimraf(path.join(__dirname, f), function (err) {
if (++ret == list.length)
callback()
})
})
list.forEach(function (f) {
rimraf(path.join(__dirname, f), function (err) {
if (err) return callback(err)
if (++ret === list.length) { callback() }
})
}
})
})
}
, setUp = function (t) {
cleanup(function (err) {
t.error(err, 'cleanup returned an error')
t.end()
})
}
var setUp = function (t) {
cleanup(function (err) {
t.error(err, 'cleanup returned an error')
t.end()
})
}
, tearDown = function (t) {
setUp(t) // same cleanup!
}
var tearDown = function (t) {
setUp(t) // same cleanup!
}
, collectEntries = function (iterator, callback) {
var data = []
, next = function () {
iterator.next(function (err, key, value) {
if (err) return callback(err)
if (!arguments.length) {
return iterator.end(function (err) {
callback(err, data)
})
}
data.push({ key: key, value: value })
setTimeout(next, 0)
})
}
next()
}
var collectEntries = function (iterator, callback) {
var data = []
var next = function () {
iterator.next(function (err, key, value) {
if (err) return callback(err)
if (!arguments.length) {
return iterator.end(function (err) {
callback(err, data)
})
}
data.push({ key: key, value: value })
setTimeout(next, 0)
})
}
next()
}
module.exports = {
location : location
, cleanup : cleanup
, lastLocation : lastLocation
, setUp : setUp
, tearDown : tearDown
, collectEntries : collectEntries
location: location,
cleanup: cleanup,
lastLocation: lastLocation,
setUp: setUp,
tearDown: tearDown,
collectEntries: collectEntries
}

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