@studyportals/sp-r2d2
Version:
A framework that contains various components used when developing projects that will be deployed via AWS λ.
51 lines • 2.76 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.LambdaHandler = void 0;
const ping_event_handler_decorator_class_1 = require("../core/event-handling/ping-event-handler-decorator.class");
const application_event_handler_class_1 = require("../core/event-handling/application-event-handler.class");
const warm_up_event_handler_decorator_class_1 = require("../core/event-handling/warm-up-event-handler-decorator.class");
class LambdaHandler {
constructor(responseSenderFactory, bootstrapperFactory, eventTranslatorFactory, requestHandlerFactory) {
this.responseSenderFactory = responseSenderFactory;
this.bootstrapperFactory = bootstrapperFactory;
this.eventTranslatorFactory = eventTranslatorFactory;
this.requestHandlerFactory = requestHandlerFactory;
}
run(event, lambdaContext) {
return __awaiter(this, void 0, void 0, function* () {
const eventHandler = this.createEventHandler();
const responseSender = this.responseSenderFactory.create();
const bootstrapper = this.bootstrapperFactory.create(responseSender);
yield bootstrapper.bootstrap();
try {
return yield eventHandler.handle(event, responseSender);
}
catch (e) {
return yield responseSender.sendUncaughtError(e);
}
finally {
yield bootstrapper.cleanup();
}
});
}
toFunction() {
return (event, lambdaContext) => this.run(event, lambdaContext);
}
createApplicationEventHandler() {
return new application_event_handler_class_1.ApplicationEventHandler(this.eventTranslatorFactory, this.requestHandlerFactory);
}
createEventHandler() {
return new warm_up_event_handler_decorator_class_1.WarmUpEventHandlerDecorator(new ping_event_handler_decorator_class_1.PingEventHandlerDecorator(this.createApplicationEventHandler()));
}
}
exports.LambdaHandler = LambdaHandler;
//# sourceMappingURL=lambda-handler.class.js.map