Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add manifest #351

Merged
merged 4 commits into from Sep 30, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
46 changes: 45 additions & 1 deletion abstract-leveldown.js
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
// }
vweevers marked this conversation as resolved.
Show resolved Hide resolved
}
})
}

AbstractLevelDOWN.prototype.open = function (options, callback) {
Expand Down
4 changes: 4 additions & 0 deletions test/common.js
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
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
@@ -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
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