npipes-client

0.1.5 • Public • Published

npipes-client-js

Some nice syntactic sugar on top of nPipes.

let person = '...';
let traversals = [];
 
// Get parents
traversals.push(new Traversal()
  .set('traversal', 'parents')
  .node(person)
  .out('Birth_Child_Ref')
  .mark('birth')
  // Get Birth Date
  .outOpt('Birth_Date_Ref', 1, new Traversal()
    .save('date.original', 'original')
    .save('date.formal', 'formal')
    .back('birth')
  )
  // Get Birth Place
  .outOpt('Birth_Place_Ref', 1, new Traversal()
    .save('place.name', 'name')
    .back('birth')
  )
  // Get Parents
  .inOpt(['Birth_Mother_Ref', 'Birth_Father_Ref'], new Traversal()
    .save('parent.id', '_id')
    .outOpt('Name_Person_Ref', 1, new Traversal()
      .save('parent.name', 'name')
    )
  )
  .compile();
);
 
// Get children
traversals.push(new Traversal()
  .set('traversal', 'children')
  .node(person)
  .out(['Birth_Mother_Ref', 'Birth_Father_Ref'])
  .mark('birth')
  // Get Birth Date
  .outOpt('Birth_Date_Ref', 1, new Traversal()
    .save('date.original', 'original')
    .save('date.formal', 'formal')
    .back('birth')
  )
  // Get Birth Place
  .outOpt('Birth_Place_Ref', 1, new Traversal()
    .save('place.name', 'name')
    .back('birth')
  )
  // Get Children
  .inOpt('Birth_Child_Ref', new Traversal()
    .save('id', '_id')
    .outOpt('Name_Person_Ref', 1, new Traversal()
      .save('child.name', 'name')
    )
  )
  .compile()
);
 
Trepo.request({
    method: 'POST',
    path: '/traversal/run',
    body: traversals
  })
  .then(response => {
    // response is our executed traversals.
  })
  .catch(error => {
    // whoops, there was an error.
  });

Traversal

A Set of Steps that will be executed.

compile()

Compiles all of the steps and outputs a JSON traversal.

node(id)

Get a node by id.

out(labels, [limit])

From a node, follow outgoing edges having labels to other nodes. Optionally limit the number of edges using limit.

in(labels, [limit])

From a node, follow incoming edges having labels to other nodes. Optionally limit the number of edges using limit.

outOpt(labels, [limit], Traversal)

If a node has outgoing edges matching label, execute the passed in traversal. Optionally limit the number of edges using limit.

inOpt(labels, [limit], Traversal)

If a node has incoming edges matching label, execute the passed in traversal. Optionally limit the number of edges using limit.

mark(marker)

Mark a node so we can backtrack to it using back(marker).

back(marker)

Backtrack to a node we've previously visited.

save([key, value] || [obj])

Save one or more properties in the paylaod of a traversal. Takes in a propertyKey/payloadKey pair or an object of propertyKey => payloadKey pairs. Note that propertyKeys that begin with _ are meta property keys (i.e. id, label, etc).

set([propertyKey, payloadKey] || [obj])

Set one or more values in the payload of a traversal. Takes in a key/value pair or an object of key => value pairs.

Response

// TODO

  • group by payload key (i.e. type)
  • status information on each traversal

Readme

Keywords

Package Sidebar

Install

npm i npipes-client

Weekly Downloads

6

Version

0.1.5

License

MIT

Last publish

Collaborators

  • jonnymbgood