"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const Functional_1 = require("../../../../../Class/Functional");
const evaluateBundleSpec_1 = require("../../../../../spec/evaluate/evaluateBundleSpec");
const fromBundle_1 = require("../../../../../spec/fromBundle");
const validate_1 = require("../../../../../spec/validate");
const _ids_1 = require("../../../../_ids");
class FromBundle extends Functional_1.Functional {
    constructor(system) {
        super({
            i: ['bundle'],
            o: ['graph'],
        }, {
            output: {},
        }, system, _ids_1.ID_FROM_BUNDLE);
    }
    f({ bundle }, done, fail) {
        const { specs, classes } = this.__system;
        let graph;
        (0, evaluateBundleSpec_1.evaluateBundleSpec)(bundle, specs, classes);
        if (!(0, validate_1.validateBundleSpec)(bundle)) {
            fail('invalid bundle spec');
            return;
        }
        try {
            graph = (0, fromBundle_1.fromBundle)(bundle, this.__system.specs, {});
        }
        catch (err) {
            fail(err.message);
            return;
        }
        done({ graph });
    }
}
exports.default = FromBundle;
//# sourceMappingURL=index.js.map