2021-06-12 15:13:13 +02:00
|
|
|
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-06-12 15:13:13 +02:00
|
|
|
};
|
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
|
2021-06-12 15:13:13 +02:00
|
|
|
* rawContent field is the string content of the message
|
2021-05-23 16:07:23 +02:00
|
|
|
*/
|
2021-06-25 16:19:43 +02:00
|
|
|
export type Message<T extends TBaseMessageType> = {
|
2021-05-23 16:07:23 +02:00
|
|
|
idListener?: number;
|
2021-06-25 16:19:43 +02:00
|
|
|
type: T | 'logging';
|
2021-05-23 16:07:23 +02:00
|
|
|
rawContent: any;
|
2021-06-12 15:13:13 +02:00
|
|
|
};
|
2021-06-25 16:19:43 +02:00
|
|
|
export type TBaseMessageType = string;
|
2021-05-23 16:07:23 +02:00
|
|
|
}
|
|
|
|
|
2021-06-25 16:19:43 +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;
|
|
|
|
}
|
|
|
|
|
2021-06-25 16:19:43 +02:00
|
|
|
public abstract receivedMessage(message: ImplementableApi.Message<T>): void;
|
2021-05-23 16:07:23 +02:00
|
|
|
}
|
|
|
|
|
2021-06-12 15:13:13 +02:00
|
|
|
export { ImplementableApi };
|