json-joy
json-joy copied to clipboard
`json-crdt-patch` schema recursive types
Add ability to specify recursive types using a function wrapper
import {s} from 'json-joy/lib/json-crdt-patch';
const User = s.obj({
id: s.con(''),
name: s.str(''),
},
// Second object are optional fields
{
friend: () => User,
});
type UserType = {id: string, name: string, friend?: User};
Binary tree example:
const Node = s.obj({
key: s.str(''),
value: s.str(''),
},
{
left: () => Node,
right: () => Node,
});
type UserType = {id: string, name: string, friend?: User};