Skip to content
This repository was archived by the owner on Mar 10, 2020. It is now read-only.

Commit 3e5967a

Browse files
author
Alan Shaw
authored
refactor: async await roundup (#1173)
This is a round up of the remaining async/await PRs along with some cleanup and docs fixes. resolves #1103 resolves #1122 resolves #1158 (hopefully!) closes #1164 closes #1165 closes #1166 closes #1169 closes #1170 closes #1172 BREAKING CHANGE: The `log.tail` method now returns an async iterator that yields log messages. Use it like: ```js for await (const message of ipfs.log.tail()) { console.log(message) } ``` BREAKING CHANGE: The response to a call to `log.level` now returns an object that has camel cased keys. i.e. `Message` and `Error` properties have changed to `message` and `error`. BREAKING CHANGE: Dropped support for go-ipfs <= 0.4.4 in `swarm.peers` response. BREAKING CHANGE: The signature for `ipfs.mount` has changed from `ipfs.mount([ipfsPath], [ipnsPath])` to `ipfs.mount([options])`. Where `options` is an optional object that may contain two boolean properties `ipfsPath` and `ipnsPath`. The response object has also changed to be camel case. See https://docs.ipfs.io/reference/api/http/#api-v0-mount. BREAKING CHANGE: Default ping `count` of 1 in client has been removed. The default ping count is now whatever the IPFS node defaults it to (currently 10). If you specifically need 1 ping message then please pass `count: 1` in options for `ipfs.ping()`. BREAKING CHANGE: Multi parameter constructor options are no longer supported. To create a new IPFS HTTP client, pass a single parameter to the constructor. The parameter can be one of: * String, formatted as one of: * Multiaddr e.g. /ip4/127.0.0.1/tcp/5001 * URL e.g. http://127.0.0.1:5001 * [Multiaddr](https://www.npmjs.com/package/multiaddr) instance * Object, in format of either: * Address and path e.g. `{ apiAddr: '/ip4/127.0.0.1/tcp/5001': apiPath: '/api/v0' }` (Note: `apiAddr` can also be a string in URL form or a Multiaddr instance) * Node.js style address e.g. `{ host: '127.0.0.1', port: 5001, protocol: 'http' }`
1 parent fc73da7 commit 3e5967a

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+1079
-2581
lines changed

README.md

+126-105
Large diffs are not rendered by default.

package.json

+10-22
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,6 @@
4242
},
4343
"dependencies": {
4444
"abort-controller": "^3.0.0",
45-
"async": "^2.6.1",
4645
"async-iterator-all": "^1.0.0",
4746
"async-iterator-to-pull-stream": "^1.3.0",
4847
"bignumber.js": "^9.0.0",
@@ -51,58 +50,47 @@
5150
"buffer": "^5.4.2",
5251
"callbackify": "^1.1.0",
5352
"cids": "~0.7.1",
54-
"concat-stream": "github:hugomrdias/concat-stream#feat/smaller",
5553
"debug": "^4.1.0",
56-
"detect-node": "^2.0.4",
5754
"err-code": "^2.0.0",
5855
"explain-error": "^1.0.4",
59-
"flatmap": "0.0.3",
6056
"form-data": "^3.0.0",
61-
"glob": "^7.1.3",
6257
"ipfs-block": "~0.8.1",
6358
"ipfs-utils": "^0.4.0",
6459
"ipld-dag-cbor": "~0.15.0",
6560
"ipld-dag-pb": "^0.18.1",
6661
"ipld-raw": "^4.0.0",
6762
"is-ipfs": "~0.6.1",
68-
"is-pull-stream": "0.0.0",
69-
"is-stream": "^2.0.0",
70-
"iso-stream-http": "~0.1.2",
7163
"it-glob": "0.0.6",
72-
"it-tar": "^1.1.0",
64+
"it-tar": "^1.1.1",
7365
"it-to-stream": "^0.1.1",
7466
"iterable-ndjson": "^1.1.0",
75-
"kind-of": "^6.0.2",
7667
"ky": "^0.15.0",
7768
"ky-universal": "^0.3.0",
7869
"merge-options": "^2.0.0",
7970
"multiaddr": "^6.0.6",
71+
"multiaddr-to-uri": "^5.0.0",
8072
"multibase": "~0.6.0",
8173
"multicodec": "~0.5.1",
8274
"multihashes": "~0.4.14",
83-
"ndjson": "github:hugomrdias/ndjson#feat/readable-stream3",
84-
"once": "^1.4.0",
8575
"parse-duration": "^0.1.1",
8676
"peer-id": "~0.12.3",
8777
"peer-info": "~0.15.1",
88-
"promise-nodeify": "^3.0.1",
89-
"promisify-es6": "^1.0.3",
90-
"pull-defer": "~0.2.3",
91-
"pull-stream": "^3.6.9",
92-
"pull-to-stream": "~0.1.1",
93-
"pump": "^3.0.0",
94-
"qs": "^6.5.2",
95-
"readable-stream": "^3.1.1",
96-
"stream-to-pull-stream": "^1.7.2"
78+
"promise-nodeify": "^3.0.1"
9779
},
9880
"devDependencies": {
9981
"aegir": "^20.4.1",
82+
"async": "^3.1.0",
10083
"browser-process-platform": "~0.1.1",
10184
"cross-env": "^6.0.0",
85+
"detect-node": "^2.0.4",
10286
"go-ipfs-dep": "^0.4.22",
103-
"interface-ipfs-core": "^0.120.0",
87+
"interface-ipfs-core": "^0.121.0",
10488
"ipfsd-ctl": "^0.47.1",
89+
"ndjson": "^1.5.0",
10590
"nock": "^11.4.0",
91+
"promisify-es6": "^1.0.3",
92+
"pull-stream": "^3.6.14",
93+
"pump": "^3.0.0",
10694
"stream-equal": "^1.1.1"
10795
},
10896
"engines": {

src/add-from-url.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const toIterable = require('./lib/stream-to-iterable')
66
module.exports = (config) => {
77
const add = require('./add')(config)
88

9-
return (url, options) => (async function * () {
9+
return async function * addFromURL (url, options) {
1010
options = options || {}
1111

1212
const { body } = await kyDefault.get(url)
@@ -17,5 +17,5 @@ module.exports = (config) => {
1717
}
1818

1919
yield * add(input, options)
20-
})()
20+
}
2121
}

src/add/index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const { toFormData } = require('./form-data')
77
const toCamel = require('../lib/object-to-camel')
88

99
module.exports = configure(({ ky }) => {
10-
return (input, options) => (async function * () {
10+
return async function * add (input, options) {
1111
options = options || {}
1212

1313
const searchParams = new URLSearchParams(options.searchParams)
@@ -47,7 +47,7 @@ module.exports = configure(({ ky }) => {
4747
yield toCoreInterface(file)
4848
}
4949
}
50-
})()
50+
}
5151
})
5252

5353
function toCoreInterface ({ name, hash, size }) {

src/bitswap/stat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = configure(({ ky }) => {
77
return async (options) => {
88
options = options || {}
99

10-
const res = await ky.get('bitswap/stat', {
10+
const res = await ky.post('bitswap/stat', {
1111
timeout: options.timeout,
1212
signal: options.signal,
1313
headers: options.headers,

src/bitswap/unwant.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = configure(({ ky }) => {
1515
searchParams.set('arg', new CID(cid).toString())
1616
}
1717

18-
const res = await ky.get('bitswap/unwant', {
18+
const res = await ky.post('bitswap/unwant', {
1919
timeout: options.timeout,
2020
signal: options.signal,
2121
headers: options.headers,

src/bitswap/wantlist.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ module.exports = configure(({ ky }) => {
1717
}
1818
}
1919

20-
const res = await ky.get('bitswap/wantlist', {
20+
const res = await ky.post('bitswap/wantlist', {
2121
timeout: options.timeout,
2222
signal: options.signal,
2323
headers: options.headers,

src/block/get.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ module.exports = configure(({ ky }) => {
1313
const searchParams = new URLSearchParams(options.searchParams)
1414
searchParams.set('arg', `${cid}`)
1515

16-
const data = await ky.get('block/get', {
16+
const data = await ky.post('block/get', {
1717
timeout: options.timeout,
1818
signal: options.signal,
1919
headers: options.headers,

src/block/rm-async-iterator.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ const toIterable = require('../lib/stream-to-iterable')
77
const toCamel = require('../lib/object-to-camel')
88

99
module.exports = configure(({ ky }) => {
10-
return async function * removeBlock (cid, options) {
10+
return async function * rm (cid, options) {
1111
options = options || {}
1212

1313
if (!Array.isArray(cid)) {

src/block/stat.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ module.exports = configure(({ ky }) => {
1616
const searchParams = new URLSearchParams(options.searchParams)
1717
searchParams.set('arg', `${cid}`)
1818

19-
const res = await ky.get('block/stat', {
19+
const res = await ky.post('block/stat', {
2020
timeout: options.timeout,
2121
signal: options.signal,
2222
headers: options.headers,

src/bootstrap/list.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ module.exports = configure(({ ky }) => {
66
return async (options) => {
77
options = options || {}
88

9-
const res = await ky.get('bootstrap/list', {
9+
const res = await ky.post('bootstrap/list', {
1010
timeout: options.timeout,
1111
signal: options.signal,
1212
headers: options.headers,

src/cat.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const configure = require('./lib/configure')
66
const toIterable = require('./lib/stream-to-iterable')
77

88
module.exports = configure(({ ky }) => {
9-
return (path, options) => (async function * () {
9+
return async function * cat (path, options) {
1010
options = options || {}
1111

1212
const searchParams = new URLSearchParams(options.searchParams)
@@ -20,7 +20,7 @@ module.exports = configure(({ ky }) => {
2020
if (options.offset) searchParams.set('offset', options.offset)
2121
if (options.length) searchParams.set('length', options.length)
2222

23-
const res = await ky.get('cat', {
23+
const res = await ky.post('cat', {
2424
timeout: options.timeout,
2525
signal: options.signal,
2626
headers: options.headers,
@@ -30,5 +30,5 @@ module.exports = configure(({ ky }) => {
3030
for await (const chunk of toIterable(res.body)) {
3131
yield Buffer.from(chunk)
3232
}
33-
})()
33+
}
3434
})

src/commands.js

+17-12
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
'use strict'
22

3-
const promisify = require('promisify-es6')
4-
const moduleConfig = require('./utils/module-config')
5-
6-
module.exports = (arg) => {
7-
const send = moduleConfig(arg)
8-
9-
return promisify((callback) => {
10-
send({
11-
path: 'commands'
12-
}, callback)
13-
})
14-
}
3+
const configure = require('./lib/configure')
4+
5+
module.exports = configure(({ ky }) => {
6+
return options => {
7+
options = options || {}
8+
9+
const searchParams = new URLSearchParams(options.searchParams)
10+
if (options.flags != null) searchParams.set('flags', options.flags)
11+
12+
return ky.post('commands', {
13+
timeout: options.timeout,
14+
signal: options.signal,
15+
headers: options.headers,
16+
searchParams
17+
}).json()
18+
}
19+
})

src/config/get.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ module.exports = configure(({ ky }) => {
1515
if (key) searchParams.set('arg', key)
1616

1717
const url = key ? 'config' : 'config/show'
18-
const data = await ky.get(url, {
18+
const data = await ky.post(url, {
1919
timeout: options.timeout,
2020
signal: options.signal,
2121
headers: options.headers,

src/config/profiles/list.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ module.exports = configure(({ ky }) => {
77
return async (options) => {
88
options = options || {}
99

10-
const res = await ky.get('config/profile/list', {
10+
const res = await ky.post('config/profile/list', {
1111
timeout: options.timeout,
1212
signal: options.signal,
1313
headers: options.headers,

src/dag/resolve.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ module.exports = configure(({ ky }) => {
1919
const searchParams = new URLSearchParams(options.searchParams)
2020
searchParams.set('arg', cidPath)
2121

22-
const res = await ky.get('dag/resolve', {
22+
const res = await ky.post('dag/resolve', {
2323
timeout: options.timeout,
2424
signal: options.signal,
2525
headers: options.headers,

src/dht/find-peer.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ const configure = require('../lib/configure')
88
const toIterable = require('../lib/stream-to-iterable')
99

1010
module.exports = configure(({ ky }) => {
11-
return (peerId, options) => (async function * () {
11+
return async function * findPeer (peerId, options) {
1212
options = options || {}
1313

1414
const searchParams = new URLSearchParams(options.searchParams)
1515
searchParams.set('arg', `${peerId}`)
1616
if (options.verbose != null) searchParams.set('verbose', options.verbose)
1717

18-
const res = await ky.get('dht/findpeer', {
18+
const res = await ky.post('dht/findpeer', {
1919
timeout: options.timeout,
2020
signal: options.signal,
2121
headers: options.headers,
@@ -33,5 +33,5 @@ module.exports = configure(({ ky }) => {
3333
}
3434
}
3535
}
36-
})()
36+
}
3737
})

src/dht/find-provs.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -8,15 +8,15 @@ const configure = require('../lib/configure')
88
const toIterable = require('../lib/stream-to-iterable')
99

1010
module.exports = configure(({ ky }) => {
11-
return (cid, options) => (async function * () {
11+
return async function * findProvs (cid, options) {
1212
options = options || {}
1313

1414
const searchParams = new URLSearchParams(options.searchParams)
1515
searchParams.set('arg', `${cid}`)
1616
if (options.numProviders) searchParams.set('num-providers', options.numProviders)
1717
if (options.verbose != null) searchParams.set('verbose', options.verbose)
1818

19-
const res = await ky.get('dht/findprovs', {
19+
const res = await ky.post('dht/findprovs', {
2020
timeout: options.timeout,
2121
signal: options.signal,
2222
headers: options.headers,
@@ -34,5 +34,5 @@ module.exports = configure(({ ky }) => {
3434
}
3535
}
3636
}
37-
})()
37+
}
3838
})

src/dht/get.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ const configure = require('../lib/configure')
55
const toIterable = require('../lib/stream-to-iterable')
66

77
module.exports = configure(({ ky }) => {
8-
return (key, options) => (async function * () {
8+
return async function * get (key, options) {
99
options = options || {}
1010

1111
const searchParams = new URLSearchParams(options.searchParams)
1212
searchParams.set('arg', `${key}`)
1313
if (options.verbose != null) searchParams.set('verbose', options.verbose)
1414

15-
const res = await ky.get('dht/get', {
15+
const res = await ky.post('dht/get', {
1616
timeout: options.timeout,
1717
signal: options.signal,
1818
headers: options.headers,
@@ -26,5 +26,5 @@ module.exports = configure(({ ky }) => {
2626
yield message.Extra
2727
}
2828
}
29-
})()
29+
}
3030
})

src/dht/provide.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ const toIterable = require('../lib/stream-to-iterable')
99
const toCamel = require('../lib/object-to-camel')
1010

1111
module.exports = configure(({ ky }) => {
12-
return (cids, options) => (async function * () {
12+
return async function * provide (cids, options) {
1313
cids = Array.isArray(cids) ? cids : [cids]
1414
options = options || {}
1515

@@ -18,7 +18,7 @@ module.exports = configure(({ ky }) => {
1818
if (options.recursive != null) searchParams.set('recursive', options.recursive)
1919
if (options.verbose != null) searchParams.set('verbose', options.verbose)
2020

21-
const res = await ky.get('dht/provide', {
21+
const res = await ky.post('dht/provide', {
2222
timeout: options.timeout,
2323
signal: options.signal,
2424
headers: options.headers,
@@ -36,5 +36,5 @@ module.exports = configure(({ ky }) => {
3636
}
3737
yield message
3838
}
39-
})()
39+
}
4040
})

src/dht/put.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ const encodeBufferURIComponent = require('../lib/encode-buffer-uri-component')
1010
const toCamel = require('../lib/object-to-camel')
1111

1212
module.exports = configure(({ ky }) => {
13-
return (key, value, options) => (async function * () {
13+
return async function * put (key, value, options) {
1414
options = options || {}
1515

1616
const searchParams = new URLSearchParams(options.searchParams)
@@ -20,7 +20,7 @@ module.exports = configure(({ ky }) => {
2020
value = Buffer.isBuffer(value) ? encodeBufferURIComponent(value) : encodeURIComponent(value)
2121

2222
const url = `dht/put?arg=${key}&arg=${value}&${searchParams}`
23-
const res = await ky.get(url, {
23+
const res = await ky.post(url, {
2424
timeout: options.timeout,
2525
signal: options.signal,
2626
headers: options.headers
@@ -37,5 +37,5 @@ module.exports = configure(({ ky }) => {
3737
}
3838
yield message
3939
}
40-
})()
40+
}
4141
})

0 commit comments

Comments
 (0)