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:
2026-05-08 11:56:52 +02:00
parent ba3b6c9af6
commit 3da93efb89
2 changed files with 26 additions and 0 deletions

View 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;
}

View File

@@ -0,0 +1,3 @@
export const CORE_EVENTS_SYMBOLS = {
IEventBus: Symbol.for("@repo/core-events/IEventBus"),
} as const;