<commit_before>import {Document, Resource} from 'idai-components-2';
import {clone} from '../../../util/object-util';
import {isNot, includedIn} from 'tsfun';


const RECORDED_IN = 'isRecordedIn';


/**
 * @author <NAME>
 */
export function mergeDocument(into: Document, additional: Document, allowOverwriteRelationsOnMerge: boolean): Document {

    const clonedTarget = clone(into);

    clonedTarget.resource =
        Object.keys(additional.resource)
            .filter(isNot(includedIn(Resource.CONSTANT_FIELDS)))
            .reduce((acc: Resource, key: string) => {
                if (additional.resource[key] !== undefined) acc[key] = clone(additional.resource[key]);
                return acc;
            }, clonedTarget.resource);

    if (allowOverwriteRelationsOnMerge) {
        clonedTarget.resource.relations = clone(additional.resource.relations);
        if (clonedTarget.resource.relations
            && into.resource.relations
            && into.resource.relations[RECORDED_IN]) {
            clonedTarget.resource.relations[RECORDED_IN] = clone(into.resource.relations[RECORDED_IN]);
        }
    }
    return clonedTarget;
}
<commit_msg>Make use of constant<commit_after>import {Document, Resource} from 'idai-components-2';
import {clone} from '../../../util/object-util';
import {isNot, includedIn} from 'tsfun';
import {HIERARCHICAL_RELATIONS} from '../../../model/relation-constants';
import RECORDED_IN = HIERARCHICAL_RELATIONS.RECORDED_IN;



/**
 * @author <NAME>
 */
export function mergeDocument(into: Document, additional: Document, allowOverwriteRelationsOnMerge: boolean): Document {

    const clonedTarget = clone(into);

    clonedTarget.resource =
        Object.keys(additional.resource)
            .filter(isNot(includedIn(Resource.CONSTANT_FIELDS)))
            .reduce((acc: Resource, key: string) => {
                if (additional.resource[key] !== undefined) acc[key] = clone(additional.resource[key]);
                return acc;
            }, clonedTarget.resource);

    if (allowOverwriteRelationsOnMerge) {
        clonedTarget.resource.relations = clone(additional.resource.relations);
        if (clonedTarget.resource.relations
            && into.resource.relations
            && into.resource.relations[RECORDED_IN]) {
            clonedTarget.resource.relations[RECORDED_IN] = clone(into.resource.relations[RECORDED_IN]);
        }
    }
    return clonedTarget;
}

{'fraction_non_alphanumeric': 0.12793089263677498, 'fraction_numerical': 0.0008227067050596463, 'mean_word_length': 3.171526586620926, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6807011', 'n_tokens_mistral': 716, 'n_tokens_neox': 666, 'n_words': 123}