FRE-600: Fix code review blockers

- Consolidated duplicate UndoManagers to single instance
- Fixed connection promise to only resolve on 'connected' status
- Fixed WebSocketProvider import (WebsocketProvider)
- Added proper doc.destroy() cleanup
- Renamed isPresenceInitialized property to avoid conflict

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
2026-04-25 00:08:01 -04:00
parent 65b552bb08
commit 7c684a42cc
48450 changed files with 5679671 additions and 383 deletions

13
node_modules/encoding-down/.travis.yml generated vendored Normal file
View File

@@ -0,0 +1,13 @@
sudo: false
language: node_js
node_js:
- 6
- 8
- 10
after_success: npm run coverage
notifications:
email: false

394
node_modules/encoding-down/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,394 @@
# Changelog
## [6.3.0] - 2019-10-13
### Added
- Add manifest ([Level/community#83](https://github.com/Level/community/issues/83)) and encode `compactRange()` ([#93](https://github.com/Level/encoding-down/issues/93)) ([**@vweevers**](https://github.com/vweevers))
- Add `type` property for `reachdown` ([Level/community#82](https://github.com/Level/community/issues/82)) ([`8a23848`](https://github.com/Level/encoding-down/commit/8a23848)) ([**@vweevers**](https://github.com/vweevers))
## [6.2.0] - 2019-09-06
### Changed
- Upgrade `hallmark` devDependency from `^0.1.0` to `^2.0.0` ([#85](https://github.com/Level/encoding-down/issues/85), [#91](https://github.com/Level/encoding-down/issues/91)) ([**@vweevers**](https://github.com/vweevers))
- Upgrade `standard` devDependency from `^12.0.0` to `^14.0.0` ([#84](https://github.com/Level/encoding-down/issues/84), [#90](https://github.com/Level/encoding-down/issues/90)) ([**@vweevers**](https://github.com/vweevers))
- Upgrade `memdown` devDependency from `^4.0.0` to `^5.0.0` ([#88](https://github.com/Level/encoding-down/issues/88)) ([**@vweevers**](https://github.com/vweevers))
### Added
- Support `db.clear()` ([#89](https://github.com/Level/encoding-down/issues/89)) ([**@vweevers**](https://github.com/vweevers))
## [6.1.0] - 2019-06-22
### Changed
- Upgrade `nyc` devDependency from `^13.2.0` to `^14.0.0` ([#81](https://github.com/Level/encoding-down/issues/81))) ([**@vweevers**](https://github.com/vweevers))
### Added
- Support seeking ([#82](https://github.com/Level/encoding-down/issues/82), [#83](https://github.com/Level/encoding-down/issues/83)) ([**@MeirionHughes**](https://github.com/MeirionHughes), [**@vweevers**](https://github.com/vweevers))
## [6.0.2] - 2019-03-31
### Changed
- Upgrade `memdown` devDependency from `^3.0.0` to `^4.0.0` ([#80](https://github.com/Level/encoding-down/issues/80)) ([**@vweevers**](https://github.com/vweevers))
- Upgrade `nyc` devDependency from `^12.0.2` to `^13.2.0` ([#79](https://github.com/Level/encoding-down/issues/79)) ([**@vweevers**](https://github.com/vweevers))
- Apply common project tweaks ([#77](https://github.com/Level/encoding-down/issues/77), [#78](https://github.com/Level/encoding-down/issues/78)) ([**@vweevers**](https://github.com/vweevers))
## [6.0.1] - 2018-12-27
### Changed
- Replace `remark-cli` devDependency with `hallmark` ([#76](https://github.com/Level/encoding-down/issues/76)) ([**@vweevers**](https://github.com/vweevers))
### Added
- Increase coverage to 100% ([#75](https://github.com/Level/encoding-down/issues/75)) ([**@vweevers**](https://github.com/vweevers))
### Fixed
- Fix `approximateSize()` to encode `start` and `end` arguments ([#75](https://github.com/Level/encoding-down/issues/75)) ([**@vweevers**](https://github.com/vweevers))
## [6.0.0] - 2018-12-25
### Changed
- Prefer `const` over `var` in README ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Upgrade `abstract-leveldown` dependency from `^5.0.0` to `^v6.0.0` ([#68](https://github.com/Level/encoding-down/issues/68)) ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Upgrade `standard` devDependency from `^11.0.0` to `^v12.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Use full link references in README ([#60](https://github.com/Level/encoding-down/issues/60)) ([**@vweevers**](https://github.com/vweevers))
### Added
- Explain serialization ([#72](https://github.com/Level/encoding-down/issues/72)) ([**@vweevers**](https://github.com/vweevers))
- Add `nyc` and `coveralls` ([#64](https://github.com/Level/encoding-down/issues/64)) ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Removed
- Remove node 9 ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Remove now superfluous `_setupIteratorOptions()` ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [5.0.4] - 2018-06-22
### Added
- Add `LICENSE.md` ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Add `CONTRIBUTORS.md` ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Add `remark` tooling ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [5.0.3] - 2018-05-30
### Changed
- Replace `util.inherits` with `inherits` module ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [5.0.2] - 2018-05-23
### Added
- Add `UPGRADING.md` ([**@vweevers**](https://github.com/vweevers))
### Changed
- Upgrade `abstract-leveldown` to `5.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Upgrade `memdown` to `3.0.0` ([**@vweevers**](https://github.com/vweevers))
## [5.0.1] - 2018-05-19
### Changed
- Override `_setupIteratorOptions` to not clobber ranges ([**@ralphtheninja**](https://github.com/ralphtheninja), [**@dominictarr**](https://github.com/dominictarr))
## [5.0.0] - 2018-05-13
### Added
- Add 10 to Travis ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Changed
- Update `level-errors` to `2.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Update `level-codec` to `9.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Removed
- Remove 4 from Travis ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [4.0.1] - 2018-05-19
### Changed
- Override `_setupIteratorOptions` to not clobber ranges ([**@ralphtheninja**](https://github.com/ralphtheninja), [**@dominictarr**](https://github.com/dominictarr))
## [4.0.0] - 2018-02-12
### Added
- Add 9 to Travis ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Changed
- Update `abstract-leveldown` to `4.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Update `memdown` to `2.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Removed
- Remove 7 from Travis ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [3.0.1] - 2017-12-18
### Added
- Test that default utf8 encoding stringifies numbers ([**@vweevers**](https://github.com/vweevers))
### Fixed
- Skip decoding if `options.keys` or `options.values` is false ([**@vweevers**](https://github.com/vweevers))
## [3.0.0] - 2017-11-11
### Added
- README: add node badge (>= 4) ([**@vweevers**](https://github.com/vweevers))
### Changed
- Update `abstract-leveldown` to `3.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Removed
- Remove 0.12 from Travis ([**@vweevers**](https://github.com/vweevers))
## [2.3.4] - 2017-10-24
### Added
- README: add example of npm installed encoding ([**@vweevers**](https://github.com/vweevers))
## [2.3.3] - 2017-10-22
### Changed
- README: fix `level-codec` links ([**@vweevers**](https://github.com/vweevers))
## [2.3.2] - 2017-10-22
### Changed
- README: tweak badges ([**@ralphtheninja**](https://github.com/ralphtheninja))
- README: add more code examples ([**@vweevers**](https://github.com/vweevers))
- Update `level-codec` to `8.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Fixed
- Fix problems related to missing `asBuffer`, `keyAsBuffer` and `valueAsBuffer` ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [2.3.1] - 2017-10-02
### Changed
- Refactor typings ([**@MeirionHughes**](https://github.com/MeirionHughes))
## [2.3.0] - 2017-09-24
### Added
- Add default export ([**@zixia**](https://github.com/zixia))
## [2.2.1] - 2017-09-13
### Fixed
- Fix typings ([**@MeirionHughes**](https://github.com/MeirionHughes))
## [2.2.0] - 2017-09-12
### Added
- Add Typescript typings ([**@MeirionHughes**](https://github.com/MeirionHughes))
### Changed
- README: `AbstractLevelDOWN` -> `abstract-leveldown` ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Update `abstract-leveldown` ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [2.1.5] - 2017-08-18
### Added
- README: add api docs ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Add basic tests ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Changed
- Enable Travis for ci ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Update dependencies ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Use `safe-buffer` ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [2.1.4] - 2017-01-26
### Fixed
- Rename methods to `_serializeKey()` and `_serializeValue()` ([**@juliangruber**](https://github.com/juliangruber))
## [2.1.3] - 2017-01-26
### Added
- Add `_encodeKey()` and `_encodeValue()` id functions ([**@juliangruber**](https://github.com/juliangruber))
## [2.1.2] - 2017-01-26
### Fixed
- Emit encoding errors in streams too ([**@juliangruber**](https://github.com/juliangruber))
## [2.1.1] - 2017-01-26
### Fixed
- Return encoding errors on get ([**@juliangruber**](https://github.com/juliangruber))
## [2.1.0] - 2017-01-26
### Added
- Add support for `approximateSize()` ([**@juliangruber**](https://github.com/juliangruber))
## [2.0.8] - 2017-01-26
### Removed
- Remove `Iterator.prototype.seek` ([**@juliangruber**](https://github.com/juliangruber))
### Fixed
- Fix encoding lt/get range options ([**@juliangruber**](https://github.com/juliangruber))
## [2.0.7] - 2017-01-26
### Added
- Add `'utf8'` as default encoding ([**@juliangruber**](https://github.com/juliangruber))
## [2.0.6] - 2017-01-26
### Fixed
- Fix `typof` -> `typeof` bug ([**@juliangruber**](https://github.com/juliangruber))
## [2.0.5] - 2017-01-26
### Fixed
- Fix bug in `iterator._next()` with undefined key or value ([**@juliangruber**](https://github.com/juliangruber))
## [2.0.4] - 2017-01-26
### Changed
- Update `level-codec` for utf8 fixes ([**@juliangruber**](https://github.com/juliangruber))
## [2.0.3] - 2017-01-26
### Fixed
- Fix bug with incorrect db ([**@juliangruber**](https://github.com/juliangruber))
## [2.0.2] - 2017-01-26
### Fixed
- Fix bug with incorrect db and missing new operator ([**@juliangruber**](https://github.com/juliangruber))
## [2.0.1] - 2017-01-26
### Fixed
- Fix bug with `AbstractChainedBatch` inheritance ([**@juliangruber**](https://github.com/juliangruber))
## [2.0.0] - 2017-01-26
### Changed
- Version bump ([**@juliangruber**](https://github.com/juliangruber))
## 1.0.0 - 2017-01-26
:seedling: Initial release.
[6.3.0]: https://github.com/Level/encoding-down/compare/v6.2.0...v6.3.0
[6.2.0]: https://github.com/Level/encoding-down/compare/v6.1.0...v6.2.0
[6.1.0]: https://github.com/Level/encoding-down/compare/v6.0.2...v6.1.0
[6.0.2]: https://github.com/Level/encoding-down/compare/v6.0.1...v6.0.2
[6.0.1]: https://github.com/Level/encoding-down/compare/v6.0.0...v6.0.1
[6.0.0]: https://github.com/Level/encoding-down/compare/v5.0.4...v6.0.0
[5.0.4]: https://github.com/Level/encoding-down/compare/v5.0.3...v5.0.4
[5.0.3]: https://github.com/Level/encoding-down/compare/v5.0.2...v5.0.3
[5.0.2]: https://github.com/Level/encoding-down/compare/v5.0.1...v5.0.2
[5.0.1]: https://github.com/Level/encoding-down/compare/v5.0.0...v5.0.1
[5.0.0]: https://github.com/Level/encoding-down/compare/v4.0.1...v5.0.0
[4.0.1]: https://github.com/Level/encoding-down/compare/v4.0.0...v4.0.1
[4.0.0]: https://github.com/Level/encoding-down/compare/v3.0.1...v4.0.0
[3.0.1]: https://github.com/Level/encoding-down/compare/v3.0.0...v3.0.1
[3.0.0]: https://github.com/Level/encoding-down/compare/v2.3.4...v3.0.0
[2.3.4]: https://github.com/Level/encoding-down/compare/v2.3.3...v2.3.4
[2.3.3]: https://github.com/Level/encoding-down/compare/v2.3.2...v2.3.3
[2.3.2]: https://github.com/Level/encoding-down/compare/v2.3.1...v2.3.2
[2.3.1]: https://github.com/Level/encoding-down/compare/v2.3.0...v2.3.1
[2.3.0]: https://github.com/Level/encoding-down/compare/v2.2.1...v2.3.0
[2.2.1]: https://github.com/Level/encoding-down/compare/v2.2.0...v2.2.1
[2.2.0]: https://github.com/Level/encoding-down/compare/v2.1.5...v2.2.0
[2.1.5]: https://github.com/Level/encoding-down/compare/v2.1.4...v2.1.5
[2.1.4]: https://github.com/Level/encoding-down/compare/v2.1.3...v2.1.4
[2.1.3]: https://github.com/Level/encoding-down/compare/v2.1.2...v2.1.3
[2.1.2]: https://github.com/Level/encoding-down/compare/v2.1.1...v2.1.2
[2.1.1]: https://github.com/Level/encoding-down/compare/v2.1.0...v2.1.1
[2.1.0]: https://github.com/Level/encoding-down/compare/v2.0.8...v2.1.0
[2.0.8]: https://github.com/Level/encoding-down/compare/v2.0.7...v2.0.8
[2.0.7]: https://github.com/Level/encoding-down/compare/v2.0.6...v2.0.7
[2.0.6]: https://github.com/Level/encoding-down/compare/v2.0.5...v2.0.6
[2.0.5]: https://github.com/Level/encoding-down/compare/v2.0.4...v2.0.5
[2.0.4]: https://github.com/Level/encoding-down/compare/v2.0.3...v2.0.4
[2.0.3]: https://github.com/Level/encoding-down/compare/v2.0.2...v2.0.3
[2.0.2]: https://github.com/Level/encoding-down/compare/v2.0.1...v2.0.2
[2.0.1]: https://github.com/Level/encoding-down/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/Level/encoding-down/compare/v1.0.0...v2.0.0

9
node_modules/encoding-down/CONTRIBUTORS.md generated vendored Normal file
View File

@@ -0,0 +1,9 @@
# Contributors
| Name | GitHub | Social |
| :------------------- | :----------------------------------------------------- | :------------------------------------------------------------ |
| **Lars-Magnus Skog** | [**@ralphtheninja**](https://github.com/ralphtheninja) | [**@ralph@social.weho.st**](https://social.weho.st/@ralph) |
| **Vincent Weevers** | [**@vweevers**](https://github.com/vweevers) | [**@vweevers@twitter**](https://twitter.com/vweevers) |
| **Julian Gruber** | [**@juliangruber**](https://github.com/juliangruber) | [**@juliangruber@twitter**](https://twitter.com/juliangruber) |
| **Meirion Hughes** | [**@MeirionHughes**](https://github.com/MeirionHughes) | |
| **Huan LI** | [**@zixia**](https://github.com/zixia) | [**@zixia@twitter**](https://twitter.com/zixia) |

21
node_modules/encoding-down/LICENSE.md generated vendored Normal file
View File

@@ -0,0 +1,21 @@
# The MIT License (MIT)
**Copyright © 2012-present [Contributors](CONTRIBUTORS.md).**
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.

205
node_modules/encoding-down/README.md generated vendored Normal file
View File

@@ -0,0 +1,205 @@
# encoding-down
> An [`abstract-leveldown`][abstract-leveldown] implementation that wraps another store to encode keys and values.
[![level badge][level-badge]](https://github.com/Level/awesome)
[![npm](https://img.shields.io/npm/v/encoding-down.svg?label=&logo=npm)](https://www.npmjs.com/package/encoding-down)
[![Node version](https://img.shields.io/node/v/encoding-down.svg)](https://www.npmjs.com/package/encoding-down)
[![Travis](https://img.shields.io/travis/Level/com/encoding-down.svg?logo=travis&label=)](https://travis-ci.com/Level/encoding-down)
[![Coverage Status](https://coveralls.io/repos/github/Level/encoding-down/badge.svg)](https://coveralls.io/github/Level/encoding-down)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![npm](https://img.shields.io/npm/dm/encoding-down.svg?label=dl)](https://www.npmjs.com/package/encoding-down)
[![Backers on Open Collective](https://opencollective.com/level/backers/badge.svg?color=orange)](#backers)
[![Sponsors on Open Collective](https://opencollective.com/level/sponsors/badge.svg?color=orange)](#sponsors)
## Introduction
Stores like [`leveldown`][leveldown] can only store strings and Buffers. Other types, though accepted, are [_serialized_](https://github.com/Level/abstract-leveldown#db_serializekeykey) before storage, which is an irreversible type conversion. For a richer set of data types you can wrap such a store with `encoding-down`. It allows you to specify an _encoding_ to use for keys and values independently. This not only widens the range of input types, but also limits the range of output types. The encoding is applied to all read and write operations: it encodes writes and decodes reads.
[Many encodings are builtin][builtin-encodings] courtesy of [`level-codec`][level-codec]. The default encoding is `utf8` which ensures you'll always get back a string. You can also provide a custom encoding like `bytewise` - [or your own](#custom-encodings)!
## Usage
Without any options, `encoding-down` defaults to the `utf8` encoding.
```js
var levelup = require('levelup')
var leveldown = require('leveldown')
var encode = require('encoding-down')
var db = levelup(encode(leveldown('./db1')))
db.put('example', Buffer.from('encoding-down'), function (err) {
db.get('example', function (err, value) {
console.log(typeof value, value) // 'string encoding-down'
})
})
```
Can we store objects? Yes!
```js
var db = levelup(encode(leveldown('./db2'), { valueEncoding: 'json' }))
db.put('example', { awesome: true }, function (err) {
db.get('example', function (err, value) {
console.log(value) // { awesome: true }
console.log(typeof value) // 'object'
})
})
```
How about storing Buffers, but getting back a hex-encoded string?
```js
var db = levelup(encode(leveldown('./db3'), { valueEncoding: 'hex' }))
db.put('example', Buffer.from([0, 255]), function (err) {
db.get('example', function (err, value) {
console.log(typeof value, value) // 'string 00ff'
})
})
```
What if we previously stored binary data?
```js
var db = levelup(encode(leveldown('./db4'), { valueEncoding: 'binary' }))
db.put('example', Buffer.from([0, 255]), function (err) {
db.get('example', function (err, value) {
console.log(typeof value, value) // 'object <Buffer 00 ff>'
})
// Override the encoding for this operation
db.get('example', { valueEncoding: 'base64' }, function (err, value) {
console.log(typeof value, value) // 'string AP8='
})
})
```
And what about keys?
```js
var db = levelup(encode(leveldown('./db5'), { keyEncoding: 'json' }))
db.put({ awesome: true }, 'example', function (err) {
db.get({ awesome: true }, function (err, value) {
console.log(value) // 'example'
})
})
```
```js
var db = levelup(encode(leveldown('./db6'), { keyEncoding: 'binary' }))
db.put(Buffer.from([0, 255]), 'example', function (err) {
db.get('00ff', { keyEncoding: 'hex' }, function (err, value) {
console.log(value) // 'example'
})
})
```
## Usage with [`level`][level]
The [`level`][level] module conveniently bundles `encoding-down` and passes its `options` to `encoding-down`. This means you can simply do:
```js
var level = require('level')
var db = level('./db7', { valueEncoding: 'json' })
db.put('example', 42, function (err) {
db.get('example', function (err, value) {
console.log(value) // 42
console.log(typeof value) // 'number'
})
})
```
## API
### `db = require('encoding-down')(db[, options])`
- `db` must be an [`abstract-leveldown`][abstract-leveldown] compliant store
- `options` are passed to [`level-codec`][level-codec]:
- `keyEncoding`: encoding to use for keys
- `valueEncoding`: encoding to use for values
Both encodings default to `'utf8'`. They can be a string (builtin `level-codec` encoding) or an object (custom encoding).
## Custom encodings
Please refer to [`level-codec` documentation][encoding-format] for a precise description of the format. Here's a quick example with `level` and `async/await` just for fun:
```js
var level = require('level')
var lexint = require('lexicographic-integer')
async function main () {
var db = level('./db8', {
keyEncoding: {
type: 'lexicographic-integer',
encode: (n) => lexint.pack(n, 'hex'),
decode: lexint.unpack,
buffer: false
}
})
await db.put(2, 'example')
await db.put(10, 'example')
// Without our encoding, the keys would sort as 10, 2.
db.createKeyStream().on('data', console.log) // 2, 10
}
main()
```
With an npm-installed encoding (modularity ftw!) we can reduce the above to:
```js
var level = require('level')
var lexint = require('lexicographic-integer-encoding')('hex')
var db = level('./db8', {
keyEncoding: lexint
})
```
## Contributing
[`Level/encoding-down`](https://github.com/Level/encoding-down) 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](https://github.com/Level/community/blob/master/CONTRIBUTING.md) for more details.
## Donate
To sustain [`Level`](https://github.com/Level) and its activities, become a backer or sponsor on [Open Collective](https://opencollective.com/level). Your logo or avatar will be displayed on our 28+ [GitHub repositories](https://github.com/Level) and [npm](https://www.npmjs.com/) packages. 💖
### Backers
[![Open Collective backers](https://opencollective.com/level/backers.svg?width=890)](https://opencollective.com/level)
### Sponsors
[![Open Collective sponsors](https://opencollective.com/level/sponsors.svg?width=890)](https://opencollective.com/level)
## License
[MIT](LICENSE.md) © 2012-present [Contributors](CONTRIBUTORS.md).
[level-badge]: https://leveljs.org/img/badge.svg
[abstract-leveldown]: https://github.com/Level/abstract-leveldown
[leveldown]: https://github.com/Level/leveldown
[level]: https://github.com/Level/level
[level-codec]: https://github.com/Level/codec
[builtin-encodings]: https://github.com/Level/codec#builtin-encodings
[encoding-format]: https://github.com/Level/codec#encoding-format

25
node_modules/encoding-down/UPGRADING.md generated vendored Normal file
View File

@@ -0,0 +1,25 @@
# Upgrade Guide
This document describes breaking changes and how to upgrade. For a complete list of changes including minor and patch releases, please refer to the [changelog](CHANGELOG.md).
## v6
Upgraded `abstract-leveldown` to `v6.0.0`. Please see the corresponding [changelog entry](https://github.com/Level/abstract-leveldown/blob/master/CHANGELOG.md#600---2018-10-20) for more information.
## v5
Dropped support for node 4. No other breaking changes.
## v4
Dropped support for node 7.
#### `.batch(array)` enforces objects
This major release contains an upgrade to `abstract-leveldown` with a [breaking change](https://github.com/Level/abstract-leveldown/commit/a2621ad70571f6ade9d2be42632ece042e068805) for the array version of `.batch()`. This change ensures all elements in the batch array are objects.
If you previously passed arrays to `.batch()` that contained `undefined` or `null`, they would be silently ignored. Now this will produce an error.
## v3
Dropped support for node 0.12. No other breaking changes.

178
node_modules/encoding-down/index.js generated vendored Normal file
View File

@@ -0,0 +1,178 @@
'use strict'
var AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN
var AbstractChainedBatch = require('abstract-leveldown').AbstractChainedBatch
var AbstractIterator = require('abstract-leveldown').AbstractIterator
var inherits = require('inherits')
var Codec = require('level-codec')
var EncodingError = require('level-errors').EncodingError
var rangeMethods = ['approximateSize', 'compactRange']
module.exports = DB.default = DB
function DB (db, opts) {
if (!(this instanceof DB)) return new DB(db, opts)
var manifest = db.supports || {}
var additionalMethods = manifest.additionalMethods || {}
AbstractLevelDOWN.call(this, manifest)
this.supports.encodings = true
this.supports.additionalMethods = {}
rangeMethods.forEach(function (m) {
// TODO (future major): remove this fallback
var fallback = typeof db[m] === 'function'
if (additionalMethods[m] || fallback) {
this.supports.additionalMethods[m] = true
this[m] = function (start, end, opts, cb) {
start = this.codec.encodeKey(start, opts)
end = this.codec.encodeKey(end, opts)
return this.db[m](start, end, opts, cb)
}
}
}, this)
opts = opts || {}
if (typeof opts.keyEncoding === 'undefined') opts.keyEncoding = 'utf8'
if (typeof opts.valueEncoding === 'undefined') opts.valueEncoding = 'utf8'
this.db = db
this.codec = new Codec(opts)
}
inherits(DB, AbstractLevelDOWN)
DB.prototype.type = 'encoding-down'
DB.prototype._serializeKey =
DB.prototype._serializeValue = function (datum) {
return datum
}
DB.prototype._open = function (opts, cb) {
this.db.open(opts, cb)
}
DB.prototype._close = function (cb) {
this.db.close(cb)
}
DB.prototype._put = function (key, value, opts, cb) {
key = this.codec.encodeKey(key, opts)
value = this.codec.encodeValue(value, opts)
this.db.put(key, value, opts, cb)
}
DB.prototype._get = function (key, opts, cb) {
var self = this
key = this.codec.encodeKey(key, opts)
opts.asBuffer = this.codec.valueAsBuffer(opts)
this.db.get(key, opts, function (err, value) {
if (err) return cb(err)
try {
value = self.codec.decodeValue(value, opts)
} catch (err) {
return cb(new EncodingError(err))
}
cb(null, value)
})
}
DB.prototype._del = function (key, opts, cb) {
key = this.codec.encodeKey(key, opts)
this.db.del(key, opts, cb)
}
DB.prototype._chainedBatch = function () {
return new Batch(this)
}
DB.prototype._batch = function (ops, opts, cb) {
ops = this.codec.encodeBatch(ops, opts)
this.db.batch(ops, opts, cb)
}
DB.prototype._iterator = function (opts) {
opts.keyAsBuffer = this.codec.keyAsBuffer(opts)
opts.valueAsBuffer = this.codec.valueAsBuffer(opts)
return new Iterator(this, opts)
}
DB.prototype._clear = function (opts, callback) {
opts = this.codec.encodeLtgt(opts)
this.db.clear(opts, callback)
}
function Iterator (db, opts) {
AbstractIterator.call(this, db)
this.codec = db.codec
this.keys = opts.keys
this.values = opts.values
this.opts = this.codec.encodeLtgt(opts)
this.it = db.db.iterator(this.opts)
}
inherits(Iterator, AbstractIterator)
Iterator.prototype._next = function (cb) {
var self = this
this.it.next(function (err, key, value) {
if (err) return cb(err)
try {
if (self.keys && typeof key !== 'undefined') {
key = self.codec.decodeKey(key, self.opts)
} else {
key = undefined
}
if (self.values && typeof value !== 'undefined') {
value = self.codec.decodeValue(value, self.opts)
} else {
value = undefined
}
} catch (err) {
return cb(new EncodingError(err))
}
cb(null, key, value)
})
}
Iterator.prototype._seek = function (key) {
key = this.codec.encodeKey(key, this.opts)
this.it.seek(key)
}
Iterator.prototype._end = function (cb) {
this.it.end(cb)
}
function Batch (db, codec) {
AbstractChainedBatch.call(this, db)
this.codec = db.codec
this.batch = db.db.batch()
}
inherits(Batch, AbstractChainedBatch)
Batch.prototype._put = function (key, value) {
key = this.codec.encodeKey(key)
value = this.codec.encodeValue(value)
this.batch.put(key, value)
}
Batch.prototype._del = function (key) {
key = this.codec.encodeKey(key)
this.batch.del(key)
}
Batch.prototype._clear = function () {
this.batch.clear()
}
Batch.prototype._write = function (opts, cb) {
this.batch.write(opts, cb)
}

42
node_modules/encoding-down/package.json generated vendored Normal file
View File

@@ -0,0 +1,42 @@
{
"name": "encoding-down",
"version": "6.3.0",
"description": "LevelDOWN wrapper supporting levelup@1 encodings",
"license": "MIT",
"main": "index.js",
"scripts": {
"test": "standard && hallmark && nyc node test",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"hallmark": "hallmark --fix",
"dependency-check": "dependency-check . test/*.js",
"prepublishOnly": "npm run dependency-check"
},
"dependencies": {
"abstract-leveldown": "^6.2.1",
"inherits": "^2.0.3",
"level-codec": "^9.0.0",
"level-errors": "^2.0.0"
},
"devDependencies": {
"coveralls": "^3.0.2",
"dependency-check": "^3.3.0",
"hallmark": "^2.0.0",
"level-community": "^3.0.0",
"memdown": "^5.0.0",
"nyc": "^14.0.0",
"safe-buffer": "^5.1.1",
"standard": "^14.0.0",
"tape": "^4.8.0"
},
"hallmark": {
"community": "level-community"
},
"repository": "Level/encoding-down",
"homepage": "https://github.com/Level/encoding-down",
"keywords": [
"level"
],
"engines": {
"node": ">=6"
}
}

803
node_modules/encoding-down/test/index.js generated vendored Normal file
View File

@@ -0,0 +1,803 @@
var test = require('tape')
var encdown = require('..')
var memdown = require('memdown')
var Buffer = require('safe-buffer').Buffer
var hasOwnProperty = Object.prototype.hasOwnProperty
var noop = function () {}
test('opens and closes the underlying db', function (t) {
var _db = {
open: function (opts, cb) {
t.pass('open called')
setImmediate(cb)
},
close: function (cb) {
t.pass('close called')
setImmediate(cb)
}
}
var db = encdown(_db)
db.open(function (err) {
t.error(err, 'no error')
db.close(function (err) {
t.error(err, 'no error')
t.end()
})
})
})
test('encodings default to utf8', function (t) {
var db = encdown(memdown())
t.ok(db.db, '.db should be set')
t.ok(db.codec, '.codec should be set')
t.deepEqual(db.codec.opts, {
keyEncoding: 'utf8',
valueEncoding: 'utf8'
}, 'correct defaults')
t.end()
})
test('default utf8 encoding stringifies numbers', function (t) {
t.plan(3)
var db = encdown({
put: function (key, value, callback) {
t.is(key, '1')
t.is(value, '2')
},
batch: function (ops, options, callback) {
t.same(ops, [{ type: 'put', key: '3', value: '4' }])
}
})
db.put(1, 2, noop)
db.batch([{ type: 'put', key: 3, value: 4 }], noop)
})
test('test safe decode in get', function (t) {
var memdb = memdown()
var db = encdown(memdb, { valueEncoding: 'utf8' })
db.put('foo', 'this {} is [] not : json', function (err) {
t.error(err, 'no error')
var db2 = encdown(memdb, { valueEncoding: 'json' })
db2.get('foo', function (err, value) {
t.equals('EncodingError', err.name)
memdb.close(t.end.bind(t))
})
})
})
test('can decode from string to json', function (t) {
var memdb = memdown()
var db = encdown(memdb, { valueEncoding: 'utf8' })
var data = { thisis: 'json' }
db.put('foo', JSON.stringify(data), function (err) {
t.error(err, 'no error')
var db2 = encdown(memdb, { valueEncoding: 'json' })
db2.get('foo', function (err, value) {
t.error(err, 'no error')
t.deepEqual(value, data, 'JSON.parse')
memdb.close(t.end.bind(t))
})
})
})
test('can decode from json to string', function (t) {
var memdb = memdown()
var db = encdown(memdb, { valueEncoding: 'json' })
var data = { thisis: 'json' }
db.put('foo', data, function (err) {
t.error(err, 'no error')
var db2 = encdown(memdb, { valueEncoding: 'utf8' })
db2.get('foo', function (err, value) {
t.error(err, 'no error')
t.deepEqual(value, JSON.stringify(data), 'JSON.stringify')
memdb.close(t.end.bind(t))
})
})
})
test('binary encoding, using batch', function (t) {
var data = [
{
type: 'put',
key: Buffer.from([1, 2, 3]),
value: Buffer.from([4, 5, 6])
},
{
type: 'put',
key: Buffer.from([7, 8, 9]),
value: Buffer.from([10, 11, 12])
}
]
var db = encdown(memdown(), {
keyEncoding: 'binary',
valueEncoding: 'binary'
})
db.batch(data, function (err) {
t.error(err, 'no error')
db.get(data[0].key, function (err, value) {
t.error(err, 'no error')
t.deepEqual(value, data[0].value)
db.get(data[1].key, function (err, value) {
t.error(err, 'no error')
t.deepEqual(value, data[1].value)
db.close(t.end.bind(t))
})
})
})
})
test('default encoding retrieves a string from underlying store', function (t) {
t.plan(1)
var down = {
get: function (key, options, cb) {
t.is(options.asBuffer, false, '.asBuffer is false')
}
}
var db = encdown(down)
db.get('key', noop)
})
test('custom value encoding that retrieves a string from underlying store', function (t) {
t.plan(1)
var down = {
get: function (key, options, cb) {
t.is(options.asBuffer, false, '.asBuffer is false')
}
}
var db = encdown(down, {
valueEncoding: {
buffer: false
}
})
db.get('key', noop)
})
test('get() forwards error from underlying store', function (t) {
t.plan(1)
var down = {
get: function (key, options, cb) {
process.nextTick(cb, new Error('error from store'))
}
}
encdown(down).get('key', function (err) {
t.is(err.message, 'error from store')
})
})
test('_del() encodes key', function (t) {
t.plan(1)
var down = {
del: function (key, options, cb) {
t.is(key, '2')
}
}
encdown(down).del(2, noop)
})
test('chainedBatch.put() encodes key and value', function (t) {
t.plan(2)
var down = {
batch: function () {
return {
put: function (key, value) {
t.is(key, '1')
t.is(value, '2')
}
}
}
}
encdown(down).batch().put(1, 2)
})
test('chainedBatch.del() encodes key', function (t) {
t.plan(1)
var down = {
batch: function () {
return {
del: function (key) {
t.is(key, '1')
}
}
}
}
encdown(down).batch().del(1)
})
test('chainedBatch.clear() is forwarded to underlying store', function (t) {
t.plan(1)
var down = {
batch: function () {
return {
clear: function () {
t.pass('called')
}
}
}
}
encdown(down).batch().clear()
})
test('chainedBatch.write() is forwarded to underlying store', function (t) {
t.plan(1)
var down = {
batch: function () {
return {
write: function () {
t.pass('called')
}
}
}
}
encdown(down).batch().write(noop)
})
test('custom value encoding that retrieves a buffer from underlying store', function (t) {
t.plan(1)
var down = {
get: function (key, options, cb) {
t.is(options.asBuffer, true, '.asBuffer is true')
}
}
var db = encdown(down, {
valueEncoding: {
buffer: true
}
})
db.get('key', noop)
})
test('.keyAsBuffer and .valueAsBuffer defaults to false', function (t) {
t.plan(2)
var down = {
iterator: function (options) {
t.is(options.keyAsBuffer, false)
t.is(options.valueAsBuffer, false)
}
}
encdown(down).iterator()
})
test('.keyAsBuffer and .valueAsBuffer as buffers if encoding says so', function (t) {
t.plan(2)
var down = {
iterator: function (options) {
t.is(options.keyAsBuffer, true)
t.is(options.valueAsBuffer, true)
}
}
var db = encdown(down, {
keyEncoding: {
buffer: true
},
valueEncoding: {
buffer: true
}
})
db.iterator()
})
test('.keyAsBuffer and .valueAsBuffer as strings if encoding says so', function (t) {
t.plan(2)
var down = {
iterator: function (options) {
t.is(options.keyAsBuffer, false)
t.is(options.valueAsBuffer, false)
}
}
var db = encdown(down, {
keyEncoding: {
buffer: false
},
valueEncoding: {
buffer: false
}
})
db.iterator()
})
test('iterator options.keys and options.values default to true', function (t) {
t.plan(2)
var down = {
iterator: function (options) {
t.is(options.keys, true)
t.is(options.values, true)
}
}
encdown(down).iterator()
})
test('iterator skips keys if options.keys is false', function (t) {
t.plan(4)
var down = {
iterator: function (options) {
t.is(options.keys, false)
return {
next: function (callback) {
callback(null, '', 'value')
}
}
}
}
var keyEncoding = {
decode: function (key) {
t.fail('should not be called')
}
}
var db = encdown(down, { keyEncoding: keyEncoding })
var it = db.iterator({ keys: false })
it.next(function (err, key, value) {
t.ifError(err, 'no next error')
t.is(key, undefined, 'normalized key to undefined')
t.is(value, 'value', 'got value')
})
})
test('iterator skips values if options.values is false', function (t) {
t.plan(4)
var down = {
iterator: function (options) {
t.is(options.values, false)
return {
next: function (callback) {
callback(null, 'key', '')
}
}
}
}
var valueEncoding = {
decode: function (value) {
t.fail('should not be called')
}
}
var db = encdown(down, { valueEncoding: valueEncoding })
var it = db.iterator({ values: false })
it.next(function (err, key, value) {
t.ifError(err, 'no next error')
t.is(key, 'key', 'got key')
t.is(value, undefined, 'normalized value to undefined')
})
})
test('iterator encodes range options', function (t) {
t.plan(7)
var keyEncoding = {
encode: function (key) {
return 'encoded_' + key
},
buffer: false
}
var db = encdown({
iterator: function (options) {
t.is(options.start, 'encoded_1')
t.is(options.end, 'encoded_2')
t.is(options.gt, 'encoded_3')
t.is(options.gte, 'encoded_4')
t.is(options.lt, 'encoded_5')
t.is(options.lte, 'encoded_6')
t.is(options.foo, 7)
}
}, { keyEncoding })
db.iterator({ start: 1, end: 2, gt: 3, gte: 4, lt: 5, lte: 6, foo: 7 })
})
test('iterator does not strip nullish range options', function (t) {
t.plan(12)
encdown({
iterator: function (options) {
t.is(options.gt, null)
t.is(options.gte, null)
t.is(options.lt, null)
t.is(options.lte, null)
}
}).iterator({
gt: null,
gte: null,
lt: null,
lte: null
})
encdown({
iterator: function (options) {
t.ok(hasOwnProperty.call(options, 'gt'))
t.ok(hasOwnProperty.call(options, 'gte'))
t.ok(hasOwnProperty.call(options, 'lt'))
t.ok(hasOwnProperty.call(options, 'lte'))
t.is(options.gt, undefined)
t.is(options.gte, undefined)
t.is(options.lt, undefined)
t.is(options.lte, undefined)
}
}).iterator({
gt: undefined,
gte: undefined,
lt: undefined,
lte: undefined
})
})
test('iterator does not add nullish range options', function (t) {
t.plan(4)
encdown({
iterator: function (options) {
t.notOk(hasOwnProperty.call(options, 'gt'))
t.notOk(hasOwnProperty.call(options, 'gte'))
t.notOk(hasOwnProperty.call(options, 'lt'))
t.notOk(hasOwnProperty.call(options, 'lte'))
}
}).iterator({})
})
test('iterator forwards next() error from underlying iterator', function (t) {
t.plan(1)
var down = {
iterator: function () {
return {
next: function (callback) {
process.nextTick(callback, new Error('from underlying iterator'))
}
}
}
}
var db = encdown(down)
var it = db.iterator()
it.next(function (err, key, value) {
t.is(err.message, 'from underlying iterator')
})
})
test('iterator forwards end() to underlying iterator', function (t) {
t.plan(2)
var down = {
iterator: function () {
return {
end: function (callback) {
t.pass('called')
process.nextTick(callback)
}
}
}
}
var db = encdown(down)
var it = db.iterator()
it.end(function () {
t.pass('called')
})
})
test('iterator catches decoding error from keyEncoding', function (t) {
t.plan(5)
var down = {
iterator: function () {
return {
next: function (callback) {
process.nextTick(callback, null, 'key', 'value')
}
}
}
}
var db = encdown(down, {
keyEncoding: {
decode: function (key) {
t.is(key, 'key')
throw new Error('from codec')
}
}
})
db.iterator().next(function (err, key, value) {
t.is(err.message, 'from codec')
t.is(err.name, 'EncodingError')
t.is(key, undefined)
t.is(value, undefined)
})
})
test('iterator catches decoding error from valueEncoding', function (t) {
t.plan(5)
var down = {
iterator: function () {
return {
next: function (callback) {
process.nextTick(callback, null, 'key', 'value')
}
}
}
}
var db = encdown(down, {
valueEncoding: {
decode: function (value) {
t.is(value, 'value')
throw new Error('from codec')
}
}
})
db.iterator().next(function (err, key, value) {
t.is(err.message, 'from codec')
t.is(err.name, 'EncodingError')
t.is(key, undefined)
t.is(value, undefined)
})
})
test('proxies approximateSize() if it exists', function (t) {
t.is(typeof encdown({ approximateSize: noop }).approximateSize, 'function')
t.ok(encdown({ approximateSize: noop }).supports.additionalMethods.approximateSize)
t.is(encdown({}).approximateSize, undefined)
t.notOk(encdown({}).supports.additionalMethods.approximateSize)
t.end()
})
test('proxies compactRange() if it exists', function (t) {
t.is(typeof encdown({ compactRange: noop }).compactRange, 'function')
t.ok(encdown({ compactRange: noop }).supports.additionalMethods.compactRange)
t.is(encdown({}).compactRange, undefined)
t.notOk(encdown({}).supports.additionalMethods.compactRange)
t.end()
})
test('encodes start and end of approximateSize()', function (t) {
var db = encdown({
approximateSize: function (start, end) {
t.is(start, '1')
t.is(end, '2')
t.end()
}
})
db.approximateSize(1, 2, noop)
})
test('encodes start and end of compactRange()', function (t) {
var db = encdown({
compactRange: function (start, end) {
t.is(start, '1')
t.is(end, '2')
t.end()
}
})
db.compactRange(1, 2, noop)
})
test('encodes start and end of approximateSize() with custom encoding', function (t) {
var db = encdown({
approximateSize: function (start, end) {
t.is(start, '"a"')
t.is(end, '"b"')
t.end()
}
})
db.approximateSize('a', 'b', { keyEncoding: 'json' }, noop)
})
test('encodes start and end of compactRange() with custom encoding', function (t) {
var db = encdown({
compactRange: function (start, end) {
t.is(start, '"a"')
t.is(end, '"b"')
t.end()
}
})
db.compactRange('a', 'b', { keyEncoding: 'json' }, noop)
})
test('encodes seek target', function (t) {
t.plan(1)
var db = encdown({
iterator: function () {
return {
seek: function (target) {
t.is(target, '123', 'encoded number')
}
}
}
}, { keyEncoding: 'json' })
db.iterator().seek(123)
})
test('encodes seek target with custom encoding', function (t) {
t.plan(1)
var targets = []
var db = encdown({
iterator: function () {
return {
seek: function (target) {
targets.push(target)
}
}
}
})
db.iterator().seek('a')
db.iterator({ keyEncoding: 'json' }).seek('a')
t.same(targets, ['a', '"a"'], 'encoded targets')
})
test('encodes nullish seek target', function (t) {
t.plan(1)
var targets = []
var db = encdown({
iterator: function () {
return {
seek: function (target) {
targets.push(target)
}
}
}
}, { keyEncoding: { encode: String } })
// Unlike keys, nullish targets should not be rejected;
// assume that the encoding gives these types meaning.
db.iterator().seek(null)
db.iterator().seek(undefined)
t.same(targets, ['null', 'undefined'], 'encoded')
})
test('clear() forwards default options', function (t) {
t.plan(3)
var down = {
clear: function (options, callback) {
t.is(options.reverse, false)
t.is(options.limit, -1)
t.is(callback, noop)
}
}
encdown(down).clear(noop)
})
test('clear() forwards error from underlying store', function (t) {
t.plan(1)
var down = {
clear: function (options, cb) {
process.nextTick(cb, new Error('error from store'))
}
}
encdown(down).clear(function (err) {
t.is(err.message, 'error from store')
})
})
test('clear() encodes range options', function (t) {
t.plan(5)
var keyEncoding = {
encode: function (key) {
return 'encoded_' + key
},
buffer: false
}
var db = encdown({
clear: function (options) {
t.is(options.gt, 'encoded_1')
t.is(options.gte, 'encoded_2')
t.is(options.lt, 'encoded_3')
t.is(options.lte, 'encoded_4')
t.is(options.foo, 5)
}
}, { keyEncoding })
db.clear({ gt: 1, gte: 2, lt: 3, lte: 4, foo: 5 }, noop)
})
test('clear() does not strip nullish range options', function (t) {
t.plan(12)
encdown({
clear: function (options) {
t.is(options.gt, null)
t.is(options.gte, null)
t.is(options.lt, null)
t.is(options.lte, null)
}
}).clear({
gt: null,
gte: null,
lt: null,
lte: null
}, noop)
encdown({
clear: function (options) {
t.ok(hasOwnProperty.call(options, 'gt'))
t.ok(hasOwnProperty.call(options, 'gte'))
t.ok(hasOwnProperty.call(options, 'lt'))
t.ok(hasOwnProperty.call(options, 'lte'))
t.is(options.gt, undefined)
t.is(options.gte, undefined)
t.is(options.lt, undefined)
t.is(options.lte, undefined)
}
}).clear({
gt: undefined,
gte: undefined,
lt: undefined,
lte: undefined
}, noop)
})
test('clear() does not add nullish range options', function (t) {
t.plan(4)
encdown({
clear: function (options) {
t.notOk(hasOwnProperty.call(options, 'gt'))
t.notOk(hasOwnProperty.call(options, 'gte'))
t.notOk(hasOwnProperty.call(options, 'lt'))
t.notOk(hasOwnProperty.call(options, 'lte'))
}
}).clear({}, noop)
})