Moleculer Decorators
Decorators for moleculer, Tested & accurate as of 0.14
Available options
constructOverride: false // True by default, This will override any properties defined in @Service if defined in the constructor as well.skipHandler: true // false by default, this will let a mixin override the handler in an action. (action options)
These are defined in @Service
Example usage
const moleculer = ;const Service Action Event Method = ;const web = ;const broker = logger: console logLevel: "debug"; @Service // Optional constructor { thissettings = // Overrides above by default, to prevent this, add "constructOverride: false" to @Service port: 3001 } // Without constructor (typescript) settings = port: 3001 @ { ... } @ { // this function will never be called since a mixin will override it, unless you specify skipHandler: false. } // With options // No need for "handler:{}" here @ { ... } @Event group: 'group_name' 'event.name'payload sender eventName ... @Event 'event.name'payload sender eventName ... @Method { ... } { // Reserved for moleculer, fired when started ... } { // Reserved for moleculer, fired when created ... } { // Reserved for moleculer, fired when stopped ... } broker;brokerstart;
Usage with moleculer-runner
Simply export the service instead of starting a broker manually.
It must be a commonjs module.
moduleexports = ServiceName
Usage with custom ServiceFactory class
Moleculer allows you to define your own ServiceFactory class, from which your services should inherit. All you have to do, is pass your custom ServiceFactory to broker options and also extend your services from this class
const moleculer = ;const Service Action = ; // create new service factory, inheriting from moleculer native ServiceService { superbroker schema } { return 'bar'; } // pass your custom service factory to broker optionsconst broker = ServiceFactory: CustomService; @ // extend your service from your custom service factory @ { return this; } broker;brokerstart;
License
Moleculer Decorators is available under the MIT license.