Skip to content

Commit 1e64873

Browse files
authored
chore: update deps (#3514)
BREAKING CHANGE: ipfs-repo upgrade requires repo migration to v10
1 parent 1e874c2 commit 1e64873

18 files changed

+80
-60
lines changed

package.json

+9-10
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535
"url": "git+https://github.com/ipfs/js-ipfs.git"
3636
},
3737
"scripts": {
38+
"build": "aegir build",
3839
"test": "aegir test",
3940
"test:node": "aegir test -t node",
4041
"test:browser": "aegir test -t browser",
@@ -44,12 +45,10 @@
4445
"test:chrome": "aegir test -t browser -t webworker -- --browsers ChromeHeadless",
4546
"test:firefox": "aegir test -t browser -t webworker -- --browsers FirefoxHeadless",
4647
"lint": "aegir lint",
47-
"build": "npm run build:js && npm run build:types",
48-
"build:js": "aegir build",
49-
"build:types": "tsc --build",
48+
"prepare": "aegir build --no-bundle",
5049
"coverage": "npx nyc -r html npm run test:node -- --bail",
5150
"clean": "rimraf ./dist",
52-
"dep-check": "aegir dep-check -i typescript -i ipfs-core -i rimraf -i ipfs-core-types"
51+
"dep-check": "aegir dep-check -i ipfs-core -i rimraf -i ipfs-core-types"
5352
},
5453
"dependencies": {
5554
"any-signal": "^2.0.0",
@@ -59,7 +58,7 @@
5958
"form-data": "^3.0.0",
6059
"ipfs-core-types": "^0.2.1",
6160
"ipfs-core-utils": "^0.6.1",
62-
"ipfs-utils": "^5.0.0",
61+
"ipfs-utils": "^6.0.0",
6362
"ipld-block": "^0.11.0",
6463
"ipld-dag-cbor": "^0.17.0",
6564
"ipld-dag-pb": "^0.20.0",
@@ -68,7 +67,7 @@
6867
"it-map": "^1.0.4",
6968
"it-tar": "^1.2.2",
7069
"it-to-stream": "^0.1.2",
71-
"merge-options": "^2.0.0",
70+
"merge-options": "^3.0.4",
7271
"multiaddr": "^8.0.0",
7372
"multibase": "^3.0.0",
7473
"multicodec": "^2.0.1",
@@ -77,19 +76,19 @@
7776
"native-abort-controller": "~0.0.3",
7877
"parse-duration": "^0.4.4",
7978
"stream-to-it": "^0.2.2",
80-
"uint8arrays": "^1.1.0"
79+
"uint8arrays": "^2.0.5"
8180
},
8281
"devDependencies": {
83-
"aegir": "^29.2.2",
82+
"aegir": "^30.3.0",
8483
"delay": "^4.4.0",
8584
"go-ipfs": "0.8.0-rc2",
8685
"ipfs-core": "^0.4.2",
8786
"ipfsd-ctl": "^7.2.0",
8887
"it-all": "^1.0.4",
8988
"it-concat": "^1.0.1",
89+
"it-first": "^1.0.4",
9090
"nock": "^13.0.2",
91-
"rimraf": "^3.0.2",
92-
"typescript": "4.0.x"
91+
"rimraf": "^3.0.2"
9392
},
9493
"engines": {
9594
"node": ">=10.3.0",

src/add-all.js

+12-6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ const toUrlSearchParams = require('./lib/to-url-search-params')
88
const { anySignal } = require('any-signal')
99
const AbortController = require('native-abort-controller')
1010

11+
/**
12+
* @typedef {import('ipfs-utils/src/types').ProgressFn} IPFSUtilsHttpUploadProgressFn
13+
* @typedef {import('ipfs-core-types/src/root').AddProgressFn} IPFSCoreAddProgressFn
14+
*/
15+
1116
module.exports = configure((api) => {
1217
/**
1318
* @type {import('.').Implements<typeof import('ipfs-core/src/components/add-all/index')>}
@@ -26,7 +31,7 @@ module.exports = configure((api) => {
2631
// in which case we disable progress updates to be written out.
2732
const [progressFn, onUploadProgress] = typeof options.progress === 'function'
2833
? createProgressHandler(total, parts, options.progress)
29-
: [null, null]
34+
: [undefined, undefined]
3035

3136
const res = await api.post('add', {
3237
searchParams: toUrlSearchParams({
@@ -60,21 +65,22 @@ module.exports = configure((api) => {
6065
*
6166
* @param {number} total
6267
* @param {{name:string, start:number, end:number}[]|null} parts
63-
* @param {(n:number, name:string) => void} progress
68+
* @param {IPFSCoreAddProgressFn} progress
69+
* @returns {[IPFSCoreAddProgressFn|undefined, IPFSUtilsHttpUploadProgressFn|undefined]}
6470
*/
6571
const createProgressHandler = (total, parts, progress) =>
66-
parts ? [null, createOnUploadPrgress(total, parts, progress)] : [progress, null]
72+
parts ? [undefined, createOnUploadProgress(total, parts, progress)] : [progress, undefined]
6773

6874
/**
6975
* Creates a progress handler that interpolates progress from upload progress
7076
* events and total size of the content that is added.
7177
*
7278
* @param {number} size - actual content size
7379
* @param {{name:string, start:number, end:number}[]} parts
74-
* @param {(n:number, name:string) => void} progress
75-
* @returns {(event:{total:number, loaded: number}) => void}
80+
* @param {IPFSCoreAddProgressFn} progress
81+
* @returns {IPFSUtilsHttpUploadProgressFn}
7682
*/
77-
const createOnUploadPrgress = (size, parts, progress) => {
83+
const createOnUploadProgress = (size, parts, progress) => {
7884
let index = 0
7985
const count = parts.length
8086
return ({ loaded, total }) => {

src/block/put.js

+1
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ module.exports = configure(api => {
4545

4646
let res
4747
try {
48+
// @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90
4849
const response = await api.post('block/put', {
4950
timeout: options.timeout,
5051
signal: signal,

src/config/replace.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ module.exports = configure(api => {
1616
const controller = new AbortController()
1717
const signal = anySignal([controller.signal, options.signal])
1818

19+
// @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90
1920
const res = await api.post('config/replace', {
2021
timeout: options.timeout,
2122
signal,
@@ -25,7 +26,7 @@ module.exports = configure(api => {
2526
)
2627
})
2728

28-
return res.text()
29+
await res.text()
2930
}
3031

3132
return replace

src/dag/put.js

+1
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ module.exports = configure((api, opts) => {
5050
const controller = new AbortController()
5151
const signal = anySignal([controller.signal, settings.signal])
5252

53+
// @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90
5354
const res = await api.post('dag/put', {
5455
timeout: settings.timeout,
5556
signal,

src/dht/put.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = configure(api => {
1717
const controller = new AbortController()
1818
const signal = anySignal([controller.signal, options.signal])
1919

20+
// @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90
2021
const res = await api.post('dht/put', {
2122
timeout: options.timeout,
2223
signal,

src/files/write.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = configure(api => {
1717
const controller = new AbortController()
1818
const signal = anySignal([controller.signal, options.signal])
1919

20+
// @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90
2021
const res = await api.post('files/write', {
2122
timeout: options.timeout,
2223
signal,

src/get-endpoint-config.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ const configure = require('./lib/configure')
44

55
module.exports = configure(api => {
66
return () => {
7-
const url = new URL(api.opts.base)
7+
const url = new URL(api.opts.base || '')
88
return {
99
host: url.hostname,
1010
port: url.port,

src/interface.ts

+30-31
Original file line numberDiff line numberDiff line change
@@ -13,46 +13,45 @@
1313
*/
1414
// This is typed in TS file because otherwise TS unifies on the first parameter
1515
// regardless of number of parameters function has.
16-
export type APIWithExtraOptions<API extends (...args: any[]) => any, Extra> =
17-
(...args: WithExtendedOptions<Parameters<API>, Extra>) => ReturnType<API>
16+
export interface APIWithExtraOptions<API extends (...args: any[]) => any, Extra> { (...args: WithExtendedOptions<Parameters<API>, Extra>): ReturnType<API> }
1817

1918
type End = never[]
2019
type WithExtendedOptions<Params, Ext> = Params extends [...End]
2120
? []
2221
// (options?: Options) -> (options?: Options & Ext)
2322
: Params extends [options?: infer Options, ...end: End]
24-
? [options?: Options & Ext]
23+
? [options?: Options & Ext]
2524
// (a: A1, options?: Options) -> (a1: A1, options?: Options & Ext)
26-
: Params extends [a1: infer A1, options?: infer Options, ...end: End]
27-
? [a1: A1, options?: Options & Ext]
28-
// (a1?: A1, options?: Options) -> (a1?: A1, options?: Options & Ext)
29-
: Params extends [a1?: infer A1, options?: infer Options, ...end: End]
30-
? [a1?: A1, options?: Options & Ext]
31-
// (a1: A1, a2: A2, options?: Options) -> (a1: A1, a2: A2 options?: Options & Ext)
32-
: Params extends [a1: infer A1, a2: infer A2, options?: infer Options, ...end: End]
33-
? [a1: A1, a2: A2, options?: Options & Ext]
34-
// (a1: A1, a2?: A2, options?: Options) -> (a1: A1, a2?: A2 options?: Options & Ext)
35-
: Params extends [a1: infer A1, a2?: infer A2, options?: infer Options, ...end: End]
36-
? [a1: A1, a2?: A2, options?: Options & Ext]
37-
// (a1: A1, a2?: A2, options?: Options) -> (a1: A1, a2?: A2 options?: Options & Ext)
38-
: Params extends [a1?: infer A1, a2?: infer A2, options?: infer Options, ...end: End]
39-
? [a1?: A1, a2?: A2, options?: Options & Ext]
40-
// (a1: A1, a2: A2, a3:A3 options?: Options) -> (a1: A1, a2: A2, a3:A3, options?: Options & Ext)
41-
: Params extends [a1: infer A1, a2: infer A2, a3:infer A3, options?: infer Options, ...end: End]
42-
? [a1: A1, a2: A2, a3: A3, options?: Options & Ext]
43-
// (a1: A1, a2: A2, a3?:A3 options?: Options) -> (a1: A1, a2: A2, a3?:A3, options?: Options & Ext)
44-
: Params extends [a1: infer A1, a2:infer A2, a3?: infer A3, options?: infer Options, ...end: End]
45-
? [a1: A1, a2: A2, a3?: A3, options?: Options & Ext]
46-
// (a1: A1, a2?: A2, a3?:A3 options?: Options) -> (a1: A1, a2?: A2, a3?:A3, options?: Options & Ext)
47-
: Params extends [a1: infer A1, a2?: infer A2, a3?: infer A3, options?: infer Options, ...end: End]
48-
? [a1: A1, a2?: A2, a3?: A3, options?: Options & Ext]
49-
// (a1?: A1, a2?: A2, a3?:A3 options?: Options) -> (a1?: A1, a2?: A2, a3?:A3, options?: Options & Ext)
50-
: Params extends [a1?: infer A1, a2?: infer A2, a3?: infer A3, options?: infer Options, ...end: End]
51-
? [a1?: A1, a2?: A2, a3?: A3, options?: Options & Ext]
52-
: never
25+
: Params extends [a1: infer A1, options?: infer Options, ...end: End]
26+
? [a1: A1, options?: Options & Ext]
27+
// (a1?: A1, options?: Options) -> (a1?: A1, options?: Options & Ext)
28+
: Params extends [a1?: infer A1, options?: infer Options, ...end: End]
29+
? [a1?: A1, options?: Options & Ext]
30+
// (a1: A1, a2: A2, options?: Options) -> (a1: A1, a2: A2 options?: Options & Ext)
31+
: Params extends [a1: infer A1, a2: infer A2, options?: infer Options, ...end: End]
32+
? [a1: A1, a2: A2, options?: Options & Ext]
33+
// (a1: A1, a2?: A2, options?: Options) -> (a1: A1, a2?: A2 options?: Options & Ext)
34+
: Params extends [a1: infer A1, a2?: infer A2, options?: infer Options, ...end: End]
35+
? [a1: A1, a2?: A2, options?: Options & Ext]
36+
// (a1: A1, a2?: A2, options?: Options) -> (a1: A1, a2?: A2 options?: Options & Ext)
37+
: Params extends [a1?: infer A1, a2?: infer A2, options?: infer Options, ...end: End]
38+
? [a1?: A1, a2?: A2, options?: Options & Ext]
39+
// (a1: A1, a2: A2, a3:A3 options?: Options) -> (a1: A1, a2: A2, a3:A3, options?: Options & Ext)
40+
: Params extends [a1: infer A1, a2: infer A2, a3:infer A3, options?: infer Options, ...end: End]
41+
? [a1: A1, a2: A2, a3: A3, options?: Options & Ext]
42+
// (a1: A1, a2: A2, a3?:A3 options?: Options) -> (a1: A1, a2: A2, a3?:A3, options?: Options & Ext)
43+
: Params extends [a1: infer A1, a2:infer A2, a3?: infer A3, options?: infer Options, ...end: End]
44+
? [a1: A1, a2: A2, a3?: A3, options?: Options & Ext]
45+
// (a1: A1, a2?: A2, a3?:A3 options?: Options) -> (a1: A1, a2?: A2, a3?:A3, options?: Options & Ext)
46+
: Params extends [a1: infer A1, a2?: infer A2, a3?: infer A3, options?: infer Options, ...end: End]
47+
? [a1: A1, a2?: A2, a3?: A3, options?: Options & Ext]
48+
// (a1?: A1, a2?: A2, a3?:A3 options?: Options) -> (a1?: A1, a2?: A2, a3?:A3, options?: Options & Ext)
49+
: Params extends [a1?: infer A1, a2?: infer A2, a3?: infer A3, options?: infer Options, ...end: End]
50+
? [a1?: A1, a2?: A2, a3?: A3, options?: Options & Ext]
51+
: never
5352

5453
export type APIMethodWithExtraOptions <
5554
API,
5655
Key extends keyof API,
5756
Extra
58-
> = API[Key] extends (...args: any[]) => any ? APIWithExtraOptions<API[Key], Extra> : never
57+
> = API[Key] extends (...args: any[]) => any ? APIWithExtraOptions<API[Key], Extra> : never

src/lib/core.js

+12-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
/* eslint-env browser */
33
const Multiaddr = require('multiaddr')
44
const { isBrowser, isWebWorker, isNode } = require('ipfs-utils/src/env')
5-
const parseDuration = require('parse-duration').default
5+
const { default: parseDuration } = require('parse-duration')
66
const log = require('debug')('ipfs-http-client:lib:error-handler')
77
const HTTP = require('ipfs-utils/src/http')
88
const merge = require('merge-options')
@@ -87,6 +87,7 @@ const errorHandler = async (response) => {
8787
msg = err.message
8888
}
8989

90+
/** @type {Error} */
9091
let error = new HTTP.HTTPError(response)
9192

9293
// This is what go-ipfs returns where there's a timeout
@@ -160,25 +161,34 @@ class Client extends HTTP {
160161
out.append(kebabCase(key), value)
161162
}
162163

163-
// server timeouts are strings
164+
// @ts-ignore server timeouts are strings
164165
if (key === 'timeout' && !isNaN(value)) {
165166
out.append(kebabCase(key), value)
166167
}
167168
}
168169

169170
return out
170171
},
172+
// @ts-ignore this can be a https agent or a http agent
171173
agent: opts.agent
172174
})
173175

176+
// @ts-ignore
174177
delete this.get
178+
// @ts-ignore
175179
delete this.put
180+
// @ts-ignore
176181
delete this.delete
182+
// @ts-ignore
177183
delete this.options
178184

179185
const fetch = this.fetch
180186

181187
this.fetch = (resource, options = {}) => {
188+
if (typeof resource === 'string' && !resource.startsWith('/')) {
189+
resource = `${opts.url}/${resource}`
190+
}
191+
182192
return fetch.call(this, resource, merge(options, {
183193
method: 'POST'
184194
}))

src/lib/multipart-request.browser.js

-1
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44
// version and fail.
55
const normaliseInput = require('ipfs-core-utils/src/files/normalise-input/index.browser')
66
const modeToString = require('./mode-to-string')
7-
const { File, FormData } = require('ipfs-utils/src/globalthis')
87

98
async function multipartRequest (source = '', abortController, headers = {}) {
109
const parts = []

src/object/data.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@ module.exports = configure(api => {
1717
})
1818
const data = await res.arrayBuffer()
1919

20-
return new Uint8Array(data, data.byteOffset, data.byteLength)
20+
return new Uint8Array(data, 0, data.byteLength)
2121
}
2222
})

src/object/patch/append-data.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = configure(api => {
1313
const controller = new AbortController()
1414
const signal = anySignal([controller.signal, options.signal])
1515

16+
// @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90
1617
const res = await api.post('object/patch/append-data', {
1718
timeout: options.timeout,
1819
signal,

src/object/patch/set-data.js

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ module.exports = configure(api => {
1313
const controller = new AbortController()
1414
const signal = anySignal([controller.signal, options.signal])
1515

16+
// @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90
1617
const { Hash } = await (await api.post('object/patch/set-data', {
1718
timeout: options.timeout,
1819
signal,

src/object/put.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ const uint8ArrayFromString = require('uint8arrays/from-string')
1313
module.exports = configure(api => {
1414
return async (obj, options = {}) => {
1515
let tmpObj = {
16-
Data: null,
1716
Links: []
1817
}
1918

@@ -52,6 +51,7 @@ module.exports = configure(api => {
5251
const controller = new AbortController()
5352
const signal = anySignal([controller.signal, options.signal])
5453

54+
// @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90
5555
const res = await api.post('object/put', {
5656
timeout: options.timeout,
5757
signal,

src/pubsub/publish.js

+1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ module.exports = configure(api => {
1717
const controller = new AbortController()
1818
const signal = anySignal([controller.signal, options.signal])
1919

20+
// @ts-ignore https://github.com/ipfs/js-ipfs-utils/issues/90
2021
const res = await api.post('pubsub/pub', {
2122
timeout: options.timeout,
2223
signal,

test/constructor.spec.js

-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ const multiaddr = require('multiaddr')
55
const { expect } = require('aegir/utils/chai')
66
const f = require('./utils/factory')()
77
const ipfsClient = require('../src/index.js')
8-
const globalThis = require('ipfs-utils/src/globalthis')
98
const { isBrowser } = require('ipfs-utils/src/env')
109

1110
describe('ipfs-http-client constructor tests', () => {

test/log.spec.js

+5-5
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
const { expect } = require('aegir/utils/chai')
66
const uint8ArrayFromString = require('uint8arrays/from-string')
77
const f = require('./utils/factory')()
8+
const first = require('it-first')
89

910
describe('.log', function () {
1011
this.timeout(100 * 1000)
@@ -26,11 +27,10 @@ describe('.log', function () {
2627
}
2728
}, 1000)
2829

29-
for await (const message of ipfs.log.tail()) {
30-
clearInterval(i)
31-
expect(message).to.be.an('object')
32-
break
33-
}
30+
const message = await first(ipfs.log.tail())
31+
32+
clearInterval(i)
33+
expect(message).to.be.an('object')
3434
})
3535

3636
it('.log.ls', async () => {

0 commit comments

Comments
 (0)