JsonifiableSchemable attempt as a trait
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:
49
src/tests.ts
49
src/tests.ts
@@ -1,39 +1,30 @@
|
||||
import { extendsAndExpresses } from "@thilawyn/thilatrait"
|
||||
import { z } from "zod"
|
||||
import { SchemableClassInput, extendSchemableClass, makeSchemableClass, newSchemableEffect } from "."
|
||||
import { makeSchemableClass, newSchemable } from "."
|
||||
import { JsonifiableSchemable } from "./jsonifiable"
|
||||
import { dejsonifyBigIntSchema, jsonifyBigIntSchema } from "./legacy/jsonifiable"
|
||||
|
||||
|
||||
// class Test1 {
|
||||
// static readonly schema = Test1Schema
|
||||
// readonly schema = Test1Schema
|
||||
|
||||
// static readonly defaultValues = { prout: "heugneu" }
|
||||
// readonly defaultValues = { prout: "heugneu" }
|
||||
|
||||
// prout: string = "heugneu"
|
||||
// }
|
||||
|
||||
const Test1 = makeSchemableClass(
|
||||
z.object({ prout: z.string() }),
|
||||
{},
|
||||
)
|
||||
|
||||
new Test1({ prout: "adfd" }).prout
|
||||
const UserLevel = z.enum(["User", "Admin"])
|
||||
|
||||
|
||||
const Test2 = extendSchemableClass(
|
||||
Test1,
|
||||
schema => schema.extend({ prout: z.literal("ruquier"), ruquier: z.number() }),
|
||||
() => ({ prout: "ruquier" as const }),
|
||||
)
|
||||
const UserProto = makeSchemableClass(z.object({
|
||||
id: z.bigint(),
|
||||
name: z.string(),
|
||||
level: UserLevel,
|
||||
}), {
|
||||
level: "User"
|
||||
} as const)
|
||||
|
||||
Test2.defaultValues
|
||||
new Test2({ prout: "ruquier", ruquier: 69 })
|
||||
UserProto.defaultValues
|
||||
|
||||
|
||||
class Test3 extends Test2 {
|
||||
}
|
||||
class User extends extendsAndExpresses(UserProto,
|
||||
JsonifiableSchemable(
|
||||
UserProto.schema.extend({ id: jsonifyBigIntSchema(z.bigint()) }),
|
||||
UserProto.schema.extend({ id: dejsonifyBigIntSchema(z.bigint()) }),
|
||||
)
|
||||
) {}
|
||||
|
||||
|
||||
type Test = SchemableClassInput<z.output<typeof Test3.schema>, typeof Test3.defaultValues>
|
||||
|
||||
const test3inst = newSchemableEffect(Test3, { ruquier: 48 })
|
||||
const user1 = newSchemable(User, { id: 1n, name: "User" })
|
||||
|
||||
Reference in New Issue
Block a user