rexy-engine
Version:
json library for the Rexster API
573 lines (508 loc) • 17.5 kB
JavaScript
// Generated by CoffeeScript 1.4.0
/*----------------------------------
Rexster API for nodejs
requirements:
restler
Author: Tyler Anderson
github: Tyler-Anderson
email: tyler@brava.do
twitter: _Bravado
website: http://brava.do
----------------------------------
*/
(function() {
var Rexy_Engine, rest;
rest = require('restler');
Rexy_Engine = (function() {
function Rexy_Engine(url, db) {
this.url = url + "/graphs/";
this.db = db;
}
Rexy_Engine.prototype.getGraphs = function(ctx, cb) {
rest.get(this.url).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getNamedGraph = function(ctx, cb) {
rest.get(this.url + this.db).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getVertices = function(ctx, cb) {
rest.get(this.url + this.db + "/vertices").on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getVertexWithId = function(ctx, cb, id) {
rest.get(this.url + this.db + "/vertices/" + id).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getAdjacentOut = function(ctx, cb, req) {
var k, v, _buf, _ref;
_buf = "";
if (req.params) {
_buf += "?";
_ref = req.params;
for (k in _ref) {
v = _ref[k];
_buf += k + "=" + v + "&";
}
_buf = _buf.slice(0, -1);
}
rest.get(this.url + this.db + "/vertices/" + req._id + "/out" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getAdjacentIn = function(ctx, cb, req) {
var k, v, _buf, _ref;
_buf = "";
if (req.params) {
_buf += "?";
_ref = req.params;
for (k in _ref) {
v = _ref[k];
_buf += k + "=" + v + "&";
}
_buf = _buf.slice(0, -1);
}
rest.get(this.url + this.db + "/vertices/" + req._id + "/in" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getAdjacentBoth = function(ctx, cb, req) {
var k, v, _buf, _ref;
if (req.params) {
_buf = "?";
_ref = req.params;
for (k in _ref) {
v = _ref[k];
_buf += k + "=" + v + "&";
}
_buf = _buf.slice(0, -1);
}
rest.get(this.url + this.db + "/vertices/" + req._id + "/both" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getOutVerticesCount = function(ctx, cb, req) {
var k, v, _buf, _ref;
if (req.params) {
_buf = "?";
_ref = req.params;
for (k in _ref) {
v = _ref[k];
_buf += k + "=" + v + "&";
}
_buf = _buf.slice(0, -1);
}
rest.get(this.url + this.db + "/vertices/" + req._id + "/outCount" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getInVerticesCount = function(ctx, cb, req) {
var k, v, _buf, _ref;
if (req.params) {
_buf = "?";
_ref = req.params;
for (k in _ref) {
v = _ref[k];
_buf += k + "=" + v + "&";
}
_buf = _buf.slice(0, -1);
}
rest.get(this.url + this.db + "/vertices/" + req._id + "/inCount" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getBothVerticesCount = function(ctx, cb, req) {
var k, v, _buf, _ref;
if (req.params) {
_buf = "?";
_ref = req.params;
for (k in _ref) {
v = _ref[k];
_buf += k + "=" + v + "&";
}
_buf = _buf.slice(0, -1);
}
rest.get(this.url + this.db + "/vertices/" + req._id + "/bothCount" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getOutVertices = function(ctx, cb, req) {
var k, v, _buf, _ref;
if (req.params) {
_buf = "?";
_ref = req.params;
for (k in _ref) {
v = _ref[k];
_buf += k + "=" + v + "&";
}
_buf = _buf.slice(0, -1);
}
rest.get(this.url + this.db + "/vertices/" + req._id + "/outIds" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getInVertices = function(ctx, cb, req) {
var k, v, _buf, _ref;
if (req.params) {
_buf = "?";
_ref = req.params;
for (k in _ref) {
v = _ref[k];
_buf += k + "=" + v + "&";
}
_buf = _buf.slice(0, -1);
}
rest.get(this.url + this.db + "/vertices/" + req._id + "/inIds" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getByBothVertices = function(ctx, cb, req) {
var k, v, _buf, _ref;
if (req.params) {
_buf = "?";
_ref = req.params;
for (k in _ref) {
v = _ref[k];
_buf += k + "=" + v + "&";
}
_buf = _buf.slice(0, -1);
}
rest.get(this.url + this.db + "/vertices/" + req._id + "/bothIds" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getAdjacentByEdgeLabel = function(ctx, cb, req) {
rest.get(this.url + this.db + "/vertices/" + req._id + req.dir + "?_" + req.label + "=written_by").on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getEdges = function(ctx, cb) {
rest.get(this.url + this.db + "/edges").on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getEdgeById = function(ctx, cb, id) {
rest.get(this.url + this.db + "/edges" + id).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getVertexOutEdges = function(ctx, cb, req) {
var k, v, _buf, _ref;
if (req.params) {
_buf = "?";
_ref = req.params;
for (k in _ref) {
v = _ref[k];
_buf += k + "=" + v + "&";
}
_buf = _buf.slice(0, -1);
}
rest.get(this.url + this.db + "/edges" + "/vertices/" + req._id + "/outE" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getVertexInEdges = function(ctx, cb, req) {
var k, v, _buf, _ref;
if (req.params) {
_buf = "?";
_ref = req.params;
for (k in _ref) {
v = _ref[k];
_buf += k + "=" + v + "&";
}
_buf = _buf.slice(0, -1);
}
rest.get(this.url + this.db + "/edges" + "/vertices/" + req._id + "/inE" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getVertexBothEdges = function(ctx, cb, req) {
var k, v, _buf, _ref;
if (req.params) {
_buf = "?";
_ref = req.params;
for (k in _ref) {
v = _ref[k];
_buf += k + "=" + v + "&";
}
_buf = _buf.slice(0, -1);
}
rest.get(this.url + this.db + "/edges" + "/vertices/" + req._id + "/bothE" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getByEdgeLabel = function(ctx, cb, req) {
rest.get(this.url + this.db + "/vertices/" + req._id + req.dir + "E?_" + req.label + "=written_by").on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getIndices = function(ctx, cb) {
rest.get(this.url + this.db + "/indices").on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getElementsByKV = function(ctx, cb, req) {
rest.get(this.url + this.db + "/indices/index?key=" + req.key + "&value=" + req.value).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getElementCountByKV = function(ctx, cb, req) {
rest.get(this.url + this.db + "/indices/index/count?key=" + req.key + "&value=" + req.value).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getKeyIndices = function(ctx, cb) {
rest.get(this.url + this.db + "/keyindices/").on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getVertexKeys = function(ctx, cb) {
rest.get(this.url + this.db + "/keyindices/vertex").on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getEdgeKeys = function(ctx, cb) {
rest.get(this.url + this.db + "/keyindices/edge").on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.postVertex = function(ctx, cb) {
rest.post(this.url + this.db + "/vertices/").on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.postVertexWithId = function(ctx, cb, id) {
rest.post(this.url + this.db + "/vertices/" + id).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.postCreateOrUpdateV = function(ctx, cb, req) {
var k, v, _buf, _ref;
_buf = "";
_ref = req.properties;
for (k in _ref) {
v = _ref[k];
_buf += k + "=" + v + "&";
}
_buf = _buf.slice(0, -1);
rest.post(this.url + this.db + "/vertices/" + req._id + "?" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.postEdgeWithLabel = function(ctx, cb, req) {
var k, v, _buf, _ref;
_buf = "";
_ref = req.properties;
for (k in _ref) {
v = _ref[k];
_buf += "&" + k + "=" + v;
}
return rest.post(this.url + this.db + "/edges?_outV=" + req.outV + "&_label=" + req.label + "&_inV=" + req.inV + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
};
Rexy_Engine.prototype.postEdgeWithId = function(ctx, cb, req) {
var k, v, _buf, _ref;
_buf = "";
_ref = req.properties;
for (k in _ref) {
v = _ref[k];
_buf += "&" + k + "=" + v;
}
rest.post(this.url + this.db + "/edges/" + req._id + "?_outV=" + req.outV + "&_label=" + req.label + "&_inV=" + req.inV + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.postUpdateEdge = function(ctx, cb, req) {
var k, v, _buf, _ref;
_buf = "";
_ref = req.properties;
for (k in _ref) {
v = _ref[k];
_buf += k + "=" + v + "&";
}
_buf = _buf.slice(0, -1);
rest.post(this.url + this.db + "/edges/" + req._id + "?" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.postManualIndex = function(ctx, cb, index) {
rest.post(this.url + this.db + "/indices/" + index + "?class=vertex").on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.postCreateKey = function(ctx, cb, req) {
rest.post(this.url + this.db + "/keyindices/" + req.vertex + "/" + req.key).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.putReplaceVProperties = function(ctx, cb, req, buf) {
var k, v, _buf, _ref;
if (buf == null) {
buf = "";
}
_buf = "";
_ref = req.properties;
for (k in _ref) {
v = _ref[k];
_buf += k + "=" + v + "&";
}
_buf = _buf.slice(0, -1);
rest.put(this.url + this.db + "/vertices/" + req._id + "?" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.putReplaceEProperties = function(ctx, cb, req) {
var k, v, _buf, _ref;
_buf = "";
_ref = req.properties;
for (k in _ref) {
v = _ref[k];
_buf += k + "=" + v + "&";
}
_buf = _buf.slice(0, -1);
rest.put(this.url + this.db + "/edges/" + req._id + "?" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.putVertexAtIndexByKV = function(ctx, cb, req) {
rest.put(this.url + this.db + "/indices/" + req.index + "?key=" + req.key + "&value=" + req.value + "&id=" + req._id).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.delVertex = function(ctx, cb, id) {
rest.del(this.url + this.db + "/vertices/" + id).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.delVProps = function(ctx, cb, req) {
rest.del(this.url + this.db + "/edges/" + req._id + req.properties.join("&")).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.delIndex = function(ctx, cb, index) {
rest.del(this.url + this.db + "/indices/" + index).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.delVertexAtIndexByKV = function(ctx, cb, req) {
rest.del(this.url + this.db + "/indices/" + req.index + "?key=" + req.key + "&value=" + req.value + "&class=vertex&id=" + req._id).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getBatchV = function(ctx, cb, idList) {
var i, _buf, _i, _ref;
_buf = "[";
for (i = _i = 0, _ref = idList.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
_buf += idList[i] += ",";
}
_buf = _buf.slice(0, -1);
_buf += "]";
rest.get(this.url + this.db + "/tp/batch/vertices?idList=" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.getBatchE = function(ctx, cb, req) {
var i, _buf, _i, _ref;
_buf = "[";
for (i = _i = 0, _ref = idList.length; 0 <= _ref ? _i < _ref : _i > _ref; i = 0 <= _ref ? ++_i : --_i) {
_buf += idList[i] += ",";
}
_buf = _buf.slice(0, -1);
_buf += "]";
rest.get(this.url + this.db + "/tp/batch/edges?idList=" + _buf).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.postBatch = function(ctx, cb, txList) {
rest.postJson(this.url + this.db + "/tp/batch/tx", txList).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.gremlin = function(ctx, cb, req) {
rest.postJson(this.url + this.db + "/tp/gremlin", req).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.gremlinV = function(ctx, cb, id, req) {
rest.postJson(this.url + this.db + "/vertices/" + id + "/tp/gremlin", req).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.gremlinE = function(ctx, cb, id, req) {
rest.postJson(this.url + this.db + "/edges/" + id + "/tp/gremlin", req).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.frameV = function(ctx, cb, id, frame) {
rest.get(this.url + this.db + "/vertices/" + id + "/tp/frames/" + frame).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.frameE = function(ctx, cb, id, frame) {
rest.get(this.url + this.db + "/edges/" + id + "/tp/frames/" + frame).on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
Rexy_Engine.prototype.frameEI = function(ctx, cb, id, frame) {
rest.get(this.url + this.db + "/edges/" + id + "/tp/frames/" + frame + "direction=inverse").on("complete", function(data) {
return cb.call(ctx, data);
});
return true;
};
return Rexy_Engine;
})();
module.exports = Rexy_Engine;
}).call(this);