@@ -29,10 +29,9 @@ THE SOFTWARE.
2929// deno-fmt-ignore-file
3030
3131import { Settings } from '../system/settings/index.ts'
32- import { Arguments } from '../system/arguments/index.ts'
3332import { Environment } from '../system/environment/index.ts'
3433import { type TLocalizedValidationError } from '../error/index.ts'
35- import { type StaticDecode , type StaticEncode , type TProperties , type TSchema , Base } from '../type/index.ts'
34+ import { type StaticDecode , type StaticEncode , type TProperties , type TSchema } from '../type/index.ts'
3635import { Errors , Clean , Convert , Create , Default , Decode , Encode , HasCodec , Parser , ParseError } from '../value/index.ts'
3736import { Build } from '../schema/index.ts'
3837
@@ -42,42 +41,22 @@ import { Build } from '../schema/index.ts'
4241export class Validator < Context extends TProperties = TProperties , Type extends TSchema = TSchema ,
4342 Encode extends unknown = StaticEncode < Type , Context > ,
4443 Decode extends unknown = StaticDecode < Type , Context >
45- > extends Base < Encode > {
44+ > {
4645 private readonly context : Context
4746 private readonly type : Type
4847 private readonly isAccelerated : boolean
4948 private readonly hasCodec : boolean
5049 private readonly code : string
5150 private readonly check : ( value : unknown ) => boolean
5251 /** Constructs a Validator with the given Context and Type. */
53- constructor ( context : Context , type : Type )
54- /** Constructs a Validator with the given arguments. */
55- constructor ( context : Context , type : Type , isEvaluated : boolean , hasCodec : boolean , code : string , check : ( value : unknown ) => boolean )
56- /** Constructs a Validator. */
57- constructor ( ...args : unknown [ ] ) {
58- super ( )
59- const matched : [ Context , Type , boolean , boolean , string , ( value : unknown ) => boolean ] | [ Context , Type ] = Arguments . Match ( args , {
60- 6 : ( context , type , isEvalulated , hasCodec , code , check ) => [ context , type , isEvalulated , hasCodec , code , check ] ,
61- 2 : ( context , type ) => [ context , type ]
62- } )
63- if ( matched . length === 6 ) {
64- const [ context , type , isEvaluated , hasCodec , code , check ] = matched
65- this . context = context
66- this . type = type
67- this . isAccelerated = isEvaluated
68- this . hasCodec = hasCodec
69- this . code = code
70- this . check = check
71- } else {
72- const [ context , type ] = matched as [ Context , Type ]
73- const result = Build ( context , type ) . Evaluate ( )
74- this . hasCodec = HasCodec ( context , type )
75- this . context = context
76- this . type = type
77- this . isAccelerated = result . IsAccelerated
78- this . code = result . Code
79- this . check = result . Check as never
80- }
52+ constructor ( context : Context , type : Type ) {
53+ const result = Build ( context , type ) . Evaluate ( )
54+ this . hasCodec = HasCodec ( context , type )
55+ this . context = context
56+ this . type = type
57+ this . isAccelerated = result . IsAccelerated
58+ this . code = result . Code
59+ this . check = result . Check as never
8160 }
8261 // ----------------------------------------------------------------
8362 // IsAccelerated
@@ -108,41 +87,30 @@ export class Validator<Context extends TProperties = TProperties, Type extends T
10887 // Base<...>
10988 // ----------------------------------------------------------------
11089 /** Performs a type-guard check on the provided value. */
111- public override Check ( value : unknown ) : value is Encode {
90+ public Check ( value : unknown ) : value is Encode {
11291 return this . check ( value )
11392 }
11493 /** Inspects a value and returns a detailed list of validation errors. */
115- public override Errors ( value : unknown ) : TLocalizedValidationError [ ] {
94+ public Errors ( value : unknown ) : TLocalizedValidationError [ ] {
11695 if ( Environment . CanEvaluate ( ) && this . check ( value ) ) return [ ]
11796 return Errors ( this . context , this . type , value )
11897 }
11998 /** Cleans a value using the Validator type. */
120- public override Clean ( value : unknown ) : unknown {
99+ public Clean ( value : unknown ) : unknown {
121100 return Clean ( this . context , this . type , value )
122101 }
123102 /** Converts a value using the Validator type. */
124- public override Convert ( value : unknown ) : unknown {
103+ public Convert ( value : unknown ) : unknown {
125104 return Convert ( this . context , this . type , value )
126105 }
127106 /** Creates a value using the Validator type. */
128- public override Create ( ) : Encode {
107+ public Create ( ) : Encode {
129108 return Create ( this . context , this . type )
130109 }
131110 /** Creates defaults using the Validator type. */
132- public override Default ( value : unknown ) : unknown {
111+ public Default ( value : unknown ) : unknown {
133112 return Default ( this . context , this . type , value )
134113 }
135- /** Clones this validator. */
136- public override Clone ( ) : Validator < Context , Type > {
137- return new Validator < Context , Type > (
138- this . context ,
139- this . type ,
140- this . isAccelerated ,
141- this . hasCodec ,
142- this . code ,
143- this . check
144- )
145- }
146114 /** Validates a value and returns it. Will throw if invalid. */
147115 public Parse ( value : unknown ) : Encode {
148116 const checked = this . Check ( value )
0 commit comments