diff --git a/package.json b/package.json index 0ee1731..81312eb 100644 --- a/package.json +++ b/package.json @@ -38,14 +38,15 @@ }, "homepage": "https://github.com/ipfs/js-datastore-core#readme", "devDependencies": { - "aegir": "^19.0.3", + "aegir": "^21.4.5", "async-iterator-all": "^1.0.0", "chai": "^4.2.0", "dirty-chai": "^2.0.1" }, "dependencies": { + "buffer": "^5.5.0", "debug": "^4.1.1", - "interface-datastore": "~0.7.0" + "interface-datastore": "^0.8.2" }, "engines": { "node": ">=6.0.0", diff --git a/src/mount.js b/src/mount.js index 15f6ce1..3141080 100644 --- a/src/mount.js +++ b/src/mount.js @@ -32,7 +32,7 @@ class MountDatastore { * @returns {{Datastore, Key, Key}} */ _lookup (key) { - for (let mount of this.mounts) { + for (const mount of this.mounts) { if (mount.prefix.toString() === key.toString() || mount.prefix.isAncestorOf(key)) { const s = replaceStartWith(key.toString(), mount.prefix.toString()) return { @@ -156,15 +156,9 @@ class MountDatastore { function _many (iterable) { return (async function * () { - let completed = iterable.map(() => false) - while (!completed.every(Boolean)) { - for (const [idx, itr] of iterable.entries()) { - const it = await itr.next() - if (it.done) { - completed[idx] = true - continue - } - yield it.value + for (let i = 0; i < iterable.length; i++) { + for await (const v of iterable[i]) { + yield v } } })() diff --git a/src/sharding.js b/src/sharding.js index e345f0b..967fccf 100644 --- a/src/sharding.js +++ b/src/sharding.js @@ -1,5 +1,6 @@ 'use strict' +const { Buffer } = require('buffer') const Key = require('interface-datastore').Key const sh = require('./shard') diff --git a/src/tiered.js b/src/tiered.js index a025fc6..a79bbac 100644 --- a/src/tiered.js +++ b/src/tiered.js @@ -17,7 +17,7 @@ class TieredDatastore { async open () { try { - await (this.stores.map((store) => store.open())) + await Promise.all(this.stores.map((store) => store.open())) } catch (err) { throw Errors.dbOpenFailedError() } @@ -43,18 +43,14 @@ class TieredDatastore { throw Errors.notFoundError() } - has (key) { - return new Promise(async (resolve) => { - await Promise.all(this.stores.map(async (store) => { - const has = await store.has(key) - - if (has) { - resolve(true) - } - })) + async has (key) { + for (const s of this.stores) { + if (await s.has(key)) { + return true + } + } - resolve(false) - }) + return false } async delete (key) { diff --git a/test/keytransform.spec.js b/test/keytransform.spec.js index 72f6507..f058c1a 100644 --- a/test/keytransform.spec.js +++ b/test/keytransform.spec.js @@ -1,6 +1,7 @@ /* eslint-env mocha */ 'use strict' +const { Buffer } = require('buffer') const chai = require('chai') chai.use(require('dirty-chai')) const expect = chai.expect @@ -37,9 +38,9 @@ describe('KeyTransformDatastore', () => { 'foo/bar/baz/barb' ].map((s) => new Key(s)) await Promise.all(keys.map((key) => kStore.put(key, Buffer.from(key.toString())))) - let kResults = Promise.all(keys.map((key) => kStore.get(key))) - let mResults = Promise.all(keys.map((key) => mStore.get(new Key('abc').child(key)))) - let results = await Promise.all([kResults, mResults]) + const kResults = Promise.all(keys.map((key) => kStore.get(key))) + const mResults = Promise.all(keys.map((key) => mStore.get(new Key('abc').child(key)))) + const results = await Promise.all([kResults, mResults]) expect(results[0]).to.eql(results[1]) const mRes = await all(mStore.query({})) diff --git a/test/mount.spec.js b/test/mount.spec.js index 0936c0f..a948610 100644 --- a/test/mount.spec.js +++ b/test/mount.spec.js @@ -2,6 +2,7 @@ /* eslint max-nested-callbacks: ["error", 8] */ 'use strict' +const { Buffer } = require('buffer') const chai = require('chai') chai.use(require('dirty-chai')) const assert = chai.assert diff --git a/test/namespace.spec.js b/test/namespace.spec.js index 397d859..7246889 100644 --- a/test/namespace.spec.js +++ b/test/namespace.spec.js @@ -1,6 +1,7 @@ /* eslint-env mocha */ 'use strict' +const { Buffer } = require('buffer') const chai = require('chai') chai.use(require('dirty-chai')) const expect = chai.expect @@ -30,9 +31,9 @@ describe('KeyTransformDatastore', () => { ].map((s) => new Key(s)) await Promise.all(keys.map(key => store.put(key, Buffer.from(key.toString())))) - let nResults = Promise.all(keys.map((key) => store.get(key))) - let mResults = Promise.all(keys.map((key) => mStore.get(new Key(prefix).child(key)))) - let results = await Promise.all([nResults, mResults]) + const nResults = Promise.all(keys.map((key) => store.get(key))) + const mResults = Promise.all(keys.map((key) => mStore.get(new Key(prefix).child(key)))) + const results = await Promise.all([nResults, mResults]) const mRes = await all(mStore.query({})) const nRes = await all(store.query({})) diff --git a/test/sharding.spec.js b/test/sharding.spec.js index fe0fba9..ad8ca9f 100644 --- a/test/sharding.spec.js +++ b/test/sharding.spec.js @@ -1,6 +1,7 @@ /* eslint-env mocha */ 'use strict' +const { Buffer } = require('buffer') const chai = require('chai') chai.use(require('dirty-chai')) const expect = chai.expect diff --git a/test/tiered.spec.js b/test/tiered.spec.js index 83e4d43..e8f2a96 100644 --- a/test/tiered.spec.js +++ b/test/tiered.spec.js @@ -1,6 +1,7 @@ /* eslint-env mocha */ 'use strict' +const { Buffer } = require('buffer') const chai = require('chai') chai.use(require('dirty-chai')) const expect = chai.expect @@ -12,7 +13,7 @@ const TieredStore = require('../src').TieredDatastore describe('Tiered', () => { describe('all stores', () => { - let ms = [] + const ms = [] let store beforeEach(() => { ms.push(new MemoryStore()) @@ -40,6 +41,10 @@ describe('Tiered', () => { expect(exists).to.be.eql(true) }) + it('has - key not found', async () => { + expect(await store.has(new Key('hello1'))).to.be.eql(false) + }) + it('has and delete', async () => { const k = new Key('hello') const v = Buffer.from('world')