typebox 1.1.4 → 1.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -15,13 +15,13 @@ export declare class Validator<Context extends TProperties = TProperties, Type e
|
|
|
15
15
|
IsAccelerated(): boolean;
|
|
16
16
|
/** Returns the Context for this validator. */
|
|
17
17
|
Context(): Context;
|
|
18
|
-
/** Returns the Type
|
|
18
|
+
/** Returns the underlying Type used to construct this Validator. */
|
|
19
19
|
Type(): Type;
|
|
20
20
|
/** Returns the generated code for this validator. */
|
|
21
21
|
Code(): string;
|
|
22
|
-
/**
|
|
22
|
+
/** Performs a type-guard check on the provided value. */
|
|
23
23
|
Check(value: unknown): value is Encode;
|
|
24
|
-
/**
|
|
24
|
+
/** Inspects a value and returns a detailed list of validation errors. */
|
|
25
25
|
Errors(value: unknown): TLocalizedValidationError[];
|
|
26
26
|
/** Cleans a value using the Validator type. */
|
|
27
27
|
Clean(value: unknown): unknown;
|
|
@@ -33,7 +33,7 @@ export declare class Validator<Context extends TProperties = TProperties, Type e
|
|
|
33
33
|
Default(value: unknown): unknown;
|
|
34
34
|
/** Clones this validator. */
|
|
35
35
|
Clone(): Validator<Context, Type>;
|
|
36
|
-
/**
|
|
36
|
+
/** Validates a value and returns it. Will throw if invalid. */
|
|
37
37
|
Parse(value: unknown): Encode;
|
|
38
38
|
/** Decodes a value */
|
|
39
39
|
Decode(value: unknown): Decode;
|
|
@@ -50,7 +50,7 @@ export class Validator extends Base {
|
|
|
50
50
|
Context() {
|
|
51
51
|
return this.context;
|
|
52
52
|
}
|
|
53
|
-
/** Returns the Type
|
|
53
|
+
/** Returns the underlying Type used to construct this Validator. */
|
|
54
54
|
Type() {
|
|
55
55
|
return this.type;
|
|
56
56
|
}
|
|
@@ -64,11 +64,11 @@ export class Validator extends Base {
|
|
|
64
64
|
// ----------------------------------------------------------------
|
|
65
65
|
// Base<...>
|
|
66
66
|
// ----------------------------------------------------------------
|
|
67
|
-
/**
|
|
67
|
+
/** Performs a type-guard check on the provided value. */
|
|
68
68
|
Check(value) {
|
|
69
69
|
return this.check(value);
|
|
70
70
|
}
|
|
71
|
-
/**
|
|
71
|
+
/** Inspects a value and returns a detailed list of validation errors. */
|
|
72
72
|
Errors(value) {
|
|
73
73
|
if (Environment.CanAccelerate() && this.check(value))
|
|
74
74
|
return [];
|
|
@@ -94,7 +94,7 @@ export class Validator extends Base {
|
|
|
94
94
|
Clone() {
|
|
95
95
|
return new Validator(this.context, this.type, this.isAccelerated, this.hasCodec, this.code, this.check);
|
|
96
96
|
}
|
|
97
|
-
/**
|
|
97
|
+
/** Validates a value and returns it. Will throw if invalid. */
|
|
98
98
|
Parse(value) {
|
|
99
99
|
const checked = this.Check(value);
|
|
100
100
|
if (checked)
|
|
@@ -7,11 +7,13 @@ export declare class Validator<Schema extends Schema.XSchema = Schema.XSchema, V
|
|
|
7
7
|
constructor(context: Record<string, Schema.XSchema>, schema: Schema);
|
|
8
8
|
/** Returns true if this Validator is using JIT acceleration. */
|
|
9
9
|
IsAccelerated(): boolean;
|
|
10
|
-
/**
|
|
10
|
+
/** Returns the underlying Schema used to construct this Validator. */
|
|
11
|
+
Schema(): Schema;
|
|
12
|
+
/** Performs a type-guard check on the provided value. */
|
|
11
13
|
Check(value: unknown): value is Value;
|
|
12
|
-
/**
|
|
14
|
+
/** Validates a value and returns it. Will throw if invalid. */
|
|
13
15
|
Parse(value: unknown): Value;
|
|
14
|
-
/**
|
|
16
|
+
/** Inspects a value and returns a detailed list of validation errors. */
|
|
15
17
|
Errors(value: unknown): [result: boolean, errors: TLocalizedValidationError[]];
|
|
16
18
|
}
|
|
17
19
|
/** Compiles this schema into a high performance Validator */
|
package/build/schema/compile.mjs
CHANGED
|
@@ -16,18 +16,22 @@ export class Validator {
|
|
|
16
16
|
IsAccelerated() {
|
|
17
17
|
return this.result.IsAccelerated;
|
|
18
18
|
}
|
|
19
|
-
/**
|
|
19
|
+
/** Returns the underlying Schema used to construct this Validator. */
|
|
20
|
+
Schema() {
|
|
21
|
+
return this.build.Schema();
|
|
22
|
+
}
|
|
23
|
+
/** Performs a type-guard check on the provided value. */
|
|
20
24
|
Check(value) {
|
|
21
25
|
return this.result.Check(value);
|
|
22
26
|
}
|
|
23
|
-
/**
|
|
27
|
+
/** Validates a value and returns it. Will throw if invalid. */
|
|
24
28
|
Parse(value) {
|
|
25
29
|
if (this.result.Check(value))
|
|
26
30
|
return value;
|
|
27
31
|
const [_result, errors] = Errors(this.build.Context(), this.build.Schema(), value);
|
|
28
32
|
throw new ParseError(this.build.Schema(), value, errors);
|
|
29
33
|
}
|
|
30
|
-
/**
|
|
34
|
+
/** Inspects a value and returns a detailed list of validation errors. */
|
|
31
35
|
Errors(value) {
|
|
32
36
|
return Errors(this.build.Context(), this.build.Schema(), value);
|
|
33
37
|
}
|