import { IExplanation } from "../../explanations" ; import { CompilationResult , TSchema , Validator } from "../../types" ; import { getExplanator } from "./getExplanator" ; export function eCompileSchema < T = any > ( schema ) { const explanator = getExplanator ( schema ) ; const explanations = [ ] ; function validator ( value ) { const explanationsOrNull = explanator ( value , [ ] ) ; if ( explanationsOrNull ) { ( ( validator as unknown ) as CompilationResult < T , IExplanation > ) . explanations = explanationsOrNull ; return false ; } else { ( ( validator as unknown ) as CompilationResult < T , IExplanation > ) . explanations = [ ] ; return true ; } } return Object . assign ( validator as Validator < T > , { explanations } ) ; }