From af84a7ef2a3f83060e46e5e233c15251631317b2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Julien=20Valverd=C3=A9?= Date: Mon, 15 Jan 2024 11:17:59 +0100 Subject: [PATCH] Jsonifiable tests --- src/tests.ts | 24 ++++++++++++++++-------- 1 file changed, 16 insertions(+), 8 deletions(-) diff --git a/src/tests.ts b/src/tests.ts index 33cca5c..bd17337 100644 --- a/src/tests.ts +++ b/src/tests.ts @@ -1,7 +1,6 @@ -import { extendsAndExpresses } from "@thilawyn/thilatrait" import { z } from "zod" import { makeSchemableClass, newSchemable } from "." -import { JsonifiableSchemable } from "./jsonifiable" +import { makeJsonifiableSchemableClass } from "./jsonifiable" import { dejsonifyBigIntSchema, jsonifyBigIntSchema } from "./legacy/jsonifiable" @@ -19,12 +18,21 @@ const UserProto = makeSchemableClass(z.object({ UserProto.defaultValues -class User extends extendsAndExpresses(UserProto, - JsonifiableSchemable( - UserProto.schema.extend({ id: jsonifyBigIntSchema(z.bigint()) }), - UserProto.schema.extend({ id: dejsonifyBigIntSchema(z.bigint()) }), - ) -) {} +const JsonifiableUserProto = makeJsonifiableSchemableClass({ + extend: UserProto, + + jsonifySchema: ({ schema, shape }) => schema.extend({ + id: jsonifyBigIntSchema(shape.id) + }), + + dejsonifySchema: ({ schema, shape }) => schema.extend({ + id: dejsonifyBigIntSchema(shape.id) + }), +}) + + +class User extends JsonifiableUserProto {} const user1 = newSchemable(User, { id: 1n, name: "User" }) +user1.jsonify()