diff --git a/examples/browser-ipns-publish/package.json b/examples/browser-ipns-publish/package.json index de717d67ef..0acee4f977 100644 --- a/examples/browser-ipns-publish/package.json +++ b/examples/browser-ipns-publish/package.json @@ -15,7 +15,7 @@ "human-crypto-keys": "^0.1.4", "ipfs": "^0.54.1", "ipfs-http-client": "^49.0.1", - "ipfs-utils": "^6.0.0", + "ipfs-utils": "^6.0.1", "ipns": "^0.8.0", "it-last": "^1.0.4", "p-retry": "^4.2.0", diff --git a/packages/interface-ipfs-core/package.json b/packages/interface-ipfs-core/package.json index 82a5311d49..67c52559a8 100644 --- a/packages/interface-ipfs-core/package.json +++ b/packages/interface-ipfs-core/package.json @@ -15,7 +15,7 @@ "scripts": { "lint": "aegir lint", "test": "echo 'No tests here'", - "dep-check": "aegir dep-check" + "dep-check": "aegir dep-check -i abort-controller" }, "files": [ "src/", @@ -30,6 +30,7 @@ ], "license": "MIT", "dependencies": { + "abort-controller": "^3.0.0", "aegir": "^30.3.0", "chai": "^4.2.0", "chai-as-promised": "^7.1.1", @@ -40,7 +41,7 @@ "err-code": "^2.0.3", "ipfs-unixfs": "^2.0.3", "ipfs-unixfs-importer": "^5.0.0", - "ipfs-utils": "^6.0.0", + "ipfs-utils": "^6.0.1", "ipld-block": "^0.11.0", "ipld-dag-cbor": "^0.17.0", "ipld-dag-pb": "^0.20.0", @@ -61,7 +62,7 @@ "multibase": "^3.0.0", "multihashing-async": "^2.0.1", "nanoid": "^3.1.12", - "native-abort-controller": "~0.0.3", + "native-abort-controller": "^1.0.3", "p-map": "^4.0.0", "peer-id": "^0.14.1", "readable-stream": "^3.4.0", diff --git a/packages/interface-ipfs-core/src/bitswap/wantlist.js b/packages/interface-ipfs-core/src/bitswap/wantlist.js index 63d31bad59..c209b039f9 100644 --- a/packages/interface-ipfs-core/src/bitswap/wantlist.js +++ b/packages/interface-ipfs-core/src/bitswap/wantlist.js @@ -5,7 +5,7 @@ const { getDescribe, getIt, expect } = require('../utils/mocha') const { waitForWantlistKey, waitForWantlistKeyToBeRemoved } = require('./utils') const { isWebWorker } = require('ipfs-utils/src/env') const testTimeout = require('../utils/test-timeout') -const AbortController = require('native-abort-controller') +const { AbortController } = require('native-abort-controller') const CID = require('cids') const delay = require('delay') const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all') diff --git a/packages/interface-ipfs-core/src/pubsub/subscribe.js b/packages/interface-ipfs-core/src/pubsub/subscribe.js index 7416a34809..e8ca12b831 100644 --- a/packages/interface-ipfs-core/src/pubsub/subscribe.js +++ b/packages/interface-ipfs-core/src/pubsub/subscribe.js @@ -9,7 +9,7 @@ const all = require('it-all') const { waitForPeers, getTopic } = require('./utils') const { getDescribe, getIt, expect } = require('../utils/mocha') const delay = require('delay') -const AbortController = require('native-abort-controller') +const { AbortController } = require('native-abort-controller') const { isWebWorker, isNode } = require('ipfs-utils/src/env') const getIpfsOptions = require('../utils/ipfs-options-websockets-filter-all') const first = require('it-first') diff --git a/packages/ipfs-cli/package.json b/packages/ipfs-cli/package.json index 35474797f6..64af6051b8 100644 --- a/packages/ipfs-cli/package.json +++ b/packages/ipfs-cli/package.json @@ -41,7 +41,7 @@ "ipfs-daemon": "^0.5.1", "ipfs-http-client": "^49.0.1", "ipfs-repo": "^8.0.0", - "ipfs-utils": "^6.0.0", + "ipfs-utils": "^6.0.1", "ipld-dag-cbor": "^0.17.0", "ipld-dag-pb": "^0.20.0", "it-all": "^1.0.4", diff --git a/packages/ipfs-core-utils/package.json b/packages/ipfs-core-utils/package.json index 375978acf8..f2a77808eb 100644 --- a/packages/ipfs-core-utils/package.json +++ b/packages/ipfs-core-utils/package.json @@ -36,13 +36,13 @@ }, "license": "MIT", "dependencies": { - "any-signal": "^2.0.0", + "any-signal": "^2.1.2", "blob-to-it": "^1.0.1", "browser-readablestream-to-it": "^1.0.1", "cids": "^1.1.5", "err-code": "^2.0.3", "ipfs-core-types": "^0.3.0", - "ipfs-utils": "^6.0.0", + "ipfs-utils": "^6.0.1", "it-all": "^1.0.4", "it-map": "^1.0.4", "it-peekable": "^1.0.1", diff --git a/packages/ipfs-core/package.json b/packages/ipfs-core/package.json index 478358fa33..9e58e0f2d1 100644 --- a/packages/ipfs-core/package.json +++ b/packages/ipfs-core/package.json @@ -50,9 +50,10 @@ "test:bootstrapers": "IPFS_TEST=bootstrapers aegir test -t browser -f test/bootstrapers.js", "coverage": "nyc --reporter=text --reporter=lcov npm run test:node", "clean": "rimraf ./dist", - "dep-check": "aegir dep-check -i interface-ipfs-core -i ipfs-core-types" + "dep-check": "aegir dep-check -i interface-ipfs-core -i ipfs-core-types -i abort-controller" }, "dependencies": { + "abort-controller": "^3.0.0", "array-shuffle": "^2.0.0", "bignumber.js": "^9.0.0", "cbor": "^6.0.1", @@ -75,7 +76,7 @@ "ipfs-unixfs": "^2.0.3", "ipfs-unixfs-exporter": "^3.0.4", "ipfs-unixfs-importer": "^5.0.0", - "ipfs-utils": "^6.0.0", + "ipfs-utils": "^6.0.1", "ipld": "^0.28.0", "ipld-block": "^0.11.0", "ipld-dag-cbor": "^0.17.0", @@ -109,7 +110,7 @@ "multibase": "^3.0.0", "multicodec": "^2.0.1", "multihashing-async": "^2.0.1", - "native-abort-controller": "~0.0.3", + "native-abort-controller": "^1.0.3", "p-queue": "^6.6.1", "parse-duration": "^0.4.4", "peer-id": "^0.14.1", diff --git a/packages/ipfs-core/src/preload.js b/packages/ipfs-core/src/preload.js index 6c74a7d508..d6857ca8ed 100644 --- a/packages/ipfs-core/src/preload.js +++ b/packages/ipfs-core/src/preload.js @@ -4,7 +4,7 @@ const toUri = require('multiaddr-to-uri') const debug = require('debug') const CID = require('cids') const shuffle = require('array-shuffle') -const AbortController = require('native-abort-controller') +const { AbortController } = require('native-abort-controller') const preload = require('./runtime/preload-nodejs') /** @type {typeof import('hashlru').default} */ // @ts-ignore - hashlru has incorrect typedefs diff --git a/packages/ipfs-daemon/package.json b/packages/ipfs-daemon/package.json index 7fa7b8998f..ea257beeec 100644 --- a/packages/ipfs-daemon/package.json +++ b/packages/ipfs-daemon/package.json @@ -35,7 +35,7 @@ "ipfs-http-client": "^49.0.1", "ipfs-http-gateway": "^0.3.0", "ipfs-http-server": "^0.3.1", - "ipfs-utils": "^6.0.0", + "ipfs-utils": "^6.0.1", "just-safe-set": "^2.1.0", "libp2p": "^0.30.7", "libp2p-delegated-content-routing": "^0.9.0", diff --git a/packages/ipfs-http-client/package.json b/packages/ipfs-http-client/package.json index 62b19d43eb..8c09f1ad32 100644 --- a/packages/ipfs-http-client/package.json +++ b/packages/ipfs-http-client/package.json @@ -48,17 +48,18 @@ "prepare": "aegir build --no-bundle", "coverage": "npx nyc -r html npm run test:node -- --bail", "clean": "rimraf ./dist", - "dep-check": "aegir dep-check -i ipfs-core -i rimraf -i ipfs-core-types" + "dep-check": "aegir dep-check -i ipfs-core -i rimraf -i ipfs-core-types -i abort-controller" }, "dependencies": { - "any-signal": "^2.0.0", + "abort-controller": "^3.0.0", + "any-signal": "^2.1.2", "bignumber.js": "^9.0.0", "cids": "^1.1.5", "debug": "^4.1.1", "form-data": "^3.0.0", "ipfs-core-types": "^0.3.0", "ipfs-core-utils": "^0.7.0", - "ipfs-utils": "^6.0.0", + "ipfs-utils": "^6.0.1", "ipld-block": "^0.11.0", "ipld-dag-cbor": "^0.17.0", "ipld-dag-pb": "^0.20.0", @@ -73,7 +74,7 @@ "multicodec": "^2.0.1", "multihashes": "^3.0.1", "nanoid": "^3.1.12", - "native-abort-controller": "~0.0.3", + "native-abort-controller": "^1.0.3", "parse-duration": "^0.4.4", "stream-to-it": "^0.2.2", "uint8arrays": "^2.0.5" diff --git a/packages/ipfs-http-client/src/add-all.js b/packages/ipfs-http-client/src/add-all.js index 9dcfbfad7c..57a54e8bb2 100644 --- a/packages/ipfs-http-client/src/add-all.js +++ b/packages/ipfs-http-client/src/add-all.js @@ -5,8 +5,8 @@ const toCamel = require('./lib/object-to-camel') const configure = require('./lib/configure') const multipartRequest = require('./lib/multipart-request') const toUrlSearchParams = require('./lib/to-url-search-params') -const { anySignal } = require('any-signal') -const AbortController = require('native-abort-controller') +const abortSignal = require('./lib/abort-signal') +const { AbortController } = require('native-abort-controller') /** * @typedef {import('ipfs-utils/src/types').ProgressFn} IPFSUtilsHttpUploadProgressFn @@ -20,7 +20,7 @@ module.exports = configure((api) => { async function * addAll (source, options = {}) { // allow aborting requests on body errors const controller = new AbortController() - const signal = anySignal([controller.signal, options.signal]) + const signal = abortSignal(controller.signal, options.signal) const { headers, body, total, parts } = await multipartRequest(source, controller, options.headers) diff --git a/packages/ipfs-http-client/src/block/put.js b/packages/ipfs-http-client/src/block/put.js index a4f549da38..2e3d5c8a34 100644 --- a/packages/ipfs-http-client/src/block/put.js +++ b/packages/ipfs-http-client/src/block/put.js @@ -6,8 +6,8 @@ const multihash = require('multihashes') const multipartRequest = require('../lib/multipart-request') const configure = require('../lib/configure') const toUrlSearchParams = require('../lib/to-url-search-params') -const { anySignal } = require('any-signal') -const AbortController = require('native-abort-controller') +const abortSignal = require('../lib/abort-signal') +const { AbortController } = require('native-abort-controller') module.exports = configure(api => { /** @@ -41,7 +41,7 @@ module.exports = configure(api => { // allow aborting requests on body errors const controller = new AbortController() - const signal = anySignal([controller.signal, options.signal]) + const signal = abortSignal(controller.signal, options.signal) let res try { diff --git a/packages/ipfs-http-client/src/config/replace.js b/packages/ipfs-http-client/src/config/replace.js index 961d8b6ba7..fe9386aa77 100644 --- a/packages/ipfs-http-client/src/config/replace.js +++ b/packages/ipfs-http-client/src/config/replace.js @@ -4,8 +4,8 @@ const uint8ArrayFromString = require('uint8arrays/from-string') const multipartRequest = require('../lib/multipart-request') const configure = require('../lib/configure') const toUrlSearchParams = require('../lib/to-url-search-params') -const { anySignal } = require('any-signal') -const AbortController = require('native-abort-controller') +const abortSignal = require('../lib/abort-signal') +const { AbortController } = require('native-abort-controller') module.exports = configure(api => { /** @@ -14,7 +14,7 @@ module.exports = configure(api => { const replace = async (config, options = {}) => { // allow aborting requests on body errors const controller = new AbortController() - const signal = anySignal([controller.signal, options.signal]) + const signal = abortSignal(controller.signal, options.signal) // @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90 const res = await api.post('config/replace', { diff --git a/packages/ipfs-http-client/src/dag/put.js b/packages/ipfs-http-client/src/dag/put.js index 401313f052..5c2899ecb7 100644 --- a/packages/ipfs-http-client/src/dag/put.js +++ b/packages/ipfs-http-client/src/dag/put.js @@ -5,8 +5,8 @@ const multihash = require('multihashes') const configure = require('../lib/configure') const multipartRequest = require('../lib/multipart-request') const toUrlSearchParams = require('../lib/to-url-search-params') -const { anySignal } = require('any-signal') -const AbortController = require('native-abort-controller') +const abortSignal = require('../lib/abort-signal') +const { AbortController } = require('native-abort-controller') const multicodec = require('multicodec') const loadFormat = require('../lib/ipld-formats') @@ -48,7 +48,7 @@ module.exports = configure((api, opts) => { // allow aborting requests on body errors const controller = new AbortController() - const signal = anySignal([controller.signal, settings.signal]) + const signal = abortSignal(controller.signal, settings.signal) // @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90 const res = await api.post('dag/put', { diff --git a/packages/ipfs-http-client/src/dht/put.js b/packages/ipfs-http-client/src/dht/put.js index ba8ac11ac0..66a9de5349 100644 --- a/packages/ipfs-http-client/src/dht/put.js +++ b/packages/ipfs-http-client/src/dht/put.js @@ -6,8 +6,8 @@ const toCamel = require('../lib/object-to-camel') const configure = require('../lib/configure') const toUrlSearchParams = require('../lib/to-url-search-params') const multipartRequest = require('../lib/multipart-request') -const { anySignal } = require('any-signal') -const AbortController = require('native-abort-controller') +const abortSignal = require('../lib/abort-signal') +const { AbortController } = require('native-abort-controller') module.exports = configure(api => { /** * @type {import('..').ImplementsMethod<'put', import('ipfs-core/src/components/dht')>} @@ -15,7 +15,7 @@ module.exports = configure(api => { async function * put (key, value, options = {}) { // allow aborting requests on body errors const controller = new AbortController() - const signal = anySignal([controller.signal, options.signal]) + const signal = abortSignal(controller.signal, options.signal) // @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90 const res = await api.post('dht/put', { diff --git a/packages/ipfs-http-client/src/files/write.js b/packages/ipfs-http-client/src/files/write.js index b67692643c..917078613f 100644 --- a/packages/ipfs-http-client/src/files/write.js +++ b/packages/ipfs-http-client/src/files/write.js @@ -5,8 +5,8 @@ const { mtimeToObject } = require('ipfs-core-utils/src/files/normalise-input/uti const configure = require('../lib/configure') const multipartRequest = require('../lib/multipart-request') const toUrlSearchParams = require('../lib/to-url-search-params') -const { anySignal } = require('any-signal') -const AbortController = require('native-abort-controller') +const abortSignal = require('../lib/abort-signal') +const { AbortController } = require('native-abort-controller') module.exports = configure(api => { /** @@ -15,7 +15,7 @@ module.exports = configure(api => { async function write (path, input, options = {}) { // allow aborting requests on body errors const controller = new AbortController() - const signal = anySignal([controller.signal, options.signal]) + const signal = abortSignal(controller.signal, options.signal) // @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90 const res = await api.post('files/write', { diff --git a/packages/ipfs-http-client/src/lib/abort-signal.js b/packages/ipfs-http-client/src/lib/abort-signal.js new file mode 100644 index 0000000000..c12e44c921 --- /dev/null +++ b/packages/ipfs-http-client/src/lib/abort-signal.js @@ -0,0 +1,21 @@ +'use strict' + +const { anySignal } = require('any-signal') + +/** + * @typedef {AbortSignal | undefined} MaybeSignal + * + * @param {MaybeSignal[]} signals + * @returns {AbortSignal[]} + */ +function filter (signals) { + // @ts-ignore + return signals.filter(Boolean) +} + +/** + * @param {...AbortSignal|undefined} signals + */ +module.exports = (...signals) => { + return anySignal(filter(signals)) +} diff --git a/packages/ipfs-http-client/src/object/patch/append-data.js b/packages/ipfs-http-client/src/object/patch/append-data.js index 6d71d8059f..c7d8f67715 100644 --- a/packages/ipfs-http-client/src/object/patch/append-data.js +++ b/packages/ipfs-http-client/src/object/patch/append-data.js @@ -4,14 +4,14 @@ const CID = require('cids') const multipartRequest = require('../../lib/multipart-request') const configure = require('../../lib/configure') const toUrlSearchParams = require('../../lib/to-url-search-params') -const { anySignal } = require('any-signal') -const AbortController = require('native-abort-controller') +const abortSignal = require('../../lib/abort-signal') +const { AbortController } = require('native-abort-controller') module.exports = configure(api => { return async (cid, data, options = {}) => { // allow aborting requests on body errors const controller = new AbortController() - const signal = anySignal([controller.signal, options.signal]) + const signal = abortSignal(controller.signal, options.signal) // @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90 const res = await api.post('object/patch/append-data', { diff --git a/packages/ipfs-http-client/src/object/patch/set-data.js b/packages/ipfs-http-client/src/object/patch/set-data.js index 43eb55fa7b..84eedc6b64 100644 --- a/packages/ipfs-http-client/src/object/patch/set-data.js +++ b/packages/ipfs-http-client/src/object/patch/set-data.js @@ -4,14 +4,14 @@ const CID = require('cids') const multipartRequest = require('../../lib/multipart-request') const configure = require('../../lib/configure') const toUrlSearchParams = require('../../lib/to-url-search-params') -const { anySignal } = require('any-signal') -const AbortController = require('native-abort-controller') +const abortSignal = require('../../lib/abort-signal') +const { AbortController } = require('native-abort-controller') module.exports = configure(api => { return async (cid, data, options = {}) => { // allow aborting requests on body errors const controller = new AbortController() - const signal = anySignal([controller.signal, options.signal]) + const signal = abortSignal(controller.signal, options.signal) // @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90 const { Hash } = await (await api.post('object/patch/set-data', { diff --git a/packages/ipfs-http-client/src/object/put.js b/packages/ipfs-http-client/src/object/put.js index 37d64f2bde..abf6b203ff 100644 --- a/packages/ipfs-http-client/src/object/put.js +++ b/packages/ipfs-http-client/src/object/put.js @@ -5,8 +5,8 @@ const { DAGNode } = require('ipld-dag-pb') const multipartRequest = require('../lib/multipart-request') const configure = require('../lib/configure') const toUrlSearchParams = require('../lib/to-url-search-params') -const { anySignal } = require('any-signal') -const AbortController = require('native-abort-controller') +const abortSignal = require('../lib/abort-signal') +const { AbortController } = require('native-abort-controller') const unit8ArrayToString = require('uint8arrays/to-string') const uint8ArrayFromString = require('uint8arrays/from-string') @@ -49,7 +49,7 @@ module.exports = configure(api => { // allow aborting requests on body errors const controller = new AbortController() - const signal = anySignal([controller.signal, options.signal]) + const signal = abortSignal(controller.signal, options.signal) // @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90 const res = await api.post('object/put', { diff --git a/packages/ipfs-http-client/src/pubsub/publish.js b/packages/ipfs-http-client/src/pubsub/publish.js index 93fd882c06..e9ef335303 100644 --- a/packages/ipfs-http-client/src/pubsub/publish.js +++ b/packages/ipfs-http-client/src/pubsub/publish.js @@ -3,8 +3,8 @@ const configure = require('../lib/configure') const toUrlSearchParams = require('../lib/to-url-search-params') const multipartRequest = require('../lib/multipart-request') -const { anySignal } = require('any-signal') -const AbortController = require('native-abort-controller') +const abortSignal = require('../lib/abort-signal') +const { AbortController } = require('native-abort-controller') module.exports = configure(api => { return async (topic, data, options = {}) => { @@ -15,7 +15,7 @@ module.exports = configure(api => { // allow aborting requests on body errors const controller = new AbortController() - const signal = anySignal([controller.signal, options.signal]) + const signal = abortSignal(controller.signal, options.signal) // @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90 const res = await api.post('pubsub/pub', { diff --git a/packages/ipfs-http-client/src/pubsub/subscription-tracker.js b/packages/ipfs-http-client/src/pubsub/subscription-tracker.js index d6da454784..5aaf93f5be 100644 --- a/packages/ipfs-http-client/src/pubsub/subscription-tracker.js +++ b/packages/ipfs-http-client/src/pubsub/subscription-tracker.js @@ -1,6 +1,6 @@ 'use strict' -const AbortController = require('native-abort-controller') +const { AbortController } = require('native-abort-controller') class SubscriptionTracker { constructor () { diff --git a/packages/ipfs-http-server/package.json b/packages/ipfs-http-server/package.json index 9b45c67e5e..29bae7183d 100644 --- a/packages/ipfs-http-server/package.json +++ b/packages/ipfs-http-server/package.json @@ -25,12 +25,13 @@ "test:node": "aegir test -t node", "coverage": "nyc --reporter=text --reporter=lcov npm run test:node", "clean": "rimraf ./dist", - "dep-check": "aegir dep-check -i ipfs-http-client -i rimraf" + "dep-check": "aegir dep-check -i ipfs-http-client -i rimraf -i abort-controller" }, "dependencies": { "@hapi/boom": "^9.1.0", "@hapi/content": "^5.0.2", "@hapi/hapi": "^20.0.0", + "abort-controller": "^3.0.0", "cids": "^1.1.5", "debug": "^4.1.1", "dlv": "^1.1.3", @@ -56,7 +57,7 @@ "multibase": "^3.0.0", "multicodec": "^2.0.1", "multihashing-async": "^2.0.1", - "native-abort-controller": "~0.0.3", + "native-abort-controller": "^1.0.3", "parse-duration": "^0.4.4", "stream-to-it": "^0.2.2", "streaming-iterables": "^5.0.2", diff --git a/packages/ipfs-http-server/src/index.js b/packages/ipfs-http-server/src/index.js index 062814abf9..409452b0c5 100644 --- a/packages/ipfs-http-server/src/index.js +++ b/packages/ipfs-http-server/src/index.js @@ -6,7 +6,7 @@ const debug = require('debug') const multiaddr = require('multiaddr') const toMultiaddr = require('uri-to-multiaddr') const Boom = require('@hapi/boom') -const AbortController = require('native-abort-controller') +const { AbortController } = require('native-abort-controller') const errorHandler = require('./error-handler') const LOG = 'ipfs:http-api' const LOG_ERROR = 'ipfs:http-api:error' diff --git a/packages/ipfs/package.json b/packages/ipfs/package.json index 71afeb87e3..69beacd95e 100644 --- a/packages/ipfs/package.json +++ b/packages/ipfs/package.json @@ -53,7 +53,7 @@ "ipfs-client": "^0.3.1", "ipfs-http-client": "^49.0.1", "ipfs-interop": "^4.0.2", - "ipfs-utils": "^6.0.0", + "ipfs-utils": "^6.0.1", "ipfsd-ctl": "^7.2.0", "iso-url": "^1.0.0", "libp2p-webrtc-star": "^0.21.0",