typebox 1.1.3 → 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)
|
|
@@ -1,17 +1,19 @@
|
|
|
1
1
|
import { type TLocalizedValidationError } from '../error/index.mjs';
|
|
2
2
|
import * as Schema from './types/index.mjs';
|
|
3
3
|
import * as Static from './static/index.mjs';
|
|
4
|
-
export declare class Validator<Schema extends Schema.XSchema, Value extends unknown = Static.XStatic<Schema>> {
|
|
4
|
+
export declare class Validator<Schema extends Schema.XSchema = Schema.XSchema, Value extends unknown = Static.XStatic<Schema>> {
|
|
5
5
|
private readonly build;
|
|
6
6
|
private readonly result;
|
|
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
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
type TEscape0<Index extends string> = Index extends `${infer Left}~0${infer Right}` ? `${Left}~${TEscape<Right>}` : Index;
|
|
2
2
|
type TEscape1<Index extends string> = Index extends `${infer Left}~1${infer Right}` ? `${Left}/${TEscape<Right>}` : Index;
|
|
3
3
|
type TEscape<Index extends string, Escaped0 extends string = TEscape0<Index>, Escaped1 extends string = TEscape1<Escaped0>> = Escaped1;
|
|
4
|
-
type IndicesReduce<Pointer extends string, Result extends string[] = []> = Pointer extends `${infer Left extends string}/${infer Right extends string}` ? Left extends '' ? IndicesReduce<Right, Result> : IndicesReduce<Right, [...Result, TEscape<Left>]> : [...Result, TEscape<Pointer>];
|
|
4
|
+
type IndicesReduce<Pointer extends string, Result extends string[] = []> = (Pointer extends `${infer Left extends string}/${infer Right extends string}` ? Left extends '' ? IndicesReduce<Right, Result> : IndicesReduce<Right, [...Result, TEscape<Left>]> : [...Result, TEscape<Pointer>]);
|
|
5
5
|
type TIndices<Pointer extends string, Result extends string[] = Pointer extends '' ? [] : IndicesReduce<Pointer>> = Result;
|
|
6
|
-
type TResolve<Value extends unknown, Indices extends string[]> = Indices extends [infer Left extends string, ...infer Right extends string[]] ? Left extends keyof Value ? TResolve<Value[Left], Right> : undefined : Value;
|
|
6
|
+
type TResolve<Value extends unknown, Indices extends string[]> = (Indices extends [infer Left extends string, ...infer Right extends string[]] ? Left extends keyof Value ? TResolve<Value[Left], Right> : undefined : Value);
|
|
7
7
|
/** Type Level RFC 6901 Json Pointer Resolver */
|
|
8
8
|
export type XPointerGet<Value extends unknown, Pointer extends string, Indices extends string[] = TIndices<Pointer>, Result extends unknown = TResolve<Value, Indices>> = Result;
|
|
9
9
|
export {};
|