ZodSchemaClassBuilder work
All checks were successful
continuous-integration/drone/push Build is passing
All checks were successful
continuous-integration/drone/push Build is passing
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { Trait, TraitExpressionBuilder, expression } from "@thilawyn/traitify-ts"
|
||||
import { AbstractClass, Simplify } from "type-fest"
|
||||
import { JsonifiableObject } from "type-fest/source/jsonifiable"
|
||||
import { z } from "zod"
|
||||
import { ExtendableZodSchemaObject } from "./traits/ExtendableZodSchemaObject"
|
||||
import { InstantiableZodSchemaObject } from "./traits/InstantiableZodSchemaObject"
|
||||
@@ -37,8 +38,11 @@ extends TraitExpressionBuilder<Superclass, Traits> {
|
||||
DefaultValues extends Partial<Values>,
|
||||
>(
|
||||
this: ZodSchemaClassBuilder<Superclass, Traits>,
|
||||
schema: z.ZodObject<SchemaT, SchemaUnknownKeys, SchemaCatchall, Values, Values>,
|
||||
defaultValues: DefaultValues,
|
||||
|
||||
{ schema, defaultValues }: {
|
||||
schema: z.ZodObject<SchemaT, SchemaUnknownKeys, SchemaCatchall, Values, Values>
|
||||
defaultValues: DefaultValues
|
||||
},
|
||||
) {
|
||||
class Schemas extends (this.expressionSuperclass as AbstractClass<object, []>) {
|
||||
static readonly schema = schema
|
||||
@@ -76,7 +80,21 @@ extends TraitExpressionBuilder<Superclass, Traits> {
|
||||
)
|
||||
}
|
||||
|
||||
jsonifiable() {
|
||||
jsonifiable<
|
||||
Superclass extends AbstractClass<object>,
|
||||
|
||||
JsonifiedValues extends JsonifiableObject,
|
||||
|
||||
JsonifySchemaT extends z.ZodRawShape,
|
||||
JsonifySchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
JsonifySchemaCatchall extends z.ZodTypeAny,
|
||||
|
||||
DejsonifySchemaT extends z.ZodRawShape,
|
||||
DejsonifySchemaUnknownKeys extends z.UnknownKeysParam,
|
||||
DejsonifySchemaCatchall extends z.ZodTypeAny,
|
||||
>(
|
||||
this: ZodSchemaClassBuilder<Superclass, Traits>,
|
||||
) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
20
src/tests.ts
20
src/tests.ts
@@ -1,23 +1,11 @@
|
||||
import { Implements, TraitExpression } from "@thilawyn/traitify-ts"
|
||||
import { z } from "zod"
|
||||
import { ZodSchemaClass, ZodSchemaClassBuilder } from "./ZodSchemaClass"
|
||||
import { ZodSchemaClassBuilder } from "./ZodSchemaClass"
|
||||
import { ObservableZodSchemaObject } from "./traits/ObservableZodSchemaObject"
|
||||
|
||||
|
||||
const newTestExp = new ZodSchemaClassBuilder(TraitExpression.NullSuperclass, [])
|
||||
.schema(
|
||||
z.object({
|
||||
/** Object ID */
|
||||
id: z.bigint(),
|
||||
name: z.string(),
|
||||
}),
|
||||
|
||||
{ id: -1n },
|
||||
)
|
||||
.expresses(ObservableZodSchemaObject)
|
||||
.build()
|
||||
|
||||
const TestExp = ZodSchemaClass({
|
||||
.schema({
|
||||
schema: z.object({
|
||||
/** Object ID */
|
||||
id: z.bigint(),
|
||||
@@ -25,14 +13,14 @@ const TestExp = ZodSchemaClass({
|
||||
}),
|
||||
|
||||
defaultValues: { id: -1n },
|
||||
})
|
||||
})
|
||||
.expresses(ObservableZodSchemaObject)
|
||||
.build()
|
||||
|
||||
@newTestExp.staticImplements
|
||||
class Test extends newTestExp.extends implements Implements<typeof newTestExp> {}
|
||||
|
||||
Test.schema
|
||||
Test.defaultValues
|
||||
const inst = Test.create({ id: 1n, name: "" })
|
||||
console.log(inst)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user