Comparing version 0.0.1-20 to 0.0.1-21
@@ -1,15 +0,16 @@ | ||
import type { Denominalize, Type, __nominal, __type } from './type'; | ||
import type { Denominalize, TypeInMediumsPartial, __nominal, __type } from './type'; | ||
export declare const hasOwnProperty: (v: PropertyKey) => boolean; | ||
export declare const toString: () => string; | ||
export declare type __RefinedMediumType<TInMedium, TRefinement, TNominal> = unknown extends TNominal ? TInMedium & TRefinement : __RefinedNominalType<TInMedium & TRefinement, TNominal>; | ||
export declare type __RefinedNominalType<T, TNominal> = T & (TNominal & Record<__type, Denominalize<T>>); | ||
export declare type __TupleInMedium<TTypeTuple extends Type[], TMediumName extends keyof XValue.Using> = { | ||
[TIndex in keyof TTypeTuple]: TTypeTuple[TIndex] extends Type<infer TElementInMediums> ? TElementInMediums[TMediumName] : never; | ||
export declare type RefinedMediumType<TInMedium, TRefinement, TNominal> = unknown extends TNominal ? TInMedium & TRefinement : RefinedNominalType<TInMedium & TRefinement, TNominal>; | ||
declare type RefinedNominalType<T, TNominal> = T & (TNominal & Record<__type, Denominalize<T>>); | ||
export declare type TupleInMedium<TTypeTuple extends TypeInMediumsPartial[], TMediumName extends XValue.UsingName> = { | ||
[TIndex in keyof TTypeTuple]: TTypeTuple[TIndex] extends TypeInMediumsPartial<infer TElementInMediums> ? TElementInMediums[TMediumName] : never; | ||
}; | ||
export declare type __UnionToIntersection<TUnion> = (TUnion extends unknown ? (_: TUnion) => unknown : never) extends (_: infer TIntersection) => unknown ? TIntersection : never; | ||
export declare type __MediumTypesPackedType<TMediumTypes, TFallback = never> = TMediumTypes extends { | ||
export declare type UnionToIntersection<TUnion> = (TUnion extends unknown ? (_: TUnion) => unknown : never) extends (_: infer TIntersection) => unknown ? TIntersection : never; | ||
export declare type MediumTypesPackedType<TMediumTypes, TFallback = never> = TMediumTypes extends { | ||
packed: infer TPacked; | ||
} ? TPacked : TFallback; | ||
export declare type __ElementOrArray<T> = T | T[]; | ||
export declare type __NominalPartial = Record<__nominal, unknown>; | ||
export declare type ElementOrArray<T> = T | T[]; | ||
export declare type NominalPartial = Record<__nominal, unknown>; | ||
export declare function merge(partials: unknown[]): unknown; | ||
export {}; |
@@ -1,3 +0,3 @@ | ||
import type { __MediumTypesPackedType } from './@internal'; | ||
import type { Type } from './type'; | ||
import type { MediumTypesPackedType } from './@internal'; | ||
import type { TypeInMediumsPartial, __type_in_mediums } from './type'; | ||
export declare const atomicTypeSymbol: unique symbol; | ||
@@ -10,3 +10,3 @@ export declare type GeneralMediumTypes = { | ||
}; | ||
export declare type GeneralUsingMedium = Medium<keyof XValue.Using, object>; | ||
export declare type GeneralUsingMedium = Medium<XValue.UsingName, object>; | ||
export declare type MediumAtomicCodecs<TMediumTypes extends object> = { | ||
@@ -24,3 +24,3 @@ [TSymbol in keyof XValue.Types]?: __MediumAtomicCodec<TMediumTypes extends { | ||
export interface MediumOptions<TMediumTypes extends object = GeneralMediumTypes> { | ||
packing?: MediumPacking<__MediumTypesPackedType<TMediumTypes>>; | ||
packing?: MediumPacking<MediumTypesPackedType<TMediumTypes>>; | ||
codecs: MediumAtomicCodecs<TMediumTypes>; | ||
@@ -35,4 +35,4 @@ } | ||
requireCodec<TSymbol extends keyof TTypes>(symbol: TSymbol): MediumAtomicCodec<TTypes, TSymbol>; | ||
unpack(packed: __MediumTypesPackedType<TTypes>): unknown; | ||
pack(unpacked: unknown): __MediumTypesPackedType<TTypes>; | ||
unpack(packed: MediumTypesPackedType<TTypes>): unknown; | ||
pack(unpacked: unknown): MediumTypesPackedType<TTypes>; | ||
} | ||
@@ -45,3 +45,3 @@ export declare type MediumAtomicCodec<TMediumTypes extends object = GeneralMediumTypes, TSymbol extends keyof TMediumTypes = keyof TMediumTypes> = __MediumAtomicCodec<TMediumTypes[TSymbol], TSymbol extends keyof XValue.Types ? XValue.Types[TSymbol] : unknown>; | ||
export declare function medium<TUsingMedium extends object>(name: Extract<keyof TUsingMedium, string>, options: MediumOptions<Extract<TUsingMedium[keyof TUsingMedium], object>>): Medium<Extract<keyof TUsingMedium, string>, Extract<TUsingMedium[keyof TUsingMedium], object>>; | ||
export declare type MediumTypeOf<TType extends Type, TMediumName extends keyof XValue.Using> = TType extends Type<infer TInMediums> ? TInMediums[TMediumName] : never; | ||
export declare type MediumTypeOf<TType extends TypeInMediumsPartial, TMediumName extends XValue.UsingName> = TType[__type_in_mediums][TMediumName]; | ||
export {}; |
@@ -1,11 +0,12 @@ | ||
import { Type } from './type'; | ||
export declare class ArrayType<TElementType extends Type> extends Type<__ArrayInMediums<TElementType>> { | ||
readonly ElementType: TElementType; | ||
protected __type: 'array'; | ||
import type { TypeInMediumsPartial, __type_in_mediums } from './type'; | ||
import { Type, __type_kind } from './type'; | ||
export declare class ArrayType<TElementType extends TypeInMediumsPartial> extends Type<ArrayInMediums<TElementType>> { | ||
readonly ElementType: Type; | ||
[__type_kind]: 'array'; | ||
constructor(ElementType: TElementType); | ||
} | ||
export declare function array<TElementType extends Type>(ElementType: TElementType): ArrayType<TElementType>; | ||
declare type __ArrayInMediums<TElementType extends Type> = TElementType extends Type<infer TElementInMediums> ? { | ||
[TKey in keyof XValue.Using]: TElementInMediums[TKey][]; | ||
} : never; | ||
export declare function array<TElementType extends TypeInMediumsPartial>(ElementType: TElementType): ArrayType<TElementType>; | ||
declare type ArrayInMediums<TElementType extends TypeInMediumsPartial> = { | ||
[TKey in XValue.UsingName]: TElementType[__type_in_mediums][TKey][]; | ||
}; | ||
export {}; |
"use strict"; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -15,3 +16,3 @@ exports.array = exports.ArrayType = void 0; | ||
}); | ||
Object.defineProperty(this, "__type", { | ||
Object.defineProperty(this, _a, { | ||
enumerable: true, | ||
@@ -109,2 +110,3 @@ configurable: true, | ||
exports.ArrayType = ArrayType; | ||
_a = type_1.__type_kind; | ||
function array(ElementType) { | ||
@@ -111,0 +113,0 @@ return new ArrayType(ElementType); |
import type { TypeConstraint } from './type'; | ||
import { Type } from './type'; | ||
export declare class AtomicType<TSymbol extends symbol> extends Type<__AtomicInMediums<TSymbol>> { | ||
import { Type, __type_kind } from './type'; | ||
export declare class AtomicType<TSymbol extends symbol> extends Type<AtomicInMediums<TSymbol>> { | ||
readonly symbol: symbol; | ||
readonly constraints: TypeConstraint[]; | ||
protected __type: 'atomic'; | ||
[__type_kind]: 'atomic'; | ||
constructor(symbol: TSymbol, constraints: TypeConstraint[]); | ||
} | ||
export declare function atomic<TSymbol extends symbol>(symbol: TSymbol, constraints: TypeConstraint | TypeConstraint[]): AtomicType<TSymbol>; | ||
declare type __AtomicInMediums<TSymbol extends symbol> = { | ||
[TMediumName in keyof XValue.Using]: __AtomicInMedium<TSymbol, XValue.Using[TMediumName]>; | ||
declare type AtomicInMediums<TSymbol extends symbol> = { | ||
[TMediumName in XValue.UsingName]: AtomicInMedium<TSymbol, XValue.Using[TMediumName]>; | ||
}; | ||
declare type __AtomicInMedium<TSymbol extends symbol, TMediumTypes> = TSymbol extends keyof TMediumTypes ? TMediumTypes[TSymbol] : never; | ||
declare type AtomicInMedium<TSymbol extends symbol, TMediumTypes> = TSymbol extends keyof TMediumTypes ? TMediumTypes[TSymbol] : never; | ||
export {}; |
"use strict"; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -20,3 +21,3 @@ exports.atomic = exports.AtomicType = void 0; | ||
}); | ||
Object.defineProperty(this, "__type", { | ||
Object.defineProperty(this, _a, { | ||
enumerable: true, | ||
@@ -93,2 +94,3 @@ configurable: true, | ||
exports.AtomicType = AtomicType; | ||
_a = type_1.__type_kind; | ||
function atomic(symbol, constraints) { | ||
@@ -95,0 +97,0 @@ return new AtomicType(symbol, Array.isArray(constraints) ? constraints : [constraints]); |
@@ -1,12 +0,21 @@ | ||
import type { __TupleInMedium, __UnionToIntersection } from '../@internal'; | ||
import { Type } from './type'; | ||
export declare class IntersectionType<TTypeTuple extends [Type, Type, ...Type[]]> extends Type<__IntersectionInMediums<TTypeTuple>> { | ||
readonly TypeTuple: TTypeTuple; | ||
protected __type: 'intersection'; | ||
import type { TupleInMedium, UnionToIntersection } from '../@internal'; | ||
import type { TypeInMediumsPartial } from './type'; | ||
import { Type, __type_kind } from './type'; | ||
export declare class IntersectionType<TTypeTuple extends [ | ||
TypeInMediumsPartial, | ||
TypeInMediumsPartial, | ||
...TypeInMediumsPartial[] | ||
]> extends Type<IntersectionInMediums<TTypeTuple>> { | ||
readonly TypeTuple: Type[]; | ||
[__type_kind]: 'intersection'; | ||
constructor(TypeTuple: TTypeTuple); | ||
} | ||
export declare function intersection<TTypeTuple extends [Type, Type, ...Type[]]>(...Types: TTypeTuple): IntersectionType<TTypeTuple>; | ||
declare type __IntersectionInMediums<TTypeTuple extends Type[]> = { | ||
[TMediumName in keyof XValue.Using]: __UnionToIntersection<__TupleInMedium<TTypeTuple, TMediumName>[number]>; | ||
export declare function intersection<TTypeTuple extends [ | ||
TypeInMediumsPartial, | ||
TypeInMediumsPartial, | ||
...TypeInMediumsPartial[] | ||
]>(...Types: TTypeTuple): IntersectionType<TTypeTuple>; | ||
declare type IntersectionInMediums<TTypeTuple extends TypeInMediumsPartial[]> = { | ||
[TMediumName in XValue.UsingName]: UnionToIntersection<TupleInMedium<TTypeTuple, TMediumName>[number]>; | ||
}; | ||
export {}; |
"use strict"; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -18,3 +19,3 @@ exports.intersection = exports.IntersectionType = void 0; | ||
}); | ||
Object.defineProperty(this, "__type", { | ||
Object.defineProperty(this, _a, { | ||
enumerable: true, | ||
@@ -65,2 +66,3 @@ configurable: true, | ||
exports.IntersectionType = IntersectionType; | ||
_a = type_1.__type_kind; | ||
function intersection(...Types) { | ||
@@ -67,0 +69,0 @@ return new IntersectionType(Types); |
import { OptionalType } from './optional-type'; | ||
import { Type } from './type'; | ||
export declare class ObjectType<TDefinition extends Record<string, Type>> extends Type<__ObjectInMediums<TDefinition>> { | ||
readonly definition: TDefinition; | ||
protected __type: 'object'; | ||
import type { TypeInMediumsPartial, TypeKindPartial, __type_in_mediums } from './type'; | ||
import { Type, __type_kind } from './type'; | ||
export declare class ObjectType<TDefinition extends Record<string, TypeInMediumsPartial>> extends Type<ObjectInMediums<TDefinition>> { | ||
readonly definition: Record<string, Type>; | ||
[__type_kind]: 'object'; | ||
constructor(definition: TDefinition); | ||
partial(): ObjectType<__Partial<TDefinition>>; | ||
partial(): ObjectType<DefinitionPartial<TDefinition>>; | ||
pick<TKeys extends string[]>(...keys: TKeys): ObjectType<Pick<TDefinition, TKeys[number]>>; | ||
omit<TKeys extends string[]>(...keys: TKeys): ObjectType<Omit<TDefinition, TKeys[number]>>; | ||
} | ||
export declare function object<TTypeDefinition extends Record<string, Type>>(definition: TTypeDefinition): ObjectType<TTypeDefinition>; | ||
declare type __ObjectInMediums<TDefinition extends Record<string, Type>> = { | ||
[TMediumName in keyof XValue.Using]: __ObjectInMedium<TDefinition, TMediumName>; | ||
export declare function object<TTypeDefinition extends Record<string, TypeInMediumsPartial>>(definition: TTypeDefinition): ObjectType<TTypeDefinition>; | ||
declare type ObjectInMediums<TDefinition extends Record<string, TypeInMediumsPartial>> = { | ||
[TMediumName in XValue.UsingName]: ObjectInMedium<TDefinition, TMediumName>; | ||
}; | ||
declare type __ObjectInMedium<TDefinition extends Record<string, Type>, TMediumName extends keyof XValue.Using> = { | ||
[TKey in __KeyOfOptional<TDefinition>]?: TDefinition[TKey] extends OptionalType<Type<infer TInMediums>> ? TInMediums[TMediumName] : never; | ||
declare type ObjectInMedium<TDefinition extends Record<string, TypeInMediumsPartial>, TMediumName extends XValue.UsingName> = { | ||
[TKey in KeyOfOptional<TDefinition>]?: TDefinition[TKey][__type_in_mediums][TMediumName]; | ||
} & { | ||
[TKey in __KeyOfNonOptional<TDefinition>]: TDefinition[TKey] extends Type<infer TInMediums> ? TInMediums[TMediumName] : never; | ||
[TKey in KeyOfNonOptional<TDefinition>]: TDefinition[TKey][__type_in_mediums][TMediumName]; | ||
}; | ||
declare type __KeyOfOptional<TType> = Extract<{ | ||
[TKey in keyof TType]: TType[TKey] extends OptionalType<Type> ? TKey : never; | ||
declare type KeyOfOptional<TType> = Extract<{ | ||
[TKey in keyof TType]: TType[TKey] extends TypeKindPartial<'optional'> ? TKey : never; | ||
}[keyof TType], string>; | ||
declare type __KeyOfNonOptional<TType> = Extract<{ | ||
[TKey in keyof TType]: TType[TKey] extends OptionalType<Type> ? never : TKey; | ||
declare type KeyOfNonOptional<TType> = Extract<{ | ||
[TKey in keyof TType]: TType[TKey] extends TypeKindPartial<'optional'> ? never : TKey; | ||
}[keyof TType], string>; | ||
declare type __Partial<TDefinition extends Record<string, Type>> = { | ||
[TKey in keyof TDefinition]: TDefinition[TKey] extends OptionalType<Type> ? TDefinition[TKey] : OptionalType<TDefinition[TKey]>; | ||
declare type DefinitionPartial<TDefinition extends Record<string, TypeInMediumsPartial>> = { | ||
[TKey in keyof TDefinition]: TDefinition[TKey] extends TypeKindPartial<'optional'> ? TDefinition[TKey] : OptionalType<TDefinition[TKey]>; | ||
}; | ||
export {}; |
"use strict"; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -16,3 +17,3 @@ exports.object = exports.ObjectType = void 0; | ||
}); | ||
Object.defineProperty(this, "__type", { | ||
Object.defineProperty(this, _a, { | ||
enumerable: true, | ||
@@ -134,2 +135,3 @@ configurable: true, | ||
exports.ObjectType = ObjectType; | ||
_a = type_1.__type_kind; | ||
function object(definition) { | ||
@@ -136,0 +138,0 @@ return new ObjectType(definition); |
@@ -1,11 +0,12 @@ | ||
import { Type } from './type'; | ||
export declare class OptionalType<TType extends Type> extends Type<__OptionalInMediums<TType>> { | ||
readonly Type: TType; | ||
protected __type: 'optional'; | ||
import type { TypeInMediumsPartial, __type_in_mediums } from './type'; | ||
import { Type, __type_kind } from './type'; | ||
export declare class OptionalType<TType extends TypeInMediumsPartial> extends Type<OptionalInMediums<TType>> { | ||
readonly Type: Type; | ||
[__type_kind]: 'optional'; | ||
constructor(Type: TType); | ||
} | ||
export declare function optional<TType extends Type>(Type: TType): OptionalType<TType>; | ||
declare type __OptionalInMediums<TType extends Type> = TType extends Type<infer TInMediums> ? { | ||
[TMediumName in keyof XValue.Using]: TInMediums[TMediumName] | undefined; | ||
} : never; | ||
export declare function optional<TType extends TypeInMediumsPartial>(Type: TType): OptionalType<TType>; | ||
declare type OptionalInMediums<TType extends TypeInMediumsPartial> = { | ||
[TMediumName in XValue.UsingName]: TType[__type_in_mediums][TMediumName] | undefined; | ||
}; | ||
export {}; |
"use strict"; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -14,3 +15,3 @@ exports.optional = exports.OptionalType = void 0; | ||
}); | ||
Object.defineProperty(this, "__type", { | ||
Object.defineProperty(this, _a, { | ||
enumerable: true, | ||
@@ -58,2 +59,3 @@ configurable: true, | ||
exports.OptionalType = OptionalType; | ||
_a = type_1.__type_kind; | ||
function optional(Type) { | ||
@@ -60,0 +62,0 @@ return new OptionalType(Type); |
@@ -1,12 +0,13 @@ | ||
import { Type } from './type'; | ||
export declare class RecordType<TKeyType extends Type, TValueType extends Type> extends Type<__RecordInMediums<TKeyType, TValueType>> { | ||
readonly Key: TKeyType; | ||
readonly Value: TValueType; | ||
protected __type: 'record'; | ||
import type { TypeInMediumsPartial, __type_in_mediums } from './type'; | ||
import { Type, __type_kind } from './type'; | ||
export declare class RecordType<TKeyType extends TypeInMediumsPartial, TValueType extends TypeInMediumsPartial> extends Type<RecordInMediums<TKeyType, TValueType>> { | ||
readonly Key: Type; | ||
readonly Value: Type; | ||
[__type_kind]: 'record'; | ||
constructor(Key: TKeyType, Value: TValueType); | ||
} | ||
export declare function record<TKeyType extends Type, TValueType extends Type>(Key: TKeyType, Value: TValueType): RecordType<TKeyType, TValueType>; | ||
declare type __RecordInMediums<TKeyType extends Type, TValueType extends Type> = { | ||
[TMediumName in keyof XValue.Using]: Record<TKeyType extends Type<infer TKeyInMediums> ? Extract<TKeyInMediums[TMediumName], string | symbol> : never, TValueType extends Type<infer TValueInMediums> ? TValueInMediums[TMediumName] : never>; | ||
export declare function record<TKeyType extends TypeInMediumsPartial, TValueType extends TypeInMediumsPartial>(Key: TKeyType, Value: TValueType): RecordType<TKeyType, TValueType>; | ||
declare type RecordInMediums<TKeyType extends TypeInMediumsPartial, TValueType extends TypeInMediumsPartial> = { | ||
[TMediumName in XValue.UsingName]: Record<Extract<TKeyType[__type_in_mediums][TMediumName], string | symbol>, TValueType[__type_in_mediums][TMediumName]>; | ||
}; | ||
export {}; |
"use strict"; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -21,3 +22,3 @@ exports.record = exports.RecordType = void 0; | ||
}); | ||
Object.defineProperty(this, "__type", { | ||
Object.defineProperty(this, _a, { | ||
enumerable: true, | ||
@@ -133,2 +134,3 @@ configurable: true, | ||
exports.RecordType = RecordType; | ||
_a = type_1.__type_kind; | ||
function record(Key, Value) { | ||
@@ -135,0 +137,0 @@ return new RecordType(Key, Value); |
@@ -1,14 +0,15 @@ | ||
import { Type } from './type'; | ||
export declare class RecursiveType<TRecursive> extends Type<__RecursiveInMediums<TRecursive>> { | ||
protected __type: 'recursive'; | ||
import type { TypeInMediumsPartial } from './type'; | ||
import { Type, __type_kind } from './type'; | ||
export declare class RecursiveType<TRecursive> extends Type<RecursiveInMediums<TRecursive>> { | ||
[__type_kind]: 'recursive'; | ||
readonly Type: Type; | ||
constructor(recursion: (Type: RecursiveType<TRecursive>) => Type); | ||
constructor(recursion: (Type: RecursiveType<TRecursive>) => TypeInMediumsPartial); | ||
} | ||
export declare function recursive<T>(recursion: (Type: RecursiveType<T>) => Type): RecursiveType<T>; | ||
declare type __RecursiveInMediums<TRecursive> = { | ||
[TMediumName in keyof XValue.Using]: __RecursiveInMedium<TRecursive, TMediumName>; | ||
export declare function recursive<T>(recursion: (Type: RecursiveType<T>) => TypeInMediumsPartial): RecursiveType<T>; | ||
declare type RecursiveInMediums<TRecursive> = { | ||
[TMediumName in XValue.UsingName]: RecursiveInMedium<TRecursive, TMediumName>; | ||
}; | ||
declare type __RecursiveInMedium<TRecursive, TMediumName extends keyof XValue.Using> = TRecursive extends Type<infer TInMediums> ? TInMediums[TMediumName] : { | ||
[TKey in keyof TRecursive]: __RecursiveInMedium<TRecursive[TKey], TMediumName>; | ||
declare type RecursiveInMedium<TRecursive, TMediumName extends XValue.UsingName> = TRecursive extends TypeInMediumsPartial<infer TInMediums> ? TInMediums[TMediumName] : { | ||
[TKey in keyof TRecursive]: RecursiveInMedium<TRecursive[TKey], TMediumName>; | ||
}; | ||
export {}; |
"use strict"; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -8,3 +9,3 @@ exports.recursive = exports.RecursiveType = void 0; | ||
super(); | ||
Object.defineProperty(this, "__type", { | ||
Object.defineProperty(this, _a, { | ||
enumerable: true, | ||
@@ -44,2 +45,3 @@ configurable: true, | ||
exports.RecursiveType = RecursiveType; | ||
_a = type_1.__type_kind; | ||
function recursive(recursion) { | ||
@@ -46,0 +48,0 @@ return new RecursiveType(recursion); |
@@ -1,8 +0,8 @@ | ||
import type { __RefinedMediumType } from '../@internal'; | ||
import type { TypeConstraint } from './type'; | ||
import { Type } from './type'; | ||
export declare class RefinedType<TType extends Type, TRefinement, TNominal> extends Type<__RefinedInMediums<TType, TRefinement, TNominal>> { | ||
readonly Type: TType; | ||
import type { RefinedMediumType } from '../@internal'; | ||
import type { TypeConstraint, TypeInMediumsPartial, TypesInMediums, __type_in_mediums } from './type'; | ||
import { Type, __type_kind } from './type'; | ||
export declare class RefinedType<TType extends TypeInMediumsPartial, TRefinement, TNominal> extends Type<RefinedInMediums<TType, TRefinement, TNominal>> { | ||
readonly Type: Type; | ||
readonly constraints: TypeConstraint[]; | ||
protected __type: 'refined'; | ||
[__type_kind]: 'refined'; | ||
constructor(Type: TType, constraints: TypeConstraint[]); | ||
@@ -30,6 +30,9 @@ private diagnoseConstraints; | ||
}>; | ||
export declare type Denominalize<T> = T extends Record<__type, infer TDenominalized> ? TDenominalized : T; | ||
declare type __RefinedInMediums<TType extends Type, TRefinement, TNominal> = TType extends Type<infer TInMediums> ? { | ||
[TMediumName in keyof XValue.Using]: __RefinedMediumType<TInMediums[TMediumName], TRefinement, TNominal>; | ||
} : never; | ||
export declare type Denominalize<T> = T extends { | ||
[__type]: infer TDenominalized; | ||
} ? TDenominalized : T; | ||
declare type RefinedInMediums<TType extends TypeInMediumsPartial, TRefinement, TNominal> = __RefinedInMediums<TType[__type_in_mediums], TRefinement, TNominal>; | ||
declare type __RefinedInMediums<TInMediums extends TypesInMediums, TRefinement, TNominal> = { | ||
[TMediumName in XValue.UsingName]: RefinedMediumType<TInMediums[TMediumName], TRefinement, TNominal>; | ||
}; | ||
export {}; |
"use strict"; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -20,3 +21,3 @@ exports.RefinedType = void 0; | ||
}); | ||
Object.defineProperty(this, "__type", { | ||
Object.defineProperty(this, _a, { | ||
enumerable: true, | ||
@@ -79,2 +80,3 @@ configurable: true, | ||
exports.RefinedType = RefinedType; | ||
_a = type_1.__type_kind; | ||
//# sourceMappingURL=refined-type.js.map |
@@ -1,12 +0,13 @@ | ||
import type { __TupleInMedium } from '../@internal'; | ||
import { Type } from './type'; | ||
export declare class TupleType<TElementTypeTuple extends Type[]> extends Type<__TupleInMediums<TElementTypeTuple>> { | ||
readonly ElementTypeTuple: TElementTypeTuple; | ||
protected __type: 'tuple'; | ||
import type { TupleInMedium } from '../@internal'; | ||
import type { TypeInMediumsPartial } from './type'; | ||
import { Type, __type_kind } from './type'; | ||
export declare class TupleType<TElementTypeTuple extends TypeInMediumsPartial[]> extends Type<TupleInMediums<TElementTypeTuple>> { | ||
readonly ElementTypeTuple: Type[]; | ||
[__type_kind]: 'tuple'; | ||
constructor(ElementTypeTuple: TElementTypeTuple); | ||
} | ||
export declare function tuple<TElementTypeTuple extends Type[]>(...ElementTypeTuple: TElementTypeTuple): TupleType<TElementTypeTuple>; | ||
declare type __TupleInMediums<TElementTypeTuple extends Type[]> = { | ||
[TMediumName in keyof XValue.Using]: __TupleInMedium<TElementTypeTuple, TMediumName>; | ||
export declare function tuple<TElementTypeTuple extends TypeInMediumsPartial[]>(...ElementTypeTuple: TElementTypeTuple): TupleType<TElementTypeTuple>; | ||
declare type TupleInMediums<TElementTypeTuple extends TypeInMediumsPartial[]> = { | ||
[TMediumName in XValue.UsingName]: TupleInMedium<TElementTypeTuple, TMediumName>; | ||
}; | ||
export {}; |
"use strict"; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -15,3 +16,3 @@ exports.tuple = exports.TupleType = void 0; | ||
}); | ||
Object.defineProperty(this, "__type", { | ||
Object.defineProperty(this, _a, { | ||
enumerable: true, | ||
@@ -111,2 +112,3 @@ configurable: true, | ||
exports.TupleType = TupleType; | ||
_a = type_1.__type_kind; | ||
function tuple(...ElementTypeTuple) { | ||
@@ -113,0 +115,0 @@ return new TupleType(ElementTypeTuple); |
@@ -1,12 +0,30 @@ | ||
import type { __ElementOrArray, __MediumTypesPackedType, __NominalPartial } from '../@internal'; | ||
import type { ElementOrArray, MediumTypesPackedType, NominalPartial } from '../@internal'; | ||
import type { Medium } from '../medium'; | ||
export declare type TypesInMediums = Record<keyof XValue.Using, unknown>; | ||
export declare type TypesInMediums = Record<XValue.UsingName, unknown>; | ||
/** | ||
* DECLARATION ONLY. | ||
*/ | ||
export declare const __type_in_mediums: unique symbol; | ||
export declare type __type_in_mediums = typeof __type_in_mediums; | ||
/** | ||
* DECLARATION ONLY. | ||
*/ | ||
export declare const __type_kind: unique symbol; | ||
export declare type __type_kind = typeof __type_kind; | ||
export interface TypeInMediumsPartial<TInMediums extends TypesInMediums = TypesInMediums> { | ||
[__type_in_mediums]: TInMediums; | ||
} | ||
export interface TypeKindPartial<TKind extends string = string> { | ||
[__type_kind]: TKind; | ||
} | ||
export declare abstract class Type<TInMediums extends TypesInMediums = TypesInMediums> { | ||
protected __static_type_in_mediums: TInMediums; | ||
refine<TNominalOrRefinement, TNominal = unknown>(constraints: __ElementOrArray<TypeConstraint<TInMediums['value']>>): __OverloadedRefinedType<this, TNominalOrRefinement, TNominal>; | ||
[__type_kind]: string; | ||
[__type_in_mediums]: TInMediums; | ||
refine<TRefinement, TNominal>(constraints: ElementOrArray<TypeConstraint<TInMediums['value']>>): RefinedType<this, TRefinement, TNominal>; | ||
refine<TNominalOrRefinement>(constraints: ElementOrArray<TypeConstraint<TInMediums['value']>>): TNominalOrRefinement extends NominalPartial ? RefinedType<this, unknown, TNominalOrRefinement> : RefinedType<this, TNominalOrRefinement, unknown>; | ||
nominal<TNominalKey extends string | symbol>(): RefinedType<this, unknown, Nominal<TNominalKey>>; | ||
optional(): OptionalType<this>; | ||
decode<TMediumName extends keyof XValue.Using, TMediumTypes extends object>(medium: Medium<TMediumName, TMediumTypes>, packed: __MediumTypesPackedType<TMediumTypes, TInMediums[TMediumName]>): TInMediums['value']; | ||
encode<TMediumName extends keyof XValue.Using, TMediumTypes extends object>(medium: Medium<TMediumName, TMediumTypes>, value: TInMediums['value']): __MediumTypesPackedType<TMediumTypes, TInMediums[TMediumName]>; | ||
transform<TFromMediumName extends keyof XValue.Using, TFromMediumTypes extends object, TToMediumName extends keyof XValue.Using, TToMediumTypes extends object>(from: Medium<TFromMediumName, TFromMediumTypes>, to: Medium<TToMediumName, TToMediumTypes>, value: __MediumTypesPackedType<TFromMediumTypes, TInMediums[TFromMediumName]>): __MediumTypesPackedType<TToMediumTypes, TInMediums[TToMediumName]>; | ||
decode<TMediumName extends XValue.UsingName, TMediumTypes extends object>(medium: Medium<TMediumName, TMediumTypes>, packed: MediumTypesPackedType<TMediumTypes, TInMediums[TMediumName]>): TInMediums['value']; | ||
encode<TMediumName extends XValue.UsingName, TMediumTypes extends object>(medium: Medium<TMediumName, TMediumTypes>, value: TInMediums['value']): MediumTypesPackedType<TMediumTypes, TInMediums[TMediumName]>; | ||
transform<TFromMediumName extends XValue.UsingName, TFromMediumTypes extends object, TToMediumName extends XValue.UsingName, TToMediumTypes extends object>(from: Medium<TFromMediumName, TFromMediumTypes>, to: Medium<TToMediumName, TToMediumTypes>, value: MediumTypesPackedType<TFromMediumTypes, TInMediums[TFromMediumName]>): MediumTypesPackedType<TToMediumTypes, TInMediums[TToMediumName]>; | ||
satisfies<T>(value: T): T; | ||
@@ -30,7 +48,5 @@ is(value: unknown): value is TInMediums['value']; | ||
} | ||
export declare type TypeOf<TType extends Type> = TType extends Type<infer TInMediums> ? TInMediums['value'] : never; | ||
declare type __OverloadedRefinedType<TType extends Type, TNominalOrRefinement, TNominal> = RefinedType<TType, TNominalOrRefinement extends __NominalPartial ? unknown : TNominalOrRefinement, TNominalOrRefinement extends __NominalPartial ? TNominalOrRefinement : TNominal>; | ||
export declare type TypeOf<TType extends TypeInMediumsPartial> = TType[__type_in_mediums]['value']; | ||
import { OptionalType } from './optional-type'; | ||
import type { Nominal } from './refined-type'; | ||
import { RefinedType } from './refined-type'; | ||
export {}; |
"use strict"; | ||
/* eslint-disable @mufan/import-groups */ | ||
var _a, _b; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -7,3 +8,3 @@ exports.TypeConstraintError = exports.Type = void 0; | ||
constructor() { | ||
Object.defineProperty(this, "__static_type_in_mediums", { | ||
Object.defineProperty(this, _a, { | ||
enumerable: true, | ||
@@ -14,2 +15,8 @@ configurable: true, | ||
}); | ||
Object.defineProperty(this, _b, { | ||
enumerable: true, | ||
configurable: true, | ||
writable: true, | ||
value: void 0 | ||
}); | ||
} | ||
@@ -63,2 +70,3 @@ refine(constraints) { | ||
exports.Type = Type; | ||
_a = exports.__type_kind, _b = exports.__type_in_mediums; | ||
class TypeConstraintError extends TypeError { | ||
@@ -65,0 +73,0 @@ constructor(_message, issues) { |
@@ -1,12 +0,21 @@ | ||
import type { __TupleInMedium } from '../@internal'; | ||
import { Type } from './type'; | ||
export declare class UnionType<TTypeTuple extends [Type, Type, ...Type[]]> extends Type<__UnionInMediums<TTypeTuple>> { | ||
readonly TypeTuple: TTypeTuple; | ||
protected __type: 'union'; | ||
import type { TupleInMedium } from '../@internal'; | ||
import type { TypeInMediumsPartial } from './type'; | ||
import { Type, __type_kind } from './type'; | ||
export declare class UnionType<TTypeTuple extends [ | ||
TypeInMediumsPartial, | ||
TypeInMediumsPartial, | ||
...TypeInMediumsPartial[] | ||
]> extends Type<UnionInMediums<TTypeTuple>> { | ||
readonly TypeTuple: Type[]; | ||
[__type_kind]: 'union'; | ||
constructor(TypeTuple: TTypeTuple); | ||
} | ||
export declare function union<TTypeTuple extends [Type, Type, ...Type[]]>(...Types: TTypeTuple): UnionType<TTypeTuple>; | ||
declare type __UnionInMediums<TTypeTuple extends Type[]> = { | ||
[TKey in keyof XValue.Using]: __TupleInMedium<TTypeTuple, TKey>[number]; | ||
export declare function union<TTypeTuple extends [ | ||
TypeInMediumsPartial, | ||
TypeInMediumsPartial, | ||
...TypeInMediumsPartial[] | ||
]>(...Types: TTypeTuple): UnionType<TTypeTuple>; | ||
declare type UnionInMediums<TTypeTuple extends TypeInMediumsPartial[]> = { | ||
[TKey in XValue.UsingName]: TupleInMedium<TTypeTuple, TKey>[number]; | ||
}; | ||
export {}; |
"use strict"; | ||
var _a; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
@@ -17,3 +18,3 @@ exports.union = exports.UnionType = void 0; | ||
}); | ||
Object.defineProperty(this, "__type", { | ||
Object.defineProperty(this, _a, { | ||
enumerable: true, | ||
@@ -103,2 +104,3 @@ configurable: true, | ||
exports.UnionType = UnionType; | ||
_a = type_1.__type_kind; | ||
function union(...Types) { | ||
@@ -105,0 +107,0 @@ return new UnionType(Types); |
@@ -18,2 +18,3 @@ declare global { | ||
} | ||
type UsingName = keyof Using; | ||
} | ||
@@ -20,0 +21,0 @@ } |
@@ -1,3 +0,3 @@ | ||
import type { __NominalPartial } from './@internal'; | ||
import type { Type, TypeOf, __nominal, __type } from './type'; | ||
import type { NominalPartial } from './@internal'; | ||
import type { TypeInMediumsPartial, TypeOf, __nominal, __type } from './type'; | ||
import { RefinedType } from './type'; | ||
@@ -10,3 +10,3 @@ import { boolean, number, string, unknown } from './types'; | ||
export declare function equal<T>(comparison: T): RefinedType<typeof unknown, T, unknown>; | ||
export declare function equal<T extends TypeOf<TType>, TType extends Type>(comparison: T, Type: TType): RefinedType<TType, T, unknown>; | ||
export declare type TransformNominal<TFrom, T> = TFrom extends __NominalPartial ? T & Record<__type, T> & Record<__nominal, TFrom[__nominal]> : T; | ||
export declare function equal<T extends TypeOf<TType>, TType extends TypeInMediumsPartial>(comparison: T, Type: TType): RefinedType<TType, T, unknown>; | ||
export declare type TransformNominal<TFrom, T> = TFrom extends NominalPartial ? T & Record<__type, T> & Record<__nominal, TFrom[__nominal]> : T; |
{ | ||
"name": "x-value", | ||
"version": "0.0.1-20", | ||
"version": "0.0.1-21", | ||
"repository": "https://github.com/vilic/x-value.git", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -1,2 +0,7 @@ | ||
import type {Denominalize, Type, __nominal, __type} from './type'; | ||
import type { | ||
Denominalize, | ||
TypeInMediumsPartial, | ||
__nominal, | ||
__type, | ||
} from './type'; | ||
@@ -7,15 +12,15 @@ export const hasOwnProperty = Object.prototype.hasOwnProperty; | ||
export type __RefinedMediumType<TInMedium, TRefinement, TNominal> = | ||
export type RefinedMediumType<TInMedium, TRefinement, TNominal> = | ||
unknown extends TNominal | ||
? TInMedium & TRefinement | ||
: __RefinedNominalType<TInMedium & TRefinement, TNominal>; | ||
: RefinedNominalType<TInMedium & TRefinement, TNominal>; | ||
export type __RefinedNominalType<T, TNominal> = T & | ||
type RefinedNominalType<T, TNominal> = T & | ||
(TNominal & Record<__type, Denominalize<T>>); | ||
export type __TupleInMedium< | ||
TTypeTuple extends Type[], | ||
TMediumName extends keyof XValue.Using, | ||
export type TupleInMedium< | ||
TTypeTuple extends TypeInMediumsPartial[], | ||
TMediumName extends XValue.UsingName, | ||
> = { | ||
[TIndex in keyof TTypeTuple]: TTypeTuple[TIndex] extends Type< | ||
[TIndex in keyof TTypeTuple]: TTypeTuple[TIndex] extends TypeInMediumsPartial< | ||
infer TElementInMediums | ||
@@ -27,3 +32,3 @@ > | ||
export type __UnionToIntersection<TUnion> = ( | ||
export type UnionToIntersection<TUnion> = ( | ||
TUnion extends unknown ? (_: TUnion) => unknown : never | ||
@@ -34,3 +39,3 @@ ) extends (_: infer TIntersection) => unknown | ||
export type __MediumTypesPackedType< | ||
export type MediumTypesPackedType< | ||
TMediumTypes, | ||
@@ -44,5 +49,5 @@ TFallback = never, | ||
export type __ElementOrArray<T> = T | T[]; | ||
export type ElementOrArray<T> = T | T[]; | ||
export type __NominalPartial = Record<__nominal, unknown>; | ||
export type NominalPartial = Record<__nominal, unknown>; | ||
@@ -49,0 +54,0 @@ export function merge(partials: unknown[]): unknown { |
@@ -1,3 +0,3 @@ | ||
import type {__MediumTypesPackedType} from './@internal'; | ||
import type {Type} from './type'; | ||
import type {MediumTypesPackedType} from './@internal'; | ||
import type {TypeInMediumsPartial, __type_in_mediums} from './type'; | ||
@@ -15,3 +15,3 @@ export const atomicTypeSymbol = Symbol(); | ||
export type GeneralUsingMedium = Medium<keyof XValue.Using, object>; | ||
export type GeneralUsingMedium = Medium<XValue.UsingName, object>; | ||
@@ -35,3 +35,3 @@ export type MediumAtomicCodecs<TMediumTypes extends object> = { | ||
> { | ||
packing?: MediumPacking<__MediumTypesPackedType<TMediumTypes>>; | ||
packing?: MediumPacking<MediumTypesPackedType<TMediumTypes>>; | ||
codecs: MediumAtomicCodecs<TMediumTypes>; | ||
@@ -44,3 +44,3 @@ } | ||
> { | ||
private packing: MediumPacking<__MediumTypesPackedType<TTypes>> | undefined; | ||
private packing: MediumPacking<MediumTypesPackedType<TTypes>> | undefined; | ||
private codecs: MediumAtomicCodecs<TTypes>; | ||
@@ -95,7 +95,7 @@ | ||
unpack(packed: __MediumTypesPackedType<TTypes>): unknown { | ||
unpack(packed: MediumTypesPackedType<TTypes>): unknown { | ||
return this.packing ? this.packing.unpack(packed) : packed; | ||
} | ||
pack(unpacked: unknown): __MediumTypesPackedType<TTypes>; | ||
pack(unpacked: unknown): MediumTypesPackedType<TTypes>; | ||
pack(unpacked: unknown): unknown { | ||
@@ -131,4 +131,4 @@ return this.packing ? this.packing.pack(unpacked) : unpacked; | ||
export type MediumTypeOf< | ||
TType extends Type, | ||
TMediumName extends keyof XValue.Using, | ||
> = TType extends Type<infer TInMediums> ? TInMediums[TMediumName] : never; | ||
TType extends TypeInMediumsPartial, | ||
TMediumName extends XValue.UsingName, | ||
> = TType[__type_in_mediums][TMediumName]; |
import {toString} from '../@internal'; | ||
import type {Medium} from '../medium'; | ||
import type {TypeIssue, TypePath} from './type'; | ||
import {Type} from './type'; | ||
import type { | ||
TypeInMediumsPartial, | ||
TypeIssue, | ||
TypePath, | ||
__type_in_mediums, | ||
} from './type'; | ||
import {Type, __type_kind} from './type'; | ||
export class ArrayType<TElementType extends Type> extends Type< | ||
__ArrayInMediums<TElementType> | ||
export class ArrayType<TElementType extends TypeInMediumsPartial> extends Type< | ||
ArrayInMediums<TElementType> | ||
> { | ||
protected __type!: 'array'; | ||
[__type_kind]!: 'array'; | ||
constructor(readonly ElementType: TElementType) { | ||
constructor(ElementType: TElementType); | ||
constructor(readonly ElementType: Type) { | ||
super(); | ||
@@ -160,3 +166,3 @@ } | ||
export function array<TElementType extends Type>( | ||
export function array<TElementType extends TypeInMediumsPartial>( | ||
ElementType: TElementType, | ||
@@ -167,6 +173,4 @@ ): ArrayType<TElementType> { | ||
type __ArrayInMediums<TElementType extends Type> = TElementType extends Type< | ||
infer TElementInMediums | ||
> | ||
? {[TKey in keyof XValue.Using]: TElementInMediums[TKey][]} | ||
: never; | ||
type ArrayInMediums<TElementType extends TypeInMediumsPartial> = { | ||
[TKey in XValue.UsingName]: TElementType[__type_in_mediums][TKey][]; | ||
}; |
import type {Medium} from '../medium'; | ||
import type {TypeConstraint, TypeIssue, TypePath} from './type'; | ||
import {Type} from './type'; | ||
import {Type, __type_kind} from './type'; | ||
export class AtomicType<TSymbol extends symbol> extends Type< | ||
__AtomicInMediums<TSymbol> | ||
AtomicInMediums<TSymbol> | ||
> { | ||
protected __type!: 'atomic'; | ||
[__type_kind]!: 'atomic'; | ||
@@ -133,4 +133,4 @@ constructor(symbol: TSymbol, constraints: TypeConstraint[]); | ||
type __AtomicInMediums<TSymbol extends symbol> = { | ||
[TMediumName in keyof XValue.Using]: __AtomicInMedium< | ||
type AtomicInMediums<TSymbol extends symbol> = { | ||
[TMediumName in XValue.UsingName]: AtomicInMedium< | ||
TSymbol, | ||
@@ -141,5 +141,5 @@ XValue.Using[TMediumName] | ||
type __AtomicInMedium< | ||
type AtomicInMedium< | ||
TSymbol extends symbol, | ||
TMediumTypes, | ||
> = TSymbol extends keyof TMediumTypes ? TMediumTypes[TSymbol] : never; |
@@ -1,14 +0,19 @@ | ||
import type {__TupleInMedium, __UnionToIntersection} from '../@internal'; | ||
import type {TupleInMedium, UnionToIntersection} from '../@internal'; | ||
import {merge} from '../@internal'; | ||
import type {Medium} from '../medium'; | ||
import type {TypeIssue, TypePath} from './type'; | ||
import {Type} from './type'; | ||
import type {TypeInMediumsPartial, TypeIssue, TypePath} from './type'; | ||
import {Type, __type_kind} from './type'; | ||
export class IntersectionType< | ||
TTypeTuple extends [Type, Type, ...Type[]], | ||
> extends Type<__IntersectionInMediums<TTypeTuple>> { | ||
protected __type!: 'intersection'; | ||
TTypeTuple extends [ | ||
TypeInMediumsPartial, | ||
TypeInMediumsPartial, | ||
...TypeInMediumsPartial[], | ||
], | ||
> extends Type<IntersectionInMediums<TTypeTuple>> { | ||
[__type_kind]!: 'intersection'; | ||
constructor(readonly TypeTuple: TTypeTuple) { | ||
constructor(TypeTuple: TTypeTuple); | ||
constructor(readonly TypeTuple: Type[]) { | ||
if (TypeTuple.length < 2) { | ||
@@ -91,12 +96,16 @@ throw new TypeError('Expecting at least 2 types for intersection type'); | ||
export function intersection<TTypeTuple extends [Type, Type, ...Type[]]>( | ||
...Types: TTypeTuple | ||
): IntersectionType<TTypeTuple> { | ||
export function intersection< | ||
TTypeTuple extends [ | ||
TypeInMediumsPartial, | ||
TypeInMediumsPartial, | ||
...TypeInMediumsPartial[], | ||
], | ||
>(...Types: TTypeTuple): IntersectionType<TTypeTuple> { | ||
return new IntersectionType(Types); | ||
} | ||
type __IntersectionInMediums<TTypeTuple extends Type[]> = { | ||
[TMediumName in keyof XValue.Using]: __UnionToIntersection< | ||
__TupleInMedium<TTypeTuple, TMediumName>[number] | ||
type IntersectionInMediums<TTypeTuple extends TypeInMediumsPartial[]> = { | ||
[TMediumName in XValue.UsingName]: UnionToIntersection< | ||
TupleInMedium<TTypeTuple, TMediumName>[number] | ||
>; | ||
}; |
@@ -5,16 +5,23 @@ import {toString} from '../@internal'; | ||
import {OptionalType} from './optional-type'; | ||
import type {TypeIssue, TypePath} from './type'; | ||
import {Type} from './type'; | ||
import type { | ||
TypeInMediumsPartial, | ||
TypeIssue, | ||
TypeKindPartial, | ||
TypePath, | ||
__type_in_mediums, | ||
} from './type'; | ||
import {Type, __type_kind} from './type'; | ||
export class ObjectType<TDefinition extends Record<string, Type>> extends Type< | ||
__ObjectInMediums<TDefinition> | ||
> { | ||
protected __type!: 'object'; | ||
export class ObjectType< | ||
TDefinition extends Record<string, TypeInMediumsPartial>, | ||
> extends Type<ObjectInMediums<TDefinition>> { | ||
[__type_kind]!: 'object'; | ||
constructor(readonly definition: TDefinition) { | ||
constructor(definition: TDefinition); | ||
constructor(readonly definition: Record<string, Type>) { | ||
super(); | ||
} | ||
partial(): ObjectType<__Partial<TDefinition>>; | ||
partial(): ObjectType<Record<string, OptionalType<Type>>> { | ||
partial(): ObjectType<DefinitionPartial<TDefinition>>; | ||
partial(): ObjectType<Record<string, any>> { | ||
let definition = Object.fromEntries( | ||
@@ -33,3 +40,3 @@ Object.entries(this.definition).map(([key, Type]) => [ | ||
): ObjectType<Pick<TDefinition, TKeys[number]>>; | ||
pick(...keys: string[]): ObjectType<Record<string, Type>> { | ||
pick(...keys: string[]): ObjectType<Record<string, TypeInMediumsPartial>> { | ||
let keySet = new Set(keys); | ||
@@ -47,3 +54,3 @@ | ||
): ObjectType<Omit<TDefinition, TKeys[number]>>; | ||
omit(...keys: string[]): ObjectType<Record<string, Type>> { | ||
omit(...keys: string[]): ObjectType<Record<string, TypeInMediumsPartial>> { | ||
let keySet = new Set(keys); | ||
@@ -202,35 +209,25 @@ | ||
export function object<TTypeDefinition extends Record<string, Type>>( | ||
definition: TTypeDefinition, | ||
): ObjectType<TTypeDefinition> { | ||
export function object< | ||
TTypeDefinition extends Record<string, TypeInMediumsPartial>, | ||
>(definition: TTypeDefinition): ObjectType<TTypeDefinition> { | ||
return new ObjectType(definition); | ||
} | ||
type __ObjectInMediums<TDefinition extends Record<string, Type>> = { | ||
[TMediumName in keyof XValue.Using]: __ObjectInMedium< | ||
TDefinition, | ||
TMediumName | ||
>; | ||
}; | ||
type ObjectInMediums<TDefinition extends Record<string, TypeInMediumsPartial>> = | ||
{ | ||
[TMediumName in XValue.UsingName]: ObjectInMedium<TDefinition, TMediumName>; | ||
}; | ||
type __ObjectInMedium< | ||
TDefinition extends Record<string, Type>, | ||
TMediumName extends keyof XValue.Using, | ||
type ObjectInMedium< | ||
TDefinition extends Record<string, TypeInMediumsPartial>, | ||
TMediumName extends XValue.UsingName, | ||
> = { | ||
[TKey in __KeyOfOptional<TDefinition>]?: TDefinition[TKey] extends OptionalType< | ||
Type<infer TInMediums> | ||
> | ||
? TInMediums[TMediumName] | ||
: never; | ||
[TKey in KeyOfOptional<TDefinition>]?: TDefinition[TKey][__type_in_mediums][TMediumName]; | ||
} & { | ||
[TKey in __KeyOfNonOptional<TDefinition>]: TDefinition[TKey] extends Type< | ||
infer TInMediums | ||
> | ||
? TInMediums[TMediumName] | ||
: never; | ||
[TKey in KeyOfNonOptional<TDefinition>]: TDefinition[TKey][__type_in_mediums][TMediumName]; | ||
}; | ||
type __KeyOfOptional<TType> = Extract< | ||
type KeyOfOptional<TType> = Extract< | ||
{ | ||
[TKey in keyof TType]: TType[TKey] extends OptionalType<Type> | ||
[TKey in keyof TType]: TType[TKey] extends TypeKindPartial<'optional'> | ||
? TKey | ||
@@ -242,5 +239,5 @@ : never; | ||
type __KeyOfNonOptional<TType> = Extract< | ||
type KeyOfNonOptional<TType> = Extract< | ||
{ | ||
[TKey in keyof TType]: TType[TKey] extends OptionalType<Type> | ||
[TKey in keyof TType]: TType[TKey] extends TypeKindPartial<'optional'> | ||
? never | ||
@@ -252,6 +249,8 @@ : TKey; | ||
type __Partial<TDefinition extends Record<string, Type>> = { | ||
[TKey in keyof TDefinition]: TDefinition[TKey] extends OptionalType<Type> | ||
type DefinitionPartial< | ||
TDefinition extends Record<string, TypeInMediumsPartial>, | ||
> = { | ||
[TKey in keyof TDefinition]: TDefinition[TKey] extends TypeKindPartial<'optional'> | ||
? TDefinition[TKey] | ||
: OptionalType<TDefinition[TKey]>; | ||
}; |
import type {Medium} from '../medium'; | ||
import type {TypeIssue, TypePath} from './type'; | ||
import {Type} from './type'; | ||
import type { | ||
TypeInMediumsPartial, | ||
TypeIssue, | ||
TypePath, | ||
__type_in_mediums, | ||
} from './type'; | ||
import {Type, __type_kind} from './type'; | ||
export class OptionalType<TType extends Type> extends Type< | ||
__OptionalInMediums<TType> | ||
export class OptionalType<TType extends TypeInMediumsPartial> extends Type< | ||
OptionalInMediums<TType> | ||
> { | ||
protected __type!: 'optional'; | ||
[__type_kind]!: 'optional'; | ||
constructor(readonly Type: TType) { | ||
constructor(Type: TType); | ||
constructor(readonly Type: Type) { | ||
super(); | ||
@@ -70,12 +76,12 @@ } | ||
export function optional<TType extends Type>(Type: TType): OptionalType<TType> { | ||
export function optional<TType extends TypeInMediumsPartial>( | ||
Type: TType, | ||
): OptionalType<TType> { | ||
return new OptionalType(Type); | ||
} | ||
type __OptionalInMediums<TType extends Type> = TType extends Type< | ||
infer TInMediums | ||
> | ||
? { | ||
[TMediumName in keyof XValue.Using]: TInMediums[TMediumName] | undefined; | ||
} | ||
: never; | ||
type OptionalInMediums<TType extends TypeInMediumsPartial> = { | ||
[TMediumName in XValue.UsingName]: | ||
| TType[__type_in_mediums][TMediumName] | ||
| undefined; | ||
}; |
import {toString} from '../@internal'; | ||
import type {Medium} from '../medium'; | ||
import type {TypeIssue, TypePath} from './type'; | ||
import {Type} from './type'; | ||
import type { | ||
TypeInMediumsPartial, | ||
TypeIssue, | ||
TypePath, | ||
__type_in_mediums, | ||
} from './type'; | ||
import {Type, __type_kind} from './type'; | ||
export class RecordType< | ||
TKeyType extends Type, | ||
TValueType extends Type, | ||
> extends Type<__RecordInMediums<TKeyType, TValueType>> { | ||
protected __type!: 'record'; | ||
TKeyType extends TypeInMediumsPartial, | ||
TValueType extends TypeInMediumsPartial, | ||
> extends Type<RecordInMediums<TKeyType, TValueType>> { | ||
[__type_kind]!: 'record'; | ||
constructor(readonly Key: TKeyType, readonly Value: TValueType) { | ||
constructor(Key: TKeyType, Value: TValueType); | ||
constructor(readonly Key: Type, readonly Value: Type) { | ||
super(); | ||
@@ -174,17 +180,16 @@ } | ||
export function record<TKeyType extends Type, TValueType extends Type>( | ||
Key: TKeyType, | ||
Value: TValueType, | ||
): RecordType<TKeyType, TValueType> { | ||
export function record< | ||
TKeyType extends TypeInMediumsPartial, | ||
TValueType extends TypeInMediumsPartial, | ||
>(Key: TKeyType, Value: TValueType): RecordType<TKeyType, TValueType> { | ||
return new RecordType(Key, Value); | ||
} | ||
type __RecordInMediums<TKeyType extends Type, TValueType extends Type> = { | ||
[TMediumName in keyof XValue.Using]: Record< | ||
TKeyType extends Type<infer TKeyInMediums> | ||
? Extract<TKeyInMediums[TMediumName], string | symbol> | ||
: never, | ||
TValueType extends Type<infer TValueInMediums> | ||
? TValueInMediums[TMediumName] | ||
: never | ||
type RecordInMediums< | ||
TKeyType extends TypeInMediumsPartial, | ||
TValueType extends TypeInMediumsPartial, | ||
> = { | ||
[TMediumName in XValue.UsingName]: Record< | ||
Extract<TKeyType[__type_in_mediums][TMediumName], string | symbol>, | ||
TValueType[__type_in_mediums][TMediumName] | ||
>; | ||
@@ -191,0 +196,0 @@ }; |
import type {Medium} from '../medium'; | ||
import type {TypeIssue, TypePath} from './type'; | ||
import {Type} from './type'; | ||
import type {TypeInMediumsPartial, TypeIssue, TypePath} from './type'; | ||
import {Type, __type_kind} from './type'; | ||
export class RecursiveType<TRecursive> extends Type< | ||
__RecursiveInMediums<TRecursive> | ||
RecursiveInMediums<TRecursive> | ||
> { | ||
protected __type!: 'recursive'; | ||
[__type_kind]!: 'recursive'; | ||
readonly Type: Type; | ||
constructor( | ||
recursion: (Type: RecursiveType<TRecursive>) => TypeInMediumsPartial, | ||
); | ||
constructor(recursion: (Type: RecursiveType<TRecursive>) => Type) { | ||
@@ -63,3 +66,3 @@ super(); | ||
export function recursive<T>( | ||
recursion: (Type: RecursiveType<T>) => Type, | ||
recursion: (Type: RecursiveType<T>) => TypeInMediumsPartial, | ||
): RecursiveType<T> { | ||
@@ -69,16 +72,13 @@ return new RecursiveType(recursion); | ||
type __RecursiveInMediums<TRecursive> = { | ||
[TMediumName in keyof XValue.Using]: __RecursiveInMedium< | ||
TRecursive, | ||
TMediumName | ||
>; | ||
type RecursiveInMediums<TRecursive> = { | ||
[TMediumName in XValue.UsingName]: RecursiveInMedium<TRecursive, TMediumName>; | ||
}; | ||
type __RecursiveInMedium< | ||
type RecursiveInMedium< | ||
TRecursive, | ||
TMediumName extends keyof XValue.Using, | ||
> = TRecursive extends Type<infer TInMediums> | ||
TMediumName extends XValue.UsingName, | ||
> = TRecursive extends TypeInMediumsPartial<infer TInMediums> | ||
? TInMediums[TMediumName] | ||
: { | ||
[TKey in keyof TRecursive]: __RecursiveInMedium< | ||
[TKey in keyof TRecursive]: RecursiveInMedium< | ||
TRecursive[TKey], | ||
@@ -85,0 +85,0 @@ TMediumName |
@@ -1,15 +0,23 @@ | ||
import type {__RefinedMediumType} from '../@internal'; | ||
import type {RefinedMediumType} from '../@internal'; | ||
import type {Medium} from '../medium'; | ||
import type {TypeConstraint, TypeIssue, TypePath} from './type'; | ||
import {Type} from './type'; | ||
import type { | ||
TypeConstraint, | ||
TypeInMediumsPartial, | ||
TypeIssue, | ||
TypePath, | ||
TypesInMediums, | ||
__type_in_mediums, | ||
} from './type'; | ||
import {Type, __type_kind} from './type'; | ||
export class RefinedType< | ||
TType extends Type, | ||
TType extends TypeInMediumsPartial, | ||
TRefinement, | ||
TNominal, | ||
> extends Type<__RefinedInMediums<TType, TRefinement, TNominal>> { | ||
protected __type!: 'refined'; | ||
> extends Type<RefinedInMediums<TType, TRefinement, TNominal>> { | ||
[__type_kind]!: 'refined'; | ||
constructor(readonly Type: TType, readonly constraints: TypeConstraint[]) { | ||
constructor(Type: TType, constraints: TypeConstraint[]); | ||
constructor(readonly Type: Type, readonly constraints: TypeConstraint[]) { | ||
super(); | ||
@@ -122,25 +130,24 @@ } | ||
(unknown extends T ? unknown : Record<__type, T>) & | ||
Record< | ||
__nominal, | ||
{ | ||
[TKey in TNominalKey]: true; | ||
} | ||
>; | ||
Record<__nominal, {[TKey in TNominalKey]: true}>; | ||
export type Denominalize<T> = T extends Record<__type, infer TDenominalized> | ||
export type Denominalize<T> = T extends {[__type]: infer TDenominalized} | ||
? TDenominalized | ||
: T; | ||
type RefinedInMediums< | ||
TType extends TypeInMediumsPartial, | ||
TRefinement, | ||
TNominal, | ||
> = __RefinedInMediums<TType[__type_in_mediums], TRefinement, TNominal>; | ||
type __RefinedInMediums< | ||
TType extends Type, | ||
TInMediums extends TypesInMediums, | ||
TRefinement, | ||
TNominal, | ||
> = TType extends Type<infer TInMediums> | ||
? { | ||
[TMediumName in keyof XValue.Using]: __RefinedMediumType< | ||
TInMediums[TMediumName], | ||
TRefinement, | ||
TNominal | ||
>; | ||
} | ||
: never; | ||
> = { | ||
[TMediumName in XValue.UsingName]: RefinedMediumType< | ||
TInMediums[TMediumName], | ||
TRefinement, | ||
TNominal | ||
>; | ||
}; |
@@ -1,14 +0,15 @@ | ||
import type {__TupleInMedium} from '../@internal'; | ||
import type {TupleInMedium} from '../@internal'; | ||
import {toString} from '../@internal'; | ||
import type {Medium} from '../medium'; | ||
import type {TypeIssue, TypePath} from './type'; | ||
import {Type} from './type'; | ||
import type {TypeInMediumsPartial, TypeIssue, TypePath} from './type'; | ||
import {Type, __type_kind} from './type'; | ||
export class TupleType<TElementTypeTuple extends Type[]> extends Type< | ||
__TupleInMediums<TElementTypeTuple> | ||
> { | ||
protected __type!: 'tuple'; | ||
export class TupleType< | ||
TElementTypeTuple extends TypeInMediumsPartial[], | ||
> extends Type<TupleInMediums<TElementTypeTuple>> { | ||
[__type_kind]!: 'tuple'; | ||
constructor(readonly ElementTypeTuple: TElementTypeTuple) { | ||
constructor(ElementTypeTuple: TElementTypeTuple); | ||
constructor(readonly ElementTypeTuple: Type[]) { | ||
super(); | ||
@@ -158,3 +159,3 @@ } | ||
export function tuple<TElementTypeTuple extends Type[]>( | ||
export function tuple<TElementTypeTuple extends TypeInMediumsPartial[]>( | ||
...ElementTypeTuple: TElementTypeTuple | ||
@@ -165,4 +166,4 @@ ): TupleType<TElementTypeTuple> { | ||
type __TupleInMediums<TElementTypeTuple extends Type[]> = { | ||
[TMediumName in keyof XValue.Using]: __TupleInMedium< | ||
type TupleInMediums<TElementTypeTuple extends TypeInMediumsPartial[]> = { | ||
[TMediumName in XValue.UsingName]: TupleInMedium< | ||
TElementTypeTuple, | ||
@@ -169,0 +170,0 @@ TMediumName |
/* eslint-disable @mufan/import-groups */ | ||
import type { | ||
__ElementOrArray, | ||
__MediumTypesPackedType, | ||
__NominalPartial, | ||
ElementOrArray, | ||
MediumTypesPackedType, | ||
NominalPartial, | ||
} from '../@internal'; | ||
import type {Medium} from '../medium'; | ||
export type TypesInMediums = Record<keyof XValue.Using, unknown>; | ||
export type TypesInMediums = Record<XValue.UsingName, unknown>; | ||
/** | ||
* DECLARATION ONLY. | ||
*/ | ||
export declare const __type_in_mediums: unique symbol; | ||
export type __type_in_mediums = typeof __type_in_mediums; | ||
/** | ||
* DECLARATION ONLY. | ||
*/ | ||
export declare const __type_kind: unique symbol; | ||
export type __type_kind = typeof __type_kind; | ||
export interface TypeInMediumsPartial< | ||
TInMediums extends TypesInMediums = TypesInMediums, | ||
> { | ||
[__type_in_mediums]: TInMediums; | ||
} | ||
export interface TypeKindPartial<TKind extends string = string> { | ||
[__type_kind]: TKind; | ||
} | ||
export abstract class Type<TInMediums extends TypesInMediums = TypesInMediums> { | ||
protected __static_type_in_mediums!: TInMediums; | ||
[__type_kind]!: string; | ||
refine<TNominalOrRefinement, TNominal = unknown>( | ||
constraints: __ElementOrArray<TypeConstraint<TInMediums['value']>>, | ||
): __OverloadedRefinedType<this, TNominalOrRefinement, TNominal> { | ||
[__type_in_mediums]!: TInMediums; | ||
refine<TRefinement, TNominal>( | ||
constraints: ElementOrArray<TypeConstraint<TInMediums['value']>>, | ||
): RefinedType<this, TRefinement, TNominal>; | ||
refine<TNominalOrRefinement>( | ||
constraints: ElementOrArray<TypeConstraint<TInMediums['value']>>, | ||
): TNominalOrRefinement extends NominalPartial | ||
? RefinedType<this, unknown, TNominalOrRefinement> | ||
: RefinedType<this, TNominalOrRefinement, unknown>; | ||
refine( | ||
constraints: ElementOrArray<TypeConstraint<TInMediums['value']>>, | ||
): RefinedType<TypeInMediumsPartial, unknown, unknown> { | ||
return new RefinedType( | ||
@@ -36,5 +70,5 @@ this, | ||
decode<TMediumName extends keyof XValue.Using, TMediumTypes extends object>( | ||
decode<TMediumName extends XValue.UsingName, TMediumTypes extends object>( | ||
medium: Medium<TMediumName, TMediumTypes>, | ||
packed: __MediumTypesPackedType<TMediumTypes, TInMediums[TMediumName]>, | ||
packed: MediumTypesPackedType<TMediumTypes, TInMediums[TMediumName]>, | ||
): TInMediums['value']; | ||
@@ -52,6 +86,6 @@ decode(medium: Medium, packed: unknown): unknown { | ||
encode<TMediumName extends keyof XValue.Using, TMediumTypes extends object>( | ||
encode<TMediumName extends XValue.UsingName, TMediumTypes extends object>( | ||
medium: Medium<TMediumName, TMediumTypes>, | ||
value: TInMediums['value'], | ||
): __MediumTypesPackedType<TMediumTypes, TInMediums[TMediumName]>; | ||
): MediumTypesPackedType<TMediumTypes, TInMediums[TMediumName]>; | ||
encode(medium: Medium, value: unknown): unknown { | ||
@@ -68,5 +102,5 @@ let [unpacked, issues] = this._encode(medium, value, [], true); | ||
transform< | ||
TFromMediumName extends keyof XValue.Using, | ||
TFromMediumName extends XValue.UsingName, | ||
TFromMediumTypes extends object, | ||
TToMediumName extends keyof XValue.Using, | ||
TToMediumName extends XValue.UsingName, | ||
TToMediumTypes extends object, | ||
@@ -76,7 +110,4 @@ >( | ||
to: Medium<TToMediumName, TToMediumTypes>, | ||
value: __MediumTypesPackedType< | ||
TFromMediumTypes, | ||
TInMediums[TFromMediumName] | ||
>, | ||
): __MediumTypesPackedType<TToMediumTypes, TInMediums[TToMediumName]>; | ||
value: MediumTypesPackedType<TFromMediumTypes, TInMediums[TFromMediumName]>, | ||
): MediumTypesPackedType<TToMediumTypes, TInMediums[TToMediumName]>; | ||
transform(from: Medium, to: Medium, packed: unknown): unknown { | ||
@@ -183,20 +214,5 @@ let unpacked = from.unpack(packed); | ||
export type TypeOf<TType extends Type> = TType extends Type<infer TInMediums> | ||
? TInMediums['value'] | ||
: never; | ||
export type TypeOf<TType extends TypeInMediumsPartial> = | ||
TType[__type_in_mediums]['value']; | ||
type __OverloadedRefinedType< | ||
TType extends Type, | ||
TNominalOrRefinement, | ||
TNominal, | ||
> = RefinedType< | ||
TType, | ||
TNominalOrRefinement extends __NominalPartial | ||
? unknown | ||
: TNominalOrRefinement, | ||
TNominalOrRefinement extends __NominalPartial | ||
? TNominalOrRefinement | ||
: TNominal | ||
>; | ||
// Make sure code circularly referenced accessing type.ts after exports ready. | ||
@@ -203,0 +219,0 @@ |
@@ -1,13 +0,18 @@ | ||
import type {__TupleInMedium} from '../@internal'; | ||
import type {TupleInMedium} from '../@internal'; | ||
import type {Medium} from '../medium'; | ||
import type {TypeIssue, TypePath} from './type'; | ||
import {Type} from './type'; | ||
import type {TypeInMediumsPartial, TypeIssue, TypePath} from './type'; | ||
import {Type, __type_kind} from './type'; | ||
export class UnionType<TTypeTuple extends [Type, Type, ...Type[]]> extends Type< | ||
__UnionInMediums<TTypeTuple> | ||
> { | ||
protected __type!: 'union'; | ||
export class UnionType< | ||
TTypeTuple extends [ | ||
TypeInMediumsPartial, | ||
TypeInMediumsPartial, | ||
...TypeInMediumsPartial[], | ||
], | ||
> extends Type<UnionInMediums<TTypeTuple>> { | ||
[__type_kind]!: 'union'; | ||
constructor(readonly TypeTuple: TTypeTuple) { | ||
constructor(TypeTuple: TTypeTuple); | ||
constructor(readonly TypeTuple: Type[]) { | ||
if (TypeTuple.length < 2) { | ||
@@ -140,10 +145,14 @@ throw new TypeError('Expecting at least 2 type for union type'); | ||
export function union<TTypeTuple extends [Type, Type, ...Type[]]>( | ||
...Types: TTypeTuple | ||
): UnionType<TTypeTuple> { | ||
export function union< | ||
TTypeTuple extends [ | ||
TypeInMediumsPartial, | ||
TypeInMediumsPartial, | ||
...TypeInMediumsPartial[], | ||
], | ||
>(...Types: TTypeTuple): UnionType<TTypeTuple> { | ||
return new UnionType(Types); | ||
} | ||
type __UnionInMediums<TTypeTuple extends Type[]> = { | ||
[TKey in keyof XValue.Using]: __TupleInMedium<TTypeTuple, TKey>[number]; | ||
type UnionInMediums<TTypeTuple extends TypeInMediumsPartial[]> = { | ||
[TKey in XValue.UsingName]: TupleInMedium<TTypeTuple, TKey>[number]; | ||
}; |
@@ -22,2 +22,4 @@ import {toString} from './@internal'; | ||
} | ||
type UsingName = keyof Using; | ||
} | ||
@@ -24,0 +26,0 @@ } |
import isEqual from 'lodash.isequal'; | ||
import type {__NominalPartial} from './@internal'; | ||
import type {Type, TypeOf, __nominal, __type} from './type'; | ||
import type {NominalPartial} from './@internal'; | ||
import type {TypeInMediumsPartial, TypeOf, __nominal, __type} from './type'; | ||
import {RefinedType, record} from './type'; | ||
@@ -19,3 +19,5 @@ import {boolean, number, string, unknown} from './types'; | ||
): RefinedType<typeof boolean, T, unknown>; | ||
export function literal(literal: unknown): RefinedType<Type, unknown, unknown> { | ||
export function literal( | ||
literal: unknown, | ||
): RefinedType<TypeInMediumsPartial, unknown, unknown> { | ||
switch (typeof literal) { | ||
@@ -36,15 +38,15 @@ case 'string': | ||
): RefinedType<typeof unknown, T, unknown>; | ||
export function equal<T extends TypeOf<TType>, TType extends Type>( | ||
comparison: T, | ||
Type: TType, | ||
): RefinedType<TType, T, unknown>; | ||
export function equal< | ||
T extends TypeOf<TType>, | ||
TType extends TypeInMediumsPartial, | ||
>(comparison: T, Type: TType): RefinedType<TType, T, unknown>; | ||
export function equal( | ||
comparison: unknown, | ||
Type = unknown, | ||
): RefinedType<Type, unknown, unknown> { | ||
): RefinedType<TypeInMediumsPartial, unknown, unknown> { | ||
return new RefinedType(Type, [value => isEqual(value, comparison)]); | ||
} | ||
export type TransformNominal<TFrom, T> = TFrom extends __NominalPartial | ||
export type TransformNominal<TFrom, T> = TFrom extends NominalPartial | ||
? T & Record<__type, T> & Record<__nominal, TFrom[__nominal]> | ||
: T; |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
183638
4016