1
- import type { Blockstore , Pair } from 'interface-blockstore'
2
- import type { AbortOptions , Await , AwaitIterable } from 'interface-store'
1
+ import type { Blockstore , InputPair , Pair } from 'interface-blockstore'
2
+ import type { AbortOptions , Await , AwaitGenerator , AwaitIterable } from 'interface-store'
3
3
import type { CID } from 'multiformats/cid'
4
4
5
5
export class BaseBlockstore implements Blockstore {
6
6
has ( key : CID , options ?: AbortOptions ) : Await < boolean > {
7
7
return Promise . reject ( new Error ( '.has is not implemented' ) )
8
8
}
9
9
10
- put ( key : CID , val : Uint8Array , options ?: AbortOptions ) : Await < CID > {
10
+ put ( key : CID , val : Uint8Array | AwaitIterable < Uint8Array > , options ?: AbortOptions ) : Await < CID > {
11
11
return Promise . reject ( new Error ( '.put is not implemented' ) )
12
12
}
13
13
14
- async * putMany ( source : AwaitIterable < Pair > , options ?: AbortOptions ) : AwaitIterable < CID > {
15
- for await ( const { cid, block } of source ) {
16
- await this . put ( cid , block , options )
14
+ async * putMany ( source : AwaitIterable < InputPair > , options ?: AbortOptions ) : AwaitGenerator < CID > {
15
+ for await ( const { cid, bytes } of source ) {
16
+ await this . put ( cid , bytes , options )
17
17
yield cid
18
18
}
19
19
}
20
20
21
- get ( key : CID , options ?: AbortOptions ) : Await < Uint8Array > {
22
- return Promise . reject ( new Error ( '.get is not implemented' ) )
21
+ get ( key : CID , options ?: AbortOptions ) : AwaitGenerator < Uint8Array > {
22
+ throw new Error ( '.get is not implemented' )
23
23
}
24
24
25
- async * getMany ( source : AwaitIterable < CID > , options ?: AbortOptions ) : AwaitIterable < Pair > {
25
+ async * getMany ( source : AwaitIterable < CID > , options ?: AbortOptions ) : AwaitGenerator < Pair > {
26
26
for await ( const key of source ) {
27
27
yield {
28
28
cid : key ,
29
- block : await this . get ( key , options )
29
+ bytes : this . get ( key , options )
30
30
}
31
31
}
32
32
}
@@ -35,7 +35,7 @@ export class BaseBlockstore implements Blockstore {
35
35
return Promise . reject ( new Error ( '.delete is not implemented' ) )
36
36
}
37
37
38
- async * deleteMany ( source : AwaitIterable < CID > , options ?: AbortOptions ) : AwaitIterable < CID > {
38
+ async * deleteMany ( source : AwaitIterable < CID > , options ?: AbortOptions ) : AwaitGenerator < CID > {
39
39
for await ( const key of source ) {
40
40
await this . delete ( key , options )
41
41
yield key
@@ -45,7 +45,7 @@ export class BaseBlockstore implements Blockstore {
45
45
/**
46
46
* Extending classes should override `query` or implement this method
47
47
*/
48
- async * getAll ( options ?: AbortOptions ) : AwaitIterable < Pair > { // eslint-disable-line require-yield
48
+ async * getAll ( options ?: AbortOptions ) : AwaitGenerator < Pair > { // eslint-disable-line require-yield
49
49
throw new Error ( '.getAll is not implemented' )
50
50
}
51
51
}
0 commit comments