ExtendableZodSchemaObject 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:
@@ -6,7 +6,7 @@ import { Extend, StaticMembers } from "./util"
|
|||||||
|
|
||||||
|
|
||||||
export function ZodSchemaClassOf<
|
export function ZodSchemaClassOf<
|
||||||
Superclass extends AbstractClass<{}, []>,
|
Super extends AbstractClass<{}, []>,
|
||||||
|
|
||||||
SchemaT extends z.ZodRawShape,
|
SchemaT extends z.ZodRawShape,
|
||||||
SchemaUnknownKeys extends z.UnknownKeysParam,
|
SchemaUnknownKeys extends z.UnknownKeysParam,
|
||||||
@@ -15,7 +15,7 @@ export function ZodSchemaClassOf<
|
|||||||
Values extends {},
|
Values extends {},
|
||||||
DefaultValues extends Partial<Values>,
|
DefaultValues extends Partial<Values>,
|
||||||
>(
|
>(
|
||||||
of: Superclass,
|
of: Super,
|
||||||
|
|
||||||
{ schema, defaultValues }: {
|
{ schema, defaultValues }: {
|
||||||
schema: z.ZodObject<SchemaT, SchemaUnknownKeys, SchemaCatchall, Values, Values>
|
schema: z.ZodObject<SchemaT, SchemaUnknownKeys, SchemaCatchall, Values, Values>
|
||||||
@@ -37,7 +37,7 @@ export function ZodSchemaClassOf<
|
|||||||
|
|
||||||
return exp.extends as AbstractClass<
|
return exp.extends as AbstractClass<
|
||||||
Extend<[
|
Extend<[
|
||||||
InstanceType<Superclass>,
|
InstanceType<Super>,
|
||||||
InstanceType<typeof exp.extends>,
|
InstanceType<typeof exp.extends>,
|
||||||
Values,
|
Values,
|
||||||
]>,
|
]>,
|
||||||
@@ -45,7 +45,7 @@ export function ZodSchemaClassOf<
|
|||||||
ConstructorParameters<typeof exp.extends>
|
ConstructorParameters<typeof exp.extends>
|
||||||
> &
|
> &
|
||||||
Extend<[
|
Extend<[
|
||||||
StaticMembers<Superclass>,
|
StaticMembers<Super>,
|
||||||
StaticMembers<typeof exp.extends>,
|
StaticMembers<typeof exp.extends>,
|
||||||
]>
|
]>
|
||||||
}
|
}
|
||||||
|
|||||||
39
src/traits/ExtendableZodSchemaObject.ts
Normal file
39
src/traits/ExtendableZodSchemaObject.ts
Normal file
@@ -0,0 +1,39 @@
|
|||||||
|
import { abstract, trait } from "@thilawyn/traitify-ts"
|
||||||
|
import { z } from "zod"
|
||||||
|
import { ZodSchemaAbstractClass } from "../types/ZodSchemaClass"
|
||||||
|
|
||||||
|
|
||||||
|
export const ExtendableZodSchemaObject = trait(
|
||||||
|
abstract(),
|
||||||
|
|
||||||
|
Super => class ExtendableZodSchemaObject extends Super {
|
||||||
|
static extend<
|
||||||
|
Super extends ZodSchemaAbstractClass<SuperSchemaT, SuperSchemaUnknownKeys, SuperSchemaCatchall, SuperValues, SuperDefaultValues>,
|
||||||
|
|
||||||
|
SuperSchemaT extends z.ZodRawShape,
|
||||||
|
SuperSchemaUnknownKeys extends z.UnknownKeysParam,
|
||||||
|
SuperSchemaCatchall extends z.ZodTypeAny,
|
||||||
|
SuperValues extends {},
|
||||||
|
SuperDefaultValues extends Partial<SuperValues>,
|
||||||
|
|
||||||
|
SchemaT extends z.ZodRawShape,
|
||||||
|
SchemaUnknownKeys extends z.UnknownKeysParam,
|
||||||
|
SchemaCatchall extends z.ZodTypeAny,
|
||||||
|
Values extends SuperValues,
|
||||||
|
DefaultValues extends Partial<Values>,
|
||||||
|
>(
|
||||||
|
this: Super | ZodSchemaAbstractClass<SuperSchemaT, SuperSchemaUnknownKeys, SuperSchemaCatchall, SuperValues, SuperDefaultValues>,
|
||||||
|
|
||||||
|
props: {
|
||||||
|
schema: (props: {
|
||||||
|
schema: Super["schema"]
|
||||||
|
shape: Super["schema"]["shape"]
|
||||||
|
}) => z.ZodObject<SchemaT, SchemaUnknownKeys, SchemaCatchall, Values, Values>
|
||||||
|
|
||||||
|
defaultValues: (defaultValues: SuperDefaultValues) => DefaultValues
|
||||||
|
},
|
||||||
|
) {
|
||||||
|
|
||||||
|
}
|
||||||
|
},
|
||||||
|
)
|
||||||
Reference in New Issue
Block a user