typebox 1.0.25 → 1.0.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/guard/emit.d.mts +1 -0
- package/build/guard/emit.mjs +8 -0
- package/build/guard/guard.d.mts +2 -2
- package/build/guard/guard.mjs +8 -4
- package/build/schema/engine/_refine.mjs +3 -3
- package/build/schema/engine/additionalProperties.mjs +3 -3
- package/build/schema/engine/dependencies.mjs +2 -2
- package/build/schema/engine/dependentRequired.mjs +3 -3
- package/build/schema/engine/dependentSchemas.mjs +2 -2
- package/build/schema/engine/items.mjs +8 -5
- package/build/schema/engine/patternProperties.mjs +5 -5
- package/build/schema/engine/prefixItems.mjs +2 -2
- package/build/schema/engine/properties.mjs +2 -2
- package/build/schema/engine/propertyNames.mjs +2 -2
- package/build/schema/engine/required.mjs +2 -2
- package/build/schema/engine/unevaluatedItems.mjs +3 -3
- package/build/schema/engine/unevaluatedProperties.mjs +3 -3
- package/build/schema/types/_refine.mjs +1 -1
- package/build/type/types/base.mjs +3 -1
- package/package.json +1 -1
package/build/guard/emit.d.mts
CHANGED
|
@@ -35,6 +35,7 @@ export declare function IsLessThan(left: string, right: string): string;
|
|
|
35
35
|
export declare function IsLessEqualThan(left: string, right: string): string;
|
|
36
36
|
export declare function IsGreaterEqualThan(left: string, right: string): string;
|
|
37
37
|
export declare function StringGraphemeCount(value: string): string;
|
|
38
|
+
export declare function Every(value: string, offset: string, params: [value: string, index: string], expression: string): string;
|
|
38
39
|
export declare function Entries(value: string): string;
|
|
39
40
|
export declare function Keys(value: string): string;
|
|
40
41
|
export declare function HasPropertyKey(value: string, key: string): string;
|
package/build/guard/emit.mjs
CHANGED
|
@@ -108,6 +108,14 @@ export function StringGraphemeCount(value) {
|
|
|
108
108
|
return `Guard.StringGraphemeCount(${value})`;
|
|
109
109
|
}
|
|
110
110
|
// --------------------------------------------------------------------------
|
|
111
|
+
// Array
|
|
112
|
+
// --------------------------------------------------------------------------
|
|
113
|
+
export function Every(value, offset, params, expression) {
|
|
114
|
+
return G.IsEqual(offset, '0')
|
|
115
|
+
? `${value}.every((${params[0]}, ${params[1]}) => ${expression})`
|
|
116
|
+
: `((value, callback) => { for(let index = ${offset}; index < value.length; index++) if (!callback(value[index], index)) return false; return true })(${value}, (${params[0]}, ${params[1]}) => ${expression})`;
|
|
117
|
+
}
|
|
118
|
+
// --------------------------------------------------------------------------
|
|
111
119
|
// Objects
|
|
112
120
|
// --------------------------------------------------------------------------
|
|
113
121
|
export function Entries(value) {
|
package/build/guard/guard.d.mts
CHANGED
|
@@ -39,8 +39,8 @@ export declare function IsClassInstance(value: unknown): boolean;
|
|
|
39
39
|
export declare function IsValueLike(value: unknown): value is bigint | boolean | null | number | string | undefined;
|
|
40
40
|
/** Returns the number of Unicode Grapheme Clusters */
|
|
41
41
|
export declare function StringGraphemeCount(value: string): number;
|
|
42
|
-
export declare function Every<T>(value: T[], callback: (value: T, index: number) => boolean): boolean;
|
|
43
|
-
export declare function EveryAll<T>(value: T[], callback: (value: T, index: number) => boolean): boolean;
|
|
42
|
+
export declare function Every<T>(value: T[], offset: number, callback: (value: T, index: number) => boolean): boolean;
|
|
43
|
+
export declare function EveryAll<T>(value: T[], offset: number, callback: (value: T, index: number) => boolean): boolean;
|
|
44
44
|
/** Returns true if this value has this property key */
|
|
45
45
|
export declare function HasPropertyKey<Key extends PropertyKey>(value: object, key: Key): value is {
|
|
46
46
|
[_ in Key]: unknown;
|
package/build/guard/guard.mjs
CHANGED
|
@@ -136,12 +136,16 @@ export function StringGraphemeCount(value) {
|
|
|
136
136
|
// --------------------------------------------------------------------------
|
|
137
137
|
// Array
|
|
138
138
|
// --------------------------------------------------------------------------
|
|
139
|
-
export function Every(value, callback) {
|
|
140
|
-
|
|
139
|
+
export function Every(value, offset, callback) {
|
|
140
|
+
for (let index = offset; index < value.length; index++) {
|
|
141
|
+
if (!callback(value[index], index))
|
|
142
|
+
return false;
|
|
143
|
+
}
|
|
144
|
+
return true;
|
|
141
145
|
}
|
|
142
|
-
export function EveryAll(value, callback) {
|
|
146
|
+
export function EveryAll(value, offset, callback) {
|
|
143
147
|
let result = true;
|
|
144
|
-
for (let index =
|
|
148
|
+
for (let index = offset; index < value.length; index++) {
|
|
145
149
|
if (!callback(value[index], index))
|
|
146
150
|
result = false;
|
|
147
151
|
}
|
|
@@ -6,19 +6,19 @@ import { EmitGuard as E, Guard as G } from '../../guard/index.mjs';
|
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
7
|
export function BuildRefine(context, schema, value) {
|
|
8
8
|
const refinements = V.CreateExternalVariable(schema['~refine'].map((refinement) => refinement));
|
|
9
|
-
return E.
|
|
9
|
+
return E.Every(refinements, E.Constant(0), ['refinement', '_'], E.Call(E.Member('refinement', 'callback'), [value]));
|
|
10
10
|
}
|
|
11
11
|
// ------------------------------------------------------------------
|
|
12
12
|
// Check
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
14
|
export function CheckRefine(context, schema, value) {
|
|
15
|
-
return G.Every(schema['~refine'], (refinement) => refinement.callback(value));
|
|
15
|
+
return G.Every(schema['~refine'], 0, (refinement, _) => refinement.callback(value));
|
|
16
16
|
}
|
|
17
17
|
// ------------------------------------------------------------------
|
|
18
18
|
// Error
|
|
19
19
|
// ------------------------------------------------------------------
|
|
20
20
|
export function ErrorRefine(context, schemaPath, instancePath, schema, value) {
|
|
21
|
-
return G.EveryAll(schema['~refine'], (refinement, index) => {
|
|
21
|
+
return G.EveryAll(schema['~refine'], 0, (refinement, index) => {
|
|
22
22
|
return refinement.callback(value) || context.AddError({
|
|
23
23
|
keyword: '~refine',
|
|
24
24
|
schemaPath,
|
|
@@ -57,7 +57,7 @@ export function BuildAdditionalPropertiesStandard(context, schema, value) {
|
|
|
57
57
|
const isKey = E.Call(E.Member(regexp, 'test'), ['key']);
|
|
58
58
|
const addKey = context.AddKey('key');
|
|
59
59
|
const guarded = context.UseUnevaluated() ? E.Or(isKey, E.And(isSchema, addKey)) : E.Or(isKey, isSchema);
|
|
60
|
-
return E.
|
|
60
|
+
return E.Every(E.Keys(value), E.Constant(0), ['key', '_'], guarded);
|
|
61
61
|
}
|
|
62
62
|
// ------------------------------------------------------------------
|
|
63
63
|
// Build
|
|
@@ -72,7 +72,7 @@ export function BuildAdditionalProperties(context, schema, value) {
|
|
|
72
72
|
// ------------------------------------------------------------------
|
|
73
73
|
export function CheckAdditionalProperties(context, schema, value) {
|
|
74
74
|
const regexp = new RegExp(GetPropertiesPattern(schema));
|
|
75
|
-
const isAdditionalProperties = G.Every(G.Keys(value), (key) => {
|
|
75
|
+
const isAdditionalProperties = G.Every(G.Keys(value), 0, (key) => {
|
|
76
76
|
return regexp.test(key) ||
|
|
77
77
|
(CheckSchema(context, schema.additionalProperties, value[key]) && context.AddKey(key));
|
|
78
78
|
});
|
|
@@ -84,7 +84,7 @@ export function CheckAdditionalProperties(context, schema, value) {
|
|
|
84
84
|
export function ErrorAdditionalProperties(context, schemaPath, instancePath, schema, value) {
|
|
85
85
|
const regexp = new RegExp(GetPropertiesPattern(schema));
|
|
86
86
|
const additionalProperties = [];
|
|
87
|
-
const isAdditionalProperties = G.EveryAll(G.Keys(value), (key) => {
|
|
87
|
+
const isAdditionalProperties = G.EveryAll(G.Keys(value), 0, (key) => {
|
|
88
88
|
const nextSchemaPath = `${schemaPath}/additionalProperties`;
|
|
89
89
|
const nextInstancePath = `${instancePath}/${key}`;
|
|
90
90
|
const nextContext = new AccumulatedErrorContext(context.GetContext(), context.GetSchema());
|
|
@@ -19,7 +19,7 @@ export function BuildDependencies(context, schema, value) {
|
|
|
19
19
|
// ------------------------------------------------------------------
|
|
20
20
|
export function CheckDependencies(context, schema, value) {
|
|
21
21
|
const isLength = G.IsEqual(G.Keys(value).length, 0);
|
|
22
|
-
const isEvery = G.Every(G.Entries(schema.dependencies), ([key, schema]) => {
|
|
22
|
+
const isEvery = G.Every(G.Entries(schema.dependencies), 0, ([key, schema]) => {
|
|
23
23
|
return !G.HasPropertyKey(value, key) || (G.IsArray(schema)
|
|
24
24
|
? schema.every((key) => G.HasPropertyKey(value, key))
|
|
25
25
|
: CheckSchema(context, schema, value));
|
|
@@ -31,7 +31,7 @@ export function CheckDependencies(context, schema, value) {
|
|
|
31
31
|
// ------------------------------------------------------------------
|
|
32
32
|
export function ErrorDependencies(context, schemaPath, instancePath, schema, value) {
|
|
33
33
|
const isLength = G.IsEqual(G.Keys(value).length, 0);
|
|
34
|
-
const isEvery = G.EveryAll(G.Entries(schema.dependencies), ([key, schema]) => {
|
|
34
|
+
const isEvery = G.EveryAll(G.Entries(schema.dependencies), 0, ([key, schema]) => {
|
|
35
35
|
const nextSchemaPath = `${schemaPath}/dependencies/${key}`;
|
|
36
36
|
return !G.HasPropertyKey(value, key) || (G.IsArray(schema)
|
|
37
37
|
? schema.every((dependency) => G.HasPropertyKey(value, dependency) || context.AddError({
|
|
@@ -17,7 +17,7 @@ export function BuildDependentRequired(context, schema, value) {
|
|
|
17
17
|
// ------------------------------------------------------------------
|
|
18
18
|
export function CheckDependentRequired(context, schema, value) {
|
|
19
19
|
const isLength = G.IsEqual(G.Keys(value).length, 0);
|
|
20
|
-
const isEvery = G.Every(G.Entries(schema.dependentRequired), ([key, keys]) => {
|
|
20
|
+
const isEvery = G.Every(G.Entries(schema.dependentRequired), 0, ([key, keys]) => {
|
|
21
21
|
return !G.HasPropertyKey(value, key) ||
|
|
22
22
|
keys.every((key) => G.HasPropertyKey(value, key));
|
|
23
23
|
});
|
|
@@ -28,8 +28,8 @@ export function CheckDependentRequired(context, schema, value) {
|
|
|
28
28
|
// ------------------------------------------------------------------
|
|
29
29
|
export function ErrorDependentRequired(context, schemaPath, instancePath, schema, value) {
|
|
30
30
|
const isLength = G.IsEqual(G.Keys(value).length, 0);
|
|
31
|
-
const isEveryEntry = G.EveryAll(G.Entries(schema.dependentRequired), ([key, keys]) => {
|
|
32
|
-
return !G.HasPropertyKey(value, key) || G.EveryAll(keys, (dependency) => G.HasPropertyKey(value, dependency) || context.AddError({
|
|
31
|
+
const isEveryEntry = G.EveryAll(G.Entries(schema.dependentRequired), 0, ([key, keys]) => {
|
|
32
|
+
return !G.HasPropertyKey(value, key) || G.EveryAll(keys, 0, (dependency) => G.HasPropertyKey(value, dependency) || context.AddError({
|
|
33
33
|
keyword: 'dependentRequired',
|
|
34
34
|
schemaPath,
|
|
35
35
|
instancePath,
|
|
@@ -18,7 +18,7 @@ export function BuildDependentSchemas(context, schema, value) {
|
|
|
18
18
|
// ------------------------------------------------------------------
|
|
19
19
|
export function CheckDependentSchemas(context, schema, value) {
|
|
20
20
|
const isLength = G.IsEqual(G.Keys(value).length, 0);
|
|
21
|
-
const isEvery = G.Every(G.Entries(schema.dependentSchemas), ([key, schema]) => {
|
|
21
|
+
const isEvery = G.Every(G.Entries(schema.dependentSchemas), 0, ([key, schema]) => {
|
|
22
22
|
return !G.HasPropertyKey(value, key) ||
|
|
23
23
|
CheckSchema(context, schema, value);
|
|
24
24
|
});
|
|
@@ -29,7 +29,7 @@ export function CheckDependentSchemas(context, schema, value) {
|
|
|
29
29
|
// ------------------------------------------------------------------
|
|
30
30
|
export function ErrorDependentSchemas(context, schemaPath, instancePath, schema, value) {
|
|
31
31
|
const isLength = G.IsEqual(G.Keys(value).length, 0);
|
|
32
|
-
const isEvery = G.EveryAll(G.Entries(schema.dependentSchemas), ([key, schema]) => {
|
|
32
|
+
const isEvery = G.EveryAll(G.Entries(schema.dependentSchemas), 0, ([key, schema]) => {
|
|
33
33
|
const nextSchemaPath = `${schemaPath}/dependentSchemas/${key}`;
|
|
34
34
|
return !G.HasPropertyKey(value, key) ||
|
|
35
35
|
ErrorSchema(context, nextSchemaPath, instancePath, schema, value);
|
|
@@ -15,13 +15,13 @@ function BuildItemsSized(context, schema, value) {
|
|
|
15
15
|
}));
|
|
16
16
|
}
|
|
17
17
|
function CheckItemsSized(context, schema, value) {
|
|
18
|
-
return G.Every(schema.items, (schema, index) => {
|
|
18
|
+
return G.Every(schema.items, 0, (schema, index) => {
|
|
19
19
|
return G.IsGreaterEqualThan(index, value.length)
|
|
20
20
|
|| (CheckSchema(context, schema, value[index]) && context.AddIndex(index));
|
|
21
21
|
});
|
|
22
22
|
}
|
|
23
23
|
function ErrorItemsSized(context, schemaPath, instancePath, schema, value) {
|
|
24
|
-
return G.EveryAll(schema.items, (schema, index) => {
|
|
24
|
+
return G.EveryAll(schema.items, 0, (schema, index) => {
|
|
25
25
|
const nextSchemaPath = `${schemaPath}/items/${index}`;
|
|
26
26
|
const nextInstancePath = `${instancePath}/${index}`;
|
|
27
27
|
return G.IsGreaterEqualThan(index, value.length)
|
|
@@ -32,19 +32,22 @@ function ErrorItemsSized(context, schemaPath, instancePath, schema, value) {
|
|
|
32
32
|
// ItemsUnsized
|
|
33
33
|
// ------------------------------------------------------------------
|
|
34
34
|
function BuildItemsUnsized(context, schema, value) {
|
|
35
|
+
const offset = S.IsPrefixItems(schema) ? schema.prefixItems.length : 0;
|
|
35
36
|
const isSchema = BuildSchema(context, schema.items, 'element');
|
|
36
37
|
const addIndex = context.AddIndex('index');
|
|
37
38
|
const guarded = context.UseUnevaluated() ? E.And(isSchema, addIndex) : isSchema;
|
|
38
|
-
return E.
|
|
39
|
+
return E.Every(value, E.Constant(offset), ['element', 'index'], guarded);
|
|
39
40
|
}
|
|
40
41
|
function CheckItemsUnsized(context, schema, value) {
|
|
41
|
-
|
|
42
|
+
const offset = S.IsPrefixItems(schema) ? schema.prefixItems.length : 0;
|
|
43
|
+
return G.Every(value, offset, (element, index) => {
|
|
42
44
|
return CheckSchema(context, schema.items, element)
|
|
43
45
|
&& context.AddIndex(index);
|
|
44
46
|
});
|
|
45
47
|
}
|
|
46
48
|
function ErrorItemsUnsized(context, schemaPath, instancePath, schema, value) {
|
|
47
|
-
|
|
49
|
+
const offset = S.IsPrefixItems(schema) ? schema.prefixItems.length : 0;
|
|
50
|
+
return G.EveryAll(value, offset, (element, index) => {
|
|
48
51
|
const nextSchemaPath = `${schemaPath}/items`;
|
|
49
52
|
const nextInstancePath = `${instancePath}/${index}`;
|
|
50
53
|
return ErrorSchema(context, nextSchemaPath, nextInstancePath, schema.items, element)
|
|
@@ -12,16 +12,16 @@ export function BuildPatternProperties(context, schema, value) {
|
|
|
12
12
|
const isSchema = BuildSchema(context, schema, 'value');
|
|
13
13
|
const addKey = context.AddKey('key');
|
|
14
14
|
const guarded = context.UseUnevaluated() ? E.Or(notKey, E.And(isSchema, addKey)) : E.Or(notKey, isSchema);
|
|
15
|
-
return E.
|
|
15
|
+
return E.Every(E.Entries(value), E.Constant(0), ['[key, value]', '_'], guarded);
|
|
16
16
|
}));
|
|
17
17
|
}
|
|
18
18
|
// ------------------------------------------------------------------
|
|
19
19
|
// Check
|
|
20
20
|
// ------------------------------------------------------------------
|
|
21
21
|
export function CheckPatternProperties(context, schema, value) {
|
|
22
|
-
return G.Every(G.Entries(schema.patternProperties), ([pattern, schema]) => {
|
|
22
|
+
return G.Every(G.Entries(schema.patternProperties), 0, ([pattern, schema]) => {
|
|
23
23
|
const regexp = new RegExp(pattern);
|
|
24
|
-
return G.Every(G.Entries(value), ([key, value]) => {
|
|
24
|
+
return G.Every(G.Entries(value), 0, ([key, value]) => {
|
|
25
25
|
return !regexp.test(key) || CheckSchema(context, schema, value) && context.AddKey(key);
|
|
26
26
|
});
|
|
27
27
|
});
|
|
@@ -30,10 +30,10 @@ export function CheckPatternProperties(context, schema, value) {
|
|
|
30
30
|
// Error
|
|
31
31
|
// ------------------------------------------------------------------
|
|
32
32
|
export function ErrorPatternProperties(context, schemaPath, instancePath, schema, value) {
|
|
33
|
-
return G.EveryAll(G.Entries(schema.patternProperties), ([pattern, schema]) => {
|
|
33
|
+
return G.EveryAll(G.Entries(schema.patternProperties), 0, ([pattern, schema]) => {
|
|
34
34
|
const nextSchemaPath = `${schemaPath}/patternProperties/${pattern}`;
|
|
35
35
|
const regexp = new RegExp(pattern);
|
|
36
|
-
return G.EveryAll(G.Entries(value), ([key, value]) => {
|
|
36
|
+
return G.EveryAll(G.Entries(value), 0, ([key, value]) => {
|
|
37
37
|
const nextInstancePath = `${instancePath}/${key}`;
|
|
38
38
|
const notKey = !regexp.test(key);
|
|
39
39
|
return notKey || ErrorSchema(context, nextSchemaPath, nextInstancePath, schema, value) && context.AddKey(key);
|
|
@@ -17,7 +17,7 @@ export function BuildPrefixItems(context, schema, value) {
|
|
|
17
17
|
// Check
|
|
18
18
|
// ------------------------------------------------------------------
|
|
19
19
|
export function CheckPrefixItems(context, schema, value) {
|
|
20
|
-
return G.IsEqual(value.length, 0) || G.Every(schema.prefixItems, (schema, index) => {
|
|
20
|
+
return G.IsEqual(value.length, 0) || G.Every(schema.prefixItems, 0, (schema, index) => {
|
|
21
21
|
return G.IsGreaterEqualThan(index, value.length)
|
|
22
22
|
|| (CheckSchema(context, schema, value[index]) && context.AddIndex(index));
|
|
23
23
|
});
|
|
@@ -26,7 +26,7 @@ export function CheckPrefixItems(context, schema, value) {
|
|
|
26
26
|
// Error
|
|
27
27
|
// ------------------------------------------------------------------
|
|
28
28
|
export function ErrorPrefixItems(context, schemaPath, instancePath, schema, value) {
|
|
29
|
-
return G.IsEqual(value.length, 0) || G.EveryAll(schema.prefixItems, (schema, index) => {
|
|
29
|
+
return G.IsEqual(value.length, 0) || G.EveryAll(schema.prefixItems, 0, (schema, index) => {
|
|
30
30
|
const nextSchemaPath = `${schemaPath}/prefixItems/${index}`;
|
|
31
31
|
const nextInstancePath = `${instancePath}/${index}`;
|
|
32
32
|
return G.IsGreaterEqualThan(index, value.length)
|
|
@@ -49,7 +49,7 @@ export function BuildProperties(context, schema, value) {
|
|
|
49
49
|
// ------------------------------------------------------------------
|
|
50
50
|
export function CheckProperties(context, schema, value) {
|
|
51
51
|
const required = S.IsRequired(schema) ? schema.required : [];
|
|
52
|
-
const isProperties = G.Every(G.Entries(schema.properties), ([key, schema]) => {
|
|
52
|
+
const isProperties = G.Every(G.Entries(schema.properties), 0, ([key, schema]) => {
|
|
53
53
|
const isProperty = !G.HasPropertyKey(value, key) || (CheckSchema(context, schema, value[key]) && context.AddKey(key));
|
|
54
54
|
return IsExactOptional(required, key)
|
|
55
55
|
? isProperty
|
|
@@ -62,7 +62,7 @@ export function CheckProperties(context, schema, value) {
|
|
|
62
62
|
// ------------------------------------------------------------------
|
|
63
63
|
export function ErrorProperties(context, schemaPath, instancePath, schema, value) {
|
|
64
64
|
const required = S.IsRequired(schema) ? schema.required : [];
|
|
65
|
-
const isProperties = G.EveryAll(G.Entries(schema.properties), ([key, schema]) => {
|
|
65
|
+
const isProperties = G.EveryAll(G.Entries(schema.properties), 0, ([key, schema]) => {
|
|
66
66
|
const nextSchemaPath = `${schemaPath}/properties/${key}`;
|
|
67
67
|
const nextInstancePath = `${instancePath}/${key}`;
|
|
68
68
|
// Defer error generation for IsExactOptional
|
|
@@ -12,14 +12,14 @@ export function BuildPropertyNames(context, schema, value) {
|
|
|
12
12
|
// Check
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
14
|
export function CheckPropertyNames(context, schema, value) {
|
|
15
|
-
return G.Every(G.Keys(value), (key) => CheckSchema(context, schema.propertyNames, key));
|
|
15
|
+
return G.Every(G.Keys(value), 0, (key) => CheckSchema(context, schema.propertyNames, key));
|
|
16
16
|
}
|
|
17
17
|
// ------------------------------------------------------------------
|
|
18
18
|
// Error
|
|
19
19
|
// ------------------------------------------------------------------
|
|
20
20
|
export function ErrorPropertyNames(context, schemaPath, instancePath, schema, value) {
|
|
21
21
|
const propertyNames = [];
|
|
22
|
-
const isPropertyNames = G.EveryAll(G.Keys(value), (key) => {
|
|
22
|
+
const isPropertyNames = G.EveryAll(G.Keys(value), 0, (key) => {
|
|
23
23
|
const nextInstancePath = `${instancePath}/${key}`;
|
|
24
24
|
const nextSchemaPath = `${schemaPath}/propertyNames`;
|
|
25
25
|
const nextContext = new AccumulatedErrorContext(context.GetContext(), context.GetSchema());
|
|
@@ -10,14 +10,14 @@ export function BuildRequired(context, schema, value) {
|
|
|
10
10
|
// Check
|
|
11
11
|
// ------------------------------------------------------------------
|
|
12
12
|
export function CheckRequired(context, schema, value) {
|
|
13
|
-
return G.Every(schema.required, (key) => G.HasPropertyKey(value, key));
|
|
13
|
+
return G.Every(schema.required, 0, (key) => G.HasPropertyKey(value, key));
|
|
14
14
|
}
|
|
15
15
|
// ------------------------------------------------------------------
|
|
16
16
|
// Error
|
|
17
17
|
// ------------------------------------------------------------------
|
|
18
18
|
export function ErrorRequired(context, schemaPath, instancePath, schema, value) {
|
|
19
19
|
const requiredProperties = [];
|
|
20
|
-
const isRequired = G.EveryAll(schema.required, (key) => {
|
|
20
|
+
const isRequired = G.EveryAll(schema.required, 0, (key) => {
|
|
21
21
|
const hasKey = G.HasPropertyKey(value, key);
|
|
22
22
|
if (!hasKey)
|
|
23
23
|
requiredProperties.push(key);
|
|
@@ -10,7 +10,7 @@ export function BuildUnevaluatedItems(context, schema, value) {
|
|
|
10
10
|
const hasIndex = E.Call(E.Member('indices', 'has'), ['index']);
|
|
11
11
|
const isSchema = BuildSchema(context, schema.unevaluatedItems, 'value');
|
|
12
12
|
const addIndex = E.Call(E.Member('context', 'AddIndex'), ['index']);
|
|
13
|
-
const isEvery = E.
|
|
13
|
+
const isEvery = E.Every(value, E.Constant(0), ['value', 'index'], E.And(E.Or(hasIndex, isSchema), addIndex));
|
|
14
14
|
return E.Call(E.ArrowFunction(['context'], E.Statements([
|
|
15
15
|
E.ConstDeclaration('indices', indices),
|
|
16
16
|
E.Return(isEvery)
|
|
@@ -21,7 +21,7 @@ export function BuildUnevaluatedItems(context, schema, value) {
|
|
|
21
21
|
// ------------------------------------------------------------------
|
|
22
22
|
export function CheckUnevaluatedItems(context, schema, value) {
|
|
23
23
|
const indices = context.GetIndices();
|
|
24
|
-
return G.Every(value, (value, index) => {
|
|
24
|
+
return G.Every(value, 0, (value, index) => {
|
|
25
25
|
return (indices.has(index) || CheckSchema(context, schema.unevaluatedItems, value))
|
|
26
26
|
&& context.AddIndex(index);
|
|
27
27
|
});
|
|
@@ -32,7 +32,7 @@ export function CheckUnevaluatedItems(context, schema, value) {
|
|
|
32
32
|
export function ErrorUnevaluatedItems(context, schemaPath, instancePath, schema, value) {
|
|
33
33
|
const indices = context.GetIndices();
|
|
34
34
|
const unevaluatedItems = [];
|
|
35
|
-
const isUnevaluatedItems = G.EveryAll(value, (value, index) => {
|
|
35
|
+
const isUnevaluatedItems = G.EveryAll(value, 0, (value, index) => {
|
|
36
36
|
const nextContext = new AccumulatedErrorContext(context.GetContext(), context.GetSchema());
|
|
37
37
|
const isEvaluatedItem = (indices.has(index) || ErrorSchema(nextContext, schemaPath, instancePath, schema.unevaluatedItems, value))
|
|
38
38
|
&& context.AddIndex(index);
|
|
@@ -10,7 +10,7 @@ export function BuildUnevaluatedProperties(context, schema, value) {
|
|
|
10
10
|
const hasKey = E.Call(E.Member('keys', 'has'), ['key']);
|
|
11
11
|
const addKey = E.Call(E.Member('context', 'AddKey'), ['key']);
|
|
12
12
|
const isSchema = BuildSchema(context, schema.unevaluatedProperties, `value`);
|
|
13
|
-
const isEvery = E.
|
|
13
|
+
const isEvery = E.Every(E.Entries(value), E.Constant(0), ['[key, value]', '_'], E.Or(hasKey, E.And(isSchema, addKey)));
|
|
14
14
|
return E.Call(E.ArrowFunction(['context'], E.Statements([
|
|
15
15
|
E.ConstDeclaration('keys', keys),
|
|
16
16
|
E.Return(isEvery)
|
|
@@ -21,7 +21,7 @@ export function BuildUnevaluatedProperties(context, schema, value) {
|
|
|
21
21
|
// ------------------------------------------------------------------
|
|
22
22
|
export function CheckUnevaluatedProperties(context, schema, value) {
|
|
23
23
|
const keys = context.GetKeys();
|
|
24
|
-
return G.Every(G.Entries(value), ([key, value]) => {
|
|
24
|
+
return G.Every(G.Entries(value), 0, ([key, value]) => {
|
|
25
25
|
return keys.has(key)
|
|
26
26
|
|| (CheckSchema(context, schema.unevaluatedProperties, value) && context.AddKey(key));
|
|
27
27
|
});
|
|
@@ -32,7 +32,7 @@ export function CheckUnevaluatedProperties(context, schema, value) {
|
|
|
32
32
|
export function ErrorUnevaluatedProperties(context, schemaPath, instancePath, schema, value) {
|
|
33
33
|
const keys = context.GetKeys();
|
|
34
34
|
const unevaluatedProperties = [];
|
|
35
|
-
const isUnevaluatedProperties = G.EveryAll(G.Entries(value), ([key, value]) => {
|
|
35
|
+
const isUnevaluatedProperties = G.EveryAll(G.Entries(value), 0, ([key, value]) => {
|
|
36
36
|
const nextContext = new AccumulatedErrorContext(context.GetContext(), context.GetSchema());
|
|
37
37
|
const isEvaluatedProperty = keys.has(key)
|
|
38
38
|
|| (ErrorSchema(nextContext, schemaPath, instancePath, schema.unevaluatedProperties, value) && context.AddKey(key));
|
|
@@ -10,7 +10,7 @@ import { Guard } from '../../guard/index.mjs';
|
|
|
10
10
|
export function IsRefine(value) {
|
|
11
11
|
return Guard.HasPropertyKey(value, '~refine')
|
|
12
12
|
&& Guard.IsArray(value["~refine"])
|
|
13
|
-
&& Guard.Every(value['~refine'], value => Guard.IsObject(value)
|
|
13
|
+
&& Guard.Every(value['~refine'], 0, value => Guard.IsObject(value)
|
|
14
14
|
&& Guard.HasPropertyKey(value, 'callback')
|
|
15
15
|
&& Guard.HasPropertyKey(value, 'message')
|
|
16
16
|
&& Guard.IsFunction(value.callback)
|
|
@@ -20,7 +20,9 @@ export class BaseNotImplemented extends Error {
|
|
|
20
20
|
/** Base class for creating extension types. */
|
|
21
21
|
export class Base {
|
|
22
22
|
constructor() {
|
|
23
|
-
const validator = new BaseValidator(
|
|
23
|
+
const validator = new BaseValidator(
|
|
24
|
+
// @ts-ignore TS 5.0.4 - unable to derive guard type
|
|
25
|
+
(value) => this.Check(value), (value) => this.Errors(value));
|
|
24
26
|
const configuration = {
|
|
25
27
|
writable: false,
|
|
26
28
|
configurable: false,
|