@sinclair/typebox 0.26.0-dev.2 → 0.26.0-dev.4
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/compiler/compiler.d.ts +33 -33
- package/compiler/compiler.js +536 -536
- package/compiler/index.d.ts +2 -2
- package/compiler/index.js +47 -47
- package/errors/errors.d.ts +84 -84
- package/errors/errors.js +570 -570
- package/errors/index.d.ts +1 -1
- package/errors/index.js +44 -44
- package/package.json +2 -2
- package/readme.md +1 -7
- package/system/index.d.ts +1 -1
- package/system/index.js +44 -44
- package/system/system.d.ts +20 -20
- package/system/system.js +69 -69
- package/typebox.d.ts +656 -649
- package/typebox.js +1889 -1883
- package/value/cast.d.ts +26 -26
- package/value/cast.js +348 -348
- package/value/check.d.ts +8 -8
- package/value/check.js +450 -450
- package/value/clone.d.ts +3 -3
- package/value/clone.js +71 -71
- package/value/convert.d.ts +13 -13
- package/value/convert.js +345 -345
- package/value/create.d.ts +18 -18
- package/value/create.js +430 -430
- package/value/delta.d.ts +43 -43
- package/value/delta.js +204 -204
- package/value/equal.d.ts +3 -3
- package/value/equal.js +80 -80
- package/value/hash.d.ts +8 -8
- package/value/hash.js +208 -208
- package/value/index.d.ts +5 -5
- package/value/index.js +56 -56
- package/value/is.d.ts +11 -11
- package/value/is.js +53 -53
- package/value/pointer.d.ts +24 -24
- package/value/pointer.js +142 -142
- package/value/value.d.ts +26 -26
- package/value/value.js +93 -93
package/value/check.js
CHANGED
|
@@ -1,450 +1,450 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*--------------------------------------------------------------------------
|
|
3
|
-
|
|
4
|
-
@sinclair/typebox/value
|
|
5
|
-
|
|
6
|
-
The MIT License (MIT)
|
|
7
|
-
|
|
8
|
-
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
-
|
|
10
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
-
in the Software without restriction, including without limitation the rights
|
|
13
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
-
furnished to do so, subject to the following conditions:
|
|
16
|
-
|
|
17
|
-
The above copyright notice and this permission notice shall be included in
|
|
18
|
-
all copies or substantial portions of the Software.
|
|
19
|
-
|
|
20
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
-
THE SOFTWARE.
|
|
27
|
-
|
|
28
|
-
---------------------------------------------------------------------------*/
|
|
29
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
-
exports.ValueCheck = exports.ValueCheckUnknownTypeError = void 0;
|
|
31
|
-
const Types = require("../typebox");
|
|
32
|
-
const index_1 = require("../system/index");
|
|
33
|
-
const hash_1 = require("./hash");
|
|
34
|
-
class ValueCheckUnknownTypeError extends Error {
|
|
35
|
-
constructor(schema) {
|
|
36
|
-
super(`ValueCheck: ${schema[Types.Kind] ? `Unknown type '${schema[Types.Kind]}'` : 'Unknown type'}`);
|
|
37
|
-
this.schema = schema;
|
|
38
|
-
}
|
|
39
|
-
}
|
|
40
|
-
exports.ValueCheckUnknownTypeError = ValueCheckUnknownTypeError;
|
|
41
|
-
var ValueCheck;
|
|
42
|
-
(function (ValueCheck) {
|
|
43
|
-
// --------------------------------------------------------
|
|
44
|
-
// Guards
|
|
45
|
-
// --------------------------------------------------------
|
|
46
|
-
function IsBigInt(value) {
|
|
47
|
-
return typeof value === 'bigint';
|
|
48
|
-
}
|
|
49
|
-
function IsNumber(value) {
|
|
50
|
-
return typeof value === 'number' && globalThis.Number.isFinite(value);
|
|
51
|
-
}
|
|
52
|
-
// --------------------------------------------------------
|
|
53
|
-
// Guards
|
|
54
|
-
// --------------------------------------------------------
|
|
55
|
-
function Any(schema, value) {
|
|
56
|
-
return true;
|
|
57
|
-
}
|
|
58
|
-
function Array(schema, value) {
|
|
59
|
-
if (!globalThis.Array.isArray(value)) {
|
|
60
|
-
return false;
|
|
61
|
-
}
|
|
62
|
-
if (IsNumber(schema.minItems) && !(value.length >= schema.minItems)) {
|
|
63
|
-
return false;
|
|
64
|
-
}
|
|
65
|
-
if (IsNumber(schema.maxItems) && !(value.length <= schema.maxItems)) {
|
|
66
|
-
return false;
|
|
67
|
-
}
|
|
68
|
-
// prettier-ignore
|
|
69
|
-
if (schema.uniqueItems === true && !((function () { const set = new Set(); for (const element of value) {
|
|
70
|
-
const hashed = hash_1.ValueHash.Create(element);
|
|
71
|
-
if (set.has(hashed)) {
|
|
72
|
-
return false;
|
|
73
|
-
}
|
|
74
|
-
else {
|
|
75
|
-
set.add(hashed);
|
|
76
|
-
}
|
|
77
|
-
} return true; })())) {
|
|
78
|
-
return false;
|
|
79
|
-
}
|
|
80
|
-
return value.every((value) => Visit(schema.items, value));
|
|
81
|
-
}
|
|
82
|
-
function BigInt(schema, value) {
|
|
83
|
-
if (typeof value !== 'bigint') {
|
|
84
|
-
return false;
|
|
85
|
-
}
|
|
86
|
-
if (IsBigInt(schema.multipleOf) && !(value % schema.multipleOf === globalThis.BigInt(0))) {
|
|
87
|
-
return false;
|
|
88
|
-
}
|
|
89
|
-
if (IsBigInt(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
90
|
-
return false;
|
|
91
|
-
}
|
|
92
|
-
if (IsBigInt(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
93
|
-
return false;
|
|
94
|
-
}
|
|
95
|
-
if (IsBigInt(schema.minimum) && !(value >= schema.minimum)) {
|
|
96
|
-
return false;
|
|
97
|
-
}
|
|
98
|
-
if (IsBigInt(schema.maximum) && !(value <= schema.maximum)) {
|
|
99
|
-
return false;
|
|
100
|
-
}
|
|
101
|
-
return true;
|
|
102
|
-
}
|
|
103
|
-
function Boolean(schema, value) {
|
|
104
|
-
return typeof value === 'boolean';
|
|
105
|
-
}
|
|
106
|
-
function Constructor(schema, value) {
|
|
107
|
-
return Visit(schema.returns, value.prototype);
|
|
108
|
-
}
|
|
109
|
-
function Date(schema, value) {
|
|
110
|
-
if (!(value instanceof globalThis.Date)) {
|
|
111
|
-
return false;
|
|
112
|
-
}
|
|
113
|
-
if (!globalThis.Number.isFinite(value.getTime())) {
|
|
114
|
-
return false;
|
|
115
|
-
}
|
|
116
|
-
if (IsNumber(schema.exclusiveMinimumTimestamp) && !(value.getTime() > schema.exclusiveMinimumTimestamp)) {
|
|
117
|
-
return false;
|
|
118
|
-
}
|
|
119
|
-
if (IsNumber(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
120
|
-
return false;
|
|
121
|
-
}
|
|
122
|
-
if (IsNumber(schema.minimumTimestamp) && !(value.getTime() >= schema.minimumTimestamp)) {
|
|
123
|
-
return false;
|
|
124
|
-
}
|
|
125
|
-
if (IsNumber(schema.maximumTimestamp) && !(value.getTime() <= schema.maximumTimestamp)) {
|
|
126
|
-
return false;
|
|
127
|
-
}
|
|
128
|
-
return true;
|
|
129
|
-
}
|
|
130
|
-
function Function(schema, value) {
|
|
131
|
-
return typeof value === 'function';
|
|
132
|
-
}
|
|
133
|
-
function Integer(schema, value) {
|
|
134
|
-
if (!(typeof value === 'number' && globalThis.Number.isInteger(value))) {
|
|
135
|
-
return false;
|
|
136
|
-
}
|
|
137
|
-
if (IsNumber(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
138
|
-
return false;
|
|
139
|
-
}
|
|
140
|
-
if (IsNumber(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
141
|
-
return false;
|
|
142
|
-
}
|
|
143
|
-
if (IsNumber(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
144
|
-
return false;
|
|
145
|
-
}
|
|
146
|
-
if (IsNumber(schema.minimum) && !(value >= schema.minimum)) {
|
|
147
|
-
return false;
|
|
148
|
-
}
|
|
149
|
-
if (IsNumber(schema.maximum) && !(value <= schema.maximum)) {
|
|
150
|
-
return false;
|
|
151
|
-
}
|
|
152
|
-
return true;
|
|
153
|
-
}
|
|
154
|
-
function Intersect(schema, value) {
|
|
155
|
-
if (!schema.allOf.every((schema) => Visit(schema, value))) {
|
|
156
|
-
return false;
|
|
157
|
-
}
|
|
158
|
-
else if (schema.unevaluatedProperties === false) {
|
|
159
|
-
const schemaKeys = Types.KeyResolver.Resolve(schema);
|
|
160
|
-
const valueKeys = globalThis.Object.getOwnPropertyNames(value);
|
|
161
|
-
return valueKeys.every((key) => schemaKeys.includes(key));
|
|
162
|
-
}
|
|
163
|
-
else if (Types.TypeGuard.TSchema(schema.unevaluatedProperties)) {
|
|
164
|
-
const schemaKeys = Types.KeyResolver.Resolve(schema);
|
|
165
|
-
const valueKeys = globalThis.Object.getOwnPropertyNames(value);
|
|
166
|
-
return valueKeys.every((key) => schemaKeys.includes(key) || Visit(schema.unevaluatedProperties, value[key]));
|
|
167
|
-
}
|
|
168
|
-
else {
|
|
169
|
-
return true;
|
|
170
|
-
}
|
|
171
|
-
}
|
|
172
|
-
function Literal(schema, value) {
|
|
173
|
-
return value === schema.const;
|
|
174
|
-
}
|
|
175
|
-
function Never(schema, value) {
|
|
176
|
-
return false;
|
|
177
|
-
}
|
|
178
|
-
function Not(schema, value) {
|
|
179
|
-
return !Visit(schema.allOf[0].not, value) && Visit(schema.allOf[1], value);
|
|
180
|
-
}
|
|
181
|
-
function Null(schema, value) {
|
|
182
|
-
return value === null;
|
|
183
|
-
}
|
|
184
|
-
function Number(schema, value) {
|
|
185
|
-
if (index_1.TypeSystem.AllowNaN) {
|
|
186
|
-
if (!(typeof value === 'number')) {
|
|
187
|
-
return false;
|
|
188
|
-
}
|
|
189
|
-
}
|
|
190
|
-
else {
|
|
191
|
-
if (!(typeof value === 'number' && globalThis.Number.isFinite(value))) {
|
|
192
|
-
return false;
|
|
193
|
-
}
|
|
194
|
-
}
|
|
195
|
-
if (IsNumber(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
196
|
-
return false;
|
|
197
|
-
}
|
|
198
|
-
if (IsNumber(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
199
|
-
return false;
|
|
200
|
-
}
|
|
201
|
-
if (IsNumber(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
202
|
-
return false;
|
|
203
|
-
}
|
|
204
|
-
if (IsNumber(schema.minimum) && !(value >= schema.minimum)) {
|
|
205
|
-
return false;
|
|
206
|
-
}
|
|
207
|
-
if (IsNumber(schema.maximum) && !(value <= schema.maximum)) {
|
|
208
|
-
return false;
|
|
209
|
-
}
|
|
210
|
-
return true;
|
|
211
|
-
}
|
|
212
|
-
function Object(schema, value) {
|
|
213
|
-
if (index_1.TypeSystem.AllowArrayObjects) {
|
|
214
|
-
if (!(typeof value === 'object' && value !== null)) {
|
|
215
|
-
return false;
|
|
216
|
-
}
|
|
217
|
-
}
|
|
218
|
-
else {
|
|
219
|
-
if (!(typeof value === 'object' && value !== null && !globalThis.Array.isArray(value))) {
|
|
220
|
-
return false;
|
|
221
|
-
}
|
|
222
|
-
}
|
|
223
|
-
if (IsNumber(schema.minProperties) && !(globalThis.Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
|
|
224
|
-
return false;
|
|
225
|
-
}
|
|
226
|
-
if (IsNumber(schema.maxProperties) && !(globalThis.Object.getOwnPropertyNames(value).length <= schema.maxProperties)) {
|
|
227
|
-
return false;
|
|
228
|
-
}
|
|
229
|
-
const schemaKeys = globalThis.Object.getOwnPropertyNames(schema.properties);
|
|
230
|
-
for (const schemaKey of schemaKeys) {
|
|
231
|
-
const property = schema.properties[schemaKey];
|
|
232
|
-
if (schema.required && schema.required.includes(schemaKey)) {
|
|
233
|
-
if (!Visit(property, value[schemaKey])) {
|
|
234
|
-
return false;
|
|
235
|
-
}
|
|
236
|
-
if (Types.ExtendsUndefined.Check(property)) {
|
|
237
|
-
return schemaKey in value;
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
else {
|
|
241
|
-
if (schemaKey in value && !Visit(property, value[schemaKey])) {
|
|
242
|
-
return false;
|
|
243
|
-
}
|
|
244
|
-
}
|
|
245
|
-
}
|
|
246
|
-
if (schema.additionalProperties === false) {
|
|
247
|
-
const valueKeys = globalThis.Object.getOwnPropertyNames(value);
|
|
248
|
-
// optimization: value is valid if schemaKey length matches the valueKey length
|
|
249
|
-
if (schema.required && schema.required.length === schemaKeys.length && valueKeys.length === schemaKeys.length) {
|
|
250
|
-
return true;
|
|
251
|
-
}
|
|
252
|
-
else {
|
|
253
|
-
return valueKeys.every((valueKey) => schemaKeys.includes(valueKey));
|
|
254
|
-
}
|
|
255
|
-
}
|
|
256
|
-
else if (typeof schema.additionalProperties === 'object') {
|
|
257
|
-
const valueKeys = globalThis.Object.getOwnPropertyNames(value);
|
|
258
|
-
return valueKeys.every((key) => schemaKeys.includes(key) || Visit(schema.additionalProperties, value[key]));
|
|
259
|
-
}
|
|
260
|
-
else {
|
|
261
|
-
return true;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
function Promise(schema, value) {
|
|
265
|
-
return typeof value === 'object' && typeof value.then === 'function';
|
|
266
|
-
}
|
|
267
|
-
function Record(schema, value) {
|
|
268
|
-
if (index_1.TypeSystem.AllowArrayObjects) {
|
|
269
|
-
if (!(typeof value === 'object' && value !== null && !(value instanceof globalThis.Date))) {
|
|
270
|
-
return false;
|
|
271
|
-
}
|
|
272
|
-
}
|
|
273
|
-
else {
|
|
274
|
-
if (!(typeof value === 'object' && value !== null && !(value instanceof globalThis.Date) && !globalThis.Array.isArray(value))) {
|
|
275
|
-
return false;
|
|
276
|
-
}
|
|
277
|
-
}
|
|
278
|
-
const [keyPattern, valueSchema] = globalThis.Object.entries(schema.patternProperties)[0];
|
|
279
|
-
const regex = new RegExp(keyPattern);
|
|
280
|
-
if (!globalThis.Object.getOwnPropertyNames(value).every((key) => regex.test(key))) {
|
|
281
|
-
return false;
|
|
282
|
-
}
|
|
283
|
-
for (const propValue of globalThis.Object.values(value)) {
|
|
284
|
-
if (!Visit(valueSchema, propValue))
|
|
285
|
-
return false;
|
|
286
|
-
}
|
|
287
|
-
return true;
|
|
288
|
-
}
|
|
289
|
-
function Ref(schema, value) {
|
|
290
|
-
return Visit(Types.ReferenceRegistry.DerefOne(schema), value);
|
|
291
|
-
}
|
|
292
|
-
function Self(schema, value) {
|
|
293
|
-
return Visit(Types.ReferenceRegistry.DerefOne(schema), value);
|
|
294
|
-
}
|
|
295
|
-
function String(schema, value) {
|
|
296
|
-
if (!(typeof value === 'string')) {
|
|
297
|
-
return false;
|
|
298
|
-
}
|
|
299
|
-
if (IsNumber(schema.minLength)) {
|
|
300
|
-
if (!(value.length >= schema.minLength))
|
|
301
|
-
return false;
|
|
302
|
-
}
|
|
303
|
-
if (IsNumber(schema.maxLength)) {
|
|
304
|
-
if (!(value.length <= schema.maxLength))
|
|
305
|
-
return false;
|
|
306
|
-
}
|
|
307
|
-
if (schema.pattern !== undefined) {
|
|
308
|
-
const regex = new RegExp(schema.pattern);
|
|
309
|
-
if (!regex.test(value))
|
|
310
|
-
return false;
|
|
311
|
-
}
|
|
312
|
-
if (schema.format !== undefined) {
|
|
313
|
-
if (!Types.FormatRegistry.Has(schema.format))
|
|
314
|
-
return false;
|
|
315
|
-
const func = Types.FormatRegistry.Get(schema.format);
|
|
316
|
-
return func(value);
|
|
317
|
-
}
|
|
318
|
-
return true;
|
|
319
|
-
}
|
|
320
|
-
function Symbol(schema, value) {
|
|
321
|
-
if (!(typeof value === 'symbol')) {
|
|
322
|
-
return false;
|
|
323
|
-
}
|
|
324
|
-
return true;
|
|
325
|
-
}
|
|
326
|
-
function Tuple(schema, value) {
|
|
327
|
-
if (!globalThis.Array.isArray(value)) {
|
|
328
|
-
return false;
|
|
329
|
-
}
|
|
330
|
-
if (schema.items === undefined && !(value.length === 0)) {
|
|
331
|
-
return false;
|
|
332
|
-
}
|
|
333
|
-
if (!(value.length === schema.maxItems)) {
|
|
334
|
-
return false;
|
|
335
|
-
}
|
|
336
|
-
if (!schema.items) {
|
|
337
|
-
return true;
|
|
338
|
-
}
|
|
339
|
-
for (let i = 0; i < schema.items.length; i++) {
|
|
340
|
-
if (!Visit(schema.items[i], value[i]))
|
|
341
|
-
return false;
|
|
342
|
-
}
|
|
343
|
-
return true;
|
|
344
|
-
}
|
|
345
|
-
function Undefined(schema, value) {
|
|
346
|
-
return value === undefined;
|
|
347
|
-
}
|
|
348
|
-
function Union(schema, value) {
|
|
349
|
-
return schema.anyOf.some((inner) => Visit(inner, value));
|
|
350
|
-
}
|
|
351
|
-
function Uint8Array(schema, value) {
|
|
352
|
-
if (!(value instanceof globalThis.Uint8Array)) {
|
|
353
|
-
return false;
|
|
354
|
-
}
|
|
355
|
-
if (IsNumber(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
|
|
356
|
-
return false;
|
|
357
|
-
}
|
|
358
|
-
if (IsNumber(schema.minByteLength) && !(value.length >= schema.minByteLength)) {
|
|
359
|
-
return false;
|
|
360
|
-
}
|
|
361
|
-
return true;
|
|
362
|
-
}
|
|
363
|
-
function Unknown(schema, value) {
|
|
364
|
-
return true;
|
|
365
|
-
}
|
|
366
|
-
function Void(schema, value) {
|
|
367
|
-
if (index_1.TypeSystem.AllowVoidNull) {
|
|
368
|
-
return value === undefined || value === null;
|
|
369
|
-
}
|
|
370
|
-
else {
|
|
371
|
-
return value === undefined;
|
|
372
|
-
}
|
|
373
|
-
}
|
|
374
|
-
function UserDefined(schema, value) {
|
|
375
|
-
if (!Types.TypeRegistry.Has(schema[Types.Kind]))
|
|
376
|
-
return false;
|
|
377
|
-
const func = Types.TypeRegistry.Get(schema[Types.Kind]);
|
|
378
|
-
return func(schema, value);
|
|
379
|
-
}
|
|
380
|
-
function Visit(schema, value) {
|
|
381
|
-
const anySchema = schema;
|
|
382
|
-
switch (anySchema[Types.Kind]) {
|
|
383
|
-
case 'Any':
|
|
384
|
-
return Any(anySchema, value);
|
|
385
|
-
case 'Array':
|
|
386
|
-
return Array(anySchema, value);
|
|
387
|
-
case 'BigInt':
|
|
388
|
-
return BigInt(anySchema, value);
|
|
389
|
-
case 'Boolean':
|
|
390
|
-
return Boolean(anySchema, value);
|
|
391
|
-
case 'Constructor':
|
|
392
|
-
return Constructor(anySchema, value);
|
|
393
|
-
case 'Date':
|
|
394
|
-
return Date(anySchema, value);
|
|
395
|
-
case 'Function':
|
|
396
|
-
return Function(anySchema, value);
|
|
397
|
-
case 'Integer':
|
|
398
|
-
return Integer(anySchema, value);
|
|
399
|
-
case 'Intersect':
|
|
400
|
-
return Intersect(anySchema, value);
|
|
401
|
-
case 'Literal':
|
|
402
|
-
return Literal(anySchema, value);
|
|
403
|
-
case 'Never':
|
|
404
|
-
return Never(anySchema, value);
|
|
405
|
-
case 'Not':
|
|
406
|
-
return Not(anySchema, value);
|
|
407
|
-
case 'Null':
|
|
408
|
-
return Null(anySchema, value);
|
|
409
|
-
case 'Number':
|
|
410
|
-
return Number(anySchema, value);
|
|
411
|
-
case 'Object':
|
|
412
|
-
return Object(anySchema, value);
|
|
413
|
-
case 'Promise':
|
|
414
|
-
return Promise(anySchema, value);
|
|
415
|
-
case 'Record':
|
|
416
|
-
return Record(anySchema, value);
|
|
417
|
-
case 'Ref':
|
|
418
|
-
return Ref(anySchema, value);
|
|
419
|
-
case 'Self':
|
|
420
|
-
return Self(anySchema, value);
|
|
421
|
-
case 'String':
|
|
422
|
-
return String(anySchema, value);
|
|
423
|
-
case 'Symbol':
|
|
424
|
-
return Symbol(anySchema, value);
|
|
425
|
-
case 'Tuple':
|
|
426
|
-
return Tuple(anySchema, value);
|
|
427
|
-
case 'Undefined':
|
|
428
|
-
return Undefined(anySchema, value);
|
|
429
|
-
case 'Union':
|
|
430
|
-
return Union(anySchema, value);
|
|
431
|
-
case 'Uint8Array':
|
|
432
|
-
return Uint8Array(anySchema, value);
|
|
433
|
-
case 'Unknown':
|
|
434
|
-
return Unknown(anySchema, value);
|
|
435
|
-
case 'Void':
|
|
436
|
-
return Void(anySchema, value);
|
|
437
|
-
default:
|
|
438
|
-
if (!Types.TypeRegistry.Has(anySchema[Types.Kind]))
|
|
439
|
-
throw new ValueCheckUnknownTypeError(anySchema);
|
|
440
|
-
return UserDefined(anySchema, value);
|
|
441
|
-
}
|
|
442
|
-
}
|
|
443
|
-
// -------------------------------------------------------------------------
|
|
444
|
-
// Check
|
|
445
|
-
// -------------------------------------------------------------------------
|
|
446
|
-
function Check(schema, value) {
|
|
447
|
-
return Visit(schema, value);
|
|
448
|
-
}
|
|
449
|
-
ValueCheck.Check = Check;
|
|
450
|
-
})(ValueCheck = exports.ValueCheck || (exports.ValueCheck = {}));
|
|
1
|
+
"use strict";
|
|
2
|
+
/*--------------------------------------------------------------------------
|
|
3
|
+
|
|
4
|
+
@sinclair/typebox/value
|
|
5
|
+
|
|
6
|
+
The MIT License (MIT)
|
|
7
|
+
|
|
8
|
+
Copyright (c) 2017-2023 Haydn Paterson (sinclair) <haydn.developer@gmail.com>
|
|
9
|
+
|
|
10
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
11
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
12
|
+
in the Software without restriction, including without limitation the rights
|
|
13
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
14
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
15
|
+
furnished to do so, subject to the following conditions:
|
|
16
|
+
|
|
17
|
+
The above copyright notice and this permission notice shall be included in
|
|
18
|
+
all copies or substantial portions of the Software.
|
|
19
|
+
|
|
20
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
21
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
22
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
23
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
24
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
25
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
26
|
+
THE SOFTWARE.
|
|
27
|
+
|
|
28
|
+
---------------------------------------------------------------------------*/
|
|
29
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
30
|
+
exports.ValueCheck = exports.ValueCheckUnknownTypeError = void 0;
|
|
31
|
+
const Types = require("../typebox");
|
|
32
|
+
const index_1 = require("../system/index");
|
|
33
|
+
const hash_1 = require("./hash");
|
|
34
|
+
class ValueCheckUnknownTypeError extends Error {
|
|
35
|
+
constructor(schema) {
|
|
36
|
+
super(`ValueCheck: ${schema[Types.Kind] ? `Unknown type '${schema[Types.Kind]}'` : 'Unknown type'}`);
|
|
37
|
+
this.schema = schema;
|
|
38
|
+
}
|
|
39
|
+
}
|
|
40
|
+
exports.ValueCheckUnknownTypeError = ValueCheckUnknownTypeError;
|
|
41
|
+
var ValueCheck;
|
|
42
|
+
(function (ValueCheck) {
|
|
43
|
+
// --------------------------------------------------------
|
|
44
|
+
// Guards
|
|
45
|
+
// --------------------------------------------------------
|
|
46
|
+
function IsBigInt(value) {
|
|
47
|
+
return typeof value === 'bigint';
|
|
48
|
+
}
|
|
49
|
+
function IsNumber(value) {
|
|
50
|
+
return typeof value === 'number' && globalThis.Number.isFinite(value);
|
|
51
|
+
}
|
|
52
|
+
// --------------------------------------------------------
|
|
53
|
+
// Guards
|
|
54
|
+
// --------------------------------------------------------
|
|
55
|
+
function Any(schema, value) {
|
|
56
|
+
return true;
|
|
57
|
+
}
|
|
58
|
+
function Array(schema, value) {
|
|
59
|
+
if (!globalThis.Array.isArray(value)) {
|
|
60
|
+
return false;
|
|
61
|
+
}
|
|
62
|
+
if (IsNumber(schema.minItems) && !(value.length >= schema.minItems)) {
|
|
63
|
+
return false;
|
|
64
|
+
}
|
|
65
|
+
if (IsNumber(schema.maxItems) && !(value.length <= schema.maxItems)) {
|
|
66
|
+
return false;
|
|
67
|
+
}
|
|
68
|
+
// prettier-ignore
|
|
69
|
+
if (schema.uniqueItems === true && !((function () { const set = new Set(); for (const element of value) {
|
|
70
|
+
const hashed = hash_1.ValueHash.Create(element);
|
|
71
|
+
if (set.has(hashed)) {
|
|
72
|
+
return false;
|
|
73
|
+
}
|
|
74
|
+
else {
|
|
75
|
+
set.add(hashed);
|
|
76
|
+
}
|
|
77
|
+
} return true; })())) {
|
|
78
|
+
return false;
|
|
79
|
+
}
|
|
80
|
+
return value.every((value) => Visit(schema.items, value));
|
|
81
|
+
}
|
|
82
|
+
function BigInt(schema, value) {
|
|
83
|
+
if (typeof value !== 'bigint') {
|
|
84
|
+
return false;
|
|
85
|
+
}
|
|
86
|
+
if (IsBigInt(schema.multipleOf) && !(value % schema.multipleOf === globalThis.BigInt(0))) {
|
|
87
|
+
return false;
|
|
88
|
+
}
|
|
89
|
+
if (IsBigInt(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
90
|
+
return false;
|
|
91
|
+
}
|
|
92
|
+
if (IsBigInt(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
93
|
+
return false;
|
|
94
|
+
}
|
|
95
|
+
if (IsBigInt(schema.minimum) && !(value >= schema.minimum)) {
|
|
96
|
+
return false;
|
|
97
|
+
}
|
|
98
|
+
if (IsBigInt(schema.maximum) && !(value <= schema.maximum)) {
|
|
99
|
+
return false;
|
|
100
|
+
}
|
|
101
|
+
return true;
|
|
102
|
+
}
|
|
103
|
+
function Boolean(schema, value) {
|
|
104
|
+
return typeof value === 'boolean';
|
|
105
|
+
}
|
|
106
|
+
function Constructor(schema, value) {
|
|
107
|
+
return Visit(schema.returns, value.prototype);
|
|
108
|
+
}
|
|
109
|
+
function Date(schema, value) {
|
|
110
|
+
if (!(value instanceof globalThis.Date)) {
|
|
111
|
+
return false;
|
|
112
|
+
}
|
|
113
|
+
if (!globalThis.Number.isFinite(value.getTime())) {
|
|
114
|
+
return false;
|
|
115
|
+
}
|
|
116
|
+
if (IsNumber(schema.exclusiveMinimumTimestamp) && !(value.getTime() > schema.exclusiveMinimumTimestamp)) {
|
|
117
|
+
return false;
|
|
118
|
+
}
|
|
119
|
+
if (IsNumber(schema.exclusiveMaximumTimestamp) && !(value.getTime() < schema.exclusiveMaximumTimestamp)) {
|
|
120
|
+
return false;
|
|
121
|
+
}
|
|
122
|
+
if (IsNumber(schema.minimumTimestamp) && !(value.getTime() >= schema.minimumTimestamp)) {
|
|
123
|
+
return false;
|
|
124
|
+
}
|
|
125
|
+
if (IsNumber(schema.maximumTimestamp) && !(value.getTime() <= schema.maximumTimestamp)) {
|
|
126
|
+
return false;
|
|
127
|
+
}
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
function Function(schema, value) {
|
|
131
|
+
return typeof value === 'function';
|
|
132
|
+
}
|
|
133
|
+
function Integer(schema, value) {
|
|
134
|
+
if (!(typeof value === 'number' && globalThis.Number.isInteger(value))) {
|
|
135
|
+
return false;
|
|
136
|
+
}
|
|
137
|
+
if (IsNumber(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
138
|
+
return false;
|
|
139
|
+
}
|
|
140
|
+
if (IsNumber(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
141
|
+
return false;
|
|
142
|
+
}
|
|
143
|
+
if (IsNumber(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
144
|
+
return false;
|
|
145
|
+
}
|
|
146
|
+
if (IsNumber(schema.minimum) && !(value >= schema.minimum)) {
|
|
147
|
+
return false;
|
|
148
|
+
}
|
|
149
|
+
if (IsNumber(schema.maximum) && !(value <= schema.maximum)) {
|
|
150
|
+
return false;
|
|
151
|
+
}
|
|
152
|
+
return true;
|
|
153
|
+
}
|
|
154
|
+
function Intersect(schema, value) {
|
|
155
|
+
if (!schema.allOf.every((schema) => Visit(schema, value))) {
|
|
156
|
+
return false;
|
|
157
|
+
}
|
|
158
|
+
else if (schema.unevaluatedProperties === false) {
|
|
159
|
+
const schemaKeys = Types.KeyResolver.Resolve(schema);
|
|
160
|
+
const valueKeys = globalThis.Object.getOwnPropertyNames(value);
|
|
161
|
+
return valueKeys.every((key) => schemaKeys.includes(key));
|
|
162
|
+
}
|
|
163
|
+
else if (Types.TypeGuard.TSchema(schema.unevaluatedProperties)) {
|
|
164
|
+
const schemaKeys = Types.KeyResolver.Resolve(schema);
|
|
165
|
+
const valueKeys = globalThis.Object.getOwnPropertyNames(value);
|
|
166
|
+
return valueKeys.every((key) => schemaKeys.includes(key) || Visit(schema.unevaluatedProperties, value[key]));
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
return true;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
function Literal(schema, value) {
|
|
173
|
+
return value === schema.const;
|
|
174
|
+
}
|
|
175
|
+
function Never(schema, value) {
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
function Not(schema, value) {
|
|
179
|
+
return !Visit(schema.allOf[0].not, value) && Visit(schema.allOf[1], value);
|
|
180
|
+
}
|
|
181
|
+
function Null(schema, value) {
|
|
182
|
+
return value === null;
|
|
183
|
+
}
|
|
184
|
+
function Number(schema, value) {
|
|
185
|
+
if (index_1.TypeSystem.AllowNaN) {
|
|
186
|
+
if (!(typeof value === 'number')) {
|
|
187
|
+
return false;
|
|
188
|
+
}
|
|
189
|
+
}
|
|
190
|
+
else {
|
|
191
|
+
if (!(typeof value === 'number' && globalThis.Number.isFinite(value))) {
|
|
192
|
+
return false;
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
if (IsNumber(schema.multipleOf) && !(value % schema.multipleOf === 0)) {
|
|
196
|
+
return false;
|
|
197
|
+
}
|
|
198
|
+
if (IsNumber(schema.exclusiveMinimum) && !(value > schema.exclusiveMinimum)) {
|
|
199
|
+
return false;
|
|
200
|
+
}
|
|
201
|
+
if (IsNumber(schema.exclusiveMaximum) && !(value < schema.exclusiveMaximum)) {
|
|
202
|
+
return false;
|
|
203
|
+
}
|
|
204
|
+
if (IsNumber(schema.minimum) && !(value >= schema.minimum)) {
|
|
205
|
+
return false;
|
|
206
|
+
}
|
|
207
|
+
if (IsNumber(schema.maximum) && !(value <= schema.maximum)) {
|
|
208
|
+
return false;
|
|
209
|
+
}
|
|
210
|
+
return true;
|
|
211
|
+
}
|
|
212
|
+
function Object(schema, value) {
|
|
213
|
+
if (index_1.TypeSystem.AllowArrayObjects) {
|
|
214
|
+
if (!(typeof value === 'object' && value !== null)) {
|
|
215
|
+
return false;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
else {
|
|
219
|
+
if (!(typeof value === 'object' && value !== null && !globalThis.Array.isArray(value))) {
|
|
220
|
+
return false;
|
|
221
|
+
}
|
|
222
|
+
}
|
|
223
|
+
if (IsNumber(schema.minProperties) && !(globalThis.Object.getOwnPropertyNames(value).length >= schema.minProperties)) {
|
|
224
|
+
return false;
|
|
225
|
+
}
|
|
226
|
+
if (IsNumber(schema.maxProperties) && !(globalThis.Object.getOwnPropertyNames(value).length <= schema.maxProperties)) {
|
|
227
|
+
return false;
|
|
228
|
+
}
|
|
229
|
+
const schemaKeys = globalThis.Object.getOwnPropertyNames(schema.properties);
|
|
230
|
+
for (const schemaKey of schemaKeys) {
|
|
231
|
+
const property = schema.properties[schemaKey];
|
|
232
|
+
if (schema.required && schema.required.includes(schemaKey)) {
|
|
233
|
+
if (!Visit(property, value[schemaKey])) {
|
|
234
|
+
return false;
|
|
235
|
+
}
|
|
236
|
+
if (Types.ExtendsUndefined.Check(property)) {
|
|
237
|
+
return schemaKey in value;
|
|
238
|
+
}
|
|
239
|
+
}
|
|
240
|
+
else {
|
|
241
|
+
if (schemaKey in value && !Visit(property, value[schemaKey])) {
|
|
242
|
+
return false;
|
|
243
|
+
}
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
if (schema.additionalProperties === false) {
|
|
247
|
+
const valueKeys = globalThis.Object.getOwnPropertyNames(value);
|
|
248
|
+
// optimization: value is valid if schemaKey length matches the valueKey length
|
|
249
|
+
if (schema.required && schema.required.length === schemaKeys.length && valueKeys.length === schemaKeys.length) {
|
|
250
|
+
return true;
|
|
251
|
+
}
|
|
252
|
+
else {
|
|
253
|
+
return valueKeys.every((valueKey) => schemaKeys.includes(valueKey));
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
else if (typeof schema.additionalProperties === 'object') {
|
|
257
|
+
const valueKeys = globalThis.Object.getOwnPropertyNames(value);
|
|
258
|
+
return valueKeys.every((key) => schemaKeys.includes(key) || Visit(schema.additionalProperties, value[key]));
|
|
259
|
+
}
|
|
260
|
+
else {
|
|
261
|
+
return true;
|
|
262
|
+
}
|
|
263
|
+
}
|
|
264
|
+
function Promise(schema, value) {
|
|
265
|
+
return typeof value === 'object' && typeof value.then === 'function';
|
|
266
|
+
}
|
|
267
|
+
function Record(schema, value) {
|
|
268
|
+
if (index_1.TypeSystem.AllowArrayObjects) {
|
|
269
|
+
if (!(typeof value === 'object' && value !== null && !(value instanceof globalThis.Date))) {
|
|
270
|
+
return false;
|
|
271
|
+
}
|
|
272
|
+
}
|
|
273
|
+
else {
|
|
274
|
+
if (!(typeof value === 'object' && value !== null && !(value instanceof globalThis.Date) && !globalThis.Array.isArray(value))) {
|
|
275
|
+
return false;
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
const [keyPattern, valueSchema] = globalThis.Object.entries(schema.patternProperties)[0];
|
|
279
|
+
const regex = new RegExp(keyPattern);
|
|
280
|
+
if (!globalThis.Object.getOwnPropertyNames(value).every((key) => regex.test(key))) {
|
|
281
|
+
return false;
|
|
282
|
+
}
|
|
283
|
+
for (const propValue of globalThis.Object.values(value)) {
|
|
284
|
+
if (!Visit(valueSchema, propValue))
|
|
285
|
+
return false;
|
|
286
|
+
}
|
|
287
|
+
return true;
|
|
288
|
+
}
|
|
289
|
+
function Ref(schema, value) {
|
|
290
|
+
return Visit(Types.ReferenceRegistry.DerefOne(schema), value);
|
|
291
|
+
}
|
|
292
|
+
function Self(schema, value) {
|
|
293
|
+
return Visit(Types.ReferenceRegistry.DerefOne(schema), value);
|
|
294
|
+
}
|
|
295
|
+
function String(schema, value) {
|
|
296
|
+
if (!(typeof value === 'string')) {
|
|
297
|
+
return false;
|
|
298
|
+
}
|
|
299
|
+
if (IsNumber(schema.minLength)) {
|
|
300
|
+
if (!(value.length >= schema.minLength))
|
|
301
|
+
return false;
|
|
302
|
+
}
|
|
303
|
+
if (IsNumber(schema.maxLength)) {
|
|
304
|
+
if (!(value.length <= schema.maxLength))
|
|
305
|
+
return false;
|
|
306
|
+
}
|
|
307
|
+
if (schema.pattern !== undefined) {
|
|
308
|
+
const regex = new RegExp(schema.pattern);
|
|
309
|
+
if (!regex.test(value))
|
|
310
|
+
return false;
|
|
311
|
+
}
|
|
312
|
+
if (schema.format !== undefined) {
|
|
313
|
+
if (!Types.FormatRegistry.Has(schema.format))
|
|
314
|
+
return false;
|
|
315
|
+
const func = Types.FormatRegistry.Get(schema.format);
|
|
316
|
+
return func(value);
|
|
317
|
+
}
|
|
318
|
+
return true;
|
|
319
|
+
}
|
|
320
|
+
function Symbol(schema, value) {
|
|
321
|
+
if (!(typeof value === 'symbol')) {
|
|
322
|
+
return false;
|
|
323
|
+
}
|
|
324
|
+
return true;
|
|
325
|
+
}
|
|
326
|
+
function Tuple(schema, value) {
|
|
327
|
+
if (!globalThis.Array.isArray(value)) {
|
|
328
|
+
return false;
|
|
329
|
+
}
|
|
330
|
+
if (schema.items === undefined && !(value.length === 0)) {
|
|
331
|
+
return false;
|
|
332
|
+
}
|
|
333
|
+
if (!(value.length === schema.maxItems)) {
|
|
334
|
+
return false;
|
|
335
|
+
}
|
|
336
|
+
if (!schema.items) {
|
|
337
|
+
return true;
|
|
338
|
+
}
|
|
339
|
+
for (let i = 0; i < schema.items.length; i++) {
|
|
340
|
+
if (!Visit(schema.items[i], value[i]))
|
|
341
|
+
return false;
|
|
342
|
+
}
|
|
343
|
+
return true;
|
|
344
|
+
}
|
|
345
|
+
function Undefined(schema, value) {
|
|
346
|
+
return value === undefined;
|
|
347
|
+
}
|
|
348
|
+
function Union(schema, value) {
|
|
349
|
+
return schema.anyOf.some((inner) => Visit(inner, value));
|
|
350
|
+
}
|
|
351
|
+
function Uint8Array(schema, value) {
|
|
352
|
+
if (!(value instanceof globalThis.Uint8Array)) {
|
|
353
|
+
return false;
|
|
354
|
+
}
|
|
355
|
+
if (IsNumber(schema.maxByteLength) && !(value.length <= schema.maxByteLength)) {
|
|
356
|
+
return false;
|
|
357
|
+
}
|
|
358
|
+
if (IsNumber(schema.minByteLength) && !(value.length >= schema.minByteLength)) {
|
|
359
|
+
return false;
|
|
360
|
+
}
|
|
361
|
+
return true;
|
|
362
|
+
}
|
|
363
|
+
function Unknown(schema, value) {
|
|
364
|
+
return true;
|
|
365
|
+
}
|
|
366
|
+
function Void(schema, value) {
|
|
367
|
+
if (index_1.TypeSystem.AllowVoidNull) {
|
|
368
|
+
return value === undefined || value === null;
|
|
369
|
+
}
|
|
370
|
+
else {
|
|
371
|
+
return value === undefined;
|
|
372
|
+
}
|
|
373
|
+
}
|
|
374
|
+
function UserDefined(schema, value) {
|
|
375
|
+
if (!Types.TypeRegistry.Has(schema[Types.Kind]))
|
|
376
|
+
return false;
|
|
377
|
+
const func = Types.TypeRegistry.Get(schema[Types.Kind]);
|
|
378
|
+
return func(schema, value);
|
|
379
|
+
}
|
|
380
|
+
function Visit(schema, value) {
|
|
381
|
+
const anySchema = schema;
|
|
382
|
+
switch (anySchema[Types.Kind]) {
|
|
383
|
+
case 'Any':
|
|
384
|
+
return Any(anySchema, value);
|
|
385
|
+
case 'Array':
|
|
386
|
+
return Array(anySchema, value);
|
|
387
|
+
case 'BigInt':
|
|
388
|
+
return BigInt(anySchema, value);
|
|
389
|
+
case 'Boolean':
|
|
390
|
+
return Boolean(anySchema, value);
|
|
391
|
+
case 'Constructor':
|
|
392
|
+
return Constructor(anySchema, value);
|
|
393
|
+
case 'Date':
|
|
394
|
+
return Date(anySchema, value);
|
|
395
|
+
case 'Function':
|
|
396
|
+
return Function(anySchema, value);
|
|
397
|
+
case 'Integer':
|
|
398
|
+
return Integer(anySchema, value);
|
|
399
|
+
case 'Intersect':
|
|
400
|
+
return Intersect(anySchema, value);
|
|
401
|
+
case 'Literal':
|
|
402
|
+
return Literal(anySchema, value);
|
|
403
|
+
case 'Never':
|
|
404
|
+
return Never(anySchema, value);
|
|
405
|
+
case 'Not':
|
|
406
|
+
return Not(anySchema, value);
|
|
407
|
+
case 'Null':
|
|
408
|
+
return Null(anySchema, value);
|
|
409
|
+
case 'Number':
|
|
410
|
+
return Number(anySchema, value);
|
|
411
|
+
case 'Object':
|
|
412
|
+
return Object(anySchema, value);
|
|
413
|
+
case 'Promise':
|
|
414
|
+
return Promise(anySchema, value);
|
|
415
|
+
case 'Record':
|
|
416
|
+
return Record(anySchema, value);
|
|
417
|
+
case 'Ref':
|
|
418
|
+
return Ref(anySchema, value);
|
|
419
|
+
case 'Self':
|
|
420
|
+
return Self(anySchema, value);
|
|
421
|
+
case 'String':
|
|
422
|
+
return String(anySchema, value);
|
|
423
|
+
case 'Symbol':
|
|
424
|
+
return Symbol(anySchema, value);
|
|
425
|
+
case 'Tuple':
|
|
426
|
+
return Tuple(anySchema, value);
|
|
427
|
+
case 'Undefined':
|
|
428
|
+
return Undefined(anySchema, value);
|
|
429
|
+
case 'Union':
|
|
430
|
+
return Union(anySchema, value);
|
|
431
|
+
case 'Uint8Array':
|
|
432
|
+
return Uint8Array(anySchema, value);
|
|
433
|
+
case 'Unknown':
|
|
434
|
+
return Unknown(anySchema, value);
|
|
435
|
+
case 'Void':
|
|
436
|
+
return Void(anySchema, value);
|
|
437
|
+
default:
|
|
438
|
+
if (!Types.TypeRegistry.Has(anySchema[Types.Kind]))
|
|
439
|
+
throw new ValueCheckUnknownTypeError(anySchema);
|
|
440
|
+
return UserDefined(anySchema, value);
|
|
441
|
+
}
|
|
442
|
+
}
|
|
443
|
+
// -------------------------------------------------------------------------
|
|
444
|
+
// Check
|
|
445
|
+
// -------------------------------------------------------------------------
|
|
446
|
+
function Check(schema, value) {
|
|
447
|
+
return Visit(schema, value);
|
|
448
|
+
}
|
|
449
|
+
ValueCheck.Check = Check;
|
|
450
|
+
})(ValueCheck = exports.ValueCheck || (exports.ValueCheck = {}));
|