Creates a new instance of Register
The ID of the current request
The response headers object. It can be changed by the user.
The provider-dependent function used to flush the events to the event store.
OptionalcurrentUser: UserEnvelopeThe current user envelope, if available
Optionalcontext: ContextEnvelopeThe current context envelope, if available
Register a list of events to be added to the event-store on handler completion
The events to register
The current Register instance, so the calls to events and/or flush can be chained.
Flushes the accumulated events and commands to the event store using the provider-depdent flusher function. This method can be called from a command or event handler to force the persistion of the events to the event store. After the events have been flushed, the eventList is cleared, so the same register instance can be used to register more events.
A Promise that resolves when the flush operation is complete
ReadonlyeventReadonlyrequestUnique request identifier. This identifier is propagated automatically by Magek to all the events generated during a request, as well as all subsequent events generated by event handlers. This identifier can be used as a correlation identifier to build the event tree coming from a single request.
ReadonlyresponseIn the context of a command handler, the responseHeaders object contains the headers
that will be returned to the client in the response. You can use this object to set
custom headers or alter the default ones.
Optional ReadonlycurrentObject that references the current user. This property is initialized by Magek in a command,
and in the same way as the requestID property, it is propagated to all the events generated
afterwards.
Optional ReadonlycontextIn the context of a command handler, the context object contains the context of the request.
Object injected by Magek in all command or event handlers to interact with the execution context. By default, the events registered won't be stored until the handler has finished, but you can force the storage by calling the
register.flush()method.Example: