diff --git a/rollup.config.ts b/rollup.config.ts index 803378f..566206a 100644 --- a/rollup.config.ts +++ b/rollup.config.ts @@ -39,5 +39,5 @@ export const createBundleConfig = ( export default [ createBundleConfig("src/lib.ts", "."), - createBundleConfig("src/schema/lib.ts", "."), + createBundleConfig("src/schema/lib.ts", "./schema"), ] diff --git a/src/builders/ZodSchemaClassExtender.ts b/src/builders/ZodSchemaClassExtender.ts index 0fea1d6..d78a3c4 100644 --- a/src/builders/ZodSchemaClassExtender.ts +++ b/src/builders/ZodSchemaClassExtender.ts @@ -1,196 +1,196 @@ -import { expression } from "@thilawyn/traitify-ts" -import { AbstractClass, Simplify } from "type-fest" -import { JsonifiableObject } from "type-fest/source/jsonifiable" -import { z } from "zod" -import { JsonifiableZodSchemaAbstractClass } from "../shapes/JsonifiableZodSchemaClass" -import { ZodSchemaAbstractClass } from "../shapes/ZodSchemaClass" -import { Extend, Override, StaticMembers } from "../util" +// import { expression } from "@thilawyn/traitify-ts" +// import { AbstractClass, Simplify } from "type-fest" +// import { JsonifiableObject } from "type-fest/source/jsonifiable" +// import { z } from "zod" +// import { JsonifiableZodSchemaAbstractClass } from "../shapes/JsonifiableZodSchemaClass" +// import { ZodSchemaAbstractClass } from "../shapes/ZodSchemaClass" +// import { Extend, Override, StaticMembers } from "../util" -export class ZodSchemaClassExtender< - Superclass extends AbstractClass, - Subclass extends AbstractClass, -> { - declare ["constructor"]: typeof ZodSchemaClassExtender +// export class ZodSchemaClassExtender< +// Superclass extends AbstractClass, +// Subclass extends AbstractClass, +// > { +// declare ["constructor"]: typeof ZodSchemaClassExtender - constructor( - readonly superclass: Superclass, - readonly subclass: Subclass, - ) {} +// constructor( +// readonly superclass: Superclass, +// readonly subclass: Subclass, +// ) {} - schema< - Super extends ZodSchemaAbstractClass, +// schema< +// Super extends ZodSchemaAbstractClass, - SuperSchemaT extends z.ZodRawShape, - SuperSchemaUnknownKeys extends z.UnknownKeysParam, - SuperSchemaCatchall extends z.ZodTypeAny, +// SuperSchemaT extends z.ZodRawShape, +// SuperSchemaUnknownKeys extends z.UnknownKeysParam, +// SuperSchemaCatchall extends z.ZodTypeAny, - SuperValues extends object, - SuperDefaultValues extends Partial, +// SuperValues extends object, +// SuperDefaultValues extends Partial, - SchemaT extends z.ZodRawShape, - SchemaUnknownKeys extends z.UnknownKeysParam, - SchemaCatchall extends z.ZodTypeAny, +// SchemaT extends z.ZodRawShape, +// SchemaUnknownKeys extends z.UnknownKeysParam, +// SchemaCatchall extends z.ZodTypeAny, - Values extends SuperValues, - DefaultValues extends Partial, - >( - this: ZodSchemaClassExtender< - Super | ZodSchemaAbstractClass, - any - >, +// Values extends SuperValues, +// DefaultValues extends Partial, +// >( +// this: ZodSchemaClassExtender< +// Super | ZodSchemaAbstractClass, +// any +// >, - props: { - schema: (schema: Super["schema"]) => z.ZodObject - defaultValues: (defaultValues: SuperDefaultValues) => DefaultValues - }, - ) { - const schema = props.schema(this.superclass.schema) - const defaultValues = props.defaultValues(this.superclass.defaultValues) +// props: { +// schema: (schema: Super["schema"]) => z.ZodObject +// defaultValues: (defaultValues: SuperDefaultValues) => DefaultValues +// }, +// ) { +// const schema = props.schema(this.superclass.schema) +// const defaultValues = props.defaultValues(this.superclass.defaultValues) - class Schemas extends (this.superclass as AbstractClass) { - static readonly schema = schema - static readonly defaultValues = defaultValues - } +// class Schemas extends (this.superclass as AbstractClass) { +// static readonly schema = schema +// static readonly defaultValues = defaultValues +// } - return new this.constructor( - this.superclass as Super, +// return new this.constructor( +// this.superclass as Super, - Schemas as unknown as AbstractClass< - Simplify< - Extend<[InstanceType, Values]> - >, +// Schemas as unknown as AbstractClass< +// Simplify< +// Extend<[InstanceType, Values]> +// >, - [values: Values] - > & - Simplify< - Override<[ - StaticMembers, - StaticMembers, - ]> - > - ) - } +// [values: Values] +// > & +// Simplify< +// Override<[ +// StaticMembers, +// StaticMembers, +// ]> +// > +// ) +// } - jsonifiable< - /** Superclass jsonifiable schemas */ - Super extends JsonifiableZodSchemaAbstractClass< - any, +// jsonifiable< +// /** Superclass jsonifiable schemas */ +// Super extends JsonifiableZodSchemaAbstractClass< +// any, - SuperJsonifySchemaT, - SuperJsonifySchemaUnknownKeys, - SuperJsonifySchemaCatchall, +// SuperJsonifySchemaT, +// SuperJsonifySchemaUnknownKeys, +// SuperJsonifySchemaCatchall, - SuperDejsonifySchemaT, - SuperDejsonifySchemaUnknownKeys, - SuperDejsonifySchemaCatchall, +// SuperDejsonifySchemaT, +// SuperDejsonifySchemaUnknownKeys, +// SuperDejsonifySchemaCatchall, - SuperJsonifiedValues, - SuperValues - >, +// SuperJsonifiedValues, +// SuperValues +// >, - SuperJsonifySchemaT extends z.ZodRawShape, - SuperJsonifySchemaUnknownKeys extends z.UnknownKeysParam, - SuperJsonifySchemaCatchall extends z.ZodTypeAny, +// SuperJsonifySchemaT extends z.ZodRawShape, +// SuperJsonifySchemaUnknownKeys extends z.UnknownKeysParam, +// SuperJsonifySchemaCatchall extends z.ZodTypeAny, - SuperDejsonifySchemaT extends z.ZodRawShape, - SuperDejsonifySchemaUnknownKeys extends z.UnknownKeysParam, - SuperDejsonifySchemaCatchall extends z.ZodTypeAny, +// SuperDejsonifySchemaT extends z.ZodRawShape, +// SuperDejsonifySchemaUnknownKeys extends z.UnknownKeysParam, +// SuperDejsonifySchemaCatchall extends z.ZodTypeAny, - SuperJsonifiedValues extends JsonifiableObject, - SuperValues extends object, +// SuperJsonifiedValues extends JsonifiableObject, +// SuperValues extends object, - /** New schemas */ - Self extends ZodSchemaAbstractClass, +// /** New schemas */ +// Self extends ZodSchemaAbstractClass, - SelfSchemaT extends z.ZodRawShape, - SelfSchemaUnknownKeys extends z.UnknownKeysParam, - SelfSchemaCatchall extends z.ZodTypeAny, +// SelfSchemaT extends z.ZodRawShape, +// SelfSchemaUnknownKeys extends z.UnknownKeysParam, +// SelfSchemaCatchall extends z.ZodTypeAny, - SelfValues extends object, - SelfDefaultValues extends Partial, +// SelfValues extends object, +// SelfDefaultValues extends Partial, - /* New jsonifiable schemas */ - JsonifySchemaT extends z.ZodRawShape, - JsonifySchemaUnknownKeys extends z.UnknownKeysParam, - JsonifySchemaCatchall extends z.ZodTypeAny, +// /* New jsonifiable schemas */ +// JsonifySchemaT extends z.ZodRawShape, +// JsonifySchemaUnknownKeys extends z.UnknownKeysParam, +// JsonifySchemaCatchall extends z.ZodTypeAny, - DejsonifySchemaT extends z.ZodRawShape, - DejsonifySchemaUnknownKeys extends z.UnknownKeysParam, - DejsonifySchemaCatchall extends z.ZodTypeAny, +// DejsonifySchemaT extends z.ZodRawShape, +// DejsonifySchemaUnknownKeys extends z.UnknownKeysParam, +// DejsonifySchemaCatchall extends z.ZodTypeAny, - JsonifiedValues extends SuperJsonifiedValues, - Values extends SelfValues, - >( - this: ZodSchemaClassExtender< - Super | JsonifiableZodSchemaAbstractClass< - any, +// JsonifiedValues extends SuperJsonifiedValues, +// Values extends SelfValues, +// >( +// this: ZodSchemaClassExtender< +// Super | JsonifiableZodSchemaAbstractClass< +// any, - SuperJsonifySchemaT, - SuperJsonifySchemaUnknownKeys, - SuperJsonifySchemaCatchall, +// SuperJsonifySchemaT, +// SuperJsonifySchemaUnknownKeys, +// SuperJsonifySchemaCatchall, - SuperDejsonifySchemaT, - SuperDejsonifySchemaUnknownKeys, - SuperDejsonifySchemaCatchall, +// SuperDejsonifySchemaT, +// SuperDejsonifySchemaUnknownKeys, +// SuperDejsonifySchemaCatchall, - SuperJsonifiedValues, - SuperValues - >, +// SuperJsonifiedValues, +// SuperValues +// >, - Self | ZodSchemaAbstractClass - >, +// Self | ZodSchemaAbstractClass +// >, - props: { - jsonifySchema: ( - schema: Self["schema"], - jsonifySchema: Super["jsonifySchema"], - ) => z.ZodObject +// props: { +// jsonifySchema: ( +// schema: Self["schema"], +// jsonifySchema: Super["jsonifySchema"], +// ) => z.ZodObject - dejsonifySchema: ( - schema: Self["schema"], - dejsonifySchema: Super["dejsonifySchema"], - ) => z.ZodObject - }, - ) { - const jsonifySchema = props.jsonifySchema(this.subclass.schema, this.superclass.jsonifySchema) - const dejsonifySchema = props.dejsonifySchema(this.subclass.schema, this.superclass.dejsonifySchema) +// dejsonifySchema: ( +// schema: Self["schema"], +// dejsonifySchema: Super["dejsonifySchema"], +// ) => z.ZodObject +// }, +// ) { +// const jsonifySchema = props.jsonifySchema(this.subclass.schema, this.superclass.jsonifySchema) +// const dejsonifySchema = props.dejsonifySchema(this.subclass.schema, this.superclass.dejsonifySchema) - class JsonifiableSchemas extends (this.subclass as AbstractClass) { - static readonly jsonifySchema = jsonifySchema - readonly jsonifySchema = jsonifySchema - static readonly dejsonifySchema = dejsonifySchema - readonly dejsonifySchema = dejsonifySchema - } +// class JsonifiableSchemas extends (this.subclass as AbstractClass) { +// static readonly jsonifySchema = jsonifySchema +// readonly jsonifySchema = jsonifySchema +// static readonly dejsonifySchema = dejsonifySchema +// readonly dejsonifySchema = dejsonifySchema +// } - return new this.constructor( - this.superclass as Super, +// return new this.constructor( +// this.superclass as Super, - JsonifiableSchemas as unknown as AbstractClass< - Simplify< - Override<[InstanceType, JsonifiableSchemas]> - >, +// JsonifiableSchemas as unknown as AbstractClass< +// Simplify< +// Override<[InstanceType, JsonifiableSchemas]> +// >, - ConstructorParameters< - ZodSchemaAbstractClass - > - > & - Simplify< - Override<[ - StaticMembers, - StaticMembers, - ]> - >, - ) - } +// ConstructorParameters< +// ZodSchemaAbstractClass +// > +// > & +// Simplify< +// Override<[ +// StaticMembers, +// StaticMembers, +// ]> +// >, +// ) +// } - toClass() { - return this.subclass - } +// toClass() { +// return this.subclass +// } - toExpressionBuilder() { - return expression.extends(this.subclass) - } -} +// toExpressionBuilder() { +// return expression.extends(this.subclass) +// } +// } diff --git a/src/lib.ts b/src/lib.ts index f2bd6a8..fa3a059 100644 --- a/src/lib.ts +++ b/src/lib.ts @@ -1,5 +1,5 @@ export { ZodSchemaClassBuilder } from "./builders/ZodSchemaClassBuilder" -export { ExtendableZodSchemaObject } from "./traits/ExtendableZodSchemaObject" +// export { ExtendableZodSchemaObject } from "./traits/ExtendableZodSchemaObject" export { JsonifiableZodSchemaObject } from "./traits/JsonifiableZodSchemaObject" export { MobXObservableZodSchemaObject } from "./traits/MobXObservableZodSchemaObject" export { ZodSchemaObject, ZodSchemaObjectTrait } from "./traits/ZodSchemaObject" diff --git a/src/traits/ExtendableZodSchemaObject.ts b/src/traits/ExtendableZodSchemaObject.ts index 2b232fb..0fc0891 100644 --- a/src/traits/ExtendableZodSchemaObject.ts +++ b/src/traits/ExtendableZodSchemaObject.ts @@ -1,16 +1,16 @@ -import { trait } from "@thilawyn/traitify-ts" -import { ZodSchemaClassExtender } from "../builders/ZodSchemaClassExtender" -import { ZodSchemaClass } from "../shapes/ZodSchemaClass" +// import { trait } from "@thilawyn/traitify-ts" +// import { ZodSchemaClassExtender } from "../builders/ZodSchemaClassExtender" +// import { ZodSchemaClass } from "../shapes/ZodSchemaClass" -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 = trait +// .implement(Super => class ExtendableZodSchemaObject extends Super { +// static extend< +// Self extends ZodSchemaClass, +// >( +// this: Self +// ) { +// return new ZodSchemaClassExtender(this, this) +// } +// }) +// .build()