import { extend, isEmptyObject } from '@jscrpt/common';
/**
 * Extractor used for extracting dynamic data from dynamic module
 */
export class DynamicModuleDataExtractor {
    //######################### constructor #########################
    /**
     * Creates new instance of DynamicModuleDataExtractor
     * @param _extractorFunctions - Array of extractor functions used to create result
     * @param _logger - Instance of logger used for logging, optional
     */
    constructor(_extractorFunctions, _logger) {
        this._extractorFunctions = _extractorFunctions;
        this._logger = _logger;
        //extractor functions is not an array
        if (!Array.isArray(this._extractorFunctions)) {
            this._logger?.error('DynamicModuleDataExtractor: missing extractor functions!');
            this._extractorFunctions = [];
        }
    }
    //######################### public methods #########################
    /**
     * Tries to extract dynamic data from dynamic module
     * @param module - Module containing dynamic data
     */
    async tryToExtract(module) {
        const result = {};
        for (const fn of this._extractorFunctions) {
            extend(true, result, await fn(module, this._logger));
        }
        if (isEmptyObject(result)) {
            return null;
        }
        return result;
    }
}
//# sourceMappingURL=dynamicModuleDataExtractor.service.js.map