diff --git a/README.md b/README.md index 8779a18..acea380 100644 --- a/README.md +++ b/README.md @@ -177,6 +177,7 @@ It may contain any of the following: - `value` - the value that resulted from the get - `remainderPath` - If it didn't manage to successfully resolve the whole path through or if simply the `localResolve` option was passed. +- `cid` - Where the graph traversal finished - if `remainderPath` has a value, this will be where it has its root ### `.getMany(cids, callback)` diff --git a/src/index.js b/src/index.js index a6bf28e..f3c539c 100644 --- a/src/index.js +++ b/src/index.js @@ -94,7 +94,8 @@ class IPLDResolver { } callback(null, { value: node, - remainderPath: '' + remainderPath: '', + cid }) }) } @@ -113,6 +114,7 @@ class IPLDResolver { if (err) { return cb(err) } + format.resolver.resolve(block.data, path, (err, result) => { if (err) { return cb(err) @@ -129,6 +131,8 @@ class IPLDResolver { const isTerminal = value && !IPLDResolver._maybeCID(value) if ((endReached && isTerminal) || options.localResolve) { + cid = IPLDResolver._maybeCID(value) || cid + return true } else { value = IPLDResolver._maybeCID(value) @@ -145,7 +149,8 @@ class IPLDResolver { } return callback(null, { value: value, - remainderPath: path + remainderPath: path, + cid }) } ) diff --git a/test/ipld-dag-cbor.js b/test/ipld-dag-cbor.js index 2df0888..83e8ffa 100644 --- a/test/ipld-dag-cbor.js +++ b/test/ipld-dag-cbor.js @@ -245,6 +245,7 @@ module.exports = (repo) => { expect(err).to.not.exist() expect(result.value).to.eql('I am 1') expect(result.remainderPath).to.eql('') + expect(result.cid).to.deep.eql(cid1) done() }) diff --git a/test/ipld-dag-pb.js b/test/ipld-dag-pb.js index 749bf73..0bbff8c 100644 --- a/test/ipld-dag-pb.js +++ b/test/ipld-dag-pb.js @@ -249,6 +249,15 @@ module.exports = (repo) => { expect(result.value).to.eql({ '/': 'QmS149H7EbyMuZ2wtEF1sAd7gPwjj4rKAorweAjKMkxr8D' }) + expect(result.cid).to.deep.equal(cid2) + done() + }) + }) + + it('resolver.get value within nested scope (1 level) returns cid of node traversed to', (done) => { + resolver.get(cid2, 'Links/0/Hash/Data', (err, result) => { + expect(err).to.not.exist() + expect(result.cid).to.deep.equal(cid1) done() }) })