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/deferred-leveldown/.travis.yml generated vendored Normal file
View File

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

329
node_modules/deferred-leveldown/CHANGELOG.md generated vendored Normal file
View File

@@ -0,0 +1,329 @@
# Changelog
## [5.3.0] - 2019-10-04
### Added
- Add manifest ([Level/community#83](https://github.com/Level/community/issues/83)) ([#79](https://github.com/Level/deferred-leveldown/issues/79)) ([**@vweevers**](https://github.com/vweevers))
- Include abstract test suite ([#77](https://github.com/Level/deferred-leveldown/issues/77)) ([**@vweevers**](https://github.com/vweevers))
### Fixed
- Pass db to `AbstractIterator` ([#77](https://github.com/Level/deferred-leveldown/issues/77)) ([**@vweevers**](https://github.com/vweevers))
## [5.2.1] - 2019-09-17
### Fixed
- Create iterators in order and add `type` property for `reachdown` ([#75](https://github.com/Level/deferred-leveldown/issues/75)) ([**@vweevers**](https://github.com/vweevers))
## [5.2.0] - 2019-09-06
### Changed
- Upgrade `abstract-leveldown` from `~6.0.0` to `~6.1.0` ([#72](https://github.com/Level/deferred-leveldown/issues/72)) ([**@vweevers**](https://github.com/vweevers))
- Upgrade `hallmark` devDependency from `^0.1.0` to `^2.0.0` ([#70](https://github.com/Level/deferred-leveldown/issues/70), [#74](https://github.com/Level/deferred-leveldown/issues/74)) ([**@vweevers**](https://github.com/vweevers))
- Upgrade `standard` devDependency from `^12.0.0` to `^14.0.0` ([#69](https://github.com/Level/deferred-leveldown/issues/69), [#73](https://github.com/Level/deferred-leveldown/issues/73)) ([**@vweevers**](https://github.com/vweevers))
### Added
- Defer `db.clear()` and `db.compactRange()` ([#72](https://github.com/Level/deferred-leveldown/issues/72))
## [5.1.0] - 2019-06-22
### Changed
- Update `nyc` devDependency from `^13.2.0` to `^14.0.0` ([#66](https://github.com/Level/deferred-leveldown/issues/66)) ([**@vweevers**](https://github.com/vweevers))
### Added
- Support seeking ([#68](https://github.com/Level/deferred-leveldown/issues/68)) ([**@MeirionHughes**](https://github.com/MeirionHughes))
## [5.0.1] - 2019-03-31
### Changed
- Upgrade `nyc` devDependency from `^12.0.2` to `^13.2.0` ([#63](https://github.com/Level/deferred-leveldown/issues/63)) ([**@vweevers**](https://github.com/vweevers))
- Apply common project tweaks ([#61](https://github.com/Level/deferred-leveldown/issues/61), [#62](https://github.com/Level/deferred-leveldown/issues/62), [`c4d169e`](https://github.com/Level/deferred-leveldown/commit/c4d169e)) ([**@vweevers**](https://github.com/vweevers))
### Fixed
- Fix subtests by adding `t.plan()` ([#65](https://github.com/Level/deferred-leveldown/issues/65)) ([**@vweevers**](https://github.com/vweevers))
## [5.0.0] - 2018-12-21
### Changed
- Upgrade `abstract-leveldown` dependency from `~5.0.0` to `~6.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Upgrade `standard` devDependency from `^11.0.0` to `^12.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Tweak copyright years for less maintenance ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Added
- Add `nyc` and `coveralls` ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Removed
- Remove contributors from `package.json` ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Remove node 9 ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [4.0.2] - 2018-05-30
### Changed
- Replace `util.inherits` with `inherits` module ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [4.0.1] - 2018-05-22
### Changed
- Upgrade `abstract-leveldown` to `5.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [4.0.0] - 2018-05-13
### Added
- Add node 10 to Travis ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Changed
- Upgrade to `standard@11.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Removed
- Remove node 4 from Travis ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [3.0.0] - 2018-02-08
### Added
- Add `9` to travis ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Changed
- Upgrade to `abstract-leveldown@4.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Removed
- Remove `DeferredLevelDOWN.prototype._isBuffer`, no longer needed since we use `Buffer.isBuffer()` ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Fixed
- Defer `approximateSize()` separately ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Fix broken link in `README` and clean up old `.jshintrc` ([**@ralphtheninja**](https://github.com/ralphtheninja))
**Historical Note** `abstract-leveldown@4.0.0` dropped `approximateSize()` so we needed to defer this method separately for stores that support it.
## [2.0.3] - 2017-11-04
### Added
- Add `4` to travis ([**@vweevers**](https://github.com/vweevers))
- Add node badge ([**@vweevers**](https://github.com/vweevers))
### Changed
- Upgrade to `abstract-leveldown@3.0.0` ([**@vweevers**](https://github.com/vweevers))
**Historical Note** `abstract-leveldown@3.0.0` dropped support for node `0.12` and didn't have any breaking changes to api or behavior, hence a new patch version.
## [2.0.2] - 2017-10-06
### Added
- Add `standard` for linting ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Changed
- Use svg instead of png for travis badge ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Update to new badge setup ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Fixed
- `_serializeKey()` and `_serializeValue()` should not modify keys or values ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [2.0.1] - 2017-09-12
### Added
- Add Greenkeeper badge ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Add `6` and `8` to travis ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Changed
- Upgrade to `abstract-leveldown@2.7.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Removed
- Remove `0.8`, `0.10` and `0.11` from travis ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [2.0.0] - 2017-07-30
### Changed
- Update dependencies ([**@ralphtheninja**](https://github.com/ralphtheninja))
- Update copyright years ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [2.0.0-2] - 2015-05-28
### Fixed
- Fix `.iterator()` after db is opened ([**@juliangruber**](https://github.com/juliangruber))
## [2.0.0-1] - 2015-05-28
No changes.
## [2.0.0-0] - 2015-05-27
### Changed
- Upgrade to `abstract-leveldown@2.4.0` for `.status` ([**@juliangruber**](https://github.com/juliangruber))
- Change api to `leveldown` api ([**@juliangruber**](https://github.com/juliangruber))
## [1.2.2] - 2017-07-30
### Added
- Add `4`, `6` and `7` to travis ([**@juliangruber**](https://github.com/juliangruber))
- Add `8` to travis ([**@ralphtheninja**](https://github.com/ralphtheninja))
### Changed
- Update `tape` and `abstract-leveldown` dependencies ([**@juliangruber**](https://github.com/juliangruber))
### Removed
- Remove `0.10` from travis ([**@juliangruber**](https://github.com/juliangruber))
## [1.2.1] - 2015-08-14
### Added
- Add `0.12`, `2.5` and `3.0` to travis ([**@juliangruber**](https://github.com/juliangruber))
### Removed
- Remove `0.8` and `0.11` from travis ([**@juliangruber**](https://github.com/juliangruber))
### Fixed
- Fix iterator after `setDb` case ([**@substack**](https://github.com/substack))
- Fix broken travis link ([**@juliangruber**](https://github.com/juliangruber))
## [1.2.0] - 2015-05-28
### Changed
- Upgrade to `abstract-leveldown@2.4.0` for `.status` ([**@juliangruber**](https://github.com/juliangruber))
## [1.1.0] - 2015-05-22
### Changed
- Export `DeferredIterator` ([**@juliangruber**](https://github.com/juliangruber))
## [1.0.0] - 2015-04-28
### Changed
- Upgrade to `abstract-leveldown@2.1.2` ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [0.3.0] - 2015-04-16
### Added
- Add support for deferred iterators ([**@juliangruber**](https://github.com/juliangruber))
### Changed
- Change to plain `MIT` license ([**@andrewrk**](https://github.com/andrewrk))
- Update logo and copyright ([**@ralphtheninja**](https://github.com/ralphtheninja))
## [0.2.0] - 2014-04-26
### Removed
- Remove `bops` and replace with `Buffer` ([**@rvagg**](https://github.com/rvagg))
## [0.1.0] - 2013-10-14
### Changed
- `location` passed to `AbstractLevelDOWN` constructor is optional ([**@rvagg**](https://github.com/rvagg))
### Removed
- Remove `npm-dl` badge ([**@rvagg**](https://github.com/rvagg))
### Fixed
- Fix broken travis badge ([**@rvagg**](https://github.com/rvagg))
- Fix links from `rvagg/` to `Level/` ([**@rvagg**](https://github.com/rvagg))
## [0.0.1] - 2013-09-30
### Added
- Add tests ([**@rvagg**](https://github.com/rvagg))
- Add node `0.10` and `0.11` to travis ([**@rvagg**](https://github.com/rvagg))
### Changed
- Update documentation ([**@rvagg**](https://github.com/rvagg))
## 0.0.0 - 2013-09-17
:seedling: First release. ([**@rvagg**](https://github.com/rvagg))
[5.3.0]: https://github.com/Level/deferred-leveldown/compare/v5.2.1...v5.3.0
[5.2.1]: https://github.com/Level/deferred-leveldown/compare/v5.2.0...v5.2.1
[5.2.0]: https://github.com/Level/deferred-leveldown/compare/v5.1.0...v5.2.0
[5.1.0]: https://github.com/Level/deferred-leveldown/compare/v5.0.1...v5.1.0
[5.0.1]: https://github.com/Level/deferred-leveldown/compare/v5.0.0...v5.0.1
[5.0.0]: https://github.com/Level/deferred-leveldown/compare/v4.0.2...v5.0.0
[4.0.2]: https://github.com/Level/deferred-leveldown/compare/v4.0.1...v4.0.2
[4.0.1]: https://github.com/Level/deferred-leveldown/compare/v4.0.0...v4.0.1
[4.0.0]: https://github.com/Level/deferred-leveldown/compare/v3.0.0...v4.0.0
[3.0.0]: https://github.com/Level/deferred-leveldown/compare/v2.0.3...v3.0.0
[2.0.3]: https://github.com/Level/deferred-leveldown/compare/v2.0.2...v2.0.3
[2.0.2]: https://github.com/Level/deferred-leveldown/compare/v2.0.1...v2.0.2
[2.0.1]: https://github.com/Level/deferred-leveldown/compare/v2.0.0...v2.0.1
[2.0.0]: https://github.com/Level/deferred-leveldown/compare/v2.0.0-2...v2.0.0
[2.0.0-2]: https://github.com/Level/deferred-leveldown/compare/v2.0.0-1...v2.0.0-2
[2.0.0-1]: https://github.com/Level/deferred-leveldown/compare/v2.0.0-0...v2.0.0-1
[2.0.0-0]: https://github.com/Level/deferred-leveldown/compare/v1.2.2...v2.0.0-0
[1.2.2]: https://github.com/Level/deferred-leveldown/compare/v1.2.1...v1.2.2
[1.2.1]: https://github.com/Level/deferred-leveldown/compare/v1.2.0...v1.2.1
[1.2.0]: https://github.com/Level/deferred-leveldown/compare/v1.1.0...v1.2.0
[1.1.0]: https://github.com/Level/deferred-leveldown/compare/v1.0.0...v1.1.0
[1.0.0]: https://github.com/Level/deferred-leveldown/compare/v0.3.0...v1.0.0
[0.3.0]: https://github.com/Level/deferred-leveldown/compare/v0.2.0...v0.3.0
[0.2.0]: https://github.com/Level/deferred-leveldown/compare/0.1.0...v0.2.0
[0.1.0]: https://github.com/Level/deferred-leveldown/compare/0.0.1...0.1.0
[0.0.1]: https://github.com/Level/deferred-leveldown/compare/0.0.0...0.0.1

10
node_modules/deferred-leveldown/CONTRIBUTORS.md generated vendored Normal file
View File

@@ -0,0 +1,10 @@
# 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) |
| **Rod Vagg** | [**@rvagg**](https://github.com/rvagg) | [**@rvagg@twitter**](https://twitter.com/rvagg) |
| **Meirion Hughes** | [**@MeirionHughes**](https://github.com/MeirionHughes) | |
| **Andrew Kelley** | [**@andrewrk**](https://github.com/andrewrk) | |

21
node_modules/deferred-leveldown/LICENSE.md generated vendored Normal file
View File

@@ -0,0 +1,21 @@
# The MIT License (MIT)
**Copyright © 2013-present Rod Vagg and [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.

62
node_modules/deferred-leveldown/README.md generated vendored Normal file
View File

@@ -0,0 +1,62 @@
# deferred-leveldown
> A mock `abstract-leveldown` implementation that queues operations while a real `abstract-leveldown` instance is being opened.
[![level badge][level-badge]](https://github.com/Level/awesome)
[![npm](https://img.shields.io/npm/v/deferred-leveldown.svg?label=&logo=npm)](https://www.npmjs.com/package/deferred-leveldown)
[![Node version](https://img.shields.io/node/v/deferred-leveldown.svg)](https://www.npmjs.com/package/deferred-leveldown)
[![Travis](https://img.shields.io/travis/Level/deferred-leveldown.svg?logo=travis&label=)](https://travis-ci.org/Level/deferred-leveldown)
[![Coverage Status](https://coveralls.io/repos/github/Level/deferred-leveldown/badge.svg)](https://coveralls.io/github/Level/deferred-leveldown)
[![JavaScript Style Guide](https://img.shields.io/badge/code_style-standard-brightgreen.svg)](https://standardjs.com)
[![npm](https://img.shields.io/npm/dm/deferred-leveldown.svg?label=dl)](https://www.npmjs.com/package/deferred-leveldown)
[![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)
`deferred-leveldown` implements the basic [abstract-leveldown](https://github.com/Level/abstract-leveldown) API so it can be used as a drop-in replacement where `leveldown` is needed.
`put()`, `get()`, `del()`, `batch()` and `clear()` operations are all queued and kept in memory until the `abstract-leveldown`-compatible object has been opened through `deferred-leveldown`'s `open()` method.
`batch()` operations will all be replayed as the array form. Chained-batch operations are converted before being stored.
```js
const deferred = require('deferred-leveldown')
const leveldown = require('leveldown')
const db = deferred(leveldown('location'))
db.put('foo', 'bar', function (err) {
})
db.open(function (err) {
// ...
})
```
**If you are upgrading:** please see [UPGRADING.md](UPGRADING.md).
## Contributing
[`Level/deferred-leveldown`](https://github.com/Level/deferred-leveldown) 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) © 2013-present Rod Vagg and [Contributors](CONTRIBUTORS.md).
[level-badge]: https://leveljs.org/img/badge.svg

19
node_modules/deferred-leveldown/UPGRADING.md generated vendored Normal file
View File

@@ -0,0 +1,19 @@
# 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).
## v5
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.
## v4
Dropped support for node 4. No other breaking changes.
## v3
#### `.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.

37
node_modules/deferred-leveldown/deferred-iterator.js generated vendored Normal file
View File

@@ -0,0 +1,37 @@
var AbstractIterator = require('abstract-leveldown').AbstractIterator
var inherits = require('inherits')
function DeferredIterator (db, options) {
AbstractIterator.call(this, db)
this._options = options
this._iterator = null
this._operations = []
}
inherits(DeferredIterator, AbstractIterator)
DeferredIterator.prototype.setDb = function (db) {
var it = this._iterator = db.iterator(this._options)
this._operations.forEach(function (op) {
it[op.method].apply(it, op.args)
})
}
DeferredIterator.prototype._operation = function (method, args) {
if (this._iterator) return this._iterator[method].apply(this._iterator, args)
this._operations.push({ method: method, args: args })
}
'next end'.split(' ').forEach(function (m) {
DeferredIterator.prototype['_' + m] = function () {
this._operation(m, arguments)
}
})
// Must defer seek() rather than _seek() because it requires db._serializeKey to be available
DeferredIterator.prototype.seek = function () {
this._operation('seek', arguments)
}
module.exports = DeferredIterator

97
node_modules/deferred-leveldown/deferred-leveldown.js generated vendored Normal file
View File

@@ -0,0 +1,97 @@
var AbstractLevelDOWN = require('abstract-leveldown').AbstractLevelDOWN
var inherits = require('inherits')
var DeferredIterator = require('./deferred-iterator')
var deferrables = 'put get del batch clear'.split(' ')
var optionalDeferrables = 'approximateSize compactRange'.split(' ')
function DeferredLevelDOWN (db) {
AbstractLevelDOWN.call(this, db.supports || {})
// TODO (future major): remove this fallback; db must have manifest that
// declares approximateSize and compactRange in additionalMethods.
optionalDeferrables.forEach(function (m) {
if (typeof db[m] === 'function' && !this.supports.additionalMethods[m]) {
this.supports.additionalMethods[m] = true
}
}, this)
this._db = db
this._operations = []
closed(this)
}
inherits(DeferredLevelDOWN, AbstractLevelDOWN)
DeferredLevelDOWN.prototype.type = 'deferred-leveldown'
DeferredLevelDOWN.prototype._open = function (options, callback) {
var self = this
this._db.open(options, function (err) {
if (err) return callback(err)
self._operations.forEach(function (op) {
if (op.iterator) {
op.iterator.setDb(self._db)
} else {
self._db[op.method].apply(self._db, op.args)
}
})
self._operations = []
open(self)
callback()
})
}
DeferredLevelDOWN.prototype._close = function (callback) {
var self = this
this._db.close(function (err) {
if (err) return callback(err)
closed(self)
callback()
})
}
function open (self) {
deferrables.concat('iterator').forEach(function (m) {
self['_' + m] = function () {
return this._db[m].apply(this._db, arguments)
}
})
Object.keys(self.supports.additionalMethods).forEach(function (m) {
self[m] = function () {
return this._db[m].apply(this._db, arguments)
}
})
}
function closed (self) {
deferrables.forEach(function (m) {
self['_' + m] = function () {
this._operations.push({ method: m, args: arguments })
}
})
Object.keys(self.supports.additionalMethods).forEach(function (m) {
self[m] = function () {
this._operations.push({ method: m, args: arguments })
}
})
self._iterator = function (options) {
var it = new DeferredIterator(self, options)
this._operations.push({ iterator: it })
return it
}
}
DeferredLevelDOWN.prototype._serializeKey = function (key) {
return key
}
DeferredLevelDOWN.prototype._serializeValue = function (value) {
return value
}
module.exports = DeferredLevelDOWN
module.exports.DeferredIterator = DeferredIterator

46
node_modules/deferred-leveldown/package.json generated vendored Normal file
View File

@@ -0,0 +1,46 @@
{
"name": "deferred-leveldown",
"version": "5.3.0",
"description": "For handling delayed-open on LevelDOWN compatible libraries",
"license": "MIT",
"main": "deferred-leveldown.js",
"scripts": {
"test": "standard && hallmark && nyc node test.js",
"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"
},
"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",
"reachdown": "^1.0.0",
"standard": "^14.0.0",
"tape": "^4.10.0"
},
"hallmark": {
"community": "level-community"
},
"repository": {
"type": "git",
"url": "https://github.com/Level/deferred-leveldown.git"
},
"homepage": "https://github.com/Level/deferred-leveldown",
"keywords": [
"leveldb",
"level",
"levelup",
"leveldown"
],
"engines": {
"node": ">=6"
}
}

566
node_modules/deferred-leveldown/test.js generated vendored Normal file
View File

@@ -0,0 +1,566 @@
var test = require('tape')
var reachdown = require('reachdown')
var memdown = require('memdown')
var suite = require('abstract-leveldown/test')
var DeferredLevelDOWN = require('./')
var noop = function () {}
const testCommon = suite.common({
test: test,
factory: function () {
return new DeferredLevelDOWN(memdown())
},
// Unsupported features
createIfMissing: false,
errorIfExists: false,
// Opt-in to new clear() tests
clear: true
})
// Hack: disable failing tests. These fail on serialize tests
require('abstract-leveldown/test/put-test').args = noop
require('abstract-leveldown/test/get-test').args = noop
require('abstract-leveldown/test/del-test').args = noop
// This fails on "iterator has db reference" test, as expected because
// the return value of db.iterator() depends on whether the db is open.
require('abstract-leveldown/test/iterator-test').args = noop
// Test abstract-leveldown compliance
suite(testCommon)
// Custom tests
test('deferred open gets correct options', function (t) {
var OPTIONS = { foo: 'BAR' }
var db = {
open: function (options, callback) {
t.same(options, OPTIONS, 'options passed on to open')
process.nextTick(callback)
}
}
var ld = new DeferredLevelDOWN(db)
ld.open(OPTIONS, function (err) {
t.error(err, 'no error')
t.end()
})
})
test('single operation', function (t) {
var called = false
var db = {
put: function (key, value, options, callback) {
t.equal(key, 'foo', 'correct key')
t.equal(value, 'bar', 'correct value')
t.deepEqual({}, options, 'empty options')
callback(null, 'called')
},
open: function (options, callback) {
process.nextTick(callback)
}
}
var ld = new DeferredLevelDOWN(db)
ld.put('foo', 'bar', function (err, v) {
t.error(err, 'no error')
called = v
})
t.ok(called === false, 'not called')
ld.open(function (err) {
t.error(err, 'no error')
t.ok(called === 'called', 'function called')
t.end()
})
})
test('many operations', function (t) {
var calls = []
var db = {
put: function (key, value, options, callback) {
if (puts++ === 0) {
t.equal(key, 'foo1', 'correct key')
t.equal(value, 'bar1', 'correct value')
t.deepEqual(options, {}, 'empty options')
} else {
t.equal(key, 'foo2', 'correct key')
t.equal(value, 'bar2', 'correct value')
t.deepEqual(options, {}, 'empty options')
}
callback(null, 'put' + puts)
},
get: function (key, options, callback) {
if (gets++ === 0) {
t.equal('woo1', key, 'correct key')
t.deepEqual(options, { asBuffer: true }, 'empty options')
} else {
t.equal('woo2', key, 'correct key')
t.deepEqual(options, { asBuffer: true }, 'empty options')
}
callback(null, 'gets' + gets)
},
del: function (key, options, callback) {
t.equal('blergh', key, 'correct key')
t.deepEqual(options, {}, 'empty options')
callback(null, 'del')
},
batch: function (arr, options, callback) {
if (batches++ === 0) {
t.deepEqual(arr, [
{ type: 'put', key: 'k1', value: 'v1' },
{ type: 'put', key: 'k2', value: 'v2' }
], 'correct batch')
} else {
t.deepEqual(arr, [
{ type: 'put', key: 'k3', value: 'v3' },
{ type: 'put', key: 'k4', value: 'v4' }
], 'correct batch')
}
callback()
},
clear: function (options, callback) {
if (clears++ === 0) {
t.deepEqual(options, { reverse: false, limit: -1 }, 'default options')
} else {
t.deepEqual(options, { gt: 'k5', reverse: false, limit: -1 }, 'range option')
}
callback()
},
open: function (options, callback) {
process.nextTick(callback)
}
}
var ld = new DeferredLevelDOWN(db)
var puts = 0
var gets = 0
var batches = 0
var clears = 0
ld.put('foo1', 'bar1', function (err, v) {
t.error(err, 'no error')
calls.push({ type: 'put', key: 'foo1', v: v })
})
ld.get('woo1', function (err, v) {
t.error(err, 'no error')
calls.push({ type: 'get', key: 'woo1', v: v })
})
ld.clear(function () {
calls.push({ type: 'clear' })
})
ld.put('foo2', 'bar2', function (err, v) {
t.error(err, 'no error')
calls.push({ type: 'put', key: 'foo2', v: v })
})
ld.get('woo2', function (err, v) {
t.error(err, 'no error')
calls.push({ type: 'get', key: 'woo2', v: v })
})
ld.del('blergh', function (err, v) {
t.error(err, 'no error')
calls.push({ type: 'del', key: 'blergh', v: v })
})
ld.batch([
{ type: 'put', key: 'k1', value: 'v1' },
{ type: 'put', key: 'k2', value: 'v2' }
], function () {
calls.push({ type: 'batch', keys: 'k1,k2' })
})
ld
.batch()
.put('k3', 'v3')
.put('k4', 'v4')
.write(function () {
calls.push({ type: 'batch', keys: 'k3,k4' })
})
ld.clear({ gt: 'k5' }, function () {
calls.push({ type: 'clear', gt: 'k5' })
})
t.ok(calls.length === 0, 'not called')
ld.open(function (err) {
t.error(err, 'no error')
t.equal(calls.length, 9, 'all functions called')
t.deepEqual(calls, [
{ type: 'put', key: 'foo1', v: 'put1' },
{ type: 'get', key: 'woo1', v: 'gets1' },
{ type: 'clear' },
{ type: 'put', key: 'foo2', v: 'put2' },
{ type: 'get', key: 'woo2', v: 'gets2' },
{ type: 'del', key: 'blergh', v: 'del' },
{ type: 'batch', keys: 'k1,k2' },
{ type: 'batch', keys: 'k3,k4' },
{ type: 'clear', gt: 'k5' }
], 'calls correctly behaved')
t.end()
})
})
test('keys and values should not be serialized', function (t) {
var DATA = []
var ITEMS = [
123,
'a string',
Buffer.from('w00t'),
{ an: 'object' }
]
ITEMS.forEach(function (k) {
ITEMS.forEach(function (v) {
DATA.push({ key: k, value: v })
})
})
function Db (m, fn) {
var db = {
open: function (options, cb) {
process.nextTick(cb)
}
}
var wrapper = function () {
fn.apply(null, arguments)
}
db[m] = wrapper
return new DeferredLevelDOWN(db)
}
function noop () {}
t.plan(8)
t.test('put', function (t) {
var calls = []
var ld = Db('put', function (key, value, cb) {
calls.push({ key: key, value: value })
})
DATA.forEach(function (d) { ld.put(d.key, d.value, noop) })
ld.open(function (err) {
t.error(err, 'no error')
t.same(calls, DATA, 'value ok')
t.end()
})
})
t.test('get', function (t) {
var calls = []
var ld = Db('get', function (key, cb) { calls.push(key) })
ITEMS.forEach(function (key) { ld.get(key, noop) })
ld.open(function (err) {
t.error(err, 'no error')
t.same(calls, ITEMS, 'value ok')
t.end()
})
})
t.test('del', function (t) {
var calls = []
var ld = Db('del', function (key, cb) { calls.push(key) })
ITEMS.forEach(function (key) { ld.del(key, noop) })
ld.open(function (err) {
t.error(err, 'no error')
t.same(calls, ITEMS, 'value ok')
t.end()
})
})
t.test('clear', function (t) {
var calls = []
var ld = Db('clear', function (opts, cb) { calls.push(opts) })
ITEMS.forEach(function (key) { ld.clear({ gt: key }, noop) })
ld.open(function (err) {
t.error(err, 'no error')
t.same(calls, ITEMS.map(function (key) {
return { gt: key, reverse: false, limit: -1 }
}), 'value ok')
t.end()
})
})
t.test('approximateSize', function (t) {
var calls = []
var ld = Db('approximateSize', function (start, end, cb) {
calls.push({ start: start, end: end })
})
ITEMS.forEach(function (key) { ld.approximateSize(key, key, noop) })
ld.open(function (err) {
t.error(err, 'no error')
t.same(calls, ITEMS.map(function (i) {
return { start: i, end: i }
}), 'value ok')
t.end()
})
})
t.test('store not supporting approximateSize', function (t) {
var ld = Db('FOO', function () {})
t.throws(function () {
ld.approximateSize('key', 'key', noop)
}, /approximateSize is not a function/)
t.end()
})
t.test('compactRange', function (t) {
var calls = []
var ld = Db('compactRange', function (start, end, cb) {
calls.push({ start: start, end: end })
})
ITEMS.forEach(function (key) { ld.compactRange(key, key, noop) })
ld.open(function (err) {
t.error(err, 'no error')
t.same(calls, ITEMS.map(function (i) {
return { start: i, end: i }
}), 'value ok')
t.end()
})
})
t.test('store not supporting compactRange', function (t) {
var ld = Db('FOO', function () {})
t.throws(function () {
ld.compactRange('key', 'key', noop)
}, /compactRange is not a function/)
t.end()
})
})
test('_close calls close for underlying store', function (t) {
t.plan(2)
var db = {
close: function (callback) {
t.pass('close for underlying store is called')
process.nextTick(callback)
}
}
var ld = new DeferredLevelDOWN(db)
ld.close(function (err) {
t.error(err, 'no error')
})
})
test('open error on underlying store calls back with error', function (t) {
t.plan(2)
var db = {
open: function (options, callback) {
t.pass('db.open called')
process.nextTick(callback, new Error('foo'))
}
}
var ld = new DeferredLevelDOWN(db)
ld.open(function (err) {
t.is(err.message, 'foo')
})
})
test('close error on underlying store calls back with error', function (t) {
t.plan(2)
var db = {
close: function (callback) {
t.pass('db.close called')
process.nextTick(callback, new Error('foo'))
}
}
var ld = new DeferredLevelDOWN(db)
ld.close(function (err) {
t.is(err.message, 'foo')
})
})
test('non-deferred approximateSize', function (t) {
t.plan(4)
var db = {
open: function (options, cb) {
process.nextTick(cb)
},
approximateSize: function (start, end, callback) {
t.is(start, 'bar')
t.is(end, 'foo')
process.nextTick(callback)
}
}
var ld = new DeferredLevelDOWN(db)
ld.open(function (err) {
t.error(err)
ld.approximateSize('bar', 'foo', function (err) {
t.error(err)
})
})
})
test('non-deferred compactRange', function (t) {
t.plan(4)
var db = {
open: function (options, cb) {
process.nextTick(cb)
},
compactRange: function (start, end, callback) {
t.is(start, 'bar')
t.is(end, 'foo')
process.nextTick(callback)
}
}
var ld = new DeferredLevelDOWN(db)
ld.open(function (err) {
t.error(err)
ld.compactRange('bar', 'foo', function (err) {
t.error(err)
})
})
})
test('iterator - deferred operations', function (t) {
t.plan(9)
var seekTarget = false
var db = {
iterator: function (options) {
return {
seek: function (target) {
seekTarget = target
},
next: function (cb) {
cb(null, 'key', 'value')
},
end: function (cb) {
process.nextTick(cb)
}
}
},
open: function (options, callback) {
process.nextTick(callback)
}
}
var ld = new DeferredLevelDOWN(db)
var it = ld.iterator()
var nextFirst = false
it.seek('foo')
it.next(function (err, key, value) {
t.is(seekTarget, 'foo', 'seek was called with correct target')
nextFirst = true
t.error(err, 'no error')
t.equal(key, 'key')
t.equal(value, 'value')
})
it.end(function (err) {
t.error(err, 'no error')
t.ok(nextFirst)
})
ld.open(function (err) {
t.error(err, 'no error')
var it2 = ld.iterator()
it2.end(t.error.bind(t))
})
t.ok(require('./').DeferredIterator)
})
test('iterator - non deferred operation', function (t) {
t.plan(5)
var seekTarget = false
var db = {
iterator: function (options) {
return {
next: function (cb) {
cb(null, 'key', 'value')
},
seek: function (target) {
seekTarget = target
},
end: function (cb) {
process.nextTick(cb)
}
}
},
open: function (options, callback) {
process.nextTick(callback)
}
}
var ld = new DeferredLevelDOWN(db)
var it = ld.iterator()
ld.open(function (err) {
t.error(err, 'no error')
it.seek('foo')
t.is(seekTarget, 'foo', 'seek was called with correct target')
it.next(function (err, key, value) {
t.error(err, 'no error')
t.equal(key, 'key')
t.equal(value, 'value')
})
})
})
test('iterator - is created in order', function (t) {
t.plan(4)
function db () {
return {
order: [],
iterator: function (options) {
this.order.push('iterator created')
return {}
},
put: function (key, value, options, callback) {
this.order.push('put')
},
open: function (options, callback) {
process.nextTick(callback)
}
}
}
var ld1 = new DeferredLevelDOWN(db())
var ld2 = new DeferredLevelDOWN(db())
ld1.iterator()
ld1.put('key', 'value', noop)
ld2.put('key', 'value', noop)
ld2.iterator()
ld1.open(function (err) {
t.error(err, 'no error')
t.same(ld1._db.order, ['iterator created', 'put'])
})
ld2.open(function (err) {
t.error(err, 'no error')
t.same(ld2._db.order, ['put', 'iterator created'])
})
})
test('reachdown supports deferred-leveldown', function (t) {
// Define just enough methods for reachdown to see this as a real db
var db = { open: noop, _batch: noop, _iterator: noop }
var ld = new DeferredLevelDOWN(db)
t.is(ld.type, 'deferred-leveldown')
t.is(reachdown(ld, 'deferred-leveldown'), ld)
t.is(reachdown(ld), db)
t.end()
})