This commit is contained in:
@@ -1,28 +1,34 @@
|
|||||||
import { Schema } from "@effect/schema"
|
import { Schema as S } from "@effect/schema"
|
||||||
import * as TF from "type-fest"
|
import * as TF from "type-fest"
|
||||||
|
|
||||||
|
|
||||||
const s1 = Schema.Struct({
|
const MyObjectStruct = S.Struct({
|
||||||
prout: Schema.String
|
id: S.BigIntFromSelf,
|
||||||
})
|
name: S.String,
|
||||||
s1 satisfies { readonly Type: TF.Jsonifiable }
|
|
||||||
|
|
||||||
const s2 = Schema.Class<unknown>("s2")({
|
|
||||||
prout: Schema.String
|
|
||||||
})
|
})
|
||||||
|
|
||||||
function expectStruct(s: Schema.Struct<any>) {}
|
class MyObjectClass extends S.Class<MyObjectClass>("MyObjectClass")({
|
||||||
expectStruct(s2)
|
id: S.BigIntFromSelf,
|
||||||
|
name: S.String,
|
||||||
|
}) {}
|
||||||
|
|
||||||
|
const MyJsonifiedObject = S.Struct({
|
||||||
|
...MyObjectStruct.fields,
|
||||||
|
id: S.BigInt,
|
||||||
|
})
|
||||||
|
|
||||||
|
|
||||||
export function Jsonifiable<
|
export function Jsonifiable<
|
||||||
A, I, R,
|
A, I, R,
|
||||||
JsonifiableA extends I, JsonifiableI, JsonifiableR,
|
JsonifiableA extends I, JsonifiableI extends TF.Jsonifiable, JsonifiableR,
|
||||||
// JsonifiableFields extends Schema.Struct.Fields
|
// JsonifiableFields extends Schema.Struct.Fields
|
||||||
>(
|
>(
|
||||||
schema: Schema.Schema<A, I, R>,
|
schema: S.Schema<A, I, R>,
|
||||||
// jsonifiable: Schema.Struct<JsonifiableFields> & { readonly Type: I },
|
// jsonifiable: Schema.Struct<JsonifiableFields> & { readonly Type: I },
|
||||||
jsonifiable: Schema.Schema<JsonifiableA, JsonifiableI, JsonifiableR>
|
jsonifiable: S.Schema<JsonifiableA, JsonifiableI, JsonifiableR>,
|
||||||
) {
|
) {
|
||||||
return jsonifiable.pipe(Schema.compose(schema))
|
return jsonifiable.pipe(S.compose(schema))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
const MyJsonifiableObject = Jsonifiable(MyObjectStruct, MyJsonifiedObject)
|
||||||
|
|||||||
Reference in New Issue
Block a user