<commit_before>'use strict';

const _ = require('lodash');
const chassis = require('./../../../../');

/**
 * Name of the transport
 *
 * @const
 */
const NAME = 'pipe';

const servers = {};

class Server {
  constructor(config, logger) {
    this.name = NAME;
    this.$config = config;
    this.$logger = logger;
    this.service = {};
    this.addr = config.addr;
  }
  *bind(name, service) {
    this.stupid = 'stupid';
    const logger = this.$logger;
    if (_.isNil(name)) {
      throw new Error('missing argument name');
    }
    if (!_.isString(name)) {
      throw new Error('argument name is not of type string');
    }
    if (_.isNil(service)) {
      throw new Error('missing argument service');
    }
    this.service[name] = service;
    logger.verbose(`service ${name} bound to transport ${this.name}`, _.functions(service));
  }
  *start() {
    if (!_.isNil(servers[this.addr])) {
      throw new Error(`address ${this.addr} in use`);
    }
    _.set(servers, this.addr, this);
    this.$logger.verbose(`transport ${this.name} is serving`);
  }
  *end() {
    _.unset(servers, this.addr);
  }
}

class Client {
  constructor(config, logger) {
    // check config
    if (!_.has(config, 'service')) {
      throw new Error('client is missing service config field');
    }

    this.name = NAME;
    this.$config = config;
    this.$logger = logger;
    this.connected = true;
  }

  *makeEndpoint(methodName, instance) {
    const logger = this.$logger;
    logger.debug('pipe.makeEndpoint', methodName, instance);
    const server = _.get(servers, instance);
    if (_.isNil(server)) {
      throw new Error(`server with ${instance} address does not exist`);
    }
    const service = server.service[this.$config.service];
    if (_.isNil(service)) {
      throw new Error(`server does not have service ${this.$config.service}`);
    }
    const method = service[methodName];
    /* eslint consistent-this: ["error", "that"]*/
    const that = this;
    return function* pipe(request, context) {
      if (_.isNil(method)) {
        return {
          error: new Error('unimplemented'),
        };
      }

      if (!that.connected) {
        return {
          error: new Error('unreachable'),
        };
      }
      const serverContext = {
        transport: 'pipe',
        logger: that.$logger,
      };
      const call = {
        request,
      };
      try {
        const response = yield method(call, serverContext);
        logger.debug(`response from ${that.$config.service}.${methodName}`, response);
        return {<commit_msg>Ensure defined request with provider pipe<commit_after>'use strict';

const _ = require('lodash');
const chassis = require('./../../../../');

/**
 * Name of the transport
 *
 * @const
 */
const NAME = 'pipe';

const servers = {};

class Server {
  constructor(config, logger) {
    this.name = NAME;
    this.$config = config;
    this.$logger = logger;
    this.service = {};
    this.addr = config.addr;
  }
  *bind(name, service) {
    this.stupid = 'stupid';
    const logger = this.$logger;
    if (_.isNil(name)) {
      throw new Error('missing argument name');
    }
    if (!_.isString(name)) {
      throw new Error('argument name is not of type string');
    }
    if (_.isNil(service)) {
      throw new Error('missing argument service');
    }
    this.service[name] = service;
    logger.verbose(`service ${name} bound to transport ${this.name}`, _.functions(service));
  }
  *start() {
    if (!_.isNil(servers[this.addr])) {
      throw new Error(`address ${this.addr} in use`);
    }
    _.set(servers, this.addr, this);
    this.$logger.verbose(`transport ${this.name} is serving`);
  }
  *end() {
    _.unset(servers, this.addr);
  }
}

class Client {
  constructor(config, logger) {
    // check config
    if (!_.has(config, 'service')) {
      throw new Error('client is missing service config field');
    }

    this.name = NAME;
    this.$config = config;
    this.$logger = logger;
    this.connected = true;
  }

  *makeEndpoint(methodName, instance) {
    const logger = this.$logger;
    logger.debug('pipe.makeEndpoint', methodName, instance);
    const server = _.get(servers, instance);
    if (_.isNil(server)) {
      throw new Error(`server with ${instance} address does not exist`);
    }
    const service = server.service[this.$config.service];
    if (_.isNil(service)) {
      throw new Error(`server does not have service ${this.$config.service}`);
    }
    const method = service[methodName];
    /* eslint consistent-this: ["error", "that"]*/
    const that = this;
    return function* pipe(request, context) {
      if (_.isNil(method)) {
        return {
          error: new Error('unimplemented'),
        };
      }

      if (!that.connected) {
        return {
          error: new Error('unreachable'),
        };
      }
      const serverContext = {
        transport: 'pipe',
        logger: that.$logger,
      };
      const call = {
        request: request || {},
      };
      try {
        const response = yield method(call, serverContext);
        logger.debug(`response from ${that.$config.service}.${methodName}`, response);
        return {
{'fraction_non_alphanumeric': 0.15710144927536232, 'fraction_numerical': 0.0, 'mean_word_length': 2.5331058020477815, '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': '2998584', 'n_tokens_mistral': 1538, 'n_tokens_neox': 1536, 'n_words': 400}