UNPKG

@mbc-cqrs-serverless/core

Version:
58 lines 2.2 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DataSyncCommandSfnEvent = void 0; const util_dynamodb_1 = require("@aws-sdk/util-dynamodb"); const constants_1 = require("../constants"); const helpers_1 = require("../helpers"); const data_sync_new_event_1 = require("./data-sync.new.event"); class DataSyncCommandSfnEvent { constructor(event) { Object.assign(this, event); if (event?.context) { this.commandEvent = new data_sync_new_event_1.DataSyncNewCommandEvent(event.context.Execution.Input); this.source = event.context.StateMachine.Id; } } get commandTableName() { return this.commandEvent?.tableName; } get dataTableName() { return this.commandTableName.replace(constants_1.COMMAND_TABLE_SUFFIX, constants_1.DATA_TABLE_SUFFIX); } get stepStateName() { return this.context.State.Name; } get commandRecord() { if (this.commandModel) { return this.commandModel; } if (!this.commandEvent?.dynamodb?.NewImage) { return null; } const newImage = this.commandEvent?.dynamodb?.NewImage; this.commandModel = (0, util_dynamodb_1.unmarshall)(newImage); // TODO convert S3 attributes if (this.commandModel.createdAt) { this.commandModel.createdAt = new Date(this.commandModel.createdAt); } if (this.commandModel.updatedAt) { this.commandModel.updatedAt = new Date(this.commandModel.updatedAt); } return this.commandModel; } get commandKey() { return { pk: this.commandRecord.pk, sk: this.commandRecord.sk, }; } async getFullCommandRecord(s3Service) { if ((0, helpers_1.isS3AttributeKey)(this.commandRecord?.attributes)) { const { key } = (0, helpers_1.parseS3AttributeKey)(this.commandRecord?.attributes); this.commandRecord.attributes = await s3Service.getItem(key); } return this.commandRecord; } } exports.DataSyncCommandSfnEvent = DataSyncCommandSfnEvent; //# sourceMappingURL=data-sync.sfn.event.js.map