Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal for @nestjs/auto-message-pattern Decorator, that I have created #14665

Open
1 task done
abdulrehmanwaseem opened this issue Feb 19, 2025 · 0 comments
Open
1 task done
Labels
needs triage This issue has not been looked into type: enhancement 🐺

Comments

@abdulrehmanwaseem
Copy link

Is there an existing issue that is already proposing this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe it

Hello Kamil/NestJS Team,

I hope you’re doing well! I’ve been experimenting with a small utility for NestJS microservices that removes the need to manually define message patterns. Instead of writing:

@MessagePattern('users.findAll')
findAll() {
  // ...
}
@MessagePattern('users.findOne')
findOne() {
  // ...
}

We can do:

@AutoMessagePattern()
findAll() {
  // ...
}
@AutoMessagePattern()
findOne() {
  // ...
}

The decorator automatically constructs the pattern (users.findAll, users.findOne) from the controller path or class name plus the method name. I’d love to release this as a community package under the @nestjs scope (e.g., @nestjs/auto-message-pattern) if you think it could benefit others.

Thank you for your time and for all your work on NestJS!

Best regards,
Abdul Rehman

Describe the solution you'd like

Solution Description:

I propose releasing a package (e.g., @nestjs/auto-message-pattern) that provides an @AutoMessagePattern() decorator. This decorator automatically constructs the message pattern for microservice controllers by using the controller’s metadata (from the @Controller() decorator or class name) and the method name. For example, in a controller decorated as @Controller('users'), the methods findAll() and findOne() will automatically generate the patterns users.findAll and users.findOne respectively.

Considered Drawbacks:

  • Edge Cases: Custom naming conventions or advanced use cases might require manual overrides.
  • Flexibility: Developers might want to customize the generated pattern further, which could necessitate additional configuration options.
  • Backward Compatibility: Ensuring compatibility with existing NestJS practices and avoiding unexpected behavior in legacy projects will be important.

Overall, the solution aims to reduce boilerplate, minimize manual errors, and improve consistency in defining message patterns across microservices.

Teachability, documentation, adoption, migration strategy

can't write more

What is the motivation / use case for changing the behavior?

can't write more

@abdulrehmanwaseem abdulrehmanwaseem added needs triage This issue has not been looked into type: enhancement 🐺 labels Feb 19, 2025
@abdulrehmanwaseem abdulrehmanwaseem changed the title Proposal for @nestjs/auto-message-pattern Decorator, that I created Proposal for @nestjs/auto-message-pattern Decorator, that I have created Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs triage This issue has not been looked into type: enhancement 🐺
Projects
None yet
Development

No branches or pull requests

1 participant