import { v4 as uuid } from 'uuid' ; import validate from 'uuid-validate' ; import { InvalidArgumentError } from './InvalidArgumentError' ; export class Uuid { readonly value : string ; constructor ( value ) { this . ensureIsValidUuid ( value ) ; this . value = value ; } static random ( ) { return new Uuid ( uuid ( ) ) ; } private ensureIsValidUuid ( id ) { if ( ! validate ( id ) ) { throw new InvalidArgumentError ( `<${ this . constructor . name }> does not allow the value <${ id }>` ) ; } } toString ( ) { return this . value ; } }