UNPKG

@fabric-es/fabric-cqrs

Version:

Hyperledger Fabric middleware for event sourcing and cqrs pattern

22 lines 860 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.commitsToGroupByEntityId = void 0; const commitsToGroupByEntityId = (commits, reducer) => { const groupedByEntityId = commits.reduce((commit, { entityId, events }) => { commit[entityId] = commit[entityId] || []; events.forEach((item) => commit[entityId].push(item)); return commit; }, {}); const currentStates = []; const errors = []; Object.entries(groupedByEntityId).forEach(([entityId, events]) => { const currentState = reducer(events); if (currentState) currentStates.push(currentState); else errors.push(entityId); }); return { currentStates, errors }; }; exports.commitsToGroupByEntityId = commitsToGroupByEntityId; //# sourceMappingURL=commitsToGroupByEntityId.js.map