UNPKG

@incdevco/framework

Version:
58 lines (31 loc) 915 B
var Util = require('util'); var Base = require('../index'); function Lambda(config) { 'use strict'; Base.call(this, config); this.handlers = config.handlers || {}; } Util.inherits(Lambda, Base); Lambda.prototype.handler = function (event, context) { 'use strict'; var promise = this.Promise.resolve(true), self = this; this.log('original-event', JSON.stringify(event, null, 2)); if (this.handlers[event.datasetName]) { promise = this.Promise.try(function () { return self.handlers[event.datasetName](event); }); } promise .then(function() { context.succeed(event); }) .catch(function (exception) { context.fail(exception); }); }; Lambda.prototype.register = function (dataset, handler) { 'use strict'; this.handlers[dataset] = handler; return this; }; module.exports = Lambda;