<commit_before>
import { Enum, MapExpr, ReduceExpr, AggregateDefinition, Lazy, Type, Index, Guid } from '../models/types';

import { PropertyDefinition } from '../models/property-definition';

export class Property {

  private _definition: PropertyDefinition;

  constructor(propDef?: PropertyDefinition) {
    this._definition = propDef || {};
  }

  public name(name: string): this {
    this._definition.name = name;
    return this;
  }

  public key(): this {
    this._definition.key = true;
    return this;
  }

  public ref(type: Type): this {
    this._definition.ref = type;
    return this;
  }

  public min(min: number): this {
    this._definition.min = min;
    return this;
  }

  public max(max: number): this {
    this._definition.max = max;
    return this;
  }

  public length(len: number): this {
    this._definition.length = len;
    return this;
  }

  public decimals(decimals: number): this {
    this._definition.decimals = decimals;
    return this;
  }

  public unique(unique = true): this {
    this._definition.unique = unique;
    return this;
  }

  public choices<T>(choices: Lazy<T[]>): this {
    this._definition.choices = choices;

    return this;
  }

  public type(type: Type, secondaryType?: Type): this {
    this._definition.type = type;
    if (secondaryType) {
      this._definition.secondaryType = secondaryType;
    }
    return this;
  }

  public array(itemType?: Type): this {
    return this.type(Array, itemType);
  }

  public guid(): this {
    return this.type(Guid);
  }

  public string(pattern?: string | RegExp): this {
    this.type(String);
    
    if (pattern) {
      // TODO: Convert wildcard string into regexp...
      this._definition.pattern = typeof pattern === 'string' ? new RegExp(pattern) : pattern;
    }
    
    return this;
  }


  public integer(): this;
  public integer(min: number, max: number): this;
  public integer(min: number = 0, max: number = Number.MAX_SAFE_INTEGER): this {

    return this
      .type(Number)
      .decimals(0)
      .min(min)
      .max(max);
  }

  public float(): this;
  public float(min: number, max: number): this;  
  public float(min: number = Number.MIN_VALUE, max: number = Number.MAX_VALUE): this {    
    return this
      .type(Number)
      .min(min)
      .max(max);
  }
  
  public sum<TModel,TProp>(prop: MapExpr<TModel, Array<TProp>> | string, val?: ReduceExpr<TProp, number>): this {
    if (typeof prop !== 'function' && (!prop.length || prop.length < 1)) {
      throw new Error(`'prop' must be defined!`);
    }
    this._definition.type = Number;
    this._definition.sum = {
      map: typeof prop === 'function' ? prop : (x => x[prop]),
      reduce: val || (x => x)
    };

    return this;
  }
  
  public build(): PropertyDefinition {
    return Object.assign({}, this._definition);<commit_msg>Removed sum method, for now.<commit_after>
import { Enum, MapExpr, ReduceExpr, AggregateDefinition, Lazy, Type, Index, Guid } from '../models/types';

import { PropertyDefinition } from '../models/property-definition';

export class Property {

  private _definition: PropertyDefinition;

  constructor(propDef?: PropertyDefinition) {
    this._definition = propDef || {};
  }

  public name(name: string): this {
    this._definition.name = name;
    return this;
  }

  public key(): this {
    this._definition.key = true;
    return this;
  }

  public ref(type: Type): this {
    this._definition.ref = type;
    return this;
  }

  public min(min: number): this {
    this._definition.min = min;
    return this;
  }

  public max(max: number): this {
    this._definition.max = max;
    return this;
  }

  public length(len: number): this {
    this._definition.length = len;
    return this;
  }

  public decimals(decimals: number): this {
    this._definition.decimals = decimals;
    return this;
  }

  public unique(unique = true): this {
    this._definition.unique = unique;
    return this;
  }

  public choices<T>(choices: Lazy<T[]>): this {
    this._definition.choices = choices;

    return this;
  }

  public type(type: Type, secondaryType?: Type): this {
    this._definition.type = type;
    if (secondaryType) {
      this._definition.secondaryType = secondaryType;
    }
    return this;
  }

  public array(itemType?: Type): this {
    return this.type(Array, itemType);
  }

  public guid(): this {
    return this.type(Guid);
  }

  public string(pattern?: string | RegExp): this {
    this.type(String);
    
    if (pattern) {
      // TODO: Convert wildcard string into regexp...
      this._definition.pattern = typeof pattern === 'string' ? new RegExp(pattern) : pattern;
    }
    
    return this;
  }


  public integer(): this;
  public integer(min: number, max: number): this;
  public integer(min: number = 0, max: number = Number.MAX_SAFE_INTEGER): this {

    return this
      .type(Number)
      .decimals(0)
      .min(min)
      .max(max);
  }

  public float(): this;
  public float(min: number, max: number): this;  
  public float(min: number = Number.MIN_VALUE, max: number = Number.MAX_VALUE): this {    
    return this
      .type(Number)
      .min(min)
      .max(max);
  }
  
  public build(): PropertyDefinition {
    return Object.assign({}, this._definition);
{'fraction_non_alphanumeric': 0.13288973384030417, 'fraction_numerical': 0.0009505703422053232, 'mean_word_length': 2.8598679383712398, 'pattern_counts': {'":': 0, '<': 12, '<?xml version=': 0, '>': 13, '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': '7122642', 'n_tokens_mistral': 1675, 'n_tokens_neox': 1619, 'n_words': 435}