Working extendable
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Julien Valverdé
2024-02-08 18:26:37 +01:00
parent 041b3f566e
commit 5f7fd30459
4 changed files with 55 additions and 11 deletions

View File

@@ -1,6 +1,8 @@
import { abstract, trait } from "@thilawyn/traitify-ts"
import { AbstractClass } from "type-fest"
import { z } from "zod"
import { ZodSchemaAbstractClass } from "../types/ZodSchemaClass"
import { Extend, StaticMembers } from "../util"
export const ExtendableZodSchemaObject = trait(
@@ -32,8 +34,26 @@ export const ExtendableZodSchemaObject = trait(
defaultValues: (defaultValues: SuperDefaultValues) => DefaultValues
},
): (
AbstractClass<
Extend<[InstanceType<Super>, Values]>,
[values: Values]
> &
Extend<[
StaticMembers<Super>,
{
readonly schema: z.ZodObject<SchemaT, SchemaUnknownKeys, SchemaCatchall, Values, Values>,
readonly defaultValues: DefaultValues,
},
]>
) {
const schema = props.schema({ schema: this.schema, shape: this.schema.shape })
const defaultValues = props.defaultValues(this.defaultValues)
return class extends this {
static readonly schema = schema
static readonly defaultValues = defaultValues
} as any
}
},
)