Skip to content

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 9b415fe commit 14cc9e5
Show file tree
Hide file tree
Showing 13 changed files with 57 additions and 35 deletions.
9 changes: 5 additions & 4 deletions 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 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 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 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 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 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 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 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 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 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 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 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
2 changes: 1 addition & 1 deletion src/pubsub/subscription-tracker.js
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

0 comments on commit 14cc9e5

Please sign in to comment.