You cannot select more than 25 topics
			Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
		
		
		
		
		
			
		
			
				
	
	
		
			23 lines
		
	
	
		
			558 B
		
	
	
	
		
			TypeScript
		
	
			
		
		
	
	
			23 lines
		
	
	
		
			558 B
		
	
	
	
		
			TypeScript
		
	
import { v4 as uuid } from 'uuid';
 | 
						|
 | 
						|
export interface MessageParams {
 | 
						|
  timestamp: number;
 | 
						|
  identifier?: string;
 | 
						|
}
 | 
						|
 | 
						|
export abstract class Message {
 | 
						|
  public readonly timestamp: number;
 | 
						|
  public readonly identifier: string;
 | 
						|
 | 
						|
  constructor({ timestamp, identifier }: MessageParams) {
 | 
						|
    this.timestamp = timestamp;
 | 
						|
    if (identifier && identifier.length === 0) {
 | 
						|
      throw new Error('Cannot set empty identifier');
 | 
						|
    }
 | 
						|
    if (!timestamp) {
 | 
						|
      throw new Error('Cannot set undefined timestamp');
 | 
						|
    }
 | 
						|
    this.identifier = identifier || uuid();
 | 
						|
  }
 | 
						|
}
 |