typebox 1.2.6 → 1.2.8

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.
@@ -1,6 +1,6 @@
1
1
  /**
2
2
  * Returns true if the value is a uuid
3
- * @specification
4
- * @source ajv-formats
3
+ * @specification https://www.rfc-editor.org/info/rfc4122/
4
+ * @specification https://www.rfc-editor.org/info/rfc9562/
5
5
  */
6
6
  export declare function IsUuid(value: string): boolean;
@@ -1,8 +1,8 @@
1
- const Uuid = /^(?:urn:uuid:)?[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
1
+ const Uuid = /^[0-9a-f]{8}-(?:[0-9a-f]{4}-){3}[0-9a-f]{12}$/i;
2
2
  /**
3
3
  * Returns true if the value is a uuid
4
- * @specification
5
- * @source ajv-formats
4
+ * @specification https://www.rfc-editor.org/info/rfc4122/
5
+ * @specification https://www.rfc-editor.org/info/rfc9562/
6
6
  */
7
7
  export function IsUuid(value) {
8
8
  return Uuid.test(value);
@@ -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.8",
5
5
  "keywords": [
6
6
  "typescript",
7
7
  "jsonschema"
@@ -16,34 +16,34 @@
16
16
  "types": "./build/index.d.mts",
17
17
  "module": "./build/index.mjs",
18
18
  "exports": {
19
- "./format": {
20
- "import": "./build/format/index.mjs",
21
- "default": "./build/format/index.mjs"
19
+ "./guard": {
20
+ "import": "./build/guard/index.mjs",
21
+ "default": "./build/guard/index.mjs"
22
22
  },
23
- "./type": {
24
- "import": "./build/type/index.mjs",
25
- "default": "./build/type/index.mjs"
23
+ "./system": {
24
+ "import": "./build/system/index.mjs",
25
+ "default": "./build/system/index.mjs"
26
26
  },
27
27
  "./schema": {
28
28
  "import": "./build/schema/index.mjs",
29
29
  "default": "./build/schema/index.mjs"
30
30
  },
31
+ "./format": {
32
+ "import": "./build/format/index.mjs",
33
+ "default": "./build/format/index.mjs"
34
+ },
31
35
  "./compile": {
32
36
  "import": "./build/compile/index.mjs",
33
37
  "default": "./build/compile/index.mjs"
34
38
  },
39
+ "./type": {
40
+ "import": "./build/type/index.mjs",
41
+ "default": "./build/type/index.mjs"
42
+ },
35
43
  "./value": {
36
44
  "import": "./build/value/index.mjs",
37
45
  "default": "./build/value/index.mjs"
38
46
  },
39
- "./guard": {
40
- "import": "./build/guard/index.mjs",
41
- "default": "./build/guard/index.mjs"
42
- },
43
- "./system": {
44
- "import": "./build/system/index.mjs",
45
- "default": "./build/system/index.mjs"
46
- },
47
47
  "./error": {
48
48
  "import": "./build/error/index.mjs",
49
49
  "default": "./build/error/index.mjs"
@@ -55,27 +55,27 @@
55
55
  },
56
56
  "typesVersions": {
57
57
  "*": {
58
- "format": [
59
- "./build/format/index.d.mts"
58
+ "guard": [
59
+ "./build/guard/index.d.mts"
60
60
  ],
61
- "type": [
62
- "./build/type/index.d.mts"
61
+ "system": [
62
+ "./build/system/index.d.mts"
63
63
  ],
64
64
  "schema": [
65
65
  "./build/schema/index.d.mts"
66
66
  ],
67
+ "format": [
68
+ "./build/format/index.d.mts"
69
+ ],
67
70
  "compile": [
68
71
  "./build/compile/index.d.mts"
69
72
  ],
73
+ "type": [
74
+ "./build/type/index.d.mts"
75
+ ],
70
76
  "value": [
71
77
  "./build/value/index.d.mts"
72
78
  ],
73
- "guard": [
74
- "./build/guard/index.d.mts"
75
- ],
76
- "system": [
77
- "./build/system/index.d.mts"
78
- ],
79
79
  "error": [
80
80
  "./build/error/index.d.mts"
81
81
  ],
package/readme.md CHANGED
@@ -73,7 +73,7 @@ License: MIT
73
73
 
74
74
  TypeBox types are JSON Schema fragments that compose into more complex types. The library offers a set of types used to construct JSON Schema compliant schematics as well as a set of extended types used to model constructs native to the JavaScript language. The schematics produced by TypeBox can be passed directly to any JSON Schema compliant validator.
75
75
 
76
- ## Example
76
+ ### Example
77
77
 
78
78
  The following creates a User type and infers with Static.
79
79
 
@@ -111,78 +111,61 @@ 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+U7UMMxm6PZbJn0fYqA7G4GrfTG4-61VBUABHHbANOmgDaSeT9qdeGS8q+hdjxZdqDLBYrKuLwZGoyo9cr9H8AF0622hWi5ko1LTUPTGcyTGYrDY2YXeT3ewK1eHJTLifL5wvuWqNRAtY0dXqN5vVR3Eskw0QLV6fX7jw3T+1OuKtOHr7aj3fEkGQ+MzZfPZG1p5B+n7xqeiagY6p5ppm2aoHmJbmHg3aQUq-a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MliVugmKdJ9nmVuj4APwKRaLn2XJzRtF5cBCcpkG9kAA)
114
+ [Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFonmXW32POv3b7k0AdAGUAxlGBgYACjwC5eAJS9G3VWvXdqdOADkAhiFQBnMHpGpKIiADsj8ALJ6YACzgBeREWFiJ0gAaUcHCEaHAAaqgiMNAATO5wAN5wZABccNYAriDEqFAANHBIaZnZuXAAvoHBROGR0VAAzPEAogBuegA2GU6oADwRUbFwAGSJcABexVk5UBUAfFUh6AP1ACwt7V09-XXQTaNJAO5TpbPlC35KygAiqGjWACao1vD6hiZmFla28En2xq5yvF+KhvOJJFIknIBI4XBUCn4gosahFYKgyPEElUgpAjMAYMAbGkVtBVnlseloCBOsTdo1yUEghlWrTBlAYlVKkElnAAOKoHCoGBQJCYimtXIE8xGWlosgAbQAugzGcBHsBpScZkrOcjQrDcsBOmLGXADMRgM8YKy1iqgg9gBgMBkjKgbaS7XATJEMh09FB3VBVrruTV-kZXB4saaAOYCwzCop8+NCkWe6kwQ00uAG8SdXWXLT0ABKGReoHQxdQGA6dUJ1ko4ecAjA2DQsEtRgEccFiZbbclnYEEo70oE+NQIC7rYg7YJxhbEDxBJs-dng4XZEbALXc6HPYTIt3G67I6lC4nU+PHYX1ipnWv867W6bj-3Kb7M73C7PGovmavL8TwEZk303bcIzArsMyzDooIEB0nRdUEgJvZ8IObVCnwEGC8zgrCh3NS0Xngl8dwIhdcKNfCBzQgRvREX1-VIos4CEGAnA1OAAElrAwXJnnMShnWsKJ6zgKBnieKApHeZw0hBYQOKlXolggDAcwBOYFESKo5O7D8j1-aV5QABkVRdl3rAQtyCfSD1TJBh0HEzzIEO8oGpODbLgezDKc4zjDMizQJ8-SqIfRDnVdGy9J3CK4KIq1Yrs+Kejw+i0EYv0oFi8ogA) | [Example 2](https://www.typescriptlang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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 that can transform TypeScript declarations into JSON Schema. The engine is 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
- import Type from 'typebox'
124
-
125
- // Script
126
-
127
- const { User, UserUpdate } = Type.Script(`
123
+ // Namespace
124
+ const Math = Type.Script(`
125
+ type Vector2 = { x: number, y: number }
126
+ type Vector3 = Evaluate<Vector2 & { z: number }>
127
+ type Vector4 = Evaluate<Vector3 & { w: number }>
128
+ `)
128
129
 
129
- interface Entity {
130
- id: string
130
+ // Dependent Namespace
131
+ const { Mesh } = Type.Script({ ...Math }, `
132
+ type Vertex = {
133
+ position: Vector4,
134
+ normal: Vector3,
135
+ uv: Vector2
131
136
  }
132
-
133
- interface User extends Entity {
134
- name: string,
135
- email: string
137
+ type Geometry = {
138
+ vertices: Vertex[],
139
+ indices: number[]
140
+ }
141
+ type Material = {
142
+ ambient: Vector4,
143
+ diffuse: Vector4,
144
+ specular: Vector4
145
+ }
146
+ type Mesh = {
147
+ geometry: Geometry,
148
+ material: Material
136
149
  }
137
-
138
- type UserUpdate = Evaluate<
139
- Pick<User, keyof Entity> &
140
- Partial<Omit<User, keyof Entity>>
141
- >
142
-
143
150
  `)
144
151
 
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
-
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
168
+ }
186
169
  ```
187
170
 
188
171
  <a name="Schema"></a>