From 1278f05d3e4661e0d3277ef44b34ee1dd96eb6fc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sat, 27 Jul 2024 02:34:39 +0200 Subject: [PATCH] Mutable tests --- src/effect/schema/class/Mutable.ts | 50 ++++++++++++++++++++++++++++++ src/effect/schema/tests.ts | 15 +++++++-- 2 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/effect/schema/class/Mutable.ts diff --git a/src/effect/schema/class/Mutable.ts b/src/effect/schema/class/Mutable.ts new file mode 100644 index 0000000..d513941 --- /dev/null +++ b/src/effect/schema/class/Mutable.ts @@ -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>, + "extend" +> +{ + new( + ...args: ConstructorParameters> + ): Omit< + InstanceType>, + keyof Fields + > & + Types.Mutable> + + extend(identifier: string): ( + fields: newFields | HasFields, + annotations?: Schema.Annotations.Schema, + ) => MutableClass< + Extended, + Fields & newFields, + I & Schema.Struct.Encoded, + R | Schema.Struct.Context, + C & Schema.Struct.Constructor, + Self, + Proto + > +} + + +export const Mutable = < + Self, + Fields extends Schema.Struct.Fields, + I, R, C, + Inherited, + Proto +>( + self: Schema.Class +) => self as MutableClass diff --git a/src/effect/schema/tests.ts b/src/effect/schema/tests.ts index 0e9f692..fe75ca0 100644 --- a/src/effect/schema/tests.ts +++ b/src/effect/schema/tests.ts @@ -1,14 +1,23 @@ import { Schema as S } from "@effect/schema" import { reaction, runInAction } from "mobx" 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", { +// class User extends MutableTaggedClass()("User", { +// id: S.BigIntFromSelf, +// role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")), +// }).pipe( +// MobXObservable +// ) {} + +class User extends TaggedClass()("User", { id: S.BigIntFromSelf, role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")), }).pipe( - MobXObservable + Mutable, + MobXObservable, ) {} const JsonifiableUser = User.pipe(