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

Commit 559a97d

Browse files
author
Alan Shaw
authored
refactor: move files to root level (#1150)
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 <[email protected]>
1 parent 2275c2a commit 559a97d

22 files changed

+179
-181
lines changed

Diff for: src/files-regular/index.js

-100
This file was deleted.

Diff for: src/files-regular/refs.js

-63
This file was deleted.

Diff for: src/files-mfs/cp.js renamed to src/files/cp.js

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: src/files-mfs/ls.js renamed to src/files/ls.js

File renamed without changes.
File renamed without changes.

Diff for: src/files-mfs/mv.js renamed to src/files/mv.js

File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: src/files-mfs/rm.js renamed to src/files/rm.js

File renamed without changes.
File renamed without changes.
File renamed without changes.

Diff for: src/files-regular/get.js renamed to src/get.js

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
'use strict'
22

3-
const configure = require('../lib/configure')
4-
const tarStreamToObjects = require('../utils/tar-stream-to-objects')
3+
const configure = require('./lib/configure')
4+
const tarStreamToObjects = require('./utils/tar-stream-to-objects')
55
const IsIpfs = require('is-ipfs')
6-
const cleanCID = require('../utils/clean-cid')
6+
const cleanCID = require('./utils/clean-cid')
77

88
module.exports = configure(({ ky }) => {
99
return async function * get (path, options) {

Diff for: src/files-regular/ls.js renamed to src/ls.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
'use strict'
22

33
const IsIpfs = require('is-ipfs')
4-
const cleanCID = require('../utils/clean-cid')
5-
const configure = require('../lib/configure')
4+
const cleanCID = require('./utils/clean-cid')
5+
const configure = require('./lib/configure')
66

77
module.exports = configure(({ ky }) => {
88
return async function * ls (path, options) {

Diff for: src/refs/index.js

+69
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
'use strict'
2+
3+
const configure = require('../lib/configure')
4+
const cleanCID = require('../utils/clean-cid')
5+
const IsIpfs = require('is-ipfs')
6+
const ndjson = require('iterable-ndjson')
7+
const toIterable = require('../lib/stream-to-iterable')
8+
const toCamel = require('../lib/object-to-camel')
9+
10+
module.exports = config => {
11+
const refs = (configure(({ ky }) => {
12+
return async function * refs (args, options) {
13+
options = options || {}
14+
15+
const searchParams = new URLSearchParams()
16+
17+
if (options.format !== undefined) {
18+
searchParams.set('format', options.format)
19+
}
20+
21+
if (options.edges !== undefined) {
22+
searchParams.set('edges', options.edges)
23+
}
24+
25+
if (options.unique !== undefined) {
26+
searchParams.set('unique', options.unique)
27+
}
28+
29+
if (options.recursive !== undefined) {
30+
searchParams.set('recursive', options.recursive)
31+
}
32+
33+
if (options.maxDepth !== undefined) {
34+
searchParams.set('max-depth', options.maxDepth)
35+
}
36+
37+
if (!Array.isArray(args)) {
38+
args = [args]
39+
}
40+
41+
for (let arg of args) {
42+
try {
43+
arg = cleanCID(arg)
44+
} catch (err) {
45+
if (!IsIpfs.ipfsPath(arg)) {
46+
throw err
47+
}
48+
}
49+
50+
searchParams.append('arg', arg.toString())
51+
}
52+
53+
const res = await ky.get('refs', {
54+
timeout: options.timeout,
55+
signal: options.signal,
56+
headers: options.headers,
57+
searchParams
58+
})
59+
60+
for await (const file of ndjson(toIterable(res.body))) {
61+
yield toCamel(file)
62+
}
63+
}
64+
}))(config)
65+
66+
refs.local = require('./local')(config)
67+
68+
return refs
69+
}
File renamed without changes.

Diff for: src/utils/load-commands.js

+94-2
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,107 @@
11
'use strict'
22

3+
const nodeify = require('promise-nodeify')
4+
const callbackify = require('callbackify')
5+
const all = require('async-iterator-all')
6+
const { concatify, collectify, pullify, streamify } = require('../lib/converters')
7+
const toPullStream = require('async-iterator-to-pull-stream')
8+
const pull = require('pull-stream/pull')
9+
const map = require('pull-stream/throughs/map')
10+
311
function requireCommands (send, config) {
12+
const add = require('../add')(config)
13+
const addFromFs = require('../add-from-fs')(config)
14+
const addFromURL = require('../add-from-url')(config)
15+
const cat = require('../cat')(config)
16+
const get = require('../get')(config)
17+
const ls = require('../ls')(config)
18+
const refs = require('../refs')(config)
19+
420
const cmds = {
5-
...require('../files-regular')(config),
21+
add: (input, options, callback) => {
22+
if (typeof options === 'function') {
23+
callback = options
24+
options = {}
25+
}
26+
return nodeify(collectify(add)(input, options), callback)
27+
},
28+
addReadableStream: streamify.transform(add),
29+
addPullStream: pullify.transform(add),
30+
addFromFs: (path, options, callback) => {
31+
if (typeof options === 'function') {
32+
callback = options
33+
options = {}
34+
}
35+
return nodeify(collectify(addFromFs)(path, options), callback)
36+
},
37+
addFromURL: (url, options, callback) => {
38+
if (typeof options === 'function') {
39+
callback = options
40+
options = {}
41+
}
42+
return nodeify(collectify(addFromURL)(url, options), callback)
43+
},
44+
addFromStream: (input, options, callback) => {
45+
if (typeof options === 'function') {
46+
callback = options
47+
options = {}
48+
}
49+
return nodeify(collectify(add)(input, options), callback)
50+
},
51+
_addAsyncIterator: add,
52+
cat: callbackify.variadic((path, options) => concatify(cat)(path, options)),
53+
catReadableStream: streamify.readable(cat),
54+
catPullStream: pullify.source(cat),
55+
_catAsyncIterator: cat,
56+
get: callbackify.variadic(async (path, options) => {
57+
const output = []
58+
59+
for await (const entry of get(path, options)) {
60+
if (entry.content) {
61+
entry.content = Buffer.concat(await all(entry.content))
62+
}
63+
64+
output.push(entry)
65+
}
66+
67+
return output
68+
}),
69+
getReadableStream: streamify.readable(get),
70+
getPullStream: (path, options) => {
71+
return pull(
72+
toPullStream(get(path, options)),
73+
map(file => {
74+
if (file.content) {
75+
file.content = toPullStream(file.content)
76+
}
77+
78+
return file
79+
})
80+
)
81+
},
82+
_getAsyncIterator: get,
83+
ls: callbackify.variadic((path, options) => collectify(ls)(path, options)),
84+
lsReadableStream: streamify.readable(ls),
85+
lsPullStream: pullify.source(ls),
86+
_lsAsyncIterator: ls,
87+
refs: callbackify.variadic((path, options) => collectify(refs)(path, options)),
88+
refsReadableStream: streamify.readable(refs),
89+
refsPullStream: pullify.source(refs),
90+
_refsAsyncIterator: refs,
691
getEndpointConfig: require('../get-endpoint-config')(config),
792
bitswap: require('../bitswap')(config)
893
}
994

95+
Object.assign(cmds.refs, {
96+
local: callbackify.variadic(options => collectify(refs.local)(options)),
97+
localReadableStream: streamify.readable(refs.local),
98+
localPullStream: pullify.source(refs.local),
99+
_localAsyncIterator: refs.local
100+
})
101+
10102
const subCmds = {
11103
// Files MFS (Mutable Filesystem)
12-
files: require('../files-mfs'),
104+
files: require('../files'),
13105

14106
// Block
15107
block: require('../block'),

0 commit comments

Comments
 (0)