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