-
Notifications
You must be signed in to change notification settings - Fork 20
feat+fix: implement .tree and fix how the resolver was working #29
Conversation
also make sure to check ipld/interface-ipld-format#5 |
sgtm |
} | ||
// 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 |
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.
is this a todo or a question? :)
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.
TODO: Ask the question:....
:D
values[i] = { | ||
hash: link.multihash, | ||
name: link.name, | ||
size: link.size |
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.
what is the size needed for?
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.
It is the size of this branch of the graph so far. It is needed to avoid traversing graphs over and over. go-ipfs has it since forever.
src/resolver.js
Outdated
@@ -1,10 +1,9 @@ | |||
'use strict' | |||
|
|||
const util = require('./util') | |||
const bs58 = require('bs58') | |||
// const bs58 = require('bs58') |
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.
please delete if you are not using it
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.
👍
src/resolver.js
Outdated
split.shift() | ||
split.shift() | ||
|
||
remainderPath = split.join('/') |
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.
these 4 lines could be simply
remainderPath = split.slice(3).join('/')
if (node.data && node.data.length > 0) { | ||
paths.push({ path: 'data', value: node.data }) | ||
} | ||
paths.push('Data') |
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 above can be simplified to
const links = node.links.map((l, i) => ([
`Links/${i}/Name`,
`Links/${i}/Tsize`,
`Links/${i}/Hash`
])
links.push('Data')
const paths = Array.prototype.concat.apply(['Links'], links)
src/resolver.js
Outdated
|
||
callback(null, paths) | ||
}) | ||
} | ||
|
||
/* | ||
* isLink: returns the Link if a given path in a block is a LInk, false otherwise |
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.
typo LInk
src/resolver.js
Outdated
} | ||
|
||
if (typeof result.value === 'object' && result.value['/']) { | ||
// result.value['/'] = bs58.encode(result.value['/']) |
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.
please remove if not used
In the process of implementing .tree, I've realized how we fell into the trap of 'transforming' the original data for convenience, for example, it was not possible to access the fields 'Name' or 'Tsize' of the protobuf, because we were handling the links as a direct jump to other objects.
This PR: