Skip to content

Commit a7db807

Browse files
committed
Next
1 parent 03a36dd commit a7db807

146 files changed

Lines changed: 508 additions & 2756 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

design/website/app/frontend/components/home/home.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ export function Home() {
9797
<div className='home'>
9898
<div className='home-card'>
9999
<TypeBoxLogo />
100-
<h1>TypeBox</h1>
100+
<h1>TypeBox<sup style={{ marginLeft: '0.4em', color: '#e0c285', fontSize: '0.6em' }}>2</sup></h1>
101101
<AnimatedSubHeading
102102
intervalMs={5000}
103103
stepDelayMs={25}

design/website/docs/value/mutate.md

Lines changed: 0 additions & 27 deletions
This file was deleted.

design/website/docs/value/parse.md

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -10,30 +10,4 @@ Example usage is shown below.
1010
const R = Value.Parse(Type.String(), 'hello') // const R: string = "hello"
1111

1212
const E = Value.Parse(Type.String(), 12345) // throws ParseError
13-
```
14-
15-
## Corrective Parse
16-
17-
TypeBox provides an optional corrective parsing mode that attempts to repair invalid values before failing. When enabled, the parser runs a pipeline consisting of Convert, Default, and Clean, then re-asserts the value after processing. This feature can be useful when parsing environment variables into target types.
18-
19-
> ⚠️ This feature can impact performance. It is not recommended for use in high throughput applications.
20-
21-
This feature can be enabled as follows:
22-
23-
```typescript
24-
import { Settings } from 'typebox/system'
25-
26-
// Corrective Parse: Enable
27-
28-
Settings.Set({ correctiveParse: true })
29-
30-
// Corrective Parse: Convert Value into the target type if reasonable conversion is possible.
31-
32-
const R = Value.Parse(Type.String(), 'hello') // const R: string = "hello"
33-
34-
const S = Value.Parse(Type.String(), 12345) // const S: string = "12345"
35-
36-
// Corrective Parse: Reset (optional)
37-
38-
Settings.Reset()
3913
```

docs/docs/value/mutate.html

Lines changed: 0 additions & 23 deletions
This file was deleted.

docs/docs/value/parse.html

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -6,25 +6,3 @@ <h2>Example</h2>
66

77
const E = Value.Parse(Type.String(), 12345) // throws ParseError
88
</code></pre>
9-
<h2>Corrective Parse</h2>
10-
<p>TypeBox provides an optional corrective parsing mode that attempts to repair invalid values before failing. When enabled, the parser runs a pipeline consisting of Convert, Default, and Clean, then re-asserts the value after processing. This feature can be useful when parsing environment variables into target types.</p>
11-
<blockquote>
12-
<p>⚠️ This feature can impact performance. It is not recommended for use in high throughput applications.</p>
13-
</blockquote>
14-
<p>This feature can be enabled as follows:</p>
15-
<pre><code class="language-typescript">import { Settings } from &#39;typebox/system&#39;
16-
17-
// Corrective Parse: Enable
18-
19-
Settings.Set({ correctiveParse: true })
20-
21-
// Corrective Parse: Convert Value into the target type if reasonable conversion is possible.
22-
23-
const R = Value.Parse(Type.String(), &#39;hello&#39;) // const R: string = &quot;hello&quot;
24-
25-
const S = Value.Parse(Type.String(), 12345) // const S: string = &quot;12345&quot;
26-
27-
// Corrective Parse: Reset (optional)
28-
29-
Settings.Reset()
30-
</code></pre>

docs/index.js

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

docs/manifest.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,6 @@
147147
"equal": "docs/value/equal.html",
148148
"errors": "docs/value/errors.html",
149149
"hash": "docs/value/hash.html",
150-
"mutate": "docs/value/mutate.html",
151150
"overview": "docs/value/overview.html",
152151
"parse": "docs/value/parse.html",
153152
"patch": "docs/value/patch.html",

example/index.ts

Lines changed: 15 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -1,70 +1,30 @@
1-
import Compile from 'typebox/compile'
2-
import System from 'typebox/system'
3-
import Guard from 'typebox/guard'
4-
import Format from 'typebox/format'
5-
import Schema from 'typebox/schema'
6-
import Value from 'typebox/value'
7-
import Type from 'typebox'
8-
9-
// ------------------------------------------------------------------
10-
// Settings
11-
// ------------------------------------------------------------------
12-
13-
System.Settings.Set({ enumerableKind: false })
14-
15-
// ------------------------------------------------------------------
16-
// Guard
17-
// ------------------------------------------------------------------
18-
19-
const A = Guard.GraphemeCount('type-📦') // 6
20-
const B = Guard.HasPropertyKey({ x: 1 }, 'x') // true
211

222
// ------------------------------------------------------------------
23-
// Type
3+
// Next
244
// ------------------------------------------------------------------
5+
// Add Pipeline
6+
// Add Match
7+
// Update Refine - Error Callback
8+
// DestructiveCodecCheck --- Need to find these
9+
// Break Decode, Encode
10+
// Add Const Types
11+
// Rename ReadonlyType to ReadonlyObject
12+
// Remove Type.Base
13+
// Remove Compiler.Code
14+
// Remove Value.Mutate
15+
// Remove DecodeUnsafe, EncodeUnsafe
2516

26-
const T = Type.Object({
27-
x: Type.Number(),
28-
y: Type.Number(),
29-
z: Type.Number()
30-
})
31-
32-
// ------------------------------------------------------------------
33-
// Script
34-
// ------------------------------------------------------------------
17+
import Type from "typebox"
18+
import Value from 'typebox/value'
19+
import Compile from 'typebox/schema'
3520

36-
const S = Type.Script({ T }, `{
37-
[K in keyof T]: T[K] | null
38-
}`)
3921

40-
// ------------------------------------------------------------------
41-
// Infer
42-
// ------------------------------------------------------------------
4322

44-
type T = Type.Static<typeof T>
45-
type S = Type.Static<typeof S>
4623

47-
// ------------------------------------------------------------------
48-
// Parse
49-
// ------------------------------------------------------------------
5024

51-
const R = Value.Parse(T, { x: 1, y: 2, z: 3 })
5225

53-
// ------------------------------------------------------------------
54-
// Compile
55-
// ------------------------------------------------------------------
56-
const C = Compile(S)
5726

58-
const X = C.Parse({ x: 1, y: 2, z: 3 })
5927

60-
// ------------------------------------------------------------------
61-
// Format
62-
// ------------------------------------------------------------------
6328

64-
const E = Format.IsEmail('user@domain.com')
6529

66-
// ------------------------------------------------------------------
67-
// Schema
68-
// ------------------------------------------------------------------
6930

70-
const D = Schema.Parse({ const: 'hello' }, 'hello')

example/legacy/date.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,9 @@ THE SOFTWARE.
2929
import Type from 'typebox'
3030

3131
// ------------------------------------------------------------------
32-
// Definition
32+
// Date: 0.34.x
3333
// ------------------------------------------------------------------
34-
export class TDate extends Type.Base<globalThis.Date> {
35-
// required: Used by validation
36-
public override Check(value: unknown): value is globalThis.Date {
37-
return value instanceof globalThis.Date
38-
}
39-
// required: Used by validation
40-
public override Errors(value: unknown): object[] {
41-
return this.Check(value) ? [] : [{ message: 'must be Date' }]
42-
}
43-
// required: Used by type compositor
44-
public override Clone(): TDate {
45-
return new TDate()
46-
}
47-
// required: Used by value/create
48-
public override Create(): globalThis.Date {
49-
return new globalThis.Date(0)
50-
}
51-
}
52-
// ------------------------------------------------------------------
53-
// Factory
54-
// ------------------------------------------------------------------
55-
export function Date(): TDate {
56-
return new TDate()
57-
}
34+
export const Date = (options: Type.TSchemaOptions = {}) =>
35+
Type.Unsafe<globalThis.Date>(Type.Refine(options,
36+
value => value instanceof globalThis.Date,
37+
() => `Must be instance of Date`))

example/legacy/uint8array.ts

Lines changed: 5 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -29,29 +29,9 @@ THE SOFTWARE.
2929
import Type from 'typebox'
3030

3131
// ------------------------------------------------------------------
32-
// Definition
32+
// Uint8Array: 0.34.x
3333
// ------------------------------------------------------------------
34-
export class TUint8Array extends Type.Base<globalThis.Uint8Array> {
35-
// required: Used by validation
36-
public override Check(value: unknown): value is Uint8Array {
37-
return value instanceof Uint8Array
38-
}
39-
// required: Used by validation
40-
public override Errors(value: unknown): object[] {
41-
return !this.Check(value) ? [{ message: 'not a Uint8Array'}] : []
42-
}
43-
// required: Used by type compositor
44-
public override Clone(): TUint8Array {
45-
return new TUint8Array()
46-
}
47-
// required: Used by value/create
48-
public override Create(): globalThis.Uint8Array {
49-
return new globalThis.Uint8Array(0)
50-
}
51-
}
52-
// ------------------------------------------------------------------
53-
// Factory
54-
// ------------------------------------------------------------------
55-
export function Uint8Array(): TUint8Array {
56-
return new TUint8Array()
57-
}
34+
export const Uint8Array = (options: Type.TSchemaOptions = {}) =>
35+
Type.Unsafe<globalThis.Uint8Array>(Type.Refine(options,
36+
value => value instanceof globalThis.Uint8Array,
37+
() => `Must be instance of Uint8Array`))

0 commit comments

Comments
 (0)