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