(
input: ChatInput,
)
| 22 | * that is what this folds. An unrecognised role is the caller being wrong |
| 23 | * about something this function cannot guess, and is refused rather than |
| 24 | * silently relabelled. |
| 25 | * |
| 26 | * ponytail: one guard on the single write path, rather than validation in |
| 27 | * each of saveMessage's callers. |
| 28 | */ |
| 29 | export function normaliseRole(role: string): MessageRole { |
| 30 | const found = Object.values(MessageRole).find( |
| 31 | (r) => r.toLowerCase() === String(role).toLowerCase(), |
| 32 | ); |
| 33 | if (!found) { |
| 34 | throw new NotFoundException( |
| 35 | `Unknown message role "${role}" — expected one of ${Object.values( |
| 36 | MessageRole, |
| 37 | ).join(', ')}`, |
no test coverage detected