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

This commit is contained in:
Julien Valverdé
2024-01-16 12:43:00 +01:00
parent 892ee29060
commit adc24574ec

View File

@@ -1,6 +1,6 @@
import { pipeInto } from "ts-functional-pipe" import { pipeInto } from "ts-functional-pipe"
import { z } from "zod" import { z } from "zod"
import { makeSchemableClass, newSchemable } from "." import { extendSchemableClass, makeSchemableClass, newSchemable } from "."
import { makeJsonifiableSchemableClass } from "./jsonifiable" import { makeJsonifiableSchemableClass } from "./jsonifiable"
import { dejsonifyBigIntSchema, jsonifyBigIntSchema } from "./legacy/jsonifiable" import { dejsonifyBigIntSchema, jsonifyBigIntSchema } from "./legacy/jsonifiable"
@@ -49,4 +49,22 @@ class User extends pipeInto(
const user1 = newSchemable(User, { id: 1n, name: "User" }) const user1 = newSchemable(User, { id: 1n, name: "User" })
user1.jsonify() console.log(user1.jsonify())
const UserWithPhone = extendSchemableClass(User, {
schema: schema => schema.extend({
phone: z.string()
}),
defaultValues: defaultValues => ({
...defaultValues,
phone: "+33600000000",
}),
})
UserWithPhone.schema
const user2 = newSchemable(UserWithPhone, { id: 1n, name: "User" })
console.log(user2.jsonify())