Skip to main content
Version: Current

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:116

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โ€‹

event

The committed event (for dynamic resolvers)

Returnsโ€‹

Target stream configuration or undefined to skip

Examplesโ€‹

Static target

.on("UserCreated")
.do(sendWelcomeEmail)
.to("email-queue") // Static target

Dynamic target per user

.on("UserLoggedIn")
.do(incrementLoginCount)
.to((event) => ({
target: `stats-${event.stream}` // Dynamic per user
}))

With source optimization

.on("UserUpdated")
.do(updateReadModel)
.to(({ stream }) => ({
source: stream, // Only fetch from this user's stream
target: `cache-${stream}` // Update corresponding cache
}))

With priority (saturated worker scheduling)

.on("OrderConfirmed")
.do(sendCriticalNotification)
.to({ target: "notifications-out", priority: 10 })

Seeโ€‹

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