import { ValidationError } from '../../../errors/index.js';
import { deepCopyObject } from '../../../utilities/deepCopyObject.js';
import { traverseFields } from './traverseFields.js';
export const beforeChange = async ({ id, collection, context, data: incomingData, doc, docWithLocales, global, operation, req, skipValidation })=>{
    const data = deepCopyObject(incomingData);
    const mergeLocaleActions = [];
    const errors = [];
    await traverseFields({
        id,
        collection,
        context,
        data,
        doc,
        docWithLocales,
        errors,
        fields: collection?.fields || global?.fields,
        global,
        mergeLocaleActions,
        operation,
        path: '',
        req,
        siblingData: data,
        siblingDoc: doc,
        siblingDocWithLocales: docWithLocales,
        skipValidation
    });
    if (errors.length > 0) {
        throw new ValidationError(errors, req.t);
    }
    mergeLocaleActions.forEach((action)=>action());
    return data;
};

//# sourceMappingURL=index.js.map