@sinclair/typebox 0.34.16 → 0.34.18
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/build/cjs/compiler/compiler.js +5 -0
- package/build/cjs/errors/errors.js +3 -0
- package/build/cjs/index.d.ts +3 -0
- package/build/cjs/index.js +3 -0
- package/build/cjs/syntax/runtime.d.ts +3 -1
- package/build/cjs/syntax/runtime.js +33 -3
- package/build/cjs/syntax/static.d.ts +22 -2
- package/build/cjs/type/argument/argument.d.ts +9 -0
- package/build/cjs/type/argument/argument.js +10 -0
- package/build/cjs/type/argument/index.d.ts +1 -0
- package/build/cjs/type/argument/index.js +18 -0
- package/build/cjs/type/guard/kind.d.ts +9 -6
- package/build/cjs/type/guard/kind.js +6 -0
- package/build/cjs/type/guard/type.d.ts +9 -6
- package/build/cjs/type/guard/type.js +9 -0
- package/build/cjs/type/index.d.ts +2 -0
- package/build/cjs/type/index.js +2 -0
- package/build/cjs/type/instantiate/index.d.ts +1 -0
- package/build/cjs/type/instantiate/index.js +18 -0
- package/build/cjs/type/instantiate/instantiate.d.ts +25 -0
- package/build/cjs/type/instantiate/instantiate.js +32 -0
- package/build/cjs/type/record/record.d.ts +16 -1
- package/build/cjs/type/record/record.js +53 -23
- package/build/cjs/type/remap/index.d.ts +1 -0
- package/build/cjs/type/remap/index.js +18 -0
- package/build/cjs/type/remap/remap.d.ts +30 -0
- package/build/cjs/type/remap/remap.js +47 -0
- package/build/cjs/type/type/javascript.d.ts +6 -0
- package/build/cjs/type/type/javascript.js +44 -34
- package/build/cjs/type/type/type.d.ts +3 -0
- package/build/cjs/type/type/type.js +123 -117
- package/build/cjs/value/check/check.js +5 -0
- package/build/cjs/value/create/create.js +5 -0
- package/build/esm/compiler/compiler.mjs +5 -0
- package/build/esm/errors/errors.mjs +3 -0
- package/build/esm/index.d.mts +3 -0
- package/build/esm/index.mjs +3 -0
- package/build/esm/syntax/runtime.d.mts +3 -1
- package/build/esm/syntax/runtime.mjs +33 -3
- package/build/esm/syntax/static.d.mts +22 -2
- package/build/esm/type/argument/argument.d.mts +9 -0
- package/build/esm/type/argument/argument.mjs +6 -0
- package/build/esm/type/argument/index.d.mts +1 -0
- package/build/esm/type/argument/index.mjs +1 -0
- package/build/esm/type/guard/kind.d.mts +9 -6
- package/build/esm/type/guard/kind.mjs +5 -0
- package/build/esm/type/guard/type.d.mts +9 -6
- package/build/esm/type/guard/type.mjs +8 -0
- package/build/esm/type/index.d.mts +2 -0
- package/build/esm/type/index.mjs +2 -0
- package/build/esm/type/instantiate/index.d.mts +1 -0
- package/build/esm/type/instantiate/index.mjs +1 -0
- package/build/esm/type/instantiate/instantiate.d.mts +25 -0
- package/build/esm/type/instantiate/instantiate.mjs +28 -0
- package/build/esm/type/record/record.d.mts +16 -1
- package/build/esm/type/record/record.mjs +35 -8
- package/build/esm/type/remap/index.d.mts +1 -0
- package/build/esm/type/remap/index.mjs +1 -0
- package/build/esm/type/remap/remap.d.mts +30 -0
- package/build/esm/type/remap/remap.mjs +43 -0
- package/build/esm/type/type/javascript.d.mts +6 -0
- package/build/esm/type/type/javascript.mjs +10 -0
- package/build/esm/type/type/type.d.mts +3 -0
- package/build/esm/type/type/type.mjs +3 -0
- package/build/esm/value/check/check.mjs +5 -0
- package/build/esm/value/create/create.mjs +5 -0
- package/package.json +1 -1
- package/readme.md +36 -39
package/readme.md
CHANGED
|
@@ -731,46 +731,42 @@ Object properties can be modified with Readonly and Optional. The following tabl
|
|
|
731
731
|
|
|
732
732
|
### Generic Types
|
|
733
733
|
|
|
734
|
-
Generic types can be created with
|
|
734
|
+
Generic types can be created with generic functions
|
|
735
735
|
|
|
736
736
|
```typescript
|
|
737
|
-
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
Type.Object({ // type Vector<T> = {
|
|
741
|
-
x: T, // x: T,
|
|
742
|
-
y: T, // y: T,
|
|
743
|
-
z: T // z: T
|
|
744
|
-
}) // }
|
|
737
|
+
const Nullable = <T extends TSchema>(T: T) => { // type Nullable<T> = T | null
|
|
738
|
+
return Type.Union([T, Type.Null())
|
|
739
|
+
}
|
|
745
740
|
|
|
746
|
-
const
|
|
741
|
+
const T = Nullable(Type.String()) // type T = Nullable<string>
|
|
747
742
|
```
|
|
748
743
|
|
|
749
|
-
Generic types
|
|
744
|
+
Generic types can also be created with Argument types
|
|
750
745
|
|
|
751
746
|
```typescript
|
|
752
|
-
const
|
|
753
|
-
|
|
754
|
-
|
|
755
|
-
|
|
756
|
-
|
|
757
|
-
|
|
758
|
-
|
|
759
|
-
|
|
760
|
-
|
|
761
|
-
|
|
747
|
+
const Vector = Type.Object({ // type Vector<A_0, A_1, A_2> = {
|
|
748
|
+
x: Type.Argument(0), // x: A_0,
|
|
749
|
+
y: Type.Argument(1), // y: A_1,
|
|
750
|
+
z: Type.Argument(2), // z: A_2
|
|
751
|
+
}) // }
|
|
752
|
+
|
|
753
|
+
const T = Type.Instantiate(Vector, [ // type T = Vector<
|
|
754
|
+
Type.Boolean(), // boolean,
|
|
755
|
+
Type.Number(), // number,
|
|
756
|
+
Type.String() // string
|
|
757
|
+
]) // >
|
|
762
758
|
```
|
|
763
759
|
|
|
764
760
|
<a name='types-recursive'></a>
|
|
765
761
|
|
|
766
762
|
### Recursive Types
|
|
767
763
|
|
|
768
|
-
Use the Recursive function to create
|
|
764
|
+
Use the Recursive function to create recursive types
|
|
769
765
|
|
|
770
766
|
```typescript
|
|
771
|
-
const Node = Type.Recursive(
|
|
767
|
+
const Node = Type.Recursive(This => Type.Object({ // const Node = {
|
|
772
768
|
id: Type.String(), // $id: 'Node',
|
|
773
|
-
nodes: Type.Array(
|
|
769
|
+
nodes: Type.Array(This) // type: 'object',
|
|
774
770
|
}), { $id: 'Node' }) // properties: {
|
|
775
771
|
// id: {
|
|
776
772
|
// type: 'string'
|
|
@@ -1394,28 +1390,27 @@ const S = Syntax({ T }, `{ x: T, y: T, z: T }`) // const S: TObject<{
|
|
|
1394
1390
|
|
|
1395
1391
|
### Generics
|
|
1396
1392
|
|
|
1397
|
-
Generic
|
|
1393
|
+
Generic types can be created by passing Argument types as parameters.
|
|
1398
1394
|
|
|
1399
1395
|
```typescript
|
|
1400
|
-
// Generic
|
|
1401
|
-
|
|
1402
|
-
const Vector =
|
|
1403
|
-
x:
|
|
1404
|
-
y:
|
|
1405
|
-
z:
|
|
1396
|
+
// Generic Vector Type
|
|
1397
|
+
|
|
1398
|
+
const Vector = Syntax({ // type Vector<X, Y, Z> = {
|
|
1399
|
+
X: Type.Argument(0), // x: X
|
|
1400
|
+
Y: Type.Argument(1), // y: Y,
|
|
1401
|
+
Z: Type.Argument(2) // z: Z
|
|
1402
|
+
}, // }
|
|
1403
|
+
`{
|
|
1404
|
+
x: X,
|
|
1405
|
+
y: Y,
|
|
1406
|
+
z: Z
|
|
1406
1407
|
}`)
|
|
1407
1408
|
|
|
1409
|
+
// Instanced Vector Type
|
|
1408
1410
|
|
|
1409
|
-
|
|
1410
|
-
|
|
1411
|
-
const NumberVector = Vector('number') // const NumberVector: TObject<{
|
|
1412
|
-
// x: TNumber,
|
|
1413
|
-
// y: TNumber,
|
|
1414
|
-
// z: TNumber
|
|
1415
|
-
// }>
|
|
1411
|
+
const Up = Syntax({ Vector }, `Vector<0, 1, 0>`) // type Up = Vector<0, 1, 0>
|
|
1416
1412
|
```
|
|
1417
1413
|
|
|
1418
|
-
|
|
1419
1414
|
<a name='typeregistry'></a>
|
|
1420
1415
|
|
|
1421
1416
|
## TypeRegistry
|
|
@@ -1704,8 +1699,10 @@ The following is a list of community packages that offer general tooling, extend
|
|
|
1704
1699
|
| [schema2typebox](https://github.com/xddq/schema2typebox) | Creating TypeBox code from Json Schemas |
|
|
1705
1700
|
| [sveltekit-superforms](https://github.com/ciscoheat/sveltekit-superforms) | A comprehensive SvelteKit form library for server and client validation |
|
|
1706
1701
|
| [ts2typebox](https://github.com/xddq/ts2typebox) | Creating TypeBox code from Typescript types |
|
|
1702
|
+
| [typebox-cli](https://github.com/gsuess/typebox-cli) | Generate Schema with typebox from the CLI |
|
|
1707
1703
|
| [typebox-form-parser](https://github.com/jtlapp/typebox-form-parser) | Parses form and query data based on TypeBox schemas |
|
|
1708
1704
|
|
|
1705
|
+
|
|
1709
1706
|
<a name='benchmark'></a>
|
|
1710
1707
|
|
|
1711
1708
|
## Benchmark
|