"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.buildTemplateRegistry = void 0;
const buildTemplateRegistry = (discovery, { template, keySelector, }) => {
    const wrappers = discovery.getProviders();
    const matched = wrappers.filter(wrapper => !!wrapper.metatype && wrapper.instance instanceof template);
    const registry = matched.reduce((acc, wrapper) => {
        let node = acc;
        const metadataKeys = keySelector(wrapper.instance);
        for (let i = 0; i < metadataKeys.length; i++) {
            const value = metadataKeys[i];
            const next = i === metadataKeys.length - 1 ? wrapper.instance : new Map();
            if (!node.get(value))
                node.set(value, next);
            node = node.get(value);
        }
        return acc;
    }, new Map());
    return registry;
};
exports.buildTemplateRegistry = buildTemplateRegistry;
//# sourceMappingURL=build-template-registry.js.map