@bitblit/epsilon
Version:
Tiny adapter to simplify building API gateway Lambda APIS
55 lines • 2.94 kB
JavaScript
;
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.BackgroundDynamoLogTableHandler = void 0;
const background_execution_event_type_1 = require("./background-execution-event-type");
const context_util_1 = require("../util/context-util");
/*
Table should be
- Hash key : guid
- Range key: timestamp
*/
class BackgroundDynamoLogTableHandler {
constructor(dynamo, tableName, env, backgroundQueueName) {
this.dynamo = dynamo;
this.tableName = tableName;
this.env = env;
this.backgroundQueueName = backgroundQueueName;
}
onEvent(event) {
var _a, _b;
return __awaiter(this, void 0, void 0, function* () {
const entry = {
env: this.env,
backgroundQueueName: this.backgroundQueueName,
requestId: context_util_1.ContextUtil.currentRequestId(),
guid: event.guid,
processTypeName: event.processorType,
state: event.type.toString(),
timestampEpochMs: new Date().getTime(),
};
if (event.type == background_execution_event_type_1.BackgroundExecutionEventType.DataValidationError) {
const errors = ((_a = event === null || event === void 0 ? void 0 : event.errors) === null || _a === void 0 ? void 0 : _a.length) ? event.errors : ['No-Error']; // DDB does not allow empty sets
entry.errors = errors;
}
else if (event.type == background_execution_event_type_1.BackgroundExecutionEventType.ProcessStarting) {
entry.params = event.data;
}
else if (event.type == background_execution_event_type_1.BackgroundExecutionEventType.ExecutionFailedError) {
const errors = ((_b = event === null || event === void 0 ? void 0 : event.errors) === null || _b === void 0 ? void 0 : _b.length) ? event.errors : ['No-Error']; // DDB does not allow empty sets
entry.errors = errors;
}
yield this.dynamo.simplePut(this.tableName, entry);
});
}
}
exports.BackgroundDynamoLogTableHandler = BackgroundDynamoLogTableHandler;
//# sourceMappingURL=background-dynamo-log-table-handler.js.map