Graph

Graph

Class to inherit. Class with methods for control links in graph. Must be completed for adaptation to a particular database.

Constructor

new Graph(collection, fields, configopt)

import { Graph } from 'ancient-graph';

Source:
Parameters:
Name Type Attributes Description
collection

A pointer to the collection dannymineobhodimye daapteru to work with the graph. This may be a connection to the SQL database and table name, for example, or a collection of Mongo.

fields Object.<string, string>

Comparison of the data in the collection of data in the graph. It is necessary for the adapter.

config Object <optional>

Additional config.

Name Type Attributes Description
aliases Object <optional>
Name Type Attributes Description
$ String <optional>

Methods

count(selector, optionsopt, callbackopt) → {number}

Should count all matching documents.

Source:
Parameters:
Name Type Attributes Description
selector string | LinkSelector
options SelectOptions <optional>
callback Graph~countCallback <optional>
Returns:
Type:
number

[count]

each(selector, optionsopt, callbackopt)

Should call callback once for each matching document, sequentially and synchronously.

Source:
Parameters:
Name Type Attributes Description
selector string | LinkSelector
options SelectOptions <optional>
callback Graph~eachCallback <optional>

fetch(selector, optionsopt, callbackopt) → {Array.<Link>}

Find and all matching links as an Array.

Source:
Parameters:
Name Type Attributes Description
selector string | LinkSelector
options SelectOptions <optional>
callback Graph~fetchCallback <optional>
Returns:
Type:
Array.<Link>

links - result links objects in array

get(selector, optionsopt, callbackopt) → {Link}

Get one first matching link.

Source:
Parameters:
Name Type Attributes Description
selector string | LinkSelector
options SelectOptions <optional>
callback Graph~getCallback <optional>
Returns:
Type:
Link

link - result link object

insert(link, callbackopt, contextopt) → {string}

Should insert new link into graph. If the database allows, it is recommended to return a synchronous result. This can be useful in your application. But for writing generic code, it is recommended to only use the callback result.

Source:
Parameters:
Name Type Attributes Description
link Link
callback Graph~insertCallback <optional>
context Object <optional>
Returns:
Type:
string

[id]

map(selector, optionsopt, callbackopt) → {Array}

Should map callback over all matching documents. Returns an Array.

Source:
Parameters:
Name Type Attributes Description
selector string | LinkSelector
options SelectOptions <optional>
callback Graph~mapCallback <optional>
Returns:
Type:
Array

results

on(event, callback) → {function}

Should subscribe to the events: link, unlink, insert, update, remove.

Source:
Parameters:
Name Type Description
event string

One event name

callback Graph~onCallback
Returns:
Type:
function

Stops event subscription.

Example
var counter = 0;
var stop = graph.on('update', (oldData, newData) => {
  if (oldData.id == '1') console.log(oldData.id, 'is changed');
  counter++;
  if (counter == 3) stop();
});

options(optionsopt) → {*}

Should generate adapter for database options.

Source:
Parameters:
Name Type Attributes Description
options Object <optional>
Returns:
Type:
*

options - a options suitable for the database

query(selector) → {*}

Should generate adapter for database query for links search by unique id or by link query object.

Source:
Parameters:
Name Type Description
selector string | LinkSelector
Returns:
Type:
*

query

remove(selector, callbackopt, contextopt)

Should remove link by unique id or by link query object.

Source:
Parameters:
Name Type Attributes Description
selector string | LinkSelector
callback Graph~removeCallback <optional>
context Object <optional>

update(selector, modifier, callbackopt, contextopt) → {number}

Should update to new state of modifier object link by unique id or by link query object. If the database allows, it is recommended to return a synchronous result. This can be useful in your application. But for writing generic code, it is recommended to only use the callback result.

Source:
Parameters:
Name Type Attributes Description
selector string | LinkSelector
modifier LinkModifier
callback Graph~updateCallback <optional>
context Object <optional>
Returns:
Type:
number

[count]

Type Definitions

countCallback(erroropt, countopt)

Source:
Parameters:
Name Type Attributes Description
error Error <optional>
count number <optional>

countCallback(erroropt, countopt)

Source:
Parameters:
Name Type Attributes Description
error Error <optional>
count number <optional>

eachCallback(linkopt)

Source:
Parameters:
Name Type Attributes Description
link Link <optional>

eachCallback(linkopt)

Source:
Parameters:
Name Type Attributes Description
link Link <optional>

fetchCallback(erroropt, linksopt)

Optional callback. If present, called with an error object as the first argument and, if no error, the result links objects in array.

Source:
Parameters:
Name Type Attributes Description
error Error <optional>
links Array.<Link> <optional>

fetchCallback(erroropt, linksopt)

Optional callback. If present, called with an error object as the first argument and, if no error, the result links objects in array.

Source:
Parameters:
Name Type Attributes Description
error Error <optional>
links Array.<Link> <optional>

getCallback(erroropt, linkopt)

Optional callback. If present, called with an error object as the first argument and, if no error, the result link object.

Source:
Parameters:
Name Type Attributes Description
error Error <optional>
link Link <optional>

insertCallback(erroropt, idopt)

Optional callback. If present, called with an error object as the first argument and, if no error, the unique id of inserted link as the second.

Source:
Parameters:
Name Type Attributes Description
error Error <optional>
id string <optional>

insertCallback(erroropt, idopt)

Optional callback. If present, called with an error object as the first argument and, if no error, the unique id of inserted link as the second.

Source:
Parameters:
Name Type Attributes Description
error Error <optional>
id number | string <optional>

mapCallback(linkopt) → {*}

Source:
Parameters:
Name Type Attributes Description
link Link <optional>
Returns:
Type:
*

result

mapCallback(linkopt) → {*}

Source:
Parameters:
Name Type Attributes Description
link Link <optional>
Returns:
Type:
*

result

onCallback(oldLinkopt, newLinkopt, contextopt)

Source:
Parameters:
Name Type Attributes Description
oldLink Link <optional>

can be undefined on link and insert events

newLink Link <optional>

can be undefined on unlink and remove events

context Object <optional>

additional app information, such as context.userId

onCallback(oldLinkopt, newLinkopt, contextopt)

Source:
Parameters:
Name Type Attributes Description
oldLink Link <optional>

can be undefined on link and insert events

newLink Link <optional>

can be undefined on unlink and remove events

context Object <optional>

additional app information, such as context.userId

removeCallback(erroropt, countopt)

Optional callback. If present, called with an error object as the first argument.

Source:
Parameters:
Name Type Attributes Description
error Error <optional>
count number <optional>

removeCallback(erroropt, countopt)

Optional callback. If present, called with an error object as the first argument.

Source:
Parameters:
Name Type Attributes Description
error Error <optional>
count number <optional>

updateCallback(erroropt, countopt)

Optional callback. If present, called with an error object as the first argument and, if no error, the number of affected documents as the second.

Source:
Parameters:
Name Type Attributes Description
error Error <optional>
count number <optional>

updateCallback(erroropt, countopt)

Optional callback. If present, called with an error object as the first argument and, if no error, the number of affected documents as the second.

Source:
Parameters:
Name Type Attributes Description
error Error <optional>
count number <optional>