50
src/effect/schema/class/Mutable.ts
Normal file
50
src/effect/schema/class/Mutable.ts
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
import { Schema } from "@effect/schema"
|
||||||
|
import type { Types } from "effect"
|
||||||
|
import type { StaticType } from "../../../StaticType"
|
||||||
|
import type { HasFields } from "./util"
|
||||||
|
|
||||||
|
|
||||||
|
export interface MutableClass<
|
||||||
|
Self,
|
||||||
|
Fields extends Schema.Struct.Fields,
|
||||||
|
I, R, C,
|
||||||
|
Inherited,
|
||||||
|
Proto,
|
||||||
|
>
|
||||||
|
extends Omit<
|
||||||
|
StaticType<Schema.Class<Self, Fields, I, R, C, Inherited, Proto>>,
|
||||||
|
"extend"
|
||||||
|
>
|
||||||
|
{
|
||||||
|
new(
|
||||||
|
...args: ConstructorParameters<Schema.Class<Self, Fields, I, R, C, Inherited, Proto>>
|
||||||
|
): Omit<
|
||||||
|
InstanceType<Schema.Class<Self, Fields, I, R, C, Inherited, Proto>>,
|
||||||
|
keyof Fields
|
||||||
|
> &
|
||||||
|
Types.Mutable<Schema.Struct.Type<Fields>>
|
||||||
|
|
||||||
|
extend<Extended>(identifier: string): <newFields extends Schema.Struct.Fields>(
|
||||||
|
fields: newFields | HasFields<newFields>,
|
||||||
|
annotations?: Schema.Annotations.Schema<Extended>,
|
||||||
|
) => MutableClass<
|
||||||
|
Extended,
|
||||||
|
Fields & newFields,
|
||||||
|
I & Schema.Struct.Encoded<newFields>,
|
||||||
|
R | Schema.Struct.Context<newFields>,
|
||||||
|
C & Schema.Struct.Constructor<newFields>,
|
||||||
|
Self,
|
||||||
|
Proto
|
||||||
|
>
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
export const Mutable = <
|
||||||
|
Self,
|
||||||
|
Fields extends Schema.Struct.Fields,
|
||||||
|
I, R, C,
|
||||||
|
Inherited,
|
||||||
|
Proto
|
||||||
|
>(
|
||||||
|
self: Schema.Class<Self, Fields, I, R, C, Inherited, Proto>
|
||||||
|
) => self as MutableClass<Self, Fields, I, R, C, Inherited, Proto>
|
||||||
@@ -1,14 +1,23 @@
|
|||||||
import { Schema as S } from "@effect/schema"
|
import { Schema as S } from "@effect/schema"
|
||||||
import { reaction, runInAction } from "mobx"
|
import { reaction, runInAction } from "mobx"
|
||||||
import { Jsonifiable } from "./Jsonifiable"
|
import { Jsonifiable } from "./Jsonifiable"
|
||||||
import { MobXObservable, MutableTaggedClass } from "./class"
|
import { Class, MobXObservable, MutableTaggedClass, TaggedClass } from "./class"
|
||||||
|
import { Mutable } from "./class/Mutable"
|
||||||
|
|
||||||
|
|
||||||
class User extends MutableTaggedClass<User>()("User", {
|
// class User extends MutableTaggedClass<User>()("User", {
|
||||||
|
// id: S.BigIntFromSelf,
|
||||||
|
// role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")),
|
||||||
|
// }).pipe(
|
||||||
|
// MobXObservable
|
||||||
|
// ) {}
|
||||||
|
|
||||||
|
class User extends TaggedClass<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")),
|
||||||
}).pipe(
|
}).pipe(
|
||||||
MobXObservable
|
Mutable,
|
||||||
|
MobXObservable,
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
const JsonifiableUser = User.pipe(
|
const JsonifiableUser = User.pipe(
|
||||||
|
|||||||
Reference in New Issue
Block a user