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

Commit

Permalink
Add manifest (Level/community#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Sep 20, 2019
1 parent d7ba459 commit 64185c3
Show file tree
Hide file tree
Showing 5 changed files with 98 additions and 2 deletions.
46 changes: 45 additions & 1 deletion abstract-leveldown.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,52 @@ var AbstractChainedBatch = require('./abstract-chained-batch')
var hasOwnProperty = Object.prototype.hasOwnProperty
var rangeOptions = 'start end gt gte lt lte'.split(' ')

function AbstractLevelDOWN () {
function AbstractLevelDOWN (supports) {
// TODO (next major): make this mandatory
if (!supports || typeof supports !== 'object') supports = {}

this.status = 'new'

// TODO (after review): move this to a module for reuse by levelup
this.supports = xtend(supports, {
// Features of abstract-leveldown
bufferKeys: !!supports.bufferKeys,
snapshots: !!supports.snapshots,
permanence: !!supports.permanence,
seek: !!supports.seek,

// Features of abstract-leveldown that levelup doesn't have
status: !!supports.status,

// Experimental features
clear: !!supports.clear,
type: !!supports.type,

// Features of disk-based implementations
createIfMissing: !!supports.createIfMissing,
errorIfExists: !!supports.errorIfExists,

// Features of level(up) that abstract-leveldown doesn't have yet
deferredOpen: !!supports.deferredOpen,
openCallback: !!supports.openCallback,
promises: !!supports.promises,
streams: !!supports.streams,
encodings: !!supports.encodings,

// Methods that are not part of abstract-leveldown or levelup
additionalMethods: supports.additionalMethods || {
// Example
// approximateSize: {
// sync: false,
// callback: true,
// promise: false
// },
// createWriteStream: {
// sync: true,
// writable: true
// }
}
})
}

AbstractLevelDOWN.prototype.open = function (options, callback) {
Expand Down
4 changes: 4 additions & 0 deletions test/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@ function testCommon (options) {
return {
test: test,
factory: factory,

// TODO (next major): remove
setUp: options.setUp || noopTest(),
tearDown: options.tearDown || noopTest(),

// TODO (next major): use db.supports instead
bufferKeys: options.bufferKeys !== false,
createIfMissing: options.createIfMissing !== false,
errorIfExists: options.errorIfExists !== false,
Expand Down
1 change: 1 addition & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ function suite (options) {
var test = testCommon.test

require('./factory-test')(test, testCommon)
require('./manifest-test')(test, testCommon)

require('./leveldown-test')(test, testCommon)
require('./open-test').all(test, testCommon)
Expand Down
47 changes: 47 additions & 0 deletions test/manifest-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
var xtend = require('xtend')
var hasOwnProperty = Object.prototype.hasOwnProperty

module.exports = function (test, testCommon) {
test('setUp common', testCommon.setUp)

test('db has manifest', function (t) {
var db = testCommon.factory()
var supports = db.supports

t.ok(isObject(supports))
t.ok(isObject(supports.additionalMethods))

for (var k in supports) {
if (!hasOwnProperty.call(supports, k)) continue
if (k === 'additionalMethods') continue

t.is(typeof supports[k], 'boolean', k)
}

for (var m in supports.additionalMethods) {
if (!hasOwnProperty.call(supports.additionalMethods, m)) continue
t.ok(isObject(supports.additionalMethods[m]), m)
}

var before = xtend(supports, {
additionalMethods: xtend(supports.additionalMethods)
})

db.open(function (err) {
t.ifError(err, 'no open error')
t.same(db.supports, before, 'manifest did not change after open')

db.close(function (err) {
t.ifError(err, 'no close error')
t.same(db.supports, before, 'manifest did not change after close')
t.end()
})
})
})

test('tearDown', testCommon.tearDown)
}

function isObject (o) {
return typeof o === 'object' && o !== null
}
2 changes: 1 addition & 1 deletion test/self.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ var legacyRangeOptions = ['start', 'end']
// excluding noop operations that can't pass the test suite.

require('./leveldown-test')(test, testCommon)

require('./manifest-test')(test, testCommon)
require('./open-test').all(test, testCommon)

require('./open-create-if-missing-test').setUp(test, testCommon)
Expand Down

0 comments on commit 64185c3

Please sign in to comment.