0.1.1 #2
@@ -42,6 +42,7 @@
|
||||
"decimal.js": "^10.4.3",
|
||||
"effect": "^2.0.2",
|
||||
"lodash-es": "^4.17.21",
|
||||
"mobx": "^6.12.0",
|
||||
"type-fest": "^4.9.0",
|
||||
"zod": "^3.22.4"
|
||||
},
|
||||
|
||||
27
src/observable/ObservableSchemable.ts
Normal file
27
src/observable/ObservableSchemable.ts
Normal file
@@ -0,0 +1,27 @@
|
||||
import { trait } from "@thilawyn/thilatrait"
|
||||
import { mapValues } from "lodash-es"
|
||||
import { makeObservable } from "mobx"
|
||||
import { z } from "zod"
|
||||
|
||||
|
||||
export const ObservableSchemable = trait(Parent => {
|
||||
abstract class ObservableSchemable extends Parent {
|
||||
abstract readonly schema: z.ZodObject<
|
||||
z.ZodRawShape,
|
||||
z.UnknownKeysParam,
|
||||
z.ZodTypeAny,
|
||||
z.objectOutputType<z.ZodRawShape, z.ZodTypeAny, z.UnknownKeysParam>,
|
||||
z.objectInputType<z.ZodRawShape, z.ZodTypeAny, z.UnknownKeysParam>
|
||||
>
|
||||
|
||||
// constructor(...args: any[]) {
|
||||
// super(...args)
|
||||
|
||||
// makeObservable(this,
|
||||
// mapValues(this.schema.shape, () => observable) as AnnotationsMap<$Config["values"], never>
|
||||
// )
|
||||
// }
|
||||
}
|
||||
|
||||
return ObservableSchemable
|
||||
})
|
||||
1
src/observable/index.ts
Normal file
1
src/observable/index.ts
Normal file
@@ -0,0 +1 @@
|
||||
export * from "./ObservableSchemable"
|
||||
@@ -2,6 +2,8 @@ import { pipeInto } from "ts-functional-pipe"
|
||||
import { z } from "zod"
|
||||
import { defineDefaultValues, extendSchemableClass, makeSchemableClass, newSchemable } from "."
|
||||
import { dejsonifyBigIntSchema, dejsonifySchemable, jsonifyBigIntSchema, makeJsonifiableSchemableClass } from "./jsonifiable"
|
||||
import { extendsAndExpresses } from "@thilawyn/thilatrait"
|
||||
import { ObservableSchemable } from "./observable"
|
||||
|
||||
|
||||
const UserLevel = z.enum(["User", "Admin"])
|
||||
@@ -29,12 +31,16 @@ class User extends pipeInto(
|
||||
id: dejsonifyBigIntSchema(shape.id)
|
||||
}),
|
||||
}),
|
||||
|
||||
v => extendsAndExpresses(v, ObservableSchemable),
|
||||
) {}
|
||||
|
||||
User.defaultValues
|
||||
User.schema
|
||||
|
||||
|
||||
const user1 = newSchemable(User, { id: 1n, name: "User" })
|
||||
user1.schema
|
||||
|
||||
const jsonifiedUser1 = user1.jsonify()
|
||||
console.log(jsonifiedUser1)
|
||||
console.log(dejsonifySchemable(User, jsonifiedUser1))
|
||||
|
||||
Reference in New Issue
Block a user