Joystream / joystream

Joystream Monorepo
http://www.joystream.org
GNU General Public License v3.0
1.43k stars 114 forks source link

Babylon: @joystream/types: api agumentation with custom class types #1393

Closed Lezek123 closed 3 years ago

Lezek123 commented 3 years ago

As this is a relatively easy step and may greatly simplify further work, I think it's worth implementing in the current release.

The idea is that we can then make queries etc. without the need for type assertions (which take some time to get right) in Pioneer (which heavily depends on custom-class types) and other projects.

We can already kind-of do this using interfaces generated with @polkadot/typegen, but this solution has a few downsides that can be eliminated:

The solution is to add a script to generate agument-api in types/augment-codec, which will augment the api.query, api.tx and api.consts types with our own classes instead of interfaces generated by @polkadot/typegen. The easiest way to do this seems to be just replacing the imports in the files that we already generate (ie. take augment-api files from types/agument and replace imports section with imports analogous to those from augment-codec/augment-types.ts).

Adding a script to do this should be relatively easy, but considering there may be some unexpected circumstances, I'm adding estimate-6h.

Lezek123 commented 3 years ago

Done in https://github.com/Joystream/joystream/pull/1460