0.1.2 #3

Merged
Thilawyn merged 136 commits from next into master 2024-03-11 19:44:21 +01:00
2 changed files with 19 additions and 29 deletions
Showing only changes of commit 81efdaab01 - Show all commits

View File

@@ -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)

View File

@@ -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()