This commit is contained in:
@@ -16,9 +16,9 @@ export function ZodSchemaClass<
|
||||
Values extends object,
|
||||
PartialValues extends Partial<Values>,
|
||||
>(
|
||||
schema: z.ZodObject<T, "strip", Catchall, Values, PartialValues>
|
||||
schemaWithDefaults: z.ZodObject<T, "strip", Catchall, Values, PartialValues>
|
||||
) {
|
||||
return expression
|
||||
.extends(ZodSchemaObjectConstructor<Values>)
|
||||
.expresses(ZodSchemaObject(schema))
|
||||
.expresses(ZodSchemaObject(schemaWithDefaults))
|
||||
}
|
||||
|
||||
@@ -1,16 +1,19 @@
|
||||
// import { trait } from "@thilawyn/traitify-ts"
|
||||
// import { ZodSchemaClassExtender } from "../builders/ZodSchemaClassExtender"
|
||||
// import { ZodSchemaClass } from "../shapes/ZodSchemaClass"
|
||||
import { expression } from "@thilawyn/traitify-ts"
|
||||
import { z } from "zod"
|
||||
import { ZodSchemaObject } from "./ZodSchemaObject"
|
||||
|
||||
|
||||
// export const ExtendableZodSchemaObject = trait
|
||||
// .implement(Super => class ExtendableZodSchemaObject extends Super {
|
||||
// static extend<
|
||||
// Self extends ZodSchemaClass<any, any, any, any, any, any, any, any, any>,
|
||||
// >(
|
||||
// this: Self
|
||||
// ) {
|
||||
// return new ZodSchemaClassExtender(this, this)
|
||||
// }
|
||||
// })
|
||||
// .build()
|
||||
export const ExtendableZodSchemaObject = <
|
||||
T extends z.ZodRawShape,
|
||||
Catchall extends z.ZodTypeAny,
|
||||
Values extends object,
|
||||
PartialValues extends Partial<Values>,
|
||||
>(
|
||||
schemaWithDefaults: z.ZodObject<T, "strip", Catchall, Values, PartialValues>,
|
||||
) => expression
|
||||
.expresses(ZodSchemaObject(schemaWithDefaults))
|
||||
.buildAnyway()
|
||||
.subtrait()
|
||||
.implement(Super => class ExtendableZodSchemaObject extends Super {
|
||||
})
|
||||
.build()
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { ImplStatic, trait } from "@thilawyn/traitify-ts"
|
||||
import { AbstractClass, Class, HasRequiredKeys } from "type-fest"
|
||||
import { Class, HasRequiredKeys } from "type-fest"
|
||||
import { z } from "zod"
|
||||
import { StaticMembers, parseZodSchemaEffect, stripZodObjectDefaults } from "../util"
|
||||
|
||||
@@ -85,13 +85,24 @@ export const ZodSchemaObject = <
|
||||
}
|
||||
|
||||
|
||||
static extend<
|
||||
Self extends AbstractClass<ZodSchemaObject> & ImplStatic<typeof ZodSchemaObject>
|
||||
>(
|
||||
this: Self
|
||||
) {
|
||||
// static extend<
|
||||
// Self extends AbstractClass<ZodSchemaObject> & ImplStatic<typeof ZodSchemaObject>,
|
||||
|
||||
}
|
||||
// ExtendedT extends z.ZodRawShape,
|
||||
// ExtendedCatchall extends z.ZodTypeAny,
|
||||
// ExtendedValues extends Values,
|
||||
// ExtendedPartialValues extends Partial<ExtendedValues>,
|
||||
// >(
|
||||
// this: Self,
|
||||
|
||||
// schemaWithDefaults: (
|
||||
// schemaWithDefaults: typeof this.schemaWithDefaults
|
||||
// ) => z.ZodObject<ExtendedT, "strip", ExtendedCatchall, ExtendedValues, ExtendedPartialValues>,
|
||||
// ) {
|
||||
// return expression
|
||||
// .extends(this)
|
||||
// .expresses(ZodSchemaObject(schemaWithDefaults(this.schemaWithDefaults)))
|
||||
// }
|
||||
}
|
||||
|
||||
return ZodSchemaObject as Class<ZodSchemaObject & Values> & StaticMembers<typeof ZodSchemaObject>
|
||||
|
||||
Reference in New Issue
Block a user