35 lines
921 B
TypeScript
35 lines
921 B
TypeScript
import EventEmitter from 'events';
|
|
|
|
namespace ImplementableApi {
|
|
export type Config = {
|
|
name: string;
|
|
};
|
|
|
|
/**
|
|
* [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
|
|
*/
|
|
export type Message<T extends TBaseMessageType> = {
|
|
idListener?: number;
|
|
type: T | 'logging';
|
|
rawContent: any;
|
|
};
|
|
export type TBaseMessageType = string;
|
|
}
|
|
|
|
abstract class ImplementableApi<
|
|
T extends ImplementableApi.TBaseMessageType
|
|
> extends EventEmitter {
|
|
readonly name: string;
|
|
|
|
constructor(readonly config: ImplementableApi.Config) {
|
|
super();
|
|
this.name = config.name;
|
|
}
|
|
|
|
public abstract receivedMessage(message: ImplementableApi.Message<T>): void;
|
|
}
|
|
|
|
export { ImplementableApi };
|