0.1.2 #3

Merged
Thilawyn merged 136 commits from next into master 2024-03-11 19:44:21 +01:00
2 changed files with 31 additions and 1 deletions
Showing only changes of commit a6414b680c - Show all commits

View File

@@ -16,7 +16,7 @@ const exp = zodSchemaClass
}),
schemaWithDefaultValues: s => s.extend({
id: s.shape.id.default(-1n)
id: s.shape.id.default(-1n),
}),
})
.jsonifiable({

View File

@@ -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,