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