<commit_before>var grpc = require('grpc');
var schema = require('protocol-buffers-schema');
var promise = require('bluebird');
var fs = require('fs')

var GrpcClient = function(config){
  if (typeof String.prototype.endsWith !== 'function') {
    String.prototype.endsWith = function(suffix) {
      return this.indexOf(suffix, this.length - suffix.length) !== -1;
    };
  }

  this.host = config.host || "";
  this.protodir = config.dir || "";
  this.header = config.header || {};
  this.currentCall = null;
  this.log = config.log || console;
  return this;
}

// parse proto file and create action;
GrpcClient.prototype.proto = function(protofile){
  var protoFilePath = "";
  if(this.protodir){
    if(this.protodir.endsWith("/")){
      protoFilePath = this.protodir + (protofile.endsWith(".proto")? protofile: protofile + ".proto");
    }else{
      protoFilePath = this.protodir + "/" + (protofile.endsWith(".proto")? protofile: protofile + ".proto");
    }
  }
  var sch = schema(fs.readFileSync(protoFilePath));
  var grpcLoadStr = "grpc.load(protoFilePath)." + sch.package;
  var ProtoClass = eval(grpcLoadStr);//grpc.load(protoFilePath)[sch.package];
  for (var i = 0; i < sch.service.services.length; i++) {
    (function(serviceFuncName){  
      GrpcClient.prototype[serviceFuncName] = GrpcClient.prototype[firstToLowerCase(serviceFuncName)] = promise.promisify(function(data,cb){
        var startTime = new Date();
          var client = new ProtoClass[sch.service.name](this.host);
          var newCb = function(cb){
            var endTime = new Date();
            var executeTime = endTime-startTime;
            var logInfo = {type:"grpc",path:protoFilePath,headers:this.header,params:data,executeTime:executeTime}
            this.log.info(logInfo);
            return cb;
          }.bind(this)
        client[firstToLowerCase(serviceFuncName)](data,newCb(cb),this.header);
      });
    }).call(this,sch.service.services[i])
  }
  return this;
}

GrpcClient.prototype.call = function(name){
  this.currentCall = name;
  return this;
}

GrpcClient.prototype.send = function(data){
  return this[this.currentCall](data);
}

GrpcClient.prototype.host = function(host){
  this.host = host;
  return this;
}

GrpcClient.prototype.dir = function(dir){
  this.protodir = dir;<commit_msg>injection log to cb<commit_after>var grpc = require('grpc');
var schema = require('protocol-buffers-schema');
var promise = require('bluebird');
var fs = require('fs')

var GrpcClient = function(config){
  if (typeof String.prototype.endsWith !== 'function') {
    String.prototype.endsWith = function(suffix) {
      return this.indexOf(suffix, this.length - suffix.length) !== -1;
    };
  }

  this.host = config.host || "";
  this.protodir = config.dir || "";
  this.header = config.header || {};
  this.currentCall = null;
  this.log = config.log || console;
  return this;
}

// parse proto file and create action;
GrpcClient.prototype.proto = function(protofile){
  var protoFilePath = "";
  if(this.protodir){
    if(this.protodir.endsWith("/")){
      protoFilePath = this.protodir + (protofile.endsWith(".proto")? protofile: protofile + ".proto");
    }else{
      protoFilePath = this.protodir + "/" + (protofile.endsWith(".proto")? protofile: protofile + ".proto");
    }
  }
  var sch = schema(fs.readFileSync(protoFilePath));
  var grpcLoadStr = "grpc.load(protoFilePath)." + sch.package;
  var ProtoClass = eval(grpcLoadStr);//grpc.load(protoFilePath)[sch.package];
  for (var i = 0; i < sch.service.services.length; i++) {
    (function(serviceFuncName){  
      GrpcClient.prototype[serviceFuncName] = GrpcClient.prototype[firstToLowerCase(serviceFuncName)] = promise.promisify(function(data,cb){
        var startTime = new Date();
          var client = new ProtoClass[sch.service.name](this.host);
          var injectionLogCb = function(err,result){
            var endTime = new Date();
            var executeTime = endTime-startTime;
            var logInfo = {type:"grpc",path:protoFilePath,headers:this.header,params:data,executeTime:executeTime}
            this.log.info(logInfo);
            return cb(err,result);
          }.bind(this);
        client[firstToLowerCase(serviceFuncName)](data,injectionLogCb,this.header);
      });
    }).call(this,sch.service.services[i])
  }
  return this;
}

GrpcClient.prototype.call = function(name){
  this.currentCall = name;
  return this;
}

GrpcClient.prototype.send = function(data){
  return this[this.currentCall](data);
}

GrpcClient.prototype.host = function(host){
  this.host = host;
  return this;
}

GrpcClient.prototype.dir = function(dir){
  this.protodir = dir;
{'fraction_non_alphanumeric': 0.15194498173221577, 'fraction_numerical': 0.0008596604341285192, 'mean_word_length': 3.682092555331992, 'pattern_counts': {'":': 0, '<': 5, '<?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': '6040689', 'n_tokens_mistral': 1466, 'n_tokens_neox': 1462, 'n_words': 270}