moleculer-service
TypeScript icon, indicating that this package has built-in type declarations

0.2.4 • Public • Published

Moleculer Service

TypeScript decorators for Moleculer.

Install

$ npm install moleculer-service

Example

import { Context } from 'moleculer';
import { Service, service, action, event } from 'moleculer-service';
 
type WelcomeParams = {
  name: string;
};
 
@service('greeter')
class GreeterService extends Service {
  @action('hello')
  public async hello(ctx: Context) {
    return 'Hello, World!';
  }
 
  @action({
    name: 'welcome',
    params: {
      name: 'string',
    },
  })
  public async welcome(ctx: Context<WelcomeParams>) {
    return `Welcome, ${ctx.params.name}!`;
  }
 
  @event('some.event')
  public async onSomeEvent(payload: Record<string, any>, sender: string, eventName: string) {
    this.logger.info(`Event[${sender}][${eventName}]: ${JSON.stringify(payload)}`);
  }
}

Readme

Keywords

none

Package Sidebar

Install

npm i moleculer-service

Weekly Downloads

0

Version

0.2.4

License

MIT

Unpacked Size

11.3 kB

Total Files

13

Last publish

Collaborators

  • joshmanders