Mutable
This commit is contained in:
@@ -1,17 +1,15 @@
|
|||||||
import { Schema as S } from "@effect/schema"
|
import { Schema as S } from "@effect/schema"
|
||||||
import type { Annotations, Struct } from "@effect/schema/Schema"
|
import type { Annotations, Struct } from "@effect/schema/Schema"
|
||||||
import type { TMutableClass } from "./TMutableClass"
|
import type { TMutableClass } from "./TMutableClass"
|
||||||
import type { HasFields, MissingSelfGeneric } from "./util"
|
import type { HasFields } from "./util"
|
||||||
|
|
||||||
|
|
||||||
export function MutableClass<Self = never>(identifier: string) {
|
export function MutableClass<Self = never>(identifier: string) {
|
||||||
return <Fields extends Struct.Fields>(
|
return <Fields extends Struct.Fields>(
|
||||||
fieldsOr: Fields | HasFields<Fields>,
|
fieldsOr: Fields | HasFields<Fields>,
|
||||||
annotations?: Annotations.Schema<Self>,
|
annotations?: Annotations.Schema<Self>,
|
||||||
): (
|
) =>
|
||||||
[Self] extends [never]
|
S.Class<Self>(identifier)(fieldsOr, annotations) as TMutableClass<
|
||||||
? MissingSelfGeneric<"Class">
|
|
||||||
: TMutableClass<
|
|
||||||
Self,
|
Self,
|
||||||
Fields,
|
Fields,
|
||||||
Struct.Encoded<Fields>,
|
Struct.Encoded<Fields>,
|
||||||
@@ -20,6 +18,4 @@ export function MutableClass<Self = never>(identifier: string) {
|
|||||||
{},
|
{},
|
||||||
{}
|
{}
|
||||||
>
|
>
|
||||||
) =>
|
|
||||||
S.Class<Self>(identifier)(fieldsOr, annotations)
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,5 +1,18 @@
|
|||||||
import { Schema as S } from "@effect/schema"
|
import { Schema as S } from "@effect/schema"
|
||||||
import { MutableClass } from "./MutableClass"
|
import { MutableClass } from "./MutableClass"
|
||||||
|
import { pipe } from "remeda"
|
||||||
|
import { Mutable } from "./Mutable"
|
||||||
|
import { MobXObservable } from "./MobXObservable"
|
||||||
|
|
||||||
|
|
||||||
|
const UserSuper = <Self>() => pipe(
|
||||||
|
MutableClass<Self>("User")({
|
||||||
|
id: S.BigIntFromSelf,
|
||||||
|
role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")),
|
||||||
|
}),
|
||||||
|
|
||||||
|
v => MobXObservable(v),
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
class User extends MutableClass<User>("User")({
|
class User extends MutableClass<User>("User")({
|
||||||
|
|||||||
Reference in New Issue
Block a user