<commit_before>
"use strict";

var SuperJS = require('../../index');

/**
 * The base model class is the basic building block for models in database engines.
 * They come bottled with methods to validate and sanitize attributes.
 *
 * @exports Model
 * @namespace SuperJS
 * @extends SuperJS.Class
 */

module.exports = SuperJS.Class.extend({

  init: function (app) {

    //maintain a reference to the app
    this.app = app;
  },

  validate: function(req) {

    /*

    //maintain reference to the instance
    var self = this;

    //return promise
    return new Promise(function(resolve, reject) {

      var validations = [];

      //loop through all the parameters for this action
      for( var attribute in self.attributes ) {

        //loop through transforms for each parameter
        for( var validation in self.blueprint.actions[req.action].params[param].validate ) {

          self.app.log.debug('executing "' + validation + '" validation on:',param);

          var validation = self.app.services.validate[validate];
          var options = self.blueprint.actions[req.action].params[param].validate[validation];
          var value = req.params(param);

          //todo: load the blueprints for services
          //var rule = self.app.services.validate.blueprint[validate].rule;

          //execute transform & reject on error)
          validations.push(function() {
            return new Promise(function(resolve,reject) {
              if( validation.apply(null, value, options) ) {
                resolve();
              } else {
                reject(new SuperJS.Error('validation_error', 422, 'A validation error occured.'));
              }
            });
          });

        }
      }

      Promise.all(validations)
        .then(function(){
          resolve();
        })
        .catch(function(err) {
          reject();
        });
    });
    */

  },

  sanitize: function(req) {

  }

});
<commit_msg>Updated base model to process the configuration and prune any incorrect validations or sanitizations.<commit_after>
"use strict";

var SuperJS = require('../../index');

/**
 * The base model class is the basic building block for models in database engines.
 * They come bottled with methods to validate and sanitize attributes.
 *
 * @exports Model
 * @namespace SuperJS
 * @extends SuperJS.Class
 */

module.exports = SuperJS.Class.extend({

  init: function (app) {

    //maintain a reference to the app
    this.app = app;

    //maintain a reference to the log engine
    this.log = app.log;

    //check the configuration for issues
    this.processConfiguration();
  },

  processConfiguration: function() {

    if( this.attributes ) {

      for( var attribute in this.attributes ) {

        if( !this.attributes[attribute].validate ) {
          this.attributes[attribute].validate = {};
        }

        if( !this.attributes[attribute].sanitize ) {
          this.attributes[attribute].sanitize = {};
        }

        if( this.attributes[attribute].type ) {
          this.attributes[attribute].validate[this.attributes[attribute].type] = true;
        }

        //warn & remove any missing validations
        for( var validation in this.attributes[attribute].validate ) {
          if( !this.app.services.validate[validation] ) {
            this.log.warn('validation missing:',validation);
            delete this.attributes[attribute].validate[validation];
          }
        }

        //warn & remove any missing sanitizations
        for( var sanitization in this.attributes[attribute].sanitize ) {
          if( !this.app.services.sanitize[sanitization] ) {
            this.log.warn('sanitization missing:',sanitization);
            delete this.attributes[attribute].sanitize[sanitization];
          }
        }

      }

    } else {

      this.log.warn('model missing attributes object...');

    }

  },

  validate: function(req) {
  },

  sanitize: function(req) {
  }

});

{'fraction_non_alphanumeric': 0.11890936632163596, 'fraction_numerical': 0.0007573844988639232, 'mean_word_length': 2.287966804979253, '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': '4514728', 'n_tokens_mistral': 1079, 'n_tokens_neox': 1035, 'n_words': 279}