Skip to content
This repository has been archived by the owner on Feb 12, 2024. It is now read-only.

Commit

Permalink
fix: re-add configure
Browse files Browse the repository at this point in the history
  • Loading branch information
hugomrdias committed Mar 11, 2020
1 parent 6a3db3f commit 1c619bb
Show file tree
Hide file tree
Showing 114 changed files with 438 additions and 810 deletions.
2 changes: 1 addition & 1 deletion packages/ipfs-http-client/examples/files-api/files-api.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/* eslint-disable no-console */
'use strict'

const { Buffer } = require('buffer')
// Run `ipfs daemon` in your terminal to start the IPFS daemon
// Look for `API server listening on /ip4/127.0.0.1/tcp/5001`
const ipfs = require('../../src')('/ip4/127.0.0.1/tcp/5001')
Expand Down
1 change: 1 addition & 0 deletions packages/ipfs-http-client/examples/name-api/index.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
/* eslint-disable no-console */
'use strict'
const { Buffer } = require('buffer')
const ipfsHttp = require('ipfs-http-client')
const ipfs = ipfsHttp('/ip4/127.0.0.1/tcp/5001')

Expand Down
4 changes: 0 additions & 4 deletions packages/ipfs-http-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,6 @@
"iso-url": "^0.4.6",
"it-tar": "^1.2.1",
"it-to-stream": "^0.1.1",
"iterable-ndjson": "^1.1.0",
"ky": "^0.15.0",
"ky-universal": "^0.3.0",
"merge-options": "^2.0.0",
"multiaddr": "^7.2.1",
"multiaddr-to-uri": "^5.1.0",
Expand All @@ -69,7 +66,6 @@
},
"devDependencies": {
"aegir": "^21.3.0",
"async": "^3.1.0",
"browser-process-platform": "^0.1.1",
"cross-env": "^7.0.0",
"go-ipfs-dep": "0.4.23-3",
Expand Down
18 changes: 7 additions & 11 deletions packages/ipfs-http-client/src/add/index.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,14 @@
'use strict'

const ndjson = require('iterable-ndjson')
const CID = require('cids')
const toIterable = require('stream-to-it/source')
const merge = require('merge-options')
const { toFormData } = require('./form-data')
const toCamel = require('../lib/object-to-camel')
const merge = require('merge-options')
const configure = require('../lib/configure')

/** @typedef { import("./../lib/api") } API */

module.exports = (/** @type {API} */ api) => {
module.exports = configure((api) => {
return async function * add (input, options = {}) {
// extract functions here
const progressFn = options.progress
// default or mutate/force options here
options = merge(
options,
{
Expand All @@ -23,14 +18,15 @@ module.exports = (/** @type {API} */ api) => {
}
)

const res = await api.post('add', {
const res = await api.ndjson('add', {
method: 'POST',
searchParams: options,
body: await toFormData(input),
timeout: options.timeout,
signal: options.signal
})

for await (let file of ndjson(toIterable(res.body))) {
for await (let file of res) {
file = toCamel(file)

if (progressFn && file.bytes) {
Expand All @@ -40,7 +36,7 @@ module.exports = (/** @type {API} */ api) => {
}
}
}
}
})

function toCoreInterface ({ name, hash, size, mode, mtime, mtimeNsecs }) {
const output = {
Expand Down
5 changes: 3 additions & 2 deletions packages/ipfs-http-client/src/bitswap/stat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,9 @@

const { BigNumber } = require('bignumber.js')
const CID = require('cids')
const configure = require('../lib/configure')

module.exports = api => {
module.exports = configure(api => {
return async (options = {}) => {
const res = await api.post('bitswap/stat', {
searchParams: options,
Expand All @@ -13,7 +14,7 @@ module.exports = api => {

return toCoreInterface(await res.json())
}
}
})

function toCoreInterface (res) {
return {
Expand Down
5 changes: 3 additions & 2 deletions packages/ipfs-http-client/src/bitswap/unwant.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict'

const CID = require('cids')
const configure = require('../lib/configure')

module.exports = api => {
module.exports = configure(api => {
return async (cid, options = {}) => {
options.arg = typeof cid === 'string' ? cid : new CID(cid).toString()

Expand All @@ -14,4 +15,4 @@ module.exports = api => {

return res.json()
}
}
})
5 changes: 3 additions & 2 deletions packages/ipfs-http-client/src/bitswap/wantlist.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
'use strict'

const CID = require('cids')
const configure = require('../lib/configure')

module.exports = api => {
module.exports = configure(api => {
return async (peer, options = {}) => {
if (peer) {
options.peer = typeof peer === 'string' ? peer : new CID(peer).toString()
Expand All @@ -16,4 +17,4 @@ module.exports = api => {

return (res.Keys || []).map(k => new CID(k['/']))
}
}
})
7 changes: 3 additions & 4 deletions packages/ipfs-http-client/src/block/get.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,9 @@
const Block = require('ipfs-block')
const CID = require('cids')
const { Buffer } = require('buffer')
const configure = require('../lib/configure')

/** @typedef { import("./../lib/api") } API */

module.exports = (/** @type {API} */ api) => {
module.exports = configure(api => {
return async (cid, options = {}) => {
cid = new CID(cid)
options.arg = cid.toString()
Expand All @@ -19,4 +18,4 @@ module.exports = (/** @type {API} */ api) => {

return new Block(Buffer.from(await rsp.arrayBuffer()), cid)
}
}
})
7 changes: 3 additions & 4 deletions packages/ipfs-http-client/src/block/put.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@ const Block = require('ipfs-block')
const CID = require('cids')
const multihash = require('multihashes')
const toFormData = require('../lib/buffer-to-form-data')
const configure = require('../lib/configure')

/** @typedef { import("./../lib/api") } API */

module.exports = (/** @type {API} */ api) => {
module.exports = configure(api => {
async function put (data, options = {}) {
if (Block.isBlock(data)) {
const { name, length } = multihash.decode(data.cid.multihash)
Expand Down Expand Up @@ -57,4 +56,4 @@ module.exports = (/** @type {API} */ api) => {
}

return put
}
})
13 changes: 5 additions & 8 deletions packages/ipfs-http-client/src/block/rm.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
'use strict'

const CID = require('cids')
const ndjson = require('iterable-ndjson')
const merge = require('merge-options')
const toIterable = require('stream-to-it/source')
const configure = require('../lib/configure')

/** @typedef { import("./../lib/api") } API */

module.exports = (/** @type {API} */ api) => {
module.exports = configure(api => {
return async function * rm (cid, options = {}) {
if (!Array.isArray(cid)) {
cid = [cid]
Expand All @@ -26,17 +23,17 @@ module.exports = (/** @type {API} */ api) => {
searchParams.append('arg', new CID(cid).toString())
})

const res = await api.post('block/rm', {
const res = await api.ndjson('block/rm', {
timeout: options.timeout,
signal: options.signal,
searchParams: searchParams
})

for await (const removed of ndjson(toIterable(res.body))) {
for await (const removed of res) {
yield toCoreInterface(removed)
}
}
}
})

function toCoreInterface (removed) {
const out = {
Expand Down
7 changes: 3 additions & 4 deletions packages/ipfs-http-client/src/block/stat.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict'

const CID = require('cids')
const configure = require('../lib/configure')

/** @typedef { import("./../lib/api") } API */

module.exports = (/** @type {API} */ api) => {
module.exports = configure(api => {
return async (cid, options = {}) => {
options.arg = (new CID(cid)).toString()

Expand All @@ -17,4 +16,4 @@ module.exports = (/** @type {API} */ api) => {

return { cid: new CID(res.Key), size: res.Size }
}
}
})
7 changes: 3 additions & 4 deletions packages/ipfs-http-client/src/bootstrap/add.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict'

const Multiaddr = require('multiaddr')
const configure = require('../lib/configure')

/** @typedef { import("./../lib/api") } API */

module.exports = (/** @type {API} */ api) => {
module.exports = configure(api => {
return async (addr, options = {}) => {
if (addr && typeof addr === 'object' && !Multiaddr.isMultiaddr(addr)) {
options = addr
Expand All @@ -21,4 +20,4 @@ module.exports = (/** @type {API} */ api) => {

return res.json()
}
}
})
6 changes: 3 additions & 3 deletions packages/ipfs-http-client/src/bootstrap/list.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

/** @typedef { import("./../lib/api") } API */
const configure = require('../lib/configure')

module.exports = (/** @type {API} */ api) => {
module.exports = configure(api => {
return async (options = {}) => {
const res = await api.post('bootstrap/list', {
timeout: options.timeout,
Expand All @@ -12,4 +12,4 @@ module.exports = (/** @type {API} */ api) => {

return res.json()
}
}
})
7 changes: 3 additions & 4 deletions packages/ipfs-http-client/src/bootstrap/rm.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict'

const Multiaddr = require('multiaddr')
const configure = require('../lib/configure')

/** @typedef { import("./../lib/api") } API */

module.exports = (/** @type {API} */ api) => {
module.exports = configure(api => {
return async (addr, options = {}) => {
if (addr && typeof addr === 'object' && !Multiaddr.isMultiaddr(addr)) {
options = addr
Expand All @@ -21,4 +20,4 @@ module.exports = (/** @type {API} */ api) => {

return res.json()
}
}
})
13 changes: 6 additions & 7 deletions packages/ipfs-http-client/src/cat.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,26 @@

const CID = require('cids')
const { Buffer } = require('buffer')
const toIterable = require('stream-to-it/source')
const merge = require('merge-options')
const configure = require('./lib/configure')

/** @typedef { import("./lib/api") } API */

module.exports = (/** @type {API} */ api) => {
module.exports = configure(api => {
return async function * cat (path, options = {}) {
options = merge(
options,
{
arg: typeof path === 'string' ? path : new CID(path).toString()
}
)
const res = await api.post('cat', {
const res = await api.iterator('cat', {
method: 'POST',
timeout: options.timeout,
signal: options.signal,
searchParams: options
})

for await (const chunk of toIterable(res.body)) {
for await (const chunk of res) {
yield Buffer.from(chunk)
}
}
}
})
6 changes: 3 additions & 3 deletions packages/ipfs-http-client/src/commands.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

/** @typedef { import("./lib/api") } API */
const configure = require('./lib/configure')

module.exports = (/** @type {API} */ api) => {
module.exports = configure(api => {
return async (options = {}) => {
const res = await api.post('commands', {
timeout: options.timeout,
Expand All @@ -12,4 +12,4 @@ module.exports = (/** @type {API} */ api) => {

return res.json()
}
}
})
6 changes: 3 additions & 3 deletions packages/ipfs-http-client/src/config/get.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

/** @typedef { import("./../lib/api") } API */
const configure = require('../lib/configure')

module.exports = (/** @type {API} */ api) => {
module.exports = configure(api => {
return async (key, options = {}) => {
if (key && typeof key === 'object') {
options = key
Expand All @@ -19,4 +19,4 @@ module.exports = (/** @type {API} */ api) => {

return key ? data.Value : data
}
}
})
6 changes: 3 additions & 3 deletions packages/ipfs-http-client/src/config/profiles/apply.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

/** @typedef { import("./../../lib/api") } API */
const configure = require('../../lib/configure')

module.exports = (/** @type {API} */ api) => {
module.exports = configure(api => {
return async (profile, options = {}) => {
options.arg = profile
const response = await api.post('config/profile/apply', {
Expand All @@ -16,4 +16,4 @@ module.exports = (/** @type {API} */ api) => {
original: res.OldCfg, updated: res.NewCfg
}
}
}
})
7 changes: 3 additions & 4 deletions packages/ipfs-http-client/src/config/profiles/list.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
'use strict'

const toCamel = require('../../lib/object-to-camel')
const configure = require('../../lib/configure')

/** @typedef { import("./../../lib/api") } API */

module.exports = (/** @type {API} */ api) => {
module.exports = configure(api => {
return async (options = {}) => {
const res = await api.post('config/profile/list', {
timeout: options.timeout,
Expand All @@ -16,4 +15,4 @@ module.exports = (/** @type {API} */ api) => {

return data.map(profile => toCamel(profile))
}
}
})
Loading

0 comments on commit 1c619bb

Please sign in to comment.