This commit is contained in:
@@ -6,7 +6,6 @@ import { Extend } from "../util"
|
||||
|
||||
|
||||
export class EffectSchemaTraitExpression<
|
||||
Superclass extends S.Class<unknown, Fields, A, I, R, C, Inherited, Proto>,
|
||||
Fields extends S.Struct.Fields,
|
||||
A,
|
||||
I,
|
||||
@@ -14,11 +13,12 @@ export class EffectSchemaTraitExpression<
|
||||
C,
|
||||
Inherited extends object,
|
||||
Proto,
|
||||
Static extends object,
|
||||
|
||||
const Traits extends readonly Trait<any, any, any, any>[],
|
||||
> {
|
||||
constructor(
|
||||
readonly superclass: Superclass,
|
||||
readonly superclass: S.Class<unknown, Fields, A, I, R, C, Inherited, Proto> & Static,
|
||||
readonly traits: Traits,
|
||||
) {}
|
||||
|
||||
@@ -41,7 +41,10 @@ export class EffectSchemaTraitExpression<
|
||||
> &
|
||||
|
||||
Simplify<
|
||||
Extend<TraitTuple.MapImplStaticMembers<Traits>>
|
||||
Extend<[
|
||||
Static,
|
||||
...TraitTuple.MapImplStaticMembers<Traits>
|
||||
]>
|
||||
>
|
||||
) {
|
||||
return this.traits.reduce(
|
||||
@@ -51,9 +54,9 @@ export class EffectSchemaTraitExpression<
|
||||
}
|
||||
|
||||
|
||||
staticImplements(_target: StaticImplements<TraitExpression<Superclass, Traits>>, _context: any) {}
|
||||
staticImplements(_target: StaticImplements<TraitExpression<typeof this.superclass, Traits>>, _context: any) {}
|
||||
|
||||
get staticImplementsStage2() {
|
||||
return (_target: StaticImplements<TraitExpression<Superclass, Traits>>) => {}
|
||||
return (_target: StaticImplements<TraitExpression<typeof this.superclass, Traits>>) => {}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { Schema as S } from "@effect/schema"
|
||||
import { Simplify } from "effect/Types"
|
||||
import { Trait } from "../Trait"
|
||||
import { Trait, TraitTuple } from "../Trait"
|
||||
import { TraitExpression } from "../TraitExpression"
|
||||
import { TraitExpressionBuilder } from "../TraitExpressionBuilder"
|
||||
import { spreadSupertraits } from "../spreadSupertraits"
|
||||
import { traitsUnique } from "../traitsUnique"
|
||||
import { StaticMembers } from "../util"
|
||||
import { Extendable, StaticMembers } from "../util"
|
||||
import { EffectSchemaTraitExpression } from "./EffectSchemaTraitExpression"
|
||||
|
||||
|
||||
export class EffectSchemaInitialTraitExpressionBuilder {
|
||||
@@ -124,6 +125,38 @@ export class EffectSchemaTraitExpressionBuilder<
|
||||
]),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
build(): (
|
||||
Extendable<TraitTuple.MapAbstract<Traits>> extends false
|
||||
? "Type conflict between the traits abstract definitions."
|
||||
: Extendable<TraitTuple.MapStaticAbstract<Traits>> extends false
|
||||
? "Type conflict between the traits static abstract definitions."
|
||||
: Extendable<[
|
||||
InstanceType<typeof this.expressionSuperclass>,
|
||||
...TraitTuple.MapImplInstance<Traits>,
|
||||
]> extends false
|
||||
? "Type conflict between the traits implementation instance and/or the superclass instance."
|
||||
: Extendable<[
|
||||
Static,
|
||||
...TraitTuple.MapImplStaticMembers<Traits>,
|
||||
]> extends false
|
||||
? "Type conflict between the traits implementation static members and/or the superclass static members."
|
||||
: EffectSchemaTraitExpression<
|
||||
Fields,
|
||||
A,
|
||||
I,
|
||||
R,
|
||||
C,
|
||||
Inherited,
|
||||
Proto,
|
||||
Static,
|
||||
|
||||
Traits
|
||||
>
|
||||
) {
|
||||
return new EffectSchemaTraitExpression(this.expressionSuperclass, this.expressionTraits) as any
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -1,30 +1,27 @@
|
||||
import { Schema as S } from "@effect/schema"
|
||||
import { Implements } from "../TraitExpression"
|
||||
import { expression } from "../TraitExpressionBuilder"
|
||||
import { extendsEffectSchemaExpression } from "../effect"
|
||||
import { effectSchemaExpression } from "./EffectSchemaTraitExpressionBuilder"
|
||||
|
||||
|
||||
const UserSchema = S.Class<unknown>("User")({
|
||||
id: S.BigIntFromSelf
|
||||
const userExp = effectSchemaExpression
|
||||
.class("User", {
|
||||
id: S.BigIntFromSelf,
|
||||
role: S.Union(S.Literal("User"), S.Literal("Admin")),
|
||||
})
|
||||
|
||||
const userExp = expression
|
||||
.extends(UserSchema)
|
||||
.build()
|
||||
|
||||
@userExp.staticImplements
|
||||
class User extends extendsEffectSchemaExpression(userExp)<User>() implements Implements<typeof userExp> {
|
||||
class User extends userExp.extends<User>() implements Implements<typeof userExp> {
|
||||
static aStaticMethodThatShouldBeInherited() {}
|
||||
}
|
||||
|
||||
|
||||
const AdminSchema = User.extend<unknown>("Admin")({
|
||||
const adminExp = effectSchemaExpression
|
||||
.extends(User, "User", {
|
||||
role: S.Literal("Admin")
|
||||
})
|
||||
|
||||
const adminExp = expression
|
||||
.extends(AdminSchema)
|
||||
.build()
|
||||
|
||||
@adminExp.staticImplements
|
||||
class Admin extends extendsEffectSchemaExpression(adminExp)<Admin>() implements Implements<typeof adminExp> {
|
||||
class Admin extends adminExp.extends<Admin>() implements Implements<typeof adminExp> {
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user