UNPKG

@studyportals/sp-r2d2

Version:

A framework that contains various components used when developing projects that will be deployed via AWS λ.

66 lines 2.28 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.DynamoDBTransactionWrite = void 0; class DynamoDBTransactionWrite { constructor(dynamoDBAdapter) { this.dynamoDBAdapter = dynamoDBAdapter; this.putItems = []; this.updateItems = []; this.deleteItems = []; } getItems() { return [...this.getPutTransactionItems(), ...this.getUpdateTransactionItems(), ...this.getDeleteTransactionItems()]; } getRegisteredPutItems() { return this.putItems; } getPutTransactionItems() { return this.putItems.map((_) => this.convertToPutTransactionItem(_)); } getRegisteredUpdateItems() { return this.updateItems; } getUpdateTransactionItems() { return this.updateItems.map((_) => this.convertToUpdateTransactionItem(_)); } getDeleteTransactionItems() { return this.deleteItems.map((_) => this.convertToDeleteTransactionItem(_)); } put(input) { this.putItems.push(input); } update(input) { const updateItem = this.convertToUpdateItem(input); this.updateItems.push(updateItem); } delete(input) { this.deleteItems.push(input); } commit() { return this.dynamoDBAdapter.commitWriteTransaction(this); } convertToUpdateItem(input) { if (undefined === input.UpdateExpression) { throw new Error('The update expression has not been specified'); } return { TableName: input.TableName, Key: input.Key, UpdateExpression: input.UpdateExpression, ConditionExpression: input.ConditionExpression, ExpressionAttributeNames: input.ExpressionAttributeNames, ExpressionAttributeValues: input.ExpressionAttributeValues, }; } convertToPutTransactionItem(input) { return { Put: input }; } convertToUpdateTransactionItem(input) { return { Update: input }; } convertToDeleteTransactionItem(input) { return { Delete: input }; } } exports.DynamoDBTransactionWrite = DynamoDBTransactionWrite; //# sourceMappingURL=dynamodb-transaction-write.class.js.map