<commit_before>'use strict';

var requestBuilders = require('./lib/requests');
var EventEmitter = require('events').EventEmitter;
var util = require('util');
var utils = require('./lib/utils');
var zookeeper = require('node-zookeeper-client');
var State = zookeeper.State;
//var slice = Array.prototype.slice;


/*!
 * Expose Rorschach
 */
module.exports = Rorschach;




/**
 * Create instance.
 *
 * @constructor
 * @extends {events.EventEmitter}
 * @param {String} connectionString ZooKeeper connection string.
 * @param {Object} [zkOptions] ZooKeeper client options.
 */
function Rorschach(connectionString, zkOptions) {
  EventEmitter.call(this);

  var self = this;
  var zk = zookeeper.createClient(connectionString, zkOptions || {});
  zk.on('state', handleStateChange);
  zk.connect();

  this.zk = zk;
  this.state = State.CONNECTING;

  function handleStateChange(state) {
    self.state = state;

    self.emit('connectionStateChanged', state);

    if (state === State.SYNC_CONNECTED) {
      self.emit('connected');
    }
  }
}
util.inherits(Rorschach, EventEmitter);




/**
 * Return Delete builder.
 *
 * @public
 * @returns {Object} Delete builder instance
 */
Rorschach.prototype.delete = function deleteBuilder() {
  return requestBuilders.delete(this);
};




/**
 * Close connection to ZooKeeper.
 *
 * @public
 * @param {Function} [callback] Callback function
 */
Rorschach.prototype.close = function close(callback) {
  if (typeof callback === 'function') {
    this.zk.on('disconnected', callback);
  }
  this.zk.close();
};




/**
 * Check if client is connected to ZK instance
 *
 * @public
 * @returns {Boolean}
 */
/*Rorschach.prototype.isConnected = function() {
  return this.zk.getState() === zookeeper.State.CONNECTED;
};*/




/**
 * Call ZooKeeper client method only when connected
 *
 * @private
 * @param {String} methodName ZooKeeper method name
 * @param {...*} args Method arguments
 */
/*Rorschach.prototype.whenConnected = function(methodName, args) {
  var zk = this.zk;
  args = slice.call(arguments, 1);

  if (this.isConnected()) {
    zk[methodName].apply(zk, args);
  }
  else {
    this.once('connected', onConnected);
  }

  function onConnected() {
    zk[methodName].apply(zk, args);
  }
};*/


Rorschach.Errors = require('./lib/errors');
Rorschach.Lock = require('./lib/Lock');
Rorschach.ReadWriteLock = require('./lib/ReadWriteLock');
Rorschach.LockDriver = require('./lib/LockDriver');<commit_msg>Add `create()` and modify `delete()` to use new builders<commit_after>'use strict';

var builders = require('./lib/builders');
var Errors = require('./lib/errors');
var EventEmitter = require('events').EventEmitter;
var Lock = require('./lib/Lock');
var LockDriver = require('./lib/LockDriver');
var ReadWriteLock = require('./lib/ReadWriteLock');
var util = require('util');
var utils = require('./lib/utils');
var zookeeper = require('node-zookeeper-client');
var State = zookeeper.State;


/*!
 * Expose Rorschach
 */
module.exports = Rorschach;




/**
 * Create instance.
 *
 * @constructor
 * @extends {events.EventEmitter}
 * @param {String} connectionString ZooKeeper connection string.
 * @param {Object} [zkOptions] ZooKeeper client options.
 */
function Rorschach(connectionString, zkOptions) {
  EventEmitter.call(this);

  var self = this;
  var zk = zookeeper.createClient(connectionString, zkOptions || {});
  zk.on('state', handleStateChange);
  zk.connect();

  this.zk = zk;
  this.state = State.CONNECTING;

  function handleStateChange(state) {
    self.state = state;

    self.emit('connectionStateChanged', state);

    if (state === State.SYNC_CONNECTED) {
      self.emit('connected');
    }
  }
}
util.inherits(Rorschach, EventEmitter);




/**
 * Close connection to ZooKeeper.
 *
 * @public
 * @param {Function} [callback] Callback function
 */
Rorschach.prototype.close = function close(callback) {
  if (typeof callback === 'function') {
    this.zk.on('disconnected', callback);
  }
  this.zk.close();
};



/**
 * Instantiate `CreateBuilder`.
 *
 * @public
 * @returns {CreateBuilder} Builder instance
 */
Rorschach.prototype.create = function createBuilder() {
  return new builders.CreateBuilder(this);
};




/**
 * Instantiate `DeleteBuilder`.
 *
 * @public
 * @returns {DeleteBuilder} Builder instance
 */
Rorschach.prototype.delete = function deleteBuilder() {
  return new builders.DeleteBuilder(this);
};


Rorschach.Errors = Errors;
Rorschach.Lock = Lock;
Rorschach.LockDriver = LockDriver;
Rorschach.ReadWriteLock = ReadWriteLock;
Rorschach.SortingLockDriver = ReadWriteLock.SortingLockDriver;
Rorschach.ReadLockDriver = ReadWriteLock.ReadLockDriver;
{'fraction_non_alphanumeric': 0.15242195909580195, 'fraction_numerical': 0.00021528525296017224, 'mean_word_length': 4.237880496054115, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '5943710', 'n_tokens_mistral': 1492, 'n_tokens_neox': 1437, 'n_words': 318}