From d7e5b386c8420b66b9469ef59cfda4bc24a83c97 Mon Sep 17 00:00:00 2001 From: achingbrain Date: Thu, 23 Sep 2021 12:56:41 +0100 Subject: [PATCH] chore: remove streaming iterables It's got some problems when bundling: ``` resolve 'process/browser' in '/Users/alex/Documents/Workspaces/ipfs-examples/js-ipfs-examples/node_modules/streaming-iterables/dist' Parsed request is a module using description file: /Users/alex/Documents/Workspaces/ipfs-examples/js-ipfs-examples/node_modules/streaming-iterables/package.json (relative path: ./dist) Field 'browser' doesn't contain a valid alias configuration ... ``` --- packages/ipfs-core/package.json | 2 +- packages/ipfs-core/src/components/block/rm.js | 41 +++++++++++-------- 2 files changed, 24 insertions(+), 19 deletions(-) diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index 33e53a5a77..f8b21885a9 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -105,6 +105,7 @@ "it-last": "^1.0.4", "it-map": "^1.0.4", "it-merge": "^1.0.2", + "it-parallel": "^1.0.0", "it-peekable": "^1.0.2", "it-pipe": "^1.1.0", "it-pushable": "^1.4.2", @@ -128,7 +129,6 @@ "pako": "^1.0.2", "parse-duration": "^1.0.0", "peer-id": "^0.15.1", - "streaming-iterables": "^6.0.0", "timeout-abort-controller": "^1.1.1", "uint8arrays": "^3.0.0" }, diff --git a/packages/ipfs-core/src/components/block/rm.js b/packages/ipfs-core/src/components/block/rm.js index 4554e14b52..5143dc2839 100644 --- a/packages/ipfs-core/src/components/block/rm.js +++ b/packages/ipfs-core/src/components/block/rm.js @@ -1,6 +1,8 @@ import errCode from 'err-code' -import { parallelMap, filter } from 'streaming-iterables' +import parallel from 'it-parallel' +import map from 'it-map' +import filter from 'it-filter' import { pipe } from 'it-pipe' import { cleanCid } from './utils.js' import { withTimeoutOption } from 'ipfs-core-utils/with-timeout-option' @@ -27,30 +29,33 @@ export function createRm ({ repo }) { try { yield * pipe( cids, - parallelMap(BLOCK_RM_CONCURRENCY, async cid => { - cid = cleanCid(cid) + source => map(source, cid => { + return async () => { + cid = cleanCid(cid) - /** @type {import('ipfs-core-types/src/block').RmResult} */ - const result = { cid } + /** @type {import('ipfs-core-types/src/block').RmResult} */ + const result = { cid } - try { - const has = await repo.blocks.has(cid) + try { + const has = await repo.blocks.has(cid) - if (!has) { - throw errCode(new Error('block not found'), 'ERR_BLOCK_NOT_FOUND') - } + if (!has) { + throw errCode(new Error('block not found'), 'ERR_BLOCK_NOT_FOUND') + } - await repo.blocks.delete(cid) - } catch (/** @type {any} */ err) { - if (!options.force) { - err.message = `cannot remove ${cid}: ${err.message}` - result.error = err + await repo.blocks.delete(cid) + } catch (/** @type {any} */ err) { + if (!options.force) { + err.message = `cannot remove ${cid}: ${err.message}` + result.error = err + } } - } - return result + return result + } }), - filter(() => !options.quiet) + source => parallel(source, BLOCK_RM_CONCURRENCY), + source => filter(source, () => !options.quiet) ) } finally { release()