Moleculer TypeScript generator for services types
Description
moleculer-ts
is a tool which generates moleculer types for your sevices actions & events.
Features
- Generate types for call, emit, broadcast, broadcastLocal functions
- Customizable Broker & Service interface
- Automatic regeneration of types on files change
- Using ts-patch & ts-transformer-enumerate - please follow installation instructions
Installation
Follow these steps to install moleculer-ts
# install moleculer and moleculer-ts npm i moleculer moleculer-ts --save # install typescript and few other tools npm i typescript ts-patch ts-transformer-enumerate prettier @types/node -D # localy patch typescript in order to work properly node_modules/.bin/ts-patch install
Add to your tsconfig.json
Add ts-transformer-enumerate
plugin to your compilerOptions
in your tsconfig
You should be good to go
How to generate
*.service.types module structure
Define your service types interface
; // required to specify your service; // export list of own service actions; // export list of own service events; // concat service's own actions/events with mixins inherited types;;
Write your gen.broker.types.ts script
Write your generator module. Use generateBroker
to scan types and prints it in outputDir
; ;
Run this script from package.json
How to use
import your generated types and use them as input/output definition in service actions
;; ;
Advanced usage
Want to see more advanced usage? You can enable realtime typescript checking in your IDE
Head to examples to find out more