This commit is contained in:
@@ -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>
|
||||
& { jsonifySchema?: never, dejsonifySchema?: never },
|
||||
Instance extends Values,
|
||||
Super extends TraitClass<ZodSchemaObjectTrait<SchemaT, SchemaUnknownKeys, SchemaCatchall, SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues>>
|
||||
& { jsonifySchema?: never, dejsonifySchema?: never },
|
||||
|
||||
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
|
||||
>,
|
||||
|
||||
|
||||
12
src/tests.ts
12
src/tests.ts
@@ -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()
|
||||
|
||||
@@ -27,8 +27,8 @@ export const ZodSchemaObject = <
|
||||
schemaWithDefaultValues: z.ZodObject<SchemaWithDefaultValuesT, SchemaWithDefaultValuesUnknownKeys, SchemaWithDefaultValuesCatchall, Values, PartialValues>,
|
||||
) => trait
|
||||
.implement(Super => class ZodSchemaObject extends Super {
|
||||
static readonly schema = schema
|
||||
static readonly schemaWithDefaultsValues = schemaWithDefaultValues
|
||||
static readonly schema = schema
|
||||
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,
|
||||
)
|
||||
|
||||
Reference in New Issue
Block a user