@sinclair/typebox 0.32.34 → 0.33.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/build/cjs/errors/function.js +1 -1
- package/build/cjs/index.d.ts +1 -0
- package/build/cjs/index.js +1 -0
- package/build/cjs/system/policy.d.ts +9 -1
- package/build/cjs/system/policy.js +13 -2
- package/build/cjs/type/any/any.js +4 -3
- package/build/cjs/type/array/array.d.ts +1 -1
- package/build/cjs/type/array/array.js +3 -8
- package/build/cjs/type/async-iterator/async-iterator.js +3 -8
- package/build/cjs/type/awaited/awaited.js +3 -3
- package/build/cjs/type/bigint/bigint.js +3 -6
- package/build/cjs/type/boolean/boolean.js +3 -6
- package/build/cjs/type/clone/type.d.ts +1 -1
- package/build/cjs/type/clone/type.js +2 -2
- package/build/cjs/type/composite/composite.js +1 -1
- package/build/cjs/type/const/const.js +3 -3
- package/build/cjs/type/constructor/constructor.js +2 -8
- package/build/cjs/type/constructor-parameters/constructor-parameters.js +2 -3
- package/build/cjs/type/create/immutable.d.ts +2 -0
- package/build/cjs/type/create/immutable.js +41 -0
- package/build/cjs/type/create/index.d.ts +1 -0
- package/build/cjs/type/create/index.js +18 -0
- package/build/cjs/type/create/type.d.ts +3 -0
- package/build/cjs/type/create/type.js +19 -0
- package/build/cjs/type/date/date.js +3 -6
- package/build/cjs/type/discard/discard.d.ts +1 -0
- package/build/cjs/type/discard/discard.js +1 -0
- package/build/cjs/type/enum/enum.js +1 -1
- package/build/cjs/type/exclude/exclude.js +4 -4
- package/build/cjs/type/extends/extends-from-mapped-key.d.ts +1 -1
- package/build/cjs/type/extends/extends-from-mapped-key.js +2 -1
- package/build/cjs/type/extends/extends-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/extends/extends-from-mapped-result.js +2 -1
- package/build/cjs/type/extends/extends.js +4 -4
- package/build/cjs/type/extract/extract.js +5 -5
- package/build/cjs/type/function/function.js +2 -8
- package/build/cjs/type/guard/value.js +3 -0
- package/build/cjs/type/indexed/indexed-from-mapped-key.d.ts +1 -1
- package/build/cjs/type/indexed/indexed-from-mapped-key.js +2 -1
- package/build/cjs/type/indexed/indexed-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/indexed/indexed.js +10 -6
- package/build/cjs/type/instance-type/instance-type.js +3 -3
- package/build/cjs/type/integer/integer.js +3 -6
- package/build/cjs/type/intersect/intersect-create.d.ts +1 -1
- package/build/cjs/type/intersect/intersect-create.js +6 -6
- package/build/cjs/type/intersect/intersect-evaluated.js +2 -2
- package/build/cjs/type/intersect/intersect.js +3 -3
- package/build/cjs/type/intrinsic/intrinsic-from-mapped-key.js +4 -2
- package/build/cjs/type/intrinsic/intrinsic.js +3 -1
- package/build/cjs/type/iterator/iterator.js +3 -8
- package/build/cjs/type/keyof/keyof-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/keyof/keyof-from-mapped-result.js +2 -1
- package/build/cjs/type/keyof/keyof.js +3 -3
- package/build/cjs/type/literal/literal.js +4 -4
- package/build/cjs/type/mapped/mapped-key.js +3 -2
- package/build/cjs/type/mapped/mapped-result.js +3 -2
- package/build/cjs/type/mapped/mapped.js +2 -3
- package/build/cjs/type/never/never.js +3 -6
- package/build/cjs/type/not/not.d.ts +1 -1
- package/build/cjs/type/not/not.js +3 -7
- package/build/cjs/type/null/null.js +3 -6
- package/build/cjs/type/number/number.js +3 -6
- package/build/cjs/type/object/object.js +13 -12
- package/build/cjs/type/omit/omit-from-mapped-key.d.ts +1 -1
- package/build/cjs/type/omit/omit-from-mapped-key.js +2 -1
- package/build/cjs/type/omit/omit-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/omit/omit-from-mapped-result.js +2 -1
- package/build/cjs/type/omit/omit.js +4 -4
- package/build/cjs/type/optional/optional.js +3 -3
- package/build/cjs/type/parameters/parameters.js +2 -3
- package/build/cjs/type/partial/partial-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/partial/partial-from-mapped-result.js +2 -1
- package/build/cjs/type/partial/partial.js +4 -4
- package/build/cjs/type/patterns/patterns.d.ts +2 -0
- package/build/cjs/type/patterns/patterns.js +3 -1
- package/build/cjs/type/pick/pick-from-mapped-key.d.ts +1 -1
- package/build/cjs/type/pick/pick-from-mapped-key.js +2 -1
- package/build/cjs/type/pick/pick-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/pick/pick-from-mapped-result.js +2 -1
- package/build/cjs/type/pick/pick.js +4 -4
- package/build/cjs/type/promise/promise.js +3 -8
- package/build/cjs/type/readonly/readonly.js +3 -3
- package/build/cjs/type/record/record.d.ts +4 -1
- package/build/cjs/type/record/record.js +16 -7
- package/build/cjs/type/recursive/recursive.js +3 -2
- package/build/cjs/type/ref/ref.js +4 -7
- package/build/cjs/type/regexp/regexp.js +3 -2
- package/build/cjs/type/required/required-from-mapped-result.d.ts +1 -1
- package/build/cjs/type/required/required.js +4 -4
- package/build/cjs/type/rest/rest.d.ts +1 -1
- package/build/cjs/type/rest/rest.js +4 -5
- package/build/cjs/type/return-type/return-type.js +3 -3
- package/build/cjs/type/string/string.js +3 -2
- package/build/cjs/type/symbol/symbol.js +2 -1
- package/build/cjs/type/template-literal/template-literal.js +3 -2
- package/build/cjs/type/transform/transform.js +1 -3
- package/build/cjs/type/tuple/tuple.js +5 -7
- package/build/cjs/type/type/javascript.js +13 -13
- package/build/cjs/type/type/json.js +35 -35
- package/build/cjs/type/uint8array/uint8array.js +3 -2
- package/build/cjs/type/undefined/undefined.js +3 -2
- package/build/cjs/type/union/union-create.d.ts +1 -1
- package/build/cjs/type/union/union-create.js +2 -2
- package/build/cjs/type/union/union-evaluated.js +3 -3
- package/build/cjs/type/union/union.js +3 -3
- package/build/cjs/type/unknown/unknown.js +3 -5
- package/build/cjs/type/unsafe/unsafe.js +2 -4
- package/build/cjs/type/void/void.js +3 -6
- package/build/cjs/value/convert/convert.js +3 -0
- package/build/esm/errors/function.mjs +1 -1
- package/build/esm/index.d.mts +1 -0
- package/build/esm/index.mjs +1 -0
- package/build/esm/system/policy.d.mts +9 -1
- package/build/esm/system/policy.mjs +13 -2
- package/build/esm/type/any/any.mjs +3 -2
- package/build/esm/type/array/array.d.mts +1 -1
- package/build/esm/type/array/array.mjs +3 -8
- package/build/esm/type/async-iterator/async-iterator.mjs +3 -8
- package/build/esm/type/awaited/awaited.mjs +3 -3
- package/build/esm/type/bigint/bigint.mjs +3 -6
- package/build/esm/type/boolean/boolean.mjs +3 -6
- package/build/esm/type/clone/type.d.mts +1 -1
- package/build/esm/type/clone/type.mjs +2 -2
- package/build/esm/type/composite/composite.mjs +1 -1
- package/build/esm/type/const/const.mjs +3 -3
- package/build/esm/type/constructor/constructor.mjs +2 -8
- package/build/esm/type/constructor-parameters/constructor-parameters.mjs +2 -3
- package/build/esm/type/create/immutable.d.mts +2 -0
- package/build/esm/type/create/immutable.mjs +37 -0
- package/build/esm/type/create/index.d.mts +1 -0
- package/build/esm/type/create/index.mjs +1 -0
- package/build/esm/type/create/type.d.mts +3 -0
- package/build/esm/type/create/type.mjs +15 -0
- package/build/esm/type/date/date.mjs +3 -6
- package/build/esm/type/discard/discard.d.mts +1 -0
- package/build/esm/type/discard/discard.mjs +1 -0
- package/build/esm/type/enum/enum.mjs +1 -1
- package/build/esm/type/exclude/exclude.mjs +4 -4
- package/build/esm/type/extends/extends-from-mapped-key.d.mts +1 -1
- package/build/esm/type/extends/extends-from-mapped-key.mjs +2 -1
- package/build/esm/type/extends/extends-from-mapped-result.d.mts +1 -1
- package/build/esm/type/extends/extends-from-mapped-result.mjs +2 -1
- package/build/esm/type/extends/extends.mjs +4 -4
- package/build/esm/type/extract/extract.mjs +5 -5
- package/build/esm/type/function/function.mjs +2 -8
- package/build/esm/type/guard/value.mjs +3 -0
- package/build/esm/type/indexed/indexed-from-mapped-key.d.mts +1 -1
- package/build/esm/type/indexed/indexed-from-mapped-key.mjs +2 -1
- package/build/esm/type/indexed/indexed-from-mapped-result.d.mts +1 -1
- package/build/esm/type/indexed/indexed.mjs +10 -6
- package/build/esm/type/instance-type/instance-type.mjs +3 -3
- package/build/esm/type/integer/integer.mjs +3 -6
- package/build/esm/type/intersect/intersect-create.d.mts +1 -1
- package/build/esm/type/intersect/intersect-create.mjs +6 -6
- package/build/esm/type/intersect/intersect-evaluated.mjs +2 -2
- package/build/esm/type/intersect/intersect.mjs +3 -3
- package/build/esm/type/intrinsic/intrinsic-from-mapped-key.mjs +4 -2
- package/build/esm/type/intrinsic/intrinsic.mjs +3 -1
- package/build/esm/type/iterator/iterator.mjs +3 -8
- package/build/esm/type/keyof/keyof-from-mapped-result.d.mts +1 -1
- package/build/esm/type/keyof/keyof-from-mapped-result.mjs +2 -1
- package/build/esm/type/keyof/keyof.mjs +3 -3
- package/build/esm/type/literal/literal.mjs +4 -4
- package/build/esm/type/mapped/mapped-key.mjs +3 -2
- package/build/esm/type/mapped/mapped-result.mjs +3 -2
- package/build/esm/type/mapped/mapped.mjs +2 -3
- package/build/esm/type/never/never.mjs +3 -6
- package/build/esm/type/not/not.d.mts +1 -1
- package/build/esm/type/not/not.mjs +3 -7
- package/build/esm/type/null/null.mjs +3 -6
- package/build/esm/type/number/number.mjs +3 -6
- package/build/esm/type/object/object.mjs +14 -13
- package/build/esm/type/omit/omit-from-mapped-key.d.mts +1 -1
- package/build/esm/type/omit/omit-from-mapped-key.mjs +2 -1
- package/build/esm/type/omit/omit-from-mapped-result.d.mts +1 -1
- package/build/esm/type/omit/omit-from-mapped-result.mjs +2 -1
- package/build/esm/type/omit/omit.mjs +4 -4
- package/build/esm/type/optional/optional.mjs +3 -3
- package/build/esm/type/parameters/parameters.mjs +2 -3
- package/build/esm/type/partial/partial-from-mapped-result.d.mts +1 -1
- package/build/esm/type/partial/partial-from-mapped-result.mjs +2 -1
- package/build/esm/type/partial/partial.mjs +4 -4
- package/build/esm/type/patterns/patterns.d.mts +2 -0
- package/build/esm/type/patterns/patterns.mjs +2 -0
- package/build/esm/type/pick/pick-from-mapped-key.d.mts +1 -1
- package/build/esm/type/pick/pick-from-mapped-key.mjs +2 -1
- package/build/esm/type/pick/pick-from-mapped-result.d.mts +1 -1
- package/build/esm/type/pick/pick-from-mapped-result.mjs +2 -1
- package/build/esm/type/pick/pick.mjs +4 -4
- package/build/esm/type/promise/promise.mjs +3 -8
- package/build/esm/type/readonly/readonly.mjs +3 -3
- package/build/esm/type/record/record.d.mts +4 -1
- package/build/esm/type/record/record.mjs +18 -9
- package/build/esm/type/recursive/recursive.mjs +3 -2
- package/build/esm/type/ref/ref.mjs +4 -7
- package/build/esm/type/regexp/regexp.mjs +3 -2
- package/build/esm/type/required/required-from-mapped-result.d.mts +1 -1
- package/build/esm/type/required/required.mjs +4 -4
- package/build/esm/type/rest/rest.d.mts +1 -1
- package/build/esm/type/rest/rest.mjs +4 -5
- package/build/esm/type/return-type/return-type.mjs +3 -3
- package/build/esm/type/string/string.mjs +3 -2
- package/build/esm/type/symbol/symbol.mjs +2 -1
- package/build/esm/type/template-literal/template-literal.mjs +3 -2
- package/build/esm/type/transform/transform.mjs +1 -3
- package/build/esm/type/tuple/tuple.mjs +5 -7
- package/build/esm/type/type/javascript.mjs +13 -13
- package/build/esm/type/type/json.mjs +35 -35
- package/build/esm/type/uint8array/uint8array.mjs +3 -2
- package/build/esm/type/undefined/undefined.mjs +3 -2
- package/build/esm/type/union/union-create.d.mts +1 -1
- package/build/esm/type/union/union-create.mjs +2 -2
- package/build/esm/type/union/union-evaluated.mjs +3 -3
- package/build/esm/type/union/union.mjs +3 -3
- package/build/esm/type/unknown/unknown.mjs +3 -5
- package/build/esm/type/unsafe/unsafe.mjs +2 -4
- package/build/esm/type/void/void.mjs +3 -6
- package/build/esm/value/convert/convert.mjs +3 -0
- package/package.json +1 -1
|
@@ -71,19 +71,19 @@ class JsonTypeBuilder {
|
|
|
71
71
|
// Types
|
|
72
72
|
// ------------------------------------------------------------------------
|
|
73
73
|
/** `[Json]` Creates an Any type */
|
|
74
|
-
Any(options
|
|
74
|
+
Any(options) {
|
|
75
75
|
return (0, index_1.Any)(options);
|
|
76
76
|
}
|
|
77
77
|
/** `[Json]` Creates an Array type */
|
|
78
|
-
Array(schema, options
|
|
78
|
+
Array(schema, options) {
|
|
79
79
|
return (0, index_2.Array)(schema, options);
|
|
80
80
|
}
|
|
81
81
|
/** `[Json]` Creates a Boolean type */
|
|
82
|
-
Boolean(options
|
|
82
|
+
Boolean(options) {
|
|
83
83
|
return (0, index_3.Boolean)(options);
|
|
84
84
|
}
|
|
85
85
|
/** `[Json]` Intrinsic function to Capitalize LiteralString types */
|
|
86
|
-
Capitalize(schema, options
|
|
86
|
+
Capitalize(schema, options) {
|
|
87
87
|
return (0, index_14.Capitalize)(schema, options);
|
|
88
88
|
}
|
|
89
89
|
/** `[Json]` Creates a Composite object type */
|
|
@@ -91,7 +91,7 @@ class JsonTypeBuilder {
|
|
|
91
91
|
return (0, index_4.Composite)(schemas, options); // (error) TS 5.4.0-dev - review TComposite implementation
|
|
92
92
|
}
|
|
93
93
|
/** `[JavaScript]` Creates a readonly const type from the given value. */
|
|
94
|
-
Const(value, options
|
|
94
|
+
Const(value, options) {
|
|
95
95
|
return (0, index_5.Const)(value, options);
|
|
96
96
|
}
|
|
97
97
|
/** `[Json]` Creates a dereferenced type */
|
|
@@ -99,51 +99,51 @@ class JsonTypeBuilder {
|
|
|
99
99
|
return (0, index_6.Deref)(schema, references);
|
|
100
100
|
}
|
|
101
101
|
/** `[Json]` Creates a Enum type */
|
|
102
|
-
Enum(item, options
|
|
102
|
+
Enum(item, options) {
|
|
103
103
|
return (0, index_7.Enum)(item, options);
|
|
104
104
|
}
|
|
105
105
|
/** `[Json]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */
|
|
106
|
-
Exclude(unionType, excludedMembers, options
|
|
106
|
+
Exclude(unionType, excludedMembers, options) {
|
|
107
107
|
return (0, index_8.Exclude)(unionType, excludedMembers, options);
|
|
108
108
|
}
|
|
109
109
|
/** `[Json]` Creates a Conditional type */
|
|
110
|
-
Extends(L, R, T, F, options
|
|
110
|
+
Extends(L, R, T, F, options) {
|
|
111
111
|
return (0, index_9.Extends)(L, R, T, F, options);
|
|
112
112
|
}
|
|
113
113
|
/** `[Json]` Constructs a type by extracting from type all union members that are assignable to union */
|
|
114
|
-
Extract(type, union, options
|
|
114
|
+
Extract(type, union, options) {
|
|
115
115
|
return (0, index_10.Extract)(type, union, options);
|
|
116
116
|
}
|
|
117
117
|
/** `[Json]` Returns an Indexed property type for the given keys */
|
|
118
|
-
Index(schema, unresolved, options
|
|
118
|
+
Index(schema, unresolved, options) {
|
|
119
119
|
return (0, index_11.Index)(schema, unresolved, options);
|
|
120
120
|
}
|
|
121
121
|
/** `[Json]` Creates an Integer type */
|
|
122
|
-
Integer(options
|
|
122
|
+
Integer(options) {
|
|
123
123
|
return (0, index_12.Integer)(options);
|
|
124
124
|
}
|
|
125
125
|
/** `[Json]` Creates an Intersect type */
|
|
126
|
-
Intersect(T, options
|
|
126
|
+
Intersect(T, options) {
|
|
127
127
|
return (0, index_13.Intersect)(T, options);
|
|
128
128
|
}
|
|
129
129
|
/** `[Json]` Creates a KeyOf type */
|
|
130
|
-
KeyOf(schema, options
|
|
130
|
+
KeyOf(schema, options) {
|
|
131
131
|
return (0, index_15.KeyOf)(schema, options);
|
|
132
132
|
}
|
|
133
133
|
/** `[Json]` Creates a Literal type */
|
|
134
|
-
Literal(value, options
|
|
134
|
+
Literal(value, options) {
|
|
135
135
|
return (0, index_16.Literal)(value, options);
|
|
136
136
|
}
|
|
137
137
|
/** `[Json]` Intrinsic function to Lowercase LiteralString types */
|
|
138
|
-
Lowercase(schema, options
|
|
138
|
+
Lowercase(schema, options) {
|
|
139
139
|
return (0, index_14.Lowercase)(schema, options);
|
|
140
140
|
}
|
|
141
141
|
/** `[Json]` Creates a Mapped object type */
|
|
142
|
-
Mapped(key, map, options
|
|
142
|
+
Mapped(key, map, options) {
|
|
143
143
|
return (0, index_17.Mapped)(key, map, options);
|
|
144
144
|
}
|
|
145
145
|
/** `[Json]` Creates a Never type */
|
|
146
|
-
Never(options
|
|
146
|
+
Never(options) {
|
|
147
147
|
return (0, index_18.Never)(options);
|
|
148
148
|
}
|
|
149
149
|
/** `[Json]` Creates a Not type */
|
|
@@ -151,43 +151,43 @@ class JsonTypeBuilder {
|
|
|
151
151
|
return (0, index_19.Not)(schema, options);
|
|
152
152
|
}
|
|
153
153
|
/** `[Json]` Creates a Null type */
|
|
154
|
-
Null(options
|
|
154
|
+
Null(options) {
|
|
155
155
|
return (0, index_20.Null)(options);
|
|
156
156
|
}
|
|
157
157
|
/** `[Json]` Creates a Number type */
|
|
158
|
-
Number(options
|
|
158
|
+
Number(options) {
|
|
159
159
|
return (0, index_21.Number)(options);
|
|
160
160
|
}
|
|
161
161
|
/** `[Json]` Creates an Object type */
|
|
162
|
-
Object(properties, options
|
|
162
|
+
Object(properties, options) {
|
|
163
163
|
return (0, index_22.Object)(properties, options);
|
|
164
164
|
}
|
|
165
165
|
/** `[Json]` Constructs a type whose keys are omitted from the given type */
|
|
166
|
-
Omit(schema, unresolved, options
|
|
166
|
+
Omit(schema, unresolved, options) {
|
|
167
167
|
return (0, index_23.Omit)(schema, unresolved, options);
|
|
168
168
|
}
|
|
169
169
|
/** `[Json]` Constructs a type where all properties are optional */
|
|
170
|
-
Partial(schema, options
|
|
170
|
+
Partial(schema, options) {
|
|
171
171
|
return (0, index_25.Partial)(schema, options);
|
|
172
172
|
}
|
|
173
173
|
/** `[Json]` Constructs a type whose keys are picked from the given type */
|
|
174
|
-
Pick(schema, unresolved, options
|
|
174
|
+
Pick(schema, unresolved, options) {
|
|
175
175
|
return (0, index_26.Pick)(schema, unresolved, options);
|
|
176
176
|
}
|
|
177
177
|
/** `[Json]` Creates a Record type */
|
|
178
|
-
Record(key, schema, options
|
|
178
|
+
Record(key, schema, options) {
|
|
179
179
|
return (0, index_29.Record)(key, schema, options);
|
|
180
180
|
}
|
|
181
181
|
/** `[Json]` Creates a Recursive type */
|
|
182
|
-
Recursive(callback, options
|
|
182
|
+
Recursive(callback, options) {
|
|
183
183
|
return (0, index_30.Recursive)(callback, options);
|
|
184
184
|
}
|
|
185
185
|
/** `[Json]` Creates a Ref type. */
|
|
186
|
-
Ref(unresolved, options
|
|
186
|
+
Ref(unresolved, options) {
|
|
187
187
|
return (0, index_31.Ref)(unresolved, options);
|
|
188
188
|
}
|
|
189
189
|
/** `[Json]` Constructs a type where all properties are required */
|
|
190
|
-
Required(schema, options
|
|
190
|
+
Required(schema, options) {
|
|
191
191
|
return (0, index_32.Required)(schema, options);
|
|
192
192
|
}
|
|
193
193
|
/** `[Json]` Extracts interior Rest elements from Tuple, Intersect and Union types */
|
|
@@ -195,11 +195,11 @@ class JsonTypeBuilder {
|
|
|
195
195
|
return (0, index_33.Rest)(schema);
|
|
196
196
|
}
|
|
197
197
|
/** `[Json]` Creates a String type */
|
|
198
|
-
String(options
|
|
198
|
+
String(options) {
|
|
199
199
|
return (0, index_35.String)(options);
|
|
200
200
|
}
|
|
201
201
|
/** `[Json]` Creates a TemplateLiteral type */
|
|
202
|
-
TemplateLiteral(unresolved, options
|
|
202
|
+
TemplateLiteral(unresolved, options) {
|
|
203
203
|
return (0, index_36.TemplateLiteral)(unresolved, options);
|
|
204
204
|
}
|
|
205
205
|
/** `[Json]` Creates a Transform type */
|
|
@@ -207,27 +207,27 @@ class JsonTypeBuilder {
|
|
|
207
207
|
return (0, index_37.Transform)(schema);
|
|
208
208
|
}
|
|
209
209
|
/** `[Json]` Creates a Tuple type */
|
|
210
|
-
Tuple(items, options
|
|
210
|
+
Tuple(items, options) {
|
|
211
211
|
return (0, index_38.Tuple)(items, options);
|
|
212
212
|
}
|
|
213
213
|
/** `[Json]` Intrinsic function to Uncapitalize LiteralString types */
|
|
214
|
-
Uncapitalize(schema, options
|
|
214
|
+
Uncapitalize(schema, options) {
|
|
215
215
|
return (0, index_14.Uncapitalize)(schema, options);
|
|
216
216
|
}
|
|
217
217
|
/** `[Json]` Creates a Union type */
|
|
218
|
-
Union(schemas, options
|
|
218
|
+
Union(schemas, options) {
|
|
219
219
|
return (0, index_39.Union)(schemas, options);
|
|
220
220
|
}
|
|
221
221
|
/** `[Json]` Creates an Unknown type */
|
|
222
|
-
Unknown(options
|
|
222
|
+
Unknown(options) {
|
|
223
223
|
return (0, index_40.Unknown)(options);
|
|
224
224
|
}
|
|
225
225
|
/** `[Json]` Creates a Unsafe type that will infers as the generic argument T */
|
|
226
|
-
Unsafe(options
|
|
226
|
+
Unsafe(options) {
|
|
227
227
|
return (0, index_41.Unsafe)(options);
|
|
228
228
|
}
|
|
229
229
|
/** `[Json]` Intrinsic function to Uppercase LiteralString types */
|
|
230
|
-
Uppercase(schema, options
|
|
230
|
+
Uppercase(schema, options) {
|
|
231
231
|
return (0, index_14.Uppercase)(schema, options);
|
|
232
232
|
}
|
|
233
233
|
}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Uint8Array = Uint8Array;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const index_1 = require("../symbols/index");
|
|
6
7
|
/** `[JavaScript]` Creates a Uint8Array type */
|
|
7
|
-
function Uint8Array(options
|
|
8
|
-
return {
|
|
8
|
+
function Uint8Array(options) {
|
|
9
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'Uint8Array', type: 'Uint8Array' }, options);
|
|
9
10
|
}
|
|
@@ -2,8 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Undefined = Undefined;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const index_1 = require("../symbols/index");
|
|
6
7
|
/** `[JavaScript]` Creates a Undefined type */
|
|
7
|
-
function Undefined(options
|
|
8
|
-
return {
|
|
8
|
+
function Undefined(options) {
|
|
9
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'Undefined', type: 'undefined' }, options);
|
|
9
10
|
}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import type { TSchema, SchemaOptions } from '../schema/index';
|
|
2
2
|
import { TUnion } from './union-type';
|
|
3
|
-
export declare function UnionCreate<T extends TSchema[]>(T: [...T], options
|
|
3
|
+
export declare function UnionCreate<T extends TSchema[]>(T: [...T], options?: SchemaOptions): TUnion<T>;
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.UnionCreate = UnionCreate;
|
|
5
|
-
const type_1 = require("../
|
|
5
|
+
const type_1 = require("../create/type");
|
|
6
6
|
const index_1 = require("../symbols/index");
|
|
7
7
|
function UnionCreate(T, options) {
|
|
8
|
-
return {
|
|
8
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'Union', anyOf: T }, options);
|
|
9
9
|
}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.UnionEvaluated = UnionEvaluated;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const index_1 = require("../symbols/index");
|
|
6
|
-
const type_1 = require("../clone/type");
|
|
7
7
|
const index_2 = require("../discard/index");
|
|
8
8
|
const index_3 = require("../never/index");
|
|
9
9
|
const index_4 = require("../optional/index");
|
|
@@ -31,9 +31,9 @@ function ResolveUnion(T, options) {
|
|
|
31
31
|
: (0, union_create_1.UnionCreate)(RemoveOptionalFromRest(T), options));
|
|
32
32
|
}
|
|
33
33
|
/** `[Json]` Creates an evaluated Union type */
|
|
34
|
-
function UnionEvaluated(T, options
|
|
34
|
+
function UnionEvaluated(T, options) {
|
|
35
35
|
// prettier-ignore
|
|
36
36
|
return (T.length === 0 ? (0, index_3.Never)(options) :
|
|
37
|
-
T.length === 1 ? (0, type_1.
|
|
37
|
+
T.length === 1 ? (0, type_1.CreateType)(T[0], options) :
|
|
38
38
|
ResolveUnion(T, options));
|
|
39
39
|
}
|
|
@@ -3,12 +3,12 @@
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Union = Union;
|
|
5
5
|
const index_1 = require("../never/index");
|
|
6
|
-
const type_1 = require("../
|
|
6
|
+
const type_1 = require("../create/type");
|
|
7
7
|
const union_create_1 = require("./union-create");
|
|
8
8
|
/** `[Json]` Creates a Union type */
|
|
9
|
-
function Union(T, options
|
|
9
|
+
function Union(T, options) {
|
|
10
10
|
// prettier-ignore
|
|
11
11
|
return (T.length === 0 ? (0, index_1.Never)(options) :
|
|
12
|
-
T.length === 1 ? (0, type_1.
|
|
12
|
+
T.length === 1 ? (0, type_1.CreateType)(T[0], options) :
|
|
13
13
|
(0, union_create_1.UnionCreate)(T, options));
|
|
14
14
|
}
|
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Unknown = Unknown;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const index_1 = require("../symbols/index");
|
|
6
7
|
/** `[Json]` Creates an Unknown type */
|
|
7
|
-
function Unknown(options
|
|
8
|
-
return {
|
|
9
|
-
...options,
|
|
10
|
-
[index_1.Kind]: 'Unknown',
|
|
11
|
-
};
|
|
8
|
+
function Unknown(options) {
|
|
9
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'Unknown' }, options);
|
|
12
10
|
}
|
|
@@ -2,11 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Unsafe = Unsafe;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const index_1 = require("../symbols/index");
|
|
6
7
|
/** `[Json]` Creates a Unsafe type that will infers as the generic argument T */
|
|
7
8
|
function Unsafe(options = {}) {
|
|
8
|
-
return {
|
|
9
|
-
...options,
|
|
10
|
-
[index_1.Kind]: options[index_1.Kind] ?? 'Unsafe',
|
|
11
|
-
};
|
|
9
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: options[index_1.Kind] ?? 'Unsafe' }, options);
|
|
12
10
|
}
|
|
@@ -2,12 +2,9 @@
|
|
|
2
2
|
|
|
3
3
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
4
4
|
exports.Void = Void;
|
|
5
|
+
const type_1 = require("../create/type");
|
|
5
6
|
const index_1 = require("../symbols/index");
|
|
6
7
|
/** `[JavaScript]` Creates a Void type */
|
|
7
|
-
function Void(options
|
|
8
|
-
return {
|
|
9
|
-
...options,
|
|
10
|
-
[index_1.Kind]: 'Void',
|
|
11
|
-
type: 'void',
|
|
12
|
-
};
|
|
8
|
+
function Void(options) {
|
|
9
|
+
return (0, type_1.CreateType)({ [index_1.Kind]: 'Void', type: 'void' }, options);
|
|
13
10
|
}
|
|
@@ -155,6 +155,9 @@ function FromObject(schema, references, value) {
|
|
|
155
155
|
return result;
|
|
156
156
|
}
|
|
157
157
|
function FromRecord(schema, references, value) {
|
|
158
|
+
const isConvertable = (0, index_5.IsObject)(value);
|
|
159
|
+
if (!isConvertable)
|
|
160
|
+
return value;
|
|
158
161
|
const propertyKey = Object.getOwnPropertyNames(schema.patternProperties)[0];
|
|
159
162
|
const property = schema.patternProperties[propertyKey];
|
|
160
163
|
const result = {};
|
|
@@ -94,7 +94,7 @@ export function DefaultErrorFunction(error) {
|
|
|
94
94
|
case ValueErrorType.ObjectMinProperties:
|
|
95
95
|
return `Expected object to have at least ${error.schema.minProperties} properties`;
|
|
96
96
|
case ValueErrorType.ObjectRequiredProperty:
|
|
97
|
-
return '
|
|
97
|
+
return 'Expected required property';
|
|
98
98
|
case ValueErrorType.Promise:
|
|
99
99
|
return 'Expected Promise';
|
|
100
100
|
case ValueErrorType.RegExp:
|
package/build/esm/index.d.mts
CHANGED
package/build/esm/index.mjs
CHANGED
|
@@ -2,6 +2,7 @@
|
|
|
2
2
|
// Infrastructure
|
|
3
3
|
// ------------------------------------------------------------------
|
|
4
4
|
export * from './type/clone/index.mjs';
|
|
5
|
+
export * from './type/create/index.mjs';
|
|
5
6
|
export * from './type/error/index.mjs';
|
|
6
7
|
export * from './type/guard/index.mjs';
|
|
7
8
|
export * from './type/helpers/index.mjs';
|
|
@@ -1,5 +1,13 @@
|
|
|
1
1
|
export declare namespace TypeSystemPolicy {
|
|
2
|
-
/**
|
|
2
|
+
/**
|
|
3
|
+
* Configures the instantiation behavior of TypeBox types. The `default` option assigns raw JavaScript
|
|
4
|
+
* references for embedded types, which may cause side effects if type properties are explicitly updated
|
|
5
|
+
* outside the TypeBox type builder. The `clone` option creates copies of any shared types upon creation,
|
|
6
|
+
* preventing unintended side effects. The `freeze` option applies `Object.freeze()` to the type, making
|
|
7
|
+
* it fully readonly and immutable. Implementations should use `default` whenever possible, as it is the
|
|
8
|
+
* fastest way to instantiate types. The default setting is `default`.
|
|
9
|
+
*/
|
|
10
|
+
let InstanceMode: 'default' | 'clone' | 'freeze';
|
|
3
11
|
/** Sets whether TypeBox should assert optional properties using the TypeScript `exactOptionalPropertyTypes` assertion policy. The default is `false` */
|
|
4
12
|
let ExactOptionalPropertyTypes: boolean;
|
|
5
13
|
/** Sets whether arrays should be treated as a kind of objects. The default is `false` */
|
|
@@ -2,9 +2,20 @@ import { IsObject, IsArray, IsNumber, IsUndefined } from '../value/guard/index.m
|
|
|
2
2
|
export var TypeSystemPolicy;
|
|
3
3
|
(function (TypeSystemPolicy) {
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
|
-
// TypeSystemPolicy
|
|
5
|
+
// TypeSystemPolicy: Instancing
|
|
6
|
+
// ------------------------------------------------------------------
|
|
7
|
+
/**
|
|
8
|
+
* Configures the instantiation behavior of TypeBox types. The `default` option assigns raw JavaScript
|
|
9
|
+
* references for embedded types, which may cause side effects if type properties are explicitly updated
|
|
10
|
+
* outside the TypeBox type builder. The `clone` option creates copies of any shared types upon creation,
|
|
11
|
+
* preventing unintended side effects. The `freeze` option applies `Object.freeze()` to the type, making
|
|
12
|
+
* it fully readonly and immutable. Implementations should use `default` whenever possible, as it is the
|
|
13
|
+
* fastest way to instantiate types. The default setting is `default`.
|
|
14
|
+
*/
|
|
15
|
+
TypeSystemPolicy.InstanceMode = 'default';
|
|
16
|
+
// ------------------------------------------------------------------
|
|
17
|
+
// TypeSystemPolicy: Checking
|
|
6
18
|
// ------------------------------------------------------------------
|
|
7
|
-
/** Shared assertion routines used by the value and errors modules */
|
|
8
19
|
/** Sets whether TypeBox should assert optional properties using the TypeScript `exactOptionalPropertyTypes` assertion policy. The default is `false` */
|
|
9
20
|
TypeSystemPolicy.ExactOptionalPropertyTypes = false;
|
|
10
21
|
/** Sets whether arrays should be treated as a kind of objects. The default is `false` */
|
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import { CreateType } from '../create/index.mjs';
|
|
1
2
|
import { Kind } from '../symbols/index.mjs';
|
|
2
3
|
/** `[Json]` Creates an Any type */
|
|
3
|
-
export function Any(options
|
|
4
|
-
return {
|
|
4
|
+
export function Any(options) {
|
|
5
|
+
return CreateType({ [Kind]: 'Any' }, options);
|
|
5
6
|
}
|
|
@@ -24,5 +24,5 @@ export interface TArray<T extends TSchema = TSchema> extends TSchema, ArrayOptio
|
|
|
24
24
|
items: T;
|
|
25
25
|
}
|
|
26
26
|
/** `[Json]` Creates an Array type */
|
|
27
|
-
export declare function Array<T extends TSchema>(
|
|
27
|
+
export declare function Array<T extends TSchema>(items: T, options?: ArrayOptions): TArray<T>;
|
|
28
28
|
export {};
|
|
@@ -1,11 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
2
2
|
import { Kind } from '../symbols/index.mjs';
|
|
3
3
|
/** `[Json]` Creates an Array type */
|
|
4
|
-
export function Array(
|
|
5
|
-
return {
|
|
6
|
-
...options,
|
|
7
|
-
[Kind]: 'Array',
|
|
8
|
-
type: 'array',
|
|
9
|
-
items: CloneType(schema),
|
|
10
|
-
};
|
|
4
|
+
export function Array(items, options) {
|
|
5
|
+
return CreateType({ [Kind]: 'Array', type: 'array', items }, options);
|
|
11
6
|
}
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import { Kind } from '../symbols/index.mjs';
|
|
2
|
-
import {
|
|
2
|
+
import { CreateType } from '../create/type.mjs';
|
|
3
3
|
/** `[JavaScript]` Creates a AsyncIterator type */
|
|
4
|
-
export function AsyncIterator(items, options
|
|
5
|
-
return {
|
|
6
|
-
...options,
|
|
7
|
-
[Kind]: 'AsyncIterator',
|
|
8
|
-
type: 'AsyncIterator',
|
|
9
|
-
items: CloneType(items),
|
|
10
|
-
};
|
|
4
|
+
export function AsyncIterator(items, options) {
|
|
5
|
+
return CreateType({ [Kind]: 'AsyncIterator', type: 'AsyncIterator', items }, options);
|
|
11
6
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { Intersect } from '../intersect/index.mjs';
|
|
2
2
|
import { Union } from '../union/index.mjs';
|
|
3
|
-
import {
|
|
3
|
+
import { CreateType } from '../create/type.mjs';
|
|
4
4
|
// ------------------------------------------------------------------
|
|
5
5
|
// TypeGuard
|
|
6
6
|
// ------------------------------------------------------------------
|
|
@@ -32,6 +32,6 @@ function AwaitedResolve(T) {
|
|
|
32
32
|
T);
|
|
33
33
|
}
|
|
34
34
|
/** `[JavaScript]` Constructs a type by recursively unwrapping Promise types */
|
|
35
|
-
export function Awaited(T, options
|
|
36
|
-
return
|
|
35
|
+
export function Awaited(T, options) {
|
|
36
|
+
return CreateType(AwaitedResolve(T), options);
|
|
37
37
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { Kind } from '../symbols/index.mjs';
|
|
2
|
+
import { CreateType } from '../create/index.mjs';
|
|
2
3
|
/** `[JavaScript]` Creates a BigInt type */
|
|
3
|
-
export function BigInt(options
|
|
4
|
-
return {
|
|
5
|
-
...options,
|
|
6
|
-
[Kind]: 'BigInt',
|
|
7
|
-
type: 'bigint',
|
|
8
|
-
};
|
|
4
|
+
export function BigInt(options) {
|
|
5
|
+
return CreateType({ [Kind]: 'BigInt', type: 'bigint' }, options);
|
|
9
6
|
}
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import { Kind } from '../symbols/index.mjs';
|
|
2
|
+
import { CreateType } from '../create/index.mjs';
|
|
2
3
|
/** `[Json]` Creates a Boolean type */
|
|
3
|
-
export function Boolean(options
|
|
4
|
-
return {
|
|
5
|
-
...options,
|
|
6
|
-
[Kind]: 'Boolean',
|
|
7
|
-
type: 'boolean',
|
|
8
|
-
};
|
|
4
|
+
export function Boolean(options) {
|
|
5
|
+
return CreateType({ [Kind]: 'Boolean', type: 'boolean' }, options);
|
|
9
6
|
}
|
|
@@ -4,6 +4,6 @@ export function CloneRest(schemas) {
|
|
|
4
4
|
return schemas.map((schema) => CloneType(schema));
|
|
5
5
|
}
|
|
6
6
|
/** Clones a Type */
|
|
7
|
-
export function CloneType(schema, options
|
|
8
|
-
return
|
|
7
|
+
export function CloneType(schema, options) {
|
|
8
|
+
return options === undefined ? Clone(schema) : Clone({ ...options, ...schema });
|
|
9
9
|
}
|
|
@@ -34,7 +34,7 @@ function CompositeProperties(T, K) {
|
|
|
34
34
|
return Acc;
|
|
35
35
|
}
|
|
36
36
|
// prettier-ignore
|
|
37
|
-
export function Composite(T, options
|
|
37
|
+
export function Composite(T, options) {
|
|
38
38
|
const K = CompositeKeys(T);
|
|
39
39
|
const P = CompositeProperties(T, K);
|
|
40
40
|
const R = Object(P, options);
|
|
@@ -11,7 +11,7 @@ import { Readonly } from '../readonly/index.mjs';
|
|
|
11
11
|
import { Undefined } from '../undefined/index.mjs';
|
|
12
12
|
import { Uint8Array } from '../uint8array/index.mjs';
|
|
13
13
|
import { Unknown } from '../unknown/index.mjs';
|
|
14
|
-
import {
|
|
14
|
+
import { CreateType } from '../create/index.mjs';
|
|
15
15
|
// ------------------------------------------------------------------
|
|
16
16
|
// ValueGuard
|
|
17
17
|
// ------------------------------------------------------------------
|
|
@@ -49,6 +49,6 @@ function FromValue(value, root) {
|
|
|
49
49
|
Object({}));
|
|
50
50
|
}
|
|
51
51
|
/** `[JavaScript]` Creates a readonly const type from the given value. */
|
|
52
|
-
export function Const(T, options
|
|
53
|
-
return
|
|
52
|
+
export function Const(T, options) {
|
|
53
|
+
return CreateType(FromValue(T, true), options);
|
|
54
54
|
}
|
|
@@ -1,12 +1,6 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { CreateType } from '../create/type.mjs';
|
|
2
2
|
import { Kind } from '../symbols/index.mjs';
|
|
3
3
|
/** `[JavaScript]` Creates a Constructor type */
|
|
4
4
|
export function Constructor(parameters, returns, options) {
|
|
5
|
-
return {
|
|
6
|
-
...options,
|
|
7
|
-
[Kind]: 'Constructor',
|
|
8
|
-
type: 'Constructor',
|
|
9
|
-
parameters: CloneRest(parameters),
|
|
10
|
-
returns: CloneType(returns),
|
|
11
|
-
};
|
|
5
|
+
return CreateType({ [Kind]: 'Constructor', type: 'Constructor', parameters, returns }, options);
|
|
12
6
|
}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { Tuple } from '../tuple/index.mjs';
|
|
2
|
-
import { CloneRest } from '../clone/type.mjs';
|
|
3
2
|
/** `[JavaScript]` Extracts the ConstructorParameters from the given Constructor type */
|
|
4
|
-
export function ConstructorParameters(schema, options
|
|
5
|
-
return Tuple(
|
|
3
|
+
export function ConstructorParameters(schema, options) {
|
|
4
|
+
return Tuple(schema.parameters, options);
|
|
6
5
|
}
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import * as ValueGuard from '../guard/value.mjs';
|
|
2
|
+
function ImmutableArray(value) {
|
|
3
|
+
return globalThis.Object.freeze(value).map((value) => Immutable(value));
|
|
4
|
+
}
|
|
5
|
+
function ImmutableDate(value) {
|
|
6
|
+
return value;
|
|
7
|
+
}
|
|
8
|
+
function ImmutableUint8Array(value) {
|
|
9
|
+
return value;
|
|
10
|
+
}
|
|
11
|
+
function ImmutableRegExp(value) {
|
|
12
|
+
return value;
|
|
13
|
+
}
|
|
14
|
+
function ImmutableObject(value) {
|
|
15
|
+
const result = {};
|
|
16
|
+
for (const key of Object.getOwnPropertyNames(value)) {
|
|
17
|
+
result[key] = Immutable(value[key]);
|
|
18
|
+
}
|
|
19
|
+
for (const key of Object.getOwnPropertySymbols(value)) {
|
|
20
|
+
result[key] = Immutable(value[key]);
|
|
21
|
+
}
|
|
22
|
+
return globalThis.Object.freeze(result);
|
|
23
|
+
}
|
|
24
|
+
/** Specialized deep immutable value. Applies freeze recursively to the given value */
|
|
25
|
+
export function Immutable(value) {
|
|
26
|
+
return ValueGuard.IsArray(value)
|
|
27
|
+
? ImmutableArray(value)
|
|
28
|
+
: ValueGuard.IsDate(value)
|
|
29
|
+
? ImmutableDate(value)
|
|
30
|
+
: ValueGuard.IsUint8Array(value)
|
|
31
|
+
? ImmutableUint8Array(value)
|
|
32
|
+
: ValueGuard.IsRegExp(value)
|
|
33
|
+
? ImmutableRegExp(value)
|
|
34
|
+
: ValueGuard.IsObject(value)
|
|
35
|
+
? ImmutableObject(value)
|
|
36
|
+
: value;
|
|
37
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './type.mjs';
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export * from './type.mjs';
|