Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
chore: update native-abort-controller module (#3521)
Browse files Browse the repository at this point in the history
To avoid extending built-in classes you now need to use named exports when importing `native-abort-controller`.

Fixes #3509
  • Loading branch information
achingbrain authored Feb 8, 2021
1 parent 95b891f commit 516505b
Show file tree
Hide file tree
Showing 25 changed files with 78 additions and 53 deletions.
2 changes: 1 addition & 1 deletion examples/browser-ipns-publish/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions packages/interface-ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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/",
Expand All @@ -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",
Expand All @@ -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",
Expand All @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/interface-ipfs-core/src/bitswap/wantlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion packages/interface-ipfs-core/src/pubsub/subscribe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-cli/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
4 changes: 2 additions & 2 deletions packages/ipfs-core-utils/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
7 changes: 4 additions & 3 deletions packages/ipfs-core/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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",
Expand Down Expand Up @@ -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",
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-core/src/preload.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion packages/ipfs-daemon/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
9 changes: 5 additions & 4 deletions packages/ipfs-http-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
6 changes: 3 additions & 3 deletions packages/ipfs-http-client/src/add-all.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down
6 changes: 3 additions & 3 deletions packages/ipfs-http-client/src/block/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
/**
Expand Down Expand Up @@ -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 {
Expand Down
6 changes: 3 additions & 3 deletions packages/ipfs-http-client/src/config/replace.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
/**
Expand All @@ -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', {
Expand Down
6 changes: 3 additions & 3 deletions packages/ipfs-http-client/src/dag/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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', {
Expand Down
6 changes: 3 additions & 3 deletions packages/ipfs-http-client/src/dht/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ 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')>}
*/
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', {
Expand Down
6 changes: 3 additions & 3 deletions packages/ipfs-http-client/src/files/write.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
/**
Expand All @@ -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', {
Expand Down
21 changes: 21 additions & 0 deletions packages/ipfs-http-client/src/lib/abort-signal.js
Original file line number Diff line number Diff line change
@@ -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))
}
6 changes: 3 additions & 3 deletions packages/ipfs-http-client/src/object/patch/append-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
6 changes: 3 additions & 3 deletions packages/ipfs-http-client/src/object/patch/set-data.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', {
Expand Down
6 changes: 3 additions & 3 deletions packages/ipfs-http-client/src/object/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')

Expand Down Expand Up @@ -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', {
Expand Down
6 changes: 3 additions & 3 deletions packages/ipfs-http-client/src/pubsub/publish.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {}) => {
Expand All @@ -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', {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use strict'

const AbortController = require('native-abort-controller')
const { AbortController } = require('native-abort-controller')

class SubscriptionTracker {
constructor () {
Expand Down
Loading

0 comments on commit 516505b

Please sign in to comment.