<commit_before>// Dependencies
var NodeElm = require("./node")
  , SubElm = require("./node/subelm")
  , LineElm = require("./line")
  , Typpy = require("typpy")
  , Deffy = require("deffy")
  , IterateObject = require("iterate-object")
  , Ul = require("ul")
  , Enny = require("enny")
  , Parsers = require("./parsers")
  ;

/**
 * Composition
 * Creates a new `Composition` instance.
 *
 * @name Composition
 * @function
 * @param {Object} input An object containing the following fields:
 *
 *   - `instances` (Object): The application instances.
 *   - `moduleInfo` (Object): Module related information.
 *   - `appService` (Object): Application service content (parsed).
 *
 * @return {Composition} The `Composition` instance.
 */
function Composition(input) {

    this.nodes = {};
    this.lines = {};

    // Internal caching
    this.ids = {};

    // Store composition data
    this.instances = Deffy(input.instances, {});
    this.moduleInfo = Deffy(input.moduleInfo, {});
    this.appService = Deffy(input.appService, {});

    // Add the instances
    this.addInstances();
}

/**
 * get
 * Gets a provided element/element id.
 *
 * @name get
 * @function
 * @param {String|Element} elm The element id or the element itself.
 * @return {Element} The found element internally.
 */
Composition.prototype.get = function (elm) {
    if (Typpy(elm, String)) {
        return this.ids[elm];
    }
    if (Typpy(elm, Object)) {
        return this.get(new NodeElm.Id(elm).toString());
    }
    return null;
};

/**
 * addNode
 * Adds a new element.
 *
 * @name addNode
 * @function
 * @param {Element|Object} node The new element to add.
 * @param {Boolean} isServer A flag indicated where to add it: on the server or on the client.
 * @return {Element} The added element.
 */
Composition.prototype.addNode = function (node, isServer) {
    node = new NodeElm(node, isServer);
    return (this.nodes[node.id] = this.ids[node.id] = node);
};

/**
 * addLine
 * Adds a new line.
 *
 * @name addLine
 * @function
 * @param {Line|Object} line The line to add.
 * @return {Line} The added line.
 */
Composition.prototype.addLine = function (line) {
    line = new LineElm(line);
    if (Typpy(line.source, SubElm)) {
        line.source.lines[line.id] = line;
    }
    return (this.lines[line.id] = this.ids[line.id] = line);
};

/**
 * connect
 * Connects two elements.
 *
 * @name connect
 * @function
 * @param {Element} s The source element
 * @param {Element} t The target element
 * @param {Object} a Additional fields to be merged.
 */
Composition.prototype.connect = function (s, t, a) {
    var self = this
      , result = []
      , r
      , sourceIsArray = false
      ;

    if ((sourceIsArray = Typpy(s, Array)) || Typpy(t, Array)) {
        r = (sourceIsArray ? s : t).map(sourceIsArray ? function (c) {
            return self.connect(c, t, a);
        } : function (c) {
            return self.connect(s, c, a);
        });
        IterateObject(r, function (c) {
            if (Typpy(c, Array)) {
                return IterateObject(c, function (c) {
                    result.push(c);
                });
            }
            result.push(c);
        });
        return result;
    }

    return this.addLine(Ul.merge(a, {
        source: s
      , target: t
    }));
};

/**
 * prepare
 * Prepares the data to be used in the builder or other client.
 *
 * @name prepare
 * @function
 * @return {Object} The prepared composition.
 */
Composition.prototype.prepare = function () {
    var out = {
        nodes: {}
      , lines: {}
    };

    IterateObject(this.nodes, function (node, id) {
        var cNode = out.nodes[id] = {
            id: node.id.toString(),
            color: node.color,
            domains: node.domains,
            icon: node.icon,
            name: node.label,
            subelms: {},<commit_msg>Export the original name too<commit_after>// Dependencies
var NodeElm = require("./node")
  , SubElm = require("./node/subelm")
  , LineElm = require("./line")
  , Typpy = require("typpy")
  , Deffy = require("deffy")
  , IterateObject = require("iterate-object")
  , Ul = require("ul")
  , Enny = require("enny")
  , Parsers = require("./parsers")
  ;

/**
 * Composition
 * Creates a new `Composition` instance.
 *
 * @name Composition
 * @function
 * @param {Object} input An object containing the following fields:
 *
 *   - `instances` (Object): The application instances.
 *   - `moduleInfo` (Object): Module related information.
 *   - `appService` (Object): Application service content (parsed).
 *
 * @return {Composition} The `Composition` instance.
 */
function Composition(input) {

    this.nodes = {};
    this.lines = {};

    // Internal caching
    this.ids = {};

    // Store composition data
    this.instances = Deffy(input.instances, {});
    this.moduleInfo = Deffy(input.moduleInfo, {});
    this.appService = Deffy(input.appService, {});

    // Add the instances
    this.addInstances();
}

/**
 * get
 * Gets a provided element/element id.
 *
 * @name get
 * @function
 * @param {String|Element} elm The element id or the element itself.
 * @return {Element} The found element internally.
 */
Composition.prototype.get = function (elm) {
    if (Typpy(elm, String)) {
        return this.ids[elm];
    }
    if (Typpy(elm, Object)) {
        return this.get(new NodeElm.Id(elm).toString());
    }
    return null;
};

/**
 * addNode
 * Adds a new element.
 *
 * @name addNode
 * @function
 * @param {Element|Object} node The new element to add.
 * @param {Boolean} isServer A flag indicated where to add it: on the server or on the client.
 * @return {Element} The added element.
 */
Composition.prototype.addNode = function (node, isServer) {
    node = new NodeElm(node, isServer);
    return (this.nodes[node.id] = this.ids[node.id] = node);
};

/**
 * addLine
 * Adds a new line.
 *
 * @name addLine
 * @function
 * @param {Line|Object} line The line to add.
 * @return {Line} The added line.
 */
Composition.prototype.addLine = function (line) {
    line = new LineElm(line);
    if (Typpy(line.source, SubElm)) {
        line.source.lines[line.id] = line;
    }
    return (this.lines[line.id] = this.ids[line.id] = line);
};

/**
 * connect
 * Connects two elements.
 *
 * @name connect
 * @function
 * @param {Element} s The source element
 * @param {Element} t The target element
 * @param {Object} a Additional fields to be merged.
 */
Composition.prototype.connect = function (s, t, a) {
    var self = this
      , result = []
      , r
      , sourceIsArray = false
      ;

    if ((sourceIsArray = Typpy(s, Array)) || Typpy(t, Array)) {
        r = (sourceIsArray ? s : t).map(sourceIsArray ? function (c) {
            return self.connect(c, t, a);
        } : function (c) {
            return self.connect(s, c, a);
        });
        IterateObject(r, function (c) {
            if (Typpy(c, Array)) {
                return IterateObject(c, function (c) {
                    result.push(c);
                });
            }
            result.push(c);
        });
        return result;
    }

    return this.addLine(Ul.merge(a, {
        source: s
      , target: t
    }));
};

/**
 * prepare
 * Prepares the data to be used in the builder or other client.
 *
 * @name prepare
 * @function
 * @return {Object} The prepared composition.
 */
Composition.prototype.prepare = function () {
    var out = {
        nodes: {}
      , lines: {}
    };

    IterateObject(this.nodes, function (node, id) {
        var cNode = out.nodes[id] = {
            id: node.id.toString(),
            color: node.color,
            domains: node.domains,
            icon: node.icon,
            name: node.label,
            _name: node.name,
            subelms: {},
{'fraction_non_alphanumeric': 0.1470171369668857, 'fraction_numerical': 0.0, 'mean_word_length': 2.419383259911894, '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': '481625', 'n_tokens_mistral': 2486, 'n_tokens_neox': 2437, 'n_words': 670}