Causation
Why an event was recorded. Every event carries two ids:
correlationIdis shared by everything that follows from one original request, across aggregates and view models.causationIdnames what directly caused the command that recorded it: the request, or the event a view model or saga was reacting to.
They travel in the fiber’s context rather than in payloads. A command run outside any causation starts a new correlation with a fresh id. Inside a view model handler the event being handled is the cause, so a chain of reactions can be drawn as a tree without passing ids around by hand.
Interfaces
Section titled “Interfaces”Causation
Section titled “Causation”Defined in: src/Causation.ts:19
Properties
Section titled “Properties”causationId
Section titled “causationId”
readonlycausationId:string
Defined in: src/Causation.ts:21
correlationId
Section titled “correlationId”
readonlycorrelationId:string
Defined in: src/Causation.ts:20
Variables
Section titled “Variables”CurrentCausation
Section titled “CurrentCausation”
constCurrentCausation:Reference<Causation|undefined>
Defined in: src/Causation.ts:25
The causation of commands run in this fiber, undefined outside any.
withCausation
Section titled “withCausation”
constwithCausation: {(causation): <A,E,R>(effect) =>Effect<A,E,R>; <A,E,R>(effect,causation):Effect<A,E,R>; }
Defined in: src/Causation.ts:30
Runs an effect with this causation, for instance the id of an incoming HTTP request.
Call Signature
Section titled “Call Signature”(
causation): <A,E,R>(effect) =>Effect<A,E,R>
Parameters
Section titled “Parameters”causation
Section titled “causation”Returns
Section titled “Returns”<A, E, R>(effect) => Effect<A, E, R>
Call Signature
Section titled “Call Signature”<
A,E,R>(effect,causation):Effect<A,E,R>
Type Parameters
Section titled “Type Parameters”A
E
R
Parameters
Section titled “Parameters”effect
Section titled “effect”Effect<A, E, R>
causation
Section titled “causation”Returns
Section titled “Returns”Effect<A, E, R>
Functions
Section titled “Functions”causedBy()
Section titled “causedBy()”causedBy(
event): <A,E,R>(effect) =>Effect<A,E,R>
Defined in: src/Causation.ts:49
Runs an effect in reaction to a stored event, so commands it runs record that event as their cause. View models do this for their handlers already.
Parameters
Section titled “Parameters”aggregateId
Section titled “aggregateId”string = Schema.String
aggregateName
Section titled “aggregateName”string = Schema.String
causationId
Section titled “causationId”string | null = ...
What directly caused the command that recorded the event: a request, a command or another event.
correlationId
Section titled “correlationId”string | null = ...
Shared by everything that follows from one original request.
metadata
Section titled “metadata”{[key: string]: Json; } = Schema.JsonObject
What the command carried beside its payload, see Metadata. Events from before metadata existed have {}.
payload
Section titled “payload”Json = Schema.Json
position
Section titled “position”number = Schema.Int
schemaVersion
Section titled “schemaVersion”number = Schema.Int
The version of the event’s schema the payload was written with. Events from before versions existed are 1.
timestamp
Section titled “timestamp”Utc = Schema.DateTimeUtcFromMillis
string = Schema.String
version
Section titled “version”number = Schema.Int
Returns
Section titled “Returns”<A, E, R>(effect) => Effect<A, E, R>
fromEvent()
Section titled “fromEvent()”fromEvent(
event):Causation
Defined in: src/Causation.ts:40
The causation of commands run in reaction to a stored event.
Parameters
Section titled “Parameters”aggregateId
Section titled “aggregateId”string = Schema.String
aggregateName
Section titled “aggregateName”string = Schema.String
causationId
Section titled “causationId”string | null = ...
What directly caused the command that recorded the event: a request, a command or another event.
correlationId
Section titled “correlationId”string | null = ...
Shared by everything that follows from one original request.
metadata
Section titled “metadata”{[key: string]: Json; } = Schema.JsonObject
What the command carried beside its payload, see Metadata. Events from before metadata existed have {}.
payload
Section titled “payload”Json = Schema.Json
position
Section titled “position”number = Schema.Int
schemaVersion
Section titled “schemaVersion”number = Schema.Int
The version of the event’s schema the payload was written with. Events from before versions existed are 1.
timestamp
Section titled “timestamp”Utc = Schema.DateTimeUtcFromMillis
string = Schema.String
version
Section titled “version”number = Schema.Int