@depup/typebox 1.3.27-depup.0 → 1.3.34-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.
Files changed (150) hide show
  1. package/README.md +2 -2
  2. package/build/compile/code.mjs +1 -2
  3. package/build/compile/validator.mjs +5 -1
  4. package/build/format/iri.mjs +16 -9
  5. package/build/guard/emit.mjs +2 -2
  6. package/build/guard/guard.d.mts +7 -5
  7. package/build/guard/guard.mjs +14 -9
  8. package/build/guard/index.mjs +6 -0
  9. package/build/guard/unicode/unicode.d.mts +6 -0
  10. package/build/guard/unicode/unicode.mjs +35 -0
  11. package/build/guard/{string.mjs → unicode/unicode_segment.mjs} +16 -19
  12. package/build/schema/build.mjs +4 -5
  13. package/build/schema/check.mjs +1 -1
  14. package/build/schema/engine/_context.d.mts +5 -1
  15. package/build/schema/engine/_context.mjs +16 -3
  16. package/build/schema/engine/_functions.d.mts +2 -2
  17. package/build/schema/engine/_functions.mjs +1 -1
  18. package/build/schema/engine/_pathing.d.mts +1 -0
  19. package/build/schema/engine/_pathing.mjs +11 -0
  20. package/build/schema/engine/_reducer.d.mts +3 -3
  21. package/build/schema/engine/_refine.d.mts +5 -5
  22. package/build/schema/engine/_refine.mjs +14 -9
  23. package/build/schema/engine/_stack.d.mts +34 -20
  24. package/build/schema/engine/_stack.mjs +143 -202
  25. package/build/schema/engine/additionalItems.d.mts +4 -4
  26. package/build/schema/engine/additionalProperties.d.mts +8 -8
  27. package/build/schema/engine/additionalProperties.mjs +12 -15
  28. package/build/schema/engine/allOf.d.mts +4 -4
  29. package/build/schema/engine/allOf.mjs +1 -1
  30. package/build/schema/engine/anyOf.d.mts +4 -4
  31. package/build/schema/engine/anyOf.mjs +4 -9
  32. package/build/schema/engine/boolean.d.mts +4 -4
  33. package/build/schema/engine/boolean.mjs +2 -6
  34. package/build/schema/engine/const.d.mts +4 -4
  35. package/build/schema/engine/const.mjs +2 -6
  36. package/build/schema/engine/contains.d.mts +4 -4
  37. package/build/schema/engine/contains.mjs +2 -6
  38. package/build/schema/engine/dependencies.d.mts +4 -4
  39. package/build/schema/engine/dependencies.mjs +5 -7
  40. package/build/schema/engine/dependentRequired.d.mts +4 -4
  41. package/build/schema/engine/dependentRequired.mjs +2 -6
  42. package/build/schema/engine/dependentSchemas.d.mts +4 -4
  43. package/build/schema/engine/dependentSchemas.mjs +2 -1
  44. package/build/schema/engine/dynamicRef.d.mts +4 -4
  45. package/build/schema/engine/dynamicRef.mjs +12 -8
  46. package/build/schema/engine/enum.d.mts +4 -4
  47. package/build/schema/engine/enum.mjs +2 -6
  48. package/build/schema/engine/exclusiveMaximum.d.mts +4 -4
  49. package/build/schema/engine/exclusiveMaximum.mjs +2 -6
  50. package/build/schema/engine/exclusiveMinimum.d.mts +4 -4
  51. package/build/schema/engine/exclusiveMinimum.mjs +2 -6
  52. package/build/schema/engine/format.d.mts +4 -4
  53. package/build/schema/engine/format.mjs +11 -8
  54. package/build/schema/engine/if.d.mts +4 -4
  55. package/build/schema/engine/if.mjs +5 -13
  56. package/build/schema/engine/items.d.mts +4 -4
  57. package/build/schema/engine/items.mjs +1 -1
  58. package/build/schema/engine/maxContains.d.mts +4 -4
  59. package/build/schema/engine/maxContains.mjs +2 -6
  60. package/build/schema/engine/maxItems.d.mts +4 -4
  61. package/build/schema/engine/maxItems.mjs +2 -6
  62. package/build/schema/engine/maxLength.d.mts +4 -4
  63. package/build/schema/engine/maxLength.mjs +2 -6
  64. package/build/schema/engine/maxProperties.d.mts +4 -4
  65. package/build/schema/engine/maxProperties.mjs +2 -6
  66. package/build/schema/engine/maximum.d.mts +4 -4
  67. package/build/schema/engine/maximum.mjs +2 -6
  68. package/build/schema/engine/minContains.d.mts +4 -4
  69. package/build/schema/engine/minContains.mjs +2 -6
  70. package/build/schema/engine/minItems.d.mts +5 -5
  71. package/build/schema/engine/minItems.mjs +2 -6
  72. package/build/schema/engine/minLength.d.mts +4 -4
  73. package/build/schema/engine/minLength.mjs +2 -6
  74. package/build/schema/engine/minProperties.d.mts +4 -4
  75. package/build/schema/engine/minProperties.mjs +2 -6
  76. package/build/schema/engine/minimum.d.mts +4 -4
  77. package/build/schema/engine/minimum.mjs +2 -6
  78. package/build/schema/engine/multipleOf.d.mts +4 -4
  79. package/build/schema/engine/multipleOf.mjs +2 -6
  80. package/build/schema/engine/not.d.mts +4 -4
  81. package/build/schema/engine/not.mjs +4 -8
  82. package/build/schema/engine/oneOf.d.mts +4 -4
  83. package/build/schema/engine/oneOf.mjs +5 -10
  84. package/build/schema/engine/pattern.d.mts +4 -4
  85. package/build/schema/engine/pattern.mjs +3 -7
  86. package/build/schema/engine/patternProperties.d.mts +4 -4
  87. package/build/schema/engine/patternProperties.mjs +4 -3
  88. package/build/schema/engine/prefixItems.d.mts +4 -4
  89. package/build/schema/engine/prefixItems.mjs +1 -1
  90. package/build/schema/engine/properties.d.mts +4 -4
  91. package/build/schema/engine/properties.mjs +4 -3
  92. package/build/schema/engine/propertyNames.d.mts +4 -4
  93. package/build/schema/engine/propertyNames.mjs +5 -8
  94. package/build/schema/engine/recursiveRef.d.mts +4 -4
  95. package/build/schema/engine/recursiveRef.mjs +12 -8
  96. package/build/schema/engine/ref.d.mts +4 -4
  97. package/build/schema/engine/ref.mjs +18 -14
  98. package/build/schema/engine/required.d.mts +4 -4
  99. package/build/schema/engine/required.mjs +2 -6
  100. package/build/schema/engine/schema.d.mts +7 -7
  101. package/build/schema/engine/schema.mjs +136 -138
  102. package/build/schema/engine/type.d.mts +4 -4
  103. package/build/schema/engine/type.mjs +2 -6
  104. package/build/schema/engine/unevaluatedItems.d.mts +4 -4
  105. package/build/schema/engine/unevaluatedItems.mjs +3 -7
  106. package/build/schema/engine/unevaluatedProperties.d.mts +4 -4
  107. package/build/schema/engine/unevaluatedProperties.mjs +3 -7
  108. package/build/schema/engine/uniqueItems.d.mts +4 -4
  109. package/build/schema/engine/uniqueItems.mjs +2 -6
  110. package/build/schema/errors.mjs +1 -1
  111. package/build/schema/intern/intern.d.mts +6 -9
  112. package/build/schema/intern/intern.mjs +90 -56
  113. package/build/schema/meta/draft_2019_09.d.mts +2 -0
  114. package/build/schema/meta/draft_2019_09.mjs +288 -0
  115. package/build/schema/meta/draft_2020_12.d.mts +2 -0
  116. package/build/schema/meta/draft_2020_12.mjs +300 -0
  117. package/build/schema/meta/draft_3.d.mts +2 -0
  118. package/build/schema/meta/draft_3.mjs +143 -0
  119. package/build/schema/meta/draft_4.d.mts +2 -0
  120. package/build/schema/meta/draft_4.mjs +149 -0
  121. package/build/schema/meta/draft_6.d.mts +2 -0
  122. package/build/schema/meta/draft_6.mjs +155 -0
  123. package/build/schema/meta/draft_7.d.mts +2 -0
  124. package/build/schema/meta/draft_7.mjs +172 -0
  125. package/build/schema/meta/index.d.mts +2 -0
  126. package/build/schema/meta/index.mjs +2 -0
  127. package/build/schema/meta/meta.d.mts +9 -0
  128. package/build/schema/meta/meta.mjs +15 -0
  129. package/build/schema/meta/schema.d.mts +6 -0
  130. package/build/schema/meta/schema.mjs +1 -0
  131. package/build/schema/parse.mjs +3 -0
  132. package/build/schema/pointer/pointer.d.mts +1 -6
  133. package/build/schema/pointer/pointer.mjs +47 -64
  134. package/build/schema/resolve/resolve.d.mts +6 -32
  135. package/build/schema/resolve/resolve.mjs +231 -227
  136. package/build/schema/schema.d.mts +1 -0
  137. package/build/schema/schema.mjs +1 -0
  138. package/build/system/settings/internal.d.mts +2 -0
  139. package/build/system/settings/internal.mjs +20 -0
  140. package/build/system/settings/settings.d.mts +11 -0
  141. package/build/system/settings/settings.mjs +14 -0
  142. package/build/type/extends/inference.d.mts +1 -1
  143. package/build/type/extends/inference.mjs +15 -2
  144. package/build/type/extends/tuple.d.mts +2 -1
  145. package/build/type/extends/tuple.mjs +21 -1
  146. package/build/value/parse/parse.mjs +10 -4
  147. package/changes.json +1 -1
  148. package/package.json +3 -3
  149. package/readme.md +52 -84
  150. /package/build/guard/{string.d.mts → unicode/unicode_segment.d.mts} +0 -0
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.27 |
17
- | Processed | 2026-09-06 |
16
+ | Original | [typebox](https://www.npmjs.com/package/typebox) @ 1.3.34 |
17
+ | Processed | 2026-09-20 |
18
18
  | Smoke test | passed |
19
19
  | Deps updated | 0 |
20
20
 
@@ -16,9 +16,8 @@ function Separator() {
16
16
  function ImportSection(build) {
17
17
  const context = build.UseUnevaluated() ? [`import { CheckContext } from "typebox/schema"`] : [];
18
18
  const hashing = `import { Hashing } from "typebox/system"`;
19
- const format = `import { Format } from "typebox/format"`;
20
19
  const guard = `import { Guard } from "typebox/guard"`;
21
- return [...context, hashing, format, guard];
20
+ return [...context, hashing, guard];
22
21
  }
23
22
  // ------------------------------------------------------------------
24
23
  // ExternalSection
@@ -1,4 +1,5 @@
1
1
  // deno-fmt-ignore-file
2
+ import { EnableParseErrors, DisableParseErrors } from '../system/settings/internal.mjs';
2
3
  import { Settings } from '../system/settings/index.mjs';
3
4
  import { Errors, Clean, Convert, Create, Default, Decode, Encode, HasCodec, Parser, ParseError } from '../value/index.mjs';
4
5
  import { Build } from '../schema/index.mjs';
@@ -51,7 +52,10 @@ export class Validator {
51
52
  return value;
52
53
  if (Settings.Get().correctiveParse)
53
54
  return Parser(this.Context(), this.Type(), value);
54
- throw new ParseError(value, this.Errors(value));
55
+ EnableParseErrors();
56
+ const errors = this.Errors(value);
57
+ DisableParseErrors();
58
+ throw new ParseError(value, errors);
55
59
  }
56
60
  /** Returns an array of validation errors for the given value. */
57
61
  Errors(value) {
@@ -1,9 +1,10 @@
1
1
  // deno-lint-ignore-file no-control-regex
2
- const IpvFutureMatchMaxLength = 2048;
3
- const IpvFutureMatch = /\[[vV][0-9a-fA-F]+\.[^\]]+\]/; // Guarded By IpvFutureMatchMaxLength
4
- const InvalidIriChars = /[\x00-\x20<>\^`{|}\\]/;
5
- const InvalidPercentEncoding = /%(?![0-9a-fA-F]{2})/;
6
2
  // ------------------------------------------------------------------
3
+ //
4
+ // Removed by the following PR
5
+ //
6
+ // https://github.com/json-schema-org/JSON-Schema-Test-Suite/pull/1176
7
+ //
7
8
  // NarrowIpvFuture
8
9
  //
9
10
  // Substitutes an IPvFuture address with a standard IPv6 loopback
@@ -13,12 +14,18 @@ const InvalidPercentEncoding = /%(?![0-9a-fA-F]{2})/;
13
14
  // be expensive on large strings, this operation is strictly
14
15
  // limited to inputs under a defined length threshold.
15
16
  //
16
- // (review-optimization)
17
+ // ------------------------------------------------------------------
18
+ //
19
+ // const IpvFutureMatchMaxLength = 2048
20
+ // const IpvFutureMatch = /\[[vV][0-9a-fA-F]+\.[^\]]+\]/ // Guarded By IpvFutureMatchMaxLength
21
+ //
22
+ // function NarrowIpvFuture(value: string): string {
23
+ // return value.length < IpvFutureMatchMaxLength ? value.replace(IpvFutureMatch, '[::1]') : value
24
+ // }
17
25
  //
18
26
  // ------------------------------------------------------------------
19
- function NarrowIpvFuture(value) {
20
- return value.length < IpvFutureMatchMaxLength ? value.replace(IpvFutureMatch, '[::1]') : value;
21
- }
27
+ const InvalidIriChars = /[\x00-\x20<>\^`{|}\\]/;
28
+ const InvalidPercentEncoding = /%(?![0-9a-fA-F]{2})/;
22
29
  /**
23
30
  * Returns true if the value is a valid Internationalized Resource Identifier.
24
31
  * @specification https://datatracker.ietf.org/doc/html/rfc3987
@@ -31,5 +38,5 @@ export function IsIri(value) {
31
38
  if (InvalidPercentEncoding.test(value))
32
39
  return false;
33
40
  // 3. Delegate to the native URL parser, patching the IPvFuture edge case beforehand.
34
- return URL.canParse(NarrowIpvFuture(value));
41
+ return URL.canParse(value);
35
42
  }
@@ -97,10 +97,10 @@ export function IsGreaterEqualThan(left, right) {
97
97
  // String
98
98
  // --------------------------------------------------------------------------
99
99
  export function IsMinLength(value, length) {
100
- return `Guard.IsMinLength(${value}, ${length})`;
100
+ return `(${value}.length >= ${(+length) << 1} || (${value}.length >= ${length} && Guard.CodePointCount(${value}) >= ${length}))`;
101
101
  }
102
102
  export function IsMaxLength(value, length) {
103
- return `Guard.IsMaxLength(${value}, ${length})`;
103
+ return `(${value}.length <= ${length} || (${value}.length <= ${(+length) << 1} && Guard.CodePointCount(${value}) <= ${length}))`;
104
104
  }
105
105
  // --------------------------------------------------------------------------
106
106
  // Array
@@ -33,12 +33,14 @@ export declare function IsMultipleOf(dividend: bigint | number, divisor: bigint
33
33
  /** Returns true if the value appears to be an instance of a class. */
34
34
  export declare function IsClassInstance(value: unknown): boolean;
35
35
  export declare function IsValueLike(value: unknown): value is bigint | boolean | null | number | string | undefined;
36
- /** Returns the number of grapheme clusters in the string */
36
+ /** Returns the total number of visual grapheme clusters in the string. */
37
37
  export declare function GraphemeCount(value: string): number;
38
- /** Returns true if the string has at most the given number of graphemes */
39
- export declare function IsMaxLength(value: string, length: number): boolean;
40
- /** Returns true if the string has at least the given number of graphemes */
41
- export declare function IsMinLength(value: string, length: number): boolean;
38
+ /** Returns the total number of Unicode code points in the string. */
39
+ export declare function CodePointCount(value: string): number;
40
+ /** Returns true if the string length in Unicode code points does not exceed maxLength */
41
+ export declare function IsMaxLength(value: string, maxLength: number): boolean;
42
+ /** Returns true if the string length in Unicode code points is at least minLength */
43
+ export declare function IsMinLength(value: string, minLength: number): boolean;
42
44
  /** Returns true if every element from offset satisfies the callback, short-circuiting on the first failure */
43
45
  export declare function Every<T>(value: T[], offset: number, callback: (value: T, index: number) => boolean): boolean;
44
46
  /** Returns true if every element from offset satisfies the callback, using exhaustive enumeration */
@@ -1,5 +1,6 @@
1
1
  // deno-fmt-ignore-file
2
- import * as String from './string.mjs';
2
+ import * as UnicodeSegmentGuard from './unicode/unicode_segment.mjs';
3
+ import * as UnicodeGuard from './unicode/unicode.mjs';
3
4
  // --------------------------------------------------------------------------
4
5
  // Guards
5
6
  // --------------------------------------------------------------------------
@@ -123,17 +124,21 @@ export function IsValueLike(value) {
123
124
  // --------------------------------------------------------------------------
124
125
  // String
125
126
  // --------------------------------------------------------------------------
126
- /** Returns the number of grapheme clusters in the string */
127
+ /** Returns the total number of visual grapheme clusters in the string. */
127
128
  export function GraphemeCount(value) {
128
- return String.GraphemeCount(value);
129
+ return UnicodeSegmentGuard.GraphemeCount(value);
129
130
  }
130
- /** Returns true if the string has at most the given number of graphemes */
131
- export function IsMaxLength(value, length) {
132
- return String.IsMaxLength(value, length);
131
+ /** Returns the total number of Unicode code points in the string. */
132
+ export function CodePointCount(value) {
133
+ return UnicodeGuard.CodePointCount(value);
133
134
  }
134
- /** Returns true if the string has at least the given number of graphemes */
135
- export function IsMinLength(value, length) {
136
- return String.IsMinLength(value, length);
135
+ /** Returns true if the string length in Unicode code points does not exceed maxLength */
136
+ export function IsMaxLength(value, maxLength) {
137
+ return UnicodeGuard.IsMaxLength(value, maxLength);
138
+ }
139
+ /** Returns true if the string length in Unicode code points is at least minLength */
140
+ export function IsMinLength(value, minLength) {
141
+ return UnicodeGuard.IsMinLength(value, minLength);
137
142
  }
138
143
  // --------------------------------------------------------------------------
139
144
  // Array
@@ -1,6 +1,12 @@
1
+ // ------------------------------------------------------------------
2
+ // Guards
3
+ // ------------------------------------------------------------------
1
4
  export * as EmitGuard from './emit.mjs';
2
5
  export * as GlobalsGuard from './globals.mjs';
3
6
  export * as NativeGuard from './native.mjs';
7
+ // ------------------------------------------------------------------
8
+ // Default
9
+ // ------------------------------------------------------------------
4
10
  import * as Guard from './guard.mjs';
5
11
  export * as Guard from './guard.mjs';
6
12
  export default Guard;
@@ -0,0 +1,6 @@
1
+ /** Returns the total number of Unicode code points in the string */
2
+ export declare function CodePointCount(value: string): number;
3
+ /** Returns true if the string length in Unicode code points is less than or equal to maxLength */
4
+ export declare function IsMaxLength(value: string, maxLength: number): boolean;
5
+ /** Returns true if the string length in Unicode code points is greater than or equal to minLength */
6
+ export declare function IsMinLength(value: string, minLength: number): boolean;
@@ -0,0 +1,35 @@
1
+ // ------------------------------------------------------------------
2
+ // CodePointCount (10-bit Shift Branchless)
3
+ //
4
+ // Counts code points by enumerating UTF-16 sequences and incrementing
5
+ // when not within a high/low pairing. Because surrogate blocks are
6
+ // 1024 (2^10) wide and aligned, by shifting right by (0xA), we can
7
+ // collapse each unit to a constant per block (high: 0x36, low: 0x37)
8
+ // and shift again into a packed (0x3637) for comparison. Fetch calls
9
+ // to charCodeAt(...) are kept to one call per iteration.
10
+ //
11
+ // ------------------------------------------------------------------
12
+ /** Returns the total number of Unicode code points in the string */
13
+ export function CodePointCount(value) {
14
+ let result = 0, index = 0, prev = 0;
15
+ while (index < value.length) {
16
+ const next = value.charCodeAt(index++) >> 0xA; // shift (10-bits into high/low)
17
+ result += +(((prev << 8) | next) !== 0x3637); // packed (or +!(prev === 0x36 && next === 0x37))
18
+ prev = next;
19
+ }
20
+ return result;
21
+ }
22
+ // ------------------------------------------------------------------
23
+ // IsMaxLength
24
+ // ------------------------------------------------------------------
25
+ /** Returns true if the string length in Unicode code points is less than or equal to maxLength */
26
+ export function IsMaxLength(value, maxLength) {
27
+ return value.length <= maxLength || (value.length <= (maxLength << 1) && CodePointCount(value) <= maxLength);
28
+ }
29
+ // ------------------------------------------------------------------
30
+ // IsMinLength
31
+ // ------------------------------------------------------------------
32
+ /** Returns true if the string length in Unicode code points is greater than or equal to minLength */
33
+ export function IsMinLength(value, minLength) {
34
+ return value.length >= (minLength << 1) || (value.length >= minLength && CodePointCount(value) >= minLength);
35
+ }
@@ -91,26 +91,12 @@ function IsGraphemeCodePoint(value) {
91
91
  IsZeroWidthJoiner(value)));
92
92
  }
93
93
  // --------------------------------------------------------------------------
94
- // GraphemeCount
95
- // --------------------------------------------------------------------------
96
- /** Returns the number of grapheme clusters in a string */
97
- export function GraphemeCount(value) {
98
- let count = 0;
99
- let index = 0;
100
- while (index < value.length) {
101
- index = NextGraphemeClusterIndex(value, index);
102
- count++;
103
- }
104
- return count;
105
- }
106
- // --------------------------------------------------------------------------
107
94
  // IsMinLengthSegmented
108
95
  // --------------------------------------------------------------------------
109
96
  /** Checks if a string has at least a minimum number of grapheme clusters */
110
97
  function IsMinLengthSegmented(value, minLength) {
111
98
  // if (minLength === 0) return true // 0-length (unreachable)
112
- let count = 0;
113
- let index = 0;
99
+ let count = 0, index = 0;
114
100
  while (index < value.length) {
115
101
  index = NextGraphemeClusterIndex(value, index);
116
102
  if ((++count) >= minLength)
@@ -123,8 +109,7 @@ function IsMinLengthSegmented(value, minLength) {
123
109
  // --------------------------------------------------------------------------
124
110
  /** Checks if a string has at most a maximum number of grapheme clusters */
125
111
  function IsMaxLengthSegmented(value, maxLength) {
126
- let count = 0;
127
- let index = 0;
112
+ let count = 0, index = 0;
128
113
  while (index < value.length) {
129
114
  index = NextGraphemeClusterIndex(value, index);
130
115
  if ((++count) > maxLength)
@@ -133,7 +118,19 @@ function IsMaxLengthSegmented(value, maxLength) {
133
118
  return true;
134
119
  }
135
120
  // --------------------------------------------------------------------------
136
- // IsMinLengthFast
121
+ // GraphemeCount
122
+ // --------------------------------------------------------------------------
123
+ /** Returns the number of grapheme clusters in a string */
124
+ export function GraphemeCount(value) {
125
+ let count = 0, index = 0;
126
+ while (index < value.length) {
127
+ index = NextGraphemeClusterIndex(value, index);
128
+ count++;
129
+ }
130
+ return count;
131
+ }
132
+ // --------------------------------------------------------------------------
133
+ // IsMinLength
137
134
  // --------------------------------------------------------------------------
138
135
  /** Fast check for minimum grapheme length, falls back to full check if needed */
139
136
  export function IsMinLength(value, minLength) {
@@ -151,7 +148,7 @@ export function IsMinLength(value, minLength) {
151
148
  }
152
149
  }
153
150
  // --------------------------------------------------------------------------
154
- // IsMaxLengthFast
151
+ // IsMaxLength
155
152
  // --------------------------------------------------------------------------
156
153
  /** Fast check for maximum grapheme length, falls back to full check if needed */
157
154
  export function IsMaxLength(value, maxLength) {
@@ -4,7 +4,6 @@ import { Arguments } from '../system/arguments/index.mjs';
4
4
  import { Environment } from '../system/environment/index.mjs';
5
5
  import { Hashing } from '../system/hashing/index.mjs';
6
6
  import { Guard } from '../guard/index.mjs';
7
- import { Format } from '../format/index.mjs';
8
7
  import * as Engine from './engine/index.mjs';
9
8
  // ------------------------------------------------------------------
10
9
  // CreateCode
@@ -20,14 +19,14 @@ function CreateCode(build) {
20
19
  // CreateEvaluatedCheck
21
20
  // ------------------------------------------------------------------
22
21
  function CreateEvaluatedCheck(build, code) {
23
- const factory = Environment.Evaluate('CheckContext', 'Guard', 'Format', 'Hashing', build.External().identifier, code);
24
- return factory(Engine.CheckContext, Guard, Format, Hashing, build.External().variables);
22
+ const factory = Environment.Evaluate('CheckContext', 'Guard', 'Hashing', build.External().identifier, code);
23
+ return factory(Engine.CheckContext, Guard, Hashing, build.External().variables);
25
24
  }
26
25
  // ------------------------------------------------------------------
27
26
  // CreateDynamicCheck
28
27
  // ------------------------------------------------------------------
29
28
  function CreateDynamicCheck(build) {
30
- const stack = new Engine.Stack(build.Context(), build.Schema());
29
+ const stack = Engine.Stack(build.Context(), build.Schema());
31
30
  const context = new Engine.CheckContext();
32
31
  return (value) => Engine.CheckSchema(stack, context, build.Schema(), value);
33
32
  }
@@ -109,7 +108,7 @@ export function Build(...args) {
109
108
  });
110
109
  Engine.ResetExternal();
111
110
  Engine.ResetFunctions();
112
- const stack = new Engine.Stack(context, schema);
111
+ const stack = Engine.Stack(context, schema);
113
112
  const build = new Engine.BuildContext(Engine.HasUnevaluated(context, schema));
114
113
  const call = Engine.CreateFunction(stack, build, schema, 'value');
115
114
  const functions = Engine.GetFunctions();
@@ -8,7 +8,7 @@ export function Check(...args) {
8
8
  3: (context, schema, value) => [context, schema, value],
9
9
  2: (schema, value) => [{}, schema, value]
10
10
  });
11
- const stack = new Engine.Stack(context, schema);
11
+ const stack = Engine.Stack(context, schema);
12
12
  const checkContext = new Engine.CheckContext();
13
13
  return Engine.CheckSchema(stack, checkContext, schema, value);
14
14
  }
@@ -25,6 +25,10 @@ export declare class ErrorContext extends CheckContext {
25
25
  private readonly errors;
26
26
  constructor();
27
27
  AtCapacity(): boolean;
28
- AddError(error: TValidationError): false;
28
+ AddError<Keyword extends TValidationError['keyword']>(keyword: Keyword, schemaPath: string, instancePath: string, params: Extract<TValidationError, {
29
+ keyword: Keyword;
30
+ }>['params']): false;
31
+ AddErrors(error: TValidationError[]): false;
29
32
  GetErrors(): TValidationError[];
33
+ private AddErrorObject;
30
34
  }
@@ -110,15 +110,28 @@ export class ErrorContext extends CheckContext {
110
110
  super();
111
111
  this.errors = [];
112
112
  }
113
+ // ----------------------------------------------------------------
114
+ // Public
115
+ // ----------------------------------------------------------------
113
116
  AtCapacity() {
114
117
  return this.errors.length >= Settings.Get().maxErrors;
115
118
  }
116
- AddError(error) {
117
- if (!this.AtCapacity())
118
- this.errors.push(error);
119
+ AddError(keyword, schemaPath, instancePath, params) {
120
+ return this.AddErrorObject({ keyword, schemaPath, instancePath, params });
121
+ }
122
+ AddErrors(error) {
123
+ error.forEach(error => this.AddErrorObject(error));
119
124
  return false;
120
125
  }
121
126
  GetErrors() {
122
127
  return this.errors;
123
128
  }
129
+ // ----------------------------------------------------------------
130
+ // Private
131
+ // ----------------------------------------------------------------
132
+ AddErrorObject(error) {
133
+ if (!this.AtCapacity())
134
+ this.errors.push(error);
135
+ return false;
136
+ }
124
137
  }
@@ -1,6 +1,6 @@
1
1
  import * as Schema from '../types/index.mjs';
2
- import { Stack } from './_stack.mjs';
2
+ import * as Stack from './_stack.mjs';
3
3
  import { BuildContext } from './_context.mjs';
4
4
  export declare function ResetFunctions(): void;
5
5
  export declare function GetFunctions(): string[];
6
- export declare function CreateFunction(stack: Stack, context: BuildContext, schema: Schema.XSchema, value: string): string;
6
+ export declare function CreateFunction(stack: Stack.XStack, context: BuildContext, schema: Schema.XSchema, value: string): string;
@@ -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.LexicalBaseURL());
58
+ const name = CreateName(schema, stack.lexicalBase);
59
59
  const call = CreateCallExpression(context, schema, name, value);
60
60
  if (funcs.has(name))
61
61
  return call;
@@ -0,0 +1 @@
1
+ export declare function EncodeFragment(fragment: string): string;
@@ -0,0 +1,11 @@
1
+ // ------------------------------------------------------------------
2
+ // EncodeFragment
3
+ //
4
+ // We use this function to encode instancePath and schemaPath path
5
+ // fragments for errors. We need this encoding such that callers
6
+ // can use Pointer to deref error targets. We should consider adding
7
+ // this to the Pointer module as Pointer.Encode(...) (review)
8
+ // ------------------------------------------------------------------
9
+ export function EncodeFragment(fragment) {
10
+ return fragment.replace(/~/g, '~0').replace(/\//g, '~1');
11
+ }
@@ -1,4 +1,4 @@
1
- import * as S from '../types/index.mjs';
2
- import { Stack } from './_stack.mjs';
1
+ import * as Schema from '../types/index.mjs';
2
+ import * as Stack from './_stack.mjs';
3
3
  import { BuildContext } from './_context.mjs';
4
- export declare function Reducer(stack: Stack, context: BuildContext, schemas: S.XSchema[], value: string, check: string): string;
4
+ export declare function Reducer(stack: Stack.XStack, context: BuildContext, schemas: Schema.XSchema[], value: string, check: string): string;
@@ -1,6 +1,6 @@
1
- import * as S from '../types/index.mjs';
2
- import { Stack } from './_stack.mjs';
1
+ import * as Schema from '../types/index.mjs';
2
+ import * as Stack from './_stack.mjs';
3
3
  import { BuildContext, CheckContext, ErrorContext } from './_context.mjs';
4
- export declare function BuildRefine(_stack: Stack, _context: BuildContext, schema: S.XRefine, value: string): string;
5
- export declare function CheckRefine(_stack: Stack, _context: CheckContext, schema: S.XRefine, value: unknown): boolean;
6
- export declare function ErrorRefine(_stack: Stack, context: ErrorContext, schemaPath: string, instancePath: string, schema: S.XRefine, value: unknown): boolean;
4
+ export declare function BuildRefine(_stack: Stack.XStack, _context: BuildContext, schema: Schema.XRefine, value: string): string;
5
+ export declare function CheckRefine(_stack: Stack.XStack, _context: CheckContext, schema: Schema.XRefine, value: unknown): boolean;
6
+ export declare function ErrorRefine(_stack: Stack.XStack, context: ErrorContext, schemaPath: string, instancePath: string, schema: Schema.XRefine, value: unknown): boolean;
@@ -1,12 +1,21 @@
1
1
  // deno-fmt-ignore-file
2
- import * as V from './_externals.mjs';
2
+ import * as Externals from './_externals.mjs';
3
3
  import { EmitGuard as E, Guard as G } from '../../guard/index.mjs';
4
4
  // ------------------------------------------------------------------
5
5
  // Build
6
6
  // ------------------------------------------------------------------
7
+ function BuildRefineMultiple(_stack, _context, schema, value) {
8
+ const external = Externals.CreateVariable(schema['~refine']);
9
+ return E.Every(external, E.Constant(0), ['refinement', '_'], E.Call(E.Member('refinement', 'check'), [value]));
10
+ }
11
+ function BuildRefineSingle(_stack, _context, schema, value) {
12
+ const external = Externals.CreateVariable(schema['~refine'][0]);
13
+ return E.Call(E.Member(external, 'check'), [value]);
14
+ }
7
15
  export function BuildRefine(_stack, _context, schema, value) {
8
- const refinements = V.CreateVariable(schema['~refine'].map((refinement) => refinement));
9
- return E.Every(refinements, E.Constant(0), ['refinement', '_'], E.Call(E.Member('refinement', 'check'), [value]));
16
+ return G.IsEqual(schema['~refine'].length, 1)
17
+ ? BuildRefineSingle(_stack, _context, schema, value)
18
+ : BuildRefineMultiple(_stack, _context, schema, value);
10
19
  }
11
20
  // ------------------------------------------------------------------
12
21
  // Check
@@ -19,11 +28,7 @@ export function CheckRefine(_stack, _context, schema, value) {
19
28
  // ------------------------------------------------------------------
20
29
  export function ErrorRefine(_stack, context, schemaPath, instancePath, schema, value) {
21
30
  return G.EveryAll(schema['~refine'], 0, (refinement, index) => {
22
- return refinement.check(value) || context.AddError({
23
- keyword: '~refine',
24
- schemaPath,
25
- instancePath,
26
- params: { index, message: refinement.error(value) },
27
- });
31
+ return refinement.check(value) ||
32
+ context.AddError('~refine', schemaPath, instancePath, { index, message: refinement.error(value) });
28
33
  });
29
34
  }
@@ -1,22 +1,36 @@
1
1
  import * as Schema from '../types/index.mjs';
2
- export declare class Stack {
3
- #private;
4
- private readonly context;
5
- private readonly schema;
6
- private readonly ids;
7
- private readonly resourceIds;
8
- private readonly anchors;
9
- private readonly recursiveAnchors;
10
- private readonly dynamicAnchors;
11
- private readonly retrievedResources;
12
- private readonly retrievedFrames;
13
- private readonly resolvedResources;
14
- private pendingResource;
15
- constructor(context: Record<PropertyKey, Schema.XSchema>, schema: Schema.XSchema);
16
- LexicalBaseURL(): string;
17
- Push(schema: Schema.XSchema): void;
18
- Pop(schema: Schema.XSchema): void;
19
- Ref(ref: Schema.XRef): Schema.XSchema | undefined;
20
- RecursiveRef(recursiveRef: Schema.XRecursiveRef): Schema.XSchema | undefined;
21
- DynamicRef(dynamicRef: Schema.XDynamicRef): Schema.XSchema | undefined;
2
+ export declare const DefaultUri = "urn:typebox:root";
3
+ export interface XStack {
4
+ /** The schema context. */
5
+ readonly context: Record<string, Schema.XSchema>;
6
+ /** The entry schema. */
7
+ readonly schema: Schema.XSchema;
8
+ /** Visited $id schemas, kept only to detect resource re-entry (see resolve.ts FindResolvedResource). */
9
+ readonly ids: Schema.XId[];
10
+ /** Nearest enclosing $id schema, used as the root for local pointer resolution. */
11
+ readonly lexicalSchema: Schema.XSchema;
12
+ /** First $recursiveAnchor: true schema seen on the path. */
13
+ readonly recursiveAnchor: Schema.XRecursiveAnchor | undefined;
14
+ /** Dynamic anchors visible at this point in the traversal. */
15
+ readonly dynamicAnchors: Schema.XDynamicAnchor[];
16
+ /** Lexical base URL, used to resolve relative $id and $ref values within the current schema. */
17
+ readonly lexicalBase: string;
18
+ /** Base URL of the current resource, reset each time a new resource $id is entered. */
19
+ readonly resourceBase: string;
20
+ /** Base URL that $ref values resolve against. */
21
+ readonly referenceBase: string;
22
+ /** Resource entry point bookkeeping: schema -> the base/root to apply when that schema is next pushed. */
23
+ readonly resourceEntries: Map<Schema.XSchemaObject, {
24
+ base: string;
25
+ root: Schema.XSchemaObject;
26
+ }>;
27
+ /** True while referenceBase should track resourceBase rather than lexicalBase. */
28
+ readonly useResourceBaseForReference: boolean;
29
+ /** True until the next $id schema is entered, marking it as a fresh resource root. */
30
+ readonly pendingResource: boolean;
31
+ /** True once traversal has entered a retrieved or legacy resource. */
32
+ readonly enteredResource: boolean;
22
33
  }
34
+ export declare function NextUri(ref: string, base: string): URL;
35
+ export declare function Stack(context: Record<string, Schema.XSchema>, schema: Schema.XSchema): XStack;
36
+ export declare function NextStack(stack: XStack, schema: Schema.XSchema): XStack;