This repository has been archived by the owner on Aug 11, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 20
fix: add support for resolving links by name #78
Merged
Merged
Changes from 2 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
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 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 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 |
---|---|---|
|
@@ -46,15 +46,14 @@ exports.resolve = (binaryBlob, path, callback) => { | |
// for the resolver | ||
node.links.forEach((l, i) => { | ||
const link = l.toJSON() | ||
values[i] = { | ||
// TODO by enabling something to resolve through link name, we are | ||
// applying a transformation (a view) to the data, confirm if this | ||
// is exactly what we want | ||
values[i] = values[link.name] = { | ||
hash: link.multihash, | ||
name: link.name, | ||
size: link.size | ||
} | ||
// TODO by enabling something to resolve through link name, we are | ||
// applying a transformation (a view) to the data, confirm if this | ||
// is exactly what we want | ||
values[link.name] = link.multihash | ||
}) | ||
|
||
let value = values[split[1]] | ||
|
@@ -74,6 +73,31 @@ exports.resolve = (binaryBlob, path, callback) => { | |
} else if (split[0] === 'Data') { | ||
cb(null, { value: node.data, remainderPath: '' }) | ||
} else { | ||
const values = {} | ||
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. Can you please add a comment saying that this is the case of a named link? It took me a while to figure that out. |
||
|
||
// populate both index number and name to enable both cases | ||
// for the resolver | ||
node.links.forEach((l, i) => { | ||
const link = l.toJSON() | ||
// TODO by enabling something to resolve through link name, we are | ||
// applying a transformation (a view) to the data, confirm if this | ||
// is exactly what we want | ||
values[i] = values[link.name] = { | ||
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. The assignment to Please remote the comments/change them to make the saying the right thing. |
||
hash: link.multihash, | ||
name: link.name, | ||
size: link.size | ||
} | ||
}) | ||
|
||
const value = values[split[0]] | ||
|
||
if (value) { | ||
return cb(null, { | ||
value: { '/': value.hash }, | ||
remainderPath: split.slice(1).join('/') | ||
}) | ||
} | ||
|
||
cb(new Error('path not available')) | ||
} | ||
} | ||
|
This file contains 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 |
---|---|---|
|
@@ -146,6 +146,15 @@ describe('IPLD Format resolver (local)', () => { | |
}) | ||
}) | ||
|
||
it('links by name', (done) => { | ||
resolver.resolve(linksNodeBlob, 'named link', (err, result) => { | ||
expect(err).to.not.exist() | ||
expect(result.value['/']).to.eql(links[1].multihash) | ||
expect(result.remainderPath).to.eql('') | ||
done() | ||
}) | ||
}) | ||
|
||
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. Could you please add tests for:
|
||
it('yield remainderPath if impossible to resolve through (a)', (done) => { | ||
resolver.resolve(linksNodeBlob, 'Links/1/Hash/Data', (err, result) => { | ||
expect(err).to.not.exist() | ||
|
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.
I don't think
values[link.name]
is needed here. The case is handled below.Please also remove the "TODO".
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.
This was already in the code base although I don't think it was working correctly:
js-ipld-dag-pb/src/resolver.js
Lines 54 to 57 in fda23c4
It allows you to reference links by name via Links e.g.
/ipfs/QmHash/Links/myNamedLink
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.
Got it. So this is kind of the IPFS vs. IPLD like traversal.
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.
Yeah, I don't know if it's really necessary to be able to
/ipfs/QmHash/Links/myNamedLink
as well as/ipfs/QmHash/myNamedLink
but the former was already there and we're adding the latter.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.
/ipfs/QmHash/Links/myNamedLink
is what I call IPLD-like traversal. It will then be use if you use the/ipld
prefix.