Skip to content

Commit

Permalink
Add manifest (Level/community#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Sep 25, 2021
1 parent d53ace3 commit f7ee1e3
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 3 deletions.
16 changes: 15 additions & 1 deletion leveldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -114,7 +114,21 @@ function SubDown (db, prefix, opts) {
}
}

abstract.AbstractLevelDOWN.call(this)
// Inherit manifest from parent db
manifest = Object.assign({}, manifest, {
// Disable unsupported features
getMany: false,
keyIterator: false,
valueIterator: false,
iteratorNextv: false,
iteratorAll: false,

// Unset additional methods (like approximateSize) which we can't support
// here and should typically be called on the underlying store instead.
additionalMethods: {}
})

abstract.AbstractLevelDOWN.call(this, manifest)
}

inherits(SubDown, abstract.AbstractLevelDOWN)
Expand Down
34 changes: 32 additions & 2 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ function runSuite (factory) {
factory: factory,

// Unsupported features
seek: false,
createIfMissing: false,
errorIfExists: false,

Expand Down Expand Up @@ -73,7 +72,6 @@ suite({
return subdb(levelup(encoding(memdown())), 'test')
},
// Unsupported features
seek: false,
createIfMissing: false,
errorIfExists: false,

Expand Down Expand Up @@ -133,6 +131,38 @@ test('SubDown constructor', function (t) {
})

test('SubDb main function', function (t) {
t.test('inherits manifest from parent db', function (t) {
var down = memdown()
down.supports.foo = true

var up = levelup(down)
t.is(up.supports.foo, true, 'levelup inherits from down')
up.supports.bar = true

var sub = subdb(up)
t.is(sub.supports.foo, true, 'subdb inherits from down via levelup')
t.is(sub.supports.seek, true, 'subdb inherits from down via levelup')
t.is(sub.supports.bar, true, 'subdb inherits from levelup')
t.end()
})

t.test('does not support additionalMethods', function (t) {
var down = memdown()
down.supports.additionalMethods.foo = true

// We're expecting that levelup exposes the additionalMethod
var up = levelup(down)
t.is(up.supports.additionalMethods.foo, true)
t.is(typeof up.foo, 'function', 'levelup exposes method')

// But that subdb removes it (although it is itself a levelup)
// because it can't automatically prefix any key(-like) arguments
var sub = subdb(up)
t.same(sub.supports.additionalMethods, {})
t.is(typeof sub.foo, 'undefined', 'subdb does not expose method')
t.end()
})

t.test('opts.open hook', function (t) {
t.plan(1)
subdb(levelup(memdown()), 'test', {
Expand Down

0 comments on commit f7ee1e3

Please sign in to comment.