<commit_before>import { Element, AttributePath, ElementDefinition, ProviderMap, Reporter } from '@openmicrostep/msbuildsystem.core';

export const elementFactories = Element.createElementFactoriesProviderMap('aspects');

export const GroupElement = Element.DynGroupElement(Element);
elementFactories.registerSimple('group', (reporter: Reporter, name: string, definition: ElementDefinition, attrPath: AttributePath, parent: Element) => {
  return new GroupElement('group', name, parent);
});

export class AspectBaseElement extends Element {

}


export class AspectRootElement extends Element {
  __classes: ClassElement[] = [];
}
export  interface AspectBaseElement {
  __root() : AspectRootElement;
}

function appendUndefined(type: string, allowUndefined: boolean) {
  return allowUndefined ? `${type} | undefined` : type;
}

function embedType(condition: boolean, prefix: [string, string], type: string, suffix: [string, string]) {
  return condition ? `${prefix[0]}${type}${suffix[0]}` : `${prefix[1]}${type}${suffix[1]}`;
}

elementFactories.registerSimple('type', (reporter, name, definition, attrPath, parent: AspectBaseElement) => {
  return new TypeElement('type', name, parent);
});
export class TypeElement extends Element {
  type: 'primitive' | 'class' | 'array' | 'set' | 'dictionary' | 'or';
  itemType?: TypeElement = undefined;
  properties?: { [s: string]: TypeElement } = undefined;
  types?: TypeElement[] = undefined;
  min?: number;
  max?: number | '*';

  __decl(isAttribute: boolean, allowUndefined: boolean = false, relation: boolean = false) {
    switch (this.type) {
      case 'primitive':
        switch (this.name) {
          case 'integer':    return appendUndefined("number", allowUndefined);
          case 'decimal':    return appendUndefined("number", allowUndefined);
          case 'date':       return appendUndefined("Date", allowUndefined);
          case 'string':     return appendUndefined("string", allowUndefined);
          case 'array':      return appendUndefined("any[]", allowUndefined);
          case 'dictionary': return appendUndefined("{ [k: string]: any }", allowUndefined);
          case 'object':     return appendUndefined("Object", allowUndefined);
          case 'identifier': return appendUndefined("string | number", allowUndefined);
        }
        return "any";
      case 'class':
        return appendUndefined(this.name, allowUndefined);
      case 'array':
        return embedType(isAttribute, [`ImmutableList<`, ``], this.itemType ? this.itemType.__decl(isAttribute) : 'any' , [`>`, `[]`]);
      case 'set':
        return embedType(isAttribute, [`ImmutableSet<`, `Set<`], this.itemType ? this.itemType.__decl(isAttribute) : 'any' , [`>`, `>`]);
      case 'dictionary':
        return embedType(isAttribute, [`ImmutableObject<`, ``], `{${Object.keys(this.properties!).map(k => `${k === '*' ? '[k: string]' : `${k}`}: ${this.properties![k].__decl(isAttribute)}`).join(', ')}}` , [`>`, ``]);
      case 'or':
        return this.types ? this.types.map(t => t.__decl(isAttribute)).join(' | ') : 'any';
    }
  }

  toJSON() {
    let r: Partial<TypeElement> = { is: this.is };
    this.name                     && (r.name = this.name);
    this.itemType !== undefined   && (r.itemType = this.itemType);
    this.types !== undefined      && (r.types = this.types);<commit_msg>buildsystem: fix 'or' typescript typings generation<commit_after>import { Element, AttributePath, ElementDefinition, ProviderMap, Reporter } from '@openmicrostep/msbuildsystem.core';

export const elementFactories = Element.createElementFactoriesProviderMap('aspects');

export const GroupElement = Element.DynGroupElement(Element);
elementFactories.registerSimple('group', (reporter: Reporter, name: string, definition: ElementDefinition, attrPath: AttributePath, parent: Element) => {
  return new GroupElement('group', name, parent);
});

export class AspectBaseElement extends Element {

}


export class AspectRootElement extends Element {
  __classes: ClassElement[] = [];
}
export  interface AspectBaseElement {
  __root() : AspectRootElement;
}

function appendUndefined(type: string, allowUndefined: boolean) {
  return allowUndefined ? `${type} | undefined` : type;
}

function embedType(condition: boolean, prefix: [string, string], type: string, suffix: [string, string]) {
  return condition ? `${prefix[0]}${type}${suffix[0]}` : `${prefix[1]}${type}${suffix[1]}`;
}

elementFactories.registerSimple('type', (reporter, name, definition, attrPath, parent: AspectBaseElement) => {
  return new TypeElement('type', name, parent);
});
export class TypeElement extends Element {
  type: 'primitive' | 'class' | 'array' | 'set' | 'dictionary' | 'or';
  itemType?: TypeElement = undefined;
  properties?: { [s: string]: TypeElement } = undefined;
  types?: TypeElement[] = undefined;
  min?: number;
  max?: number | '*';

  __decl(isAttribute: boolean, allowUndefined: boolean = false, relation: boolean = false) {
    switch (this.type) {
      case 'primitive':
        switch (this.name) {
          case 'integer':    return appendUndefined("number", allowUndefined);
          case 'decimal':    return appendUndefined("number", allowUndefined);
          case 'date':       return appendUndefined("Date", allowUndefined);
          case 'string':     return appendUndefined("string", allowUndefined);
          case 'array':      return appendUndefined("any[]", allowUndefined);
          case 'dictionary': return appendUndefined("{ [k: string]: any }", allowUndefined);
          case 'object':     return appendUndefined("Object", allowUndefined);
          case 'identifier': return appendUndefined("string | number", allowUndefined);
        }
        return "any";
      case 'class':
        return appendUndefined(this.name, allowUndefined);
      case 'array':
        return embedType(isAttribute, [`ImmutableList<`, ``], this.itemType ? this.itemType.__decl(isAttribute) : 'any' , [`>`, `[]`]);
      case 'set':
        return embedType(isAttribute, [`ImmutableSet<`, `Set<`], this.itemType ? this.itemType.__decl(isAttribute) : 'any' , [`>`, `>`]);
      case 'dictionary':
        return embedType(isAttribute, [`ImmutableObject<`, ``], `{${Object.keys(this.properties!).map(k => `${k === '*' ? '[k: string]' : `${k}`}: ${this.properties![k].__decl(isAttribute)}`).join(', ')}}` , [`>`, ``]);
      case 'or':
        return this.types ? `(${this.types.map(t => t.__decl(isAttribute)).join(' | ')})` : 'any';
    }
  }

  toJSON() {
    let r: Partial<TypeElement> = { is: this.is };
    this.name                     && (r.name = this.name);
    this.itemType !== undefined   && (r.itemType = this.itemType);
    this.types !== undefined      && (r.types = this.types);
{'fraction_non_alphanumeric': 0.16535783078974664, 'fraction_numerical': 0.001185360794191732, 'mean_word_length': 4.152671755725191, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 21, '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': '3920999', 'n_tokens_mistral': 1963, 'n_tokens_neox': 1934, 'n_words': 464}