diff --git a/leveldown.js b/leveldown.js index 197cf51..3050a64 100644 --- a/leveldown.js +++ b/leveldown.js @@ -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) diff --git a/test/index.js b/test/index.js index c596d92..66000df 100644 --- a/test/index.js +++ b/test/index.js @@ -19,7 +19,6 @@ function runSuite (factory) { factory: factory, // Unsupported features - seek: false, createIfMissing: false, errorIfExists: false, @@ -73,7 +72,6 @@ suite({ return subdb(levelup(encoding(memdown())), 'test') }, // Unsupported features - seek: false, createIfMissing: false, errorIfExists: false, @@ -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', {