<commit_before>'use strict';

var Request = require('kuzzle-common-objects').Request;

/**
 * Manage communication with the load balancer
 *
 * @param {Kuzzle} kuzzle
 * @constructor
 */
function KuzzleProxy (kuzzle) {
  this.kuzzle = kuzzle;
  this.channels = {};

  return this;
}

KuzzleProxy.prototype.init = function kuzzleProxyInit () {
  this.kuzzle.services.list.proxyBroker.listen('request', onRequest.bind(this));
  this.kuzzle.services.list.proxyBroker.listen('connection', onConnection.bind(this));
  this.kuzzle.services.list.proxyBroker.listen('disconnect', onDisconnect.bind(this));
  this.kuzzle.services.list.proxyBroker.listen('error', onDisconnect.bind(this));
  this.kuzzle.services.list.proxyBroker.listen('httpRequest', onHttpRequest.bind(this));
};

KuzzleProxy.prototype.joinChannel = function kuzzleProxyJoinChannel (data) {
  this.kuzzle.services.list.proxyBroker.send('joinChannel', data);
};

KuzzleProxy.prototype.leaveChannel = function kuzzleProxyLeaveChannel (data) {
  this.kuzzle.services.list.proxyBroker.send('leaveChannel', data);
};

KuzzleProxy.prototype.dispatch = function kuzzleProxyDispatch (event, data) {
  this.kuzzle.services.list.proxyBroker.send(event, data);
};

/**
 * @this {KuzzleProxy}
 * @param {object} data
 */
function onRequest (data) {
  var request = new Request(data.request, data.options);

  this.kuzzle.funnel.execute(request, (error, result) => {
    this.kuzzle.services.list.proxyBroker.send('response', result.serialize());
  });
}

/**
 * @this {KuzzleProxy}
 * @param {RequestContext} data
 */
function onConnection (data) {
  this.kuzzle.router.newConnection(data);
}

/**
 * @this {KuzzleProxy}
 * @param {RequestContext} data
 */
function onDisconnect (data) {
  this.kuzzle.router.removeConnection(data);
}
<commit_msg>returns a Request.response object to proxy's requests<commit_after>'use strict';

var Request = require('kuzzle-common-objects').Request;

/**
 * Manage communication with the load balancer
 *
 * @param {Kuzzle} kuzzle
 * @constructor
 */
function KuzzleProxy (kuzzle) {
  this.kuzzle = kuzzle;
  this.channels = {};

  return this;
}

KuzzleProxy.prototype.init = function kuzzleProxyInit () {
  this.kuzzle.services.list.proxyBroker.listen('request', onRequest.bind(this));
  this.kuzzle.services.list.proxyBroker.listen('connection', onConnection.bind(this));
  this.kuzzle.services.list.proxyBroker.listen('disconnect', onDisconnect.bind(this));
  this.kuzzle.services.list.proxyBroker.listen('error', onDisconnect.bind(this));
  this.kuzzle.services.list.proxyBroker.listen('httpRequest', onHttpRequest.bind(this));
};

KuzzleProxy.prototype.joinChannel = function kuzzleProxyJoinChannel (data) {
  this.kuzzle.services.list.proxyBroker.send('joinChannel', data);
};

KuzzleProxy.prototype.leaveChannel = function kuzzleProxyLeaveChannel (data) {
  this.kuzzle.services.list.proxyBroker.send('leaveChannel', data);
};

KuzzleProxy.prototype.dispatch = function kuzzleProxyDispatch (event, data) {
  this.kuzzle.services.list.proxyBroker.send(event, data);
};

/**
 * @this {KuzzleProxy}
 * @param {object} data
 */
function onRequest (data) {
  var request = new Request(data.request, data.options);

  this.kuzzle.funnel.execute(request, (error, result) => {
    this.kuzzle.services.list.proxyBroker.send('response', result.response);
  });
}

/**
 * @this {KuzzleProxy}
 * @param {RequestContext} data
 */
function onConnection (data) {
  this.kuzzle.router.newConnection(data);
}

/**
 * @this {KuzzleProxy}
 * @param {RequestContext} data
 */
function onDisconnect (data) {
  this.kuzzle.router.removeConnection(data);
}

{'fraction_non_alphanumeric': 0.15062068965517242, 'fraction_numerical': 0.0, 'mean_word_length': 5.339160839160839, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, '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': '6801339', 'n_tokens_mistral': 1217, 'n_tokens_neox': 1167, 'n_words': 188}