@sinclair/typebox 0.26.0-dev.5 → 0.26.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/compiler/compiler.d.ts +1 -1
- package/compiler/compiler.js +22 -19
- package/package.json +1 -1
- package/readme.md +104 -90
- package/system/system.d.ts +4 -0
- package/system/system.js +15 -2
- package/typebox.d.ts +14 -12
- package/typebox.js +6 -12
- package/value/value.d.ts +5 -5
- package/value/value.js +2 -2
package/compiler/compiler.d.ts
CHANGED
|
@@ -32,7 +32,7 @@ export declare class TypeCompilerTypeGuardError extends Error {
|
|
|
32
32
|
/** Compiles Types for Runtime Type Checking */
|
|
33
33
|
export declare namespace TypeCompiler {
|
|
34
34
|
/** Returns the generated assertion code used to validate this type. */
|
|
35
|
-
function Code<T extends Types.TSchema>(schema: T, references
|
|
35
|
+
function Code<T extends Types.TSchema>(schema: T, references?: Types.TSchema[]): string;
|
|
36
36
|
/** Compiles the given type for runtime type checking. This compiler only accepts known TypeBox types non-inclusive of unsafe types. */
|
|
37
37
|
function Compile<T extends Types.TSchema>(schema: T, references?: Types.TSchema[]): TypeCheck<T>;
|
|
38
38
|
}
|
package/compiler/compiler.js
CHANGED
|
@@ -165,6 +165,23 @@ var TypeCompiler;
|
|
|
165
165
|
return typeof value === 'string';
|
|
166
166
|
}
|
|
167
167
|
// -------------------------------------------------------------------
|
|
168
|
+
// Overrides
|
|
169
|
+
// -------------------------------------------------------------------
|
|
170
|
+
function IsNumberCheck(value) {
|
|
171
|
+
return !index_2.TypeSystem.AllowNaN ? `(typeof ${value} === 'number' && Number.isFinite(${value}))` : `typeof ${value} === 'number'`;
|
|
172
|
+
}
|
|
173
|
+
function IsObjectCheck(value) {
|
|
174
|
+
return !index_2.TypeSystem.AllowArrayObjects ? `(typeof ${value} === 'object' && ${value} !== null && !Array.isArray(${value}))` : `(typeof ${value} === 'object' && ${value} !== null)`;
|
|
175
|
+
}
|
|
176
|
+
function IsRecordCheck(value) {
|
|
177
|
+
return !index_2.TypeSystem.AllowArrayObjects
|
|
178
|
+
? `(typeof ${value} === 'object' && ${value} !== null && !Array.isArray(${value}) && !(${value} instanceof Date) && !(${value} instanceof Uint8Array))`
|
|
179
|
+
: `(typeof ${value} === 'object' && ${value} !== null && !(${value} instanceof Date) && !(${value} instanceof Uint8Array))`;
|
|
180
|
+
}
|
|
181
|
+
function IsVoidCheck(value) {
|
|
182
|
+
return index_2.TypeSystem.AllowVoidNull ? `(${value} === undefined || ${value} === null)` : `${value} === undefined`;
|
|
183
|
+
}
|
|
184
|
+
// -------------------------------------------------------------------
|
|
168
185
|
// Types
|
|
169
186
|
// -------------------------------------------------------------------
|
|
170
187
|
function* Any(schema, references, value) {
|
|
@@ -267,9 +284,7 @@ var TypeCompiler;
|
|
|
267
284
|
yield `${value} === null`;
|
|
268
285
|
}
|
|
269
286
|
function* Number(schema, references, value) {
|
|
270
|
-
yield
|
|
271
|
-
if (!index_2.TypeSystem.AllowNaN)
|
|
272
|
-
yield `Number.isFinite(${value})`;
|
|
287
|
+
yield IsNumberCheck(value);
|
|
273
288
|
if (IsNumber(schema.multipleOf))
|
|
274
289
|
yield `(${value} % ${schema.multipleOf}) === 0`;
|
|
275
290
|
if (IsNumber(schema.exclusiveMinimum))
|
|
@@ -282,12 +297,7 @@ var TypeCompiler;
|
|
|
282
297
|
yield `${value} <= ${schema.maximum}`;
|
|
283
298
|
}
|
|
284
299
|
function* Object(schema, references, value) {
|
|
285
|
-
|
|
286
|
-
yield `(typeof ${value} === 'object' && ${value} !== null && !Array.isArray(${value}))`;
|
|
287
|
-
}
|
|
288
|
-
else {
|
|
289
|
-
yield `(typeof ${value} === 'object' && ${value} !== null)`;
|
|
290
|
-
}
|
|
300
|
+
yield IsObjectCheck(value);
|
|
291
301
|
if (!index_2.TypeSystem.AllowArrayObjects)
|
|
292
302
|
yield `!Array.isArray(${value})`;
|
|
293
303
|
if (IsNumber(schema.minProperties))
|
|
@@ -327,9 +337,7 @@ var TypeCompiler;
|
|
|
327
337
|
yield `(typeof value === 'object' && typeof ${value}.then === 'function')`;
|
|
328
338
|
}
|
|
329
339
|
function* Record(schema, references, value) {
|
|
330
|
-
yield
|
|
331
|
-
if (!index_2.TypeSystem.AllowArrayObjects)
|
|
332
|
-
yield `!Array.isArray(${value})`;
|
|
340
|
+
yield IsRecordCheck(value);
|
|
333
341
|
const [keyPattern, valueSchema] = globalThis.Object.entries(schema.patternProperties)[0];
|
|
334
342
|
const local = PushLocal(`new RegExp(/${keyPattern}/)`);
|
|
335
343
|
yield `(Object.getOwnPropertyNames(${value}).every(key => ${local}.test(key)))`;
|
|
@@ -397,12 +405,7 @@ var TypeCompiler;
|
|
|
397
405
|
yield 'true';
|
|
398
406
|
}
|
|
399
407
|
function* Void(schema, references, value) {
|
|
400
|
-
|
|
401
|
-
yield `(${value} === undefined || ${value} === null)`;
|
|
402
|
-
}
|
|
403
|
-
else {
|
|
404
|
-
yield `${value} === undefined`;
|
|
405
|
-
}
|
|
408
|
+
yield IsVoidCheck(value);
|
|
406
409
|
}
|
|
407
410
|
function* UserDefined(schema, references, value) {
|
|
408
411
|
const schema_key = `schema_key_${state_remote_custom_types.size}`;
|
|
@@ -526,7 +529,7 @@ var TypeCompiler;
|
|
|
526
529
|
return `${locals.join('\n')}\nreturn ${check}`;
|
|
527
530
|
}
|
|
528
531
|
/** Returns the generated assertion code used to validate this type. */
|
|
529
|
-
function Code(schema, references) {
|
|
532
|
+
function Code(schema, references = []) {
|
|
530
533
|
if (!Types.TypeGuard.TSchema(schema))
|
|
531
534
|
throw new TypeCompilerTypeGuardError(schema);
|
|
532
535
|
for (const schema of references)
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
<p>JSON Schema Type Builder with Static Type Resolution for TypeScript</p>
|
|
6
6
|
|
|
7
|
-
<img src="
|
|
7
|
+
<img src="https://github.com/sinclairzx81/typebox/blob/master/typebox.png?raw=true" />
|
|
8
8
|
|
|
9
9
|
<br />
|
|
10
10
|
<br />
|
|
@@ -62,9 +62,9 @@ type T = Static<typeof T> // type T = {
|
|
|
62
62
|
|
|
63
63
|
## Overview
|
|
64
64
|
|
|
65
|
-
TypeBox is a runtime type builder that
|
|
65
|
+
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.
|
|
66
66
|
|
|
67
|
-
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
|
|
67
|
+
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
68
|
|
|
69
69
|
License MIT
|
|
70
70
|
|
|
@@ -189,13 +189,13 @@ function receive(value: T) { // ... as a Static Type
|
|
|
189
189
|
|
|
190
190
|
## Types
|
|
191
191
|
|
|
192
|
-
TypeBox types are
|
|
192
|
+
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.
|
|
193
193
|
|
|
194
194
|
<a name='types-standard'></a>
|
|
195
195
|
|
|
196
196
|
### Standard Types
|
|
197
197
|
|
|
198
|
-
The following table lists the Standard TypeBox types. These types are fully compatible with the JSON Schema specification.
|
|
198
|
+
The following table lists the Standard TypeBox types. These types are fully compatible with the JSON Schema Draft 6 specification.
|
|
199
199
|
|
|
200
200
|
```typescript
|
|
201
201
|
┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐
|
|
@@ -457,17 +457,6 @@ The following table lists the Standard TypeBox types. These types are fully comp
|
|
|
457
457
|
│ │ │ │
|
|
458
458
|
│ │ │ │
|
|
459
459
|
│ │ │ │
|
|
460
|
-
├────────────────────────────────┼─────────────────────────────┼────────────────────────────────┤
|
|
461
|
-
│ const A = Type.Object({ │ type T = { │ const T = { │
|
|
462
|
-
│ x: Type.Number(), │ x: number, │ $id: 'T' │
|
|
463
|
-
│ y: Type.Number() │ y: number │ type: 'object', │
|
|
464
|
-
│ }, { $id: 'T' }) | } │ required: ['x', 'y'], │
|
|
465
|
-
│ │ │ properties: { │
|
|
466
|
-
│ const T = Type.Deref( │ │ x: { type: 'number' }, │
|
|
467
|
-
│ Type.Ref(A) │ │ y: { type: 'number' }, │
|
|
468
|
-
│ ) │ │ } │
|
|
469
|
-
│ │ │ } │
|
|
470
|
-
│ │ │ │
|
|
471
460
|
└────────────────────────────────┴─────────────────────────────┴────────────────────────────────┘
|
|
472
461
|
```
|
|
473
462
|
|
|
@@ -475,9 +464,7 @@ The following table lists the Standard TypeBox types. These types are fully comp
|
|
|
475
464
|
|
|
476
465
|
### Extended Types
|
|
477
466
|
|
|
478
|
-
TypeBox provides several extended types that can be used to produce schematics for common JavaScript constructs. These types
|
|
479
|
-
|
|
480
|
-
The following lists the supported types
|
|
467
|
+
TypeBox provides several extended types that can be used to produce schematics for common JavaScript constructs. These types can not be used with standard JSON schema validators; but are useful to help frame schematics for RPC interfaces that may receive JSON validated data. Extended types are prefixed with the `[Extended]` doc comment for convenience. The following table lists the supported types.
|
|
481
468
|
|
|
482
469
|
```typescript
|
|
483
470
|
┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐
|
|
@@ -570,7 +557,7 @@ The following lists the supported types
|
|
|
570
557
|
|
|
571
558
|
### Modifiers
|
|
572
559
|
|
|
573
|
-
TypeBox provides
|
|
560
|
+
TypeBox provides modifiers that allow schema properties to be statically inferred as `readonly` or `optional`. The following table shows the supported modifiers and how they map between TypeScript and JSON Schema.
|
|
574
561
|
|
|
575
562
|
```typescript
|
|
576
563
|
┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐
|
|
@@ -614,7 +601,7 @@ TypeBox provides property modifier types that allow properties to be mapped with
|
|
|
614
601
|
|
|
615
602
|
### Options
|
|
616
603
|
|
|
617
|
-
You can pass JSON Schema
|
|
604
|
+
You can pass JSON Schema options on the last argument of any type. Option hints specific to each type are provided for convenience.
|
|
618
605
|
|
|
619
606
|
```typescript
|
|
620
607
|
// String must be an email
|
|
@@ -644,7 +631,7 @@ const T = Type.Array(Type.Integer(), { // const T = {
|
|
|
644
631
|
|
|
645
632
|
### Generic Types
|
|
646
633
|
|
|
647
|
-
Generic types can be created with generic functions
|
|
634
|
+
Generic types can be created with generic functions constrained to type `TSchema`. The following creates a generic `Vector<T>` type.
|
|
648
635
|
|
|
649
636
|
```typescript
|
|
650
637
|
import { Type, Static, TSchema } from '@sinclair/typebox'
|
|
@@ -661,6 +648,12 @@ const NumberVector = Vector(Type.Number()) // const NumberVector = {
|
|
|
661
648
|
// }
|
|
662
649
|
// }
|
|
663
650
|
|
|
651
|
+
type NumberVector = Static<typeof NumberVector> // type NumberVector = {
|
|
652
|
+
// x: number,
|
|
653
|
+
// y: number,
|
|
654
|
+
// z: number
|
|
655
|
+
// }
|
|
656
|
+
|
|
664
657
|
const BooleanVector = Vector(Type.Boolean()) // const BooleanVector = {
|
|
665
658
|
// type: 'object',
|
|
666
659
|
// required: ['x', 'y', 'z'],
|
|
@@ -670,13 +663,34 @@ const BooleanVector = Vector(Type.Boolean()) // const BooleanVector = {
|
|
|
670
663
|
// z: { type: 'boolean' }
|
|
671
664
|
// }
|
|
672
665
|
// }
|
|
666
|
+
|
|
667
|
+
type BooleanVector = Static<typeof BooleanVector> // type BooleanVector = {
|
|
668
|
+
// x: boolean,
|
|
669
|
+
// y: boolean,
|
|
670
|
+
// z: boolean
|
|
671
|
+
// }
|
|
672
|
+
```
|
|
673
|
+
|
|
674
|
+
The following creates a generic `Nullable<T>` type.
|
|
675
|
+
|
|
676
|
+
```typescript
|
|
677
|
+
const Nullable = <T extends TSchema>(schema: T) => Type.Union([schema, Type.Null()])
|
|
678
|
+
|
|
679
|
+
const T = Nullable(Type.String()) // const T = {
|
|
680
|
+
// anyOf: [
|
|
681
|
+
// { type: 'string' },
|
|
682
|
+
// { type: 'null' }
|
|
683
|
+
// ]
|
|
684
|
+
// }
|
|
685
|
+
|
|
686
|
+
type T = Static<typeof T> // type T = string | null
|
|
673
687
|
```
|
|
674
688
|
|
|
675
689
|
<a name='types-references'></a>
|
|
676
690
|
|
|
677
691
|
### Reference Types
|
|
678
692
|
|
|
679
|
-
Reference types are supported with `Type.Ref(...)`.
|
|
693
|
+
Reference types are supported with `Type.Ref(...)`. The target type must specify a valid `$id`.
|
|
680
694
|
|
|
681
695
|
```typescript
|
|
682
696
|
const T = Type.String({ $id: 'T' }) // const T = {
|
|
@@ -730,9 +744,9 @@ function test(node: Node) {
|
|
|
730
744
|
|
|
731
745
|
### Conditional Types
|
|
732
746
|
|
|
733
|
-
Conditional types are supported with `Extends`, `Exclude` and `Extract`.
|
|
747
|
+
Conditional types are supported with `Extends`, `Exclude` and `Extract`.
|
|
734
748
|
|
|
735
|
-
|
|
749
|
+
**TypeScript**
|
|
736
750
|
|
|
737
751
|
```typescript
|
|
738
752
|
type T0 = string extends number ? true : false
|
|
@@ -742,7 +756,7 @@ type T1 = Extract<string | number, number>
|
|
|
742
756
|
type T2 = Exclude<string | number, number>
|
|
743
757
|
// ^ string
|
|
744
758
|
```
|
|
745
|
-
|
|
759
|
+
**TypeBox**
|
|
746
760
|
```typescript
|
|
747
761
|
const T0 = Type.Extends(Type.String(), Type.Number(), Type.Literal(true), Type.Literal(false))
|
|
748
762
|
// ^ TLiteral<false>
|
|
@@ -756,7 +770,7 @@ const T2 = Type.Exclude(Type.Union([Type.String(), Type.Number()]), Type.Number(
|
|
|
756
770
|
|
|
757
771
|
### Unsafe
|
|
758
772
|
|
|
759
|
-
Use `Type.Unsafe(...)` to create custom
|
|
773
|
+
Use `Type.Unsafe(...)` to create custom schematics with user defined inference rules.
|
|
760
774
|
|
|
761
775
|
```typescript
|
|
762
776
|
const T = Type.Unsafe<string>({ type: 'number' }) // const T = {
|
|
@@ -766,7 +780,7 @@ const T = Type.Unsafe<string>({ type: 'number' }) // const T = {
|
|
|
766
780
|
type T = Static<typeof T> // type T = string
|
|
767
781
|
```
|
|
768
782
|
|
|
769
|
-
The `Type.Unsafe(...)` type
|
|
783
|
+
The `Type.Unsafe(...)` type can be useful to express specific OpenAPI schema representations.
|
|
770
784
|
|
|
771
785
|
```typescript
|
|
772
786
|
import { Type, Static, TSchema } from '@sinclair/typebox'
|
|
@@ -801,7 +815,7 @@ type T = Static<typeof T> // type T = 'A' | 'B' | 'C'
|
|
|
801
815
|
|
|
802
816
|
### Guards
|
|
803
817
|
|
|
804
|
-
TypeBox provides a `TypeGuard` module for reflection and
|
|
818
|
+
TypeBox provides a `TypeGuard` module that can be used for reflection and asserting values as types.
|
|
805
819
|
|
|
806
820
|
```typescript
|
|
807
821
|
import { Type, TypeGuard } from '@sinclair/typebox'
|
|
@@ -818,7 +832,7 @@ if(TypeGuard.TString(T)) {
|
|
|
818
832
|
|
|
819
833
|
### Strict
|
|
820
834
|
|
|
821
|
-
TypeBox schemas contain the `Kind` and `Modifier` symbol properties. These properties are used for type composition and
|
|
835
|
+
TypeBox schemas contain the `Kind` and `Modifier` symbol properties. These properties are used for type composition and reflection. These properties are not strictly valid JSON schema; so in some cases it may be desirable to omit them. TypeBox provides a `Type.Strict()` function that will omit these properties if necessary.
|
|
822
836
|
|
|
823
837
|
```typescript
|
|
824
838
|
const T = Type.Object({ // const T = {
|
|
@@ -847,7 +861,7 @@ const U = Type.Strict(T) // const U = {
|
|
|
847
861
|
|
|
848
862
|
## Values
|
|
849
863
|
|
|
850
|
-
TypeBox provides an optional utility module that can be used to perform common operations on JavaScript values. This module includes functionality to create, check and cast values from types as well as check equality, clone, diff and patch JavaScript values. This module is provided via
|
|
864
|
+
TypeBox provides an optional utility module that can be used to perform common operations on JavaScript values. This module includes functionality to create, check and cast values from types as well as check equality, clone, diff and patch JavaScript values. This module is provided via optional import.
|
|
851
865
|
|
|
852
866
|
```typescript
|
|
853
867
|
import { Value } from '@sinclair/typebox/value'
|
|
@@ -1220,33 +1234,33 @@ This benchmark measures compilation performance for varying types. You can revie
|
|
|
1220
1234
|
┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┐
|
|
1221
1235
|
│ (index) │ Iterations │ Ajv │ TypeCompiler │ Performance │
|
|
1222
1236
|
├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┤
|
|
1223
|
-
│ Literal_String │ 1000 │ '
|
|
1224
|
-
│ Literal_Number │ 1000 │ ' 198 ms' │ '
|
|
1225
|
-
│ Literal_Boolean │ 1000 │ '
|
|
1226
|
-
│ Primitive_Number │ 1000 │ '
|
|
1227
|
-
│ Primitive_String │ 1000 │ '
|
|
1228
|
-
│
|
|
1229
|
-
│
|
|
1230
|
-
│
|
|
1231
|
-
│ Object_Unconstrained │ 1000 │ '
|
|
1232
|
-
│ Object_Constrained │ 1000 │ '
|
|
1233
|
-
│ Tuple_Primitive │ 1000 │ '
|
|
1234
|
-
│ Tuple_Object │ 1000 │ '
|
|
1235
|
-
│ Composite_Intersect │ 1000 │ '
|
|
1236
|
-
│ Composite_Union │ 1000 │ '
|
|
1237
|
-
│ Math_Vector4 │ 1000 │ '
|
|
1238
|
-
│ Math_Matrix4 │ 1000 │ '
|
|
1239
|
-
│ Array_Primitive_Number │ 1000 │ '
|
|
1240
|
-
│ Array_Primitive_String │ 1000 │ '
|
|
1241
|
-
│ Array_Primitive_Boolean │ 1000 │ '
|
|
1242
|
-
│ Array_Object_Unconstrained │ 1000 │ '
|
|
1243
|
-
│ Array_Object_Constrained │ 1000 │ '
|
|
1244
|
-
│ Array_Tuple_Primitive │ 1000 │ '
|
|
1245
|
-
│ Array_Tuple_Object │ 1000 │ '
|
|
1246
|
-
│ Array_Composite_Intersect │ 1000 │ '
|
|
1247
|
-
│ Array_Composite_Union │ 1000 │ '
|
|
1248
|
-
│ Array_Math_Vector4 │ 1000 │ '
|
|
1249
|
-
│ Array_Math_Matrix4 │ 1000 │ '
|
|
1237
|
+
│ Literal_String │ 1000 │ ' 260 ms' │ ' 8 ms' │ ' 32.50 x' │
|
|
1238
|
+
│ Literal_Number │ 1000 │ ' 198 ms' │ ' 4 ms' │ ' 49.50 x' │
|
|
1239
|
+
│ Literal_Boolean │ 1000 │ ' 185 ms' │ ' 5 ms' │ ' 37.00 x' │
|
|
1240
|
+
│ Primitive_Number │ 1000 │ ' 176 ms' │ ' 9 ms' │ ' 19.56 x' │
|
|
1241
|
+
│ Primitive_String │ 1000 │ ' 161 ms' │ ' 9 ms' │ ' 17.89 x' │
|
|
1242
|
+
│ Primitive_String_Pattern │ 1000 │ ' 215 ms' │ ' 12 ms' │ ' 17.92 x' │
|
|
1243
|
+
│ Primitive_Boolean │ 1000 │ ' 133 ms' │ ' 5 ms' │ ' 26.60 x' │
|
|
1244
|
+
│ Primitive_Null │ 1000 │ ' 143 ms' │ ' 8 ms' │ ' 17.88 x' │
|
|
1245
|
+
│ Object_Unconstrained │ 1000 │ ' 1181 ms' │ ' 38 ms' │ ' 31.08 x' │
|
|
1246
|
+
│ Object_Constrained │ 1000 │ ' 1168 ms' │ ' 32 ms' │ ' 36.50 x' │
|
|
1247
|
+
│ Tuple_Primitive │ 1000 │ ' 557 ms' │ ' 16 ms' │ ' 34.81 x' │
|
|
1248
|
+
│ Tuple_Object │ 1000 │ ' 1119 ms' │ ' 17 ms' │ ' 65.82 x' │
|
|
1249
|
+
│ Composite_Intersect │ 1000 │ ' 569 ms' │ ' 22 ms' │ ' 25.86 x' │
|
|
1250
|
+
│ Composite_Union │ 1000 │ ' 513 ms' │ ' 23 ms' │ ' 22.30 x' │
|
|
1251
|
+
│ Math_Vector4 │ 1000 │ ' 802 ms' │ ' 10 ms' │ ' 80.20 x' │
|
|
1252
|
+
│ Math_Matrix4 │ 1000 │ ' 395 ms' │ ' 12 ms' │ ' 32.92 x' │
|
|
1253
|
+
│ Array_Primitive_Number │ 1000 │ ' 282 ms' │ ' 8 ms' │ ' 35.25 x' │
|
|
1254
|
+
│ Array_Primitive_String │ 1000 │ ' 321 ms' │ ' 5 ms' │ ' 64.20 x' │
|
|
1255
|
+
│ Array_Primitive_Boolean │ 1000 │ ' 364 ms' │ ' 5 ms' │ ' 72.80 x' │
|
|
1256
|
+
│ Array_Object_Unconstrained │ 1000 │ ' 1573 ms' │ ' 18 ms' │ ' 87.39 x' │
|
|
1257
|
+
│ Array_Object_Constrained │ 1000 │ ' 1270 ms' │ ' 20 ms' │ ' 63.50 x' │
|
|
1258
|
+
│ Array_Tuple_Primitive │ 1000 │ ' 973 ms' │ ' 18 ms' │ ' 54.06 x' │
|
|
1259
|
+
│ Array_Tuple_Object │ 1000 │ ' 1253 ms' │ ' 16 ms' │ ' 78.31 x' │
|
|
1260
|
+
│ Array_Composite_Intersect │ 1000 │ ' 927 ms' │ ' 20 ms' │ ' 46.35 x' │
|
|
1261
|
+
│ Array_Composite_Union │ 1000 │ ' 1123 ms' │ ' 16 ms' │ ' 70.19 x' │
|
|
1262
|
+
│ Array_Math_Vector4 │ 1000 │ ' 1068 ms' │ ' 10 ms' │ ' 106.80 x' │
|
|
1263
|
+
│ Array_Math_Matrix4 │ 1000 │ ' 488 ms' │ ' 7 ms' │ ' 69.71 x' │
|
|
1250
1264
|
└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┘
|
|
1251
1265
|
```
|
|
1252
1266
|
|
|
@@ -1260,35 +1274,35 @@ This benchmark measures validation performance for varying types. You can review
|
|
|
1260
1274
|
┌────────────────────────────┬────────────┬──────────────┬──────────────┬──────────────┬──────────────┐
|
|
1261
1275
|
│ (index) │ Iterations │ ValueCheck │ Ajv │ TypeCompiler │ Performance │
|
|
1262
1276
|
├────────────────────────────┼────────────┼──────────────┼──────────────┼──────────────┼──────────────┤
|
|
1263
|
-
│ Literal_String │ 1000000 │ '
|
|
1264
|
-
│ Literal_Number │ 1000000 │ '
|
|
1277
|
+
│ Literal_String │ 1000000 │ ' 26 ms' │ ' 6 ms' │ ' 6 ms' │ ' 1.00 x' │
|
|
1278
|
+
│ Literal_Number │ 1000000 │ ' 21 ms' │ ' 19 ms' │ ' 11 ms' │ ' 1.73 x' │
|
|
1265
1279
|
│ Literal_Boolean │ 1000000 │ ' 19 ms' │ ' 18 ms' │ ' 10 ms' │ ' 1.80 x' │
|
|
1266
|
-
│ Primitive_Number │ 1000000 │ '
|
|
1267
|
-
│ Primitive_String │ 1000000 │ '
|
|
1268
|
-
│
|
|
1269
|
-
│
|
|
1270
|
-
│
|
|
1271
|
-
│ Object_Unconstrained │ 1000000 │ '
|
|
1272
|
-
│ Object_Constrained │ 1000000 │ '
|
|
1273
|
-
│ Object_Recursive │ 1000000 │ '
|
|
1274
|
-
│ Tuple_Primitive │ 1000000 │ '
|
|
1275
|
-
│ Tuple_Object │ 1000000 │ '
|
|
1276
|
-
│ Composite_Intersect │ 1000000 │ '
|
|
1277
|
-
│ Composite_Union │ 1000000 │ '
|
|
1278
|
-
│ Math_Vector4 │ 1000000 │ '
|
|
1279
|
-
│ Math_Matrix4 │ 1000000 │ '
|
|
1280
|
-
│ Array_Primitive_Number │ 1000000 │ '
|
|
1281
|
-
│ Array_Primitive_String │ 1000000 │ '
|
|
1282
|
-
│ Array_Primitive_Boolean │ 1000000 │ '
|
|
1283
|
-
│ Array_Object_Unconstrained │ 1000000 │ '
|
|
1284
|
-
│ Array_Object_Constrained │ 1000000 │ '
|
|
1285
|
-
│ Array_Object_Recursive │ 1000000 │ '
|
|
1286
|
-
│ Array_Tuple_Primitive │ 1000000 │ '
|
|
1287
|
-
│ Array_Tuple_Object │ 1000000 │ '
|
|
1288
|
-
│ Array_Composite_Intersect │ 1000000 │ '
|
|
1289
|
-
│ Array_Composite_Union │ 1000000 │ '
|
|
1290
|
-
│ Array_Math_Vector4 │ 1000000 │ '
|
|
1291
|
-
│ Array_Math_Matrix4 │ 1000000 │ '
|
|
1280
|
+
│ Primitive_Number │ 1000000 │ ' 24 ms' │ ' 19 ms' │ ' 11 ms' │ ' 1.73 x' │
|
|
1281
|
+
│ Primitive_String │ 1000000 │ ' 26 ms' │ ' 17 ms' │ ' 10 ms' │ ' 1.70 x' │
|
|
1282
|
+
│ Primitive_String_Pattern │ 1000000 │ ' 159 ms' │ ' 45 ms' │ ' 37 ms' │ ' 1.22 x' │
|
|
1283
|
+
│ Primitive_Boolean │ 1000000 │ ' 23 ms' │ ' 17 ms' │ ' 10 ms' │ ' 1.70 x' │
|
|
1284
|
+
│ Primitive_Null │ 1000000 │ ' 23 ms' │ ' 18 ms' │ ' 10 ms' │ ' 1.80 x' │
|
|
1285
|
+
│ Object_Unconstrained │ 1000000 │ ' 809 ms' │ ' 35 ms' │ ' 30 ms' │ ' 1.17 x' │
|
|
1286
|
+
│ Object_Constrained │ 1000000 │ ' 1060 ms' │ ' 56 ms' │ ' 45 ms' │ ' 1.24 x' │
|
|
1287
|
+
│ Object_Recursive │ 1000000 │ ' 4965 ms' │ ' 397 ms' │ ' 100 ms' │ ' 3.97 x' │
|
|
1288
|
+
│ Tuple_Primitive │ 1000000 │ ' 159 ms' │ ' 22 ms' │ ' 16 ms' │ ' 1.38 x' │
|
|
1289
|
+
│ Tuple_Object │ 1000000 │ ' 658 ms' │ ' 31 ms' │ ' 27 ms' │ ' 1.15 x' │
|
|
1290
|
+
│ Composite_Intersect │ 1000000 │ ' 695 ms' │ ' 26 ms' │ ' 22 ms' │ ' 1.18 x' │
|
|
1291
|
+
│ Composite_Union │ 1000000 │ ' 503 ms' │ ' 24 ms' │ ' 19 ms' │ ' 1.26 x' │
|
|
1292
|
+
│ Math_Vector4 │ 1000000 │ ' 259 ms' │ ' 22 ms' │ ' 14 ms' │ ' 1.57 x' │
|
|
1293
|
+
│ Math_Matrix4 │ 1000000 │ ' 1007 ms' │ ' 40 ms' │ ' 29 ms' │ ' 1.38 x' │
|
|
1294
|
+
│ Array_Primitive_Number │ 1000000 │ ' 262 ms' │ ' 23 ms' │ ' 17 ms' │ ' 1.35 x' │
|
|
1295
|
+
│ Array_Primitive_String │ 1000000 │ ' 241 ms' │ ' 27 ms' │ ' 24 ms' │ ' 1.13 x' │
|
|
1296
|
+
│ Array_Primitive_Boolean │ 1000000 │ ' 141 ms' │ ' 23 ms' │ ' 20 ms' │ ' 1.15 x' │
|
|
1297
|
+
│ Array_Object_Unconstrained │ 1000000 │ ' 4976 ms' │ ' 70 ms' │ ' 67 ms' │ ' 1.04 x' │
|
|
1298
|
+
│ Array_Object_Constrained │ 1000000 │ ' 5234 ms' │ ' 143 ms' │ ' 120 ms' │ ' 1.19 x' │
|
|
1299
|
+
│ Array_Object_Recursive │ 1000000 │ ' 19605 ms' │ ' 1909 ms' │ ' 350 ms' │ ' 5.45 x' │
|
|
1300
|
+
│ Array_Tuple_Primitive │ 1000000 │ ' 706 ms' │ ' 39 ms' │ ' 32 ms' │ ' 1.22 x' │
|
|
1301
|
+
│ Array_Tuple_Object │ 1000000 │ ' 2951 ms' │ ' 67 ms' │ ' 63 ms' │ ' 1.06 x' │
|
|
1302
|
+
│ Array_Composite_Intersect │ 1000000 │ ' 2969 ms' │ ' 49 ms' │ ' 44 ms' │ ' 1.11 x' │
|
|
1303
|
+
│ Array_Composite_Union │ 1000000 │ ' 2191 ms' │ ' 77 ms' │ ' 41 ms' │ ' 1.88 x' │
|
|
1304
|
+
│ Array_Math_Vector4 │ 1000000 │ ' 1164 ms' │ ' 41 ms' │ ' 25 ms' │ ' 1.64 x' │
|
|
1305
|
+
│ Array_Math_Matrix4 │ 1000000 │ ' 4903 ms' │ ' 115 ms' │ ' 99 ms' │ ' 1.16 x' │
|
|
1292
1306
|
└────────────────────────────┴────────────┴──────────────┴──────────────┴──────────────┴──────────────┘
|
|
1293
1307
|
```
|
|
1294
1308
|
|
|
@@ -1302,10 +1316,10 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
|
|
|
1302
1316
|
┌──────────────────────┬────────────┬────────────┬─────────────┐
|
|
1303
1317
|
│ (index) │ Compiled │ Minified │ Compression │
|
|
1304
1318
|
├──────────────────────┼────────────┼────────────┼─────────────┤
|
|
1305
|
-
│ typebox/compiler │ '108.
|
|
1306
|
-
│ typebox/errors │ '
|
|
1307
|
-
│ typebox/system │ '
|
|
1308
|
-
│ typebox/value │ '153.
|
|
1319
|
+
│ typebox/compiler │ '108.8 kb' │ ' 48.9 kb' │ '2.23 x' │
|
|
1320
|
+
│ typebox/errors │ ' 93.2 kb' │ ' 41.5 kb' │ '2.24 x' │
|
|
1321
|
+
│ typebox/system │ ' 60.0 kb' │ ' 24.6 kb' │ '2.43 x' │
|
|
1322
|
+
│ typebox/value │ '153.5 kb' │ ' 66.7 kb' │ '2.30 x' │
|
|
1309
1323
|
│ typebox │ ' 58.7 kb' │ ' 24.1 kb' │ '2.43 x' │
|
|
1310
1324
|
└──────────────────────┴────────────┴────────────┴─────────────┘
|
|
1311
1325
|
```
|
package/system/system.d.ts
CHANGED
|
@@ -17,4 +17,8 @@ export declare namespace TypeSystem {
|
|
|
17
17
|
function Type<Type, Options = object>(kind: string, check: (options: Options, value: unknown) => boolean): (options?: Partial<Options>) => Types.TUnsafe<Type>;
|
|
18
18
|
/** Creates a new string format */
|
|
19
19
|
function Format<F extends string>(format: F, check: (value: string) => boolean): F;
|
|
20
|
+
/** @deprecated Use `TypeSystem.Type()` instead. */
|
|
21
|
+
function CreateType<Type, Options = object>(kind: string, check: (options: Options, value: unknown) => boolean): (options?: Partial<Options>) => Types.TUnsafe<Type>;
|
|
22
|
+
/** @deprecated Use `TypeSystem.Format()` instead. */
|
|
23
|
+
function CreateFormat<F extends string>(format: F, check: (value: string) => boolean): F;
|
|
20
24
|
}
|
package/system/system.js
CHANGED
|
@@ -31,13 +31,13 @@ exports.TypeSystem = exports.TypeSystemDuplicateFormat = exports.TypeSystemDupli
|
|
|
31
31
|
const Types = require("../typebox");
|
|
32
32
|
class TypeSystemDuplicateTypeKind extends Error {
|
|
33
33
|
constructor(kind) {
|
|
34
|
-
super(`Duplicate kind '${kind}' detected`);
|
|
34
|
+
super(`Duplicate type kind '${kind}' detected`);
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
37
|
exports.TypeSystemDuplicateTypeKind = TypeSystemDuplicateTypeKind;
|
|
38
38
|
class TypeSystemDuplicateFormat extends Error {
|
|
39
39
|
constructor(kind) {
|
|
40
|
-
super(`Duplicate format '${kind}' detected`);
|
|
40
|
+
super(`Duplicate string format '${kind}' detected`);
|
|
41
41
|
}
|
|
42
42
|
}
|
|
43
43
|
exports.TypeSystemDuplicateFormat = TypeSystemDuplicateFormat;
|
|
@@ -66,4 +66,17 @@ var TypeSystem;
|
|
|
66
66
|
return format;
|
|
67
67
|
}
|
|
68
68
|
TypeSystem.Format = Format;
|
|
69
|
+
// ------------------------------------------------------------------------
|
|
70
|
+
// Deprecated
|
|
71
|
+
// ------------------------------------------------------------------------
|
|
72
|
+
/** @deprecated Use `TypeSystem.Type()` instead. */
|
|
73
|
+
function CreateType(kind, check) {
|
|
74
|
+
return Type(kind, check);
|
|
75
|
+
}
|
|
76
|
+
TypeSystem.CreateType = CreateType;
|
|
77
|
+
/** @deprecated Use `TypeSystem.Format()` instead. */
|
|
78
|
+
function CreateFormat(format, check) {
|
|
79
|
+
return Format(format, check);
|
|
80
|
+
}
|
|
81
|
+
TypeSystem.CreateFormat = CreateFormat;
|
|
69
82
|
})(TypeSystem = exports.TypeSystem || (exports.TypeSystem = {}));
|
package/typebox.d.ts
CHANGED
|
@@ -84,13 +84,15 @@ export interface TBoolean extends TSchema {
|
|
|
84
84
|
export type TConstructorParameters<T extends TConstructor<TSchema[], TSchema>> = TTuple<T['parameters']>;
|
|
85
85
|
export type TInstanceType<T extends TConstructor<TSchema[], TSchema>> = T['returns'];
|
|
86
86
|
export type TCompositeUnion<Left extends TSchema, Right extends TSchema> = Ensure<TUnion<[Left, Right]>>;
|
|
87
|
-
export type
|
|
88
|
-
[
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
export type
|
|
87
|
+
export type TCompositeUnionLeft<T extends TObject, Acc extends TProperties> = {
|
|
88
|
+
[K in keyof T['properties']]: K extends keyof Acc ? TCompositeUnion<T['properties'][K], Acc[K]> : T['properties'][K];
|
|
89
|
+
};
|
|
90
|
+
export type TCompositeUnionRight<T extends TObject, Acc extends TProperties> = {
|
|
91
|
+
[K in keyof Acc]: K extends keyof T['properties'] ? TCompositeUnion<T['properties'][K], Acc[K]> : Acc[K];
|
|
92
|
+
};
|
|
93
|
+
export type TCompositeUnionObject<T extends TObject, Acc extends TProperties> = Evaluate<TCompositeUnionLeft<T, Acc> & TCompositeUnionRight<T, Acc>>;
|
|
94
|
+
export type TCompositeProperties<T extends TObject[], Acc extends TProperties> = T extends [...infer L, infer R] ? TCompositeProperties<Assert<L, TObject[]>, TCompositeUnionObject<Assert<R, TObject>, Acc>> : T extends [] ? Acc : never;
|
|
95
|
+
export type TComposite<T extends TObject[] = TObject[]> = Ensure<TObject<TCompositeProperties<T, {}>>>;
|
|
94
96
|
export type TConstructorParameterArray<T extends readonly TSchema[], P extends unknown[]> = [...{
|
|
95
97
|
[K in keyof T]: Static<Assert<T[K], TSchema>, P>;
|
|
96
98
|
}];
|
|
@@ -382,11 +384,12 @@ export interface TVoid extends TSchema {
|
|
|
382
384
|
type: 'null';
|
|
383
385
|
typeOf: 'Void';
|
|
384
386
|
}
|
|
385
|
-
/** Creates a static type from a TypeBox type */
|
|
387
|
+
/** Creates a TypeScript static type from a TypeBox type */
|
|
386
388
|
export type Static<T extends TSchema, P extends unknown[] = []> = (T & {
|
|
387
389
|
params: P;
|
|
388
390
|
})['static'];
|
|
389
391
|
export type TypeRegistryValidationFunction<TSchema> = (schema: TSchema, value: unknown) => boolean;
|
|
392
|
+
/** A registry for user defined types */
|
|
390
393
|
export declare namespace TypeRegistry {
|
|
391
394
|
/** Returns the entries in this registry */
|
|
392
395
|
function Entries(): Map<string, TypeRegistryValidationFunction<any>>;
|
|
@@ -400,7 +403,7 @@ export declare namespace TypeRegistry {
|
|
|
400
403
|
function Get(kind: string): TypeRegistryValidationFunction<any> | undefined;
|
|
401
404
|
}
|
|
402
405
|
export type FormatRegistryValidationFunction = (value: string) => boolean;
|
|
403
|
-
/**
|
|
406
|
+
/** A registry for user defined string formats */
|
|
404
407
|
export declare namespace FormatRegistry {
|
|
405
408
|
/** Returns the entries in this registry */
|
|
406
409
|
function Entries(): Map<string, FormatRegistryValidationFunction>;
|
|
@@ -417,6 +420,7 @@ export declare class TypeGuardUnknownTypeError extends Error {
|
|
|
417
420
|
readonly schema: unknown;
|
|
418
421
|
constructor(schema: unknown);
|
|
419
422
|
}
|
|
423
|
+
/** Provides functions to test if JavaScript values are TypeBox types */
|
|
420
424
|
export declare namespace TypeGuard {
|
|
421
425
|
/** Returns true if the given schema is TAny */
|
|
422
426
|
function TAny(schema: unknown): schema is TAny;
|
|
@@ -527,9 +531,7 @@ export declare class StandardTypeBuilder extends TypeBuilder {
|
|
|
527
531
|
Array<T extends TSchema>(items: T, options?: ArrayOptions): TArray<T>;
|
|
528
532
|
/** `[Standard]` Creates a Boolean type */
|
|
529
533
|
Boolean(options?: SchemaOptions): TBoolean;
|
|
530
|
-
/** `[Standard]` Creates a Composite object type that will
|
|
531
|
-
Composite<T extends TIntersect<TObject[]>>(schema: T, options?: ObjectOptions): TComposite<T['allOf']>;
|
|
532
|
-
/** `[Standard]` Creates a Composite object type that will Union any overlapping properties of the given Object array */
|
|
534
|
+
/** `[Standard]` Creates a Composite object type that will union any overlapping properties of the given object array */
|
|
533
535
|
Composite<T extends TObject[]>(schemas: [...T], options?: ObjectOptions): TComposite<T>;
|
|
534
536
|
/** `[Standard]` Creates a Enum type */
|
|
535
537
|
Enum<T extends Record<string, string | number>>(item: T, options?: SchemaOptions): TEnum<T>;
|
package/typebox.js
CHANGED
|
@@ -34,6 +34,7 @@ exports.Type = exports.StandardType = exports.ExtendedTypeBuilder = exports.Stan
|
|
|
34
34
|
exports.Modifier = Symbol.for('TypeBox.Modifier');
|
|
35
35
|
exports.Hint = Symbol.for('TypeBox.Hint');
|
|
36
36
|
exports.Kind = Symbol.for('TypeBox.Kind');
|
|
37
|
+
/** A registry for user defined types */
|
|
37
38
|
var TypeRegistry;
|
|
38
39
|
(function (TypeRegistry) {
|
|
39
40
|
const map = new Map();
|
|
@@ -63,7 +64,7 @@ var TypeRegistry;
|
|
|
63
64
|
}
|
|
64
65
|
TypeRegistry.Get = Get;
|
|
65
66
|
})(TypeRegistry = exports.TypeRegistry || (exports.TypeRegistry = {}));
|
|
66
|
-
/**
|
|
67
|
+
/** A registry for user defined string formats */
|
|
67
68
|
var FormatRegistry;
|
|
68
69
|
(function (FormatRegistry) {
|
|
69
70
|
const map = new Map();
|
|
@@ -103,6 +104,7 @@ class TypeGuardUnknownTypeError extends Error {
|
|
|
103
104
|
}
|
|
104
105
|
}
|
|
105
106
|
exports.TypeGuardUnknownTypeError = TypeGuardUnknownTypeError;
|
|
107
|
+
/** Provides functions to test if JavaScript values are TypeBox types */
|
|
106
108
|
var TypeGuard;
|
|
107
109
|
(function (TypeGuard) {
|
|
108
110
|
function IsObject(value) {
|
|
@@ -1463,20 +1465,12 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
1463
1465
|
Boolean(options = {}) {
|
|
1464
1466
|
return this.Create({ ...options, [exports.Kind]: 'Boolean', type: 'boolean' });
|
|
1465
1467
|
}
|
|
1466
|
-
Composite
|
|
1467
|
-
|
|
1468
|
-
const optional = new Set();
|
|
1469
|
-
for (const schema of schemas) {
|
|
1470
|
-
for (const [key, property] of globalThis.Object.entries(schema.properties)) {
|
|
1471
|
-
if (TypeGuard.TOptional(property) || TypeGuard.TReadonlyOptional(property))
|
|
1472
|
-
optional.add(key);
|
|
1473
|
-
}
|
|
1474
|
-
}
|
|
1468
|
+
/** `[Standard]` Creates a Composite object type that will union any overlapping properties of the given object array */
|
|
1469
|
+
Composite(schemas, options) {
|
|
1475
1470
|
const properties = {};
|
|
1476
1471
|
for (const object of schemas) {
|
|
1477
1472
|
for (const [key, property] of globalThis.Object.entries(object.properties)) {
|
|
1478
|
-
|
|
1479
|
-
properties[key] = optional.has(key) ? this.Optional(mapped) : mapped;
|
|
1473
|
+
properties[key] = key in properties ? this.Union([properties[key], property]) : TypeClone.Clone(property, {});
|
|
1480
1474
|
}
|
|
1481
1475
|
}
|
|
1482
1476
|
return this.Object(properties, options);
|
package/value/value.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import * as Types from '../typebox';
|
|
2
|
-
import {
|
|
2
|
+
import { ValueErrorIterator } from '../errors/index';
|
|
3
3
|
import { Edit } from './delta';
|
|
4
4
|
/** Provides functions to perform structural updates to JavaScript values */
|
|
5
5
|
export declare namespace Value {
|
|
@@ -16,15 +16,15 @@ export declare namespace Value {
|
|
|
16
16
|
/** Returns true if the value matches the given type. */
|
|
17
17
|
function Check<T extends Types.TSchema>(schema: T, value: unknown): value is Types.Static<T>;
|
|
18
18
|
/** Converts any type mismatched values to their target type if a conversion is possible. */
|
|
19
|
-
function Convert<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown):
|
|
19
|
+
function Convert<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown): unknown;
|
|
20
20
|
/** Converts any type mismatched values to their target type if a conversion is possible. */
|
|
21
|
-
function Convert<T extends Types.TSchema>(schema: T, value: unknown):
|
|
21
|
+
function Convert<T extends Types.TSchema>(schema: T, value: unknown): unknown;
|
|
22
22
|
/** Returns a structural clone of the given value */
|
|
23
23
|
function Clone<T>(value: T): T;
|
|
24
24
|
/** Returns an iterator for each error in this value. */
|
|
25
|
-
function Errors<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown):
|
|
25
|
+
function Errors<T extends Types.TSchema, R extends Types.TSchema[]>(schema: T, references: [...R], value: unknown): ValueErrorIterator;
|
|
26
26
|
/** Returns an iterator for each error in this value. */
|
|
27
|
-
function Errors<T extends Types.TSchema>(schema: T, value: unknown):
|
|
27
|
+
function Errors<T extends Types.TSchema>(schema: T, value: unknown): ValueErrorIterator;
|
|
28
28
|
/** Returns true if left and right values are structurally equal */
|
|
29
29
|
function Equal<T>(left: T, right: unknown): right is T;
|
|
30
30
|
/** Returns edits to transform the current value into the next value */
|
package/value/value.js
CHANGED
|
@@ -65,9 +65,9 @@ var Value;
|
|
|
65
65
|
return clone_1.ValueClone.Clone(value);
|
|
66
66
|
}
|
|
67
67
|
Value.Clone = Clone;
|
|
68
|
-
function
|
|
68
|
+
function Errors(...args) {
|
|
69
69
|
const [schema, references, value] = args.length === 3 ? [args[0], args[1], args[2]] : [args[0], [], args[1]];
|
|
70
|
-
|
|
70
|
+
return index_1.ValueErrors.Errors(schema, references, value);
|
|
71
71
|
}
|
|
72
72
|
Value.Errors = Errors;
|
|
73
73
|
/** Returns true if left and right values are structurally equal */
|