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.
- package/build/format/uuid.d.mts +2 -2
- package/build/format/uuid.mjs +3 -3
- package/build/value/default/from_object.mjs +1 -1
- package/package.json +25 -25
- package/readme.md +45 -62
package/build/format/uuid.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Returns true if the value is a uuid
|
|
3
|
-
* @specification
|
|
4
|
-
* @
|
|
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;
|
package/build/format/uuid.mjs
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
const Uuid = /^
|
|
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
|
-
* @
|
|
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] =
|
|
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.
|
|
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
|
-
"./
|
|
20
|
-
"import": "./build/
|
|
21
|
-
"default": "./build/
|
|
19
|
+
"./guard": {
|
|
20
|
+
"import": "./build/guard/index.mjs",
|
|
21
|
+
"default": "./build/guard/index.mjs"
|
|
22
22
|
},
|
|
23
|
-
"./
|
|
24
|
-
"import": "./build/
|
|
25
|
-
"default": "./build/
|
|
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
|
-
"
|
|
59
|
-
"./build/
|
|
58
|
+
"guard": [
|
|
59
|
+
"./build/guard/index.d.mts"
|
|
60
60
|
],
|
|
61
|
-
"
|
|
62
|
-
"./build/
|
|
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
|
-
|
|
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
|
|
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+i0EYv0oFi8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iAA)
|
|
115
115
|
|
|
116
|
-
TypeBox includes a
|
|
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
|
|
120
|
+
The following uses Script to parse TypeScript declarations into JSON Schema.
|
|
121
121
|
|
|
122
122
|
```typescript
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
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
|
-
|
|
130
|
-
|
|
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
|
-
|
|
134
|
-
|
|
135
|
-
|
|
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
|
-
//
|
|
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
|
-
|
|
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>
|