0.1.3 #4
@@ -19,69 +19,73 @@ export const ZodSchemaObject = <
|
|||||||
>(
|
>(
|
||||||
schemaWithDefaults: z.ZodObject<T, "strip", Catchall, Values, PartialValues>,
|
schemaWithDefaults: z.ZodObject<T, "strip", Catchall, Values, PartialValues>,
|
||||||
) => trait
|
) => trait
|
||||||
.implement(Super => class ZodSchemaObjectImpl extends Super {
|
.implement(Super => {
|
||||||
static readonly schema = stripZodObjectDefaults<T, "strip", Catchall, Values, PartialValues>(schemaWithDefaults)
|
class ZodSchemaObjectImpl extends Super {
|
||||||
static readonly schemaWithDefaults = schemaWithDefaults
|
static readonly schema = stripZodObjectDefaults(schemaWithDefaults)
|
||||||
|
static readonly schemaWithDefaults = schemaWithDefaults
|
||||||
|
|
||||||
static transform<
|
static transform<
|
||||||
Instance extends Values,
|
Instance extends Values,
|
||||||
|
|
||||||
TransformT extends z.ZodRawShape,
|
TransformT extends z.ZodRawShape,
|
||||||
TransformUnknownKeys extends z.UnknownKeysParam,
|
TransformUnknownKeys extends z.UnknownKeysParam,
|
||||||
TransformCatchall extends z.ZodTypeAny,
|
TransformCatchall extends z.ZodTypeAny,
|
||||||
TransformOutput extends Values,
|
TransformOutput extends Values,
|
||||||
TransformInput,
|
TransformInput,
|
||||||
>(
|
>(
|
||||||
this: Class<Instance, [values: Values]>,
|
this: Class<Instance, [values: Values]>,
|
||||||
schema: z.ZodObject<TransformT, TransformUnknownKeys, TransformCatchall, TransformOutput, TransformInput>,
|
schema: z.ZodObject<TransformT, TransformUnknownKeys, TransformCatchall, TransformOutput, TransformInput>,
|
||||||
) {
|
) {
|
||||||
return schema.transform(values => new this(values))
|
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,
|
||||||
|
)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return ZodSchemaObjectImpl
|
||||||
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,
|
|
||||||
)
|
|
||||||
}
|
|
||||||
})
|
})
|
||||||
.build()
|
.build()
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user