From 27c80a7b1e61ce76c180fef591731216b878eb58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Fri, 14 Jun 2024 21:26:26 +0200 Subject: [PATCH] MutableTaggedClass --- src/effect/schema/class/Mutable.ts | 37 ---------------- src/effect/schema/class/MutableTaggedClass.ts | 21 +++++----- src/effect/schema/class/TMutableClass.ts | 42 ------------------- src/effect/schema/class/index.ts | 2 +- src/effect/schema/class/tests.ts | 20 ++------- 5 files changed, 16 insertions(+), 106 deletions(-) delete mode 100644 src/effect/schema/class/Mutable.ts delete mode 100644 src/effect/schema/class/TMutableClass.ts diff --git a/src/effect/schema/class/Mutable.ts b/src/effect/schema/class/Mutable.ts deleted file mode 100644 index f734bca..0000000 --- a/src/effect/schema/class/Mutable.ts +++ /dev/null @@ -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 extends Struct.Fields, - I, R, C, - Inherited, - Proto, ->( - class_: - | This - | Class -) { - return class_ as ( - Constructor< - Omit< - InstanceType, - keyof InstanceType> - > & - InstanceType>, - - ConstructorParameters> - > & - - Omit< - StaticType, - keyof StaticType> - > & - StaticType> - ) -} diff --git a/src/effect/schema/class/MutableTaggedClass.ts b/src/effect/schema/class/MutableTaggedClass.ts index 201441f..428b303 100644 --- a/src/effect/schema/class/MutableTaggedClass.ts +++ b/src/effect/schema/class/MutableTaggedClass.ts @@ -1,5 +1,6 @@ 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" @@ -12,14 +13,14 @@ export function MutableTaggedClass(identifier?: string) { fieldsOr: Fields | HasFields, annotations?: Annotations.Schema, ) => - // S.TaggedClass(identifier)(tag, fieldsOr, annotations) as S.TaggedClass< - // Self, - // Tag, - // { readonly _tag: PropertySignature<":", Tag, never, ":", Tag, true, never> } & Fields - // > - S.TaggedClass(identifier)(tag, fieldsOr, annotations) as S.TaggedClass< + S.TaggedClass(identifier)(tag, fieldsOr, annotations) as IMutableClass< Self, - Tag, - { readonly _tag: PropertySignature<":", Tag, never, ":", Tag, true, never> } & Fields - > + Fields, + Struct.Encoded, + Struct.Context, + Struct.Constructor>, + {}, + {} + > & + { readonly _tag: Tag } } diff --git a/src/effect/schema/class/TMutableClass.ts b/src/effect/schema/class/TMutableClass.ts deleted file mode 100644 index 28171bd..0000000 --- a/src/effect/schema/class/TMutableClass.ts +++ /dev/null @@ -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>, - keyof Fields - > & - Mutable>, - - ConstructorParameters> - > & - - Omit< - StaticType>, - "extend" - > & { - extend(identifier: string): ( - fields: newFields | HasFields, - annotations?: Annotations.Schema, - ) => TMutableClass< - Extended, - Fields & newFields, - I & Struct.Encoded, - R | Struct.Context, - C & Struct.Constructor, - Self, - Proto - > - } -) diff --git a/src/effect/schema/class/index.ts b/src/effect/schema/class/index.ts index c099da4..ae97e69 100644 --- a/src/effect/schema/class/index.ts +++ b/src/effect/schema/class/index.ts @@ -1,6 +1,6 @@ export { Class } from "./Class" export { MobXObservable } from "./MobXObservable" -export { Mutable } from "./Mutable" export { MutableClass } from "./MutableClass" export type { IMutableClass } from "./MutableClass" +export { MutableTaggedClass } from "./MutableTaggedClass" export { TaggedClass } from "./TaggedClass" diff --git a/src/effect/schema/class/tests.ts b/src/effect/schema/class/tests.ts index 60fe28c..25e478d 100644 --- a/src/effect/schema/class/tests.ts +++ b/src/effect/schema/class/tests.ts @@ -1,28 +1,16 @@ import { Schema as S } from "@effect/schema" -import { MutableClass } from "./MutableClass" import { pipe } from "remeda" -import { Mutable } from "./Mutable" import { MobXObservable } from "./MobXObservable" -import { Class } from "./Class" -import { TaggedClass } from "./TaggedClass" +import { MutableTaggedClass } from "./MutableTaggedClass" -const UserSuper = () => pipe( - MutableClass("User")({ +class User extends pipe( + MutableTaggedClass()("User", { id: S.BigIntFromSelf, role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")), }), - // TaggedClass()("User", { - // id: S.BigIntFromSelf, - // role: S.Union(S.Literal("BasicUser"), S.Literal("Admin")), - // }), - - // Mutable, MobXObservable, -) - - -class User extends UserSuper() {} +) {} const user1 = new User({ id: 1n, role: "BasicUser" }) user1.id = 1n