Skip to content

Commit 6489b4c

Browse files
committed
Documentation
1 parent 3d9dfe7 commit 6489b4c

File tree

16 files changed

+11075
-202
lines changed

16 files changed

+11075
-202
lines changed

changelog/1.0.0-migration.md

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,16 +84,20 @@ The following implements Uint8Array using Type.Base.
8484
```typescript
8585
import Type from 'typebox'
8686

87-
// Definition
8887
export class TUint8Array extends Type.Base<Uint8Array> {
88+
// required: Used by validation
8989
public override Check(value: unknown): value is Uint8Array {
9090
return value instanceof Uint8Array
9191
}
92+
// required: Used by validation
9293
public override Errors(value: unknown): object[] {
93-
return !this.Check(value) ? [{ message: 'Not a Uint8Array'}] : []
94+
return !this.Check(value) ? [{ message: 'not a Uint8Array'}] : []
95+
}
96+
// required: Used by type compositor
97+
public override Clone(): TUint8Array {
98+
return new TUint8Array()
9499
}
95100
}
96-
// Factory
97101
export function Uint8Array(): TUint8Array {
98102
return new TUint8Array()
99103
}

design/website/docs/compile/overview.md

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -4,17 +4,15 @@ High Performance Runtime Validation
44

55
## Overview
66

7-
The TypeBox Compile module provides functions to convert types into high-performance validators. The compiler is tuned for fast compilation as well as fast validation.
8-
9-
The Compile module is available via optional import.
7+
The Compile module is a high-performance JIT compiler that transforms types into efficient runtime validators. The compiler is optimized for both fast compilation and validation.
108

119
```typescript
1210
import { Compile } from 'typebox/compile'
1311
```
1412

1513
### Example
1614

17-
The following uses the Compile module to Check and Parse a value.
15+
The following uses the compiler to Compile and Parse a value.
1816

1917
```typescript
2018
const C = Compile(Type.Object({ // const C: Validator<{}, TObject<{
@@ -23,19 +21,9 @@ const C = Compile(Type.Object({ // const C: Validator<{}, TO
2321
z: Type.Number() // z: TNumber
2422
})) // }>>
2523

26-
// Check
27-
28-
const A = C.Check({ // const A: boolean = true
29-
x: 1,
30-
y: 2,
31-
z: 3
32-
})
33-
34-
// Parse
35-
36-
const B = C.Parse({ // const B: {
37-
x: 1, // x: number,
38-
y: 2, // y: number,
39-
z: 3 // z: number
24+
const A = C.Parse({ // const A: {
25+
x: 0, // x: number,
26+
y: 1, // y: number,
27+
z: 0 // z: number
4028
}) // } = ...
4129
```
Lines changed: 27 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,45 @@
11
# Script
22

3-
Parse TypeScript into Json Schema
3+
TypeScript Scripting Engine
44

55
## Overview
66

7-
TypeBox can parse TypeScript syntax into Json Schema. The Script function is designed to be syntactic frontend to the TypeBox type builder API, enabling Json Schema to be both constructed and mapped using TypeScript type expressions encoded in template literal strings.
8-
9-
### Example
10-
11-
The following uses Script to construct and map Json Schema.
7+
TypeBox includes a TypeScript scripting engine able to parse TypeScript types directly into Json Schema. The engine uses symmetric runtime and type-level parsing and returns typed safe schematics from TypeScript types (including computed types). The engine is designed for TypeScript 7 native compiler but is supported in TypeScript 5 and above.
128

139
```typescript
14-
import Type from 'typebox'
10+
// Scripted Type
1511

1612
const T = Type.Script(`{
1713
x: number,
18-
y: number,
19-
z: number
20-
}`) // const T = {
21-
// type: 'object',
22-
// required: ['x', 'y', 'z'],
23-
// properties: {
24-
// x: { type: 'number' },
25-
// y: { type: 'number' },
26-
// z: { type: 'number' }
27-
// }
28-
// }
14+
y: string,
15+
z: boolean
16+
}`) // const T: TObject<{
17+
// x: TNumber,
18+
// y: TString,
19+
// z: TBoolean
20+
// }>
21+
22+
// Json Schema Introspection
23+
24+
T.type // 'object'
25+
T.required // ['x', 'y', 'z']
26+
T.properties // { x: ..., y: ..., z: ... }
27+
28+
// Scripted Type (Computed)
2929

3030
const S = Type.Script({ T }, `{
3131
[K in keyof T]: T[K] | null
32-
}`) // const S = {
33-
// type: 'object',
34-
// required: ['x', 'y', 'z'],
35-
// properties: {
36-
// x: {
37-
// anyOf: [
38-
// { type: 'number' },
39-
// { type: 'null' }
40-
// ]
41-
// },
42-
// y: {
43-
// anyOf: [
44-
// { type: 'number' },
45-
// { type: 'null' }
46-
// ]
47-
// },
48-
// z: {
49-
// anyOf: [
50-
// { type: 'number' },
51-
// { type: 'null' }
52-
// ]
53-
// },
54-
// }
55-
// }
32+
}`) // const S: TObject<{
33+
// x: TUnion<[TNumber, TNull]>,
34+
// y: TUnion<[TString, TNull]>,
35+
// z: TUnion<[TBoolean, TNull]>
36+
// }>
37+
38+
// Standard Inference
5639

5740
type S = Type.Static<typeof S> // type S = {
5841
// x: number | null,
59-
// y: number | null,
60-
// z: number | null
42+
// y: string | null,
43+
// z: boolean | null
6144
// }
6245
```
Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,18 @@
11
# Value
22

3-
Check, Decode and Parse JavaScript Values
3+
Check and Parse JavaScript Values
44

55
## Overview
66

7-
The TypeBox Value module provides functions to Check and Parse JavaScript values. It also includes functions such as Clone, Repair, Encode, Decode, Diff and Patch which perform various structural operations on JavaScript values.
8-
9-
The Value module is available via optional import.
7+
The Value module provides functions that perform typed operations on JavaScript values. It includes functions such as Check, Parse, Clone, Encode, Decode and as well as advanced functions to perform structural Diff and Patch on dynamic JavaScript values.
108

119
```typescript
1210
import Value from 'typebox/value'
1311
```
1412

1513
### Example
1614

17-
The following uses the Value module to Check and Parse a value.
15+
The following uses the Value module to Parse a value.
1816

1917
```typescript
2018
const T = Type.Object({
@@ -23,19 +21,9 @@ const T = Type.Object({
2321
z: Type.Number()
2422
})
2523

26-
// Check
27-
28-
const A = Value.Check(T, { // const A: boolean = true
29-
x: 1,
30-
y: 2,
31-
z: 3
32-
})
33-
34-
// Parse
35-
36-
const B = Value.Parse(T, { // const B: {
24+
const A = Value.Parse(T, { // const A: {
3725
x: 1, // x: number,
38-
y: 2, // y: number,
39-
z: 3 // z: number
26+
y: 0, // y: number,
27+
z: 0 // z: number
4028
}) // } = ...
4129
```

docs/docs/compile/overview.html

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
11
<h1>Compile</h1>
22
<p>High Performance Runtime Validation</p>
33
<h2>Overview</h2>
4-
<p>The TypeBox Compile module provides functions to convert types into high-performance validators. The compiler is tuned for fast compilation as well as fast validation.</p>
5-
<p>The Compile module is available via optional import.</p>
4+
<p>The Compile module is a high-performance JIT compiler that transforms types into efficient runtime validators. The compiler is optimized for both fast compilation and validation.</p>
65
<pre><code class="language-typescript">import { Compile } from &#39;typebox/compile&#39;
76
</code></pre>
87
<h3>Example</h3>
9-
<p>The following uses the Compile module to Check and Parse a value. </p>
8+
<p>The following uses the compiler to Compile and Parse a value. </p>
109
<pre><code class="language-typescript">const C = Compile(Type.Object({ // const C: Validator&lt;{}, TObject&lt;{
1110
x: Type.Number(), // x: TNumber,
1211
y: Type.Number(), // y: TNumber,
1312
z: Type.Number() // z: TNumber
1413
})) // }&gt;&gt;
1514

16-
// Check
17-
18-
const A = C.Check({ // const A: boolean = true
19-
x: 1,
20-
y: 2,
21-
z: 3
22-
})
23-
24-
// Parse
25-
26-
const B = C.Parse({ // const B: {
27-
x: 1, // x: number,
28-
y: 2, // y: number,
29-
z: 3 // z: number
15+
const A = C.Parse({ // const A: {
16+
x: 0, // x: number,
17+
y: 1, // y: number,
18+
z: 0 // z: number
3019
}) // } = ...
3120
</code></pre>

docs/docs/script/overview.html

Lines changed: 27 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,40 @@
11
<h1>Script</h1>
2-
<p>Parse TypeScript into Json Schema</p>
2+
<p>TypeScript Scripting Engine</p>
33
<h2>Overview</h2>
4-
<p>TypeBox can parse TypeScript syntax into Json Schema. The Script function is designed to be syntactic frontend to the TypeBox type builder API, enabling Json Schema to be both constructed and mapped using TypeScript type expressions encoded in template literal strings.</p>
5-
<h3>Example</h3>
6-
<p>The following uses Script to construct and map Json Schema.</p>
7-
<pre><code class="language-typescript">import Type from &#39;typebox&#39;
4+
<p>TypeBox includes a TypeScript scripting engine able to parse TypeScript types directly into Json Schema. The engine uses symmetric runtime and type-level parsing and returns typed safe schematics from TypeScript types (including computed types). The engine is designed for TypeScript 7 native compiler but is supported in TypeScript 5 and above.</p>
5+
<pre><code class="language-typescript">// Scripted Type
86

97
const T = Type.Script(`{
108
x: number,
11-
y: number,
12-
z: number
13-
}`) // const T = {
14-
// type: &#39;object&#39;,
15-
// required: [&#39;x&#39;, &#39;y&#39;, &#39;z&#39;],
16-
// properties: {
17-
// x: { type: &#39;number&#39; },
18-
// y: { type: &#39;number&#39; },
19-
// z: { type: &#39;number&#39; }
20-
// }
21-
// }
9+
y: string,
10+
z: boolean
11+
}`) // const T: TObject&lt;{
12+
// x: TNumber,
13+
// y: TString,
14+
// z: TBoolean
15+
// }&gt;
16+
17+
// Json Schema Introspection
18+
19+
T.type // &#39;object&#39;
20+
T.required // [&#39;x&#39;, &#39;y&#39;, &#39;z&#39;]
21+
T.properties // { x: ..., y: ..., z: ... }
22+
23+
// Scripted Type (Computed)
2224

2325
const S = Type.Script({ T }, `{
2426
[K in keyof T]: T[K] | null
25-
}`) // const S = {
26-
// type: &#39;object&#39;,
27-
// required: [&#39;x&#39;, &#39;y&#39;, &#39;z&#39;],
28-
// properties: {
29-
// x: {
30-
// anyOf: [
31-
// { type: &#39;number&#39; },
32-
// { type: &#39;null&#39; }
33-
// ]
34-
// },
35-
// y: {
36-
// anyOf: [
37-
// { type: &#39;number&#39; },
38-
// { type: &#39;null&#39; }
39-
// ]
40-
// },
41-
// z: {
42-
// anyOf: [
43-
// { type: &#39;number&#39; },
44-
// { type: &#39;null&#39; }
45-
// ]
46-
// },
47-
// }
48-
// }
27+
}`) // const S: TObject&lt;{
28+
// x: TUnion&lt;[TNumber, TNull]&gt;,
29+
// y: TUnion&lt;[TString, TNull]&gt;,
30+
// z: TUnion&lt;[TBoolean, TNull]&gt;
31+
// }&gt;
32+
33+
// Standard Inference
4934

5035
type S = Type.Static&lt;typeof S&gt; // type S = {
5136
// x: number | null,
52-
// y: number | null,
53-
// z: number | null
37+
// y: string | null,
38+
// z: boolean | null
5439
// }
5540
</code></pre>

docs/docs/value/overview.html

Lines changed: 6 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,20 @@
11
<h1>Value</h1>
2-
<p>Check, Decode and Parse JavaScript Values</p>
2+
<p>Check and Parse JavaScript Values</p>
33
<h2>Overview</h2>
4-
<p>The TypeBox Value module provides functions to Check and Parse JavaScript values. It also includes functions such as Clone, Repair, Encode, Decode, Diff and Patch which perform various structural operations on JavaScript values.</p>
5-
<p>The Value module is available via optional import.</p>
4+
<p>The Value module provides functions that perform typed operations on JavaScript values. It includes functions such as Check, Parse, Clone, Encode, Decode and as well as advanced functions to perform structural Diff and Patch on dynamic JavaScript values.</p>
65
<pre><code class="language-typescript">import Value from &#39;typebox/value&#39;
76
</code></pre>
87
<h3>Example</h3>
9-
<p>The following uses the Value module to Check and Parse a value. </p>
8+
<p>The following uses the Value module to Parse a value. </p>
109
<pre><code class="language-typescript">const T = Type.Object({
1110
x: Type.Number(),
1211
y: Type.Number(),
1312
z: Type.Number()
1413
})
1514

16-
// Check
17-
18-
const A = Value.Check(T, { // const A: boolean = true
19-
x: 1,
20-
y: 2,
21-
z: 3
22-
})
23-
24-
// Parse
25-
26-
const B = Value.Parse(T, { // const B: {
15+
const A = Value.Parse(T, { // const A: {
2716
x: 1, // x: number,
28-
y: 2, // y: number,
29-
z: 3 // z: number
17+
y: 0, // y: number,
18+
z: 0 // z: number
3019
}) // } = ...
3120
</code></pre>

example/legacy/date.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,12 +32,19 @@ import Type from 'typebox'
3232
// Definition
3333
// ------------------------------------------------------------------
3434
export class TDate extends Type.Base<globalThis.Date> {
35+
// required: Used by validation
3536
public override Check(value: unknown): value is globalThis.Date {
3637
return value instanceof globalThis.Date
3738
}
39+
// required: Used by validation
3840
public override Errors(value: unknown): object[] {
3941
return this.Check(value) ? [] : [{ message: 'must be Date' }]
4042
}
43+
// required: Used by type compositor
44+
public override Clone(): TDate {
45+
return new TDate()
46+
}
47+
// required: Used by value/create
4148
public override Create(): globalThis.Date {
4249
return new globalThis.Date(0)
4350
}

0 commit comments

Comments
 (0)