Phase 3 Completed

This commit is contained in:
Rayyan
2026-08-02 17:44:50 +07:00
parent 7ce0de4e91
commit ffc5ecd259
68 changed files with 3132 additions and 163 deletions
+28
View File
@@ -0,0 +1,28 @@
import { Injectable, Logger } from '@nestjs/common';
import { EventEnvelope } from './event.interface';
type Handler = (event: EventEnvelope<any>) => Promise<void> | void;
@Injectable()
export class EventBus {
private handlers: Map<string, Handler[]> = new Map();
private readonly logger = new Logger(EventBus.name);
publish(event: EventEnvelope<any>) {
const handlers = this.handlers.get(event.type) || [];
for (const h of handlers) {
try {
Promise.resolve(h(event)).catch((err) => this.logger.error('Event handler error', err));
} catch (e) {
this.logger.error('Event handler threw', e as any);
}
}
}
subscribe(eventType: string, handler: Handler) {
const list = this.handlers.get(eventType) || [];
list.push(handler);
this.handlers.set(eventType, list);
}
}
+6
View File
@@ -0,0 +1,6 @@
export interface EventEnvelope<T = any> {
id: string;
timestamp: string; // ISO
type: string; // PascalCase event type
payload: T;
}