@depup/typebox 1.3.27-depup.0 → 1.3.34-depup.0
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/README.md +2 -2
- package/build/compile/code.mjs +1 -2
- package/build/compile/validator.mjs +5 -1
- package/build/format/iri.mjs +16 -9
- package/build/guard/emit.mjs +2 -2
- package/build/guard/guard.d.mts +7 -5
- package/build/guard/guard.mjs +14 -9
- package/build/guard/index.mjs +6 -0
- package/build/guard/unicode/unicode.d.mts +6 -0
- package/build/guard/unicode/unicode.mjs +35 -0
- package/build/guard/{string.mjs → unicode/unicode_segment.mjs} +16 -19
- package/build/schema/build.mjs +4 -5
- package/build/schema/check.mjs +1 -1
- package/build/schema/engine/_context.d.mts +5 -1
- package/build/schema/engine/_context.mjs +16 -3
- package/build/schema/engine/_functions.d.mts +2 -2
- package/build/schema/engine/_functions.mjs +1 -1
- package/build/schema/engine/_pathing.d.mts +1 -0
- package/build/schema/engine/_pathing.mjs +11 -0
- package/build/schema/engine/_reducer.d.mts +3 -3
- package/build/schema/engine/_refine.d.mts +5 -5
- package/build/schema/engine/_refine.mjs +14 -9
- package/build/schema/engine/_stack.d.mts +34 -20
- package/build/schema/engine/_stack.mjs +143 -202
- package/build/schema/engine/additionalItems.d.mts +4 -4
- package/build/schema/engine/additionalProperties.d.mts +8 -8
- package/build/schema/engine/additionalProperties.mjs +12 -15
- package/build/schema/engine/allOf.d.mts +4 -4
- package/build/schema/engine/allOf.mjs +1 -1
- package/build/schema/engine/anyOf.d.mts +4 -4
- package/build/schema/engine/anyOf.mjs +4 -9
- package/build/schema/engine/boolean.d.mts +4 -4
- package/build/schema/engine/boolean.mjs +2 -6
- package/build/schema/engine/const.d.mts +4 -4
- package/build/schema/engine/const.mjs +2 -6
- package/build/schema/engine/contains.d.mts +4 -4
- package/build/schema/engine/contains.mjs +2 -6
- package/build/schema/engine/dependencies.d.mts +4 -4
- package/build/schema/engine/dependencies.mjs +5 -7
- package/build/schema/engine/dependentRequired.d.mts +4 -4
- package/build/schema/engine/dependentRequired.mjs +2 -6
- package/build/schema/engine/dependentSchemas.d.mts +4 -4
- package/build/schema/engine/dependentSchemas.mjs +2 -1
- package/build/schema/engine/dynamicRef.d.mts +4 -4
- package/build/schema/engine/dynamicRef.mjs +12 -8
- package/build/schema/engine/enum.d.mts +4 -4
- package/build/schema/engine/enum.mjs +2 -6
- package/build/schema/engine/exclusiveMaximum.d.mts +4 -4
- package/build/schema/engine/exclusiveMaximum.mjs +2 -6
- package/build/schema/engine/exclusiveMinimum.d.mts +4 -4
- package/build/schema/engine/exclusiveMinimum.mjs +2 -6
- package/build/schema/engine/format.d.mts +4 -4
- package/build/schema/engine/format.mjs +11 -8
- package/build/schema/engine/if.d.mts +4 -4
- package/build/schema/engine/if.mjs +5 -13
- package/build/schema/engine/items.d.mts +4 -4
- package/build/schema/engine/items.mjs +1 -1
- package/build/schema/engine/maxContains.d.mts +4 -4
- package/build/schema/engine/maxContains.mjs +2 -6
- package/build/schema/engine/maxItems.d.mts +4 -4
- package/build/schema/engine/maxItems.mjs +2 -6
- package/build/schema/engine/maxLength.d.mts +4 -4
- package/build/schema/engine/maxLength.mjs +2 -6
- package/build/schema/engine/maxProperties.d.mts +4 -4
- package/build/schema/engine/maxProperties.mjs +2 -6
- package/build/schema/engine/maximum.d.mts +4 -4
- package/build/schema/engine/maximum.mjs +2 -6
- package/build/schema/engine/minContains.d.mts +4 -4
- package/build/schema/engine/minContains.mjs +2 -6
- package/build/schema/engine/minItems.d.mts +5 -5
- package/build/schema/engine/minItems.mjs +2 -6
- package/build/schema/engine/minLength.d.mts +4 -4
- package/build/schema/engine/minLength.mjs +2 -6
- package/build/schema/engine/minProperties.d.mts +4 -4
- package/build/schema/engine/minProperties.mjs +2 -6
- package/build/schema/engine/minimum.d.mts +4 -4
- package/build/schema/engine/minimum.mjs +2 -6
- package/build/schema/engine/multipleOf.d.mts +4 -4
- package/build/schema/engine/multipleOf.mjs +2 -6
- package/build/schema/engine/not.d.mts +4 -4
- package/build/schema/engine/not.mjs +4 -8
- package/build/schema/engine/oneOf.d.mts +4 -4
- package/build/schema/engine/oneOf.mjs +5 -10
- package/build/schema/engine/pattern.d.mts +4 -4
- package/build/schema/engine/pattern.mjs +3 -7
- package/build/schema/engine/patternProperties.d.mts +4 -4
- package/build/schema/engine/patternProperties.mjs +4 -3
- package/build/schema/engine/prefixItems.d.mts +4 -4
- package/build/schema/engine/prefixItems.mjs +1 -1
- package/build/schema/engine/properties.d.mts +4 -4
- package/build/schema/engine/properties.mjs +4 -3
- package/build/schema/engine/propertyNames.d.mts +4 -4
- package/build/schema/engine/propertyNames.mjs +5 -8
- package/build/schema/engine/recursiveRef.d.mts +4 -4
- package/build/schema/engine/recursiveRef.mjs +12 -8
- package/build/schema/engine/ref.d.mts +4 -4
- package/build/schema/engine/ref.mjs +18 -14
- package/build/schema/engine/required.d.mts +4 -4
- package/build/schema/engine/required.mjs +2 -6
- package/build/schema/engine/schema.d.mts +7 -7
- package/build/schema/engine/schema.mjs +136 -138
- package/build/schema/engine/type.d.mts +4 -4
- package/build/schema/engine/type.mjs +2 -6
- package/build/schema/engine/unevaluatedItems.d.mts +4 -4
- package/build/schema/engine/unevaluatedItems.mjs +3 -7
- package/build/schema/engine/unevaluatedProperties.d.mts +4 -4
- package/build/schema/engine/unevaluatedProperties.mjs +3 -7
- package/build/schema/engine/uniqueItems.d.mts +4 -4
- package/build/schema/engine/uniqueItems.mjs +2 -6
- package/build/schema/errors.mjs +1 -1
- package/build/schema/intern/intern.d.mts +6 -9
- package/build/schema/intern/intern.mjs +90 -56
- package/build/schema/meta/draft_2019_09.d.mts +2 -0
- package/build/schema/meta/draft_2019_09.mjs +288 -0
- package/build/schema/meta/draft_2020_12.d.mts +2 -0
- package/build/schema/meta/draft_2020_12.mjs +300 -0
- package/build/schema/meta/draft_3.d.mts +2 -0
- package/build/schema/meta/draft_3.mjs +143 -0
- package/build/schema/meta/draft_4.d.mts +2 -0
- package/build/schema/meta/draft_4.mjs +149 -0
- package/build/schema/meta/draft_6.d.mts +2 -0
- package/build/schema/meta/draft_6.mjs +155 -0
- package/build/schema/meta/draft_7.d.mts +2 -0
- package/build/schema/meta/draft_7.mjs +172 -0
- package/build/schema/meta/index.d.mts +2 -0
- package/build/schema/meta/index.mjs +2 -0
- package/build/schema/meta/meta.d.mts +9 -0
- package/build/schema/meta/meta.mjs +15 -0
- package/build/schema/meta/schema.d.mts +6 -0
- package/build/schema/meta/schema.mjs +1 -0
- package/build/schema/parse.mjs +3 -0
- package/build/schema/pointer/pointer.d.mts +1 -6
- package/build/schema/pointer/pointer.mjs +47 -64
- package/build/schema/resolve/resolve.d.mts +6 -32
- package/build/schema/resolve/resolve.mjs +231 -227
- package/build/schema/schema.d.mts +1 -0
- package/build/schema/schema.mjs +1 -0
- package/build/system/settings/internal.d.mts +2 -0
- package/build/system/settings/internal.mjs +20 -0
- package/build/system/settings/settings.d.mts +11 -0
- package/build/system/settings/settings.mjs +14 -0
- package/build/type/extends/inference.d.mts +1 -1
- package/build/type/extends/inference.mjs +15 -2
- package/build/type/extends/tuple.d.mts +2 -1
- package/build/type/extends/tuple.mjs +21 -1
- package/build/value/parse/parse.mjs +10 -4
- package/changes.json +1 -1
- package/package.json +3 -3
- package/readme.md +52 -84
- /package/build/guard/{string.d.mts → unicode/unicode_segment.d.mts} +0 -0
|
@@ -1,8 +1,12 @@
|
|
|
1
1
|
import { Guard } from '../../guard/index.mjs';
|
|
2
|
+
// -------------------------------------------------------------------
|
|
3
|
+
// State
|
|
4
|
+
// -------------------------------------------------------------------
|
|
2
5
|
// Internal mutable state
|
|
3
6
|
const settings = {
|
|
4
7
|
immutableTypes: false,
|
|
5
8
|
maxErrors: 8,
|
|
9
|
+
maxParseErrors: 1,
|
|
6
10
|
maxInstantiationCount: 128,
|
|
7
11
|
useAcceleration: true,
|
|
8
12
|
exactOptionalPropertyTypes: false,
|
|
@@ -10,10 +14,14 @@ const settings = {
|
|
|
10
14
|
correctiveParse: false,
|
|
11
15
|
unionPrioritySort: true
|
|
12
16
|
};
|
|
17
|
+
// -------------------------------------------------------------------
|
|
18
|
+
// Reset
|
|
19
|
+
// -------------------------------------------------------------------
|
|
13
20
|
/** Resets system settings to defaults */
|
|
14
21
|
export function Reset() {
|
|
15
22
|
settings.immutableTypes = false;
|
|
16
23
|
settings.maxErrors = 8;
|
|
24
|
+
settings.maxParseErrors = 1;
|
|
17
25
|
settings.maxInstantiationCount = 128;
|
|
18
26
|
settings.useAcceleration = true;
|
|
19
27
|
settings.exactOptionalPropertyTypes = false;
|
|
@@ -21,6 +29,9 @@ export function Reset() {
|
|
|
21
29
|
settings.correctiveParse = false;
|
|
22
30
|
settings.unionPrioritySort = true;
|
|
23
31
|
}
|
|
32
|
+
// -------------------------------------------------------------------
|
|
33
|
+
// Set
|
|
34
|
+
// -------------------------------------------------------------------
|
|
24
35
|
/** Sets system settings */
|
|
25
36
|
export function Set(options) {
|
|
26
37
|
for (const key of Guard.Keys(options)) {
|
|
@@ -30,6 +41,9 @@ export function Set(options) {
|
|
|
30
41
|
}
|
|
31
42
|
}
|
|
32
43
|
}
|
|
44
|
+
// -------------------------------------------------------------------
|
|
45
|
+
// Get
|
|
46
|
+
// -------------------------------------------------------------------
|
|
33
47
|
/** Gets current system settings */
|
|
34
48
|
export function Get() {
|
|
35
49
|
return settings;
|
|
@@ -22,7 +22,7 @@ export declare function TryRestInferable<Type extends TSchema>(type: Type): TTry
|
|
|
22
22
|
export type TTryInferable<Type extends TSchema, Result extends TInferable | undefined = (Type extends TInfer<infer Name extends string, infer Type extends TSchema> ? TInferable<Name, Type> : undefined)> = Result;
|
|
23
23
|
export declare function TryInferable<Type extends TSchema>(type: Type): TTryInferable<Type>;
|
|
24
24
|
type TryInferResults<Rest extends TSchema[], Right extends TSchema, Result extends TSchema[] = []> = (Rest extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TExtendsLeft<{}, Head, Right> extends Result.TExtendsTrueLike ? TryInferResults<Tail, Right, [...Result, Head]> : undefined : Result);
|
|
25
|
-
declare function TryInferResults<Rest extends TSchema[], Right extends TSchema>(rest: [...Rest], right: Right
|
|
25
|
+
declare function TryInferResults<Rest extends TSchema[], Right extends TSchema>(rest: [...Rest], right: Right): TryInferResults<Rest, Right>;
|
|
26
26
|
export type TInferTupleResult<Inferred extends TProperties, Name extends string, Left extends TSchema[], Right extends TSchema, Results extends TSchema[] | undefined = TryInferResults<Left, Right>> = (Results extends [...infer Results extends TSchema[]] ? Result.TExtendsTrue<Memory.TAssign<Inferred, {
|
|
27
27
|
[_ in Name]: TTuple<Results>;
|
|
28
28
|
}>> : Result.TExtendsFalse);
|
|
@@ -45,8 +45,21 @@ export function TryInferable(type) {
|
|
|
45
45
|
return (IsInfer(type) ? Inferrable(type.name, type.extends) :
|
|
46
46
|
undefined);
|
|
47
47
|
}
|
|
48
|
-
function TryInferResults(rest, right, result = []) {
|
|
49
|
-
|
|
48
|
+
// function TryInferResults<Rest extends TSchema[], Right extends TSchema>(rest: [...Rest], right: Right, result: TSchema[] = []): TryInferResults<Rest, Right> {
|
|
49
|
+
// return Guard.ShiftLeft(rest, (head, tail) =>
|
|
50
|
+
// Result.Match(ExtendsLeft({}, head, right),
|
|
51
|
+
// () => TryInferResults(tail, right, [...result, head]), // Stack Overflow Here (Large Rest)
|
|
52
|
+
// () => undefined),
|
|
53
|
+
// () => result) as never
|
|
54
|
+
// }
|
|
55
|
+
function TryInferResults(rest, right) {
|
|
56
|
+
const result = [];
|
|
57
|
+
for (const head of rest) {
|
|
58
|
+
if (!Result.IsExtendsTrueLike(ExtendsLeft({}, head, right)))
|
|
59
|
+
return undefined;
|
|
60
|
+
result.push(head);
|
|
61
|
+
}
|
|
62
|
+
return result;
|
|
50
63
|
}
|
|
51
64
|
export function InferTupleResult(inferred, name, left, right) {
|
|
52
65
|
const results = TryInferResults(left, right);
|
|
@@ -16,7 +16,8 @@ type TElementsLeft<Inferred extends TProperties, Reversed extends boolean, LeftR
|
|
|
16
16
|
type TElementsRight<Inferred extends TProperties, Reversed extends boolean, LeftRest extends TSchema[], RightRest extends TSchema[]> = (RightRest extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TElementsLeft<Inferred, Reversed, LeftRest, Head, Tail> : LeftRest['length'] extends 0 ? Result.TExtendsTrue<Inferred> : Result.TExtendsFalse);
|
|
17
17
|
type TElements<Inferred extends TProperties, Reversed extends boolean, LeftRest extends TSchema[], RightRest extends TSchema[]> = TElementsRight<Inferred, Reversed, LeftRest, RightRest>;
|
|
18
18
|
type TExtendsTupleToTuple<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema[], InstantiatedRight extends TSchema[] = TInstantiateElements<Inferred, TState<[], []>, Right>, Reversed extends boolean = TReversed<InstantiatedRight>> = TElements<Inferred, Reversed, TApplyReverse<Left, Reversed>, TApplyReverse<InstantiatedRight, Reversed>>;
|
|
19
|
-
type
|
|
19
|
+
type TExtendsTupleToArrayReduce<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema> = (Left extends [infer Head extends TSchema, ...infer Tail extends TSchema[]] ? TExtendsLeft<Inferred, Head, Right> extends Result.TExtendsTrueLike<infer Inferred extends TProperties> ? TExtendsTupleToArrayReduce<Inferred, Tail, Right> : Result.TExtendsFalse : Result.TExtendsTrue<Inferred>);
|
|
20
|
+
type TExtendsTupleToArray<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema, Inferrable extends TInferable | undefined = TTryInferable<Right>> = (Inferrable extends TInferable ? TInferUnionResult<Inferred, Inferrable['name'], Left, Inferrable['type']> : TExtendsTupleToArrayReduce<Inferred, Left, Right>);
|
|
20
21
|
export type TExtendsTuple<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema, InstantiatedLeft extends TSchema[] = TInstantiateElements<Inferred, TState<[], []>, Left>> = (Right extends TTuple<infer Types extends TSchema[]> ? TExtendsTupleToTuple<Inferred, InstantiatedLeft, Types> : Right extends TArray<infer Type extends TSchema> ? TExtendsTupleToArray<Inferred, InstantiatedLeft, Type> : TExtendsRight<Inferred, TTuple<InstantiatedLeft>, Right>);
|
|
21
22
|
export declare function ExtendsTuple<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema>(inferred: Inferred, left: Left, right: Right): TExtendsTuple<Inferred, Left, Right>;
|
|
22
23
|
export {};
|
|
@@ -47,11 +47,31 @@ function ExtendsTupleToTuple(inferred, left, right) {
|
|
|
47
47
|
const reversed = Reversed(instantiatedRight);
|
|
48
48
|
return Elements(inferred, reversed, ApplyReverse(left, reversed), ApplyReverse(instantiatedRight, reversed));
|
|
49
49
|
}
|
|
50
|
+
// function ExtendsTupleToArrayReduce<Inferred extends TProperties, Left extends TSchema[], Right extends TSchema>
|
|
51
|
+
// (inferred: Inferred, left: [...Left], right: Right):
|
|
52
|
+
// TExtendsTupleToArrayReduce<Inferred, Left, Right> {
|
|
53
|
+
// return (
|
|
54
|
+
// Guard.ShiftLeft(left, (head, tail) =>
|
|
55
|
+
// Result.Match(ExtendsLeft(inferred, head, right), inferred =>
|
|
56
|
+
// ExtendsTupleToArrayReduce(inferred, tail, right), // Stack Overflow Here (Large Left)
|
|
57
|
+
// () => Result.ExtendsFalse()),
|
|
58
|
+
// () => Result.ExtendsTrue(inferred))
|
|
59
|
+
// ) as never
|
|
60
|
+
// }
|
|
61
|
+
function ExtendsTupleToArrayReduce(inferred, left, right) {
|
|
62
|
+
for (const head of left) {
|
|
63
|
+
const result = ExtendsLeft(inferred, head, right);
|
|
64
|
+
if (!Result.IsExtendsTrueLike(result))
|
|
65
|
+
return result;
|
|
66
|
+
inferred = result.inferred; // (review-assign-to-argument)
|
|
67
|
+
}
|
|
68
|
+
return Result.ExtendsTrue(inferred);
|
|
69
|
+
}
|
|
50
70
|
function ExtendsTupleToArray(inferred, left, right) {
|
|
51
71
|
const inferrable = TryInferable(right);
|
|
52
72
|
return (IsInferable(inferrable)
|
|
53
73
|
? InferUnionResult(inferred, inferrable['name'], left, inferrable['type'])
|
|
54
|
-
:
|
|
74
|
+
: ExtendsTupleToArrayReduce(inferred, left, right));
|
|
55
75
|
}
|
|
56
76
|
export function ExtendsTuple(inferred, left, right) {
|
|
57
77
|
const instantiatedLeft = InstantiateElements(inferred, State([], []), left);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// deno-fmt-ignore-file
|
|
2
|
-
import {
|
|
3
|
-
import { Arguments } from '../../system/
|
|
2
|
+
import { EnableParseErrors, DisableParseErrors } from '../../system/settings/internal.mjs';
|
|
3
|
+
import { Arguments, Settings } from '../../system/index.mjs';
|
|
4
4
|
import { AssertError } from '../assert/index.mjs';
|
|
5
5
|
import { Check } from '../check/index.mjs';
|
|
6
6
|
import { Errors } from '../errors/index.mjs';
|
|
@@ -18,8 +18,11 @@ export class ParseError extends AssertError {
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
function Assert(context, type, value) {
|
|
21
|
+
EnableParseErrors();
|
|
22
|
+
const errors = Errors(context, type, value);
|
|
23
|
+
DisableParseErrors();
|
|
21
24
|
if (!Check(context, type, value))
|
|
22
|
-
throw new ParseError(value,
|
|
25
|
+
throw new ParseError(value, errors);
|
|
23
26
|
return value;
|
|
24
27
|
}
|
|
25
28
|
// ------------------------------------------------------------------
|
|
@@ -43,5 +46,8 @@ export function Parse(...args) {
|
|
|
43
46
|
return value;
|
|
44
47
|
if (Settings.Get().correctiveParse)
|
|
45
48
|
return Parser(context, type, value);
|
|
46
|
-
|
|
49
|
+
EnableParseErrors();
|
|
50
|
+
const errors = Errors(context, type, value);
|
|
51
|
+
DisableParseErrors();
|
|
52
|
+
throw new ParseError(value, errors);
|
|
47
53
|
}
|
package/changes.json
CHANGED
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@depup/typebox",
|
|
3
3
|
"description": "Json Schema Type Builder with Static Type Resolution for TypeScript (with updated dependencies)",
|
|
4
|
-
"version": "1.3.
|
|
4
|
+
"version": "1.3.34-depup.0",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"typebox",
|
|
7
7
|
"depup",
|
|
@@ -94,8 +94,8 @@
|
|
|
94
94
|
"changes": {},
|
|
95
95
|
"depsUpdated": 0,
|
|
96
96
|
"originalPackage": "typebox",
|
|
97
|
-
"originalVersion": "1.3.
|
|
98
|
-
"processedAt": "2026-09-
|
|
97
|
+
"originalVersion": "1.3.34",
|
|
98
|
+
"processedAt": "2026-09-20T01:02:50.022Z",
|
|
99
99
|
"smokeTest": "passed"
|
|
100
100
|
}
|
|
101
101
|
}
|
package/readme.md
CHANGED
|
@@ -30,12 +30,12 @@ import Type from 'typebox'
|
|
|
30
30
|
|
|
31
31
|
const T = Type.Object({ // const T = {
|
|
32
32
|
x: Type.Number(), // type: 'object',
|
|
33
|
-
y: Type.Number(), //
|
|
34
|
-
z: Type.Number() //
|
|
35
|
-
}) //
|
|
33
|
+
y: Type.Number(), // required: ['x', 'y', 'z']
|
|
34
|
+
z: Type.Number() // properties: {
|
|
35
|
+
}) // x: { type: 'number' },
|
|
36
|
+
// y: { type: 'number' },
|
|
36
37
|
// z: { type: 'number' }
|
|
37
38
|
// },
|
|
38
|
-
// required: ['x', 'y', 'z']
|
|
39
39
|
// }
|
|
40
40
|
|
|
41
41
|
type T = Type.Static<typeof T> // type T = {
|
|
@@ -69,9 +69,9 @@ License: MIT
|
|
|
69
69
|
|
|
70
70
|
## Type
|
|
71
71
|
|
|
72
|
-
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/type/overview) | [Example](https://www.typescriptlang.org/play
|
|
72
|
+
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/type/overview) | [Example](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgYwgDsBneAVUdSjgF5EiA6APLEAVqhowAFAG84sufIWLZAemVw6TVu048plWcAAmALl5o+AZRhRg9AOYSAlABolb9wtVzCaU3ggiYjB4zvpw9ACGIKimyOZWNvZOrh6pnmqyUKgAjgCuwFkmcADaYaggEcAANrH8CbYOMhjQFTB+5ZVVeHAAvo5uXvJ4RiFwlH1pk1MDGXJ4kdGjYdMrK4NzHdVUqztT6wC6obvHHutg2GiwwKiMpnonD4rrBkUyPjH4zIl23T1HjwC4M9wlEPm8iH4vg1fv9AQ9gZsanAZMs4cdgbJ3pDrNDXKi0TsMZgWhE2vhEd18QS1rNZD0qdS9rN6Yzdl56ZR3nA2BxuGZUJYYKTgDQADzvCAYbnaAB8TLgXJ5OmRDNZaXWRlMUPssLV03WCw+2rsur1k3WiK1OPsqrNM16QA)
|
|
73
73
|
|
|
74
|
-
TypeBox types are JSON Schema fragments that compose into more complex types. The library
|
|
74
|
+
TypeBox types are JSON Schema fragments that compose into more complex types. The library provides a core set of types for constructing JSON Schema compliant schematics, alongside extended types designed to model constructs native to JavaScript and TypeScript. The JSON Schema schematics produced by TypeBox can be passed directly to any compliant validator.
|
|
75
75
|
|
|
76
76
|
### Example
|
|
77
77
|
|
|
@@ -80,38 +80,33 @@ The following creates a User type and infers with Static.
|
|
|
80
80
|
```typescript
|
|
81
81
|
import Type from 'typebox'
|
|
82
82
|
|
|
83
|
-
// Type
|
|
84
|
-
|
|
85
83
|
const User = Type.Object({ // const User = {
|
|
86
84
|
id: Type.String(), // type: 'object',
|
|
87
|
-
name: Type.String(), //
|
|
88
|
-
email: Type.String({ format: 'email' }) // id
|
|
89
|
-
}) // name
|
|
85
|
+
name: Type.String(), // required: [
|
|
86
|
+
email: Type.String({ format: 'email' }) // 'id',
|
|
87
|
+
}) // 'name',
|
|
88
|
+
// 'email'
|
|
89
|
+
// ],
|
|
90
|
+
// properties: {
|
|
91
|
+
// id: { type: 'string' },
|
|
92
|
+
// name: { type: 'string' },
|
|
90
93
|
// email: {
|
|
91
94
|
// type: 'string',
|
|
92
95
|
// format: 'email'
|
|
93
96
|
// }
|
|
94
|
-
// }
|
|
95
|
-
// required: [
|
|
96
|
-
// 'id',
|
|
97
|
-
// 'name',
|
|
98
|
-
// 'email'
|
|
99
|
-
// ]
|
|
97
|
+
// }
|
|
100
98
|
// }
|
|
101
99
|
|
|
102
|
-
// Static
|
|
103
|
-
|
|
104
100
|
type User = Type.Static<typeof User> // type User = {
|
|
105
101
|
// id: string,
|
|
106
102
|
// name: string,
|
|
107
103
|
// email: string
|
|
108
104
|
// }
|
|
109
|
-
|
|
110
105
|
```
|
|
111
106
|
|
|
112
107
|
## Script
|
|
113
108
|
|
|
114
|
-
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play/?target=99&module=7#code/
|
|
109
|
+
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/script/overview) | [Example 1](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgYwgDsBneAWQEMYALOAXkSIB0AZRpRgYGAAoABpThxCaOADVUNGNAAsvOAG84ZAFxx6AVxDFUUADRwkxsxau2AXg-OWbcAO7unUOABfOQUiFTUNKABmHX0jEw9nOz9PVxSrIJDFdFV1aAAmWIN0r3sE-0zpAEpqOiZ4AHEoNjBOYBpGHWQ0YVFxKXYuW1l5bPDYVDJYkPlIRmAYYAZjXMjNaxmTaBA2ABsViOgojfl5UwA3A7yofJDg0bCG1BxUGCgkadO4c6tFmlRGAcJmQANoAXROp2A9AAJu0ASVwXcsmFBlZgHtPqc2BZgKh6DArmtIfI4RgMKZGKgiVoSXBGGgaKZdmwoDSoJpkQ8lCwAdw+LpNgBzZ4gV7vYxPF5vJB0nYwdF7YxosR7ZHVahjXmMfn8HpCGAcdoAHmyEAwcCaLTaHRBeG1nDwYIAfPIAPRu0I8vlYr5+-0BwNBoMe04i6USvRwAQxoJ04MJxNJ0PyeWK-ZRmMCTJJ3N5wOhwJAA) | [Example 2](https://www.typescriptlang.org/play/?target=99&module=7#code/JYWwDg9gTgLgBAFQJ5gKZwGZQiOByGFVAIwgA88AoSgehrgFkBDGAC0YgBMBXAG1WoBjCADsAzvABqqQTGgAWOAF5ERAHQB5YgCsZMABQBvOGQBcqtGoBy3EMVRR9ASgA0cJOeSWbdh87cAXp7qPvaOrnAA7sHetmHOcAC+TpTC4lJ60ADMyhaomjp6RiYx+aF+ER551nEVgaU1vuFJKWkScNKy0ABMuV75WrqyxWbV5eFuVf2N8U4t1HRwAOJQTGCswIJiHDz8QqLt0rCoZH3qg0WGlHBwkGLAMMCi5p1yUPIu13Ai0CBMvC9MlAsp8btwAG6ArpQbqUZKpA7wJaoHCoGBQJBnSwXYZXG7ghyPQSoMQNACCUFWSH0RxgJ1cX2AIk4mxJ5MpTGp03GzhS8La8GYdKgwH+WIGhVxXyYdmAqBEMChbw+XxZGAw3DEqCVClBcDEaEEfCYUB170+-MRjBJ7BU0xxBjxcAA5iiQGiMeZkaj0Ug9X9haKAYwWA4g3CUpRCGhrWJbdUAMowFibAA80ZRGFjrAAfDd8wXC4sM9nck7CxXK1XqzX84sbq6fZ64MY1G2knra13u1363AA2H-uZW+3El8exPJ3X6IkgA)
|
|
115
110
|
|
|
116
111
|
TypeBox includes a micro TypeScript engine that can transform TypeScript definitions to JSON Schema. The engine is fully type-safe and supports many programmable constructs including Conditional, Mapped, Indexed, Generics, Distributive Generics, and more.
|
|
117
112
|
|
|
@@ -122,16 +117,12 @@ Syntax highlighting is available via the [Visual Studio Marketplace](https://mar
|
|
|
122
117
|
```typescript
|
|
123
118
|
import Type from 'typebox'
|
|
124
119
|
|
|
125
|
-
// Math Module
|
|
126
|
-
|
|
127
120
|
const Math = Type.Script(`
|
|
128
121
|
type Vector4 = { x: number, y: number, z: number, w: number }
|
|
129
122
|
type Vector3 = { x: number, y: number, z: number }
|
|
130
123
|
type Vector2 = { x: number, y: number }
|
|
131
124
|
`)
|
|
132
125
|
|
|
133
|
-
// Graphics Module
|
|
134
|
-
|
|
135
126
|
const Graphics = Type.Script(Math, `
|
|
136
127
|
type Vertex = {
|
|
137
128
|
position: Vector4,
|
|
@@ -163,9 +154,9 @@ type Mesh = Type.Static<typeof Graphics['Mesh']> // type Mesh = {
|
|
|
163
154
|
|
|
164
155
|
## Schema
|
|
165
156
|
|
|
166
|
-
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/schema/overview) | [Example 1](https://www.typescriptlang.org/play
|
|
157
|
+
[Documentation](https://sinclairzx81.github.io/typebox/#/docs/schema/overview) | [Example 1](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAZQMYAsCmICGcBmUIhwDkMAnmGgEYQAeA9AM6oaZEBQokscAKuWrnyES-ajXZs6dOAGECYYABs0bNkggA7BvABqaJDGhwAvImZYAdHPBK0ACj4ULyKMDAw7AAwDebOHBoALjgNAFcQSjQoPzhSYLCIqJiAL3jwyOiAX08AShzVKVl0JABrVXUteAA3TEVgABMTOD0DaCtikrtvAOCARgAaWOCABkHUuGG4TJz-OEKK7Tgauvrg6ghlTA0C6QAFTCgGFTVNRag0BlDFeFMWwygLfcP7bqC4AaGJsZGpmbnpBbwc6Xa7BbqzfwxCHQmGwuHwhGFfxvBIZKEIjGYrH+JGfVFJbGEokw3HjfHRYmUomFTJAA) | [Example 2](https://www.typescriptlang.org/play/?#code/JYWwDg9gTgLgBAZQMYAsCmICGcBmUIhwDkMAnmGgEYQAeA9AM6oaZEBQokscAKuWrnyES-ajXZs6dOAGECYYABs0bNkggA7BvABqaJDGhwAvImZYAdHPBK0ACj4ULAeUoArfTDsBvNnDg0AFy8-BYAcgCuIJRoUHYAlAA0fnCkwY5o4VExcUkpAF7poZHRsQlsAL7x8apSsuhIANaq6lrwAG6YisAAJiZwegbQVg2NPgHBAIyJqcEADDOFcHNwVf5wda3acJ3dPcHUEMqYGrXSAAqYUAwqaprbUGgMEYrwpoOGUBaX1-beE3BprNlot5qt4v5Nvd4I9nq9gv91v4UkjUWj0RjMVi6v4gnANNlYiisSTSWTIdJ-Gl8YSoMTyQzGRT1ksCaU6UzOYy6hUgA) | [Example 3](https://www.typescriptlang.org/play/#code/JYWwDg9gTgLgBAZQMYAsCmICGcBmUIhwDkMAnmGgEYQAeA9AM6oaZEBQbddcAwgWMAA2aDkggA7BvABqaJDGhwAvImZYAdH3BC0ACgDebOHDIUAXMQiUAVnJhEANEbhQ0ARwCuwVwBMLAbSIaR2JSEKIALyIAXSdjMHwKWGA0BgtDY2MadJNyNAsicQ8QSjQoIjgAXzjM0hzTfOIikrKK6udjCPq8gubS8qrnSrZKgEoOLl50JABrUQkpOAA3TEFgH2U4WXloTWmZgzhsuABGBzg6uAAGc67rqtHMybFJeBW1vzhqCGFMcQnuAAFTBQBgiNgvRauBgeQTwFTbBRQdTA0F6fRHCxnC4WG5wO5XB7GZ4LeDQ2EwHKZYwdal0+kMxlMpmTLIWPplWnM7k83lwVk4uAcqBcvli8X87iddnFfqiiUK5mTSpAA)
|
|
167
158
|
|
|
168
|
-
TypeBox includes a high-performance JIT compiler that supports
|
|
159
|
+
TypeBox includes a high-performance JSON Schema JIT compiler that supports Draft 3 through to 2020-12. The compiler is designed to be a lightweight industry-grade alternative to Ajv and offers improved compilation and validation performance. It also offers automatic fallback to dynamic validation in JIT restricted environments such as Cloudflare Workers.
|
|
169
160
|
|
|
170
161
|
The compiler is available via optional sub module import.
|
|
171
162
|
|
|
@@ -175,36 +166,10 @@ import Schema from 'typebox/schema'
|
|
|
175
166
|
|
|
176
167
|
### Compile
|
|
177
168
|
|
|
178
|
-
The compiler accepts
|
|
179
|
-
|
|
180
|
-
```typescript
|
|
181
|
-
|
|
182
|
-
// Type
|
|
183
|
-
|
|
184
|
-
const VectorA = Schema.Compile(Type.Object({ // const VectorA: Validator<TObject<{
|
|
185
|
-
x: Type.Number(), // x: TNumber
|
|
186
|
-
y: Type.Number(), // y: TNumber
|
|
187
|
-
z: Type.Number() // z: TNumber
|
|
188
|
-
})) // }>>
|
|
189
|
-
|
|
190
|
-
// Schema
|
|
191
|
-
|
|
192
|
-
const VectorB = Schema.Compile({ // const VectorB: Validator<{
|
|
193
|
-
type: 'object', // type: "object";
|
|
194
|
-
required: ['x', 'y', 'z'], // required: ["x", "y", "z"];
|
|
195
|
-
properties: { // properties: { ... };
|
|
196
|
-
x: { type: 'number' }, // }, { ... }>
|
|
197
|
-
y: { type: 'number' },
|
|
198
|
-
z: { type: 'number' }
|
|
199
|
-
}
|
|
200
|
-
})
|
|
201
|
-
```
|
|
202
|
-
|
|
203
|
-
### Validate
|
|
204
|
-
|
|
205
|
-
Compiled validator instances provide functions to Check and Parse values.
|
|
169
|
+
The compiler accepts TypeBox types as well as plain JSON Schema objects, and returns a Validator instance which can be used to check values. The following compiles a Vector type.
|
|
206
170
|
|
|
207
171
|
```typescript
|
|
172
|
+
import Schema from 'typebox/schema'
|
|
208
173
|
|
|
209
174
|
// Compile
|
|
210
175
|
|
|
@@ -227,11 +192,11 @@ const result = Vector.Parse({ x: 1, y: 0, z: 0 }) // const result: {
|
|
|
227
192
|
// }
|
|
228
193
|
```
|
|
229
194
|
|
|
230
|
-
###
|
|
195
|
+
### Compatibility
|
|
231
196
|
|
|
232
197
|
[JSON Schema Test Suite](https://github.com/json-schema-org/JSON-Schema-Test-Suite) | [JSON Schema Compliance Suite](https://github.com/sinclairzx81/json-schema-compliance-suite)
|
|
233
198
|
|
|
234
|
-
TypeBox supports all
|
|
199
|
+
TypeBox supports all versions of JSON Schema and is heavily tested against the official JSON Schema Test Suite. It prioritizes compatibility with modern specifications while also maintaining broad support for legacy versions provided their semantics are not in conflict with modern specifications.
|
|
235
200
|
|
|
236
201
|
| Spec | 3 | 4 | 6 | 7 | 2019-09 | 2020-12 | v1 |
|
|
237
202
|
|:-----|:--|:--|:--|:--|:--|:--|:--|
|
|
@@ -254,7 +219,6 @@ TypeBox supports all major JSON Schema draft versions and tracks compliance agai
|
|
|
254
219
|
| enum | 16/18 | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
255
220
|
| exclusiveMaximum | - | - | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
256
221
|
| exclusiveMinimum | - | - | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
257
|
-
| format | ✅ | ✅ | ✅ | ✅ | ✅ | 114/133 | - |
|
|
258
222
|
| if-then-else | - | - | - | ✅ | ✅ | ✅ | ✅ |
|
|
259
223
|
| infinite-loop-detection | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
260
224
|
| items | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ |
|
|
@@ -287,43 +251,47 @@ TypeBox supports all major JSON Schema draft versions and tracks compliance agai
|
|
|
287
251
|
|
|
288
252
|
### Performance
|
|
289
253
|
|
|
290
|
-
TypeBox tracks
|
|
254
|
+
TypeBox tracks performance against AJV8 only as the defacto performance standard. For broader comparative benchmarks, refer to the following community maintained projects.
|
|
291
255
|
|
|
292
256
|
[Runtime Benchmarks](https://moltar.github.io/typescript-runtime-type-benchmarks/) | [Schema Benchmarks](https://schemabenchmarks.dev/)
|
|
293
257
|
|
|
294
|
-
|
|
258
|
+
### Compile
|
|
259
|
+
|
|
260
|
+
The following table shows compile performance for various JSON Schema structures. These benchmarks measure the time required to build and runtime JIT schematics. Faster compilation results in faster application startup.
|
|
295
261
|
|
|
296
262
|
```python
|
|
297
263
|
┌──────────────────────┬──────────────┬──────────────┐
|
|
298
264
|
│ Compile │ TB1X │ AJV8 │
|
|
299
265
|
├──────────────────────┼──────────────┼──────────────┤
|
|
300
|
-
│ Boolean │
|
|
301
|
-
│ Number │
|
|
302
|
-
│ String │
|
|
303
|
-
│ Null │
|
|
304
|
-
│ Literal_String │
|
|
305
|
-
│ Literal_Number │
|
|
306
|
-
│ Literal_Boolean │
|
|
307
|
-
│ Pattern │
|
|
308
|
-
│ Object_Open │
|
|
309
|
-
│ Object_Close │
|
|
310
|
-
│ Object_Vector3 │
|
|
311
|
-
│ Object_Basis3 │
|
|
312
|
-
│ Intersect_And │
|
|
313
|
-
│ Intersect_Structural │ 25.
|
|
314
|
-
│ Union_Or │ 58.
|
|
315
|
-
│ Union_Structural │
|
|
316
|
-
│ Tuple_Values │
|
|
317
|
-
│ Tuple_Objects │
|
|
318
|
-
│ Array_Numbers_4 │
|
|
319
|
-
│ Array_Numbers_8 │
|
|
320
|
-
│ Array_Numbers_16 │
|
|
321
|
-
│ Array_Objects_Open │
|
|
322
|
-
│ Array_Objects_Close │
|
|
266
|
+
│ Boolean │ 54.9K ops/s │ 7K ops/s │
|
|
267
|
+
│ Number │ 154.2K ops/s │ 7.8K ops/s │
|
|
268
|
+
│ String │ 161.4K ops/s │ 9.7K ops/s │
|
|
269
|
+
│ Null │ 111.9K ops/s │ 8.9K ops/s │
|
|
270
|
+
│ Literal_String │ 34.6K ops/s │ 7.5K ops/s │
|
|
271
|
+
│ Literal_Number │ 78.1K ops/s │ 7.6K ops/s │
|
|
272
|
+
│ Literal_Boolean │ 79.7K ops/s │ 8.4K ops/s │
|
|
273
|
+
│ Pattern │ 92.1K ops/s │ 6.1K ops/s │
|
|
274
|
+
│ Object_Open │ 18.6K ops/s │ 1.3K ops/s │
|
|
275
|
+
│ Object_Close │ 17K ops/s │ 975 ops/s │
|
|
276
|
+
│ Object_Vector3 │ 33.3K ops/s │ 3.4K ops/s │
|
|
277
|
+
│ Object_Basis3 │ 18.9K ops/s │ 858 ops/s │
|
|
278
|
+
│ Intersect_And │ 63.5K ops/s │ 3.6K ops/s │
|
|
279
|
+
│ Intersect_Structural │ 25.7K ops/s │ 1.7K ops/s │
|
|
280
|
+
│ Union_Or │ 58.2K ops/s │ 3.3K ops/s │
|
|
281
|
+
│ Union_Structural │ 33.7K ops/s │ 2K ops/s │
|
|
282
|
+
│ Tuple_Values │ 19.5K ops/s │ 2K ops/s │
|
|
283
|
+
│ Tuple_Objects │ 4K ops/s │ 388 ops/s │
|
|
284
|
+
│ Array_Numbers_4 │ 90.7K ops/s │ 4.3K ops/s │
|
|
285
|
+
│ Array_Numbers_8 │ 121.8K ops/s │ 3.8K ops/s │
|
|
286
|
+
│ Array_Numbers_16 │ 116.6K ops/s │ 3.9K ops/s │
|
|
287
|
+
│ Array_Objects_Open │ 22.6K ops/s │ 802 ops/s │
|
|
288
|
+
│ Array_Objects_Close │ 18.4K ops/s │ 930 ops/s │
|
|
323
289
|
└──────────────────────┴──────────────┴──────────────┘
|
|
324
290
|
```
|
|
325
291
|
|
|
326
|
-
|
|
292
|
+
### Validate
|
|
293
|
+
|
|
294
|
+
The following table shows validation performance for various JSON Schema structures. These benchmarks measure overall validation throughput for compiled schematics.
|
|
327
295
|
|
|
328
296
|
```python
|
|
329
297
|
┌──────────────────────┬──────────────┬──────────────┐
|
|
File without changes
|