import EventEmitter2 from "eventemitter2"; import type { AuthToken } from "../cloud/auth"; import type { GetApiEventPayload } from "../cloud/buffered-event-stream"; import type { LogEntry } from "../logger/log-entry"; export type GardenEventListener = (payload: Events[T]) => void; export type GardenEventAnyListener = (name: E, payload: Events[E]) => void; /** * This simple class serves as the central event bus for a Garden instance. Its function * is mainly to consolidate all events for the instance, to ensure type-safety. * * See below for the event interfaces. */ export declare class EventBus extends EventEmitter2 { private keyIndex; constructor(); emit(name: T, payload: Events[T]): boolean; on(name: T, listener: GardenEventListener): import("eventemitter2").Listener | this; /** * Registers the listener under the provided key for easy cleanup via `offKey`. This is useful e.g. for the * plugin event broker, which is instantiated in several places and where there isn't a single obvious place to * remove listeners from all instances generated in a single command run. */ onKey(name: T, listener: GardenEventListener, key: string): import("eventemitter2").Listener | this; /** * Removes all event listeners for the event `name` that were registered under `key` (via `onKey`). */ offKey(name: T, key: string): void; /** * Removes all event listeners that were registered under `key` (via `onKey`). */ clearKey(key: string): void; /** * Add the given listener if it's not already been added. * Basically an idempotent version of on(), which otherwise adds the same listener again if called twice with * the same listener. */ ensure(name: T, listener: GardenEventListener): import("eventemitter2").Listener | this; onAny(listener: GardenEventAnyListener): this; /** * Add the given listener if it's not already been added. * Basically an idempotent version of onAny(), which otherwise adds the same listener again if called twice with * the same listener. */ ensureAny(listener: GardenEventAnyListener): this; once(name: T, listener: GardenEventListener): import("eventemitter2").Listener | this; } /** * Supported Garden events and their interfaces. */ export interface Events { _exit: object; _restart: object; _test: { msg?: string; }; receivedToken: AuthToken; internalError: { timestamp: Date; error: Error; }; sessionCompleted: GetApiEventPayload<"sessionCompleted">; sessionFailed: GetApiEventPayload<"sessionFailed">; sessionCancelled: GetApiEventPayload<"sessionCancelled">; commandInfo: GetApiEventPayload<"commandInfo">; logEntry: LogEntry; runStatus: GetApiEventPayload<"runStatus">; deployStatus: GetApiEventPayload<"deployStatus">; } export type EventName = keyof Events;