Socket
Socket
Sign inDemoInstall

level-supports

Package Overview
Dependencies
Maintainers
1
Versions
11
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

level-supports

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


Version published
Weekly downloads
544K
decreased by-5.92%
Maintainers
1
Weekly downloads
 
Created
Source

level-supports

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

level badge npm Node version Test Coverage Standard Common Changelog Donate

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).

Support matrix
ModuleSupport
abstract-leveldown
leveldown
rocksdb
memdown
level-js
encoding-down
deferred-leveldown
levelup
level-packager
level
level-mem
level-rocksdb
subleveldown
multileveldown
level-party

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.
Support matrix
ModuleSnapshot guarantee
abstract-leveldown
leveldown
rocksdb
memdown
level-js✅ (by buffering)
encoding-down
deferred-leveldown
levelup
level-packager
level
level-mem
level-rocksdb
subleveldown
multileveldown✅ (unless retry is true)
level-party❌ (unless retry is false)

permanence (boolean)

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

seek (boolean)

Do iterators support seek(..)?

Support matrix
ModuleSupport
abstract-leveldown✅ 6.0.0
leveldown✅ 1.2.0
rocksdb✅ 1.0.0
memdown✅ 4.1.0
level-js
encoding-down✅ 6.1.0
deferred-leveldown✅ 5.1.0
levelup✅ n/a
level-packager✅ n/a
level❌ (level-js)
level-mem✅ 4.0.0
level-rocksdb✅ 1.0.0
subleveldown✅ 4.1.0
multileveldown
level-party
clear (boolean)

Does db support db.clear(..)?

Support matrix

See also Level/community#79.

ModuleSupportOptimized
abstract-leveldown✅ 6.1.0n/a
leveldown✅ 5.2.0
rocksdb✅ 4.1.0
memdown✅ 5.0.0
level-js✅ 5.0.0✅ 5.0.0
encoding-down✅ 6.2.0n/a
deferred-leveldown✅ 5.2.0n/a
levelup✅ 4.2.0n/a
level-packager✅ 5.0.3n/a
level✅ 6.0.0❌ (leveldown)
level-mem✅ 5.0.1❌ (memdown)
level-rocksdb✅ 5.0.0❌ (rocksdb)
subleveldown✅ 4.2.1n/a
multileveldownn/a
level-partyn/a

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 options?

Support matrix
ModuleSupport
leveldown
rocksdb
memdown
level-js

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')
Support matrix
ModuleSupport
abstract-leveldown❌ (except iterators)
leveldown❌ (except iterators)
rocksdb❌ (except iterators)
memdown❌ (except iterators)
level-js❌ (except iterators)
encoding-down❌ (except iterators)
deferred-leveldown❌ (except iterators)
levelup
level-packager
level
level-mem
level-rocksdb
subleveldown
multileveldown
level-party

streams (boolean)

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

Support matrix
ModuleSupport
abstract-leveldown
leveldown
rocksdb
memdown
level-js
encoding-down
deferred-leveldown
levelup
level-packager
level
level-mem
level-rocksdb
subleveldown
multileveldown
level-party

encodings (boolean)

Do all relevant db methods take keyEncoding and valueEncoding options?

TBD: what this means for *asBuffer options.

Support matrix
ModuleSupport
abstract-leveldown
leveldown
rocksdb
memdown
level-js
encoding-down
deferred-leveldown
levelup
level-packager
level
level-mem
level-rocksdb
subleveldown
multileveldown
level-party

getMany (boolean)

Does the db have a getMany(keys[, options][, callback]) method?

At the time of writing this is a new feature, subject to change, zero modules support it.

keyIterator (boolean)

Does the db have a keys([options]) method that returns a key iterator? Also implies support of iterator#mode.

At the time of writing this is a new feature, subject to change, zero modules support it.

valueIterator (boolean)

Does the db have a values([options]) method that returns a key iterator? Also implies support of iterator#mode.

At the time of writing this is a new feature, subject to change, zero modules support it.

iteratorNextv (boolean)

Do iterators have a nextv(size[, options][, callback]) method?

At the time of writing this is a new feature, subject to change, zero modules support it.

iteratorAll (boolean)

Do iterators have a all([options][, callback]) method?

At the time of writing this is a new feature, subject to change, zero modules support it.

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

Support us with a monthly donation on Open Collective and help us continue our work.

License

MIT

Keywords

FAQs

Package last updated on 24 Sep 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc