Comparing version 5.1.0 to 5.1.1
# Changelog | ||
## [5.1.1] - 2021-10-02 | ||
### Added | ||
- Document new features ([#727](https://github.com/Level/levelup/issues/727)) ([`e1ecad9`](https://github.com/Level/levelup/commit/e1ecad9)) (Vincent Weevers) | ||
### Fixed | ||
- Expose nextTick for API parity with `abstract-leveldown` ([`7bc86e4`](https://github.com/Level/levelup/commit/7bc86e4)) (Vincent Weevers) | ||
- Set `supports.status` to true ([`e2e2c34`](https://github.com/Level/levelup/commit/e2e2c34)) (Vincent Weevers) | ||
## [5.1.0] - 2021-10-01 | ||
@@ -1154,2 +1165,4 @@ | ||
[5.1.1]: https://github.com/Level/levelup/releases/tag/v5.1.1 | ||
[5.1.0]: https://github.com/Level/levelup/releases/tag/v5.1.0 | ||
@@ -1156,0 +1169,0 @@ |
@@ -23,10 +23,2 @@ 'use strict' | ||
// Possible AbstractLevelDOWN#status values: | ||
// - 'new' - newly created, not opened or closed | ||
// - 'opening' - waiting for the database to be opened, post open() | ||
// - 'open' - successfully opened the database, available for use | ||
// - 'closing' - waiting for the database to be closed, post close() | ||
// - 'closed' - database has been successfully closed, should not be | ||
// used except for another open() operation | ||
function LevelUP (db, options, callback) { | ||
@@ -70,3 +62,3 @@ if (!(this instanceof LevelUP)) { | ||
this.supports = supports(this.db.supports, { | ||
status: false, | ||
status: true, | ||
deferredOpen: true, | ||
@@ -93,3 +85,3 @@ openCallback: true, | ||
// TODO: docs and tests | ||
// TODO: tests | ||
Object.defineProperty(LevelUP.prototype, 'status', { | ||
@@ -102,3 +94,3 @@ enumerable: true, | ||
// TODO: docs and tests | ||
// TODO: tests | ||
LevelUP.prototype.isOperational = function () { | ||
@@ -332,2 +324,5 @@ return this.db.status === 'open' || this.db.status === 'opening' | ||
// Expose nextTick for API parity with abstract-leveldown | ||
LevelUP.prototype._nextTick = nextTick | ||
function maybeError (db, callback) { | ||
@@ -334,0 +329,0 @@ if (!db.isOperational()) { |
{ | ||
"name": "levelup", | ||
"version": "5.1.0", | ||
"version": "5.1.1", | ||
"description": "Fast & simple storage - a Node.js-style LevelDB wrapper", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
156
README.md
@@ -20,3 +20,2 @@ # levelup | ||
- [API](#api) | ||
- [Special Notes](#special-notes) | ||
- [`levelup(db[, options[, callback]])`](#levelupdb-options-callback) | ||
@@ -32,4 +31,4 @@ - [`db.supports`](#dbsupports) | ||
- [`db.batch()` _(chained form)_](#dbbatch-chained-form) | ||
- [`db.isOpen()`](#dbisopen) | ||
- [`db.isClosed()`](#dbisclosed) | ||
- [`db.status`](#dbstatus) | ||
- [`db.isOperational()`](#dbisoperational) | ||
- [`db.createReadStream([options])`](#dbcreatereadstreamoptions) | ||
@@ -40,3 +39,3 @@ - [`db.createKeyStream([options])`](#dbcreatekeystreamoptions) | ||
- [`db.clear([options][, callback])`](#dbclearoptions-callback) | ||
- [What happened to `db.createWriteStream`?](#what-happened-to-dbcreatewritestream) | ||
- [What happened to `db.createWriteStream`?](#what-happened-to-dbcreatewritestream) | ||
- [Promise Support](#promise-support) | ||
@@ -58,3 +57,3 @@ - [Events](#events) | ||
LevelDB stores entries sorted lexicographically by keys. This makes the <a href="#createReadStream">streaming interface</a> of `levelup` - which exposes LevelDB iterators as [Readable Streams](https://nodejs.org/docs/latest/api/stream.html#stream_readable_streams) - a very powerful query mechanism. | ||
LevelDB stores entries sorted lexicographically by keys. This makes the streaming interface of `levelup` - which exposes LevelDB iterators as [Readable Streams](https://nodejs.org/docs/latest/api/stream.html#stream_readable_streams) - a very powerful query mechanism. | ||
@@ -73,3 +72,3 @@ The most common store is [`leveldown`](https://github.com/Level/leveldown/) which provides a pure C++ binding to LevelDB. [Many alternative stores are available](https://github.com/Level/awesome/#stores) such as [`level.js`](https://github.com/Level/level.js) in the browser or [`memdown`](https://github.com/Level/memdown) for an in-memory store. They typically support strings and Buffers for both keys and values. For a richer set of data types you can wrap the store with [`encoding-down`](https://github.com/Level/encoding-down). | ||
**If you are upgrading:** please see [`UPGRADING.md`](UPGRADING.md). | ||
_If you are upgrading: please see [`UPGRADING.md`](UPGRADING.md)._ | ||
@@ -107,25 +106,2 @@ First you need to install `levelup`! No stores are included so you must also install `leveldown` (for example). | ||
- <a href="#ctor"><code><b>levelup()</b></code></a> | ||
- <a href="#supports"><code>db.<b>supports</b></code></a> | ||
- <a href="#open"><code>db.<b>open()</b></code></a> | ||
- <a href="#close"><code>db.<b>close()</b></code></a> | ||
- <a href="#put"><code>db.<b>put()</b></code></a> | ||
- <a href="#get"><code>db.<b>get()</b></code></a> | ||
- <a href="#del"><code>db.<b>del()</b></code></a> | ||
- <a href="#batch"><code>db.<b>batch()</b></code></a> _(array form)_ | ||
- <a href="#batch_chained"><code>db.<b>batch()</b></code></a> _(chained form)_ | ||
- <a href="#isOpen"><code>db.<b>isOpen()</b></code></a> | ||
- <a href="#isClosed"><code>db.<b>isClosed()</b></code></a> | ||
- <a href="#createReadStream"><code>db.<b>createReadStream()</b></code></a> | ||
- <a href="#createKeyStream"><code>db.<b>createKeyStream()</b></code></a> | ||
- <a href="#createValueStream"><code>db.<b>createValueStream()</b></code></a> | ||
- <a href="#iterator"><code>db.<b>iterator()</b></code></a> | ||
- <a href="#clear"><code>db.<b>clear()</b></code></a> | ||
### Special Notes | ||
- <a href="#writeStreams">What happened to <code><b>db.createWriteStream()</b></code></a> | ||
<a name="ctor"></a> | ||
### `levelup(db[, options[, callback]])` | ||
@@ -165,7 +141,5 @@ | ||
<a name="supports"></a> | ||
### `db.supports` | ||
A read-only [manifest](https://github.com/Level/supports). Not [widely supported yet](https://github.com/Level/community/issues/83). Might be used like so: | ||
A read-only [manifest](https://github.com/Level/supports). Might be used like so: | ||
@@ -182,17 +156,11 @@ ```js | ||
<a name="open"></a> | ||
### `db.open([options][, callback])` | ||
Opens the underlying store. In general you should never need to call this method directly as it's automatically called by <a href="#ctor"><code>levelup()</code></a>. | ||
Opens the underlying store. In general you shouldn't need to call this method directly as it's automatically called by [`levelup()`](#levelupdb-options-callback). However, it is possible to reopen the store after it has been closed with [`close()`](#dbclosecallback). | ||
However, it is possible to _reopen_ the store after it has been closed with <a href="#close"><code>close()</code></a>, although this is not generally advised. | ||
If no callback is passed, a promise is returned. | ||
<a name="close"></a> | ||
### `db.close([callback])` | ||
<code>close()</code> closes the underlying store. The callback will receive any error encountered during closing as the first argument. | ||
`close()` closes the underlying store. The callback will receive any error encountered during closing as the first argument. | ||
@@ -203,7 +171,5 @@ You should always clean up your `levelup` instance by calling `close()` when you no longer need it to free up resources. A store cannot be opened by multiple instances of `levelup` simultaneously. | ||
<a name="put"></a> | ||
### `db.put(key, value[, options][, callback])` | ||
<code>put()</code> is the primary method for inserting data into the store. Both `key` and `value` can be of any type as far as `levelup` is concerned. | ||
`put()` is the primary method for inserting data into the store. Both `key` and `value` can be of any type as far as `levelup` is concerned. | ||
@@ -214,4 +180,2 @@ `options` is passed on to the underlying store. | ||
<a name="get"></a> | ||
### `db.get(key[, options][, callback])` | ||
@@ -240,4 +204,2 @@ | ||
<a name="get_many"></a> | ||
### `db.getMany(keys[, options][, callback])` | ||
@@ -251,7 +213,5 @@ | ||
<a name="del"></a> | ||
### `db.del(key[, options][, callback])` | ||
<code>del()</code> is the primary method for removing data from the store. | ||
`del()` is the primary method for removing data from the store. | ||
@@ -269,7 +229,5 @@ ```js | ||
<a name="batch"></a> | ||
### `db.batch(array[, options][, callback])` _(array form)_ | ||
<code>batch()</code> can be used for very fast bulk-write operations (both _put_ and _delete_). The `array` argument should contain a list of operations to be executed sequentially, although as a whole they are performed as an atomic operation inside the underlying store. | ||
`batch()` can be used for very fast bulk-write operations (both _put_ and _delete_). The `array` argument should contain a list of operations to be executed sequentially, although as a whole they are performed as an atomic operation inside the underlying store. | ||
@@ -279,3 +237,3 @@ Each operation is contained in an object having the following properties: `type`, `key`, `value`, where the _type_ is either `'put'` or `'del'`. In the case of `'del'` the `value` property is ignored. Any entries with a `key` of `null` or `undefined` will cause an error to be returned on the `callback` and any `type: 'put'` entry with a `value` of `null` or `undefined` will return an error. | ||
```js | ||
var ops = [ | ||
const ops = [ | ||
{ type: 'del', key: 'father' }, | ||
@@ -298,7 +256,5 @@ { type: 'put', key: 'name', value: 'Yuri Irsenovich Kim' }, | ||
<a name="batch_chained"></a> | ||
### `db.batch()` _(chained form)_ | ||
<code>batch()</code>, when called with no arguments will return a `Batch` object which can be used to build, and eventually commit, an atomic batch operation. Depending on how it's used, it is possible to obtain greater performance when using the chained form of `batch()` over the array form. | ||
`batch()`, when called with no arguments will return a `Batch` object which can be used to build, and eventually commit, an atomic batch operation. Depending on how it's used, it is possible to obtain greater performance when using the chained form of `batch()` over the array form. | ||
@@ -343,26 +299,16 @@ ```js | ||
<a name="isOpen"></a> | ||
### `db.status` | ||
### `db.isOpen()` | ||
A readonly string that is one of: | ||
A `levelup` instance can be in one of the following states: | ||
- `new` - newly created, not opened or closed | ||
- `opening` - waiting for the underlying store to be opened | ||
- `open` - successfully opened the store, available for use | ||
- `closing` - waiting for the store to be closed | ||
- `closed` - store has been successfully closed. | ||
- _"new"_ - newly created, not opened or closed | ||
- _"opening"_ - waiting for the underlying store to be opened | ||
- _"open"_ - successfully opened the store, available for use | ||
- _"closing"_ - waiting for the store to be closed | ||
- _"closed"_ - store has been successfully closed, should not be used | ||
### `db.isOperational()` | ||
`isOpen()` will return `true` only when the state is "open". | ||
Returns `true` if the store accepts operations, which in the case of `levelup` means that `status` is either `opening` or `open`, because it opens itself and queues up operations until opened. | ||
<a name="isClosed"></a> | ||
### `db.isClosed()` | ||
_See <a href="#put"><code>isOpen()</code></a>_ | ||
`isClosed()` will return `true` only when the state is "closing" _or_ "closed", it can be useful for determining if read and write operations are permissible. | ||
<a name="createReadStream"></a> | ||
### `db.createReadStream([options])` | ||
@@ -402,7 +348,5 @@ | ||
<a name="createKeyStream"></a> | ||
### `db.createKeyStream([options])` | ||
Returns a [Readable Stream](https://nodejs.org/docs/latest/api/stream.html#stream_readable_streams) of keys rather than key-value pairs. Use the same options as described for <a href="#createReadStream"><code>createReadStream</code></a> to control the range and direction. | ||
Returns a [Readable Stream](https://nodejs.org/docs/latest/api/stream.html#stream_readable_streams) of keys rather than key-value pairs. Use the same options as described for [`createReadStream()`](#dbcreatereadstreamoptions) to control the range and direction. | ||
@@ -424,7 +368,5 @@ You can also obtain this stream by passing an options object to `createReadStream()` with `keys` set to `true` and `values` set to `false`. The result is equivalent; both streams operate in [object mode](https://nodejs.org/docs/latest/api/stream.html#stream_object_mode). | ||
<a name="createValueStream"></a> | ||
### `db.createValueStream([options])` | ||
Returns a [Readable Stream](https://nodejs.org/docs/latest/api/stream.html#stream_readable_streams) of values rather than key-value pairs. Use the same options as described for <a href="#createReadStream"><code>createReadStream</code></a> to control the range and direction. | ||
Returns a [Readable Stream](https://nodejs.org/docs/latest/api/stream.html#stream_readable_streams) of values rather than key-value pairs. Use the same options as described for [`createReadStream()`](#dbcreatereadstreamoptions) to control the range and direction. | ||
@@ -446,14 +388,16 @@ You can also obtain this stream by passing an options object to `createReadStream()` with `values` set to `true` and `keys` set to `false`. The result is equivalent; both streams operate in [object mode](https://nodejs.org/docs/latest/api/stream.html#stream_object_mode). | ||
<a name="iterator"></a> | ||
### `db.iterator([options])` | ||
Returns an [`abstract-leveldown` iterator](https://github.com/Level/abstract-leveldown/#abstractleveldown_iteratoroptions), which is what powers the readable streams above. Options are the same as the range options of <a href="#createReadStream"><code>createReadStream</code></a> and are passed to the underlying store. | ||
Returns an [`abstract-leveldown` iterator](https://github.com/Level/abstract-leveldown/#abstractleveldown_iteratoroptions), which is what powers the readable streams above. Options are the same as the range options of [`createReadStream()`](#dbcreatereadstreamoptions) and are passed to the underlying store. | ||
<a name="clear"></a> | ||
These iterators support [`for await...of`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for-await...of): | ||
```js | ||
for await (const [key, value] of db.iterator()) { | ||
console.log(value) | ||
} | ||
``` | ||
### `db.clear([options][, callback])` | ||
**This method is experimental. Not all underlying stores support it yet. Consult [Level/community#79](https://github.com/Level/community/issues/79) to find out if your (combination of) dependencies support `db.clear()`.** | ||
Delete all entries or a range. Not guaranteed to be atomic. Accepts the following range options (with the same rules as on iterators): | ||
@@ -470,6 +414,4 @@ | ||
<a name="writeStreams"></a> | ||
## What happened to `db.createWriteStream`? | ||
#### What happened to `db.createWriteStream`? | ||
`db.createWriteStream()` has been removed in order to provide a smaller and more maintainable core. It primarily existed to create symmetry with `db.createReadStream()` but through much [discussion](https://github.com/Level/levelup/issues/199), removing it was the best course of action. | ||
@@ -483,36 +425,12 @@ | ||
`levelup` ships with native `Promise` support out of the box. | ||
Each function accepting a callback returns a promise if the callback is omitted. The only exception is the `levelup` constructor itself, which if no callback is passed will lazily open the underlying store in the background. | ||
Each function accepting a callback returns a promise if the callback is omitted. This applies for: | ||
- `db.get(key[, options])` | ||
- `db.put(key, value[, options])` | ||
- `db.del(key[, options])` | ||
- `db.batch(ops[, options])` | ||
- `db.batch().write()` | ||
The only exception is the `levelup` constructor itself, which if no callback is passed will lazily open the underlying store in the background. | ||
Example: | ||
```js | ||
var db = levelup(leveldown('./my-db')) | ||
db.put('foo', 'bar') | ||
.then(function () { return db.get('foo') }) | ||
.then(function (value) { console.log(value) }) | ||
.catch(function (err) { console.error(err) }) | ||
const db = levelup(leveldown('./my-db')) | ||
await db.put('foo', 'bar') | ||
console.log(await db.get('foo')) | ||
``` | ||
Or using `async/await`: | ||
```js | ||
const main = async () => { | ||
const db = levelup(leveldown('./my-db')) | ||
await db.put('foo', 'bar') | ||
console.log(await db.get('foo')) | ||
} | ||
``` | ||
## Events | ||
@@ -519,0 +437,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
102453
342
469