moleculer-decorators
Version:
decorators for moleculer
103 lines (84 loc) • 2.53 kB
Markdown

[](https://www.npmjs.com/package/moleculer-decorators)
[](https://www.npmjs.com/package/moleculer-decorators)
[](https://github.com/ColonelBundy/moleculer-decorators/issues)
[](https://github.com/ColonelBundy/moleculer-decorators/blob/master/LICENSE)
# Moleculer Decorators
Decorators for moleculer
## Available options
```js
constructOverride: false // True by default, This will override any properties defined in @Service if defined in the constructor as well.
```
These are defined in
# Example usage
```js
const moleculer = require('moleculer');
const { Service, Action, Event, Method, BaseSchema } = require('moleculer-decorators');
const web = require('moleculer-web');
const broker = new moleculer.ServiceBroker({
logger: console,
logLevel: "debug",
});
class ServiceName extends BaseSchema {
// Optional constructor
constructor() {
this.settings = { // Overrides above by default, to prevent this, add "constructOverride: false" to @Service
port: 3001
}
}
// Without constructor (typescript)
settings = {
port: 3001
}
Login(ctx) {
...
}
// With options
Login2(ctx) {
...
}
'event.name'(payload, sender, eventName) {
...
}
authorize(ctx, route, req, res) {
...
}
started() { // Reserved for moleculer, fired when started
...
}
created() { // Reserved for moleculer, fired when created
...
}
stopped() { // Reserved for moleculer, fired when stopped
...
}
}
broker.createService(ServiceName);
broker.start();
```
# Usage with moleculer-runner
Simply export the service instead of starting a broker manually.
```js
export default class ServiceName
```
# License
Moleculer Decorators is available under the [MIT license](https://tldrlegal.com/license/mit-license).