|
|
|
@ -2,22 +2,19 @@ import { v4 as uuid } from 'uuid';
|
|
|
|
|
|
|
|
|
|
export interface MessageParams {
|
|
|
|
|
timestamp: number;
|
|
|
|
|
identifier?: string;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
export abstract class Message {
|
|
|
|
|
public readonly timestamp: number;
|
|
|
|
|
public identifier: string;
|
|
|
|
|
public readonly identifier: string;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
constructor({ timestamp }: MessageParams) {
|
|
|
|
|
constructor({ timestamp, identifier }: MessageParams) {
|
|
|
|
|
this.timestamp = timestamp;
|
|
|
|
|
this.identifier = uuid();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public setIdentifier(identifier: string) {
|
|
|
|
|
if (identifier.length === 0) {
|
|
|
|
|
if (identifier && identifier.length === 0) {
|
|
|
|
|
throw new Error('Cannot set empty identifier');
|
|
|
|
|
}
|
|
|
|
|
this.identifier = identifier;
|
|
|
|
|
this.identifier = identifier || uuid();
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|