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