Mutable work
This commit is contained in:
@@ -1,48 +1,7 @@
|
|||||||
import { Schema as S } from "@effect/schema"
|
import type { Class, Struct } from "@effect/schema/Schema"
|
||||||
import type { Annotations, Class, Struct } from "@effect/schema/Schema"
|
|
||||||
import type { Mutable } from "effect/Types"
|
|
||||||
import type { Constructor } from "type-fest"
|
import type { Constructor } from "type-fest"
|
||||||
import type { StaticType } from "../../.."
|
import type { StaticType } from "../../.."
|
||||||
import type { HasFields, MissingSelfGeneric } from "./util"
|
import type { TMutableClass } from "./TMutableClass"
|
||||||
|
|
||||||
|
|
||||||
export type TMutableClass<
|
|
||||||
Self,
|
|
||||||
Fields extends Struct.Fields,
|
|
||||||
I, R, C,
|
|
||||||
Inherited,
|
|
||||||
Proto,
|
|
||||||
> = (
|
|
||||||
Constructor<
|
|
||||||
Omit<
|
|
||||||
InstanceType<Class<Self, Fields, I, R, C, Inherited, Proto>>,
|
|
||||||
keyof Fields
|
|
||||||
> &
|
|
||||||
Mutable<Struct.Type<Fields>>,
|
|
||||||
|
|
||||||
ConstructorParameters<Class<Self, Fields, I, R, C, Inherited, Proto>>
|
|
||||||
> &
|
|
||||||
|
|
||||||
Omit<
|
|
||||||
StaticType<Class<Self, Fields, I, R, C, Inherited, Proto>>,
|
|
||||||
"extend"
|
|
||||||
> & {
|
|
||||||
extend<Extended = never>(identifier: string): <newFields extends Struct.Fields>(
|
|
||||||
fields: newFields | HasFields<newFields>,
|
|
||||||
annotations?: Annotations.Schema<Extended>,
|
|
||||||
) => [Extended] extends [never]
|
|
||||||
? MissingSelfGeneric<"Base.extend">
|
|
||||||
: TMutableClass<
|
|
||||||
Extended,
|
|
||||||
Fields & newFields,
|
|
||||||
I & Struct.Encoded<newFields>,
|
|
||||||
R | Struct.Context<newFields>,
|
|
||||||
C & Struct.Constructor<newFields>,
|
|
||||||
Self,
|
|
||||||
Proto
|
|
||||||
>
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
|
|
||||||
export function Mutable<
|
export function Mutable<
|
||||||
@@ -58,5 +17,21 @@ export function Mutable<
|
|||||||
| This
|
| This
|
||||||
| Class<Self, Fields, I, R, C, Inherited, Proto>
|
| Class<Self, Fields, I, R, C, Inherited, Proto>
|
||||||
) {
|
) {
|
||||||
|
return class_ as (
|
||||||
|
Constructor<
|
||||||
|
Omit<
|
||||||
|
InstanceType<This>,
|
||||||
|
keyof InstanceType<TMutableClass<Self, Fields, I, R, C, Inherited, Proto>>
|
||||||
|
> &
|
||||||
|
InstanceType<TMutableClass<Self, Fields, I, R, C, Inherited, Proto>>,
|
||||||
|
|
||||||
|
ConstructorParameters<TMutableClass<Self, Fields, I, R, C, Inherited, Proto>>
|
||||||
|
> &
|
||||||
|
|
||||||
|
Omit<
|
||||||
|
StaticType<This>,
|
||||||
|
keyof StaticType<TMutableClass<Self, Fields, I, R, C, Inherited, Proto>>
|
||||||
|
> &
|
||||||
|
StaticType<TMutableClass<Self, Fields, I, R, C, Inherited, Proto>>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,49 +1,9 @@
|
|||||||
import { Schema as S } from "@effect/schema"
|
import { Schema as S } from "@effect/schema"
|
||||||
import type { Annotations, Class, Struct } from "@effect/schema/Schema"
|
import type { Annotations, Struct } from "@effect/schema/Schema"
|
||||||
import type { Mutable } from "effect/Types"
|
import type { TMutableClass } from "./TMutableClass"
|
||||||
import type { Constructor } from "type-fest"
|
|
||||||
import type { StaticType } from "../../.."
|
|
||||||
import type { HasFields, MissingSelfGeneric } from "./util"
|
import type { HasFields, MissingSelfGeneric } from "./util"
|
||||||
|
|
||||||
|
|
||||||
export type TMutableClass<
|
|
||||||
Self,
|
|
||||||
Fields extends Struct.Fields,
|
|
||||||
I, R, C,
|
|
||||||
Inherited,
|
|
||||||
Proto,
|
|
||||||
> = (
|
|
||||||
Constructor<
|
|
||||||
Omit<
|
|
||||||
InstanceType<Class<Self, Fields, I, R, C, Inherited, Proto>>,
|
|
||||||
keyof Fields
|
|
||||||
> &
|
|
||||||
Mutable<Struct.Type<Fields>>,
|
|
||||||
|
|
||||||
ConstructorParameters<Class<Self, Fields, I, R, C, Inherited, Proto>>
|
|
||||||
> &
|
|
||||||
|
|
||||||
Omit<
|
|
||||||
StaticType<Class<Self, Fields, I, R, C, Inherited, Proto>>,
|
|
||||||
"extend"
|
|
||||||
> & {
|
|
||||||
extend<Extended = never>(identifier: string): <newFields extends Struct.Fields>(
|
|
||||||
fields: newFields | HasFields<newFields>,
|
|
||||||
annotations?: Annotations.Schema<Extended>,
|
|
||||||
) => [Extended] extends [never]
|
|
||||||
? MissingSelfGeneric<"Base.extend">
|
|
||||||
: TMutableClass<
|
|
||||||
Extended,
|
|
||||||
Fields & newFields,
|
|
||||||
I & Struct.Encoded<newFields>,
|
|
||||||
R | Struct.Context<newFields>,
|
|
||||||
C & Struct.Constructor<newFields>,
|
|
||||||
Self,
|
|
||||||
Proto
|
|
||||||
>
|
|
||||||
}
|
|
||||||
)
|
|
||||||
|
|
||||||
export const MutableClass = <Self = never>(identifier: string) => (
|
export const MutableClass = <Self = never>(identifier: string) => (
|
||||||
<Fields extends Struct.Fields>(
|
<Fields extends Struct.Fields>(
|
||||||
fieldsOr: Fields | HasFields<Fields>,
|
fieldsOr: Fields | HasFields<Fields>,
|
||||||
|
|||||||
44
src/effect/schema/class/TMutableClass.ts
Normal file
44
src/effect/schema/class/TMutableClass.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
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, MissingSelfGeneric } from "./util"
|
||||||
|
|
||||||
|
|
||||||
|
export type TMutableClass<
|
||||||
|
Self,
|
||||||
|
Fields extends Struct.Fields,
|
||||||
|
I, R, C,
|
||||||
|
Inherited,
|
||||||
|
Proto,
|
||||||
|
> = (
|
||||||
|
Constructor<
|
||||||
|
Omit<
|
||||||
|
InstanceType<Class<Self, Fields, I, R, C, Inherited, Proto>>,
|
||||||
|
keyof Fields
|
||||||
|
> &
|
||||||
|
Mutable<Struct.Type<Fields>>,
|
||||||
|
|
||||||
|
ConstructorParameters<Class<Self, Fields, I, R, C, Inherited, Proto>>
|
||||||
|
> &
|
||||||
|
|
||||||
|
Omit<
|
||||||
|
StaticType<Class<Self, Fields, I, R, C, Inherited, Proto>>,
|
||||||
|
"extend"
|
||||||
|
> & {
|
||||||
|
extend<Extended = never>(identifier: string): <newFields extends Struct.Fields>(
|
||||||
|
fields: newFields | HasFields<newFields>,
|
||||||
|
annotations?: Annotations.Schema<Extended>,
|
||||||
|
) => [Extended] extends [never]
|
||||||
|
? MissingSelfGeneric<"Base.extend">
|
||||||
|
: TMutableClass<
|
||||||
|
Extended,
|
||||||
|
Fields & newFields,
|
||||||
|
I & Struct.Encoded<newFields>,
|
||||||
|
R | Struct.Context<newFields>,
|
||||||
|
C & Struct.Constructor<newFields>,
|
||||||
|
Self,
|
||||||
|
Proto
|
||||||
|
>
|
||||||
|
}
|
||||||
|
)
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
export { MobXObservable } from "./MobXObservable"
|
export { MobXObservable } from "./MobXObservable"
|
||||||
|
export { Mutable } from "./Mutable"
|
||||||
export { MutableClass } from "./MutableClass"
|
export { MutableClass } from "./MutableClass"
|
||||||
export type { TMutableClass } from "./MutableClass"
|
export type { TMutableClass } from "./TMutableClass"
|
||||||
|
|||||||
Reference in New Issue
Block a user