Skip to main content

ReactionResolver

@rotorsoft/act-root


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

Type Alias: ReactionResolver<TEvents, TKey>

ReactionResolver<TEvents, TKey> = { source?: string; target: string; } | (event) => { source?: string; target: string; } | undefined

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

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.

Type Parameters

TEvents

TEvents extends Schemas

Event schemas

TKey

TKey extends keyof TEvents

Event name

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
}))

See

Reaction for complete reaction configuration