[Spike] SDK Architecture Improvements
This spike is to evaluate the current architecture: xdrgen to js-xdr (where js-xdr produces an output which uses dts-xdr to output the d.ts typescript definition). Details in this doc.
Paths
-
One suggested path: In an ideal world, can go straight from xdrgen to typescript. (possibly rewrite js-xdr to ts-xdr?)
-
Another possible path: JSON => XDR. However, there is concern on performance (need to bundle) and also technical lift. Short term, we could potentially add a .toJSON() method to convert
Exploratory Ideas
- sunset xdrgen?
- what are other tools for *.x to Typescript or JSON with types
- XDR -> Rust -> Typescript? https://github.com/kochavalabs/xdr-codegen
We should timebox this spike to no more than 1 sprint.
Kick-Off Discussion Notes
There are many possible approaches on improving the XDR <-> TypeScript pipeline, each with their own trade-offs:
@stellar/stellar-xdr-json-webrequires an environment that can instantiate a WASM VM which may have non-trivial performance impacts. @willemneal is on point to do a secondary spike on whether or not it's feasible to use pointers from JS to WASM to avoid an encode/decode round-trip and improve the performance significantly.- We also discussed whether or not this package could provide a comprehensive JSON schema of the XDR types which could then be used in a second one-time "generator" step to build compatible structures.
- Something we didn't discuss that just came to mind is the possibility to perform that secondary generator step at build time in the downstream project, which would let us ensure that only the "used" XDR structures get language bindings generated for them. However, this might be absurdly hard to pull off and could probably be achieved easier with tree shaking.
- There may be existing solutions in 2024 that do XDR -> JSON/TS/JS better/faster/stronger than we do and @chadoh is on point to produce a research spike on those.
- @Shaptic (me) will do a spike into the possibility for xdrgen to output well-mannered TypeScript directly.
Does that cover things, guys? Feel free to edit my comment or add more thoughts below.
There may be existing solutions in 2024 that do XDR -> JSON/TS/JS better/faster/stronger than we do and @chadoh is on point to produce a research spike on those.
I asked @BlaineHeffron to help with this while I was busy with other things, and his discovery is "SDF is the only team building XDR libraries" and that, if we want something, we will need to be the ones to build it!
@chadoh figures 😂 wellll I don't think this is a high-enough priority item given the massive gains in #1066! Imo we should just call this a dead end since there's no way anyone has the bandwidth to understand and rewrite xdrgen for TypeScript.
@willemneal Please summarize what you did
- json serde, wasm json
- wasm bindgen