-
Notifications
You must be signed in to change notification settings - Fork 20
fix: add support for resolving links by name #78
Conversation
Codecov Report
@@ Coverage Diff @@
## master #78 +/- ##
========================================
+ Coverage 90.6% 90.8% +0.2%
========================================
Files 13 13
Lines 266 272 +6
========================================
+ Hits 241 247 +6
Misses 25 25
Continue to review full report at Codecov.
|
@vmx can you check on this with @olizilla and @alanshaw. They are looking for this feature in for the WebUI. @victorbjelkholm can we make sure to disable codecov comments? |
@diasdavid Do you mean that I should finish this PR? |
License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io>
I hope you don't mind, I made some fixes and added a test - should be good to go now. |
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 did a review. If I should take this PR over (I'd prefer not to), please let me know an I'd fix those things myself.
src/resolver.js
Outdated
// 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 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
// 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 |
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.
src/resolver.js
Outdated
@@ -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 comment
The 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.
src/resolver.js
Outdated
// 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 comment
The reason will be displayed to describe this comment to others. Learn more.
The assignment to values[i]
is not needed here and I find it rather confusing.
Please remote the comments/change them to make the saying the right thing.
done() | ||
}) | ||
}) | ||
|
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.
Could you please add tests for:
- named link and a remainder path
- error case for non-existent named link
License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io>
License: MIT Signed-off-by: Alan Shaw <alan@tableflip.io>
Is good now @vmx? macOS tests are npm failure not test failure. |
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.
Thanks!
Please merge it (I normally let the author merge). Please squash them up into a single commit as it is one unit of change.
@alanshaw yes it's good to be merged. |
This is just a stab at fixing the resolve links by name on dag-pb nodes. This PR is not finished (at all) but it shows what is missing.
Short story: go-ipfs and js-ipfs historically have supported the ability to do
jsipfs dag get CID/a
where a is a named link in a dag-pb.So a dag-pb node like this.
Should support resolving the link through name so that both
jsipfs dag get CID/a
andjsipfs dag get CID/Links/0/Hash
are equivalent.