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

import { ComponentInterface, PropOptions, ComponentField, SystemField } from 'core/component/interface';
import { defaultWrapper, NULL } from 'core/component/create/helpers/const';

export interface FieldInfo {
	path: string;
	fullPath: string;
	name: string;
	ctx: ComponentInterface;
	type: 'prop' | 'field' | 'system' | 'computed' | 'accessor';
}

const
	propRgxp = /Prop$/,
	storeRgxp = /Store$/,
	hasSeparator = /\./;

/**
 * Returns an object with component field info by the specified path
 *
 * @param path
 * @param ctx
 */
export function getFieldInfo(path: string, ctx: ComponentInterface): FieldInfo {
	let
		name = path,
		fullPath = path,
		chunks,
		rootI;

	if (hasSeparator.test(path)) {
		chunks = path.split('.');
		rootI = 0;

		let
			obj = ctx;

		for (let i = 0; i < chunks.length; i++) {
			if (!obj) {
				break;
			}

			obj = obj[chunks[i]];

			if (obj && obj.instance instanceof ComponentInterface) {
				ctx = obj;
				rootI = i === chunks.length - 1 ? i : i + 1;
			}
		}

		path = chunks.slice(rootI).join('.');
		name = chunks[rootI];
	}

	const
		// @ts-ignore (access)
		{props, fields, systemFields, computed, accessors} = ctx.meta;

	if (propRgxp.test(name)) {
		return {
			path,
			fullPath,
			name,
			ctx,
			type: 'prop'
		};
	}

	if (storeRgxp.test(name)) {
		if (fields[name]) {
			return {
				path,
				fullPath,
				name,
				ctx,
				type: 'field'
			};
		}

		return {
			path,
			fullPath,
			name,
			ctx,
			type: 'system'
		};
	}

	if (fields[name]) {
		return {
			path,
			fullPath,
			name,
			ctx,
			type: 'field'
		};
	}

	if (props[name]) {
		return {
			path,
			fullPath,
			name,
			ctx,
			type: 'prop'
		};
	}

	if (systemFields[name]) {
		return {
			path,
			fullPath,
			name,
			ctx,
			type: 'system'
		};
	}

	const
		storeName = `${name}Store`;

	if (fields[storeName]) {
		if (chunks) {
			chunks[rootI] = storeName;
			path = chunks.slice(chunks).join('.');
			fullPath = chunks.join('.');
		}

		return {
			path,
			fullPath,
			name,
			ctx,
			type: 'field'
		};
	}

	if (systemFields[storeName]) {
		if (chunks) {
			chunks[rootI] = storeName;
			path = chunks.slice(chunks).join('.');
			fullPath = chunks.join('.');
		}

		return {
			path,
			fullPath,
			name,
			ctx,
			type: 'system'
		};
	}

	const
		propName = `${name}Prop`;

	if (props[propName]) {
		if (chunks) {
			chunks[rootI] = propName;
			path = chunks.slice(chunks).join('.');
			fullPath = chunks.join('.');
		}

		return {
			path,
			fullPath,
			name,
			ctx,
			type: 'prop'<commit_msg>Fixed @watch with getters<commit_after>/*!
 * V4Fire Client Core
 * https://github.com/V4Fire/Client
 *
 * Released under the MIT license
 * https://github.com/V4Fire/Client/blob/master/LICENSE
 */

import { ComponentInterface, PropOptions, ComponentField, SystemField } from 'core/component/interface';
import { defaultWrapper, NULL } from 'core/component/create/helpers/const';

export interface FieldInfo {
	path: string;
	fullPath: string;
	name: string;
	ctx: ComponentInterface;
	type: 'prop' | 'field' | 'system' | 'computed' | 'accessor';
}

const
	propRgxp = /Prop$/,
	storeRgxp = /Store$/,
	hasSeparator = /\./;

/**
 * Returns an object with component field info by the specified path
 *
 * @param path
 * @param ctx
 */
export function getFieldInfo(path: string, ctx: ComponentInterface): FieldInfo {
	let
		name = path,
		fullPath = path,
		chunks,
		rootI;

	if (hasSeparator.test(path)) {
		chunks = path.split('.');
		rootI = 0;

		let
			obj = ctx;

		for (let i = 0; i < chunks.length; i++) {
			if (!obj) {
				break;
			}

			obj = obj[chunks[i]];

			if (obj && obj.instance instanceof ComponentInterface) {
				ctx = obj;
				rootI = i === chunks.length - 1 ? i : i + 1;
			}
		}

		path = chunks.slice(rootI).join('.');
		name = chunks[rootI];
	}

	const
		// @ts-ignore (access)
		{props, fields, systemFields, computed, accessors} = ctx.meta;

	if (propRgxp.test(name)) {
		return {
			path,
			fullPath,
			name,
			ctx,
			type: 'prop'
		};
	}

	if (storeRgxp.test(name)) {
		if (fields[name]) {
			return {
				path,
				fullPath,
				name,
				ctx,
				type: 'field'
			};
		}

		return {
			path,
			fullPath,
			name,
			ctx,
			type: 'system'
		};
	}

	if (fields[name]) {
		return {
			path,
			fullPath,
			name,
			ctx,
			type: 'field'
		};
	}

	if (props[name]) {
		return {
			path,
			fullPath,
			name,
			ctx,
			type: 'prop'
		};
	}

	if (systemFields[name]) {
		return {
			path,
			fullPath,
			name,
			ctx,
			type: 'system'
		};
	}

	const
		storeName = `${name}Store`;

	if (fields[storeName]) {
		name = storeName;

		if (chunks) {
			chunks[rootI] = storeName;
			path = chunks.slice(chunks).join('.');
			fullPath = chunks.join('.');

		} else {
			path = fullPath = storeName;
		}

		return {
			path,
			fullPath,
			name,
			ctx,
			type: 'field'
		};
	}

	if (systemFields[storeName]) {
		name = storeName;

		if (chunks) {
			chunks[rootI] = storeName;
			path = chunks.slice(chunks).join('.');
			fullPath = chunks.join('.');

		} else {
			path = fullPath = storeName;
		}

		return {
			path,
			fullPath,
			name,
			ctx,
			type: 'system'
		};
	}

	const
		propName = `${name}Prop`;

	if (props[propName]) {
		name = propName;

		if (chunks) {
			chunks[rootI] = propName;
			path = chunks.slice(chunks).join('.');
			fullPath = chunks.join('.');

		} else {
			path = fullPath = storeName;
		}

		return {
			path,
			fullPath,
			name: propName,
			ctx,
			type: 'prop'
{'fraction_non_alphanumeric': 0.16094192634560905, 'fraction_numerical': 0.002478753541076487, 'mean_word_length': 2.6327974276527333, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 3, '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': '2546963', 'n_tokens_mistral': 2543, 'n_tokens_neox': 2144, 'n_words': 489}