Skip to content
This repository was archived by the owner on Aug 11, 2021. It is now read-only.

Commit

Permalink
feat: update isCID to isLink by spec
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Mar 13, 2017
1 parent ad47ffa commit df759c8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 15 deletions.
14 changes: 5 additions & 9 deletions src/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,11 +60,7 @@ exports.resolve = (block, path, callback) => {
value = { '/': value.name }
}

split.shift()
split.shift()
split.shift()

remainderPath = split.join('/')
remainderPath = split.slice(3).join('/')

callback(null, { value: value, remainderPath: remainderPath })
} else if (split[0] === 'Data') {
Expand Down Expand Up @@ -93,6 +89,7 @@ exports.tree = (block, options, callback) => {
}

const paths = []

paths.push('Links')

node.links.forEach((link, i) => {
Expand All @@ -108,9 +105,9 @@ exports.tree = (block, options, callback) => {
}

/*
* isCID: returns the CID if a given path in a block is a CID, false otherwise
* isLink: returns the Link if a given path in a block is a Link, false otherwise
*/
exports.isCID = (block, path, callback) => {
exports.isLink = (block, path, callback) => {
exports.resolve(block, path, (err, result) => {
if (err) {
return callback(err)
Expand All @@ -120,8 +117,7 @@ exports.isCID = (block, path, callback) => {
return callback(new Error('path out of scope'))
}

if (typeof result.value === 'object' &&
result.value['/']) {
if (typeof result.value === 'object' && result.value['/']) {
callback(null, result.value)
} else {
callback(null, false)
Expand Down
12 changes: 6 additions & 6 deletions test/resolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -220,18 +220,18 @@ describe('IPLD Format resolver (local)', () => {
})
})

it('resolver.isCID for valid CID', (done) => {
resolver.isCID(dataLinksNodeBlock, 'Links/0/Hash', (err, cid) => {
it('resolver.isLink for valid CID', (done) => {
resolver.isLink(dataLinksNodeBlock, 'Links/0/Hash', (err, link) => {
expect(err).to.not.exist
expect(CID.isCID(cid))
expect(CID.isCID(new CID(link['/']))).to.be.true
done()
})
})

it('resolver.isCID for non valid CID', (done) => {
resolver.isCID(dataLinksNodeBlock, 'Links/0/Name', (err, cid) => {
it('resolver.isLink for non valid CID', (done) => {
resolver.isLink(dataLinksNodeBlock, 'Links/0/Name', (err, link) => {
expect(err).to.not.exist
expect(cid).to.be.false
expect(link).to.be.false
done()
})
})
Expand Down

0 comments on commit df759c8

Please sign in to comment.