<commit_before>import _ from 'lodash';
import t from 'tcomb';

export const EntityFieldSchema = t.struct({
	name: t.String,
	type: t.String
});

export const EntitySchema = t.struct({
	name: t.String,
	idFieldName: t.String,
	displayFieldName: t.String,
	isFilterable: t.Boolean,
	fields: t.refinement(
		t.dict(
			t.String,
			EntityFieldSchema
		),
		(dictionary) => {
			return _.every(dictionary, (item, key) => item.name === key);
		},
		'Schema fields dictionary'
	)<commit_msg>fix(entityDescriptors): refine entity field schema types<commit_after>import _ from 'lodash';
import t from 'tcomb';

export const EntityValueFieldSchema = t.struct({
	name: t.String,
	type: t.String
});

export const EntityAssociationFieldSchema = t.struct({
	name: t.String,
	type: t.refinement(t.String, (x) => x === 'association', 'Association type value'),
	collectionName: t.String
});

export const EntityFieldSchema = t.union([EntityValueFieldSchema, EntityAssociationFieldSchema]);
EntityFieldSchema.dispatch = (x) => {
	if(x.type === 'association') {
		return EntityAssociationFieldSchema;
	}
	return EntityValueFieldSchema;
};

export const EntitySchema = t.struct({
	name: t.String,
	idFieldName: t.String,
	displayFieldName: t.String,
	isFilterable: t.Boolean,
	fields: t.refinement(
		t.dict(
			t.String,
			EntityFieldSchema
		),
		(dictionary) => {
			return _.every(dictionary, (item, key) => item.name === key);
		},
		'Schema fields dictionary'
	)
{'fraction_non_alphanumeric': 0.13980716253443526, 'fraction_numerical': 0.0, 'mean_word_length': 4.743083003952569, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 9, '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': '4654581', 'n_tokens_mistral': 513, 'n_tokens_neox': 478, 'n_words': 118}