typebox 1.3.7 → 1.3.9
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/guard/emit.d.mts +3 -1
- package/build/guard/emit.mjs +12 -5
- package/build/guard/guard.d.mts +8 -2
- package/build/guard/guard.mjs +23 -2
- package/build/schema/engine/_context.mjs +3 -3
- package/build/schema/engine/_functions.mjs +1 -2
- package/build/schema/engine/additionalItems.mjs +17 -7
- package/build/schema/engine/contains.mjs +18 -6
- package/build/schema/engine/enum.mjs +1 -1
- package/build/schema/engine/items.mjs +26 -6
- package/build/schema/engine/maxContains.mjs +3 -3
- package/build/schema/engine/minContains.mjs +14 -4
- package/build/schema/engine/not.mjs +4 -2
- package/build/schema/engine/oneOf.mjs +7 -6
- package/build/schema/engine/ref.mjs +1 -7
- package/build/schema/engine/type.mjs +1 -1
- package/build/type/script/mapping.d.mts +32 -29
- package/build/type/script/mapping.mjs +18 -25
- package/build/type/script/parser.d.mts +19 -25
- package/build/type/script/parser.mjs +19 -22
- package/package.json +29 -29
- package/readme.md +39 -46
package/readme.md
CHANGED
|
@@ -91,7 +91,7 @@ const User = Type.Object({ // const User = {
|
|
|
91
91
|
// type: 'string',
|
|
92
92
|
// format: 'email'
|
|
93
93
|
// }
|
|
94
|
-
// }
|
|
94
|
+
// },
|
|
95
95
|
// required: [
|
|
96
96
|
// 'id',
|
|
97
97
|
// 'name',
|
|
@@ -111,9 +111,9 @@ type User = Type.Static<typeof User> // type User = {
|
|
|
111
111
|
|
|
112
112
|
## Script
|
|
113
113
|
|
|
114
|
-
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play/?target=99&module=7#code/
|
|
114
|
+
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFkIATAVwBtVKBj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ar1JAhHsfM4FtwADyENAQDBwYkAPhscEywYxqKNugjmIJnEchZ11KgedLubtlad1Zh5oSAgA2gAGAC6+JKMAbmKb93bXdrVYLuYHrc75c59ZCQA) | [Challenge](test/typescript/readme.md)
|
|
115
115
|
|
|
116
|
-
TypeBox includes a runtime
|
|
116
|
+
TypeBox includes a runtime TypeScript engine that can transform TypeScript definitions to JSON Schema. The engine is fully type-safe and supports many programmable constructs including Conditional, Mapped, Indexed, Generics, Distributive Generics, and more.
|
|
117
117
|
|
|
118
118
|
### Example
|
|
119
119
|
|
|
@@ -121,50 +121,43 @@ Syntax highlighting is available via the [Visual Studio Marketplace](https://mar
|
|
|
121
121
|
|
|
122
122
|
```typescript
|
|
123
123
|
// Module
|
|
124
|
-
const
|
|
125
|
-
type
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
`)
|
|
129
|
-
|
|
130
|
-
// Dependent Module
|
|
131
|
-
const { Mesh } = Type.Script(Math, `
|
|
132
|
-
type Vertex = {
|
|
133
|
-
position: Vector4,
|
|
134
|
-
normal: Vector3,
|
|
135
|
-
uv: Vector2
|
|
136
|
-
}
|
|
137
|
-
type Geometry = {
|
|
138
|
-
vertices: Vertex[],
|
|
139
|
-
indices: number[]
|
|
124
|
+
const { Post } = Type.Script(`
|
|
125
|
+
type User = {
|
|
126
|
+
id: number,
|
|
127
|
+
name: string
|
|
140
128
|
}
|
|
141
|
-
type
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
129
|
+
type Comment = {
|
|
130
|
+
id: number,
|
|
131
|
+
text: string,
|
|
132
|
+
author: User
|
|
145
133
|
}
|
|
146
|
-
type
|
|
147
|
-
|
|
148
|
-
|
|
134
|
+
type Post = {
|
|
135
|
+
id: number,
|
|
136
|
+
title: string,
|
|
137
|
+
body: string,
|
|
138
|
+
author: User,
|
|
139
|
+
comments: Comment[]
|
|
149
140
|
}
|
|
150
141
|
`)
|
|
151
142
|
|
|
152
|
-
//
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
143
|
+
// Reflection
|
|
144
|
+
Post.properties.id
|
|
145
|
+
Post.properties.title
|
|
146
|
+
Post.properties.author.properties.id
|
|
147
|
+
Post.properties.author.properties.name
|
|
148
|
+
Post.properties.comments.items.properties.text
|
|
149
|
+
Post.properties.comments.items.properties.author.properties.id
|
|
150
|
+
Post.properties.comments.items.properties.author.properties.name
|
|
151
|
+
|
|
152
|
+
// Inference
|
|
153
|
+
function present(post: Type.Static<typeof Post>) {
|
|
154
|
+
post.id
|
|
155
|
+
post.title
|
|
156
|
+
post.author.id
|
|
157
|
+
post.author.name
|
|
158
|
+
post.comments[0].text
|
|
159
|
+
post.comments[0].author.id
|
|
160
|
+
post.comments[0].author.name
|
|
168
161
|
}
|
|
169
162
|
```
|
|
170
163
|
|
|
@@ -236,7 +229,7 @@ const value = Vector.Parse({ // const value: {
|
|
|
236
229
|
|
|
237
230
|
The following table shows specification coverage implemented by TypeBox.
|
|
238
231
|
|
|
239
|
-
|
|
232
|
+
[JSON Schema Test Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite)
|
|
240
233
|
|
|
241
234
|
| Spec | 3 | 4 | 6 | 7 | 2019-09 | 2020-12 | v1 |
|
|
242
235
|
|:-----|:--|:--|:--|:--|:--|:--|:--|
|
|
@@ -279,11 +272,11 @@ Ref: [JSON Schema Test Suite](https://github.com/json-schema-org/JSON-Schema-Tes
|
|
|
279
272
|
| properties | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
280
273
|
| propertyNames | - | - | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
281
274
|
| recursiveRef | - | - | - | - | ✅ | - | - |
|
|
282
|
-
| ref |
|
|
275
|
+
| ref | 22/27 | 37/45 | 67/70 | 75/78 | 79/81 | 77/79 | 77/79 |
|
|
283
276
|
| required | 3/4 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
284
277
|
| type | 73/80 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
285
|
-
| unevaluatedItems | - | - | - | - | ✅ |
|
|
286
|
-
| unevaluatedProperties | - | - | - | - | ✅ | ✅ |
|
|
278
|
+
| unevaluatedItems | - | - | - | - | ✅ | ✅ | 70/71 |
|
|
279
|
+
| unevaluatedProperties | - | - | - | - | ✅ | ✅ | 128/129 |
|
|
287
280
|
| uniqueItems | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
288
281
|
|
|
289
282
|
|