Skip to content

Commit ec89f05

Browse files
committed
Documentation
1 parent 706a2bb commit ec89f05

12 files changed

Lines changed: 72 additions & 33 deletions

File tree

design/website/docs/overview/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# TypeBox
22

3-
A Runtime Type System for JavaScript
3+
Json Schema Type Builder with Static Type Resolution for TypeScript
44

55
## Overview
66

design/website/docs/script/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Script
22

3-
A TypeScript Engine for JavaScript
3+
TypeScript Runtime Scripting Engine
44

55
## Overview
66

design/website/docs/type/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Type
22

3-
A Json Schema Type Builder with Static Inference for TypeScript
3+
Json Schema Type Builder with Static Type Resolution for TypeScript
44

55
## Overview
66

design/website/docs/value/overview.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Value
22

3-
Functions to Process JavaScript Values
3+
Check, Decode and Parse JavaScript Values
44

55
## Overview
66

docs/docs/overview/overview.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h1>TypeBox</h1>
2-
<p>A Runtime Type System for JavaScript</p>
2+
<p>Json Schema Type Builder with Static Type Resolution for TypeScript</p>
33
<h2>Overview</h2>
44
<p>TypeBox is a runtime type system that creates in-memory Json Schema objects that infer as TypeScript types. The schematics produced by this library are designed to match the static type checking rules of the TypeScript compiler. TypeBox offers a unified type system that can be statically checked by TypeScript and validated at runtime using standard Json Schema.</p>
55
<p>This library is designed to allow Json Schema to compose similar to how types compose within TypeScript&#39;s type system. It can be used as a simple tool to build up complex schematics or integrated into REST and RPC services to help validate data received over the wire.</p>

docs/docs/script/overview.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h1>Script</h1>
2-
<p>A TypeScript Engine for JavaScript</p>
2+
<p>TypeScript Runtime Scripting Engine</p>
33
<h2>Overview</h2>
44
<p>TypeBox can translate TypeScript syntax into Json Schema. The Script function is a fully type-safe, syntactic frontend to the TypeBox type builder API, allowing Json Schema to be constructed and mapped using TypeScript type expressions encoded as strings.</p>
55
<h3>Example</h3>

docs/docs/type/overview.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h1>Type</h1>
2-
<p>A Json Schema Type Builder with Static Inference for TypeScript</p>
2+
<p>Json Schema Type Builder with Static Type Resolution for TypeScript</p>
33
<h2>Overview</h2>
44
<p>TypeBox includes many functions to create Json Schema types. Each function returns a small Json Schema fragment that corresponds to a TypeScript type. TypeBox uses function composition to combine schema fragments into more complex types. It provides a set of functions that are used to model Json Schema schematics as well as a set of functions that model constructs native to JavaScript and TypeScript.</p>
55
<h2>Example</h2>

docs/docs/value/overview.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<h1>Value</h1>
2-
<p>Functions to Process JavaScript Values</p>
2+
<p>Check, Decode and Parse JavaScript Values</p>
33
<h2>Overview</h2>
44
<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>
55
<p>The Value module is available via optional import.</p>

example/standard/readme.md

Lines changed: 58 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,30 +1,69 @@
11
# Standard Schema V1
22

3-
This example is an adapter to the Standard Schema V1 specification.
3+
This is a reference adapter for the Standard Schema V1 specification. The adapter enables Json Schema and TypeBox schematics to be mapped into a StandardSchemaV1 interface.
4+
5+
### Json Schema
6+
7+
Json Schema can be passed to the StandardSchemaV1 function.
48

59
```typescript
6-
import StandardSchema, { type StandardSchemaV1 } from './standard/standard.ts'
10+
import StandardSchemaV1 from './standard/standard.ts'
11+
12+
const T = StandardSchemaV1({
13+
type: 'object',
14+
required: ['x', 'y', 'z'],
15+
properties: {
16+
x: { type: 'number' },
17+
y: { type: 'number' },
18+
z: { type: 'number' }
19+
}
20+
})
21+
22+
type T = StandardSchemaV1.InferInput<typeof T> // type T = {
23+
// x: number,
24+
// y: number,
25+
// z: number
26+
// }
27+
28+
const R = T['~standard'].validate(null) // const R: StandardSchemaV1.Result<{
29+
// x: number;
30+
// y: number;
31+
// z: number;
32+
// }> | Promise<StandardSchemaV1.Result<{
33+
// x: number;
34+
// y: number;
35+
// z: number;
36+
// }>>
37+
```
38+
39+
### TypeBox
40+
41+
TypeBox types can also be passed.
42+
43+
```typescript
44+
import StandardSchemaV1 from './standard/standard.ts'
745
import Type from 'typebox'
846

9-
const T = StandardSchema(Type.Object({
47+
const T = StandardSchemaV1(Type.Object({
1048
x: Type.Number(),
1149
y: Type.Number(),
1250
z: Type.Number()
1351
}))
1452

15-
type T = StandardSchemaV1.InferInput<typeof T> // type T = {
16-
// x: number,
17-
// y: number,
18-
// z: number
19-
// }
20-
21-
const R = T['~standard'].validate({ // const R: StandardSchemaV1.Result<{
22-
x: 1, // x: number;
23-
y: 2, // y: number;
24-
z: 3 // z: number;
25-
}) // }> | Promise<StandardSchemaV1.Result<{
26-
// x: number;
27-
// y: number;
28-
// z: number;
29-
// }>>
30-
```
53+
type T = StandardSchemaV1.InferInput<typeof T> // type T = {
54+
// x: number,
55+
// y: number,
56+
// z: number
57+
// }
58+
59+
const R = T['~standard'].validate({ // const R: StandardSchemaV1.Result<{
60+
x: 1, // x: number;
61+
y: 2, // y: number;
62+
z: 3 // z: number;
63+
}) // }> | Promise<StandardSchemaV1.Result<{
64+
// x: number;
65+
// y: number;
66+
// z: number;
67+
// }>>
68+
```
69+

example/standard/standard.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,14 @@ export class TStandardSchema<Context extends Type.TProperties, Type extends Type
7171
// ------------------------------------------------------------------
7272
// Factory
7373
// ------------------------------------------------------------------
74-
export function StandardSchema<const Type extends Type.TSchema,
74+
export function StandardSchemaV1<const Type extends Type.TSchema,
7575
Result = TStandardSchema<{}, Type>
7676
>(type: Type): Result
77-
export function StandardSchema<Context extends Type.TProperties, const Type extends Type.TSchema,
77+
export function StandardSchemaV1<Context extends Type.TProperties, const Type extends Type.TSchema,
7878
Result = TStandardSchema<Context, Type>
7979
>(context: Context, type: Type): Result
8080

81-
export function StandardSchema(...args: unknown[]): unknown {
81+
export function StandardSchemaV1(...args: unknown[]): unknown {
8282
const [context, type] = Arguments.Match<[Type.TProperties, Type.TSchema]>(args, {
8383
2: (context, type) => [context, type],
8484
1: (type) => [{}, type]
@@ -89,7 +89,7 @@ export function StandardSchema(...args: unknown[]): unknown {
8989
// ------------------------------------------------------------------
9090
// Default
9191
// ------------------------------------------------------------------
92-
export default StandardSchema
92+
export default StandardSchemaV1
9393

9494
// ------------------------------------------------------------------
9595
// Standard Schema Interface

0 commit comments

Comments
 (0)