<commit_before>/* -*- Mode: Javascript; js-indent-level: 2 -*- */

var async = require('async');
var naan = require('naan');
var _ = require('underscore');
var util = require('util');

module.exports = {
  /**
   * Create a new relationship between two nodes. Maps to 
   * POST node/<startNodeId>/relationship
   */
  create: function(startNode, type, endNode, properties, callback) {
    if (typeof properties === 'function') {
      callback = properties;
      properties = null;
    }

    if (Array.isArray(startNode)) {
      var args = [ type, endNode, properties ];
      var createRel = naan.ecurry(this.rel.create, args, [1, 2, 3]);
      return this.throttleMap(startNode, createRel, callback);
    } else if (Array.isArray(endNode)) {
      var args = [ startNode, type, properties ];
      var createRel = naan.ecurry(this.rel.create, args, [0, 1, 3]);
      return this.throttleMap(endNode, createRel, callback);
    }
    
    var startNodeId = this._getId(startNode),
        endNodeId = this._getId(endNode);

    if (startNodeId == null || endNodeId == null) {
      return callback(new Error("Invalid ID"));
    }

    var request = {
      to: this._location('node', endNodeId),
      type: type,
    };

    if (properties) {
      request['data'] = properties;
    }

    var endpoint = util.format('node/%d/relationships', startNodeId);
    var op = this.operation(endpoint, 'POST', request);
    this.call(op, function(err, rel) {
      if (err) {
        callback(err);
      } else {
        callback(null, this._createRelationshipObject(rel));
      }
    });
  },

  /**
   * Update the properties of a given relationship. Maps to
   * POST relationship/<id>/properties
   */
  update: function(rel, callback) {
    if (Array.isArray(rel)) {
      return this.throttleMap(rel, this.rel.update, callback);
    }

    var id = this._getId(rel);

    if (id == null) {
      return callback(new Error("Invalid ID"));
    }

    var endpoint = util.format('relationship/%d/properties', id);
    var op = this.operation(endpoint, 'PUT', rel.properties);
    this.call(op, function(err) {
      callback(err);
    });
  }, 

  read: function(id, callback) {
    if (Array.isArray(id)) {
      return this.throttleMap(id, this.rel.read, callback);
    }

    id = this._getId(id);

    if (id == null) {
      return callback(new Error("Invalid ID"));
    }

    var endpoint = util.format('relationship/%d', id);
    var op = this.operation(endpoint);
    this.call(op, function(err, rel) {
      if (err) {
        callback(err);
      } else {
        callback(null, this._createRelationshipObject(rel));
      }
    });
  }
};
<commit_msg>implemented rel.delete. closes #56<commit_after>/* -*- Mode: Javascript; js-indent-level: 2 -*- */

var async = require('async');
var naan = require('naan');
var _ = require('underscore');
var util = require('util');

module.exports = {
  /**
   * Create a new relationship between two nodes. Maps to 
   * POST node/<startNodeId>/relationship
   */
  create: function(startNode, type, endNode, properties, callback) {
    if (typeof properties === 'function') {
      callback = properties;
      properties = null;
    }

    if (Array.isArray(startNode)) {
      var args = [ type, endNode, properties ];
      var createRel = naan.ecurry(this.rel.create, args, [1, 2, 3]);
      return this.throttleMap(startNode, createRel, callback);
    } else if (Array.isArray(endNode)) {
      var args = [ startNode, type, properties ];
      var createRel = naan.ecurry(this.rel.create, args, [0, 1, 3]);
      return this.throttleMap(endNode, createRel, callback);
    }
    
    var startNodeId = this._getId(startNode),
        endNodeId = this._getId(endNode);

    if (startNodeId == null || endNodeId == null) {
      return callback(new Error("Invalid ID"));
    }

    var request = {
      to: this._location('node', endNodeId),
      type: type,
    };

    if (properties) {
      request['data'] = properties;
    }

    var endpoint = util.format('node/%d/relationships', startNodeId);
    var op = this.operation(endpoint, 'POST', request);
    this.call(op, function(err, rel) {
      if (err) {
        callback(err);
      } else {
        callback(null, this._createRelationshipObject(rel));
      }
    });
  },

  /**
   * Update the properties of a given relationship. Maps to
   * POST relationship/<id>/properties
   */
  update: function(rel, callback) {
    if (Array.isArray(rel)) {
      return this.throttleMap(rel, this.rel.update, callback);
    }

    var id = this._getId(rel);

    if (id == null) {
      return callback(new Error("Invalid ID"));
    }

    var endpoint = util.format('relationship/%d/properties', id);
    var op = this.operation(endpoint, 'PUT', rel.properties);
    this.call(op, function(err) {
      callback(err);
    });
  }, 

  read: function(id, callback) {
    if (Array.isArray(id)) {
      return this.throttleMap(id, this.rel.read, callback);
    }

    id = this._getId(id);

    if (id == null) {
      return callback(new Error("Invalid ID"));
    }

    var endpoint = util.format('relationship/%d', id);
    var op = this.operation(endpoint);
    this.call(op, function(err, rel) {
      if (err) {
        callback(err);
      } else {
        callback(null, this._createRelationshipObject(rel));
      }
    });
  },

  delete: function(id, callback) {
    if (Array.isArray(id)) {
      return this.throttleMap(id, this.rel.delete, callback);
    }

    id = this._getId(id);

    if (id == null) {
      return callback(new Error("Invalid ID"));
    }

    var endpoint = util.format('relationship/%d', id);
    var op = this.operation(endpoint, 'DELETE');
    this.call(op, function(err, rel) {
      callback(err);
    });
  }
};

{'fraction_non_alphanumeric': 0.15435310440513353, 'fraction_numerical': 0.002774887270204648, 'mean_word_length': 2.7278603749191985, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3175286', 'n_tokens_mistral': 1856, 'n_tokens_neox': 1800, 'n_words': 429}