<commit_before>/**
 * Created by Johan on 4/14/2015.
 */

var API = require('./api');
var happn = require('@smc/happn');
var happnServer = happn.service;
var dataLayer;
var happn_client = happn.client;
var async = require('async');
var MeshError = require('./error');
var Utilities = require('./utilities');
var ComponentInstance = require('./componentInstance');
var path = require("path");
// var Messenger = require('./messenger');

module.exports = function () {
  return new Mesh();
}

function Mesh() {

  var _this = this;

  //the system is the 'global' variable passed around to all component instances for use
  
  _this.api = {};
  
  _this._initializeDataLayer = function(config, callback){
    try{

      if (!config.dataLayer) config.dataLayer = {};
      if (!config.dataLayer.authTokenSecret) config.dataLayer.authTokenSecret = '<KEY>';
      if (!config.dataLayer.systemSecret) config.dataLayer.systemSecret = 'mesh';
      if (!config.dataLayer.log_level) config.dataLayer.log_level = 'info|error|warning';
      if (!config.dataLayer.setOptions) config.dataLayer.setOptions = {noStore:true};

      happnServer.initialize({
          port: config.dataLayer.port?config.dataLayer.port:8000,
          host: config.dataLayer.host?config.dataLayer.host:"localhost",
          mode:'embedded', 
          services:{
            auth:{
              path:'./services/auth/service.js',
              config:{
                authTokenSecret:config.dataLayer.authTokenSecret,
                systemSecret:config.dataLayer.systemSecret
              }
            },
            data:{
              path:'./services/data_embedded/service.js'
            },
            pubsub:{
              path:'./services/pubsub/service.js'
            }
          },
          utils:{
            log_level:config.dataLayer.log_level
          }
        }, 
        function(e, happnInstance){

          if (e)
            return callback(e);

          //so now all components can talk to the data layer
          new happn.client({plugin:happn.client_plugins.intra_process, context:happnInstance}, function(e, client){
            if (e) return callback(e);
            _this.api.data = client;
            callback();
          });

        });
    }catch(e){
      callback(new Error(e));
    }
  }

  _this._initializeModules = function(config, callback){
    _this.modules = {};
    _this.modulePaths = {};

    var moduleManager = require('module');

    async.eachSeries(Object.keys(config), function(moduleName, eachCallback) {

        _this.modules[moduleName] = {};
        var moduleConfig = config[moduleName];
        var moduleBase;
        
        _this.modules[moduleName].config = config[moduleName];

        try {

          var modulePath = moduleConfig.path;
          if (moduleConfig.path.indexOf('system:') == 0){
            var pathParts = moduleConfig.path.split(':');
            modulePath = __dirname + '/components/' + pathParts[1];
          }
          moduleBase = require(modulePath);

          _this.modules[moduleName].directory = path.dirname(require.resolve(modulePath));

        } catch (e) {
          return eachCallback(new Error(e));
        }
        var constructorCallBack;

        if (moduleConfig.constructor){

          if (moduleConfig.constructor.name)
            moduleBase = moduleBase[moduleConfig.constructor.name];

          if (!moduleConfig.constructor.parameters)
            moduleConfig.constructor.parameters = [];

          var callParameters = [moduleConfig.constructor.parameters.length];
          var callbackIndex = -1;
<commit_msg>default module path to module name<commit_after>/**
 * Created by Johan on 4/14/2015.
 */

var API = require('./api');
var happn = require('@smc/happn');
var happnServer = happn.service;
var dataLayer;
var happn_client = happn.client;
var async = require('async');
var MeshError = require('./error');
var Utilities = require('./utilities');
var ComponentInstance = require('./componentInstance');
var path = require("path");
// var Messenger = require('./messenger');

module.exports = function () {
  return new Mesh();
}

function Mesh() {

  var _this = this;

  //the system is the 'global' variable passed around to all component instances for use
  
  _this.api = {};
  
  _this._initializeDataLayer = function(config, callback){
    try{

      if (!config.dataLayer) config.dataLayer = {};
      if (!config.dataLayer.authTokenSecret) config.dataLayer.authTokenSecret = '<KEY>';
      if (!config.dataLayer.systemSecret) config.dataLayer.systemSecret = 'mesh';
      if (!config.dataLayer.log_level) config.dataLayer.log_level = 'info|error|warning';
      if (!config.dataLayer.setOptions) config.dataLayer.setOptions = {noStore:true};

      happnServer.initialize({
          port: config.dataLayer.port?config.dataLayer.port:8000,
          host: config.dataLayer.host?config.dataLayer.host:"localhost",
          mode:'embedded', 
          services:{
            auth:{
              path:'./services/auth/service.js',
              config:{
                authTokenSecret:config.dataLayer.authTokenSecret,
                systemSecret:config.dataLayer.systemSecret
              }
            },
            data:{
              path:'./services/data_embedded/service.js'
            },
            pubsub:{
              path:'./services/pubsub/service.js'
            }
          },
          utils:{
            log_level:config.dataLayer.log_level
          }
        }, 
        function(e, happnInstance){

          if (e)
            return callback(e);

          //so now all components can talk to the data layer
          new happn.client({plugin:happn.client_plugins.intra_process, context:happnInstance}, function(e, client){
            if (e) return callback(e);
            _this.api.data = client;
            callback();
          });

        });
    }catch(e){
      callback(new Error(e));
    }
  }

  _this._initializeModules = function(config, callback){
    _this.modules = {};
    _this.modulePaths = {};

    var moduleManager = require('module');

    async.eachSeries(Object.keys(config), function(moduleName, eachCallback) {

        _this.modules[moduleName] = {};
        var moduleConfig = config[moduleName];
        var moduleBase;

        if (!moduleConfig.path) moduleConfig.path = moduleName;

        _this.modules[moduleName].config = config[moduleName];

        try {

          var modulePath = moduleConfig.path;
          if (moduleConfig.path.indexOf('system:') == 0){
            var pathParts = moduleConfig.path.split(':');
            modulePath = __dirname + '/components/' + pathParts[1];
          }
          moduleBase = require(modulePath);

          _this.modules[moduleName].directory = path.dirname(require.resolve(modulePath));

        } catch (e) {
          return eachCallback(new Error(e));
        }
        var constructorCallBack;

        if (moduleConfig.constructor){

          if (moduleConfig.constructor.name)
            moduleBase = moduleBase[moduleConfig.constructor.name];

          if (!moduleConfig.constructor.parameters)
            moduleConfig.constructor.parameters = [];

          var callParameters = [moduleConfig.constructor.parameters.length];
          var callbackIndex = -1;

{'fraction_non_alphanumeric': 0.12582146768893757, 'fraction_numerical': 0.0038335158817086527, 'mean_word_length': 2.335616438356164, 'pattern_counts': {'":': 0, '<': 5, '<?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': '67022', 'n_tokens_mistral': 2023, 'n_tokens_neox': 1950, 'n_words': 397}