Jsonifiable tests
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Julien Valverdé
2024-01-15 11:17:59 +01:00
parent 354454f76c
commit af84a7ef2a

View File

@@ -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()