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