git ssb


0+

wanderer / js-ipld-graph-builder



Branch:

wanderer committed renameLatest: 7606807 on 2/8/2017, 10:34:21 PM
📄.travis.yml
📄README.md
📄cache.js
📁docs
📁example
📄index.js
📄package.json
📄readStream.js
📄store.js
📁test

SYNOPSIS

NPM Package
Build Status
Coverage Status

js-standard-style

This provides an efficent way to build and manipulate IPLD DAGs.

INSTALL

npm install ipld-graph-builder

USAGE

const store = new Store()
const newVertex = new Vertex({
  store: store
})
const path = ['not', 'all', 'those', 'who', 'wanderer', 'are', 'lost']
const value = 'all that is gold does not glitter'

newVertex.set(path, new Vertex({
  value: value
}))

newVertex.get(path)
.then(vertex => {
  // retrieves the vertex that was stored
  // saves all the work done on the trie to the store
  // and return the merkle link to the root vertex
  return newVertex.flush()
}).then(cid => {
  // get the vertex from the store
  return store.get(cid)
}).then(vertex => {
  // the vertex returned from the store
  return vertex.get(path)
}).then(vertex => {
  console.log(vertex.value) // all that is gold does not glitter
})

NOTES

Operations that mutate the trie (set and delete) are synchronous while operations that return values (get, update) are asynchronous. This is because writing operations are written to a cache. And the cache is only written to the store when flush is called. The idea here is to avoid doing lookups and hashing until it is absolutely necessary.

Store is just a instance of ipld-resolver
that uses promises instead of callbacks.

API

TESTS

npm run tests

LICENSE

MPL-2.0)


Built with git-ssb-web