Files
Codewalkers/apps/server/events/bus.ts
Lukas May 34578d39c6 refactor: Restructure monorepo to apps/server/ and apps/web/ layout
Move src/ → apps/server/ and packages/web/ → apps/web/ to adopt
standard monorepo conventions (apps/ for runnable apps, packages/
for reusable libraries). Update all config files, shared package
imports, test fixtures, and documentation to reflect new paths.

Key fixes:
- Update workspace config to ["apps/*", "packages/*"]
- Update tsconfig.json rootDir/include for apps/server/
- Add apps/web/** to vitest exclude list
- Update drizzle.config.ts schema path
- Fix ensure-schema.ts migration path detection (3 levels up in dev,
  2 levels up in dist)
- Fix tests/integration/cli-server.test.ts import paths
- Update packages/shared imports to apps/server/ paths
- Update all docs/ files with new paths
2026-03-03 11:22:53 +01:00

68 lines
1.7 KiB
TypeScript

/**
* Event Emitter Bus - Adapter Implementation
*
* In-process EventBus implementation using Node.js EventEmitter.
* This is the ADAPTER for the EventBus PORT.
*
* Can be swapped for RabbitMQ, Kafka, WebSocket, etc. later
* without changing consumers.
*/
import { EventEmitter } from 'node:events';
import type { DomainEvent, EventBus } from './types.js';
/**
* EventEmitter-based implementation of the EventBus interface.
*
* Wraps Node.js EventEmitter to provide type-safe event handling
* that conforms to the EventBus port interface.
*/
export class EventEmitterBus implements EventBus {
private emitter: EventEmitter;
constructor() {
this.emitter = new EventEmitter();
// Allow more listeners for complex systems
this.emitter.setMaxListeners(100);
}
/**
* Emit an event to all subscribed handlers.
* The event's type property determines which handlers receive it.
*/
emit<T extends DomainEvent>(event: T): void {
this.emitter.emit(event.type, event);
}
/**
* Subscribe to events of a specific type.
*/
on<T extends DomainEvent>(
eventType: T['type'],
handler: (event: T) => void
): void {
this.emitter.on(eventType, handler);
}
/**
* Unsubscribe from events of a specific type.
*/
off<T extends DomainEvent>(
eventType: T['type'],
handler: (event: T) => void
): void {
this.emitter.off(eventType, handler);
}
/**
* Subscribe to a single occurrence of an event type.
* Handler is automatically removed after first invocation.
*/
once<T extends DomainEvent>(
eventType: T['type'],
handler: (event: T) => void
): void {
this.emitter.once(eventType, handler);
}
}