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"
|
||||
|
||||
|
||||
const s1 = Schema.Struct({
|
||||
prout: Schema.String
|
||||
})
|
||||
s1 satisfies { readonly Type: TF.Jsonifiable }
|
||||
|
||||
const s2 = Schema.Class<unknown>("s2")({
|
||||
prout: Schema.String
|
||||
const MyObjectStruct = S.Struct({
|
||||
id: S.BigIntFromSelf,
|
||||
name: S.String,
|
||||
})
|
||||
|
||||
function expectStruct(s: Schema.Struct<any>) {}
|
||||
expectStruct(s2)
|
||||
class MyObjectClass extends S.Class<MyObjectClass>("MyObjectClass")({
|
||||
id: S.BigIntFromSelf,
|
||||
name: S.String,
|
||||
}) {}
|
||||
|
||||
const MyJsonifiedObject = S.Struct({
|
||||
...MyObjectStruct.fields,
|
||||
id: S.BigInt,
|
||||
})
|
||||
|
||||
|
||||
export function Jsonifiable<
|
||||
A, I, R,
|
||||
JsonifiableA extends I, JsonifiableI, JsonifiableR,
|
||||
JsonifiableA extends I, JsonifiableI extends TF.Jsonifiable, JsonifiableR,
|
||||
// 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.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