typebox 1.0.0-rc → 1.0.1
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/type/types/unsafe.d.mts +1 -0
- package/package.json +1 -1
- package/readme.md +16 -22
|
@@ -3,6 +3,7 @@ export type StaticUnsafe<Type extends unknown> = Type;
|
|
|
3
3
|
/** Represents an Unsafe type. */
|
|
4
4
|
export interface TUnsafe<Type extends unknown = unknown> extends TSchema {
|
|
5
5
|
'~kind': 'Unsafe';
|
|
6
|
+
'~hint': Type;
|
|
6
7
|
}
|
|
7
8
|
/** Creates a Unsafe type. */
|
|
8
9
|
export declare function Unsafe<Type extends unknown>(schema: TSchema): TUnsafe<Type>;
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -24,6 +24,7 @@ $ npm install typebox --save # 1.0.0
|
|
|
24
24
|
$ npm install @sinclair/typebox --save # 0.34.x
|
|
25
25
|
```
|
|
26
26
|
|
|
27
|
+
|
|
27
28
|
## Usage
|
|
28
29
|
|
|
29
30
|
```typescript
|
|
@@ -48,40 +49,33 @@ type T = Static<typeof T> // type T = {
|
|
|
48
49
|
|
|
49
50
|
## Overview
|
|
50
51
|
|
|
51
|
-
TypeBox is a runtime type system that creates in-memory Json Schema objects that infer as TypeScript types. The
|
|
52
|
+
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.
|
|
52
53
|
|
|
53
|
-
|
|
54
|
+
This library is designed to allow Json Schema to compose similar to how types compose within TypeScript'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.
|
|
54
55
|
|
|
55
56
|
License MIT
|
|
56
57
|
|
|
57
58
|
## Contents
|
|
58
59
|
|
|
59
|
-
- [Docs](#Docs)
|
|
60
60
|
- [Type](#Type)
|
|
61
61
|
- [Script](#Script)
|
|
62
62
|
- [Value](#Value)
|
|
63
63
|
- [Compile](#Compile)
|
|
64
64
|
- [Contribute](#Contribute)
|
|
65
65
|
|
|
66
|
-
<a name="Documentation"></a>
|
|
67
|
-
|
|
68
|
-
## Docs
|
|
69
66
|
|
|
70
|
-
Full documentation for TypeBox can be found on the TypeBox website.
|
|
71
|
-
|
|
72
|
-
[Website](#)
|
|
73
67
|
|
|
74
68
|
<a name="Type"></a>
|
|
75
69
|
|
|
76
70
|
## Type
|
|
77
71
|
|
|
78
|
-
[Documentation](
|
|
72
|
+
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/type/overview) | [Example](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAFQJ5gKYBo4G84xauAZRgEMZgBjOAXzgDMoIQ4ByPNAIwgA8WAoPhQgA7AM7wEcALyJ8AOgDyHAFaoKMABQ44O3Xv0HDAeiNwhYidOx8d3AFyy0cgHIBXEB1RQNASkyGAwICTXXZUBxYIFTUYFnQbOCQHZCc3Dy9ffyDsoJCdKFQAR1dgAoATBwBtFl5MFiQ41gAvFgBdeJ0m5Pk0z28fHMHAvLgwRjRYYFRRByw+agGhpeW9EdtZ3HwI4Xc+lhoOlaPltcSNsO3dr33qQ+P77NOu7E20S-SoG4SHn+NTHWo31+wJ0IUBfDCiCsxDIlAAPGEIHREAA+EGg0yQyQyObo9EjexwHYfO54n4jJJEq5QUlk+4jZ7EvpAunHMFAA)
|
|
79
73
|
|
|
80
|
-
TypeBox
|
|
74
|
+
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.
|
|
81
75
|
|
|
82
76
|
## Example
|
|
83
77
|
|
|
84
|
-
The following creates Json Schema and infers with Static.
|
|
78
|
+
The following creates a Json Schema type and infers with Static.
|
|
85
79
|
|
|
86
80
|
```typescript
|
|
87
81
|
import Type, { type Static } from 'typebox'
|
|
@@ -109,16 +103,16 @@ type T = Static<typeof T> // type T = {
|
|
|
109
103
|
|
|
110
104
|
## Script
|
|
111
105
|
|
|
112
|
-
[Documentation](
|
|
106
|
+
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAFQJ5gKYBo4G84xauAZRgEMZgBjOAXzgDMoIQ4ByPNAIwgA8WAoPhQgA7AM7wEcALyJ8AOkIUowMDAAUAAxx84cbgC44wgK4gOqKJh1wkhk2YtXdALzunzUOH2oaAlLoDAoOCQ0LCggHoIuCExCWlEAHkOACtUChgAHixrcLz8gsCogINEADl3R1zCmtqi6N1bcsrLarr2guKXQwQKhyg2jqHQ4uoAPgFY8SIE5DQFJRV1HElqTC1rAG0AaThgYTgAa1QkCDpEAF0enYu4AB8jYwAbJ+8-YY-g4qn4Qh7ktIZbKDT6fLp6HoAVWEwBEmU2vRamERLwuY3QINBw3BTQQ0NhwnhiP6yIqqPRmKxHXBrkQ+LhCL6HlJzyeaMpVLqowmfHYBEICWIZEomT5ZyIY05xT5MxkOU5WPBpXsHnujxeGIVoJxbn6apMGo5Ws6DTgtJVFn1rKNxryowEfCAA)
|
|
113
107
|
|
|
114
|
-
TypeBox is a type
|
|
108
|
+
TypeBox is a runtime type system that uses Json Schema as an AST for runtime type representation. The Script function provides a syntactic frontend to the type system and allows Json Schema to be created using native TypeScript syntax. TypeBox provides full static and runtime type safety for string-encoded types.
|
|
115
109
|
|
|
116
110
|
### Example
|
|
117
111
|
|
|
118
112
|
The following uses Script to create and map types.
|
|
119
113
|
|
|
120
114
|
```typescript
|
|
121
|
-
import Type from 'typebox'
|
|
115
|
+
import Type, { type Static } from 'typebox'
|
|
122
116
|
|
|
123
117
|
const T = Type.Script(`{
|
|
124
118
|
x: number,
|
|
@@ -149,9 +143,9 @@ type S = Static<typeof S> // type S = {
|
|
|
149
143
|
|
|
150
144
|
## Value
|
|
151
145
|
|
|
152
|
-
[Documentation](
|
|
146
|
+
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/value/overview) | [Example](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoUSWOANQEMAbAV3Sx30LVLIHoAbi3ZVKAYwgA7AM7wEcALyIiAOgDyxAFapxMABQBvSnDhkAXCrSqAcqxDFUUfQEoANCbhJLya3YdOrh6mAF4+av6Ozi6UAL4xlPz8cADCABa6ANaUEtJycACCSgwiqKrpWfoIbnCGpvUNjU1NSXCSsvAFlqQQzKiMUsUwUOyeFnAAjDXNM7Nzs57ecABMwXBhcADMcQmtAAqMUDKoOe35AELFTGxlB0eoVTV18y+mrWfw55bGpuNTrwDAfVWr9LFJ7FE1ktVkDYS8QV4wRCnGsNps4RjZgiNuCAlAdpjCVjkrFiqpyUA)
|
|
153
147
|
|
|
154
|
-
The Value module provides functions to Check and Parse JavaScript values.
|
|
148
|
+
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. This module provides unified support for both Json Schema and Standard Schema.
|
|
155
149
|
|
|
156
150
|
The Value module is available via optional import.
|
|
157
151
|
|
|
@@ -192,11 +186,11 @@ const B = Value.Parse(T, { // const B: {
|
|
|
192
186
|
|
|
193
187
|
## Compile
|
|
194
188
|
|
|
195
|
-
[Documentation](
|
|
189
|
+
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/compile/overview) | [Example](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAbzgYQuYAbApnAvnAMyjTgHIYBPMLAIwgA8B6AYzTEy1IChRJY4AKlRxES5YXXrcurAHYBneMjgBeFGw4AKIdQB0AeRoArLMxiakcK9Zu3bjRnDmKUALjgA1AIYZgAEy8YaAAeBFwAGkFDEzNQrit6dx0sXQA5AFcQGiwoTQBKSLsi4pKrB2tEwQysnPD4uAok4TTM7NyC0s6u8qtGqtba+oAvJr1qtvyuqZKeuBH+mqguXDy86fWNm3LcAD4dri5y5AALUwBrA+d4AEFVFF0T84tNjfKruGv3OghsL1k7mBQdJYeqVACMhReUNs9T6ACY6lZ5gBmZZ5A7lAAKXig8hBMggCngACE7shdNjcVhntDuo53sT3AhQe4IbT2WVHAl3LIBlBEQ13AiOezZn1eYsBSiRaKuXMeXy0TKZds7rp1UA)
|
|
196
190
|
|
|
197
|
-
The Compile module provides functions to
|
|
191
|
+
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. This module provides unified support to compile both Json Schema and Standard Schema, however performance optimizations are only possible with Json Schema.
|
|
198
192
|
|
|
199
|
-
The
|
|
193
|
+
The Compile module is available via optional import.
|
|
200
194
|
|
|
201
195
|
```typescript
|
|
202
196
|
import { Compile } from 'typebox/compile'
|
|
@@ -215,7 +209,7 @@ const C = Compile(Type.Object({ // const C: Validator<{}, TO
|
|
|
215
209
|
|
|
216
210
|
// Check
|
|
217
211
|
|
|
218
|
-
const A = C.Check(
|
|
212
|
+
const A = C.Check({ // const A: boolean = true
|
|
219
213
|
x: 1,
|
|
220
214
|
y: 2,
|
|
221
215
|
z: 3
|
|
@@ -232,4 +226,4 @@ const B = C.Parse({ // const B: {
|
|
|
232
226
|
|
|
233
227
|
## Contribute
|
|
234
228
|
|
|
235
|
-
TypeBox is open to community contribution. Please ensure you submit an issue before submitting
|
|
229
|
+
TypeBox is open to community contribution. Please ensure you submit an issue before submitting a pull request. The TypeBox project prefers open community discussion before accepting new features.
|