Feature Proposal: Handler Parameter Entity Decorators

v4

#1

Hey everyone,
From other frameworks that have similar controller structure to Jovo, I have seen heavy usage of parameter Decorators to map query string parameters or URL parameters to handler function parameters for easier access. As an example, this is how it looks in nest.js:

@Get(':id')
findOne(@Param('id') id: string): string {
  return `This action returns a #${id} cat`;
}

I could see this being useful with entities in jovo as well, so we could have something like this:

@Handle(...)
@If((jovo:Jovo) => jovo.$entities.episode)
playEpisode(@Entity('episode') episode?: Entity){
    return this.$send({message: `Okay, playing ${episode.value}!`});
}

This might be even more handy if combined with a decorator that can make entities required, so that intents with that entity not filled, would not call this handler. With that, you could get rid of a lot of the @If Decorators, this could look like this:

@Handle(...)
playEpisode(@Required() @Entity('episode') episode: Entity){
    return this.$send({message: `Okay, playing ${episode.value}!`});
}

Is that something anyone else might find useful, or any issues I might be missing?


#2

I’m a big fan of NestJS and its architecture. I really like your idea. We discussed it with the team last year while working on version 4, but never took it further.

@Required() looks interesting. This could also be really useful.