@sinclair/typebox 0.28.13 → 0.28.15
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.js +27 -15
- package/errors/errors.js +2 -2
- package/package.json +2 -2
- package/readme.md +125 -124
- package/system/system.js +1 -1
- package/typebox.js +18 -18
- package/value/cast.js +1 -1
- package/value/check.js +8 -2
- package/value/clone.js +1 -1
- package/value/convert.js +1 -1
- package/value/create.js +1 -1
- package/value/delta.js +1 -1
- package/value/equal.js +1 -1
- package/value/hash.js +1 -1
- package/value/is.js +1 -1
- package/value/mutate.js +1 -1
- package/value/pointer.js +1 -1
- package/value/value.js +1 -1
package/compiler/compiler.js
CHANGED
|
@@ -166,6 +166,12 @@ var TypeCompiler;
|
|
|
166
166
|
function IsString(value) {
|
|
167
167
|
return typeof value === 'string';
|
|
168
168
|
}
|
|
169
|
+
// ----------------------------------------------------------------------
|
|
170
|
+
// SchemaGuards
|
|
171
|
+
// ----------------------------------------------------------------------
|
|
172
|
+
function IsAnyOrUnknown(schema) {
|
|
173
|
+
return schema[Types.Kind] === 'Any' || schema[Types.Kind] === 'Unknown';
|
|
174
|
+
}
|
|
169
175
|
// -------------------------------------------------------------------
|
|
170
176
|
// Polices
|
|
171
177
|
// -------------------------------------------------------------------
|
|
@@ -308,7 +314,7 @@ var TypeCompiler;
|
|
|
308
314
|
const property = schema.properties[knownKey];
|
|
309
315
|
if (schema.required && schema.required.includes(knownKey)) {
|
|
310
316
|
yield* Visit(property, references, memberExpression);
|
|
311
|
-
if (Types.ExtendsUndefined.Check(property))
|
|
317
|
+
if (Types.ExtendsUndefined.Check(property) || IsAnyOrUnknown(property))
|
|
312
318
|
yield `('${knownKey}' in ${value})`;
|
|
313
319
|
}
|
|
314
320
|
else {
|
|
@@ -420,19 +426,22 @@ var TypeCompiler;
|
|
|
420
426
|
state_remote_custom_types.set(schema_key, schema);
|
|
421
427
|
yield `custom('${schema[Types.Kind]}', '${schema_key}', ${value})`;
|
|
422
428
|
}
|
|
423
|
-
function* Visit(schema, references, value) {
|
|
429
|
+
function* Visit(schema, references, value, root = false) {
|
|
424
430
|
const references_ = IsString(schema.$id) ? [...references, schema] : references;
|
|
425
431
|
const schema_ = schema;
|
|
426
|
-
//
|
|
427
|
-
//
|
|
428
|
-
//
|
|
429
|
-
|
|
430
|
-
|
|
432
|
+
// Rule: Types with identifiers are hoisted into their own functions. The following will generate a function for the schema
|
|
433
|
+
// and yield the call to that function. This call is only made if NOT the root type which allows the generated function to
|
|
434
|
+
// yield its expression. The root argument is only true when making calls via CreateFunction(). Note there is potential to
|
|
435
|
+
// omit the root argument and conditional by refactoring the logic below. Consider for review.
|
|
436
|
+
if (IsString(schema.$id)) {
|
|
431
437
|
const name = CreateFunctionName(schema.$id);
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
435
|
-
|
|
438
|
+
if (!state_local_function_names.has(schema.$id)) {
|
|
439
|
+
state_local_function_names.add(schema.$id);
|
|
440
|
+
const body = CreateFunction(name, schema, references, 'value');
|
|
441
|
+
PushFunction(body);
|
|
442
|
+
}
|
|
443
|
+
if (!root)
|
|
444
|
+
return yield `${name}(${value})`;
|
|
436
445
|
}
|
|
437
446
|
switch (schema_[Types.Kind]) {
|
|
438
447
|
case 'Any':
|
|
@@ -515,7 +524,7 @@ var TypeCompiler;
|
|
|
515
524
|
return `check_${Identifier.Encode($id)}`;
|
|
516
525
|
}
|
|
517
526
|
function CreateFunction(name, schema, references, value) {
|
|
518
|
-
const expression = [...Visit(schema, references, value)].map((condition) => ` ${condition}`).join(' &&\n');
|
|
527
|
+
const expression = [...Visit(schema, references, value, true)].map((condition) => ` ${condition}`).join(' &&\n');
|
|
519
528
|
return `function ${name}(value) {\n return (\n${expression}\n )\n}`;
|
|
520
529
|
}
|
|
521
530
|
function PushFunction(functionBody) {
|
|
@@ -534,9 +543,12 @@ var TypeCompiler;
|
|
|
534
543
|
// -------------------------------------------------------------------
|
|
535
544
|
function Build(schema, references) {
|
|
536
545
|
ResetCompiler();
|
|
537
|
-
const check = CreateFunction('check', schema, references, 'value');
|
|
546
|
+
const check = CreateFunction('check', schema, references, 'value'); // interior visit
|
|
538
547
|
const locals = GetLocals();
|
|
539
|
-
|
|
548
|
+
// prettier-ignore
|
|
549
|
+
return IsString(schema.$id) // ensure top level schemas with $id's are hoisted
|
|
550
|
+
? `${locals.join('\n')}\nreturn function check(value) {\n return ${CreateFunctionName(schema.$id)}(value)\n}`
|
|
551
|
+
: `${locals.join('\n')}\nreturn ${check}`;
|
|
540
552
|
}
|
|
541
553
|
/** Returns the generated assertion code used to validate this type. */
|
|
542
554
|
function Code(schema, references = []) {
|
|
@@ -570,4 +582,4 @@ var TypeCompiler;
|
|
|
570
582
|
return new TypeCheck(schema, references, checkFunction, code);
|
|
571
583
|
}
|
|
572
584
|
TypeCompiler.Compile = Compile;
|
|
573
|
-
})(TypeCompiler
|
|
585
|
+
})(TypeCompiler || (exports.TypeCompiler = TypeCompiler = {}));
|
package/errors/errors.js
CHANGED
|
@@ -95,7 +95,7 @@ var ValueErrorType;
|
|
|
95
95
|
ValueErrorType[ValueErrorType["Uint8ArrayMaxByteLength"] = 56] = "Uint8ArrayMaxByteLength";
|
|
96
96
|
ValueErrorType[ValueErrorType["Void"] = 57] = "Void";
|
|
97
97
|
ValueErrorType[ValueErrorType["Custom"] = 58] = "Custom";
|
|
98
|
-
})(ValueErrorType
|
|
98
|
+
})(ValueErrorType || (exports.ValueErrorType = ValueErrorType = {}));
|
|
99
99
|
// -------------------------------------------------------------------
|
|
100
100
|
// ValueErrorIterator
|
|
101
101
|
// -------------------------------------------------------------------
|
|
@@ -609,4 +609,4 @@ var ValueErrors;
|
|
|
609
609
|
return new ValueErrorIterator(iterator);
|
|
610
610
|
}
|
|
611
611
|
ValueErrors.Errors = Errors;
|
|
612
|
-
})(ValueErrors
|
|
612
|
+
})(ValueErrors || (exports.ValueErrors = ValueErrors = {}));
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@sinclair/typebox",
|
|
3
|
-
"version": "0.28.
|
|
3
|
+
"version": "0.28.15",
|
|
4
4
|
"description": "JSONSchema Type Builder with Static Type Resolution for TypeScript",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typescript",
|
|
@@ -42,6 +42,6 @@
|
|
|
42
42
|
"chai": "^4.3.6",
|
|
43
43
|
"mocha": "^9.2.2",
|
|
44
44
|
"prettier": "^2.7.1",
|
|
45
|
-
"typescript": "^5.
|
|
45
|
+
"typescript": "^5.1.3"
|
|
46
46
|
}
|
|
47
47
|
}
|
package/readme.md
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
<h1>TypeBox</h1>
|
|
4
4
|
|
|
5
5
|
<p>JSON Schema Type Builder with Static Type Resolution for TypeScript</p>
|
|
6
|
-
|
|
6
|
+
|
|
7
7
|
<img src="https://github.com/sinclairzx81/typebox/blob/master/typebox.png?raw=true" />
|
|
8
8
|
|
|
9
9
|
<br />
|
|
@@ -65,7 +65,7 @@ type T = Static<typeof T> // type T = {
|
|
|
65
65
|
|
|
66
66
|
TypeBox is a runtime type builder that creates in-memory JSON Schema objects that can be statically inferred as TypeScript types. The schemas produced by this library are designed to match the static type assertion rules of the TypeScript compiler. TypeBox enables one to create a unified type that can be statically checked by TypeScript and runtime asserted using standard JSON Schema validation.
|
|
67
67
|
|
|
68
|
-
This library is designed to enable JSON schema to compose with the same flexibility as TypeScript's type system. It can be used as a simple tool to build up complex schemas or integrated into REST or RPC services to help validate data received over the wire.
|
|
68
|
+
This library is designed to enable JSON schema to compose with the same flexibility as TypeScript's type system. It can be used as a simple tool to build up complex schemas or integrated into REST or RPC services to help validate data received over the wire.
|
|
69
69
|
|
|
70
70
|
License MIT
|
|
71
71
|
|
|
@@ -145,23 +145,23 @@ type T = {
|
|
|
145
145
|
|
|
146
146
|
const T = Type.Object({ // const T = {
|
|
147
147
|
id: Type.String(), // type: 'object',
|
|
148
|
-
name: Type.String(), // properties: {
|
|
149
|
-
timestamp: Type.Integer() // id: {
|
|
150
|
-
}) // type: 'string'
|
|
148
|
+
name: Type.String(), // properties: {
|
|
149
|
+
timestamp: Type.Integer() // id: {
|
|
150
|
+
}) // type: 'string'
|
|
151
151
|
// },
|
|
152
|
-
// name: {
|
|
153
|
-
// type: 'string'
|
|
152
|
+
// name: {
|
|
153
|
+
// type: 'string'
|
|
154
154
|
// },
|
|
155
|
-
// timestamp: {
|
|
156
|
-
// type: 'integer'
|
|
155
|
+
// timestamp: {
|
|
156
|
+
// type: 'integer'
|
|
157
157
|
// }
|
|
158
|
-
// },
|
|
158
|
+
// },
|
|
159
159
|
// required: [
|
|
160
160
|
// 'id',
|
|
161
161
|
// 'name',
|
|
162
162
|
// 'timestamp'
|
|
163
163
|
// ]
|
|
164
|
-
// }
|
|
164
|
+
// }
|
|
165
165
|
|
|
166
166
|
//--------------------------------------------------------------------------------------------
|
|
167
167
|
//
|
|
@@ -186,7 +186,7 @@ import { Value } from '@sinclair/typebox/value'
|
|
|
186
186
|
function receive(value: T) { // ... as a Static Type
|
|
187
187
|
|
|
188
188
|
if(Value.Check(T, value)) { // ... as a JSON Schema
|
|
189
|
-
|
|
189
|
+
|
|
190
190
|
// ok...
|
|
191
191
|
}
|
|
192
192
|
}
|
|
@@ -196,7 +196,7 @@ function receive(value: T) { // ... as a Static Type
|
|
|
196
196
|
|
|
197
197
|
## Types
|
|
198
198
|
|
|
199
|
-
TypeBox types are JSON schema fragments that can be composed into more complex types. Each fragment is structured such that a JSON schema compliant validator can runtime assert a value the same way TypeScript will statically assert a type. TypeBox provides a set of Standard types which are used create JSON schema compliant schematics as well as an Extended type set used to create schematics for constructs native to JavaScript.
|
|
199
|
+
TypeBox types are JSON schema fragments that can be composed into more complex types. Each fragment is structured such that a JSON schema compliant validator can runtime assert a value the same way TypeScript will statically assert a type. TypeBox provides a set of Standard types which are used create JSON schema compliant schematics as well as an Extended type set used to create schematics for constructs native to JavaScript.
|
|
200
200
|
|
|
201
201
|
<a name='types-standard'></a>
|
|
202
202
|
|
|
@@ -645,22 +645,22 @@ You can pass JSON Schema options on the last argument of any type. Option hints
|
|
|
645
645
|
|
|
646
646
|
```typescript
|
|
647
647
|
// String must be an email
|
|
648
|
-
const T = Type.String({ // const T = {
|
|
648
|
+
const T = Type.String({ // const T = {
|
|
649
649
|
format: 'email' // type: 'string',
|
|
650
|
-
}) // format: 'email'
|
|
650
|
+
}) // format: 'email'
|
|
651
651
|
// }
|
|
652
652
|
|
|
653
653
|
// Mumber must be a multiple of 2
|
|
654
|
-
const T = Type.Number({ // const T = {
|
|
655
|
-
multipleOf: 2 // type: 'number',
|
|
656
|
-
}) // multipleOf: 2
|
|
654
|
+
const T = Type.Number({ // const T = {
|
|
655
|
+
multipleOf: 2 // type: 'number',
|
|
656
|
+
}) // multipleOf: 2
|
|
657
657
|
// }
|
|
658
658
|
|
|
659
659
|
// Array must have at least 5 integer values
|
|
660
|
-
const T = Type.Array(Type.Integer(), { // const T = {
|
|
660
|
+
const T = Type.Array(Type.Integer(), { // const T = {
|
|
661
661
|
minItems: 5 // type: 'array',
|
|
662
|
-
}) // minItems: 5,
|
|
663
|
-
// items: {
|
|
662
|
+
}) // minItems: 5,
|
|
663
|
+
// items: {
|
|
664
664
|
// type: 'integer'
|
|
665
665
|
// }
|
|
666
666
|
// }
|
|
@@ -737,7 +737,7 @@ const T = Type.String({ $id: 'T' }) // const T = {
|
|
|
737
737
|
// $id: 'T',
|
|
738
738
|
// type: 'string'
|
|
739
739
|
// }
|
|
740
|
-
|
|
740
|
+
|
|
741
741
|
const R = Type.Ref(T) // const R = {
|
|
742
742
|
// $ref: 'T'
|
|
743
743
|
// }
|
|
@@ -808,7 +808,7 @@ type T0 = Static<typeof T0> // type T0 = false
|
|
|
808
808
|
|
|
809
809
|
type T1 = Static<typeof T1> // type T1 = number
|
|
810
810
|
|
|
811
|
-
type T2 = Static<typeof T2> // type T2 = string
|
|
811
|
+
type T2 = Static<typeof T2> // type T2 = string
|
|
812
812
|
```
|
|
813
813
|
|
|
814
814
|
<a name='types-template-literal'></a>
|
|
@@ -876,16 +876,16 @@ const T = Type.Object({ // const T = {
|
|
|
876
876
|
|
|
877
877
|
const A = Type.Index(T, ['x']) // const A = { type: 'number' }
|
|
878
878
|
|
|
879
|
-
const B = Type.Index(T, ['x', 'y']) // const B = {
|
|
879
|
+
const B = Type.Index(T, ['x', 'y']) // const B = {
|
|
880
880
|
// anyOf: [
|
|
881
|
-
// { type: 'number' },
|
|
881
|
+
// { type: 'number' },
|
|
882
882
|
// { type: 'string' }
|
|
883
883
|
// ]
|
|
884
884
|
// }
|
|
885
885
|
|
|
886
|
-
const C = Type.Index(T, Type.KeyOf(T)) // const C = {
|
|
886
|
+
const C = Type.Index(T, Type.KeyOf(T)) // const C = {
|
|
887
887
|
// anyOf: [
|
|
888
|
-
// { type: 'number' },
|
|
888
|
+
// { type: 'number' },
|
|
889
889
|
// { type: 'string' },
|
|
890
890
|
// { type: 'boolean' }
|
|
891
891
|
// ]
|
|
@@ -987,7 +987,7 @@ import { Type, TypeGuard } from '@sinclair/typebox'
|
|
|
987
987
|
const T = Type.String()
|
|
988
988
|
|
|
989
989
|
if(TypeGuard.TString(T)) {
|
|
990
|
-
|
|
990
|
+
|
|
991
991
|
// T is TString
|
|
992
992
|
}
|
|
993
993
|
```
|
|
@@ -1012,12 +1012,12 @@ const T = Type.Object({ // const T = {
|
|
|
1012
1012
|
// }
|
|
1013
1013
|
|
|
1014
1014
|
const U = Type.Strict(T) // const U = {
|
|
1015
|
-
// type: 'object',
|
|
1016
|
-
// properties: {
|
|
1017
|
-
// name: {
|
|
1018
|
-
// type: 'string'
|
|
1019
|
-
// }
|
|
1020
|
-
// }
|
|
1015
|
+
// type: 'object',
|
|
1016
|
+
// properties: {
|
|
1017
|
+
// name: {
|
|
1018
|
+
// type: 'string'
|
|
1019
|
+
// }
|
|
1020
|
+
// }
|
|
1021
1021
|
// }
|
|
1022
1022
|
```
|
|
1023
1023
|
|
|
@@ -1183,21 +1183,21 @@ const R = [...Value.Errors(T, { x: '42' })] // const R = [{
|
|
|
1183
1183
|
Use the Mutate function to perform a deep mutable value assignment while retaining internal references.
|
|
1184
1184
|
|
|
1185
1185
|
```typescript
|
|
1186
|
-
const Y = { z: 1 } // const Y = { z: 1 }
|
|
1186
|
+
const Y = { z: 1 } // const Y = { z: 1 }
|
|
1187
1187
|
|
|
1188
1188
|
const X = { y: Y } // const X = { y: { z: 1 } }
|
|
1189
1189
|
|
|
1190
|
-
const A = { x: X } // const A = { x: { y: { z: 1 } } }
|
|
1190
|
+
const A = { x: X } // const A = { x: { y: { z: 1 } } }
|
|
1191
1191
|
|
|
1192
1192
|
|
|
1193
|
-
Value.Mutate(A, { x: { y: { z: 2 } } }) // const A' = { x: { y: { z: 2 } } }
|
|
1193
|
+
Value.Mutate(A, { x: { y: { z: 2 } } }) // const A' = { x: { y: { z: 2 } } }
|
|
1194
1194
|
|
|
1195
|
-
const R0 = A.x.y.z === 2 // const R0 =
|
|
1195
|
+
const R0 = A.x.y.z === 2 // const R0 = true
|
|
1196
1196
|
|
|
1197
1197
|
const R1 = A.x.y === Y // const R1 = true
|
|
1198
1198
|
|
|
1199
1199
|
const R2 = A.x === X // const R2 = true
|
|
1200
|
-
```
|
|
1200
|
+
```
|
|
1201
1201
|
|
|
1202
1202
|
<a name='values-pointer'></a>
|
|
1203
1203
|
|
|
@@ -1241,29 +1241,29 @@ import addFormats from 'ajv-formats'
|
|
|
1241
1241
|
import Ajv from 'ajv'
|
|
1242
1242
|
|
|
1243
1243
|
const ajv = addFormats(new Ajv({}), [
|
|
1244
|
-
'date-time',
|
|
1245
|
-
'time',
|
|
1246
|
-
'date',
|
|
1247
|
-
'email',
|
|
1248
|
-
'hostname',
|
|
1249
|
-
'ipv4',
|
|
1250
|
-
'ipv6',
|
|
1251
|
-
'uri',
|
|
1252
|
-
'uri-reference',
|
|
1244
|
+
'date-time',
|
|
1245
|
+
'time',
|
|
1246
|
+
'date',
|
|
1247
|
+
'email',
|
|
1248
|
+
'hostname',
|
|
1249
|
+
'ipv4',
|
|
1250
|
+
'ipv6',
|
|
1251
|
+
'uri',
|
|
1252
|
+
'uri-reference',
|
|
1253
1253
|
'uuid',
|
|
1254
|
-
'uri-template',
|
|
1255
|
-
'json-pointer',
|
|
1256
|
-
'relative-json-pointer',
|
|
1254
|
+
'uri-template',
|
|
1255
|
+
'json-pointer',
|
|
1256
|
+
'relative-json-pointer',
|
|
1257
1257
|
'regex'
|
|
1258
1258
|
])
|
|
1259
1259
|
|
|
1260
|
-
const C = ajv.compile(Type.Object({
|
|
1260
|
+
const C = ajv.compile(Type.Object({
|
|
1261
1261
|
x: Type.Number(),
|
|
1262
1262
|
y: Type.Number(),
|
|
1263
1263
|
z: Type.Number()
|
|
1264
1264
|
}))
|
|
1265
1265
|
|
|
1266
|
-
const R = C({ x: 1, y: 2, z: 3 }) // const R = true
|
|
1266
|
+
const R = C({ x: 1, y: 2, z: 3 }) // const R = true
|
|
1267
1267
|
```
|
|
1268
1268
|
|
|
1269
1269
|
<a name='typecheck-typecompiler'></a>
|
|
@@ -1350,15 +1350,15 @@ import { TypeSystem } from '@sinclair/typebox/system'
|
|
|
1350
1350
|
Use the `Type(...)` function to create custom types. This function lets you specify custom value assertion logic and will return a type factory function which is used to instance the type. This function accepts two generic arguments, the first is the inference type, the second is options used to constrain the type. The following creates a Vector type.
|
|
1351
1351
|
|
|
1352
1352
|
```typescript
|
|
1353
|
-
type VectorOptions = { abs: boolean }
|
|
1353
|
+
type VectorOptions = { abs: boolean }
|
|
1354
1354
|
|
|
1355
1355
|
type Vector = { x: number, y: number }
|
|
1356
1356
|
|
|
1357
1357
|
const Vector = TypeSystem.Type<Vector, VectorOptions>('Vector', (options, value) => {
|
|
1358
1358
|
return (
|
|
1359
1359
|
typeof value === 'object' && value !== null &&
|
|
1360
|
-
'x' in value && typeof value.x === 'number' &&
|
|
1361
|
-
'y' in value && typeof value.y === 'number' &&
|
|
1360
|
+
'x' in value && typeof value.x === 'number' &&
|
|
1361
|
+
'y' in value && typeof value.y === 'number' &&
|
|
1362
1362
|
(options.abs ? (value.x === Math.abs(value.x) && value.y === Math.abs(value.y)) : true)
|
|
1363
1363
|
)
|
|
1364
1364
|
})
|
|
@@ -1383,7 +1383,7 @@ Use the `Format(...)` function to create a custom string format. The following c
|
|
|
1383
1383
|
```typescript
|
|
1384
1384
|
TypeSystem.Format('lowercase', value => value === value.toLowerCase()) // format should be lowercase
|
|
1385
1385
|
|
|
1386
|
-
const T = Type.String({ format: 'lowercase' })
|
|
1386
|
+
const T = Type.String({ format: 'lowercase' })
|
|
1387
1387
|
|
|
1388
1388
|
const A = Value.Check(T, 'Hello') // const A = false
|
|
1389
1389
|
|
|
@@ -1407,13 +1407,13 @@ TypeSystem.ExactOptionalPropertyTypes = true
|
|
|
1407
1407
|
//
|
|
1408
1408
|
// const A: {} = [] - allowed in TS
|
|
1409
1409
|
|
|
1410
|
-
TypeSystem.AllowArrayObjects = true
|
|
1410
|
+
TypeSystem.AllowArrayObjects = true
|
|
1411
1411
|
|
|
1412
1412
|
// Allow numeric values to be NaN or + or - Infinity (default is false)
|
|
1413
1413
|
//
|
|
1414
1414
|
// const A: number = NaN - allowed in TS
|
|
1415
1415
|
|
|
1416
|
-
TypeSystem.AllowNaN = true
|
|
1416
|
+
TypeSystem.AllowNaN = true
|
|
1417
1417
|
```
|
|
1418
1418
|
|
|
1419
1419
|
<a name='workbench'></a>
|
|
@@ -1441,7 +1441,8 @@ The following is a list of community packages that provide general tooling and f
|
|
|
1441
1441
|
| [elysia](https://github.com/elysiajs/elysia) | Fast and friendly Bun web framework |
|
|
1442
1442
|
| [fastify-type-provider-typebox](https://github.com/fastify/fastify-type-provider-typebox) | Fastify TypeBox integration with the Fastify Type Provider |
|
|
1443
1443
|
| [fetch-typebox](https://github.com/erfanium/fetch-typebox) | Drop-in replacement for fetch that brings easy integration with TypeBox |
|
|
1444
|
-
| [
|
|
1444
|
+
| [schema2typebox](https://github.com/xddq/schema2typebox) | Creating TypeBox code from JSON schemas |
|
|
1445
|
+
| [ts2typebox](https://github.com/xddq/ts2typebox) | Creating TypeBox code from Typescript types |
|
|
1445
1446
|
|
|
1446
1447
|
<a name='benchmark'></a>
|
|
1447
1448
|
|
|
@@ -1461,35 +1462,35 @@ This benchmark measures compilation performance for varying types. You can revie
|
|
|
1461
1462
|
┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┐
|
|
1462
1463
|
│ (index) │ Iterations │ Ajv │ TypeCompiler │ Performance │
|
|
1463
1464
|
├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┤
|
|
1464
|
-
│ Literal_String │ 1000 │ '
|
|
1465
|
-
│ Literal_Number │ 1000 │ '
|
|
1465
|
+
│ Literal_String │ 1000 │ ' 220 ms' │ ' 6 ms' │ ' 36.67 x' │
|
|
1466
|
+
│ Literal_Number │ 1000 │ ' 172 ms' │ ' 4 ms' │ ' 43.00 x' │
|
|
1466
1467
|
│ Literal_Boolean │ 1000 │ ' 162 ms' │ ' 4 ms' │ ' 40.50 x' │
|
|
1467
|
-
│ Primitive_Number │ 1000 │ '
|
|
1468
|
-
│ Primitive_String │ 1000 │ '
|
|
1469
|
-
│ Primitive_String_Pattern │ 1000 │ '
|
|
1470
|
-
│ Primitive_Boolean │ 1000 │ '
|
|
1471
|
-
│ Primitive_Null │ 1000 │ '
|
|
1472
|
-
│ Object_Unconstrained │ 1000 │ '
|
|
1473
|
-
│ Object_Constrained │ 1000 │ '
|
|
1474
|
-
│ Object_Vector3 │ 1000 │ '
|
|
1475
|
-
│ Object_Box3D │ 1000 │ '
|
|
1476
|
-
│ Tuple_Primitive │ 1000 │ '
|
|
1477
|
-
│ Tuple_Object │ 1000 │ '
|
|
1478
|
-
│ Composite_Intersect │ 1000 │ '
|
|
1479
|
-
│ Composite_Union │ 1000 │ '
|
|
1480
|
-
│ Math_Vector4 │ 1000 │ '
|
|
1481
|
-
│ Math_Matrix4 │ 1000 │ '
|
|
1482
|
-
│ Array_Primitive_Number │ 1000 │ '
|
|
1483
|
-
│ Array_Primitive_String │ 1000 │ '
|
|
1484
|
-
│ Array_Primitive_Boolean │ 1000 │ '
|
|
1485
|
-
│ Array_Object_Unconstrained │ 1000 │ '
|
|
1486
|
-
│ Array_Object_Constrained │ 1000 │ '
|
|
1487
|
-
│ Array_Tuple_Primitive │ 1000 │ '
|
|
1488
|
-
│ Array_Tuple_Object │ 1000 │ '
|
|
1489
|
-
│ Array_Composite_Intersect │ 1000 │ '
|
|
1490
|
-
│ Array_Composite_Union │ 1000 │ '
|
|
1491
|
-
│ Array_Math_Vector4 │ 1000 │ '
|
|
1492
|
-
│ Array_Math_Matrix4 │ 1000 │ '
|
|
1468
|
+
│ Primitive_Number │ 1000 │ ' 161 ms' │ ' 6 ms' │ ' 26.83 x' │
|
|
1469
|
+
│ Primitive_String │ 1000 │ ' 154 ms' │ ' 4 ms' │ ' 38.50 x' │
|
|
1470
|
+
│ Primitive_String_Pattern │ 1000 │ ' 204 ms' │ ' 10 ms' │ ' 20.40 x' │
|
|
1471
|
+
│ Primitive_Boolean │ 1000 │ ' 131 ms' │ ' 4 ms' │ ' 32.75 x' │
|
|
1472
|
+
│ Primitive_Null │ 1000 │ ' 142 ms' │ ' 5 ms' │ ' 28.40 x' │
|
|
1473
|
+
│ Object_Unconstrained │ 1000 │ ' 1263 ms' │ ' 29 ms' │ ' 43.55 x' │
|
|
1474
|
+
│ Object_Constrained │ 1000 │ ' 1267 ms' │ ' 24 ms' │ ' 52.79 x' │
|
|
1475
|
+
│ Object_Vector3 │ 1000 │ ' 382 ms' │ ' 7 ms' │ ' 54.57 x' │
|
|
1476
|
+
│ Object_Box3D │ 1000 │ ' 1723 ms' │ ' 28 ms' │ ' 61.54 x' │
|
|
1477
|
+
│ Tuple_Primitive │ 1000 │ ' 495 ms' │ ' 13 ms' │ ' 38.08 x' │
|
|
1478
|
+
│ Tuple_Object │ 1000 │ ' 1271 ms' │ ' 16 ms' │ ' 79.44 x' │
|
|
1479
|
+
│ Composite_Intersect │ 1000 │ ' 656 ms' │ ' 19 ms' │ ' 34.53 x' │
|
|
1480
|
+
│ Composite_Union │ 1000 │ ' 529 ms' │ ' 18 ms' │ ' 29.39 x' │
|
|
1481
|
+
│ Math_Vector4 │ 1000 │ ' 802 ms' │ ' 14 ms' │ ' 57.29 x' │
|
|
1482
|
+
│ Math_Matrix4 │ 1000 │ ' 411 ms' │ ' 6 ms' │ ' 68.50 x' │
|
|
1483
|
+
│ Array_Primitive_Number │ 1000 │ ' 369 ms' │ ' 6 ms' │ ' 61.50 x' │
|
|
1484
|
+
│ Array_Primitive_String │ 1000 │ ' 369 ms' │ ' 4 ms' │ ' 92.25 x' │
|
|
1485
|
+
│ Array_Primitive_Boolean │ 1000 │ ' 297 ms' │ ' 3 ms' │ ' 99.00 x' │
|
|
1486
|
+
│ Array_Object_Unconstrained │ 1000 │ ' 1582 ms' │ ' 20 ms' │ ' 79.10 x' │
|
|
1487
|
+
│ Array_Object_Constrained │ 1000 │ ' 1629 ms' │ ' 19 ms' │ ' 85.74 x' │
|
|
1488
|
+
│ Array_Tuple_Primitive │ 1000 │ ' 652 ms' │ ' 12 ms' │ ' 54.33 x' │
|
|
1489
|
+
│ Array_Tuple_Object │ 1000 │ ' 1587 ms' │ ' 16 ms' │ ' 99.19 x' │
|
|
1490
|
+
│ Array_Composite_Intersect │ 1000 │ ' 1051 ms' │ ' 15 ms' │ ' 70.07 x' │
|
|
1491
|
+
│ Array_Composite_Union │ 1000 │ ' 733 ms' │ ' 15 ms' │ ' 48.87 x' │
|
|
1492
|
+
│ Array_Math_Vector4 │ 1000 │ ' 1071 ms' │ ' 12 ms' │ ' 89.25 x' │
|
|
1493
|
+
│ Array_Math_Matrix4 │ 1000 │ ' 636 ms' │ ' 5 ms' │ ' 127.20 x' │
|
|
1493
1494
|
└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┘
|
|
1494
1495
|
```
|
|
1495
1496
|
|
|
@@ -1503,37 +1504,37 @@ This benchmark measures validation performance for varying types. You can review
|
|
|
1503
1504
|
┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
|
|
1504
1505
|
│ (index) │ Iterations │ ValueCheck │ Ajv │ TypeCompiler │ Performance │
|
|
1505
1506
|
├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
|
|
1506
|
-
│ Literal_String │ 1000000 │ ' 24 ms' │ ' 5 ms' │ '
|
|
1507
|
-
│ Literal_Number │ 1000000 │ ' 21 ms' │ ' 17 ms' │ '
|
|
1508
|
-
│ Literal_Boolean │ 1000000 │ '
|
|
1509
|
-
│ Primitive_Number │ 1000000 │ '
|
|
1510
|
-
│ Primitive_String │ 1000000 │ '
|
|
1511
|
-
│ Primitive_String_Pattern │ 1000000 │ '
|
|
1512
|
-
│ Primitive_Boolean │ 1000000 │ ' 22 ms' │ ' 17 ms' │ '
|
|
1513
|
-
│ Primitive_Null │ 1000000 │ '
|
|
1514
|
-
│ Object_Unconstrained │ 1000000 │ '
|
|
1515
|
-
│ Object_Constrained │ 1000000 │ '
|
|
1516
|
-
│ Object_Vector3 │ 1000000 │ '
|
|
1517
|
-
│ Object_Box3D │ 1000000 │ '
|
|
1518
|
-
│ Object_Recursive │ 1000000 │ '
|
|
1519
|
-
│ Tuple_Primitive │ 1000000 │ '
|
|
1520
|
-
│ Tuple_Object │ 1000000 │ '
|
|
1521
|
-
│ Composite_Intersect │ 1000000 │ '
|
|
1522
|
-
│ Composite_Union │ 1000000 │ '
|
|
1523
|
-
│ Math_Vector4 │ 1000000 │ '
|
|
1524
|
-
│ Math_Matrix4 │ 1000000 │ '
|
|
1525
|
-
│ Array_Primitive_Number │ 1000000 │ '
|
|
1526
|
-
│ Array_Primitive_String │ 1000000 │ '
|
|
1527
|
-
│ Array_Primitive_Boolean │ 1000000 │ '
|
|
1528
|
-
│ Array_Object_Unconstrained │ 1000000 │ '
|
|
1529
|
-
│ Array_Object_Constrained │ 1000000 │ '
|
|
1530
|
-
│ Array_Object_Recursive │ 1000000 │ '
|
|
1531
|
-
│ Array_Tuple_Primitive │ 1000000 │ '
|
|
1532
|
-
│ Array_Tuple_Object │ 1000000 │ '
|
|
1533
|
-
│ Array_Composite_Intersect │ 1000000 │ '
|
|
1534
|
-
│ Array_Composite_Union │ 1000000 │ '
|
|
1535
|
-
│ Array_Math_Vector4 │ 1000000 │ '
|
|
1536
|
-
│ Array_Math_Matrix4 │ 1000000 │ '
|
|
1507
|
+
│ Literal_String │ 1000000 │ ' 24 ms' │ ' 5 ms' │ ' 5 ms' │ ' 1.00 x' │
|
|
1508
|
+
│ Literal_Number │ 1000000 │ ' 21 ms' │ ' 17 ms' │ ' 9 ms' │ ' 1.89 x' │
|
|
1509
|
+
│ Literal_Boolean │ 1000000 │ ' 18 ms' │ ' 18 ms' │ ' 9 ms' │ ' 2.00 x' │
|
|
1510
|
+
│ Primitive_Number │ 1000000 │ ' 25 ms' │ ' 18 ms' │ ' 9 ms' │ ' 2.00 x' │
|
|
1511
|
+
│ Primitive_String │ 1000000 │ ' 25 ms' │ ' 17 ms' │ ' 9 ms' │ ' 1.89 x' │
|
|
1512
|
+
│ Primitive_String_Pattern │ 1000000 │ ' 174 ms' │ ' 44 ms' │ ' 36 ms' │ ' 1.22 x' │
|
|
1513
|
+
│ Primitive_Boolean │ 1000000 │ ' 22 ms' │ ' 17 ms' │ ' 9 ms' │ ' 1.89 x' │
|
|
1514
|
+
│ Primitive_Null │ 1000000 │ ' 22 ms' │ ' 16 ms' │ ' 9 ms' │ ' 1.78 x' │
|
|
1515
|
+
│ Object_Unconstrained │ 1000000 │ ' 1065 ms' │ ' 33 ms' │ ' 25 ms' │ ' 1.32 x' │
|
|
1516
|
+
│ Object_Constrained │ 1000000 │ ' 1192 ms' │ ' 53 ms' │ ' 38 ms' │ ' 1.39 x' │
|
|
1517
|
+
│ Object_Vector3 │ 1000000 │ ' 410 ms' │ ' 23 ms' │ ' 14 ms' │ ' 1.64 x' │
|
|
1518
|
+
│ Object_Box3D │ 1000000 │ ' 1939 ms' │ ' 54 ms' │ ' 50 ms' │ ' 1.08 x' │
|
|
1519
|
+
│ Object_Recursive │ 1000000 │ ' 5248 ms' │ ' 355 ms' │ ' 149 ms' │ ' 2.38 x' │
|
|
1520
|
+
│ Tuple_Primitive │ 1000000 │ ' 163 ms' │ ' 21 ms' │ ' 13 ms' │ ' 1.62 x' │
|
|
1521
|
+
│ Tuple_Object │ 1000000 │ ' 737 ms' │ ' 29 ms' │ ' 20 ms' │ ' 1.45 x' │
|
|
1522
|
+
│ Composite_Intersect │ 1000000 │ ' 761 ms' │ ' 24 ms' │ ' 15 ms' │ ' 1.60 x' │
|
|
1523
|
+
│ Composite_Union │ 1000000 │ ' 519 ms' │ ' 23 ms' │ ' 13 ms' │ ' 1.77 x' │
|
|
1524
|
+
│ Math_Vector4 │ 1000000 │ ' 247 ms' │ ' 21 ms' │ ' 11 ms' │ ' 1.91 x' │
|
|
1525
|
+
│ Math_Matrix4 │ 1000000 │ ' 1045 ms' │ ' 39 ms' │ ' 27 ms' │ ' 1.44 x' │
|
|
1526
|
+
│ Array_Primitive_Number │ 1000000 │ ' 256 ms' │ ' 20 ms' │ ' 12 ms' │ ' 1.67 x' │
|
|
1527
|
+
│ Array_Primitive_String │ 1000000 │ ' 222 ms' │ ' 21 ms' │ ' 14 ms' │ ' 1.50 x' │
|
|
1528
|
+
│ Array_Primitive_Boolean │ 1000000 │ ' 149 ms' │ ' 22 ms' │ ' 16 ms' │ ' 1.38 x' │
|
|
1529
|
+
│ Array_Object_Unconstrained │ 1000000 │ ' 5473 ms' │ ' 67 ms' │ ' 59 ms' │ ' 1.14 x' │
|
|
1530
|
+
│ Array_Object_Constrained │ 1000000 │ ' 5548 ms' │ ' 130 ms' │ ' 116 ms' │ ' 1.12 x' │
|
|
1531
|
+
│ Array_Object_Recursive │ 1000000 │ ' 21047 ms' │ ' 1710 ms' │ ' 584 ms' │ ' 2.93 x' │
|
|
1532
|
+
│ Array_Tuple_Primitive │ 1000000 │ ' 691 ms' │ ' 35 ms' │ ' 29 ms' │ ' 1.21 x' │
|
|
1533
|
+
│ Array_Tuple_Object │ 1000000 │ ' 3075 ms' │ ' 63 ms' │ ' 50 ms' │ ' 1.26 x' │
|
|
1534
|
+
│ Array_Composite_Intersect │ 1000000 │ ' 3126 ms' │ ' 44 ms' │ ' 35 ms' │ ' 1.26 x' │
|
|
1535
|
+
│ Array_Composite_Union │ 1000000 │ ' 2086 ms' │ ' 68 ms' │ ' 33 ms' │ ' 2.06 x' │
|
|
1536
|
+
│ Array_Math_Vector4 │ 1000000 │ ' 1069 ms' │ ' 38 ms' │ ' 23 ms' │ ' 1.65 x' │
|
|
1537
|
+
│ Array_Math_Matrix4 │ 1000000 │ ' 4559 ms' │ ' 111 ms' │ ' 88 ms' │ ' 1.26 x' │
|
|
1537
1538
|
└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┴──────────────┘
|
|
1538
1539
|
```
|
|
1539
1540
|
|
|
@@ -1547,11 +1548,11 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
|
|
|
1547
1548
|
┌──────────────────────┬────────────┬────────────┬─────────────┐
|
|
1548
1549
|
│ (index) │ Compiled │ Minified │ Compression │
|
|
1549
1550
|
├──────────────────────┼────────────┼────────────┼─────────────┤
|
|
1550
|
-
│ typebox/compiler │ '
|
|
1551
|
-
│ typebox/errors │ '
|
|
1552
|
-
│ typebox/system │ '
|
|
1553
|
-
│ typebox/value │ '
|
|
1554
|
-
│ typebox │ ' 75.
|
|
1551
|
+
│ typebox/compiler │ '128.0 kb' │ ' 57.0 kb' │ '2.25 x' │
|
|
1552
|
+
│ typebox/errors │ '111.6 kb' │ ' 49.1 kb' │ '2.27 x' │
|
|
1553
|
+
│ typebox/system │ ' 77.0 kb' │ ' 31.5 kb' │ '2.45 x' │
|
|
1554
|
+
│ typebox/value │ '177.7 kb' │ ' 76.8 kb' │ '2.31 x' │
|
|
1555
|
+
│ typebox │ ' 75.9 kb' │ ' 31.0 kb' │ '2.45 x' │
|
|
1555
1556
|
└──────────────────────┴────────────┴────────────┴─────────────┘
|
|
1556
1557
|
```
|
|
1557
1558
|
|
package/system/system.js
CHANGED
package/typebox.js
CHANGED
|
@@ -72,7 +72,7 @@ var TypeRegistry;
|
|
|
72
72
|
return map.get(kind);
|
|
73
73
|
}
|
|
74
74
|
TypeRegistry.Get = Get;
|
|
75
|
-
})(TypeRegistry
|
|
75
|
+
})(TypeRegistry || (exports.TypeRegistry = TypeRegistry = {}));
|
|
76
76
|
/** A registry for user defined string formats */
|
|
77
77
|
var FormatRegistry;
|
|
78
78
|
(function (FormatRegistry) {
|
|
@@ -102,7 +102,7 @@ var FormatRegistry;
|
|
|
102
102
|
return map.get(format);
|
|
103
103
|
}
|
|
104
104
|
FormatRegistry.Get = Get;
|
|
105
|
-
})(FormatRegistry
|
|
105
|
+
})(FormatRegistry || (exports.FormatRegistry = FormatRegistry = {}));
|
|
106
106
|
// --------------------------------------------------------------------------
|
|
107
107
|
// TypeGuard
|
|
108
108
|
// --------------------------------------------------------------------------
|
|
@@ -611,7 +611,7 @@ var TypeGuard;
|
|
|
611
611
|
(TKind(schema) && TypeRegistry.Has(schema[exports.Kind]))));
|
|
612
612
|
}
|
|
613
613
|
TypeGuard.TSchema = TSchema;
|
|
614
|
-
})(TypeGuard
|
|
614
|
+
})(TypeGuard || (exports.TypeGuard = TypeGuard = {}));
|
|
615
615
|
// --------------------------------------------------------------------------
|
|
616
616
|
// ExtendsUndefined
|
|
617
617
|
// --------------------------------------------------------------------------
|
|
@@ -636,7 +636,7 @@ var ExtendsUndefined;
|
|
|
636
636
|
return false;
|
|
637
637
|
}
|
|
638
638
|
ExtendsUndefined.Check = Check;
|
|
639
|
-
})(ExtendsUndefined
|
|
639
|
+
})(ExtendsUndefined || (exports.ExtendsUndefined = ExtendsUndefined = {}));
|
|
640
640
|
// --------------------------------------------------------------------------
|
|
641
641
|
// TypeExtends
|
|
642
642
|
// --------------------------------------------------------------------------
|
|
@@ -645,7 +645,7 @@ var TypeExtendsResult;
|
|
|
645
645
|
TypeExtendsResult[TypeExtendsResult["Union"] = 0] = "Union";
|
|
646
646
|
TypeExtendsResult[TypeExtendsResult["True"] = 1] = "True";
|
|
647
647
|
TypeExtendsResult[TypeExtendsResult["False"] = 2] = "False";
|
|
648
|
-
})(TypeExtendsResult
|
|
648
|
+
})(TypeExtendsResult || (exports.TypeExtendsResult = TypeExtendsResult = {}));
|
|
649
649
|
var TypeExtends;
|
|
650
650
|
(function (TypeExtends) {
|
|
651
651
|
// --------------------------------------------------------------------------
|
|
@@ -1369,7 +1369,7 @@ var TypeExtends;
|
|
|
1369
1369
|
return Visit(left, right);
|
|
1370
1370
|
}
|
|
1371
1371
|
TypeExtends.Extends = Extends;
|
|
1372
|
-
})(TypeExtends
|
|
1372
|
+
})(TypeExtends || (exports.TypeExtends = TypeExtends = {}));
|
|
1373
1373
|
// --------------------------------------------------------------------------
|
|
1374
1374
|
// TypeClone
|
|
1375
1375
|
// --------------------------------------------------------------------------
|
|
@@ -1406,7 +1406,7 @@ var TypeClone;
|
|
|
1406
1406
|
return { ...Visit(schema), ...options };
|
|
1407
1407
|
}
|
|
1408
1408
|
TypeClone.Clone = Clone;
|
|
1409
|
-
})(TypeClone
|
|
1409
|
+
})(TypeClone || (exports.TypeClone = TypeClone = {}));
|
|
1410
1410
|
// --------------------------------------------------------------------------
|
|
1411
1411
|
// IndexedAccessor
|
|
1412
1412
|
// --------------------------------------------------------------------------
|
|
@@ -1452,7 +1452,7 @@ var IndexedAccessor;
|
|
|
1452
1452
|
return exports.Type.Union(keys.map((key) => Visit(schema, key.toString())), options);
|
|
1453
1453
|
}
|
|
1454
1454
|
IndexedAccessor.Resolve = Resolve;
|
|
1455
|
-
})(IndexedAccessor
|
|
1455
|
+
})(IndexedAccessor || (exports.IndexedAccessor = IndexedAccessor = {}));
|
|
1456
1456
|
// --------------------------------------------------------------------------
|
|
1457
1457
|
// ObjectMap
|
|
1458
1458
|
// --------------------------------------------------------------------------
|
|
@@ -1486,7 +1486,7 @@ var ObjectMap;
|
|
|
1486
1486
|
return { ...Visit(TypeClone.Clone(schema, {}), callback), ...options };
|
|
1487
1487
|
}
|
|
1488
1488
|
ObjectMap.Map = Map;
|
|
1489
|
-
})(ObjectMap
|
|
1489
|
+
})(ObjectMap || (exports.ObjectMap = ObjectMap = {}));
|
|
1490
1490
|
var KeyResolver;
|
|
1491
1491
|
(function (KeyResolver) {
|
|
1492
1492
|
function UnwrapPattern(key) {
|
|
@@ -1528,7 +1528,7 @@ var KeyResolver;
|
|
|
1528
1528
|
return `^(${pattern.join('|')})$`;
|
|
1529
1529
|
}
|
|
1530
1530
|
KeyResolver.ResolvePattern = ResolvePattern;
|
|
1531
|
-
})(KeyResolver
|
|
1531
|
+
})(KeyResolver || (exports.KeyResolver = KeyResolver = {}));
|
|
1532
1532
|
// --------------------------------------------------------------------------
|
|
1533
1533
|
// KeyArrayResolver
|
|
1534
1534
|
// --------------------------------------------------------------------------
|
|
@@ -1551,7 +1551,7 @@ var KeyArrayResolver;
|
|
|
1551
1551
|
return [];
|
|
1552
1552
|
}
|
|
1553
1553
|
KeyArrayResolver.Resolve = Resolve;
|
|
1554
|
-
})(KeyArrayResolver
|
|
1554
|
+
})(KeyArrayResolver || (exports.KeyArrayResolver = KeyArrayResolver = {}));
|
|
1555
1555
|
// --------------------------------------------------------------------------
|
|
1556
1556
|
// UnionResolver
|
|
1557
1557
|
// --------------------------------------------------------------------------
|
|
@@ -1572,7 +1572,7 @@ var UnionResolver;
|
|
|
1572
1572
|
return exports.Type.Union([...Union(union)], { ...union });
|
|
1573
1573
|
}
|
|
1574
1574
|
UnionResolver.Resolve = Resolve;
|
|
1575
|
-
})(UnionResolver
|
|
1575
|
+
})(UnionResolver || (exports.UnionResolver = UnionResolver = {}));
|
|
1576
1576
|
// --------------------------------------------------------------------------
|
|
1577
1577
|
// TemplateLiteralPattern
|
|
1578
1578
|
// --------------------------------------------------------------------------
|
|
@@ -1619,7 +1619,7 @@ var TemplateLiteralPattern;
|
|
|
1619
1619
|
return `^${kinds.map((schema) => Visit(schema, '')).join('')}\$`;
|
|
1620
1620
|
}
|
|
1621
1621
|
TemplateLiteralPattern.Create = Create;
|
|
1622
|
-
})(TemplateLiteralPattern
|
|
1622
|
+
})(TemplateLiteralPattern || (exports.TemplateLiteralPattern = TemplateLiteralPattern = {}));
|
|
1623
1623
|
// --------------------------------------------------------------------------------------
|
|
1624
1624
|
// TemplateLiteralResolver
|
|
1625
1625
|
// --------------------------------------------------------------------------------------
|
|
@@ -1634,7 +1634,7 @@ var TemplateLiteralResolver;
|
|
|
1634
1634
|
return exports.Type.Union(literals);
|
|
1635
1635
|
}
|
|
1636
1636
|
TemplateLiteralResolver.Resolve = Resolve;
|
|
1637
|
-
})(TemplateLiteralResolver
|
|
1637
|
+
})(TemplateLiteralResolver || (exports.TemplateLiteralResolver = TemplateLiteralResolver = {}));
|
|
1638
1638
|
// --------------------------------------------------------------------------------------
|
|
1639
1639
|
// TemplateLiteralParser
|
|
1640
1640
|
// --------------------------------------------------------------------------------------
|
|
@@ -1778,7 +1778,7 @@ var TemplateLiteralParser;
|
|
|
1778
1778
|
return Parse(pattern.slice(1, pattern.length - 1));
|
|
1779
1779
|
}
|
|
1780
1780
|
TemplateLiteralParser.ParseExact = ParseExact;
|
|
1781
|
-
})(TemplateLiteralParser
|
|
1781
|
+
})(TemplateLiteralParser || (exports.TemplateLiteralParser = TemplateLiteralParser = {}));
|
|
1782
1782
|
// --------------------------------------------------------------------------------------
|
|
1783
1783
|
// TemplateLiteralFinite
|
|
1784
1784
|
// --------------------------------------------------------------------------------------
|
|
@@ -1819,7 +1819,7 @@ var TemplateLiteralFinite;
|
|
|
1819
1819
|
throw Error(`TemplateLiteralFinite: Unknown expression type`);
|
|
1820
1820
|
}
|
|
1821
1821
|
TemplateLiteralFinite.Check = Check;
|
|
1822
|
-
})(TemplateLiteralFinite
|
|
1822
|
+
})(TemplateLiteralFinite || (exports.TemplateLiteralFinite = TemplateLiteralFinite = {}));
|
|
1823
1823
|
// --------------------------------------------------------------------------------------
|
|
1824
1824
|
// TemplateLiteralGenerator
|
|
1825
1825
|
// --------------------------------------------------------------------------------------
|
|
@@ -1854,7 +1854,7 @@ var TemplateLiteralGenerator;
|
|
|
1854
1854
|
throw Error('TemplateLiteralGenerator: Unknown expression');
|
|
1855
1855
|
}
|
|
1856
1856
|
TemplateLiteralGenerator.Generate = Generate;
|
|
1857
|
-
})(TemplateLiteralGenerator
|
|
1857
|
+
})(TemplateLiteralGenerator || (exports.TemplateLiteralGenerator = TemplateLiteralGenerator = {}));
|
|
1858
1858
|
// ---------------------------------------------------------------------
|
|
1859
1859
|
// TemplateLiteralDslParser
|
|
1860
1860
|
// ---------------------------------------------------------------------
|
|
@@ -1902,7 +1902,7 @@ var TemplateLiteralDslParser;
|
|
|
1902
1902
|
return [...ParseLiteral(template_dsl)];
|
|
1903
1903
|
}
|
|
1904
1904
|
TemplateLiteralDslParser.Parse = Parse;
|
|
1905
|
-
})(TemplateLiteralDslParser
|
|
1905
|
+
})(TemplateLiteralDslParser || (exports.TemplateLiteralDslParser = TemplateLiteralDslParser = {}));
|
|
1906
1906
|
// --------------------------------------------------------------------------
|
|
1907
1907
|
// TypeOrdinal: Used for auto $id generation
|
|
1908
1908
|
// --------------------------------------------------------------------------
|
package/value/cast.js
CHANGED
package/value/check.js
CHANGED
|
@@ -66,6 +66,12 @@ var ValueCheck;
|
|
|
66
66
|
return value !== undefined;
|
|
67
67
|
}
|
|
68
68
|
// ----------------------------------------------------------------------
|
|
69
|
+
// SchemaGuards
|
|
70
|
+
// ----------------------------------------------------------------------
|
|
71
|
+
function IsAnyOrUnknown(schema) {
|
|
72
|
+
return schema[Types.Kind] === 'Any' || schema[Types.Kind] === 'Unknown';
|
|
73
|
+
}
|
|
74
|
+
// ----------------------------------------------------------------------
|
|
69
75
|
// Policies
|
|
70
76
|
// ----------------------------------------------------------------------
|
|
71
77
|
function IsExactOptionalProperty(value, key) {
|
|
@@ -254,7 +260,7 @@ var ValueCheck;
|
|
|
254
260
|
if (!Visit(property, references, value[knownKey])) {
|
|
255
261
|
return false;
|
|
256
262
|
}
|
|
257
|
-
if (Types.ExtendsUndefined.Check(property) && !(knownKey in value)) {
|
|
263
|
+
if ((Types.ExtendsUndefined.Check(property) || IsAnyOrUnknown(property)) && !(knownKey in value)) {
|
|
258
264
|
return false;
|
|
259
265
|
}
|
|
260
266
|
}
|
|
@@ -483,4 +489,4 @@ var ValueCheck;
|
|
|
483
489
|
return Visit(schema, references, value);
|
|
484
490
|
}
|
|
485
491
|
ValueCheck.Check = Check;
|
|
486
|
-
})(ValueCheck
|
|
492
|
+
})(ValueCheck || (exports.ValueCheck = ValueCheck = {}));
|
package/value/clone.js
CHANGED
package/value/convert.js
CHANGED
|
@@ -369,4 +369,4 @@ var ValueConvert;
|
|
|
369
369
|
return Visit(schema, references, clone_1.ValueClone.Clone(value));
|
|
370
370
|
}
|
|
371
371
|
ValueConvert.Convert = Convert;
|
|
372
|
-
})(ValueConvert
|
|
372
|
+
})(ValueConvert || (exports.ValueConvert = ValueConvert = {}));
|
package/value/create.js
CHANGED
package/value/delta.js
CHANGED
package/value/equal.js
CHANGED
package/value/hash.js
CHANGED
package/value/is.js
CHANGED
package/value/mutate.js
CHANGED
package/value/pointer.js
CHANGED
package/value/value.js
CHANGED