"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.validateBundleSpec = exports.validateGraphSpec = exports.validObjectKeys = void 0;
const f_1 = require("../system/f/object/Keys/f");
const ALLOWED_BUNDLE_SPEC_KEY_SET = new Set(['spec', 'specs', 'metadata']);
const ALLOWED_SPEC_KEY_SET = new Set([
    'name',
    'version',
    'id',
    'units',
    'merges',
    'data',
    'component',
    'metadata',
    'inputs',
    'outputs',
    'type',
    'render',
]);
function validObjectKeys(obj, set) {
    let valid = true;
    const _keys = (0, f_1.keys)(obj);
    for (const key of _keys) {
        if (!set.has(key)) {
            valid = false;
            break;
        }
    }
    return valid;
}
exports.validObjectKeys = validObjectKeys;
function validateGraphSpec(spec) {
    return validObjectKeys(spec, ALLOWED_SPEC_KEY_SET);
}
exports.validateGraphSpec = validateGraphSpec;
function validateBundleSpec(bundle) {
    if (!validObjectKeys(bundle, ALLOWED_BUNDLE_SPEC_KEY_SET)) {
        return false;
    }
    const { spec = {}, specs = {}, metadata = {} } = bundle;
    if (!validateGraphSpec(spec)) {
        return false;
    }
    for (const specId in specs) {
        if (!validateGraphSpec(specs[specId])) {
            return false;
        }
    }
    return true;
}
exports.validateBundleSpec = validateBundleSpec;
//# sourceMappingURL=validate.js.map