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

Commit

Permalink
Breaking: modernize syntax and bump standard (Level/community#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
vweevers committed Apr 17, 2021
1 parent ef4b318 commit 4770d17
Show file tree
Hide file tree
Showing 10 changed files with 52 additions and 47 deletions.
1 change: 0 additions & 1 deletion .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,3 @@ updates:
ignore:
- dependency-name: dependency-check
- dependency-name: nyc
- dependency-name: standard
12 changes: 6 additions & 6 deletions abstract/base-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

var location = require('./location')
const location = require('./location')

module.exports = function (test, level) {
test('test db open and use, level(location, cb)', function (t) {
Expand All @@ -24,27 +24,27 @@ module.exports = function (test, level) {
})

test('test db open and use, db=level(location)', function (t) {
var db = level(location)
const db = level(location)
db.put('test3', 'success', function (err) {
t.notOk(err, 'no error')
db.close(t.end.bind(t))
})
})

test('options.keyEncoding and options.valueEncoding are passed on to encoding-down', function (t) {
var db = level(location, { keyEncoding: 'json', valueEncoding: 'json' })
const db = level(location, { keyEncoding: 'json', valueEncoding: 'json' })
db.on('ready', function () {
var codec = db.db.codec
const codec = db.db.codec
t.equal(codec.opts.keyEncoding, 'json', 'keyEncoding correct')
t.equal(codec.opts.valueEncoding, 'json', 'valueEncoding correct')
db.close(t.end.bind(t))
})
})

test('encoding options default to utf8', function (t) {
var db = level(location)
const db = level(location)
db.on('ready', function () {
var codec = db.db.codec
const codec = db.db.codec
t.equal(codec.opts.keyEncoding, 'utf8', 'keyEncoding correct')
t.equal(codec.opts.valueEncoding, 'utf8', 'valueEncoding correct')
db.close(t.end.bind(t))
Expand Down
22 changes: 12 additions & 10 deletions abstract/db-values-test.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
'use strict'

var location = require('./location')
const location = require('./location')

module.exports = function (test, level, nonPersistent) {
test('test db values', function (t) {
var c = 0
var db = level(location)
var setup = nonPersistent ? function (callback) {
db.batch([
{ type: 'put', key: 'test1', value: 'success' },
{ type: 'put', key: 'test2', value: 'success' },
{ type: 'put', key: 'test3', value: 'success' }
], callback)
} : function (callback) { callback() }
let c = 0
const db = level(location)
const setup = nonPersistent
? function (callback) {
db.batch([
{ type: 'put', key: 'test1', value: 'success' },
{ type: 'put', key: 'test2', value: 'success' },
{ type: 'put', key: 'test3', value: 'success' }
], callback)
}
: function (callback) { callback() }

function read (err, value) {
t.notOk(err, 'no error')
Expand Down
6 changes: 3 additions & 3 deletions abstract/destroy-test.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

var fs = require('fs')
var path = require('path')
var location = require('./location')
const fs = require('fs')
const path = require('path')
const location = require('./location')

module.exports = function (test, level) {
test('test destroy', function (t) {
Expand Down
2 changes: 1 addition & 1 deletion abstract/error-if-exists-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

var location = require('./location')
const location = require('./location')

module.exports = function (test, level) {
test('test db open and use, level(location, options, cb) force error', function (t) {
Expand Down
4 changes: 3 additions & 1 deletion abstract/location.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
var path = require('path')
'use strict'

const path = require('path')

module.exports = path.join(__dirname, 'level-test-' + process.pid + '.db')
2 changes: 1 addition & 1 deletion abstract/repair-test.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

var location = require('./location')
const location = require('./location')

module.exports = function (test, level) {
test('test repair', function (t) {
Expand Down
14 changes: 8 additions & 6 deletions level-packager.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
var levelup = require('levelup')
var encode = require('encoding-down')
'use strict'

const levelup = require('levelup')
const encode = require('encoding-down')

function packager (leveldown) {
function Level (location, options, callback) {
Expand All @@ -20,13 +22,13 @@ function packager (leveldown) {
return typeof o === 'object' && o !== null
}

['destroy', 'repair'].forEach(function (m) {
for (const m of ['destroy', 'repair']) {
if (typeof leveldown[m] === 'function') {
Level[m] = function () {
leveldown[m].apply(leveldown, arguments)
Level[m] = function (...args) {
leveldown[m](...args)
}
}
})
}

Level.errors = levelup.errors

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"hallmark": "^3.1.0",
"level-community": "^3.0.0",
"nyc": "^14.0.0",
"standard": "^14.0.0",
"standard": "^16.0.3",
"tape": "^5.0.1"
},
"hallmark": {
Expand Down
34 changes: 17 additions & 17 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

var test = require('tape')
var packager = require('.')
const test = require('tape')
const packager = require('.')

test('Level constructor has access to levelup errors', function (t) {
function Down () {}
Expand All @@ -18,16 +18,16 @@ test('Level constructor relays .destroy and .repair if they exist', function (t)
function test (method) {
function Down () {}

Down[method] = function () {
t.same([].slice.call(arguments), args, 'supports variadic arguments')
Down[method] = function (...actual) {
t.same(actual, expected, 'supports variadic arguments')
}

var level = packager(Down)
var args = []
const level = packager(Down)
const expected = []

for (var i = 0; i < 4; i++) {
args.push(i)
level[method].apply(level, args)
for (let i = 0; i < 4; i++) {
expected.push(i)
level[method](...expected)
}
}
})
Expand All @@ -48,7 +48,7 @@ test('Level constructor', function (t) {
}
}
}
var levelup = packager(Down)()
const levelup = packager(Down)()
t.is(levelup.options.keyEncoding, 'utf8')
t.is(levelup.options.valueEncoding, 'utf8')
})
Expand All @@ -68,7 +68,7 @@ test('Level constructor with location', function (t) {
}
}
}
var levelup = packager(Down)('location')
const levelup = packager(Down)('location')
t.is(levelup.options.keyEncoding, 'utf8')
t.is(levelup.options.valueEncoding, 'utf8')
})
Expand Down Expand Up @@ -134,7 +134,7 @@ test('Level constructor with location & callback', function (t) {

test('Level constructor with location & options passed to levelup', function (t) {
t.plan(4)
var Down = function (location) {
const Down = function (location) {
t.is(location, 'location', 'location is correct')
return {
open: function (opts, cb) {
Expand All @@ -147,7 +147,7 @@ test('Level constructor with location & options passed to levelup', function (t)
}
}
}
var levelup = packager(Down)('location', {
const levelup = packager(Down)('location', {
keyEncoding: 'binary',
valueEncoding: 'binary'
})
Expand All @@ -157,7 +157,7 @@ test('Level constructor with location & options passed to levelup', function (t)

test('Level constructor with options passed to levelup', function (t) {
t.plan(3)
var Down = function () {
const Down = function () {
return {
open: function (opts, cb) {
t.same(opts, {
Expand All @@ -169,7 +169,7 @@ test('Level constructor with options passed to levelup', function (t) {
}
}
}
var levelup = packager(Down)({
const levelup = packager(Down)({
keyEncoding: 'binary',
valueEncoding: 'binary'
})
Expand All @@ -179,7 +179,7 @@ test('Level constructor with options passed to levelup', function (t) {

test('Level constructor with options & callback passed to levelup', function (t) {
t.plan(5)
var Down = function () {
const Down = function () {
return {
open: function (opts, cb) {
t.same(opts, {
Expand All @@ -192,7 +192,7 @@ test('Level constructor with options & callback passed to levelup', function (t)
}
}
}
var levelup = packager(Down)({
const levelup = packager(Down)({
keyEncoding: 'binary',
valueEncoding: 'binary'
}, function (err, db) {
Expand Down

0 comments on commit 4770d17

Please sign in to comment.