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

This commit is contained in:
Julien Valverdé
2024-03-15 03:40:48 +01:00
parent 83b5af1719
commit 07fb50d21d

View File

@@ -3,6 +3,13 @@ import { z } from "zod"
import { ZodSchemaObject } from "./lib"
class ZodSchemaObjectConstructor<Values> {
constructor(values: Values) {
Object.assign(this, values)
}
}
export function ZodSchemaClass<
SchemaT extends z.ZodRawShape,
SchemaCatchall extends z.ZodTypeAny,
@@ -20,16 +27,7 @@ export function ZodSchemaClass<
) => z.ZodObject<SchemaWithDefaultValuesT, "strip", SchemaWithDefaultValuesCatchall, Values, PartialValues>
}
) {
const schema = props.schema
const schemaWithDefaultValues = props.schemaWithDefaultValues(props.schema)
abstract class ZodSchemaObjectConstructor {
constructor(values: Values) {
Object.assign(this, values)
}
}
return expression
.extends(ZodSchemaObjectConstructor)
.expresses(ZodSchemaObject(schema, schemaWithDefaultValues))
.extends(ZodSchemaObjectConstructor<Values>)
.expresses(ZodSchemaObject(props.schema, props.schemaWithDefaultValues(props.schema)))
}