From b4309528788aafd85fbae0066129a1319b54dbe5 Mon Sep 17 00:00:00 2001 From: Peter Hooper <diversemix@gmail.com> Date: Mon, 30 Dec 2019 13:55:35 +0000 Subject: [PATCH] Move EventBus into its own file --- src/event-bus/index.ts | 45 ++---------------------------------------- 1 file changed, 2 insertions(+), 43 deletions(-) diff --git a/src/event-bus/index.ts b/src/event-bus/index.ts index 96fbe60..3067e75 100644 --- a/src/event-bus/index.ts +++ b/src/event-bus/index.ts @@ -1,43 +1,2 @@ -// Abstract Message Queue - types and interfaces - -/** - * TODO: Once agreed, add these to DefinitelyTyped so they can be shared. - */ - -export type EventType = string; - -export interface Event<T extends object> { - readonly eventType: EventType; - readonly id: string; // Generated when the event is emitted - readonly created: Date; - readonly payload: T; // The actual data the event is carrying. - // version: has been removed - so we can remain weakly typed - // context: has also been removed - if you need information about the origin - // source of the event then put it in the payload. -} - -export interface EventPublisher { - // Promise<boolean> should this become void | exception? we only need to know if something went wrong - publish<T extends object>(event: Event<T>): Promise<boolean>; -} - -export interface EventSubscriber { - // handler: returns whether or not we should ack the message - subscribe<T extends object>(eventType: string, handler: (event: Event<T>) => Promise<boolean>): void; -} - -export abstract class EventBus { - // register the following: - // - eventsToHandle - a list of events you will publish/subscribe to - // - serviceName - used when subscribing to generate a unique queue for holding - // incoming messages of the form: `consumer__${eventType}__${serviceName}` - constructor(readonly eventsToHandle: EventType[], readonly serviceName: string) {} - destroy(): Promise<void> { - return Promise.resolve(); - } -} - -// This isn't generic enough -export interface EventConfig { - url: string; -} +export * from './event-bus'; +export * from './types'; -- GitLab