Schema generation for JS and TS, and other languages
MaksymZavershynskyi opened this issue · comments
Borsh is not a self-descriptive language, so some languages like JS need to either generate schema (which is currently consumed by borsh-js) or generate the full class implementation in JS.
We could take the following approach. Write cargo extension that would provide command like cargo generate-borsh js
that generates JS classes from Rust classes by walking over the crate looking for types decorated with #[derive(BorshSerialize, BorshDeserialize)]
and dump the generate JS analog while preserving the directory structure. We need to decide what do we want to do with types that implement BorshSerialize
, BorshDeserialize
explicitly. I suggest we skip them delegating JS code to the user. We can use https://crates.io/crates/syn for that.
Another question to discuss. CC @ilblackdragon @vgrichina What is the advantage of generating a schema that is later consumed by BinaryReader
over generating the full class implementation in JS? That it is more human-readable? Is there any performance disadvantage?