Skip to content
This repository has been archived by the owner on Dec 2, 2024. It is now read-only.

Upgrade to latest Level modules #15

Merged
merged 3 commits into from
Oct 25, 2019
Merged

Upgrade to latest Level modules #15

merged 3 commits into from
Oct 25, 2019

Conversation

vweevers
Copy link
Member

@vweevers vweevers commented Sep 8, 2019

Semver-major. Goes hand-in-hand with a level-party PR which I'll open shortly. Achieves the following:

  • Upgrade to latest Level modules
    • Mainly to support node 10, 12 and future
    • Also includes latest memdown, which now internally stores keys+values as Buffers, making it more reliable as a leveldown replacement
  • Support an input db that isn't level (may or may not have levelup, encoding-down, deferred-leveldown layers, and may have additional layers)
  • Expose all methods that level-party needs on the multileveldown client, so that level-party doesn't have to reach down (e.g. db.db)
  • Support subleveldown on level-party
  • Support subleveldown on multileveldown client (i.e. for client-side sublevels)
  • Support multileveldown server on subleveldown (i.e. to expose only a sublevel to client)

abstract.AbstractLevelDOWN.call(this, path)
function Multilevel (opts) {
if (!(this instanceof Multilevel)) return new Multilevel(opts)
abstract.AbstractLevelDOWN.call(this)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

abstract-leveldown no longer needs a location (aka path here).

@@ -38,6 +40,8 @@ function Multilevel (path, opts) {

util.inherits(Multilevel, abstract.AbstractLevelDOWN)

Multilevel.prototype.type = 'multileveldown'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is for compatibility with reachdown, which I also intend to start using in subleveldown, level-test and more.

}
}

Multilevel.prototype.forward = function (down) {
this._db = down
this._db = reachdown(down, matchdown, false)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This peels off levelup, deferred-leveldown and encoding-down.


Multilevel.prototype._serializeValue = function (value) {
return Buffer.isBuffer(value) ? value : Buffer.from(String(value))
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This ensures we're only working with buffers internally.

Multilevel.prototype._get = function (key, opts, cb) {
if (this._db) return this._db._get(key, opts, cb)

var req = {
tag: 0,
id: 0,
key: key,
valueEncoding: opts.valueEncoding || (opts.asBuffer === false ? 'utf-8' : 'binary'),
valueAsBuffer: opts.asBuffer,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We no longer have access to key/ValueEncoding options here, but we don't need it. We only have to care about returning a buffer or string (which at a higher level, is dictated by encoding-down and the user's choice of encoding).

@@ -29,7 +32,7 @@ module.exports = function (db, opts) {
return stream

function ready () {
var down = db.db
var down = reachdown(db, matchdown, false)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This peels off levelup, deferred-leveldown and encoding-down.

}

this._iterator = down.iterator(req.options)
this._iterator = down.iterator(cleanRangeOptions(req.options))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Because null and undefined are valid range options in latest abstract-leveldown, we must strip them from the options object.

@julien-f
Copy link

@vweevers Any chance of seeing this and level-party merged?

Do you think we should do a proper fork?

@vweevers
Copy link
Member Author

We can move these modules to Level if @mafintosh is cool with that.

@julien-f
Copy link

Would be really nice, I'm currently stuck on Node 8 because I'm using level-party.

@mafintosh
Copy link
Member

I’m very cool with that!

@vweevers
Copy link
Member Author

Thanks @mafintosh! Do we need @substack for moving level-party?

@vweevers vweevers added the semver-major Changes that break backward compatibility label Oct 23, 2019
@vweevers vweevers merged commit cfaa4c7 into Level:master Oct 25, 2019
@vweevers vweevers deleted the upgrade branch October 25, 2019 18:52
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
semver-major Changes that break backward compatibility
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants