UNPKG

express-lambda

Version:

Make AWS lambda behave like an express app

108 lines (88 loc) 3.94 kB
"use strict"; var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var async = require("async"); var ApiGatewayResource = require("./api_gateway_resource"); var Node = require("./node"); var _ = require("underscore")._; var Resource = function (_Node) { _inherits(Resource, _Node); function Resource() { _classCallCheck(this, Resource); return _possibleConstructorReturn(this, Object.getPrototypeOf(Resource).apply(this, arguments)); } _createClass(Resource, [{ key: "make", value: function make(parent, fullpath, path) { return new Resource(parent, fullpath, path); } }, { key: "build", value: function build(apiGw, done) { var _this2 = this; this._apiGw = apiGw; var tasks = _.values(this.children).map(function (c) { return function (done) { c.build(apiGw, done); }; }); tasks.unshift(function (done) { _this2.apiGwResource = new ApiGatewayResource(apiGw, _this2.parent.resourceId(), _this2.methods, _this2.path, _this2.fullpath); _this2.apiGwResource.build(done); }); async.series(tasks, done); } }, { key: "resourceId", value: function resourceId() { return this.apiGwResource.resourceId; } }, { key: "print", value: function print(table) { if (this.methods.length) { table.push([this.methods.join(", ") || "-", this._apiGw.url() + this.fullpath, this.lambda && this.lambda.name || "-"]); } for (var k in this.children) { this.children[k].print(table); } } }, { key: "buildLambda", value: function buildLambda(done) { var _this3 = this; var tasks = _.values(this.children).map(function (c) { return function (done) { c.buildLambda(done); }; }); tasks.unshift(function (done) { _this3.lambda && _this3.lambda.build().deploy(); done(); }); async.series(tasks, done); } }, { key: "integrateToLambda", value: function integrateToLambda(done) { var _this4 = this; var tasks = _.values(this.children).map(function (c) { return function (done) { c.integrateToLambda(done); }; }); tasks.unshift(function (done) { if (_this4.lambda) { _this4.apiGwResource.integrateToLambda(_this4.lambda, done); } else { done(); } }); async.series(tasks, done); } }]); return Resource; }(Node); module.exports = Resource;