InstantiableZodSchemaObject work
Some checks failed
continuous-integration/drone/push Build is failing
Some checks failed
continuous-integration/drone/push Build is failing
This commit is contained in:
@@ -16,7 +16,7 @@ const exp = zodSchemaClass
|
||||
}),
|
||||
|
||||
schemaWithDefaultValues: s => s.extend({
|
||||
id: s.shape.id.default(-1n)
|
||||
id: s.shape.id.default(-1n),
|
||||
}),
|
||||
})
|
||||
.jsonifiable({
|
||||
|
||||
@@ -28,6 +28,36 @@ type NewZodSchemaInstanceArgs<Input extends object> = (
|
||||
|
||||
export const InstantiableZodSchemaObject = trait
|
||||
.implement(Super => class InstantiableZodSchemaObject extends Super {
|
||||
static instantiationSchema<
|
||||
Instance extends Values,
|
||||
|
||||
SchemaT extends z.ZodRawShape,
|
||||
SchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
SchemaCatchall extends z.ZodTypeAny,
|
||||
|
||||
Values extends object,
|
||||
>(
|
||||
this: ZodSchemaClass<Instance, SchemaT, SchemaUnknownKeys, SchemaCatchall, any, any, any, Values, any>,
|
||||
) {
|
||||
return this.schema.transform(values => new this(values))
|
||||
}
|
||||
|
||||
static instantiationSchemaWithDefaultValues<
|
||||
Instance extends Values,
|
||||
|
||||
SchemaWithDefaultValuesT extends z.ZodRawShape,
|
||||
SchemaWithDefaultValuesUnknownKeys extends z.UnknownKeysParam,
|
||||
SchemaWithDefaultValuesCatchall extends z.ZodTypeAny,
|
||||
|
||||
Values extends object,
|
||||
PartialValues extends Partial<Values>,
|
||||
>(
|
||||
this: ZodSchemaClass<Instance, any, any, any, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues>,
|
||||
) {
|
||||
return this.schemaWithDefaultValues.transform(values => new this(values))
|
||||
}
|
||||
|
||||
|
||||
static create<
|
||||
Instance extends Values,
|
||||
|
||||
|
||||
Reference in New Issue
Block a user