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 handler

Summary

type: Function

Parameters

handlersMap
: Record<eventName:string,handler:(UncommittedEvent) => Operation|Operation[]>

an object with keys are event types and values are projection functions

returns

Usages

// utility function to map an event type to a event handler
const 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 },
},
},
};
},
});