typebox 1.1.14 → 1.1.15
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.
|
@@ -5,14 +5,14 @@ import { Guard as G, EmitGuard as E } from '../../guard/index.mjs';
|
|
|
5
5
|
// Build
|
|
6
6
|
// ------------------------------------------------------------------
|
|
7
7
|
export function BuildPattern(stack, context, schema, value) {
|
|
8
|
-
const regexp = Externals.CreateVariable(G.IsString(schema.pattern) ? new RegExp(schema.pattern) : schema.pattern);
|
|
8
|
+
const regexp = Externals.CreateVariable(G.IsString(schema.pattern) ? new RegExp(schema.pattern, 'u') : schema.pattern);
|
|
9
9
|
return E.Call(E.Member(regexp, 'test'), [value]);
|
|
10
10
|
}
|
|
11
11
|
// ------------------------------------------------------------------
|
|
12
12
|
// Check
|
|
13
13
|
// ------------------------------------------------------------------
|
|
14
14
|
export function CheckPattern(stack, context, schema, value) {
|
|
15
|
-
const regexp = G.IsString(schema.pattern) ? new RegExp(schema.pattern) : schema.pattern;
|
|
15
|
+
const regexp = G.IsString(schema.pattern) ? new RegExp(schema.pattern, 'u') : schema.pattern;
|
|
16
16
|
return regexp.test(value);
|
|
17
17
|
}
|
|
18
18
|
// ------------------------------------------------------------------
|
|
@@ -9,7 +9,7 @@ import { BuildSchema, CheckSchema, ErrorSchema } from './schema.mjs';
|
|
|
9
9
|
export function BuildPatternProperties(stack, context, schema, value) {
|
|
10
10
|
return E.ReduceAnd(G.Entries(schema.patternProperties).map(([pattern, schema]) => {
|
|
11
11
|
const [key, prop] = [Unique(), Unique()];
|
|
12
|
-
const regexp = Externals.CreateVariable(new RegExp(pattern));
|
|
12
|
+
const regexp = Externals.CreateVariable(new RegExp(pattern, 'u'));
|
|
13
13
|
const notKey = E.Not(E.Call(E.Member(regexp, 'test'), [key]));
|
|
14
14
|
const isSchema = BuildSchema(stack, context, schema, prop);
|
|
15
15
|
const addKey = context.AddKey(key);
|
|
@@ -22,7 +22,7 @@ export function BuildPatternProperties(stack, context, schema, value) {
|
|
|
22
22
|
// ------------------------------------------------------------------
|
|
23
23
|
export function CheckPatternProperties(stack, context, schema, value) {
|
|
24
24
|
return G.Every(G.Entries(schema.patternProperties), 0, ([pattern, schema]) => {
|
|
25
|
-
const regexp = new RegExp(pattern);
|
|
25
|
+
const regexp = new RegExp(pattern, 'u');
|
|
26
26
|
return G.Every(G.Entries(value), 0, ([key, prop]) => {
|
|
27
27
|
return !regexp.test(key) || CheckSchema(stack, context, schema, prop) && context.AddKey(key);
|
|
28
28
|
});
|
|
@@ -34,7 +34,7 @@ export function CheckPatternProperties(stack, context, schema, value) {
|
|
|
34
34
|
export function ErrorPatternProperties(stack, context, schemaPath, instancePath, schema, value) {
|
|
35
35
|
return G.EveryAll(G.Entries(schema.patternProperties), 0, ([pattern, schema]) => {
|
|
36
36
|
const nextSchemaPath = `${schemaPath}/patternProperties/${pattern}`;
|
|
37
|
-
const regexp = new RegExp(pattern);
|
|
37
|
+
const regexp = new RegExp(pattern, 'u');
|
|
38
38
|
return G.EveryAll(G.Entries(value), 0, ([key, value]) => {
|
|
39
39
|
const nextInstancePath = `${instancePath}/${key}`;
|
|
40
40
|
const notKey = !regexp.test(key);
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -70,7 +70,7 @@ License: MIT
|
|
|
70
70
|
|
|
71
71
|
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/type/overview) | [Example](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFonmXW32POvueHb7kafo16ix4ic2oBjCADsAzvACqC1FDgBeREQB0AeWIArVNJgAKAN5wbtu-Yc26cWYpVqN2y5RvAAJgBcOmi6AMowUMByAObmAJQANI7JKfbONoRoQXgQxqYweAk+cHIAhiCoQYKoYRFRsYmpTQ7pcGDYaLDAqApB3jaoIKXAADZVeuGRMVaY0EMw2YPDI3hwAL5xya2+gXDWmZX4SlPRq2tFG81X11v0dmUVfXAH2cf1Z0U3X99w23BLoyexR+INSfwyRFedRihTgwNBCLSd3sGDmpQW+ABKzhiNxdj+a3heIRrUJxLxrSgqAAjgBXYBU3YAbSJ5J+fzw-lhrLZXw5D1Q3N5JORNjwWKowtBrQAujypc1nIThJJVWr1XxnOF0cBpCqNQbDZxqAc4Kp1FpgjVtTBdQAeA4QDBmjwAPmuzlN5s8e3lCqarX8QTeMU+-u+rQFweh0TD4ZurSx0ZOfvjjiVQA)
|
|
72
72
|
|
|
73
|
-
TypeBox types are JSON Schema fragments that
|
|
73
|
+
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.
|
|
74
74
|
|
|
75
75
|
## Example
|
|
76
76
|
|
|
@@ -113,13 +113,13 @@ type User = Type.Static<typeof User> // type User = {
|
|
|
113
113
|
|
|
114
114
|
## Script
|
|
115
115
|
|
|
116
|
-
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play
|
|
116
|
+
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play/#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFonmXW32POvueHb6AygGMowMDH6Ne0mbLnNqQiADsAzvADecAKqrUUADQ69UbWAAmAQxjoAvnAC8iIgDpho8QAoABtThxgZRsoDEshdABRIOBCOA1Kf39gcwAuOHVRZQBzBLhbPwCg-VDw4304VDIbZXNVOCiYGKQ4uFz-ZUsQVDSMwKyjNoqQS2AAGx6YTKzW-3zcwjQy0wtrdCcIgDdLUYBXVYAeQYAFYCEAa33dfSMz1CQIDHrowgA+OAAyGcSjy1hgbf2AHkQDFLiYbncHk9Gq8Xrk4ZRvABKah0KTyDGYzGSABKqAwo1QQgkaKxZPJvEUKlUEEJLlGECyniuUCRiXZHM5XK5aPi3P5AsFgrR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68O4ZXAC4W7cXSuUyxXKzri0G2lQG-6ldZ6225SjIhTZFT0rT6WDRuNJozk5yu93+fRBe78GLJTsZTPZ4r58rVYYVBqteuN2zHYbQyaPZGQt7bUee1uXDWXWHTXhPVfrTfb3OWc2Q67zxGFreoeX7xluiagQ6W5ppm2aoLmlglm4eCdpBUHRsSZJYdhnCCP4EzHJhOHEcR1AmkMYKpDM+EqBIAA8JoQBgFGGAAfPKKLkRcqTamhPJKqeb7BJ+fGskqj5eEJImicySq-pJl7BCBaG9mRRAsVAY6rFRnQwAR9GMcxFxaZM7FwJx6nGWM2maLxMliVugmKdJ9nmVuj4APwKRaLn2XJzRtF5cBCcpkG9kAA)
|
|
117
117
|
|
|
118
118
|
TypeBox can transform TypeScript definitions into JSON Schema. The Script function provides an optional programmatic syntax to rapidly convert type definitions into JSON Schema, or serve more generally as an alternative to Type.* builders. The Script function is designed to handle a wide array of complex TypeScript type-level expressions.
|
|
119
119
|
|
|
120
120
|
### Example
|
|
121
121
|
|
|
122
|
-
The following uses the Script to parse interfaces into JSON Schema.
|
|
122
|
+
The following uses the Script function to parse TypeScript interfaces into JSON Schema.
|
|
123
123
|
|
|
124
124
|
```typescript
|
|
125
125
|
import Type from 'typebox'
|
|
@@ -130,19 +130,20 @@ import Type from 'typebox'
|
|
|
130
130
|
|
|
131
131
|
const { User, UserUpdate } = Type.Script(`
|
|
132
132
|
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
133
|
+
interface Entity {
|
|
134
|
+
id: string
|
|
135
|
+
}
|
|
136
136
|
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
137
|
+
interface User extends Entity {
|
|
138
|
+
name: string,
|
|
139
|
+
email: string
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
type UserUpdate = Evaluate<
|
|
143
|
+
Pick<User, keyof Entity> &
|
|
144
|
+
Partial<Omit<User, keyof Entity>>
|
|
145
|
+
>
|
|
141
146
|
|
|
142
|
-
type UserUpdate = Evaluate<
|
|
143
|
-
Pick<User, keyof Entity> &
|
|
144
|
-
Partial<Omit<User, keyof Entity>>
|
|
145
|
-
>
|
|
146
147
|
`)
|
|
147
148
|
|
|
148
149
|
// -------------------------------------------------------------------------------
|
|
@@ -195,9 +196,9 @@ type UserUpdate = Type.Static<typeof UserUpdate> // type UserUpdate = {
|
|
|
195
196
|
|
|
196
197
|
## Schema
|
|
197
198
|
|
|
198
|
-
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/schema/overview) | [Example 1](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAZQMYAsCmICGcBmUIhwDkMAnmGgEYQAeA9AM6oaZEBQokscAKuWrnyES-ajXZs6dOAFo58hYqXKVqteo0zJ0gMIEwwADZptszeYuWr8tmyQQAdg3gBVBmihwAvImZYAdHrgRmgAFHwU-gDylABWaEgwoQDebHBwwAAmAFy8-P4IMFDADgDmoQCUADRpcA6YIGi5EWgFRSXl1bUsRs35hcVlKbjQWDC5RD2GRHAAvhVs8wum1qtr61pScAAKmFDuKxtHx6q29k7wAK7unj5uHv67+2HJ6W-vH5-vW+fOcNceXKpdJZCYANgArDgAIyYABMlAAzEgACyZCFoME4ADsmAAHJQAJxIAAMmWhRCqX2pcC2IJycGcg1KNXS9UaEwBUEpNN5fO+0jZDSajPaZVZcCmnJuAAFMgRMCV-PYQDN+by6ZKsL1RczFhV1YajR8trNvHB-JagA) | [Example 2](https://www.typescriptlang.org/play
|
|
199
|
+
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/schema/overview) | [Example 1](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAZQMYAsCmICGcBmUIhwDkMAnmGgEYQAeA9AM6oaZEBQokscAKuWrnyES-ajXZs6dOAFo58hYqXKVqteo0zJ0gMIEwwADZptszeYuWr8tmyQQAdg3gBVBmihwAvImZYAdHrgRmgAFHwU-gDylABWaEgwoQDebHBwwAAmAFy8-P4IMFDADgDmoQCUADRpcA6YIGi5EWgFRSXl1bUsRs35hcVlKbjQWDC5RD2GRHAAvhVs8wum1qtr61pScAAKmFDuKxtHx6q29k7wAK7unj5uHv67+2HJ6W-vH5-vW+fOcNceXKpdJZCYANgArDgAIyYABMlAAzEgACyZCFoME4ADsmAAHJQAJxIAAMmWhRCqX2pcC2IJycGcg1KNXS9UaEwBUEpNN5fO+0jZDSajPaZVZcCmnJuAAFMgRMCV-PYQDN+by6ZKsL1RczFhV1YajR8trNvHB-JagA) | [Example 2](https://www.typescriptlang.org/play/#code/JYWwDg9gTgLgBAZQMYAsCmICGcBmUIhwDkMAnmGgEYQAeA9AM6oaZEBQbddcAtH-wMFDhI0WPESenbgGECYYABs003pPUbNW-hyQQAdg3gBVBmihwAvImZYAdHPBK0ACgDebOHDIUAXMQhKACs0JBgiABpPODB8ClhgNAZ-Dy8vYAATFO9yNH8iIyhgfQBzIjgAXyi0uH1MEDy4Nxy-YkLissrqtJYlbJ9Ggpgi0sjcaCwYfN7FcoroquioNABHAFdgZay4AG1oryJMsf3iOobjmqIZ9i8AXTYKgEoOLjVtd4+P1QAFTCgzVSfIHAyS6AxGOBrMwWaymcx2X7-VzNGqotHouCvPSGeBQ8wpaKZfIANgArDgAIyYABMlAAzEgACwZUloYk4ADsmAAHJQAJxIAAMGQpYwx6Ne6W27VK3TOgzxUDF4pVqq8ktq9UaMpK3Rm+UVAAEMgRMMU7HoQOU1SqNfq4DqHo8bS7XajXhUrHA7D6gA) | [Specification](https://sinclairzx81.github.io/typebox/#/docs/schema/6_specification)
|
|
199
200
|
|
|
200
|
-
TypeBox includes
|
|
201
|
+
TypeBox includes a JSON Schema compiler designed for high-performance JIT validation. It also provides automatic fallback to dynamic interpreted checking for JIT restrictive environments such as Cloudflare Workers. The compiler is designed to be a lightweight, spec compliant alternative to Ajv for high-throughput applications based on the JSON Schema standard.
|
|
201
202
|
|
|
202
203
|
### Example
|
|
203
204
|
|
|
@@ -233,10 +234,10 @@ const user = User.Parse({ // const user: {
|
|
|
233
234
|
|
|
234
235
|
TypeBox provides two distinct versions that span two generations of the TypeScript compiler.
|
|
235
236
|
|
|
236
|
-
|
|
|
237
|
+
| TypeBox | TypeScript | Description |
|
|
237
238
|
| :--- | :--- | :--- |
|
|
238
|
-
|
|
|
239
|
-
|
|
|
239
|
+
| 1.x | 6.0 - 7.0+ | **Latest.** Developed against the TypeScript 7 native compiler. Provides advanced type inference and native JSON Schema 2020-12 support. Includes backwards compatibility with `0.x` types. **ESM only.** |
|
|
240
|
+
| 0.x | 5.0 - 6.0 | **LTS.** Developed against older TypeScript versions and actively maintained under Long Term Support. Compatible with both **ESM and CJS**. Issues should be submitted to the [Sinclair TypeBox](https://github.com/sinclairzx81/sinclair-typebox) repository. |
|
|
240
241
|
|
|
241
242
|
## Contribute
|
|
242
243
|
|