@@ -20,7 +20,8 @@ declare module 'fastest-validator' {
2020 | 'object'
2121 | 'string'
2222 | 'url'
23- | 'uuid' ;
23+ | 'uuid'
24+ | string ;
2425
2526 /**
2627 * Validation schema definition for "any" built-in validator
@@ -62,15 +63,15 @@ declare module 'fastest-validator' {
6263 /**
6364 * The array must contain this element too
6465 */
65- contains ?: T [ ] ;
66+ contains ?: T | T [ ] ;
6667 /**
6768 * Every element must be an element of the enum array
6869 */
6970 enum ?: T [ ] ;
7071 /**
7172 * Validation rules that should be applied to each element of array
7273 */
73- items : ValidationRule ;
74+ items ? : ValidationRule ;
7475 }
7576
7677 /**
@@ -439,7 +440,7 @@ declare module 'fastest-validator' {
439440 /**
440441 * Default value
441442 */
442- default : any ;
443+ default ? : any ;
443444
444445 /**
445446 * You can define any additional options for custom validators
@@ -679,7 +680,7 @@ declare module 'fastest-validator' {
679680 /**
680681 * Description of validation rule definition for a some property
681682 */
682- type ValidationRule = ValidationRuleObject | ValidationRuleObject [ ] | ValidationRuleName | string ;
683+ type ValidationRule = ValidationRuleObject | ValidationRuleObject [ ] | ValidationRuleName ;
683684
684685 /**
685686 * Definition for validation schema based on validation rules
@@ -707,7 +708,7 @@ declare module 'fastest-validator' {
707708 /**
708709 * Name of validation rule that generates this message
709710 */
710- type : ValidationRuleName | string ;
711+ type : ValidationRuleName ;
711712 /**
712713 * Field that catch validation error
713714 */
@@ -738,6 +739,16 @@ declare module 'fastest-validator' {
738739 } ;
739740
740741 class Validator {
742+ /**
743+ * List of possible error messages
744+ */
745+ messages : MessagesType ;
746+
747+ /**
748+ * List of rules attached to current validator
749+ */
750+ rules : { [ key : string ] : ValidationRuleObject } ;
751+
741752 /**
742753 * Constructor of validation class
743754 * @param {ValidatorConstructorOptions } opts List of possible validator constructor options
@@ -753,19 +764,22 @@ declare module 'fastest-validator' {
753764
754765 /**
755766 * Build error message
756- * @param {string } type Name of validation rule (equal to "type" option)
757- * @param {{any} } [expected] Expected value for validation rule
758- * @param {{any} } [actual] Actual value received to validation
759767 * @return {ValidationError }
768+ * @param {Object } opts
769+ * @param {String } opts.type
770+ * @param {String } opts.field
771+ * @param {any= } opts.expected
772+ * @param {any= } opts.actual
773+ * @param {MessagesType } opts.messages
760774 */
761- makeError ( type : keyof BuiltInMessages | string , expected ?: any , actual ?: any ) : ValidationError ;
775+ makeError ( opts : { type : keyof MessagesType , field ?: string , expected ?: any , actual ?: any , messages : MessagesType } ) : ValidationError ;
762776
763777 /**
764778 * Compile validator functiona that working up 100 times faster that native validation process
765779 * @param {ValidationSchema | ValidationSchema[] } schema Validation schema definition that should be used for validation
766780 * @return {(object: object) => (true | ValidationError[]) } function that can be used next for validation of current schema
767781 */
768- compile ( schema : ValidationSchema | ValidationSchema [ ] ) : ( object : object ) => true | ValidationError [ ] ;
782+ compile ( schema : ValidationSchema | ValidationSchema [ ] ) : ( object : any ) => true | ValidationError [ ] ;
769783
770784 /**
771785 * Native validation method to validate obj
@@ -774,6 +788,13 @@ declare module 'fastest-validator' {
774788 * @return {{true} | ValidationError[] }
775789 */
776790 validate ( obj : object , schema : ValidationSchema ) : true | ValidationError [ ] ;
791+
792+ /**
793+ * Get defined in validator rule
794+ * @param {ValidationRuleName | ValidationRuleName[] } name List or name of defined rule
795+ * @return {ValidationRule }
796+ */
797+ getRuleFromSchema ( name : ValidationRuleName | ValidationRuleName [ ] ) : { messages : MessagesType , schema : ValidationSchema , ruleFunction : Function }
777798 }
778799
779800 export {
0 commit comments