@sinclair/typebox 0.31.19 → 0.31.21
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/typebox.d.ts +2 -1
- package/typebox.js +41 -34
package/package.json
CHANGED
package/typebox.d.ts
CHANGED
|
@@ -337,6 +337,7 @@ export type TRecordFromUnionLiteralString<K extends TLiteralString, T extends TS
|
|
|
337
337
|
export type TRecordFromUnionLiteralNumber<K extends TLiteralNumber, T extends TSchema> = {
|
|
338
338
|
[_ in K['const']]: T;
|
|
339
339
|
};
|
|
340
|
+
export type TRecordFromEnumKey<K extends TEnum, T extends TSchema> = Ensure<TRecord<K, T>>;
|
|
340
341
|
export type TRecordFromUnionRest<K extends TSchema[], T extends TSchema> = K extends [infer L, ...infer R] ? (L extends TUnion<infer S> ? TRecordFromUnionRest<S, T> & TRecordFromUnionRest<AssertRest<R>, T> : L extends TLiteralString ? TRecordFromUnionLiteralString<L, T> & TRecordFromUnionRest<AssertRest<R>, T> : L extends TLiteralNumber ? TRecordFromUnionLiteralNumber<L, T> & TRecordFromUnionRest<AssertRest<R>, T> : {}) : {};
|
|
341
342
|
export type TRecordFromUnion<K extends TSchema[], T extends TSchema> = Ensure<TObject<AssertProperties<Evaluate<TRecordFromUnionRest<K, T>>>>>;
|
|
342
343
|
export type TRecordFromTemplateLiteralKeyInfinite<K extends TTemplateLiteral, T extends TSchema> = Ensure<TRecord<K, T>>;
|
|
@@ -353,7 +354,7 @@ export type TRecordFromLiteralNumberKey<K extends TLiteralNumber, T extends TSch
|
|
|
353
354
|
export type TRecordFromStringKey<K extends TString, T extends TSchema> = Ensure<TRecord<K, T>>;
|
|
354
355
|
export type TRecordFromNumberKey<K extends TNumber, T extends TSchema> = Ensure<TRecord<K, T>>;
|
|
355
356
|
export type TRecordFromIntegerKey<K extends TInteger, T extends TSchema> = Ensure<TRecord<K, T>>;
|
|
356
|
-
export type TRecordResolve<K extends TSchema, T extends TSchema> = K extends TUnion<infer S> ? TRecordFromUnion<S, T> : K extends TTemplateLiteral ? TRecordFromTemplateLiteralKey<K, T> : K extends TLiteralString ? TRecordFromLiteralStringKey<K, T> : K extends TLiteralNumber ? TRecordFromLiteralNumberKey<K, T> : K extends TString ? TRecordFromStringKey<K, T> : K extends TNumber ? TRecordFromNumberKey<K, T> : K extends TInteger ? TRecordFromIntegerKey<K, T> : TNever;
|
|
357
|
+
export type TRecordResolve<K extends TSchema, T extends TSchema> = K extends TEnum<infer _> ? TRecordFromEnumKey<K, T> : K extends TUnion<infer S> ? TRecordFromUnion<S, T> : K extends TTemplateLiteral ? TRecordFromTemplateLiteralKey<K, T> : K extends TLiteralString ? TRecordFromLiteralStringKey<K, T> : K extends TLiteralNumber ? TRecordFromLiteralNumberKey<K, T> : K extends TString ? TRecordFromStringKey<K, T> : K extends TNumber ? TRecordFromNumberKey<K, T> : K extends TInteger ? TRecordFromIntegerKey<K, T> : TNever;
|
|
357
358
|
export interface TRecord<K extends TSchema = TSchema, T extends TSchema = TSchema> extends TSchema {
|
|
358
359
|
[Kind]: 'Record';
|
|
359
360
|
static: Record<Assert<Static<K>, string | number>, Static<T, this['params']>>;
|
package/typebox.js
CHANGED
|
@@ -224,6 +224,9 @@ var TypeGuard;
|
|
|
224
224
|
function IsOptionalSchema(value) {
|
|
225
225
|
return ValueGuard.IsUndefined(value) || TSchema(value);
|
|
226
226
|
}
|
|
227
|
+
// ----------------------------------------------------------------
|
|
228
|
+
// Types
|
|
229
|
+
// ----------------------------------------------------------------
|
|
227
230
|
/** Returns true if the given value is TAny */
|
|
228
231
|
function TAny(schema) {
|
|
229
232
|
// prettier-ignore
|
|
@@ -587,39 +590,39 @@ var TypeGuard;
|
|
|
587
590
|
TypeGuard.TOptional = TOptional;
|
|
588
591
|
/** Returns true if the given value is TSchema */
|
|
589
592
|
function TSchema(schema) {
|
|
590
|
-
|
|
591
|
-
|
|
592
|
-
|
|
593
|
-
|
|
594
|
-
|
|
595
|
-
|
|
596
|
-
|
|
597
|
-
|
|
598
|
-
|
|
599
|
-
|
|
600
|
-
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
|
|
620
|
-
|
|
621
|
-
|
|
622
|
-
|
|
593
|
+
// prettier-ignore
|
|
594
|
+
return (ValueGuard.IsObject(schema)) && (TAny(schema) ||
|
|
595
|
+
TArray(schema) ||
|
|
596
|
+
TBoolean(schema) ||
|
|
597
|
+
TBigInt(schema) ||
|
|
598
|
+
TAsyncIterator(schema) ||
|
|
599
|
+
TConstructor(schema) ||
|
|
600
|
+
TDate(schema) ||
|
|
601
|
+
TFunction(schema) ||
|
|
602
|
+
TInteger(schema) ||
|
|
603
|
+
TIntersect(schema) ||
|
|
604
|
+
TIterator(schema) ||
|
|
605
|
+
TLiteral(schema) ||
|
|
606
|
+
TNever(schema) ||
|
|
607
|
+
TNot(schema) ||
|
|
608
|
+
TNull(schema) ||
|
|
609
|
+
TNumber(schema) ||
|
|
610
|
+
TObject(schema) ||
|
|
611
|
+
TPromise(schema) ||
|
|
612
|
+
TRecord(schema) ||
|
|
613
|
+
TRef(schema) ||
|
|
614
|
+
TString(schema) ||
|
|
615
|
+
TSymbol(schema) ||
|
|
616
|
+
TTemplateLiteral(schema) ||
|
|
617
|
+
TThis(schema) ||
|
|
618
|
+
TTuple(schema) ||
|
|
619
|
+
TUndefined(schema) ||
|
|
620
|
+
TUnion(schema) ||
|
|
621
|
+
TUint8Array(schema) ||
|
|
622
|
+
TUnknown(schema) ||
|
|
623
|
+
TUnsafe(schema) ||
|
|
624
|
+
TVoid(schema) ||
|
|
625
|
+
(TKind(schema) && TypeRegistry.Has(schema[exports.Kind])));
|
|
623
626
|
}
|
|
624
627
|
TypeGuard.TSchema = TSchema;
|
|
625
628
|
})(TypeGuard || (exports.TypeGuard = TypeGuard = {}));
|
|
@@ -995,8 +998,12 @@ var TypeExtends;
|
|
|
995
998
|
!TypeGuard.TObject(right) ? TypeExtendsResult.False :
|
|
996
999
|
(() => {
|
|
997
1000
|
for (const key of Object.getOwnPropertyNames(right.properties)) {
|
|
998
|
-
if (!(key in left.properties))
|
|
1001
|
+
if (!(key in left.properties) && !TypeGuard.TOptional(right.properties[key])) {
|
|
999
1002
|
return TypeExtendsResult.False;
|
|
1003
|
+
}
|
|
1004
|
+
if (TypeGuard.TOptional(right.properties[key])) {
|
|
1005
|
+
return TypeExtendsResult.True;
|
|
1006
|
+
}
|
|
1000
1007
|
if (Property(left.properties[key], right.properties[key]) === TypeExtendsResult.False) {
|
|
1001
1008
|
return TypeExtendsResult.False;
|
|
1002
1009
|
}
|