From a5a07f9108af5ebc6bf659174501e5578ba06246 Mon Sep 17 00:00:00 2001 From: "greenkeeper[bot]" Date: Sat, 20 Oct 2018 12:54:09 +0000 Subject: [PATCH 1/9] Upgrade abstract-leveldown from ~5.0.0 to ~6.0.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9acad4d..46d9094 100644 --- a/package.json +++ b/package.json @@ -28,7 +28,7 @@ "./immediate.js": "./immediate-browser.js" }, "dependencies": { - "abstract-leveldown": "~5.0.0", + "abstract-leveldown": "~6.0.1", "functional-red-black-tree": "~1.0.1", "immediate": "~3.2.3", "inherits": "~2.0.1", From 35b97ee9972f346f4d0f09d373a308988669b122 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sun, 20 Jan 2019 10:09:57 +0100 Subject: [PATCH 2/9] Invoke abstract tests from single function --- test.js | 80 ++++++++++++++++++++++++++------------------------------- 1 file changed, 36 insertions(+), 44 deletions(-) diff --git a/test.js b/test.js index 9c98023..0436d33 100644 --- a/test.js +++ b/test.js @@ -1,36 +1,28 @@ var test = require('tape') -var testCommon = require('abstract-leveldown/testCommon') -var MemDOWN = require('./').default +var suite = require('abstract-leveldown/test') +var memdown = require('.').default var ltgt = require('ltgt') var Buffer = require('safe-buffer').Buffer var noop = function () {} -/** compatibility with basic LevelDOWN API **/ +var testCommon = suite.common({ + test: test, + factory: function () { + return memdown() + }, -// Skip this test because memdown doesn't have a location or constructor options -// require('abstract-leveldown/abstract/leveldown-test').args(MemDOWN, test) - -require('abstract-leveldown/abstract/open-test').args(MemDOWN, test, testCommon) -require('abstract-leveldown/abstract/open-test').open(MemDOWN, test, testCommon) - -require('abstract-leveldown/abstract/del-test').all(MemDOWN, test) - -require('abstract-leveldown/abstract/get-test').all(MemDOWN, test) - -require('abstract-leveldown/abstract/put-test').all(MemDOWN, test) - -require('abstract-leveldown/abstract/put-get-del-test').all(MemDOWN, test) - -require('abstract-leveldown/abstract/batch-test').all(MemDOWN, test) -require('abstract-leveldown/abstract/chained-batch-test').all(MemDOWN, test) - -require('abstract-leveldown/abstract/close-test').close(MemDOWN, test) + // Unsupported features + createIfMissing: false, + errorIfExists: false, + seek: false +}) -require('abstract-leveldown/abstract/iterator-test').all(MemDOWN, test) -require('abstract-leveldown/abstract/iterator-range-test').all(MemDOWN, test) +// Test abstract-leveldown compliance +suite(testCommon) -test('unsorted entry, sorted iterator', function (t) { - var db = new MemDOWN() +// Additional tests for this implementation +test.skip('unsorted entry, sorted iterator', function (t) { + var db = memdown() db.open(noop) @@ -71,7 +63,7 @@ test('unsorted entry, sorted iterator', function (t) { }) test('reading while putting', function (t) { - var db = new MemDOWN() + var db = memdown() db.open(noop) @@ -98,7 +90,7 @@ test('reading while putting', function (t) { }) test('reading while deleting', function (t) { - var db = new MemDOWN() + var db = memdown() db.open(noop) @@ -126,7 +118,7 @@ test('reading while deleting', function (t) { }) test('reverse ranges', function (t) { - var db = new MemDOWN() + var db = memdown() db.open(noop) @@ -149,7 +141,7 @@ test('reverse ranges', function (t) { }) test('delete while iterating', function (t) { - var db = new MemDOWN() + var db = memdown() db.open(function (err) { t.error(err, 'opens correctly') @@ -184,7 +176,7 @@ test('delete while iterating', function (t) { }) test('iterator with byte range', function (t) { - var db = new MemDOWN() + var db = memdown() db.open(function (err) { t.error(err, 'opens correctly') @@ -202,10 +194,10 @@ test('iterator with byte range', function (t) { }) }) -test('iterator does not clone buffers', function (t) { +test.skip('iterator does not clone buffers', function (t) { t.plan(3) - var db = new MemDOWN() + var db = memdown() var buf = Buffer.from('a') db.open(noop) @@ -218,10 +210,10 @@ test('iterator does not clone buffers', function (t) { }) }) -test('iterator stringifies buffer input', function (t) { +test.skip('iterator stringifies buffer input', function (t) { t.plan(3) - var db = new MemDOWN() + var db = memdown() db.open(noop) db.put(1, 2, noop) @@ -234,7 +226,7 @@ test('iterator stringifies buffer input', function (t) { }) test('backing rbtree is buffer-aware', function (t) { - var db = new MemDOWN() + var db = memdown() db.open(function (err) { t.error(err, 'opens correctly') @@ -269,7 +261,7 @@ test('backing rbtree is buffer-aware', function (t) { test('empty value in batch', function (t) { t.plan(6) - var db = new MemDOWN() + var db = memdown() db.open(function (err) { t.error(err, 'opens correctly') @@ -302,7 +294,7 @@ test('empty value in batch', function (t) { }) test('empty buffer key in batch', function (t) { - var db = new MemDOWN() + var db = memdown() db.open(function (err) { t.error(err, 'opens correctly') @@ -319,7 +311,7 @@ test('empty buffer key in batch', function (t) { }) test('buffer key in batch', function (t) { - var db = new MemDOWN() + var db = memdown() db.open(function (err) { t.error(err, 'opens correctly') @@ -343,7 +335,7 @@ test('buffer key in batch', function (t) { test('put multiple times', function (t) { t.plan(5) - var db = new MemDOWN() + var db = memdown() db.open(function (err) { t.error(err, 'opens correctly') @@ -363,10 +355,10 @@ test('put multiple times', function (t) { }) }) -test('number keys', function (t) { +test.skip('number keys', function (t) { t.plan(4) - var db = new MemDOWN() + var db = memdown() var numbers = [2, 12] var buffers = numbers.map(stringBuffer) @@ -387,10 +379,10 @@ test('number keys', function (t) { }) }) -test('date keys', function (t) { +test.skip('date keys', function (t) { t.plan(4) - var db = new MemDOWN() + var db = memdown() var dates = [new Date(0), new Date(1)] var buffers = dates.map(stringBuffer) @@ -414,7 +406,7 @@ test('date keys', function (t) { test('object value', function (t) { t.plan(2) - var db = new MemDOWN() + var db = memdown() var obj = {} db.open(noop) From 2e1caf5aeb923115b1d66c23c72abc83c7218b32 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sun, 20 Jan 2019 10:13:55 +0100 Subject: [PATCH 3/9] Use level-concat-iterator and testCommon.factory() in custom tests --- package.json | 1 + test.js | 57 ++++++++++++++++++++++++++-------------------------- 2 files changed, 30 insertions(+), 28 deletions(-) diff --git a/package.json b/package.json index 46d9094..23cb0aa 100644 --- a/package.json +++ b/package.json @@ -41,6 +41,7 @@ "dependency-check": "^3.3.0", "hallmark": "^0.1.0", "level-community": "^3.0.0", + "level-concat-iterator": "^2.0.0", "nyc": "^13.2.0", "rimraf": "^2.6.2", "standard": "^12.0.0", diff --git a/test.js b/test.js index 0436d33..e531739 100644 --- a/test.js +++ b/test.js @@ -1,5 +1,6 @@ var test = require('tape') var suite = require('abstract-leveldown/test') +var concat = require('level-concat-iterator') var memdown = require('.').default var ltgt = require('ltgt') var Buffer = require('safe-buffer').Buffer @@ -21,8 +22,8 @@ var testCommon = suite.common({ suite(testCommon) // Additional tests for this implementation -test.skip('unsorted entry, sorted iterator', function (t) { - var db = memdown() +test('unsorted entry, sorted iterator', function (t) { + var db = testCommon.factory() db.open(noop) @@ -40,7 +41,7 @@ test.skip('unsorted entry, sorted iterator', function (t) { noop ) - testCommon.collectEntries( + concat( db.iterator({ keyAsBuffer: false, valueAsBuffer: false }), function (err, data) { t.notOk(err, 'no error') @@ -63,7 +64,7 @@ test.skip('unsorted entry, sorted iterator', function (t) { }) test('reading while putting', function (t) { - var db = memdown() + var db = testCommon.factory() db.open(noop) @@ -90,7 +91,7 @@ test('reading while putting', function (t) { }) test('reading while deleting', function (t) { - var db = memdown() + var db = testCommon.factory() db.open(noop) @@ -118,7 +119,7 @@ test('reading while deleting', function (t) { }) test('reverse ranges', function (t) { - var db = memdown() + var db = testCommon.factory() db.open(noop) @@ -141,7 +142,7 @@ test('reverse ranges', function (t) { }) test('delete while iterating', function (t) { - var db = memdown() + var db = testCommon.factory() db.open(function (err) { t.error(err, 'opens correctly') @@ -176,7 +177,7 @@ test('delete while iterating', function (t) { }) test('iterator with byte range', function (t) { - var db = memdown() + var db = testCommon.factory() db.open(function (err) { t.error(err, 'opens correctly') @@ -194,31 +195,31 @@ test('iterator with byte range', function (t) { }) }) -test.skip('iterator does not clone buffers', function (t) { +test('iterator does not clone buffers', function (t) { t.plan(3) - var db = memdown() + var db = testCommon.factory() var buf = Buffer.from('a') db.open(noop) db.put(buf, buf, noop) - testCommon.collectEntries(db.iterator(), function (err, entries) { + concat(db.iterator(), function (err, entries) { t.ifError(err, 'no iterator error') t.ok(entries[0].key === buf, 'key is same buffer') t.ok(entries[0].value === buf, 'value is same buffer') }) }) -test.skip('iterator stringifies buffer input', function (t) { +test('iterator stringifies buffer input', function (t) { t.plan(3) - var db = memdown() + var db = testCommon.factory() db.open(noop) db.put(1, 2, noop) - testCommon.collectEntries(db.iterator(), function (err, entries) { + concat(db.iterator(), function (err, entries) { t.ifError(err, 'no iterator error') t.same(entries[0].key, Buffer.from('1'), 'key is stringified') t.same(entries[0].value, Buffer.from('2'), 'value is stringified') @@ -226,7 +227,7 @@ test.skip('iterator stringifies buffer input', function (t) { }) test('backing rbtree is buffer-aware', function (t) { - var db = memdown() + var db = testCommon.factory() db.open(function (err) { t.error(err, 'opens correctly') @@ -261,7 +262,7 @@ test('backing rbtree is buffer-aware', function (t) { test('empty value in batch', function (t) { t.plan(6) - var db = memdown() + var db = testCommon.factory() db.open(function (err) { t.error(err, 'opens correctly') @@ -294,7 +295,7 @@ test('empty value in batch', function (t) { }) test('empty buffer key in batch', function (t) { - var db = memdown() + var db = testCommon.factory() db.open(function (err) { t.error(err, 'opens correctly') @@ -311,7 +312,7 @@ test('empty buffer key in batch', function (t) { }) test('buffer key in batch', function (t) { - var db = memdown() + var db = testCommon.factory() db.open(function (err) { t.error(err, 'opens correctly') @@ -335,7 +336,7 @@ test('buffer key in batch', function (t) { test('put multiple times', function (t) { t.plan(5) - var db = memdown() + var db = testCommon.factory() db.open(function (err) { t.error(err, 'opens correctly') @@ -355,10 +356,10 @@ test('put multiple times', function (t) { }) }) -test.skip('number keys', function (t) { +test('number keys', function (t) { t.plan(4) - var db = memdown() + var db = testCommon.factory() var numbers = [2, 12] var buffers = numbers.map(stringBuffer) @@ -368,21 +369,21 @@ test.skip('number keys', function (t) { var iterator1 = db.iterator({ keyAsBuffer: false }) var iterator2 = db.iterator({ keyAsBuffer: true }) - testCommon.collectEntries(iterator1, function (err, entries) { + concat(iterator1, function (err, entries) { t.ifError(err, 'no iterator error') t.same(entries.map(getKey), numbers, 'sorts naturally') }) - testCommon.collectEntries(iterator2, function (err, entries) { + concat(iterator2, function (err, entries) { t.ifError(err, 'no iterator error') t.same(entries.map(getKey), buffers, 'buffer input is stringified') }) }) -test.skip('date keys', function (t) { +test('date keys', function (t) { t.plan(4) - var db = memdown() + var db = testCommon.factory() var dates = [new Date(0), new Date(1)] var buffers = dates.map(stringBuffer) @@ -392,12 +393,12 @@ test.skip('date keys', function (t) { var iterator = db.iterator({ keyAsBuffer: false }) var iterator2 = db.iterator({ keyAsBuffer: true }) - testCommon.collectEntries(iterator, function (err, entries) { + concat(iterator, function (err, entries) { t.ifError(err, 'no iterator error') t.same(entries.map(getKey), dates, 'sorts naturally') }) - testCommon.collectEntries(iterator2, function (err, entries) { + concat(iterator2, function (err, entries) { t.ifError(err, 'no iterator error') t.same(entries.map(getKey), buffers, 'buffer input is stringified') }) @@ -406,7 +407,7 @@ test.skip('date keys', function (t) { test('object value', function (t) { t.plan(2) - var db = memdown() + var db = testCommon.factory() var obj = {} db.open(noop) From 552f501e7151f002921ac218c8dafb600982e245 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sun, 20 Jan 2019 10:18:49 +0100 Subject: [PATCH 4/9] Remove dummy location from abstract-leveldown constructor call --- memdown.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/memdown.js b/memdown.js index 21dd241..b62a64b 100644 --- a/memdown.js +++ b/memdown.js @@ -118,7 +118,7 @@ MemIterator.prototype._test = function () { function MemDOWN () { if (!(this instanceof MemDOWN)) return new MemDOWN() - AbstractLevelDOWN.call(this, '') + AbstractLevelDOWN.call(this) this._store = createRBT(ltgt.compare) } From f9ed6958f84e3572542fcf72b9ab45b9e165e74a Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Sun, 20 Jan 2019 10:19:29 +0100 Subject: [PATCH 5/9] Remove now irrelevant serialization of nullish values --- memdown.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/memdown.js b/memdown.js index b62a64b..2848b2a 100644 --- a/memdown.js +++ b/memdown.js @@ -137,7 +137,7 @@ MemDOWN.prototype._serializeKey = function (key) { } MemDOWN.prototype._serializeValue = function (value) { - return value == null ? '' : value + return value } MemDOWN.prototype._put = function (key, value, options, callback) { From ee0f1336328301ddbb7b75a170d58c747e2ea9af Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Fri, 29 Mar 2019 13:38:41 +0100 Subject: [PATCH 6/9] Don't use falsy or undefined as not-defined signal --- memdown.js | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/memdown.js b/memdown.js index 2848b2a..b182fc1 100644 --- a/memdown.js +++ b/memdown.js @@ -8,6 +8,7 @@ var Buffer = require('safe-buffer').Buffer // In Node, use global.setImmediate. In the browser, use a consistent // microtask library to give consistent microtask experience to all browsers var setImmediate = require('./immediate') +var NONE = {} function gt (value) { return ltgt.compare(value, this._upperBound) > 0 @@ -41,10 +42,10 @@ function MemIterator (db, options) { if (!this._reverse) { this._incr = 'next' - this._lowerBound = ltgt.lowerBound(options) - this._upperBound = ltgt.upperBound(options) + this._lowerBound = ltgt.lowerBound(options, NONE) + this._upperBound = ltgt.upperBound(options, NONE) - if (typeof this._lowerBound === 'undefined') { + if (this._lowerBound === NONE) { this._tree = tree.begin } else if (ltgt.lowerBoundInclusive(options)) { this._tree = tree.ge(this._lowerBound) @@ -52,7 +53,7 @@ function MemIterator (db, options) { this._tree = tree.gt(this._lowerBound) } - if (this._upperBound) { + if (this._upperBound !== NONE) { if (ltgt.upperBoundInclusive(options)) { this._test = lte } else { @@ -61,10 +62,10 @@ function MemIterator (db, options) { } } else { this._incr = 'prev' - this._lowerBound = ltgt.upperBound(options) - this._upperBound = ltgt.lowerBound(options) + this._lowerBound = ltgt.upperBound(options, NONE) + this._upperBound = ltgt.lowerBound(options, NONE) - if (typeof this._lowerBound === 'undefined') { + if (this._lowerBound === NONE) { this._tree = tree.end } else if (ltgt.upperBoundInclusive(options)) { this._tree = tree.le(this._lowerBound) @@ -72,7 +73,7 @@ function MemIterator (db, options) { this._tree = tree.lt(this._lowerBound) } - if (this._upperBound) { + if (this._upperBound !== NONE) { if (ltgt.lowerBoundInclusive(options)) { this._test = gte } else { From 04e32ffc58ca5979d14df4eb85932f3bdb9e5582 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Fri, 29 Mar 2019 13:39:16 +0100 Subject: [PATCH 7/9] Test negative and positive Infinity as keys --- test.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test.js b/test.js index e531739..770ce16 100644 --- a/test.js +++ b/test.js @@ -360,7 +360,7 @@ test('number keys', function (t) { t.plan(4) var db = testCommon.factory() - var numbers = [2, 12] + var numbers = [-Infinity, 0, 2, 12, +Infinity] var buffers = numbers.map(stringBuffer) db.open(noop) From fdb52a794b63f28c442207e8407b2deb4160a61a Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Fri, 29 Mar 2019 13:43:15 +0100 Subject: [PATCH 8/9] Document that nullish values are now also rejected --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 7bdeafc..05fd080 100644 --- a/README.md +++ b/README.md @@ -42,7 +42,7 @@ Your data is discarded when the process ends or you release a reference to the s ## Data types -Unlike [`leveldown`], `memdown` does not stringify keys or values. This means that in addition to Buffers, you can store any JS type without the need for [`encoding-down`]. For keys for example, you could use Buffers or strings, which sort lexicographically, or numbers, even Dates, which sort naturally. The only exceptions are `null` and `undefined`. Keys of that type are rejected; values of that type are converted to empty strings. +Unlike [`leveldown`], `memdown` does not stringify keys or values. This means that in addition to Buffers, you can store any JS type without the need for [`encoding-down`]. For keys for example, you could use Buffers or strings, which sort lexicographically, or numbers, even Dates, which sort naturally. The only exceptions are `null` and `undefined`. Keys and values of that type are rejected. ```js const db = levelup(memdown()) From 155ca81f45ff6ced03dc2ac4b967005331f1b908 Mon Sep 17 00:00:00 2001 From: Vincent Weevers Date: Fri, 29 Mar 2019 13:54:19 +0100 Subject: [PATCH 9/9] Remove rimraf devDependency (closes #114) --- package.json | 1 - 1 file changed, 1 deletion(-) diff --git a/package.json b/package.json index 23cb0aa..36ca0c5 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,6 @@ "level-community": "^3.0.0", "level-concat-iterator": "^2.0.0", "nyc": "^13.2.0", - "rimraf": "^2.6.2", "standard": "^12.0.0", "tape": "^4.8.0" },