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

dynamo-graph

v0.4.2

Published

Low-level graph database operations implemented in DynamoDB.

Downloads

2

Readme

dynamo-graph

Low-level graph database operations implemented in DynamoDB. Logic involving complex traversals, lazy lists, intersections, and unions, are deferred to the consuming client.

Ensure that you have your AWS CLI properly configured, so that the aws-sdk dependency can do its magic.

Documentation (TODO)

All code is written in a literate style. For more detailed explanations, refer to the source code.

Example

import { G, V, E } from 'dynamo-graph'

// create a graph instance

const g = G.define('my-graph')

// create vertex definitions

const USER = V.define('User')
const NOTE = V.define('Note')

// create edge definitions

const AUTHORED = E.define('Authored', E.ONE_TO_MANY)

const overview = async () => {

  // if this is our first time using the graph
  // G.generate will instantiate all the DynamoDB tables, indices, and system objects
  await G.generate(g)

  // V.create

  const me = await V.create(g, USER, { name: "James", job: "Intern" })
    // => { id: '3Rx', label: 'User', updatedAt: 14699502051042, attrs: { name: "James", job: "Intern" } }
  const boss = await V.create(g, USER, { name: "Tyler", job: "CTO" })
    // => { id: '3Ry', label: 'User', updatedAt: 14699502056492, attrs: { name: "Tyler", job: "CTO" }}
  const note = await V.create(g, NOTE, { message: "some note" })
    // => { id: '3Rz', label: 'Note', updatedAt: 14699502285314, attrs: { message: "some note" }}

  // V.all

  await V.all(g, USER)
    // => TODO: document

  // V.update

  await V.update(g, USER, me.id, { name: "James", job: "Engineer" })
    // => { id: '3Rx', label: 'User', updatedAt: 14699502496014, attrs: { name: "James", job: "Engineer" } }

  // V.putByKey

  await V.putByKey(g, NOTE, 'important', { message: 'Publish dynamo-graph!' })
    // => { id: 'd7', label: 'Note', updatedAt: 1469950262268, key: 'important', attrs: { message: 'Publish dynamo-graph!' } }

  // n.b. the id remains the same, the key uniquely identifies the vertex
  const important = await V.putByKey(g, NOTE, 'important', { message: 'Published' })
    // => { id: 'd7', label: 'Note', updatedAt: 1469950309677, key: 'important', attrs: { message: 'Published' } }

  // E.set

  const e1 = await E.set(g, important.id, AUTHORED, E.IN, E.GENERATE, me.id)
    // => { from: 'd7', label: 'Authored', direction: '<', weight: 1042, to: '3Rx', updatedAt: 1469950464801 }

  const e2 = await E.set(g, me.id, AUTHORED, E.OUT, +Date.now(), note.id)
    // => { from: '3Rx', label: 'Authored', direction: '>', weight: 1469950468427, to: '3Rz', updatedat: 1469950468427 }

  // E.get

  await E.get(g, note.id, AUTHORED, E.IN, +Date.now(), me.id)
    // => { from: '3Rz', label: 'Authored', direction: '<', weight: 1469950468427, to: '3Rx', updatedat: 1469950468427 }

  // E.range

  await E.range(g, me.id, AUTHORED, E.OUT)
    // => { items: [ e2, e1 ], hasMore: false, lastCursor: 1042 }
  await E.range(g, me.id, AUTHORED, E.OUT, { first: 1, after: 99999 })
    // => { items: [ e1 ], hasMore: false, lastCursor: 1042 }
  await E.range(g, me.id, AUTHORED, E.OUT, { last: 1, before: -1 })
    // => { items: [ e1 ], hasMore: true, lastCursor: 1042 }

  // Edge multiplicities are respected:
  
  await E.set(g, boss.id, AUTHORED, E.OUT, E.GENERATE, important.id)
    // => { from: '3Ry', label: 'Authored', direction: '>', weight: 1043, to: 'd7', updatedAt: 1469981321205 }
  await E.get(g, me.id, AUTHORED, E.OUT, important.id)
    // => null
  await E.get(g, important.id, AUTHORED, E.IN, me.id)
    // => null

  // E.remove
  await E.remove(g, boss.id, AUTHORED, E.OUT, important.id)
    // => { from: '3Ry', label: 'Authored', direction: '>', weight: 1043, to: 'd7', updatedAt: 1469981321205 }

}

G

A graph is an abstraction over the database, containing meta information as well as exposure to the raw operations

type Graph =
  { name: string
  , env: "production" | "beta" | "development"
  , region: "us-east-1" | "us-west-1" | ... | "local"
  , id: () => Promise<Id>
  , weight: () => Promise<Weight>
  , putCounter: (key: string, value: number) => Promise<number>
  , incrCounter: (key: string, value: number) => Promise<number></number>
  }

G.define(name[, { env, region }]): Graph

G.generate(g): Promise<Graph>

V

A vertex is a tuple (id, label, attrs, key?, updatedAt) such that the id uniquely determines the vertex, the label uniquely determines the type of the attributes, and the label-key pair uniquely determines a vertex

type Vertex<a> =
  { id        : string
  , label     : Label
  , attrs     : a
  , key?      : string
  , updatedAt : number
  }

V.define(label)

V.create(g, def, attrs)

V.update(g, def, id, attrs)

V.putByKey(g, def, key, attrs)

V.get(g, id)

V.getMany(g, ids)

V.getByKey(g, def, key)

V.all(g, def, cursor)

V.count(g, def, cursor)

V.remove(g, id)

E

An edge is a tuple (from, label, direction, weight, to, attrs, updatedAt) such that (from, label, direction, to) and (from, label, direction, weight) both uniquely identify the edge.

type Edge<a> =
  { from       : string
  , label      : Label
  , direction  : ">" | "<"
  , weight     : number
  , to         : string
  , attrs      : a
  , updatedAt  : number
  }

Directions

Edge operations require a direction: E.OUT, or E.IN

Multiplicities

Defining an Edge requires the use of one of the following multiplicities:

  • E.MANY_TO_MANY: no restrictions, describes a simple graph
  • E.ONE_TO_MANY: a vertex may have many OUT edges, but only one IN edge, typically surjective
  • E.MANY_TO_ONE: a vertex may have many IN edges, but many OUT edge, i.e. an injective mapping
  • E.ONE_TO_ONE: a vertex may have only one IN or OUT edge, i.e. a bipartition

E.define(label, multiplicity)

E.get(g, from, def, direction, to)

E.range(g, from, def, direction, cursor)

E.count(g, from, def, direction, cursor)

E.set(g, from, def, direction, weight, to, attrs)

E.remove(g, from, def, to)