MutableTaggedClass
This commit is contained in:
@@ -1,37 +0,0 @@
|
|||||||
import type { Class, Struct } from "@effect/schema/Schema"
|
|
||||||
import type { Constructor } from "type-fest"
|
|
||||||
import type { StaticType } from "../../.."
|
|
||||||
import type { TMutableClass } from "./TMutableClass"
|
|
||||||
|
|
||||||
|
|
||||||
export function Mutable<
|
|
||||||
This extends Class<Self, Fields, I, R, C, Inherited, Proto>,
|
|
||||||
|
|
||||||
Self,
|
|
||||||
Fields extends Struct.Fields,
|
|
||||||
I, R, C,
|
|
||||||
Inherited,
|
|
||||||
Proto,
|
|
||||||
>(
|
|
||||||
class_:
|
|
||||||
| This
|
|
||||||
| Class<Self, Fields, I, R, C, Inherited, Proto>
|
|
||||||
) {
|
|
||||||
return class_ as (
|
|
||||||
Constructor<
|
|
||||||
Omit<
|
|
||||||
InstanceType<This>,
|
|
||||||
keyof InstanceType<Class<Self, Fields, I, R, C, Inherited, Proto>>
|
|
||||||
> &
|
|
||||||
InstanceType<TMutableClass<Self, Fields, I, R, C, Inherited, Proto>>,
|
|
||||||
|
|
||||||
ConstructorParameters<TMutableClass<Self, Fields, I, R, C, Inherited, Proto>>
|
|
||||||
> &
|
|
||||||
|
|
||||||
Omit<
|
|
||||||
StaticType<This>,
|
|
||||||
keyof StaticType<Class<Self, Fields, I, R, C, Inherited, Proto>>
|
|
||||||
> &
|
|
||||||
StaticType<TMutableClass<Self, Fields, I, R, C, Inherited, Proto>>
|
|
||||||
)
|
|
||||||
}
|
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Schema as S } from "@effect/schema"
|
import { Schema as S } from "@effect/schema"
|
||||||
import type { Annotations, PropertySignature, Struct } from "@effect/schema/Schema"
|
import type { Annotations, Struct } from "@effect/schema/Schema"
|
||||||
|
import type { IMutableClass } from "./MutableClass"
|
||||||
import type { HasFields } from "./util"
|
import type { HasFields } from "./util"
|
||||||
|
|
||||||
|
|
||||||
@@ -12,14 +13,14 @@ export function MutableTaggedClass<Self>(identifier?: string) {
|
|||||||
fieldsOr: Fields | HasFields<Fields>,
|
fieldsOr: Fields | HasFields<Fields>,
|
||||||
annotations?: Annotations.Schema<Self>,
|
annotations?: Annotations.Schema<Self>,
|
||||||
) =>
|
) =>
|
||||||
// S.TaggedClass<Self>(identifier)(tag, fieldsOr, annotations) as S.TaggedClass<
|
S.TaggedClass<Self>(identifier)(tag, fieldsOr, annotations) as IMutableClass<
|
||||||
// Self,
|
|
||||||
// Tag,
|
|
||||||
// { readonly _tag: PropertySignature<":", Tag, never, ":", Tag, true, never> } & Fields
|
|
||||||
// >
|
|
||||||
S.TaggedClass<Self>(identifier)(tag, fieldsOr, annotations) as S.TaggedClass<
|
|
||||||
Self,
|
Self,
|
||||||
Tag,
|
Fields,
|
||||||
{ readonly _tag: PropertySignature<":", Tag, never, ":", Tag, true, never> } & Fields
|
Struct.Encoded<Fields>,
|
||||||
>
|
Struct.Context<Fields>,
|
||||||
|
Struct.Constructor<Omit<Fields, "_tag">>,
|
||||||
|
{},
|
||||||
|
{}
|
||||||
|
> &
|
||||||
|
{ readonly _tag: Tag }
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,42 +0,0 @@
|
|||||||
import type { Annotations, Class, Struct } from "@effect/schema/Schema"
|
|
||||||
import type { Mutable } from "effect/Types"
|
|
||||||
import type { Constructor } from "type-fest"
|
|
||||||
import type { StaticType } from "../../.."
|
|
||||||
import type { HasFields } from "./util"
|
|
||||||
|
|
||||||
|
|
||||||
export type TMutableClass<
|
|
||||||
Self,
|
|
||||||
Fields extends Struct.Fields,
|
|
||||||
I, R, C,
|
|
||||||
Inherited,
|
|
||||||
Proto,
|
|
||||||
> = (
|
|
||||||
Constructor<
|
|
||||||
Omit<
|
|
||||||
InstanceType<Class<Self, Fields, I, R, C, Inherited, Proto>>,
|
|
||||||
keyof Fields
|
|
||||||
> &
|
|
||||||
Mutable<Struct.Type<Fields>>,
|
|
||||||
|
|
||||||
ConstructorParameters<Class<Self, Fields, I, R, C, Inherited, Proto>>
|
|
||||||
> &
|
|
||||||
|
|
||||||
Omit<
|
|
||||||
StaticType<Class<Self, Fields, I, R, C, Inherited, Proto>>,
|
|
||||||
"extend"
|
|
||||||
> & {
|
|
||||||
extend<Extended>(identifier: string): <newFields extends Struct.Fields>(
|
|
||||||
fields: newFields | HasFields<newFields>,
|
|
||||||
annotations?: Annotations.Schema<Extended>,
|
|
||||||
) => TMutableClass<
|
|
||||||
Extended,
|
|
||||||
Fields & newFields,
|
|
||||||
I & Struct.Encoded<newFields>,
|
|
||||||
R | Struct.Context<newFields>,
|
|
||||||
C & Struct.Constructor<newFields>,
|
|
||||||
Self,
|
|
||||||
Proto
|
|
||||||
>
|
|
||||||
}
|
|
||||||
)
|
|
||||||
@@ -1,6 +1,6 @@
|
|||||||
export { Class } from "./Class"
|
export { Class } from "./Class"
|
||||||
export { MobXObservable } from "./MobXObservable"
|
export { MobXObservable } from "./MobXObservable"
|
||||||
export { Mutable } from "./Mutable"
|
|
||||||
export { MutableClass } from "./MutableClass"
|
export { MutableClass } from "./MutableClass"
|
||||||
export type { IMutableClass } from "./MutableClass"
|
export type { IMutableClass } from "./MutableClass"
|
||||||
|
export { MutableTaggedClass } from "./MutableTaggedClass"
|
||||||
export { TaggedClass } from "./TaggedClass"
|
export { TaggedClass } from "./TaggedClass"
|
||||||
|
|||||||
@@ -1,28 +1,16 @@
|
|||||||
import { Schema as S } from "@effect/schema"
|
import { Schema as S } from "@effect/schema"
|
||||||
import { MutableClass } from "./MutableClass"
|
|
||||||
import { pipe } from "remeda"
|
import { pipe } from "remeda"
|
||||||
import { Mutable } from "./Mutable"
|
|
||||||
import { MobXObservable } from "./MobXObservable"
|
import { MobXObservable } from "./MobXObservable"
|
||||||
import { Class } from "./Class"
|
import { MutableTaggedClass } from "./MutableTaggedClass"
|
||||||
import { TaggedClass } from "./TaggedClass"
|
|
||||||
|
|
||||||
|
|
||||||
const UserSuper = <Self>() => pipe(
|
class User extends pipe(
|
||||||
MutableClass<Self>("User")({
|
MutableTaggedClass<User>()("User", {
|
||||||
id: S.BigIntFromSelf,
|
id: S.BigIntFromSelf,
|
||||||
role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")),
|
role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")),
|
||||||
}),
|
}),
|
||||||
// TaggedClass<Self>()("User", {
|
|
||||||
// id: S.BigIntFromSelf,
|
|
||||||
// role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")),
|
|
||||||
// }),
|
|
||||||
|
|
||||||
// Mutable,
|
|
||||||
MobXObservable,
|
MobXObservable,
|
||||||
)
|
) {}
|
||||||
|
|
||||||
|
|
||||||
class User extends UserSuper<User>() {}
|
|
||||||
|
|
||||||
const user1 = new User({ id: 1n, role: "BasicUser" })
|
const user1 = new User({ id: 1n, role: "BasicUser" })
|
||||||
user1.id = 1n
|
user1.id = 1n
|
||||||
|
|||||||
Reference in New Issue
Block a user