@agntn/harnesses 0.1.0 → 0.2.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.
@@ -1,3 +1,4 @@
1
+ import "node:module";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __exportAll = (all, no_symbols) => {
3
4
  let target = {};
@@ -15,89 +16,20 @@ const Metrics = {
15
16
  discard: 0,
16
17
  update: 0
17
18
  };
18
- function IsBetween(value, min, max) {
19
- return value >= min && value <= max;
20
- }
21
- function IsZeroWidthJoiner(value) {
22
- return value === 8205;
23
- }
24
- function IsHighSurrogate(value) {
25
- return IsBetween(value, 55296, 56319);
26
- }
27
- function IsRegionalIndicator(value) {
28
- return IsBetween(value, 127462, 127487);
29
- }
30
- function IsVariationSelector(value) {
31
- return IsBetween(value, 65024, 65039);
32
- }
33
- function IsCombiningMark(value) {
34
- return IsBetween(value, 768, 879) || IsBetween(value, 6832, 6911) || IsBetween(value, 7616, 7679) || IsBetween(value, 65056, 65071);
35
- }
36
- function CodePointLength(value) {
37
- return value > 65535 ? 2 : 1;
38
- }
39
- function ConsumeModifiers(value, index) {
19
+ function CodePointCount$1(value) {
20
+ let result = 0, index = 0, prev = 0;
40
21
  while (index < value.length) {
41
- const point = value.codePointAt(index);
42
- if (IsCombiningMark(point) || IsVariationSelector(point)) index += CodePointLength(point);
43
- else break;
22
+ const next = value.charCodeAt(index++) >> 10;
23
+ result += +((prev << 8 | next) !== 13879);
24
+ prev = next;
44
25
  }
45
- return index;
46
- }
47
- function NextGraphemeClusterIndex(value, clusterStart) {
48
- const startCP = value.codePointAt(clusterStart);
49
- let clusterEnd = clusterStart + CodePointLength(startCP);
50
- clusterEnd = ConsumeModifiers(value, clusterEnd);
51
- while (clusterEnd < value.length - 1 && IsZeroWidthJoiner(value.codePointAt(clusterEnd))) {
52
- const nextCP = value.codePointAt(clusterEnd + 1);
53
- clusterEnd += 1 + CodePointLength(nextCP);
54
- clusterEnd = ConsumeModifiers(value, clusterEnd);
55
- }
56
- if (IsRegionalIndicator(startCP) && clusterEnd < value.length && IsRegionalIndicator(value.codePointAt(clusterEnd))) clusterEnd += CodePointLength(value.codePointAt(clusterEnd));
57
- return clusterEnd;
58
- }
59
- function IsGraphemeCodePoint(value) {
60
- return IsHighSurrogate(value) || IsCombiningMark(value) || IsVariationSelector(value) || IsZeroWidthJoiner(value);
61
- }
62
- function IsMinLengthSegmented(value, minLength) {
63
- if (minLength === 0) return true;
64
- let count = 0;
65
- let index = 0;
66
- while (index < value.length) {
67
- index = NextGraphemeClusterIndex(value, index);
68
- count++;
69
- if (count >= minLength) return true;
70
- }
71
- return false;
26
+ return result;
72
27
  }
73
- function IsMaxLengthSegmented(value, maxLength) {
74
- let count = 0;
75
- let index = 0;
76
- while (index < value.length) {
77
- index = NextGraphemeClusterIndex(value, index);
78
- count++;
79
- if (count > maxLength) return false;
80
- }
81
- return true;
28
+ function IsMaxLength$2(value, maxLength) {
29
+ return value.length <= maxLength || value.length <= maxLength << 1 && CodePointCount$1(value) <= maxLength;
82
30
  }
83
31
  function IsMinLength$2(value, minLength) {
84
- if (minLength === 0) return true;
85
- let index = 0;
86
- while (index < value.length) {
87
- if (IsGraphemeCodePoint(value.charCodeAt(index))) return IsMinLengthSegmented(value, minLength);
88
- index++;
89
- if (index >= minLength) return true;
90
- }
91
- return false;
92
- }
93
- function IsMaxLength$2(value, maxLength) {
94
- let index = 0;
95
- while (index < value.length) {
96
- if (IsGraphemeCodePoint(value.charCodeAt(index))) return IsMaxLengthSegmented(value, maxLength);
97
- index++;
98
- if (index > maxLength) return false;
99
- }
100
- return true;
32
+ return value.length >= minLength << 1 || value.length >= minLength && CodePointCount$1(value) >= minLength;
101
33
  }
102
34
  function IsArray$1(value) {
103
35
  return Array.isArray(value);
@@ -174,28 +106,30 @@ function IsClassInstance(value) {
174
106
  function IsValueLike(value) {
175
107
  return IsBigInt$1(value) || IsBoolean$2(value) || IsNull$1(value) || IsNumber$2(value) || IsString$2(value) || IsUndefined$1(value);
176
108
  }
177
- function IsMaxLength$1(value, length) {
178
- return IsMaxLength$2(value, length);
109
+ function IsMaxLength$1(value, maxLength) {
110
+ return IsMaxLength$2(value, maxLength);
179
111
  }
180
- function IsMinLength$1(value, length) {
181
- return IsMinLength$2(value, length);
112
+ function IsMinLength$1(value, minLength) {
113
+ return IsMinLength$2(value, minLength);
182
114
  }
183
115
  function Every(value, offset, callback) {
184
- for (let index = offset; index < value.length; index++) if (!callback(value[index], index)) return false;
185
- return true;
116
+ return value.every((item, index) => index < offset || callback(item, index));
186
117
  }
187
118
  function EveryAll(value, offset, callback) {
188
119
  let result = true;
189
- for (let index = offset; index < value.length; index++) if (!callback(value[index], index)) result = false;
120
+ value.forEach((item, index) => {
121
+ if (index >= offset && !callback(item, index)) result = false;
122
+ });
190
123
  return result;
191
124
  }
192
125
  function Some(value, callback) {
193
- for (let index = 0; index < value.length; index++) if (callback(value[index], index)) return true;
194
- return false;
126
+ return value.some((value, index) => callback(value, index));
195
127
  }
196
128
  function SomeAll(value, callback) {
197
129
  let result = false;
198
- for (let index = 0; index < value.length; index++) if (callback(value[index], index)) result = true;
130
+ value.forEach((item, index) => {
131
+ if (callback(item, index)) result = true;
132
+ });
199
133
  return result;
200
134
  }
201
135
  function Counted(value, callback) {
@@ -260,6 +194,7 @@ function IsMap(value) {
260
194
  const settings = {
261
195
  immutableTypes: false,
262
196
  maxErrors: 8,
197
+ maxParseErrors: 1,
263
198
  maxInstantiationCount: 128,
264
199
  useAcceleration: true,
265
200
  exactOptionalPropertyTypes: false,
@@ -291,7 +226,7 @@ function FromSchemaObject(value) {
291
226
  for (const key of Keys(value)) {
292
227
  if (IsUnsafePropertyKey(key)) continue;
293
228
  const descriptor = Object.getOwnPropertyDescriptor(value, key);
294
- descriptor.value = FromValue$2(descriptor.value);
229
+ descriptor.value = FromValue$1(descriptor.value);
295
230
  if (IsEqual(descriptor.enumerable, true)) result[key] = descriptor.value;
296
231
  else Object.defineProperty(result, key, descriptor);
297
232
  }
@@ -301,16 +236,16 @@ function FromPlainObject(value) {
301
236
  const result = {};
302
237
  for (const key of Keys(value)) {
303
238
  if (IsUnsafePropertyKey(key)) continue;
304
- result[key] = FromValue$2(value[key]);
239
+ result[key] = FromValue$1(value[key]);
305
240
  }
306
- for (const key of Symbols(value)) result[key] = FromValue$2(value[key]);
241
+ for (const key of Symbols(value)) result[key] = FromValue$1(value[key]);
307
242
  return result;
308
243
  }
309
- function FromObject$13(value) {
244
+ function FromObject$12(value) {
310
245
  return IsClassInstance(value) ? FromClassInstance(value) : IsSchemaObject$1(value) ? FromSchemaObject(value) : FromPlainObject(value);
311
246
  }
312
- function FromArray$9(value) {
313
- return value.map((element) => FromValue$2(element));
247
+ function FromArray$8(value) {
248
+ return value.map((element) => FromValue$1(element));
314
249
  }
315
250
  function FromTypedArray(value) {
316
251
  return value.slice();
@@ -319,17 +254,17 @@ function FromRegExp$1(value) {
319
254
  return new RegExp(value.source, value.flags);
320
255
  }
321
256
  function FromMap(value) {
322
- return new Map(FromValue$2([...value.entries()]));
257
+ return new Map(FromValue$1([...value.entries()]));
323
258
  }
324
259
  function FromSet(value) {
325
- return new Set(FromValue$2([...value.values()]));
260
+ return new Set(FromValue$1([...value.values()]));
326
261
  }
327
- function FromValue$2(value) {
328
- return IsTypeArray(value) ? FromTypedArray(value) : IsRegExp(value) ? FromRegExp$1(value) : IsMap(value) ? FromMap(value) : IsSet(value) ? FromSet(value) : IsArray$1(value) ? FromArray$9(value) : IsObject$1(value) ? FromObject$13(value) : value;
262
+ function FromValue$1(value) {
263
+ return IsTypeArray(value) ? FromTypedArray(value) : IsRegExp(value) ? FromRegExp$1(value) : IsMap(value) ? FromMap(value) : IsSet(value) ? FromSet(value) : IsArray$1(value) ? FromArray$8(value) : IsObject$1(value) ? FromObject$12(value) : value;
329
264
  }
330
265
  function Clone$1(value) {
331
266
  Metrics.clone += 1;
332
- return FromValue$2(value);
267
+ return FromValue$1(value);
333
268
  }
334
269
  function MergeHidden(left, right) {
335
270
  for (const key of Object.keys(right)) Object.defineProperty(left, key, {
@@ -674,9 +609,9 @@ function FNV1A64_OP(byte) {
674
609
  Accumulator = Accumulator ^ Bytes[byte];
675
610
  Accumulator = Accumulator * Prime % Size;
676
611
  }
677
- function FromArray$8(value) {
612
+ function FromArray$7(value) {
678
613
  FNV1A64_OP(ByteMarker.Array);
679
- for (const item of value) FromValue$1(item);
614
+ for (const item of value) FromValue(item);
680
615
  }
681
616
  function FromBigInt$5(value) {
682
617
  FNV1A64_OP(ByteMarker.BigInt);
@@ -689,15 +624,15 @@ function FromBoolean$5(value) {
689
624
  }
690
625
  function FromConstructor(value) {
691
626
  FNV1A64_OP(ByteMarker.Constructor);
692
- FromValue$1(value.toString());
627
+ FromValue(value.toString());
693
628
  }
694
629
  function FromDate(value) {
695
630
  FNV1A64_OP(ByteMarker.Date);
696
- FromValue$1(value.getTime());
631
+ FromValue(value.getTime());
697
632
  }
698
633
  function FromFunction(value) {
699
634
  FNV1A64_OP(ByteMarker.Function);
700
- FromValue$1(value.toString());
635
+ FromValue(value.toString());
701
636
  }
702
637
  function FromNull$1(_value) {
703
638
  FNV1A64_OP(ByteMarker.Null);
@@ -707,11 +642,11 @@ function FromNumber$4(value) {
707
642
  F64In.setFloat64(0, value, true);
708
643
  for (const byte of F64Out) FNV1A64_OP(byte);
709
644
  }
710
- function FromObject$12(value) {
645
+ function FromObject$11(value) {
711
646
  FNV1A64_OP(ByteMarker.Object);
712
647
  for (const key of InstanceKeys(value).sort()) {
713
- FromValue$1(key);
714
- FromValue$1(value[key]);
648
+ FromValue(key);
649
+ FromValue(value[key]);
715
650
  }
716
651
  }
717
652
  function FromRegExp(value) {
@@ -725,7 +660,7 @@ function FromString$6(value) {
725
660
  }
726
661
  function FromSymbol(value) {
727
662
  FNV1A64_OP(ByteMarker.Symbol);
728
- FromValue$1(value.toString());
663
+ FromValue(value.toString());
729
664
  }
730
665
  function FromTypeArray(value) {
731
666
  FNV1A64_OP(ByteMarker.TypeArray);
@@ -735,12 +670,12 @@ function FromTypeArray(value) {
735
670
  function FromUndefined$1(_value) {
736
671
  return FNV1A64_OP(ByteMarker.Undefined);
737
672
  }
738
- function FromValue$1(value) {
739
- return IsTypeArray(value) ? FromTypeArray(value) : IsDate$1(value) ? FromDate(value) : IsRegExp(value) ? FromRegExp(value) : IsBoolean$1(value) ? FromBoolean$5(value.valueOf()) : IsString$1(value) ? FromString$6(value.valueOf()) : IsNumber$1(value) ? FromNumber$4(value.valueOf()) : IsIEEE754(value) ? FromNumber$4(value) : IsArray$1(value) ? FromArray$8(value) : IsBoolean$2(value) ? FromBoolean$5(value) : IsBigInt$1(value) ? FromBigInt$5(value) : IsConstructor$1(value) ? FromConstructor(value) : IsNull$1(value) ? FromNull$1(value) : IsObject$1(value) ? FromObject$12(value) : IsString$2(value) ? FromString$6(value) : IsSymbol$1(value) ? FromSymbol(value) : IsUndefined$1(value) ? FromUndefined$1(value) : IsFunction$1(value) ? FromFunction(value) : Unreachable$1();
673
+ function FromValue(value) {
674
+ return IsTypeArray(value) ? FromTypeArray(value) : IsDate$1(value) ? FromDate(value) : IsRegExp(value) ? FromRegExp(value) : IsBoolean$1(value) ? FromBoolean$5(value.valueOf()) : IsString$1(value) ? FromString$6(value.valueOf()) : IsNumber$1(value) ? FromNumber$4(value.valueOf()) : IsIEEE754(value) ? FromNumber$4(value) : IsArray$1(value) ? FromArray$7(value) : IsBoolean$2(value) ? FromBoolean$5(value) : IsBigInt$1(value) ? FromBigInt$5(value) : IsConstructor$1(value) ? FromConstructor(value) : IsNull$1(value) ? FromNull$1(value) : IsObject$1(value) ? FromObject$11(value) : IsString$2(value) ? FromString$6(value) : IsSymbol$1(value) ? FromSymbol(value) : IsUndefined$1(value) ? FromUndefined$1(value) : IsFunction$1(value) ? FromFunction(value) : Unreachable$1();
740
675
  }
741
676
  function HashCode(value) {
742
677
  Accumulator = BigInt("14695981039346656037");
743
- FromValue$1(value);
678
+ FromValue(value);
744
679
  return Accumulator;
745
680
  }
746
681
  function Hash(value) {
@@ -2029,13 +1964,13 @@ const Extends$1 = (input) => If(If(If(Const("extends", input), ([_0, input]) =>
2029
1964
  _4,
2030
1965
  _5
2031
1966
  ], input])))))), ([_0, input]) => [_0, input], () => If([[], input], ([_0, input]) => [_0, input], () => [])), ([_0, input]) => [ExtendsMapping(_0), input]);
2032
- const Base = (input) => If(If(If(Const("(", input), ([_0, input]) => If(Type(input), ([_1, input]) => If(Const(")", input), ([_2, input]) => [[
1967
+ const Base$1 = (input) => If(If(If(Const("(", input), ([_0, input]) => If(Type(input), ([_1, input]) => If(Const(")", input), ([_2, input]) => [[
2033
1968
  _0,
2034
1969
  _1,
2035
1970
  _2
2036
1971
  ], input]))), ([_0, input]) => [_0, input], () => If(KeywordString(input), ([_0, input]) => [_0, input], () => If(KeywordNumber(input), ([_0, input]) => [_0, input], () => If(KeywordBoolean(input), ([_0, input]) => [_0, input], () => If(KeywordUndefined(input), ([_0, input]) => [_0, input], () => If(KeywordNull(input), ([_0, input]) => [_0, input], () => If(KeywordInteger(input), ([_0, input]) => [_0, input], () => If(KeywordBigInt(input), ([_0, input]) => [_0, input], () => If(KeywordUnknown(input), ([_0, input]) => [_0, input], () => If(KeywordAny(input), ([_0, input]) => [_0, input], () => If(KeywordObject(input), ([_0, input]) => [_0, input], () => If(KeywordNever(input), ([_0, input]) => [_0, input], () => If(KeywordSymbol(input), ([_0, input]) => [_0, input], () => If(KeywordVoid(input), ([_0, input]) => [_0, input], () => If(KeywordThis(input), ([_0, input]) => [_0, input], () => If(LiteralBigInt(input), ([_0, input]) => [_0, input], () => If(LiteralBoolean(input), ([_0, input]) => [_0, input], () => If(LiteralNumber(input), ([_0, input]) => [_0, input], () => If(LiteralString(input), ([_0, input]) => [_0, input], () => If(TemplateLiteral$1(input), ([_0, input]) => [_0, input], () => If(Dependent(input), ([_0, input]) => [_0, input], () => If(_Object_(input), ([_0, input]) => [_0, input], () => If(_Tuple_(input), ([_0, input]) => [_0, input], () => If(_Constructor_(input), ([_0, input]) => [_0, input], () => If(_Function_(input), ([_0, input]) => [_0, input], () => If(_Mapped_(input), ([_0, input]) => [_0, input], () => If(GenericCall(input), ([_0, input]) => [_0, input], () => If(Reference(input), ([_0, input]) => [_0, input], () => [])))))))))))))))))))))))))))), ([_0, input]) => [BaseMapping(_0), input]);
2037
1972
  const With$1 = (input) => If(If(If(Const("with", input), ([_0, input]) => If(WithObject(input), ([_1, input]) => [[_0, _1], input])), ([_0, input]) => [_0, input], () => If([[], input], ([_0, input]) => [_0, input], () => [])), ([_0, input]) => [WithMapping(_0), input]);
2038
- const Factor = (input) => If(If(KeyOf$1(input), ([_0, input]) => If(Base(input), ([_1, input]) => If(IndexArray(input), ([_2, input]) => If(Extends$1(input), ([_3, input]) => If(With$1(input), ([_4, input]) => [[
1973
+ const Factor = (input) => If(If(KeyOf$1(input), ([_0, input]) => If(Base$1(input), ([_1, input]) => If(IndexArray(input), ([_2, input]) => If(Extends$1(input), ([_3, input]) => If(With$1(input), ([_4, input]) => [[
2039
1974
  _0,
2040
1975
  _1,
2041
1976
  _2,
@@ -2581,14 +2516,14 @@ function ExtendsObjectToRecord(inferred, properties, _pattern, value) {
2581
2516
  function ExtendsObject(inferred, left, right) {
2582
2517
  return IsRecord(right) ? ExtendsObjectToRecord(inferred, left, RecordPattern(right), RecordValue(right)) : IsObject(right) ? ExtendsObjectToObject(inferred, left, right.properties) : ExtendsRight(inferred, _Object_$1(left), right);
2583
2518
  }
2584
- function FromObject$11(inferred, properties) {
2519
+ function FromObject$10(inferred, properties) {
2585
2520
  return IsEqual(Keys(properties).length, 0) ? ExtendsTrue(inferred) : ExtendsFalse();
2586
2521
  }
2587
2522
  function FromRecord$5(inferred, _leftKey, leftValue, _rightKey, rightValue) {
2588
2523
  return ExtendsLeft(inferred, leftValue, rightValue);
2589
2524
  }
2590
2525
  function ExtendsRecord(inferred, leftPattern, leftValue, right) {
2591
- return IsRecord(right) ? FromRecord$5(inferred, RecordPatternToType(leftPattern), leftValue, RecordPatternToType(RecordPattern(right)), RecordValue(right)) : IsObject(right) ? FromObject$11(inferred, right.properties) : IsAny(right) ? ExtendsTrue(inferred) : IsUnknown(right) ? ExtendsTrue(inferred) : ExtendsFalse();
2526
+ return IsRecord(right) ? FromRecord$5(inferred, RecordPatternToType(leftPattern), leftValue, RecordPatternToType(RecordPattern(right)), RecordValue(right)) : IsObject(right) ? FromObject$10(inferred, right.properties) : IsAny(right) ? ExtendsTrue(inferred) : IsUnknown(right) ? ExtendsTrue(inferred) : ExtendsFalse();
2592
2527
  }
2593
2528
  function ExtendsString(inferred, left, right) {
2594
2529
  return IsString(right) ? ExtendsTrue(inferred) : ExtendsRight(inferred, left, right);
@@ -2614,8 +2549,13 @@ function TryRestInferable(type) {
2614
2549
  function TryInferable(type) {
2615
2550
  return IsInfer(type) ? Inferrable(type.name, type.extends) : void 0;
2616
2551
  }
2617
- function TryInferResults(rest, right, result = []) {
2618
- return ShiftLeft(rest, (head, tail) => Match$1(ExtendsLeft({}, head, right), () => TryInferResults(tail, right, [...result, head]), () => void 0), () => result);
2552
+ function TryInferResults(rest, right) {
2553
+ const result = [];
2554
+ for (const head of rest) {
2555
+ if (!IsExtendsTrueLike(ExtendsLeft({}, head, right))) return void 0;
2556
+ result.push(head);
2557
+ }
2558
+ return result;
2619
2559
  }
2620
2560
  function InferTupleResult(inferred, name, left, right) {
2621
2561
  const results = TryInferResults(left, right);
@@ -2653,9 +2593,17 @@ function ExtendsTupleToTuple(inferred, left, right) {
2653
2593
  const reversed = Reversed(instantiatedRight);
2654
2594
  return Elements(inferred, reversed, ApplyReverse(left, reversed), ApplyReverse(instantiatedRight, reversed));
2655
2595
  }
2596
+ function ExtendsTupleToArrayReduce(inferred, left, right) {
2597
+ for (const head of left) {
2598
+ const result = ExtendsLeft(inferred, head, right);
2599
+ if (!IsExtendsTrueLike(result)) return result;
2600
+ inferred = result.inferred;
2601
+ }
2602
+ return ExtendsTrue(inferred);
2603
+ }
2656
2604
  function ExtendsTupleToArray(inferred, left, right) {
2657
2605
  const inferrable = TryInferable(right);
2658
- return IsInferable(inferrable) ? InferUnionResult(inferred, inferrable["name"], left, inferrable["type"]) : ShiftLeft(left, (head, tail) => Match$1(ExtendsLeft(inferred, head, right), (inferred) => ExtendsTupleToArray(inferred, tail, right), () => ExtendsFalse()), () => ExtendsTrue(inferred));
2606
+ return IsInferable(inferrable) ? InferUnionResult(inferred, inferrable["name"], left, inferrable["type"]) : ExtendsTupleToArrayReduce(inferred, left, right);
2659
2607
  }
2660
2608
  function ExtendsTuple(inferred, left, right) {
2661
2609
  const instantiatedLeft = InstantiateElements(inferred, State([], []), left);
@@ -3149,7 +3097,7 @@ function FromIntersect$8(types) {
3149
3097
  return CollapseIntersectProperties(result, FromType$15(left));
3150
3098
  }, {});
3151
3099
  }
3152
- function FromObject$10(properties) {
3100
+ function FromObject$9(properties) {
3153
3101
  return properties;
3154
3102
  }
3155
3103
  function FromTuple$7(types) {
@@ -3170,7 +3118,7 @@ function FromUnion$9(types) {
3170
3118
  return ShiftLeft(types, (left, right) => ReduceVariants(right, FromType$15(left)), () => Unreachable$1());
3171
3119
  }
3172
3120
  function FromType$15(type) {
3173
- return IsCyclic(type) ? FromCyclic$8(type.$defs, type.$ref) : IsDependent(type) ? FromDependent$4(type.if, type.then, type.else) : IsIntersect(type) ? FromIntersect$8(type.allOf) : IsUnion(type) ? FromUnion$9(type.anyOf) : IsTuple(type) ? FromTuple$7(type.items) : IsObject(type) ? FromObject$10(type.properties) : {};
3121
+ return IsCyclic(type) ? FromCyclic$8(type.$defs, type.$ref) : IsDependent(type) ? FromDependent$4(type.if, type.then, type.else) : IsIntersect(type) ? FromIntersect$8(type.allOf) : IsUnion(type) ? FromUnion$9(type.anyOf) : IsTuple(type) ? FromTuple$7(type.items) : IsObject(type) ? FromObject$9(type.properties) : {};
3174
3122
  }
3175
3123
  function CollapseToObject(type) {
3176
3124
  return _Object_$1(FromType$15(type));
@@ -3189,7 +3137,7 @@ function NormalizeIndexerTypes(types) {
3189
3137
  function NormalizeIndexer(type) {
3190
3138
  return IsIntersect(type) ? Intersect(NormalizeIndexerTypes(type.allOf)) : IsUnion(type) ? Union(NormalizeIndexerTypes(type.anyOf)) : IsLiteral(type) ? NormalizeLiteral(type.const) : type;
3191
3139
  }
3192
- function FromArray$7(type, indexer) {
3140
+ function FromArray$6(type, indexer) {
3193
3141
  return IsExtendsTrueLike(Extends({}, NormalizeIndexer(indexer), Number$2())) ? type : IsLiteral(indexer) && IsEqual(indexer.const, "length") ? Number$2() : Never();
3194
3142
  }
3195
3143
  function FromCyclic$7(defs, ref) {
@@ -3248,7 +3196,7 @@ function NumericKeys(keys) {
3248
3196
  function FromIndexerNumber(properties) {
3249
3197
  return EvaluateUnion(IndexProperties(properties, NumericKeys(PropertyKeys(properties))));
3250
3198
  }
3251
- function FromObject$9(properties, indexer) {
3199
+ function FromObject$8(properties, indexer) {
3252
3200
  return IsNumber(indexer) ? FromIndexerNumber(properties) : FromIndexer(properties, indexer);
3253
3201
  }
3254
3202
  function ConvertLiteral(value) {
@@ -3275,7 +3223,7 @@ function FromTuple$6(types, indexer) {
3275
3223
  return IsLiteral(indexer) && IsEqual(indexer.const, "length") ? Literal(types.length) : IsNumber(indexer) || IsInteger(indexer) ? FromTupleWithoutIndexer(types) : FromTupleWithIndexer(types, indexer);
3276
3224
  }
3277
3225
  function FromType$12(type, indexer) {
3278
- return IsArray(type) ? FromArray$7(type.items, indexer) : IsObject(type) ? FromObject$9(type.properties, indexer) : IsTuple(type) ? FromTuple$6(type.items, indexer) : Never();
3226
+ return IsArray(type) ? FromArray$6(type.items, indexer) : IsObject(type) ? FromObject$8(type.properties, indexer) : IsTuple(type) ? FromTuple$6(type.items, indexer) : Never();
3279
3227
  }
3280
3228
  function NormalizeType$1(type) {
3281
3229
  return IsCyclic(type) || IsDependent(type) || IsIntersect(type) || IsUnion(type) ? CollapseToObject(type) : type;
@@ -3314,7 +3262,7 @@ function FromAny() {
3314
3262
  Symbol$1()
3315
3263
  ]);
3316
3264
  }
3317
- function FromArray$6(_type) {
3265
+ function FromArray$5(_type) {
3318
3266
  return Number$2();
3319
3267
  }
3320
3268
  function FromPropertyKeys(keys) {
@@ -3322,7 +3270,7 @@ function FromPropertyKeys(keys) {
3322
3270
  return IsLiteralValue(left) ? [...result, Literal(ConvertToIntegerKey(left))] : Unreachable$1();
3323
3271
  }, []);
3324
3272
  }
3325
- function FromObject$8(properties) {
3273
+ function FromObject$7(properties) {
3326
3274
  return EvaluateUnionFast(FromPropertyKeys(Keys(properties)));
3327
3275
  }
3328
3276
  function FromRecord$4(type) {
@@ -3332,7 +3280,7 @@ function FromTuple$5(types) {
3332
3280
  return EvaluateUnionFast(types.map((_, index) => Literal(index)));
3333
3281
  }
3334
3282
  function FromType$11(type) {
3335
- return IsAny(type) ? FromAny() : IsArray(type) ? FromArray$6(type.items) : IsObject(type) ? FromObject$8(type.properties) : IsRecord(type) ? FromRecord$4(type) : IsTuple(type) ? FromTuple$5(type.items) : Never();
3283
+ return IsAny(type) ? FromAny() : IsArray(type) ? FromArray$5(type.items) : IsObject(type) ? FromObject$7(type.properties) : IsRecord(type) ? FromRecord$4(type) : IsTuple(type) ? FromTuple$5(type.items) : Never();
3336
3284
  }
3337
3285
  function NormalizeType(type) {
3338
3286
  return IsCyclic(type) || IsDependent(type) || IsIntersect(type) || IsUnion(type) ? CollapseToObject(type) : type;
@@ -3509,7 +3457,7 @@ function FromIntersect$6(types) {
3509
3457
  function FromUnion$6(types) {
3510
3458
  return Union(types.map((type) => FromType$8(type)));
3511
3459
  }
3512
- function FromObject$7(properties) {
3460
+ function FromObject$6(properties) {
3513
3461
  return _Object_$1(Keys(properties).reduce((result, left) => {
3514
3462
  return {
3515
3463
  ...result,
@@ -3518,7 +3466,7 @@ function FromObject$7(properties) {
3518
3466
  }, {}));
3519
3467
  }
3520
3468
  function FromType$8(type) {
3521
- return IsCyclic(type) ? FromCyclic$6(type.$defs, type.$ref) : IsDependent(type) ? FromDependent$2(type.if, type.then, type.else) : IsIntersect(type) ? FromIntersect$6(type.allOf) : IsUnion(type) ? FromUnion$6(type.anyOf) : IsObject(type) ? FromObject$7(type.properties) : _Object_$1({});
3469
+ return IsCyclic(type) ? FromCyclic$6(type.$defs, type.$ref) : IsDependent(type) ? FromDependent$2(type.if, type.then, type.else) : IsIntersect(type) ? FromIntersect$6(type.allOf) : IsUnion(type) ? FromUnion$6(type.anyOf) : IsObject(type) ? FromObject$6(type.properties) : _Object_$1({});
3522
3470
  }
3523
3471
  function PartialAction(type, options) {
3524
3472
  return CanInstantiate([type]) ? Update$1(FromType$8(type), {}, options) : PartialDeferred(type, options);
@@ -3553,7 +3501,7 @@ function ReadonlyObject(type, options = {}) {
3553
3501
  return ReadonlyObjectAction(type, options);
3554
3502
  }
3555
3503
  const ReadonlyType = ReadonlyObject;
3556
- function FromArray$5(type) {
3504
+ function FromArray$4(type) {
3557
3505
  return AddImmutable(_Array_(type));
3558
3506
  }
3559
3507
  function FromCyclic$5(defs, ref) {
@@ -3566,7 +3514,7 @@ function FromDependent$1(if_, then_, else_) {
3566
3514
  function FromIntersect$5(types) {
3567
3515
  return FromType$6(EvaluateIntersect(types));
3568
3516
  }
3569
- function FromObject$6(properties) {
3517
+ function FromObject$5(properties) {
3570
3518
  return _Object_$1(Keys(properties).reduce((result, left) => {
3571
3519
  return {
3572
3520
  ...result,
@@ -3581,7 +3529,7 @@ function FromUnion$5(types) {
3581
3529
  return Union(types.map((type) => FromType$6(type)));
3582
3530
  }
3583
3531
  function FromType$6(type) {
3584
- return IsArray(type) ? FromArray$5(type.items) : IsCyclic(type) ? FromCyclic$5(type.$defs, type.$ref) : IsDependent(type) ? FromDependent$1(type.if, type.then, type.else) : IsIntersect(type) ? FromIntersect$5(type.allOf) : IsObject(type) ? FromObject$6(type.properties) : IsTuple(type) ? FromTuple$4(type.items) : IsUnion(type) ? FromUnion$5(type.anyOf) : type;
3532
+ return IsArray(type) ? FromArray$4(type.items) : IsCyclic(type) ? FromCyclic$5(type.$defs, type.$ref) : IsDependent(type) ? FromDependent$1(type.if, type.then, type.else) : IsIntersect(type) ? FromIntersect$5(type.allOf) : IsObject(type) ? FromObject$5(type.properties) : IsTuple(type) ? FromTuple$4(type.items) : IsUnion(type) ? FromUnion$5(type.anyOf) : type;
3585
3533
  }
3586
3534
  function ReadonlyObjectAction(type, options) {
3587
3535
  return CanInstantiate([type]) ? Update$1(FromType$6(type), {}, options) : ReadonlyObjectDeferred(type);
@@ -3605,7 +3553,7 @@ function FromIntersect$4(types) {
3605
3553
  function FromUnion$4(types) {
3606
3554
  return Union(types.map((type) => FromType$5(type)));
3607
3555
  }
3608
- function FromObject$5(properties) {
3556
+ function FromObject$4(properties) {
3609
3557
  return _Object_$1(Keys(properties).reduce((result, left) => {
3610
3558
  return {
3611
3559
  ...result,
@@ -3614,7 +3562,7 @@ function FromObject$5(properties) {
3614
3562
  }, {}));
3615
3563
  }
3616
3564
  function FromType$5(type) {
3617
- return IsCyclic(type) ? FromCyclic$4(type.$defs, type.$ref) : IsDependent(type) ? FromDependent(type.if, type.then, type.else) : IsIntersect(type) ? FromIntersect$4(type.allOf) : IsUnion(type) ? FromUnion$4(type.anyOf) : IsObject(type) ? FromObject$5(type.properties) : _Object_$1({});
3565
+ return IsCyclic(type) ? FromCyclic$4(type.$defs, type.$ref) : IsDependent(type) ? FromDependent(type.if, type.then, type.else) : IsIntersect(type) ? FromIntersect$4(type.allOf) : IsUnion(type) ? FromUnion$4(type.anyOf) : IsObject(type) ? FromObject$4(type.properties) : _Object_$1({});
3618
3566
  }
3619
3567
  function RequiredDeferred(type, options = {}) {
3620
3568
  return Deferred("Required", [type], options);
@@ -4080,44 +4028,137 @@ var CheckContext = class {
4080
4028
  }
4081
4029
  };
4082
4030
  var ErrorContext = class extends CheckContext {
4083
- constructor(callback) {
4031
+ constructor() {
4084
4032
  super();
4085
- this.callback = callback;
4033
+ this.errors = [];
4086
4034
  }
4087
- AddError(error) {
4088
- this.callback(error);
4089
- return false;
4035
+ AtCapacity() {
4036
+ return this.errors.length >= Get$2().maxErrors;
4090
4037
  }
4091
- };
4092
- var AccumulatedErrorContext = class extends ErrorContext {
4093
- constructor() {
4094
- super((error) => this.errors.push(error));
4095
- this.errors = [];
4038
+ AddError(keyword, schemaPath, instancePath, params) {
4039
+ return this.AddErrorObject({
4040
+ keyword,
4041
+ schemaPath,
4042
+ instancePath,
4043
+ params
4044
+ });
4096
4045
  }
4097
- AddError(error) {
4098
- this.errors.push(error);
4046
+ AddErrors(error) {
4047
+ error.forEach((error) => this.AddErrorObject(error));
4099
4048
  return false;
4100
4049
  }
4101
4050
  GetErrors() {
4102
4051
  return this.errors;
4103
4052
  }
4053
+ AddErrorObject(error) {
4054
+ if (!this.AtCapacity()) this.errors.push(error);
4055
+ return false;
4056
+ }
4104
4057
  };
4105
4058
  function CheckRefine(_stack, _context, schema, value) {
4106
4059
  return Every(schema["~refine"], 0, (refinement, _) => refinement.check(value));
4107
4060
  }
4108
4061
  function ErrorRefine(_stack, context, schemaPath, instancePath, schema, value) {
4109
4062
  return EveryAll(schema["~refine"], 0, (refinement, index) => {
4110
- return refinement.check(value) || context.AddError({
4111
- keyword: "~refine",
4112
- schemaPath,
4113
- instancePath,
4114
- params: {
4115
- index,
4116
- message: refinement.error(value)
4117
- }
4063
+ return refinement.check(value) || context.AddError("~refine", schemaPath, instancePath, {
4064
+ index,
4065
+ message: refinement.error(value)
4118
4066
  });
4119
4067
  });
4120
4068
  }
4069
+ const DefaultUri = "urn:typebox:root";
4070
+ function NextUri(ref, base) {
4071
+ return URL.canParse(ref, base) ? new URL(ref, base) : IsEqual(base, "urn:typebox:root") ? new URL(`${base}:${ref}`) : new URL(`${base.slice(0, base.lastIndexOf(":"))}:${ref}`);
4072
+ }
4073
+ function Stack(context, schema) {
4074
+ const base = IsSchemaObject(schema) && IsId(schema) ? NextUri(schema.$id, DefaultUri).href : DefaultUri;
4075
+ return {
4076
+ context,
4077
+ schema,
4078
+ lexicalSchema: schema,
4079
+ lexicalBase: base,
4080
+ resourceBase: base,
4081
+ referenceBase: base,
4082
+ ids: [],
4083
+ useResourceBaseForReference: true,
4084
+ recursiveAnchor: void 0,
4085
+ dynamicAnchors: [],
4086
+ resourceEntries: /* @__PURE__ */ new Map(),
4087
+ pendingResource: true,
4088
+ enteredResource: false
4089
+ };
4090
+ }
4091
+ function RegisterResourceAnchors(anchors, schema, isRoot = true) {
4092
+ if (IsSchemaBoolean(schema)) return anchors;
4093
+ if (Array.isArray(schema)) return schema.reduce((result, item) => RegisterResourceAnchors(result, item, false), anchors);
4094
+ if (!IsSchemaObject(schema)) return anchors;
4095
+ if (!isRoot && IsId(schema)) return anchors;
4096
+ const next = !isRoot && IsDynamicAnchor(schema) ? [...anchors, schema] : anchors;
4097
+ return Object.keys(schema).reduce((result, key) => RegisterResourceAnchors(result, schema[key], false), next);
4098
+ }
4099
+ function ResourceEntry(stack, schema) {
4100
+ return stack.resourceEntries.get(schema);
4101
+ }
4102
+ function NextEnteredResource(stack, schema) {
4103
+ return stack.enteredResource || ResourceEntry(stack, schema) !== void 0;
4104
+ }
4105
+ function IsRelativeId(schema) {
4106
+ return !/^[A-Za-z][A-Za-z0-9+.-]*:/.test(schema.$id);
4107
+ }
4108
+ function NextIds(stack, schema) {
4109
+ return IsId(schema) ? [...stack.ids, schema] : stack.ids;
4110
+ }
4111
+ function NextRecursiveAnchor(stack, schema) {
4112
+ return stack.recursiveAnchor ?? (IsRecursiveAnchorTrue(schema) ? schema : void 0);
4113
+ }
4114
+ function NextDynamicAnchors(stack, schema) {
4115
+ const registered = IsId(schema) ? RegisterResourceAnchors(stack.dynamicAnchors, schema) : stack.dynamicAnchors;
4116
+ return IsDynamicAnchor(schema) ? [...registered, schema] : registered;
4117
+ }
4118
+ function NextPendingResource(stack, schema) {
4119
+ return IsId(schema) ? false : stack.pendingResource;
4120
+ }
4121
+ function NextLexicalBase(stack, schema) {
4122
+ const entry = ResourceEntry(stack, schema);
4123
+ if (entry) return entry.base;
4124
+ return IsId(schema) ? NextUri(schema.$id, stack.lexicalBase).href : stack.lexicalBase;
4125
+ }
4126
+ function NextResourceBase(stack, schema) {
4127
+ const entry = ResourceEntry(stack, schema);
4128
+ if (entry) return entry.base;
4129
+ return IsId(schema) && stack.pendingResource ? NextUri(schema.$id, stack.resourceBase).href : stack.resourceBase;
4130
+ }
4131
+ function NextUseResourceBaseForReference(stack, schema) {
4132
+ return IsId(schema) ? !IsRelativeId(schema) : stack.useResourceBaseForReference;
4133
+ }
4134
+ function NextReferenceBase(stack, schema) {
4135
+ const isRetrieved = NextEnteredResource(stack, schema);
4136
+ const useResourceBaseForReference = NextUseResourceBaseForReference(stack, schema);
4137
+ return isRetrieved || useResourceBaseForReference ? NextResourceBase(stack, schema) : NextLexicalBase(stack, schema);
4138
+ }
4139
+ function NextLexicalSchema(stack, schema) {
4140
+ const entry = ResourceEntry(stack, schema);
4141
+ if (entry) return entry.root;
4142
+ return IsId(schema) ? schema : stack.lexicalSchema;
4143
+ }
4144
+ function HasStackKeywords(stack, schema) {
4145
+ return IsSchemaObject(schema) && (IsId(schema) || IsDynamicAnchor(schema) || IsUndefined$1(stack.recursiveAnchor) && IsRecursiveAnchorTrue(schema) || !IsUndefined$1(ResourceEntry(stack, schema)));
4146
+ }
4147
+ function NextStack(stack, schema) {
4148
+ return HasStackKeywords(stack, schema) ? {
4149
+ ...stack,
4150
+ ids: NextIds(stack, schema),
4151
+ dynamicAnchors: NextDynamicAnchors(stack, schema),
4152
+ recursiveAnchor: NextRecursiveAnchor(stack, schema),
4153
+ pendingResource: NextPendingResource(stack, schema),
4154
+ lexicalBase: NextLexicalBase(stack, schema),
4155
+ resourceBase: NextResourceBase(stack, schema),
4156
+ useResourceBaseForReference: NextUseResourceBaseForReference(stack, schema),
4157
+ referenceBase: NextReferenceBase(stack, schema),
4158
+ lexicalSchema: NextLexicalSchema(stack, schema),
4159
+ enteredResource: NextEnteredResource(stack, schema)
4160
+ } : stack;
4161
+ }
4121
4162
  function IsValid$4(schema) {
4122
4163
  return IsItems(schema) && IsArray$1(schema.items);
4123
4164
  }
@@ -4159,16 +4200,10 @@ function ErrorAdditionalProperties(stack, context, schemaPath, instancePath, sch
4159
4200
  return EveryAll(Keys(value), 0, (key, _index) => {
4160
4201
  const nextSchemaPath = `${schemaPath}/additionalProperties`;
4161
4202
  const nextInstancePath = `${instancePath}/${key}`;
4162
- const nextContext = new AccumulatedErrorContext();
4163
- const isAdditionalProperty = regexp.test(key) || ErrorSchemaPushStack(stack, nextContext, nextSchemaPath, nextInstancePath, schema.additionalProperties, value[key]) && context.AddKey(key);
4203
+ const isAdditionalProperty = regexp.test(key) || ErrorSchemaPushStack(stack, context, nextSchemaPath, nextInstancePath, schema.additionalProperties, value[key]) && context.AddKey(key);
4164
4204
  if (!isAdditionalProperty) additionalProperties.push(key);
4165
4205
  return isAdditionalProperty;
4166
- }) || context.AddError({
4167
- keyword: "additionalProperties",
4168
- schemaPath,
4169
- instancePath,
4170
- params: { additionalProperties }
4171
- });
4206
+ }) || context.AddError("additionalProperties", schemaPath, instancePath, { additionalProperties });
4172
4207
  }
4173
4208
  function CheckAllOf(stack, context, schema, value) {
4174
4209
  const results = schema.allOf.reduce((result, schema) => {
@@ -4181,13 +4216,13 @@ function ErrorAllOf(stack, context, schemaPath, instancePath, schema, value) {
4181
4216
  const failedContexts = [];
4182
4217
  const results = schema.allOf.reduce((result, schema, index) => {
4183
4218
  const nextSchemaPath = `${schemaPath}/allOf/${index}`;
4184
- const nextContext = new AccumulatedErrorContext();
4219
+ const nextContext = new ErrorContext();
4185
4220
  const isSchema = ErrorSchema(stack, nextContext, nextSchemaPath, instancePath, schema, value);
4186
4221
  if (!isSchema) failedContexts.push(nextContext);
4187
4222
  return isSchema ? [...result, nextContext] : result;
4188
4223
  }, []);
4189
4224
  const isAllOf = IsEqual(results.length, schema.allOf.length) && context.Merge(results);
4190
- if (!isAllOf) failedContexts.forEach((failed) => failed.GetErrors().forEach((error) => context.AddError(error)));
4225
+ if (!isAllOf) failedContexts.forEach((failed) => context.AddErrors(failed.GetErrors()));
4191
4226
  return isAllOf;
4192
4227
  }
4193
4228
  function CheckAnyOf(stack, context, schema, value) {
@@ -4200,41 +4235,26 @@ function CheckAnyOf(stack, context, schema, value) {
4200
4235
  function ErrorAnyOf(stack, context, schemaPath, instancePath, schema, value) {
4201
4236
  const failedContexts = [];
4202
4237
  const results = schema.anyOf.reduce((result, schema, index) => {
4203
- const nextContext = new AccumulatedErrorContext();
4238
+ const nextContext = new ErrorContext();
4204
4239
  const isSchema = ErrorSchema(stack, nextContext, `${schemaPath}/anyOf/${index}`, instancePath, schema, value);
4205
4240
  if (!isSchema) failedContexts.push(nextContext);
4206
4241
  return isSchema ? [...result, nextContext] : result;
4207
4242
  }, []);
4208
4243
  const isAnyOf = IsGreaterThan(results.length, 0) && context.Merge(results);
4209
- if (!isAnyOf) failedContexts.forEach((failed) => failed.GetErrors().forEach((error) => context.AddError(error)));
4210
- return isAnyOf || context.AddError({
4211
- keyword: "anyOf",
4212
- schemaPath,
4213
- instancePath,
4214
- params: {}
4215
- });
4244
+ if (!isAnyOf) failedContexts.forEach((failed) => context.AddErrors(failed.GetErrors()));
4245
+ return isAnyOf || context.AddError("anyOf", schemaPath, instancePath, {});
4216
4246
  }
4217
4247
  function CheckSchemaBoolean(_stack, _context, schema, _value) {
4218
4248
  return schema;
4219
4249
  }
4220
4250
  function ErrorSchemaBoolean(stack, context, schemaPath, instancePath, schema, value) {
4221
- return CheckSchemaBoolean(stack, context, schema, value) || context.AddError({
4222
- keyword: "boolean",
4223
- schemaPath,
4224
- instancePath,
4225
- params: {}
4226
- });
4251
+ return CheckSchemaBoolean(stack, context, schema, value) || context.AddError("boolean", schemaPath, instancePath, {});
4227
4252
  }
4228
4253
  function CheckConst(_stack, _context, schema, value) {
4229
4254
  return IsValueLike(schema.const) ? IsEqual(value, schema.const) : IsDeepEqual(value, schema.const);
4230
4255
  }
4231
4256
  function ErrorConst(stack, context, schemaPath, instancePath, schema, value) {
4232
- return CheckConst(stack, context, schema, value) || context.AddError({
4233
- keyword: "const",
4234
- schemaPath,
4235
- instancePath,
4236
- params: { allowedValue: schema.const }
4237
- });
4257
+ return CheckConst(stack, context, schema, value) || context.AddError("const", schemaPath, instancePath, { allowedValue: schema.const });
4238
4258
  }
4239
4259
  function IsValid$3(schema) {
4240
4260
  return !(IsMinContains(schema) && IsEqual(schema.minContains, 0));
@@ -4246,12 +4266,7 @@ function CheckContains(stack, context, schema, value) {
4246
4266
  });
4247
4267
  }
4248
4268
  function ErrorContains(stack, context, schemaPath, instancePath, schema, value) {
4249
- return CheckContains(stack, context, schema, value) || context.AddError({
4250
- keyword: "contains",
4251
- schemaPath,
4252
- instancePath,
4253
- params: { minContains: 1 }
4254
- });
4269
+ return CheckContains(stack, context, schema, value) || context.AddError("contains", schemaPath, instancePath, { minContains: 1 });
4255
4270
  }
4256
4271
  function CheckDependencies(stack, context, schema, value) {
4257
4272
  const isLength = IsEqual(Keys(value).length, 0);
@@ -4264,14 +4279,9 @@ function ErrorDependencies(stack, context, schemaPath, instancePath, schema, val
4264
4279
  const isLength = IsEqual(Keys(value).length, 0);
4265
4280
  const isEvery = EveryAll(Entries(schema.dependencies), 0, ([key, schema]) => {
4266
4281
  const nextSchemaPath = `${schemaPath}/dependencies/${key}`;
4267
- return !HasPropertyKey(value, key) || (IsArray$1(schema) ? schema.every((dependency) => HasPropertyKey(value, dependency) || context.AddError({
4268
- keyword: "dependencies",
4269
- schemaPath,
4270
- instancePath,
4271
- params: {
4272
- property: key,
4273
- dependencies: schema
4274
- }
4282
+ return !HasPropertyKey(value, key) || (IsArray$1(schema) ? schema.every((dependency) => HasPropertyKey(value, dependency) || context.AddError("dependencies", schemaPath, instancePath, {
4283
+ property: key,
4284
+ dependencies: schema
4275
4285
  })) : ErrorSchema(stack, context, nextSchemaPath, instancePath, schema, value));
4276
4286
  });
4277
4287
  return isLength || isEvery;
@@ -4286,14 +4296,9 @@ function CheckDependentRequired(_stack, _context, schema, value) {
4286
4296
  function ErrorDependentRequired(_stack, context, schemaPath, instancePath, schema, value) {
4287
4297
  const isLength = IsEqual(Keys(value).length, 0);
4288
4298
  const isEveryEntry = EveryAll(Entries(schema.dependentRequired), 0, ([key, keys]) => {
4289
- return !HasPropertyKey(value, key) || EveryAll(keys, 0, (dependency) => HasPropertyKey(value, dependency) || context.AddError({
4290
- keyword: "dependentRequired",
4291
- schemaPath,
4292
- instancePath,
4293
- params: {
4294
- property: key,
4295
- dependencies: keys
4296
- }
4299
+ return !HasPropertyKey(value, key) || EveryAll(keys, 0, (dependency) => HasPropertyKey(value, dependency) || context.AddError("dependentRequired", schemaPath, instancePath, {
4300
+ property: key,
4301
+ dependencies: keys
4297
4302
  }));
4298
4303
  });
4299
4304
  return isLength || isEveryEntry;
@@ -4313,51 +4318,258 @@ function ErrorDependentSchemas(stack, context, schemaPath, instancePath, schema,
4313
4318
  });
4314
4319
  return isLength || isEvery;
4315
4320
  }
4316
- function CheckDynamicRef(stack, context, schema, value) {
4317
- const target = stack.DynamicRef(schema) ?? false;
4318
- return IsSchema(target) && CheckSchema(stack, context, target, value);
4321
+ function Indices(pointer) {
4322
+ const indices = pointer.split("/").map((index) => index.replace(/~1/g, "/").replace(/~0/g, "~"));
4323
+ return indices[0] === "" ? indices.slice(1) : indices;
4324
+ }
4325
+ function Get(value, pointer) {
4326
+ let current = value;
4327
+ for (const index of Indices(pointer)) {
4328
+ if (!IsObject$1(current) || IsUnsafePropertyKey(index)) return void 0;
4329
+ current = current[index];
4330
+ }
4331
+ return current;
4332
+ }
4333
+ function RelativeBase(schema, base) {
4334
+ return IsSchemaObject(schema) && IsId(schema) ? NextUri(schema.$id, base.href) : base;
4335
+ }
4336
+ function AbsoluteBase(base) {
4337
+ return NextUri(base, DefaultUri);
4338
+ }
4339
+ function CanonicalHref(url) {
4340
+ return url.href.split("#")[0];
4341
+ }
4342
+ function Base(schema, base, target) {
4343
+ return SearchBase(schema, AbsoluteBase(base), target);
4344
+ }
4345
+ function RefRoot(stack, ref) {
4346
+ return ref.$ref.startsWith("#") || stack.enteredResource ? stack.lexicalSchema : stack.schema;
4347
+ }
4348
+ function IsPointerFragment(fragment) {
4349
+ return fragment.startsWith("#/");
4350
+ }
4351
+ function SearchDynamicAnchor(schema, name) {
4352
+ if (IsObject$1(schema) && IsDynamicAnchor(schema) && IsEqual(schema.$dynamicAnchor, name)) return schema;
4353
+ if (IsObject$1(schema)) for (const key of Keys(schema)) {
4354
+ const result = SearchDynamicAnchor(schema[key], name);
4355
+ if (result) return result;
4356
+ }
4357
+ }
4358
+ function SearchBase(schema, base, target) {
4359
+ if (IsEqual(schema, target)) return base.href;
4360
+ const nextBase = RelativeBase(schema, base);
4361
+ if (IsArray$1(schema)) for (const item of schema) {
4362
+ const result = SearchBase(item, nextBase, target);
4363
+ if (!IsUndefined$1(result)) return result;
4364
+ }
4365
+ else if (IsObject$1(schema)) for (const key of Keys(schema)) {
4366
+ const result = SearchBase(schema[key], nextBase, target);
4367
+ if (!IsUndefined$1(result)) return result;
4368
+ }
4369
+ }
4370
+ function MatchWithHash(schema, ref) {
4371
+ if (ref.href.endsWith("#")) return schema;
4372
+ if (!ref.hash.startsWith("#")) return void 0;
4373
+ const fragment = decodeURIComponent(ref.hash.slice(1));
4374
+ if (!fragment.startsWith("/")) return void 0;
4375
+ return Get(schema, fragment);
4376
+ }
4377
+ function MatchWithId(schema, base, ref) {
4378
+ if (!IsId(schema)) return void 0;
4379
+ if (IsEqual(schema.$id, ref.hash)) return schema;
4380
+ const absoluteRef = new URL(ref.href, base.href);
4381
+ if (IsEqual(base.pathname, absoluteRef.pathname)) return ref.hash.startsWith("#") ? MatchWithHash(schema, ref) : schema;
4382
+ }
4383
+ function MatchWithAnchor(schema, base, ref) {
4384
+ if (!IsAnchor(schema)) return void 0;
4385
+ const absoluteAnchor = new URL(`#${schema.$anchor}`, base.href);
4386
+ const absoluteRef = new URL(ref.href, base.href);
4387
+ return IsEqual(absoluteAnchor.href, absoluteRef.href) ? schema : void 0;
4388
+ }
4389
+ function MatchWithDynamicAnchor(schema, base, ref) {
4390
+ if (!IsDynamicAnchor(schema)) return void 0;
4391
+ const absoluteAnchor = new URL(`#${schema.$dynamicAnchor}`, base.href);
4392
+ const absoluteRef = new URL(ref.href, base.href);
4393
+ return IsEqual(absoluteAnchor.href, absoluteRef.href) ? schema : void 0;
4394
+ }
4395
+ function MatchSchemaObject(schema, base, ref) {
4396
+ if (!IsSchemaObject(schema)) return void 0;
4397
+ return MatchWithId(schema, base, ref) ?? MatchWithAnchor(schema, base, ref) ?? MatchWithDynamicAnchor(schema, base, ref) ?? MatchWithHash(schema, ref);
4398
+ }
4399
+ function MatchFromArray(schema, base, ref) {
4400
+ if (!IsArray$1(schema)) return void 0;
4401
+ return schema.reduce((result, item) => {
4402
+ const match = Match(item, base, ref);
4403
+ return !IsUndefined$1(match) ? match : result;
4404
+ }, void 0);
4405
+ }
4406
+ function MatchFromObject(schema, base, ref) {
4407
+ if (!IsObject$1(schema)) return void 0;
4408
+ return Keys(schema).reduce((result, key) => {
4409
+ if (IsEqual(key, "const") || IsEqual(key, "enum")) return result;
4410
+ const match = Match(schema[key], base, ref);
4411
+ return !IsUndefined$1(match) ? match : result;
4412
+ }, void 0);
4413
+ }
4414
+ function Match(schema, base, ref) {
4415
+ const relativeBase = RelativeBase(schema, base);
4416
+ return MatchSchemaObject(schema, relativeBase, ref) ?? MatchFromArray(schema, relativeBase, ref) ?? MatchFromObject(schema, relativeBase, ref);
4417
+ }
4418
+ function Resource(context, schema, base, ref) {
4419
+ const result = RefInternal(context, schema, base, ref);
4420
+ return IsSchemaObject(result) && IsId(result) ? result : void 0;
4421
+ }
4422
+ function FindDeferredResourceLegacy(stack, ref, schema) {
4423
+ if (!ref.$ref.startsWith("#")) return void 0;
4424
+ if (!IsSchemaObject(stack.schema) || HasPropertyKey(stack.schema, "$schema")) return void 0;
4425
+ const targetBase = Base(stack.lexicalSchema, stack.referenceBase, schema);
4426
+ if (IsUndefined$1(targetBase) || IsEqual(targetBase, stack.referenceBase)) return void 0;
4427
+ return {
4428
+ target: schema,
4429
+ base: targetBase,
4430
+ root: stack.lexicalSchema
4431
+ };
4432
+ }
4433
+ function FindDeferredResourceModern(stack, canonical, schema) {
4434
+ const remoteRoot = stack.context[canonical];
4435
+ if (!IsSchemaObject(remoteRoot)) return void 0;
4436
+ return {
4437
+ target: schema,
4438
+ base: canonical,
4439
+ root: remoteRoot
4440
+ };
4441
+ }
4442
+ function FindDeferredResource(stack, ref, schema, canonical, isRemote) {
4443
+ const remote = isRemote ? FindDeferredResourceModern(stack, canonical, schema) : void 0;
4444
+ return IsUndefined$1(remote) ? FindDeferredResourceLegacy(stack, ref, schema) : remote;
4319
4445
  }
4320
- function ErrorDynamicRef(stack, context, _schemaPath, instancePath, schema, value) {
4321
- const target = stack.DynamicRef(schema) ?? false;
4322
- return IsSchema(target) && ErrorSchema(stack, context, "#", instancePath, target, value);
4446
+ function FindResolvedResource(stack, canonical, schema) {
4447
+ if (IsId(schema)) return void 0;
4448
+ const resource = Resource(stack.context, stack.schema, stack.referenceBase, canonical);
4449
+ if (!resource || stack.ids.includes(resource)) return void 0;
4450
+ return { resource };
4451
+ }
4452
+ function RefInternalWithContext(context, ref) {
4453
+ return HasPropertyKey(context, ref) ? context[ref] : void 0;
4454
+ }
4455
+ function RefInternalWithLocal(schema, base, ref) {
4456
+ return Match(schema, base, ref);
4457
+ }
4458
+ function RefInternalWithRemote(context, base, ref) {
4459
+ const canonicalHref = CanonicalHref(ref);
4460
+ if (!HasPropertyKey(context, canonicalHref) || IsEqual(canonicalHref, CanonicalHref(base))) return void 0;
4461
+ const remoteSchema = context[canonicalHref];
4462
+ const remoteBase = RelativeBase(remoteSchema, new URL(canonicalHref));
4463
+ return IsEqual(ref.hash, "") ? remoteSchema : Match(remoteSchema, remoteBase, ref);
4464
+ }
4465
+ function RefInternal(context, schema, base, ref) {
4466
+ const absoluteBase = AbsoluteBase(base);
4467
+ const target = NextUri(ref, absoluteBase.href);
4468
+ return RefInternalWithContext(context, ref) ?? RefInternalWithLocal(schema, absoluteBase, target) ?? RefInternalWithRemote(context, absoluteBase, target);
4469
+ }
4470
+ function RefNextStackDeferred(stack, deferredResource) {
4471
+ if (!deferredResource) return stack;
4472
+ const resourceEntries = new Map(stack.resourceEntries);
4473
+ resourceEntries.set(deferredResource.target, {
4474
+ base: deferredResource.base,
4475
+ root: deferredResource.root
4476
+ });
4477
+ return {
4478
+ ...stack,
4479
+ resourceEntries
4480
+ };
4481
+ }
4482
+ function RefNextStackResolved(stack, resolvedResource) {
4483
+ return resolvedResource ? NextStack(stack, resolvedResource.resource) : stack;
4484
+ }
4485
+ function RefNextStack(stack, pendingResource, deferredResource, resolvedResource) {
4486
+ return RefNextStackResolved(RefNextStackDeferred({
4487
+ ...stack,
4488
+ pendingResource
4489
+ }, deferredResource), resolvedResource);
4490
+ }
4491
+ function RefResultFound(stack, ref, schema) {
4492
+ const canonical = CanonicalHref(NextUri(ref.$ref, stack.referenceBase));
4493
+ const isRemote = !IsEqual(canonical, stack.resourceBase);
4494
+ return {
4495
+ schema,
4496
+ stack: RefNextStack(stack, true, FindDeferredResource(stack, ref, schema, canonical, isRemote), isRemote ? FindResolvedResource(stack, canonical, schema) : void 0)
4497
+ };
4498
+ }
4499
+ function RefResultNotFound(stack, schema) {
4500
+ return {
4501
+ schema,
4502
+ stack: RefNextStack(stack, !IsUndefined$1(schema))
4503
+ };
4504
+ }
4505
+ function Ref(stack, ref) {
4506
+ const schema = RefInternal(stack.context, RefRoot(stack, ref), stack.referenceBase, ref.$ref);
4507
+ return IsSchemaObject(schema) ? RefResultFound(stack, ref, schema) : RefResultNotFound(stack, schema);
4508
+ }
4509
+ function IsRecursiveAnchorInScope(stack) {
4510
+ return IsSchemaObject(stack.lexicalSchema) && IsRecursiveAnchorTrue(stack.lexicalSchema);
4511
+ }
4512
+ function RecursiveRef(stack, recursiveRef) {
4513
+ const schema = IsRecursiveAnchorInScope(stack) ? stack.recursiveAnchor : stack.lexicalSchema;
4514
+ return RefInternal(stack.context, schema, stack.lexicalBase, recursiveRef.$recursiveRef);
4515
+ }
4516
+ function DynamicRefFragment(stack, dynamicRef) {
4517
+ return NextUri(dynamicRef.$dynamicRef, AbsoluteBase(stack.lexicalBase).href).hash;
4518
+ }
4519
+ function FindScopedDynamicAnchor(stack, name) {
4520
+ return stack.dynamicAnchors.find((anchor) => IsEqual(anchor.$dynamicAnchor, name)) ?? SearchDynamicAnchor(stack.schema, name);
4521
+ }
4522
+ function DynamicRefWhenFound(stack, dynamicRef, fragmentTarget) {
4523
+ if (!IsSchemaObject(fragmentTarget) || !IsDynamicAnchor(fragmentTarget)) return fragmentTarget;
4524
+ return IsPointerFragment(DynamicRefFragment(stack, dynamicRef)) ? fragmentTarget : FindScopedDynamicAnchor(stack, fragmentTarget.$dynamicAnchor);
4525
+ }
4526
+ function DynamicRefWhenNotFound(stack, dynamicRef) {
4527
+ const fragment = DynamicRefFragment(stack, dynamicRef);
4528
+ return FindScopedDynamicAnchor(stack, decodeURIComponent(fragment.slice(1)));
4529
+ }
4530
+ function DynamicRef(stack, dynamicRef) {
4531
+ const fragmentRoot = dynamicRef.$dynamicRef.startsWith("#") ? stack.lexicalSchema : stack.schema;
4532
+ const fragmentTarget = RefInternal(stack.context, fragmentRoot, stack.lexicalBase, dynamicRef.$dynamicRef);
4533
+ return IsUndefined$1(fragmentTarget) ? DynamicRefWhenNotFound(stack, dynamicRef) : DynamicRefWhenFound(stack, dynamicRef, fragmentTarget);
4534
+ }
4535
+ function CheckDynamicRef(stack, context, schema, value) {
4536
+ const target = DynamicRef(stack, schema) ?? false;
4537
+ const nextStack = target ? {
4538
+ ...stack,
4539
+ pendingResource: true
4540
+ } : stack;
4541
+ return IsSchema(target) && CheckSchema(nextStack, context, target, value);
4542
+ }
4543
+ function ErrorDynamicRef(stack, context, schemaPath, instancePath, schema, value) {
4544
+ const target = DynamicRef(stack, schema) ?? false;
4545
+ const nextStack = target ? {
4546
+ ...stack,
4547
+ pendingResource: true
4548
+ } : stack;
4549
+ return IsSchema(target) && ErrorSchema(nextStack, context, schemaPath, instancePath, target, value);
4323
4550
  }
4324
4551
  function CheckEnum(_stack, _context, schema, value) {
4325
4552
  return Some(schema.enum, (option) => IsValueLike(option) ? IsEqual(value, option) : IsDeepEqual(value, option));
4326
4553
  }
4327
4554
  function ErrorEnum(stack, context, schemaPath, instancePath, schema, value) {
4328
- return CheckEnum(stack, context, schema, value) || context.AddError({
4329
- keyword: "enum",
4330
- schemaPath,
4331
- instancePath,
4332
- params: { allowedValues: schema.enum }
4333
- });
4555
+ return CheckEnum(stack, context, schema, value) || context.AddError("enum", schemaPath, instancePath, { allowedValues: schema.enum });
4334
4556
  }
4335
4557
  function CheckExclusiveMaximum(_stack, _context, schema, value) {
4336
4558
  return IsLessThan(value, schema.exclusiveMaximum);
4337
4559
  }
4338
4560
  function ErrorExclusiveMaximum(stack, context, schemaPath, instancePath, schema, value) {
4339
- return CheckExclusiveMaximum(stack, context, schema, value) || context.AddError({
4340
- keyword: "exclusiveMaximum",
4341
- schemaPath,
4342
- instancePath,
4343
- params: {
4344
- comparison: "<",
4345
- limit: schema.exclusiveMaximum
4346
- }
4561
+ return CheckExclusiveMaximum(stack, context, schema, value) || context.AddError("exclusiveMaximum", schemaPath, instancePath, {
4562
+ comparison: "<",
4563
+ limit: schema.exclusiveMaximum
4347
4564
  });
4348
4565
  }
4349
4566
  function CheckExclusiveMinimum(_stack, _context, schema, value) {
4350
4567
  return IsGreaterThan(value, schema.exclusiveMinimum);
4351
4568
  }
4352
4569
  function ErrorExclusiveMinimum(stack, context, schemaPath, instancePath, schema, value) {
4353
- return CheckExclusiveMinimum(stack, context, schema, value) || context.AddError({
4354
- keyword: "exclusiveMinimum",
4355
- schemaPath,
4356
- instancePath,
4357
- params: {
4358
- comparison: ">",
4359
- limit: schema.exclusiveMinimum
4360
- }
4570
+ return CheckExclusiveMinimum(stack, context, schema, value) || context.AddError("exclusiveMinimum", schemaPath, instancePath, {
4571
+ comparison: ">",
4572
+ limit: schema.exclusiveMinimum
4361
4573
  });
4362
4574
  }
4363
4575
  const DAYS = [
@@ -4702,15 +4914,12 @@ const MalformedScheme = /^[a-zA-Z][a-zA-Z0-9+\-.]*\/\//;
4702
4914
  function IsIriReference(value) {
4703
4915
  return !InvalidIriChars$1.test(value) && !MalformedScheme.test(value) && URL.canParse(value, "http://example.com");
4704
4916
  }
4705
- const IpvFutureMatchMaxLength = 2048;
4706
- const IpvFutureMatch = /\[[vV][0-9a-fA-F]+\.[^\]]+\]/;
4707
4917
  const InvalidIriChars = /[\x00-\x20<>\^`{|}\\]/;
4708
- function NarrowIpvFuture(value) {
4709
- return value.length < IpvFutureMatchMaxLength ? value.replace(IpvFutureMatch, "[::1]") : value;
4710
- }
4918
+ const InvalidPercentEncoding = /%(?![0-9a-fA-F]{2})/;
4711
4919
  function IsIri(value) {
4712
4920
  if (InvalidIriChars.test(value)) return false;
4713
- return URL.canParse(NarrowIpvFuture(value));
4921
+ if (InvalidPercentEncoding.test(value)) return false;
4922
+ return URL.canParse(value);
4714
4923
  }
4715
4924
  const JsonPointerUriFragment = /^#(?:\/(?:[a-z0-9_\-.!$&'()*+,;:=@]|%[0-9a-f]{2}|~0|~1)*)*$/i;
4716
4925
  function IsJsonPointerUriFragment(value) {
@@ -4787,12 +4996,7 @@ function CheckFormat(_stack, _context, schema, value) {
4787
4996
  return Test(schema.format, value);
4788
4997
  }
4789
4998
  function ErrorFormat(stack, context, schemaPath, instancePath, schema, value) {
4790
- return CheckFormat(stack, context, schema, value) || context.AddError({
4791
- keyword: "format",
4792
- schemaPath,
4793
- instancePath,
4794
- params: { format: schema.format }
4795
- });
4999
+ return CheckFormat(stack, context, schema, value) || context.AddError("format", schemaPath, instancePath, { format: schema.format });
4796
5000
  }
4797
5001
  function CheckIf(stack, context, schema, value) {
4798
5002
  const thenSchema = IsThen(schema) ? schema.then : true;
@@ -4802,18 +5006,8 @@ function CheckIf(stack, context, schema, value) {
4802
5006
  function ErrorIf(stack, context, schemaPath, instancePath, schema, value) {
4803
5007
  const thenSchema = IsThen(schema) ? schema.then : true;
4804
5008
  const elseSchema = IsElse(schema) ? schema.else : true;
4805
- const trueContext = new AccumulatedErrorContext();
4806
- const isIf = ErrorSchema(stack, trueContext, `${schemaPath}/if`, instancePath, schema.if, value) ? ErrorSchema(stack, trueContext, `${schemaPath}/then`, instancePath, thenSchema, value) || context.AddError({
4807
- keyword: "if",
4808
- schemaPath,
4809
- instancePath,
4810
- params: { failingKeyword: "then" }
4811
- }) : ErrorSchema(stack, context, `${schemaPath}/else`, instancePath, elseSchema, value) || context.AddError({
4812
- keyword: "if",
4813
- schemaPath,
4814
- instancePath,
4815
- params: { failingKeyword: "else" }
4816
- });
5009
+ const trueContext = new ErrorContext();
5010
+ const isIf = ErrorSchema(stack, trueContext, `${schemaPath}/if`, instancePath, schema.if, value) ? ErrorSchema(stack, trueContext, `${schemaPath}/then`, instancePath, thenSchema, value) || context.AddError("if", schemaPath, instancePath, { failingKeyword: "then" }) : ErrorSchema(stack, context, `${schemaPath}/else`, instancePath, elseSchema, value) || context.AddError("if", schemaPath, instancePath, { failingKeyword: "else" });
4817
5011
  if (isIf) context.Merge([trueContext]);
4818
5012
  return isIf;
4819
5013
  }
@@ -4854,62 +5048,37 @@ function CheckMaxContains(stack, context, schema, value) {
4854
5048
  }
4855
5049
  function ErrorMaxContains(stack, context, schemaPath, instancePath, schema, value) {
4856
5050
  const minContains = IsMinContains(schema) ? schema.minContains : 1;
4857
- return CheckMaxContains(stack, context, schema, value) || context.AddError({
4858
- keyword: "contains",
4859
- schemaPath,
4860
- instancePath,
4861
- params: {
4862
- minContains,
4863
- maxContains: schema.maxContains
4864
- }
5051
+ return CheckMaxContains(stack, context, schema, value) || context.AddError("contains", schemaPath, instancePath, {
5052
+ minContains,
5053
+ maxContains: schema.maxContains
4865
5054
  });
4866
5055
  }
4867
5056
  function CheckMaximum(_stack, _context, schema, value) {
4868
5057
  return IsLessEqualThan(value, schema.maximum);
4869
5058
  }
4870
5059
  function ErrorMaximum(stack, context, schemaPath, instancePath, schema, value) {
4871
- return CheckMaximum(stack, context, schema, value) || context.AddError({
4872
- keyword: "maximum",
4873
- schemaPath,
4874
- instancePath,
4875
- params: {
4876
- comparison: "<=",
4877
- limit: schema.maximum
4878
- }
5060
+ return CheckMaximum(stack, context, schema, value) || context.AddError("maximum", schemaPath, instancePath, {
5061
+ comparison: "<=",
5062
+ limit: schema.maximum
4879
5063
  });
4880
5064
  }
4881
5065
  function CheckMaxItems(_stack, _context, schema, value) {
4882
5066
  return IsLessEqualThan(value.length, schema.maxItems);
4883
5067
  }
4884
5068
  function ErrorMaxItems(stack, context, schemaPath, instancePath, schema, value) {
4885
- return CheckMaxItems(stack, context, schema, value) || context.AddError({
4886
- keyword: "maxItems",
4887
- schemaPath,
4888
- instancePath,
4889
- params: { limit: schema.maxItems }
4890
- });
5069
+ return CheckMaxItems(stack, context, schema, value) || context.AddError("maxItems", schemaPath, instancePath, { limit: schema.maxItems });
4891
5070
  }
4892
5071
  function CheckMaxLength(_stack, _context, schema, value) {
4893
5072
  return IsMaxLength$1(value, schema.maxLength);
4894
5073
  }
4895
5074
  function ErrorMaxLength(stack, context, schemaPath, instancePath, schema, value) {
4896
- return CheckMaxLength(stack, context, schema, value) || context.AddError({
4897
- keyword: "maxLength",
4898
- schemaPath,
4899
- instancePath,
4900
- params: { limit: schema.maxLength }
4901
- });
5075
+ return CheckMaxLength(stack, context, schema, value) || context.AddError("maxLength", schemaPath, instancePath, { limit: schema.maxLength });
4902
5076
  }
4903
5077
  function CheckMaxProperties(_stack, _context, schema, value) {
4904
5078
  return IsLessEqualThan(Keys(value).length, schema.maxProperties);
4905
5079
  }
4906
5080
  function ErrorMaxProperties(stack, context, schemaPath, instancePath, schema, value) {
4907
- return CheckMaxProperties(stack, context, schema, value) || context.AddError({
4908
- keyword: "maxProperties",
4909
- schemaPath,
4910
- instancePath,
4911
- params: { limit: schema.maxProperties }
4912
- });
5081
+ return CheckMaxProperties(stack, context, schema, value) || context.AddError("maxProperties", schemaPath, instancePath, { limit: schema.maxProperties });
4913
5082
  }
4914
5083
  function IsValid$1(schema) {
4915
5084
  return IsContains(schema);
@@ -4919,82 +5088,47 @@ function CheckMinContains(stack, context, schema, value) {
4919
5088
  return IsGreaterEqualThan(Counted(value, (item, index) => CheckSchema(stack, context, schema.contains, item) && context.AddIndex(index)), schema.minContains);
4920
5089
  }
4921
5090
  function ErrorMinContains(stack, context, schemaPath, instancePath, schema, value) {
4922
- return CheckMinContains(stack, context, schema, value) || context.AddError({
4923
- keyword: "contains",
4924
- schemaPath,
4925
- instancePath,
4926
- params: { minContains: schema.minContains }
4927
- });
5091
+ return CheckMinContains(stack, context, schema, value) || context.AddError("contains", schemaPath, instancePath, { minContains: schema.minContains });
4928
5092
  }
4929
5093
  function CheckMinimum(_stack, _context, schema, value) {
4930
5094
  return IsGreaterEqualThan(value, schema.minimum);
4931
5095
  }
4932
5096
  function ErrorMinimum(stack, context, schemaPath, instancePath, schema, value) {
4933
- return CheckMinimum(stack, context, schema, value) || context.AddError({
4934
- keyword: "minimum",
4935
- schemaPath,
4936
- instancePath,
4937
- params: {
4938
- comparison: ">=",
4939
- limit: schema.minimum
4940
- }
5097
+ return CheckMinimum(stack, context, schema, value) || context.AddError("minimum", schemaPath, instancePath, {
5098
+ comparison: ">=",
5099
+ limit: schema.minimum
4941
5100
  });
4942
5101
  }
4943
5102
  function CheckMinItems(_stack, _context, schema, value) {
4944
5103
  return IsGreaterEqualThan(value.length, schema.minItems);
4945
5104
  }
4946
5105
  function ErrorMinItems(stack, context, schemaPath, instancePath, schema, value) {
4947
- return CheckMinItems(stack, context, schema, value) || context.AddError({
4948
- keyword: "minItems",
4949
- schemaPath,
4950
- instancePath,
4951
- params: { limit: schema.minItems }
4952
- });
5106
+ return CheckMinItems(stack, context, schema, value) || context.AddError("minItems", schemaPath, instancePath, { limit: schema.minItems });
4953
5107
  }
4954
5108
  function CheckMinLength(_stack, _context, schema, value) {
4955
5109
  return IsMinLength$1(value, schema.minLength);
4956
5110
  }
4957
5111
  function ErrorMinLength(stack, context, schemaPath, instancePath, schema, value) {
4958
- return CheckMinLength(stack, context, schema, value) || context.AddError({
4959
- keyword: "minLength",
4960
- schemaPath,
4961
- instancePath,
4962
- params: { limit: schema.minLength }
4963
- });
5112
+ return CheckMinLength(stack, context, schema, value) || context.AddError("minLength", schemaPath, instancePath, { limit: schema.minLength });
4964
5113
  }
4965
5114
  function CheckMinProperties(_stack, _context, schema, value) {
4966
5115
  return IsGreaterEqualThan(Keys(value).length, schema.minProperties);
4967
5116
  }
4968
5117
  function ErrorMinProperties(stack, context, schemaPath, instancePath, schema, value) {
4969
- return CheckMinProperties(stack, context, schema, value) || context.AddError({
4970
- keyword: "minProperties",
4971
- schemaPath,
4972
- instancePath,
4973
- params: { limit: schema.minProperties }
4974
- });
5118
+ return CheckMinProperties(stack, context, schema, value) || context.AddError("minProperties", schemaPath, instancePath, { limit: schema.minProperties });
4975
5119
  }
4976
5120
  function CheckMultipleOf(_stack, _context, schema, value) {
4977
5121
  return IsMultipleOf$1(value, schema.multipleOf);
4978
5122
  }
4979
5123
  function ErrorMultipleOf(stack, context, schemaPath, instancePath, schema, value) {
4980
- return CheckMultipleOf(stack, context, schema, value) || context.AddError({
4981
- keyword: "multipleOf",
4982
- schemaPath,
4983
- instancePath,
4984
- params: { multipleOf: schema.multipleOf }
4985
- });
5124
+ return CheckMultipleOf(stack, context, schema, value) || context.AddError("multipleOf", schemaPath, instancePath, { multipleOf: schema.multipleOf });
4986
5125
  }
4987
5126
  function CheckNot(stack, context, schema, value) {
4988
5127
  const nextContext = new CheckContext();
4989
5128
  return !CheckSchema(stack, nextContext, schema.not, value) && context.Merge([nextContext]);
4990
5129
  }
4991
5130
  function ErrorNot(stack, context, schemaPath, instancePath, schema, value) {
4992
- return CheckNot(stack, context, schema, value) || context.AddError({
4993
- keyword: "not",
4994
- schemaPath,
4995
- instancePath,
4996
- params: {}
4997
- });
5131
+ return CheckNot(stack, context, schema, value) || context.AddError("not", schemaPath, instancePath, {});
4998
5132
  }
4999
5133
  function CheckOneOf(stack, context, schema, value) {
5000
5134
  const passedContexts = schema.oneOf.reduce((result, schema) => {
@@ -5007,31 +5141,21 @@ function ErrorOneOf(stack, context, schemaPath, instancePath, schema, value) {
5007
5141
  const failedContexts = [];
5008
5142
  const passingSchemas = [];
5009
5143
  const passedContexts = schema.oneOf.reduce((result, schema, index) => {
5010
- const nextContext = new AccumulatedErrorContext();
5144
+ const nextContext = new ErrorContext();
5011
5145
  const isSchema = ErrorSchema(stack, nextContext, `${schemaPath}/oneOf/${index}`, instancePath, schema, value);
5012
5146
  if (isSchema) passingSchemas.push(index);
5013
5147
  if (!isSchema) failedContexts.push(nextContext);
5014
5148
  return isSchema ? [...result, nextContext] : result;
5015
5149
  }, []);
5016
5150
  const isOneOf = IsEqual(passedContexts.length, 1) && context.Merge(passedContexts);
5017
- if (!isOneOf && IsEqual(passingSchemas.length, 0)) failedContexts.forEach((failed) => failed.GetErrors().forEach((error) => context.AddError(error)));
5018
- return isOneOf || context.AddError({
5019
- keyword: "oneOf",
5020
- schemaPath,
5021
- instancePath,
5022
- params: { passingSchemas }
5023
- });
5151
+ if (!isOneOf && IsEqual(passingSchemas.length, 0)) failedContexts.forEach((failed) => context.AddErrors(failed.GetErrors()));
5152
+ return isOneOf || context.AddError("oneOf", schemaPath, instancePath, { passingSchemas });
5024
5153
  }
5025
5154
  function CheckPattern(_stack, _context, schema, value) {
5026
5155
  return (IsString$2(schema.pattern) ? UnicodeRegExp(schema.pattern) : schema.pattern).test(value);
5027
5156
  }
5028
5157
  function ErrorPattern(stack, context, schemaPath, instancePath, schema, value) {
5029
- return CheckPattern(stack, context, schema, value) || context.AddError({
5030
- keyword: "pattern",
5031
- schemaPath,
5032
- instancePath,
5033
- params: { pattern: schema.pattern }
5034
- });
5158
+ return CheckPattern(stack, context, schema, value) || context.AddError("pattern", schemaPath, instancePath, { pattern: schema.pattern });
5035
5159
  }
5036
5160
  function CheckPatternProperties(stack, context, schema, value) {
5037
5161
  return Every(Entries(schema.patternProperties), 0, ([pattern, schema]) => {
@@ -5092,39 +5216,43 @@ function ErrorPropertyNames(stack, context, schemaPath, instancePath, schema, va
5092
5216
  const propertyNames = [];
5093
5217
  return EveryAll(Keys(value), 0, (key, _index) => {
5094
5218
  const nextInstancePath = `${instancePath}/${key}`;
5095
- const nextSchemaPath = `${schemaPath}/propertyNames`;
5096
- const isPropertyName = ErrorSchema(stack, new AccumulatedErrorContext(), nextSchemaPath, nextInstancePath, schema.propertyNames, key);
5219
+ const isPropertyName = ErrorSchema(stack, context, `${schemaPath}/propertyNames`, nextInstancePath, schema.propertyNames, key);
5097
5220
  if (!isPropertyName) propertyNames.push(key);
5098
5221
  return isPropertyName;
5099
- }) || context.AddError({
5100
- keyword: "propertyNames",
5101
- schemaPath,
5102
- instancePath,
5103
- params: { propertyNames }
5104
- });
5222
+ }) || context.AddError("propertyNames", schemaPath, instancePath, { propertyNames });
5105
5223
  }
5106
5224
  function CheckRecursiveRef(stack, context, schema, value) {
5107
- const target = stack.RecursiveRef(schema) ?? false;
5108
- return IsSchema(target) && CheckSchema(stack, context, target, value);
5109
- }
5110
- function ErrorRecursiveRef(stack, context, _schemaPath, instancePath, schema, value) {
5111
- const target = stack.RecursiveRef(schema) ?? false;
5112
- return IsSchema(target) && ErrorSchema(stack, context, "#", instancePath, target, value);
5225
+ const target = RecursiveRef(stack, schema) ?? false;
5226
+ const nextStack = target ? {
5227
+ ...stack,
5228
+ pendingResource: true
5229
+ } : stack;
5230
+ return IsSchema(target) && CheckSchema(nextStack, context, target, value);
5231
+ }
5232
+ function ErrorRecursiveRef(stack, context, schemaPath, instancePath, schema, value) {
5233
+ const target = RecursiveRef(stack, schema) ?? false;
5234
+ const nextStack = target ? {
5235
+ ...stack,
5236
+ pendingResource: true
5237
+ } : stack;
5238
+ return IsSchema(target) && ErrorSchema(nextStack, context, schemaPath, instancePath, target, value);
5113
5239
  }
5114
5240
  function CheckRef(stack, context, schema, value) {
5115
- const target = stack.Ref(schema) ?? false;
5241
+ const result = Ref(stack, schema);
5242
+ const target = result.schema ?? false;
5116
5243
  const nextContext = new CheckContext();
5117
- const result = IsSchema(target) && CheckSchema(stack, nextContext, target, value);
5118
- if (result) context.Merge([nextContext]);
5119
- return result;
5120
- }
5121
- function ErrorRef(stack, context, _schemaPath, instancePath, schema, value) {
5122
- const target = stack.Ref(schema) ?? false;
5123
- const nextContext = new AccumulatedErrorContext();
5124
- const result = IsSchema(target) && ErrorSchema(stack, nextContext, "#", instancePath, target, value);
5125
- if (result) context.Merge([nextContext]);
5126
- if (!result) nextContext.GetErrors().forEach((error) => context.AddError(error));
5127
- return result;
5244
+ const valid = IsSchema(target) && CheckSchema(result.stack, nextContext, target, value);
5245
+ if (valid) context.Merge([nextContext]);
5246
+ return valid;
5247
+ }
5248
+ function ErrorRef(stack, context, schemaPath, instancePath, schema, value) {
5249
+ const result = Ref(stack, schema);
5250
+ const target = result.schema ?? false;
5251
+ const nextContext = new ErrorContext();
5252
+ const valid = IsSchema(target) && ErrorSchema(result.stack, nextContext, schemaPath, instancePath, target, value);
5253
+ if (valid) context.Merge([nextContext]);
5254
+ if (!valid) context.AddErrors(nextContext.GetErrors());
5255
+ return valid;
5128
5256
  }
5129
5257
  function CheckRequired(_stack, _context, schema, value) {
5130
5258
  return Every(schema.required, 0, (key) => HasPropertyKey(value, key));
@@ -5135,12 +5263,7 @@ function ErrorRequired(_stack, context, schemaPath, instancePath, schema, value)
5135
5263
  const hasKey = HasPropertyKey(value, key);
5136
5264
  if (!hasKey) requiredProperties.push(key);
5137
5265
  return hasKey;
5138
- }) || context.AddError({
5139
- keyword: "required",
5140
- schemaPath,
5141
- instancePath,
5142
- params: { requiredProperties }
5143
- });
5266
+ }) || context.AddError("required", schemaPath, instancePath, { requiredProperties });
5144
5267
  }
5145
5268
  function CheckTypeName(_stack, _context, type, _schema, value) {
5146
5269
  return IsEqual(type, "object") ? IsObjectNotArray(value) : IsEqual(type, "array") ? IsArray$1(value) : IsEqual(type, "boolean") ? IsBoolean$2(value) : IsEqual(type, "integer") ? IsInteger$1(value) : IsEqual(type, "number") ? IsNumber$2(value) : IsEqual(type, "null") ? IsNull$1(value) : IsEqual(type, "string") ? IsString$2(value) : IsEqual(type, "bigint") ? IsBigInt$1(value) : IsEqual(type, "constructor") ? IsConstructor$1(value) : IsEqual(type, "function") ? IsFunction$1(value) : IsEqual(type, "symbol") ? IsSymbol$1(value) : IsEqual(type, "undefined") ? IsUndefined$1(value) : IsEqual(type, "void") ? IsUndefined$1(value) : true;
@@ -5152,12 +5275,7 @@ function CheckType(stack, context, schema, value) {
5152
5275
  return IsArray$1(schema.type) ? CheckTypeNames(stack, context, schema.type, schema, value) : CheckTypeName(stack, context, schema.type, schema, value);
5153
5276
  }
5154
5277
  function ErrorType(stack, context, schemaPath, instancePath, schema, value) {
5155
- return (IsArray$1(schema.type) ? CheckTypeNames(stack, context, schema.type, schema, value) : CheckTypeName(stack, context, schema.type, schema, value)) || context.AddError({
5156
- keyword: "type",
5157
- schemaPath,
5158
- instancePath,
5159
- params: { type: schema.type }
5160
- });
5278
+ return (IsArray$1(schema.type) ? CheckTypeNames(stack, context, schema.type, schema, value) : CheckTypeName(stack, context, schema.type, schema, value)) || context.AddError("type", schemaPath, instancePath, { type: schema.type });
5161
5279
  }
5162
5280
  function CheckUnevaluatedItems(stack, context, schema, value) {
5163
5281
  const indices = context.GetIndices();
@@ -5169,16 +5287,11 @@ function ErrorUnevaluatedItems(stack, context, schemaPath, instancePath, schema,
5169
5287
  const indices = context.GetIndices();
5170
5288
  const unevaluatedItems = [];
5171
5289
  return EveryAll(value, 0, (item, index) => {
5172
- const nextContext = new AccumulatedErrorContext();
5290
+ const nextContext = new ErrorContext();
5173
5291
  const isEvaluatedItem = (indices.has(index) || ErrorSchema(stack, nextContext, schemaPath, instancePath, schema.unevaluatedItems, item)) && context.AddIndex(index);
5174
5292
  if (!isEvaluatedItem) unevaluatedItems.push(index);
5175
5293
  return isEvaluatedItem;
5176
- }) || context.AddError({
5177
- keyword: "unevaluatedItems",
5178
- schemaPath,
5179
- instancePath,
5180
- params: { unevaluatedItems }
5181
- });
5294
+ }) || context.AddError("unevaluatedItems", schemaPath, instancePath, { unevaluatedItems });
5182
5295
  }
5183
5296
  function CheckUnevaluatedProperties(stack, context, schema, value) {
5184
5297
  const keys = context.GetKeys();
@@ -5190,16 +5303,11 @@ function ErrorUnevaluatedProperties(stack, context, schemaPath, instancePath, sc
5190
5303
  const keys = context.GetKeys();
5191
5304
  const unevaluatedProperties = [];
5192
5305
  return EveryAll(Entries(value), 0, ([key, prop]) => {
5193
- const nextContext = new AccumulatedErrorContext();
5306
+ const nextContext = new ErrorContext();
5194
5307
  const isEvaluatedProperty = keys.has(key) || ErrorSchema(stack, nextContext, schemaPath, instancePath, schema.unevaluatedProperties, prop) && context.AddKey(key);
5195
5308
  if (!isEvaluatedProperty) unevaluatedProperties.push(key);
5196
5309
  return isEvaluatedProperty;
5197
- }) || context.AddError({
5198
- keyword: "unevaluatedProperties",
5199
- schemaPath,
5200
- instancePath,
5201
- params: { unevaluatedProperties }
5202
- });
5310
+ }) || context.AddError("unevaluatedProperties", schemaPath, instancePath, { unevaluatedProperties });
5203
5311
  }
5204
5312
  function IsValid(schema) {
5205
5313
  return !IsEqual(schema.uniqueItems, false);
@@ -5219,206 +5327,23 @@ function ErrorUniqueItems(_stack, context, schemaPath, instancePath, schema, val
5219
5327
  set.add(hash);
5220
5328
  return result;
5221
5329
  }, []);
5222
- return IsEqual(duplicateItems.length, 0) || context.AddError({
5223
- keyword: "uniqueItems",
5224
- schemaPath,
5225
- instancePath,
5226
- params: { duplicateItems }
5227
- });
5330
+ return IsEqual(duplicateItems.length, 0) || context.AddError("uniqueItems", schemaPath, instancePath, { duplicateItems });
5228
5331
  }
5229
5332
  function CheckSchemaPushStack(stack, context, schema, value) {
5230
5333
  return context.Push() && CheckSchema(stack, context, schema, value) && context.Pop();
5231
5334
  }
5232
5335
  function CheckSchema(stack, context, schema, value) {
5233
- stack.Push(schema);
5234
- const result = IsSchemaBoolean(schema) ? CheckSchemaBoolean(stack, context, schema, value) : (!IsType(schema) || CheckType(stack, context, schema, value)) && (!(IsObject$1(value) && !IsArray$1(value)) || (!IsRequired(schema) || CheckRequired(stack, context, schema, value)) && (!IsAdditionalProperties(schema) || CheckAdditionalProperties(stack, context, schema, value)) && (!IsDependencies(schema) || CheckDependencies(stack, context, schema, value)) && (!IsDependentRequired(schema) || CheckDependentRequired(stack, context, schema, value)) && (!IsDependentSchemas(schema) || CheckDependentSchemas(stack, context, schema, value)) && (!IsPatternProperties(schema) || CheckPatternProperties(stack, context, schema, value)) && (!IsProperties(schema) || CheckProperties(stack, context, schema, value)) && (!IsPropertyNames(schema) || CheckPropertyNames(stack, context, schema, value)) && (!IsMinProperties(schema) || CheckMinProperties(stack, context, schema, value)) && (!IsMaxProperties(schema) || CheckMaxProperties(stack, context, schema, value))) && (!IsArray$1(value) || (!IsAdditionalItems(schema) || CheckAdditionalItems(stack, context, schema, value)) && (!IsContains(schema) || CheckContains(stack, context, schema, value)) && (!IsItems(schema) || CheckItems(stack, context, schema, value)) && (!IsMaxContains(schema) || CheckMaxContains(stack, context, schema, value)) && (!IsMaxItems(schema) || CheckMaxItems(stack, context, schema, value)) && (!IsMinContains(schema) || CheckMinContains(stack, context, schema, value)) && (!IsMinItems(schema) || CheckMinItems(stack, context, schema, value)) && (!IsPrefixItems(schema) || CheckPrefixItems(stack, context, schema, value)) && (!IsUniqueItems(schema) || CheckUniqueItems(stack, context, schema, value))) && (!IsString$2(value) || (!IsMaxLength(schema) || CheckMaxLength(stack, context, schema, value)) && (!IsMinLength(schema) || CheckMinLength(stack, context, schema, value)) && (!IsFormat(schema) || CheckFormat(stack, context, schema, value)) && (!IsPattern(schema) || CheckPattern(stack, context, schema, value))) && (!(IsNumber$2(value) || IsBigInt$1(value)) || (!IsExclusiveMaximum(schema) || CheckExclusiveMaximum(stack, context, schema, value)) && (!IsExclusiveMinimum(schema) || CheckExclusiveMinimum(stack, context, schema, value)) && (!IsMaximum(schema) || CheckMaximum(stack, context, schema, value)) && (!IsMinimum(schema) || CheckMinimum(stack, context, schema, value)) && (!IsMultipleOf(schema) || CheckMultipleOf(stack, context, schema, value))) && (!IsRef(schema) || CheckRef(stack, context, schema, value)) && (!IsRecursiveRef(schema) || CheckRecursiveRef(stack, context, schema, value)) && (!IsDynamicRef(schema) || CheckDynamicRef(stack, context, schema, value)) && (!IsConst(schema) || CheckConst(stack, context, schema, value)) && (!IsEnum(schema) || CheckEnum(stack, context, schema, value)) && (!IsIf(schema) || CheckIf(stack, context, schema, value)) && (!IsNot(schema) || CheckNot(stack, context, schema, value)) && (!IsAllOf(schema) || CheckAllOf(stack, context, schema, value)) && (!IsAnyOf(schema) || CheckAnyOf(stack, context, schema, value)) && (!IsOneOf(schema) || CheckOneOf(stack, context, schema, value)) && (!IsUnevaluatedItems(schema) || !IsArray$1(value) || CheckUnevaluatedItems(stack, context, schema, value)) && (!IsUnevaluatedProperties(schema) || !IsObject$1(value) || CheckUnevaluatedProperties(stack, context, schema, value)) && (!IsRefine(schema) || CheckRefine(stack, context, schema, value));
5235
- stack.Pop(schema);
5236
- return result;
5336
+ const current = NextStack(stack, schema);
5337
+ return IsSchemaBoolean(schema) ? CheckSchemaBoolean(current, context, schema, value) : (!IsType(schema) || CheckType(current, context, schema, value)) && (!(IsObject$1(value) && !IsArray$1(value)) || (!IsRequired(schema) || CheckRequired(current, context, schema, value)) && (!IsAdditionalProperties(schema) || CheckAdditionalProperties(current, context, schema, value)) && (!IsDependencies(schema) || CheckDependencies(current, context, schema, value)) && (!IsDependentRequired(schema) || CheckDependentRequired(current, context, schema, value)) && (!IsDependentSchemas(schema) || CheckDependentSchemas(current, context, schema, value)) && (!IsPatternProperties(schema) || CheckPatternProperties(current, context, schema, value)) && (!IsProperties(schema) || CheckProperties(current, context, schema, value)) && (!IsPropertyNames(schema) || CheckPropertyNames(current, context, schema, value)) && (!IsMinProperties(schema) || CheckMinProperties(current, context, schema, value)) && (!IsMaxProperties(schema) || CheckMaxProperties(current, context, schema, value))) && (!IsArray$1(value) || (!IsAdditionalItems(schema) || CheckAdditionalItems(current, context, schema, value)) && (!IsContains(schema) || CheckContains(current, context, schema, value)) && (!IsItems(schema) || CheckItems(current, context, schema, value)) && (!IsMinContains(schema) || CheckMinContains(current, context, schema, value)) && (!IsMaxContains(schema) || CheckMaxContains(current, context, schema, value)) && (!IsMinItems(schema) || CheckMinItems(current, context, schema, value)) && (!IsMaxItems(schema) || CheckMaxItems(current, context, schema, value)) && (!IsPrefixItems(schema) || CheckPrefixItems(current, context, schema, value)) && (!IsUniqueItems(schema) || CheckUniqueItems(current, context, schema, value))) && (!IsString$2(value) || (!IsMinLength(schema) || CheckMinLength(current, context, schema, value)) && (!IsMaxLength(schema) || CheckMaxLength(current, context, schema, value)) && (!IsFormat(schema) || CheckFormat(current, context, schema, value)) && (!IsPattern(schema) || CheckPattern(current, context, schema, value))) && (!(IsNumber$2(value) || IsBigInt$1(value)) || (!IsExclusiveMinimum(schema) || CheckExclusiveMinimum(current, context, schema, value)) && (!IsExclusiveMaximum(schema) || CheckExclusiveMaximum(current, context, schema, value)) && (!IsMinimum(schema) || CheckMinimum(current, context, schema, value)) && (!IsMaximum(schema) || CheckMaximum(current, context, schema, value)) && (!IsMultipleOf(schema) || CheckMultipleOf(current, context, schema, value))) && (!IsRef(schema) || CheckRef(current, context, schema, value)) && (!IsRecursiveRef(schema) || CheckRecursiveRef(current, context, schema, value)) && (!IsDynamicRef(schema) || CheckDynamicRef(current, context, schema, value)) && (!IsConst(schema) || CheckConst(current, context, schema, value)) && (!IsEnum(schema) || CheckEnum(current, context, schema, value)) && (!IsIf(schema) || CheckIf(current, context, schema, value)) && (!IsNot(schema) || CheckNot(current, context, schema, value)) && (!IsAllOf(schema) || CheckAllOf(current, context, schema, value)) && (!IsAnyOf(schema) || CheckAnyOf(current, context, schema, value)) && (!IsOneOf(schema) || CheckOneOf(current, context, schema, value)) && (!IsUnevaluatedItems(schema) || !IsArray$1(value) || CheckUnevaluatedItems(current, context, schema, value)) && (!IsUnevaluatedProperties(schema) || !IsObject$1(value) || CheckUnevaluatedProperties(current, context, schema, value)) && (!IsRefine(schema) || CheckRefine(current, context, schema, value));
5237
5338
  }
5238
5339
  function ErrorSchemaPushStack(stack, context, schemaPath, instancePath, schema, value) {
5239
5340
  return context.Push() && ErrorSchema(stack, context, schemaPath, instancePath, schema, value) && context.Pop();
5240
5341
  }
5241
5342
  function ErrorSchema(stack, context, schemaPath, instancePath, schema, value) {
5242
- stack.Push(schema);
5243
- const result = IsSchemaBoolean(schema) ? ErrorSchemaBoolean(stack, context, schemaPath, instancePath, schema, value) : !!(+(!IsType(schema) || ErrorType(stack, context, schemaPath, instancePath, schema, value)) & +(!(IsObject$1(value) && !IsArray$1(value)) || !!(+(!IsRequired(schema) || ErrorRequired(stack, context, schemaPath, instancePath, schema, value)) & +(!IsAdditionalProperties(schema) || ErrorAdditionalProperties(stack, context, schemaPath, instancePath, schema, value)) & +(!IsDependencies(schema) || ErrorDependencies(stack, context, schemaPath, instancePath, schema, value)) & +(!IsDependentRequired(schema) || ErrorDependentRequired(stack, context, schemaPath, instancePath, schema, value)) & +(!IsDependentSchemas(schema) || ErrorDependentSchemas(stack, context, schemaPath, instancePath, schema, value)) & +(!IsPatternProperties(schema) || ErrorPatternProperties(stack, context, schemaPath, instancePath, schema, value)) & +(!IsProperties(schema) || ErrorProperties(stack, context, schemaPath, instancePath, schema, value)) & +(!IsPropertyNames(schema) || ErrorPropertyNames(stack, context, schemaPath, instancePath, schema, value)) & +(!IsMinProperties(schema) || ErrorMinProperties(stack, context, schemaPath, instancePath, schema, value)) & +(!IsMaxProperties(schema) || ErrorMaxProperties(stack, context, schemaPath, instancePath, schema, value)))) & +(!IsArray$1(value) || !!(+(!IsAdditionalItems(schema) || ErrorAdditionalItems(stack, context, schemaPath, instancePath, schema, value)) & +(!IsContains(schema) || ErrorContains(stack, context, schemaPath, instancePath, schema, value)) & +(!IsItems(schema) || ErrorItems(stack, context, schemaPath, instancePath, schema, value)) & +(!IsMaxContains(schema) || ErrorMaxContains(stack, context, schemaPath, instancePath, schema, value)) & +(!IsMaxItems(schema) || ErrorMaxItems(stack, context, schemaPath, instancePath, schema, value)) & +(!IsMinContains(schema) || ErrorMinContains(stack, context, schemaPath, instancePath, schema, value)) & +(!IsMinItems(schema) || ErrorMinItems(stack, context, schemaPath, instancePath, schema, value)) & +(!IsPrefixItems(schema) || ErrorPrefixItems(stack, context, schemaPath, instancePath, schema, value)) & +(!IsUniqueItems(schema) || ErrorUniqueItems(stack, context, schemaPath, instancePath, schema, value)))) & +(!IsString$2(value) || !!(+(!IsMaxLength(schema) || ErrorMaxLength(stack, context, schemaPath, instancePath, schema, value)) & +(!IsMinLength(schema) || ErrorMinLength(stack, context, schemaPath, instancePath, schema, value)) & +(!IsFormat(schema) || ErrorFormat(stack, context, schemaPath, instancePath, schema, value)) & +(!IsPattern(schema) || ErrorPattern(stack, context, schemaPath, instancePath, schema, value)))) & +(!(IsNumber$2(value) || IsBigInt$1(value)) || !!(+(!IsExclusiveMaximum(schema) || ErrorExclusiveMaximum(stack, context, schemaPath, instancePath, schema, value)) & +(!IsExclusiveMinimum(schema) || ErrorExclusiveMinimum(stack, context, schemaPath, instancePath, schema, value)) & +(!IsMaximum(schema) || ErrorMaximum(stack, context, schemaPath, instancePath, schema, value)) & +(!IsMinimum(schema) || ErrorMinimum(stack, context, schemaPath, instancePath, schema, value)) & +(!IsMultipleOf(schema) || ErrorMultipleOf(stack, context, schemaPath, instancePath, schema, value)))) & +(!IsRef(schema) || ErrorRef(stack, context, schemaPath, instancePath, schema, value)) & +(!IsRecursiveRef(schema) || ErrorRecursiveRef(stack, context, schemaPath, instancePath, schema, value)) & +(!IsDynamicRef(schema) || ErrorDynamicRef(stack, context, schemaPath, instancePath, schema, value)) & +(!IsConst(schema) || ErrorConst(stack, context, schemaPath, instancePath, schema, value)) & +(!IsEnum(schema) || ErrorEnum(stack, context, schemaPath, instancePath, schema, value)) & +(!IsIf(schema) || ErrorIf(stack, context, schemaPath, instancePath, schema, value)) & +(!IsNot(schema) || ErrorNot(stack, context, schemaPath, instancePath, schema, value)) & +(!IsAllOf(schema) || ErrorAllOf(stack, context, schemaPath, instancePath, schema, value)) & +(!IsAnyOf(schema) || ErrorAnyOf(stack, context, schemaPath, instancePath, schema, value)) & +(!IsOneOf(schema) || ErrorOneOf(stack, context, schemaPath, instancePath, schema, value)) & +(!IsUnevaluatedItems(schema) || !IsArray$1(value) || ErrorUnevaluatedItems(stack, context, schemaPath, instancePath, schema, value)) & +(!IsUnevaluatedProperties(schema) || !IsObject$1(value) || ErrorUnevaluatedProperties(stack, context, schemaPath, instancePath, schema, value))) && (!IsRefine(schema) || ErrorRefine(stack, context, schemaPath, instancePath, schema, value));
5244
- stack.Pop(schema);
5245
- return result;
5343
+ if (context.AtCapacity()) return false;
5344
+ const current = NextStack(stack, schema);
5345
+ return IsSchemaBoolean(schema) ? ErrorSchemaBoolean(current, context, schemaPath, instancePath, schema, value) : !!(+(!IsType(schema) || ErrorType(current, context, schemaPath, instancePath, schema, value)) & +(!(IsObject$1(value) && !IsArray$1(value)) || !!(+(!IsRequired(schema) || ErrorRequired(current, context, schemaPath, instancePath, schema, value)) & +(!IsAdditionalProperties(schema) || ErrorAdditionalProperties(current, context, schemaPath, instancePath, schema, value)) & +(!IsDependencies(schema) || ErrorDependencies(current, context, schemaPath, instancePath, schema, value)) & +(!IsDependentRequired(schema) || ErrorDependentRequired(current, context, schemaPath, instancePath, schema, value)) & +(!IsDependentSchemas(schema) || ErrorDependentSchemas(current, context, schemaPath, instancePath, schema, value)) & +(!IsPatternProperties(schema) || ErrorPatternProperties(current, context, schemaPath, instancePath, schema, value)) & +(!IsProperties(schema) || ErrorProperties(current, context, schemaPath, instancePath, schema, value)) & +(!IsPropertyNames(schema) || ErrorPropertyNames(current, context, schemaPath, instancePath, schema, value)) & +(!IsMinProperties(schema) || ErrorMinProperties(current, context, schemaPath, instancePath, schema, value)) & +(!IsMaxProperties(schema) || ErrorMaxProperties(current, context, schemaPath, instancePath, schema, value)))) & +(!IsArray$1(value) || !!(+(!IsAdditionalItems(schema) || ErrorAdditionalItems(current, context, schemaPath, instancePath, schema, value)) & +(!IsContains(schema) || ErrorContains(current, context, schemaPath, instancePath, schema, value)) & +(!IsItems(schema) || ErrorItems(current, context, schemaPath, instancePath, schema, value)) & +(!IsMinContains(schema) || ErrorMinContains(current, context, schemaPath, instancePath, schema, value)) & +(!IsMaxContains(schema) || ErrorMaxContains(current, context, schemaPath, instancePath, schema, value)) & +(!IsMinItems(schema) || ErrorMinItems(current, context, schemaPath, instancePath, schema, value)) & +(!IsMaxItems(schema) || ErrorMaxItems(current, context, schemaPath, instancePath, schema, value)) & +(!IsPrefixItems(schema) || ErrorPrefixItems(current, context, schemaPath, instancePath, schema, value)) & +(!IsUniqueItems(schema) || ErrorUniqueItems(current, context, schemaPath, instancePath, schema, value)))) & +(!IsString$2(value) || !!(+(!IsMinLength(schema) || ErrorMinLength(current, context, schemaPath, instancePath, schema, value)) & +(!IsMaxLength(schema) || ErrorMaxLength(current, context, schemaPath, instancePath, schema, value)) & +(!IsFormat(schema) || ErrorFormat(current, context, schemaPath, instancePath, schema, value)) & +(!IsPattern(schema) || ErrorPattern(current, context, schemaPath, instancePath, schema, value)))) & +(!(IsNumber$2(value) || IsBigInt$1(value)) || !!(+(!IsExclusiveMinimum(schema) || ErrorExclusiveMinimum(current, context, schemaPath, instancePath, schema, value)) & +(!IsExclusiveMaximum(schema) || ErrorExclusiveMaximum(current, context, schemaPath, instancePath, schema, value)) & +(!IsMinimum(schema) || ErrorMinimum(current, context, schemaPath, instancePath, schema, value)) & +(!IsMaximum(schema) || ErrorMaximum(current, context, schemaPath, instancePath, schema, value)) & +(!IsMultipleOf(schema) || ErrorMultipleOf(current, context, schemaPath, instancePath, schema, value)))) & +(!IsRef(schema) || ErrorRef(current, context, schemaPath, instancePath, schema, value)) & +(!IsRecursiveRef(schema) || ErrorRecursiveRef(current, context, schemaPath, instancePath, schema, value)) & +(!IsDynamicRef(schema) || ErrorDynamicRef(current, context, schemaPath, instancePath, schema, value)) & +(!IsConst(schema) || ErrorConst(current, context, schemaPath, instancePath, schema, value)) & +(!IsEnum(schema) || ErrorEnum(current, context, schemaPath, instancePath, schema, value)) & +(!IsIf(schema) || ErrorIf(current, context, schemaPath, instancePath, schema, value)) & +(!IsNot(schema) || ErrorNot(current, context, schemaPath, instancePath, schema, value)) & +(!IsAllOf(schema) || ErrorAllOf(current, context, schemaPath, instancePath, schema, value)) & +(!IsAnyOf(schema) || ErrorAnyOf(current, context, schemaPath, instancePath, schema, value)) & +(!IsOneOf(schema) || ErrorOneOf(current, context, schemaPath, instancePath, schema, value)) & +(!IsUnevaluatedItems(schema) || !IsArray$1(value) || ErrorUnevaluatedItems(current, context, schemaPath, instancePath, schema, value)) & +(!IsUnevaluatedProperties(schema) || !IsObject$1(value) || ErrorUnevaluatedProperties(current, context, schemaPath, instancePath, schema, value))) && (!IsRefine(schema) || ErrorRefine(current, context, schemaPath, instancePath, schema, value));
5246
5346
  }
5247
- function GetIndex(index, value) {
5248
- return IsObject$1(value) && !IsUnsafePropertyKey(index) ? value[index] : void 0;
5249
- }
5250
- function GetIndices(indices, value) {
5251
- return indices.reduce((value, index) => GetIndex(index, value), value);
5252
- }
5253
- function Indices(pointer) {
5254
- if (IsEqual(pointer.length, 0)) return [];
5255
- const indices = pointer.split("/").map((index) => index.replace(/~1/g, "/").replace(/~0/g, "~"));
5256
- return indices.length > 0 && indices[0] === "" ? indices.slice(1) : indices;
5257
- }
5258
- function Get(value, pointer) {
5259
- return GetIndices(Indices(pointer), value);
5260
- }
5261
- const DefaultBase = new URL("https://json-schema.org");
5262
- function MatchId(schema, base, ref) {
5263
- if (schema.$id === ref.hash) return schema;
5264
- const absoluteId = new URL(schema.$id, base.href);
5265
- const absoluteRef = new URL(ref.href, base.href);
5266
- if (IsEqual(absoluteId.pathname, absoluteRef.pathname)) return ref.hash.startsWith("#") ? MatchHash(schema, base, ref) : schema;
5267
- }
5268
- function MatchAnchor(schema, base, ref) {
5269
- const absoluteAnchor = new URL(`#${schema.$anchor}`, base.href);
5270
- const absoluteRef = new URL(ref.href, base.href);
5271
- return IsEqual(absoluteAnchor.href, absoluteRef.href) ? schema : void 0;
5272
- }
5273
- function MatchDynamicAnchor(schema, base, ref) {
5274
- const absoluteAnchor = new URL(`#${schema.$dynamicAnchor}`, base.href);
5275
- const absoluteRef = new URL(ref.href, base.href);
5276
- return IsEqual(absoluteAnchor.href, absoluteRef.href) ? schema : void 0;
5277
- }
5278
- function MatchHash(schema, _base, ref) {
5279
- if (ref.href.endsWith("#")) return schema;
5280
- if (!ref.hash.startsWith("#")) return void 0;
5281
- const fragment = decodeURIComponent(ref.hash.slice(1));
5282
- if (!fragment.startsWith("/")) return void 0;
5283
- return Get(schema, fragment);
5284
- }
5285
- function Match(schema, base, ref) {
5286
- if (IsId(schema)) {
5287
- const result = MatchId(schema, base, ref);
5288
- if (!IsUndefined$1(result)) return result;
5289
- }
5290
- if (IsAnchor(schema)) {
5291
- const result = MatchAnchor(schema, base, ref);
5292
- if (!IsUndefined$1(result)) return result;
5293
- }
5294
- if (IsDynamicAnchor(schema)) {
5295
- const result = MatchDynamicAnchor(schema, base, ref);
5296
- if (!IsUndefined$1(result)) return result;
5297
- }
5298
- return MatchHash(schema, base, ref);
5299
- }
5300
- function FromArray$4(schema, base, ref) {
5301
- return schema.reduce((result, item) => {
5302
- const match = FromValue(item, base, ref);
5303
- return !IsUndefined$1(match) ? match : result;
5304
- }, void 0);
5305
- }
5306
- function SkipProperty(key) {
5307
- return IsEqual(key, "const") || IsEqual(key, "enum");
5308
- }
5309
- function FromObject$4(schema, base, ref) {
5310
- return Keys(schema).reduce((result, key) => {
5311
- if (SkipProperty(key)) return result;
5312
- const match = FromValue(schema[key], base, ref);
5313
- return !IsUndefined$1(match) ? match : result;
5314
- }, void 0);
5315
- }
5316
- function FromValue(schema, base, ref) {
5317
- const nextBase = IsSchemaObject(schema) && IsId(schema) ? new URL(schema.$id, base.href) : base;
5318
- if (IsSchemaObject(schema)) {
5319
- const result = Match(schema, nextBase, ref);
5320
- if (!IsUndefined$1(result)) return result;
5321
- }
5322
- if (IsArray$1(schema)) return FromArray$4(schema, nextBase, ref);
5323
- if (IsObject$1(schema)) return FromObject$4(schema, nextBase, ref);
5324
- }
5325
- function CanonicalHref(url) {
5326
- return url.href.split("#")[0];
5327
- }
5328
- function RefContext(context, ref) {
5329
- return HasPropertyKey(context, ref) ? context[ref] : void 0;
5330
- }
5331
- function RefLocal(schema, base, ref) {
5332
- return FromValue(schema, base, ref);
5333
- }
5334
- function RefRemote(context, base, ref) {
5335
- const targetDocumentHref = CanonicalHref(ref);
5336
- if (IsEqual(targetDocumentHref, CanonicalHref(base))) return void 0;
5337
- if (!HasPropertyKey(context, targetDocumentHref)) return void 0;
5338
- const remoteSchema = context[targetDocumentHref];
5339
- return FromValue(remoteSchema, IsSchemaObject(remoteSchema) && IsId(remoteSchema) ? new URL(remoteSchema.$id, DefaultBase.href) : new URL(targetDocumentHref), ref);
5340
- }
5341
- function Ref(context, schema, ref) {
5342
- const initialBase = IsId(schema) ? new URL(schema.$id, DefaultBase.href) : DefaultBase;
5343
- const initialRef = new URL(ref, initialBase.href);
5344
- return RefContext(context, ref) ?? RefLocal(schema, initialBase, initialRef) ?? RefRemote(context, initialBase, initialRef);
5345
- }
5346
- function DynamicRef(context, root, base, dynamicRef, dynamicAnchors) {
5347
- const fragmentTarget = dynamicRef.$dynamicRef.startsWith("#") ? Ref(context, base, dynamicRef.$dynamicRef) : Ref(context, root, dynamicRef.$dynamicRef);
5348
- if (IsUndefined$1(fragmentTarget)) return void 0;
5349
- if (!IsSchemaObject(fragmentTarget) || !IsDynamicAnchor(fragmentTarget)) return fragmentTarget;
5350
- if (new URL(dynamicRef.$dynamicRef, DefaultBase).hash.startsWith("#/")) return fragmentTarget;
5351
- return dynamicAnchors.find((anchor) => anchor.$dynamicAnchor === fragmentTarget.$dynamicAnchor) ?? fragmentTarget;
5352
- }
5353
- var __classPrivateFieldGet = function(receiver, state, kind, f) {
5354
- if (kind === "a" && !f) throw new TypeError("Private accessor was defined without a getter");
5355
- if (typeof state === "function" ? receiver !== state || !f : !state.has(receiver)) throw new TypeError("Cannot read private member from an object whose class did not declare it");
5356
- return kind === "m" ? f : kind === "a" ? f.call(receiver) : f ? f.value : state.get(receiver);
5357
- };
5358
- var _Stack_instances;
5359
- var _Stack_PushResourceAnchors;
5360
- var _Stack_PopResourceAnchors;
5361
- var Stack = class {
5362
- constructor(context, schema) {
5363
- _Stack_instances.add(this);
5364
- this.context = context;
5365
- this.schema = schema;
5366
- this.ids = [];
5367
- this.anchors = [];
5368
- this.recursiveAnchors = [];
5369
- this.dynamicAnchors = [];
5370
- }
5371
- BaseURL() {
5372
- return this.ids.reduce((result, schema) => new URL(schema.$id, result), DefaultBase);
5373
- }
5374
- Base() {
5375
- return this.ids[this.ids.length - 1] ?? this.schema;
5376
- }
5377
- Push(schema) {
5378
- if (!IsSchemaObject(schema)) return;
5379
- if (IsId(schema)) {
5380
- this.ids.push(schema);
5381
- __classPrivateFieldGet(this, _Stack_instances, "m", _Stack_PushResourceAnchors).call(this, schema);
5382
- }
5383
- if (IsAnchor(schema)) this.anchors.push(schema);
5384
- if (IsRecursiveAnchorTrue(schema)) this.recursiveAnchors.push(schema);
5385
- if (IsDynamicAnchor(schema)) this.dynamicAnchors.push(schema);
5386
- }
5387
- Pop(schema) {
5388
- if (!IsSchemaObject(schema)) return;
5389
- if (IsId(schema)) {
5390
- this.ids.pop();
5391
- __classPrivateFieldGet(this, _Stack_instances, "m", _Stack_PopResourceAnchors).call(this, schema);
5392
- }
5393
- if (IsAnchor(schema)) this.anchors.pop();
5394
- if (IsRecursiveAnchorTrue(schema)) this.recursiveAnchors.pop();
5395
- if (IsDynamicAnchor(schema)) this.dynamicAnchors.pop();
5396
- }
5397
- Ref(ref) {
5398
- const root = this.schema;
5399
- return !ref.$ref.startsWith("#") ? Ref(this.context, root, ref.$ref) : Ref(this.context, this.Base(), ref.$ref);
5400
- }
5401
- RecursiveRef(recursiveRef) {
5402
- return IsRecursiveAnchorTrue(this.Base()) ? Ref(this.context, this.recursiveAnchors[0], recursiveRef.$recursiveRef) : Ref(this.context, this.Base(), recursiveRef.$recursiveRef);
5403
- }
5404
- DynamicRef(dynamicRef) {
5405
- const root = this.schema;
5406
- return DynamicRef(this.context, root, this.Base(), dynamicRef, this.dynamicAnchors);
5407
- }
5408
- };
5409
- _Stack_instances = /* @__PURE__ */ new WeakSet(), _Stack_PushResourceAnchors = function _Stack_PushResourceAnchors(schema, isRoot = true) {
5410
- if (!IsSchemaObject(schema)) return;
5411
- const current = schema;
5412
- if (!isRoot && IsId(current)) return;
5413
- if (!isRoot && IsDynamicAnchor(current)) this.dynamicAnchors.push(current);
5414
- for (const key of Keys(current)) __classPrivateFieldGet(this, _Stack_instances, "m", _Stack_PushResourceAnchors).call(this, current[key], false);
5415
- }, _Stack_PopResourceAnchors = function _Stack_PopResourceAnchors(schema, isRoot = true) {
5416
- if (!IsSchemaObject(schema)) return;
5417
- const current = schema;
5418
- if (!isRoot && IsId(current)) return;
5419
- if (!isRoot && IsDynamicAnchor(current)) this.dynamicAnchors.pop();
5420
- for (const key of Keys(current)) __classPrivateFieldGet(this, _Stack_instances, "m", _Stack_PopResourceAnchors).call(this, current[key], false);
5421
- };
5422
5347
  function Errors$1(...args) {
5423
5348
  const [context, schema, value] = Match$3(args, {
5424
5349
  3: (context, schema, value) => [
@@ -5432,16 +5357,15 @@ function Errors$1(...args) {
5432
5357
  value
5433
5358
  ]
5434
5359
  });
5435
- const settings = Get$2();
5360
+ const stack = Stack(context, schema);
5361
+ const errorContext = new ErrorContext();
5362
+ const result = ErrorSchema(stack, errorContext, "#", "", schema, value);
5363
+ const errors = errorContext.GetErrors();
5436
5364
  const locale = Get$1();
5437
- const errors = [];
5438
- return [ErrorSchema(new Stack(context, schema), new ErrorContext((error) => {
5439
- if (IsGreaterEqualThan(errors.length, settings.maxErrors)) return;
5440
- return errors.push({
5441
- ...error,
5442
- message: locale(error)
5443
- });
5444
- }), "#", "", schema, value), errors];
5365
+ return [result, errors.map((error) => ({
5366
+ ...error,
5367
+ message: locale(error)
5368
+ }))];
5445
5369
  }
5446
5370
  function Check$1(...args) {
5447
5371
  const [context, schema, value] = Match$3(args, {
@@ -5456,7 +5380,7 @@ function Check$1(...args) {
5456
5380
  value
5457
5381
  ]
5458
5382
  });
5459
- return CheckSchema(new Stack(context, schema), new CheckContext(), schema, value);
5383
+ return CheckSchema(Stack(context, schema), new CheckContext(), schema, value);
5460
5384
  }
5461
5385
  function Check(...args) {
5462
5386
  const [context, type, value] = Match$3(args, {