Overview
What this package owns in the runtime
CQRS adds message buses, handler discovery, read or write repository injection, process managers, projection rebuilders, and idempotent command execution to xtaskjs. It builds on @xtaskjs/typeorm so the container can expose read and write datasources and repositories without hard-coding infrastructure details into handlers.
What it provides
- CommandBus, QueryBus, and EventBus are registered in the xtaskjs container and can be injected into controllers and services.
- CommandHandler(), QueryHandler(), EventHandler(), ProcessManager(), Saga, and ProjectionRebuilder() declare the CQRS runtime with decorators.
- InjectReadRepository(), InjectWriteRepository(), InjectReadDataSource(), and InjectWriteDataSource() resolve aliases backed by @xtaskjs/typeorm.
- IdempotentCommand() adds built-in in-memory command deduplication with an overridable idempotency store.
How it fits
- Configured through configureCqrs() or @Cqrs(...) before CreateApplication() so read and write datasource names are known during bootstrap.
- Initializes after TypeORM registration and publishes buses, lifecycle services, datasource aliases, and repository aliases into the same DI container.
- Demonstrated by the 19-cqrs_app and 20-cqrs_postgres_replication_app samples, and used by this website to route admin, registration, and news flows through command and query buses.