@depup/typebox 1.3.16-depup.0 → 1.3.27-depup.0
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/README.md +2 -2
- package/build/compile/validator.d.mts +1 -1
- package/build/compile/validator.mjs +1 -1
- package/build/format/email.mjs +1 -1
- package/build/format/idna/idn-hostname.mjs +21 -1
- package/build/format/iri.mjs +5 -1
- package/build/format/json_pointer.d.mts +2 -2
- package/build/format/json_pointer.mjs +2 -2
- package/build/format/json_pointer_uri_fragment.d.mts +2 -2
- package/build/format/json_pointer_uri_fragment.mjs +2 -2
- package/build/format/relative_json_pointer.d.mts +2 -2
- package/build/format/relative_json_pointer.mjs +2 -2
- package/build/guard/emit.mjs +2 -4
- package/build/guard/guard.mjs +6 -18
- package/build/guard/string.mjs +16 -24
- package/build/schema/compile.d.mts +3 -2
- package/build/schema/compile.mjs +8 -8
- package/build/schema/engine/_context.d.mts +1 -6
- package/build/schema/engine/_context.mjs +9 -14
- package/build/schema/engine/_functions.mjs +1 -1
- package/build/schema/engine/_stack.d.mts +6 -2
- package/build/schema/engine/_stack.mjs +135 -32
- package/build/schema/engine/additionalProperties.mjs +16 -4
- package/build/schema/engine/allOf.mjs +2 -2
- package/build/schema/engine/anyOf.mjs +2 -2
- package/build/schema/engine/if.mjs +2 -2
- package/build/schema/engine/oneOf.mjs +2 -2
- package/build/schema/engine/propertyNames.mjs +1 -3
- package/build/schema/engine/ref.mjs +2 -2
- package/build/schema/engine/schema.mjs +6 -0
- package/build/schema/engine/unevaluatedItems.mjs +2 -2
- package/build/schema/engine/unevaluatedProperties.mjs +2 -2
- package/build/schema/errors.d.mts +2 -2
- package/build/schema/errors.mjs +7 -13
- package/build/schema/intern/index.d.mts +1 -0
- package/build/schema/intern/index.mjs +1 -0
- package/build/schema/intern/intern.d.mts +14 -0
- package/build/schema/intern/intern.mjs +259 -0
- package/build/schema/parse.d.mts +1 -0
- package/build/schema/parse.mjs +10 -5
- package/build/schema/resolve/resolve.d.mts +34 -3
- package/build/schema/resolve/resolve.mjs +198 -73
- package/build/schema/schema.d.mts +1 -0
- package/build/schema/schema.mjs +1 -0
- package/build/system/memory/assign.mjs +2 -1
- package/build/system/memory/create.mjs +3 -4
- package/build/system/memory/discard.mjs +2 -2
- package/build/system/memory/freeze.d.mts +4 -0
- package/build/system/memory/freeze.mjs +6 -0
- package/build/system/memory/update.mjs +3 -2
- package/build/value/errors/errors.d.mts +2 -12
- package/build/value/errors/errors.mjs +2 -7
- package/changes.json +1 -1
- package/package.json +3 -3
- package/readme.md +9 -5
package/README.md
CHANGED
|
@@ -13,8 +13,8 @@ npm install @depup/typebox
|
|
|
13
13
|
|
|
14
14
|
| Field | Value |
|
|
15
15
|
|-------|-------|
|
|
16
|
-
| Original | [typebox](https://www.npmjs.com/package/typebox) @ 1.3.
|
|
17
|
-
| Processed | 2026-
|
|
16
|
+
| Original | [typebox](https://www.npmjs.com/package/typebox) @ 1.3.27 |
|
|
17
|
+
| Processed | 2026-09-06 |
|
|
18
18
|
| Smoke test | passed |
|
|
19
19
|
| Deps updated | 0 |
|
|
20
20
|
|
|
@@ -18,7 +18,7 @@ export declare class Validator<Context extends TProperties = TProperties, Type e
|
|
|
18
18
|
Check(value: unknown): value is Encode;
|
|
19
19
|
/** Validates a value and returns it. Will throw if invalid. */
|
|
20
20
|
Parse(value: unknown): Encode;
|
|
21
|
-
/**
|
|
21
|
+
/** Returns an array of validation errors for the given value. */
|
|
22
22
|
Errors(value: unknown): TLocalizedValidationError[];
|
|
23
23
|
/** Cleans a value using the Validator type. */
|
|
24
24
|
Clean(value: unknown): unknown;
|
|
@@ -53,7 +53,7 @@ export class Validator {
|
|
|
53
53
|
return Parser(this.Context(), this.Type(), value);
|
|
54
54
|
throw new ParseError(value, this.Errors(value));
|
|
55
55
|
}
|
|
56
|
-
/**
|
|
56
|
+
/** Returns an array of validation errors for the given value. */
|
|
57
57
|
Errors(value) {
|
|
58
58
|
if (this.IsAccelerated() && this.Check(value))
|
|
59
59
|
return [];
|
package/build/format/email.mjs
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
const Email = /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[^"\\]
|
|
1
|
+
const Email = /^(?:[a-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-z0-9!#$%&'*+/=?^_`{|}~-]+)*|"(?:[^"\\]|\\[\x20-\x7e])*")@(?:[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?(?:\.[a-z0-9](?:[a-z0-9-]{0,61}[a-z0-9])?)*|\[(?:IPv6:[a-f0-9:]+|(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])(?:\.(?:25[0-5]|2[0-4][0-9]|1[0-9]{2}|[1-9]?[0-9])){3})\])$/i;
|
|
2
2
|
/**
|
|
3
3
|
* Returns true if the value is an Email
|
|
4
4
|
* @specification https://datatracker.ietf.org/doc/html/rfc5322
|
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
import * as FormatBidi from './format/bidi.mjs';
|
|
2
2
|
import * as LabelUnicode from './label/unicode.mjs';
|
|
3
3
|
import * as LabelPuny from './label/puny.mjs';
|
|
4
|
+
// ------------------------------------------------------------------
|
|
5
|
+
// IsLabel
|
|
6
|
+
// ------------------------------------------------------------------
|
|
4
7
|
function IsValidLabelLength(value) {
|
|
5
8
|
return value.length > 0 && value.length <= 63;
|
|
6
9
|
}
|
|
@@ -8,9 +11,26 @@ function IsLabel(value) {
|
|
|
8
11
|
return IsValidLabelLength(value) && (LabelPuny.IsPunyLabel(value) ||
|
|
9
12
|
LabelUnicode.IsUnicodeLabel(value));
|
|
10
13
|
}
|
|
14
|
+
// ------------------------------------------------------------------
|
|
15
|
+
// NormalizeHostname
|
|
16
|
+
//
|
|
17
|
+
// Normalizes a hostname for label validation. Maps fullwidth
|
|
18
|
+
// codepoints to their ASCII equivalent (e.g. 'a' U+FF41 maps to
|
|
19
|
+
// 'a'), then normalizes for NFC such that equivalent codepoint
|
|
20
|
+
// sequences can be uniformly compared. It also removes codepoints
|
|
21
|
+
// that IDNA mapping ignores, and converts full stop variants to
|
|
22
|
+
// ASCII '.' so the hostname can be split into labels.
|
|
23
|
+
// ------------------------------------------------------------------
|
|
11
24
|
function NormalizeHostname(value) {
|
|
12
|
-
return value
|
|
25
|
+
return value
|
|
26
|
+
.replace(/[\uff01-\uff5e]/g, (char) => String.fromCharCode(char.charCodeAt(0) - 0xfee0)) // RE_FULLWIDTH_MAPPING
|
|
27
|
+
.normalize('NFC')
|
|
28
|
+
.replace(/[\u00ad\u034f\u180b-\u180d\u200b\ufe00-\ufe0f\u{e0100}-\u{e01ef}]/gu, '') // RE_IGNORED_MAPPING
|
|
29
|
+
.replace(/[\u002E\u3002\uFF0E\uFF61]/g, '.'); // RE_FULL_STOP_MAPPING
|
|
13
30
|
}
|
|
31
|
+
// ------------------------------------------------------------------
|
|
32
|
+
// IsIdnHostname
|
|
33
|
+
// ------------------------------------------------------------------
|
|
14
34
|
export function IsIdnHostname(value) {
|
|
15
35
|
if (value.length === 0 || value.includes(' '))
|
|
16
36
|
return false;
|
package/build/format/iri.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
const IpvFutureMatchMaxLength = 2048;
|
|
3
3
|
const IpvFutureMatch = /\[[vV][0-9a-fA-F]+\.[^\]]+\]/; // Guarded By IpvFutureMatchMaxLength
|
|
4
4
|
const InvalidIriChars = /[\x00-\x20<>\^`{|}\\]/;
|
|
5
|
+
const InvalidPercentEncoding = /%(?![0-9a-fA-F]{2})/;
|
|
5
6
|
// ------------------------------------------------------------------
|
|
6
7
|
// NarrowIpvFuture
|
|
7
8
|
//
|
|
@@ -26,6 +27,9 @@ export function IsIri(value) {
|
|
|
26
27
|
// 1. Reject strings containing unencoded whitespace or illegal control characters.
|
|
27
28
|
if (InvalidIriChars.test(value))
|
|
28
29
|
return false;
|
|
29
|
-
// 2.
|
|
30
|
+
// 2. Reject malformed percent-encoding triplets.
|
|
31
|
+
if (InvalidPercentEncoding.test(value))
|
|
32
|
+
return false;
|
|
33
|
+
// 3. Delegate to the native URL parser, patching the IPvFuture edge case beforehand.
|
|
30
34
|
return URL.canParse(NarrowIpvFuture(value));
|
|
31
35
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns true if the value is a json pointer
|
|
3
|
-
* @specification
|
|
4
|
-
* @source ajv-formats
|
|
3
|
+
* @specification https://datatracker.ietf.org/doc/html/rfc6901
|
|
4
|
+
* @source https://github.com/ajv-validator/ajv-formats
|
|
5
5
|
*/
|
|
6
6
|
export declare function IsJsonPointer(value: string): boolean;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const JsonPointer = /^(?:\/(?:[^~/]|~0|~1)*)*$/;
|
|
2
2
|
/**
|
|
3
3
|
* Returns true if the value is a json pointer
|
|
4
|
-
* @specification
|
|
5
|
-
* @source ajv-formats
|
|
4
|
+
* @specification https://datatracker.ietf.org/doc/html/rfc6901
|
|
5
|
+
* @source https://github.com/ajv-validator/ajv-formats
|
|
6
6
|
*/
|
|
7
7
|
export function IsJsonPointer(value) {
|
|
8
8
|
return JsonPointer.test(value);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns true if the value is a json pointer uri fragment
|
|
3
|
-
* @specification
|
|
4
|
-
* @source ajv-formats
|
|
3
|
+
* @specification https://datatracker.ietf.org/doc/html/rfc6901
|
|
4
|
+
* @source https://github.com/ajv-validator/ajv-formats
|
|
5
5
|
*/
|
|
6
6
|
export declare function IsJsonPointerUriFragment(value: string): boolean;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const JsonPointerUriFragment = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;
|
|
2
2
|
/**
|
|
3
3
|
* Returns true if the value is a json pointer uri fragment
|
|
4
|
-
* @specification
|
|
5
|
-
* @source ajv-formats
|
|
4
|
+
* @specification https://datatracker.ietf.org/doc/html/rfc6901
|
|
5
|
+
* @source https://github.com/ajv-validator/ajv-formats
|
|
6
6
|
*/
|
|
7
7
|
export function IsJsonPointerUriFragment(value) {
|
|
8
8
|
return JsonPointerUriFragment.test(value);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns true if the value is a relative json pointer
|
|
3
|
-
* @specification
|
|
4
|
-
* @source ajv-formats
|
|
3
|
+
* @specification https://datatracker.ietf.org/doc/html/rfc6901
|
|
4
|
+
* @source https://github.com/ajv-validator/ajv-formats
|
|
5
5
|
*/
|
|
6
6
|
export declare function IsRelativeJsonPointer(value: string): boolean;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
const RelativeJsonPointer = /^(?:0|[1-9][0-9]*)(?:#|(?:\/(?:[^~/]|~0|~1)*)*)$/;
|
|
2
2
|
/**
|
|
3
3
|
* Returns true if the value is a relative json pointer
|
|
4
|
-
* @specification
|
|
5
|
-
* @source ajv-formats
|
|
4
|
+
* @specification https://datatracker.ietf.org/doc/html/rfc6901
|
|
5
|
+
* @source https://github.com/ajv-validator/ajv-formats
|
|
6
6
|
*/
|
|
7
7
|
export function IsRelativeJsonPointer(value) {
|
|
8
8
|
return RelativeJsonPointer.test(value);
|
package/build/guard/emit.mjs
CHANGED
|
@@ -106,15 +106,13 @@ export function IsMaxLength(value, length) {
|
|
|
106
106
|
// Array
|
|
107
107
|
// --------------------------------------------------------------------------
|
|
108
108
|
export function Every(value, offset, params, expression) {
|
|
109
|
-
return G.IsEqual(offset, '0')
|
|
110
|
-
? `${value}.every((${params[0]}, ${params[1]}) => ${expression})`
|
|
111
|
-
: `((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})`;
|
|
109
|
+
return G.IsEqual(offset, '0') ? `${value}.every((${params[0]}, ${params[1]}) => (${expression}))` : `${value}.every((${params[0]}, ${params[1]}) => (${params[1]} < ${offset}) || (${expression}))`;
|
|
112
110
|
}
|
|
113
111
|
export function Some(value, params, expression) {
|
|
114
112
|
return `${value}.some((${params[0]}, ${params[1]}) => ${expression})`;
|
|
115
113
|
}
|
|
116
114
|
export function SomeAll(value, params, expression) {
|
|
117
|
-
return `((value
|
|
115
|
+
return `((value) => { let result = false; value.forEach((${params[0]}, ${params[1]}) => { if (${expression}) result = true }); return result })(${value})`;
|
|
118
116
|
}
|
|
119
117
|
export function Counted(value, params, expression) {
|
|
120
118
|
return `${value}.reduce((result, ${params[0]}, ${params[1]}) => (${expression}) ? ++result : result, 0)`;
|
package/build/guard/guard.mjs
CHANGED
|
@@ -140,36 +140,24 @@ export function IsMinLength(value, length) {
|
|
|
140
140
|
// --------------------------------------------------------------------------
|
|
141
141
|
/** Returns true if every element from offset satisfies the callback, short-circuiting on the first failure */
|
|
142
142
|
export function Every(value, offset, callback) {
|
|
143
|
-
|
|
144
|
-
if (!callback(value[index], index))
|
|
145
|
-
return false;
|
|
146
|
-
}
|
|
147
|
-
return true;
|
|
143
|
+
return value.every((item, index) => (index < offset) || callback(item, index));
|
|
148
144
|
}
|
|
149
145
|
/** Returns true if every element from offset satisfies the callback, using exhaustive enumeration */
|
|
150
146
|
export function EveryAll(value, offset, callback) {
|
|
151
147
|
let result = true;
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
result = false;
|
|
155
|
-
}
|
|
148
|
+
value.forEach((item, index) => { if ((index >= offset) && !callback(item, index))
|
|
149
|
+
result = false; });
|
|
156
150
|
return result;
|
|
157
151
|
}
|
|
158
152
|
/** Returns true if some element satisfies the callback, short-circuiting on the first success */
|
|
159
153
|
export function Some(value, callback) {
|
|
160
|
-
|
|
161
|
-
if (callback(value[index], index))
|
|
162
|
-
return true;
|
|
163
|
-
}
|
|
164
|
-
return false;
|
|
154
|
+
return value.some((value, index) => callback(value, index));
|
|
165
155
|
}
|
|
166
156
|
/** Returns true if some element satisfies the callback, using exhaustive enumeration */
|
|
167
157
|
export function SomeAll(value, callback) {
|
|
168
158
|
let result = false;
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
result = true;
|
|
172
|
-
}
|
|
159
|
+
value.forEach((item, index) => { if (callback(item, index))
|
|
160
|
+
result = true; });
|
|
173
161
|
return result;
|
|
174
162
|
}
|
|
175
163
|
/** Returns the count of elements that satisfy the callback */
|
package/build/guard/string.mjs
CHANGED
|
@@ -84,10 +84,11 @@ function NextGraphemeClusterIndex(value, clusterStart) {
|
|
|
84
84
|
// IsGraphemeCodePoint
|
|
85
85
|
// --------------------------------------------------------------------------
|
|
86
86
|
function IsGraphemeCodePoint(value) {
|
|
87
|
-
return (
|
|
87
|
+
return ((value >= 0x0300) && ( // above special range
|
|
88
|
+
IsHighSurrogate(value) ||
|
|
88
89
|
IsCombiningMark(value) ||
|
|
89
90
|
IsVariationSelector(value) ||
|
|
90
|
-
IsZeroWidthJoiner(value));
|
|
91
|
+
IsZeroWidthJoiner(value)));
|
|
91
92
|
}
|
|
92
93
|
// --------------------------------------------------------------------------
|
|
93
94
|
// GraphemeCount
|
|
@@ -103,30 +104,22 @@ export function GraphemeCount(value) {
|
|
|
103
104
|
return count;
|
|
104
105
|
}
|
|
105
106
|
// --------------------------------------------------------------------------
|
|
106
|
-
//
|
|
107
|
+
// IsMinLengthSegmented
|
|
107
108
|
// --------------------------------------------------------------------------
|
|
108
109
|
/** Checks if a string has at least a minimum number of grapheme clusters */
|
|
109
110
|
function IsMinLengthSegmented(value, minLength) {
|
|
110
|
-
//
|
|
111
|
-
// Inaccessible via public interface (review)
|
|
112
|
-
//
|
|
113
|
-
// deno-coverage-ignore-start
|
|
114
|
-
// ----------------------------------------------------------------
|
|
115
|
-
if (minLength === 0)
|
|
116
|
-
return true; // 0-length
|
|
117
|
-
// deno-coverage-ignore-stop
|
|
111
|
+
// if (minLength === 0) return true // 0-length (unreachable)
|
|
118
112
|
let count = 0;
|
|
119
113
|
let index = 0;
|
|
120
114
|
while (index < value.length) {
|
|
121
115
|
index = NextGraphemeClusterIndex(value, index);
|
|
122
|
-
count
|
|
123
|
-
if (count >= minLength)
|
|
116
|
+
if ((++count) >= minLength)
|
|
124
117
|
return true;
|
|
125
118
|
}
|
|
126
119
|
return false;
|
|
127
120
|
}
|
|
128
121
|
// --------------------------------------------------------------------------
|
|
129
|
-
//
|
|
122
|
+
// IsMaxLengthSegmented
|
|
130
123
|
// --------------------------------------------------------------------------
|
|
131
124
|
/** Checks if a string has at most a maximum number of grapheme clusters */
|
|
132
125
|
function IsMaxLengthSegmented(value, maxLength) {
|
|
@@ -134,8 +127,7 @@ function IsMaxLengthSegmented(value, maxLength) {
|
|
|
134
127
|
let index = 0;
|
|
135
128
|
while (index < value.length) {
|
|
136
129
|
index = NextGraphemeClusterIndex(value, index);
|
|
137
|
-
count
|
|
138
|
-
if (count > maxLength)
|
|
130
|
+
if ((++count) > maxLength)
|
|
139
131
|
return false;
|
|
140
132
|
}
|
|
141
133
|
return true;
|
|
@@ -147,30 +139,30 @@ function IsMaxLengthSegmented(value, maxLength) {
|
|
|
147
139
|
export function IsMinLength(value, minLength) {
|
|
148
140
|
if (minLength === 0)
|
|
149
141
|
return true; // 0-length
|
|
142
|
+
if (value.length < minLength)
|
|
143
|
+
return false; // length is upper bound on grapheme count
|
|
150
144
|
let index = 0;
|
|
151
|
-
while (
|
|
145
|
+
while (true) {
|
|
152
146
|
if (IsGraphemeCodePoint(value.charCodeAt(index))) {
|
|
153
147
|
return IsMinLengthSegmented(value, minLength);
|
|
154
148
|
}
|
|
155
|
-
index
|
|
156
|
-
if (index >= minLength)
|
|
149
|
+
if ((++index) >= minLength)
|
|
157
150
|
return true;
|
|
158
151
|
}
|
|
159
|
-
return false;
|
|
160
152
|
}
|
|
161
153
|
// --------------------------------------------------------------------------
|
|
162
154
|
// IsMaxLengthFast
|
|
163
155
|
// --------------------------------------------------------------------------
|
|
164
156
|
/** Fast check for maximum grapheme length, falls back to full check if needed */
|
|
165
157
|
export function IsMaxLength(value, maxLength) {
|
|
158
|
+
if (value.length <= maxLength)
|
|
159
|
+
return true; // length is upper bound on grapheme count
|
|
166
160
|
let index = 0;
|
|
167
|
-
while (
|
|
161
|
+
while (true) {
|
|
168
162
|
if (IsGraphemeCodePoint(value.charCodeAt(index))) {
|
|
169
163
|
return IsMaxLengthSegmented(value, maxLength);
|
|
170
164
|
}
|
|
171
|
-
index
|
|
172
|
-
if (index > maxLength)
|
|
165
|
+
if ((++index) > maxLength)
|
|
173
166
|
return false;
|
|
174
167
|
}
|
|
175
|
-
return true;
|
|
176
168
|
}
|
|
@@ -2,8 +2,9 @@ import { type TLocalizedValidationError } from '../error/index.mjs';
|
|
|
2
2
|
import { type Static } from '../type/types/static.mjs';
|
|
3
3
|
import * as Schema from './types/index.mjs';
|
|
4
4
|
export declare class Validator<const Schema extends Schema.XSchema = Schema.XSchema, Value extends unknown = Static<Schema>> {
|
|
5
|
-
private readonly buildResult;
|
|
6
5
|
private readonly evaluateResult;
|
|
6
|
+
private readonly context;
|
|
7
|
+
private readonly schema;
|
|
7
8
|
constructor(context: Record<string, Schema.XSchema>, schema: Schema);
|
|
8
9
|
/** Returns true if this Validator is using JIT acceleration. */
|
|
9
10
|
IsAccelerated(): boolean;
|
|
@@ -13,7 +14,7 @@ export declare class Validator<const Schema extends Schema.XSchema = Schema.XSch
|
|
|
13
14
|
Check(value: unknown): value is Value;
|
|
14
15
|
/** Validates a value and returns it. Will throw if invalid. */
|
|
15
16
|
Parse(value: unknown): Value;
|
|
16
|
-
/**
|
|
17
|
+
/** Returns an array of validation errors for the given value. */
|
|
17
18
|
Errors(value: unknown): [result: boolean, errors: TLocalizedValidationError[]];
|
|
18
19
|
}
|
|
19
20
|
/** Compiles this schema into a high performance Validator */
|
package/build/schema/compile.mjs
CHANGED
|
@@ -3,14 +3,15 @@
|
|
|
3
3
|
import { Arguments } from '../system/arguments/index.mjs';
|
|
4
4
|
import * as Build from './build.mjs';
|
|
5
5
|
import { Errors } from './errors.mjs';
|
|
6
|
-
import {
|
|
6
|
+
import { ThrowParseError } from './parse.mjs';
|
|
7
7
|
// ------------------------------------------------------------------
|
|
8
8
|
// Validator
|
|
9
9
|
// ------------------------------------------------------------------
|
|
10
10
|
export class Validator {
|
|
11
11
|
constructor(context, schema) {
|
|
12
|
-
this.
|
|
13
|
-
this.
|
|
12
|
+
this.evaluateResult = Build.Build(context, schema).Evaluate();
|
|
13
|
+
this.context = context;
|
|
14
|
+
this.schema = schema;
|
|
14
15
|
}
|
|
15
16
|
/** Returns true if this Validator is using JIT acceleration. */
|
|
16
17
|
IsAccelerated() {
|
|
@@ -18,7 +19,7 @@ export class Validator {
|
|
|
18
19
|
}
|
|
19
20
|
/** Returns the underlying Schema used to construct this Validator. */
|
|
20
21
|
Schema() {
|
|
21
|
-
return this.
|
|
22
|
+
return this.schema;
|
|
22
23
|
}
|
|
23
24
|
/** Performs a type-guard check on the provided value. */
|
|
24
25
|
Check(value) {
|
|
@@ -28,12 +29,11 @@ export class Validator {
|
|
|
28
29
|
Parse(value) {
|
|
29
30
|
if (this.evaluateResult.Check(value))
|
|
30
31
|
return value;
|
|
31
|
-
|
|
32
|
-
throw new ParseError(this.buildResult.Schema(), value, errors);
|
|
32
|
+
ThrowParseError(this.context, this.schema, value);
|
|
33
33
|
}
|
|
34
|
-
/**
|
|
34
|
+
/** Returns an array of validation errors for the given value. */
|
|
35
35
|
Errors(value) {
|
|
36
|
-
return Errors(this.
|
|
36
|
+
return Errors(this.context, this.schema, value);
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
/** Compiles this schema into a high performance Validator */
|
|
@@ -21,15 +21,10 @@ export declare class CheckContext {
|
|
|
21
21
|
GetKeys(): Set<string>;
|
|
22
22
|
Merge(results: CheckContext[]): true;
|
|
23
23
|
}
|
|
24
|
-
export type ErrorContextCallback = (error: TValidationError) => unknown;
|
|
25
24
|
export declare class ErrorContext extends CheckContext {
|
|
26
|
-
private readonly callback;
|
|
27
|
-
constructor(callback: ErrorContextCallback);
|
|
28
|
-
AddError(error: TValidationError): false;
|
|
29
|
-
}
|
|
30
|
-
export declare class AccumulatedErrorContext extends ErrorContext {
|
|
31
25
|
private readonly errors;
|
|
32
26
|
constructor();
|
|
27
|
+
AtCapacity(): boolean;
|
|
33
28
|
AddError(error: TValidationError): false;
|
|
34
29
|
GetErrors(): TValidationError[];
|
|
35
30
|
}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
+
import { Settings } from '../../system/settings/index.mjs';
|
|
2
3
|
import * as Schema from '../types/index.mjs';
|
|
3
4
|
import { Guard as G, EmitGuard as E } from '../../guard/index.mjs';
|
|
4
5
|
// ------------------------------------------------------------------
|
|
@@ -101,26 +102,20 @@ export class CheckContext {
|
|
|
101
102
|
return true;
|
|
102
103
|
}
|
|
103
104
|
}
|
|
104
|
-
export class ErrorContext extends CheckContext {
|
|
105
|
-
constructor(callback) {
|
|
106
|
-
super();
|
|
107
|
-
this.callback = callback;
|
|
108
|
-
}
|
|
109
|
-
AddError(error) {
|
|
110
|
-
this.callback(error);
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
105
|
// ------------------------------------------------------------------
|
|
115
|
-
//
|
|
106
|
+
// ErrorContext
|
|
116
107
|
// ------------------------------------------------------------------
|
|
117
|
-
export class
|
|
108
|
+
export class ErrorContext extends CheckContext {
|
|
118
109
|
constructor() {
|
|
119
|
-
super(
|
|
110
|
+
super();
|
|
120
111
|
this.errors = [];
|
|
121
112
|
}
|
|
113
|
+
AtCapacity() {
|
|
114
|
+
return this.errors.length >= Settings.Get().maxErrors;
|
|
115
|
+
}
|
|
122
116
|
AddError(error) {
|
|
123
|
-
this.
|
|
117
|
+
if (!this.AtCapacity())
|
|
118
|
+
this.errors.push(error);
|
|
124
119
|
return false;
|
|
125
120
|
}
|
|
126
121
|
GetErrors() {
|
|
@@ -55,7 +55,7 @@ export function GetFunctions() {
|
|
|
55
55
|
// CreateFunction
|
|
56
56
|
// ------------------------------------------------------------------
|
|
57
57
|
export function CreateFunction(stack, context, schema, value) {
|
|
58
|
-
const name = CreateName(schema, stack.
|
|
58
|
+
const name = CreateName(schema, stack.LexicalBaseURL());
|
|
59
59
|
const call = CreateCallExpression(context, schema, name, value);
|
|
60
60
|
if (funcs.has(name))
|
|
61
61
|
return call;
|
|
@@ -4,12 +4,16 @@ export declare class Stack {
|
|
|
4
4
|
private readonly context;
|
|
5
5
|
private readonly schema;
|
|
6
6
|
private readonly ids;
|
|
7
|
+
private readonly resourceIds;
|
|
7
8
|
private readonly anchors;
|
|
8
9
|
private readonly recursiveAnchors;
|
|
9
10
|
private readonly dynamicAnchors;
|
|
11
|
+
private readonly retrievedResources;
|
|
12
|
+
private readonly retrievedFrames;
|
|
13
|
+
private readonly resolvedResources;
|
|
14
|
+
private pendingResource;
|
|
10
15
|
constructor(context: Record<PropertyKey, Schema.XSchema>, schema: Schema.XSchema);
|
|
11
|
-
|
|
12
|
-
Base(): Schema.XSchemaObject;
|
|
16
|
+
LexicalBaseURL(): string;
|
|
13
17
|
Push(schema: Schema.XSchema): void;
|
|
14
18
|
Pop(schema: Schema.XSchema): void;
|
|
15
19
|
Ref(ref: Schema.XRef): Schema.XSchema | undefined;
|