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

refactor: async await roundup #1173

Merged
merged 37 commits into from
Nov 22, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
f281b20
refactor: convert key API to async/await
Nov 19, 2019
acf2233
refactor: convert log API to async/await
Nov 19, 2019
0ad3897
fix: tests
Nov 19, 2019
e0a4ffd
fix: tests
Nov 19, 2019
cdf9390
refactor: convert name API to async/await
Nov 19, 2019
2895384
fix: tests
Nov 19, 2019
96b86f5
refactor: convert misc root level APIs to async/await
Nov 19, 2019
8638f9c
Merge branch 'master' into refactor/key-async-await
Nov 19, 2019
aa33b9a
Merge branch 'master' into refactor/log-async-await
Nov 19, 2019
2c110a5
Merge branch 'master' into refactor/name-async-await
Nov 19, 2019
e673f91
Merge branch 'master' into refactor/key-async-await
Nov 20, 2019
373d1e0
Merge branch 'master' into refactor/log-async-await
Nov 20, 2019
f4476cc
Merge branch 'master' into refactor/name-async-await
Nov 20, 2019
29cce3a
refactor: convert repo API to async await
Nov 20, 2019
a891032
refactor: convert stats API to async/await
Nov 21, 2019
a88767f
refactor: convert swarm API to async/await
Nov 21, 2019
1363199
fix: tests
Nov 21, 2019
c3cd680
refactor: convert mount API to async/await
Nov 21, 2019
e011c8e
fix: load mount
Nov 21, 2019
4186327
fix: post all the things
Nov 21, 2019
2281599
refactor: convert version API to async/await
Nov 21, 2019
d8da835
refactor: convert ping API to async/await
Nov 21, 2019
aa83f91
refactor: convert update API to async/await
Nov 21, 2019
f0d2aca
Merge branch 'master' into refactor/misc-async-await
Nov 21, 2019
09afe67
fix: remove tests for go-ipfs 0.4.4 peer response
Nov 21, 2019
3840f40
fix: ping sub modules test
Nov 21, 2019
1980530
Merge branch 'refactor/log-async-await' into refactor/async-await-rou…
Nov 21, 2019
81e72b3
Merge branch 'refactor/name-async-await' into refactor/async-await-ro…
Nov 21, 2019
12ff0d8
Merge branch 'refactor/misc-async-await' into refactor/async-await-ro…
Nov 21, 2019
6ecf79b
Merge branch 'refactor/repo-async-await' into refactor/async-await-ro…
Nov 21, 2019
d2beb18
Merge branch 'refactor/swarm-async-await' into refactor/async-await-r…
Nov 21, 2019
78b430a
refactor: move loadCommands into index and remove unused code
Nov 21, 2019
d7adafc
fix: browser and Node.js configuration
Nov 21, 2019
ec0e66c
fix: dev dependencies
Nov 21, 2019
b9d6d1b
fix: post all the things so not more breaking changes
Nov 21, 2019
31881e5
fix: inconsistent error message in browsers
Nov 21, 2019
fab4c67
refactor: return generator func not func that returns generator
Nov 22, 2019
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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