This repository was archived by the owner on Mar 10, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 296
Merged
refs endpoint #978
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
862964e
feat: refs
dirkmc 8617792
feat: add refsReadableStream()
dirkmc 0a91725
fix: add refsReadableStream to sub-modules spec
dirkmc 3220447
feat: stream refs endpoints
dirkmc 015d938
fix: change Ref -> ref
dirkmc aadfb38
chore: lint fixes
dirkmc c49143b
fix: support multiple refs
dirkmc f396f01
chore: add refs to README
dirkmc File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
'use strict' | ||
|
||
const pull = require('pull-stream') | ||
const toPull = require('stream-to-pull-stream') | ||
const deferred = require('pull-defer') | ||
const moduleConfig = require('../utils/module-config') | ||
|
||
module.exports = (send) => { | ||
send = moduleConfig(send) | ||
|
||
return (opts) => { | ||
opts = opts || {} | ||
|
||
const p = deferred.source() | ||
|
||
send({ path: 'refs/local', qs: opts }, (err, stream) => { | ||
if (err) { return p.resolve(pull.error(err)) } | ||
|
||
p.resolve(pull( | ||
toPull.source(stream), | ||
pull.map(r => ({ ref: r.Ref, err: r.Err })) | ||
)) | ||
}) | ||
|
||
return p | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
'use strict' | ||
|
||
const Stream = require('readable-stream') | ||
const pump = require('pump') | ||
const through = require('through2') | ||
|
||
module.exports = (send) => { | ||
return (opts) => { | ||
opts = opts || {} | ||
|
||
const pt = new Stream.PassThrough({ objectMode: true }) | ||
|
||
send({ path: 'refs/local', qs: opts }, (err, stream) => { | ||
if (err) { return pt.destroy(err) } | ||
|
||
pump(stream, through.obj(function (r, enc, cb) { | ||
cb(null, { ref: r.Ref, err: r.Err }) | ||
}), pt) | ||
}) | ||
|
||
return pt | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
'use strict' | ||
|
||
const promisify = require('promisify-es6') | ||
const streamToValueWithTransformer = require('../utils/stream-to-value-with-transformer') | ||
const moduleConfig = require('../utils/module-config') | ||
|
||
module.exports = (arg) => { | ||
const send = moduleConfig(arg) | ||
|
||
return promisify((opts, callback) => { | ||
if (typeof (opts) === 'function') { | ||
callback = opts | ||
opts = {} | ||
} | ||
|
||
const transform = (res, cb) => { | ||
cb(null, res.map(r => ({ ref: r.Ref, err: r.Err }))) | ||
} | ||
|
||
const request = { | ||
path: 'refs/local', | ||
qs: opts | ||
} | ||
send(request, (err, result) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
|
||
streamToValueWithTransformer(result, transform, callback) | ||
}) | ||
}) | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
'use strict' | ||
|
||
const pull = require('pull-stream') | ||
const toPull = require('stream-to-pull-stream') | ||
const deferred = require('pull-defer') | ||
const moduleConfig = require('../utils/module-config') | ||
const { checkArgs, normalizeOpts } = require('./refs') | ||
|
||
module.exports = (send) => { | ||
send = moduleConfig(send) | ||
|
||
return (args, opts) => { | ||
opts = normalizeOpts(opts) | ||
|
||
const p = deferred.source() | ||
|
||
try { | ||
args = checkArgs(args) | ||
} catch (err) { | ||
return p.end(err) | ||
} | ||
|
||
send({ path: 'refs', args, qs: opts }, (err, stream) => { | ||
if (err) { return p.resolve(pull.error(err)) } | ||
|
||
p.resolve(pull( | ||
toPull.source(stream), | ||
pull.map(r => ({ ref: r.Ref, err: r.Err })) | ||
)) | ||
}) | ||
|
||
return p | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
'use strict' | ||
|
||
const Stream = require('readable-stream') | ||
const pump = require('pump') | ||
const through = require('through2') | ||
const { checkArgs, normalizeOpts } = require('./refs') | ||
|
||
module.exports = (send) => { | ||
return (args, opts) => { | ||
opts = normalizeOpts(opts) | ||
|
||
const pt = new Stream.PassThrough({ objectMode: true }) | ||
|
||
try { | ||
args = checkArgs(args) | ||
} catch (err) { | ||
return pt.destroy(err) | ||
} | ||
|
||
send({ path: 'refs', args, qs: opts }, (err, stream) => { | ||
if (err) { return pt.destroy(err) } | ||
|
||
pump(stream, through.obj(function (r, enc, cb) { | ||
cb(null, { ref: r.Ref, err: r.Err }) | ||
}), pt) | ||
}) | ||
|
||
return pt | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
'use strict' | ||
|
||
const IsIpfs = require('is-ipfs') | ||
const promisify = require('promisify-es6') | ||
const streamToValueWithTransformer = require('../utils/stream-to-value-with-transformer') | ||
const moduleConfig = require('../utils/module-config') | ||
const cleanCID = require('../utils/clean-cid') | ||
|
||
module.exports = (arg) => { | ||
const send = moduleConfig(arg) | ||
|
||
const refs = promisify((args, opts, callback) => { | ||
if (typeof (opts) === 'function') { | ||
callback = opts | ||
opts = {} | ||
} | ||
opts = module.exports.normalizeOpts(opts) | ||
|
||
try { | ||
args = module.exports.checkArgs(args) | ||
} catch (err) { | ||
return callback(err) | ||
} | ||
|
||
const transform = (res, cb) => { | ||
cb(null, res.map(r => ({ ref: r.Ref, err: r.Err }))) | ||
} | ||
|
||
const request = { | ||
args, | ||
path: 'refs', | ||
qs: opts | ||
} | ||
send(request, (err, result) => { | ||
if (err) { | ||
return callback(err) | ||
} | ||
|
||
streamToValueWithTransformer(result, transform, callback) | ||
}) | ||
}) | ||
|
||
refs.local = require('./refs-local')(arg) | ||
refs.localReadableStream = require('./refs-local-readable-stream')(arg) | ||
refs.localPullStream = require('./refs-local-pull-stream')(arg) | ||
|
||
return refs | ||
} | ||
|
||
module.exports.checkArgs = (args) => { | ||
const isArray = Array.isArray(args) | ||
args = isArray ? args : [args] | ||
|
||
const res = [] | ||
for (let arg of args) { | ||
try { | ||
arg = cleanCID(arg) | ||
} catch (err) { | ||
if (!IsIpfs.ipfsPath(arg)) { | ||
throw err | ||
} | ||
} | ||
res.push(arg) | ||
} | ||
|
||
return isArray ? res : res[0] | ||
} | ||
|
||
module.exports.normalizeOpts = (opts) => { | ||
opts = opts || {} | ||
if (typeof opts.maxDepth === 'number') { | ||
opts['max-depth'] = opts.maxDepth | ||
} | ||
return opts | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.