Magek Framework
    Preparing search index...

    Class Register

    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:

     public handle(register: Register): void {
    //...
    register.events(new CartItemChanged(cart, this.sku, this.quantity))
    if (this.hasPromotion()) {
    if (this.isEmpty()) {
    throw new Error("Added a promotion to an empty cart")
    } else {
    register.commands(new ApplyPromoToCart(this.promo, cart)
    }
    }
    // ...
    }
    Index

    Constructors

    Methods

    • 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.

      Returns Promise<void>

      A Promise that resolves when the flush operation is complete

    Properties

    requestID: UUID

    Unique 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.

    responseHeaders: Record<string, string>

    In 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.

    currentUser?: UserEnvelope

    Object 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.

    context?: ContextEnvelope

    In the context of a command handler, the context object contains the context of the request.