This commit is contained in:
@@ -3,6 +3,13 @@ import { z } from "zod"
|
|||||||
import { ZodSchemaObject } from "./lib"
|
import { ZodSchemaObject } from "./lib"
|
||||||
|
|
||||||
|
|
||||||
|
class ZodSchemaObjectConstructor<Values> {
|
||||||
|
constructor(values: Values) {
|
||||||
|
Object.assign(this, values)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
export function ZodSchemaClass<
|
export function ZodSchemaClass<
|
||||||
SchemaT extends z.ZodRawShape,
|
SchemaT extends z.ZodRawShape,
|
||||||
SchemaCatchall extends z.ZodTypeAny,
|
SchemaCatchall extends z.ZodTypeAny,
|
||||||
@@ -20,16 +27,7 @@ export function ZodSchemaClass<
|
|||||||
) => z.ZodObject<SchemaWithDefaultValuesT, "strip", SchemaWithDefaultValuesCatchall, Values, PartialValues>
|
) => 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
|
return expression
|
||||||
.extends(ZodSchemaObjectConstructor)
|
.extends(ZodSchemaObjectConstructor<Values>)
|
||||||
.expresses(ZodSchemaObject(schema, schemaWithDefaultValues))
|
.expresses(ZodSchemaObject(props.schema, props.schemaWithDefaultValues(props.schema)))
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user