0.1.2 #3
@@ -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 { 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 { JsonifiableZodSchemaObject } from "../traits/JsonifiableZodSchemaObject"
|
import { JsonifiableZodSchemaObject } from "../traits/JsonifiableZodSchemaObject"
|
||||||
import { ZodSchemaObject } from "../traits/ZodSchemaObject"
|
import { ZodSchemaObject, ZodSchemaObjectTrait } from "../traits/ZodSchemaObject"
|
||||||
import { StaticMembers } from "../util"
|
import { StaticMembers } from "../util"
|
||||||
|
|
||||||
|
|
||||||
@@ -64,9 +63,8 @@ export class ZodSchemaClassBuilder<
|
|||||||
}
|
}
|
||||||
|
|
||||||
jsonifiable<
|
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 },
|
& { jsonifySchema?: never, dejsonifySchema?: never },
|
||||||
Instance extends Values,
|
|
||||||
|
|
||||||
SchemaT extends z.ZodRawShape,
|
SchemaT extends z.ZodRawShape,
|
||||||
SchemaUnknownKeys extends z.UnknownKeysParam,
|
SchemaUnknownKeys extends z.UnknownKeysParam,
|
||||||
@@ -90,7 +88,7 @@ export class ZodSchemaClassBuilder<
|
|||||||
JsonifiedValues extends JsonifiableObject,
|
JsonifiedValues extends JsonifiableObject,
|
||||||
>(
|
>(
|
||||||
this: ZodSchemaClassBuilder<
|
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
|
Traits
|
||||||
>,
|
>,
|
||||||
|
|
||||||
|
|||||||
12
src/tests.ts
12
src/tests.ts
@@ -18,15 +18,15 @@ const exp = zodSchemaClass
|
|||||||
id: s.shape.id.default(-1n),
|
id: s.shape.id.default(-1n),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.jsonifiable({
|
// .jsonifiable({
|
||||||
jsonifySchema: s => s.extend({
|
// jsonifySchema: s => s.extend({
|
||||||
|
|
||||||
}),
|
// }),
|
||||||
|
|
||||||
dejsonifySchema: s => s.extend({
|
// dejsonifySchema: s => s.extend({
|
||||||
|
|
||||||
}),
|
// }),
|
||||||
})
|
// })
|
||||||
.expression
|
.expression
|
||||||
.expresses(MobXObservableZodSchemaObject)
|
.expresses(MobXObservableZodSchemaObject)
|
||||||
.build()
|
.build()
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ export const ZodSchemaObject = <
|
|||||||
) => trait
|
) => trait
|
||||||
.implement(Super => class ZodSchemaObject extends Super {
|
.implement(Super => class ZodSchemaObject extends Super {
|
||||||
static readonly schema = schema
|
static readonly schema = schema
|
||||||
static readonly schemaWithDefaultsValues = schemaWithDefaultValues
|
static readonly schemaWithDefaultValues = schemaWithDefaultValues
|
||||||
|
|
||||||
static transform<
|
static transform<
|
||||||
Instance extends Values,
|
Instance extends Values,
|
||||||
@@ -56,7 +56,7 @@ export const ZodSchemaObject = <
|
|||||||
...[values, params]: CreateArgs<PartialValues>
|
...[values, params]: CreateArgs<PartialValues>
|
||||||
) {
|
) {
|
||||||
return this
|
return this
|
||||||
.transform(this.schemaWithDefaultsValues)
|
.transform(this.schemaWithDefaultValues)
|
||||||
.parse(values, params)
|
.parse(values, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -70,7 +70,7 @@ export const ZodSchemaObject = <
|
|||||||
...[values, params]: CreateArgs<PartialValues>
|
...[values, params]: CreateArgs<PartialValues>
|
||||||
) {
|
) {
|
||||||
return this
|
return this
|
||||||
.transform(this.schemaWithDefaultsValues)
|
.transform(this.schemaWithDefaultValues)
|
||||||
.parseAsync(values, params)
|
.parseAsync(values, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -84,7 +84,7 @@ export const ZodSchemaObject = <
|
|||||||
...[values, params]: CreateArgs<PartialValues>
|
...[values, params]: CreateArgs<PartialValues>
|
||||||
) {
|
) {
|
||||||
return parseZodSchemaEffect(
|
return parseZodSchemaEffect(
|
||||||
this.transform(this.schemaWithDefaultsValues),
|
this.transform(this.schemaWithDefaultValues),
|
||||||
values,
|
values,
|
||||||
params,
|
params,
|
||||||
)
|
)
|
||||||
|
|||||||
Reference in New Issue
Block a user