You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
Björn b963b3396c
init
5 years ago
..
test init 5 years ago
CHANGELOG.md init 5 years ago
CONTRIBUTORS.md init 5 years ago
LICENSE.md init 5 years ago
README.md init 5 years ago
index.js init 5 years ago
package.json init 5 years ago

README.md

level-supports

Create a manifest describing the abilities of a levelup or abstract-leveldown db.

level badge npm Node version Travis Coverage Status JavaScript Style Guide Backers on Open Collective Sponsors on Open Collective

Usage

const supports = require('level-supports')

db.supports = supports({
  bufferKeys: true,
  additionalMethods: {
    approximateSize: true
  }
})

Receivers of the db can then use it like so:

if (!db.supports.permanence) {
  throw new Error('Persistent storage is required')
}

if (db.supports.bufferKeys && db.supports.promises) {
  await db.put(Buffer.from('key'), 'value')
}

API

manifest = supports([manifest, ..])

Given zero or more manifest objects, returns a merged and enriched manifest object that has:

  • Truthy properties for each of the features listed below
  • An additionalMethods object

For future extensibility, the properties are truthy rather than strictly typed booleans. Falsy or absent properties are converted to false, other values are allowed:

supports().streams // false
supports({ streams: true }).streams // true
supports({ streams: {} }).streams // {}
supports({ streams: 1 }, { streams: 2 }).streams // 2

For consumers of the manifest this means they should check support like so:

if (db.supports.streams)

Rather than:

if (db.supports.streams === true)

Note: the manifest describes high-level features that typically encompass multiple methods of a db. It is currently not a goal to describe a full API, or versions of it.

Features

bufferKeys (boolean)

Does the db support Buffer keys? May depend on runtime environment as well. Does not include support of other binary types like typed arrays (which is why this is called bufferKeys rather than binaryKeys).

snapshots (boolean)

Does the db have snapshot guarantees (meaning that reads are unaffected by simultaneous writes)? Must be false if any of the following is true:

  • Reads don't operate on a snapshot
  • Snapshots are created asynchronously.

permanence (boolean)

Does data survive after process exit? Is false for e.g. memdown, typically true.

seek (boolean)

Does db.iterator() support seek(..)?

clear (boolean)

Does db support db.clear(..)? For an overview, see Level/community#79.

status (boolean)

Does db have a status property? Currently available on abstract-leveldown implementations, but not levelup.

deferredOpen (boolean)

Can operations like db.put() be called without explicitly opening the db? Like so:

var db = level()
db.put('key', 'value', callback)

Rather than:

var db = level()

db.open(function (err) {
  if (err) throw err
  db.put('key', 'value', callback)
})

TBD: whether this also includes methods like isOpen() and isClosed().

openCallback (boolean)

Does the db constructor take a callback?

var db = level(.., callback)

To the same effect as:

var db = level()
db.open(.., callback)

createIfMissing, errorIfExists (boolean)

Does db.open(options, ..) support these (leveldown) options?

promises (boolean)

Do all db methods (that don't otherwise have a return value) support promises, in addition to callbacks? Such that, when a callback argument is omitted, a promise is returned:

db.put('key', 'value', callback)
await db.put('key', 'value')

Note: iterators are currently exonerated because they, at the time of writing, don't support promises anywhere.

streams (boolean)

Does db have the methods createReadStream, createKeyStream and createValueStream, following the API currently documented in levelup?

encodings (boolean)

Do all relevant db methods take keyEncoding and valueEncoding options?

TBD: what this means for *asBuffer options.

additionalMethods (object)

In the form of:

{
  foo: true,
  bar: true
}

Which says the db has two methods, foo and bar, that are not part of the abstract-leveldown interface. It might be used like so:

if (db.supports.additionalMethods.foo) {
  db.foo()
}

For future extensibility, the properties of additionalMethods should be taken as truthy rather than strictly typed booleans. We may add additional metadata (see #1).

Install

With npm do:

npm install level-supports

Contributing

Level/supports is an OPEN Open Source Project. This means that:

Individuals making significant and valuable contributions are given commit-access to the project to contribute as they see fit. This project is more like an open wiki than a standard guarded open source project.

See the Contribution Guide for more details.

Donate

To sustain Level and its activities, become a backer or sponsor on Open Collective. Your logo or avatar will be displayed on our 28+ GitHub repositories and npm packages. 💖

Backers

Open Collective backers

Sponsors

Open Collective sponsors

License

MIT © 2019-present Contributors.