Socket
Socket
Sign inDemoInstall

subleveldown

Package Overview
Dependencies
Maintainers
3
Versions
23
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

subleveldown - npm Package Compare versions

Comparing version 4.1.2 to 4.1.3

matchdown.js

8

CHANGELOG.md

@@ -5,2 +5,8 @@ # Changelog

## [4.1.3] - 2019-09-17
### Changed
- Use `reachdown` package ([Level/community#82](https://github.com/Level/community/issues/82)) ([#75](https://github.com/level/subleveldown/issues/75)) ([**@vweevers**](https://github.com/vweevers))
## [4.1.2] - 2019-09-12

@@ -219,2 +225,4 @@

[4.1.3]: https://github.com/level/subleveldown/compare/v4.1.2...v4.1.3
[4.1.2]: https://github.com/level/subleveldown/compare/v4.1.1...v4.1.2

@@ -221,0 +229,0 @@

21

leveldown.js
var inherits = require('inherits')
var abstract = require('abstract-leveldown')
var wrap = require('level-option-wrap')
var reachdown = require('reachdown')
var matchdown = require('./matchdown')

@@ -86,9 +88,9 @@ var rangeOptions = 'start end gt gte lt lte'.split(' ')

var subdb = down(self.db, 'subleveldown')
var subdb = reachdown(self.db, 'subleveldown')
if (subdb && subdb.prefix) {
self.prefix = subdb.prefix + self.prefix
self.leveldown = down(subdb.db)
self.leveldown = reachdown(subdb.db, matchdown, false)
} else {
self.leveldown = down(self.db)
self.leveldown = reachdown(self.db, matchdown, false)
}

@@ -183,14 +185,1 @@

module.exports = SubDown
function down (db, type) {
if (typeof db.down === 'function') return db.down(type)
if (type && db.type === type) return db
if (isLooseAbstract(db.db)) return down(db.db, type)
if (isLooseAbstract(db._db)) return down(db._db, type)
return type ? null : db
}
function isLooseAbstract (db) {
if (!db || typeof db !== 'object') { return false }
return typeof db._batch === 'function' && typeof db._iterator === 'function'
}
{
"name": "subleveldown",
"version": "4.1.2",
"version": "4.1.3",
"description": "Split a levelup database into sublevels with their own keyspace, encoding and events",

@@ -9,3 +9,3 @@ "author": "Mathias Buus (@mafintosh)",

"scripts": {
"test": "standard && hallmark && nyc node test",
"test": "standard && hallmark && (nyc -s node test | faucet) && nyc report",
"coverage": "nyc report --reporter=text-lcov | coveralls",

@@ -24,3 +24,4 @@ "hallmark": "hallmark --fix",

"level-option-wrap": "^1.1.0",
"levelup": "^4.2.0"
"levelup": "^4.2.0",
"reachdown": "^1.0.0"
},

@@ -31,5 +32,7 @@ "devDependencies": {

"dependency-check": "^3.3.0",
"faucet": "^0.0.1",
"hallmark": "^2.0.0",
"level-community": "^3.0.0",
"level-concat-iterator": "^2.0.1",
"memdb": "^1.3.1",
"memdown": "^5.0.0",

@@ -36,0 +39,0 @@ "nyc": "^14.0.0",

@@ -10,2 +10,6 @@ var test = require('tape')

var levelup = require('levelup')
var reachdown = require('reachdown')
var memdb = require('memdb')
var abstract = require('abstract-leveldown')
var inherits = require('util').inherits

@@ -363,4 +367,76 @@ // Test abstract-leveldown compliance

// Test that we peel off the levelup, deferred-leveldown and encoding-down
// layers from db, but stop at any other intermediate layer like encrypt-down,
// cachedown, etc.
test('subleveldown on intermediate layer', function (t) {
t.plan(7)
function Intermediate (db) {
abstract.AbstractLevelDOWN.call(this)
this.db = db
}
inherits(Intermediate, abstract.AbstractLevelDOWN)
Intermediate.prototype._put = function (key, value, options, callback) {
t.pass('got _put call')
this.db._put('mitm' + key, value, options, callback)
}
Intermediate.prototype._get = function (key, options, callback) {
t.pass('got _get call')
this.db._get('mitm' + key, options, callback)
}
var db = levelup(encoding(new Intermediate(memdown())))
var sub = subdb(db, 'test')
sub.put('key', 'value', function (err) {
t.error(err, 'no err')
db.get('!test!key', function (err, value) {
t.ifError(err, 'no levelup get error')
t.is(value, 'value')
})
reachdown(db).get('mitm!test!key', { asBuffer: false }, function (err, value) {
t.ifError(err, 'no memdown get error')
t.is(value, 'value')
})
})
})
test('legacy memdb (old levelup)', function (t) {
t.plan(7)
// Should not result in double json encoding
var db = memdb({ valueEncoding: 'json' })
var sub = subdb(db, 'test', { valueEncoding: 'json' })
// Integration with memdb still works because subleveldown waits to reachdown
// until the (old levelup) db is open. Reaching down then correctly lands on
// the memdown db. If subleveldown were to reachdown immediately it'd land on
// the old deferred-leveldown (which when unopened doesn't have a reference to
// the memdown db yet) so we'd be unable to persist anything.
t.is(Object.getPrototypeOf(reachdown(db)).constructor.name, 'DeferredLevelDOWN')
sub.put('key', { a: 1 }, function (err) {
t.ifError(err, 'no put error')
sub.get('key', function (err, value) {
t.ifError(err, 'no get error')
t.same(value, { a: 1 })
})
t.is(Object.getPrototypeOf(reachdown(db)).constructor.name, 'MemDOWN')
reachdown(db).get('!test!key', { asBuffer: false }, function (err, value) {
t.ifError(err, 'no get error')
t.is(value, '{"a":1}')
})
})
})
function getKey (entry) {
return entry.key
}
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc