{"id":28665554,"url":"https://github.com/colonelbundy/moleculer-decorators","last_synced_at":"2025-07-17T15:37:39.574Z","repository":{"id":28159055,"uuid":"116502527","full_name":"ColonelBundy/moleculer-decorators","owner":"ColonelBundy","description":"decorators for moleculer","archived":false,"fork":false,"pushed_at":"2023-01-23T22:05:48.000Z","size":554,"stargazers_count":62,"open_issues_count":17,"forks_count":19,"subscribers_count":4,"default_branch":"master","last_synced_at":"2025-05-25T17:05:11.707Z","etag":null,"topics":["decorators","microservice","moleculer","nodejs","typescript"],"latest_commit_sha":null,"homepage":null,"language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ColonelBundy.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2018-01-06T17:35:00.000Z","updated_at":"2024-05-15T08:06:51.000Z","dependencies_parsed_at":"2023-02-13T04:01:01.939Z","dependency_job_id":null,"html_url":"https://github.com/ColonelBundy/moleculer-decorators","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/ColonelBundy/moleculer-decorators","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColonelBundy%2Fmoleculer-decorators","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColonelBundy%2Fmoleculer-decorators/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColonelBundy%2Fmoleculer-decorators/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColonelBundy%2Fmoleculer-decorators/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ColonelBundy","download_url":"https://codeload.github.com/ColonelBundy/moleculer-decorators/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ColonelBundy%2Fmoleculer-decorators/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":259654511,"owners_count":22891032,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["decorators","microservice","moleculer","nodejs","typescript"],"created_at":"2025-06-13T13:38:48.129Z","updated_at":"2025-06-13T13:39:58.894Z","avatar_url":"https://github.com/ColonelBundy.png","language":"TypeScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"![Moleculer logo](https://raw.githubusercontent.com/ice-services/moleculer/HEAD/docs/assets/logo.png)\n\n\n[![npm](https://img.shields.io/npm/v/moleculer-decorators.svg)](https://www.npmjs.com/package/moleculer-decorators) \n[![npm](https://img.shields.io/npm/dm/moleculer-decorators.svg)](https://www.npmjs.com/package/moleculer-decorators) \n[![GitHub issues](https://img.shields.io/github/issues/ColonelBundy/moleculer-decorators.svg)](https://github.com/ColonelBundy/moleculer-decorators/issues) \n[![GitHub license](https://img.shields.io/github/license/ColonelBundy/moleculer-decorators.svg)](https://github.com/ColonelBundy/moleculer-decorators/blob/master/LICENSE)\n[![Powered by moleculer](https://img.shields.io/badge/Powered%20by-Moleculer-green.svg?colorB=0e83cd)](http://moleculer.services/)\n# Moleculer Decorators\n\u003e Decorators for moleculer, Tested \u0026 accurate as of 0.14\n\n## Available options\n```js\nconstructOverride: false // True by default, This will override any properties defined in @Service if defined in the constructor as well.\nskipHandler: true // false by default, this will let a mixin override the handler in an action. (action options)\n```\n\u003e These are defined in @Service\n\n# Example usage\n\n```js\nconst moleculer = require('moleculer');\nconst { Service, Action, Event, Method } = require('moleculer-decorators');\nconst web = require('moleculer-web');\nconst broker = new moleculer.ServiceBroker({\n  logger: console,\n  logLevel: \"debug\",\n});\n\n@Service({\n  mixins: [web],\n  settings: {\n    port: 3000,\n    routes: [\n      ...\n    ]\n  }\n})\nclass ServiceName extends moleculer.Service {\n\n  // Optional constructor\n  constructor() {\n    this.settings = { // Overrides above by default, to prevent this, add \"constructOverride: false\" to @Service\n      port: 3001\n    }\n  }\n\n  // Without constructor (typescript)\n  settings = {\n    port: 3001\n  }\n\n  @Action()\n  Login(ctx) {\n    ...\n  }\n\n  @Action({\n    skipHandler: true // Any options will be merged with the mixin's action.\n  })\n  Login3() { // this function will never be called since a mixin will override it, unless you specify skipHandler: false.\n\n  }\n\n  // With options\n  // No need for \"handler:{}\" here\n  @Action({\n    cache: false,\n    params: {\n      a: \"number\",\n      b: \"number\"\n    }\n  })\n  Login2(ctx) {\n    ...\n  }\n\n  @Event({\n    group: 'group_name'\n  })\n  'event.name'(payload, sender, eventName) {\n    ...\n  }\n\n  @Event()\n  'event.name'(payload, sender, eventName) {\n    ...\n  }\n\n  @Method\n  authorize(ctx, route, req, res) {\n    ...\n  }\n\n  started() { // Reserved for moleculer, fired when started\n    ...\n  }\n\n  created() { // Reserved for moleculer, fired when created\n    ...\n  }\n\n  stopped() { // Reserved for moleculer, fired when stopped\n    ...\n  }\n}\n\nbroker.createService(ServiceName);\nbroker.start();\n```\n\n# Usage with moleculer-runner\n\u003e Simply export the service instead of starting a broker manually.    \n\u003e It must be a commonjs module.\n```js \n  module.exports = ServiceName \n``` \n\n## Usage with custom ServiceFactory class\n\u003e Moleculer allows you to define your own ServiceFactory class, from which your services should inherit. \n\u003e All you have to do, is pass your custom ServiceFactory to broker options and also extend your services from this class \n```js\nconst moleculer = require('moleculer');\nconst { Service, Action } = require('moleculer-decorators');\n\n// create new service factory, inheriting from moleculer native Service\nclass CustomService extends moleculer.Service {\n    constructor(broker, schema) {\n        super(broker, schema)\n    }\n\n    foo() {\n        return 'bar';\n    }\n}\n\n// pass your custom service factory to broker options\nconst broker = new moleculer.ServiceBroker({\n  ServiceFactory: CustomService\n});\n\n@Service()\nclass ServiceName extends CustomService { // extend your service from your custom service factory\n  @Action()\n  Bar(ctx) {\n    return this.foo();\n  }\n}\n\nbroker.createService(CustomService);\nbroker.start();\n```\n\n# License\nMoleculer Decorators is available under the [MIT license](https://tldrlegal.com/license/mit-license).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolonelbundy%2Fmoleculer-decorators","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcolonelbundy%2Fmoleculer-decorators","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcolonelbundy%2Fmoleculer-decorators/lists"}