Adds EventId type for robust event ID handling

Introduces type-safe EventId with centralized normalization logic for clone and standard event IDs

Refactors event ID management across multiple components to use consistent ID transformation methods
Improves type safety and reduces potential ID-related bugs in drag-and-drop and event rendering
This commit is contained in:
Janus C. H. Knudsen 2025-12-03 14:43:25 +01:00
parent d53af317bb
commit 73e284660f
5 changed files with 82 additions and 29 deletions

31
src/types/EventId.ts Normal file
View file

@ -0,0 +1,31 @@
/**
* Branded type for Event IDs
* Ensures type-safety and centralizes ID normalization logic
*/
export type EventId = string & { readonly __brand: 'EventId' };
/**
* EventId utility functions
*/
export const EventId = {
/**
* Create EventId from string, normalizing clone- prefix
*/
from(id: string): EventId {
return id.replace('clone-', '') as EventId;
},
/**
* Check if raw ID is a clone
*/
isClone(id: string): boolean {
return id.startsWith('clone-');
},
/**
* Create clone ID string from EventId
*/
toCloneId(id: EventId): string {
return `clone-${id}`;
}
};