This commit is contained in:
@@ -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 { AbstractClass } 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 { ZodSchemaAbstractClass } from "../shapes/ZodSchemaClass"
|
import { ZodSchemaAbstractClass } from "../shapes/ZodSchemaClass"
|
||||||
import { DejsonifiableZodSchemaObject } from "../traits/DejsonifiableZodSchemaObject"
|
|
||||||
import { JsonifiableZodSchemaObject } from "../traits/JsonifiableZodSchemaObject"
|
import { JsonifiableZodSchemaObject } from "../traits/JsonifiableZodSchemaObject"
|
||||||
import { ZodSchemaObject } from "../traits/ZodSchemaObject"
|
import { ZodSchemaObject } from "../traits/ZodSchemaObject"
|
||||||
import { StaticMembers } from "../util"
|
import { StaticMembers } from "../util"
|
||||||
@@ -105,36 +104,18 @@ export class ZodSchemaClassBuilder<
|
|||||||
) => z.ZodObject<DejsonifySchemaT, DejsonifySchemaUnknownKeys, DejsonifySchemaCatchall, Values, JsonifiedValues>
|
) => 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(
|
return new this.constructor(
|
||||||
JsonifiableSchemas as unknown as (
|
this.expression.expresses(
|
||||||
AbstractClass<
|
JsonifiableZodSchemaObject(
|
||||||
Instance & JsonifiableSchemas,
|
this.expression.expressionSuperclass.schema,
|
||||||
|
this.expression.expressionSuperclass.schemaWithDefaultValues,
|
||||||
// TODO: for some reason, ConstructorParameters<Super> does not work here. Maybe try to find a fix?
|
props.jsonifySchema(this.expression.expressionSuperclass.schema),
|
||||||
ConstructorParameters<ZodSchemaAbstractClass<Instance, SchemaT, SchemaUnknownKeys, SchemaCatchall, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues>>
|
props.dejsonifySchema(this.expression.expressionSuperclass.schema),
|
||||||
> &
|
)
|
||||||
StaticMembers<Super> &
|
)
|
||||||
StaticMembers<typeof JsonifiableSchemas>
|
|
||||||
),
|
|
||||||
|
|
||||||
[
|
|
||||||
...this.expressionTraits,
|
|
||||||
JsonifiableZodSchemaObject,
|
|
||||||
DejsonifiableZodSchemaObject,
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
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),
|
id: s.shape.id.default(-1n),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
.jsonifiable({
|
||||||
|
jsonifySchema: s => s.extend({
|
||||||
|
|
||||||
|
}),
|
||||||
|
|
||||||
|
dejsonifySchema: s => s.extend({
|
||||||
|
|
||||||
|
}),
|
||||||
|
})
|
||||||
.expression
|
.expression
|
||||||
.expresses(MobXObservableZodSchemaObject)
|
.expresses(MobXObservableZodSchemaObject)
|
||||||
.build()
|
.build()
|
||||||
|
|||||||
Reference in New Issue
Block a user