"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.injectUserBundle = injectUserBundle;
exports.injectUserSpecs = injectUserSpecs;
const weakMerge_1 = require("./weakMerge");
function injectUserBundle(registry, bundle) {
    const { spec, specs = {} } = bundle;
    const specs_ = (0, weakMerge_1.weakMerge)(specs, { [spec.id]: spec });
    return injectUserSpecs(registry, specs_);
}
function injectUserSpecs(registry, specs) {
    var _a, _b, _c;
    // mark as "user" spec to prevent deletion
    for (const specId in specs) {
        specs[specId].user = true;
        specs[specId].metadata = (_a = specs[specId].metadata) !== null && _a !== void 0 ? _a : {};
        specs[specId].metadata.tags = (_c = (_b = specs[specId].metadata) === null || _b === void 0 ? void 0 : _b.tags) !== null && _c !== void 0 ? _c : [];
        if (!specs[specId].metadata.tags.includes('user')) {
            specs[specId].metadata.tags.push('user');
        }
    }
    const specIdMap = registry.injectSpecs(specs);
    return specIdMap;
}
//# sourceMappingURL=injectBundle.js.map