Moved current version to legacy
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:
63
src/tests.ts
63
src/tests.ts
@@ -1,63 +0,0 @@
|
||||
import { pipeInto } from "ts-functional-pipe"
|
||||
import { z } from "zod"
|
||||
import { defineDefaultValues, extendSchemableClass, makeSchemableClass, newSchemable } from "."
|
||||
import { dejsonifyBigIntSchema, dejsonifySchemable, jsonifyBigIntSchema, makeJsonifiableSchemableClass } from "./jsonifiable"
|
||||
import { makeSchemableClassObservable } from "./observable"
|
||||
|
||||
|
||||
const UserLevel = z.enum(["User", "Admin"])
|
||||
|
||||
|
||||
class User extends pipeInto(
|
||||
makeSchemableClass({
|
||||
schema: z.object({
|
||||
id: z.bigint(),
|
||||
name: z.string(),
|
||||
level: UserLevel,
|
||||
}),
|
||||
|
||||
defaultValues: defineDefaultValues({
|
||||
level: "User" as const
|
||||
}),
|
||||
}),
|
||||
|
||||
v => makeSchemableClassObservable(v),
|
||||
|
||||
v => makeJsonifiableSchemableClass(v, {
|
||||
jsonifySchema: ({ schema, shape }) => schema.extend({
|
||||
id: jsonifyBigIntSchema(shape.id)
|
||||
}),
|
||||
|
||||
dejsonifySchema: ({ schema, shape }) => schema.extend({
|
||||
id: dejsonifyBigIntSchema(shape.id)
|
||||
}),
|
||||
}),
|
||||
) {}
|
||||
|
||||
User.schema
|
||||
|
||||
|
||||
const user1 = newSchemable(User, { id: 1n, name: "User" })
|
||||
user1.schema
|
||||
|
||||
const jsonifiedUser1 = user1.jsonify()
|
||||
console.log(jsonifiedUser1)
|
||||
console.log(dejsonifySchemable(User, jsonifiedUser1))
|
||||
|
||||
|
||||
const UserWithPhone = extendSchemableClass(User, {
|
||||
schema: ({ schema }) => schema.extend({
|
||||
phone: z.string()
|
||||
}),
|
||||
|
||||
defaultValues: defaultValues => defineDefaultValues({
|
||||
...defaultValues,
|
||||
phone: "+33600000000",
|
||||
}),
|
||||
})
|
||||
|
||||
UserWithPhone.defaultValues
|
||||
|
||||
|
||||
// const user2 = newSchemable(UserWithPhone, { id: 1n, name: "User" })
|
||||
// console.log(user2.jsonify())
|
||||
|
||||
Reference in New Issue
Block a user