ObservableZodSchemaObject
All checks were successful
continuous-integration/drone/push Build is passing

This commit is contained in:
Julien Valverdé
2024-02-21 04:45:43 +01:00
parent 4020f99d18
commit 1b9fa09186
2 changed files with 34 additions and 13 deletions

View File

@@ -1,14 +1,20 @@
import { expression } from "@thilawyn/traitify-ts"
import { InstantiableZodSchemaObject } from "./InstantiableZodSchemaObject"
import { trait } from "@thilawyn/traitify-ts"
import { mapValues } from "lodash-es"
import { makeObservable, observable } from "mobx"
import { z } from "zod"
export const ObservableZodSchemaObject = expression
.expresses(InstantiableZodSchemaObject)
export const ObservableZodSchemaObject = trait
.staticAbstract(Super => class extends Super {
declare readonly schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, object, object>
})
.implement(Super => class ObservableZodSchemaObject extends Super {
constructor(...args: any[]) {
super(...args)
makeObservable(this,
mapValues(ObservableZodSchemaObject.schema.shape, () => observable)
)
}
})
.build()
.subtrait()
.implement(Super => class ObservableZodSchemaObject extends Super {
constructor(...args: any[]) {
super(...args)
}
})
.build()