From f6c7bf49419af7a7ec6d25f589d27e1d5688cb5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Tue, 18 Jun 2024 00:38:04 +0200 Subject: [PATCH] Jsonifiable work --- src/effect/schema/Jsonifiable.ts | 34 +++++++++++++++++++------------- 1 file changed, 20 insertions(+), 14 deletions(-) diff --git a/src/effect/schema/Jsonifiable.ts b/src/effect/schema/Jsonifiable.ts index 1d055a3..19cb15f 100644 --- a/src/effect/schema/Jsonifiable.ts +++ b/src/effect/schema/Jsonifiable.ts @@ -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("s2")({ - prout: Schema.String +const MyObjectStruct = S.Struct({ + id: S.BigIntFromSelf, + name: S.String, }) -function expectStruct(s: Schema.Struct) {} -expectStruct(s2) +class MyObjectClass extends S.Class("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, + schema: S.Schema, // jsonifiable: Schema.Struct & { readonly Type: I }, - jsonifiable: Schema.Schema + jsonifiable: S.Schema, ) { - return jsonifiable.pipe(Schema.compose(schema)) + return jsonifiable.pipe(S.compose(schema)) } + + +const MyJsonifiableObject = Jsonifiable(MyObjectStruct, MyJsonifiedObject)