From 6fac7c7321a89a8fc89f695f5ca89444ed93e300 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Sun, 16 Jun 2024 04:12:28 +0200 Subject: [PATCH] Refactoring --- src/effect/schema/class/Class.ts | 24 +++++------ src/effect/schema/class/MutableClass.ts | 24 +++++------ src/effect/schema/class/MutableTaggedClass.ts | 42 ++++++++++++------- src/effect/schema/class/TaggedClass.ts | 16 ++++--- src/effect/schema/class/index.ts | 1 + 5 files changed, 57 insertions(+), 50 deletions(-) diff --git a/src/effect/schema/class/Class.ts b/src/effect/schema/class/Class.ts index dcbba72..818e205 100644 --- a/src/effect/schema/class/Class.ts +++ b/src/effect/schema/class/Class.ts @@ -3,18 +3,16 @@ import type { Annotations, Struct } from "@effect/schema/Schema" import type { HasFields } from "./util" -export function Class(identifier: string) { - return ( +export const Class = S.Class as (identifier: string) => + ( fieldsOr: Fields | HasFields, annotations?: Annotations.Schema, - ) => - S.Class(identifier)(fieldsOr, annotations) as S.Class< - Self, - Fields, - Struct.Encoded, - Struct.Context, - Struct.Constructor, - {}, - {} - > -} + ) => S.Class< + Self, + Fields, + Struct.Encoded, + Struct.Context, + Struct.Constructor, + {}, + {} + > diff --git a/src/effect/schema/class/MutableClass.ts b/src/effect/schema/class/MutableClass.ts index 38c14b5..5040ba0 100644 --- a/src/effect/schema/class/MutableClass.ts +++ b/src/effect/schema/class/MutableClass.ts @@ -40,18 +40,16 @@ extends Omit< } -export function MutableClass(identifier: string) { - return ( +export const MutableClass = S.Class as (identifier: string) => + ( fieldsOr: Fields | HasFields, annotations?: Annotations.Schema, - ) => - S.Class(identifier)(fieldsOr, annotations) as IMutableClass< - Self, - Fields, - Struct.Encoded, - Struct.Context, - Struct.Constructor, - {}, - {} - > -} + ) => IMutableClass< + Self, + Fields, + Struct.Encoded, + Struct.Context, + Struct.Constructor, + {}, + {} + > diff --git a/src/effect/schema/class/MutableTaggedClass.ts b/src/effect/schema/class/MutableTaggedClass.ts index 428b303..b706616 100644 --- a/src/effect/schema/class/MutableTaggedClass.ts +++ b/src/effect/schema/class/MutableTaggedClass.ts @@ -1,26 +1,38 @@ import { Schema as S } from "@effect/schema" -import type { Annotations, Struct } from "@effect/schema/Schema" +import type { Annotations, PropertySignature, Struct } from "@effect/schema/Schema" import type { IMutableClass } from "./MutableClass" import type { HasFields } from "./util" -export function MutableTaggedClass(identifier?: string) { - return < +export interface IMutableTaggedClass< + Self, + Tag, + Fields extends Struct.Fields, +> +extends IMutableClass< + Self, + Fields, + Struct.Encoded, + Struct.Context, + Struct.Constructor>, + {}, + {} +> +{ + readonly _tag: Tag +} + + +export const MutableTaggedClass = S.TaggedClass as (identifier?: string) => + < Tag extends string, Fields extends Struct.Fields, >( tag: Tag, fieldsOr: Fields | HasFields, annotations?: Annotations.Schema, - ) => - S.TaggedClass(identifier)(tag, fieldsOr, annotations) as IMutableClass< - Self, - Fields, - Struct.Encoded, - Struct.Context, - Struct.Constructor>, - {}, - {} - > & - { readonly _tag: Tag } -} + ) => IMutableTaggedClass< + Self, + Tag, + { readonly _tag: PropertySignature<":", Tag, never, ":", Tag, true, never> } & Fields + > diff --git a/src/effect/schema/class/TaggedClass.ts b/src/effect/schema/class/TaggedClass.ts index 1619805..3d22786 100644 --- a/src/effect/schema/class/TaggedClass.ts +++ b/src/effect/schema/class/TaggedClass.ts @@ -3,18 +3,16 @@ import type { Annotations, PropertySignature, Struct } from "@effect/schema/Sche import type { HasFields } from "./util" -export function TaggedClass(identifier?: string) { - return < +export const TaggedClass = S.TaggedClass as (identifier?: string) => + < Tag extends string, Fields extends Struct.Fields, >( tag: Tag, 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< + Self, + Tag, + { readonly _tag: PropertySignature<":", Tag, never, ":", Tag, true, never> } & Fields + > diff --git a/src/effect/schema/class/index.ts b/src/effect/schema/class/index.ts index ae97e69..3bc9960 100644 --- a/src/effect/schema/class/index.ts +++ b/src/effect/schema/class/index.ts @@ -3,4 +3,5 @@ export { MobXObservable } from "./MobXObservable" export { MutableClass } from "./MutableClass" export type { IMutableClass } from "./MutableClass" export { MutableTaggedClass } from "./MutableTaggedClass" +export type { IMutableTaggedClass } from "./MutableTaggedClass" export { TaggedClass } from "./TaggedClass"