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

Commit

Permalink
feat: upgrade to latest spec
Browse files Browse the repository at this point in the history
  • Loading branch information
dignifiedquire committed May 22, 2016
1 parent f197208 commit c2ec9fe
Show file tree
Hide file tree
Showing 6 changed files with 34 additions and 27 deletions.
23 changes: 12 additions & 11 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -32,25 +32,26 @@
"homepage": "https://github.com/ipfs/js-ipfs-ipld#readme",
"license": "MIT",
"devDependencies": {
"aegir": "^2.1.1",
"async": "^2.0.0-rc.3",
"aegir": "^3.0.4",
"async": "^2.0.0-rc.5",
"buffer-loader": "0.0.1",
"chai": "^3.5.0",
"fs-blob-store": "^5.2.1",
"idb-plus-blob-store": "^1.0.0",
"ipfs-repo": "^0.6.1",
"lodash": "^4.8.2",
"idb-plus-blob-store": "^1.1.2",
"ipfs-block-service": "^0.4.0",
"ipfs-repo": "^0.8.0",
"lodash": "^4.12.0",
"ncp": "^2.0.0",
"pre-commit": "^1.1.2",
"pre-commit": "^1.1.3",
"rimraf": "^2.5.2"
},
"dependencies": {
"babel-runtime": "^6.6.1",
"babel-runtime": "^6.9.0",
"bs58": "^3.0.0",
"ipfs-blocks": "^0.1.2",
"ipld": "^0.5.2",
"ipfs-block": "^0.3.0",
"ipld": "^0.6.0",
"is-ipfs": "^0.2.0",
"lodash.flatten": "^4.1.1",
"lodash.includes": "^4.1.2"
"lodash.flatten": "^4.2.0",
"lodash.includes": "^4.1.3"
}
}
2 changes: 1 addition & 1 deletion src/ipld-service.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
'use strict'

const isIPFS = require('is-ipfs')
const Block = require('ipfs-blocks').Block
const Block = require('ipfs-block')
const ipld = require('ipld')
const base58 = require('bs58')

Expand Down
9 changes: 6 additions & 3 deletions src/resolve.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,12 @@

const isIPFS = require('is-ipfs')
const includes = require('lodash.includes')
const ipld = require('ipld')

const IPLDService = require('./ipld-service')

const LINK_SYMBOL = ipld.LINK_SYMBOL

module.exports = function resolve (is, path, cb) {
if (!(is instanceof IPLDService)) {
return cb(new Error('Missing IPLDService'))
Expand All @@ -13,14 +16,14 @@ module.exports = function resolve (is, path, cb) {
function access (parts, obj, cb) {
const isRoot = obj === null && (isIPFS.multihash(parts[0]) || isIPFS.ipfsPath('/' + parts.join('/')))
const next = parts.shift()
const isLink = obj && obj['@link']
const isLink = obj && Object.keys(obj).length === 1 && obj[LINK_SYMBOL]
const fetchLink = obj && (next ? !includes(Object.keys(obj), next) : true)

if (!obj && !isRoot) {
cb(new Error('No root object provided'))
} else if (isLink && fetchLink) {
// resolve links in objects with an @link property
const link = obj['@link']
// resolve links in objects with an / property
const link = obj[LINK_SYMBOL]
const linkParts = splitLink(link)
let blockLink = ''

Expand Down
5 changes: 4 additions & 1 deletion src/utils.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,16 @@
'use strict'

const flatten = require('lodash.flatten')
const ipld = require('ipld')

const LINK_SYMBOL = ipld.LINK_SYMBOL

exports = module.exports

// Recursively find all '@link' values in a given node
exports.getKeys = (node) => {
return flatten(Object.keys(node).map((key) => {
if (key === '@link') {
if (key === LINK_SYMBOL) {
return node[key]
}

Expand Down
16 changes: 8 additions & 8 deletions test/ipld-tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
'use strict'

const expect = require('chai').expect
const BlockService = require('ipfs-blocks').BlockService
const BlockService = require('ipfs-block-service')
const ipld = require('ipld')
const multihash = require('multihashing')
const async = require('async')
Expand Down Expand Up @@ -57,11 +57,11 @@ module.exports = (repo) => {
const node3 = {data: '3'}

node2.ref = {
'@link': ipld.multihash(ipld.marshal(node3))
'/': ipld.multihash(ipld.marshal(node3))
}

node1.ref = {
'@link': ipld.multihash(ipld.marshal(node2))
'/': ipld.multihash(ipld.marshal(node2))
}

async.series([
Expand Down Expand Up @@ -190,10 +190,10 @@ module.exports = (repo) => {
const alice = {
name: 'Alice',
about: {
'@link': ipld.multihash(ipld.marshal(aliceAbout))
'/': ipld.multihash(ipld.marshal(aliceAbout))
},
friends: [{
'@link': ipld.multihash(ipld.marshal(bob))
'/': ipld.multihash(ipld.marshal(bob))
}]
}
const mh = ipld.multihash(ipld.marshal(alice))
Expand Down Expand Up @@ -250,16 +250,16 @@ module.exports = (repo) => {

const author = {
name: {
'@link': `/${ipld.multihash(ipld.marshal(alice))}/name`
'/': `/${ipld.multihash(ipld.marshal(alice))}/name`
}
}

const blogpost = {
title: {
'@link': `/${ipld.multihash(ipld.marshal(draft))}/title`
'/': `/${ipld.multihash(ipld.marshal(draft))}/title`
},
author: {
'@link': `/ipfs/${ipld.multihash(ipld.marshal(author))}`
'/': `/ipfs/${ipld.multihash(ipld.marshal(author))}`
}
}

Expand Down
6 changes: 3 additions & 3 deletions test/utils.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ describe('utils', () => {
expect(
utils.getKeys({
hello: 'world',
'@link': 'link-1',
l1: {'/': 'link-1'},
nested: {
'@link': 'link-2',
l2: {'/': 'link-2'},
even: {
deeper: true,
'@link': 'link-3'
l3: {'/': 'link-3'}
}
}
})
Expand Down

0 comments on commit c2ec9fe

Please sign in to comment.