I treat the data from DB as foreign for my application and pass it through rescript-struct first to ensure that it represents what I expect. Also, it allows mapping data to a more convenient format to work, e.g. use option instead of nullable.
Do your test correlate with your types somehow? As in, is there a guarantee the tests will fail if the backend data doesn’t match your types? If so, you can probably push the checks to test time.
One other variant is to generate the types by the GraphQL/OpenRPC schema. That way, depending on how you deploy, you can skip runtime checks as well. But are there any solutions that generate ReScript (or even OCaml) code?
This feels like an exaggeration to me. You should decode your external data once it enters you app, not all the time.
Well, in theory, if you trust your data (e.g., if you’re able to generate types by schema), you can massage it without decoding. Pedantically speaking, these are two separate concerns anyway, even though it’s convenient to lump the code for both together.
There’s a related discussion, but no progress for now.
Looks like the most popular way to generate ReScript code is by using string templates. I haven’t seen any tools to work with ast directly, excluding the ocaml ones.
It can parse two nested objects with 8 fields ~3_000_000 times per second (benchmark). I’ve decided that it’s definitely won’t be a bottleneck in my app.
But I’d like to replace it with a codegen solution in the future.