This repository was archived by the owner on Mar 23, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 9 files changed +32
-31
lines changed Expand file tree Collapse file tree 9 files changed +32
-31
lines changed Original file line number Diff line number Diff line change 38
38
},
39
39
"homepage" : " https://github.com/ipfs/js-datastore-core#readme" ,
40
40
"devDependencies" : {
41
- "aegir" : " ^19.0.3 " ,
41
+ "aegir" : " ^21.4.5 " ,
42
42
"async-iterator-all" : " ^1.0.0" ,
43
43
"chai" : " ^4.2.0" ,
44
44
"dirty-chai" : " ^2.0.1"
45
45
},
46
46
"dependencies" : {
47
+ "buffer" : " ^5.5.0" ,
47
48
"debug" : " ^4.1.1" ,
48
- "interface-datastore" : " ~0.7.0 "
49
+ "interface-datastore" : " ^0.8.2 "
49
50
},
50
51
"engines" : {
51
52
"node" : " >=6.0.0" ,
Original file line number Diff line number Diff line change @@ -32,7 +32,7 @@ class MountDatastore {
32
32
* @returns {{Datastore, Key, Key} }
33
33
*/
34
34
_lookup ( key ) {
35
- for ( let mount of this . mounts ) {
35
+ for ( const mount of this . mounts ) {
36
36
if ( mount . prefix . toString ( ) === key . toString ( ) || mount . prefix . isAncestorOf ( key ) ) {
37
37
const s = replaceStartWith ( key . toString ( ) , mount . prefix . toString ( ) )
38
38
return {
@@ -156,15 +156,9 @@ class MountDatastore {
156
156
157
157
function _many ( iterable ) {
158
158
return ( async function * ( ) {
159
- let completed = iterable . map ( ( ) => false )
160
- while ( ! completed . every ( Boolean ) ) {
161
- for ( const [ idx , itr ] of iterable . entries ( ) ) {
162
- const it = await itr . next ( )
163
- if ( it . done ) {
164
- completed [ idx ] = true
165
- continue
166
- }
167
- yield it . value
159
+ for ( let i = 0 ; i < iterable . length ; i ++ ) {
160
+ for await ( const v of iterable [ i ] ) {
161
+ yield v
168
162
}
169
163
}
170
164
} ) ( )
Original file line number Diff line number Diff line change 1
1
'use strict'
2
2
3
+ const { Buffer } = require ( 'buffer' )
3
4
const Key = require ( 'interface-datastore' ) . Key
4
5
5
6
const sh = require ( './shard' )
Original file line number Diff line number Diff line change @@ -17,7 +17,7 @@ class TieredDatastore {
17
17
18
18
async open ( ) {
19
19
try {
20
- await ( this . stores . map ( ( store ) => store . open ( ) ) )
20
+ await Promise . all ( this . stores . map ( ( store ) => store . open ( ) ) )
21
21
} catch ( err ) {
22
22
throw Errors . dbOpenFailedError ( )
23
23
}
@@ -43,18 +43,14 @@ class TieredDatastore {
43
43
throw Errors . notFoundError ( )
44
44
}
45
45
46
- has ( key ) {
47
- return new Promise ( async ( resolve ) => {
48
- await Promise . all ( this . stores . map ( async ( store ) => {
49
- const has = await store . has ( key )
50
-
51
- if ( has ) {
52
- resolve ( true )
53
- }
54
- } ) )
46
+ async has ( key ) {
47
+ for ( const s of this . stores ) {
48
+ if ( await s . has ( key ) ) {
49
+ return true
50
+ }
51
+ }
55
52
56
- resolve ( false )
57
- } )
53
+ return false
58
54
}
59
55
60
56
async delete ( key ) {
Original file line number Diff line number Diff line change 1
1
/* eslint-env mocha */
2
2
'use strict'
3
3
4
+ const { Buffer } = require ( 'buffer' )
4
5
const chai = require ( 'chai' )
5
6
chai . use ( require ( 'dirty-chai' ) )
6
7
const expect = chai . expect
@@ -37,9 +38,9 @@ describe('KeyTransformDatastore', () => {
37
38
'foo/bar/baz/barb'
38
39
] . map ( ( s ) => new Key ( s ) )
39
40
await Promise . all ( keys . map ( ( key ) => kStore . put ( key , Buffer . from ( key . toString ( ) ) ) ) )
40
- let kResults = Promise . all ( keys . map ( ( key ) => kStore . get ( key ) ) )
41
- let mResults = Promise . all ( keys . map ( ( key ) => mStore . get ( new Key ( 'abc' ) . child ( key ) ) ) )
42
- let results = await Promise . all ( [ kResults , mResults ] )
41
+ const kResults = Promise . all ( keys . map ( ( key ) => kStore . get ( key ) ) )
42
+ const mResults = Promise . all ( keys . map ( ( key ) => mStore . get ( new Key ( 'abc' ) . child ( key ) ) ) )
43
+ const results = await Promise . all ( [ kResults , mResults ] )
43
44
expect ( results [ 0 ] ) . to . eql ( results [ 1 ] )
44
45
45
46
const mRes = await all ( mStore . query ( { } ) )
Original file line number Diff line number Diff line change 2
2
/* eslint max-nested-callbacks: ["error", 8] */
3
3
'use strict'
4
4
5
+ const { Buffer } = require ( 'buffer' )
5
6
const chai = require ( 'chai' )
6
7
chai . use ( require ( 'dirty-chai' ) )
7
8
const assert = chai . assert
Original file line number Diff line number Diff line change 1
1
/* eslint-env mocha */
2
2
'use strict'
3
3
4
+ const { Buffer } = require ( 'buffer' )
4
5
const chai = require ( 'chai' )
5
6
chai . use ( require ( 'dirty-chai' ) )
6
7
const expect = chai . expect
@@ -30,9 +31,9 @@ describe('KeyTransformDatastore', () => {
30
31
] . map ( ( s ) => new Key ( s ) )
31
32
32
33
await Promise . all ( keys . map ( key => store . put ( key , Buffer . from ( key . toString ( ) ) ) ) )
33
- let nResults = Promise . all ( keys . map ( ( key ) => store . get ( key ) ) )
34
- let mResults = Promise . all ( keys . map ( ( key ) => mStore . get ( new Key ( prefix ) . child ( key ) ) ) )
35
- let results = await Promise . all ( [ nResults , mResults ] )
34
+ const nResults = Promise . all ( keys . map ( ( key ) => store . get ( key ) ) )
35
+ const mResults = Promise . all ( keys . map ( ( key ) => mStore . get ( new Key ( prefix ) . child ( key ) ) ) )
36
+ const results = await Promise . all ( [ nResults , mResults ] )
36
37
const mRes = await all ( mStore . query ( { } ) )
37
38
const nRes = await all ( store . query ( { } ) )
38
39
Original file line number Diff line number Diff line change 1
1
/* eslint-env mocha */
2
2
'use strict'
3
3
4
+ const { Buffer } = require ( 'buffer' )
4
5
const chai = require ( 'chai' )
5
6
chai . use ( require ( 'dirty-chai' ) )
6
7
const expect = chai . expect
Original file line number Diff line number Diff line change 1
1
/* eslint-env mocha */
2
2
'use strict'
3
3
4
+ const { Buffer } = require ( 'buffer' )
4
5
const chai = require ( 'chai' )
5
6
chai . use ( require ( 'dirty-chai' ) )
6
7
const expect = chai . expect
@@ -12,7 +13,7 @@ const TieredStore = require('../src').TieredDatastore
12
13
13
14
describe ( 'Tiered' , ( ) => {
14
15
describe ( 'all stores' , ( ) => {
15
- let ms = [ ]
16
+ const ms = [ ]
16
17
let store
17
18
beforeEach ( ( ) => {
18
19
ms . push ( new MemoryStore ( ) )
@@ -40,6 +41,10 @@ describe('Tiered', () => {
40
41
expect ( exists ) . to . be . eql ( true )
41
42
} )
42
43
44
+ it ( 'has - key not found' , async ( ) => {
45
+ expect ( await store . has ( new Key ( 'hello1' ) ) ) . to . be . eql ( false )
46
+ } )
47
+
43
48
it ( 'has and delete' , async ( ) => {
44
49
const k = new Key ( 'hello' )
45
50
const v = Buffer . from ( 'world' )
You can’t perform that action at this time.
0 commit comments