typebox 1.2.6 → 1.2.7
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/value/default/from_object.mjs +1 -1
- package/package.json +1 -1
- package/readme.md +41 -60
|
@@ -17,7 +17,7 @@ export function FromObject(context, type, value) {
|
|
|
17
17
|
if (isUnassignableUndefined)
|
|
18
18
|
continue;
|
|
19
19
|
// Assign
|
|
20
|
-
value[key] =
|
|
20
|
+
value[key] = propertyValue;
|
|
21
21
|
}
|
|
22
22
|
// return if not additional properties
|
|
23
23
|
if (!IsAdditionalProperties(type) || Guard.IsBoolean(type.additionalProperties))
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -111,78 +111,59 @@ 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
|
|
114
|
+
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgYwgDsBneAbzgFlVGALOAXzgBeREQB0AZRpRgYGAAoABpThxCaOADVUNGNABMQuGzIAuOPQCuIYqigAaOEjOXrt-stVFN23VADMhgCiAG4AhgA2FqEwqAA8Wjr6cABkRnAAXs5WNlD8AHweaugJvgAsQWGR0XEl0AGpbADuWa65fAUqhV5asKhkhiweKpCMwDDADGa1UKV2Q+bQIBFTPnVzKioWwSuJUHoefF3qAOKoOKgwUEgD88G24zRcK71kANoAuusbwPQAJsCPRgtHIfA5HdDsarSCI3DZwULWYCoegwHZleb-DAYCyMVBo6CleaMNA0CzhUJQfEzMEqIocLi8YSDOEAczOIAuVzMp3OlyQ8yWMWh4TMkKFwAiYIUAEpqAB6OVwABKFhRoHQStQGHCPgm9EonB4ojA2DQsCRjFEbN5V2NpvuFtEd3NgNEY1QIEtJogZvGXGNEFG4wYdp9Dv9ZANDNDvsd1o5fJj4ctzoe-vdnqT5v99EWESzfstkcN3ALcfZnKQZf9qYB6Zime9sf9W2rRajRqbydEgtsEvCbdEmOxuMHxejXezlt7wsHCOISJRY47pcnhZ7UP7g+J2jJFOXlAVcHEMGiALgAEl6BhbMjHpRsfQdHq4FBkb9bHIOTwzMg0BJTweWIiggDB6R4PJpSMDxv1LeNKydB1AVeAAGd4AyDPVREjFRYKtCtE1rZC0NEXMoCWAccLgPD4MIpCuFQ9DWyovCZy3YccVQbCYOjNj83nRcYG43DeM3fMd1JckoG4vggA) | [Example 2](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFonmXW32POv3b7k0AdACpejbuImTu1SgGMIAOwDO8AGqpZMaACY4AXkREBAeWIArDTAAUAbzhkAXIcEA5AK4hiqKFYCUAGjgkJ35UAXdPbz84AF9fOUUVOHVNaABmfWcwgFEANwBDABs3fJhUK1CBAEkFMqglSysAbRStKG1AytMLTVs4AC8QowivH19Y3wBdX3j5ZTVLaAAWTMq8opKyiqMauobelsWoNM6jbsa7AHch1w9R6Ljp+IT55O8yslWz8wvKODhIEpgDBgIonK1lv4-nAFNAQEVwUcTtC3LlEal2pQ4i8kgBxVA4VAwKBIL6Cc69GzQ3LvYCyVBKG5hACCUCg+SQVnUsFQZAC0OACgAJnSGUyBKz2ZzKiMojMsbNEvAALKlbzAIpksIU6xU-75TzAVC1dFtJZQ-4ijAYNwNU2Q6FKNCyNyFfJQe1QJYKnEqhkACy1Jh+lOhAHMCSAiSSnPjCcSkBa4PC6hrCk5Vamij7RAAlNy1UDoXOoDCFSyghSUZUBgRgbBoWBGpQCCPxkl1hu0hkCGlN+kt4GoEAt+sQRsgnuA4GVzvj7stsjV2tjifN1uR6NIOdrnt9kEDgRDkc7hcCWFQeGFU9NntLmtKf03yctttRhPP9f70WDson1dnqin53suj7AS2KbqkU4ECFaNoNDB94rl2t4QWqUBpjBBrEEatSIaBT4AahAiQRh0FES+AhOhorruvhogAMowKUdJwDUGDeMa9KUDaCiaJWcBQMaQpRFGj7ikxLGyAAPIQaAQBgcAPv6AB84x6smtZvluva0gOTQAAyTHWEBAiCigCEu-xiU+2kft++lGeecLQVZmlgXZHYOQyhnGUBbk2SR6GYXBtphAFtakZh2G4TAlnQoFUXQdRLpulA8UxEAA)
|
|
115
115
|
|
|
116
|
-
TypeBox includes a
|
|
116
|
+
TypeBox includes a syntax engine to transform TypeScript definitions into JSON Schema. The DSL offers a full syntactic frontend to Type.* and supports many advanced type-level constructs such as Conditional, Mapped, Indexed, Infer, Generics, Distributed types and more. This feature is implemented symmetrically at runtime and statically via TypeScript Template Literal types.
|
|
117
117
|
|
|
118
118
|
### Example
|
|
119
119
|
|
|
120
|
-
The following uses Script to parse
|
|
120
|
+
The following uses Script to parse TypeScript declarations into JSON Schema.
|
|
121
121
|
|
|
122
122
|
```typescript
|
|
123
123
|
import Type from 'typebox'
|
|
124
124
|
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
125
|
+
const { Mesh } = Type.Script(`
|
|
126
|
+
type Vector2 = { x: number, y: number }
|
|
127
|
+
type Vector3 = Evaluate<Vector2 & { z: number }>
|
|
128
|
+
type Vector4 = Evaluate<Vector3 & { w: number }>
|
|
129
|
+
|
|
130
|
+
type Vertex = {
|
|
131
|
+
position: Vector4,
|
|
132
|
+
normal: Vector3,
|
|
133
|
+
uv: Vector2
|
|
131
134
|
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
135
|
+
type Geometry = {
|
|
136
|
+
vertices: Vertex[],
|
|
137
|
+
indices: number[]
|
|
138
|
+
}
|
|
139
|
+
type Material = {
|
|
140
|
+
ambient: Vector4
|
|
141
|
+
diffuse: Vector4
|
|
142
|
+
specular: Vector4
|
|
143
|
+
}
|
|
144
|
+
type Mesh = {
|
|
145
|
+
geometry: Geometry
|
|
146
|
+
material: Material
|
|
136
147
|
}
|
|
137
|
-
|
|
138
|
-
type UserUpdate = Evaluate<
|
|
139
|
-
Pick<User, keyof Entity> &
|
|
140
|
-
Partial<Omit<User, keyof Entity>>
|
|
141
|
-
>
|
|
142
|
-
|
|
143
148
|
`)
|
|
144
149
|
|
|
145
|
-
//
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
// type: 'object',
|
|
163
|
-
// properties: {
|
|
164
|
-
// id: { type: 'string' },
|
|
165
|
-
// name: { type: 'string' },
|
|
166
|
-
// email: { type: 'string' }
|
|
167
|
-
// },
|
|
168
|
-
// required: ['id']
|
|
169
|
-
// }
|
|
170
|
-
|
|
171
|
-
// Static
|
|
172
|
-
|
|
173
|
-
type User = Type.Static<typeof User> // type User = {
|
|
174
|
-
// id: string,
|
|
175
|
-
// name: string,
|
|
176
|
-
// email: string
|
|
177
|
-
// }
|
|
178
|
-
|
|
179
|
-
type UserUpdate = Type.Static<typeof UserUpdate> // type UserUpdate = {
|
|
180
|
-
// id: string,
|
|
181
|
-
// name?: string,
|
|
182
|
-
// email?: string
|
|
183
|
-
// }
|
|
184
|
-
|
|
185
|
-
|
|
150
|
+
// Runtime Reflection
|
|
151
|
+
Mesh.properties.geometry.properties.vertices.items.properties.position.properties.x
|
|
152
|
+
Mesh.properties.geometry.properties.vertices.items.properties.normal.properties.x
|
|
153
|
+
Mesh.properties.geometry.properties.vertices.items.properties.uv.properties.x
|
|
154
|
+
Mesh.properties.material.properties.diffuse.properties.x
|
|
155
|
+
Mesh.properties.material.properties.ambient.properties.x
|
|
156
|
+
Mesh.properties.material.properties.specular.properties.x
|
|
157
|
+
|
|
158
|
+
// Static Inference
|
|
159
|
+
function render(mesh: Type.Static<typeof Mesh>) {
|
|
160
|
+
mesh.geometry.vertices[0].position.x
|
|
161
|
+
mesh.geometry.vertices[0].normal.x
|
|
162
|
+
mesh.geometry.vertices[0].uv.x
|
|
163
|
+
mesh.material.diffuse.x
|
|
164
|
+
mesh.material.ambient.x
|
|
165
|
+
mesh.material.specular.x
|
|
166
|
+
}
|
|
186
167
|
```
|
|
187
168
|
|
|
188
169
|
<a name="Schema"></a>
|