const filterNullishValues = value => value !== undefined && value !== null;
export function removeFieldsWithNullishValues(object) {
    return filterValue(object, filterNullishValues);
}
function filterValue(object, filterValue = filterNullishValues) {
    const clone = {};
    for (const [key, value] of Object.entries(object)) {
        if (filterValue(value)) {
            if (typeof value === 'object') {
                if (Array.isArray(value)) {
                    clone[key] = value.filter(filterValue);
                }
                else {
                    clone[key] = removeFieldsWithNullishValues(value);
                }
            }
            else {
                clone[key] = value;
            }
        }
    }
    return clone;
}
export const pickFields = (source, fields) => Object.fromEntries(fields.map(field => [field, source[field]]));
export const mutateApplication = (application, ...mutations) => {
    for (const mutation of mutations) {
        for (const [key, value] of Object.entries(mutation)) {
            if (typeof value === 'function') {
                application[key] = value(application);
            }
            else if (application[key] === undefined) {
                application[key] = value;
            }
        }
    }
};
