import _ from 'lodash';
export function validate(validatorsMap) {
    return new Promise(function (resolve, reject) {
        var result = Promise.resolve();
        var errors = {};
        // iterate by all keys except null values
        _.forOwn(_.omitBy(validatorsMap, _.isNull), function (validator, key) {
            result = result.then(function () {
                return validator.catch(function (error) {
                    errors[key] = error;
                    return Promise.resolve();
                });
            });
        });
        result.then(function () {
            if (_.isEmpty(errors)) {
                resolve();
            }
            else {
                reject(errors); //FIXME Promise rejected with non-Error
            }
        });
    });
}
export function stripErrors(errors) {
    return _.reduce(errors, function (acc, errorDetails, errorFieldName) {
        if (_.isString(errorDetails.message)) {
            acc[errorFieldName] = errorDetails.message;
        }
        else {
            acc[errorFieldName] = stripErrors(errorDetails);
        }
        return acc;
    }, {});
}
//# sourceMappingURL=ValidationUtils.js.map