diff --git a/src/compiler/compiler.ts b/src/compiler/compiler.ts index 9e840ca92..361b40cdb 100644 --- a/src/compiler/compiler.ts +++ b/src/compiler/compiler.ts @@ -26,7 +26,6 @@ THE SOFTWARE. ---------------------------------------------------------------------------*/ -import { EncodeTransform, DecodeTransform, HasTransform, TransformDecodeCheckError, TransformEncodeCheckError } from '../value/transform' import { IsArray, IsString, IsNumber, IsBigInt } from '../value/guard' import { Errors, ValueErrorIterator } from '../errors/errors' import { TypeSystemPolicy } from '../system/index' @@ -42,10 +41,7 @@ export type CheckFunction = (value: unknown) => boolean // TypeCheck // ------------------------------------------------------------------- export class TypeCheck { - private readonly hasTransform: boolean - constructor(private readonly schema: T, private readonly references: Types.TSchema[], private readonly checkFunc: CheckFunction, private readonly code: string) { - this.hasTransform = HasTransform.Has(schema, references) - } + constructor(private readonly schema: T, private readonly references: Types.TSchema[], private readonly checkFunc: CheckFunction, private readonly code: string) {} /** Returns the generated assertion code used to validate this type. */ public Code(): string { return this.code @@ -58,17 +54,6 @@ export class TypeCheck { public Check(value: unknown): value is Types.Static { return this.checkFunc(value) } - /** Decodes a value or throws if error */ - public Decode(value: unknown): Types.StaticDecode { - if (!this.checkFunc(value)) throw new TransformDecodeCheckError(this.schema, value, this.Errors(value).First()!) - return this.hasTransform ? DecodeTransform.Decode(this.schema, this.references, value, (_, __, value) => this.Check(value)) : value - } - /** Encodes a value or throws if error */ - public Encode(value: unknown): Types.StaticEncode { - const encoded = this.hasTransform ? EncodeTransform.Encode(this.schema, this.references, value, (_, __, value) => this.Check(value)) : value - if (!this.checkFunc(encoded)) throw new TransformEncodeCheckError(this.schema, value, this.Errors(value).First()!) - return encoded - } } // ------------------------------------------------------------------- // Character