var Client = function (options) { if (!options) { throw new Error('Client requires an options object.'); } if (!options.url) { throw new Error('No cayley url provided.') } this._client = cayley(options.url); };
module.exports = (config) => { // singleton if (adapters[config]) { return adapters[config]; } const client = cayley(config); const incomming = (node, edges) => { return client.g.V.apply(client.g, nodes).Tag("o").In(null, "p").All(); }; const outgoing = (node, edges) => { return client.g.V.apply(client.g, nodes).Tag("s").Out(edges, "p").All(); }; const getObject = (id) => { return client.g.V(id) .Tag('subject') .Out([ SCHEMA + 'name>', FLOW_VOCAB + 'json>'] , 'predicate') .Out(RDF_SYNTAX + 'string>') .GetLimit(2); }; const getName = (id) => { return client.g.V(id) .Tag('subject') .Out(SCHEMA + 'name>', 'predicate') .Out(RDF_SYNTAX + 'string>') .GetLimit(1); }; const write = (triples) => { if (triples && triples.length) { return client.write(triples); } }; const remove = (triples) => { if (triples && triples.length) { return client.delete(triples); } }; // export store adapter return adapters[config] = Object.freeze({ sequence: (sequence_id, role, objectMode) => { return Triples.parse(sequence(client, sequence_id, role), objectMode); }, entrypoint: (entrypoint_name, objectMode) => { return Triples.parse(entrypoint(client, entrypoint_name), objectMode); }, outNodes: (id) => { return Triples.parse(visualization.outNodes(client, id)); }, // TODO move to service api networks: (id) => { return Triples.parse(visualization.networks(client, id)); }, getObject: (id) => { return Triples.parse(getObject(id)); }, getName: (id) => { return Triples.parse(getName(id)); }, incomming: incomming, outgoing: outgoing, remove: remove, write: write }); };
var cayley = require('cayley'); var client = cayley("http://localhost:64210/"); var g = graph = client.graph; g = graph = client.g; // Example to get all villains g.V('http://dbtropes.org/resource/Main/Villains').Out().All(function(err, res){ console.log(res); });