Skip to content

Commit

Permalink
remove defined behavior for nullish targets
Browse files Browse the repository at this point in the history
By targets I mean range options as well as seek targets.

Previously, nullish range options were ignored and `seek(null)`
and `seek(undefined)` would throw an error. Now they translate to
`String(null)` and `String(undefined)`. This means `{ gt: null }`
and `{ gt: undefined }` are *not* the same as `{}`.

This change makes it explicit that leveldown only supports buffers
and strings. Nullish targets do have a meaning in the ecosystem;
that meaning should be given at a higher level like encoding-down.

In other words, it isn't leveldown's concern anymore.
  • Loading branch information
vweevers committed Sep 22, 2018
1 parent 9be66ac commit f267647
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 7 deletions.
11 changes: 5 additions & 6 deletions leveldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@ LevelDOWN.prototype._close = function (callback) {
this.binding.close(callback)
}

LevelDOWN.prototype._serializeKey =
LevelDOWN.prototype._serializeValue = function (datum) {
// This is only needed for range options. We must ignore nullish
// range options and already ignore empty range options in C++.
if (datum == null) return ''
LevelDOWN.prototype._serializeKey = function (key) {
return Buffer.isBuffer(key) ? key : String(key)
}

return Buffer.isBuffer(datum) ? datum : String(datum)
LevelDOWN.prototype._serializeValue = function (value) {
return Buffer.isBuffer(value) ? value : String(value)
}

LevelDOWN.prototype._put = function (key, value, options, callback) {
Expand Down
2 changes: 1 addition & 1 deletion test/iterator-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ const lexi = require('lexicographic-integer')
const util = require('util')

make('iterator#seek throws if target is empty', function (db, t, done) {
var targets = [null, undefined, '', Buffer.alloc(0), []]
var targets = ['', Buffer.alloc(0), []]
var pending = targets.length

targets.forEach(function (target) {
Expand Down

0 comments on commit f267647

Please sign in to comment.