UNPKG

pg-trx-outbox

Version:

Transactional outbox of Postgres for Node.js with little Event Sourcing

20 lines (19 loc) 752 B
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.GroupedAdapter = void 0; const base_ts_1 = require("./base.js"); class GroupedAdapter extends base_ts_1.BaseAdapter { async send(messages) { const respMap = new Map(); const grouped = new Map(); messages.forEach(msg => grouped.set(msg.key, (grouped.get(msg.key) ?? []).concat(msg))); await Promise.all(Array.from(grouped.values()).map(async (msgs) => { for (const msg of msgs) { const resp = await this.baseHandleMessage(msg); respMap.set(msg.id, resp); } })); return messages.map(msg => respMap.get(msg.id)); } } exports.GroupedAdapter = GroupedAdapter;