"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const logger_1 = require("../utils/logger");
const logger = logger_1.log('abstract-node');
class AbstractNode {
    constructor(graph) {
        this._graph = graph;
    }
    isExternal() {
        return this._external === true;
    }
    getName() {
        return this._name;
    }
    getVersion() {
        return this._version;
    }
    getLocation() {
        return this._location;
    }
    getDescendants() {
        const deps = [];
        this._accumulateDependencies(deps);
        return deps;
    }
    _accumulateDependencies(deps) {
        for (const dep of this._dependencies) {
            deps.push(dep);
            dep._accumulateDependencies(deps);
        }
    }
    getAncestors() {
        const dependent = this._graph.getNodes().filter((n) => n.getDescendants().some((d) => d.equals(this)));
        logger.silly(`Nodes depending upon ${this._name}`, dependent.map((d) => d._name));
        return dependent;
    }
    isRoot() {
        return this.getAncestors().length === 0;
    }
    getChildren() {
        return this._dependencies;
    }
    getChild(name) {
        return this._dependencies.find((d) => d._name === name);
    }
    getParents() {
        return this._graph.getNodes().filter((n) => n._dependencies.some((d) => d.equals(this)));
    }
    getInternalChildren() {
        return this.getChildren().filter((n) => !n.isExternal());
    }
    getInternalDependencies() {
        return this.getDescendants().filter((n) => !n.isExternal());
    }
    getInternalAncestors() {
        return this.getAncestors().filter((n) => !n.isExternal());
    }
    getExternalDependencies() {
        return this.getDescendants().filter((n) => n.isExternal());
    }
}
exports.AbstractNode = AbstractNode;
//# sourceMappingURL=abstract-node.js.map