0.1.3 #4
@@ -1,15 +1,9 @@
|
||||
import { expression } from "@thilawyn/traitify-ts"
|
||||
import { Class } from "type-fest"
|
||||
import { z } from "zod"
|
||||
import { ZodSchemaObject } from "./lib"
|
||||
|
||||
|
||||
class ZodSchemaObjectConstructor<Values> {
|
||||
constructor(values: Values) {
|
||||
Object.assign(this, values)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export function ZodSchemaClass<
|
||||
T extends z.ZodRawShape,
|
||||
Catchall extends z.ZodTypeAny,
|
||||
@@ -19,6 +13,12 @@ export function ZodSchemaClass<
|
||||
schemaWithDefaults: z.ZodObject<T, "strip", Catchall, Values, PartialValues>
|
||||
) {
|
||||
return expression
|
||||
.extends(ZodSchemaObjectConstructor<Values>)
|
||||
.extends(
|
||||
class ZodSchemaObjectConstructor {
|
||||
constructor(values: Values) {
|
||||
Object.assign(this, values)
|
||||
}
|
||||
} as Class<Values, [values: Values]>
|
||||
)
|
||||
.expresses(ZodSchemaObject(schemaWithDefaults))
|
||||
}
|
||||
|
||||
@@ -12,8 +12,8 @@ export const ExtendableZodSchemaObject = <
|
||||
schemaWithDefaults: z.ZodObject<T, "strip", Catchall, Values, PartialValues>,
|
||||
) => expression
|
||||
.expresses(ZodSchemaObject(schemaWithDefaults))
|
||||
.buildAnyway()
|
||||
.build()
|
||||
.subtrait()
|
||||
.implement(Super => class ExtendableZodSchemaObject extends Super {
|
||||
.implement(Super => class ExtendableZodSchemaObjectImpl extends Super {
|
||||
})
|
||||
.build()
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import { ImplStatic, trait } from "@thilawyn/traitify-ts"
|
||||
import { Class, HasRequiredKeys } from "type-fest"
|
||||
import { z } from "zod"
|
||||
import { StaticMembers, parseZodSchemaEffect, stripZodObjectDefaults } from "../util"
|
||||
import { parseZodSchemaEffect, stripZodObjectDefaults } from "../util"
|
||||
|
||||
|
||||
type CreateArgs<Input extends object> = (
|
||||
@@ -19,8 +19,7 @@ export const ZodSchemaObject = <
|
||||
>(
|
||||
schemaWithDefaults: z.ZodObject<T, "strip", Catchall, Values, PartialValues>,
|
||||
) => trait
|
||||
.implement(Super => {
|
||||
class ZodSchemaObject extends Super {
|
||||
.implement(Super => class ZodSchemaObjectImpl extends Super {
|
||||
static readonly schema = stripZodObjectDefaults(schemaWithDefaults)
|
||||
static readonly schemaWithDefaults = schemaWithDefaults
|
||||
|
||||
@@ -45,7 +44,7 @@ export const ZodSchemaObject = <
|
||||
>(
|
||||
this: (
|
||||
Class<Instance, [values: Values]> &
|
||||
ImplStatic<typeof ZodSchemaObject>
|
||||
ImplStatic<typeof ZodSchemaObjectImpl>
|
||||
),
|
||||
...[values, params]: CreateArgs<PartialValues>
|
||||
) {
|
||||
@@ -59,7 +58,7 @@ export const ZodSchemaObject = <
|
||||
>(
|
||||
this: (
|
||||
Class<Instance, [values: Values]> &
|
||||
ImplStatic<typeof ZodSchemaObject>
|
||||
ImplStatic<typeof ZodSchemaObjectImpl>
|
||||
),
|
||||
...[values, params]: CreateArgs<PartialValues>
|
||||
) {
|
||||
@@ -73,7 +72,7 @@ export const ZodSchemaObject = <
|
||||
>(
|
||||
this: (
|
||||
Class<Instance, [values: Values]> &
|
||||
ImplStatic<typeof ZodSchemaObject>
|
||||
ImplStatic<typeof ZodSchemaObjectImpl>
|
||||
),
|
||||
...[values, params]: CreateArgs<PartialValues>
|
||||
) {
|
||||
@@ -103,9 +102,6 @@ export const ZodSchemaObject = <
|
||||
// .extends(this)
|
||||
// .expresses(ZodSchemaObject(schemaWithDefaults(this.schemaWithDefaults)))
|
||||
// }
|
||||
}
|
||||
|
||||
return ZodSchemaObject as Class<ZodSchemaObject & Values> & StaticMembers<typeof ZodSchemaObject>
|
||||
})
|
||||
.build()
|
||||
|
||||
|
||||
Reference in New Issue
Block a user