import { pipeInto } from "ts-functional-pipe" import { z } from "zod" import { makeSchemableClass, newSchemable } from "." import { makeJsonifiableSchemableClass } from "./jsonifiable" import { dejsonifyBigIntSchema, jsonifyBigIntSchema } from "./legacy/jsonifiable" const UserLevel = z.enum(["User", "Admin"]) const UserProto = makeSchemableClass({ schema: z.object({ id: z.bigint(), name: z.string(), level: UserLevel, }), defaultValues: { level: "User" } as const, }) UserProto.defaultValues class User extends pipeInto( makeSchemableClass({ schema: z.object({ id: z.bigint(), name: z.string(), level: UserLevel, }), defaultValues: { level: "User" } as const, }), v => makeJsonifiableSchemableClass(v, { jsonifySchema: ({ schema, shape }) => schema.extend({ id: jsonifyBigIntSchema(shape.id) }), dejsonifySchema: ({ schema, shape }) => schema.extend({ id: dejsonifyBigIntSchema(shape.id) }), }) ) {} const user1 = newSchemable(User, { id: 1n, name: "User" }) user1.jsonify()