ZodSchemaClassBuilder work
Some checks failed
continuous-integration/drone/push Build is failing

This commit is contained in:
Julien Valverdé
2024-03-09 01:29:38 +01:00
parent 81efdaab01
commit 12b73e39e3
3 changed files with 16 additions and 18 deletions

View File

@@ -1,10 +1,9 @@
import { Trait, TraitExpressionBuilder, expression } from "@thilawyn/traitify-ts"
import { Trait, TraitClass, 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 { JsonifiableZodSchemaObject } from "../traits/JsonifiableZodSchemaObject"
import { ZodSchemaObject } from "../traits/ZodSchemaObject"
import { ZodSchemaObject, ZodSchemaObjectTrait } from "../traits/ZodSchemaObject"
import { StaticMembers } from "../util"
@@ -64,9 +63,8 @@ export class ZodSchemaClassBuilder<
}
jsonifiable<
Super extends ZodSchemaAbstractClass<Instance, SchemaT, SchemaUnknownKeys, SchemaCatchall, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues>
Super extends TraitClass<ZodSchemaObjectTrait<SchemaT, SchemaUnknownKeys, SchemaCatchall, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues>>
& { jsonifySchema?: never, dejsonifySchema?: never },
Instance extends Values,
SchemaT extends z.ZodRawShape,
SchemaUnknownKeys extends z.UnknownKeysParam,
@@ -90,7 +88,7 @@ export class ZodSchemaClassBuilder<
JsonifiedValues extends JsonifiableObject,
>(
this: ZodSchemaClassBuilder<
Super | ZodSchemaAbstractClass<Instance, SchemaT, SchemaUnknownKeys, SchemaCatchall, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues>,
Super | TraitClass<ZodSchemaObjectTrait<SchemaT, SchemaUnknownKeys, SchemaCatchall, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues>>,
Traits
>,

View File

@@ -18,15 +18,15 @@ const exp = zodSchemaClass
id: s.shape.id.default(-1n),
}),
})
.jsonifiable({
jsonifySchema: s => s.extend({
// .jsonifiable({
// jsonifySchema: s => s.extend({
}),
// }),
dejsonifySchema: s => s.extend({
// dejsonifySchema: s => s.extend({
}),
})
// }),
// })
.expression
.expresses(MobXObservableZodSchemaObject)
.build()

View File

@@ -28,7 +28,7 @@ export const ZodSchemaObject = <
) => trait
.implement(Super => class ZodSchemaObject extends Super {
static readonly schema = schema
static readonly schemaWithDefaultsValues = schemaWithDefaultValues
static readonly schemaWithDefaultValues = schemaWithDefaultValues
static transform<
Instance extends Values,
@@ -56,7 +56,7 @@ export const ZodSchemaObject = <
...[values, params]: CreateArgs<PartialValues>
) {
return this
.transform(this.schemaWithDefaultsValues)
.transform(this.schemaWithDefaultValues)
.parse(values, params)
}
@@ -70,7 +70,7 @@ export const ZodSchemaObject = <
...[values, params]: CreateArgs<PartialValues>
) {
return this
.transform(this.schemaWithDefaultsValues)
.transform(this.schemaWithDefaultValues)
.parseAsync(values, params)
}
@@ -84,7 +84,7 @@ export const ZodSchemaObject = <
...[values, params]: CreateArgs<PartialValues>
) {
return parseZodSchemaEffect(
this.transform(this.schemaWithDefaultsValues),
this.transform(this.schemaWithDefaultValues),
values,
params,
)