This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import { ImplStaticThis, trait } from "@thilawyn/traitify-ts"
|
||||
import { Class, HasRequiredKeys } from "type-fest"
|
||||
import { z } from "zod"
|
||||
import { StaticMembers } from "../util"
|
||||
import { StaticMembers, parseZodSchemaEffect } from "../util"
|
||||
|
||||
|
||||
type ParseParamsArgs = [] | [params: Partial<z.ParseParams>]
|
||||
@@ -50,20 +50,38 @@ export const ZodSchemaObject = <
|
||||
>(
|
||||
this: Class<Instance, [values: Values]> & Self
|
||||
) {
|
||||
return this.schema.transform(values => new this(values))
|
||||
return this.schemaWithDefaultsValues.transform(values => new this(values))
|
||||
}
|
||||
|
||||
|
||||
static create<
|
||||
Instance extends Values
|
||||
Self extends StaticMembers<ImplStaticThis<typeof ZodSchemaObject>>,
|
||||
Instance extends Values,
|
||||
>(
|
||||
this: (
|
||||
Class<Instance, [values: Values]> &
|
||||
StaticMembers<ImplStaticThis<typeof ZodSchemaObject>>
|
||||
),
|
||||
this: Class<Instance, [values: Values]> & Self,
|
||||
...[values, params]: NewZodSchemaInstanceArgs<PartialValues>
|
||||
) {
|
||||
return this.instantiationSchemaWithDefaultValues().parse(values, params)
|
||||
}
|
||||
|
||||
static createPromise<
|
||||
Self extends StaticMembers<ImplStaticThis<typeof ZodSchemaObject>>,
|
||||
Instance extends Values,
|
||||
>(
|
||||
this: Class<Instance, [values: Values]> & Self,
|
||||
...[values, params]: NewZodSchemaInstanceArgs<PartialValues>
|
||||
) {
|
||||
return this.instantiationSchemaWithDefaultValues().parseAsync(values, params)
|
||||
}
|
||||
|
||||
static createEffect<
|
||||
Self extends StaticMembers<ImplStaticThis<typeof ZodSchemaObject>>,
|
||||
Instance extends Values,
|
||||
>(
|
||||
this: Class<Instance, [values: Values]> & Self,
|
||||
...[values, params]: NewZodSchemaInstanceArgs<PartialValues>
|
||||
) {
|
||||
return parseZodSchemaEffect(this.instantiationSchemaWithDefaultValues(), values, params)
|
||||
}
|
||||
})
|
||||
.build()
|
||||
|
||||
Reference in New Issue
Block a user