"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const code_1 = require("./code");
const lambda_1 = require("./lambda");
const runtime_1 = require("./runtime");
/**
 * A lambda function with inline node.js code.
 *
 * Usage:
 *
 *    new InlineJavaScriptLambda(this, 'MyFunc', {
 *      handler: {
 *        fn: (event, context, callback) => {
 *          console.log('hello, world');
 *          callback();
 *        }
 *      }
 *    });
 *
 * This will define a node.js 6.10 function with the provided function has
 * the handler code.
 */
class InlineJavaScriptFunction extends lambda_1.Function {
    constructor(parent, name, props) {
        const code = new code_1.InlineCode(renderCode(props.handler));
        const runtime = props.runtime || runtime_1.Runtime.NodeJS610;
        const handler = 'index.handler';
        const timeout = props.timeout || 30;
        super(parent, name, {
            code,
            runtime,
            handler,
            timeout,
            description: props.description,
            memorySize: props.memorySize,
            functionName: props.functionName,
            environment: props.environment,
        });
    }
}
exports.InlineJavaScriptFunction = InlineJavaScriptFunction;
function renderCode(handler) {
    return `exports.handler = ${handler.fn.toString()}`;
}
//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5saW5lLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiaW5saW5lLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7O0FBQ0EsaUNBQW9DO0FBQ3BDLHFDQUFvQztBQUNwQyx1Q0FBZ0U7QUF1RmhFOzs7Ozs7Ozs7Ozs7Ozs7O0dBZ0JHO0FBQ0gsTUFBYSx3QkFBeUIsU0FBUSxpQkFBUTtJQUNsRCxZQUFZLE1BQWlCLEVBQUUsSUFBWSxFQUFFLEtBQWtDO1FBQzNFLE1BQU0sSUFBSSxHQUFHLElBQUksaUJBQVUsQ0FBQyxVQUFVLENBQUMsS0FBSyxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUM7UUFDdkQsTUFBTSxPQUFPLEdBQStCLEtBQUssQ0FBQyxPQUFPLElBQUksaUJBQU8sQ0FBQyxTQUFTLENBQUM7UUFDL0Us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