1
1
'use strict'
2
2
3
- const { map } = require ( 'streaming-iterables ' )
3
+ const map = require ( 'it-map ' )
4
4
const errcode = require ( 'err-code' )
5
5
6
+ /**
7
+ * @typedef {import('ipfs-repo') } IPFSRepo
8
+ * @typedef {import('ipld-block') } Block
9
+ * @typedef {import('cids') } CID
10
+ */
11
+
6
12
/**
7
13
* BlockService is a hybrid block datastore. It stores data in a local
8
14
* datastore and may retrieve data from a remote Exchange.
@@ -26,26 +32,21 @@ class BlockService {
26
32
* If the node is online all requests for blocks first
27
33
* check locally and afterwards ask the network for the blocks.
28
34
*
29
- * @param {Bitswap } bitswap
30
- * @returns {void }
35
+ * @param {any } bitswap
31
36
*/
32
37
setExchange ( bitswap ) {
33
38
this . _bitswap = bitswap
34
39
}
35
40
36
41
/**
37
42
* Go offline, i.e. drop the reference to bitswap.
38
- *
39
- * @returns {void }
40
43
*/
41
44
unsetExchange ( ) {
42
45
this . _bitswap = null
43
46
}
44
47
45
48
/**
46
49
* Is the blockservice online, i.e. is bitswap present.
47
- *
48
- * @returns {bool }
49
50
*/
50
51
hasExchange ( ) {
51
52
return this . _bitswap != null
@@ -55,9 +56,9 @@ class BlockService {
55
56
* Put a block to the underlying datastore.
56
57
*
57
58
* @param {Block } block
58
- * @param {Object } [options] - Options is an object with the following properties
59
+ * @param {object } [options] - Options is an object with the following properties
59
60
* @param {AbortSignal } [options.signal] - A signal that can be used to abort any long-lived operations that are started as a result of this operation
60
- * @returns {Promise }
61
+ * @returns {Promise<Block> }
61
62
*/
62
63
put ( block , options ) {
63
64
if ( this . hasExchange ( ) ) {
@@ -70,10 +71,10 @@ class BlockService {
70
71
/**
71
72
* Put a multiple blocks to the underlying datastore.
72
73
*
73
- * @param {AsyncIterator <Block> } blocks
74
- * @param {Object } [options] - Options is an object with the following properties
74
+ * @param {AsyncIterable<Block> | Iterable <Block> } blocks
75
+ * @param {object } [options] - Options is an object with the following properties
75
76
* @param {AbortSignal } [options.signal] - A signal that can be used to abort any long-lived operations that are started as a result of this operation
76
- * @returns {Promise }
77
+ * @returns {AsyncIterable<Block> }
77
78
*/
78
79
putMany ( blocks , options ) {
79
80
if ( this . hasExchange ( ) ) {
@@ -87,7 +88,7 @@ class BlockService {
87
88
* Get a block by cid.
88
89
*
89
90
* @param {CID } cid
90
- * @param {Object } [options] - Options is an object with the following properties
91
+ * @param {object } [options] - Options is an object with the following properties
91
92
* @param {AbortSignal } [options.signal] - A signal that can be used to abort any long-lived operations that are started as a result of this operation
92
93
* @returns {Promise<Block> }
93
94
*/
@@ -102,10 +103,10 @@ class BlockService {
102
103
/**
103
104
* Get multiple blocks back from an array of cids.
104
105
*
105
- * @param {AsyncIterator <CID> } cids
106
- * @param {Object } [options] - Options is an object with the following properties
106
+ * @param {AsyncIterable<CID> | Iterable <CID> } cids
107
+ * @param {object } [options] - Options is an object with the following properties
107
108
* @param {AbortSignal } [options.signal] - A signal that can be used to abort any long-lived operations that are started as a result of this operation
108
- * @returns {AsyncIterator <Block> }
109
+ * @returns {AsyncIterable <Block> }
109
110
*/
110
111
getMany ( cids , options ) {
111
112
if ( ! Array . isArray ( cids ) ) {
@@ -115,18 +116,16 @@ class BlockService {
115
116
if ( this . hasExchange ( ) ) {
116
117
return this . _bitswap . getMany ( cids , options )
117
118
} else {
118
- const getRepoBlocks = map ( ( cid ) => this . _repo . blocks . get ( cid , options ) )
119
- return getRepoBlocks ( cids )
119
+ return map ( cids , ( cid ) => this . _repo . blocks . get ( cid , options ) )
120
120
}
121
121
}
122
122
123
123
/**
124
124
* Delete a block from the blockstore.
125
125
*
126
126
* @param {CID } cid
127
- * @param {Object } [options] - Options is an object with the following properties
127
+ * @param {object } [options] - Options is an object with the following properties
128
128
* @param {AbortSignal } [options.signal] - A signal that can be used to abort any long-lived operations that are started as a result of this operation
129
- * @returns {Promise }
130
129
*/
131
130
async delete ( cid , options ) {
132
131
if ( ! await this . _repo . blocks . has ( cid ) ) {
@@ -139,10 +138,9 @@ class BlockService {
139
138
/**
140
139
* Delete multiple blocks from the blockstore.
141
140
*
142
- * @param {AsyncIterator <CID> } cids
143
- * @param {Object } [options] - Options is an object with the following properties
141
+ * @param {AsyncIterable<CID> | Iterable <CID> } cids
142
+ * @param {object } [options] - Options is an object with the following properties
144
143
* @param {AbortSignal } [options.signal] - A signal that can be used to abort any long-lived operations that are started as a result of this operation
145
- * @returns {Promise }
146
144
*/
147
145
deleteMany ( cids , options ) {
148
146
const repo = this . _repo
0 commit comments