<commit_before>﻿module Foundation.ViewModel.Implementations {

    export class DtoRules<TDto extends Model.Contracts.IDto> {

        private _model: TDto;

        public get model(): TDto {
            return this._model;
        }

        public set model(value: TDto) {
            this._model = value;
        }

        public validateMember(memberName: keyof TDto, newValue: any, oldValue: any): void {

        }

        public setMemberValidaty: (memberName: keyof TDto, errorKey: string, isValid: boolean) => void;
    }

}<commit_msg>Dto rules now apply required & regex of jaydata (from dto metadata & dto attributes) by its own.<commit_after>﻿module Foundation.ViewModel.Implementations {

    export class DtoRules<TDto extends Model.Contracts.IDto> {

        private _model: TDto;

        public get model(): TDto {
            return this._model;
        }

        public set model(value: TDto) {
            this._model = value;
        }

        public validateMember(memberName: keyof TDto, newValue: any, oldValue: any): void {
            let modelIsValid = this.model.isValid();
            let type = this.model.getType();
            let memberDefs = type.memberDefinitions;
            if (memberDefs[`$${memberName}`].required == true) {
                this.setMemberValidaty(memberName, 'required', modelIsValid == true || this.model['ValidationErrors'] == null || this.model['ValidationErrors'].find(v => v.Type == 'required' && v.PropertyDefinition.name == memberName) == null);
            }
            if (memberDefs[`$${memberName}`].regex == true) {
                this.setMemberValidaty(memberName, 'pattern', modelIsValid == true || this.model['ValidationErrors'] == null || this.model['ValidationErrors'].find(v => v.Type == 'regex' && v.PropertyDefinition.name == memberName) == null);
            }
        }

        public setMemberValidaty: (memberName: keyof TDto, errorKey: string, isValid: boolean) => void;

        public async onActivated(): Promise<void> {

        }
    }

}
{'fraction_non_alphanumeric': 0.1224188790560472, 'fraction_numerical': 0.0, 'mean_word_length': 2.5764499121265376, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 10, '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': '3144090', 'n_tokens_mistral': 574, 'n_tokens_neox': 559, 'n_words': 140}