This commit is contained in:
77
src/tests.ts
77
src/tests.ts
@@ -1,69 +1,24 @@
|
||||
import { Implements, expression } from "@thilawyn/traitify-ts"
|
||||
import { Class } from "type-fest"
|
||||
import { Implements } from "@thilawyn/traitify-ts"
|
||||
import { z } from "zod"
|
||||
import { ZodSchemaObject } from "./traits/ZodSchemaObject"
|
||||
import { StaticMembers } from "./util"
|
||||
import { zodSchemaClass } from "./builders/ZodSchemaClassBuilder"
|
||||
import { MobXObservableZodSchemaObject } from "./traits/MobXObservableZodSchemaObject"
|
||||
|
||||
|
||||
// const exp = zodSchemaClass
|
||||
// .schema({
|
||||
// schema: z.object({
|
||||
// /** User ID */
|
||||
// id: z.bigint(),
|
||||
const exp = zodSchemaClass
|
||||
.schema({
|
||||
schema: z.object({
|
||||
/** User ID */
|
||||
id: z.bigint(),
|
||||
|
||||
// /** Username */
|
||||
// name: z.string(),
|
||||
// }),
|
||||
/** Username */
|
||||
name: z.string(),
|
||||
}),
|
||||
|
||||
// schemaWithDefaultValues: s => s.extend({
|
||||
// id: s.shape.id.default(-1n),
|
||||
// }),
|
||||
// })
|
||||
// .jsonifiable({
|
||||
// jsonifySchema: s => s.extend({
|
||||
// id: jsonify.bigint(s.shape.id)
|
||||
// }),
|
||||
|
||||
// dejsonifySchema: s => s.extend({
|
||||
// id: dejsonify.bigint(s.shape.id)
|
||||
// }),
|
||||
// })
|
||||
// .expresses(MobXObservableZodSchemaObject)
|
||||
// .build()
|
||||
|
||||
const schema = z.object({
|
||||
/** User ID */
|
||||
id: z.bigint(),
|
||||
|
||||
/** Username */
|
||||
name: z.string(),
|
||||
})
|
||||
const schemaWithDefaultsValues = schema.extend({
|
||||
id: schema.shape.id.default(-1n),
|
||||
})
|
||||
class UserSchemas {
|
||||
static readonly schema = schema
|
||||
static readonly schemaWithDefaultValues = schemaWithDefaultsValues
|
||||
|
||||
constructor(values: z.output<typeof schema>) {
|
||||
Object.assign(this, values)
|
||||
}
|
||||
}
|
||||
|
||||
const exp = expression
|
||||
.extends(UserSchemas as (
|
||||
Class<UserSchemas & z.output<typeof schema>> &
|
||||
StaticMembers<typeof UserSchemas>
|
||||
))
|
||||
.expresses(
|
||||
ZodSchemaObject(
|
||||
schema,
|
||||
|
||||
s => s.extend({
|
||||
id: s.shape.id.default(-1n),
|
||||
}),
|
||||
)
|
||||
)
|
||||
schemaWithDefaultValues: s => s.extend({
|
||||
id: s.shape.id.default(-1n),
|
||||
}),
|
||||
})
|
||||
.expresses(MobXObservableZodSchemaObject)
|
||||
.build()
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user