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

Drop legacy features & runtime environments #63

Merged
merged 6 commits into from
Apr 9, 2021
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .airtap.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
providers:
- airtap-playwright

browsers:
- name: chromium
- name: firefox
- name: webkit
4 changes: 2 additions & 2 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
language: node_js

node_js:
- 6
- 8
- 10
- 12
- 14

after_success: npm run coverage

Expand Down
47 changes: 24 additions & 23 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var encodings = require('./lib/encodings')
'use strict'

const encodings = require('./lib/encodings')

module.exports = Codec

Expand Down Expand Up @@ -45,53 +47,52 @@ Codec.prototype.decodeValue = function (value, opts) {
}

Codec.prototype.encodeBatch = function (ops, opts) {
var self = this
juliangruber marked this conversation as resolved.
Show resolved Hide resolved

return ops.map(function (_op) {
var op = {
return ops.map((_op) => {
const op = {
type: _op.type,
key: self.encodeKey(_op.key, opts, _op)
key: this.encodeKey(_op.key, opts, _op)
}
if (self.keyAsBuffer(opts, _op)) op.keyEncoding = 'binary'
if (this.keyAsBuffer(opts, _op)) op.keyEncoding = 'binary'
if (_op.prefix) op.prefix = _op.prefix
if ('value' in _op) {
op.value = self.encodeValue(_op.value, opts, _op)
if (self.valueAsBuffer(opts, _op)) op.valueEncoding = 'binary'
op.value = this.encodeValue(_op.value, opts, _op)
if (this.valueAsBuffer(opts, _op)) op.valueEncoding = 'binary'
}
return op
})
}

var ltgtKeys = ['lt', 'gt', 'lte', 'gte', 'start', 'end']
const ltgtKeys = ['lt', 'gt', 'lte', 'gte']

Codec.prototype.encodeLtgt = function (ltgt) {
var self = this
var ret = {}
Object.keys(ltgt).forEach(function (key) {
const ret = {}
Object.keys(ltgt).forEach((key) => {
vweevers marked this conversation as resolved.
Show resolved Hide resolved
if (key === 'start' || key === 'end') {
throw new Error('Legacy range options ("start" and "end") have been removed')
}

ret[key] = ltgtKeys.indexOf(key) > -1
? self.encodeKey(ltgt[key], ltgt)
? this.encodeKey(ltgt[key], ltgt)
: ltgt[key]
})
return ret
}

Codec.prototype.createStreamDecoder = function (opts) {
var self = this

if (opts.keys && opts.values) {
return function (key, value) {
return (key, value) => {
return {
key: self.decodeKey(key, opts),
value: self.decodeValue(value, opts)
key: this.decodeKey(key, opts),
value: this.decodeValue(value, opts)
}
}
} else if (opts.keys) {
return function (key) {
return self.decodeKey(key, opts)
return (key) => {
return this.decodeKey(key, opts)
}
} else if (opts.values) {
return function (_, value) {
return self.decodeValue(value, opts)
return (_, value) => {
return this.decodeValue(value, opts)
}
} else {
return function () {}
Expand Down
6 changes: 4 additions & 2 deletions lib/encodings.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
var Buffer = require('buffer').Buffer
'use strict'

const Buffer = require('buffer').Buffer
vweevers marked this conversation as resolved.
Show resolved Hide resolved

exports.utf8 = exports['utf-8'] = {
encode: function (data) {
Expand Down Expand Up @@ -34,7 +36,7 @@ exports.none = {

exports.id = exports.none

var bufferEncodings = [
const bufferEncodings = [
'hex',
'ascii',
'base64',
Expand Down
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
"main": "index.js",
"scripts": {
"test": "standard && hallmark && nyc tape test/*.js",
"test-browsers-local": "airtap --coverage --verbose test/*.js",
"coverage": "nyc report --reporter=text-lcov | coveralls",
"hallmark": "hallmark --fix",
"dependency-check": "dependency-check . test/*.js",
Expand All @@ -15,12 +16,14 @@
"buffer": "^5.6.0"
},
"devDependencies": {
"airtap": "^4.0.3",
"airtap-playwright": "^1.0.1",
"coveralls": "^3.0.2",
"dependency-check": "^3.3.0",
"hallmark": "^3.1.0",
"level-community": "^3.0.0",
"nyc": "^14.0.0",
"standard": "^14.0.0",
"nyc": "^15.1.0",
"standard": "^16.0.3",
"tape": "^5.0.1"
},
"hallmark": {
Expand All @@ -32,6 +35,6 @@
"level"
],
"engines": {
"node": ">=6"
"node": ">=10"
}
}
8 changes: 4 additions & 4 deletions test/as-buffer.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
var test = require('tape')
var Codec = require('..')
const test = require('tape')
const Codec = require('..')

test('key as buffer', function (t) {
var codec = new Codec({ keyEncoding: 'hex' })
const codec = new Codec({ keyEncoding: 'hex' })
t.ok(codec.keyAsBuffer({}))
t.ok(codec.keyAsBuffer())
t.notOk(codec.keyAsBuffer({ keyEncoding: 'utf8' }))
t.end()
})

test('value as buffer', function (t) {
var codec = new Codec({ valueEncoding: 'hex' })
const codec = new Codec({ valueEncoding: 'hex' })
t.ok(codec.valueAsBuffer({}))
t.ok(codec.valueAsBuffer())
t.notOk(codec.valueAsBuffer({ valueEncoding: 'utf8' }))
Expand Down
20 changes: 10 additions & 10 deletions test/batch.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
var test = require('tape')
var Codec = require('..')
const test = require('tape')
const Codec = require('..')

test('batch', function (t) {
var codec = new Codec({})
var ops = [
const codec = new Codec({})
const ops = [
{ type: 'put', key: 'string', value: 'string', valueEncoding: 'utf8' },
{ type: 'put', key: 'json', value: {} }
]
var opsSerialized = JSON.stringify(ops)
const opsSerialized = JSON.stringify(ops)

var encoded = codec.encodeBatch(ops, { valueEncoding: 'json' })
let encoded = codec.encodeBatch(ops, { valueEncoding: 'json' })

t.equal(opsSerialized, JSON.stringify(ops), 'ops not changed')

Expand All @@ -28,14 +28,14 @@ test('batch', function (t) {
})

test('batch - legacy', function (t) {
var codec = new Codec({})
var ops = [
const codec = new Codec({})
const ops = [
{ type: 'put', key: 'string', value: 'string', encoding: 'utf8' },
{ type: 'put', key: 'json', value: {} }
]
var opsSerialized = JSON.stringify(ops)
const opsSerialized = JSON.stringify(ops)

var encoded = codec.encodeBatch(ops, { encoding: 'json' })
let encoded = codec.encodeBatch(ops, { encoding: 'json' })

t.equal(opsSerialized, JSON.stringify(ops), 'ops not changed')

Expand Down
8 changes: 4 additions & 4 deletions test/codec.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
var test = require('tape')
var Codec = require('..')
const test = require('tape')
const Codec = require('..')

test('codec', function (t) {
var codec = new Codec({ keyEncoding: 'hex' })
let codec = new Codec({ keyEncoding: 'hex' })
t.ok(codec.keyAsBuffer())
codec = new Codec()
t.notOk(codec.keyAsBuffer())
t.end()
})

test('codec, new not needed', function (t) {
var codec = Codec({ keyEncoding: 'hex' })
let codec = Codec({ keyEncoding: 'hex' })
t.ok(codec.keyAsBuffer())
codec = Codec()
t.notOk(codec.keyAsBuffer())
Expand Down
20 changes: 10 additions & 10 deletions test/decoder.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
var test = require('tape')
var Codec = require('..')
const test = require('tape')
const Codec = require('..')

test('createStreamDecoder', function (t) {
var codec = new Codec({ keyEncoding: 'hex' })
const codec = new Codec({ keyEncoding: 'hex' })

t.plan(3)

t.test('keys and values', function (t) {
var decoder = codec.createStreamDecoder({
const decoder = codec.createStreamDecoder({
valueEncoding: 'json',
keys: true,
values: true
Expand All @@ -20,15 +20,15 @@ test('createStreamDecoder', function (t) {
})

t.test('keys', function (t) {
var decoder = codec.createStreamDecoder({
const decoder = codec.createStreamDecoder({
keys: true
})
t.equal(decoder(Buffer.from('hey')), '686579')
t.end()
})

t.test('values', function (t) {
var decoder = codec.createStreamDecoder({
const decoder = codec.createStreamDecoder({
valueEncoding: 'hex',
values: true
})
Expand All @@ -38,12 +38,12 @@ test('createStreamDecoder', function (t) {
})

test('createStreamDecoder - legacy', function (t) {
var codec = new Codec({ keyEncoding: 'hex' })
const codec = new Codec({ keyEncoding: 'hex' })

t.plan(3)

t.test('keys and values', function (t) {
var decoder = codec.createStreamDecoder({
const decoder = codec.createStreamDecoder({
encoding: 'json',
keys: true,
values: true
Expand All @@ -56,15 +56,15 @@ test('createStreamDecoder - legacy', function (t) {
})

t.test('keys', function (t) {
var decoder = codec.createStreamDecoder({
const decoder = codec.createStreamDecoder({
keys: true
})
t.equal(decoder(Buffer.from('hey')), '686579')
t.end()
})

t.test('values', function (t) {
var decoder = codec.createStreamDecoder({
const decoder = codec.createStreamDecoder({
encoding: 'hex',
values: true
})
Expand Down
28 changes: 14 additions & 14 deletions test/kv.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
var test = require('tape')
var Codec = require('..')
const test = require('tape')
const Codec = require('..')

test('encode key', function (t) {
var codec = new Codec({ keyEncoding: 'hex' })
const codec = new Codec({ keyEncoding: 'hex' })

var buf = codec.encodeKey('686579', {})
let buf = codec.encodeKey('686579', {})
t.equal(buf.toString(), 'hey')

buf = codec.encodeKey('686579')
Expand All @@ -24,9 +24,9 @@ test('encode key', function (t) {
})

test('encode value', function (t) {
var codec = new Codec({ valueEncoding: 'hex' })
const codec = new Codec({ valueEncoding: 'hex' })

var buf = codec.encodeValue('686579', {})
let buf = codec.encodeValue('686579', {})
t.equal(buf.toString(), 'hey')

buf = codec.encodeValue('686579')
Expand All @@ -41,9 +41,9 @@ test('encode value', function (t) {
})

test('decode key', function (t) {
var codec = new Codec({ keyEncoding: 'hex' })
const codec = new Codec({ keyEncoding: 'hex' })

var buf = codec.decodeKey(Buffer.from('hey'), {})
let buf = codec.decodeKey(Buffer.from('hey'), {})
t.equal(buf, '686579')

buf = codec.decodeKey(Buffer.from('hey'))
Expand All @@ -58,9 +58,9 @@ test('decode key', function (t) {
})

test('decode value', function (t) {
var codec = new Codec({ valueEncoding: 'hex' })
const codec = new Codec({ valueEncoding: 'hex' })

var buf = codec.decodeValue(Buffer.from('hey'), {})
let buf = codec.decodeValue(Buffer.from('hey'), {})
t.equal(buf, '686579')

buf = codec.decodeValue(Buffer.from('hey'))
Expand All @@ -75,9 +75,9 @@ test('decode value', function (t) {
})

test('encode value - legacy', function (t) {
var codec = new Codec({ encoding: 'hex' })
const codec = new Codec({ encoding: 'hex' })

var buf = codec.encodeValue('686579', {})
let buf = codec.encodeValue('686579', {})
t.equal(buf.toString(), 'hey')

buf = codec.encodeValue('686579')
Expand All @@ -92,9 +92,9 @@ test('encode value - legacy', function (t) {
})

test('decode value - legacy', function (t) {
var codec = new Codec({ encoding: 'hex' })
const codec = new Codec({ encoding: 'hex' })

var buf = codec.decodeValue(Buffer.from('hey'), {})
let buf = codec.decodeValue(Buffer.from('hey'), {})
t.equal(buf, '686579')

buf = codec.decodeValue(Buffer.from('hey'))
Expand Down
Loading