feat(core-events): IEventBus interface + symbol registry
IEventBus defines publish<T> and subscribe<T> with consumerFeature parameter. CORE_EVENTS_SYMBOLS.IEventBus uses Symbol.for for cross-module identity. Typecheck passes. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
23
packages/core-events/src/event-bus.interface.ts
Normal file
23
packages/core-events/src/event-bus.interface.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import type { z } from "zod";
|
||||||
|
import type { EventDescriptor } from "./event-descriptor";
|
||||||
|
|
||||||
|
export type EventHandler<T> = (event: T) => Promise<void>;
|
||||||
|
|
||||||
|
export interface IEventBus {
|
||||||
|
publish<T>(
|
||||||
|
descriptor: EventDescriptor<string, z.ZodType<T>>,
|
||||||
|
payload: T,
|
||||||
|
): Promise<void>;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Subscribe a handler. `consumerFeature` is the kebab-case name of the
|
||||||
|
* subscribing feature (e.g., "marketing-pages"). InMemoryEventBus uses it
|
||||||
|
* only as a debug tag; PayloadJobsEventBus uses it to name the fan-out task
|
||||||
|
* slug deterministically (`__events.<event>.<consumerFeature>`).
|
||||||
|
*/
|
||||||
|
subscribe<T>(
|
||||||
|
descriptor: EventDescriptor<string, z.ZodType<T>>,
|
||||||
|
consumerFeature: string,
|
||||||
|
handler: EventHandler<T>,
|
||||||
|
): void;
|
||||||
|
}
|
||||||
3
packages/core-events/src/symbols.ts
Normal file
3
packages/core-events/src/symbols.ts
Normal file
@@ -0,0 +1,3 @@
|
|||||||
|
export const CORE_EVENTS_SYMBOLS = {
|
||||||
|
IEventBus: Symbol.for("@repo/core-events/IEventBus"),
|
||||||
|
} as const;
|
||||||
Reference in New Issue
Block a user