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