Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Socket
Sign inDemoInstall

@tangle/graph

Package Overview
Dependencies
Maintainers
2
Versions
13
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@tangle/graph

a helper for building + updating traverseable tangle graphs


Version published
Weekly downloads
159
increased by488.89%
Maintainers
2
Weekly downloads
 
Created
Source

@tangle/graph

A module which allows you to build a simple graph, and provides simple helper methods for modifying an querying that graph.

Example Usage

const Graph = require('@tangle/graph')

//     A   (root)
//    / \          |
//   B   C         | causality
//    \ /          V
//     D

const nodes = [
  {
    key: 'A',
    comment: 'What shall we have for dinner?',
    previous: null // << signals this is a rootNode
  },
  {
    key: 'B',
    comment: 'Hows about spaghetti?',
    previous: ['A']
  },
  {
    key: 'C',
    comment: 'My only constraint is no wheat.',
    previous: ['A']
  },
  {
    key: 'D',
    comment: 'Everyone ok with glutten-free spaghetti?',
    previous: ['C', 'D']
  }
]

const graph = new Graph (nodes)
graph.isMergeNode('D')
// => true

API

new Graph(nodes, opts) -> graph

Creates a Graph instance which builds a model of the graph. Notably builds a graph based on links where:

All of these graph methods assume you're passing in nodes which have :

  • a key property which is unique
  • a thread property which stores root (key) and previous (Array of keys)

In scuttlebutt the keys are the hash addresses of the messages

You can an opts Object to some methods:

  • getBacklinks which takes a node and returns either:
    • [key] - an Array of keys of nodes that this node was extending from
    • null - if this was a "root node" (i.e. was the start of a tangle graph)

graph.getNode(key) => result

where result is:

  • node if it's connected within the graph
  • null if it's disconnected
  • undefined if it was not in the set of nodes passed in initially

graph.isConnected(key) => Boolean

graph.getLinks(key) => [key]

Returns an Array of keys of nodes that are causally linked to this node-key. These links pointing forwards in time to node after this key-node in the graph.

graph.getBacklinks(key) => [key]

Returns an Array of keys of nodes that are causally linked to this node-key. These links pointing backwards in time to node before this key-node in the graph.

graph.isBrancNode(key) => Boolean

Tells you whether the graph diverges as you proceed from the given node-key. (basically graph.getLinks(key).length > 1)

graph.isMergeNode(key) => Boolean

Tells you if 2 or more branches converge in the given node-key. (basically graph.getBacklinks(key).length > 1)

graph.isHeadNode(key) => Boolean

Tells you whether the given node-key belongs to a head of the graph, i.e. a leading tip causally (basically graph.getLinks(key).length === 0)

graph.rootNodeKeys

A getter which gives you access to an Array of keys for nodes which are "roots" within the graph (i.e. are the starting points of the graph)

graph.raw

A getter which gives you access to { linkMap, backlinkMap }. These are data structures which map the links of the graph in both directions.


NOTES

this is expected to be used with DAGs (directed acyclic graphs), but there is currently no internal check built to guarentee this

Keywords

FAQs

Package last updated on 01 Oct 2020

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc