@sinclair/typebox 0.32.0-dev-25 → 0.32.0-dev-26
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.
- package/build/import/errors/errors.mjs +2 -2
- package/build/import/errors/function.d.mts +13 -3
- package/build/import/errors/function.mjs +39 -39
- package/build/import/type/indexed/indexed-from-mapped-result.d.mts +1 -1
- package/build/import/type/indexed/indexed-from-mapped-result.mjs +1 -1
- package/build/require/errors/errors.js +2 -2
- package/build/require/errors/function.d.ts +13 -3
- package/build/require/errors/function.js +39 -39
- package/build/require/type/indexed/indexed-from-mapped-result.d.ts +1 -1
- package/build/require/type/indexed/indexed-from-mapped-result.js +1 -1
- package/package.json +1 -1
- package/readme.md +6 -6
|
@@ -124,8 +124,8 @@ export class ValueErrorIterator {
|
|
|
124
124
|
// --------------------------------------------------------------------------
|
|
125
125
|
// Create
|
|
126
126
|
// --------------------------------------------------------------------------
|
|
127
|
-
function Create(
|
|
128
|
-
return { type, schema, path, value, message: GetErrorFunction()(schema,
|
|
127
|
+
function Create(errorType, schema, path, value) {
|
|
128
|
+
return { type: errorType, schema, path, value, message: GetErrorFunction()({ errorType, path, schema, value }) };
|
|
129
129
|
}
|
|
130
130
|
// --------------------------------------------------------------------------
|
|
131
131
|
// Types
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { TSchema } from '../type/schema/index.mjs';
|
|
2
2
|
import { ValueErrorType } from './errors.mjs';
|
|
3
3
|
/** Creates an error message using en-US as the default locale */
|
|
4
|
-
export declare function DefaultErrorFunction(
|
|
5
|
-
export type
|
|
6
|
-
/**
|
|
4
|
+
export declare function DefaultErrorFunction(error: ErrorFunctionParameter): string;
|
|
5
|
+
export type ErrorFunctionParameter = {
|
|
6
|
+
/** The type of validation error */
|
|
7
|
+
errorType: ValueErrorType;
|
|
8
|
+
/** The path of the error */
|
|
9
|
+
path: string;
|
|
10
|
+
/** The schema associated with the error */
|
|
11
|
+
schema: TSchema;
|
|
12
|
+
/** The value associated with the error */
|
|
13
|
+
value: unknown;
|
|
14
|
+
};
|
|
15
|
+
export type ErrorFunction = (parameter: ErrorFunctionParameter) => string;
|
|
16
|
+
/** Sets the error function used to generate error messages. */
|
|
7
17
|
export declare function SetErrorFunction(callback: ErrorFunction): void;
|
|
8
18
|
/** Gets the error function used to generate error messages */
|
|
9
19
|
export declare function GetErrorFunction(): ErrorFunction;
|
|
@@ -1,18 +1,18 @@
|
|
|
1
1
|
import { Kind } from '../type/symbols/index.mjs';
|
|
2
2
|
import { ValueErrorType } from './errors.mjs';
|
|
3
3
|
/** Creates an error message using en-US as the default locale */
|
|
4
|
-
export function DefaultErrorFunction(
|
|
5
|
-
switch (errorType) {
|
|
4
|
+
export function DefaultErrorFunction(error) {
|
|
5
|
+
switch (error.errorType) {
|
|
6
6
|
case ValueErrorType.ArrayContains:
|
|
7
7
|
return 'Expected array to contain at least one matching value';
|
|
8
8
|
case ValueErrorType.ArrayMaxContains:
|
|
9
|
-
return `Expected array to contain no more than ${schema.maxContains} matching values`;
|
|
9
|
+
return `Expected array to contain no more than ${error.schema.maxContains} matching values`;
|
|
10
10
|
case ValueErrorType.ArrayMinContains:
|
|
11
|
-
return `Expected array to contain at least ${schema.minContains} matching values`;
|
|
11
|
+
return `Expected array to contain at least ${error.schema.minContains} matching values`;
|
|
12
12
|
case ValueErrorType.ArrayMaxItems:
|
|
13
|
-
return `Expected array length to be less or equal to ${schema.maxItems}`;
|
|
13
|
+
return `Expected array length to be less or equal to ${error.schema.maxItems}`;
|
|
14
14
|
case ValueErrorType.ArrayMinItems:
|
|
15
|
-
return `Expected array length to be greater or equal to ${schema.minItems}`;
|
|
15
|
+
return `Expected array length to be greater or equal to ${error.schema.minItems}`;
|
|
16
16
|
case ValueErrorType.ArrayUniqueItems:
|
|
17
17
|
return 'Expected array elements to be unique';
|
|
18
18
|
case ValueErrorType.Array:
|
|
@@ -20,43 +20,43 @@ export function DefaultErrorFunction(schema, errorType) {
|
|
|
20
20
|
case ValueErrorType.AsyncIterator:
|
|
21
21
|
return 'Expected AsyncIterator';
|
|
22
22
|
case ValueErrorType.BigIntExclusiveMaximum:
|
|
23
|
-
return `Expected bigint to be less than ${schema.exclusiveMaximum}`;
|
|
23
|
+
return `Expected bigint to be less than ${error.schema.exclusiveMaximum}`;
|
|
24
24
|
case ValueErrorType.BigIntExclusiveMinimum:
|
|
25
|
-
return `Expected bigint to be greater than ${schema.exclusiveMinimum}`;
|
|
25
|
+
return `Expected bigint to be greater than ${error.schema.exclusiveMinimum}`;
|
|
26
26
|
case ValueErrorType.BigIntMaximum:
|
|
27
|
-
return `Expected bigint to be less or equal to ${schema.maximum}`;
|
|
27
|
+
return `Expected bigint to be less or equal to ${error.schema.maximum}`;
|
|
28
28
|
case ValueErrorType.BigIntMinimum:
|
|
29
|
-
return `Expected bigint to be greater or equal to ${schema.minimum}`;
|
|
29
|
+
return `Expected bigint to be greater or equal to ${error.schema.minimum}`;
|
|
30
30
|
case ValueErrorType.BigIntMultipleOf:
|
|
31
|
-
return `Expected bigint to be a multiple of ${schema.multipleOf}`;
|
|
31
|
+
return `Expected bigint to be a multiple of ${error.schema.multipleOf}`;
|
|
32
32
|
case ValueErrorType.BigInt:
|
|
33
33
|
return 'Expected bigint';
|
|
34
34
|
case ValueErrorType.Boolean:
|
|
35
35
|
return 'Expected boolean';
|
|
36
36
|
case ValueErrorType.DateExclusiveMinimumTimestamp:
|
|
37
|
-
return `Expected Date timestamp to be greater than ${schema.exclusiveMinimumTimestamp}`;
|
|
37
|
+
return `Expected Date timestamp to be greater than ${error.schema.exclusiveMinimumTimestamp}`;
|
|
38
38
|
case ValueErrorType.DateExclusiveMaximumTimestamp:
|
|
39
|
-
return `Expected Date timestamp to be less than ${schema.exclusiveMaximumTimestamp}`;
|
|
39
|
+
return `Expected Date timestamp to be less than ${error.schema.exclusiveMaximumTimestamp}`;
|
|
40
40
|
case ValueErrorType.DateMinimumTimestamp:
|
|
41
|
-
return `Expected Date timestamp to be greater or equal to ${schema.minimumTimestamp}`;
|
|
41
|
+
return `Expected Date timestamp to be greater or equal to ${error.schema.minimumTimestamp}`;
|
|
42
42
|
case ValueErrorType.DateMaximumTimestamp:
|
|
43
|
-
return `Expected Date timestamp to be less or equal to ${schema.maximumTimestamp}`;
|
|
43
|
+
return `Expected Date timestamp to be less or equal to ${error.schema.maximumTimestamp}`;
|
|
44
44
|
case ValueErrorType.DateMultipleOfTimestamp:
|
|
45
|
-
return `Expected Date timestamp to be a multiple of ${schema.multipleOfTimestamp}`;
|
|
45
|
+
return `Expected Date timestamp to be a multiple of ${error.schema.multipleOfTimestamp}`;
|
|
46
46
|
case ValueErrorType.Date:
|
|
47
47
|
return 'Expected Date';
|
|
48
48
|
case ValueErrorType.Function:
|
|
49
49
|
return 'Expected function';
|
|
50
50
|
case ValueErrorType.IntegerExclusiveMaximum:
|
|
51
|
-
return `Expected integer to be less than ${schema.exclusiveMaximum}`;
|
|
51
|
+
return `Expected integer to be less than ${error.schema.exclusiveMaximum}`;
|
|
52
52
|
case ValueErrorType.IntegerExclusiveMinimum:
|
|
53
|
-
return `Expected integer to be greater than ${schema.exclusiveMinimum}`;
|
|
53
|
+
return `Expected integer to be greater than ${error.schema.exclusiveMinimum}`;
|
|
54
54
|
case ValueErrorType.IntegerMaximum:
|
|
55
|
-
return `Expected integer to be less or equal to ${schema.maximum}`;
|
|
55
|
+
return `Expected integer to be less or equal to ${error.schema.maximum}`;
|
|
56
56
|
case ValueErrorType.IntegerMinimum:
|
|
57
|
-
return `Expected integer to be greater or equal to ${schema.minimum}`;
|
|
57
|
+
return `Expected integer to be greater or equal to ${error.schema.minimum}`;
|
|
58
58
|
case ValueErrorType.IntegerMultipleOf:
|
|
59
|
-
return `Expected integer to be a multiple of ${schema.multipleOf}`;
|
|
59
|
+
return `Expected integer to be a multiple of ${error.schema.multipleOf}`;
|
|
60
60
|
case ValueErrorType.Integer:
|
|
61
61
|
return 'Expected integer';
|
|
62
62
|
case ValueErrorType.IntersectUnevaluatedProperties:
|
|
@@ -66,7 +66,7 @@ export function DefaultErrorFunction(schema, errorType) {
|
|
|
66
66
|
case ValueErrorType.Iterator:
|
|
67
67
|
return 'Expected Iterator';
|
|
68
68
|
case ValueErrorType.Literal:
|
|
69
|
-
return `Expected ${typeof schema.const === 'string' ? `'${schema.const}'` : schema.const}`;
|
|
69
|
+
return `Expected ${typeof error.schema.const === 'string' ? `'${error.schema.const}'` : error.schema.const}`;
|
|
70
70
|
case ValueErrorType.Never:
|
|
71
71
|
return 'Never';
|
|
72
72
|
case ValueErrorType.Not:
|
|
@@ -74,15 +74,15 @@ export function DefaultErrorFunction(schema, errorType) {
|
|
|
74
74
|
case ValueErrorType.Null:
|
|
75
75
|
return 'Expected null';
|
|
76
76
|
case ValueErrorType.NumberExclusiveMaximum:
|
|
77
|
-
return `Expected number to be less than ${schema.exclusiveMaximum}`;
|
|
77
|
+
return `Expected number to be less than ${error.schema.exclusiveMaximum}`;
|
|
78
78
|
case ValueErrorType.NumberExclusiveMinimum:
|
|
79
|
-
return `Expected number to be greater than ${schema.exclusiveMinimum}`;
|
|
79
|
+
return `Expected number to be greater than ${error.schema.exclusiveMinimum}`;
|
|
80
80
|
case ValueErrorType.NumberMaximum:
|
|
81
|
-
return `Expected number to be less or equal to ${schema.maximum}`;
|
|
81
|
+
return `Expected number to be less or equal to ${error.schema.maximum}`;
|
|
82
82
|
case ValueErrorType.NumberMinimum:
|
|
83
|
-
return `Expected number to be greater or equal to ${schema.minimum}`;
|
|
83
|
+
return `Expected number to be greater or equal to ${error.schema.minimum}`;
|
|
84
84
|
case ValueErrorType.NumberMultipleOf:
|
|
85
|
-
return `Expected number to be a multiple of ${schema.multipleOf}`;
|
|
85
|
+
return `Expected number to be a multiple of ${error.schema.multipleOf}`;
|
|
86
86
|
case ValueErrorType.Number:
|
|
87
87
|
return 'Expected number';
|
|
88
88
|
case ValueErrorType.Object:
|
|
@@ -90,35 +90,35 @@ export function DefaultErrorFunction(schema, errorType) {
|
|
|
90
90
|
case ValueErrorType.ObjectAdditionalProperties:
|
|
91
91
|
return 'Unexpected property';
|
|
92
92
|
case ValueErrorType.ObjectMaxProperties:
|
|
93
|
-
return `Expected object to have no more than ${schema.maxProperties} properties`;
|
|
93
|
+
return `Expected object to have no more than ${error.schema.maxProperties} properties`;
|
|
94
94
|
case ValueErrorType.ObjectMinProperties:
|
|
95
|
-
return `Expected object to have at least ${schema.minProperties} properties`;
|
|
95
|
+
return `Expected object to have at least ${error.schema.minProperties} properties`;
|
|
96
96
|
case ValueErrorType.ObjectRequiredProperty:
|
|
97
97
|
return 'Required property';
|
|
98
98
|
case ValueErrorType.Promise:
|
|
99
99
|
return 'Expected Promise';
|
|
100
100
|
case ValueErrorType.StringFormatUnknown:
|
|
101
|
-
return `Unknown format '${schema.format}'`;
|
|
101
|
+
return `Unknown format '${error.schema.format}'`;
|
|
102
102
|
case ValueErrorType.StringFormat:
|
|
103
|
-
return `Expected string to match '${schema.format}' format`;
|
|
103
|
+
return `Expected string to match '${error.schema.format}' format`;
|
|
104
104
|
case ValueErrorType.StringMaxLength:
|
|
105
|
-
return `Expected string length less or equal to ${schema.maxLength}`;
|
|
105
|
+
return `Expected string length less or equal to ${error.schema.maxLength}`;
|
|
106
106
|
case ValueErrorType.StringMinLength:
|
|
107
|
-
return `Expected string length greater or equal to ${schema.minLength}`;
|
|
107
|
+
return `Expected string length greater or equal to ${error.schema.minLength}`;
|
|
108
108
|
case ValueErrorType.StringPattern:
|
|
109
|
-
return `Expected string to match '${schema.pattern}'`;
|
|
109
|
+
return `Expected string to match '${error.schema.pattern}'`;
|
|
110
110
|
case ValueErrorType.String:
|
|
111
111
|
return 'Expected string';
|
|
112
112
|
case ValueErrorType.Symbol:
|
|
113
113
|
return 'Expected symbol';
|
|
114
114
|
case ValueErrorType.TupleLength:
|
|
115
|
-
return `Expected tuple to have ${schema.maxItems || 0} elements`;
|
|
115
|
+
return `Expected tuple to have ${error.schema.maxItems || 0} elements`;
|
|
116
116
|
case ValueErrorType.Tuple:
|
|
117
117
|
return 'Expected tuple';
|
|
118
118
|
case ValueErrorType.Uint8ArrayMaxByteLength:
|
|
119
|
-
return `Expected byte length less or equal to ${schema.maxByteLength}`;
|
|
119
|
+
return `Expected byte length less or equal to ${error.schema.maxByteLength}`;
|
|
120
120
|
case ValueErrorType.Uint8ArrayMinByteLength:
|
|
121
|
-
return `Expected byte length greater or equal to ${schema.minByteLength}`;
|
|
121
|
+
return `Expected byte length greater or equal to ${error.schema.minByteLength}`;
|
|
122
122
|
case ValueErrorType.Uint8Array:
|
|
123
123
|
return 'Expected Uint8Array';
|
|
124
124
|
case ValueErrorType.Undefined:
|
|
@@ -128,14 +128,14 @@ export function DefaultErrorFunction(schema, errorType) {
|
|
|
128
128
|
case ValueErrorType.Void:
|
|
129
129
|
return 'Expected void';
|
|
130
130
|
case ValueErrorType.Kind:
|
|
131
|
-
return `Expected kind '${schema[Kind]}'`;
|
|
131
|
+
return `Expected kind '${error.schema[Kind]}'`;
|
|
132
132
|
default:
|
|
133
133
|
return 'Unknown error type';
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
/** Manages error message providers */
|
|
137
137
|
let errorFunction = DefaultErrorFunction;
|
|
138
|
-
/** Sets the error function used to generate error messages */
|
|
138
|
+
/** Sets the error function used to generate error messages. */
|
|
139
139
|
export function SetErrorFunction(callback) {
|
|
140
140
|
errorFunction = callback;
|
|
141
141
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index.mjs';
|
|
2
2
|
import type { TProperties } from '../object/index.mjs';
|
|
3
3
|
import { type TMappedResult } from '../mapped/index.mjs';
|
|
4
|
+
import { type TIndexPropertyKeys } from './indexed-property-keys.mjs';
|
|
4
5
|
import { type TIndex } from './index.mjs';
|
|
5
|
-
import { TIndexPropertyKeys } from './indexed-property-keys.mjs';
|
|
6
6
|
type TFromProperties<T extends TSchema, P extends TProperties> = ({
|
|
7
7
|
[K2 in keyof P]: TIndex<T, TIndexPropertyKeys<P[K2]>>;
|
|
8
8
|
});
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MappedResult } from '../mapped/index.mjs';
|
|
2
|
-
import { Index } from './index.mjs';
|
|
3
2
|
import { IndexPropertyKeys } from './indexed-property-keys.mjs';
|
|
3
|
+
import { Index } from './index.mjs';
|
|
4
4
|
// prettier-ignore
|
|
5
5
|
function FromProperties(T, P, options) {
|
|
6
6
|
return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
|
|
@@ -128,8 +128,8 @@ exports.ValueErrorIterator = ValueErrorIterator;
|
|
|
128
128
|
// --------------------------------------------------------------------------
|
|
129
129
|
// Create
|
|
130
130
|
// --------------------------------------------------------------------------
|
|
131
|
-
function Create(
|
|
132
|
-
return { type, schema, path, value, message: (0, function_1.GetErrorFunction)()(schema,
|
|
131
|
+
function Create(errorType, schema, path, value) {
|
|
132
|
+
return { type: errorType, schema, path, value, message: (0, function_1.GetErrorFunction)()({ errorType, path, schema, value }) };
|
|
133
133
|
}
|
|
134
134
|
// --------------------------------------------------------------------------
|
|
135
135
|
// Types
|
|
@@ -1,9 +1,19 @@
|
|
|
1
1
|
import { TSchema } from '../type/schema/index';
|
|
2
2
|
import { ValueErrorType } from './errors';
|
|
3
3
|
/** Creates an error message using en-US as the default locale */
|
|
4
|
-
export declare function DefaultErrorFunction(
|
|
5
|
-
export type
|
|
6
|
-
/**
|
|
4
|
+
export declare function DefaultErrorFunction(error: ErrorFunctionParameter): string;
|
|
5
|
+
export type ErrorFunctionParameter = {
|
|
6
|
+
/** The type of validation error */
|
|
7
|
+
errorType: ValueErrorType;
|
|
8
|
+
/** The path of the error */
|
|
9
|
+
path: string;
|
|
10
|
+
/** The schema associated with the error */
|
|
11
|
+
schema: TSchema;
|
|
12
|
+
/** The value associated with the error */
|
|
13
|
+
value: unknown;
|
|
14
|
+
};
|
|
15
|
+
export type ErrorFunction = (parameter: ErrorFunctionParameter) => string;
|
|
16
|
+
/** Sets the error function used to generate error messages. */
|
|
7
17
|
export declare function SetErrorFunction(callback: ErrorFunction): void;
|
|
8
18
|
/** Gets the error function used to generate error messages */
|
|
9
19
|
export declare function GetErrorFunction(): ErrorFunction;
|
|
@@ -5,18 +5,18 @@ exports.GetErrorFunction = exports.SetErrorFunction = exports.DefaultErrorFuncti
|
|
|
5
5
|
const index_1 = require("../type/symbols/index");
|
|
6
6
|
const errors_1 = require("./errors");
|
|
7
7
|
/** Creates an error message using en-US as the default locale */
|
|
8
|
-
function DefaultErrorFunction(
|
|
9
|
-
switch (errorType) {
|
|
8
|
+
function DefaultErrorFunction(error) {
|
|
9
|
+
switch (error.errorType) {
|
|
10
10
|
case errors_1.ValueErrorType.ArrayContains:
|
|
11
11
|
return 'Expected array to contain at least one matching value';
|
|
12
12
|
case errors_1.ValueErrorType.ArrayMaxContains:
|
|
13
|
-
return `Expected array to contain no more than ${schema.maxContains} matching values`;
|
|
13
|
+
return `Expected array to contain no more than ${error.schema.maxContains} matching values`;
|
|
14
14
|
case errors_1.ValueErrorType.ArrayMinContains:
|
|
15
|
-
return `Expected array to contain at least ${schema.minContains} matching values`;
|
|
15
|
+
return `Expected array to contain at least ${error.schema.minContains} matching values`;
|
|
16
16
|
case errors_1.ValueErrorType.ArrayMaxItems:
|
|
17
|
-
return `Expected array length to be less or equal to ${schema.maxItems}`;
|
|
17
|
+
return `Expected array length to be less or equal to ${error.schema.maxItems}`;
|
|
18
18
|
case errors_1.ValueErrorType.ArrayMinItems:
|
|
19
|
-
return `Expected array length to be greater or equal to ${schema.minItems}`;
|
|
19
|
+
return `Expected array length to be greater or equal to ${error.schema.minItems}`;
|
|
20
20
|
case errors_1.ValueErrorType.ArrayUniqueItems:
|
|
21
21
|
return 'Expected array elements to be unique';
|
|
22
22
|
case errors_1.ValueErrorType.Array:
|
|
@@ -24,43 +24,43 @@ function DefaultErrorFunction(schema, errorType) {
|
|
|
24
24
|
case errors_1.ValueErrorType.AsyncIterator:
|
|
25
25
|
return 'Expected AsyncIterator';
|
|
26
26
|
case errors_1.ValueErrorType.BigIntExclusiveMaximum:
|
|
27
|
-
return `Expected bigint to be less than ${schema.exclusiveMaximum}`;
|
|
27
|
+
return `Expected bigint to be less than ${error.schema.exclusiveMaximum}`;
|
|
28
28
|
case errors_1.ValueErrorType.BigIntExclusiveMinimum:
|
|
29
|
-
return `Expected bigint to be greater than ${schema.exclusiveMinimum}`;
|
|
29
|
+
return `Expected bigint to be greater than ${error.schema.exclusiveMinimum}`;
|
|
30
30
|
case errors_1.ValueErrorType.BigIntMaximum:
|
|
31
|
-
return `Expected bigint to be less or equal to ${schema.maximum}`;
|
|
31
|
+
return `Expected bigint to be less or equal to ${error.schema.maximum}`;
|
|
32
32
|
case errors_1.ValueErrorType.BigIntMinimum:
|
|
33
|
-
return `Expected bigint to be greater or equal to ${schema.minimum}`;
|
|
33
|
+
return `Expected bigint to be greater or equal to ${error.schema.minimum}`;
|
|
34
34
|
case errors_1.ValueErrorType.BigIntMultipleOf:
|
|
35
|
-
return `Expected bigint to be a multiple of ${schema.multipleOf}`;
|
|
35
|
+
return `Expected bigint to be a multiple of ${error.schema.multipleOf}`;
|
|
36
36
|
case errors_1.ValueErrorType.BigInt:
|
|
37
37
|
return 'Expected bigint';
|
|
38
38
|
case errors_1.ValueErrorType.Boolean:
|
|
39
39
|
return 'Expected boolean';
|
|
40
40
|
case errors_1.ValueErrorType.DateExclusiveMinimumTimestamp:
|
|
41
|
-
return `Expected Date timestamp to be greater than ${schema.exclusiveMinimumTimestamp}`;
|
|
41
|
+
return `Expected Date timestamp to be greater than ${error.schema.exclusiveMinimumTimestamp}`;
|
|
42
42
|
case errors_1.ValueErrorType.DateExclusiveMaximumTimestamp:
|
|
43
|
-
return `Expected Date timestamp to be less than ${schema.exclusiveMaximumTimestamp}`;
|
|
43
|
+
return `Expected Date timestamp to be less than ${error.schema.exclusiveMaximumTimestamp}`;
|
|
44
44
|
case errors_1.ValueErrorType.DateMinimumTimestamp:
|
|
45
|
-
return `Expected Date timestamp to be greater or equal to ${schema.minimumTimestamp}`;
|
|
45
|
+
return `Expected Date timestamp to be greater or equal to ${error.schema.minimumTimestamp}`;
|
|
46
46
|
case errors_1.ValueErrorType.DateMaximumTimestamp:
|
|
47
|
-
return `Expected Date timestamp to be less or equal to ${schema.maximumTimestamp}`;
|
|
47
|
+
return `Expected Date timestamp to be less or equal to ${error.schema.maximumTimestamp}`;
|
|
48
48
|
case errors_1.ValueErrorType.DateMultipleOfTimestamp:
|
|
49
|
-
return `Expected Date timestamp to be a multiple of ${schema.multipleOfTimestamp}`;
|
|
49
|
+
return `Expected Date timestamp to be a multiple of ${error.schema.multipleOfTimestamp}`;
|
|
50
50
|
case errors_1.ValueErrorType.Date:
|
|
51
51
|
return 'Expected Date';
|
|
52
52
|
case errors_1.ValueErrorType.Function:
|
|
53
53
|
return 'Expected function';
|
|
54
54
|
case errors_1.ValueErrorType.IntegerExclusiveMaximum:
|
|
55
|
-
return `Expected integer to be less than ${schema.exclusiveMaximum}`;
|
|
55
|
+
return `Expected integer to be less than ${error.schema.exclusiveMaximum}`;
|
|
56
56
|
case errors_1.ValueErrorType.IntegerExclusiveMinimum:
|
|
57
|
-
return `Expected integer to be greater than ${schema.exclusiveMinimum}`;
|
|
57
|
+
return `Expected integer to be greater than ${error.schema.exclusiveMinimum}`;
|
|
58
58
|
case errors_1.ValueErrorType.IntegerMaximum:
|
|
59
|
-
return `Expected integer to be less or equal to ${schema.maximum}`;
|
|
59
|
+
return `Expected integer to be less or equal to ${error.schema.maximum}`;
|
|
60
60
|
case errors_1.ValueErrorType.IntegerMinimum:
|
|
61
|
-
return `Expected integer to be greater or equal to ${schema.minimum}`;
|
|
61
|
+
return `Expected integer to be greater or equal to ${error.schema.minimum}`;
|
|
62
62
|
case errors_1.ValueErrorType.IntegerMultipleOf:
|
|
63
|
-
return `Expected integer to be a multiple of ${schema.multipleOf}`;
|
|
63
|
+
return `Expected integer to be a multiple of ${error.schema.multipleOf}`;
|
|
64
64
|
case errors_1.ValueErrorType.Integer:
|
|
65
65
|
return 'Expected integer';
|
|
66
66
|
case errors_1.ValueErrorType.IntersectUnevaluatedProperties:
|
|
@@ -70,7 +70,7 @@ function DefaultErrorFunction(schema, errorType) {
|
|
|
70
70
|
case errors_1.ValueErrorType.Iterator:
|
|
71
71
|
return 'Expected Iterator';
|
|
72
72
|
case errors_1.ValueErrorType.Literal:
|
|
73
|
-
return `Expected ${typeof schema.const === 'string' ? `'${schema.const}'` : schema.const}`;
|
|
73
|
+
return `Expected ${typeof error.schema.const === 'string' ? `'${error.schema.const}'` : error.schema.const}`;
|
|
74
74
|
case errors_1.ValueErrorType.Never:
|
|
75
75
|
return 'Never';
|
|
76
76
|
case errors_1.ValueErrorType.Not:
|
|
@@ -78,15 +78,15 @@ function DefaultErrorFunction(schema, errorType) {
|
|
|
78
78
|
case errors_1.ValueErrorType.Null:
|
|
79
79
|
return 'Expected null';
|
|
80
80
|
case errors_1.ValueErrorType.NumberExclusiveMaximum:
|
|
81
|
-
return `Expected number to be less than ${schema.exclusiveMaximum}`;
|
|
81
|
+
return `Expected number to be less than ${error.schema.exclusiveMaximum}`;
|
|
82
82
|
case errors_1.ValueErrorType.NumberExclusiveMinimum:
|
|
83
|
-
return `Expected number to be greater than ${schema.exclusiveMinimum}`;
|
|
83
|
+
return `Expected number to be greater than ${error.schema.exclusiveMinimum}`;
|
|
84
84
|
case errors_1.ValueErrorType.NumberMaximum:
|
|
85
|
-
return `Expected number to be less or equal to ${schema.maximum}`;
|
|
85
|
+
return `Expected number to be less or equal to ${error.schema.maximum}`;
|
|
86
86
|
case errors_1.ValueErrorType.NumberMinimum:
|
|
87
|
-
return `Expected number to be greater or equal to ${schema.minimum}`;
|
|
87
|
+
return `Expected number to be greater or equal to ${error.schema.minimum}`;
|
|
88
88
|
case errors_1.ValueErrorType.NumberMultipleOf:
|
|
89
|
-
return `Expected number to be a multiple of ${schema.multipleOf}`;
|
|
89
|
+
return `Expected number to be a multiple of ${error.schema.multipleOf}`;
|
|
90
90
|
case errors_1.ValueErrorType.Number:
|
|
91
91
|
return 'Expected number';
|
|
92
92
|
case errors_1.ValueErrorType.Object:
|
|
@@ -94,35 +94,35 @@ function DefaultErrorFunction(schema, errorType) {
|
|
|
94
94
|
case errors_1.ValueErrorType.ObjectAdditionalProperties:
|
|
95
95
|
return 'Unexpected property';
|
|
96
96
|
case errors_1.ValueErrorType.ObjectMaxProperties:
|
|
97
|
-
return `Expected object to have no more than ${schema.maxProperties} properties`;
|
|
97
|
+
return `Expected object to have no more than ${error.schema.maxProperties} properties`;
|
|
98
98
|
case errors_1.ValueErrorType.ObjectMinProperties:
|
|
99
|
-
return `Expected object to have at least ${schema.minProperties} properties`;
|
|
99
|
+
return `Expected object to have at least ${error.schema.minProperties} properties`;
|
|
100
100
|
case errors_1.ValueErrorType.ObjectRequiredProperty:
|
|
101
101
|
return 'Required property';
|
|
102
102
|
case errors_1.ValueErrorType.Promise:
|
|
103
103
|
return 'Expected Promise';
|
|
104
104
|
case errors_1.ValueErrorType.StringFormatUnknown:
|
|
105
|
-
return `Unknown format '${schema.format}'`;
|
|
105
|
+
return `Unknown format '${error.schema.format}'`;
|
|
106
106
|
case errors_1.ValueErrorType.StringFormat:
|
|
107
|
-
return `Expected string to match '${schema.format}' format`;
|
|
107
|
+
return `Expected string to match '${error.schema.format}' format`;
|
|
108
108
|
case errors_1.ValueErrorType.StringMaxLength:
|
|
109
|
-
return `Expected string length less or equal to ${schema.maxLength}`;
|
|
109
|
+
return `Expected string length less or equal to ${error.schema.maxLength}`;
|
|
110
110
|
case errors_1.ValueErrorType.StringMinLength:
|
|
111
|
-
return `Expected string length greater or equal to ${schema.minLength}`;
|
|
111
|
+
return `Expected string length greater or equal to ${error.schema.minLength}`;
|
|
112
112
|
case errors_1.ValueErrorType.StringPattern:
|
|
113
|
-
return `Expected string to match '${schema.pattern}'`;
|
|
113
|
+
return `Expected string to match '${error.schema.pattern}'`;
|
|
114
114
|
case errors_1.ValueErrorType.String:
|
|
115
115
|
return 'Expected string';
|
|
116
116
|
case errors_1.ValueErrorType.Symbol:
|
|
117
117
|
return 'Expected symbol';
|
|
118
118
|
case errors_1.ValueErrorType.TupleLength:
|
|
119
|
-
return `Expected tuple to have ${schema.maxItems || 0} elements`;
|
|
119
|
+
return `Expected tuple to have ${error.schema.maxItems || 0} elements`;
|
|
120
120
|
case errors_1.ValueErrorType.Tuple:
|
|
121
121
|
return 'Expected tuple';
|
|
122
122
|
case errors_1.ValueErrorType.Uint8ArrayMaxByteLength:
|
|
123
|
-
return `Expected byte length less or equal to ${schema.maxByteLength}`;
|
|
123
|
+
return `Expected byte length less or equal to ${error.schema.maxByteLength}`;
|
|
124
124
|
case errors_1.ValueErrorType.Uint8ArrayMinByteLength:
|
|
125
|
-
return `Expected byte length greater or equal to ${schema.minByteLength}`;
|
|
125
|
+
return `Expected byte length greater or equal to ${error.schema.minByteLength}`;
|
|
126
126
|
case errors_1.ValueErrorType.Uint8Array:
|
|
127
127
|
return 'Expected Uint8Array';
|
|
128
128
|
case errors_1.ValueErrorType.Undefined:
|
|
@@ -132,7 +132,7 @@ function DefaultErrorFunction(schema, errorType) {
|
|
|
132
132
|
case errors_1.ValueErrorType.Void:
|
|
133
133
|
return 'Expected void';
|
|
134
134
|
case errors_1.ValueErrorType.Kind:
|
|
135
|
-
return `Expected kind '${schema[index_1.Kind]}'`;
|
|
135
|
+
return `Expected kind '${error.schema[index_1.Kind]}'`;
|
|
136
136
|
default:
|
|
137
137
|
return 'Unknown error type';
|
|
138
138
|
}
|
|
@@ -140,7 +140,7 @@ function DefaultErrorFunction(schema, errorType) {
|
|
|
140
140
|
exports.DefaultErrorFunction = DefaultErrorFunction;
|
|
141
141
|
/** Manages error message providers */
|
|
142
142
|
let errorFunction = DefaultErrorFunction;
|
|
143
|
-
/** Sets the error function used to generate error messages */
|
|
143
|
+
/** Sets the error function used to generate error messages. */
|
|
144
144
|
function SetErrorFunction(callback) {
|
|
145
145
|
errorFunction = callback;
|
|
146
146
|
}
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index';
|
|
2
2
|
import type { TProperties } from '../object/index';
|
|
3
3
|
import { type TMappedResult } from '../mapped/index';
|
|
4
|
+
import { type TIndexPropertyKeys } from './indexed-property-keys';
|
|
4
5
|
import { type TIndex } from './index';
|
|
5
|
-
import { TIndexPropertyKeys } from './indexed-property-keys';
|
|
6
6
|
type TFromProperties<T extends TSchema, P extends TProperties> = ({
|
|
7
7
|
[K2 in keyof P]: TIndex<T, TIndexPropertyKeys<P[K2]>>;
|
|
8
8
|
});
|
|
@@ -3,8 +3,8 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.IndexFromMappedResult = void 0;
|
|
5
5
|
const index_1 = require("../mapped/index");
|
|
6
|
-
const index_2 = require("./index");
|
|
7
6
|
const indexed_property_keys_1 = require("./indexed-property-keys");
|
|
7
|
+
const index_2 = require("./index");
|
|
8
8
|
// prettier-ignore
|
|
9
9
|
function FromProperties(T, P, options) {
|
|
10
10
|
return globalThis.Object.getOwnPropertyNames(P).reduce((Acc, K2) => {
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1619,12 +1619,12 @@ The following example shows an inline error function that intercepts errors for
|
|
|
1619
1619
|
```typescript
|
|
1620
1620
|
import { SetErrorFunction, DefaultErrorFunction, ValueErrorType } from '@sinclair/typebox/errors'
|
|
1621
1621
|
|
|
1622
|
-
SetErrorFunction((
|
|
1623
|
-
switch(errorType) {
|
|
1622
|
+
SetErrorFunction((error) => { // i18n override
|
|
1623
|
+
switch(error.errorType) {
|
|
1624
1624
|
/* en-US */ case ValueErrorType.String: return 'Expected string'
|
|
1625
1625
|
/* fr-FR */ case ValueErrorType.Number: return 'Nombre attendu'
|
|
1626
1626
|
/* ko-KR */ case ValueErrorType.Boolean: return '예상 부울'
|
|
1627
|
-
/* en-US */ default: return DefaultErrorFunction(
|
|
1627
|
+
/* en-US */ default: return DefaultErrorFunction(error)
|
|
1628
1628
|
}
|
|
1629
1629
|
})
|
|
1630
1630
|
const T = Type.Object({ // const T: TObject<{
|
|
@@ -1795,10 +1795,10 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
|
|
|
1795
1795
|
┌──────────────────────┬────────────┬────────────┬─────────────┐
|
|
1796
1796
|
│ (index) │ Compiled │ Minified │ Compression │
|
|
1797
1797
|
├──────────────────────┼────────────┼────────────┼─────────────┤
|
|
1798
|
-
│ typebox/compiler │ '120.
|
|
1799
|
-
│ typebox/errors │ ' 55.
|
|
1798
|
+
│ typebox/compiler │ '120.7 kb' │ ' 53.0 kb' │ '2.28 x' │
|
|
1799
|
+
│ typebox/errors │ ' 55.8 kb' │ ' 25.5 kb' │ '2.19 x' │
|
|
1800
1800
|
│ typebox/system │ ' 4.7 kb' │ ' 2.0 kb' │ '2.33 x' │
|
|
1801
|
-
│ typebox/value │ '147.
|
|
1801
|
+
│ typebox/value │ '147.6 kb' │ ' 62.5 kb' │ '2.36 x' │
|
|
1802
1802
|
│ typebox │ ' 91.3 kb' │ ' 38.0 kb' │ '2.40 x' │
|
|
1803
1803
|
└──────────────────────┴────────────┴────────────┴─────────────┘
|
|
1804
1804
|
```
|