(tableId: string, afterEventId: number)
| 206 | } |
| 207 | |
| 208 | function readMemory(tableId: string, afterEventId: number): TableEventsReadResult { |
| 209 | pruneExpiredMemoryStreams() |
| 210 | const stream = memoryTableStreams.get(tableId) |
| 211 | if (!stream) { |
| 212 | // Mirror the Redis path: a non-zero afterEventId with no buffer at all |
| 213 | // means TTL expired or the stream never existed; either way the caller's |
| 214 | // cursor is stale. |
| 215 | if (afterEventId > 0) return { status: 'pruned', earliestEventId: undefined } |
| 216 | return { status: 'ok', events: [] } |
| 217 | } |
| 218 | if (stream.earliestEventId !== undefined && afterEventId + 1 < stream.earliestEventId) { |
| 219 | return { status: 'pruned', earliestEventId: stream.earliestEventId } |
| 220 | } |
| 221 | return { |
| 222 | status: 'ok', |
| 223 | events: stream.events |
| 224 | .filter((entry) => entry.eventId > afterEventId) |
| 225 | .slice(0, TABLE_EVENT_READ_CHUNK), |
| 226 | } |
| 227 | } |
| 228 | |
| 229 | /** |
| 230 | * Append an event to the table's buffer. Fire-and-forget from the caller — |
no test coverage detected