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 34 additions and 13 deletions
Showing only changes of commit 1b9fa09186 - Show all commits

View File

@@ -1,6 +1,7 @@
import { Implements } from "@thilawyn/traitify-ts" import { Implements } from "@thilawyn/traitify-ts"
import { z } from "zod" import { z } from "zod"
import { ZodSchemaClass } from "./ZodSchemaClass" import { ZodSchemaClass } from "./ZodSchemaClass"
import { ObservableZodSchemaObject } from "./traits/ObservableZodSchemaObject"
const TestExp = ZodSchemaClass({ const TestExp = ZodSchemaClass({
@@ -11,12 +12,14 @@ const TestExp = ZodSchemaClass({
}), }),
defaultValues: { id: -1n }, defaultValues: { id: -1n },
}).build() })
.expresses(ObservableZodSchemaObject)
.buildAnyway()
@TestExp.implementsStatic @TestExp.implementsStatic
class Test extends TestExp.extends implements Implements<typeof TestExp> {} class Test extends TestExp.extends implements Implements<typeof TestExp> {}
Test.defaultValues Test.schema
const inst = Test.create({ id: 1n, name: "" }) const inst = Test.create({ id: 1n, name: "" })
console.log(inst) console.log(inst)
@@ -37,3 +40,15 @@ console.log(subInst)
// class ChildTest extends Test {} // class ChildTest extends Test {}
// ChildTest.instantiate({ name: "" }) // ChildTest.instantiate({ name: "" })
const testSchema = { schema: Test.schema }
declare const testGenericSchema: {
schema: z.ZodObject<z.ZodRawShape, z.UnknownKeysParam, z.ZodTypeAny, object, object>
}
type U<T> = T
interface ExtendTest extends U<typeof testSchema> {
schema: z.ZodObject<any, any, any, any, any>
}

View File

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