Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit 00a94f6

Browse files
committed
fix: also check for async iterators
Add an additional check for async iterators. This check was also submitted upstream to typical: 75lb/typical#2
1 parent e209c8f commit 00a94f6

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/index.js

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,9 @@ class IPLDResolver {
134134
* @returns {Iterable.<Promise.<Object>>} - Returns an async iterator with the IPLD Nodes that correspond to the given `cids`.
135135
*/
136136
get (cids) {
137-
if (!typical.isIterable(cids) || typical.isString(cids) ||
137+
if (!(typical.isIterable(cids) ||
138+
typeof cids[Symbol.asyncIterator] === 'function') ||
139+
typical.isString(cids) ||
138140
Buffer.isBuffer(cids)) {
139141
throw new Error('`cids` must be an iterable of CIDs')
140142
}
@@ -163,7 +165,9 @@ class IPLDResolver {
163165
* @returns {Iterable.<Promise.<CID>>} - Returns an async iterator with the CIDs of the serialized IPLD Nodes.
164166
*/
165167
put (nodes, format, userOptions) {
166-
if (!typical.isIterable(nodes) || typical.isString(nodes) ||
168+
if (!(typical.isIterable(nodes) ||
169+
typeof nodes[Symbol.asyncIterator] === 'function') ||
170+
typical.isString(nodes) ||
167171
Buffer.isBuffer(nodes)) {
168172
throw new Error('`nodes` must be an iterable')
169173
}
@@ -218,7 +222,9 @@ class IPLDResolver {
218222
* @return {void}
219223
*/
220224
remove (cids) {
221-
if (!typical.isIterable(cids) || typical.isString(cids) ||
225+
if (!(typical.isIterable(cids) ||
226+
typeof cids[Symbol.asyncIterator] === 'function') ||
227+
typical.isString(cids) ||
222228
Buffer.isBuffer(cids)) {
223229
throw new Error('`cids` must be an iterable of CIDs')
224230
}

0 commit comments

Comments
 (0)