json-joy icon indicating copy to clipboard operation
json-joy copied to clipboard

`json-crdt-patch` schema recursive types

Open streamich opened this issue 4 months ago • 0 comments

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};

streamich avatar Jul 28 '25 08:07 streamich