"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.extract = exports.extractDepsFromFragment = exports.extractDepsFromFragmentData = exports.supportedRulesRegex = void 0;
const zod_1 = require("zod");
const regex_1 = require("../../../../util/regex");
const docker_1 = require("./docker");
const git_1 = require("./git");
const go_1 = require("./go");
const http_1 = require("./http");
const Target = zod_1.z.union([docker_1.DockerTarget, git_1.GitTarget, go_1.GoTarget, http_1.HttpTarget]);
/**
 * Gather all rule names supported by Renovate in order to speed up parsing
 * by filtering out other syntactically correct rules we don't support yet.
 */
const supportedRules = [...docker_1.dockerRules, ...git_1.gitRules, ...go_1.goRules, ...http_1.httpRules];
exports.supportedRulesRegex = (0, regex_1.regEx)(`^${supportedRules.join('|')}$`);
function extractDepsFromFragmentData(fragmentData) {
    const res = Target.safeParse(fragmentData);
    if (!res.success) {
        return [];
    }
    return res.data;
}
exports.extractDepsFromFragmentData = extractDepsFromFragmentData;
function extractDepsFromFragment(fragment) {
    const fragmentData = extract(fragment);
    return extractDepsFromFragmentData(fragmentData);
}
exports.extractDepsFromFragment = extractDepsFromFragment;
function extract(fragment) {
    if (fragment.type === 'string') {
        return fragment.value;
    }
    if (fragment.type === 'record') {
        const { children } = fragment;
        const result = {};
        for (const [key, value] of Object.entries(children)) {
            result[key] = extract(value);
        }
        return result;
    }
    return fragment.children.map(extract);
}
exports.extract = extract;
//# sourceMappingURL=index.js.map