/** @internal */ export interface UniqueRegistrationOptions { /** @internal */ duplicateMessage: string; /** @internal */ validate?: (value: TValue) => void; } /** @internal */ export function registerUnique( registry: Map, key: TKey, value: TValue, options: UniqueRegistrationOptions, ): void { if (registry.has(key)) { throw new Error(options.duplicateMessage); } options.validate?.(value); registry.set(key, value); } /** @internal */ export function cloneMap(registry: ReadonlyMap): Map { return new Map(registry); } /** @internal */ export function cloneArrayValueMap( registry: ReadonlyMap, ): Map { return new Map(Array.from(registry, ([key, values]) => [key, [...values]])); }