diff --git a/src/effect/schema/MutableClass.ts b/src/effect/schema/MutableClass.ts new file mode 100644 index 0000000..70f5411 --- /dev/null +++ b/src/effect/schema/MutableClass.ts @@ -0,0 +1,24 @@ +import { Schema as S } from "@effect/schema" +import type { Annotations, Class, Struct } from "@effect/schema/Schema" +import type { HasFields, MissingSelfGeneric } from "./util" + + +export const MutableClass = (identifier: string) => ( + ( + fieldsOr: Fields | HasFields, + annotations?: Annotations.Schema + ): ( + [Self] extends [never] + ? MissingSelfGeneric<"Class"> + : Class< + Self, + Fields, + Struct.Encoded, + Struct.Context, + Struct.Constructor, + {}, + {} + > + ) => + S.Class(identifier)(fieldsOr, annotations) +) diff --git a/src/effect/schema/index.ts b/src/effect/schema/index.ts index 336ce12..8c87023 100644 --- a/src/effect/schema/index.ts +++ b/src/effect/schema/index.ts @@ -1 +1 @@ -export {} +export { MutableClass } from "./MutableClass" diff --git a/src/effect/schema/tests.ts b/src/effect/schema/tests.ts new file mode 100644 index 0000000..64a465e --- /dev/null +++ b/src/effect/schema/tests.ts @@ -0,0 +1 @@ +import { Schema as S } from "@effect/schema" diff --git a/src/effect/schema/util.ts b/src/effect/schema/util.ts new file mode 100644 index 0000000..504f41b --- /dev/null +++ b/src/effect/schema/util.ts @@ -0,0 +1,11 @@ +import type { Struct } from "@effect/schema/Schema" + + +export type MissingSelfGeneric = ( + `Missing \`Self\` generic - use \`class Self extends ${Usage}()(${Params}{ ... })\`` +) + +export type HasFields = ( + | { readonly fields: Fields } + | { readonly from: HasFields } +)