import { createEventBus } from 'eventbus-z'; import type { RuntimeContainer } from '../app/container'; export type RuntimeLogger = { info(message: string, meta?: unknown): void; error(message: string, meta?: unknown): void; }; export type RuntimeEventBus = ReturnType; export type GlobalEventBus = ReturnType; export type TypedRuntimeEventBus> = { $emit(event: K, ...args: TEvents[K]): void; $on(event: K, listener: (...args: TEvents[K]) => void): () => void; $off?(event: K, listener?: (...args: TEvents[K]) => void): void; $once?(event: K, listener: (...args: TEvents[K]) => void): void; }; export type RuntimeContext = { requestId: string; signal: AbortSignal; container: RuntimeContainer; logger: RuntimeLogger; events: RuntimeEventBus; globalEvents?: GlobalEventBus; cache: Map; auth?: { userId: string; }; throwIfAborted(): void; }; export type ActionNext = () => Promise; export type Middleware = (params: { input: TInput; context: RuntimeContext; next: ActionNext; }) => Promise; export type ActionHandler = (params: { input: TInput; context: RuntimeContext; }) => Promise; export type RuntimeAction = { name: string; middleware?: Middleware[]; retry?: { attempts: number; }; handler: ActionHandler; }; export type RuntimeSystem = { globalEvents: GlobalEventBus; };