routing/src/implementableApi.ts

35 lines
921 B
TypeScript
Raw Normal View History

import EventEmitter from 'events';
2021-05-19 12:55:10 +02:00
2021-05-23 16:07:23 +02:00
namespace ImplementableApi {
export type Config = {
name: string;
};
2021-05-19 12:55:10 +02:00
2021-05-23 16:07:23 +02:00
/**
* [optional] idListener is the way to identificate the listener who's the src of the newEntries
* the type field permit to know which type of message it is
* rawContent field is the string content of the message
2021-05-23 16:07:23 +02:00
*/
export type Message<T extends TBaseMessageType> = {
2021-05-23 16:07:23 +02:00
idListener?: number;
type: T | 'logging';
2021-05-23 16:07:23 +02:00
rawContent: any;
};
export type TBaseMessageType = string;
2021-05-23 16:07:23 +02:00
}
abstract class ImplementableApi<
T extends ImplementableApi.TBaseMessageType
> extends EventEmitter {
2021-05-23 16:07:23 +02:00
readonly name: string;
constructor(readonly config: ImplementableApi.Config) {
super();
this.name = config.name;
}
public abstract receivedMessage(message: ImplementableApi.Message<T>): void;
2021-05-23 16:07:23 +02:00
}
export { ImplementableApi };