@sinclair/typebox 0.30.4 → 0.31.0-dev-2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/errors/errors.js CHANGED
@@ -27,82 +27,98 @@ THE SOFTWARE.
27
27
 
28
28
  ---------------------------------------------------------------------------*/
29
29
  Object.defineProperty(exports, "__esModule", { value: true });
30
- exports.Errors = exports.ValueErrorsDereferenceError = exports.ValueErrorsUnknownTypeError = exports.ValueErrorIterator = exports.ValueErrorType = void 0;
31
- const index_1 = require("../system/index");
30
+ exports.Errors = exports.ValueErrorIterator = exports.ValueErrorsUnknownTypeError = exports.ValueErrorType = void 0;
31
+ const guard_1 = require("../value/guard");
32
+ const system_1 = require("../system/system");
33
+ const deref_1 = require("../value/deref");
34
+ const hash_1 = require("../value/hash");
32
35
  const Types = require("../typebox");
33
- const ValueHash = require("../value/hash");
34
- const ValueGuard = require("../value/guard");
35
36
  // --------------------------------------------------------------------------
36
37
  // ValueErrorType
37
38
  // --------------------------------------------------------------------------
38
39
  var ValueErrorType;
39
40
  (function (ValueErrorType) {
40
- ValueErrorType[ValueErrorType["Array"] = 0] = "Array";
41
- ValueErrorType[ValueErrorType["ArrayMinItems"] = 1] = "ArrayMinItems";
41
+ ValueErrorType[ValueErrorType["ArrayContains"] = 0] = "ArrayContains";
42
+ ValueErrorType[ValueErrorType["ArrayMaxContains"] = 1] = "ArrayMaxContains";
42
43
  ValueErrorType[ValueErrorType["ArrayMaxItems"] = 2] = "ArrayMaxItems";
43
- ValueErrorType[ValueErrorType["ArrayContains"] = 3] = "ArrayContains";
44
- ValueErrorType[ValueErrorType["ArrayMinContains"] = 4] = "ArrayMinContains";
45
- ValueErrorType[ValueErrorType["ArrayMaxContains"] = 5] = "ArrayMaxContains";
46
- ValueErrorType[ValueErrorType["ArrayUniqueItems"] = 6] = "ArrayUniqueItems";
44
+ ValueErrorType[ValueErrorType["ArrayMinContains"] = 3] = "ArrayMinContains";
45
+ ValueErrorType[ValueErrorType["ArrayMinItems"] = 4] = "ArrayMinItems";
46
+ ValueErrorType[ValueErrorType["ArrayUniqueItems"] = 5] = "ArrayUniqueItems";
47
+ ValueErrorType[ValueErrorType["Array"] = 6] = "Array";
47
48
  ValueErrorType[ValueErrorType["AsyncIterator"] = 7] = "AsyncIterator";
48
- ValueErrorType[ValueErrorType["BigInt"] = 8] = "BigInt";
49
- ValueErrorType[ValueErrorType["BigIntMultipleOf"] = 9] = "BigIntMultipleOf";
50
- ValueErrorType[ValueErrorType["BigIntExclusiveMinimum"] = 10] = "BigIntExclusiveMinimum";
51
- ValueErrorType[ValueErrorType["BigIntExclusiveMaximum"] = 11] = "BigIntExclusiveMaximum";
52
- ValueErrorType[ValueErrorType["BigIntMinimum"] = 12] = "BigIntMinimum";
53
- ValueErrorType[ValueErrorType["BigIntMaximum"] = 13] = "BigIntMaximum";
49
+ ValueErrorType[ValueErrorType["BigIntExclusiveMaximum"] = 8] = "BigIntExclusiveMaximum";
50
+ ValueErrorType[ValueErrorType["BigIntExclusiveMinimum"] = 9] = "BigIntExclusiveMinimum";
51
+ ValueErrorType[ValueErrorType["BigIntMaximum"] = 10] = "BigIntMaximum";
52
+ ValueErrorType[ValueErrorType["BigIntMinimum"] = 11] = "BigIntMinimum";
53
+ ValueErrorType[ValueErrorType["BigIntMultipleOf"] = 12] = "BigIntMultipleOf";
54
+ ValueErrorType[ValueErrorType["BigInt"] = 13] = "BigInt";
54
55
  ValueErrorType[ValueErrorType["Boolean"] = 14] = "Boolean";
55
- ValueErrorType[ValueErrorType["Date"] = 15] = "Date";
56
+ ValueErrorType[ValueErrorType["DateExclusiveMaximumTimestamp"] = 15] = "DateExclusiveMaximumTimestamp";
56
57
  ValueErrorType[ValueErrorType["DateExclusiveMinimumTimestamp"] = 16] = "DateExclusiveMinimumTimestamp";
57
- ValueErrorType[ValueErrorType["DateExclusiveMaximumTimestamp"] = 17] = "DateExclusiveMaximumTimestamp";
58
+ ValueErrorType[ValueErrorType["DateMaximumTimestamp"] = 17] = "DateMaximumTimestamp";
58
59
  ValueErrorType[ValueErrorType["DateMinimumTimestamp"] = 18] = "DateMinimumTimestamp";
59
- ValueErrorType[ValueErrorType["DateMaximumTimestamp"] = 19] = "DateMaximumTimestamp";
60
- ValueErrorType[ValueErrorType["Function"] = 20] = "Function";
61
- ValueErrorType[ValueErrorType["Integer"] = 21] = "Integer";
62
- ValueErrorType[ValueErrorType["IntegerMultipleOf"] = 22] = "IntegerMultipleOf";
60
+ ValueErrorType[ValueErrorType["DateMultipleOfTimestamp"] = 19] = "DateMultipleOfTimestamp";
61
+ ValueErrorType[ValueErrorType["Date"] = 20] = "Date";
62
+ ValueErrorType[ValueErrorType["Function"] = 21] = "Function";
63
+ ValueErrorType[ValueErrorType["IntegerExclusiveMaximum"] = 22] = "IntegerExclusiveMaximum";
63
64
  ValueErrorType[ValueErrorType["IntegerExclusiveMinimum"] = 23] = "IntegerExclusiveMinimum";
64
- ValueErrorType[ValueErrorType["IntegerExclusiveMaximum"] = 24] = "IntegerExclusiveMaximum";
65
+ ValueErrorType[ValueErrorType["IntegerMaximum"] = 24] = "IntegerMaximum";
65
66
  ValueErrorType[ValueErrorType["IntegerMinimum"] = 25] = "IntegerMinimum";
66
- ValueErrorType[ValueErrorType["IntegerMaximum"] = 26] = "IntegerMaximum";
67
- ValueErrorType[ValueErrorType["Intersect"] = 27] = "Intersect";
67
+ ValueErrorType[ValueErrorType["IntegerMultipleOf"] = 26] = "IntegerMultipleOf";
68
+ ValueErrorType[ValueErrorType["Integer"] = 27] = "Integer";
68
69
  ValueErrorType[ValueErrorType["IntersectUnevaluatedProperties"] = 28] = "IntersectUnevaluatedProperties";
69
- ValueErrorType[ValueErrorType["Iterator"] = 29] = "Iterator";
70
- ValueErrorType[ValueErrorType["Literal"] = 30] = "Literal";
71
- ValueErrorType[ValueErrorType["Never"] = 31] = "Never";
72
- ValueErrorType[ValueErrorType["Not"] = 32] = "Not";
73
- ValueErrorType[ValueErrorType["Null"] = 33] = "Null";
74
- ValueErrorType[ValueErrorType["Number"] = 34] = "Number";
75
- ValueErrorType[ValueErrorType["NumberMultipleOf"] = 35] = "NumberMultipleOf";
76
- ValueErrorType[ValueErrorType["NumberExclusiveMinimum"] = 36] = "NumberExclusiveMinimum";
77
- ValueErrorType[ValueErrorType["NumberExclusiveMaximum"] = 37] = "NumberExclusiveMaximum";
78
- ValueErrorType[ValueErrorType["NumberMinimum"] = 38] = "NumberMinimum";
79
- ValueErrorType[ValueErrorType["NumberMaximum"] = 39] = "NumberMaximum";
80
- ValueErrorType[ValueErrorType["Object"] = 40] = "Object";
81
- ValueErrorType[ValueErrorType["ObjectMinProperties"] = 41] = "ObjectMinProperties";
82
- ValueErrorType[ValueErrorType["ObjectMaxProperties"] = 42] = "ObjectMaxProperties";
83
- ValueErrorType[ValueErrorType["ObjectAdditionalProperties"] = 43] = "ObjectAdditionalProperties";
84
- ValueErrorType[ValueErrorType["ObjectRequiredProperties"] = 44] = "ObjectRequiredProperties";
85
- ValueErrorType[ValueErrorType["Promise"] = 45] = "Promise";
86
- ValueErrorType[ValueErrorType["RecordKeyNumeric"] = 46] = "RecordKeyNumeric";
87
- ValueErrorType[ValueErrorType["RecordKeyString"] = 47] = "RecordKeyString";
88
- ValueErrorType[ValueErrorType["String"] = 48] = "String";
89
- ValueErrorType[ValueErrorType["StringMinLength"] = 49] = "StringMinLength";
70
+ ValueErrorType[ValueErrorType["Intersect"] = 29] = "Intersect";
71
+ ValueErrorType[ValueErrorType["Iterator"] = 30] = "Iterator";
72
+ ValueErrorType[ValueErrorType["Kind"] = 31] = "Kind";
73
+ ValueErrorType[ValueErrorType["Literal"] = 32] = "Literal";
74
+ ValueErrorType[ValueErrorType["Never"] = 33] = "Never";
75
+ ValueErrorType[ValueErrorType["Not"] = 34] = "Not";
76
+ ValueErrorType[ValueErrorType["Null"] = 35] = "Null";
77
+ ValueErrorType[ValueErrorType["NumberExclusiveMaximum"] = 36] = "NumberExclusiveMaximum";
78
+ ValueErrorType[ValueErrorType["NumberExclusiveMinimum"] = 37] = "NumberExclusiveMinimum";
79
+ ValueErrorType[ValueErrorType["NumberMaximum"] = 38] = "NumberMaximum";
80
+ ValueErrorType[ValueErrorType["NumberMinimum"] = 39] = "NumberMinimum";
81
+ ValueErrorType[ValueErrorType["NumberMultipleOf"] = 40] = "NumberMultipleOf";
82
+ ValueErrorType[ValueErrorType["Number"] = 41] = "Number";
83
+ ValueErrorType[ValueErrorType["ObjectAdditionalProperties"] = 42] = "ObjectAdditionalProperties";
84
+ ValueErrorType[ValueErrorType["ObjectMaxProperties"] = 43] = "ObjectMaxProperties";
85
+ ValueErrorType[ValueErrorType["ObjectMinProperties"] = 44] = "ObjectMinProperties";
86
+ ValueErrorType[ValueErrorType["ObjectRequiredProperty"] = 45] = "ObjectRequiredProperty";
87
+ ValueErrorType[ValueErrorType["Object"] = 46] = "Object";
88
+ ValueErrorType[ValueErrorType["Promise"] = 47] = "Promise";
89
+ ValueErrorType[ValueErrorType["StringFormatUnknown"] = 48] = "StringFormatUnknown";
90
+ ValueErrorType[ValueErrorType["StringFormat"] = 49] = "StringFormat";
90
91
  ValueErrorType[ValueErrorType["StringMaxLength"] = 50] = "StringMaxLength";
91
- ValueErrorType[ValueErrorType["StringPattern"] = 51] = "StringPattern";
92
- ValueErrorType[ValueErrorType["StringFormatUnknown"] = 52] = "StringFormatUnknown";
93
- ValueErrorType[ValueErrorType["StringFormat"] = 53] = "StringFormat";
92
+ ValueErrorType[ValueErrorType["StringMinLength"] = 51] = "StringMinLength";
93
+ ValueErrorType[ValueErrorType["StringPattern"] = 52] = "StringPattern";
94
+ ValueErrorType[ValueErrorType["String"] = 53] = "String";
94
95
  ValueErrorType[ValueErrorType["Symbol"] = 54] = "Symbol";
95
- ValueErrorType[ValueErrorType["TupleZeroLength"] = 55] = "TupleZeroLength";
96
- ValueErrorType[ValueErrorType["TupleLength"] = 56] = "TupleLength";
97
- ValueErrorType[ValueErrorType["Undefined"] = 57] = "Undefined";
98
- ValueErrorType[ValueErrorType["Union"] = 58] = "Union";
96
+ ValueErrorType[ValueErrorType["TupleLength"] = 55] = "TupleLength";
97
+ ValueErrorType[ValueErrorType["Tuple"] = 56] = "Tuple";
98
+ ValueErrorType[ValueErrorType["Uint8ArrayMaxByteLength"] = 57] = "Uint8ArrayMaxByteLength";
99
+ ValueErrorType[ValueErrorType["Uint8ArrayMinByteLength"] = 58] = "Uint8ArrayMinByteLength";
99
100
  ValueErrorType[ValueErrorType["Uint8Array"] = 59] = "Uint8Array";
100
- ValueErrorType[ValueErrorType["Uint8ArrayMinByteLength"] = 60] = "Uint8ArrayMinByteLength";
101
- ValueErrorType[ValueErrorType["Uint8ArrayMaxByteLength"] = 61] = "Uint8ArrayMaxByteLength";
101
+ ValueErrorType[ValueErrorType["Undefined"] = 60] = "Undefined";
102
+ ValueErrorType[ValueErrorType["Union"] = 61] = "Union";
102
103
  ValueErrorType[ValueErrorType["Void"] = 62] = "Void";
103
- ValueErrorType[ValueErrorType["Kind"] = 63] = "Kind";
104
104
  })(ValueErrorType || (exports.ValueErrorType = ValueErrorType = {}));
105
105
  // --------------------------------------------------------------------------
106
+ // ValueErrors
107
+ // --------------------------------------------------------------------------
108
+ class ValueErrorsUnknownTypeError extends Types.TypeBoxError {
109
+ constructor(schema) {
110
+ super('Unknown type');
111
+ this.schema = schema;
112
+ }
113
+ }
114
+ exports.ValueErrorsUnknownTypeError = ValueErrorsUnknownTypeError;
115
+ // --------------------------------------------------------------------------
116
+ // Guards
117
+ // --------------------------------------------------------------------------
118
+ function IsDefined(value) {
119
+ return value !== undefined;
120
+ }
121
+ // --------------------------------------------------------------------------
106
122
  // ValueErrorIterator
107
123
  // --------------------------------------------------------------------------
108
124
  class ValueErrorIterator {
@@ -120,69 +136,31 @@ class ValueErrorIterator {
120
136
  }
121
137
  exports.ValueErrorIterator = ValueErrorIterator;
122
138
  // --------------------------------------------------------------------------
123
- // ValueErrors
124
- // --------------------------------------------------------------------------
125
- class ValueErrorsUnknownTypeError extends Error {
126
- constructor(schema) {
127
- super('ValueErrors: Unknown type');
128
- this.schema = schema;
129
- }
130
- }
131
- exports.ValueErrorsUnknownTypeError = ValueErrorsUnknownTypeError;
132
- class ValueErrorsDereferenceError extends Error {
133
- constructor(schema) {
134
- super(`ValueErrors: Unable to dereference type with $id '${schema.$ref}'`);
135
- this.schema = schema;
136
- }
137
- }
138
- exports.ValueErrorsDereferenceError = ValueErrorsDereferenceError;
139
- // --------------------------------------------------------------------------
140
- // Guards
141
- // --------------------------------------------------------------------------
142
- function IsDefined(value) {
143
- return value !== undefined;
144
- }
145
- // --------------------------------------------------------------------------
146
- // Policies
139
+ // Create
147
140
  // --------------------------------------------------------------------------
148
- function IsExactOptionalProperty(value, key) {
149
- return index_1.TypeSystem.ExactOptionalPropertyTypes ? key in value : value[key] !== undefined;
150
- }
151
- function IsObject(value) {
152
- const isObject = ValueGuard.IsObject(value);
153
- return index_1.TypeSystem.AllowArrayObjects ? isObject : isObject && !ValueGuard.IsArray(value);
154
- }
155
- function IsRecordObject(value) {
156
- return IsObject(value) && !(value instanceof Date) && !(value instanceof Uint8Array);
157
- }
158
- function IsNumber(value) {
159
- const isNumber = ValueGuard.IsNumber(value);
160
- return index_1.TypeSystem.AllowNaN ? isNumber : isNumber && Number.isFinite(value);
161
- }
162
- function IsVoid(value) {
163
- const isUndefined = ValueGuard.IsUndefined(value);
164
- return index_1.TypeSystem.AllowVoidNull ? isUndefined || value === null : isUndefined;
141
+ function Create(type, schema, path, value) {
142
+ return { type, schema, path, value, message: system_1.TypeSystemErrorFunction.Get()(schema, type) };
165
143
  }
166
144
  // --------------------------------------------------------------------------
167
145
  // Types
168
146
  // --------------------------------------------------------------------------
169
147
  function* TAny(schema, references, path, value) { }
170
148
  function* TArray(schema, references, path, value) {
171
- if (!ValueGuard.IsArray(value)) {
172
- return yield { type: ValueErrorType.Array, schema, path, value, message: `Expected array` };
149
+ if (!(0, guard_1.IsArray)(value)) {
150
+ return yield Create(ValueErrorType.Array, schema, path, value);
173
151
  }
174
152
  if (IsDefined(schema.minItems) && !(value.length >= schema.minItems)) {
175
- yield { type: ValueErrorType.ArrayMinItems, schema, path, value, message: `Expected array length to be greater or equal to ${schema.minItems}` };
153
+ yield Create(ValueErrorType.ArrayMinItems, schema, path, value);
176
154
  }
177
155
  if (IsDefined(schema.maxItems) && !(value.length <= schema.maxItems)) {
178
- yield { type: ValueErrorType.ArrayMinItems, schema, path, value, message: `Expected array length to be less or equal to ${schema.maxItems}` };
156
+ yield Create(ValueErrorType.ArrayMaxItems, schema, path, value);
179
157
  }
180
158
  for (let i = 0; i < value.length; i++) {
181
159
  yield* Visit(schema.items, references, `${path}/${i}`, value[i]);
182
160
  }
183
161
  // prettier-ignore
184
162
  if (schema.uniqueItems === true && !((function () { const set = new Set(); for (const element of value) {
185
- const hashed = ValueHash.Hash(element);
163
+ const hashed = (0, hash_1.Hash)(element);
186
164
  if (set.has(hashed)) {
187
165
  return false;
188
166
  }
@@ -190,116 +168,109 @@ function* TArray(schema, references, path, value) {
190
168
  set.add(hashed);
191
169
  }
192
170
  } return true; })())) {
193
- yield { type: ValueErrorType.ArrayUniqueItems, schema, path, value, message: `Expected array elements to be unique` };
171
+ yield Create(ValueErrorType.ArrayUniqueItems, schema, path, value);
194
172
  }
195
173
  // contains
196
- if (!(IsDefined(schema.contains) || IsNumber(schema.minContains) || IsNumber(schema.maxContains))) {
174
+ if (!(IsDefined(schema.contains) || IsDefined(schema.minContains) || IsDefined(schema.maxContains))) {
197
175
  return;
198
176
  }
199
177
  const containsSchema = IsDefined(schema.contains) ? schema.contains : Types.Type.Never();
200
178
  const containsCount = value.reduce((acc, value, index) => (Visit(containsSchema, references, `${path}${index}`, value).next().done === true ? acc + 1 : acc), 0);
201
179
  if (containsCount === 0) {
202
- yield { type: ValueErrorType.ArrayContains, schema, path, value, message: `Expected array to contain at least one matching type` };
180
+ yield Create(ValueErrorType.ArrayContains, schema, path, value);
203
181
  }
204
- if (ValueGuard.IsNumber(schema.minContains) && containsCount < schema.minContains) {
205
- yield { type: ValueErrorType.ArrayMinContains, schema, path, value, message: `Expected array to contain at least ${schema.minContains} matching types` };
182
+ if ((0, guard_1.IsNumber)(schema.minContains) && containsCount < schema.minContains) {
183
+ yield Create(ValueErrorType.ArrayMinContains, schema, path, value);
206
184
  }
207
- if (ValueGuard.IsNumber(schema.maxContains) && containsCount > schema.maxContains) {
208
- yield { type: ValueErrorType.ArrayMaxContains, schema, path, value, message: `Expected array to contain no more than ${schema.maxContains} matching types` };
185
+ if ((0, guard_1.IsNumber)(schema.maxContains) && containsCount > schema.maxContains) {
186
+ yield Create(ValueErrorType.ArrayMaxContains, schema, path, value);
209
187
  }
210
188
  }
211
189
  function* TAsyncIterator(schema, references, path, value) {
212
- if (!ValueGuard.IsAsyncIterator(value)) {
213
- yield { type: ValueErrorType.AsyncIterator, schema, path, value, message: `Expected value to be an async iterator` };
214
- }
190
+ if (!(0, guard_1.IsAsyncIterator)(value))
191
+ yield Create(ValueErrorType.AsyncIterator, schema, path, value);
215
192
  }
216
193
  function* TBigInt(schema, references, path, value) {
217
- if (!ValueGuard.IsBigInt(value)) {
218
- return yield { type: ValueErrorType.BigInt, schema, path, value, message: `Expected bigint` };
219
- }
220
- if (IsDefined(schema.multipleOf) && !(value % schema.multipleOf === BigInt(0))) {
221
- yield { type: ValueErrorType.BigIntMultipleOf, schema, path, value, message: `Expected bigint to be a multiple of ${schema.multipleOf}` };
194
+ if (!(0, guard_1.IsBigInt)(value))
195
+ return yield Create(ValueErrorType.BigInt, schema, path, value);
196
+ if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
197
+ yield Create(ValueErrorType.BigIntExclusiveMaximum, schema, path, value);
222
198
  }
223
199
  if (IsDefined(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
224
- yield { type: ValueErrorType.BigIntExclusiveMinimum, schema, path, value, message: `Expected bigint to be greater than ${schema.exclusiveMinimum}` };
200
+ yield Create(ValueErrorType.BigIntExclusiveMinimum, schema, path, value);
225
201
  }
226
- if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
227
- yield { type: ValueErrorType.BigIntExclusiveMaximum, schema, path, value, message: `Expected bigint to be less than ${schema.exclusiveMaximum}` };
202
+ if (IsDefined(schema.maximum) && !(value <= schema.maximum)) {
203
+ yield Create(ValueErrorType.BigIntMaximum, schema, path, value);
228
204
  }
229
205
  if (IsDefined(schema.minimum) && !(value >= schema.minimum)) {
230
- yield { type: ValueErrorType.BigIntMinimum, schema, path, value, message: `Expected bigint to be greater or equal to ${schema.minimum}` };
206
+ yield Create(ValueErrorType.BigIntMinimum, schema, path, value);
231
207
  }
232
- if (IsDefined(schema.maximum) && !(value <= schema.maximum)) {
233
- yield { type: ValueErrorType.BigIntMaximum, schema, path, value, message: `Expected bigint to be less or equal to ${schema.maximum}` };
208
+ if (IsDefined(schema.multipleOf) && !(value % schema.multipleOf === BigInt(0))) {
209
+ yield Create(ValueErrorType.BigIntMultipleOf, schema, path, value);
234
210
  }
235
211
  }
236
212
  function* TBoolean(schema, references, path, value) {
237
- if (!ValueGuard.IsBoolean(value)) {
238
- return yield { type: ValueErrorType.Boolean, schema, path, value, message: `Expected boolean` };
239
- }
213
+ if (!(0, guard_1.IsBoolean)(value))
214
+ yield Create(ValueErrorType.Boolean, schema, path, value);
240
215
  }
241
216
  function* TConstructor(schema, references, path, value) {
242
217
  yield* Visit(schema.returns, references, path, value.prototype);
243
218
  }
244
219
  function* TDate(schema, references, path, value) {
245
- if (!ValueGuard.IsDate(value)) {
246
- return yield { type: ValueErrorType.Date, schema, path, value, message: `Expected Date object` };
247
- }
248
- if (!isFinite(value.getTime())) {
249
- return yield { type: ValueErrorType.Date, schema, path, value, message: `Invalid Date` };
220
+ if (!(0, guard_1.IsDate)(value))
221
+ return yield Create(ValueErrorType.Date, schema, path, value);
222
+ if (IsDefined(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
223
+ yield Create(ValueErrorType.DateExclusiveMaximumTimestamp, schema, path, value);
250
224
  }
251
225
  if (IsDefined(schema.exclusiveMinimumTimestamp) && !(value.getTime() > schema.exclusiveMinimumTimestamp)) {
252
- yield { type: ValueErrorType.DateExclusiveMinimumTimestamp, schema, path, value, message: `Expected Date timestamp to be greater than ${schema.exclusiveMinimum}` };
226
+ yield Create(ValueErrorType.DateExclusiveMinimumTimestamp, schema, path, value);
253
227
  }
254
- if (IsDefined(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
255
- yield { type: ValueErrorType.DateExclusiveMaximumTimestamp, schema, path, value, message: `Expected Date timestamp to be less than ${schema.exclusiveMaximum}` };
228
+ if (IsDefined(schema.maximumTimestamp) && !(value.getTime() <= schema.maximumTimestamp)) {
229
+ yield Create(ValueErrorType.DateMaximumTimestamp, schema, path, value);
256
230
  }
257
231
  if (IsDefined(schema.minimumTimestamp) && !(value.getTime() >= schema.minimumTimestamp)) {
258
- yield { type: ValueErrorType.DateMinimumTimestamp, schema, path, value, message: `Expected Date timestamp to be greater or equal to ${schema.minimum}` };
232
+ yield Create(ValueErrorType.DateMinimumTimestamp, schema, path, value);
259
233
  }
260
- if (IsDefined(schema.maximumTimestamp) && !(value.getTime() <= schema.maximumTimestamp)) {
261
- yield { type: ValueErrorType.DateMaximumTimestamp, schema, path, value, message: `Expected Date timestamp to be less or equal to ${schema.maximum}` };
234
+ if (IsDefined(schema.multipleOfTimestamp) && !(value.getTime() % schema.multipleOfTimestamp === 0)) {
235
+ yield Create(ValueErrorType.DateMultipleOfTimestamp, schema, path, value);
262
236
  }
263
237
  }
264
238
  function* TFunction(schema, references, path, value) {
265
- if (!ValueGuard.IsFunction(value)) {
266
- return yield { type: ValueErrorType.Function, schema, path, value, message: `Expected function` };
267
- }
239
+ if (!(0, guard_1.IsFunction)(value))
240
+ yield Create(ValueErrorType.Function, schema, path, value);
268
241
  }
269
242
  function* TInteger(schema, references, path, value) {
270
- if (!ValueGuard.IsInteger(value)) {
271
- return yield { type: ValueErrorType.Integer, schema, path, value, message: `Expected integer` };
272
- }
273
- if (IsDefined(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
274
- yield { type: ValueErrorType.IntegerMultipleOf, schema, path, value, message: `Expected integer to be a multiple of ${schema.multipleOf}` };
243
+ if (!(0, guard_1.IsInteger)(value))
244
+ return yield Create(ValueErrorType.Integer, schema, path, value);
245
+ if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
246
+ yield Create(ValueErrorType.IntegerExclusiveMaximum, schema, path, value);
275
247
  }
276
248
  if (IsDefined(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
277
- yield { type: ValueErrorType.IntegerExclusiveMinimum, schema, path, value, message: `Expected integer to be greater than ${schema.exclusiveMinimum}` };
249
+ yield Create(ValueErrorType.IntegerExclusiveMinimum, schema, path, value);
278
250
  }
279
- if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
280
- yield { type: ValueErrorType.IntegerExclusiveMaximum, schema, path, value, message: `Expected integer to be less than ${schema.exclusiveMaximum}` };
251
+ if (IsDefined(schema.maximum) && !(value <= schema.maximum)) {
252
+ yield Create(ValueErrorType.IntegerMaximum, schema, path, value);
281
253
  }
282
254
  if (IsDefined(schema.minimum) && !(value >= schema.minimum)) {
283
- yield { type: ValueErrorType.IntegerMinimum, schema, path, value, message: `Expected integer to be greater or equal to ${schema.minimum}` };
255
+ yield Create(ValueErrorType.IntegerMinimum, schema, path, value);
284
256
  }
285
- if (IsDefined(schema.maximum) && !(value <= schema.maximum)) {
286
- yield { type: ValueErrorType.IntegerMaximum, schema, path, value, message: `Expected integer to be less or equal to ${schema.maximum}` };
257
+ if (IsDefined(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
258
+ yield Create(ValueErrorType.IntegerMultipleOf, schema, path, value);
287
259
  }
288
260
  }
289
261
  function* TIntersect(schema, references, path, value) {
290
262
  for (const inner of schema.allOf) {
291
263
  const next = Visit(inner, references, path, value).next();
292
264
  if (!next.done) {
265
+ yield Create(ValueErrorType.Intersect, schema, path, value);
293
266
  yield next.value;
294
- yield { type: ValueErrorType.Intersect, schema, path, value, message: `Expected all sub schemas to be valid` };
295
- return;
296
267
  }
297
268
  }
298
269
  if (schema.unevaluatedProperties === false) {
299
270
  const keyCheck = new RegExp(Types.KeyResolver.ResolvePattern(schema));
300
271
  for (const valueKey of Object.getOwnPropertyNames(value)) {
301
272
  if (!keyCheck.test(valueKey)) {
302
- yield { type: ValueErrorType.IntersectUnevaluatedProperties, schema, path: `${path}/${valueKey}`, value, message: `Unexpected property` };
273
+ yield Create(ValueErrorType.IntersectUnevaluatedProperties, schema, `${path}/${valueKey}`, value);
303
274
  }
304
275
  }
305
276
  }
@@ -308,95 +279,71 @@ function* TIntersect(schema, references, path, value) {
308
279
  for (const valueKey of Object.getOwnPropertyNames(value)) {
309
280
  if (!keyCheck.test(valueKey)) {
310
281
  const next = Visit(schema.unevaluatedProperties, references, `${path}/${valueKey}`, value[valueKey]).next();
311
- if (!next.done) {
312
- yield next.value;
313
- yield { type: ValueErrorType.IntersectUnevaluatedProperties, schema, path: `${path}/${valueKey}`, value, message: `Invalid additional property` };
314
- return;
315
- }
282
+ if (!next.done)
283
+ yield next.value; // yield interior
316
284
  }
317
285
  }
318
286
  }
319
287
  }
320
288
  function* TIterator(schema, references, path, value) {
321
- if (!(IsObject(value) && Symbol.iterator in value)) {
322
- yield { type: ValueErrorType.Iterator, schema, path, value, message: `Expected value to be an iterator` };
323
- }
289
+ if (!(0, guard_1.IsIterator)(value))
290
+ yield Create(ValueErrorType.Iterator, schema, path, value);
324
291
  }
325
292
  function* TLiteral(schema, references, path, value) {
326
- if (!(value === schema.const)) {
327
- const error = typeof schema.const === 'string' ? `'${schema.const}'` : schema.const;
328
- return yield { type: ValueErrorType.Literal, schema, path, value, message: `Expected ${error}` };
329
- }
293
+ if (!(value === schema.const))
294
+ yield Create(ValueErrorType.Literal, schema, path, value);
330
295
  }
331
296
  function* TNever(schema, references, path, value) {
332
- yield { type: ValueErrorType.Never, schema, path, value, message: `Value cannot be validated` };
297
+ yield Create(ValueErrorType.Never, schema, path, value);
333
298
  }
334
299
  function* TNot(schema, references, path, value) {
335
- if (Visit(schema.not, references, path, value).next().done === true) {
336
- yield { type: ValueErrorType.Not, schema, path, value, message: `Value should not validate` };
337
- }
300
+ if (Visit(schema.not, references, path, value).next().done === true)
301
+ yield Create(ValueErrorType.Not, schema, path, value);
338
302
  }
339
303
  function* TNull(schema, references, path, value) {
340
- if (!ValueGuard.IsNull(value)) {
341
- return yield { type: ValueErrorType.Null, schema, path, value, message: `Expected null` };
342
- }
304
+ if (!(0, guard_1.IsNull)(value))
305
+ yield Create(ValueErrorType.Null, schema, path, value);
343
306
  }
344
307
  function* TNumber(schema, references, path, value) {
345
- if (!IsNumber(value)) {
346
- return yield { type: ValueErrorType.Number, schema, path, value, message: `Expected number` };
347
- }
348
- if (IsDefined(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
349
- yield { type: ValueErrorType.NumberMultipleOf, schema, path, value, message: `Expected number to be a multiple of ${schema.multipleOf}` };
308
+ if (!system_1.TypeSystemPolicy.IsNumberLike(value))
309
+ return yield Create(ValueErrorType.Number, schema, path, value);
310
+ if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
311
+ yield Create(ValueErrorType.NumberExclusiveMaximum, schema, path, value);
350
312
  }
351
313
  if (IsDefined(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
352
- yield { type: ValueErrorType.NumberExclusiveMinimum, schema, path, value, message: `Expected number to be greater than ${schema.exclusiveMinimum}` };
314
+ yield Create(ValueErrorType.NumberExclusiveMinimum, schema, path, value);
353
315
  }
354
- if (IsDefined(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
355
- yield { type: ValueErrorType.NumberExclusiveMaximum, schema, path, value, message: `Expected number to be less than ${schema.exclusiveMaximum}` };
316
+ if (IsDefined(schema.maximum) && !(value <= schema.maximum)) {
317
+ yield Create(ValueErrorType.NumberMaximum, schema, path, value);
356
318
  }
357
319
  if (IsDefined(schema.minimum) && !(value >= schema.minimum)) {
358
- yield { type: ValueErrorType.NumberMinimum, schema, path, value, message: `Expected number to be greater or equal to ${schema.minimum}` };
320
+ yield Create(ValueErrorType.NumberMinimum, schema, path, value);
359
321
  }
360
- if (IsDefined(schema.maximum) && !(value <= schema.maximum)) {
361
- yield { type: ValueErrorType.NumberMaximum, schema, path, value, message: `Expected number to be less or equal to ${schema.maximum}` };
322
+ if (IsDefined(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
323
+ yield Create(ValueErrorType.NumberMultipleOf, schema, path, value);
362
324
  }
363
325
  }
364
326
  function* TObject(schema, references, path, value) {
365
- if (!IsObject(value)) {
366
- return yield { type: ValueErrorType.Object, schema, path, value, message: `Expected object` };
367
- }
327
+ if (!system_1.TypeSystemPolicy.IsObjectLike(value))
328
+ return yield Create(ValueErrorType.Object, schema, path, value);
368
329
  if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
369
- yield { type: ValueErrorType.ObjectMinProperties, schema, path, value, message: `Expected object to have at least ${schema.minProperties} properties` };
330
+ yield Create(ValueErrorType.ObjectMinProperties, schema, path, value);
370
331
  }
371
332
  if (IsDefined(schema.maxProperties) && !(Object.getOwnPropertyNames(value).length <= schema.maxProperties)) {
372
- yield { type: ValueErrorType.ObjectMaxProperties, schema, path, value, message: `Expected object to have no more than ${schema.maxProperties} properties` };
333
+ yield Create(ValueErrorType.ObjectMaxProperties, schema, path, value);
373
334
  }
374
335
  const requiredKeys = Array.isArray(schema.required) ? schema.required : [];
375
336
  const knownKeys = Object.getOwnPropertyNames(schema.properties);
376
337
  const unknownKeys = Object.getOwnPropertyNames(value);
377
- for (const knownKey of knownKeys) {
378
- const property = schema.properties[knownKey];
379
- if (schema.required && schema.required.includes(knownKey)) {
380
- yield* Visit(property, references, `${path}/${knownKey}`, value[knownKey]);
381
- if (Types.ExtendsUndefined.Check(schema) && !(knownKey in value)) {
382
- yield { type: ValueErrorType.ObjectRequiredProperties, schema: property, path: `${path}/${knownKey}`, value: undefined, message: `Expected required property` };
383
- }
384
- }
385
- else {
386
- if (IsExactOptionalProperty(value, knownKey)) {
387
- yield* Visit(property, references, `${path}/${knownKey}`, value[knownKey]);
388
- }
389
- }
390
- }
391
338
  for (const requiredKey of requiredKeys) {
392
339
  if (unknownKeys.includes(requiredKey))
393
340
  continue;
394
- yield { type: ValueErrorType.ObjectRequiredProperties, schema: schema.properties[requiredKey], path: `${path}/${requiredKey}`, value: undefined, message: `Expected required property` };
341
+ yield Create(ValueErrorType.ObjectRequiredProperty, schema.properties[requiredKey], `${path}/${requiredKey}`, undefined);
395
342
  }
396
343
  if (schema.additionalProperties === false) {
397
344
  for (const valueKey of unknownKeys) {
398
345
  if (!knownKeys.includes(valueKey)) {
399
- yield { type: ValueErrorType.ObjectAdditionalProperties, schema, path: `${path}/${valueKey}`, value: value[valueKey], message: `Unexpected property` };
346
+ yield Create(ValueErrorType.ObjectAdditionalProperties, schema, `${path}/${valueKey}`, value[valueKey]);
400
347
  }
401
348
  }
402
349
  }
@@ -407,104 +354,107 @@ function* TObject(schema, references, path, value) {
407
354
  yield* Visit(schema.additionalProperties, references, `${path}/${valueKey}`, value[valueKey]);
408
355
  }
409
356
  }
357
+ for (const knownKey of knownKeys) {
358
+ const property = schema.properties[knownKey];
359
+ if (schema.required && schema.required.includes(knownKey)) {
360
+ yield* Visit(property, references, `${path}/${knownKey}`, value[knownKey]);
361
+ if (Types.ExtendsUndefined.Check(schema) && !(knownKey in value)) {
362
+ yield Create(ValueErrorType.ObjectRequiredProperty, property, `${path}/${knownKey}`, undefined);
363
+ }
364
+ }
365
+ else {
366
+ if (system_1.TypeSystemPolicy.IsExactOptionalProperty(value, knownKey)) {
367
+ yield* Visit(property, references, `${path}/${knownKey}`, value[knownKey]);
368
+ }
369
+ }
370
+ }
410
371
  }
411
372
  function* TPromise(schema, references, path, value) {
412
- if (!ValueGuard.IsPromise(value)) {
413
- yield { type: ValueErrorType.Promise, schema, path, value, message: `Expected Promise` };
414
- }
373
+ if (!(0, guard_1.IsPromise)(value))
374
+ yield Create(ValueErrorType.Promise, schema, path, value);
415
375
  }
416
376
  function* TRecord(schema, references, path, value) {
417
- if (!IsRecordObject(value)) {
418
- return yield { type: ValueErrorType.Object, schema, path, value, message: `Expected record object` };
419
- }
377
+ if (!system_1.TypeSystemPolicy.IsRecordLike(value))
378
+ return yield Create(ValueErrorType.Object, schema, path, value);
420
379
  if (IsDefined(schema.minProperties) && !(Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
421
- yield { type: ValueErrorType.ObjectMinProperties, schema, path, value, message: `Expected object to have at least ${schema.minProperties} properties` };
380
+ yield Create(ValueErrorType.ObjectMinProperties, schema, path, value);
422
381
  }
423
382
  if (IsDefined(schema.maxProperties) && !(Object.getOwnPropertyNames(value).length <= schema.maxProperties)) {
424
- yield { type: ValueErrorType.ObjectMaxProperties, schema, path, value, message: `Expected object to have no more than ${schema.maxProperties} properties` };
383
+ yield Create(ValueErrorType.ObjectMaxProperties, schema, path, value);
425
384
  }
426
385
  const [patternKey, patternSchema] = Object.entries(schema.patternProperties)[0];
427
386
  const regex = new RegExp(patternKey);
428
387
  for (const [propertyKey, propertyValue] of Object.entries(value)) {
429
- if (regex.test(propertyKey)) {
388
+ if (regex.test(propertyKey))
430
389
  yield* Visit(patternSchema, references, `${path}/${propertyKey}`, propertyValue);
431
- continue;
432
- }
433
- if (typeof schema.additionalProperties === 'object') {
434
- yield* Visit(schema.additionalProperties, references, `${path}/${propertyKey}`, propertyValue);
390
+ }
391
+ if (typeof schema.additionalProperties === 'object') {
392
+ for (const [propertyKey, propertyValue] of Object.entries(value)) {
393
+ if (!regex.test(propertyKey))
394
+ yield* Visit(schema.additionalProperties, references, `${path}/${propertyKey}`, propertyValue);
435
395
  }
436
- if (schema.additionalProperties === false) {
437
- const propertyPath = `${path}/${propertyKey}`;
438
- const message = `Unexpected property '${propertyPath}'`;
439
- return yield { type: ValueErrorType.ObjectAdditionalProperties, schema, path: propertyPath, value: propertyValue, message };
396
+ }
397
+ if (schema.additionalProperties === false) {
398
+ for (const [propertyKey, propertyValue] of Object.entries(value)) {
399
+ if (regex.test(propertyKey))
400
+ continue;
401
+ return yield Create(ValueErrorType.ObjectAdditionalProperties, schema, `${path}/${propertyKey}`, propertyValue);
440
402
  }
441
403
  }
442
404
  }
443
405
  function* TRef(schema, references, path, value) {
444
- const index = references.findIndex((foreign) => foreign.$id === schema.$ref);
445
- if (index === -1)
446
- throw new ValueErrorsDereferenceError(schema);
447
- const target = references[index];
448
- yield* Visit(target, references, path, value);
406
+ yield* Visit((0, deref_1.Deref)(schema, references), references, path, value);
449
407
  }
450
408
  function* TString(schema, references, path, value) {
451
- if (!ValueGuard.IsString(value)) {
452
- return yield { type: ValueErrorType.String, schema, path, value, message: 'Expected string' };
453
- }
409
+ if (!(0, guard_1.IsString)(value))
410
+ return yield Create(ValueErrorType.String, schema, path, value);
454
411
  if (IsDefined(schema.minLength) && !(value.length >= schema.minLength)) {
455
- yield { type: ValueErrorType.StringMinLength, schema, path, value, message: `Expected string length greater or equal to ${schema.minLength}` };
412
+ yield Create(ValueErrorType.StringMinLength, schema, path, value);
456
413
  }
457
414
  if (IsDefined(schema.maxLength) && !(value.length <= schema.maxLength)) {
458
- yield { type: ValueErrorType.StringMaxLength, schema, path, value, message: `Expected string length less or equal to ${schema.maxLength}` };
415
+ yield Create(ValueErrorType.StringMaxLength, schema, path, value);
459
416
  }
460
- if (ValueGuard.IsString(schema.pattern)) {
417
+ if ((0, guard_1.IsString)(schema.pattern)) {
461
418
  const regex = new RegExp(schema.pattern);
462
419
  if (!regex.test(value)) {
463
- yield { type: ValueErrorType.StringPattern, schema, path, value, message: `Expected string to match pattern ${schema.pattern}` };
420
+ yield Create(ValueErrorType.StringPattern, schema, path, value);
464
421
  }
465
422
  }
466
- if (ValueGuard.IsString(schema.format)) {
423
+ if ((0, guard_1.IsString)(schema.format)) {
467
424
  if (!Types.FormatRegistry.Has(schema.format)) {
468
- yield { type: ValueErrorType.StringFormatUnknown, schema, path, value, message: `Unknown string format '${schema.format}'` };
425
+ yield Create(ValueErrorType.StringFormatUnknown, schema, path, value);
469
426
  }
470
427
  else {
471
428
  const format = Types.FormatRegistry.Get(schema.format);
472
429
  if (!format(value)) {
473
- yield { type: ValueErrorType.StringFormat, schema, path, value, message: `Expected string to match format '${schema.format}'` };
430
+ yield Create(ValueErrorType.StringFormat, schema, path, value);
474
431
  }
475
432
  }
476
433
  }
477
434
  }
478
435
  function* TSymbol(schema, references, path, value) {
479
- if (!ValueGuard.IsSymbol(value)) {
480
- return yield { type: ValueErrorType.Symbol, schema, path, value, message: 'Expected symbol' };
481
- }
436
+ if (!(0, guard_1.IsSymbol)(value))
437
+ yield Create(ValueErrorType.Symbol, schema, path, value);
482
438
  }
483
439
  function* TTemplateLiteral(schema, references, path, value) {
484
- if (!ValueGuard.IsString(value)) {
485
- return yield { type: ValueErrorType.String, schema, path, value, message: 'Expected string' };
486
- }
440
+ if (!(0, guard_1.IsString)(value))
441
+ return yield Create(ValueErrorType.String, schema, path, value);
487
442
  const regex = new RegExp(schema.pattern);
488
443
  if (!regex.test(value)) {
489
- yield { type: ValueErrorType.StringPattern, schema, path, value, message: `Expected string to match pattern ${schema.pattern}` };
444
+ yield Create(ValueErrorType.StringPattern, schema, path, value);
490
445
  }
491
446
  }
492
447
  function* TThis(schema, references, path, value) {
493
- const index = references.findIndex((foreign) => foreign.$id === schema.$ref);
494
- if (index === -1)
495
- throw new ValueErrorsDereferenceError(schema);
496
- const target = references[index];
497
- yield* Visit(target, references, path, value);
448
+ yield* Visit((0, deref_1.Deref)(schema, references), references, path, value);
498
449
  }
499
450
  function* TTuple(schema, references, path, value) {
500
- if (!ValueGuard.IsArray(value)) {
501
- return yield { type: ValueErrorType.Array, schema, path, value, message: 'Expected Array' };
502
- }
451
+ if (!(0, guard_1.IsArray)(value))
452
+ return yield Create(ValueErrorType.Tuple, schema, path, value);
503
453
  if (schema.items === undefined && !(value.length === 0)) {
504
- return yield { type: ValueErrorType.TupleZeroLength, schema, path, value, message: 'Expected tuple to have 0 elements' };
454
+ return yield Create(ValueErrorType.TupleLength, schema, path, value);
505
455
  }
506
456
  if (!(value.length === schema.maxItems)) {
507
- yield { type: ValueErrorType.TupleLength, schema, path, value, message: `Expected tuple to have ${schema.maxItems} elements` };
457
+ return yield Create(ValueErrorType.TupleLength, schema, path, value);
508
458
  }
509
459
  if (!schema.items) {
510
460
  return;
@@ -514,47 +464,40 @@ function* TTuple(schema, references, path, value) {
514
464
  }
515
465
  }
516
466
  function* TUndefined(schema, references, path, value) {
517
- if (!(value === undefined)) {
518
- yield { type: ValueErrorType.Undefined, schema, path, value, message: `Expected undefined` };
519
- }
467
+ if (!(0, guard_1.IsUndefined)(value))
468
+ yield Create(ValueErrorType.Undefined, schema, path, value);
520
469
  }
521
470
  function* TUnion(schema, references, path, value) {
522
- const errors = [];
523
- for (const inner of schema.anyOf) {
524
- const variantErrors = [...Visit(inner, references, path, value)];
525
- if (variantErrors.length === 0)
526
- return;
527
- errors.push(...variantErrors);
528
- }
529
- if (errors.length > 0) {
530
- yield { type: ValueErrorType.Union, schema, path, value, message: 'Expected value of union' };
471
+ let count = 0;
472
+ for (const subschema of schema.anyOf) {
473
+ const errors = [...Visit(subschema, references, path, value)];
474
+ if (errors.length === 0)
475
+ return; // matched
476
+ count += errors.length;
531
477
  }
532
- for (const error of errors) {
533
- yield error;
478
+ if (count > 0) {
479
+ yield Create(ValueErrorType.Union, schema, path, value);
534
480
  }
535
481
  }
536
482
  function* TUint8Array(schema, references, path, value) {
537
- if (!ValueGuard.IsUint8Array(value)) {
538
- return yield { type: ValueErrorType.Uint8Array, schema, path, value, message: `Expected Uint8Array` };
539
- }
483
+ if (!(0, guard_1.IsUint8Array)(value))
484
+ return yield Create(ValueErrorType.Uint8Array, schema, path, value);
540
485
  if (IsDefined(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
541
- yield { type: ValueErrorType.Uint8ArrayMaxByteLength, schema, path, value, message: `Expected Uint8Array to have a byte length less or equal to ${schema.maxByteLength}` };
486
+ yield Create(ValueErrorType.Uint8ArrayMaxByteLength, schema, path, value);
542
487
  }
543
488
  if (IsDefined(schema.minByteLength) && !(value.length >= schema.minByteLength)) {
544
- yield { type: ValueErrorType.Uint8ArrayMinByteLength, schema, path, value, message: `Expected Uint8Array to have a byte length greater or equal to ${schema.maxByteLength}` };
489
+ yield Create(ValueErrorType.Uint8ArrayMinByteLength, schema, path, value);
545
490
  }
546
491
  }
547
492
  function* TUnknown(schema, references, path, value) { }
548
493
  function* TVoid(schema, references, path, value) {
549
- if (!IsVoid(value)) {
550
- return yield { type: ValueErrorType.Void, schema, path, value, message: `Expected void` };
551
- }
494
+ if (!system_1.TypeSystemPolicy.IsVoidLike(value))
495
+ yield Create(ValueErrorType.Void, schema, path, value);
552
496
  }
553
497
  function* TKind(schema, references, path, value) {
554
498
  const check = Types.TypeRegistry.Get(schema[Types.Kind]);
555
- if (!check(schema, value)) {
556
- return yield { type: ValueErrorType.Kind, schema, path, value, message: `Expected kind ${schema[Types.Kind]}` };
557
- }
499
+ if (!check(schema, value))
500
+ yield Create(ValueErrorType.Kind, schema, path, value);
558
501
  }
559
502
  function* Visit(schema, references, path, value) {
560
503
  const references_ = IsDefined(schema.$id) ? [...references, schema] : references;