Repository navigation
Description
This is just an idea at this point, briefly discussed offline; we're not committing to anything. The premise: make any abstract-leveldown implementation a standalone, ready-to-go database.
Refactorings in the past years have increased modularity. It has allowed us to clean up various internals. That said, now that we have, there are downsides to the current architecture, with its many layers:
- Adding custom behavior to e.g.
levelmeans having to peel off layers first, then add them back (most notably insubleveldown- that code is gnarly) - The layers share API surface with treacherously subtle differences (e.g.
leveldownby itself returns Buffers by default,level(up)returns strings by default). - There are 4 forms of "encoding" now:
encoding-down, serialization,asBuffer, and whatever the underlying storage does (e.g. IDB returning a Buffer as Uint8Array). Yet for anabstract-leveldownimplementation there's no builtin primitive to decode/deserialize data. - Breaking changes in one layer typically bubble up, leading to what we call "the release dance". Prior to that, canary testing is often required because we can't foresee everything.
- A rabbit hole of documentation and changelogs (
levellinks toleveluplinks toencoding-downlinks tolevel-codecgives an example aboutleveldownlinks tolevel- you get the point) - Double allocation of callback functions, options objects, etc.
- No builtin mechanism for asynchronous hooks (this could be achieved as another
abstract-leveldownlayer, but that doesn't make it available to levelup per se) (related: plugin extension points: merge level-hooks / level-sublevel #44). - Implementing manifests (Requirements for manifests #42) is hard.
Back to the idea: there are many open questions. Making a POC is probably the best way forward. To be clear: I don't want it to be a big batteries-included database. I think what we need are simpler primitives to enable composing (and maintaining!) such a database. Some "batteries" could be worth including, if they provide a foundation for userland modularity.
We have been recommending people to use levelup, and more so, level and friends, which is a clear indication that much of the functionality belongs in a single core component. Or to put it in other words, a single shell (the public API of abstract-leveldown) around a nut (the private API of abstract-leveldown).

Activity
ralphtheninja commentedon Dec 30, 2018
I'm all for simplifying. There's also an issue of performance. Maybe we could benchmark the hell out of
leveland compare with a benchmark done on a POC.abstract-leveldown?bytewiseandcharwise).Love the picture btw. This style is really nice. We should reuse it for documentation, blog post etc. How did you make it?
vweevers commentedon Dec 31, 2018
Photoshop. I wanted to try its 3D features. And I'm never gonna do it again, lol. Took 10 crashes and retries and then 20 minutes waiting time just to render some damn plastic material 😄
vweevers commentedon Jan 1, 2019
vweevers commentedon Mar 30, 2019
I say yes. The first version can and should be a drop-in replacement. To keep all the history and get regression tests for free.
Rough roadmap
abstract-leveldownandlevelupHaveabstract-leveldownuselevel-errors(semver-major if any error messages need to change)codeproperty to errors errors#39db.isClosed()andisOpen()in tests (semver-patch) (relevant test)nextTicktolevelup(see TODO comment insubleveldown).statustolevelupabstract-leveldown, same aslevelupPerform type checks in same order (e.g. check key before callback) (semver-minor or semver-major, TBD)abstract-leveldownabstract-leveldownanEventEmitterlevelupopen()options to constructor (semver-minor, by temporarily supporting options in both places)abstract-leveldowntoabstract-levelSkipdeferred-leveldowninlevelupif manifest indicates that db supports deferredOpendeferred-leveldowninmaybeError()thatdb.statusmay beopeninglevelupdeferred-leveldown#90The fork provides a starting point for later breaking changes, and a turning point for dependents: when they make the switch from
abstract-leveldowntoabstract-level, you no longer needlevelup. Up until this pointabstract-levelis a drop-in replacement forabstract-leveldownthat is also still safe to be wrapped bylevelup- yet behaves the same aslevelupif you don't. This is very optimistic, mind you. I'm sure there will be stumbling blocks along the way that may force us to reconsider this approach.Let's make encodings "phase 2".
vweevers commentedon Apr 6, 2019
vweevers commentedon Apr 28, 2019
vweevers commentedon Apr 28, 2019
vweevers commentedon Apr 28, 2019
💡 If
abstract-leveldownimplementations are encoding-aware thenleveldowncould implement the IndexedDB comparator (which sorts almost the same asbytewise/charwise) natively.[-]Merge level(up) functionality into abstract-leveldown[/-][+]Merge levelup into abstract-leveldown[/+]vweevers commentedon Jan 2, 2021
Calling this
abstract-levelgoing forward. It ain't down, it ain't up, it's level.vweevers commentedon Jan 2, 2021
I think it will be easier to do this the right way from the get-go. I want to support encodings out of the box, replacing both
_serialize()(which is just another encoding API with a different name) andasBuffer(which in a way expresses a relation between codecs, for example thatjsonis alsoutf8). I'm working out the details.Don't wrap existing errors
Don't wrap existing errors (#37)
Make opening & closing idempotent and add events
Temporarily relax error tests for `abstract-leveldown`
vweevers commentedon Nov 9, 2021
This thread got messy with my frequent edits and inline task lists. Continuing at https://github.com/Level/abstract-level.
Make opening & closing idempotent and add events