<commit_before>// Set the Wolfpack global variable
GLOBAL.WOLFPACK = {
  results: {},
  CRUD: {},
  operations: [],
  classResults:{}
};

var Waterline;

try {
  // Try loading waterline from sails first rather than from package
  Waterline = require(__dirname + '/../../sails/node_modules/waterline');
} catch (e) {
  // If it cannot be loaded, then load wolfpack's waterline
  Waterline = require('waterline');
}

var sinon = require('sinon'),
    path = require('path'),
    adapter = require(__dirname + '/wolfpack_adapter'),
    rs = require('random-strings'),
    _ = require('lodash');


function wolfpack(model_path, pk_type) {
  
  if (!model_path) {
    return methods();
  }

  if (pk_type && !_.contains(['integer', 'string'], pk_type)) {
    throw new Error('WOLFPACK: Currently wolfpack only supports strings and integers as default type for id');
  }

  if (!pk_type) {
    pk_type === 'integer';
  }

  var model;
  if ((model_path && typeof model_path !== 'object' && typeof model_path !== 'string') || (typeof model_path === 'object' && !model_path.attributes)) {
    throw new Error('WOLFPACK: Please provide a valid path or object');
  }
  
  var modelName;
  if (typeof model_path === 'string') {
    // Load the model
    try {
      model = require(path.join(process.cwd(), model_path));
    } catch (e) {
      try {
        model = require(model_path);
      } catch (e) {
        throw new Error('WOLFPACK: Cannot load model: ' + e.message);
      }
    }
    var splitPath =  model_path.split('/');
    modelName = splitPath[splitPath.length - 1];
  } else {
    model = model_path;
    modelName = rs.human(20);
  }

  // Spy on model class methods
  for (var idx in model) {
    if (typeof model[idx] === 'function') {
      model[idx] = sinon.spy(model[idx]);
    }
  }

  var pk = false;
  var attrKeys;
  // Spy on instance methods
  if (model.attributes) {
    for (idx in model.attributes) {
      if (typeof model.attributes[idx] === 'function') {
        model.attributes[idx] = sinon.spy(model.attributes[idx]);
      }
      // Check for associations and delete them
      if (_.isObject(model.attributes[idx])) {
        attrKeys = _.keys(model.attributes[idx]);
        if (attrKeys.indexOf('via') > -1 || attrKeys.indexOf('collection') > -1 || attrKeys.indexOf('model') > -1) {
          delete model.attributes[idx].via;
          delete model.attributes[idx].collection;
          delete model.attributes[idx].model;
          delete model.attributes[idx].dominant;
          model.attributes[idx].type = 'json';
        }
      }
    }
  }
  
  // Instantiate a new instance of the ORM
  waterline = new Waterline();

  var config = {
    adapters: {
      'default': adapter,
      'wolfpack': adapter
    },
    connections: {
      wolfpack: {
        adapter: 'wolfpack'
      }
    },
    defaults: {
      schema: false
    }
  };

  // Set the custom adapter and schemales
  model.connection = 'wolfpack';
  model.schema = false;
  model.identity = modelName;

  var Class = Waterline.Collection.extend(model);
  waterline.loadCollection(Class);
  
  var CollectionLoader = require('waterline/lib/waterline/collection/loader');
  var Connections = require('waterline/lib/waterline/connections');
  var Schema = require('waterline/node_modules/waterline-schema');
  <commit_msg>npm 3 compatibility - looking in base node_modules directory for npm dependencies<commit_after>// Set the Wolfpack global variable
GLOBAL.WOLFPACK = {
  results: {},
  CRUD: {},
  operations: [],
  classResults:{}
};

var Waterline;

try {
  // Try loading waterline from sails first rather than from package
  Waterline = require(__dirname + '/../../sails/node_modules/waterline');
} catch (e) {
  try {
    // Try loading waterline from node_modules directly (if on npm 3> dependencies are install in top level node_modules)
    Waterline = require(__dirname + '/../../waterline');
  } catch {
    // If it cannot be loaded, then load wolfpack's waterline
    Waterline = require('waterline');
  }
}

var sinon = require('sinon'),
    path = require('path'),
    adapter = require(__dirname + '/wolfpack_adapter'),
    rs = require('random-strings'),
    _ = require('lodash');


function wolfpack(model_path, pk_type) {
  
  if (!model_path) {
    return methods();
  }

  if (pk_type && !_.contains(['integer', 'string'], pk_type)) {
    throw new Error('WOLFPACK: Currently wolfpack only supports strings and integers as default type for id');
  }

  if (!pk_type) {
    pk_type === 'integer';
  }

  var model;
  if ((model_path && typeof model_path !== 'object' && typeof model_path !== 'string') || (typeof model_path === 'object' && !model_path.attributes)) {
    throw new Error('WOLFPACK: Please provide a valid path or object');
  }
  
  var modelName;
  if (typeof model_path === 'string') {
    // Load the model
    try {
      model = require(path.join(process.cwd(), model_path));
    } catch (e) {
      try {
        model = require(model_path);
      } catch (e) {
        throw new Error('WOLFPACK: Cannot load model: ' + e.message);
      }
    }
    var splitPath =  model_path.split('/');
    modelName = splitPath[splitPath.length - 1];
  } else {
    model = model_path;
    modelName = rs.human(20);
  }

  // Spy on model class methods
  for (var idx in model) {
    if (typeof model[idx] === 'function') {
      model[idx] = sinon.spy(model[idx]);
    }
  }

  var pk = false;
  var attrKeys;
  // Spy on instance methods
  if (model.attributes) {
    for (idx in model.attributes) {
      if (typeof model.attributes[idx] === 'function') {
        model.attributes[idx] = sinon.spy(model.attributes[idx]);
      }
      // Check for associations and delete them
      if (_.isObject(model.attributes[idx])) {
        attrKeys = _.keys(model.attributes[idx]);
        if (attrKeys.indexOf('via') > -1 || attrKeys.indexOf('collection') > -1 || attrKeys.indexOf('model') > -1) {
          delete model.attributes[idx].via;
          delete model.attributes[idx].collection;
          delete model.attributes[idx].model;
          delete model.attributes[idx].dominant;
          model.attributes[idx].type = 'json';
        }
      }
    }
  }
  
  // Instantiate a new instance of the ORM
  waterline = new Waterline();

  var config = {
    adapters: {
      'default': adapter,
      'wolfpack': adapter
    },
    connections: {
      wolfpack: {
        adapter: 'wolfpack'
      }
    },
    defaults: {
      schema: false
    }
  };

  // Set the custom adapter and schemales
  model.connection = 'wolfpack';
  model.schema = false;
  model.identity = modelName;

  var Class = Waterline.Collection.extend(model);
  waterline.loadCollection(Class);
  
  var CollectionLoader = require('waterline/lib/waterline/collection/loader');
  var Connections = require('waterline/lib/waterline/connections');
  var Schema = null;
  try {
    Schema = require('waterline/node_modules/waterline-schema');
  } catch {
    // Try loading waterline from node_modules directly (if on npm 3> dependencies are install in top level node_modules)
    Schema = require('waterline-schema/lib/waterline-schema');
  }
  
{'fraction_non_alphanumeric': 0.13982399776505097, 'fraction_numerical': 0.002095264701773991, 'mean_word_length': 2.8640043173232597, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 11, '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': '58168', 'n_tokens_mistral': 2229, 'n_tokens_neox': 2171, 'n_words': 573}