( notification: WebhookNotification, catchUpEvents?: Array<ChangeEvent> )
| 250 | } |
| 251 | |
| 252 | function constructWakeEvent( |
| 253 | notification: WebhookNotification, |
| 254 | catchUpEvents?: Array<ChangeEvent> |
| 255 | ): WakeEvent { |
| 256 | const fallbackSource = notification.entity?.url ?? notification.streamPath |
| 257 | if (notification.wakeEvent) { |
| 258 | return notification.wakeEvent |
| 259 | } |
| 260 | if (catchUpEvents) { |
| 261 | const cancelledInboxKeys = new Set<string>() |
| 262 | for (let i = catchUpEvents.length - 1; i >= 0; i--) { |
| 263 | const event = catchUpEvents[i]! |
| 264 | if (isInboxCancellationEvent(event)) { |
| 265 | cancelledInboxKeys.add(inboxEventKey(event)) |
| 266 | continue |
| 267 | } |
| 268 | if (isInboxEvent(event) && cancelledInboxKeys.has(inboxEventKey(event))) { |
| 269 | continue |
| 270 | } |
| 271 | const wakeEvent = changeEventToWakeEvent(event, fallbackSource) |
| 272 | if (wakeEvent) { |
| 273 | return wakeEvent |
| 274 | } |
| 275 | } |
| 276 | } |
| 277 | return { |
| 278 | source: fallbackSource, |
| 279 | type: notification.triggerEvent ?? `message`, |
| 280 | fromOffset: 0, |
| 281 | toOffset: 0, |
| 282 | eventCount: 0, |
| 283 | payload: undefined, |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | function changeEventToWakeEvent( |
| 288 | event: ChangeEvent, |
no test coverage detected