uuid.ts (402B)
1 import { DomainError } from "#core/domain/error.ts"; 2 import { validate } from "$std/uuid/v4.ts"; 3 4 export class UUID { 5 constructor(readonly value: string) { 6 if (!validate(value)) { 7 throw new InvalidUUID(value); 8 } 9 } 10 11 toString() { 12 return this.value; 13 } 14 } 15 16 export class InvalidUUID extends DomainError { 17 constructor(readonly candidate: string) { 18 super("Invalid UUID"); 19 } 20 }