Security News
The Dark Side of Open Source
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
level-supports
Advanced tools
Changelog
Readme
Create a manifest describing the abilities of an abstract-level
database. No longer compatible with levelup
or abstract-leveldown
since version 3.0.0.
const { supports } = require('level-supports')
db.supports = supports({
permanence: false,
encodings: {
utf8: true
}
})
Receivers of the db can then use it like so:
if (!db.supports.permanence) {
throw new Error('Persistent storage is required')
}
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.
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().snapshots // false
supports({ snapshots: true }).snapshots // true
supports({ snapshots: {} }).snapshots // {}
supports({ snapshots: 1 }, { snapshots: 2 }).snapshots // 2
For consumers of the manifest this means they should check support like so:
if (db.supports.snapshots)
Rather than:
if (db.supports.snapshots === 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.
snapshots
(boolean)Does the database have snapshot guarantees? Meaning that reads are unaffected by simultaneous writes. For example, an iterator should read from a snapshot of the database, created at the time db.iterator()
was called. This means the iterator will not see the data of simultaneous write operations.
Must be false
if any of the following is true:
Module | Snapshot guarantee |
---|---|
classic-level | ✅ |
memory-level | ✅ |
browser-level | ❌ |
rocks-level | ✅ |
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 (or environment) exit? Typically true. False for memory-level
and memdown
.
seek
(boolean)Do iterators support seek(..)
?
Module | Support |
---|---|
abstract-level | ✅ 1.0.0 |
classic-level | ✅ 1.0.0 |
memory-level | ✅ 1.0.0 |
browser-level | ✅ 1.0.0 |
rocks-level | ✅ 1.0.0 |
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 | ✅ 8.0.0 |
level-mem | ✅ 4.0.0 |
level-rocksdb | ✅ 1.0.0 |
subleveldown | ✅ 4.1.0 |
multileveldown | ❌ |
level-party | ❌ |
clear
(boolean)Does the database support db.clear()
? Always true since abstract-level@1
.
See also Level/community#79.
Module | Support | Optimized |
---|---|---|
abstract-level and dependents | ✅ 1.0.0 | ✅ 1.0.0 |
abstract-leveldown | ✅ 6.1.0 | n/a |
leveldown | ✅ 5.2.0 | ✅ 6.0.3 |
rocksdb | ✅ 4.1.0 | ✅ 5.2.0 |
memdown | ✅ 5.0.0 | ✅ 6.1.1 |
level-js | ✅ 5.0.0 | ✅ 5.0.0 |
encoding-down | ✅ 6.2.0 | n/a |
deferred-leveldown | ✅ 5.2.0 | n/a |
levelup | ✅ 4.2.0 | n/a |
level-packager | ✅ 5.0.3 | n/a |
level | ✅ 6.0.0 | ✅ 7.0.1 |
level-mem | ✅ 5.0.1 | ✅ 6.0.1 |
level-rocksdb | ✅ 5.0.0 | ✅ 5.0.0 |
subleveldown | ✅ 4.2.1 | ✅ 4.2.1 |
multileveldown | ✅ 5.0.0 | ✅ 5.0.0 |
level-party | ✅ 5.1.0 | ✅ 5.1.0 |
status
(boolean)Does the database have a status
property? Always true since abstract-level@1
.
deferredOpen
(boolean)Can operations like db.put()
be called without explicitly opening the db? Like so:
const db = new Level()
await db.put('key', 'value')
Always true since abstract-level@1
.
createIfMissing
, errorIfExists
(boolean)Does db.open()
support these options?
Module | Support |
---|---|
classic-level | ✅ |
rocks-level | ✅ |
memory-level | ❌ |
browser-level | ❌ |
leveldown | ✅ |
rocksdb | ✅ |
memdown | ❌ |
level-js | ❌ |
promises
(boolean)Do all database 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')
Always true since abstract-level@1
.
Module | Support |
---|---|
abstract-level and dependents | ✅ |
abstract-leveldown and dependents | ❌ (except iterators) |
levelup | ✅ |
level-packager | ✅ |
level | ✅ |
level-mem | ✅ |
level-rocksdb | ✅ |
subleveldown | ✅ |
multileveldown | ✅ |
level-party | ✅ |
events
(object)Which events does the database emit, as indicated by nested properties? For example:
if (db.supports.events.put) {
db.on('put', listener)
}
streams
(boolean)Does database have the methods createReadStream
, createKeyStream
and createValueStream
, following the API documented in levelup
? For abstract-level
databases, a standalone module called level-read-stream
is available.
Module | Support |
---|---|
abstract-level and dependents | ❌ |
abstract-leveldown and dependents | ❌ |
levelup | ✅ |
level-packager | ✅ |
level | ✅ |
level-mem | ✅ |
level-rocksdb | ✅ |
subleveldown | ✅ |
multileveldown | ✅ |
level-party | ✅ |
encodings
(object)Which encodings (by name) does the database support, as indicated by nested properties? For example:
{ utf8: true, json: true }
As the encodings
property cannot be false (anymore, since level-supports
v3.0.0) it implies that the database supports keyEncoding
and valueEncoding
options on all relevant methods, uses a default encoding of utf8 and that hence all of its read operations return strings rather than buffers by default.
This matrix just indicates general support of encodings as a feature, not that the listed modules support the encodings
property exactly as described above, which only works on abstract-level
databases.
Module | Support |
---|---|
abstract-level (and dependents) | ✅ |
abstract-leveldown (and dependents) | ❌ |
encoding-down | ✅ |
levelup | ✅ |
level-packager | ✅ |
level | ✅ |
level-mem | ✅ |
level-rocksdb | ✅ |
subleveldown | ✅ |
multileveldown | ✅ |
level-party | ✅ |
This matrix lists which encodings are supported as indicated by e.g. db.supports.encodings.utf8
. Encodings that encode to another (like how 'json'
encodes to 'utf8'
) are excluded here, though they are present in db.supports.encodings
.
Module | 'utf8' | 'buffer' | 'view' |
---|---|---|---|
classic-level | ✅ | ✅ | ✅ 1 |
memory-level | ✅ 2 | ✅ 2 | ✅ 2 |
browser-level | ✅ 1 | ✅ 1 | ✅ |
rocks-level | ✅ | ✅ | ✅ 1 |
level@8 | ✅ 3 | ✅ 3 | ✅ 3 |
storeEncoding
option.getMany
(boolean)Does the database support db.getMany()
? Always true since abstract-level@1
.
Module | Support |
---|---|
abstract-level and dependents | ✅ 1.0.0 |
abstract-leveldown | ✅ 7.2.0 |
leveldown | ✅ 6.1.0 |
rocksdb | ✅ 5.2.0 |
memdown | ✅ |
level-js | ✅ 6.1.0 |
encoding-down | ✅ 7.1.0 |
deferred-leveldown | ✅ 7.0.0 |
levelup | ✅ 5.1.0 |
level | ✅ 7.0.1 |
level-mem | ✅ 6.0.1 |
level-rocksdb | ✅ 5.0.0 |
subleveldown | ✅ 6.0.0 |
multileveldown | ✅ 5.0.0 |
level-party | ✅ 5.1.0 |
keyIterator
(boolean)Does the database have a keys([options])
method that returns a key iterator? Always true since abstract-level@1
.
valueIterator
(boolean)Does the database have a values([options])
method that returns a key iterator? Always true since abstract-level@1
.
iteratorNextv
(boolean)Do iterators have a nextv(size[, options][, callback])
method? Always true since abstract-level@1
.
iteratorAll
(boolean)Do iterators have a all([options][, callback])
method? Always true since abstract-level@1
.
additionalMethods
(object)Declares support of additional methods, that are not part of the abstract-level
interface. In the form of:
{
foo: true,
bar: true
}
Which says the db has two methods, foo
and bar
. 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).
With npm do:
npm install level-supports
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.
Support us with a monthly donation on Open Collective and help us continue our work.
FAQs
Create a manifest describing the abilities of an abstract-level database
The npm package level-supports receives a total of 565,685 weekly downloads. As such, level-supports popularity was classified as popular.
We found that level-supports demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
At Node Congress, Socket CEO Feross Aboukhadijeh uncovers the darker aspects of open source, where applications that rely heavily on third-party dependencies can be exploited in supply chain attacks.
Research
Security News
The Socket Research team found this npm package includes code for collecting sensitive developer information, including your operating system username, Git username, and Git email.
Security News
OpenJS is warning of social engineering takeovers targeting open source projects after receiving a credible attempt on the foundation.