11'use strict'
22
3- const { map } = require ( 'streaming-iterables ' )
3+ const map = require ( 'it-map ' )
44const errcode = require ( 'err-code' )
55
6+ /**
7+ * @typedef {import('ipfs-repo') } IPFSRepo
8+ * @typedef {import('ipld-block') } Block
9+ * @typedef {import('cids') } CID
10+ */
11+
612/**
713 * BlockService is a hybrid block datastore. It stores data in a local
814 * datastore and may retrieve data from a remote Exchange.
@@ -26,26 +32,21 @@ class BlockService {
2632 * If the node is online all requests for blocks first
2733 * check locally and afterwards ask the network for the blocks.
2834 *
29- * @param {Bitswap } bitswap
30- * @returns {void }
35+ * @param {any } bitswap
3136 */
3237 setExchange ( bitswap ) {
3338 this . _bitswap = bitswap
3439 }
3540
3641 /**
3742 * Go offline, i.e. drop the reference to bitswap.
38- *
39- * @returns {void }
4043 */
4144 unsetExchange ( ) {
4245 this . _bitswap = null
4346 }
4447
4548 /**
4649 * Is the blockservice online, i.e. is bitswap present.
47- *
48- * @returns {bool }
4950 */
5051 hasExchange ( ) {
5152 return this . _bitswap != null
@@ -55,9 +56,9 @@ class BlockService {
5556 * Put a block to the underlying datastore.
5657 *
5758 * @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
5960 * @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> }
6162 */
6263 put ( block , options ) {
6364 if ( this . hasExchange ( ) ) {
@@ -70,10 +71,10 @@ class BlockService {
7071 /**
7172 * Put a multiple blocks to the underlying datastore.
7273 *
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
7576 * @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> }
7778 */
7879 putMany ( blocks , options ) {
7980 if ( this . hasExchange ( ) ) {
@@ -87,7 +88,7 @@ class BlockService {
8788 * Get a block by cid.
8889 *
8990 * @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
9192 * @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
9293 * @returns {Promise<Block> }
9394 */
@@ -102,10 +103,10 @@ class BlockService {
102103 /**
103104 * Get multiple blocks back from an array of cids.
104105 *
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
107108 * @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> }
109110 */
110111 getMany ( cids , options ) {
111112 if ( ! Array . isArray ( cids ) ) {
@@ -115,18 +116,16 @@ class BlockService {
115116 if ( this . hasExchange ( ) ) {
116117 return this . _bitswap . getMany ( cids , options )
117118 } 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 ) )
120120 }
121121 }
122122
123123 /**
124124 * Delete a block from the blockstore.
125125 *
126126 * @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
128128 * @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 }
130129 */
131130 async delete ( cid , options ) {
132131 if ( ! await this . _repo . blocks . has ( cid ) ) {
@@ -139,10 +138,9 @@ class BlockService {
139138 /**
140139 * Delete multiple blocks from the blockstore.
141140 *
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
144143 * @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 }
146144 */
147145 deleteMany ( cids , options ) {
148146 const repo = this . _repo
0 commit comments