MCPcopy Create free account
hub / github.com/electric-sql/electric / constructWakeEvent

Function constructWakeEvent

packages/agents-runtime/src/process-wake.ts:252–285  ·  view source on GitHub ↗
(
  notification: WebhookNotification,
  catchUpEvents?: Array<ChangeEvent>
)

Source from the content-addressed store, hash-verified

250}
251
252function 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
287function changeEventToWakeEvent(
288 event: ChangeEvent,

Callers 1

processWakeFunction · 0.85

Calls 6

isInboxCancellationEventFunction · 0.85
inboxEventKeyFunction · 0.85
isInboxEventFunction · 0.85
changeEventToWakeEventFunction · 0.85
addMethod · 0.45
hasMethod · 0.45

Tested by

no test coverage detected