relay-id.ts raw
1 import { v4 as uuidv4 } from 'uuid';
2 import { EntityId } from './entity-id';
3
4 /**
5 * Strongly-typed identifier for Relay entities.
6 * Prevents accidental mixing with other ID types.
7 */
8 export class RelayId extends EntityId<'RelayId'> {
9 private readonly _brand = 'RelayId' as const;
10
11 private constructor(value: string) {
12 super(value);
13 }
14
15 /**
16 * Generate a new unique RelayId.
17 */
18 static generate(): RelayId {
19 return new RelayId(uuidv4());
20 }
21
22 /**
23 * Create a RelayId from an existing string value.
24 * Use this when reconstituting from storage.
25 */
26 static from(value: string): RelayId {
27 return new RelayId(value);
28 }
29
30 /**
31 * Type guard to check if two IDs are equal.
32 */
33 override equals(other: RelayId): boolean {
34 return other instanceof RelayId && this._value === other._value;
35 }
36 }
37