Example #1
0
ArangoDatabase.prototype._document = function (id) {
  var rev = null;
  var requestResult;

  if (id.hasOwnProperty("_id")) {
    if (id.hasOwnProperty("_rev")) {
      rev = id._rev;
    }

    id = id._id;
  }

  if (rev === null) {
    requestResult = this._connection.GET(this._documenturl(id));
  }
  else {
    requestResult = this._connection.GET(this._documenturl(id),
      {'if-match' : JSON.stringify(rev) });
  }

  if (requestResult !== null
      && requestResult.error === true 
      && requestResult.errorNum === internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code) {
    throw new ArangoError(requestResult);
  }

  arangosh.checkRequestResult(requestResult);

  return requestResult;
};
Example #2
0
Vertex.prototype.getEdges = function () {
  var labels = Array.prototype.slice.call(arguments);
  var graph = this._graph;
  var requestResult;
  var edges;
  var cursor;

  requestResult = graph._connection.POST("/_api/graph/"
    + encodeURIComponent(graph._properties._key)
    + "/edges/"
    + encodeURIComponent(this._properties._key),
    JSON.stringify({ filter : { labels: labels } }));

  arangosh.checkRequestResult(requestResult);

  cursor = new ArangoQueryCursor(graph._vertices._database, requestResult);
  edges = new GraphArray();

  while (cursor.hasNext()) {
    var edge = new Edge(graph, cursor.next());

    edges.push(edge);
  }

  return edges;
};
Example #3
0
Graph.prototype.addEdge = function (out_vertex, in_vertex, id, label, data) {
  var requestResult;
  var params;
  var key;

  if (data === null || typeof data !== "object") {
    params = {};
  }
  else {
    params = data._shallowCopy || {};
  }

  params._key = id;
  params._from = out_vertex._properties._key;
  params._to = in_vertex._properties._key;
  params.$label = label;

  requestResult = this._connection.POST("/_api/graph/"
    + encodeURIComponent(this._properties._key) + "/edge",
    JSON.stringify(params));

  arangosh.checkRequestResult(requestResult);

  return new Edge(this, requestResult.edge);
};
Example #4
0
ArangoDatabase.prototype._version = function () {
  var requestResult = this._connection.GET("/_api/version");

  arangosh.checkRequestResult(requestResult);

  return requestResult.version;
};
Example #5
0
var setupReplication = function(config) {
  config = config || { };
  if (! config.hasOwnProperty('autoStart')) {
    config.autoStart = true;
  }
  if (! config.hasOwnProperty('includeSystem')) {
    config.includeSystem = true;
  }
  if (! config.hasOwnProperty('verbose')) {
    config.verbose = false;
  }

  const db = internal.db;

  const body = JSON.stringify(config);
  const headers = {
    "X-Arango-Async": "store"
  };
    
  const requestResult = db._connection.PUT_RAW("/_api/replication/make-slave", body, headers);
  arangosh.checkRequestResult(requestResult);


  if (config.async) {
    return requestResult.headers["x-arango-async-id"];
  }
   
  return waitForResult(config, requestResult.headers["x-arango-async-id"]);
};
Example #6
0
ArangoDatabase.prototype._collections = function () {
  var requestResult = this._connection.GET(this._collectionurl());

  arangosh.checkRequestResult(requestResult);

  if (requestResult.collections !== undefined) {
    var collections = requestResult.collections;
    var result = [];
    var i;

    // add all collentions to object
    for (i = 0;  i < collections.length;  ++i) {
      // only include collections of the "correct" type
      // if (collections[i]["type"] != this._type) {
      //   continue;
      // }
      var collection = new this._collectionConstructor(this, collections[i]);
      this._registerCollection(collection._name, collection);
      result.push(collection);
    }

    return result;
  }

  return undefined;
};
Example #7
0
ArangoDatabase.prototype._collection = function (id) {
  var url;

  if (typeof id === "number") {
    url = this._collectionurl(id) + "?useId=true";
  }
  else {
    url = this._collectionurl(id);
  }

  var requestResult = this._connection.GET(url);

  // return null in case of not found
  if (requestResult !== null
      && requestResult.error === true 
      && requestResult.errorNum === internal.errors.ERROR_ARANGO_COLLECTION_NOT_FOUND.code) {
    return null;
  }

  // check all other errors and throw them
  arangosh.checkRequestResult(requestResult);

  var name = requestResult.name;

  if (name !== undefined) {
    this._registerCollection(name, new this._collectionConstructor(this, requestResult));
    return this[name];
  }

  return null;
};
Example #8
0
exports.update = function (user, passwd, active, extra, changePassword) {
  var db = internal.db;

  var uri = "_api/user/" + encodeURIComponent(user);
  var data = {};

  if (passwd !== undefined) {
    data.passwd = passwd;
  }

  if (active !== undefined) {
    data.active = active;
  }

  if (extra !== undefined) {
    data.extra = extra;
  }

  if (changePassword !== undefined) {
    data.changePassword = changePassword;
  }

  var requestResult = db._connection.PATCH(uri, JSON.stringify(data));
  return arangosh.checkRequestResult(requestResult);
};
Example #9
0
Graph.prototype.getEdges = function () {
  var that = this;
  var requestResult;
  var cursor;
  var Iterator;

  requestResult = this._connection.POST("/_api/graph/"
    + encodeURIComponent(this._properties._key)
    + "/edges",
    "{}");

  arangosh.checkRequestResult(requestResult);

  cursor = new ArangoQueryCursor(this._vertices._database, requestResult);

  Iterator = function () {
    this.next = function next() {
      if (cursor.hasNext()) {
        return new Edge(that, cursor.next());
      }

      return undefined;
    };

    this.hasNext = function hasNext() {
      return cursor.hasNext();
    };

    this._PRINT = function (context) {
      context.output += "[edge iterator]";
    };
  };

  return new Iterator();
};
Example #10
0
Vertex.prototype.edges = function () {
  var graph = this._graph;
  var requestResult;
  var edges;
  var cursor;

  requestResult = graph._connection.POST("/_api/graph/"
    + encodeURIComponent(graph._properties._key)
    + "/edges/"
    + encodeURIComponent(this._properties._key),
  '{ "filter" : { "direction" : "any" } }');

  arangosh.checkRequestResult(requestResult);

  cursor = new ArangoQueryCursor(graph._vertices._database, requestResult);
  edges = new GraphArray();

  while (cursor.hasNext()) {
    var edge = new Edge(graph, cursor.next());

    edges.push(edge);
  }

  return edges;
};
Example #11
0
applier.forget = function () {
  var db = internal.db;

  var requestResult = db._connection.DELETE("/_api/replication/applier-state");
  arangosh.checkRequestResult(requestResult);

  return requestResult;
};
Example #12
0
applier.stop = applier.shutdown = function () {
  var db = internal.db;

  var requestResult = db._connection.PUT("/_api/replication/applier-stop", "");
  arangosh.checkRequestResult(requestResult);

  return requestResult;
};
Example #13
0
Graph.prototype.drop = function () {
  var requestResult;

  requestResult = this._connection.DELETE("/_api/graph/"
    + encodeURIComponent(this._properties._key));

  arangosh.checkRequestResult(requestResult);
};
Example #14
0
exports.all = function () {
  var db = internal.db;

  var uri = "_api/user";

  var requestResult = db._connection.GET(uri);
  return arangosh.checkRequestResult(requestResult).result;
};
Example #15
0
exports.document = function (user) {
  var db = internal.db;

  var uri = "_api/user/" + encodeURIComponent(user);

  var requestResult = db._connection.GET(uri);
  return arangosh.checkRequestResult(requestResult);
};
Example #16
0
exports.remove = function (user) {
  var db = internal.db;

  var uri = "_api/user/" + encodeURIComponent(user);

  var requestResult = db._connection.DELETE(uri);
  arangosh.checkRequestResult(requestResult);
};
Example #17
0
exports.notifications.versions = function () {
  var db = internal.db;

  var uri = "_admin/configuration/notifications/versions";

  var requestResult = db._connection.GET(uri);
  return arangosh.checkRequestResult(requestResult);
};
Example #18
0
exports.notifications.setVersions = function (data) {
  var db = internal.db;

  var uri = "_admin/configuration/notifications/versions";

  var requestResult = db._connection.PUT(uri, JSON.stringify(data));
  return arangosh.checkRequestResult(requestResult);
};
Example #19
0
logger.firstTick = function () {
  var db = internal.db;

  var requestResult = db._connection.GET("/_api/replication/logger-first-tick");
  arangosh.checkRequestResult(requestResult);

  return requestResult.firstTick;
};
Example #20
0
logger.tickRanges = function () {
  var db = internal.db;

  var requestResult = db._connection.GET("/_api/replication/logger-tick-ranges");
  arangosh.checkRequestResult(requestResult);

  return requestResult;
};
Example #21
0
var serverId = function () {
  var db = internal.db;

  var requestResult = db._connection.GET("/_api/replication/server-id");

  arangosh.checkRequestResult(requestResult);

  return requestResult.serverId;
};
Example #22
0
ArangoDatabase.prototype._index = function (id) {
  if (id.hasOwnProperty("id")) {
    id = id.id;
  }

  var requestResult = this._connection.GET(this._indexurl(id));

  arangosh.checkRequestResult(requestResult);

  return requestResult;
};
Example #23
0
ArangoQueryCursor.prototype.dispose = function () {
  if (! this.data.id) {
    // client side only cursor
    return;
  }

  var requestResult = this._database._connection.DELETE(this._baseurl(), "");

  arangosh.checkRequestResult(requestResult);

  this.data.id = undefined;
};
Example #24
0
var getSyncResult = function (id) {
  var db = internal.db;

  var requestResult = db._connection.PUT_RAW("/_api/job/" + encodeURIComponent(id), "");
  arangosh.checkRequestResult(requestResult);

  if (requestResult.headers.hasOwnProperty("x-arango-async-id")) {
    return JSON.parse(requestResult.body);
  }

  return false;
};
Example #25
0
Graph.prototype.removeEdge = function (edge) {
  var requestResult;

  requestResult = this._connection.DELETE("/_api/graph/"
    + encodeURIComponent(this._properties._key)
    + "/edge/"
    + encodeURIComponent(edge._properties._key));

  arangosh.checkRequestResult(requestResult);

  edge._properties = undefined;
};
Example #26
0
Graph.prototype.removeVertex = function (vertex) {
  var requestResult;

  requestResult = this._connection.DELETE("/_api/graph/"
    + encodeURIComponent(this._properties._key)
    + "/vertex/"
    + encodeURIComponent(vertex._properties._key));

  arangosh.checkRequestResult(requestResult);

  vertex._properties = undefined;
};
Example #27
0
exports.replace = function (user, passwd, active, extra, changePassword) {
  var db = internal.db;

  var uri = "_api/user/" + encodeURIComponent(user);
  var data = {
    passwd: passwd,
    active: active,
    extra: extra,
    changePassword: changePassword
  };

  var requestResult = db._connection.PUT(uri, JSON.stringify(data));
  return arangosh.checkRequestResult(requestResult);
};
Example #28
0
ArangoDatabase.prototype._create = function (name, properties, type) {
  // document collection is the default type
  // but if the containing object has the _type attribute (it should!), then use it
  var body = {
    "name" : name,
    "type" : this._type || ArangoCollection.TYPE_DOCUMENT
  };

  if (properties !== undefined) {
    if (properties.hasOwnProperty("waitForSync")) {
      body.waitForSync = properties.waitForSync;
    }

    if (properties.hasOwnProperty("journalSize")) {
      body.journalSize = properties.journalSize;
    }

    if (properties.hasOwnProperty("isSystem")) {
      body.isSystem = properties.isSystem;
    }

    if (properties.hasOwnProperty("isVolatile")) {
      body.isVolatile = properties.isVolatile;
    }

    if (properties.hasOwnProperty("createOptions")) {
      body.createOptions = properties.createOptions;
    }
  }

  if (type !== undefined) {
    body.type = type;
  }

  var requestResult = this._connection.POST(this._collectionurl(),
    JSON.stringify(body));

  arangosh.checkRequestResult(requestResult);

  var nname = requestResult.name;

  if (nname !== undefined) {
    this._registerCollection(nname, new this._collectionConstructor(this, requestResult));
    return this[nname];
  }

  return undefined;
};
Example #29
0
applier.properties = function (config) {
  var db = internal.db;

  var requestResult;
  if (config === undefined) {
    requestResult = db._connection.GET("/_api/replication/applier-config");
  }
  else {
    requestResult = db._connection.PUT("/_api/replication/applier-config",
      JSON.stringify(config));
  }

  arangosh.checkRequestResult(requestResult);

  return requestResult;
};
Example #30
0
ArangoDatabase.prototype._dropIndex = function (id) {
  if (id.hasOwnProperty("id")) {
    id = id.id;
  }

  var requestResult = this._connection.DELETE(this._indexurl(id));

  if (requestResult !== null
      && requestResult.error === true 
      && requestResult.errorNum === internal.errors.ERROR_ARANGO_INDEX_NOT_FOUND.code) {
    return false;
  }

  arangosh.checkRequestResult(requestResult);

  return true;
};