Skip to content

Commit a6db083

Browse files
committed
Remove Base
1 parent 03a36dd commit a6db083

37 files changed

Lines changed: 71 additions & 1363 deletions

File tree

example/legacy/date.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,30 @@ THE SOFTWARE.
2828

2929
import Type from 'typebox'
3030

31-
// ------------------------------------------------------------------
32-
// Definition
33-
// ------------------------------------------------------------------
34-
export class TDate extends Type.Base<globalThis.Date> {
35-
// required: Used by validation
36-
public override Check(value: unknown): value is globalThis.Date {
37-
return value instanceof globalThis.Date
38-
}
39-
// required: Used by validation
40-
public override Errors(value: unknown): object[] {
41-
return this.Check(value) ? [] : [{ message: 'must be Date' }]
42-
}
43-
// required: Used by type compositor
44-
public override Clone(): TDate {
45-
return new TDate()
46-
}
47-
// required: Used by value/create
48-
public override Create(): globalThis.Date {
49-
return new globalThis.Date(0)
50-
}
51-
}
52-
// ------------------------------------------------------------------
53-
// Factory
54-
// ------------------------------------------------------------------
55-
export function Date(): TDate {
56-
return new TDate()
57-
}
31+
// // ------------------------------------------------------------------
32+
// // Definition
33+
// // ------------------------------------------------------------------
34+
// export class TDate extends Type.Base<globalThis.Date> {
35+
// // required: Used by validation
36+
// public override Check(value: unknown): value is globalThis.Date {
37+
// return value instanceof globalThis.Date
38+
// }
39+
// // required: Used by validation
40+
// public override Errors(value: unknown): object[] {
41+
// return this.Check(value) ? [] : [{ message: 'must be Date' }]
42+
// }
43+
// // required: Used by type compositor
44+
// public override Clone(): TDate {
45+
// return new TDate()
46+
// }
47+
// // required: Used by value/create
48+
// public override Create(): globalThis.Date {
49+
// return new globalThis.Date(0)
50+
// }
51+
// }
52+
// // ------------------------------------------------------------------
53+
// // Factory
54+
// // ------------------------------------------------------------------
55+
// export function Date(): TDate {
56+
// return new TDate()
57+
// }

example/legacy/uint8array.ts

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,30 +28,30 @@ THE SOFTWARE.
2828

2929
import Type from 'typebox'
3030

31-
// ------------------------------------------------------------------
32-
// Definition
33-
// ------------------------------------------------------------------
34-
export class TUint8Array extends Type.Base<globalThis.Uint8Array> {
35-
// required: Used by validation
36-
public override Check(value: unknown): value is Uint8Array {
37-
return value instanceof Uint8Array
38-
}
39-
// required: Used by validation
40-
public override Errors(value: unknown): object[] {
41-
return !this.Check(value) ? [{ message: 'not a Uint8Array'}] : []
42-
}
43-
// required: Used by type compositor
44-
public override Clone(): TUint8Array {
45-
return new TUint8Array()
46-
}
47-
// required: Used by value/create
48-
public override Create(): globalThis.Uint8Array {
49-
return new globalThis.Uint8Array(0)
50-
}
51-
}
52-
// ------------------------------------------------------------------
53-
// Factory
54-
// ------------------------------------------------------------------
55-
export function Uint8Array(): TUint8Array {
56-
return new TUint8Array()
57-
}
31+
// // ------------------------------------------------------------------
32+
// // Definition
33+
// // ------------------------------------------------------------------
34+
// export class TUint8Array extends Type.Base<globalThis.Uint8Array> {
35+
// // required: Used by validation
36+
// public override Check(value: unknown): value is Uint8Array {
37+
// return value instanceof Uint8Array
38+
// }
39+
// // required: Used by validation
40+
// public override Errors(value: unknown): object[] {
41+
// return !this.Check(value) ? [{ message: 'not a Uint8Array'}] : []
42+
// }
43+
// // required: Used by type compositor
44+
// public override Clone(): TUint8Array {
45+
// return new TUint8Array()
46+
// }
47+
// // required: Used by value/create
48+
// public override Create(): globalThis.Uint8Array {
49+
// return new globalThis.Uint8Array(0)
50+
// }
51+
// }
52+
// // ------------------------------------------------------------------
53+
// // Factory
54+
// // ------------------------------------------------------------------
55+
// export function Uint8Array(): TUint8Array {
56+
// return new TUint8Array()
57+
// }

src/compile/validator.ts

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ THE SOFTWARE.
2929
// deno-fmt-ignore-file
3030

3131
import { Settings } from '../system/settings/index.ts'
32-
import { Arguments } from '../system/arguments/index.ts'
3332
import { Environment } from '../system/environment/index.ts'
3433
import { 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'
3635
import { Errors, Clean, Convert, Create, Default, Decode, Encode, HasCodec, Parser, ParseError } from '../value/index.ts'
3736
import { Build } from '../schema/index.ts'
3837

@@ -42,42 +41,22 @@ import { Build } from '../schema/index.ts'
4241
export 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)

src/schema/engine/_guard.ts

Lines changed: 0 additions & 59 deletions
This file was deleted.

src/schema/engine/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,6 @@ THE SOFTWARE.
3131
// ------------------------------------------------------------------
3232
export * from './_context.ts'
3333
export * from './_externals.ts'
34-
export * from './_guard.ts'
3534
export * from './_functions.ts'
3635
export * from './_reducer.ts'
3736
export * from './_refine.ts'

src/schema/engine/schema.ts

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ import * as Schema from '../types/index.ts'
3232
import { Stack } from './_stack.ts'
3333
import { BuildContext, CheckContext, ErrorContext } from './_context.ts'
3434
import { BuildRefine, CheckRefine, ErrorRefine } from './_refine.ts'
35-
import { BuildGuard, CheckGuard, ErrorGuard } from './_guard.ts'
3635

3736
import { EmitGuard as E, Guard as G } from '../../guard/index.ts'
3837

@@ -226,7 +225,6 @@ export function BuildSchema(stack: Stack, context: BuildContext, schema: Schema.
226225
if (Schema.IsRef(schema)) conditions.push(BuildRef(stack, context, schema, value))
227226
if (Schema.IsRecursiveRef(schema)) conditions.push(BuildRecursiveRef(stack, context, schema, value))
228227
if (Schema.IsDynamicRef(schema)) conditions.push(BuildDynamicRef(stack, context, schema, value))
229-
if (Schema.IsGuard(schema)) conditions.push(BuildGuard(stack, context, schema, value))
230228
if (Schema.IsConst(schema)) conditions.push(BuildConst(stack, context, schema, value))
231229
if (Schema.IsEnum(schema)) conditions.push(BuildEnum(stack, context, schema, value))
232230
if (Schema.IsIf(schema)) conditions.push(BuildIf(stack, context, schema, value))
@@ -291,7 +289,6 @@ export function CheckSchema(stack: Stack, context: CheckContext, schema: Schema.
291289
(!Schema.IsRef(schema) || CheckRef(stack, context, schema, value)) &&
292290
(!Schema.IsRecursiveRef(schema) || CheckRecursiveRef(stack, context, schema, value)) &&
293291
(!Schema.IsDynamicRef(schema) || CheckDynamicRef(stack, context, schema, value)) &&
294-
(!Schema.IsGuard(schema) || CheckGuard(stack, context, schema, value)) &&
295292
(!Schema.IsConst(schema) || CheckConst(stack, context, schema, value)) &&
296293
(!Schema.IsEnum(schema) || CheckEnum(stack, context, schema, value)) &&
297294
(!Schema.IsIf(schema) || CheckIf(stack, context, schema, value)) &&
@@ -356,7 +353,6 @@ export function ErrorSchema(stack: Stack, context: ErrorContext, schemaPath: str
356353
+(!Schema.IsRef(schema) || ErrorRef(stack, context, schemaPath, instancePath, schema, value)) &
357354
+(!Schema.IsRecursiveRef(schema) || ErrorRecursiveRef(stack, context, schemaPath, instancePath, schema, value)) &
358355
+(!Schema.IsDynamicRef(schema) || ErrorDynamicRef(stack, context, schemaPath, instancePath, schema, value)) &
359-
+(!Schema.IsGuard(schema) || ErrorGuard(stack, context, schemaPath, instancePath, schema, value)) &
360356
+(!Schema.IsConst(schema) || ErrorConst(stack, context, schemaPath, instancePath, schema, value)) &
361357
+(!Schema.IsEnum(schema) || ErrorEnum(stack, context, schemaPath, instancePath, schema, value)) &
362358
+(!Schema.IsIf(schema) || ErrorIf(stack, context, schemaPath, instancePath, schema, value)) &

src/schema/types/_guard.ts

Lines changed: 0 additions & 57 deletions
This file was deleted.

src/schema/types/index.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@ THE SOFTWARE.
2929
// ------------------------------------------------------------------
3030
// Extensions
3131
// ------------------------------------------------------------------
32-
export * from './_guard.ts'
3332
export * from './_refine.ts'
3433

3534
// ------------------------------------------------------------------

0 commit comments

Comments
 (0)