proto-kit / framework

Apache License 2.0
28 stars 10 forks source link

Decorators API for runtime module methods #13

Open maht0rz opened 1 year ago

maht0rz commented 1 year ago

Is your feature request related to a problem? Please describe. In order to be able to support e.g. method guards, we want to expose a developer friendly way of writing decorators for runtime module methods.

Describe the solution you'd like The actual API is to be designed, but the main intention is to allow runtime module developers to expose reusable pieces of business logic that can be applied to methods outside of the runtime module itself. The main feature of the decorator API would be to provide access to the this of the module/method to which the decorator is being applied. This then allows access to the module dependency injection, which the decorator might rely on.

Example of a decorator, that only allows an admin to call a method:


const adminOnly = methodDecorator((module, method) => {
this.admin.isAdmin(this.sender);
});

@adminOnly()
@method()
public mint(to: PublicKey) {}