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:
Refactoring Pioneer to use interfaces instead of class-types would take a long time
We cannot access getters like Entity.values in auto-generated interfaces (because values is already part of Struct and all interfaces extend Struct. In our custom-class types we change the getter name to ie. entity_values to sidestep this problem)
If our class types define getters that return modified field value (ie. return this.getField('name').toString()), the type in the auto-generated interface will not match
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.
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:Entity.values
in auto-generated interfaces (becausevalues
is already part ofStruct
and all interfaces extendStruct
. In our custom-class types we change the getter name to ie.entity_values
to sidestep this problem)return this.getField('name').toString()
), the type in the auto-generated interface will not matchThe solution is to add a script to generate
agument-api
intypes/augment-codec
, which will augment theapi.query
,api.tx
andapi.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. takeaugment-api
files fromtypes/agument
and replace imports section with imports analogous to those fromaugment-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
.