@sinclair/typebox 0.30.0-dev-3 → 0.30.0-dev-4
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/package.json +1 -1
- package/readme.md +5 -5
- package/typebox.d.ts +1 -1
- package/typebox.js +44 -44
package/package.json
CHANGED
package/readme.md
CHANGED
|
@@ -1586,11 +1586,11 @@ The following table lists esbuild compiled and minified sizes for each TypeBox m
|
|
|
1586
1586
|
┌──────────────────────┬────────────┬────────────┬─────────────┐
|
|
1587
1587
|
│ (index) │ Compiled │ Minified │ Compression │
|
|
1588
1588
|
├──────────────────────┼────────────┼────────────┼─────────────┤
|
|
1589
|
-
│ typebox/compiler │ '128.
|
|
1590
|
-
│ typebox/errors │ '110.
|
|
1591
|
-
│ typebox/system │ ' 75.
|
|
1592
|
-
│ typebox/value │ '179.
|
|
1593
|
-
│ typebox │ ' 74.
|
|
1589
|
+
│ typebox/compiler │ '128.3 kb' │ ' 58.0 kb' │ '2.21 x' │
|
|
1590
|
+
│ typebox/errors │ '110.5 kb' │ ' 49.5 kb' │ '2.23 x' │
|
|
1591
|
+
│ typebox/system │ ' 75.4 kb' │ ' 31.2 kb' │ '2.42 x' │
|
|
1592
|
+
│ typebox/value │ '179.7 kb' │ ' 78.7 kb' │ '2.28 x' │
|
|
1593
|
+
│ typebox │ ' 74.3 kb' │ ' 30.7 kb' │ '2.42 x' │
|
|
1594
1594
|
└──────────────────────┴────────────┴────────────┴─────────────┘
|
|
1595
1595
|
```
|
|
1596
1596
|
|
package/typebox.d.ts
CHANGED
|
@@ -601,7 +601,7 @@ export declare namespace TypeExtends {
|
|
|
601
601
|
/** Specialized Clone for Types */
|
|
602
602
|
export declare namespace TypeClone {
|
|
603
603
|
/** Clones a type. */
|
|
604
|
-
function Clone<T extends TSchema>(schema: T, options
|
|
604
|
+
function Clone<T extends TSchema>(schema: T, options?: SchemaOptions): T;
|
|
605
605
|
}
|
|
606
606
|
export declare namespace IndexedAccessor {
|
|
607
607
|
function Resolve(schema: TSchema, keys: Key[], options?: SchemaOptions): TSchema;
|
package/typebox.js
CHANGED
|
@@ -1369,7 +1369,7 @@ var TypeClone;
|
|
|
1369
1369
|
return value;
|
|
1370
1370
|
}
|
|
1371
1371
|
/** Clones a type. */
|
|
1372
|
-
function Clone(schema, options) {
|
|
1372
|
+
function Clone(schema, options = {}) {
|
|
1373
1373
|
return { ...Visit(schema), ...options };
|
|
1374
1374
|
}
|
|
1375
1375
|
TypeClone.Clone = Clone;
|
|
@@ -1381,7 +1381,7 @@ var IndexedAccessor;
|
|
|
1381
1381
|
(function (IndexedAccessor) {
|
|
1382
1382
|
function OptionalUnwrap(schema) {
|
|
1383
1383
|
return schema.map((schema) => {
|
|
1384
|
-
const { [exports.Optional]: _, ...clone } = TypeClone.Clone(schema
|
|
1384
|
+
const { [exports.Optional]: _, ...clone } = TypeClone.Clone(schema);
|
|
1385
1385
|
return clone;
|
|
1386
1386
|
});
|
|
1387
1387
|
}
|
|
@@ -1477,7 +1477,7 @@ var ObjectMap;
|
|
|
1477
1477
|
return schema;
|
|
1478
1478
|
}
|
|
1479
1479
|
function Map(schema, callback, options) {
|
|
1480
|
-
return { ...Visit(TypeClone.Clone(schema
|
|
1480
|
+
return { ...Visit(TypeClone.Clone(schema), callback), ...options };
|
|
1481
1481
|
}
|
|
1482
1482
|
ObjectMap.Map = Map;
|
|
1483
1483
|
})(ObjectMap || (exports.ObjectMap = ObjectMap = {}));
|
|
@@ -1931,11 +1931,11 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
1931
1931
|
}
|
|
1932
1932
|
/** `[Standard]` Creates a Readonly property */
|
|
1933
1933
|
Readonly(schema) {
|
|
1934
|
-
return { ...TypeClone.Clone(schema
|
|
1934
|
+
return { ...TypeClone.Clone(schema), [exports.Readonly]: 'Readonly' };
|
|
1935
1935
|
}
|
|
1936
1936
|
/** `[Standard]` Creates an Optional property */
|
|
1937
1937
|
Optional(schema) {
|
|
1938
|
-
return { ...TypeClone.Clone(schema
|
|
1938
|
+
return { ...TypeClone.Clone(schema), [exports.Optional]: 'Optional' };
|
|
1939
1939
|
}
|
|
1940
1940
|
// ------------------------------------------------------------------------
|
|
1941
1941
|
// Types
|
|
@@ -1946,7 +1946,7 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
1946
1946
|
}
|
|
1947
1947
|
/** `[Standard]` Creates an Array type */
|
|
1948
1948
|
Array(items, options = {}) {
|
|
1949
|
-
return this.Create({ ...options, [exports.Kind]: 'Array', type: 'array', items: TypeClone.Clone(items
|
|
1949
|
+
return this.Create({ ...options, [exports.Kind]: 'Array', type: 'array', items: TypeClone.Clone(items) });
|
|
1950
1950
|
}
|
|
1951
1951
|
/** `[Standard]` Creates a Boolean type */
|
|
1952
1952
|
Boolean(options = {}) {
|
|
@@ -2012,12 +2012,12 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
2012
2012
|
}
|
|
2013
2013
|
else if (TypeGuard.TTuple(schema) && TypeGuard.TNumber(unresolved)) {
|
|
2014
2014
|
const items = ValueGuard.IsUndefined(schema.items) ? [] : schema.items;
|
|
2015
|
-
const cloned = items.map((schema) => TypeClone.Clone(schema
|
|
2015
|
+
const cloned = items.map((schema) => TypeClone.Clone(schema));
|
|
2016
2016
|
return this.Union(cloned, options);
|
|
2017
2017
|
}
|
|
2018
2018
|
else {
|
|
2019
2019
|
const keys = KeyArrayResolver.Resolve(unresolved);
|
|
2020
|
-
const clone = TypeClone.Clone(schema
|
|
2020
|
+
const clone = TypeClone.Clone(schema);
|
|
2021
2021
|
return IndexedAccessor.Resolve(clone, keys, options);
|
|
2022
2022
|
}
|
|
2023
2023
|
}
|
|
@@ -2031,8 +2031,8 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
2031
2031
|
if (allOf.length === 1)
|
|
2032
2032
|
return TypeClone.Clone(allOf[0], options);
|
|
2033
2033
|
const objects = allOf.every((schema) => TypeGuard.TObject(schema));
|
|
2034
|
-
const cloned = allOf.map((schema) => TypeClone.Clone(schema
|
|
2035
|
-
const clonedUnevaluatedProperties = TypeGuard.TSchema(options.unevaluatedProperties) ? { unevaluatedProperties: TypeClone.Clone(options.unevaluatedProperties
|
|
2034
|
+
const cloned = allOf.map((schema) => TypeClone.Clone(schema));
|
|
2035
|
+
const clonedUnevaluatedProperties = TypeGuard.TSchema(options.unevaluatedProperties) ? { unevaluatedProperties: TypeClone.Clone(options.unevaluatedProperties) } : {};
|
|
2036
2036
|
if (options.unevaluatedProperties === false || TypeGuard.TSchema(options.unevaluatedProperties) || objects) {
|
|
2037
2037
|
return this.Create({ ...options, ...clonedUnevaluatedProperties, [exports.Kind]: 'Intersect', type: 'object', allOf: cloned });
|
|
2038
2038
|
}
|
|
@@ -2091,8 +2091,8 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
2091
2091
|
const propertyKeys = Object.getOwnPropertyNames(properties);
|
|
2092
2092
|
const optionalKeys = propertyKeys.filter((key) => TypeGuard.TOptional(properties[key]));
|
|
2093
2093
|
const requiredKeys = propertyKeys.filter((name) => !optionalKeys.includes(name));
|
|
2094
|
-
const clonedAdditionalProperties = TypeGuard.TSchema(options.additionalProperties) ? { additionalProperties: TypeClone.Clone(options.additionalProperties
|
|
2095
|
-
const clonedProperties = propertyKeys.reduce((acc, key) => ({ ...acc, [key]: TypeClone.Clone(properties[key]
|
|
2094
|
+
const clonedAdditionalProperties = TypeGuard.TSchema(options.additionalProperties) ? { additionalProperties: TypeClone.Clone(options.additionalProperties) } : {};
|
|
2095
|
+
const clonedProperties = propertyKeys.reduce((acc, key) => ({ ...acc, [key]: TypeClone.Clone(properties[key]) }), {});
|
|
2096
2096
|
if (requiredKeys.length > 0) {
|
|
2097
2097
|
return this.Create({ ...options, ...clonedAdditionalProperties, [exports.Kind]: 'Object', type: 'object', properties: clonedProperties, required: requiredKeys });
|
|
2098
2098
|
}
|
|
@@ -2103,17 +2103,17 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
2103
2103
|
Omit(schema, unresolved, options = {}) {
|
|
2104
2104
|
const keys = KeyArrayResolver.Resolve(unresolved);
|
|
2105
2105
|
// prettier-ignore
|
|
2106
|
-
return ObjectMap.Map(TypeClone.Clone(schema
|
|
2107
|
-
if (
|
|
2108
|
-
|
|
2109
|
-
if (
|
|
2110
|
-
delete
|
|
2106
|
+
return ObjectMap.Map(TypeClone.Clone(schema), (object) => {
|
|
2107
|
+
if (ValueGuard.IsArray(object.required)) {
|
|
2108
|
+
object.required = object.required.filter((key) => !keys.includes(key));
|
|
2109
|
+
if (object.required.length === 0)
|
|
2110
|
+
delete object.required;
|
|
2111
2111
|
}
|
|
2112
|
-
for (const key of Object.getOwnPropertyNames(
|
|
2112
|
+
for (const key of Object.getOwnPropertyNames(object.properties)) {
|
|
2113
2113
|
if (keys.includes(key))
|
|
2114
|
-
delete
|
|
2114
|
+
delete object.properties[key];
|
|
2115
2115
|
}
|
|
2116
|
-
return this.Create(
|
|
2116
|
+
return this.Create(object);
|
|
2117
2117
|
}, options);
|
|
2118
2118
|
}
|
|
2119
2119
|
/** `[Standard]` Creates a mapped type where all properties are Optional */
|
|
@@ -2129,17 +2129,17 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
2129
2129
|
Pick(schema, unresolved, options = {}) {
|
|
2130
2130
|
const keys = KeyArrayResolver.Resolve(unresolved);
|
|
2131
2131
|
// prettier-ignore
|
|
2132
|
-
return ObjectMap.Map(TypeClone.Clone(schema
|
|
2133
|
-
if (
|
|
2134
|
-
|
|
2135
|
-
if (
|
|
2136
|
-
delete
|
|
2132
|
+
return ObjectMap.Map(TypeClone.Clone(schema), (object) => {
|
|
2133
|
+
if (ValueGuard.IsArray(object.required)) {
|
|
2134
|
+
object.required = object.required.filter((key) => keys.includes(key));
|
|
2135
|
+
if (object.required.length === 0)
|
|
2136
|
+
delete object.required;
|
|
2137
2137
|
}
|
|
2138
|
-
for (const key of Object.getOwnPropertyNames(
|
|
2138
|
+
for (const key of Object.getOwnPropertyNames(object.properties)) {
|
|
2139
2139
|
if (!keys.includes(key))
|
|
2140
|
-
delete
|
|
2140
|
+
delete object.properties[key];
|
|
2141
2141
|
}
|
|
2142
|
-
return this.Create(
|
|
2142
|
+
return this.Create(object);
|
|
2143
2143
|
}, options);
|
|
2144
2144
|
}
|
|
2145
2145
|
/** `[Standard]` Creates a Record type */
|
|
@@ -2148,13 +2148,13 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
2148
2148
|
const expression = TemplateLiteralParser.ParseExact(key.pattern);
|
|
2149
2149
|
// prettier-ignore
|
|
2150
2150
|
return TemplateLiteralFinite.Check(expression)
|
|
2151
|
-
? (this.Object([...TemplateLiteralGenerator.Generate(expression)].reduce((acc, key) => ({ ...acc, [key]: TypeClone.Clone(schema
|
|
2152
|
-
: this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [key.pattern]: TypeClone.Clone(schema
|
|
2151
|
+
? (this.Object([...TemplateLiteralGenerator.Generate(expression)].reduce((acc, key) => ({ ...acc, [key]: TypeClone.Clone(schema) }), {}), options))
|
|
2152
|
+
: this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [key.pattern]: TypeClone.Clone(schema) } });
|
|
2153
2153
|
}
|
|
2154
2154
|
else if (TypeGuard.TUnion(key)) {
|
|
2155
2155
|
const union = UnionResolver.Resolve(key);
|
|
2156
2156
|
if (TypeGuard.TUnionLiteral(union)) {
|
|
2157
|
-
const properties = union.anyOf.reduce((acc, literal) => ({ ...acc, [literal.const]: TypeClone.Clone(schema
|
|
2157
|
+
const properties = union.anyOf.reduce((acc, literal) => ({ ...acc, [literal.const]: TypeClone.Clone(schema) }), {});
|
|
2158
2158
|
return this.Object(properties, { ...options, [exports.Hint]: 'Record' });
|
|
2159
2159
|
}
|
|
2160
2160
|
else
|
|
@@ -2162,17 +2162,17 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
2162
2162
|
}
|
|
2163
2163
|
else if (TypeGuard.TLiteral(key)) {
|
|
2164
2164
|
if (ValueGuard.IsString(key.const) || ValueGuard.IsNumber(key.const)) {
|
|
2165
|
-
return this.Object({ [key.const]: TypeClone.Clone(schema
|
|
2165
|
+
return this.Object({ [key.const]: TypeClone.Clone(schema) }, options);
|
|
2166
2166
|
}
|
|
2167
2167
|
else
|
|
2168
2168
|
throw Error('StandardTypeBuilder: Record key of type literal is not of type string or number');
|
|
2169
2169
|
}
|
|
2170
2170
|
else if (TypeGuard.TInteger(key) || TypeGuard.TNumber(key)) {
|
|
2171
|
-
return this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [exports.PatternNumberExact]: TypeClone.Clone(schema
|
|
2171
|
+
return this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [exports.PatternNumberExact]: TypeClone.Clone(schema) } });
|
|
2172
2172
|
}
|
|
2173
2173
|
else if (TypeGuard.TString(key)) {
|
|
2174
2174
|
const pattern = ValueGuard.IsUndefined(key.pattern) ? exports.PatternStringExact : key.pattern;
|
|
2175
|
-
return this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [pattern]: TypeClone.Clone(schema
|
|
2175
|
+
return this.Create({ ...options, [exports.Kind]: 'Record', type: 'object', patternProperties: { [pattern]: TypeClone.Clone(schema) } });
|
|
2176
2176
|
}
|
|
2177
2177
|
else {
|
|
2178
2178
|
throw Error(`StandardTypeBuilder: Record key is an invalid type`);
|
|
@@ -2209,10 +2209,10 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
2209
2209
|
if (TypeGuard.TTuple(schema)) {
|
|
2210
2210
|
if (ValueGuard.IsUndefined(schema.items))
|
|
2211
2211
|
return [];
|
|
2212
|
-
return schema.items.map((schema) => TypeClone.Clone(schema
|
|
2212
|
+
return schema.items.map((schema) => TypeClone.Clone(schema));
|
|
2213
2213
|
}
|
|
2214
2214
|
else {
|
|
2215
|
-
return [TypeClone.Clone(schema
|
|
2215
|
+
return [TypeClone.Clone(schema)];
|
|
2216
2216
|
}
|
|
2217
2217
|
}
|
|
2218
2218
|
/** `[Standard]` Creates a String type */
|
|
@@ -2230,7 +2230,7 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
2230
2230
|
/** `[Standard]` Creates a Tuple type */
|
|
2231
2231
|
Tuple(items, options = {}) {
|
|
2232
2232
|
const [additionalItems, minItems, maxItems] = [false, items.length, items.length];
|
|
2233
|
-
const clonedItems = items.map((item) => TypeClone.Clone(item
|
|
2233
|
+
const clonedItems = items.map((item) => TypeClone.Clone(item));
|
|
2234
2234
|
// prettier-ignore
|
|
2235
2235
|
const schema = (items.length > 0 ?
|
|
2236
2236
|
{ ...options, [exports.Kind]: 'Tuple', type: 'array', items: clonedItems, additionalItems, minItems, maxItems } :
|
|
@@ -2247,7 +2247,7 @@ class StandardTypeBuilder extends TypeBuilder {
|
|
|
2247
2247
|
return this.Never(options);
|
|
2248
2248
|
if (anyOf.length === 1)
|
|
2249
2249
|
return this.Create(TypeClone.Clone(anyOf[0], options));
|
|
2250
|
-
const clonedAnyOf = anyOf.map((schema) => TypeClone.Clone(schema
|
|
2250
|
+
const clonedAnyOf = anyOf.map((schema) => TypeClone.Clone(schema));
|
|
2251
2251
|
return this.Create({ ...options, [exports.Kind]: 'Union', anyOf: clonedAnyOf });
|
|
2252
2252
|
}
|
|
2253
2253
|
}
|
|
@@ -2267,7 +2267,7 @@ exports.StandardTypeBuilder = StandardTypeBuilder;
|
|
|
2267
2267
|
class ExtendedTypeBuilder extends StandardTypeBuilder {
|
|
2268
2268
|
/** `[Extended]` Creates a AsyncIterator type */
|
|
2269
2269
|
AsyncIterator(items, options = {}) {
|
|
2270
|
-
return this.Create({ ...options, [exports.Kind]: 'AsyncIterator', type: 'AsyncIterator', items: TypeClone.Clone(items
|
|
2270
|
+
return this.Create({ ...options, [exports.Kind]: 'AsyncIterator', type: 'AsyncIterator', items: TypeClone.Clone(items) });
|
|
2271
2271
|
}
|
|
2272
2272
|
/** `[Extended]` Creates a BigInt type */
|
|
2273
2273
|
BigInt(options = {}) {
|
|
@@ -2279,8 +2279,8 @@ class ExtendedTypeBuilder extends StandardTypeBuilder {
|
|
|
2279
2279
|
}
|
|
2280
2280
|
/** `[Extended]` Creates a Constructor type */
|
|
2281
2281
|
Constructor(parameters, returns, options) {
|
|
2282
|
-
const clonedReturns = TypeClone.Clone(returns
|
|
2283
|
-
const clonedParameters = parameters.map((parameter) => TypeClone.Clone(parameter
|
|
2282
|
+
const clonedReturns = TypeClone.Clone(returns);
|
|
2283
|
+
const clonedParameters = parameters.map((parameter) => TypeClone.Clone(parameter));
|
|
2284
2284
|
return this.Create({ ...options, [exports.Kind]: 'Constructor', type: 'constructor', parameters: clonedParameters, returns: clonedReturns });
|
|
2285
2285
|
}
|
|
2286
2286
|
/** `[Extended]` Creates a Date type */
|
|
@@ -2290,7 +2290,7 @@ class ExtendedTypeBuilder extends StandardTypeBuilder {
|
|
|
2290
2290
|
/** `[Extended]` Creates a Function type */
|
|
2291
2291
|
Function(parameters, returns, options) {
|
|
2292
2292
|
const clonedReturns = TypeClone.Clone(returns, {});
|
|
2293
|
-
const clonedParameters = parameters.map((parameter) => TypeClone.Clone(parameter
|
|
2293
|
+
const clonedParameters = parameters.map((parameter) => TypeClone.Clone(parameter));
|
|
2294
2294
|
return this.Create({ ...options, [exports.Kind]: 'Function', type: 'function', parameters: clonedParameters, returns: clonedReturns });
|
|
2295
2295
|
}
|
|
2296
2296
|
/** `[Extended]` Extracts the InstanceType from the given Constructor */
|
|
@@ -2299,7 +2299,7 @@ class ExtendedTypeBuilder extends StandardTypeBuilder {
|
|
|
2299
2299
|
}
|
|
2300
2300
|
/** `[Extended]` Creates an Iterator type */
|
|
2301
2301
|
Iterator(items, options = {}) {
|
|
2302
|
-
return this.Create({ ...options, [exports.Kind]: 'Iterator', type: 'Iterator', items: TypeClone.Clone(items
|
|
2302
|
+
return this.Create({ ...options, [exports.Kind]: 'Iterator', type: 'Iterator', items: TypeClone.Clone(items) });
|
|
2303
2303
|
}
|
|
2304
2304
|
/** `[Extended]` Extracts the Parameters from the given Function type */
|
|
2305
2305
|
Parameters(schema, options = {}) {
|
|
@@ -2307,7 +2307,7 @@ class ExtendedTypeBuilder extends StandardTypeBuilder {
|
|
|
2307
2307
|
}
|
|
2308
2308
|
/** `[Extended]` Creates a Promise type */
|
|
2309
2309
|
Promise(item, options = {}) {
|
|
2310
|
-
return this.Create({ ...options, [exports.Kind]: 'Promise', type: 'Promise', item: TypeClone.Clone(item
|
|
2310
|
+
return this.Create({ ...options, [exports.Kind]: 'Promise', type: 'Promise', item: TypeClone.Clone(item) });
|
|
2311
2311
|
}
|
|
2312
2312
|
/** `[Extended]` Creates a String pattern type from Regular Expression */
|
|
2313
2313
|
RegExp(unresolved, options = {}) {
|