Skip to content

Commit

Permalink
Merge pull request #7 from adorsys/edge-compatibility
Browse files Browse the repository at this point in the history
feat(*): Add edge compatibility
  • Loading branch information
radzom authored Jan 10, 2020
2 parents b0e5d5a + 07cb6f3 commit 6051d42
Show file tree
Hide file tree
Showing 7 changed files with 10,260 additions and 8,292 deletions.
12 changes: 4 additions & 8 deletions .airtap.yml
Original file line number Diff line number Diff line change
@@ -1,15 +1,11 @@
browsers:
- name: chrome
version: latest
platform: Windows 10
# - name: internet explorer
# version: '11'
- name: firefox
version: latest
platform: Windows 10
# - name: iphone
# version: '9.0'
- name: safari
version: latest
- name: microsoftedge
version: latest
- name: android
version: '6.0'
# - name: microsoftedge
# version: latest
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
.idea/

# dist
dist

Expand Down Expand Up @@ -74,3 +76,6 @@ typings/

# Serverless directories
.serverless

# Ignore IDEA
.idea/
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ branches:
- master
addons:
sauce_connect: true
hosts:
- airtap.local

notifications:
email: false
script:
Expand Down
18,449 changes: 10,208 additions & 8,241 deletions package-lock.json

Large diffs are not rendered by default.

58 changes: 29 additions & 29 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
"lint": "standard --verbose | snazzy",
"format": "prettier-standard '**/*.js'",
"test": "nyc --reporter=lcov --reporter=text ava",
"test:integ-browser": "airtap test/integrations/leveljs.test.js",
"test:integ-browser": "airtap --loopback airtap.local test/integrations/leveljs.test.js",
"test:integ-browser-local": "airtap --coverage --local --port 9000 test/integrations/leveljs.test.js",
"test:integ-node": "tape test/integrations/leveldown.test.js test/integrations/memdown.test.js | tap-spec",
"test:ci": "npm run test && npm run test:integ-node && npm run test:integ-browser",
Expand Down Expand Up @@ -62,35 +62,35 @@
"verbose": true
},
"dependencies": {
"@adorsys/jwe-codec": "1.0.0",
"abstract-leveldown": "6.0.0",
"inherits": "2.0.3",
"node-jose": "1.0.0"
"@adorsys/jwe-codec": "^1.0.1",
"abstract-leveldown": "^6.2.2",
"inherits": "^2.0.4",
"node-jose": "^1.1.3"
},
"devDependencies": {
"@commitlint/cli": "7.1.2",
"@commitlint/config-conventional": "7.1.2",
"airtap": "0.1.0",
"ava": "1.0.0-beta.8",
"browserify": "16.2.3",
"coveralls": "3.0.2",
"cuid": "2.1.4",
"eslint-plugin-html": "4.0.5",
"eslint-plugin-markdown": "1.0.0-beta.6",
"husky": "1.0.0-rc.15",
"level-concat-iterator": "2.0.0",
"level-js": "3.0.0",
"leveldown": "4.0.1",
"lint-staged": "7.3.0",
"memdown": "3.0.0",
"nyc": "13.0.1",
"prettier-standard": "8.0.1",
"semantic-release": "^15.9.17",
"snazzy": "8.0.0",
"standard": "12.0.1",
"tap-spec": "5.0.0",
"tape": "4.9.1",
"tempy": "0.2.1",
"travis-deploy-once": "^5.0.9"
"@commitlint/cli": "^8.3.4",
"@commitlint/config-conventional": "^8.3.4",
"airtap": "^2.0.4",
"ava": "^2.4.0",
"browserify": "^16.5.0",
"coveralls": "^3.0.9",
"cuid": "^2.1.8",
"eslint-plugin-html": "^6.0.0",
"eslint-plugin-markdown": "^1.0.1",
"husky": "^4.0.1",
"level-concat-iterator": "^2.0.1",
"level-js": "^4.0.2",
"leveldown": "^5.4.1",
"lint-staged": "^9.5.0",
"memdown": "^4.1.0",
"nyc": "^15.0.0",
"prettier-standard": "^16.1.0",
"semantic-release": "^15.14.0",
"snazzy": "^8.0.0",
"standard": "^14.3.1",
"tap-spec": "^5.0.0",
"tape": "^4.13.0",
"tempy": "^0.3.0",
"travis-deploy-once": "^5.0.11"
}
}
17 changes: 5 additions & 12 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,18 +62,15 @@ DB.prototype._put = function (key, value, options, callback) {
}

DB.prototype._get = function (key, options, callback) {
this.db.get(key, { ...options, asBuffer: false }, (err, cipher) => {
this.db.get(key, Object.assign({}, options, { asBuffer: false }), (err, cipher) => {
if (err) {
return callback(err)
}
this.codec
.decrypt(cipher)
.then(function (value) {
const checkedValue = emptyStringWhenNull(value)
callback(
null,
options.asBuffer ? Buffer.from(String(checkedValue)) : checkedValue
)
callback(null, options.asBuffer ? Buffer.from(String(checkedValue)) : checkedValue)
})
.catch(callback)
})
Expand Down Expand Up @@ -108,7 +105,7 @@ function Iterator (db, options) {
this.keys = options.keys
this.values = options.values
this.options = options
this.it = db.db.iterator({ ...this.options, valueAsBuffer: false })
this.it = db.db.iterator(Object.assign({}, this.options, { valueAsBuffer: false }))
}

inherits(Iterator, AbstractIterator)
Expand All @@ -124,11 +121,7 @@ Iterator.prototype._next = function (callback) {
this.codec
.decrypt(cipher)
.then(value => {
callback(
null,
key,
this.options.valueAsBuffer ? Buffer.from(String(value)) : value
)
callback(null, key, this.options.valueAsBuffer ? Buffer.from(String(value)) : value)
})
.catch(callback)
})
Expand All @@ -144,6 +137,6 @@ function emptyStringWhenNull (value) {

function encryptOperationValue (codec, operation) {
return codec.encrypt(operation.value).then(function (cipher) {
return { ...operation, value: cipher }
return Object.assign({}, operation, { value: cipher })
})
}
8 changes: 6 additions & 2 deletions test/encrypt-down.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ test.cb('unsorted entry, sorted iterator', t => {
await promisedDB.put('a', 'A')
await promisedDB.put('c', 'C')
await promisedDB.put('e', 'E')
await promisedDB.put('ß', 'ß')
await promisedDB.put('😀', '🎉')
await promisedDB.batch([
{ type: 'put', key: 'd', value: 'D' },
{ type: 'put', key: 'b', value: 'B' },
Expand All @@ -58,13 +60,15 @@ test.cb('unsorted entry, sorted iterator', t => {
promisedDB.db.iterator({ keyAsBuffer: false, valueAsBuffer: false }),
function (err, data) {
t.falsy(err, 'no error')
t.is(data.length, 5, 'correct number of entries')
t.is(data.length, 7, 'correct number of entries')
const expected = [
{ key: 'a', value: 'A' },
{ key: 'c', value: 'C' },
{ key: 'd', value: 'D' },
{ key: 'f', value: 'F' },
{ key: 'g', value: 'G' }
{ key: 'g', value: 'G' },
{ key: 'ß', value: 'ß' },
{ key: '😀', value: '🎉' }
]
t.deepEqual(data, expected)
t.end()
Expand Down

0 comments on commit 6051d42

Please sign in to comment.