@sinclair/typebox 0.31.8 → 0.31.9
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 +9 -11
- package/typebox.js +6 -6
package/package.json
CHANGED
package/typebox.d.ts
CHANGED
|
@@ -72,7 +72,7 @@ export interface TSchema extends SchemaOptions, TKind {
|
|
|
72
72
|
params: unknown[];
|
|
73
73
|
static: unknown;
|
|
74
74
|
}
|
|
75
|
-
export type TAnySchema = TSchema | TAny | TArray | TAsyncIterator | TBigInt | TBoolean | TConstructor | TDate |
|
|
75
|
+
export type TAnySchema = TSchema | TAny | TArray | TAsyncIterator | TBigInt | TBoolean | TConstructor | TDate | TFunction | TInteger | TIntersect | TIterator | TLiteral | TNot | TNull | TNumber | TObject | TPromise | TRecord | TRef | TString | TSymbol | TTemplateLiteral | TThis | TTuple | TUndefined | TUnion | TUint8Array | TUnknown | TVoid;
|
|
76
76
|
export interface NumericOptions<N extends number | bigint> extends SchemaOptions {
|
|
77
77
|
exclusiveMaximum?: N;
|
|
78
78
|
exclusiveMinimum?: N;
|
|
@@ -157,15 +157,13 @@ export interface TDate extends TSchema, DateOptions {
|
|
|
157
157
|
static: Date;
|
|
158
158
|
type: 'date';
|
|
159
159
|
}
|
|
160
|
-
export
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
export
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
anyOf: TLiteral<T[keyof T]>[];
|
|
168
|
-
}
|
|
160
|
+
export type TEnumRecord = Record<TEnumKey, TEnumValue>;
|
|
161
|
+
export type TEnumValue = string | number;
|
|
162
|
+
export type TEnumKey = string;
|
|
163
|
+
export type TEnumToLiteralUnion<T extends TEnumValue> = T extends TEnumValue ? TLiteral<T> : never;
|
|
164
|
+
export type TEnumToLiteralTuple<T extends TEnumValue> = UnionToTuple<TEnumToLiteralUnion<T>>;
|
|
165
|
+
export type TEnumToUnion<T extends TEnumValue, R = UnionType<AssertRest<TEnumToLiteralTuple<T>>>> = R extends TLiteralString ? TNever : R;
|
|
166
|
+
export type TEnum<T extends TEnumValue> = Ensure<TEnumToUnion<T>>;
|
|
169
167
|
export type TExtends<L extends TSchema, R extends TSchema, T extends TSchema, U extends TSchema> = (Static<L> extends Static<R> ? T : U) extends infer O ? UnionToTuple<O> extends [infer X, infer Y] ? TUnion<[AssertType<X>, AssertType<Y>]> : AssertType<O> : never;
|
|
170
168
|
export type TExcludeTemplateLiteralResult<T extends string> = UnionType<AssertRest<UnionToTuple<{
|
|
171
169
|
[K in T]: TLiteral<K>;
|
|
@@ -799,7 +797,7 @@ export declare class JsonTypeBuilder extends TypeBuilder {
|
|
|
799
797
|
/** `[Json]` Creates a Composite object type */
|
|
800
798
|
Composite<T extends TObject[]>(objects: [...T], options?: ObjectOptions): TComposite<T>;
|
|
801
799
|
/** `[Json]` Creates a Enum type */
|
|
802
|
-
Enum<V extends
|
|
800
|
+
Enum<V extends TEnumValue, T extends Record<TEnumKey, V>>(item: T, options?: SchemaOptions): TEnum<T[keyof T]>;
|
|
803
801
|
/** `[Json]` Creates a Conditional type */
|
|
804
802
|
Extends<L extends TSchema, R extends TSchema, T extends TSchema, U extends TSchema>(left: L, right: R, trueType: T, falseType: U, options?: SchemaOptions): TExtends<L, R, T, U>;
|
|
805
803
|
/** `[Json]` Constructs a type by excluding from unionType all union members that are assignable to excludedMembers */
|
package/typebox.js
CHANGED
|
@@ -1934,13 +1934,13 @@ class JsonTypeBuilder extends TypeBuilder {
|
|
|
1934
1934
|
}
|
|
1935
1935
|
/** `[Json]` Creates a Enum type */
|
|
1936
1936
|
Enum(item, options = {}) {
|
|
1937
|
+
if (ValueGuard.IsUndefined(item))
|
|
1938
|
+
return this.Union([], options);
|
|
1937
1939
|
// prettier-ignore
|
|
1938
|
-
const
|
|
1939
|
-
//
|
|
1940
|
-
const anyOf =
|
|
1941
|
-
|
|
1942
|
-
: { [exports.Kind]: 'Literal', type: 'number', const: value });
|
|
1943
|
-
return this.Create({ ...options, [exports.Kind]: 'Union', anyOf });
|
|
1940
|
+
const values1 = Object.getOwnPropertyNames(item).filter((key) => isNaN(key)).map((key) => item[key]);
|
|
1941
|
+
const values2 = [...new Set(values1)]; // distinct
|
|
1942
|
+
const anyOf = values2.map((value) => exports.Type.Literal(value));
|
|
1943
|
+
return this.Union(anyOf, options);
|
|
1944
1944
|
}
|
|
1945
1945
|
/** `[Json]` Creates a Conditional type */
|
|
1946
1946
|
Extends(left, right, trueType, falseType, options = {}) {
|