0.1.2 #3
@@ -1,9 +1,8 @@
|
||||
import { Trait, TraitExpression, TraitExpressionBuilder } from "@thilawyn/traitify-ts"
|
||||
import { Trait, TraitExpressionBuilder, expression } from "@thilawyn/traitify-ts"
|
||||
import { AbstractClass } from "type-fest"
|
||||
import { JsonifiableObject } from "type-fest/source/jsonifiable"
|
||||
import { z } from "zod"
|
||||
import { ZodSchemaAbstractClass } from "../shapes/ZodSchemaClass"
|
||||
import { DejsonifiableZodSchemaObject } from "../traits/DejsonifiableZodSchemaObject"
|
||||
import { JsonifiableZodSchemaObject } from "../traits/JsonifiableZodSchemaObject"
|
||||
import { ZodSchemaObject } from "../traits/ZodSchemaObject"
|
||||
import { StaticMembers } from "../util"
|
||||
@@ -105,36 +104,18 @@ export class ZodSchemaClassBuilder<
|
||||
) => z.ZodObject<DejsonifySchemaT, DejsonifySchemaUnknownKeys, DejsonifySchemaCatchall, Values, JsonifiedValues>
|
||||
},
|
||||
) {
|
||||
const jsonifySchema = props.jsonifySchema(this.expression.expressionSuperclass.schema)
|
||||
const dejsonifySchema = props.dejsonifySchema(this.expression.expressionSuperclass.schema)
|
||||
|
||||
class JsonifiableSchemas extends (this.expression.expressionSuperclass as AbstractClass<object>) {
|
||||
static readonly jsonifySchema = jsonifySchema
|
||||
readonly jsonifySchema = jsonifySchema
|
||||
static readonly dejsonifySchema = dejsonifySchema
|
||||
readonly dejsonifySchema = dejsonifySchema
|
||||
}
|
||||
|
||||
return new this.constructor(
|
||||
JsonifiableSchemas as unknown as (
|
||||
AbstractClass<
|
||||
Instance & JsonifiableSchemas,
|
||||
|
||||
// TODO: for some reason, ConstructorParameters<Super> does not work here. Maybe try to find a fix?
|
||||
ConstructorParameters<ZodSchemaAbstractClass<Instance, SchemaT, SchemaUnknownKeys, SchemaCatchall, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues>>
|
||||
> &
|
||||
StaticMembers<Super> &
|
||||
StaticMembers<typeof JsonifiableSchemas>
|
||||
),
|
||||
|
||||
[
|
||||
...this.expressionTraits,
|
||||
JsonifiableZodSchemaObject,
|
||||
DejsonifiableZodSchemaObject,
|
||||
],
|
||||
this.expression.expresses(
|
||||
JsonifiableZodSchemaObject(
|
||||
this.expression.expressionSuperclass.schema,
|
||||
this.expression.expressionSuperclass.schemaWithDefaultValues,
|
||||
props.jsonifySchema(this.expression.expressionSuperclass.schema),
|
||||
props.dejsonifySchema(this.expression.expressionSuperclass.schema),
|
||||
)
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
export const zodSchemaClass = new ZodSchemaClassBuilder(TraitExpression.NullSuperclass, [])
|
||||
export const zodSchemaClass = new ZodSchemaClassBuilder(expression)
|
||||
|
||||
@@ -18,6 +18,15 @@ const exp = zodSchemaClass
|
||||
id: s.shape.id.default(-1n),
|
||||
}),
|
||||
})
|
||||
.jsonifiable({
|
||||
jsonifySchema: s => s.extend({
|
||||
|
||||
}),
|
||||
|
||||
dejsonifySchema: s => s.extend({
|
||||
|
||||
}),
|
||||
})
|
||||
.expression
|
||||
.expresses(MobXObservableZodSchemaObject)
|
||||
.build()
|
||||
|
||||
Reference in New Issue
Block a user