Skip to main content

Class: EntityEventBus

Defined in: src/events/EntityEventBus.ts:27

High-performance, zero-dependency async event bus for entity domain and lifecycle events.

Supports exact event names ('Account:created'), table-level events ('accounts:created'), wildcard patterns ('*:created', 'Account:*', '*'), and domain event types ('EntityCreated').

Example​

db.on('Account:created', async (entity) => {
await eventBus.publish(new AccountCreatedEvent(entity));
});

Constructors​

Constructor​

new EntityEventBus(): EntityEventBus

Returns​

EntityEventBus

Methods​

on()​

on<T>(event, handler): this

Defined in: src/events/EntityEventBus.ts:51

Registers a persistent event listener for matching events.

Type Parameters​

Type ParameterDefault type
Tany

Parameters​

ParameterTypeDescription
eventstringThe event name or pattern (e.g. 'Account:created', '*:deleted', 'EntityCreated').
handlerEventHandler<T>The asynchronous or synchronous callback function.

Returns​

this

this instance for chaining.


once()​

once<T>(event, handler): this

Defined in: src/events/EntityEventBus.ts:68

Registers a one-time event listener that auto-unregisters after its first invocation.

Type Parameters​

Type ParameterDefault type
Tany

Parameters​

ParameterTypeDescription
eventstringThe event name or pattern.
handlerEventHandler<T>The callback function.

Returns​

this

this instance for chaining.


off()​

off(event, handler?): this

Defined in: src/events/EntityEventBus.ts:85

Unregisters an event listener. If handler is omitted, all listeners for event are removed.

Parameters​

ParameterTypeDescription
eventstringThe event name or pattern.
handler?EventHandler<any>The specific callback function to remove.

Returns​

this

this instance for chaining.


emit()​

emit(event, payload, alias?): Promise<void>

Defined in: src/events/EntityEventBus.ts:103

Emits an event with the given payload, invoking all matching listeners.

Parameters​

ParameterTypeDescription
eventstringThe concrete event name being emitted (e.g. 'Account:created').
payloadanyThe entity or event object to pass to handlers.
alias?stringOptional alias event name (e.g. table name 'accounts:created').

Returns​

Promise<void>


publish()​

publish(event, payload, alias?): Promise<void>

Defined in: src/events/EntityEventBus.ts:129

Publishes an event to listeners (alias for emit).

Parameters​

ParameterType
eventstring
payloadany
alias?string

Returns​

Promise<void>


listenerCount()​

listenerCount(event?): number

Defined in: src/events/EntityEventBus.ts:136

Returns the count of listeners registered for a specific pattern or in total.

Parameters​

ParameterType
event?string

Returns​

number


removeAllListeners()​

removeAllListeners(event?): this

Defined in: src/events/EntityEventBus.ts:144

Removes all registered event listeners, or all listeners for a given pattern.

Parameters​

ParameterType
event?string

Returns​

this