UNPKG

@commodo/fields-storage-dynamodb

Version:

We're working hard to get all the docs in order. New articles will be added daily.

79 lines (63 loc) 1.99 kB
"use strict"; var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault"); Object.defineProperty(exports, "__esModule", { value: true }); exports.default = void 0; var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties")); class BatchProcess { constructor(batch, documentClient) { this.documentClient = documentClient; this.batchProcess = batch; this.queryBuildResolveFunction = null; this.queryBuilding = new Promise(resolve => { this.queryBuildResolveFunction = resolve; }); this.queryExecutionResolveFunction = null; this.queryExecution = new Promise(resolve => { this.queryExecutionResolveFunction = resolve; }); this.operations = []; this.results = []; } addOperation(type, operation) { this.operations.push([type, operation]); return this.operations.length - 1; } allOperationsAdded() { return this.operations.length === this.batchProcess.operations.length; } markAsReady() { this.queryBuildResolveFunction(); } async execute() { const batchWriteParams = { RequestItems: {} }; for (let i = 0; i < this.operations.length; i++) { let [type, _ref] = this.operations[i]; let { TableName } = _ref, rest = (0, _objectWithoutProperties2.default)(_ref, ["TableName"]); if (!batchWriteParams.RequestItems[TableName]) { batchWriteParams.RequestItems[TableName] = []; } batchWriteParams.RequestItems[TableName].push({ [type]: rest }); } this.results = await this.documentClient.batchWrite(batchWriteParams).promise(); this.queryExecutionResolveFunction(); return []; } waitForOperationsAdded() { return this.queryBuilding; } waitForQueryExecution() { return this.queryExecution; } } var _default = BatchProcess; exports.default = _default; //# sourceMappingURL=BatchProcess.js.map