Open jackkleeman opened 6 months ago
I think we should modify the state ser/de support to be extensible, rather than going on a specific library. Similarly to how we do in the java sdk with the Serde
/StateKey
interface. For example:
ctx.get<number>("myKey"); // This uses JSON.parse to parse to `number`
ctx.set("myKey", myNumber); // This uses JSON.stringify to serialize `number`
const stateKey = StateKey.of<number>("myKey", serFunc, deserFun);
ctx.get(stateKey) // This uses deserFun to parse `number`
ctx.set(statekey, myNumber); // This uses serFun to serialize `number`
I think that is fine, but i would also change the default to superjson. It's quite annoying that Set or Map don't serialise properly right now
https://github.com/blitz-js/superjson
Would support serialising and deserialising various useful values like Sets, Maps, Dates without changing the stored JSON to anything too weird (still valid json, just a new schema)
Probably be used for the RPC stuff though because we want to stay wire compatible with JSON