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

Commit

Permalink
refactor: async await roundup (#1173)
Browse files Browse the repository at this point in the history
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' }`
  • Loading branch information
Alan Shaw authored Nov 22, 2019
1 parent fc73da7 commit 3e5967a
Show file tree
Hide file tree
Showing 109 changed files with 1,079 additions and 2,581 deletions.
231 changes: 126 additions & 105 deletions README.md

Large diffs are not rendered by default.

32 changes: 10 additions & 22 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,6 @@
},
"dependencies": {
"abort-controller": "^3.0.0",
"async": "^2.6.1",
"async-iterator-all": "^1.0.0",
"async-iterator-to-pull-stream": "^1.3.0",
"bignumber.js": "^9.0.0",
Expand All @@ -51,58 +50,47 @@
"buffer": "^5.4.2",
"callbackify": "^1.1.0",
"cids": "~0.7.1",
"concat-stream": "github:hugomrdias/concat-stream#feat/smaller",
"debug": "^4.1.0",
"detect-node": "^2.0.4",
"err-code": "^2.0.0",
"explain-error": "^1.0.4",
"flatmap": "0.0.3",
"form-data": "^3.0.0",
"glob": "^7.1.3",
"ipfs-block": "~0.8.1",
"ipfs-utils": "^0.4.0",
"ipld-dag-cbor": "~0.15.0",
"ipld-dag-pb": "^0.18.1",
"ipld-raw": "^4.0.0",
"is-ipfs": "~0.6.1",
"is-pull-stream": "0.0.0",
"is-stream": "^2.0.0",
"iso-stream-http": "~0.1.2",
"it-glob": "0.0.6",
"it-tar": "^1.1.0",
"it-tar": "^1.1.1",
"it-to-stream": "^0.1.1",
"iterable-ndjson": "^1.1.0",
"kind-of": "^6.0.2",
"ky": "^0.15.0",
"ky-universal": "^0.3.0",
"merge-options": "^2.0.0",
"multiaddr": "^6.0.6",
"multiaddr-to-uri": "^5.0.0",
"multibase": "~0.6.0",
"multicodec": "~0.5.1",
"multihashes": "~0.4.14",
"ndjson": "github:hugomrdias/ndjson#feat/readable-stream3",
"once": "^1.4.0",
"parse-duration": "^0.1.1",
"peer-id": "~0.12.3",
"peer-info": "~0.15.1",
"promise-nodeify": "^3.0.1",
"promisify-es6": "^1.0.3",
"pull-defer": "~0.2.3",
"pull-stream": "^3.6.9",
"pull-to-stream": "~0.1.1",
"pump": "^3.0.0",
"qs": "^6.5.2",
"readable-stream": "^3.1.1",
"stream-to-pull-stream": "^1.7.2"
"promise-nodeify": "^3.0.1"
},
"devDependencies": {
"aegir": "^20.4.1",
"async": "^3.1.0",
"browser-process-platform": "~0.1.1",
"cross-env": "^6.0.0",
"detect-node": "^2.0.4",
"go-ipfs-dep": "^0.4.22",
"interface-ipfs-core": "^0.120.0",
"interface-ipfs-core": "^0.121.0",
"ipfsd-ctl": "^0.47.1",
"ndjson": "^1.5.0",
"nock": "^11.4.0",
"promisify-es6": "^1.0.3",
"pull-stream": "^3.6.14",
"pump": "^3.0.0",
"stream-equal": "^1.1.1"
},
"engines": {
Expand Down
4 changes: 2 additions & 2 deletions src/add-from-url.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const toIterable = require('./lib/stream-to-iterable')
module.exports = (config) => {
const add = require('./add')(config)

return (url, options) => (async function * () {
return async function * addFromURL (url, options) {
options = options || {}

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

yield * add(input, options)
})()
}
}
4 changes: 2 additions & 2 deletions src/add/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const { toFormData } = require('./form-data')
const toCamel = require('../lib/object-to-camel')

module.exports = configure(({ ky }) => {
return (input, options) => (async function * () {
return async function * add (input, options) {
options = options || {}

const searchParams = new URLSearchParams(options.searchParams)
Expand Down Expand Up @@ -47,7 +47,7 @@ module.exports = configure(({ ky }) => {
yield toCoreInterface(file)
}
}
})()
}
})

function toCoreInterface ({ name, hash, size }) {
Expand Down
2 changes: 1 addition & 1 deletion src/bitswap/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = configure(({ ky }) => {
return async (options) => {
options = options || {}

const res = await ky.get('bitswap/stat', {
const res = await ky.post('bitswap/stat', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
Expand Down
2 changes: 1 addition & 1 deletion src/bitswap/unwant.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = configure(({ ky }) => {
searchParams.set('arg', new CID(cid).toString())
}

const res = await ky.get('bitswap/unwant', {
const res = await ky.post('bitswap/unwant', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
Expand Down
2 changes: 1 addition & 1 deletion src/bitswap/wantlist.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ module.exports = configure(({ ky }) => {
}
}

const res = await ky.get('bitswap/wantlist', {
const res = await ky.post('bitswap/wantlist', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
Expand Down
2 changes: 1 addition & 1 deletion src/block/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ module.exports = configure(({ ky }) => {
const searchParams = new URLSearchParams(options.searchParams)
searchParams.set('arg', `${cid}`)

const data = await ky.get('block/get', {
const data = await ky.post('block/get', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
Expand Down
2 changes: 1 addition & 1 deletion src/block/rm-async-iterator.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const toIterable = require('../lib/stream-to-iterable')
const toCamel = require('../lib/object-to-camel')

module.exports = configure(({ ky }) => {
return async function * removeBlock (cid, options) {
return async function * rm (cid, options) {
options = options || {}

if (!Array.isArray(cid)) {
Expand Down
2 changes: 1 addition & 1 deletion src/block/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ module.exports = configure(({ ky }) => {
const searchParams = new URLSearchParams(options.searchParams)
searchParams.set('arg', `${cid}`)

const res = await ky.get('block/stat', {
const res = await ky.post('block/stat', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
Expand Down
2 changes: 1 addition & 1 deletion src/bootstrap/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ module.exports = configure(({ ky }) => {
return async (options) => {
options = options || {}

const res = await ky.get('bootstrap/list', {
const res = await ky.post('bootstrap/list', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
Expand Down
6 changes: 3 additions & 3 deletions src/cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ const configure = require('./lib/configure')
const toIterable = require('./lib/stream-to-iterable')

module.exports = configure(({ ky }) => {
return (path, options) => (async function * () {
return async function * cat (path, options) {
options = options || {}

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

const res = await ky.get('cat', {
const res = await ky.post('cat', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
Expand All @@ -30,5 +30,5 @@ module.exports = configure(({ ky }) => {
for await (const chunk of toIterable(res.body)) {
yield Buffer.from(chunk)
}
})()
}
})
29 changes: 17 additions & 12 deletions src/commands.js
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
'use strict'

const promisify = require('promisify-es6')
const moduleConfig = require('./utils/module-config')

module.exports = (arg) => {
const send = moduleConfig(arg)

return promisify((callback) => {
send({
path: 'commands'
}, callback)
})
}
const configure = require('./lib/configure')

module.exports = configure(({ ky }) => {
return options => {
options = options || {}

const searchParams = new URLSearchParams(options.searchParams)
if (options.flags != null) searchParams.set('flags', options.flags)

return ky.post('commands', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
searchParams
}).json()
}
})
2 changes: 1 addition & 1 deletion src/config/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ module.exports = configure(({ ky }) => {
if (key) searchParams.set('arg', key)

const url = key ? 'config' : 'config/show'
const data = await ky.get(url, {
const data = await ky.post(url, {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
Expand Down
2 changes: 1 addition & 1 deletion src/config/profiles/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module.exports = configure(({ ky }) => {
return async (options) => {
options = options || {}

const res = await ky.get('config/profile/list', {
const res = await ky.post('config/profile/list', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
Expand Down
2 changes: 1 addition & 1 deletion src/dag/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ module.exports = configure(({ ky }) => {
const searchParams = new URLSearchParams(options.searchParams)
searchParams.set('arg', cidPath)

const res = await ky.get('dag/resolve', {
const res = await ky.post('dag/resolve', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
Expand Down
6 changes: 3 additions & 3 deletions src/dht/find-peer.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,14 +8,14 @@ const configure = require('../lib/configure')
const toIterable = require('../lib/stream-to-iterable')

module.exports = configure(({ ky }) => {
return (peerId, options) => (async function * () {
return async function * findPeer (peerId, options) {
options = options || {}

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

const res = await ky.get('dht/findpeer', {
const res = await ky.post('dht/findpeer', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
Expand All @@ -33,5 +33,5 @@ module.exports = configure(({ ky }) => {
}
}
}
})()
}
})
6 changes: 3 additions & 3 deletions src/dht/find-provs.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,15 +8,15 @@ const configure = require('../lib/configure')
const toIterable = require('../lib/stream-to-iterable')

module.exports = configure(({ ky }) => {
return (cid, options) => (async function * () {
return async function * findProvs (cid, options) {
options = options || {}

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

const res = await ky.get('dht/findprovs', {
const res = await ky.post('dht/findprovs', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
Expand All @@ -34,5 +34,5 @@ module.exports = configure(({ ky }) => {
}
}
}
})()
}
})
6 changes: 3 additions & 3 deletions src/dht/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,14 @@ const configure = require('../lib/configure')
const toIterable = require('../lib/stream-to-iterable')

module.exports = configure(({ ky }) => {
return (key, options) => (async function * () {
return async function * get (key, options) {
options = options || {}

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

const res = await ky.get('dht/get', {
const res = await ky.post('dht/get', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
Expand All @@ -26,5 +26,5 @@ module.exports = configure(({ ky }) => {
yield message.Extra
}
}
})()
}
})
6 changes: 3 additions & 3 deletions src/dht/provide.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ const toIterable = require('../lib/stream-to-iterable')
const toCamel = require('../lib/object-to-camel')

module.exports = configure(({ ky }) => {
return (cids, options) => (async function * () {
return async function * provide (cids, options) {
cids = Array.isArray(cids) ? cids : [cids]
options = options || {}

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

const res = await ky.get('dht/provide', {
const res = await ky.post('dht/provide', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
Expand All @@ -36,5 +36,5 @@ module.exports = configure(({ ky }) => {
}
yield message
}
})()
}
})
6 changes: 3 additions & 3 deletions src/dht/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ const encodeBufferURIComponent = require('../lib/encode-buffer-uri-component')
const toCamel = require('../lib/object-to-camel')

module.exports = configure(({ ky }) => {
return (key, value, options) => (async function * () {
return async function * put (key, value, options) {
options = options || {}

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

const url = `dht/put?arg=${key}&arg=${value}&${searchParams}`
const res = await ky.get(url, {
const res = await ky.post(url, {
timeout: options.timeout,
signal: options.signal,
headers: options.headers
Expand All @@ -37,5 +37,5 @@ module.exports = configure(({ ky }) => {
}
yield message
}
})()
}
})
Loading

0 comments on commit 3e5967a

Please sign in to comment.