jerni a framework to build data-driven products from the ground up
module: jerni/lib/mapEvents
utility function to map an event type to a event handlerSummary
type: Function
Parameters
handlersMap
: Record<eventName:string,handler:(UncommittedEvent) => Operation|Operation[]>
an object with keys are event types and values are projection functions
returns
(UncommittedEvent) => Operation[]
Usages
// utility function to map an event type to a event handlerconst mapEvents = require("jerni/lib/mapEvents");const transform = mapEvents({USER_REGISTERED(event) {return {insertOne: {id: event.payload.id,username: event.payload.username,createdAt: event.payload.registered_timstamp,active: true,},};}USER_SUSPENDED(event) {return {updateOne: {where: { id: event.payload.user_id },changes: {$set: { active: false },},},};},});