From fa59ac0b63ef3a89e36f9525764445abc6125ae5 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 28 Jul 2020 16:13:10 +0100 Subject: [PATCH 1/3] fix: remove node buffers This module didn't have a lot of buffer use in the first place, but we remove any references to buffers in favour of Uint8Arrays. When quering, values come back as Buffers which are Uint8Arrays so the conversion was unecessary. Depends on: - [ ] https://github.com/ipfs/interface-datastore/pull/43 - [ ] https://github.com/ipfs/js-datastore-core/pull/27 BREAKING CHANGE: remove node buffers in favour of Uint8Arrays --- .aegir.js | 10 ++++++++++ package.json | 10 +++++----- src/index.js | 2 +- test/index.spec.js | 4 ++-- 4 files changed, 18 insertions(+), 8 deletions(-) create mode 100644 .aegir.js diff --git a/.aegir.js b/.aegir.js new file mode 100644 index 0000000..f176614 --- /dev/null +++ b/.aegir.js @@ -0,0 +1,10 @@ +'use strict' + +module.exports = { + webpack: { + node: { + // this is needed until level stops using node buffers in browser code + Buffer: true + } + } +} diff --git a/package.json b/package.json index bd28419..9ef5bd1 100644 --- a/package.json +++ b/package.json @@ -37,14 +37,14 @@ }, "homepage": "https://github.com/ipfs/js-datastore-level#readme", "dependencies": { - "datastore-core": "^1.1.0", - "interface-datastore": "^1.0.2", - "level": "^5.0.1" + "datastore-core": "ipfs/js-datastore-core#fix/remove-node-buffers", + "interface-datastore": "ipfs/interface-datastore#fix/remove-node-buffer", + "level": "^5.0.2" }, "devDependencies": { - "aegir": "^22.0.0", + "aegir": "^25.0.0", "chai": "^4.2.0", - "cids": "^0.8.0", + "cids": "^0.8.3", "dirty-chai": "^2.0.1", "level-mem": "^5.0.1", "rimraf": "^3.0.0" diff --git a/src/index.js b/src/index.js index c52b961..26a20f6 100644 --- a/src/index.js +++ b/src/index.js @@ -133,7 +133,7 @@ class LevelDatastore extends Adapter { it = map(it, ({ key, value }) => { const res = { key: new Key(key, false) } if (values) { - res.value = Buffer.from(value) + res.value = value } return res }) diff --git a/test/index.spec.js b/test/index.spec.js index 60d1f8b..d4ab1ee 100644 --- a/test/index.spec.js +++ b/test/index.spec.js @@ -6,8 +6,8 @@ chai.use(require('dirty-chai')) const expect = chai.expect const levelmem = require('level-mem') const level = require('level') -const os = require('os') const LevelStore = require('../src') +const { utils } = require('interface-datastore') describe('LevelDatastore', () => { describe('initialization', () => { @@ -43,7 +43,7 @@ describe('LevelDatastore', () => { ;[levelmem, level].forEach(database => { describe(`interface-datastore ${database.name}`, () => { require('interface-datastore/src/tests')({ - setup: () => new LevelStore(`${os.tmpdir()}/datastore-level-test-${Math.random()}`, { db: database }), + setup: () => new LevelStore(utils.tmpdir(), { db: database }), teardown () {} }) }) From 4cd4489f4e3c6cd8c230f9b1693dd90a839e2957 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Tue, 28 Jul 2020 18:21:51 +0100 Subject: [PATCH 2/3] chore: use actual level version --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index 9ef5bd1..66ec88c 100644 --- a/package.json +++ b/package.json @@ -39,7 +39,7 @@ "dependencies": { "datastore-core": "ipfs/js-datastore-core#fix/remove-node-buffers", "interface-datastore": "ipfs/interface-datastore#fix/remove-node-buffer", - "level": "^5.0.2" + "level": "^5.0.1" }, "devDependencies": { "aegir": "^25.0.0", From 640624cafb5ee40996edc1227d9fa1a5c95e6dd3 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Wed, 29 Jul 2020 14:19:19 +0100 Subject: [PATCH 3/3] chore: remove gh urls --- package.json | 4 ++-- test/node.js | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/package.json b/package.json index 66ec88c..40e203f 100644 --- a/package.json +++ b/package.json @@ -37,8 +37,8 @@ }, "homepage": "https://github.com/ipfs/js-datastore-level#readme", "dependencies": { - "datastore-core": "ipfs/js-datastore-core#fix/remove-node-buffers", - "interface-datastore": "ipfs/interface-datastore#fix/remove-node-buffer", + "datastore-core": "^2.0.0", + "interface-datastore": "^2.0.0", "level": "^5.0.1" }, "devDependencies": { diff --git a/test/node.js b/test/node.js index 2cf0115..8bc6ca6 100644 --- a/test/node.js +++ b/test/node.js @@ -63,7 +63,7 @@ describe('LevelDatastore', () => { const cids = [] for await (const e of store.query({})) { - cids.push(new CID(1, 'dag-cbor', e.key.toBuffer())) + cids.push(new CID(1, 'dag-cbor', e.key.uint8Array())) } expect(cids[0].version).to.be.eql(0)