This commit is contained in:
@@ -7,7 +7,7 @@ import { Extend } from "../util"
|
||||
|
||||
export class EffectSchemaTraitExpression<
|
||||
Fields extends S.Struct.Fields,
|
||||
A, I, R, C,
|
||||
I, R, C,
|
||||
Inherited extends object,
|
||||
Proto,
|
||||
Static extends object,
|
||||
@@ -15,11 +15,11 @@ export class EffectSchemaTraitExpression<
|
||||
const Traits extends readonly Trait<any, any, any, any>[],
|
||||
>
|
||||
implements TraitExpressionLike<
|
||||
S.Class<unknown, Fields, A, I, R, C, Inherited, Proto>,
|
||||
S.Class<unknown, Fields, I, R, C, Inherited, Proto>,
|
||||
Traits
|
||||
> {
|
||||
constructor(
|
||||
readonly superclass: S.Class<unknown, Fields, A, I, R, C, Inherited, Proto>,
|
||||
readonly superclass: S.Class<unknown, Fields, I, R, C, Inherited, Proto>,
|
||||
readonly superclassStatic: Static,
|
||||
readonly traits: Traits,
|
||||
) {}
|
||||
@@ -29,7 +29,7 @@ implements TraitExpressionLike<
|
||||
S.Class<
|
||||
Self,
|
||||
Fields,
|
||||
A, I, R, C,
|
||||
I, R, C,
|
||||
Simplify<
|
||||
Extend<[
|
||||
Inherited,
|
||||
|
||||
@@ -1,6 +1,5 @@
|
||||
import { Schema as S } from "@effect/schema"
|
||||
import * as Types from "effect/Types"
|
||||
import { Simplify } from "type-fest"
|
||||
import { Trait, TraitTuple } from "../Trait"
|
||||
import { TraitExpression } from "../TraitExpression"
|
||||
import { TraitExpressionBuilder } from "../TraitExpressionBuilder"
|
||||
@@ -41,36 +40,32 @@ export class EffectSchemaInitialTraitExpressionBuilder {
|
||||
}
|
||||
|
||||
extends<
|
||||
Super extends S.Class<any, Fields, A, I, R, C, Inherited, Proto>,
|
||||
|
||||
Super extends S.Class<Self, Fields, I, R, C, Inherited, Proto>,
|
||||
Self,
|
||||
Fields extends S.Struct.Fields,
|
||||
A, I, R, C,
|
||||
I, R, C,
|
||||
Inherited extends object,
|
||||
Proto,
|
||||
|
||||
NewFields extends S.Struct.Fields,
|
||||
>(
|
||||
superclass: Super | S.Class<any, Fields, A, I, R, C, Inherited, Proto>,
|
||||
superclass: Super | S.Class<Self, Fields, I, R, C, Inherited, Proto>,
|
||||
identifier: string,
|
||||
fields: NewFields,
|
||||
annotations?: S.Annotations.Schema<unknown>,
|
||||
) {
|
||||
return new EffectSchemaTraitExpressionBuilder(
|
||||
superclass.extend<unknown>(identifier)(fields, annotations) as S.Class<
|
||||
unknown,
|
||||
Fields & NewFields,
|
||||
Types.Simplify<A & S.Struct.Type<NewFields>>,
|
||||
Types.Simplify<I & S.Struct.Encoded<NewFields>>,
|
||||
R | S.Struct.Context<NewFields>,
|
||||
Types.Simplify<C & S.Struct.Type<NewFields>>,
|
||||
InstanceType<Super>,
|
||||
Proto
|
||||
>,
|
||||
|
||||
{} as Simplify<
|
||||
Omit<StaticMembers<Super>, keyof S.Class<any, Fields, A, I, R, C, Inherited, Proto>>
|
||||
>,
|
||||
|
||||
// superclass.extend<unknown>(identifier)(fields, annotations) as S.Class<
|
||||
// unknown,
|
||||
// Fields & NewFields,
|
||||
// I & S.Struct.Encoded<NewFields>,
|
||||
// R | S.Struct.Context<NewFields>,
|
||||
// C & S.Struct.Constructor<NewFields>,
|
||||
// InstanceType<Super>,
|
||||
// Proto
|
||||
// >,
|
||||
superclass.extend<unknown>(identifier)(fields, annotations),
|
||||
{} as Omit<StaticMembers<Super>, keyof S.Class<Self, Fields, I, R, C, Inherited, Proto>>,
|
||||
[],
|
||||
)
|
||||
}
|
||||
@@ -79,7 +74,7 @@ export class EffectSchemaInitialTraitExpressionBuilder {
|
||||
|
||||
export class EffectSchemaTraitExpressionBuilder<
|
||||
Fields extends S.Struct.Fields,
|
||||
A, I, R, C,
|
||||
I, R, C,
|
||||
Inherited extends object,
|
||||
Proto,
|
||||
Static extends object,
|
||||
@@ -87,31 +82,31 @@ export class EffectSchemaTraitExpressionBuilder<
|
||||
const Traits extends readonly Trait<any, any, any, any>[],
|
||||
> {
|
||||
constructor(
|
||||
readonly expressionSuperclass: S.Class<unknown, Fields, A, I, R, C, Inherited, Proto>,
|
||||
readonly expressionSuperclass: S.Class<unknown, Fields, I, R, C, Inherited, Proto>,
|
||||
readonly expressionSuperclassStatic: Static,
|
||||
readonly expressionTraits: Traits,
|
||||
) {}
|
||||
|
||||
|
||||
mutable() {
|
||||
return new EffectSchemaTraitExpressionBuilder(
|
||||
this.expressionSuperclass as S.Class<unknown, Fields, Types.Mutable<A>, I, R, C, Inherited, Proto>,
|
||||
this.expressionSuperclassStatic,
|
||||
this.expressionTraits,
|
||||
)
|
||||
}
|
||||
// mutable() {
|
||||
// return new EffectSchemaTraitExpressionBuilder(
|
||||
// this.expressionSuperclass as S.Class<unknown, Fields, Types.Mutable<A>, I, R, C, Inherited, Proto>,
|
||||
// this.expressionSuperclassStatic,
|
||||
// this.expressionTraits,
|
||||
// )
|
||||
// }
|
||||
|
||||
immutable() {
|
||||
return new EffectSchemaTraitExpressionBuilder(
|
||||
this.expressionSuperclass as S.Class<unknown, Fields, Readonly<A>, I, R, C, Inherited, Proto>,
|
||||
this.expressionSuperclassStatic,
|
||||
this.expressionTraits,
|
||||
)
|
||||
}
|
||||
// immutable() {
|
||||
// return new EffectSchemaTraitExpressionBuilder(
|
||||
// this.expressionSuperclass as S.Class<unknown, Fields, Readonly<A>, I, R, C, Inherited, Proto>,
|
||||
// this.expressionSuperclassStatic,
|
||||
// this.expressionTraits,
|
||||
// )
|
||||
// }
|
||||
|
||||
mutableEncoded() {
|
||||
return new EffectSchemaTraitExpressionBuilder(
|
||||
this.expressionSuperclass as S.Class<unknown, Fields, A, Readonly<I>, R, C, Inherited, Proto>,
|
||||
this.expressionSuperclass as S.Class<unknown, Fields, Readonly<I>, R, C, Inherited, Proto>,
|
||||
this.expressionSuperclassStatic,
|
||||
this.expressionTraits,
|
||||
)
|
||||
@@ -119,7 +114,7 @@ export class EffectSchemaTraitExpressionBuilder<
|
||||
|
||||
immutableEncoded() {
|
||||
return new EffectSchemaTraitExpressionBuilder(
|
||||
this.expressionSuperclass as S.Class<unknown, Fields, A, Types.Mutable<I>, R, C, Inherited, Proto>,
|
||||
this.expressionSuperclass as S.Class<unknown, Fields, Types.Mutable<I>, R, C, Inherited, Proto>,
|
||||
this.expressionSuperclassStatic,
|
||||
this.expressionTraits,
|
||||
)
|
||||
@@ -168,7 +163,7 @@ export class EffectSchemaTraitExpressionBuilder<
|
||||
? "Type conflict between the traits implementation static members and/or the superclass static members."
|
||||
: EffectSchemaTraitExpression<
|
||||
Fields,
|
||||
A, I, R, C,
|
||||
I, R, C,
|
||||
Inherited,
|
||||
Proto,
|
||||
Static,
|
||||
|
||||
@@ -7,7 +7,6 @@ import { effectSchemaExpression } from "./EffectSchemaTraitExpressionBuilder"
|
||||
type Extr<T> =
|
||||
T extends EffectSchemaTraitExpression<
|
||||
infer Fields,
|
||||
infer A,
|
||||
infer I,
|
||||
infer R,
|
||||
infer C,
|
||||
@@ -26,8 +25,8 @@ const userExp = effectSchemaExpression
|
||||
id: S.BigIntFromSelf,
|
||||
role: S.Union(S.Literal("User"), S.Literal("Admin")),
|
||||
})
|
||||
.mutable()
|
||||
.mutableEncoded()
|
||||
// .mutable()
|
||||
// .mutableEncoded()
|
||||
.build()
|
||||
|
||||
@userExp.staticImplements
|
||||
@@ -37,7 +36,7 @@ class User extends userExp.extends<User>() implements Implements<typeof userExp>
|
||||
}
|
||||
|
||||
const user = new User({ id: 0n, role: "User" })
|
||||
user.id = 0n
|
||||
// user.id = 0n
|
||||
type UserEncoded = S.Schema.Encoded<typeof User>
|
||||
|
||||
|
||||
@@ -45,7 +44,7 @@ const adminExp = effectSchemaExpression
|
||||
.extends(User, "User", {
|
||||
role: S.Literal("Admin")
|
||||
})
|
||||
.immutable()
|
||||
// .immutable()
|
||||
.build()
|
||||
|
||||
adminExp.superclass
|
||||
|
||||
Reference in New Issue
Block a user