<commit_before>/*!
 * V4Fire Client Core
 * https://github.com/V4Fire/Client
 *
 * Released under the MIT license
 * https://github.com/V4Fire/Client/blob/master/LICENSE
 */

import { AsyncOpts } from 'core/async';
import { WatchOptions, Hooks } from 'core/component';
import { Statuses } from 'super/i-block/modules/interface';

export interface DaemonWatchObject extends WatchOptions {
	field: string;
}

export type DaemonWatcher = DaemonWatchObject | string;

export interface Daemon {
	hook?: Hooks[];
	watch?: DaemonWatcher[];
	wait?: Statuses;
	immediate?: boolean;
	asyncOptions?: AsyncOpts;
	fn: Function;
}

export type DaemonsDict = Dictionary<Daemon>;

/**
 * Inherit daemons
 *
 * @param daemons
 * @param parentDaemons
 */
export function inheritDaemons(daemons: DaemonsDict, parentDaemons: DaemonsDict): DaemonsDict {
	for (let keys = Object.keys(parentDaemons), i = 0; i < keys.length; i++) {
		const
			daemonName = keys[i],
			parentDaemon = parentDaemons[daemonName],
			daemon = daemons[daemonName];

		if (daemon && parentDaemon) {
			daemons[daemonName] = mergeDaemons(daemon, parentDaemon);
		}
	}

	return daemons;
}

/**
 * Merge two daemons
 *
 * @param a - daemon
 * @param b - parent daemon
 */
export function mergeDaemons(a: Daemon, b: Daemon): Daemon {
	const
		hook = (a.hook || []).concat(b.hook || []),
		watch = (a.watch || []).concat(b.watch || []);

	return {
		...b,
		...a,
		hook,
		watch
	};
}
<commit_msg>Fix wrong merge, prevent daemon was modified<commit_after>/*!
 * V4Fire Client Core
 * https://github.com/V4Fire/Client
 *
 * Released under the MIT license
 * https://github.com/V4Fire/Client/blob/master/LICENSE
 */

import { AsyncOpts } from 'core/async';
import { WatchOptions, Hooks } from 'core/component';
import { Statuses } from 'super/i-block/modules/interface';

export interface DaemonWatchObject extends WatchOptions {
	field: string;
}

export type DaemonWatcher = DaemonWatchObject | string;

export interface Daemon {
	hook?: Hooks[];
	watch?: DaemonWatcher[];
	wait?: Statuses;
	immediate?: boolean;
	asyncOptions?: AsyncOpts;
	fn: Function;
}

export type DaemonsDict = Dictionary<Daemon>;

/**
 * Inherit daemons
 *
 * @param daemons
 * @param parentDaemons
 */
export function inheritDaemons(parentDaemons: DaemonsDict, daemons: DaemonsDict): DaemonsDict {
	const
		mixedDaemons: DaemonsDict = {};

	for (let keys = Object.keys(parentDaemons), i = 0; i < keys.length; i++) {
		const
			daemonName = keys[i],
			parentDaemon = parentDaemons[daemonName],
			daemon = daemons[daemonName];

		if (daemon && parentDaemon) {
			mixedDaemons[daemonName] = mergeDaemons(parentDaemon, daemon);
		}
	}

	return mixedDaemons;
}

/**
 * Merge two daemons
 *
 * @param a - parent daemon
 * @param b - daemon
 */
export function mergeDaemons(a: Daemon, b: Daemon): Daemon {
	const
		hook = (a.hook || []).concat(b.hook || []),
		watch = (a.watch || []).concat(b.watch || []);

	return {
		...a,
		...b,
		hook,
		watch
	};
}

{'fraction_non_alphanumeric': 0.14444071212630163, 'fraction_numerical': 0.0026872690628149142, 'mean_word_length': 3.9966442953020134, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, 'https://': 4, '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': '4135583', 'n_tokens_mistral': 1097, 'n_tokens_neox': 1058, 'n_words': 251}