0.1.3 #4

Merged
Thilawyn merged 74 commits from next into master 2024-03-24 22:24:25 +01:00
Showing only changes of commit 07fb50d21d - Show all commits

View File

@@ -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)))
} }