@sinclair/typebox 0.34.26 → 0.34.28
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/cjs/type/module/compute.d.ts +16 -14
- package/build/cjs/type/module/compute.js +51 -40
- package/build/cjs/type/static/static.d.ts +14 -10
- package/build/cjs/value/parse/parse.d.ts +1 -1
- package/build/cjs/value/parse/parse.js +14 -12
- package/build/cjs/value/transform/decode.js +3 -5
- package/build/cjs/value/transform/encode.js +3 -5
- package/build/cjs/value/transform/has.js +8 -0
- package/build/esm/type/module/compute.d.mts +16 -14
- package/build/esm/type/module/compute.mjs +52 -41
- package/build/esm/type/static/static.d.mts +14 -10
- package/build/esm/value/parse/parse.d.mts +1 -1
- package/build/esm/value/parse/parse.mjs +8 -6
- package/build/esm/value/transform/decode.mjs +3 -5
- package/build/esm/value/transform/encode.mjs +3 -5
- package/build/esm/value/transform/has.mjs +8 -0
- package/package.json +1 -1
- package/readme.md +13 -13
|
@@ -20,11 +20,12 @@ import { TPartial } from '../partial/index';
|
|
|
20
20
|
import { type TReadonly } from '../readonly/index';
|
|
21
21
|
import { type TRecordOrObject, type TRecord } from '../record/index';
|
|
22
22
|
import { type TRef } from '../ref/index';
|
|
23
|
-
import { TRequired } from '../required/index';
|
|
23
|
+
import { type TRequired } from '../required/index';
|
|
24
|
+
import { type TTransform } from '../transform/index';
|
|
24
25
|
import { type TTuple } from '../tuple/index';
|
|
25
26
|
import { type TUnion, type TUnionEvaluated } from '../union/index';
|
|
26
|
-
type
|
|
27
|
-
type
|
|
27
|
+
type TDereferenceParameters<ModuleProperties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TRef<infer Key extends string> ? TDereferenceParameters<ModuleProperties, Right, [...Result, TDereference<ModuleProperties, Key>]> : TDereferenceParameters<ModuleProperties, Right, [...Result, TFromType<ModuleProperties, Left>]> : Result);
|
|
28
|
+
type TDereference<ModuleProperties extends TProperties, Ref extends string, Result extends TSchema = (Ref extends keyof ModuleProperties ? ModuleProperties[Ref] extends TRef<infer Ref2 extends string> ? TDereference<ModuleProperties, Ref2> : TFromType<ModuleProperties, ModuleProperties[Ref]> : TNever)> = Result;
|
|
28
29
|
type TFromAwaited<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TAwaited<T0> : never);
|
|
29
30
|
type TFromIndex<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TIndex<T0, TIndexPropertyKeys<T1>> extends infer Result extends TSchema ? Result : never : never);
|
|
30
31
|
type TFromKeyOf<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TKeyOf<T0> : never);
|
|
@@ -32,21 +33,22 @@ type TFromPartial<Parameters extends TSchema[]> = (Parameters extends [infer T0
|
|
|
32
33
|
type TFromOmit<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TOmit<T0, T1> : never);
|
|
33
34
|
type TFromPick<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TPick<T0, T1> : never);
|
|
34
35
|
type TFromRequired<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TRequired<T0> : never);
|
|
35
|
-
type TFromComputed<ModuleProperties extends TProperties, Target extends string, Parameters extends TSchema[], Dereferenced extends TSchema[] =
|
|
36
|
+
type TFromComputed<ModuleProperties extends TProperties, Target extends string, Parameters extends TSchema[], Dereferenced extends TSchema[] = TDereferenceParameters<ModuleProperties, Parameters>> = (Target extends 'Awaited' ? TFromAwaited<Dereferenced> : Target extends 'Index' ? TFromIndex<Dereferenced> : Target extends 'KeyOf' ? TFromKeyOf<Dereferenced> : Target extends 'Partial' ? TFromPartial<Dereferenced> : Target extends 'Omit' ? TFromOmit<Dereferenced> : Target extends 'Pick' ? TFromPick<Dereferenced> : Target extends 'Required' ? TFromRequired<Dereferenced> : TNever);
|
|
37
|
+
type TFromArray<ModuleProperties extends TProperties, Type extends TSchema> = (Ensure<TArray<TFromType<ModuleProperties, Type>>>);
|
|
38
|
+
type TFromAsyncIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TAsyncIterator<TFromType<ModuleProperties, Type>>);
|
|
39
|
+
type TFromConstructor<ModuleProperties extends TProperties, Parameters extends TSchema[], InstanceType extends TSchema> = (TConstructor<TFromTypes<ModuleProperties, Parameters>, TFromType<ModuleProperties, InstanceType>>);
|
|
40
|
+
type TFromFunction<ModuleProperties extends TProperties, Parameters extends TSchema[], ReturnType extends TSchema> = Ensure<Ensure<TFunction<TFromTypes<ModuleProperties, Parameters>, TFromType<ModuleProperties, ReturnType>>>>;
|
|
41
|
+
type TFromIntersect<ModuleProperties extends TProperties, Types extends TSchema[]> = (Ensure<TIntersectEvaluated<TFromTypes<ModuleProperties, Types>>>);
|
|
42
|
+
type TFromIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TIterator<TFromType<ModuleProperties, Type>>);
|
|
36
43
|
type TFromObject<ModuleProperties extends TProperties, Properties extends TProperties> = Ensure<TObject<Evaluate<{
|
|
37
44
|
[Key in keyof Properties]: TFromType<ModuleProperties, Properties[Key]>;
|
|
38
45
|
}>>>;
|
|
39
46
|
type TFromRecord<ModuleProperties extends TProperties, Key extends TSchema, Value extends TSchema, Result extends TSchema = TRecordOrObject<Key, TFromType<ModuleProperties, Value>>> = Result;
|
|
40
|
-
type
|
|
41
|
-
type
|
|
42
|
-
type
|
|
43
|
-
type
|
|
44
|
-
type
|
|
45
|
-
type TFromArray<ModuleProperties extends TProperties, Type extends TSchema> = (Ensure<TArray<TFromType<ModuleProperties, Type>>>);
|
|
46
|
-
type TFromAsyncIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TAsyncIterator<TFromType<ModuleProperties, Type>>);
|
|
47
|
-
type TFromIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TIterator<TFromType<ModuleProperties, Type>>);
|
|
48
|
-
type TFromRest<ModuleProperties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromRest<ModuleProperties, Right, [...Result, TFromType<ModuleProperties, Left>]> : Result);
|
|
49
|
-
export type TFromType<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TOptional<infer Type extends TSchema> ? TOptional<TFromType<ModuleProperties, Type>> : Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TFromType<ModuleProperties, Type>> : Type extends TArray<infer Type extends TSchema> ? TFromArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromAsyncIterator<ModuleProperties, Type> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<ModuleProperties, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TFromIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<ModuleProperties, Properties> : Type extends TRecord<infer Key extends TSchema, infer Value extends TSchema> ? TFromRecord<ModuleProperties, Key, Value> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Type : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<ModuleProperties, Types> : Type);
|
|
47
|
+
type TFromTransform<ModuleProperties extends TProperties, Input extends TSchema, Output extends unknown, Result extends TSchema = Input extends TRef<infer Key extends string> ? TTransform<TDereference<ModuleProperties, Key>, Output> : TTransform<Input, Output>> = Result;
|
|
48
|
+
type TFromTuple<ModuleProperties extends TProperties, Types extends TSchema[]> = (Ensure<TTuple<TFromTypes<ModuleProperties, Types>>>);
|
|
49
|
+
type TFromUnion<ModuleProperties extends TProperties, Types extends TSchema[]> = (Ensure<TUnionEvaluated<TFromTypes<ModuleProperties, Types>>>);
|
|
50
|
+
type TFromTypes<ModuleProperties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromTypes<ModuleProperties, Right, [...Result, TFromType<ModuleProperties, Left>]> : Result);
|
|
51
|
+
export type TFromType<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TOptional<infer Type extends TSchema> ? TOptional<TFromType<ModuleProperties, Type>> : Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TFromType<ModuleProperties, Type>> : Type extends TTransform<infer Input extends TSchema, infer Output extends unknown> ? TFromTransform<ModuleProperties, Input, Output> : Type extends TArray<infer Type extends TSchema> ? TFromArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromAsyncIterator<ModuleProperties, Type> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<ModuleProperties, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TFromIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<ModuleProperties, Properties> : Type extends TRecord<infer Key extends TSchema, infer Value extends TSchema> ? TFromRecord<ModuleProperties, Key, Value> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Type : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<ModuleProperties, Types> : Type);
|
|
50
52
|
export declare function FromType<ModuleProperties extends TProperties, Type extends TSchema>(moduleProperties: ModuleProperties, type: Type): TFromType<ModuleProperties, Type>;
|
|
51
53
|
export type TComputeType<ModuleProperties extends TProperties, Key extends PropertyKey> = (Key extends keyof ModuleProperties ? TFromType<ModuleProperties, ModuleProperties[Key]> : TNever);
|
|
52
54
|
export declare function ComputeType<ModuleProperties extends TProperties, Key extends PropertyKey>(moduleProperties: ModuleProperties, key: Key): TComputeType<ModuleProperties, Key>;
|
|
@@ -25,24 +25,27 @@ const index_18 = require("../record/index");
|
|
|
25
25
|
const index_19 = require("../required/index");
|
|
26
26
|
const index_20 = require("../tuple/index");
|
|
27
27
|
const index_21 = require("../union/index");
|
|
28
|
+
// ------------------------------------------------------------------
|
|
29
|
+
// Symbols
|
|
30
|
+
// ------------------------------------------------------------------
|
|
28
31
|
const index_22 = require("../symbols/index");
|
|
29
32
|
// ------------------------------------------------------------------
|
|
30
33
|
// KindGuard
|
|
31
34
|
// ------------------------------------------------------------------
|
|
32
35
|
const KindGuard = require("../guard/kind");
|
|
33
36
|
// prettier-ignore
|
|
34
|
-
function
|
|
37
|
+
function DereferenceParameters(moduleProperties, types) {
|
|
35
38
|
return types.map((type) => {
|
|
36
39
|
return KindGuard.IsRef(type)
|
|
37
|
-
?
|
|
40
|
+
? Dereference(moduleProperties, type.$ref)
|
|
38
41
|
: FromType(moduleProperties, type);
|
|
39
42
|
});
|
|
40
43
|
}
|
|
41
44
|
// prettier-ignore
|
|
42
|
-
function
|
|
45
|
+
function Dereference(moduleProperties, ref) {
|
|
43
46
|
return (ref in moduleProperties
|
|
44
47
|
? KindGuard.IsRef(moduleProperties[ref])
|
|
45
|
-
?
|
|
48
|
+
? Dereference(moduleProperties, moduleProperties[ref].$ref)
|
|
46
49
|
: FromType(moduleProperties, moduleProperties[ref])
|
|
47
50
|
: (0, index_16.Never)());
|
|
48
51
|
}
|
|
@@ -76,7 +79,7 @@ function FromRequired(parameters) {
|
|
|
76
79
|
}
|
|
77
80
|
// prettier-ignore
|
|
78
81
|
function FromComputed(moduleProperties, target, parameters) {
|
|
79
|
-
const dereferenced =
|
|
82
|
+
const dereferenced = DereferenceParameters(moduleProperties, parameters);
|
|
80
83
|
return (target === 'Awaited' ? FromAwaited(dereferenced) :
|
|
81
84
|
target === 'Index' ? FromIndex(dereferenced) :
|
|
82
85
|
target === 'KeyOf' ? FromKeyOf(dereferenced) :
|
|
@@ -86,6 +89,26 @@ function FromComputed(moduleProperties, target, parameters) {
|
|
|
86
89
|
target === 'Required' ? FromRequired(dereferenced) :
|
|
87
90
|
(0, index_16.Never)());
|
|
88
91
|
}
|
|
92
|
+
function FromArray(moduleProperties, type) {
|
|
93
|
+
return (0, index_4.Array)(FromType(moduleProperties, type));
|
|
94
|
+
}
|
|
95
|
+
function FromAsyncIterator(moduleProperties, type) {
|
|
96
|
+
return (0, index_6.AsyncIterator)(FromType(moduleProperties, type));
|
|
97
|
+
}
|
|
98
|
+
// prettier-ignore
|
|
99
|
+
function FromConstructor(moduleProperties, parameters, instanceType) {
|
|
100
|
+
return (0, index_7.Constructor)(FromTypes(moduleProperties, parameters), FromType(moduleProperties, instanceType));
|
|
101
|
+
}
|
|
102
|
+
// prettier-ignore
|
|
103
|
+
function FromFunction(moduleProperties, parameters, returnType) {
|
|
104
|
+
return (0, index_9.Function)(FromTypes(moduleProperties, parameters), FromType(moduleProperties, returnType));
|
|
105
|
+
}
|
|
106
|
+
function FromIntersect(moduleProperties, types) {
|
|
107
|
+
return (0, index_10.Intersect)(FromTypes(moduleProperties, types));
|
|
108
|
+
}
|
|
109
|
+
function FromIterator(moduleProperties, type) {
|
|
110
|
+
return (0, index_11.Iterator)(FromType(moduleProperties, type));
|
|
111
|
+
}
|
|
89
112
|
function FromObject(moduleProperties, properties) {
|
|
90
113
|
return (0, index_13.Object)(globalThis.Object.keys(properties).reduce((result, key) => {
|
|
91
114
|
return { ...result, [key]: FromType(moduleProperties, properties[key]) };
|
|
@@ -99,53 +122,41 @@ function FromRecord(moduleProperties, type) {
|
|
|
99
122
|
return result;
|
|
100
123
|
}
|
|
101
124
|
// prettier-ignore
|
|
102
|
-
function
|
|
103
|
-
return (
|
|
104
|
-
}
|
|
105
|
-
|
|
106
|
-
function FromFunction(moduleProperties, parameters, returnType) {
|
|
107
|
-
return (0, index_9.Function)(FromRest(moduleProperties, parameters), FromType(moduleProperties, returnType));
|
|
125
|
+
function FromTransform(moduleProperties, transform) {
|
|
126
|
+
return (KindGuard.IsRef(transform))
|
|
127
|
+
? { ...Dereference(moduleProperties, transform.$ref), [index_22.TransformKind]: transform[index_22.TransformKind] }
|
|
128
|
+
: transform;
|
|
108
129
|
}
|
|
109
130
|
function FromTuple(moduleProperties, types) {
|
|
110
|
-
return (0, index_20.Tuple)(
|
|
111
|
-
}
|
|
112
|
-
function FromIntersect(moduleProperties, types) {
|
|
113
|
-
return (0, index_10.Intersect)(FromRest(moduleProperties, types));
|
|
131
|
+
return (0, index_20.Tuple)(FromTypes(moduleProperties, types));
|
|
114
132
|
}
|
|
115
133
|
function FromUnion(moduleProperties, types) {
|
|
116
|
-
return (0, index_21.Union)(
|
|
117
|
-
}
|
|
118
|
-
function FromArray(moduleProperties, type) {
|
|
119
|
-
return (0, index_4.Array)(FromType(moduleProperties, type));
|
|
120
|
-
}
|
|
121
|
-
function FromAsyncIterator(moduleProperties, type) {
|
|
122
|
-
return (0, index_6.AsyncIterator)(FromType(moduleProperties, type));
|
|
123
|
-
}
|
|
124
|
-
function FromIterator(moduleProperties, type) {
|
|
125
|
-
return (0, index_11.Iterator)(FromType(moduleProperties, type));
|
|
134
|
+
return (0, index_21.Union)(FromTypes(moduleProperties, types));
|
|
126
135
|
}
|
|
127
|
-
function
|
|
136
|
+
function FromTypes(moduleProperties, types) {
|
|
128
137
|
return types.map((type) => FromType(moduleProperties, type));
|
|
129
138
|
}
|
|
130
139
|
// prettier-ignore
|
|
131
140
|
function FromType(moduleProperties, type) {
|
|
132
141
|
return (
|
|
133
|
-
//
|
|
142
|
+
// Modifiers
|
|
134
143
|
KindGuard.IsOptional(type) ? (0, index_1.CreateType)(FromType(moduleProperties, (0, index_3.Discard)(type, [index_22.OptionalKind])), type) :
|
|
135
144
|
KindGuard.IsReadonly(type) ? (0, index_1.CreateType)(FromType(moduleProperties, (0, index_3.Discard)(type, [index_22.ReadonlyKind])), type) :
|
|
136
|
-
//
|
|
137
|
-
KindGuard.
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
145
|
+
// Transform
|
|
146
|
+
KindGuard.IsTransform(type) ? (0, index_1.CreateType)(FromTransform(moduleProperties, type), type) :
|
|
147
|
+
// Types
|
|
148
|
+
KindGuard.IsArray(type) ? (0, index_1.CreateType)(FromArray(moduleProperties, type.items), type) :
|
|
149
|
+
KindGuard.IsAsyncIterator(type) ? (0, index_1.CreateType)(FromAsyncIterator(moduleProperties, type.items), type) :
|
|
150
|
+
KindGuard.IsComputed(type) ? (0, index_1.CreateType)(FromComputed(moduleProperties, type.target, type.parameters)) :
|
|
151
|
+
KindGuard.IsConstructor(type) ? (0, index_1.CreateType)(FromConstructor(moduleProperties, type.parameters, type.returns), type) :
|
|
152
|
+
KindGuard.IsFunction(type) ? (0, index_1.CreateType)(FromFunction(moduleProperties, type.parameters, type.returns), type) :
|
|
153
|
+
KindGuard.IsIntersect(type) ? (0, index_1.CreateType)(FromIntersect(moduleProperties, type.allOf), type) :
|
|
154
|
+
KindGuard.IsIterator(type) ? (0, index_1.CreateType)(FromIterator(moduleProperties, type.items), type) :
|
|
155
|
+
KindGuard.IsObject(type) ? (0, index_1.CreateType)(FromObject(moduleProperties, type.properties), type) :
|
|
156
|
+
KindGuard.IsRecord(type) ? (0, index_1.CreateType)(FromRecord(moduleProperties, type)) :
|
|
157
|
+
KindGuard.IsTuple(type) ? (0, index_1.CreateType)(FromTuple(moduleProperties, type.items || []), type) :
|
|
158
|
+
KindGuard.IsUnion(type) ? (0, index_1.CreateType)(FromUnion(moduleProperties, type.anyOf), type) :
|
|
159
|
+
type);
|
|
149
160
|
}
|
|
150
161
|
// prettier-ignore
|
|
151
162
|
function ComputeType(moduleProperties, key) {
|
|
@@ -7,6 +7,7 @@ import type { TConstructor } from '../constructor/index';
|
|
|
7
7
|
import type { TEnum } from '../enum/index';
|
|
8
8
|
import type { TFunction } from '../function/index';
|
|
9
9
|
import type { TIntersect } from '../intersect/index';
|
|
10
|
+
import type { TImport } from '../module/index';
|
|
10
11
|
import type { TIterator } from '../iterator/index';
|
|
11
12
|
import type { TNot } from '../not/index';
|
|
12
13
|
import type { TObject, TProperties } from '../object/index';
|
|
@@ -19,17 +20,20 @@ import type { TUnion } from '../union/index';
|
|
|
19
20
|
import type { TUnsafe } from '../unsafe/index';
|
|
20
21
|
import type { TSchema } from '../schema/index';
|
|
21
22
|
import type { TTransform } from '../transform/index';
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
import type { TNever } from '../never/index';
|
|
24
|
+
type TDecodeImport<ModuleProperties extends TProperties, Key extends PropertyKey> = (Key extends keyof ModuleProperties ? TDecodeType<ModuleProperties[Key]> extends infer Type extends TSchema ? Type extends TRef<infer Ref extends string> ? TDecodeImport<ModuleProperties, Ref> : Type : TNever : TNever);
|
|
25
|
+
type TDecodeProperties<Properties extends TProperties> = {
|
|
26
|
+
[Key in keyof Properties]: TDecodeType<Properties[Key]>;
|
|
24
27
|
};
|
|
25
|
-
|
|
26
|
-
export type TDecodeType<
|
|
27
|
-
export type StaticDecodeIsAny<
|
|
28
|
+
type TDecodeTypes<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TDecodeTypes<Right, [...Result, TDecodeType<Left>]> : Result);
|
|
29
|
+
export type TDecodeType<Type extends TSchema> = (Type extends TOptional<infer Type extends TSchema> ? TOptional<TDecodeType<Type>> : Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TDecodeType<Type>> : Type extends TTransform<infer _Input extends TSchema, infer Output> ? TUnsafe<Output> : Type extends TArray<infer Type extends TSchema> ? TArray<TDecodeType<Type>> : Type extends TAsyncIterator<infer Type extends TSchema> ? TAsyncIterator<TDecodeType<Type>> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TConstructor<TDecodeTypes<Parameters>, TDecodeType<InstanceType>> : Type extends TEnum<infer Values> ? TEnum<Values> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TDecodeTypes<Parameters>, TDecodeType<ReturnType>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TDecodeTypes<Types>> : Type extends TImport<infer ModuleProperties extends TProperties, infer Key> ? TDecodeImport<ModuleProperties, Key> : Type extends TIterator<infer Type extends TSchema> ? TIterator<TDecodeType<Type>> : Type extends TNot<infer Type extends TSchema> ? TNot<TDecodeType<Type>> : Type extends TObject<infer Properties extends TProperties> ? TObject<Evaluate<TDecodeProperties<Properties>>> : Type extends TPromise<infer Type extends TSchema> ? TPromise<TDecodeType<Type>> : Type extends TRecord<infer Key extends TSchema, infer Value extends TSchema> ? TRecord<Key, TDecodeType<Value>> : Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TDecodeType<Type>> : Type extends TRef<infer Ref extends string> ? TRef<Ref> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TDecodeTypes<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TDecodeTypes<Types>> : Type);
|
|
30
|
+
export type StaticDecodeIsAny<Type> = boolean extends (Type extends TSchema ? true : false) ? true : false;
|
|
28
31
|
/** Creates an decoded static type from a TypeBox type */
|
|
29
|
-
export type StaticDecode<
|
|
32
|
+
export type StaticDecode<Type extends TSchema, Params extends unknown[] = [], Result = StaticDecodeIsAny<Type> extends true ? unknown : Static<TDecodeType<Type>, Params>> = Result;
|
|
30
33
|
/** Creates an encoded static type from a TypeBox type */
|
|
31
|
-
export type StaticEncode<
|
|
34
|
+
export type StaticEncode<Type extends TSchema, Params extends unknown[] = [], Result = Static<Type, Params>> = Result;
|
|
32
35
|
/** Creates a static type from a TypeBox type */
|
|
33
|
-
export type Static<
|
|
34
|
-
params:
|
|
35
|
-
})['static'];
|
|
36
|
+
export type Static<Type extends TSchema, Params extends unknown[] = [], Result = (Type & {
|
|
37
|
+
params: Params;
|
|
38
|
+
})['static']> = Result;
|
|
39
|
+
export {};
|
|
@@ -4,7 +4,7 @@ import { StaticDecode } from '../../type/static/index';
|
|
|
4
4
|
export declare class ParseError extends TypeBoxError {
|
|
5
5
|
constructor(message: string);
|
|
6
6
|
}
|
|
7
|
-
export type TParseOperation = '
|
|
7
|
+
export type TParseOperation = 'Assert' | 'Cast' | 'Clean' | 'Clone' | 'Convert' | 'Decode' | 'Default' | 'Encode' | ({} & string);
|
|
8
8
|
export type TParseFunction = (type: TSchema, references: TSchema[], value: unknown) => unknown;
|
|
9
9
|
export declare namespace ParseRegistry {
|
|
10
10
|
function Delete(key: string): void;
|
|
@@ -6,14 +6,15 @@ exports.Parse = Parse;
|
|
|
6
6
|
const index_1 = require("../../type/error/index");
|
|
7
7
|
const index_2 = require("../transform/index");
|
|
8
8
|
const index_3 = require("../assert/index");
|
|
9
|
-
const index_4 = require("../
|
|
10
|
-
const index_5 = require("../
|
|
11
|
-
const index_6 = require("../
|
|
12
|
-
const index_7 = require("../
|
|
9
|
+
const index_4 = require("../cast/index");
|
|
10
|
+
const index_5 = require("../clean/index");
|
|
11
|
+
const index_6 = require("../clone/index");
|
|
12
|
+
const index_7 = require("../convert/index");
|
|
13
|
+
const index_8 = require("../default/index");
|
|
13
14
|
// ------------------------------------------------------------------
|
|
14
15
|
// Guards
|
|
15
16
|
// ------------------------------------------------------------------
|
|
16
|
-
const
|
|
17
|
+
const index_9 = require("../guard/index");
|
|
17
18
|
// ------------------------------------------------------------------
|
|
18
19
|
// Error
|
|
19
20
|
// ------------------------------------------------------------------
|
|
@@ -27,12 +28,13 @@ exports.ParseError = ParseError;
|
|
|
27
28
|
var ParseRegistry;
|
|
28
29
|
(function (ParseRegistry) {
|
|
29
30
|
const registry = new Map([
|
|
30
|
-
['Clone', (_type, _references, value) => (0, index_7.Clone)(value)],
|
|
31
|
-
['Clean', (type, references, value) => (0, index_6.Clean)(type, references, value)],
|
|
32
|
-
['Default', (type, references, value) => (0, index_4.Default)(type, references, value)],
|
|
33
|
-
['Convert', (type, references, value) => (0, index_5.Convert)(type, references, value)],
|
|
34
31
|
['Assert', (type, references, value) => { (0, index_3.Assert)(type, references, value); return value; }],
|
|
32
|
+
['Cast', (type, references, value) => (0, index_4.Cast)(type, references, value)],
|
|
33
|
+
['Clean', (type, references, value) => (0, index_5.Clean)(type, references, value)],
|
|
34
|
+
['Clone', (_type, _references, value) => (0, index_6.Clone)(value)],
|
|
35
|
+
['Convert', (type, references, value) => (0, index_7.Convert)(type, references, value)],
|
|
35
36
|
['Decode', (type, references, value) => ((0, index_2.HasTransform)(type, references) ? (0, index_2.TransformDecode)(type, references, value) : value)],
|
|
37
|
+
['Default', (type, references, value) => (0, index_8.Default)(type, references, value)],
|
|
36
38
|
['Encode', (type, references, value) => ((0, index_2.HasTransform)(type, references) ? (0, index_2.TransformEncode)(type, references, value) : value)],
|
|
37
39
|
]);
|
|
38
40
|
// Deletes an entry from the registry
|
|
@@ -52,7 +54,7 @@ var ParseRegistry;
|
|
|
52
54
|
ParseRegistry.Get = Get;
|
|
53
55
|
})(ParseRegistry || (exports.ParseRegistry = ParseRegistry = {}));
|
|
54
56
|
// ------------------------------------------------------------------
|
|
55
|
-
// Default Parse
|
|
57
|
+
// Default Parse Pipeline
|
|
56
58
|
// ------------------------------------------------------------------
|
|
57
59
|
// prettier-ignore
|
|
58
60
|
exports.ParseDefault = [
|
|
@@ -69,7 +71,7 @@ exports.ParseDefault = [
|
|
|
69
71
|
function ParseValue(operations, type, references, value) {
|
|
70
72
|
return operations.reduce((value, operationKey) => {
|
|
71
73
|
const operation = ParseRegistry.Get(operationKey);
|
|
72
|
-
if ((0,
|
|
74
|
+
if ((0, index_9.IsUndefined)(operation))
|
|
73
75
|
throw new ParseError(`Unable to find Parse operation '${operationKey}'`);
|
|
74
76
|
return operation(type, references, value);
|
|
75
77
|
}, value);
|
|
@@ -78,7 +80,7 @@ function ParseValue(operations, type, references, value) {
|
|
|
78
80
|
function Parse(...args) {
|
|
79
81
|
// prettier-ignore
|
|
80
82
|
const [operations, schema, references, value] = (args.length === 4 ? [args[0], args[1], args[2], args[3]] :
|
|
81
|
-
args.length === 3 ? (0,
|
|
83
|
+
args.length === 3 ? (0, index_9.IsArray)(args[0]) ? [args[0], args[1], [], args[2]] : [exports.ParseDefault, args[0], args[1], args[2]] :
|
|
82
84
|
args.length === 2 ? [exports.ParseDefault, args[0], [], args[1]] :
|
|
83
85
|
(() => { throw new ParseError('Invalid Arguments'); })());
|
|
84
86
|
return ParseValue(operations, schema, references, value);
|
|
@@ -85,12 +85,10 @@ function FromIntersect(schema, references, path, value) {
|
|
|
85
85
|
}
|
|
86
86
|
// prettier-ignore
|
|
87
87
|
function FromImport(schema, references, path, value) {
|
|
88
|
-
const
|
|
88
|
+
const additional = globalThis.Object.values(schema.$defs);
|
|
89
89
|
const target = schema.$defs[schema.$ref];
|
|
90
|
-
const
|
|
91
|
-
|
|
92
|
-
const transformTarget = { [index_1.TransformKind]: transform, ...target };
|
|
93
|
-
return Visit(transformTarget, [...references, ...definitions], path, value);
|
|
90
|
+
const result = Visit(target, [...references, ...additional], path, value);
|
|
91
|
+
return Default(schema, path, result);
|
|
94
92
|
}
|
|
95
93
|
function FromNot(schema, references, path, value) {
|
|
96
94
|
return Default(schema, path, Visit(schema.not, references, path, value));
|
|
@@ -62,12 +62,10 @@ function FromArray(schema, references, path, value) {
|
|
|
62
62
|
}
|
|
63
63
|
// prettier-ignore
|
|
64
64
|
function FromImport(schema, references, path, value) {
|
|
65
|
-
const
|
|
65
|
+
const additional = globalThis.Object.values(schema.$defs);
|
|
66
66
|
const target = schema.$defs[schema.$ref];
|
|
67
|
-
const
|
|
68
|
-
|
|
69
|
-
const transformTarget = { [index_1.TransformKind]: transform, ...target };
|
|
70
|
-
return Visit(transformTarget, [...references, ...definitions], path, value);
|
|
67
|
+
const result = Default(schema, path, value);
|
|
68
|
+
return Visit(target, [...references, ...additional], path, result);
|
|
71
69
|
}
|
|
72
70
|
// prettier-ignore
|
|
73
71
|
function FromIntersect(schema, references, path, value) {
|
|
@@ -33,6 +33,12 @@ function FromIntersect(schema, references) {
|
|
|
33
33
|
return (0, kind_1.IsTransform)(schema) || (0, kind_1.IsTransform)(schema.unevaluatedProperties) || schema.allOf.some((schema) => Visit(schema, references));
|
|
34
34
|
}
|
|
35
35
|
// prettier-ignore
|
|
36
|
+
function FromImport(schema, references) {
|
|
37
|
+
const additional = globalThis.Object.getOwnPropertyNames(schema.$defs).reduce((result, key) => [...result, schema.$defs[key]], []);
|
|
38
|
+
const target = schema.$defs[schema.$ref];
|
|
39
|
+
return (0, kind_1.IsTransform)(schema) || Visit(target, [...additional, ...references]);
|
|
40
|
+
}
|
|
41
|
+
// prettier-ignore
|
|
36
42
|
function FromIterator(schema, references) {
|
|
37
43
|
return (0, kind_1.IsTransform)(schema) || Visit(schema.items, references);
|
|
38
44
|
}
|
|
@@ -93,6 +99,8 @@ function Visit(schema, references) {
|
|
|
93
99
|
return FromConstructor(schema_, references_);
|
|
94
100
|
case 'Function':
|
|
95
101
|
return FromFunction(schema_, references_);
|
|
102
|
+
case 'Import':
|
|
103
|
+
return FromImport(schema_, references_);
|
|
96
104
|
case 'Intersect':
|
|
97
105
|
return FromIntersect(schema_, references_);
|
|
98
106
|
case 'Iterator':
|
|
@@ -20,11 +20,12 @@ import { TPartial } from '../partial/index.mjs';
|
|
|
20
20
|
import { type TReadonly } from '../readonly/index.mjs';
|
|
21
21
|
import { type TRecordOrObject, type TRecord } from '../record/index.mjs';
|
|
22
22
|
import { type TRef } from '../ref/index.mjs';
|
|
23
|
-
import { TRequired } from '../required/index.mjs';
|
|
23
|
+
import { type TRequired } from '../required/index.mjs';
|
|
24
|
+
import { type TTransform } from '../transform/index.mjs';
|
|
24
25
|
import { type TTuple } from '../tuple/index.mjs';
|
|
25
26
|
import { type TUnion, type TUnionEvaluated } from '../union/index.mjs';
|
|
26
|
-
type
|
|
27
|
-
type
|
|
27
|
+
type TDereferenceParameters<ModuleProperties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? Left extends TRef<infer Key extends string> ? TDereferenceParameters<ModuleProperties, Right, [...Result, TDereference<ModuleProperties, Key>]> : TDereferenceParameters<ModuleProperties, Right, [...Result, TFromType<ModuleProperties, Left>]> : Result);
|
|
28
|
+
type TDereference<ModuleProperties extends TProperties, Ref extends string, Result extends TSchema = (Ref extends keyof ModuleProperties ? ModuleProperties[Ref] extends TRef<infer Ref2 extends string> ? TDereference<ModuleProperties, Ref2> : TFromType<ModuleProperties, ModuleProperties[Ref]> : TNever)> = Result;
|
|
28
29
|
type TFromAwaited<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TAwaited<T0> : never);
|
|
29
30
|
type TFromIndex<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TIndex<T0, TIndexPropertyKeys<T1>> extends infer Result extends TSchema ? Result : never : never);
|
|
30
31
|
type TFromKeyOf<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TKeyOf<T0> : never);
|
|
@@ -32,21 +33,22 @@ type TFromPartial<Parameters extends TSchema[]> = (Parameters extends [infer T0
|
|
|
32
33
|
type TFromOmit<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TOmit<T0, T1> : never);
|
|
33
34
|
type TFromPick<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema, infer T1 extends TSchema] ? TPick<T0, T1> : never);
|
|
34
35
|
type TFromRequired<Parameters extends TSchema[]> = (Parameters extends [infer T0 extends TSchema] ? TRequired<T0> : never);
|
|
35
|
-
type TFromComputed<ModuleProperties extends TProperties, Target extends string, Parameters extends TSchema[], Dereferenced extends TSchema[] =
|
|
36
|
+
type TFromComputed<ModuleProperties extends TProperties, Target extends string, Parameters extends TSchema[], Dereferenced extends TSchema[] = TDereferenceParameters<ModuleProperties, Parameters>> = (Target extends 'Awaited' ? TFromAwaited<Dereferenced> : Target extends 'Index' ? TFromIndex<Dereferenced> : Target extends 'KeyOf' ? TFromKeyOf<Dereferenced> : Target extends 'Partial' ? TFromPartial<Dereferenced> : Target extends 'Omit' ? TFromOmit<Dereferenced> : Target extends 'Pick' ? TFromPick<Dereferenced> : Target extends 'Required' ? TFromRequired<Dereferenced> : TNever);
|
|
37
|
+
type TFromArray<ModuleProperties extends TProperties, Type extends TSchema> = (Ensure<TArray<TFromType<ModuleProperties, Type>>>);
|
|
38
|
+
type TFromAsyncIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TAsyncIterator<TFromType<ModuleProperties, Type>>);
|
|
39
|
+
type TFromConstructor<ModuleProperties extends TProperties, Parameters extends TSchema[], InstanceType extends TSchema> = (TConstructor<TFromTypes<ModuleProperties, Parameters>, TFromType<ModuleProperties, InstanceType>>);
|
|
40
|
+
type TFromFunction<ModuleProperties extends TProperties, Parameters extends TSchema[], ReturnType extends TSchema> = Ensure<Ensure<TFunction<TFromTypes<ModuleProperties, Parameters>, TFromType<ModuleProperties, ReturnType>>>>;
|
|
41
|
+
type TFromIntersect<ModuleProperties extends TProperties, Types extends TSchema[]> = (Ensure<TIntersectEvaluated<TFromTypes<ModuleProperties, Types>>>);
|
|
42
|
+
type TFromIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TIterator<TFromType<ModuleProperties, Type>>);
|
|
36
43
|
type TFromObject<ModuleProperties extends TProperties, Properties extends TProperties> = Ensure<TObject<Evaluate<{
|
|
37
44
|
[Key in keyof Properties]: TFromType<ModuleProperties, Properties[Key]>;
|
|
38
45
|
}>>>;
|
|
39
46
|
type TFromRecord<ModuleProperties extends TProperties, Key extends TSchema, Value extends TSchema, Result extends TSchema = TRecordOrObject<Key, TFromType<ModuleProperties, Value>>> = Result;
|
|
40
|
-
type
|
|
41
|
-
type
|
|
42
|
-
type
|
|
43
|
-
type
|
|
44
|
-
type
|
|
45
|
-
type TFromArray<ModuleProperties extends TProperties, Type extends TSchema> = (Ensure<TArray<TFromType<ModuleProperties, Type>>>);
|
|
46
|
-
type TFromAsyncIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TAsyncIterator<TFromType<ModuleProperties, Type>>);
|
|
47
|
-
type TFromIterator<ModuleProperties extends TProperties, Type extends TSchema> = (TIterator<TFromType<ModuleProperties, Type>>);
|
|
48
|
-
type TFromRest<ModuleProperties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromRest<ModuleProperties, Right, [...Result, TFromType<ModuleProperties, Left>]> : Result);
|
|
49
|
-
export type TFromType<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TOptional<infer Type extends TSchema> ? TOptional<TFromType<ModuleProperties, Type>> : Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TFromType<ModuleProperties, Type>> : Type extends TArray<infer Type extends TSchema> ? TFromArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromAsyncIterator<ModuleProperties, Type> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<ModuleProperties, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TFromIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<ModuleProperties, Properties> : Type extends TRecord<infer Key extends TSchema, infer Value extends TSchema> ? TFromRecord<ModuleProperties, Key, Value> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Type : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<ModuleProperties, Types> : Type);
|
|
47
|
+
type TFromTransform<ModuleProperties extends TProperties, Input extends TSchema, Output extends unknown, Result extends TSchema = Input extends TRef<infer Key extends string> ? TTransform<TDereference<ModuleProperties, Key>, Output> : TTransform<Input, Output>> = Result;
|
|
48
|
+
type TFromTuple<ModuleProperties extends TProperties, Types extends TSchema[]> = (Ensure<TTuple<TFromTypes<ModuleProperties, Types>>>);
|
|
49
|
+
type TFromUnion<ModuleProperties extends TProperties, Types extends TSchema[]> = (Ensure<TUnionEvaluated<TFromTypes<ModuleProperties, Types>>>);
|
|
50
|
+
type TFromTypes<ModuleProperties extends TProperties, Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TFromTypes<ModuleProperties, Right, [...Result, TFromType<ModuleProperties, Left>]> : Result);
|
|
51
|
+
export type TFromType<ModuleProperties extends TProperties, Type extends TSchema> = (Type extends TOptional<infer Type extends TSchema> ? TOptional<TFromType<ModuleProperties, Type>> : Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TFromType<ModuleProperties, Type>> : Type extends TTransform<infer Input extends TSchema, infer Output extends unknown> ? TFromTransform<ModuleProperties, Input, Output> : Type extends TArray<infer Type extends TSchema> ? TFromArray<ModuleProperties, Type> : Type extends TAsyncIterator<infer Type extends TSchema> ? TFromAsyncIterator<ModuleProperties, Type> : Type extends TComputed<infer Target extends string, infer Parameters extends TSchema[]> ? TFromComputed<ModuleProperties, Target, Parameters> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TFromConstructor<ModuleProperties, Parameters, InstanceType> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFromFunction<ModuleProperties, Parameters, ReturnType> : Type extends TIntersect<infer Types extends TSchema[]> ? TFromIntersect<ModuleProperties, Types> : Type extends TIterator<infer Type extends TSchema> ? TFromIterator<ModuleProperties, Type> : Type extends TObject<infer Properties extends TProperties> ? TFromObject<ModuleProperties, Properties> : Type extends TRecord<infer Key extends TSchema, infer Value extends TSchema> ? TFromRecord<ModuleProperties, Key, Value> : Type extends TTuple<infer Types extends TSchema[]> ? TFromTuple<ModuleProperties, Types> : Type extends TEnum<infer _ extends TEnumRecord> ? Type : Type extends TUnion<infer Types extends TSchema[]> ? TFromUnion<ModuleProperties, Types> : Type);
|
|
50
52
|
export declare function FromType<ModuleProperties extends TProperties, Type extends TSchema>(moduleProperties: ModuleProperties, type: Type): TFromType<ModuleProperties, Type>;
|
|
51
53
|
export type TComputeType<ModuleProperties extends TProperties, Key extends PropertyKey> = (Key extends keyof ModuleProperties ? TFromType<ModuleProperties, ModuleProperties[Key]> : TNever);
|
|
52
54
|
export declare function ComputeType<ModuleProperties extends TProperties, Key extends PropertyKey>(moduleProperties: ModuleProperties, key: Key): TComputeType<ModuleProperties, Key>;
|
|
@@ -19,24 +19,27 @@ import { RecordValue, RecordPattern } from '../record/index.mjs';
|
|
|
19
19
|
import { Required } from '../required/index.mjs';
|
|
20
20
|
import { Tuple } from '../tuple/index.mjs';
|
|
21
21
|
import { Union } from '../union/index.mjs';
|
|
22
|
-
|
|
22
|
+
// ------------------------------------------------------------------
|
|
23
|
+
// Symbols
|
|
24
|
+
// ------------------------------------------------------------------
|
|
25
|
+
import { TransformKind, OptionalKind, ReadonlyKind } from '../symbols/index.mjs';
|
|
23
26
|
// ------------------------------------------------------------------
|
|
24
27
|
// KindGuard
|
|
25
28
|
// ------------------------------------------------------------------
|
|
26
29
|
import * as KindGuard from '../guard/kind.mjs';
|
|
27
30
|
// prettier-ignore
|
|
28
|
-
function
|
|
31
|
+
function DereferenceParameters(moduleProperties, types) {
|
|
29
32
|
return types.map((type) => {
|
|
30
33
|
return KindGuard.IsRef(type)
|
|
31
|
-
?
|
|
34
|
+
? Dereference(moduleProperties, type.$ref)
|
|
32
35
|
: FromType(moduleProperties, type);
|
|
33
36
|
});
|
|
34
37
|
}
|
|
35
38
|
// prettier-ignore
|
|
36
|
-
function
|
|
39
|
+
function Dereference(moduleProperties, ref) {
|
|
37
40
|
return (ref in moduleProperties
|
|
38
41
|
? KindGuard.IsRef(moduleProperties[ref])
|
|
39
|
-
?
|
|
42
|
+
? Dereference(moduleProperties, moduleProperties[ref].$ref)
|
|
40
43
|
: FromType(moduleProperties, moduleProperties[ref])
|
|
41
44
|
: Never());
|
|
42
45
|
}
|
|
@@ -70,7 +73,7 @@ function FromRequired(parameters) {
|
|
|
70
73
|
}
|
|
71
74
|
// prettier-ignore
|
|
72
75
|
function FromComputed(moduleProperties, target, parameters) {
|
|
73
|
-
const dereferenced =
|
|
76
|
+
const dereferenced = DereferenceParameters(moduleProperties, parameters);
|
|
74
77
|
return (target === 'Awaited' ? FromAwaited(dereferenced) :
|
|
75
78
|
target === 'Index' ? FromIndex(dereferenced) :
|
|
76
79
|
target === 'KeyOf' ? FromKeyOf(dereferenced) :
|
|
@@ -80,6 +83,26 @@ function FromComputed(moduleProperties, target, parameters) {
|
|
|
80
83
|
target === 'Required' ? FromRequired(dereferenced) :
|
|
81
84
|
Never());
|
|
82
85
|
}
|
|
86
|
+
function FromArray(moduleProperties, type) {
|
|
87
|
+
return Array(FromType(moduleProperties, type));
|
|
88
|
+
}
|
|
89
|
+
function FromAsyncIterator(moduleProperties, type) {
|
|
90
|
+
return AsyncIterator(FromType(moduleProperties, type));
|
|
91
|
+
}
|
|
92
|
+
// prettier-ignore
|
|
93
|
+
function FromConstructor(moduleProperties, parameters, instanceType) {
|
|
94
|
+
return Constructor(FromTypes(moduleProperties, parameters), FromType(moduleProperties, instanceType));
|
|
95
|
+
}
|
|
96
|
+
// prettier-ignore
|
|
97
|
+
function FromFunction(moduleProperties, parameters, returnType) {
|
|
98
|
+
return FunctionType(FromTypes(moduleProperties, parameters), FromType(moduleProperties, returnType));
|
|
99
|
+
}
|
|
100
|
+
function FromIntersect(moduleProperties, types) {
|
|
101
|
+
return Intersect(FromTypes(moduleProperties, types));
|
|
102
|
+
}
|
|
103
|
+
function FromIterator(moduleProperties, type) {
|
|
104
|
+
return Iterator(FromType(moduleProperties, type));
|
|
105
|
+
}
|
|
83
106
|
function FromObject(moduleProperties, properties) {
|
|
84
107
|
return Object(globalThis.Object.keys(properties).reduce((result, key) => {
|
|
85
108
|
return { ...result, [key]: FromType(moduleProperties, properties[key]) };
|
|
@@ -93,53 +116,41 @@ function FromRecord(moduleProperties, type) {
|
|
|
93
116
|
return result;
|
|
94
117
|
}
|
|
95
118
|
// prettier-ignore
|
|
96
|
-
function
|
|
97
|
-
return
|
|
98
|
-
}
|
|
99
|
-
|
|
100
|
-
function FromFunction(moduleProperties, parameters, returnType) {
|
|
101
|
-
return FunctionType(FromRest(moduleProperties, parameters), FromType(moduleProperties, returnType));
|
|
119
|
+
function FromTransform(moduleProperties, transform) {
|
|
120
|
+
return (KindGuard.IsRef(transform))
|
|
121
|
+
? { ...Dereference(moduleProperties, transform.$ref), [TransformKind]: transform[TransformKind] }
|
|
122
|
+
: transform;
|
|
102
123
|
}
|
|
103
124
|
function FromTuple(moduleProperties, types) {
|
|
104
|
-
return Tuple(
|
|
105
|
-
}
|
|
106
|
-
function FromIntersect(moduleProperties, types) {
|
|
107
|
-
return Intersect(FromRest(moduleProperties, types));
|
|
125
|
+
return Tuple(FromTypes(moduleProperties, types));
|
|
108
126
|
}
|
|
109
127
|
function FromUnion(moduleProperties, types) {
|
|
110
|
-
return Union(
|
|
111
|
-
}
|
|
112
|
-
function FromArray(moduleProperties, type) {
|
|
113
|
-
return Array(FromType(moduleProperties, type));
|
|
114
|
-
}
|
|
115
|
-
function FromAsyncIterator(moduleProperties, type) {
|
|
116
|
-
return AsyncIterator(FromType(moduleProperties, type));
|
|
117
|
-
}
|
|
118
|
-
function FromIterator(moduleProperties, type) {
|
|
119
|
-
return Iterator(FromType(moduleProperties, type));
|
|
128
|
+
return Union(FromTypes(moduleProperties, types));
|
|
120
129
|
}
|
|
121
|
-
function
|
|
130
|
+
function FromTypes(moduleProperties, types) {
|
|
122
131
|
return types.map((type) => FromType(moduleProperties, type));
|
|
123
132
|
}
|
|
124
133
|
// prettier-ignore
|
|
125
134
|
export function FromType(moduleProperties, type) {
|
|
126
135
|
return (
|
|
127
|
-
//
|
|
136
|
+
// Modifiers
|
|
128
137
|
KindGuard.IsOptional(type) ? CreateType(FromType(moduleProperties, Discard(type, [OptionalKind])), type) :
|
|
129
138
|
KindGuard.IsReadonly(type) ? CreateType(FromType(moduleProperties, Discard(type, [ReadonlyKind])), type) :
|
|
130
|
-
//
|
|
131
|
-
KindGuard.
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
139
|
+
// Transform
|
|
140
|
+
KindGuard.IsTransform(type) ? CreateType(FromTransform(moduleProperties, type), type) :
|
|
141
|
+
// Types
|
|
142
|
+
KindGuard.IsArray(type) ? CreateType(FromArray(moduleProperties, type.items), type) :
|
|
143
|
+
KindGuard.IsAsyncIterator(type) ? CreateType(FromAsyncIterator(moduleProperties, type.items), type) :
|
|
144
|
+
KindGuard.IsComputed(type) ? CreateType(FromComputed(moduleProperties, type.target, type.parameters)) :
|
|
145
|
+
KindGuard.IsConstructor(type) ? CreateType(FromConstructor(moduleProperties, type.parameters, type.returns), type) :
|
|
146
|
+
KindGuard.IsFunction(type) ? CreateType(FromFunction(moduleProperties, type.parameters, type.returns), type) :
|
|
147
|
+
KindGuard.IsIntersect(type) ? CreateType(FromIntersect(moduleProperties, type.allOf), type) :
|
|
148
|
+
KindGuard.IsIterator(type) ? CreateType(FromIterator(moduleProperties, type.items), type) :
|
|
149
|
+
KindGuard.IsObject(type) ? CreateType(FromObject(moduleProperties, type.properties), type) :
|
|
150
|
+
KindGuard.IsRecord(type) ? CreateType(FromRecord(moduleProperties, type)) :
|
|
151
|
+
KindGuard.IsTuple(type) ? CreateType(FromTuple(moduleProperties, type.items || []), type) :
|
|
152
|
+
KindGuard.IsUnion(type) ? CreateType(FromUnion(moduleProperties, type.anyOf), type) :
|
|
153
|
+
type);
|
|
143
154
|
}
|
|
144
155
|
// prettier-ignore
|
|
145
156
|
export function ComputeType(moduleProperties, key) {
|
|
@@ -7,6 +7,7 @@ import type { TConstructor } from '../constructor/index.mjs';
|
|
|
7
7
|
import type { TEnum } from '../enum/index.mjs';
|
|
8
8
|
import type { TFunction } from '../function/index.mjs';
|
|
9
9
|
import type { TIntersect } from '../intersect/index.mjs';
|
|
10
|
+
import type { TImport } from '../module/index.mjs';
|
|
10
11
|
import type { TIterator } from '../iterator/index.mjs';
|
|
11
12
|
import type { TNot } from '../not/index.mjs';
|
|
12
13
|
import type { TObject, TProperties } from '../object/index.mjs';
|
|
@@ -19,17 +20,20 @@ import type { TUnion } from '../union/index.mjs';
|
|
|
19
20
|
import type { TUnsafe } from '../unsafe/index.mjs';
|
|
20
21
|
import type { TSchema } from '../schema/index.mjs';
|
|
21
22
|
import type { TTransform } from '../transform/index.mjs';
|
|
22
|
-
|
|
23
|
-
|
|
23
|
+
import type { TNever } from '../never/index.mjs';
|
|
24
|
+
type TDecodeImport<ModuleProperties extends TProperties, Key extends PropertyKey> = (Key extends keyof ModuleProperties ? TDecodeType<ModuleProperties[Key]> extends infer Type extends TSchema ? Type extends TRef<infer Ref extends string> ? TDecodeImport<ModuleProperties, Ref> : Type : TNever : TNever);
|
|
25
|
+
type TDecodeProperties<Properties extends TProperties> = {
|
|
26
|
+
[Key in keyof Properties]: TDecodeType<Properties[Key]>;
|
|
24
27
|
};
|
|
25
|
-
|
|
26
|
-
export type TDecodeType<
|
|
27
|
-
export type StaticDecodeIsAny<
|
|
28
|
+
type TDecodeTypes<Types extends TSchema[], Result extends TSchema[] = []> = (Types extends [infer Left extends TSchema, ...infer Right extends TSchema[]] ? TDecodeTypes<Right, [...Result, TDecodeType<Left>]> : Result);
|
|
29
|
+
export type TDecodeType<Type extends TSchema> = (Type extends TOptional<infer Type extends TSchema> ? TOptional<TDecodeType<Type>> : Type extends TReadonly<infer Type extends TSchema> ? TReadonly<TDecodeType<Type>> : Type extends TTransform<infer _Input extends TSchema, infer Output> ? TUnsafe<Output> : Type extends TArray<infer Type extends TSchema> ? TArray<TDecodeType<Type>> : Type extends TAsyncIterator<infer Type extends TSchema> ? TAsyncIterator<TDecodeType<Type>> : Type extends TConstructor<infer Parameters extends TSchema[], infer InstanceType extends TSchema> ? TConstructor<TDecodeTypes<Parameters>, TDecodeType<InstanceType>> : Type extends TEnum<infer Values> ? TEnum<Values> : Type extends TFunction<infer Parameters extends TSchema[], infer ReturnType extends TSchema> ? TFunction<TDecodeTypes<Parameters>, TDecodeType<ReturnType>> : Type extends TIntersect<infer Types extends TSchema[]> ? TIntersect<TDecodeTypes<Types>> : Type extends TImport<infer ModuleProperties extends TProperties, infer Key> ? TDecodeImport<ModuleProperties, Key> : Type extends TIterator<infer Type extends TSchema> ? TIterator<TDecodeType<Type>> : Type extends TNot<infer Type extends TSchema> ? TNot<TDecodeType<Type>> : Type extends TObject<infer Properties extends TProperties> ? TObject<Evaluate<TDecodeProperties<Properties>>> : Type extends TPromise<infer Type extends TSchema> ? TPromise<TDecodeType<Type>> : Type extends TRecord<infer Key extends TSchema, infer Value extends TSchema> ? TRecord<Key, TDecodeType<Value>> : Type extends TRecursive<infer Type extends TSchema> ? TRecursive<TDecodeType<Type>> : Type extends TRef<infer Ref extends string> ? TRef<Ref> : Type extends TTuple<infer Types extends TSchema[]> ? TTuple<TDecodeTypes<Types>> : Type extends TUnion<infer Types extends TSchema[]> ? TUnion<TDecodeTypes<Types>> : Type);
|
|
30
|
+
export type StaticDecodeIsAny<Type> = boolean extends (Type extends TSchema ? true : false) ? true : false;
|
|
28
31
|
/** Creates an decoded static type from a TypeBox type */
|
|
29
|
-
export type StaticDecode<
|
|
32
|
+
export type StaticDecode<Type extends TSchema, Params extends unknown[] = [], Result = StaticDecodeIsAny<Type> extends true ? unknown : Static<TDecodeType<Type>, Params>> = Result;
|
|
30
33
|
/** Creates an encoded static type from a TypeBox type */
|
|
31
|
-
export type StaticEncode<
|
|
34
|
+
export type StaticEncode<Type extends TSchema, Params extends unknown[] = [], Result = Static<Type, Params>> = Result;
|
|
32
35
|
/** Creates a static type from a TypeBox type */
|
|
33
|
-
export type Static<
|
|
34
|
-
params:
|
|
35
|
-
})['static'];
|
|
36
|
+
export type Static<Type extends TSchema, Params extends unknown[] = [], Result = (Type & {
|
|
37
|
+
params: Params;
|
|
38
|
+
})['static']> = Result;
|
|
39
|
+
export {};
|
|
@@ -4,7 +4,7 @@ import { StaticDecode } from '../../type/static/index.mjs';
|
|
|
4
4
|
export declare class ParseError extends TypeBoxError {
|
|
5
5
|
constructor(message: string);
|
|
6
6
|
}
|
|
7
|
-
export type TParseOperation = '
|
|
7
|
+
export type TParseOperation = 'Assert' | 'Cast' | 'Clean' | 'Clone' | 'Convert' | 'Decode' | 'Default' | 'Encode' | ({} & string);
|
|
8
8
|
export type TParseFunction = (type: TSchema, references: TSchema[], value: unknown) => unknown;
|
|
9
9
|
export declare namespace ParseRegistry {
|
|
10
10
|
function Delete(key: string): void;
|
|
@@ -1,10 +1,11 @@
|
|
|
1
1
|
import { TypeBoxError } from '../../type/error/index.mjs';
|
|
2
2
|
import { TransformDecode, TransformEncode, HasTransform } from '../transform/index.mjs';
|
|
3
3
|
import { Assert } from '../assert/index.mjs';
|
|
4
|
-
import {
|
|
5
|
-
import { Convert } from '../convert/index.mjs';
|
|
4
|
+
import { Cast } from '../cast/index.mjs';
|
|
6
5
|
import { Clean } from '../clean/index.mjs';
|
|
7
6
|
import { Clone } from '../clone/index.mjs';
|
|
7
|
+
import { Convert } from '../convert/index.mjs';
|
|
8
|
+
import { Default } from '../default/index.mjs';
|
|
8
9
|
// ------------------------------------------------------------------
|
|
9
10
|
// Guards
|
|
10
11
|
// ------------------------------------------------------------------
|
|
@@ -21,12 +22,13 @@ export class ParseError extends TypeBoxError {
|
|
|
21
22
|
export var ParseRegistry;
|
|
22
23
|
(function (ParseRegistry) {
|
|
23
24
|
const registry = new Map([
|
|
24
|
-
['
|
|
25
|
+
['Assert', (type, references, value) => { Assert(type, references, value); return value; }],
|
|
26
|
+
['Cast', (type, references, value) => Cast(type, references, value)],
|
|
25
27
|
['Clean', (type, references, value) => Clean(type, references, value)],
|
|
26
|
-
['
|
|
28
|
+
['Clone', (_type, _references, value) => Clone(value)],
|
|
27
29
|
['Convert', (type, references, value) => Convert(type, references, value)],
|
|
28
|
-
['Assert', (type, references, value) => { Assert(type, references, value); return value; }],
|
|
29
30
|
['Decode', (type, references, value) => (HasTransform(type, references) ? TransformDecode(type, references, value) : value)],
|
|
31
|
+
['Default', (type, references, value) => Default(type, references, value)],
|
|
30
32
|
['Encode', (type, references, value) => (HasTransform(type, references) ? TransformEncode(type, references, value) : value)],
|
|
31
33
|
]);
|
|
32
34
|
// Deletes an entry from the registry
|
|
@@ -46,7 +48,7 @@ export var ParseRegistry;
|
|
|
46
48
|
ParseRegistry.Get = Get;
|
|
47
49
|
})(ParseRegistry || (ParseRegistry = {}));
|
|
48
50
|
// ------------------------------------------------------------------
|
|
49
|
-
// Default Parse
|
|
51
|
+
// Default Parse Pipeline
|
|
50
52
|
// ------------------------------------------------------------------
|
|
51
53
|
// prettier-ignore
|
|
52
54
|
export const ParseDefault = [
|
|
@@ -78,12 +78,10 @@ function FromIntersect(schema, references, path, value) {
|
|
|
78
78
|
}
|
|
79
79
|
// prettier-ignore
|
|
80
80
|
function FromImport(schema, references, path, value) {
|
|
81
|
-
const
|
|
81
|
+
const additional = globalThis.Object.values(schema.$defs);
|
|
82
82
|
const target = schema.$defs[schema.$ref];
|
|
83
|
-
const
|
|
84
|
-
|
|
85
|
-
const transformTarget = { [TransformKind]: transform, ...target };
|
|
86
|
-
return Visit(transformTarget, [...references, ...definitions], path, value);
|
|
83
|
+
const result = Visit(target, [...references, ...additional], path, value);
|
|
84
|
+
return Default(schema, path, result);
|
|
87
85
|
}
|
|
88
86
|
function FromNot(schema, references, path, value) {
|
|
89
87
|
return Default(schema, path, Visit(schema.not, references, path, value));
|
|
@@ -55,12 +55,10 @@ function FromArray(schema, references, path, value) {
|
|
|
55
55
|
}
|
|
56
56
|
// prettier-ignore
|
|
57
57
|
function FromImport(schema, references, path, value) {
|
|
58
|
-
const
|
|
58
|
+
const additional = globalThis.Object.values(schema.$defs);
|
|
59
59
|
const target = schema.$defs[schema.$ref];
|
|
60
|
-
const
|
|
61
|
-
|
|
62
|
-
const transformTarget = { [TransformKind]: transform, ...target };
|
|
63
|
-
return Visit(transformTarget, [...references, ...definitions], path, value);
|
|
60
|
+
const result = Default(schema, path, value);
|
|
61
|
+
return Visit(target, [...references, ...additional], path, result);
|
|
64
62
|
}
|
|
65
63
|
// prettier-ignore
|
|
66
64
|
function FromIntersect(schema, references, path, value) {
|
|
@@ -29,6 +29,12 @@ function FromIntersect(schema, references) {
|
|
|
29
29
|
return IsTransform(schema) || IsTransform(schema.unevaluatedProperties) || schema.allOf.some((schema) => Visit(schema, references));
|
|
30
30
|
}
|
|
31
31
|
// prettier-ignore
|
|
32
|
+
function FromImport(schema, references) {
|
|
33
|
+
const additional = globalThis.Object.getOwnPropertyNames(schema.$defs).reduce((result, key) => [...result, schema.$defs[key]], []);
|
|
34
|
+
const target = schema.$defs[schema.$ref];
|
|
35
|
+
return IsTransform(schema) || Visit(target, [...additional, ...references]);
|
|
36
|
+
}
|
|
37
|
+
// prettier-ignore
|
|
32
38
|
function FromIterator(schema, references) {
|
|
33
39
|
return IsTransform(schema) || Visit(schema.items, references);
|
|
34
40
|
}
|
|
@@ -89,6 +95,8 @@ function Visit(schema, references) {
|
|
|
89
95
|
return FromConstructor(schema_, references_);
|
|
90
96
|
case 'Function':
|
|
91
97
|
return FromFunction(schema_, references_);
|
|
98
|
+
case 'Import':
|
|
99
|
+
return FromImport(schema_, references_);
|
|
92
100
|
case 'Intersect':
|
|
93
101
|
return FromIntersect(schema_, references_);
|
|
94
102
|
case 'Iterator':
|
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -544,7 +544,7 @@ The following table lists the supported Json types. These types are fully compat
|
|
|
544
544
|
|
|
545
545
|
### JavaScript Types
|
|
546
546
|
|
|
547
|
-
TypeBox provides an extended type set that can be used to create schematics for common JavaScript constructs. These types can not be used with any standard Json Schema validator; but can be used to frame schematics for interfaces that may receive Json validated data. JavaScript types are prefixed with the `[JavaScript]`
|
|
547
|
+
TypeBox provides an extended type set that can be used to create schematics for common JavaScript constructs. These types can not be used with any standard Json Schema validator; but can be used to frame schematics for interfaces that may receive Json validated data. JavaScript types are prefixed with the `[JavaScript]` JSDoc comment for convenience. The following table lists the supported types.
|
|
548
548
|
|
|
549
549
|
```typescript
|
|
550
550
|
┌────────────────────────────────┬─────────────────────────────┬────────────────────────────────┐
|
|
@@ -717,11 +717,11 @@ Object properties can be modified with Readonly and Optional. The following tabl
|
|
|
717
717
|
|
|
718
718
|
### Generic Types
|
|
719
719
|
|
|
720
|
-
Generic types can be created with generic functions
|
|
720
|
+
Generic types can be created with generic functions.
|
|
721
721
|
|
|
722
722
|
```typescript
|
|
723
723
|
const Nullable = <T extends TSchema>(T: T) => { // type Nullable<T> = T | null
|
|
724
|
-
return Type.Union([T, Type.Null())
|
|
724
|
+
return Type.Union([T, Type.Null()])
|
|
725
725
|
}
|
|
726
726
|
|
|
727
727
|
const T = Nullable(Type.String()) // type T = Nullable<string>
|
|
@@ -731,7 +731,7 @@ const T = Nullable(Type.String()) // type T = Nullable<string>
|
|
|
731
731
|
|
|
732
732
|
### Recursive Types
|
|
733
733
|
|
|
734
|
-
Use the Recursive function to create recursive types
|
|
734
|
+
Use the Recursive function to create recursive types.
|
|
735
735
|
|
|
736
736
|
```typescript
|
|
737
737
|
const Node = Type.Recursive(This => Type.Object({ // const Node = {
|
|
@@ -875,7 +875,7 @@ const C = Type.Index(T, Type.KeyOf(T)) // type C = T[keyof T]
|
|
|
875
875
|
|
|
876
876
|
### Mapped Types
|
|
877
877
|
|
|
878
|
-
TypeBox supports mapped types with the Mapped function. This function accepts two arguments, the first is a union type typically derived from KeyOf, the second is a mapping function that receives a mapping key `K` that can be used to index properties of a type. The following implements a mapped type that remaps each property to be `T | null
|
|
878
|
+
TypeBox supports mapped types with the Mapped function. This function accepts two arguments, the first is a union type typically derived from KeyOf, the second is a mapping function that receives a mapping key `K` that can be used to index properties of a type. The following implements a mapped type that remaps each property to be `T | null`.
|
|
879
879
|
|
|
880
880
|
```typescript
|
|
881
881
|
const T = Type.Object({ // type T = {
|
|
@@ -1123,7 +1123,7 @@ const Z = Value.Default(T, { x: 1 }) // const 'Z = { x: 1, y:
|
|
|
1123
1123
|
|
|
1124
1124
|
### Cast
|
|
1125
1125
|
|
|
1126
|
-
Use the Cast function to upcast a value into a target type. This function will retain as much
|
|
1126
|
+
Use the Cast function to upcast a value into a target type. This function will retain as much information as possible from the original value. The Cast function is intended to be used in data migration scenarios where existing values need to be upgraded to match a modified type.
|
|
1127
1127
|
|
|
1128
1128
|
```typescript
|
|
1129
1129
|
const T = Type.Object({ x: Type.Number(), y: Type.Number() }, { additionalProperties: false })
|
|
@@ -1203,7 +1203,7 @@ const R = Value.Equal( // const R = true
|
|
|
1203
1203
|
|
|
1204
1204
|
### Hash
|
|
1205
1205
|
|
|
1206
|
-
Use the Hash function to create a [FNV1A-64](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function) non
|
|
1206
|
+
Use the Hash function to create a [FNV1A-64](https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function) non-cryptographic hash of a value.
|
|
1207
1207
|
|
|
1208
1208
|
```typescript
|
|
1209
1209
|
const A = Value.Hash({ x: 1, y: 2, z: 3 }) // const A = 2910466848807138541n
|
|
@@ -1383,7 +1383,7 @@ type BasisVectors = Static<typeof BasisVectors> // type BasisVectors = {
|
|
|
1383
1383
|
|
|
1384
1384
|
### Options
|
|
1385
1385
|
|
|
1386
|
-
Options can be passed via the last parameter
|
|
1386
|
+
Options can be passed via the last parameter.
|
|
1387
1387
|
|
|
1388
1388
|
```typescript
|
|
1389
1389
|
const T = Syntax(`number`, { minimum: 42 }) // const T = {
|
|
@@ -1455,7 +1455,7 @@ const B = Value.Check(T, 'bar') // const B = false
|
|
|
1455
1455
|
|
|
1456
1456
|
## TypeCheck
|
|
1457
1457
|
|
|
1458
|
-
TypeBox types target Json Schema Draft 7 and are compatible with any validator that supports this specification. TypeBox also provides a built
|
|
1458
|
+
TypeBox types target Json Schema Draft 7 and are compatible with any validator that supports this specification. TypeBox also provides a built-in type checking compiler designed specifically for TypeBox types that offers high performance compilation and value checking.
|
|
1459
1459
|
|
|
1460
1460
|
The following sections detail using Ajv and the TypeBox compiler infrastructure.
|
|
1461
1461
|
|
|
@@ -1574,7 +1574,7 @@ const C = TypeCompiler.Code(Type.String()) // const C = `return functi
|
|
|
1574
1574
|
|
|
1575
1575
|
## TypeMap
|
|
1576
1576
|
|
|
1577
|
-
TypeBox offers an external package for
|
|
1577
|
+
TypeBox offers an external package for bidirectional mapping between TypeBox, Valibot, and Zod type libraries. It also includes syntax parsing support for Valibot and Zod and supports the Standard Schema specification. For more details on TypeMap, refer to the project repository.
|
|
1578
1578
|
|
|
1579
1579
|
[TypeMap Repository](https://github.com/sinclairzx81/typemap)
|
|
1580
1580
|
|
|
@@ -1582,7 +1582,7 @@ TypeBox offers an external package for bi-directional mapping between TypeBox, V
|
|
|
1582
1582
|
|
|
1583
1583
|
### Usage
|
|
1584
1584
|
|
|
1585
|
-
TypeMap needs to be installed
|
|
1585
|
+
TypeMap needs to be installed separately
|
|
1586
1586
|
|
|
1587
1587
|
```bash
|
|
1588
1588
|
$ npm install @sinclair/typemap
|
|
@@ -1731,11 +1731,11 @@ The following is a list of community packages that offer general tooling, extend
|
|
|
1731
1731
|
| [json2typebox](https://github.com/hacxy/json2typebox) | Creating TypeBox code from Json Data |
|
|
1732
1732
|
| [nominal-typebox](https://github.com/Coder-Spirit/nominal/tree/main/%40coderspirit/nominal-typebox) | Allows devs to integrate nominal types into TypeBox schemas |
|
|
1733
1733
|
| [openapi-box](https://github.com/geut/openapi-box) | Generate TypeBox types from OpenApi IDL + Http client library |
|
|
1734
|
-
| [prismabox](https://github.com/m1212e/prismabox) | Converts a prisma.schema to
|
|
1734
|
+
| [prismabox](https://github.com/m1212e/prismabox) | Converts a prisma.schema to TypeBox schema matching the database models |
|
|
1735
1735
|
| [schema2typebox](https://github.com/xddq/schema2typebox) | Creating TypeBox code from Json Schemas |
|
|
1736
1736
|
| [sveltekit-superforms](https://github.com/ciscoheat/sveltekit-superforms) | A comprehensive SvelteKit form library for server and client validation |
|
|
1737
1737
|
| [ts2typebox](https://github.com/xddq/ts2typebox) | Creating TypeBox code from Typescript types |
|
|
1738
|
-
| [typebox-cli](https://github.com/gsuess/typebox-cli) | Generate Schema with
|
|
1738
|
+
| [typebox-cli](https://github.com/gsuess/typebox-cli) | Generate Schema with TypeBox from the CLI |
|
|
1739
1739
|
| [typebox-form-parser](https://github.com/jtlapp/typebox-form-parser) | Parses form and query data based on TypeBox schemas |
|
|
1740
1740
|
|
|
1741
1741
|
|