<commit_before>"use strict"

// Dependencies
const EngineTools = require("engine-tools")
    , SameTime = require("same-time")
    , EngineParser = require("engine-parser")
    , Parser = require("./parser")
    , IterateObject = require("iterate-object")
    ;

class EngineParserGen {

    constructor (app) {
        if (typeof app !== "string" || !app) {
            throw new TypeError("The app parameter should be a string.");
        }
        this.app = app;
        this.path = EngineTools.getAppPath(this.app);
    }

    // Read the instances
    parse (cb) {

        // Read the instances
        EngineTools.getComposition(this.app, { iName: true }, (err, data) => {
            if (err) { return cb(err); }

            // Parse the raw json
            this.parser = new Parser(data);
            cb(null, this.parser.parse());
        });
    }

    /**
     * renameInstance
     * Renames an instance.
     *
     * @name renameInstance
     * @function
     * @param {String} oldName The old instance name.
     * @param {String} newName The new instance name.
     * @param {Function} cb The callback function.
     * @return {EngineParserGen} The `EngineParserGen` instance.
     */
    renameInstance (oldName, newName, cb) {
        this.parse((err, data) => {
            if (err) { return cb(err); }
            var instanceToRename = this.parser.getInstance(oldName);
            if (!instanceToRename) {
                return cb(new Error("There is no such instance."));
            }

            // Change the instance name
            instanceToRename.name = newName;
            var renameFlow = function (flow) {
                if (!Array.isArray(flow)) { return; }
                IterateObject(flow, cElement =>  {
                    IterateObject(cElement._, cComponent =>  {
                        if (cComponent.data.instance === oldName) {
                            cComponent.data.to =
                        }
                    });
                });
            };

            // Change the instance name in flows
            IterateObject(this.parser.data.instances, cInstance => {
                if (cInstance._.name === oldName) { return; }<commit_msg>Send some type errors<commit_after>"use strict"

// Dependencies
const EngineTools = require("engine-tools")
    , SameTime = require("same-time")
    , EngineParser = require("engine-parser")
    , Parser = require("./parser")
    , IterateObject = require("iterate-object")
    ;

class EngineParserGen {

    constructor (app) {
        if (typeof app !== "string" || !app) {
            throw new TypeError("The app parameter should be a string.");
        }
        this.app = app;
        this.path = EngineTools.getAppPath(this.app);
    }

    // Read the instances
    parse (cb) {

        // Read the instances
        EngineTools.getComposition(this.app, { iName: true }, (err, data) => {
            if (err) { return cb(err); }

            // Parse the raw json
            this.parser = new Parser(data);
            cb(null, this.parser.parse());
        });
    }

    /**
     * renameInstance
     * Renames an instance.
     *
     * @name renameInstance
     * @function
     * @param {String} oldName The old instance name.
     * @param {String} newName The new instance name.
     * @param {Function} cb The callback function.
     * @return {EngineParserGen} The `EngineParserGen` instance.
     */
    renameInstance (oldName, newName, cb) {

        if (typeof oldName !== "string") {
            return cb(new TypeError("The old instance name should be a string."));
        }

        if (typeof newName !== "string") {
            return cb(new TypeError("The new instance name should be a string."));
        }

        this.parse((err, data) => {
            if (err) { return cb(err); }
            var instanceToRename = this.parser.getInstance(oldName);
            if (!instanceToRename) {
                return cb(new Error("There is no such instance."));
            }

            // Change the instance name
            instanceToRename.name = newName;
            var renameFlow = function (flow) {
                if (!Array.isArray(flow)) { return; }
                IterateObject(flow, cElement =>  {
                    IterateObject(cElement._, cComponent =>  {
                        if (cComponent.data.instance === oldName) {
                            cComponent.data.to = newName;
                        }
                    });
                });
            };

            // Change the instance name in flows
            IterateObject(this.parser.data.instances, cInstance => {
                if (cInstance._.name === oldName) { return; }
{'fraction_non_alphanumeric': 0.12038216560509554, 'fraction_numerical': 0.0, 'mean_word_length': 1.6981672394043528, 'pattern_counts': {'":': 0, '<': 3, '<?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': '48373', 'n_tokens_mistral': 1284, 'n_tokens_neox': 1240, 'n_words': 330}