SchemaWithDefaultValues
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Julien Valverdé
2024-02-26 22:55:44 +01:00
parent c652aae238
commit 055caf1320
5 changed files with 121 additions and 95 deletions

View File

@@ -3,7 +3,6 @@ import { z } from "zod"
import { zodSchemaClass } from "./builders/ZodSchemaClassBuilder"
import { dejsonify, jsonify } from "./schema/jsonify"
import { MobXObservableZodSchemaObject } from "./traits/MobXObservableZodSchemaObject"
import { StaticMembers } from "./util"
const exp = zodSchemaClass
@@ -16,7 +15,9 @@ const exp = zodSchemaClass
name: z.string(),
}),
defaultValues: { id: -1n },
schemaWithDefaultValues: s => s.extend({
id: s.shape.id.default(-1n)
}),
})
.jsonifiable({
jsonifySchema: s => s.extend({
@@ -33,7 +34,12 @@ const exp = zodSchemaClass
@exp.staticImplements
class User extends exp.extends implements Implements<typeof exp> {}
User.defaultValues
const test = User.schema.extend({
prout: z.string()
}).merge(
User.schemaWithDefaultValues
)
const inst = User.create({ id: 1n, name: "" })
// console.log(inst)
const jsonifiedUser = await inst.jsonifyPromise()