This commit is contained in:
18
src/Trait.ts
18
src/Trait.ts
@@ -69,24 +69,6 @@ export namespace Trait {
|
|||||||
StaticMembers<Trait.OwnImplClass<T>>
|
StaticMembers<Trait.OwnImplClass<T>>
|
||||||
)
|
)
|
||||||
|
|
||||||
export type OwnClass<T> = (
|
|
||||||
AbstractClass<Trait.OwnInstance<T>, any[]> &
|
|
||||||
Extend<[
|
|
||||||
Trait.OwnStaticAbstract<T>,
|
|
||||||
StaticMembers<Trait.OwnImplClass<T>>,
|
|
||||||
]>
|
|
||||||
)
|
|
||||||
export interface OwnClassFn extends Fn {
|
|
||||||
return: Trait.OwnClass<this["arg0"]>
|
|
||||||
}
|
|
||||||
|
|
||||||
export type OwnInstance<T> = (
|
|
||||||
Extend<[Trait.OwnAbstract<T>, Trait.OwnImplInstance<T>]>
|
|
||||||
)
|
|
||||||
export interface OwnInstanceFn extends Fn {
|
|
||||||
return: Trait.OwnInstance<this["arg0"]>
|
|
||||||
}
|
|
||||||
|
|
||||||
export type Supertraits<T> = (
|
export type Supertraits<T> = (
|
||||||
TraitExpression.Traits<Trait.OwnSuperExpression<T>>
|
TraitExpression.Traits<Trait.OwnSuperExpression<T>>
|
||||||
)
|
)
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import { Fn, Pipe, Tuples } from "hotscript"
|
import { Fn, Pipe, Tuples } from "hotscript"
|
||||||
import { AbstractClass, Class, Simplify } from "type-fest"
|
import { AbstractClass, Class, Simplify } from "type-fest"
|
||||||
import { Trait, Traits } from "./Trait"
|
import { Trait, TraitInstance, Traits } from "./Trait"
|
||||||
import { TraitBuilder } from "./TraitBuilder"
|
import { TraitBuilder } from "./TraitBuilder"
|
||||||
import { ExtendFn, ExtendPlain, SimplifyFn, StaticMembersFn } from "./util"
|
import { ExtendFn, ExtendPlain, SimplifyFn, StaticMembersFn } from "./util"
|
||||||
|
|
||||||
@@ -49,22 +49,22 @@ export class TraitExpression<
|
|||||||
) {
|
) {
|
||||||
return new TraitBuilder<
|
return new TraitBuilder<
|
||||||
This,
|
This,
|
||||||
|
|
||||||
Simplify<
|
Simplify<
|
||||||
ExtendPlain<Traits.MapAbstract<T>>
|
ExtendPlain<Traits.MapAbstract<T>>
|
||||||
>,
|
>,
|
||||||
Simplify<
|
Simplify<
|
||||||
ExtendPlain<Traits.MapStaticAbstract<T>>
|
ExtendPlain<Traits.MapStaticAbstract<T>>
|
||||||
>,
|
>,
|
||||||
(
|
|
||||||
AbstractClass<
|
AbstractClass<
|
||||||
Simplify<
|
|
||||||
ExtendPlain<Traits.MapImplInstance<T>>
|
|
||||||
>
|
|
||||||
> &
|
|
||||||
Simplify<
|
Simplify<
|
||||||
ExtendPlain<Traits.MapImplStaticMembers<T>>
|
ExtendPlain<Traits.MapImplInstance<T>>
|
||||||
>
|
>
|
||||||
)
|
> &
|
||||||
|
Simplify<
|
||||||
|
ExtendPlain<Traits.MapImplStaticMembers<T>>
|
||||||
|
>
|
||||||
>(
|
>(
|
||||||
this,
|
this,
|
||||||
{} as any,
|
{} as any,
|
||||||
@@ -100,26 +100,34 @@ export namespace TraitExpression {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
export type Implements<Exp extends TraitExpression<any, any>> = (
|
export type Implements<
|
||||||
Pipe<Exp, [
|
Exp extends TraitExpression<any, Trait<any, any, any, any>[]>
|
||||||
TraitExpression.TraitsFn,
|
> = (
|
||||||
Tuples.Map<Trait.OwnAbstractFn>,
|
Simplify<
|
||||||
ExtendFn,
|
ExtendPlain<
|
||||||
SimplifyFn,
|
Traits.MapAbstract<
|
||||||
]>
|
TraitExpression.Traits<Exp>
|
||||||
|
>
|
||||||
|
>
|
||||||
|
>
|
||||||
)
|
)
|
||||||
|
|
||||||
export type ImplementsStatic<Exp extends TraitExpression<any, any>> = (
|
export type ImplementsStatic<
|
||||||
Pipe<Exp, [
|
Exp extends TraitExpression<any, Trait<any, any, any, any>[]>
|
||||||
TraitExpression.TraitsFn,
|
> = (
|
||||||
Tuples.Map<Trait.OwnStaticAbstractFn>,
|
Simplify<
|
||||||
ExtendFn,
|
ExtendPlain<
|
||||||
SimplifyFn,
|
Traits.MapStaticAbstract<
|
||||||
]>
|
TraitExpression.Traits<Exp>
|
||||||
|
>
|
||||||
|
>
|
||||||
|
>
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
export type TraitExpressionClass<Exp extends TraitExpression<any, any>> = (
|
export type TraitExpressionClass<
|
||||||
|
Exp extends TraitExpression<any, Trait<any, any, any, any>[]>
|
||||||
|
> = (
|
||||||
AbstractClass<
|
AbstractClass<
|
||||||
TraitExpressionInstance<Exp>,
|
TraitExpressionInstance<Exp>,
|
||||||
ConstructorParameters<TraitExpression.Superclass<Exp>>
|
ConstructorParameters<TraitExpression.Superclass<Exp>>
|
||||||
@@ -127,7 +135,9 @@ export type TraitExpressionClass<Exp extends TraitExpression<any, any>> = (
|
|||||||
TraitExpressionStaticMembers<Exp>
|
TraitExpressionStaticMembers<Exp>
|
||||||
)
|
)
|
||||||
|
|
||||||
export type TraitExpressionConcreteClass<Exp extends TraitExpression<any, any>> = (
|
export type TraitExpressionConcreteClass<
|
||||||
|
Exp extends TraitExpression<any, Trait<any, any, any, any>[]>
|
||||||
|
> = (
|
||||||
Class<
|
Class<
|
||||||
TraitExpressionInstance<Exp>,
|
TraitExpressionInstance<Exp>,
|
||||||
ConstructorParameters<TraitExpression.Superclass<Exp>>
|
ConstructorParameters<TraitExpression.Superclass<Exp>>
|
||||||
@@ -135,18 +145,35 @@ export type TraitExpressionConcreteClass<Exp extends TraitExpression<any, any>>
|
|||||||
TraitExpressionStaticMembers<Exp>
|
TraitExpressionStaticMembers<Exp>
|
||||||
)
|
)
|
||||||
|
|
||||||
export type TraitExpressionInstance<Exp extends TraitExpression<any, any>> = (
|
export type TraitExpressionInstance<
|
||||||
Pipe<TraitExpression.Traits<Exp>, [
|
Exp extends TraitExpression<any, Trait<any, any, any, any>[]>
|
||||||
Tuples.Map<Trait.OwnInstanceFn>, // Map all the traits to their instance representation
|
> = (
|
||||||
Tuples.Prepend< // Add the instance of the superclass at the top of the list
|
// Pipe<TraitExpression.Traits<Exp>, [
|
||||||
InstanceType<TraitExpression.Superclass<Exp>>
|
// Tuples.Map<Trait.OwnInstanceFn>, // Map all the traits to their instance representation
|
||||||
>,
|
// Tuples.Prepend< // Add the instance of the superclass at the top of the list
|
||||||
ExtendFn, // Reduce to a single object that extends all the objects in the list
|
// InstanceType<TraitExpression.Superclass<Exp>>
|
||||||
SimplifyFn, // Make readable for IDEs
|
// >,
|
||||||
]>
|
// ExtendFn, // Reduce to a single object that extends all the objects in the list
|
||||||
|
// SimplifyFn, // Make readable for IDEs
|
||||||
|
// ]>
|
||||||
|
Simplify<
|
||||||
|
ExtendPlain<[
|
||||||
|
InstanceType<TraitExpression.Superclass<Exp>>,
|
||||||
|
...MapTraitsInstance<
|
||||||
|
TraitExpression.Traits<Exp>
|
||||||
|
>,
|
||||||
|
]>
|
||||||
|
>
|
||||||
)
|
)
|
||||||
|
type MapTraitsInstance<T extends Trait<any, any, any, any>[]> = {
|
||||||
|
[K in keyof T]: K extends keyof []
|
||||||
|
? T[K]
|
||||||
|
: TraitInstance<T[K]>
|
||||||
|
}
|
||||||
|
|
||||||
export type TraitExpressionStaticMembers<Exp extends TraitExpression<any, any>> = (
|
export type TraitExpressionStaticMembers<
|
||||||
|
Exp extends TraitExpression<any, Trait<any, any, any, any>[]>
|
||||||
|
> = (
|
||||||
Pipe<TraitExpression.Traits<Exp>, [
|
Pipe<TraitExpression.Traits<Exp>, [
|
||||||
Tuples.Map<Trait.OwnClassFn>, // Map all the traits to their class representation
|
Tuples.Map<Trait.OwnClassFn>, // Map all the traits to their class representation
|
||||||
Tuples.Prepend<TraitExpression.Superclass<Exp>>, // Add the superclass at the top of the list
|
Tuples.Prepend<TraitExpression.Superclass<Exp>>, // Add the superclass at the top of the list
|
||||||
|
|||||||
Reference in New Issue
Block a user