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

Commit

Permalink
refactor: move files to root level (#1150)
Browse files Browse the repository at this point in the history
Moves remaining files that contain root level commands to the root of the src directory. This makes it easier for new contributors to find things.

It also renames the `files-mfs` dir to `files` to reflect the fact that it lives in the "files" namespace currently.

BREAKING CHANGE: files in `src/files-regular` have moved to `src`. The `src/files-mfs` directory has been renamed to `src/files`. If you were previously requiring files from these directories e.g. `require('ipfs-http-client/src/files-regular/add')` then please be aware that they have moved.

License: MIT
Signed-off-by: Alan Shaw <alan.shaw@protocol.ai>
  • Loading branch information
alanshaw committed Nov 12, 2019
1 parent 2275c2a commit 559a97d
Show file tree
Hide file tree
Showing 22 changed files with 179 additions and 181 deletions.
100 changes: 0 additions & 100 deletions src/files-regular/index.js

This file was deleted.

63 changes: 0 additions & 63 deletions src/files-regular/refs.js

This file was deleted.

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions src/files-regular/get.js → src/get.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
'use strict'

const configure = require('../lib/configure')
const tarStreamToObjects = require('../utils/tar-stream-to-objects')
const configure = require('./lib/configure')
const tarStreamToObjects = require('./utils/tar-stream-to-objects')
const IsIpfs = require('is-ipfs')
const cleanCID = require('../utils/clean-cid')
const cleanCID = require('./utils/clean-cid')

module.exports = configure(({ ky }) => {
return async function * get (path, options) {
Expand Down
4 changes: 2 additions & 2 deletions src/files-regular/ls.js → src/ls.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
'use strict'

const IsIpfs = require('is-ipfs')
const cleanCID = require('../utils/clean-cid')
const configure = require('../lib/configure')
const cleanCID = require('./utils/clean-cid')
const configure = require('./lib/configure')

module.exports = configure(({ ky }) => {
return async function * ls (path, options) {
Expand Down
69 changes: 69 additions & 0 deletions src/refs/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
'use strict'

const configure = require('../lib/configure')
const cleanCID = require('../utils/clean-cid')
const IsIpfs = require('is-ipfs')
const ndjson = require('iterable-ndjson')
const toIterable = require('../lib/stream-to-iterable')
const toCamel = require('../lib/object-to-camel')

module.exports = config => {
const refs = (configure(({ ky }) => {
return async function * refs (args, options) {
options = options || {}

const searchParams = new URLSearchParams()

if (options.format !== undefined) {
searchParams.set('format', options.format)
}

if (options.edges !== undefined) {
searchParams.set('edges', options.edges)
}

if (options.unique !== undefined) {
searchParams.set('unique', options.unique)
}

if (options.recursive !== undefined) {
searchParams.set('recursive', options.recursive)
}

if (options.maxDepth !== undefined) {
searchParams.set('max-depth', options.maxDepth)
}

if (!Array.isArray(args)) {
args = [args]
}

for (let arg of args) {
try {
arg = cleanCID(arg)
} catch (err) {
if (!IsIpfs.ipfsPath(arg)) {
throw err
}
}

searchParams.append('arg', arg.toString())
}

const res = await ky.get('refs', {
timeout: options.timeout,
signal: options.signal,
headers: options.headers,
searchParams
})

for await (const file of ndjson(toIterable(res.body))) {
yield toCamel(file)
}
}
}))(config)

refs.local = require('./local')(config)

return refs
}
File renamed without changes.
96 changes: 94 additions & 2 deletions src/utils/load-commands.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,107 @@
'use strict'

const nodeify = require('promise-nodeify')
const callbackify = require('callbackify')
const all = require('async-iterator-all')
const { concatify, collectify, pullify, streamify } = require('../lib/converters')
const toPullStream = require('async-iterator-to-pull-stream')
const pull = require('pull-stream/pull')
const map = require('pull-stream/throughs/map')

function requireCommands (send, config) {
const add = require('../add')(config)
const addFromFs = require('../add-from-fs')(config)
const addFromURL = require('../add-from-url')(config)
const cat = require('../cat')(config)
const get = require('../get')(config)
const ls = require('../ls')(config)
const refs = require('../refs')(config)

const cmds = {
...require('../files-regular')(config),
add: (input, options, callback) => {
if (typeof options === 'function') {
callback = options
options = {}
}
return nodeify(collectify(add)(input, options), callback)
},
addReadableStream: streamify.transform(add),
addPullStream: pullify.transform(add),
addFromFs: (path, options, callback) => {
if (typeof options === 'function') {
callback = options
options = {}
}
return nodeify(collectify(addFromFs)(path, options), callback)
},
addFromURL: (url, options, callback) => {
if (typeof options === 'function') {
callback = options
options = {}
}
return nodeify(collectify(addFromURL)(url, options), callback)
},
addFromStream: (input, options, callback) => {
if (typeof options === 'function') {
callback = options
options = {}
}
return nodeify(collectify(add)(input, options), callback)
},
_addAsyncIterator: add,
cat: callbackify.variadic((path, options) => concatify(cat)(path, options)),
catReadableStream: streamify.readable(cat),
catPullStream: pullify.source(cat),
_catAsyncIterator: cat,
get: callbackify.variadic(async (path, options) => {
const output = []

for await (const entry of get(path, options)) {
if (entry.content) {
entry.content = Buffer.concat(await all(entry.content))
}

output.push(entry)
}

return output
}),
getReadableStream: streamify.readable(get),
getPullStream: (path, options) => {
return pull(
toPullStream(get(path, options)),
map(file => {
if (file.content) {
file.content = toPullStream(file.content)
}

return file
})
)
},
_getAsyncIterator: get,
ls: callbackify.variadic((path, options) => collectify(ls)(path, options)),
lsReadableStream: streamify.readable(ls),
lsPullStream: pullify.source(ls),
_lsAsyncIterator: ls,
refs: callbackify.variadic((path, options) => collectify(refs)(path, options)),
refsReadableStream: streamify.readable(refs),
refsPullStream: pullify.source(refs),
_refsAsyncIterator: refs,
getEndpointConfig: require('../get-endpoint-config')(config),
bitswap: require('../bitswap')(config)
}

Object.assign(cmds.refs, {
local: callbackify.variadic(options => collectify(refs.local)(options)),
localReadableStream: streamify.readable(refs.local),
localPullStream: pullify.source(refs.local),
_localAsyncIterator: refs.local
})

const subCmds = {
// Files MFS (Mutable Filesystem)
files: require('../files-mfs'),
files: require('../files'),

// Block
block: require('../block'),
Expand Down
Loading

0 comments on commit 559a97d

Please sign in to comment.