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 108
More DAG API goodness #123
Merged
Merged
Changes from 5 commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
40c43aa
feat: update dag.put spec
daviddias eb20f31
feat: update dag.get spec
daviddias 3f4e81f
feat: tests for all permutations of dag.get
daviddias b6d33d1
feat: add dag.ls and dag.tree spec
daviddias e5565f1
feat: update tree spec
daviddias 4505bdd
docs: add examples to put and get
daviddias f89a302
fix: examples links
daviddias 2797e24
test: .tree tests everywhere
daviddias 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
"bl": "^1.2.0", | ||
"bs58": "^4.0.0", | ||
"chai": "^3.5.0", | ||
"cids": "^0.4.1", | ||
"concat-stream": "^1.6.0", | ||
"detect-node": "^2.0.3", | ||
"ipfs-block": "^0.5.4", | ||
|
@@ -54,4 +55,4 @@ | |
"haad <[email protected]>", | ||
"nginnever <[email protected]>" | ||
] | ||
} | ||
} |
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 |
---|---|---|
|
@@ -9,9 +9,10 @@ const pull = require('pull-stream') | |
const dagPB = require('ipld-dag-pb') | ||
const DAGNode = dagPB.DAGNode | ||
const dagCBOR = require('ipld-dag-cbor') | ||
const CID = require('cids') | ||
|
||
module.exports = (common) => { | ||
describe('.dag', () => { | ||
describe.only('.dag', () => { | ||
let ipfs | ||
|
||
before(function (done) { | ||
|
@@ -50,7 +51,7 @@ module.exports = (common) => { | |
} | ||
}) | ||
|
||
describe('.put', () => { | ||
describe.only('.put', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please remove There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 |
||
it('dag-pb with default hash func (sha2-256)', (done) => { | ||
ipfs.dag.put(pbNode, { | ||
format: 'dag-pb', | ||
|
@@ -100,6 +101,24 @@ module.exports = (common) => { | |
done() | ||
}) | ||
}) | ||
|
||
it('returns the cid', (done) => { | ||
ipfs.dag.put(cborNode, { | ||
format: 'dag-cbor', | ||
hashAlg: 'sha3-512' | ||
}, (err, cid) => { | ||
expect(err).to.not.exist | ||
expect(cid).to.exist | ||
expect(CID.isCID(cid)).to.be.true | ||
dagCBOR.util.cid(cborNode, (err, _cid) => { | ||
expect(err).to.not.exist | ||
expect(cid.buffer).to.eql(_cid.buffer) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it.skip('pass the cid instead of format and hashAlg', (done) => {}) | ||
}) | ||
|
||
describe('.get', () => { | ||
|
@@ -175,16 +194,13 @@ module.exports = (common) => { | |
ipfs.dag.put(pbNode, { | ||
format: 'dag-pb', | ||
hashAlg: 'sha2-256' | ||
}, (err) => { | ||
}, (err, cid) => { | ||
expect(err).to.not.exist | ||
dagPB.util.cid(pbNode, (err, cid) => { | ||
ipfs.dag.get(cid, (err, result) => { | ||
expect(err).to.not.exist | ||
ipfs.dag.get(cid, (err, result) => { | ||
expect(err).to.not.exist | ||
const node = result.value | ||
expect(pbNode.toJSON()).to.eql(node.toJSON()) | ||
done() | ||
}) | ||
const node = result.value | ||
expect(pbNode.toJSON()).to.eql(node.toJSON()) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
@@ -193,17 +209,14 @@ module.exports = (common) => { | |
ipfs.dag.put(cborNode, { | ||
format: 'dag-cbor', | ||
hashAlg: 'sha2-256' | ||
}, (err) => { | ||
}, (err, cid) => { | ||
expect(err).to.not.exist | ||
dagCBOR.util.cid(cborNode, (err, cid) => { | ||
ipfs.dag.get(cid, (err, result) => { | ||
expect(err).to.not.exist | ||
ipfs.dag.get(cid, (err, result) => { | ||
expect(err).to.not.exist | ||
|
||
const node = result.value | ||
expect(cborNode).to.eql(node) | ||
done() | ||
}) | ||
const node = result.value | ||
expect(cborNode).to.eql(node) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
@@ -267,13 +280,49 @@ module.exports = (common) => { | |
done() | ||
}) | ||
}) | ||
|
||
it('CID String', (done) => { | ||
const cidCborStr = cidCbor.toBaseEncodedString() | ||
|
||
ipfs.dag.get(cidCborStr, (err, result) => { | ||
expect(err).to.not.exist | ||
|
||
const node = result.value | ||
|
||
dagCBOR.util.cid(node, (err, cid) => { | ||
expect(err).to.not.exist | ||
expect(cid).to.eql(cidCbor) | ||
done() | ||
}) | ||
}) | ||
}) | ||
|
||
it('CID String + path', (done) => { | ||
const cidCborStr = cidCbor.toBaseEncodedString() | ||
|
||
ipfs.dag.get(cidCborStr + '/pb/data', (err, result) => { | ||
expect(err).to.not.exist | ||
expect(result.value).to.eql(new Buffer('I am inside a Protobuf')) | ||
done() | ||
}) | ||
}) | ||
}) | ||
}) | ||
|
||
describe('.tree', () => { | ||
it.skip('.tree with CID', (done) => {}) | ||
it.skip('.tree with CID and path', (done) => {}) | ||
it.skip('.tree with CID and path as String', (done) => {}) | ||
it.skip('.tree with CID recursive', (done) => {}) | ||
it.skip('.tree with CID and path recursive', (done) => {}) | ||
}) | ||
}) | ||
|
||
describe('promise API', () => { | ||
describe('.put', () => {}) | ||
describe('.get', () => {}) | ||
describe('.tree', () => {}) | ||
describe('.ls', () => {}) | ||
}) | ||
}) | ||
} |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dignifiedquire what is your take on this (options for streaming)? See #121
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not a big fan of this, if we want a streaming interface make it multiple methods, i.e.
.ls
callback, no streaming.lsStream
node stream.lsPull
pull streamor sth like that
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed comment about JS specific things, section is under JavaScript so makes sense.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@dignifiedquire understood. Right now it is PITA because we have places where 'xStream' is returning a pull-stream, other places where there is an option (really legacy) for
buffer: true
and a lot of internals that are pull-streams and the 'external' (ie js-ipfs) is Node.js Streams for the sake of not breaking API.I would be down to just sit, define a language for this different options (or through options object or through different methods) and then apply as a golden rule throughout all the modules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes, we should try unify this api, agreed
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I'll come up with a proposal then based on things we've discussed. I've some cool ideas, I believe :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
here you go #126