Skip to content
This repository has been archived by the owner on Mar 23, 2023. It is now read-only.

Commit

Permalink
fix: upgrade level libs to resolve node 10 failure
Browse files Browse the repository at this point in the history
License: MIT
Signed-off-by: Jacob Heun <jacobheun@gmail.com>
  • Loading branch information
jacobheun authored and daviddias committed May 29, 2018
1 parent fad0098 commit a427eca
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 14 deletions.
Binary file removed .DS_Store
Binary file not shown.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
"version": "0.7.0",
"description": "Datastore implementation with level(up|down) backend",
"main": "src/index.js",
"browser": {
"leveldown": "level-js"
},
"scripts": {
"lint": "aegir lint",
"build": "aegir build",
Expand Down Expand Up @@ -39,9 +42,9 @@
"dependencies": {
"datastore-core": "~0.4.0",
"interface-datastore": "~0.4.1",
"level-js": "^2.2.4",
"leveldown": "^1.9.0",
"levelup": "^1.3.9",
"level-js": "github:timkuijsten/level.js#idbunwrapper",

This comment has been minimized.

Copy link
@vanjan

vanjan May 21, 2019

Contributor

given this is now a year old, and the fix is surely in the main level-js repo, can we use a registry version here? using git deps makes it impossible to install in some environments that rely on registry only

"leveldown": "^3.0.2",
"levelup": "^2.0.2",
"pull-stream": "^3.6.1"
},
"devDependencies": {
Expand Down
27 changes: 22 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,24 @@ class LevelDatastore {
/* :: db: levelup */

constructor (path /* : string */, opts /* : ?LevelOptions */) {
this.db = levelup(path, Object.assign({}, opts, {
compression: false, // same default as go
valueEncoding: 'binary'
}))
// Default to leveldown db
const database = opts && opts.db ? opts.db : require('leveldown')
delete opts.db

this.db = levelup(
database(
path,
Object.assign({}, opts, {
compression: false, // same default as go
valueEncoding: 'binary'
})
), (err) => {
// Prevent an uncaught exception error on duplicate locks
if (err) {
throw err
}
}
)
}

open (callback /* : Callback<void> */) /* : void */ {
Expand Down Expand Up @@ -58,7 +72,10 @@ class LevelDatastore {
}

delete (key /* : Key */, callback /* : Callback<void> */) /* : void */ {
this.db.del(key.toString(), callback)
this.db.del(key.toString(), (err) => {
// Avoid level passing additional arguments to callback, we dont need them
callback(err)
})
}

close (callback /* : Callback<void> */) /* : void */ {
Expand Down
4 changes: 3 additions & 1 deletion test/browser.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
const each = require('async/each')
const MountStore = require('datastore-core').MountDatastore
const Key = require('interface-datastore').Key
const leveljs = require('level-js')

// leveldown will be swapped for level-js
const leveljs = require('leveldown')

const LevelStore = require('../src')

Expand Down
20 changes: 15 additions & 5 deletions test/node.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ describe('LevelDatastore', () => {
const dir = utils.tmpdir()
require('interface-datastore/src/tests')({
setup (callback) {
callback(null, new LevelStore(dir))
callback(null, new LevelStore(dir, {
db: require('leveldown')
}))
},
teardown (callback) {
rimraf(dir, callback)
Expand All @@ -40,13 +42,19 @@ describe('LevelDatastore', () => {
setup (callback) {
callback(null, new MountStore([{
prefix: new Key('/a'),
datastore: new LevelStore(dirs[0])
datastore: new LevelStore(dirs[0], {
db: require('leveldown')
})
}, {
prefix: new Key('/q'),
datastore: new LevelStore(dirs[1])
datastore: new LevelStore(dirs[1], {
db: require('leveldown')
})
}, {
prefix: new Key('/z'),
datastore: new LevelStore(dirs[2])
datastore: new LevelStore(dirs[2], {
db: require('leveldown')
})
}]))
},
teardown (callback) {
Expand All @@ -56,7 +64,9 @@ describe('LevelDatastore', () => {
})

it.skip('interop with go', (done) => {
const store = new LevelStore(path.join(__dirname, 'test-repo', 'datastore'))
const store = new LevelStore(path.join(__dirname, 'test-repo', 'datastore'), {
db: require('leveldown')
})

pull(
store.query({}),
Expand Down

0 comments on commit a427eca

Please sign in to comment.