62 lines
1.5 KiB
TypeScript
62 lines
1.5 KiB
TypeScript
import { Schema as S } from "@effect/schema"
|
|
import { Simplify } from "type-fest"
|
|
import { Trait, TraitTuple } from "../Trait"
|
|
import { StaticImplements, TraitExpressionLike } from "../TraitExpression"
|
|
import { Extend } from "../util"
|
|
|
|
|
|
export class EffectSchemaTraitExpression<
|
|
Fields extends S.Struct.Fields,
|
|
A, I, R, C,
|
|
Inherited extends object,
|
|
Proto,
|
|
Static extends object,
|
|
|
|
const Traits extends readonly Trait<any, any, any, any>[],
|
|
>
|
|
implements TraitExpressionLike<
|
|
S.Class<unknown, Fields, A, I, R, C, Inherited, Proto>,
|
|
Traits
|
|
> {
|
|
constructor(
|
|
readonly superclass: S.Class<unknown, Fields, A, I, R, C, Inherited, Proto>,
|
|
readonly superclassStatic: Static,
|
|
readonly traits: Traits,
|
|
) {}
|
|
|
|
|
|
extends<Self>(): (
|
|
S.Class<
|
|
Self,
|
|
Fields,
|
|
A, I, R, C,
|
|
Simplify<
|
|
Extend<[
|
|
Inherited,
|
|
...TraitTuple.MapImplInstance<Traits>
|
|
]>
|
|
>,
|
|
Proto
|
|
> &
|
|
|
|
Simplify<
|
|
Extend<[
|
|
Static,
|
|
...TraitTuple.MapImplStaticMembers<Traits>
|
|
]>
|
|
>
|
|
) {
|
|
return this.traits.reduce(
|
|
(previous, trait) => trait.apply(previous),
|
|
this.superclass,
|
|
) as any
|
|
}
|
|
|
|
|
|
staticImplements(_target: StaticImplements<typeof this>, _context: any) {}
|
|
|
|
get staticImplementsStage2() {
|
|
return (_target: StaticImplements<typeof this>) => {}
|
|
}
|
|
}
|