@sinclair/typebox
Advanced tools
Comparing version 0.21.0 to 0.21.1
{ | ||
"name": "@sinclair/typebox", | ||
"version": "0.21.0", | ||
"version": "0.21.1", | ||
"description": "JSONSchema Type Builder with Static Type Resolution for TypeScript", | ||
@@ -5,0 +5,0 @@ "keywords": [ |
@@ -777,5 +777,3 @@ <div align='center'> | ||
type IntoStringUnion<T> = {[K in keyof T]: T[K] extends string ? TLiteral<T[K]>: never } | ||
function StringUnion<T extends string[]>(values: [...T]): TUnion<IntoStringUnion<T>> { | ||
function StringUnion<T extends string[]>(values: [...T]): TUnion<{[K in keyof T]: T[K] }[number]> { | ||
return { enum: values } as any | ||
@@ -782,0 +780,0 @@ } |
@@ -66,2 +66,5 @@ export declare const ReadonlyOptionalModifier: unique symbol; | ||
} & CustomOptions; | ||
export declare type TDefinitions = { | ||
[key: string]: TSchema; | ||
}; | ||
export declare type TNamespace<T extends TDefinitions> = { | ||
@@ -71,5 +74,2 @@ kind: typeof BoxKind; | ||
} & CustomOptions; | ||
export declare type TDefinitions = { | ||
[key: string]: TSchema; | ||
}; | ||
export declare type Infer<T> = { | ||
@@ -81,3 +81,3 @@ '_infer': T; | ||
export declare type TValue = string | number | boolean; | ||
export declare type TRecordKey = TString | TNumber | TKeyOf<any>; | ||
export declare type TRecordKey = TString | TNumber | TKeyOf<any> | TUnion<string | number>; | ||
export declare type TEnumKey<T = TKey> = { | ||
@@ -90,3 +90,3 @@ type: 'number' | 'string'; | ||
}; | ||
export declare type TTuple<T> = Infer<T> & { | ||
export declare type TTuple<I> = Infer<I> & { | ||
kind: typeof TupleKind; | ||
@@ -99,3 +99,3 @@ type: 'array'; | ||
} & CustomOptions; | ||
export declare type TObject<T> = Infer<T> & { | ||
export declare type TObject<I> = Infer<I> & { | ||
kind: typeof ObjectKind; | ||
@@ -106,7 +106,7 @@ type: 'object'; | ||
} & ObjectOptions; | ||
export declare type TUnion<T> = Infer<T> & { | ||
export declare type TUnion<I> = Infer<I> & { | ||
kind: typeof UnionKind; | ||
anyOf: TSchema[]; | ||
} & CustomOptions; | ||
export declare type TIntersect<T> = Infer<T> & { | ||
export declare type TIntersect<I> = Infer<I> & { | ||
kind: typeof IntersectKind; | ||
@@ -116,3 +116,3 @@ type: 'object'; | ||
} & IntersectOptions; | ||
export declare type TKeyOf<T> = Infer<T> & { | ||
export declare type TKeyOf<I> = Infer<I> & { | ||
kind: typeof KeyOfKind; | ||
@@ -122,3 +122,3 @@ type: 'string'; | ||
} & CustomOptions; | ||
export declare type TRecord<T> = Infer<T> & { | ||
export declare type TRecord<I> = Infer<I> & { | ||
kind: typeof RecordKind; | ||
@@ -130,3 +130,3 @@ type: 'object'; | ||
} & ObjectOptions; | ||
export declare type TArray<T> = Infer<T> & { | ||
export declare type TArray<I> = Infer<I> & { | ||
kind: typeof ArrayKind; | ||
@@ -136,7 +136,7 @@ type: 'array'; | ||
} & ArrayOptions; | ||
export declare type TLiteral<T> = Infer<T> & { | ||
export declare type TLiteral<I> = Infer<I> & { | ||
kind: typeof LiteralKind; | ||
const: TSchema; | ||
const: TValue; | ||
} & CustomOptions; | ||
export declare type TEnum<T> = Infer<T> & { | ||
export declare type TEnum<I> = Infer<I> & { | ||
kind: typeof EnumKind; | ||
@@ -232,3 +232,3 @@ anyOf: TSchema; | ||
export declare type StaticObject<T extends TProperties> = StaticProperties<StaticProperties<T>>; | ||
export declare type StaticRecord<K extends TRecordKey, T extends TSchema> = K extends TString ? Record<string, Static<T>> : K extends TNumber ? Record<number, Static<T>> : K extends TKeyOf<any> ? Record<K['_infer'], Static<T>> : never; | ||
export declare type StaticRecord<K extends TRecordKey, T extends TSchema> = K extends TString ? Record<string, Static<T>> : K extends TNumber ? Record<number, Static<T>> : K extends TKeyOf<any> ? Record<K['_infer'], Static<T>> : K extends TUnion<any> ? Record<K['_infer'], Static<T>> : never; | ||
export declare type StaticArray<T extends TSchema> = Array<Static<T>>; | ||
@@ -235,0 +235,0 @@ export declare type StaticLiteral<T extends TValue> = T; |
@@ -58,3 +58,3 @@ "use strict"; | ||
// ------------------------------------------------------------------------ | ||
// Schema Extended | ||
// Extended Schema Types | ||
// ------------------------------------------------------------------------ | ||
@@ -183,5 +183,11 @@ exports.ConstructorKind = Symbol('ConstructorKind'); | ||
Record(key, value, options = {}) { | ||
const pattern = key.kind === exports.KeyOfKind ? `^${key.enum.join('|')}$` : | ||
key.kind === exports.NumberKind ? '^(0|[1-9][0-9]*)$' : | ||
key.pattern ? key.pattern : '^.*$'; | ||
const pattern = (() => { | ||
switch (key.kind) { | ||
case exports.UnionKind: return `^${key.anyOf.map(literal => literal.const).join('|')}$`; | ||
case exports.KeyOfKind: return `^${key.enum.join('|')}$`; | ||
case exports.NumberKind: return '^(0|[1-9][0-9]*)$'; | ||
case exports.StringKind: return key.pattern ? key.pattern : '^.*$'; | ||
default: throw Error('Invalid Record Key'); | ||
} | ||
})(); | ||
return { ...options, kind: exports.RecordKind, type: 'object', patternProperties: { [pattern]: value } }; | ||
@@ -188,0 +194,0 @@ } |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
89500
608
787