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/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/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFkIATAVwBtVKBjCAOwDO8BgEMYACzgBeREQB0AZW5RgYGAAoABpThxCaOADVU3GNABM0uAG84ZAFxw+rEMVRQANHCSPnr93AAvjp6REYmZlAAzFa2Dk4ubp7evonuXgBeqf5QQSH66Mam0AAssXbZSV4+CTmZlelwAO4NucGaAJTUdHAAIqhofMyofMIsHFy8gvC2DKgCkoFWyGiKyqoaohJemrr5YcawqGSxIbqQAsAwwPyORZElHmdO0CAi7HcR0FFPurqsADdPsUoOYQsFdAU4ABxVA4VAwKBIU5-OAA9zXbjzT5HMgAbQAur8-sAhsAsQJWoTwfsDFt3MB3ii-iJXMARjBgQ9ibpmMAMBhWAJUFzSjy4AI0NwOCIoKKoCUaZCwnMFszdABzOEgBFIxyw+GIpDit4wBnvRz0lTvGmdbr0ABKrFGoHQDtQGE4phufEoqvEcjA2DQsHZAjkWsNSMDwYxYbk6NDFLkV1QIHDQYgIeu80DEEu134MazcdzZD98wDmez8cjOqNxZrucTmNzqfTjdL4b4r3endDZYrC37OfDdd1SBH8Zb5LbZo71a7ckBU8H-tX4dN5vYG7kfIFQtQu-L68XA83Ym3u9ZxHZo2PQ6rsfPci31p3Z9HcklJhlUAftD0AoMBiOScAAJJ8Bg7gjFilCCnw3r8HAUA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ABdVd12bBClAs-tU0ApAbMneznKsJ8Xw8uAvKsocryVQKXNgvdPPbZiMOw91PTCrzktfKibQypKDTI192M4hDkiAA) | [Challenge](test/typescript/readme.md)
114
+ [Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFkIATAVwBtVKBjCAOwDO8AN5wAChCFwAvnAC8iIgDoAytyjAwMABQADSnDiE0cAKoDUUeXGEHDcYMwBccPqxDFLAGjuG+AQxBUFyENPgBzO2k7Y3QAYRwgvngFW3sHZ1d3TygfdJhUMhgQmDDwvPt-VhgAC2gXc0somKJxSRSbXwyXNw9vLphgGE4SsorDUmYkUeAI8bgq2vqzC1yu3hAkmAEXBM3UZIBtAF1m3QBKajo4ACVUDE5uQf5KCSElMGw0WGBUASVHK92h8vpZBn8lINhlw3jAQRBvuD-os6lB4Yjfv9AbD0WDMUoUdBcT8IQEgkD3p8EXiIRstliCiB-lSMRCCkUKXCWTT-nSDtsAYzmaCScjqqjiUiAcxOZL8XzkgzUEy5RDCWjuaKlGSuLR6ABJPgYSwHbhcDCsPhPYD8OCfP787SQIQuZBoVQwfyDbgAHliEAwbSEAD5zp1DM64YCI8CoZw7JGCeKidG7cD1drAlwY+8FdtDgAGY6QwowBPAvMCQvFjOpxOV6tJpZonWUaRAA) | [Example 2](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFkIATAVwBtVKBjCAOwDO8AKoDUUOAF5ERAHQB5YgCtU3GAAoA3pThxgzAFwy0sgHKsQxceoCUAGh1w+AQxCojyEwGUYUYHwBzW0oAXxsefiE4AGEcNz54aU9UBWVVDW1dfQ85c0tre0cYVDIYHO9ffyDC3WdWGAALaCNRcVDw3kF4AAUIKKS5RRU1LUds4xS8qyhbB10YYBhOcpSfP0DZx1JmJBXZNarN2vqmqBaxKDm4XhB4mAE9gEEoKGckdVjb1ATwsOo6OAAJVQGE4amA-EovSEsjA2DQsGAqAEsn0UL6MFh8PEC2RsgWSy40MxcIgCNxKLqjWgWLJOKRKLRxNp5IZsippxZ9LxLjc6JhpNZeJud0ZxRAKMF3JRxVK-JJ2MRwri33uqPFksVFPZJxpUqVjOY8q5BtkItVYtQEpN2o5eq1bN5XFo9AAknwMOJvtwuBhWHxwfw4HDkar1JAhHsfM4FtwADyENAQDBwYkAPhscEywYxqKNugjmIJnEchZ11KgedLubtlad1Zh5oSAgA2gAGAC6+JKMAbmKb93bXdrVYLuYHrc75c59ZCQA) | [Challenge](test/typescript/readme.md)
115
115
 
116
- TypeBox includes a runtime scripting engine that can transform TypeScript definitions into JSON Schema. The engine is implemented symmetrically at runtime and inside TypeScript's type system. It supports many programmable type-level constructs such as Conditional, Mapped, Indexed, Generic, Distributive Conditional, and more. The engine is designed for TypeScript 7 but is supported in TypeScript 5 and above.
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 Math = Type.Script(`
125
- type Vector2 = { x: number, y: number }
126
- type Vector3 = { x: number, y: number, z: number }
127
- type Vector4 = { x: number, y: number, z: number, w: number }
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 Material = {
142
- ambient: Vector4,
143
- diffuse: Vector4,
144
- specular: Vector4
129
+ type Comment = {
130
+ id: number,
131
+ text: string,
132
+ author: User
145
133
  }
146
- type Mesh = {
147
- geometry: Geometry,
148
- material: Material
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
- // Runtime Reflection
153
- Mesh.properties.geometry.properties.vertices.items.properties.position.properties.x
154
- Mesh.properties.geometry.properties.vertices.items.properties.normal.properties.x
155
- Mesh.properties.geometry.properties.vertices.items.properties.uv.properties.x
156
- Mesh.properties.material.properties.diffuse.properties.x
157
- Mesh.properties.material.properties.ambient.properties.x
158
- Mesh.properties.material.properties.specular.properties.x
159
-
160
- // Static Inference
161
- function render(mesh: Type.Static<typeof Mesh>) {
162
- mesh.geometry.vertices[0].position.x
163
- mesh.geometry.vertices[0].normal.x
164
- mesh.geometry.vertices[0].uv.x
165
- mesh.material.diffuse.x
166
- mesh.material.ambient.x
167
- mesh.material.specular.x
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
- Ref: [JSON Schema Test Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite)
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 | 23/27 | 37/45 | 67/70 | 75/78 | 79/81 | 77/79 | 77/79 |
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 | - | - | - | - | ✅ | 65/71 | 64/71 |
286
- | unevaluatedProperties | - | - | - | - | ✅ | ✅ | 124/125 |
278
+ | unevaluatedItems | - | - | - | - | ✅ | | 70/71 |
279
+ | unevaluatedProperties | - | - | - | - | ✅ | ✅ | 128/129 |
287
280
  | uniqueItems | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
288
281
 
289
282