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

codex-ogm

v5.0.0

Published

[![Build Status](https://travis-ci.org/codex-digital/ogm.svg?branch=master)](https://travis-ci.org/codex-digital/ogm) [![devDependency Status](https://david-dm.org/codex-digital/ogm.png?theme=shields.io)](https://david-dm.org/codex-digital/ogm.png#info=de

Downloads

6

Readme

Codex OGM

Build Status devDependency Status Coverage Status npm version Slack Status

Build a graph and query it.

Powered by Neo4j 3, Bolt, and cypher-stream.

Install

npm install --save codex-ogm

Neo4j

Requires Neo4j 3 running on localhost with the following configurations:

# Enable auto-indexing for nodes, default is false
dbms.auto_index.nodes.enabled=true
# The node property keys to be auto-indexed, if enabled
dbms.auto_index.nodes.keys=id

Using Docker:

mkdir -p ~/.neo4j/conf
cp -R ./test/conf ~/.neo4j/conf
docker run -d --publish=7474:7474 --publish=7687:7687 --volume ~/.neo4j/conf:/conf neo4j:3.0

Example Usage

Creating a Tree with Access Control

See ./test/make-tree.js and ./test/access-control-test.js.

var ogm = require('codex-ogm');
var ogm     = require('./index');
var R       = require('ramda');
var Promise = require('bluebird');

var Node = ogm.Graph.Node;
var User = ogm.Graph.User;

var db = ogm.db();
var tx = db.createTransaction();
var log = console.log.bind(console);

var addChild = R.curry((tx, parent, child) => parent.addChild(child).save(tx))
var fiveTimes = R.times(R.__, 5);

// Node parent -> String type -> Promise<Node[]>
var createFiveChildren = R.curry((tx, type, parent) =>
  Promise
  .all(fiveTimes(
    i =>
      Promise.resolve(
        new Node(type, { name: `${type} ${i}`, i })
        .save(tx)
      )
      .tap(addChild(tx, parent, R.__))
  )))
;

var users = Promise
  .all(['Bob', 'Sue'])
  .map(name =>
    new User({ name })
    .save(tx)
  )
;

var nodes = Promise.resolve(
  new Node('Parent', { name: 'Parent' })
  .save(tx)
)
.then(parent =>
  createFiveChildren(tx, 'Child', parent)
  .then(children =>
    Promise.all(children)
    .map(createFiveChildren(tx, 'Grand Child'))
    .then(R.flatten)
    .then(grandChildren => ({ parent, children, grandChildren }))
  )
);

Promise.all([ users, nodes ])
.tap(([ [ bob, sue ], { parent, children } ]) => Promise.all([
  bob.grantAccessTo(parent).save(tx),
  sue.grantAccessTo(children[3]).save(tx)
]))
.tap(log)
.finally(() => {
  tx.commit();
})
;

The resulting graph

The resulting graph.

Reading From the Graph

Find a Node by ID

  context('given a saved node', () => {
    var node;
    var db = ogm.db();

    beforeEach(function (done) {
      var tx = db.createTransaction();
      node = new ogm.Graph.Node('Test', { foo: 'Bar' });
      node.save(tx);
      tx.on('end', done);
      tx.commit();
    });

    it('can find it by id', done => {
      var callback = sinon.spy();
      var tx = db.createTransaction();

      tx.concat(ogm.Graph.Node.findById(node.getId()));

      tx.forEach(callback);
      tx.forEach(result => {
        result.node.equals(node).should.equal(true);
      });

      tx.on('end', () => {
        callback.should.have.callCount(1);
        done();
      });

      tx.commit();

    });

  });

Find Related Nodes

See ./test/find-related-tests.js for more examples.

it('finds grand children', done => {

  var callback = sinon.spy();
  var db       = ogm.db();
  var tx       = db.createTransaction();

  tx.concat(parent.findRelated(['Child', 'Grand Child']));

  tx.forEach(callback);

  tx.on('end', () => {
    callback.should.have.callCount(25);
    done();
  });

  tx.commit();
});

Additionally supports sorting, filtering, searching, and returning a subset of properties.


Check the tests for more examples.