npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

giraffe

v2.1.1

Published

Lightweight Graph DB implementation

Downloads

64

Readme

Giraffe

A simple node & browser graph database

Travis CI Version NPM Downloads LICENSE

Install

npm install --save giraffe

Use

import Giraffe from 'giraffe';

const db = new Giraffe();

export default db;

Methods

  • new Giraffe(data, callback)

    • data: Object Optional
      • Should be in the shape of { nodes: [], edges: [] }
      • Labels are created dynamically based on data passed in
      • Nodes and Edges are checked for their correct shape.
    • callback: Function Optional
      • Can be passed first if no data is supplied
      • Callback is called just before returning on each Database Method
    • Create the DB instance
  • .create(label, data)

    • label: String || Array Optional
    • data: Object
    • label is type checked and coerced into a Array within the Node constructor
  • .remove(nodes)

    • nodes: Array Array of Nodes to be removed from graph
      • this is automatically converted to an Array if a single node is passed in.
  • .edge([ from ], [ to ], label, properties)

    • from Array Array of Nodes where edge originates
    • to: Array Array of Nodes where edge goes
    • label: String Optional
    • properties: Object Optional
  • .query(label, properties)

    • label: String Optional
    • properties: Object Optional
      • you can search for an edge with the property key _edges
    • An empty query returns all nodes
    • Queries return only their immediate relationships
  • .update([ nodes ], [ labels ], data)

    • nodes: Array (or single) node to be updated
    • labels: Array (or single) label to be added to Nodes.
    • data: Object Data set to be merged with previous data, any duplicate keys will be overwritten.
    • edge labels cannot be updated, an error will be thrown

Internal Structure

Database

{
  /**
   * All relationships with additional properties
   */
  edges: [],

  /**
   * All nodes with properties
   */
  nodes: [],

  /**
   * Dynamic key:value store for tracking known node and edge labels
   */
  labels: {
    nodes: {
      [label]: [/* Array of Node ids */]
    },
    edges: {
      [label]: [/* Array of Edge ids */]
    }

  }
}

Callback

The callback passed to your DB instance is called before the return statement of every method. That is to say db.create returns the created Node, but just before that return you callback is fired.

The calls are all identical it is called with the Type of request and the modified, added, or removed data.

| method | type | data | | ------ | -------- | ------------------------------- | | Create | 'create' | Node | | Remove | 'remove' | Array[Node] | | Edge | 'edge' | Array[Edge] | | Query | 'query' | Array[Query Result] | | Update | 'update' | Array[Updated Nodes / Edges] |

Node

{
  identity: <UUID />,
  properties: Object,
  labels: Array,
  edges: Array,
}

Node information

  • properties is the object passed into the db.create method.
  • edges is an array of Edge identity's before a query, after a query it is an array of references to the Node's they represent

Edge

{
  identity: <UUID />,
  from: <Node Identity /> || <Node />,
  through: <Node Identity /> || <Node />,
  label: String,
  properties: Object
}

Edge information

  • properties is the object passed into the db.edge method.
  • from and through are stored in the DB as from.identity and through.identity.
  • When db.query returns from and through are references to the Node's they represent

Coming Features

Checkout out the TODO Project on Github.

  1. Complex Queries.
  2. Investigate Typescript.