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.
@@ -17,7 +17,7 @@ export function FromObject(context, type, value) {
17
17
  if (isUnassignableUndefined)
18
18
  continue;
19
19
  // Assign
20
- value[key] = FromType(context, type.properties[key], 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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "typebox",
3
3
  "description": "Json Schema Type Builder with Static Type Resolution for TypeScript",
4
- "version": "1.2.6",
4
+ "version": "1.2.7",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "jsonschema"
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/#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFonmXW32POvueHb6AygGMowMDH6Ne0mbLnNqQiADsAzvADecAKqrUUADQ69UbWAAmAQxjoAvnAC8iIgDpho8QAoABtThxgZRsoDEshdABRIOBCOA1Kf39gcwAuOHVRZQBzBLhbPwCg-VDw4304VDIbZXNVOCiYGKQ4uFz-ZUsQVDSMwKyjNoqQS2AAGx6YTKzW-3zcwjQy0wtrdCcIgDdLUYBXVYAeQYAFYCEAa33dfSMz1CQIDHrowgA+OAAyGcSjy1hgbf2AHkQDFLiYbncHk9Gq8Xrk4ZRvABKah0KTyDGYzGSABKqAwo1QQgkaKxZPJvEUKlUEEJLlGECyniuUCRiXZHM5XK5aPi3P5AsFgrR-gW3XwEGIACsiTA8AZBkKlcrOSK4GBsGg-qhVGk+SqDYa1UlUi0xWk8L1sng8grDfblca4B0unq4Ob8FasjbbHaHf7+U7UM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2zHYbQyaPZGQt7bUee1uXDWXWHTXhPVfrTfb3OWc2Q67zxGFreoeX7xluiagQ6W5ppm2aoLmlglm4eCdpBUHRsSZJYdhnCCP4EzHJhOHEcR1AmkMYKpDM+EqBIAA8JoQBgFGGAAfPKKLkRcqTamhPJKqeb7BJ+fGskqj5eEJImicySq-pJl7BCBaG9mRRAsVAY6rFRnQwAR9GMcxFxaZM7FwJx6nGWM2maLxMliVugmKdJ9nmVuj4APwKRaLn2XJzRtF5cBCcpkG9kAA)
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 micro DSL for composing JSON Schema with TypeScript syntax. 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.
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 a TypeScript definition module into JSON Schema.
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
- // Script
126
-
127
- const { User, UserUpdate } = Type.Script(`
128
-
129
- interface Entity {
130
- id: string
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
- interface User extends Entity {
134
- name: string,
135
- email: string
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
- // Reflect
146
-
147
- console.log(User) // {
148
- // type: 'object',
149
- // properties: {
150
- // id: { type: 'string' },
151
- // name: { type: 'string' },
152
- // email: { type: 'string' }
153
- // },
154
- // required: [
155
- // 'id',
156
- // 'name',
157
- // 'email'
158
- // ]
159
- // }
160
-
161
- console.log(UserUpdate) // {
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>