{"id":13651715,"url":"https://github.com/jarvify/moleculer-ts","last_synced_at":"2025-04-27T05:32:54.310Z","repository":{"id":36471264,"uuid":"219496174","full_name":"jarvify/moleculer-ts","owner":"jarvify","description":"Definitive TypeScript support for Moleculer service actions interface","archived":false,"fork":false,"pushed_at":"2022-12-10T18:31:08.000Z","size":1971,"stargazers_count":24,"open_issues_count":28,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2024-04-27T02:27:05.208Z","etag":null,"topics":["moleculer","moleculerjs","mustache-js","typescript"],"latest_commit_sha":null,"homepage":"","language":"TypeScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/jarvify.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-11-04T12:26:49.000Z","updated_at":"2024-03-15T10:54:38.000Z","dependencies_parsed_at":"2023-01-17T02:00:52.273Z","dependency_job_id":null,"html_url":"https://github.com/jarvify/moleculer-ts","commit_stats":null,"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarvify%2Fmoleculer-ts","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarvify%2Fmoleculer-ts/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarvify%2Fmoleculer-ts/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/jarvify%2Fmoleculer-ts/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/jarvify","download_url":"https://codeload.github.com/jarvify/moleculer-ts/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":223906371,"owners_count":17223045,"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":["moleculer","moleculerjs","mustache-js","typescript"],"created_at":"2024-08-02T02:00:51.741Z","updated_at":"2024-11-10T02:31:18.840Z","avatar_url":"https://github.com/jarvify.png","language":"TypeScript","funding_links":[],"categories":["Tools"],"sub_categories":["GraphQL"],"readme":"![Moleculer logo](https://raw.githubusercontent.com/ice-services/moleculer/HEAD/docs/assets/logo.png)\n\n[![npm](https://img.shields.io/npm/v/moleculer-ts.svg)](https://www.npmjs.com/package/moleculer-ts)\n[![npm](https://img.shields.io/npm/dm/moleculer-ts.svg)](https://www.npmjs.com/package/moleculer-ts)\n[![GitHub issues](https://img.shields.io/github/issues/jarvify/moleculer-ts.svg)](https://github.com/jarvify/moleculer-ts/issues)\n[![Powered by moleculer](https://img.shields.io/badge/Powered%20by-Moleculer-green.svg?colorB=0e83cd)](http://moleculer.services/)\n\n# Moleculer TypeScript generator for services types\n\n## Description\n\n`moleculer-ts` is a tool which generates [moleculer](https://github.com/moleculerjs/moleculer) types for your sevices actions \u0026 events.\n\n## Features\n\n- Generate types for call, emit, broadcast, broadcastLocal functions\n- Customizable Broker \u0026 Service interface\n- Automatic regeneration of types on files change\n- Using ts-patch \u0026 ts-transformer-enumerate - please follow installation instructions\n\n## Installation\n\nFollow these steps to install `moleculer-ts`\n\n```bash\n# install moleculer and moleculer-ts\nnpm i moleculer moleculer-ts --save\n\n# install typescript and few other tools\nnpm i typescript ts-patch ts-transformer-enumerate prettier @types/node -D\n\n# localy patch typescript in order to work properly\nnode_modules/.bin/ts-patch install\n```\n\n### Add to your tsconfig.json\n\nAdd `ts-transformer-enumerate` plugin to your `compilerOptions` in your `tsconfig`\n\n```json\n{\n  \"compilerOptions\": {\n    \"plugins\": [{ \"transform\": \"ts-transformer-enumerate/transformer\" }]\n  }\n}\n```\n\nYou should be good to go\n\n### How to generate\n\n#### \\*.service.types module structure\n\nDefine your service types interface\n\n```typescript\nimport { Action, Event, ConcatMultiple } from 'moleculer-ts';\n\n// required to specify your service\nexport const name: 'serviceName' = 'serviceName';\n\n// export list of own service actions\nexport type OwnActions = [];\n\n// export list of own service events\nexport type OwnEvents = [];\n\n// concat service's own actions/events with mixins inherited types\nexport type Actions = ConcatMultiple\u003c[OwnActions]\u003e;\nexport type Events = ConcatMultiple\u003c[OwnEvents]\u003e;\n```\n\n#### Write your gen.broker.types.ts script\n\nWrite your generator module. Use `generateBroker` to scan types and prints it in `outputDir`\n\n```typescript\nimport { generateBroker } from 'moleculer-ts';\n\n(async () =\u003e {\n  const brokerRootDir = `${process.cwd()}/src`;\n\n  await generateBroker({\n    serviceTypesPattern: `${brokerRootDir}/**/*.service.types.ts`,\n    outputDir: `${brokerRootDir}/types`,\n  });\n})();\n```\n\nRun this script from `package.json`\n\n```json\n{\n  \"scripts\": {\n    \"gen:broker:types\": \"ts-node src/gen.broker.types.ts\"\n  }\n}\n```\n\n### How to use\n\nimport your generated types and use them as input/output definition in service actions\n\n```typescript\nimport { Context } from 'moleculer';\nimport { UserServiceTypes } from '{brokerRootDir}/types';\n\nexport default {\n  name: UserServiceTypes.name,\n  actions: {\n    async get(\n      ctx: Context\u003cUserServiceTypes.ActionParams\u003c'get'\u003e\u003e,\n    ): Promise\u003cUserServiceTypes.ActionReturn\u003c'get'\u003e\u003e {\n      // fully typed params\n      const { params } = ctx;\n\n      // Return matching output\n      return {\n        id: 'a',\n        email: 'a',\n        name: 'a',\n      };\n    },\n  },\n};\n```\n\n### Advanced usage\n\n![Moleculer TypeScript](examples/moleculer-ts.gif)\n\nWant to see more advanced usage? You can enable realtime typescript checking in your IDE\n\nHead to [examples](/examples#readme) to find out more\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjarvify%2Fmoleculer-ts","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjarvify%2Fmoleculer-ts","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjarvify%2Fmoleculer-ts/lists"}