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

Commit

Permalink
feat: resolver.resolve within scope
Browse files Browse the repository at this point in the history
  • Loading branch information
daviddias committed Oct 26, 2016
1 parent 21ddefc commit 1158fa4
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 189 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
"cids": "^0.1.1",
"lodash.clonedeep": "^4.3.2",
"lodash.defaults": "^4.0.1",
"lodash.includes": "^4.1.3",
"lodash.includes": "^4.3.0",
"multiaddr": "^2.0.0",
"multihashes": "^0.2.2",
"multihashing": "^0.2.1",
Expand Down
24 changes: 24 additions & 0 deletions src/resolver.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,31 @@ exports.multicodec = 'dag-cbor'
* throw if not possible. `block` is an IPFS Block instance (contains data + key)
*/
exports.resolve = (block, path) => {
const node = util.deserialize(block.data)

// root

if (!path || path === '/') {
return { value: node, remainderPath: '' }
}

// within scope

const tree = exports.tree(block)
let result

tree.forEach((item) => {
if (item.path === path) {
result = { value: item.value, remainderPath: '' }
}
})

if (result) {
return result
}

// out of scope
// TODO
}

/*
Expand Down
187 changes: 0 additions & 187 deletions test/old-cbor.js

This file was deleted.

15 changes: 14 additions & 1 deletion test/resolver.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,20 @@ describe('IPLD format resolver (local)', () => {

describe('empty node', () => {
describe('resolver.resolve', () => {
it.skip('path', () => {
it('path within scope', () => {
const result = resolver.resolve(nodeBlock, 'name')
expect(result.value).to.equal('I am a node')
})

it('path within scope, but nested', () => {
const result = resolver.resolve(nodeBlock, 'nest/foo/bar')
expect(result.value).to.equal('baz')
})

it.skip('path out of scope', () => {
const result = resolver.resolve(nodeBlock, 'someLink/a/b/c')
expect(result.value).to.eql({ '/': 'LINK' })
expect(result.remainderPath).to.equal('a/b/c')
})
})

Expand Down

0 comments on commit 1158fa4

Please # to comment.