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

This commit is contained in:
Julien Valverdé
2024-02-20 16:40:05 +01:00
parent 8297685453
commit eaaef3bfd1
2 changed files with 32 additions and 56 deletions

View File

@@ -1,28 +1,19 @@
import { expression } from "@thilawyn/traitify-ts"
import { AbstractClass } from "type-fest"
import { Implements } from "@thilawyn/traitify-ts"
import { z } from "zod"
import { ZodSchemaClass } from "./ZodSchemaClass"
import { ExtendableZodSchemaObject } from "./lib"
import { InstantiableZodSchemaObject } from "./traits/InstantiableZodSchemaObject"
class Test extends ZodSchemaClass({
const TestExp = ZodSchemaClass({
schema: z.object({
id: z.bigint(),
name: z.string(),
}),
defaultValues: { id: -1n },
}) {}
}).build()
const Test2 = ZodSchemaClass({
schema: z.object({
id: z.bigint(),
name: z.string(),
}),
defaultValues: { id: -1n },
})
@TestExp.implementsStatic
class Test extends TestExp.extends implements Implements<typeof TestExp> {}
Test.defaultValues
const inst = Test.create({ id: 1n, name: "" })
@@ -45,19 +36,3 @@ console.log(subInst)
// class ChildTest extends Test {}
// ChildTest.instantiate({ name: "" })
class Gneugneu {
}
export function getExpression<C extends AbstractClass<object>>(class_: C) {
return expression
.extends(class_)
.expresses(
InstantiableZodSchemaObject,
ExtendableZodSchemaObject,
)
}
const exp = getExpression(Gneugneu).build()