Skip to main content

ReactionResolver

@rotorsoft/act-root


@rotorsoft/act-root / act/src / ReactionResolver

Type Alias: ReactionResolver<TEvents, TKey, TLane>

ReactionResolver<TEvents, TKey, TLane> = Resolved<TLane> | ((event) => Resolved<TLane> | undefined)

Defined in: libs/act/src/types/reaction.ts:115

Resolver for determining which stream a reaction should target.

Resolvers enable dynamic reaction routing based on event content. They can be:

  • Static: Always route to the same target stream
  • Dynamic: Determine target based on event data at runtime

Resolvers can also specify source streams for optimization, allowing the drain process to efficiently fetch only relevant events. An optional priority biases the lagging-frontier claim() ordering โ€” see Resolved.priority.

Type Parametersโ€‹

TEventsโ€‹

TEvents extends Schemas

Event schemas

TKeyโ€‹

TKey extends keyof TEvents

Event name

TLaneโ€‹

TLane extends string = string

Paramโ€‹

The committed event (for dynamic resolvers)

Returnsโ€‹

Target stream configuration or undefined to skip

Examplesโ€‹

.on("UserCreated")
.do(sendWelcomeEmail)
.to("email-queue") // Static target
.on("UserLoggedIn")
.do(incrementLoginCount)
.to((event) => ({
target: `stats-${event.stream}` // Dynamic per user
}))
.on("UserUpdated")
.do(updateReadModel)
.to(({ stream }) => ({
source: stream, // Only fetch from this user's stream
target: `cache-${stream}` // Update corresponding cache
}))
.on("OrderConfirmed")
.do(sendCriticalNotification)
.to({ target: "notifications-out", priority: 10 })

Seeโ€‹

  • Reaction for complete reaction configuration
  • Resolved for the resolved-target shape