{"size": 1742, "ext": "js", "max_stars_repo_path": "dist/src/query-models/EntityLink.js", "max_stars_repo_name": "gsbelarus/gdmn-orm", "max_stars_repo_stars_event_min_datetime": "2018-07-20T07:56:57.000Z", "max_stars_repo_stars_event_max_datetime": "2018-08-03T18:28:57.000Z", "max_issues_repo_path": "dist/src/query-models/EntityLink.js", "max_issues_repo_name": "gsbelarus/gdmn-orm", "max_issues_repo_issues_event_min_datetime": "2018-09-01T13:38:11.000Z", "max_issues_repo_issues_event_max_datetime": "2018-09-02T07:41:20.000Z", "max_forks_repo_path": "dist/src/query-models/EntityLink.js", "max_forks_repo_name": "gsbelarus/gdmn-orm", "max_forks_repo_forks_event_min_datetime": "2018-08-08T05:59:11.000Z", "max_forks_repo_forks_event_max_datetime": "2018-08-09T12:09:50.000Z"}
{"max_stars_count": 2, "max_issues_count": 1, "max_forks_count": 2, "avg_line_length": 32.2592592593, "max_line_length": 154, "alphanum_fraction": 0.5424799082}
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const EntityQueryField_1 = require("./EntityQueryField");
class EntityLink {
    constructor(entity, alias, fields) {
        this.entity = entity;
        this.alias = alias;
        this.fields = fields;
    }
    static inspectorToObject(erModel, inspector) {
        const entity = erModel.entity(inspector.entity);
        const alias = inspector.alias;
        const fields = inspector.fields.map((inspectorField) => (EntityQueryField_1.EntityQueryField.inspectorToObject(erModel, entity, inspectorField)));
        return new EntityLink(entity, alias, fields);
    }
    deepFindLinkByField(field) {
        const find = this.fields
            .filter((qField) => !qField.link)
            .some((qField) => qField === field);
        if (find) {
            return this;
        }
        for (const qField of this.fields) {
            if (qField.link) {
                const findLink = qField.link.deepFindLinkByField(field);
                if (findLink) {
                    return findLink;
                }
            }
        }
    }
    deepFindLinkByAlias(alias) {
        if (this.alias === alias) {
            return this;
        }
        for (const field of this.fields) {
            if (field.link) {
                const find = field.link.deepFindLinkByAlias(alias);
                if (find) {
                    return find;
                }
            }
        }
    }
    inspect() {
        return {
            entity: this.entity.name,
            alias: this.alias,
            fields: this.fields.map((field) => field.inspect())
        };
    }
}
exports.EntityLink = EntityLink;
//# sourceMappingURL=EntityLink.js.map