Skip to content
This repository was archived by the owner on Dec 2, 2024. It is now read-only.

Commit f7ee1e3

Browse files
committed
Add manifest (Level/community#83)
1 parent d53ace3 commit f7ee1e3

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

leveldown.js

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,21 @@ function SubDown (db, prefix, opts) {
114114
}
115115
}
116116

117-
abstract.AbstractLevelDOWN.call(this)
117+
// Inherit manifest from parent db
118+
manifest = Object.assign({}, manifest, {
119+
// Disable unsupported features
120+
getMany: false,
121+
keyIterator: false,
122+
valueIterator: false,
123+
iteratorNextv: false,
124+
iteratorAll: false,
125+
126+
// Unset additional methods (like approximateSize) which we can't support
127+
// here and should typically be called on the underlying store instead.
128+
additionalMethods: {}
129+
})
130+
131+
abstract.AbstractLevelDOWN.call(this, manifest)
118132
}
119133

120134
inherits(SubDown, abstract.AbstractLevelDOWN)

test/index.js

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@ function runSuite (factory) {
1919
factory: factory,
2020

2121
// Unsupported features
22-
seek: false,
2322
createIfMissing: false,
2423
errorIfExists: false,
2524

@@ -73,7 +72,6 @@ suite({
7372
return subdb(levelup(encoding(memdown())), 'test')
7473
},
7574
// Unsupported features
76-
seek: false,
7775
createIfMissing: false,
7876
errorIfExists: false,
7977

@@ -133,6 +131,38 @@ test('SubDown constructor', function (t) {
133131
})
134132

135133
test('SubDb main function', function (t) {
134+
t.test('inherits manifest from parent db', function (t) {
135+
var down = memdown()
136+
down.supports.foo = true
137+
138+
var up = levelup(down)
139+
t.is(up.supports.foo, true, 'levelup inherits from down')
140+
up.supports.bar = true
141+
142+
var sub = subdb(up)
143+
t.is(sub.supports.foo, true, 'subdb inherits from down via levelup')
144+
t.is(sub.supports.seek, true, 'subdb inherits from down via levelup')
145+
t.is(sub.supports.bar, true, 'subdb inherits from levelup')
146+
t.end()
147+
})
148+
149+
t.test('does not support additionalMethods', function (t) {
150+
var down = memdown()
151+
down.supports.additionalMethods.foo = true
152+
153+
// We're expecting that levelup exposes the additionalMethod
154+
var up = levelup(down)
155+
t.is(up.supports.additionalMethods.foo, true)
156+
t.is(typeof up.foo, 'function', 'levelup exposes method')
157+
158+
// But that subdb removes it (although it is itself a levelup)
159+
// because it can't automatically prefix any key(-like) arguments
160+
var sub = subdb(up)
161+
t.same(sub.supports.additionalMethods, {})
162+
t.is(typeof sub.foo, 'undefined', 'subdb does not expose method')
163+
t.end()
164+
})
165+
136166
t.test('opts.open hook', function (t) {
137167
t.plan(1)
138168
subdb(levelup(memdown()), 'test', {

0 commit comments

Comments
 (0)