This commit is contained in:
@@ -35,22 +35,19 @@ export const ZodSchemaObject = <
|
||||
static readonly schema = schema
|
||||
static readonly schemaWithDefaultsValues = schemaWithDefaultValues(schema)
|
||||
|
||||
static instantiationSchema<
|
||||
Self extends StaticMembers<ImplStaticThis<typeof ZodSchemaObject>>,
|
||||
Instance extends Values,
|
||||
>(
|
||||
this: Class<Instance, [values: Values]> & Self
|
||||
) {
|
||||
return this.schema.transform(values => new this(values))
|
||||
}
|
||||
static instantiationTransform<
|
||||
Instance extends Values,
|
||||
|
||||
static instantiationSchemaWithDefaultValues<
|
||||
Self extends StaticMembers<ImplStaticThis<typeof ZodSchemaObject>>,
|
||||
Instance extends Values,
|
||||
T extends z.ZodRawShape,
|
||||
UnknownKeys extends z.UnknownKeysParam,
|
||||
Catchall extends z.ZodTypeAny,
|
||||
Output extends Values,
|
||||
Input,
|
||||
>(
|
||||
this: Class<Instance, [values: Values]> & Self
|
||||
this: Class<Instance, [values: Values]>,
|
||||
schema: z.ZodObject<T, UnknownKeys, Catchall, Output, Input>,
|
||||
) {
|
||||
return this.schemaWithDefaultsValues.transform(values => new this(values))
|
||||
return schema.transform(values => new this(values))
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +58,9 @@ export const ZodSchemaObject = <
|
||||
this: Class<Instance, [values: Values]> & Self,
|
||||
...[values, params]: NewZodSchemaInstanceArgs<PartialValues>
|
||||
) {
|
||||
return this.instantiationSchemaWithDefaultValues().parse(values, params)
|
||||
return this
|
||||
.instantiationTransform(this.schemaWithDefaultsValues)
|
||||
.parse(values, params)
|
||||
}
|
||||
|
||||
static createPromise<
|
||||
@@ -71,7 +70,9 @@ export const ZodSchemaObject = <
|
||||
this: Class<Instance, [values: Values]> & Self,
|
||||
...[values, params]: NewZodSchemaInstanceArgs<PartialValues>
|
||||
) {
|
||||
return this.instantiationSchemaWithDefaultValues().parseAsync(values, params)
|
||||
return this
|
||||
.instantiationTransform(this.schemaWithDefaultsValues)
|
||||
.parseAsync(values, params)
|
||||
}
|
||||
|
||||
static createEffect<
|
||||
@@ -81,7 +82,11 @@ export const ZodSchemaObject = <
|
||||
this: Class<Instance, [values: Values]> & Self,
|
||||
...[values, params]: NewZodSchemaInstanceArgs<PartialValues>
|
||||
) {
|
||||
return parseZodSchemaEffect(this.instantiationSchemaWithDefaultValues(), values, params)
|
||||
return parseZodSchemaEffect(
|
||||
this.instantiationTransform(this.schemaWithDefaultsValues),
|
||||
values,
|
||||
params,
|
||||
)
|
||||
}
|
||||
})
|
||||
.build()
|
||||
|
||||
Reference in New Issue
Block a user