@mbc-cqrs-serverless/core
Version:
CQRS and event base core
56 lines • 2.4 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.DefaultEventFactory = void 0;
const data_sync_new_event_1 = require("../command-events/data-sync.new.event");
const data_sync_sfn_event_1 = require("../command-events/data-sync.sfn.event");
const command_sync_mode_enum_1 = require("../commands/enums/command-sync-mode.enum");
const constants_1 = require("../constants");
const notification_event_1 = require("../notifications/event/notification.event");
class DefaultEventFactory {
async transformSqs(event) {
const events = event.Records.map((record) => {
if (record.eventSourceARN.endsWith(constants_1.DEFAULT_NOTIFICATION_QUEUE)) {
return new notification_event_1.NotificationEvent().fromSqsRecord(record);
}
return undefined;
}).filter((event) => !!event);
return events;
}
async transformSns(event) {
return event.Records.map((record) => ({
...record,
source: record.EventSource,
}));
}
async transformDynamodbStream(event) {
const events = event.Records.map((record) => {
if (record.eventSourceARN.endsWith(constants_1.COMMAND_TABLE_SUFFIX) ||
record.eventSourceARN.includes(constants_1.COMMAND_TABLE_SUFFIX + '/stream/')) {
if (record.eventName === 'INSERT') {
// Local development does not support complex filter patterns
if (record.dynamodb?.NewImage?.syncMode?.S === command_sync_mode_enum_1.CommandSyncMode.SYNC) {
return undefined;
}
return new data_sync_new_event_1.DataSyncNewCommandEvent().fromDynamoDBRecord(record);
}
}
return undefined;
}).filter((event) => !!event);
return events;
}
async transformEventBridge(event) {
return [event];
}
async transformStepFunction(event) {
const commandStepFunction = new data_sync_sfn_event_1.DataSyncCommandSfnEvent(event);
return [commandStepFunction];
}
async transformS3(event) {
return event.Records.map((record) => ({
...record,
source: record.eventSource,
}));
}
}
exports.DefaultEventFactory = DefaultEventFactory;
//# sourceMappingURL=default-event-factory.js.map