Skip to content
This repository was archived by the owner on Mar 23, 2023. It is now read-only.

Commit 4c23666

Browse files
committed
chore: fix linting, address PR comments
1 parent 79ed3f7 commit 4c23666

File tree

10 files changed

+63
-61
lines changed

10 files changed

+63
-61
lines changed

package.json

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,17 @@
55
"leadMaintainer": "Pedro Teixeira <pedro@protocol.ai>",
66
"main": "src/index.js",
77
"scripts": {
8-
"lint": "aegir lint",
9-
"build": "aegir build",
108
"test": "aegir test",
11-
"flow": "flow",
12-
"test:node": "aegir test --target node",
13-
"test:browser": "aegir test --target browser",
14-
"release": "aegir release --docs",
15-
"release-minor": "aegir release --type minor --docs",
16-
"release-major": "aegir release --type major --docs",
17-
"coverage": "aegir coverage",
18-
"coverage-publish": "aegir coverage --provider codecov",
19-
"docs": "aegir docs"
9+
"test:node": "aegir test -t node",
10+
"test:browser": "aegir test -t browser",
11+
"test:webworker": "aegir test -t webworker",
12+
"build": "aegir build",
13+
"lint": "aegir lint",
14+
"release": "aegir release",
15+
"release-minor": "aegir release --type minor",
16+
"release-major": "aegir release --type major",
17+
"coverage": "nyc -s npm run test:node && nyc report --reporter=html",
18+
"dep-check": "aegir dep-check"
2019
},
2120
"files": [
2221
"src",
@@ -39,12 +38,13 @@
3938
},
4039
"homepage": "https://github.com/ipfs/js-datastore-core#readme",
4140
"devDependencies": {
42-
"aegir": "^v18.2.0",
41+
"aegir": "^19.0.3",
42+
"async-iterator-all": "^1.0.0",
4343
"chai": "^4.2.0",
44-
"dirty-chai": "^2.0.1",
45-
"flow-bin": "~0.83.0"
44+
"dirty-chai": "^2.0.1"
4645
},
4746
"dependencies": {
47+
"debug": "^4.1.1",
4848
"interface-datastore": "~0.7.0"
4949
},
5050
"engines": {

src/keytransform.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,19 +43,19 @@ class KeyTransformDatastore /* :: <Value> */ {
4343
return this.child.open()
4444
}
4545

46-
async put (key /* : Key */, val /* : Value */) /* : Promise<void> */ {
46+
put (key /* : Key */, val /* : Value */) /* : Promise<void> */ {
4747
return this.child.put(this.transform.convert(key), val)
4848
}
4949

50-
async get (key /* : Key */) /* : Promise<Value> */ {
50+
get (key /* : Key */) /* : Promise<Value> */ {
5151
return this.child.get(this.transform.convert(key))
5252
}
5353

54-
async has (key /* : Key */) /* : Promise<bool> */ {
54+
has (key /* : Key */) /* : Promise<bool> */ {
5555
return this.child.has(this.transform.convert(key))
5656
}
5757

58-
async delete (key /* : Key */) /* : Promise<void> */ {
58+
delete (key /* : Key */) /* : Promise<void> */ {
5959
return this.child.delete(this.transform.convert(key))
6060
}
6161

@@ -68,7 +68,7 @@ class KeyTransformDatastore /* :: <Value> */ {
6868
delete: (key /* : Key */) /* : void */ => {
6969
b.delete(this.transform.convert(key))
7070
},
71-
commit: async () /* : Promise<void> */ => {
71+
commit: () /* : Promise<void> */ => {
7272
return b.commit()
7373
}
7474
}
@@ -81,7 +81,7 @@ class KeyTransformDatastore /* :: <Value> */ {
8181
})
8282
}
8383

84-
async close () /* : Promise<void> */ {
84+
close () /* : Promise<void> */ {
8585
return this.child.close()
8686
}
8787
}

src/mount.js

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class MountDatastore /* :: <Value> */ {
3131
this.mounts = mounts.slice()
3232
}
3333

34-
async open () /* : Promise<void> */ {
34+
open () /* : Promise<void> */ {
3535
return Promise.all(this.mounts.map((m) => m.datastore.open()))
3636
}
3737

@@ -55,7 +55,7 @@ class MountDatastore /* :: <Value> */ {
5555
}
5656
}
5757

58-
async put (key /* : Key */, value /* : Value */) /* : Promise<void> */ {
58+
put (key /* : Key */, value /* : Value */) /* : Promise<void> */ {
5959
const match = this._lookup(key)
6060
if (match == null) {
6161
throw Errors.dbWriteFailedError(new Error('No datastore mounted for this key'))
@@ -64,23 +64,23 @@ class MountDatastore /* :: <Value> */ {
6464
return match.datastore.put(match.rest, value)
6565
}
6666

67-
async get (key /* : Key */) /* : Promise<Value> */ {
67+
get (key /* : Key */) /* : Promise<Value> */ {
6868
const match = this._lookup(key)
6969
if (match == null) {
7070
throw Errors.notFoundError(new Error('No datastore mounted for this key'))
7171
}
7272
return match.datastore.get(match.rest)
7373
}
7474

75-
async has (key /* : Key */) /* : Promise<bool> */ {
75+
has (key /* : Key */) /* : Promise<bool> */ {
7676
const match = this._lookup(key)
7777
if (match == null) {
7878
return false
7979
}
8080
return match.datastore.has(match.rest)
8181
}
8282

83-
async delete (key /* : Key */) /* : Promise<void> */ {
83+
delete (key /* : Key */) /* : Promise<void> */ {
8484
const match = this._lookup(key)
8585
if (match == null) {
8686
throw Errors.dbDeleteFailedError(new Error('No datastore mounted for this key'))
@@ -89,7 +89,7 @@ class MountDatastore /* :: <Value> */ {
8989
return match.datastore.delete(match.rest)
9090
}
9191

92-
async close () /* : Promise<void> */ {
92+
close () /* : Promise<void> */ {
9393
return Promise.all(this.mounts.map((m) => {
9494
return m.datastore.close()
9595
}))
@@ -123,7 +123,7 @@ class MountDatastore /* :: <Value> */ {
123123
const match = lookup(key)
124124
match.batch.delete(match.rest)
125125
},
126-
commit: async () /* : Promise<void> */ => {
126+
commit: () /* : Promise<void> */ => {
127127
return Promise.all(Object.keys(batchMounts).map(p => batchMounts[p].commit()))
128128
}
129129
}

src/sharding.js

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ class ShardingDatastore {
3333
this.shard = shard
3434
}
3535

36-
async open () /* : Promise<void> */ {
36+
open () /* : Promise<void> */ {
3737
return this.child.open()
3838
}
3939

@@ -84,19 +84,19 @@ class ShardingDatastore {
8484
throw new Error('datastore exists')
8585
}
8686

87-
async put (key /* : Key */, val /* : Buffer */) /* : Promise<void> */ {
87+
put (key /* : Key */, val /* : Buffer */) /* : Promise<void> */ {
8888
return this.child.put(key, val)
8989
}
9090

91-
async get (key /* : Key */) /* : Promise<Buffer> */ {
91+
get (key /* : Key */) /* : Promise<Buffer> */ {
9292
return this.child.get(key)
9393
}
9494

95-
async has (key /* : Key */) /* : Promise<bool> */ {
95+
has (key /* : Key */) /* : Promise<bool> */ {
9696
return this.child.has(key)
9797
}
9898

99-
async delete (key /* : Key */) /* : Promise<void> */ {
99+
delete (key /* : Key */) /* : Promise<void> */ {
100100
return this.child.delete(key)
101101
}
102102

@@ -142,7 +142,7 @@ class ShardingDatastore {
142142
return this.child.query(tq)
143143
}
144144

145-
async close () /* : Promise<void> */ {
145+
close () /* : Promise<void> */ {
146146
return this.child.close()
147147
}
148148
}

src/tiered.js

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
'use strict'
33

44
const Errors = require('interface-datastore').Errors
5+
const log = require('debug')('datastore:core:tiered')
56

67
/* ::
78
import type {Key, Datastore, Callback, Batch, Query, QueryResult} from 'interface-datastore'
@@ -42,17 +43,25 @@ class TieredDatastore /* :: <Value> */ {
4243
try {
4344
const res = await store.get(key)
4445
if (res) return res
45-
} catch (err) {}
46+
} catch (err) {
47+
log(err)
48+
}
4649
}
4750
throw Errors.notFoundError()
4851
}
4952

50-
async has (key /* : Key */) /* : Promise<bool> */ {
51-
for (const store of this.stores) {
52-
const exists = await store.has(key)
53-
if (exists) return true
54-
}
55-
return false
53+
has (key /* : Key */) /* : Promise<bool> */ {
54+
return new Promise(async (resolve) => {
55+
await Promise.all(this.stores.map(async (store) => {
56+
const has = await store.has(key)
57+
58+
if (has) {
59+
resolve(true)
60+
}
61+
}))
62+
63+
resolve(false)
64+
})
5665
}
5766

5867
async delete (key /* : Key */) /* : Promise<void> */ {

test/keytransform.spec.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ chai.use(require('dirty-chai'))
77
const expect = chai.expect
88
const Memory = require('interface-datastore').MemoryDatastore
99
const Key = require('interface-datastore').Key
10-
const collect = require('./util').collect
10+
const all = require('async-iterator-all')
1111

1212
const KeytransformStore = require('../src/').KeytransformDatastore
1313

@@ -43,8 +43,8 @@ describe('KeyTransformDatastore', () => {
4343
let results = await Promise.all([kResults, mResults])
4444
expect(results[0]).to.eql(results[1])
4545

46-
const mRes = await collect(mStore.query({}))
47-
const kRes = await collect(kStore.query({}))
46+
const mRes = await all(mStore.query({}))
47+
const kRes = await all(kStore.query({}))
4848
expect(kRes).to.have.length(mRes.length)
4949

5050
mRes.forEach((a, i) => {

test/mount.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const chai = require('chai')
77
chai.use(require('dirty-chai'))
88
const assert = chai.assert
99
const expect = chai.expect
10-
const collect = require('./util').collect
10+
const all = require('async-iterator-all')
1111

1212
const Key = require('interface-datastore').Key
1313
const MemoryStore = require('interface-datastore').MemoryDatastore
@@ -102,13 +102,13 @@ describe('MountStore', () => {
102102

103103
const val = Buffer.from('hello')
104104
await m.put(new Key('/cool/hello'), val)
105-
const res = await collect(m.query({ prefix: '/cool' }))
105+
const res = await all(m.query({ prefix: '/cool' }))
106106
expect(res).to.eql([{ key: new Key('/cool/hello'), value: val }])
107107
})
108108

109109
describe('interface-datastore', () => {
110110
require('interface-datastore/src/tests')({
111-
async setup () {
111+
setup () {
112112
return new MountStore([{
113113
prefix: new Key('/a'),
114114
datastore: new MemoryStore()
@@ -120,7 +120,7 @@ describe('MountStore', () => {
120120
datastore: new MemoryStore()
121121
}])
122122
},
123-
async teardown () { }
123+
teardown () { }
124124
})
125125
})
126126
})

test/namespace.spec.js

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const Key = require('interface-datastore').Key
1010
const MemoryStore = require('interface-datastore').MemoryDatastore
1111

1212
const NamespaceStore = require('../src/').NamespaceDatastore
13-
const collect = require('./util').collect
13+
const all = require('async-iterator-all')
1414

1515
describe('KeyTransformDatastore', () => {
1616
const prefixes = [
@@ -34,8 +34,8 @@ describe('KeyTransformDatastore', () => {
3434
let nResults = Promise.all(keys.map((key) => store.get(key)))
3535
let mResults = Promise.all(keys.map((key) => mStore.get(new Key(prefix).child(key))))
3636
let results = await Promise.all([nResults, mResults])
37-
const mRes = await collect(mStore.query({}))
38-
const nRes = await collect(store.query({}))
37+
const mRes = await all(mStore.query({}))
38+
const nRes = await all(store.query({}))
3939

4040
expect(nRes).to.have.length(mRes.length)
4141

@@ -53,7 +53,7 @@ describe('KeyTransformDatastore', () => {
5353
prefixes.forEach((prefix) => {
5454
describe(`interface-datastore: '${prefix}'`, () => {
5555
require('interface-datastore/src/tests')({
56-
async setup () {
56+
setup () {
5757
return new NamespaceStore(new MemoryStore(), new Key(prefix))
5858
},
5959
async teardown () { }

test/sharding.spec.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ describe('ShardingStore', () => {
2929
try {
3030
await ShardingStore.open(ms)
3131
assert(false, 'Failed to throw error on ShardStore.open')
32-
} catch (err) {}
32+
} catch (err) {
33+
expect(err.code).to.equal('ERR_NOT_FOUND')
34+
}
3335
})
3436

3537
it('open - existing', async () => {

test/util.js

Lines changed: 0 additions & 9 deletions
This file was deleted.

0 commit comments

Comments
 (0)