<commit_before>var _ = require('lodash');
var Waterline = require('waterline');

function createModel (schema, name, doc, connection) {
  return schema.type === 'object' && {
    dynamicFinders: false,
    associationFinders: false,
    identity: name.toLowerCase(),
    globalId: name,
    connection: connection,
    attributes: createAttributes(schema, doc)
  };
}

function createAttributes (schema, doc) {

  return _.mapValues(schema.properties, function (property, name) {
    var ref = property.$ref || (property.items && property.items.$ref) || '';

    return _.compact({
      type: getType(property),
      notNull: !!property.required,
      model: property.$ref,
      collection: property.items ? property.items.$ref : undefined,
      via: ref.split('/')[1] || undefined
    });
  });
}

function getType (property) {
  if (_.contains([ 'object', 'array' ], (property.type || '').toLowerCase())) {
    return undefined;
  }
  else {
    return property.type;
  }
}

/**
 * Return a list of Waterline collection objects that can be passed into
 * waterline.loadCollections
 * 
 * @param doc - a google discovery doc (restDescription)
 */
exports.createCollections = function (doc, connection) {
  return _.compact(
    _.map(doc.schemas, function (schema, name) {
      var model = createModel(schema, name, doc, connection || 'sailsDiscovery');
      if (_.isObject(model)) {
        return Waterline.Collection.extend(model);
      }
      else {
        console.log('adsdadsadasdsadas');
        return;
      }
    })
  );<commit_msg>build orm from resources instead of schemas<commit_after>var _ = require('lodash');
var Waterline = require('waterline');

function createModel (schema, name, doc, connection) {
  return schema.type === 'object' && {
    dynamicFinders: false,
    associationFinders: false,
    identity: name.toLowerCase(),
    globalId: name,
    connection: connection,
    attributes: createAttributes(schema, doc)
  };
}

function createAttributes (schema, doc) {

  return _.mapValues(schema.properties, function (property, name) {
    var ref = property.$ref || (property.items && property.items.$ref) || '';

    return _.compact({
      type: getType(property),
      notNull: !!property.required,
      model: property.$ref,
      collection: property.items ? property.items.$ref : undefined,
      via: ref.split('/')[1] || undefined
    });
  });
}

function getType (property) {
  if (_.contains([ 'object', 'array' ], (property.type || '').toLowerCase())) {
    return undefined;
  }
  else {
    return property.type;
  }
}

/**
 * Return a list of Waterline collection objects that can be passed into
 * waterline.loadCollections
 * 
 * @param doc - a google discovery doc (restDescription)
 */
exports.createCollections = function (doc, _connection) {
  var connection = _connection || 'sailsDiscovery';

  return _.compact(
    _.map(doc.resources, function (resource, name) {
      var schema = doc.shemas[name];
      var model = createModel(schema, name, doc, connection);
      return Waterline.Collection.extend(model);
    })
  );
{'fraction_non_alphanumeric': 0.14073115496603042, 'fraction_numerical': 0.0006470397929472663, 'mean_word_length': 3.4553314121037464, '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': '5776006', 'n_tokens_mistral': 888, 'n_tokens_neox': 884, 'n_words': 235}