31 lines
792 B
TypeScript
31 lines
792 B
TypeScript
import { extendsAndExpresses } from "@thilawyn/thilatrait"
|
|
import { z } from "zod"
|
|
import { makeSchemableClass, newSchemable } from "."
|
|
import { JsonifiableSchemable } from "./jsonifiable"
|
|
import { dejsonifyBigIntSchema, jsonifyBigIntSchema } from "./legacy/jsonifiable"
|
|
|
|
|
|
const UserLevel = z.enum(["User", "Admin"])
|
|
|
|
|
|
const UserProto = makeSchemableClass(z.object({
|
|
id: z.bigint(),
|
|
name: z.string(),
|
|
level: UserLevel,
|
|
}), {
|
|
level: "User"
|
|
} as const)
|
|
|
|
UserProto.defaultValues
|
|
|
|
|
|
class User extends extendsAndExpresses(UserProto,
|
|
JsonifiableSchemable(
|
|
UserProto.schema.extend({ id: jsonifyBigIntSchema(z.bigint()) }),
|
|
UserProto.schema.extend({ id: dejsonifyBigIntSchema(z.bigint()) }),
|
|
)
|
|
) {}
|
|
|
|
|
|
const user1 = newSchemable(User, { id: 1n, name: "User" })
|