0.1.2 #3

Merged
Thilawyn merged 136 commits from next into master 2024-03-11 19:44:21 +01:00
4 changed files with 172 additions and 172 deletions
Showing only changes of commit b98a7cf3fc - Show all commits

View File

@@ -39,5 +39,5 @@ export const createBundleConfig = (
export default [
createBundleConfig("src/lib.ts", "."),
createBundleConfig("src/schema/lib.ts", "."),
createBundleConfig("src/schema/lib.ts", "./schema"),
]

View File

@@ -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<object>,
Subclass extends AbstractClass<object>,
> {
declare ["constructor"]: typeof ZodSchemaClassExtender
// export class ZodSchemaClassExtender<
// Superclass extends AbstractClass<object>,
// Subclass extends AbstractClass<object>,
// > {
// declare ["constructor"]: typeof ZodSchemaClassExtender
constructor(
readonly superclass: Superclass,
readonly subclass: Subclass,
) {}
// constructor(
// readonly superclass: Superclass,
// readonly subclass: Subclass,
// ) {}
schema<
Super extends ZodSchemaAbstractClass<any, SuperSchemaT, SuperSchemaUnknownKeys, SuperSchemaCatchall, SuperValues, SuperDefaultValues>,
// schema<
// Super extends ZodSchemaAbstractClass<any, SuperSchemaT, SuperSchemaUnknownKeys, SuperSchemaCatchall, SuperValues, SuperDefaultValues>,
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>,
// SuperValues extends object,
// SuperDefaultValues extends Partial<SuperValues>,
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<Values>,
>(
this: ZodSchemaClassExtender<
Super | ZodSchemaAbstractClass<any, SuperSchemaT, SuperSchemaUnknownKeys, SuperSchemaCatchall, SuperValues, SuperDefaultValues>,
any
>,
// Values extends SuperValues,
// DefaultValues extends Partial<Values>,
// >(
// this: ZodSchemaClassExtender<
// Super | ZodSchemaAbstractClass<any, SuperSchemaT, SuperSchemaUnknownKeys, SuperSchemaCatchall, SuperValues, SuperDefaultValues>,
// any
// >,
props: {
schema: (schema: Super["schema"]) => z.ZodObject<SchemaT, SchemaUnknownKeys, SchemaCatchall, Values, Values>
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<SchemaT, SchemaUnknownKeys, SchemaCatchall, Values, Values>
// 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<object, any[]>) {
static readonly schema = schema
static readonly defaultValues = defaultValues
}
// class Schemas extends (this.superclass as AbstractClass<object, any[]>) {
// 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<Super>, Values]>
>,
// Schemas as unknown as AbstractClass<
// Simplify<
// Extend<[InstanceType<Super>, Values]>
// >,
[values: Values]
> &
Simplify<
Override<[
StaticMembers<Super>,
StaticMembers<typeof Schemas>,
]>
>
)
}
// [values: Values]
// > &
// Simplify<
// Override<[
// StaticMembers<Super>,
// StaticMembers<typeof Schemas>,
// ]>
// >
// )
// }
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<any, SelfSchemaT, SelfSchemaUnknownKeys, SelfSchemaCatchall, SelfValues, SelfDefaultValues>,
// /** New schemas */
// Self extends ZodSchemaAbstractClass<any, SelfSchemaT, SelfSchemaUnknownKeys, SelfSchemaCatchall, SelfValues, SelfDefaultValues>,
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>,
// SelfValues extends object,
// SelfDefaultValues extends Partial<SelfValues>,
/* 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<any, SelfSchemaT, SelfSchemaUnknownKeys, SelfSchemaCatchall, SelfValues, SelfDefaultValues>
>,
// Self | ZodSchemaAbstractClass<any, SelfSchemaT, SelfSchemaUnknownKeys, SelfSchemaCatchall, SelfValues, SelfDefaultValues>
// >,
props: {
jsonifySchema: (
schema: Self["schema"],
jsonifySchema: Super["jsonifySchema"],
) => z.ZodObject<JsonifySchemaT, JsonifySchemaUnknownKeys, JsonifySchemaCatchall, JsonifiedValues, Values>
// props: {
// jsonifySchema: (
// schema: Self["schema"],
// jsonifySchema: Super["jsonifySchema"],
// ) => z.ZodObject<JsonifySchemaT, JsonifySchemaUnknownKeys, JsonifySchemaCatchall, JsonifiedValues, Values>
dejsonifySchema: (
schema: Self["schema"],
dejsonifySchema: Super["dejsonifySchema"],
) => z.ZodObject<DejsonifySchemaT, DejsonifySchemaUnknownKeys, DejsonifySchemaCatchall, Values, JsonifiedValues>
},
) {
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<DejsonifySchemaT, DejsonifySchemaUnknownKeys, DejsonifySchemaCatchall, Values, JsonifiedValues>
// },
// ) {
// 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<object>) {
static readonly jsonifySchema = jsonifySchema
readonly jsonifySchema = jsonifySchema
static readonly dejsonifySchema = dejsonifySchema
readonly dejsonifySchema = dejsonifySchema
}
// class JsonifiableSchemas extends (this.subclass as AbstractClass<object>) {
// 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<Self>, JsonifiableSchemas]>
>,
// JsonifiableSchemas as unknown as AbstractClass<
// Simplify<
// Override<[InstanceType<Self>, JsonifiableSchemas]>
// >,
ConstructorParameters<
ZodSchemaAbstractClass<any, SelfSchemaT, SelfSchemaUnknownKeys, SelfSchemaCatchall, SelfValues, SelfDefaultValues>
>
> &
Simplify<
Override<[
StaticMembers<Self>,
StaticMembers<typeof JsonifiableSchemas>,
]>
>,
)
}
// ConstructorParameters<
// ZodSchemaAbstractClass<any, SelfSchemaT, SelfSchemaUnknownKeys, SelfSchemaCatchall, SelfValues, SelfDefaultValues>
// >
// > &
// Simplify<
// Override<[
// StaticMembers<Self>,
// StaticMembers<typeof JsonifiableSchemas>,
// ]>
// >,
// )
// }
toClass() {
return this.subclass
}
// toClass() {
// return this.subclass
// }
toExpressionBuilder() {
return expression.extends(this.subclass)
}
}
// toExpressionBuilder() {
// return expression.extends(this.subclass)
// }
// }

View File

@@ -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"

View File

@@ -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<any, any, any, any, any, any, any, any, any>,
>(
this: Self
) {
return new ZodSchemaClassExtender(this, this)
}
})
.build()
// export const ExtendableZodSchemaObject = trait
// .implement(Super => class ExtendableZodSchemaObject extends Super {
// static extend<
// Self extends ZodSchemaClass<any, any, any, any, any, any, any, any, any>,
// >(
// this: Self
// ) {
// return new ZodSchemaClassExtender(this, this)
// }
// })
// .build()