diff --git a/src/ZodSchemaClass.ts b/src/ZodSchemaClass.ts index 94b84e5..c13f9d6 100644 --- a/src/ZodSchemaClass.ts +++ b/src/ZodSchemaClass.ts @@ -16,9 +16,9 @@ export function ZodSchemaClass< Values extends object, PartialValues extends Partial, >( - schema: z.ZodObject + schemaWithDefaults: z.ZodObject ) { return expression .extends(ZodSchemaObjectConstructor) - .expresses(ZodSchemaObject(schema)) + .expresses(ZodSchemaObject(schemaWithDefaults)) } diff --git a/src/traits/ExtendableZodSchemaObject.ts b/src/traits/ExtendableZodSchemaObject.ts index 0fc0891..c89c66d 100644 --- a/src/traits/ExtendableZodSchemaObject.ts +++ b/src/traits/ExtendableZodSchemaObject.ts @@ -1,16 +1,19 @@ -// import { trait } from "@thilawyn/traitify-ts" -// import { ZodSchemaClassExtender } from "../builders/ZodSchemaClassExtender" -// import { ZodSchemaClass } from "../shapes/ZodSchemaClass" +import { expression } from "@thilawyn/traitify-ts" +import { z } from "zod" +import { ZodSchemaObject } from "./ZodSchemaObject" -// export const ExtendableZodSchemaObject = trait -// .implement(Super => class ExtendableZodSchemaObject extends Super { -// static extend< -// Self extends ZodSchemaClass, -// >( -// this: Self -// ) { -// return new ZodSchemaClassExtender(this, this) -// } -// }) -// .build() +export const ExtendableZodSchemaObject = < + T extends z.ZodRawShape, + Catchall extends z.ZodTypeAny, + Values extends object, + PartialValues extends Partial, +>( + schemaWithDefaults: z.ZodObject, +) => expression + .expresses(ZodSchemaObject(schemaWithDefaults)) + .buildAnyway() + .subtrait() + .implement(Super => class ExtendableZodSchemaObject extends Super { + }) + .build() diff --git a/src/traits/ZodSchemaObject.ts b/src/traits/ZodSchemaObject.ts index 54a3601..850121f 100644 --- a/src/traits/ZodSchemaObject.ts +++ b/src/traits/ZodSchemaObject.ts @@ -1,5 +1,5 @@ import { ImplStatic, trait } from "@thilawyn/traitify-ts" -import { AbstractClass, Class, HasRequiredKeys } from "type-fest" +import { Class, HasRequiredKeys } from "type-fest" import { z } from "zod" import { StaticMembers, parseZodSchemaEffect, stripZodObjectDefaults } from "../util" @@ -85,13 +85,24 @@ export const ZodSchemaObject = < } - static extend< - Self extends AbstractClass & ImplStatic - >( - this: Self - ) { + // static extend< + // Self extends AbstractClass & ImplStatic, - } + // ExtendedT extends z.ZodRawShape, + // ExtendedCatchall extends z.ZodTypeAny, + // ExtendedValues extends Values, + // ExtendedPartialValues extends Partial, + // >( + // this: Self, + + // schemaWithDefaults: ( + // schemaWithDefaults: typeof this.schemaWithDefaults + // ) => z.ZodObject, + // ) { + // return expression + // .extends(this) + // .expresses(ZodSchemaObject(schemaWithDefaults(this.schemaWithDefaults))) + // } } return ZodSchemaObject as Class & StaticMembers