This commit is contained in:
@@ -1,7 +1,10 @@
|
||||
import { expression } from "@thilawyn/traitify-ts"
|
||||
import { AbstractClass, Simplify } from "type-fest"
|
||||
import { z } from "zod"
|
||||
import { ZodSchemaAbstractClass } from "../shapes/ZodSchemaClass"
|
||||
import { Extend, Override, StaticMembers } from "../util"
|
||||
import { JsonifiableZodSchemaAbstractClass, JsonifiableZodSchemaClass } from "../shapes/JsonifiableZodSchemaClass"
|
||||
import { JsonifiableObject } from "type-fest/source/jsonifiable"
|
||||
|
||||
|
||||
export class ZodSchemaClassExtender<Superclass extends AbstractClass<object>> {
|
||||
@@ -63,30 +66,58 @@ export class ZodSchemaClassExtender<Superclass extends AbstractClass<object>> {
|
||||
}
|
||||
|
||||
jsonifiable<
|
||||
Super extends ZodSchemaAbstractClass<SuperInstance, SuperSchemaT, SuperSchemaUnknownKeys, SuperSchemaCatchall, SuperValues, SuperDefaultValues>,
|
||||
SuperInstance extends SuperValues,
|
||||
Super extends JsonifiableZodSchemaAbstractClass<
|
||||
Instance,
|
||||
|
||||
SuperSchemaT extends z.ZodRawShape,
|
||||
SuperSchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
SuperSchemaCatchall extends z.ZodTypeAny,
|
||||
JsonifySchemaT,
|
||||
JsonifySchemaUnknownKeys,
|
||||
JsonifySchemaCatchall,
|
||||
|
||||
SuperValues extends object,
|
||||
SuperDefaultValues extends Partial<SuperValues>,
|
||||
DejsonifySchemaT,
|
||||
DejsonifySchemaUnknownKeys,
|
||||
DejsonifySchemaCatchall,
|
||||
|
||||
SchemaT extends z.ZodRawShape,
|
||||
SchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
SchemaCatchall extends z.ZodTypeAny,
|
||||
JsonifiedValues,
|
||||
Values
|
||||
>,
|
||||
Instance extends Values,
|
||||
|
||||
Values extends SuperValues,
|
||||
DefaultValues extends Partial<Values>,
|
||||
JsonifySchemaT extends z.ZodRawShape,
|
||||
JsonifySchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
JsonifySchemaCatchall extends z.ZodTypeAny,
|
||||
|
||||
DejsonifySchemaT extends z.ZodRawShape,
|
||||
DejsonifySchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
DejsonifySchemaCatchall extends z.ZodTypeAny,
|
||||
|
||||
JsonifiedValues extends JsonifiableObject,
|
||||
Values extends object,
|
||||
>(
|
||||
this: ZodSchemaClassExtender<
|
||||
Super | ZodSchemaAbstractClass<SuperInstance, SuperSchemaT, SuperSchemaUnknownKeys, SuperSchemaCatchall, SuperValues, SuperDefaultValues>
|
||||
Super | JsonifiableZodSchemaAbstractClass<
|
||||
Instance,
|
||||
|
||||
JsonifySchemaT,
|
||||
JsonifySchemaUnknownKeys,
|
||||
JsonifySchemaCatchall,
|
||||
|
||||
DejsonifySchemaT,
|
||||
DejsonifySchemaUnknownKeys,
|
||||
DejsonifySchemaCatchall,
|
||||
|
||||
JsonifiedValues,
|
||||
Values
|
||||
>
|
||||
>,
|
||||
|
||||
props: {
|
||||
schema: (schema: Super["schema"]) => z.ZodObject<SchemaT, SchemaUnknownKeys, SchemaCatchall, Values, Values>
|
||||
defaultValues: (defaultValues: SuperDefaultValues) => DefaultValues
|
||||
jsonifySchema: (
|
||||
schema: z.ZodObject<SchemaT, SchemaUnknownKeys, SchemaCatchall, Values, Values>
|
||||
) => z.ZodObject<JsonifySchemaT, JsonifySchemaUnknownKeys, JsonifySchemaCatchall, JsonifiedValues, Values>
|
||||
|
||||
dejsonifySchema: (
|
||||
schema: z.ZodObject<SchemaT, SchemaUnknownKeys, SchemaCatchall, Values, Values>
|
||||
) => z.ZodObject<DejsonifySchemaT, DejsonifySchemaUnknownKeys, DejsonifySchemaCatchall, Values, JsonifiedValues>
|
||||
},
|
||||
) {
|
||||
const schema = props.schema(this.superclass.schema)
|
||||
@@ -115,7 +146,11 @@ export class ZodSchemaClassExtender<Superclass extends AbstractClass<object>> {
|
||||
}
|
||||
|
||||
|
||||
build() {
|
||||
toClass() {
|
||||
return this.superclass
|
||||
}
|
||||
|
||||
toExpressionBuilder() {
|
||||
return expression.extends(this.superclass)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -48,7 +48,7 @@ const AdminUserProto = User.extend()
|
||||
})
|
||||
|
||||
|
||||
class AdminUser extends AdminUserProto.build() {}
|
||||
class AdminUser extends AdminUserProto.toClass() {}
|
||||
const subInst = await AdminUser.createPromise({ id: 2n, prout: "" })
|
||||
console.log(subInst)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user