Skip to main content

Projection

TypeScript Support

A read model projection has an associated TypeScript type:

  • Type Name - ReadModel
  • Package - @resolve-js/core

A read model projection is an object of the following structure:

const projection = {
// The *Init* function initializes the read model's persistent store.
Init: async (store) => { ... }
// An event handler function is associated with an event type.
// It receives the read model store and an incoming event
// and updates the store based on the event's data.
[EVENT_TYPE1]: async (store, event, context) -> { ... }
[EVENT_TYPE2]: async (store, event, context) -> { ... }
}

An event handler implementation receives the following arguments:

Argument NameDescription
storeExposes API used to communicate with the read model's persistent data storage.
eventAn object that contains the incoming event's data.
contextAn object that contains data and functions related to the current operation.

contextā€‹

The context argument is an object with the following fields:

Field NameDescription
encryptThe user-defined encrypt function.
decryptThe user-defined decrypt function.

This object can also contain additional fields added by middleware.