<commit_before>var util = require(__dirname+'/../util.js');
var schema =      require(__dirname+'/../schema.js');
var arrayPrefix = schema.arrayPrefix;

function TypeArray() {
  this._min = -1;
  this._max = -1;
  this._length = -1;
  this._schema = undefined;
  this._validator = undefined;
}


TypeArray.prototype.options = function(options) {
  this._options = options;
  return this;
}


TypeArray.prototype.min = function(min) {
  if (min < 0) {
    throw new Error("The value for `min` must be a positive integer");
  }
  this._min = min;
  return this;
}


TypeArray.prototype.max = function(max) {
  if (max < 0) {
    throw new Error("The value for `max` must be a positive integer");
  }
  this._max = max;
  return this;
}


TypeArray.prototype.length = function(length) {
  if (length < 0) {
    throw new Error("The value for `length` must be a positive integer");
  }
  this._length = length;
  return this;
}


TypeArray.prototype.schema = function(schema) {
  this._schema = schema;
  return this;
}


TypeArray.prototype.default = function(fnOrValue) {
  this._default = fnOrValue;
  return this;
}


TypeArray.prototype.validator = function(fn) {
  this._validator = fn;
  return this;
}


TypeArray.prototype.validate = function(array, prefix, options) {
  var self = this;
  options = util.mergeOptions(this._options, options);

  if (util.validateIfUndefined(array, prefix, "array", options)) return;

  if ((typeof self._validator === "function") && (self._validator(array) === false)) {
    throw new Error("Validator for the field "+prefix+" returned `false`.");
  }

  if (Array.isArray(array) === false) {
    if (options.enforce_type === "strict") {
      util.strictType(prefix, "array");
    }
    else if ((options.enforce_type === "loose") && (array !== null)) {
      util.looseType(prefix, "array");
    }
  }
  else {
    if ((this._min !== -1) && (this._min > array.length)){
      throw new Error("Value for "+prefix+" must have at least "+this._min+" elements.") 
    }
    if ((this._max !== -1) && (this._max < array.length)){
      throw new Error("Value for "+prefix+" must have at most "+this._max+" elements.") 
    }
    if ((this._length !== -1) && (this._length !== array.length)){
      throw new Error("Value for "+prefix+" must be an array with "+this._length+" elements.") 
    }<commit_msg>Do not validate reql terms in partial update of array<commit_after>var util = require(__dirname+'/../util.js');
var schema =      require(__dirname+'/../schema.js');
var arrayPrefix = schema.arrayPrefix;

function TypeArray() {
  this._min = -1;
  this._max = -1;
  this._length = -1;
  this._schema = undefined;
  this._validator = undefined;
}


TypeArray.prototype.options = function(options) {
  this._options = options;
  return this;
}


TypeArray.prototype.min = function(min) {
  if (min < 0) {
    throw new Error("The value for `min` must be a positive integer");
  }
  this._min = min;
  return this;
}


TypeArray.prototype.max = function(max) {
  if (max < 0) {
    throw new Error("The value for `max` must be a positive integer");
  }
  this._max = max;
  return this;
}


TypeArray.prototype.length = function(length) {
  if (length < 0) {
    throw new Error("The value for `length` must be a positive integer");
  }
  this._length = length;
  return this;
}


TypeArray.prototype.schema = function(schema) {
  this._schema = schema;
  return this;
}


TypeArray.prototype.default = function(fnOrValue) {
  this._default = fnOrValue;
  return this;
}


TypeArray.prototype.validator = function(fn) {
  this._validator = fn;
  return this;
}


TypeArray.prototype.validate = function(array, prefix, options) {
  var self = this;
  options = util.mergeOptions(this._options, options);

  if (util.validateIfUndefined(array, prefix, "array", options)) return;

  if ((typeof self._validator === "function") && (self._validator(array) === false)) {
    throw new Error("Validator for the field "+prefix+" returned `false`.");
  }

  if ((typeof array === 'function') && (array._query !== undefined)) {
    // We do not check ReQL terms
  }
  else if (Array.isArray(array) === false) {
    if (options.enforce_type === "strict") {
      util.strictType(prefix, "array");
    }
    else if ((options.enforce_type === "loose") && (array !== null)) {
      util.looseType(prefix, "array");
    }
  }
  else {
    if ((this._min !== -1) && (this._min > array.length)){
      throw new Error("Value for "+prefix+" must have at least "+this._min+" elements.") 
    }
    if ((this._max !== -1) && (this._max < array.length)){
      throw new Error("Value for "+prefix+" must have at most "+this._max+" elements.") 
    }
    if ((this._length !== -1) && (this._length !== array.length)){
      throw new Error("Value for "+prefix+" must be an array with "+this._length+" elements.") 
    }
{'fraction_non_alphanumeric': 0.16108354011579817, 'fraction_numerical': 0.0037220843672456576, 'mean_word_length': 3.381340579710145, 'pattern_counts': {'":': 0, '<': 11, '<?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': '5854934', 'n_tokens_mistral': 1540, 'n_tokens_neox': 1516, 'n_words': 426}