ZodSchemaObject fix
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Julien Valverdé
2024-03-17 13:22:31 +01:00
parent d45708dc26
commit 1a1a169719

View File

@@ -19,69 +19,73 @@ export const ZodSchemaObject = <
>(
schemaWithDefaults: z.ZodObject<T, "strip", Catchall, Values, PartialValues>,
) => trait
.implement(Super => class ZodSchemaObjectImpl extends Super {
static readonly schema = stripZodObjectDefaults<T, "strip", Catchall, Values, PartialValues>(schemaWithDefaults)
static readonly schemaWithDefaults = schemaWithDefaults
.implement(Super => {
class ZodSchemaObjectImpl extends Super {
static readonly schema = stripZodObjectDefaults(schemaWithDefaults)
static readonly schemaWithDefaults = schemaWithDefaults
static transform<
Instance extends Values,
static transform<
Instance extends Values,
TransformT extends z.ZodRawShape,
TransformUnknownKeys extends z.UnknownKeysParam,
TransformCatchall extends z.ZodTypeAny,
TransformOutput extends Values,
TransformInput,
>(
this: Class<Instance, [values: Values]>,
schema: z.ZodObject<TransformT, TransformUnknownKeys, TransformCatchall, TransformOutput, TransformInput>,
) {
return schema.transform(values => new this(values))
TransformT extends z.ZodRawShape,
TransformUnknownKeys extends z.UnknownKeysParam,
TransformCatchall extends z.ZodTypeAny,
TransformOutput extends Values,
TransformInput,
>(
this: Class<Instance, [values: Values]>,
schema: z.ZodObject<TransformT, TransformUnknownKeys, TransformCatchall, TransformOutput, TransformInput>,
) {
return schema.transform(values => new this(values))
}
static create<
Instance extends Values
>(
this: (
Class<Instance, [values: Values]> &
ImplStatic<typeof ZodSchemaObjectImpl>
),
...[values, params]: CreateArgs<PartialValues>
) {
return this
.transform(this.schemaWithDefaults)
.parse(values, params)
}
static createPromise<
Instance extends Values
>(
this: (
Class<Instance, [values: Values]> &
ImplStatic<typeof ZodSchemaObjectImpl>
),
...[values, params]: CreateArgs<PartialValues>
) {
return this
.transform(this.schemaWithDefaults)
.parseAsync(values, params)
}
static createEffect<
Instance extends Values
>(
this: (
Class<Instance, [values: Values]> &
ImplStatic<typeof ZodSchemaObjectImpl>
),
...[values, params]: CreateArgs<PartialValues>
) {
return parseZodSchemaEffect(
this.transform(this.schemaWithDefaults),
values,
params,
)
}
}
static create<
Instance extends Values
>(
this: (
Class<Instance, [values: Values]> &
ImplStatic<typeof ZodSchemaObjectImpl>
),
...[values, params]: CreateArgs<PartialValues>
) {
return this
.transform(this.schemaWithDefaults)
.parse(values, params)
}
static createPromise<
Instance extends Values
>(
this: (
Class<Instance, [values: Values]> &
ImplStatic<typeof ZodSchemaObjectImpl>
),
...[values, params]: CreateArgs<PartialValues>
) {
return this
.transform(this.schemaWithDefaults)
.parseAsync(values, params)
}
static createEffect<
Instance extends Values
>(
this: (
Class<Instance, [values: Values]> &
ImplStatic<typeof ZodSchemaObjectImpl>
),
...[values, params]: CreateArgs<PartialValues>
) {
return parseZodSchemaEffect(
this.transform(this.schemaWithDefaults),
values,
params,
)
}
return ZodSchemaObjectImpl
})
.build()