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

Commit

Permalink
fix: also check for async iterators
Browse files Browse the repository at this point in the history
Add an additional check for async iterators. This check was also
submitted upstream to typical: 75lb/typical#2
  • Loading branch information
vmx committed Feb 28, 2019
1 parent e209c8f commit 00a94f6
Showing 1 changed file with 9 additions and 3 deletions.
12 changes: 9 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,9 @@ class IPLDResolver {
* @returns {Iterable.<Promise.<Object>>} - Returns an async iterator with the IPLD Nodes that correspond to the given `cids`.
*/
get (cids) {
if (!typical.isIterable(cids) || typical.isString(cids) ||
if (!(typical.isIterable(cids) ||
typeof cids[Symbol.asyncIterator] === 'function') ||
typical.isString(cids) ||
Buffer.isBuffer(cids)) {
throw new Error('`cids` must be an iterable of CIDs')
}
Expand Down Expand Up @@ -163,7 +165,9 @@ class IPLDResolver {
* @returns {Iterable.<Promise.<CID>>} - Returns an async iterator with the CIDs of the serialized IPLD Nodes.
*/
put (nodes, format, userOptions) {
if (!typical.isIterable(nodes) || typical.isString(nodes) ||
if (!(typical.isIterable(nodes) ||
typeof nodes[Symbol.asyncIterator] === 'function') ||
typical.isString(nodes) ||
Buffer.isBuffer(nodes)) {
throw new Error('`nodes` must be an iterable')
}
Expand Down Expand Up @@ -218,7 +222,9 @@ class IPLDResolver {
* @return {void}
*/
remove (cids) {
if (!typical.isIterable(cids) || typical.isString(cids) ||
if (!(typical.isIterable(cids) ||
typeof cids[Symbol.asyncIterator] === 'function') ||
typical.isString(cids) ||
Buffer.isBuffer(cids)) {
throw new Error('`cids` must be an iterable of CIDs')
}
Expand Down

0 comments on commit 00a94f6

Please sign in to comment.