(state: SessionState)
| 153 | } |
| 154 | |
| 155 | function allocateNextMessageRef(state: SessionState): string { |
| 156 | let candidate = Number.isInteger(state.messageIds.nextRef) |
| 157 | ? Math.max(MESSAGE_REF_MIN_INDEX, state.messageIds.nextRef) |
| 158 | : MESSAGE_REF_MIN_INDEX |
| 159 | |
| 160 | while (candidate <= MESSAGE_REF_MAX_INDEX) { |
| 161 | const ref = formatMessageRef(candidate) |
| 162 | if (!state.messageIds.byRef.has(ref)) { |
| 163 | state.messageIds.nextRef = candidate + 1 |
| 164 | return ref |
| 165 | } |
| 166 | candidate++ |
| 167 | } |
| 168 | |
| 169 | throw new Error( |
| 170 | `Message ID alias capacity exceeded. Cannot allocate more than ${formatMessageRef(MESSAGE_REF_MAX_INDEX)} aliases in this session.`, |
| 171 | ) |
| 172 | } |
no test coverage detected