This commit is contained in:
@@ -4,10 +4,8 @@ import { JsonifiableObject } from "type-fest/source/jsonifiable"
|
||||
import { z } from "zod"
|
||||
import { ZodSchemaAbstractClass } from "../shapes/ZodSchemaClass"
|
||||
import { DejsonifiableZodSchemaObject } from "../traits/DejsonifiableZodSchemaObject"
|
||||
import { ExtendableZodSchemaObject } from "../traits/ExtendableZodSchemaObject"
|
||||
import { InstantiableZodSchemaObject } from "../traits/InstantiableZodSchemaObject"
|
||||
import { JsonifiableZodSchemaObject } from "../traits/JsonifiableZodSchemaObject"
|
||||
import { ZodSchemaObjectInstantiationSchemas } from "../traits/ZodSchemaObjectInstantiationSchemas"
|
||||
import { ZodSchemaObject } from "../traits/ZodSchemaObject"
|
||||
import { StaticMembers } from "../util"
|
||||
|
||||
|
||||
@@ -34,7 +32,7 @@ extends TraitExpressionBuilder<Superclass, Traits> {
|
||||
>(
|
||||
this: ZodSchemaClassBuilder<Super, Traits>,
|
||||
|
||||
props: {
|
||||
{ schema, schemaWithDefaultValues }: {
|
||||
schema: z.ZodObject<SchemaT, SchemaUnknownKeys, SchemaCatchall, Values, Values>
|
||||
|
||||
schemaWithDefaultValues: (
|
||||
@@ -42,10 +40,7 @@ extends TraitExpressionBuilder<Superclass, Traits> {
|
||||
) => z.ZodObject<SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues>
|
||||
},
|
||||
) {
|
||||
class Schemas extends (this.expressionSuperclass as AbstractClass<object, []>) {
|
||||
static readonly schema = props.schema
|
||||
static readonly schemaWithDefaultValues = props.schemaWithDefaultValues(props.schema)
|
||||
|
||||
class ZodSchemaObjectConstructor extends (this.expressionSuperclass as AbstractClass<object, []>) {
|
||||
constructor(values: Values) {
|
||||
super()
|
||||
Object.assign(this, values)
|
||||
@@ -53,21 +48,15 @@ extends TraitExpressionBuilder<Superclass, Traits> {
|
||||
}
|
||||
|
||||
return new this.constructor(
|
||||
Schemas as unknown as (
|
||||
ZodSchemaObjectConstructor as unknown as (
|
||||
AbstractClass<
|
||||
InstanceType<Super> & Values,
|
||||
ConstructorParameters<typeof Schemas>
|
||||
[values: Values]
|
||||
> &
|
||||
StaticMembers<Super> &
|
||||
StaticMembers<typeof Schemas>
|
||||
StaticMembers<Super>
|
||||
),
|
||||
|
||||
[
|
||||
...this.expressionTraits,
|
||||
ZodSchemaObjectInstantiationSchemas,
|
||||
InstantiableZodSchemaObject,
|
||||
ExtendableZodSchemaObject,
|
||||
],
|
||||
[...this.expressionTraits, ZodSchemaObject(schema, schemaWithDefaultValues)],
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user