fix: Resolve TypeScript errors
Signed-off-by: Hermes Agent <hermes@nosuchhost>
This commit is contained in:
189
client/node_modules/level-iterator-stream/CHANGELOG.md
generated
vendored
Normal file
189
client/node_modules/level-iterator-stream/CHANGELOG.md
generated
vendored
Normal file
@@ -0,0 +1,189 @@
|
||||
# Changelog
|
||||
|
||||
_**If you are upgrading:** please see [`UPGRADING.md`](UPGRADING.md)._
|
||||
|
||||
## [4.0.2] - 2019-10-05
|
||||
|
||||
### Changed
|
||||
|
||||
- Upgrade `hallmark` devDependency from `^0.1.0` to `^2.0.0` ([#58](https://github.com/Level/iterator-stream/issues/58), [#61](https://github.com/Level/iterator-stream/issues/61)) ([**@vweevers**](https://github.com/vweevers))
|
||||
- Upgrade `standard` devDependency from `^12.0.0` to `^14.0.0` ([#57](https://github.com/Level/iterator-stream/issues/57), [#60](https://github.com/Level/iterator-stream/issues/60)) ([**@vweevers**](https://github.com/vweevers))
|
||||
- Upgrade `nyc` devDependency from `^13.2.0` to `^14.0.0` ([#55](https://github.com/Level/iterator-stream/issues/55)) ([**@vweevers**](https://github.com/vweevers))
|
||||
- Tweak tests ([#62](https://github.com/Level/iterator-stream/issues/62)) ([**@vweevers**](https://github.com/vweevers))
|
||||
|
||||
### Added
|
||||
|
||||
- Test that stream keeps a reference to the iterator ([`16a4dd5`](https://github.com/Level/iterator-stream/commit/16a4dd5)) ([**@vweevers**](https://github.com/vweevers))
|
||||
|
||||
## [4.0.1] - 2019-03-30
|
||||
|
||||
### Changed
|
||||
|
||||
- Upgrade `leveldown` devDependency from `^4.0.0` to `^5.0.0` ([#52](https://github.com/Level/iterator-stream/issues/52)) ([**@vweevers**](https://github.com/vweevers))
|
||||
- Upgrade `nyc` devDependency from `^12.0.2` to `^13.2.0` ([#51](https://github.com/Level/iterator-stream/issues/51)) ([**@vweevers**](https://github.com/vweevers))
|
||||
- Apply common project tweaks ([#49](https://github.com/Level/iterator-stream/issues/49), [#50](https://github.com/Level/iterator-stream/issues/50), [`fece33a`](https://github.com/Level/iterator-stream/commit/fece33a), [`b3b3b6c`](https://github.com/Level/iterator-stream/commit/b3b3b6c)) ([**@vweevers**](https://github.com/vweevers))
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix reference to undefined definition in `CHANGELOG.md` ([`aa88961`](https://github.com/Level/iterator-stream/commit/aa88961)) ([**@vweevers**](https://github.com/vweevers))
|
||||
|
||||
## [4.0.0] - 2018-12-17
|
||||
|
||||
### Changed
|
||||
|
||||
- Upgrade `through2` devDependency from `^2.0.0` to `^3.0.0` ([**@vweevers**](https://github.com/vweevers))
|
||||
- Upgrade `readable-stream` dependency from `^2.0.5` to `^3.0.2` ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
- Upgrade `standard` devDependency from `^11.0.0` to `^12.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
|
||||
### Added
|
||||
|
||||
- Add `nyc` and `coveralls` ([#39](https://github.com/Level/iterator-stream/issues/39)) ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
|
||||
### Removed
|
||||
|
||||
- Remove node 9 ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
|
||||
## [3.0.1] - 2018-10-18
|
||||
|
||||
### Fixed
|
||||
|
||||
- Bump `readable-stream` from `^2.0` to `^2.3` to prevent npm dedupe and ensure it has `#destroy()` ([**@vweevers**](https://github.com/vweevers))
|
||||
|
||||
## [3.0.0] - 2018-06-28
|
||||
|
||||
### Changed
|
||||
|
||||
- Proper destroy ([#34](https://github.com/Level/iterator-stream/issues/34)) ([**@vweevers**](https://github.com/vweevers))
|
||||
|
||||
### Removed
|
||||
|
||||
- Remove node 4 ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
|
||||
## [2.0.3] - 2018-06-28
|
||||
|
||||
### Fixed
|
||||
|
||||
- Revert proper destroy ([#34](https://github.com/Level/iterator-stream/issues/34)) ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
|
||||
**Historical Note** The previous release was meant to restore node 4 and included an additional change by mistake.
|
||||
|
||||
## [2.0.2] - 2018-06-28
|
||||
|
||||
### Changed
|
||||
|
||||
- Restore node 4 ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
- Proper destroy ([#34](https://github.com/Level/iterator-stream/issues/34)) ([**@vweevers**](https://github.com/vweevers))
|
||||
|
||||
**Historical Note** We made a mistake releasing `v2.0.1` with the `engines` field in `package.json` set to node 6 as minimal version. This caused problems for users of yarn. We therefore released `v2.0.2` which restored node 4 and a new major directly after this.
|
||||
|
||||
## [2.0.1] - 2018-06-10
|
||||
|
||||
### Changed
|
||||
|
||||
- Upgrade `leveldown` devDependency from `^1.4.1` to `^4.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
- Upgrade `standard` devDependency from `^10.0.3` to `^11.0.0` ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
|
||||
### Added
|
||||
|
||||
- Add node 9 and 10 to Travis ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
- Add `UPGRADING.md` ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
|
||||
### Removed
|
||||
|
||||
- Remove node 7 from Travis ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
|
||||
## [2.0.0] - 2017-08-28
|
||||
|
||||
### Changed
|
||||
|
||||
- Upgrade `readable-stream` from `^1.0.33` to `^2.0.5` ([**@greenkeeper**](https://github.com/greenkeeper), [**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
- Upgrade `tape` devDependency from `^3.5.0` to `^4.4.0` ([**@greenkeeper**](https://github.com/greenkeeper), [**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
- Upgrade `through2` devDependency from `^0.6.3` to `^2.0.0` ([**@greenkeeper**](https://github.com/greenkeeper), [**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
- Upgrade `leveldown` devDependency from `^0.10.4` to `^1.4.1` ([**@juliangruber**](https://github.com/juliangruber))
|
||||
- Update copyright year to 2017 ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
- Update README example using `standard` ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
|
||||
### Added
|
||||
|
||||
- Add node 6 to Travis ([**@greenkeeper**](https://github.com/greenkeeper), [**@juliangruber**](https://github.com/juliangruber))
|
||||
- Add node 7 and 8 to Travis ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
- Add Greenkeeper ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
- Add `standard` ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
- Test `.destroy()` during and after `iterator.next()` ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
|
||||
### Removed
|
||||
|
||||
- Remove node 0.10, 0.12 and iojs from Travis ([**@greenkeeper**](https://github.com/greenkeeper), [**@juliangruber**](https://github.com/juliangruber))
|
||||
- Remove encodings ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
- Remove Makefile ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
|
||||
## [1.3.1] - 2015-08-17
|
||||
|
||||
### Changed
|
||||
|
||||
- Update `.repository` path in `package.json` ([**@timoxley**](https://github.com/timoxley))
|
||||
|
||||
### Fixed
|
||||
|
||||
- Use `level-codec` from npm ([**@juliangruber**](https://github.com/juliangruber))
|
||||
|
||||
## [1.3.0] - 2015-05-05
|
||||
|
||||
### Fixed
|
||||
|
||||
- Emit `'close'` after `'error'` ([**@juliangruber**](https://github.com/juliangruber))
|
||||
|
||||
## [1.2.0] - 2015-05-04
|
||||
|
||||
### Added
|
||||
|
||||
- Add `.decoder` option to constructor for decoding keys and values ([**@juliangruber**](https://github.com/juliangruber))
|
||||
|
||||
## [1.1.1] - 2015-03-29
|
||||
|
||||
### Added
|
||||
|
||||
- Enable Travis and add node 0.10, 0.12 and iojs ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
- Add MIT license ([**@ralphtheninja**](https://github.com/ralphtheninja))
|
||||
|
||||
### Fixed
|
||||
|
||||
- Fix race condition in `.destroy()` ([**@juliangruber**](https://github.com/juliangruber))
|
||||
|
||||
## [1.1.0] - 2015-03-29
|
||||
|
||||
### Added
|
||||
|
||||
- Add `.destroy()` ([**@juliangruber**](https://github.com/juliangruber))
|
||||
|
||||
## 1.0.0 - 2015-03-29
|
||||
|
||||
:seedling: Initial release.
|
||||
|
||||
[4.0.2]: https://github.com/Level/iterator-stream/compare/v4.0.1...v4.0.2
|
||||
|
||||
[4.0.1]: https://github.com/Level/iterator-stream/compare/v4.0.0...v4.0.1
|
||||
|
||||
[4.0.0]: https://github.com/Level/iterator-stream/compare/v3.0.1...v4.0.0
|
||||
|
||||
[3.0.1]: https://github.com/Level/iterator-stream/compare/v3.0.0...v3.0.1
|
||||
|
||||
[3.0.0]: https://github.com/Level/iterator-stream/compare/v2.0.3...v3.0.0
|
||||
|
||||
[2.0.3]: https://github.com/Level/iterator-stream/compare/v2.0.2...v2.0.3
|
||||
|
||||
[2.0.2]: https://github.com/Level/iterator-stream/compare/v2.0.1...v2.0.2
|
||||
|
||||
[2.0.1]: https://github.com/Level/iterator-stream/compare/v2.0.0...v2.0.1
|
||||
|
||||
[2.0.0]: https://github.com/Level/iterator-stream/compare/v1.3.1...v2.0.0
|
||||
|
||||
[1.3.1]: https://github.com/Level/iterator-stream/compare/v1.3.0...v1.3.1
|
||||
|
||||
[1.3.0]: https://github.com/Level/iterator-stream/compare/v1.2.0...v1.3.0
|
||||
|
||||
[1.2.0]: https://github.com/Level/iterator-stream/compare/v1.1.1...v1.2.0
|
||||
|
||||
[1.1.1]: https://github.com/Level/iterator-stream/compare/v1.1.0...v1.1.1
|
||||
|
||||
[1.1.0]: https://github.com/Level/iterator-stream/compare/v1.0.0...v1.1.0
|
||||
8
client/node_modules/level-iterator-stream/CONTRIBUTORS.md
generated
vendored
Normal file
8
client/node_modules/level-iterator-stream/CONTRIBUTORS.md
generated
vendored
Normal file
@@ -0,0 +1,8 @@
|
||||
# Contributors
|
||||
|
||||
| Name | GitHub | Social |
|
||||
| :------------------- | :----------------------------------------------------- | :------------------------------------------------------------ |
|
||||
| **Lars-Magnus Skog** | [**@ralphtheninja**](https://github.com/ralphtheninja) | [**@ralph@social.weho.st**](https://social.weho.st/@ralph) |
|
||||
| **Julian Gruber** | [**@juliangruber**](https://github.com/juliangruber) | [**@juliangruber@twitter**](https://twitter.com/juliangruber) |
|
||||
| **Vincent Weevers** | [**@vweevers**](https://github.com/vweevers) | [**@vweevers@twitter**](https://twitter.com/vweevers) |
|
||||
| **Tim Oxley** | [**@timoxley**](https://github.com/timoxley) | [**@secoif@twitter**](https://twitter.com/secoif) |
|
||||
21
client/node_modules/level-iterator-stream/LICENSE.md
generated
vendored
Normal file
21
client/node_modules/level-iterator-stream/LICENSE.md
generated
vendored
Normal 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.
|
||||
76
client/node_modules/level-iterator-stream/README.md
generated
vendored
Normal file
76
client/node_modules/level-iterator-stream/README.md
generated
vendored
Normal file
@@ -0,0 +1,76 @@
|
||||
# level-iterator-stream
|
||||
|
||||
> Turn an [abstract-leveldown](https://github.com/Level/abstract-leveldown) iterator into a readable stream.
|
||||
|
||||
[![level badge][level-badge]](https://github.com/Level/awesome)
|
||||
[](https://www.npmjs.com/package/level-iterator-stream)
|
||||
[](https://www.npmjs.com/package/level-iterator-stream)
|
||||
[](https://travis-ci.com/Level/iterator-stream)
|
||||
[](https://coveralls.io/github/Level/iterator-stream)
|
||||
[](https://standardjs.com)
|
||||
[](https://www.npmjs.com/package/level-iterator-stream)
|
||||
[](#backers)
|
||||
[](#sponsors)
|
||||
|
||||
## Usage
|
||||
|
||||
**If you are upgrading:** please see [UPGRADING.md](UPGRADING.md).
|
||||
|
||||
```js
|
||||
var iteratorStream = require('level-iterator-stream')
|
||||
var leveldown = require('leveldown')
|
||||
|
||||
var db = leveldown(__dirname + '/db')
|
||||
db.open(function (err) {
|
||||
if (err) throw err
|
||||
|
||||
var stream = iteratorStream(db.iterator())
|
||||
stream.on('data', function (kv) {
|
||||
console.log('%s -> %s', kv.key, kv.value)
|
||||
})
|
||||
})
|
||||
```
|
||||
|
||||
## Installation
|
||||
|
||||
```bash
|
||||
$ npm install level-iterator-stream
|
||||
```
|
||||
|
||||
## API
|
||||
|
||||
### `stream = iteratorStream(iterator[, options])`
|
||||
|
||||
Create a readable stream from `iterator`. `options` are passed down to the `require('readable-stream').Readable` constructor, with `objectMode` forced to `true`.
|
||||
|
||||
Set `options.keys` or `options.values` to `false` to only get values / keys. Otherwise receive `{ key, value }` objects.
|
||||
|
||||
When the stream ends, the `iterator` will be closed and afterwards a `"close"` event emitted.
|
||||
|
||||
`.destroy()` will force close the underlying iterator.
|
||||
|
||||
## Contributing
|
||||
|
||||
[`Level/iterator-stream`](https://github.com/Level/iterator-stream) 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
|
||||
|
||||
[](https://opencollective.com/level)
|
||||
|
||||
### Sponsors
|
||||
|
||||
[](https://opencollective.com/level)
|
||||
|
||||
## License
|
||||
|
||||
[MIT](LICENSE.md) © 2012-present [Contributors](CONTRIBUTORS.md).
|
||||
|
||||
[level-badge]: https://leveljs.org/img/badge.svg
|
||||
22
client/node_modules/level-iterator-stream/UPGRADING.md
generated
vendored
Normal file
22
client/node_modules/level-iterator-stream/UPGRADING.md
generated
vendored
Normal file
@@ -0,0 +1,22 @@
|
||||
# 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).
|
||||
|
||||
## v4
|
||||
|
||||
Upgraded to [`readable-stream@3`](https://github.com/nodejs/readable-stream#version-3xx) which contains several substantial changes and improvements. Since `level-iterator-stream` derives from `readable-stream` we decided to bump major as well.
|
||||
|
||||
## v3
|
||||
|
||||
Removed support for node 4.
|
||||
|
||||
## v2
|
||||
|
||||
Encodings were factored out from `levelup` into `encoding-down` and in that process they were removed from this module as well. For more information, please check the corresponding `CHANGELOG.md` for:
|
||||
|
||||
- [`levelup`](https://github.com/Level/levelup/blob/master/CHANGELOG.md)
|
||||
- [`encoding-down`](https://github.com/Level/encoding-down/blob/master/CHANGELOG.md)
|
||||
|
||||
If your code relies on `options.decoder` for decoding keys and values you need to handle this yourself, e.g. by a transform stream or similar.
|
||||
|
||||
Support for node 0.10, 0.12 and iojs was also dropped.
|
||||
26
client/node_modules/level-iterator-stream/example.js
generated
vendored
Normal file
26
client/node_modules/level-iterator-stream/example.js
generated
vendored
Normal file
@@ -0,0 +1,26 @@
|
||||
var iteratorStream = require('./')
|
||||
var leveldown = require('leveldown')
|
||||
var path = require('path')
|
||||
|
||||
var db = leveldown(path.join(__dirname, 'db'))
|
||||
db.open(function (err) {
|
||||
if (err) throw err
|
||||
|
||||
var ops = []
|
||||
for (var i = 0; i < 1000; i++) {
|
||||
ops.push({
|
||||
type: 'put',
|
||||
key: String(Math.random()),
|
||||
value: String(Math.random())
|
||||
})
|
||||
}
|
||||
|
||||
db.batch(ops, function (err) {
|
||||
if (err) throw err
|
||||
|
||||
var stream = iteratorStream(db.iterator())
|
||||
stream.on('data', function (kv) {
|
||||
console.log('%s -> %s', kv.key, kv.value)
|
||||
})
|
||||
})
|
||||
})
|
||||
44
client/node_modules/level-iterator-stream/index.js
generated
vendored
Normal file
44
client/node_modules/level-iterator-stream/index.js
generated
vendored
Normal file
@@ -0,0 +1,44 @@
|
||||
var inherits = require('inherits')
|
||||
var Readable = require('readable-stream').Readable
|
||||
var extend = require('xtend')
|
||||
|
||||
module.exports = ReadStream
|
||||
inherits(ReadStream, Readable)
|
||||
|
||||
function ReadStream (iterator, options) {
|
||||
if (!(this instanceof ReadStream)) return new ReadStream(iterator, options)
|
||||
options = options || {}
|
||||
Readable.call(this, extend(options, {
|
||||
objectMode: true
|
||||
}))
|
||||
this._iterator = iterator
|
||||
this._options = options
|
||||
this.on('end', this.destroy.bind(this, null, null))
|
||||
}
|
||||
|
||||
ReadStream.prototype._read = function () {
|
||||
var self = this
|
||||
var options = this._options
|
||||
if (this.destroyed) return
|
||||
|
||||
this._iterator.next(function (err, key, value) {
|
||||
if (self.destroyed) return
|
||||
if (err) return self.destroy(err)
|
||||
|
||||
if (key === undefined && value === undefined) {
|
||||
self.push(null)
|
||||
} else if (options.keys !== false && options.values === false) {
|
||||
self.push(key)
|
||||
} else if (options.keys === false && options.values !== false) {
|
||||
self.push(value)
|
||||
} else {
|
||||
self.push({ key: key, value: value })
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
ReadStream.prototype._destroy = function (err, callback) {
|
||||
this._iterator.end(function (err2) {
|
||||
callback(err || err2)
|
||||
})
|
||||
}
|
||||
48
client/node_modules/level-iterator-stream/package.json
generated
vendored
Normal file
48
client/node_modules/level-iterator-stream/package.json
generated
vendored
Normal file
@@ -0,0 +1,48 @@
|
||||
{
|
||||
"name": "level-iterator-stream",
|
||||
"version": "4.0.2",
|
||||
"description": "Turn an abstract-leveldown iterator into a readable stream",
|
||||
"license": "MIT",
|
||||
"scripts": {
|
||||
"test": "standard && hallmark && (nyc -s node test.js | faucet) && nyc report",
|
||||
"coverage": "nyc report --reporter=text-lcov | coveralls",
|
||||
"hallmark": "hallmark --fix",
|
||||
"dependency-check": "dependency-check . test.js",
|
||||
"prepublishOnly": "npm run dependency-check"
|
||||
},
|
||||
"dependencies": {
|
||||
"inherits": "^2.0.4",
|
||||
"readable-stream": "^3.4.0",
|
||||
"xtend": "^4.0.2"
|
||||
},
|
||||
"devDependencies": {
|
||||
"coveralls": "^3.0.2",
|
||||
"dependency-check": "^3.3.0",
|
||||
"faucet": "^0.0.1",
|
||||
"hallmark": "^2.0.0",
|
||||
"level-community": "^3.0.0",
|
||||
"leveldown": "^5.0.0",
|
||||
"nyc": "^14.0.0",
|
||||
"secret-event-listener": "^1.0.0",
|
||||
"standard": "^14.0.0",
|
||||
"tape": "^4.4.0",
|
||||
"tempy": "0.2.1",
|
||||
"through2": "^3.0.0"
|
||||
},
|
||||
"hallmark": {
|
||||
"community": "level-community"
|
||||
},
|
||||
"repository": "Level/iterator-stream",
|
||||
"homepage": "https://github.com/Level/iterator-stream",
|
||||
"keywords": [
|
||||
"level"
|
||||
],
|
||||
"engines": {
|
||||
"node": ">=6"
|
||||
},
|
||||
"greenkeeper": {
|
||||
"ignore": [
|
||||
"tempy"
|
||||
]
|
||||
}
|
||||
}
|
||||
371
client/node_modules/level-iterator-stream/test.js
generated
vendored
Normal file
371
client/node_modules/level-iterator-stream/test.js
generated
vendored
Normal file
@@ -0,0 +1,371 @@
|
||||
var test = require('tape')
|
||||
var leveldown = require('leveldown')
|
||||
var iteratorStream = require('./')
|
||||
var through2 = require('through2')
|
||||
var tempy = require('tempy')
|
||||
var addSecretListener = require('secret-event-listener')
|
||||
|
||||
var db
|
||||
var data = [
|
||||
{ type: 'put', key: 'foobatch1', value: 'bar1' },
|
||||
{ type: 'put', key: 'foobatch2', value: 'bar2' },
|
||||
{ type: 'put', key: 'foobatch3', value: 'bar3' }
|
||||
]
|
||||
|
||||
test('setup', function (t) {
|
||||
db = leveldown(tempy.directory())
|
||||
db.open(function (err) {
|
||||
t.error(err, 'no error')
|
||||
db.batch(data, function (err) {
|
||||
t.error(err, 'no error')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
test('keys and values', function (t) {
|
||||
var idx = 0
|
||||
var stream = iteratorStream(db.iterator())
|
||||
stream.pipe(through2.obj(function (kv, _, done) {
|
||||
t.ok(Buffer.isBuffer(kv.key))
|
||||
t.ok(Buffer.isBuffer(kv.value))
|
||||
t.equal(kv.key.toString(), data[idx].key)
|
||||
t.equal(kv.value.toString(), data[idx].value)
|
||||
idx++
|
||||
done()
|
||||
}, function () {
|
||||
t.equal(idx, data.length)
|
||||
stream.on('close', function () {
|
||||
t.end()
|
||||
})
|
||||
}))
|
||||
})
|
||||
|
||||
test('normal event order', function (t) {
|
||||
var iterator = db.iterator()
|
||||
var stream = iteratorStream(iterator)
|
||||
|
||||
var order = monitor(iterator, stream, function () {
|
||||
t.same(order.filter(withoutDataEvents), ['_end', 'end', 'close'])
|
||||
t.end()
|
||||
})
|
||||
|
||||
stream.resume()
|
||||
})
|
||||
|
||||
test('error from iterator.next', function (t) {
|
||||
var iterator = db.iterator()
|
||||
var stream = iteratorStream(iterator)
|
||||
|
||||
var order = monitor(iterator, stream, function () {
|
||||
t.same(order, ['_end', 'error: next', 'close'], 'event order')
|
||||
t.end()
|
||||
})
|
||||
|
||||
iterator.next = function (cb) {
|
||||
process.nextTick(cb, new Error('next'))
|
||||
}
|
||||
|
||||
stream.resume()
|
||||
})
|
||||
|
||||
test('error from iterator end', function (t) {
|
||||
var iterator = db.iterator()
|
||||
var stream = iteratorStream(iterator)
|
||||
var _end = iterator._end
|
||||
|
||||
var order = monitor(iterator, stream, function () {
|
||||
t.same(order.filter(withoutDataEvents), ['_end', 'end', 'error: end', 'close'])
|
||||
t.end()
|
||||
})
|
||||
|
||||
iterator._end = function (cb) {
|
||||
order.push('_end')
|
||||
_end.call(this, function (err) {
|
||||
t.ifError(err)
|
||||
cb(new Error('end'))
|
||||
})
|
||||
}
|
||||
|
||||
stream.resume()
|
||||
})
|
||||
|
||||
test('.destroy', function (t) {
|
||||
var iterator = db.iterator()
|
||||
var stream = iteratorStream(iterator)
|
||||
|
||||
var order = monitor(iterator, stream, function () {
|
||||
t.same(order, ['_end', 'close'])
|
||||
t.end()
|
||||
})
|
||||
|
||||
stream.destroy()
|
||||
})
|
||||
|
||||
test('.destroy(err)', function (t) {
|
||||
var iterator = db.iterator()
|
||||
var stream = iteratorStream(iterator)
|
||||
|
||||
var order = monitor(iterator, stream, function () {
|
||||
t.same(order, ['_end', 'error: user', 'close'])
|
||||
t.end()
|
||||
})
|
||||
|
||||
stream.destroy(new Error('user'))
|
||||
})
|
||||
|
||||
test('.destroy(err, callback)', function (t) {
|
||||
var iterator = db.iterator()
|
||||
var stream = iteratorStream(iterator)
|
||||
|
||||
var order = monitor(iterator, stream, function () {
|
||||
t.same(order, ['_end', 'callback', 'close'])
|
||||
t.end()
|
||||
})
|
||||
|
||||
stream.destroy(new Error('user'), function (err) {
|
||||
order.push('callback')
|
||||
t.is(err.message, 'user', 'got error')
|
||||
})
|
||||
})
|
||||
|
||||
test('.destroy(null, callback)', function (t) {
|
||||
var iterator = db.iterator()
|
||||
var stream = iteratorStream(iterator)
|
||||
|
||||
var order = monitor(iterator, stream, function () {
|
||||
t.same(order, ['_end', 'callback', 'close'])
|
||||
t.end()
|
||||
})
|
||||
|
||||
stream.destroy(null, function (err) {
|
||||
order.push('callback')
|
||||
t.ifError(err, 'no error')
|
||||
})
|
||||
})
|
||||
|
||||
test('.destroy() during iterator.next', function (t) {
|
||||
var iterator = db.iterator()
|
||||
var stream = iteratorStream(iterator)
|
||||
|
||||
var order = monitor(iterator, stream, function () {
|
||||
t.same(order, ['_end', 'close'], 'event order')
|
||||
t.end()
|
||||
})
|
||||
|
||||
iterator.next = function () {
|
||||
stream.destroy()
|
||||
}
|
||||
|
||||
stream.resume()
|
||||
})
|
||||
|
||||
test('.destroy(err) during iterator.next', function (t) {
|
||||
var iterator = db.iterator()
|
||||
var stream = iteratorStream(iterator)
|
||||
|
||||
var order = monitor(iterator, stream, function () {
|
||||
t.same(order, ['_end', 'error: user', 'close'], 'event order')
|
||||
t.end()
|
||||
})
|
||||
|
||||
iterator.next = function (cb) {
|
||||
stream.destroy(new Error('user'))
|
||||
}
|
||||
|
||||
stream.resume()
|
||||
})
|
||||
|
||||
test('.destroy(err, callback) during iterator.next', function (t) {
|
||||
var iterator = db.iterator()
|
||||
var stream = iteratorStream(iterator)
|
||||
|
||||
var order = monitor(iterator, stream, function () {
|
||||
t.same(order, ['_end', 'callback', 'close'], 'event order')
|
||||
t.end()
|
||||
})
|
||||
|
||||
iterator.next = function (cb) {
|
||||
stream.destroy(new Error('user'), function (err) {
|
||||
order.push('callback')
|
||||
t.is(err.message, 'user', 'got error')
|
||||
})
|
||||
}
|
||||
|
||||
stream.resume()
|
||||
})
|
||||
|
||||
test('.destroy(null, callback) during iterator.next', function (t) {
|
||||
var iterator = db.iterator()
|
||||
var stream = iteratorStream(iterator)
|
||||
|
||||
var order = monitor(iterator, stream, function () {
|
||||
t.same(order, ['_end', 'callback', 'close'], 'event order')
|
||||
t.end()
|
||||
})
|
||||
|
||||
iterator.next = function (cb) {
|
||||
stream.destroy(null, function (err) {
|
||||
order.push('callback')
|
||||
t.ifError(err, 'no error')
|
||||
})
|
||||
}
|
||||
|
||||
stream.resume()
|
||||
})
|
||||
|
||||
test('.destroy during iterator.next 1', function (t) {
|
||||
var stream
|
||||
var iterator = db.iterator()
|
||||
var next = iterator.next.bind(iterator)
|
||||
iterator.next = function (cb) {
|
||||
t.pass('should be called once')
|
||||
next(cb)
|
||||
stream.destroy()
|
||||
}
|
||||
stream = iteratorStream(iterator)
|
||||
stream.on('data', function (data) {
|
||||
t.fail('should not be called')
|
||||
})
|
||||
stream.on('close', t.end.bind(t))
|
||||
})
|
||||
|
||||
test('.destroy during iterator.next 2', function (t) {
|
||||
var stream
|
||||
var iterator = db.iterator()
|
||||
var next = iterator.next.bind(iterator)
|
||||
var count = 0
|
||||
iterator.next = function (cb) {
|
||||
t.pass('should be called')
|
||||
next(cb)
|
||||
if (++count === 2) {
|
||||
stream.destroy()
|
||||
}
|
||||
}
|
||||
stream = iteratorStream(iterator)
|
||||
stream.on('data', function (data) {
|
||||
t.pass('should be called')
|
||||
})
|
||||
stream.on('close', t.end.bind(t))
|
||||
})
|
||||
|
||||
test('.destroy after iterator.next 1', function (t) {
|
||||
var stream
|
||||
var iterator = db.iterator()
|
||||
var next = iterator.next.bind(iterator)
|
||||
iterator.next = function (cb) {
|
||||
next(function (err, key, value) {
|
||||
stream.destroy()
|
||||
cb(err, key, value)
|
||||
t.pass('should be called')
|
||||
})
|
||||
}
|
||||
stream = iteratorStream(iterator)
|
||||
stream.on('data', function (data) {
|
||||
t.fail('should not be called')
|
||||
})
|
||||
stream.on('close', t.end.bind(t))
|
||||
})
|
||||
|
||||
test('.destroy after iterator.next 2', function (t) {
|
||||
var stream
|
||||
var iterator = db.iterator()
|
||||
var next = iterator.next.bind(iterator)
|
||||
var count = 0
|
||||
iterator.next = function (cb) {
|
||||
next(function (err, key, value) {
|
||||
if (++count === 2) {
|
||||
stream.destroy()
|
||||
}
|
||||
cb(err, key, value)
|
||||
t.pass('should be called')
|
||||
})
|
||||
}
|
||||
stream = iteratorStream(iterator)
|
||||
stream.on('data', function (data) {
|
||||
t.pass('should be called')
|
||||
})
|
||||
stream.on('close', t.end.bind(t))
|
||||
})
|
||||
|
||||
test('keys=false', function (t) {
|
||||
var stream = iteratorStream(db.iterator(), { keys: false })
|
||||
stream.once('data', function (value) {
|
||||
stream.destroy()
|
||||
t.equal(value.toString(), 'bar1')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
test('values=false', function (t) {
|
||||
var stream = iteratorStream(db.iterator(), { values: false })
|
||||
stream.once('data', function (key) {
|
||||
stream.destroy()
|
||||
t.equal(key.toString(), 'foobatch1')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
// It's important to keep a reference to the iterator at least until we end,
|
||||
// to prevent GC of the iterator and therefor its db (esp. for native addons).
|
||||
test('keeps a reference to the iterator', function (t) {
|
||||
var it = db.iterator()
|
||||
var stream = iteratorStream(it)
|
||||
|
||||
stream.on('close', function () {
|
||||
t.is(stream._iterator, it, 'has reference')
|
||||
t.end()
|
||||
})
|
||||
|
||||
stream.resume()
|
||||
})
|
||||
|
||||
// Note: also serves as teardown of above tests
|
||||
test('it is safe to close db on end of stream', function (t) {
|
||||
// Set highWaterMark to 0 so that we don't preemptively fetch.
|
||||
var it = db.iterator({ highWaterMark: 0 })
|
||||
var stream = iteratorStream(it)
|
||||
|
||||
stream.on('end', function () {
|
||||
// Although the underlying iterator is still alive at this point (before
|
||||
// the 'close' event has been emitted) it's safe to close the db because
|
||||
// leveldown (v5) ends any open iterators before closing.
|
||||
db.close(function (err) {
|
||||
t.ifError(err, 'no error')
|
||||
t.end()
|
||||
})
|
||||
})
|
||||
|
||||
stream.resume()
|
||||
})
|
||||
|
||||
function monitor (iterator, stream, onClose) {
|
||||
var order = []
|
||||
|
||||
;['_next', '_end'].forEach(function (method) {
|
||||
var original = iterator[method]
|
||||
|
||||
iterator[method] = function () {
|
||||
order.push(method)
|
||||
original.apply(this, arguments)
|
||||
}
|
||||
})
|
||||
|
||||
;['data', 'end', 'error', 'close'].forEach(function (event) {
|
||||
// Add listener without side effects (like triggering flowing mode)
|
||||
addSecretListener(stream, event, function (err) {
|
||||
if (event === 'error') order.push('error: ' + err.message)
|
||||
else order.push(event)
|
||||
})
|
||||
})
|
||||
|
||||
if (onClose) {
|
||||
addSecretListener(stream, 'close', onClose)
|
||||
}
|
||||
|
||||
return order
|
||||
}
|
||||
|
||||
function withoutDataEvents (event) {
|
||||
return event !== '_next' && event !== 'data'
|
||||
}
|
||||
Reference in New Issue
Block a user