<commit_before>import deepExtend from 'deep-extend';
import MongoObject from 'mongo-object';
import _ from 'underscore';
import MessageBox from 'message-box';
import humanize from './humanize.js';
import ValidationContext from './ValidationContext';
import SimpleSchemaGroup from './SimpleSchemaGroup';
import regExpObj from './regExp';
import clean from './clean';
import expandShorthand from './expandShorthand';
import { forEachKeyAncestor } from './utility';
import defaultMessages from './defaultMessages';

// Exported for tests
export const schemaDefinitionOptions = [
  'type',
  'label',
  'optional',
  'required',
  'autoValue',
  'defaultValue',
];

const oneOfProps = [
  'type',
  'min',
  'max',
  'minCount',
  'maxCount',
  'allowedValues',
  'exclusiveMin',
  'exclusiveMax',
  'regEx',
  'custom',
  'blackbox',
  'trim',
];

const propsThatCanBeFunction = [
  'label',
  'optional',
  'min',
  'max',
  'minCount',
  'maxCount',
  'allowedValues',
  'exclusiveMin',
  'exclusiveMax',
  'regEx',
];

class SimpleSchema {
  constructor(schema = {}, options = {}) {
    // Stash the options object
    this._constructorOptions = { ...options };
    if (this._constructorOptions.humanizeAutoLabels !== false) this._constructorOptions.humanizeAutoLabels = true;

    // Custom validators for this instance
    this._validators = [];
    this._docValidators = [];

    // Named validation contexts
    this._validationContexts = {};

    // Clone, expanding shorthand, and store the schema object in this._schema
    this._schema = {};
    this.extend(schema);

    // Define default validation error messages
    this.messageBox = new MessageBox(defaultMessages);

    // Schema-level defaults for cleaning
    this._cleanOptions = {
      filter: true,
      autoConvert: true,
      removeEmptyStrings: true,
      trimStrings: true,
      getAutoValues: true,
      removeNullsFromArrays: false,
      extendAutoValueContext: {},
      ...options.clean,
    };

    this.version = SimpleSchema.version;
  }

  findFirstAncestorSimpleSchema(key, func) {
    const genericKey = MongoObject.makeKeyGeneric(key);

    let foundSchema = false;
    forEachKeyAncestor(genericKey, (ancestor) => {
      if (foundSchema) return; // skip remaining once we've found it
      const def = this._schema[ancestor];
      if (!def) return;
      def.type.definitions.forEach(typeDef => {<commit_msg>Fix custom error messages not separate<commit_after>import deepExtend from 'deep-extend';
import MongoObject from 'mongo-object';
import _ from 'underscore';
import MessageBox from 'message-box';
import clone from 'clone';
import humanize from './humanize.js';
import ValidationContext from './ValidationContext';
import SimpleSchemaGroup from './SimpleSchemaGroup';
import regExpObj from './regExp';
import clean from './clean';
import expandShorthand from './expandShorthand';
import { forEachKeyAncestor } from './utility';
import defaultMessages from './defaultMessages';

// Exported for tests
export const schemaDefinitionOptions = [
  'type',
  'label',
  'optional',
  'required',
  'autoValue',
  'defaultValue',
];

const oneOfProps = [
  'type',
  'min',
  'max',
  'minCount',
  'maxCount',
  'allowedValues',
  'exclusiveMin',
  'exclusiveMax',
  'regEx',
  'custom',
  'blackbox',
  'trim',
];

const propsThatCanBeFunction = [
  'label',
  'optional',
  'min',
  'max',
  'minCount',
  'maxCount',
  'allowedValues',
  'exclusiveMin',
  'exclusiveMax',
  'regEx',
];

class SimpleSchema {
  constructor(schema = {}, options = {}) {
    // Stash the options object
    this._constructorOptions = { ...options };
    if (this._constructorOptions.humanizeAutoLabels !== false) this._constructorOptions.humanizeAutoLabels = true;

    // Custom validators for this instance
    this._validators = [];
    this._docValidators = [];

    // Named validation contexts
    this._validationContexts = {};

    // Clone, expanding shorthand, and store the schema object in this._schema
    this._schema = {};
    this.extend(schema);

    // Define default validation error messages
    this.messageBox = new MessageBox(clone(defaultMessages));

    // Schema-level defaults for cleaning
    this._cleanOptions = {
      filter: true,
      autoConvert: true,
      removeEmptyStrings: true,
      trimStrings: true,
      getAutoValues: true,
      removeNullsFromArrays: false,
      extendAutoValueContext: {},
      ...options.clean,
    };

    this.version = SimpleSchema.version;
  }

  findFirstAncestorSimpleSchema(key, func) {
    const genericKey = MongoObject.makeKeyGeneric(key);

    let foundSchema = false;
    forEachKeyAncestor(genericKey, (ancestor) => {
      if (foundSchema) return; // skip remaining once we've found it
      const def = this._schema[ancestor];
      if (!def) return;
      def.type.definitions.forEach(typeDef => {
{'fraction_non_alphanumeric': 0.12646514497223935, 'fraction_numerical': 0.0, 'mean_word_length': 3.623574144486692, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '2928229', 'n_tokens_mistral': 1451, 'n_tokens_neox': 1422, 'n_words': 365}