@sinclair/typebox 0.33.0 → 0.33.2
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/create/type.js +1 -1
- package/build/cjs/type/intrinsic/intrinsic.js +1 -1
- package/build/cjs/type/mapped/mapped.js +12 -10
- package/build/cjs/type/omit/omit.js +2 -4
- package/build/cjs/type/pick/pick.js +2 -4
- package/build/esm/type/create/type.mjs +1 -1
- package/build/esm/type/intrinsic/intrinsic.mjs +1 -1
- package/build/esm/type/mapped/mapped.mjs +12 -10
- package/build/esm/type/omit/omit.mjs +2 -4
- package/build/esm/type/pick/pick.mjs +2 -4
- package/package.json +1 -1
|
@@ -7,7 +7,7 @@ const immutable_1 = require("./immutable");
|
|
|
7
7
|
const value_1 = require("../clone/value");
|
|
8
8
|
/** Creates TypeBox schematics using the configured InstanceMode */
|
|
9
9
|
function CreateType(schema, options) {
|
|
10
|
-
const result = options !== undefined ?
|
|
10
|
+
const result = options !== undefined ? { ...options, ...schema } : schema;
|
|
11
11
|
switch (policy_1.TypeSystemPolicy.InstanceMode) {
|
|
12
12
|
case 'freeze':
|
|
13
13
|
return (0, immutable_1.Immutable)(result);
|
|
@@ -60,7 +60,7 @@ function Intrinsic(schema, mode, options = {}) {
|
|
|
60
60
|
// Intrinsic-Mapped-Inference
|
|
61
61
|
(0, kind_1.IsMappedKey)(schema) ? (0, intrinsic_from_mapped_key_1.IntrinsicFromMappedKey)(schema, mode, options) :
|
|
62
62
|
// Standard-Inference
|
|
63
|
-
(0, kind_1.IsTemplateLiteral)(schema) ? FromTemplateLiteral(schema, mode,
|
|
63
|
+
(0, kind_1.IsTemplateLiteral)(schema) ? FromTemplateLiteral(schema, mode, options) :
|
|
64
64
|
(0, kind_1.IsUnion)(schema) ? (0, index_3.Union)(FromRest(schema.anyOf, mode), options) :
|
|
65
65
|
(0, kind_1.IsLiteral)(schema) ? (0, index_2.Literal)(FromLiteralValue(schema.const, mode), options) :
|
|
66
66
|
// Default Type
|
|
@@ -69,6 +69,8 @@ function FromProperties(K, T) {
|
|
|
69
69
|
}
|
|
70
70
|
// prettier-ignore
|
|
71
71
|
function FromSchemaType(K, T) {
|
|
72
|
+
// required to retain user defined options for mapped type
|
|
73
|
+
const options = { ...T };
|
|
72
74
|
return (
|
|
73
75
|
// unevaluated modifier types
|
|
74
76
|
(0, kind_1.IsOptional)(T) ? (0, index_12.Optional)(FromSchemaType(K, (0, index_2.Discard)(T, [index_1.OptionalKind]))) :
|
|
@@ -77,16 +79,16 @@ function FromSchemaType(K, T) {
|
|
|
77
79
|
(0, kind_1.IsMappedResult)(T) ? FromMappedResult(K, T.properties) :
|
|
78
80
|
(0, kind_1.IsMappedKey)(T) ? FromMappedKey(K, T.keys) :
|
|
79
81
|
// unevaluated types
|
|
80
|
-
(0, kind_1.IsConstructor)(T) ? (0, index_5.Constructor)(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
|
|
81
|
-
(0, kind_1.IsFunction)(T) ? (0, index_6.Function)(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
|
|
82
|
-
(0, kind_1.IsAsyncIterator)(T) ? (0, index_4.AsyncIterator)(FromSchemaType(K, T.items)) :
|
|
83
|
-
(0, kind_1.IsIterator)(T) ? (0, index_9.Iterator)(FromSchemaType(K, T.items)) :
|
|
84
|
-
(0, kind_1.IsIntersect)(T) ? (0, index_8.Intersect)(FromRest(K, T.allOf)) :
|
|
85
|
-
(0, kind_1.IsUnion)(T) ? (0, index_16.Union)(FromRest(K, T.anyOf)) :
|
|
86
|
-
(0, kind_1.IsTuple)(T) ? (0, index_15.Tuple)(FromRest(K, T.items ?? [])) :
|
|
87
|
-
(0, kind_1.IsObject)(T) ? (0, index_11.Object)(FromProperties(K, T.properties)) :
|
|
88
|
-
(0, kind_1.IsArray)(T) ? (0, index_3.Array)(FromSchemaType(K, T.items)) :
|
|
89
|
-
(0, kind_1.IsPromise)(T) ? (0, index_13.Promise)(FromSchemaType(K, T.item)) :
|
|
82
|
+
(0, kind_1.IsConstructor)(T) ? (0, index_5.Constructor)(FromRest(K, T.parameters), FromSchemaType(K, T.returns), options) :
|
|
83
|
+
(0, kind_1.IsFunction)(T) ? (0, index_6.Function)(FromRest(K, T.parameters), FromSchemaType(K, T.returns), options) :
|
|
84
|
+
(0, kind_1.IsAsyncIterator)(T) ? (0, index_4.AsyncIterator)(FromSchemaType(K, T.items), options) :
|
|
85
|
+
(0, kind_1.IsIterator)(T) ? (0, index_9.Iterator)(FromSchemaType(K, T.items), options) :
|
|
86
|
+
(0, kind_1.IsIntersect)(T) ? (0, index_8.Intersect)(FromRest(K, T.allOf), options) :
|
|
87
|
+
(0, kind_1.IsUnion)(T) ? (0, index_16.Union)(FromRest(K, T.anyOf), options) :
|
|
88
|
+
(0, kind_1.IsTuple)(T) ? (0, index_15.Tuple)(FromRest(K, T.items ?? []), options) :
|
|
89
|
+
(0, kind_1.IsObject)(T) ? (0, index_11.Object)(FromProperties(K, T.properties), options) :
|
|
90
|
+
(0, kind_1.IsArray)(T) ? (0, index_3.Array)(FromSchemaType(K, T.items), options) :
|
|
91
|
+
(0, kind_1.IsPromise)(T) ? (0, index_13.Promise)(FromSchemaType(K, T.item), options) :
|
|
90
92
|
T);
|
|
91
93
|
}
|
|
92
94
|
// prettier-ignore
|
|
@@ -42,7 +42,7 @@ function FromProperties(T, K) {
|
|
|
42
42
|
function OmitResolve(T, K) {
|
|
43
43
|
return ((0, kind_1.IsIntersect)(T) ? (0, index_1.Intersect)(FromIntersect(T.allOf, K)) :
|
|
44
44
|
(0, kind_1.IsUnion)(T) ? (0, index_2.Union)(FromUnion(T.anyOf, K)) :
|
|
45
|
-
(0, kind_1.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties, K)) :
|
|
45
|
+
(0, kind_1.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties, K), (0, index_5.Discard)(T, [index_6.TransformKind, '$id', 'required'])) :
|
|
46
46
|
(0, index_3.Object)({}));
|
|
47
47
|
}
|
|
48
48
|
function Omit(T, K, options) {
|
|
@@ -53,7 +53,5 @@ function Omit(T, K, options) {
|
|
|
53
53
|
return (0, omit_from_mapped_result_1.OmitFromMappedResult)(T, K, options);
|
|
54
54
|
// non-mapped
|
|
55
55
|
const I = (0, kind_1.IsSchema)(K) ? (0, index_4.IndexPropertyKeys)(K) : K;
|
|
56
|
-
|
|
57
|
-
const R = OmitResolve(T, I);
|
|
58
|
-
return (0, type_1.CreateType)({ ...D, ...R }, options);
|
|
56
|
+
return (0, type_1.CreateType)(OmitResolve(T, I), options);
|
|
59
57
|
}
|
|
@@ -37,7 +37,7 @@ function FromProperties(T, K) {
|
|
|
37
37
|
function PickResolve(T, K) {
|
|
38
38
|
return ((0, kind_1.IsIntersect)(T) ? (0, index_1.Intersect)(FromIntersect(T.allOf, K)) :
|
|
39
39
|
(0, kind_1.IsUnion)(T) ? (0, index_2.Union)(FromUnion(T.anyOf, K)) :
|
|
40
|
-
(0, kind_1.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties, K)) :
|
|
40
|
+
(0, kind_1.IsObject)(T) ? (0, index_3.Object)(FromProperties(T.properties, K), (0, index_5.Discard)(T, [index_6.TransformKind, '$id', 'required'])) :
|
|
41
41
|
(0, index_3.Object)({}));
|
|
42
42
|
}
|
|
43
43
|
function Pick(T, K, options) {
|
|
@@ -48,7 +48,5 @@ function Pick(T, K, options) {
|
|
|
48
48
|
return (0, pick_from_mapped_result_1.PickFromMappedResult)(T, K, options);
|
|
49
49
|
// non-mapped
|
|
50
50
|
const I = (0, kind_1.IsSchema)(K) ? (0, index_4.IndexPropertyKeys)(K) : K;
|
|
51
|
-
|
|
52
|
-
const R = PickResolve(T, I);
|
|
53
|
-
return (0, type_1.CreateType)({ ...D, ...R }, options);
|
|
51
|
+
return (0, type_1.CreateType)(PickResolve(T, I), options);
|
|
54
52
|
}
|
|
@@ -3,7 +3,7 @@ import { Immutable } from './immutable.mjs';
|
|
|
3
3
|
import { Clone } from '../clone/value.mjs';
|
|
4
4
|
/** Creates TypeBox schematics using the configured InstanceMode */
|
|
5
5
|
export function CreateType(schema, options) {
|
|
6
|
-
const result = options !== undefined ?
|
|
6
|
+
const result = options !== undefined ? { ...options, ...schema } : schema;
|
|
7
7
|
switch (TypeSystemPolicy.InstanceMode) {
|
|
8
8
|
case 'freeze':
|
|
9
9
|
return Immutable(result);
|
|
@@ -56,7 +56,7 @@ export function Intrinsic(schema, mode, options = {}) {
|
|
|
56
56
|
// Intrinsic-Mapped-Inference
|
|
57
57
|
IsMappedKey(schema) ? IntrinsicFromMappedKey(schema, mode, options) :
|
|
58
58
|
// Standard-Inference
|
|
59
|
-
IsTemplateLiteral(schema) ? FromTemplateLiteral(schema, mode,
|
|
59
|
+
IsTemplateLiteral(schema) ? FromTemplateLiteral(schema, mode, options) :
|
|
60
60
|
IsUnion(schema) ? Union(FromRest(schema.anyOf, mode), options) :
|
|
61
61
|
IsLiteral(schema) ? Literal(FromLiteralValue(schema.const, mode), options) :
|
|
62
62
|
// Default Type
|
|
@@ -64,6 +64,8 @@ function FromProperties(K, T) {
|
|
|
64
64
|
}
|
|
65
65
|
// prettier-ignore
|
|
66
66
|
function FromSchemaType(K, T) {
|
|
67
|
+
// required to retain user defined options for mapped type
|
|
68
|
+
const options = { ...T };
|
|
67
69
|
return (
|
|
68
70
|
// unevaluated modifier types
|
|
69
71
|
IsOptional(T) ? Optional(FromSchemaType(K, Discard(T, [OptionalKind]))) :
|
|
@@ -72,16 +74,16 @@ function FromSchemaType(K, T) {
|
|
|
72
74
|
IsMappedResult(T) ? FromMappedResult(K, T.properties) :
|
|
73
75
|
IsMappedKey(T) ? FromMappedKey(K, T.keys) :
|
|
74
76
|
// unevaluated types
|
|
75
|
-
IsConstructor(T) ? Constructor(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
|
|
76
|
-
IsFunction(T) ? FunctionType(FromRest(K, T.parameters), FromSchemaType(K, T.returns)) :
|
|
77
|
-
IsAsyncIterator(T) ? AsyncIterator(FromSchemaType(K, T.items)) :
|
|
78
|
-
IsIterator(T) ? Iterator(FromSchemaType(K, T.items)) :
|
|
79
|
-
IsIntersect(T) ? Intersect(FromRest(K, T.allOf)) :
|
|
80
|
-
IsUnion(T) ? Union(FromRest(K, T.anyOf)) :
|
|
81
|
-
IsTuple(T) ? Tuple(FromRest(K, T.items ?? [])) :
|
|
82
|
-
IsObject(T) ? Object(FromProperties(K, T.properties)) :
|
|
83
|
-
IsArray(T) ? Array(FromSchemaType(K, T.items)) :
|
|
84
|
-
IsPromise(T) ? Promise(FromSchemaType(K, T.item)) :
|
|
77
|
+
IsConstructor(T) ? Constructor(FromRest(K, T.parameters), FromSchemaType(K, T.returns), options) :
|
|
78
|
+
IsFunction(T) ? FunctionType(FromRest(K, T.parameters), FromSchemaType(K, T.returns), options) :
|
|
79
|
+
IsAsyncIterator(T) ? AsyncIterator(FromSchemaType(K, T.items), options) :
|
|
80
|
+
IsIterator(T) ? Iterator(FromSchemaType(K, T.items), options) :
|
|
81
|
+
IsIntersect(T) ? Intersect(FromRest(K, T.allOf), options) :
|
|
82
|
+
IsUnion(T) ? Union(FromRest(K, T.anyOf), options) :
|
|
83
|
+
IsTuple(T) ? Tuple(FromRest(K, T.items ?? []), options) :
|
|
84
|
+
IsObject(T) ? Object(FromProperties(K, T.properties), options) :
|
|
85
|
+
IsArray(T) ? Array(FromSchemaType(K, T.items), options) :
|
|
86
|
+
IsPromise(T) ? Promise(FromSchemaType(K, T.item), options) :
|
|
85
87
|
T);
|
|
86
88
|
}
|
|
87
89
|
// prettier-ignore
|
|
@@ -38,7 +38,7 @@ function FromProperties(T, K) {
|
|
|
38
38
|
function OmitResolve(T, K) {
|
|
39
39
|
return (IsIntersect(T) ? Intersect(FromIntersect(T.allOf, K)) :
|
|
40
40
|
IsUnion(T) ? Union(FromUnion(T.anyOf, K)) :
|
|
41
|
-
IsObject(T) ? Object(FromProperties(T.properties, K)) :
|
|
41
|
+
IsObject(T) ? Object(FromProperties(T.properties, K), Discard(T, [TransformKind, '$id', 'required'])) :
|
|
42
42
|
Object({}));
|
|
43
43
|
}
|
|
44
44
|
export function Omit(T, K, options) {
|
|
@@ -49,7 +49,5 @@ export function Omit(T, K, options) {
|
|
|
49
49
|
return OmitFromMappedResult(T, K, options);
|
|
50
50
|
// non-mapped
|
|
51
51
|
const I = IsSchema(K) ? IndexPropertyKeys(K) : K;
|
|
52
|
-
|
|
53
|
-
const R = OmitResolve(T, I);
|
|
54
|
-
return CreateType({ ...D, ...R }, options);
|
|
52
|
+
return CreateType(OmitResolve(T, I), options);
|
|
55
53
|
}
|
|
@@ -33,7 +33,7 @@ function FromProperties(T, K) {
|
|
|
33
33
|
function PickResolve(T, K) {
|
|
34
34
|
return (IsIntersect(T) ? Intersect(FromIntersect(T.allOf, K)) :
|
|
35
35
|
IsUnion(T) ? Union(FromUnion(T.anyOf, K)) :
|
|
36
|
-
IsObject(T) ? Object(FromProperties(T.properties, K)) :
|
|
36
|
+
IsObject(T) ? Object(FromProperties(T.properties, K), Discard(T, [TransformKind, '$id', 'required'])) :
|
|
37
37
|
Object({}));
|
|
38
38
|
}
|
|
39
39
|
export function Pick(T, K, options) {
|
|
@@ -44,7 +44,5 @@ export function Pick(T, K, options) {
|
|
|
44
44
|
return PickFromMappedResult(T, K, options);
|
|
45
45
|
// non-mapped
|
|
46
46
|
const I = IsSchema(K) ? IndexPropertyKeys(K) : K;
|
|
47
|
-
|
|
48
|
-
const R = PickResolve(T, I);
|
|
49
|
-
return CreateType({ ...D, ...R }, options);
|
|
47
|
+
return CreateType(PickResolve(T, I), options);
|
|
50
48
|
}
|