ipld/js-ipld-graph-builder

Name: js-ipld-graph-builder

Owner: IPLD

Description: Provides an efficient way to build and manipulate IPLD DAGs as JSON

Created: 2016-10-18 17:54:18.0

Updated: 2018-05-20 06:40:53.0

Pushed: 2018-05-07 08:59:11.0

Homepage:

Size: 511

Language: JavaScript

GitHub Committers

UserMost Recent Commit# Commits

Other Committers

UserEmailMost Recent Commit# Commits

README

SYNOPSIS

NPM Package Build Status Coverage Status

js-standard-style

This provides an efficent way to build and manipulate IPLD DAGs as JSON. This is accomplished by only producing merkle roots when flushing the DAG. If any object has a “/” property, its value will be replaced with the merkle hash of that value when flushed. This allows you to build object anyway you like.

LEAD MAINTAINER

wanderer

INSTALL

npm install ipld-graph-builder

USAGE

t IPFS = require('ipfs')
t Graph = require('ipld-graph-builder')
t ipfs = new IPFS()

.on('start', () => {
nst graph = new Graph(ipfs.dag)
nst a = {
some: {
  thing: 'nested'
}

nst b = {
lol: 1


aph.set(a, 'some/thing/else', b).then(result => {
// set "patches" together two objects
console.log(JSON.stringify(result))
> {
>  "some": {
>    "thing": {
>      "else": {
>        "/": {
>          "lol": 1
>        }
>      }
>    }
>  }
>}


// flush replaces the links with merkle links, resulting in a single root hash
graph.flush(result).then((result) => {
  console.log(result)
  > { '/': 'zdpuAqnGt7k49xSfawetvZXSLm4b1vvkSMnDrk4NFqnCCnW5V' }

  // taverse paths through merkle links given a starting vertex
  graph.get(result, 'some/thing/else').then(result2 => {
    console.log(result2)
    > { lol: 1 }
  })
})


Additonally you can define the encoding of each link by adding the follow options property to un-merklized links. options will be used as the options argument for DAG.put. For Example:


y-link': {
'/': {
  'some': 'stuff here'
},
'options': {
  format: 'dag-cbor',
  hashAlg: 'sha2-256'
 }


API

'./docs/'

TESTS

npm run tests

LICENSE

MPL-2.0


This work is supported by the National Institutes of Health's National Center for Advancing Translational Sciences, Grant Number U24TR002306. This work is solely the responsibility of the creators and does not necessarily represent the official views of the National Institutes of Health.