MutableClass
This commit is contained in:
24
src/effect/schema/MutableClass.ts
Normal file
24
src/effect/schema/MutableClass.ts
Normal file
@@ -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 = <Self = never>(identifier: string) => (
|
||||||
|
<Fields extends Struct.Fields>(
|
||||||
|
fieldsOr: Fields | HasFields<Fields>,
|
||||||
|
annotations?: Annotations.Schema<Self>
|
||||||
|
): (
|
||||||
|
[Self] extends [never]
|
||||||
|
? MissingSelfGeneric<"Class">
|
||||||
|
: Class<
|
||||||
|
Self,
|
||||||
|
Fields,
|
||||||
|
Struct.Encoded<Fields>,
|
||||||
|
Struct.Context<Fields>,
|
||||||
|
Struct.Constructor<Fields>,
|
||||||
|
{},
|
||||||
|
{}
|
||||||
|
>
|
||||||
|
) =>
|
||||||
|
S.Class<Self>(identifier)(fieldsOr, annotations)
|
||||||
|
)
|
||||||
@@ -1 +1 @@
|
|||||||
export {}
|
export { MutableClass } from "./MutableClass"
|
||||||
|
|||||||
1
src/effect/schema/tests.ts
Normal file
1
src/effect/schema/tests.ts
Normal file
@@ -0,0 +1 @@
|
|||||||
|
import { Schema as S } from "@effect/schema"
|
||||||
11
src/effect/schema/util.ts
Normal file
11
src/effect/schema/util.ts
Normal file
@@ -0,0 +1,11 @@
|
|||||||
|
import type { Struct } from "@effect/schema/Schema"
|
||||||
|
|
||||||
|
|
||||||
|
export type MissingSelfGeneric<Usage extends string, Params extends string = ""> = (
|
||||||
|
`Missing \`Self\` generic - use \`class Self extends ${Usage}<Self>()(${Params}{ ... })\``
|
||||||
|
)
|
||||||
|
|
||||||
|
export type HasFields<Fields extends Struct.Fields> = (
|
||||||
|
| { readonly fields: Fields }
|
||||||
|
| { readonly from: HasFields<Fields> }
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user