diff --git a/deps/aws-lambda-cpp-0.2.6.tar.gz b/deps/aws-lambda-cpp-0.2.6.tar.gz index fe1fbae..ff1a706 100644 Binary files a/deps/aws-lambda-cpp-0.2.6.tar.gz and b/deps/aws-lambda-cpp-0.2.6.tar.gz differ diff --git a/deps/patches/aws-lambda-cpp-macos-fixes.patch b/deps/patches/aws-lambda-cpp-macos-fixes.patch new file mode 100644 index 0000000..2bafc27 --- /dev/null +++ b/deps/patches/aws-lambda-cpp-macos-fixes.patch @@ -0,0 +1,22 @@ +diff --git a/include/backward.h b/include/backward.h +index e065783..9e369a6 100644 +--- a/include/backward.h ++++ b/include/backward.h +@@ -43,7 +43,7 @@ + + // You can define one of the following (or leave it to the auto-detection): + // +-# define BACKWARD_SYSTEM_LINUX ++// #define BACKWARD_SYSTEM_LINUX + // - specialization for linux + // + // #define BACKWARD_SYSTEM_DARWIN +@@ -3057,7 +3057,7 @@ public: + if (st.size() == 0) { + return; + } +- _symbols.reset(backtrace_symbols(st.begin(), st.size())); ++ _symbols.reset(backtrace_symbols(st.begin(), (int)st.size())); + } + + ResolvedTrace resolve(ResolvedTrace trace) diff --git a/lib/Common/index.d.ts b/lib/Common/index.d.ts new file mode 100644 index 0000000..05c3d63 --- /dev/null +++ b/lib/Common/index.d.ts @@ -0,0 +1,62 @@ +/** + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * This module defines types, enums and interfaces common to the other modules. + */ +/// +import { IncomingHttpHeaders } from "http"; +export interface InvocationResponse { + bodyJson: string; + headers: IncomingHttpHeaders; +} +export interface NativeClient { + initializeClient: (userAgent: string) => void; + done: (id: string, bodyString: string) => void; + error: (id: string, bodyString: string, xrayString: string) => void; + next: () => Promise; +} +export declare enum INVOKE_HEADER { + ClientContext = "lambda-runtime-client-context", + CognitoIdentity = "lambda-runtime-cognito-identity", + ARN = "lambda-runtime-invoked-function-arn", + AWSRequestId = "lambda-runtime-aws-request-id", + DeadlineMs = "lambda-runtime-deadline-ms", + XRayTrace = "lambda-runtime-trace-id" +} +export interface IEnvironmentData { + functionVersion?: string; + functionName?: string; + memoryLimitInMB?: string; + logGroupName?: string; + logStreamName?: string; +} +export interface IHeaderData { + clientContext?: string; + identity?: string; + invokedFunctionArn?: string; + awsRequestId?: string; + getRemainingTimeInMillis: () => number; +} +export declare type ErrorStringOrUndefined = Error | string | undefined; +export declare type ErrorStringOrUndefinedOrNull = ErrorStringOrUndefined | null; +/** + * + */ +export interface ICallbackContext { + callbackWaitsForEmptyEventLoop: boolean; + succeed: (result: unknown) => void; + fail: (err: ErrorStringOrUndefinedOrNull) => void; + done: (err: ErrorStringOrUndefinedOrNull, result?: unknown) => void; +} +export declare type CallbackFunction = (err: ErrorStringOrUndefinedOrNull, result?: unknown) => void; +export interface IBeforeExitListener { + invoke: () => void; + reset: () => () => void; + set: (listener: () => void) => () => void; +} +export interface IErrorCallbacks { + uncaughtException: (err: Error) => void; + unhandledRejection: (err: Error) => void; +} +export declare type HandlerFunction = (body: unknown, data: IEnvironmentData & IHeaderData, callback: CallbackFunction) => PromiseLike | unknown; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib/Common/index.d.ts.map b/lib/Common/index.d.ts.map new file mode 100644 index 0000000..dbfdc20 --- /dev/null +++ b/lib/Common/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Common/index.ts"],"names":[],"mappings":"AAAA;;;;GAIG;;AAEH,OAAO,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAE3C,MAAM,WAAW,kBAAkB;IACjC,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,mBAAmB,CAAC;CAC9B;AAED,MAAM,WAAW,YAAY;IAC3B,gBAAgB,EAAE,CAAC,SAAS,EAAE,MAAM,KAAK,IAAI,CAAC;IAC9C,IAAI,EAAE,CAAC,EAAE,EAAE,MAAM,EAAE,UAAU,EAAE,MAAM,KAAK,IAAI,CAAC;IAC/C,KAAK,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AAO,KACb,IAAI,CAAC;AAEV,MAAM,WAAW,mBAAmB;IAClC,MAAM,EAAE,MAAM,IAAI,CAAC;IACnB,KAAK,EAAE,MAAM,MAAM,IAAI,CAAC;IACxB,GAAG,EAAE,CAAC,QAAQ,EAAE,MAAM,IAAI,KAAK,MAAM,IAAI,CAAC;CAC3C;AAED,MAAM,WAAW,eAAe;IAC9B,iBAAiB,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC;IACxC,kBAAkB,EAAE,CAAC,GAAG,EAAE,KAAK,KAAK,IAAI,CAAC;CAC1C;AAED,oBAAY,eAAe,GAAG,CAC5B,IAAI,EAAE,OAAO,EACb,IAAI,EAAE,gBAAgB,GAAG,WAAW,EACpC,QAAQ,EAAE,gBAAgB,KACvB,WAAW,CAAC,OAAO,CAAC,GAAG,OAAO,CAAC"} \ No newline at end of file diff --git a/lib/Common/index.js b/lib/Common/index.js new file mode 100644 index 0000000..1608bba --- /dev/null +++ b/lib/Common/index.js @@ -0,0 +1,18 @@ +"use strict"; +/** + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * This module defines types, enums and interfaces common to the other modules. + */ +Object.defineProperty(exports, "__esModule", { value: true }); +exports.INVOKE_HEADER = void 0; +var INVOKE_HEADER; +(function (INVOKE_HEADER) { + INVOKE_HEADER["ClientContext"] = "lambda-runtime-client-context"; + INVOKE_HEADER["CognitoIdentity"] = "lambda-runtime-cognito-identity"; + INVOKE_HEADER["ARN"] = "lambda-runtime-invoked-function-arn"; + INVOKE_HEADER["AWSRequestId"] = "lambda-runtime-aws-request-id"; + INVOKE_HEADER["DeadlineMs"] = "lambda-runtime-deadline-ms"; + INVOKE_HEADER["XRayTrace"] = "lambda-runtime-trace-id"; +})(INVOKE_HEADER = exports.INVOKE_HEADER || (exports.INVOKE_HEADER = {})); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvQ29tbW9uL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiI7QUFBQTs7OztHQUlHOzs7QUFnQkgsSUFBWSxhQU9YO0FBUEQsV0FBWSxhQUFhO0lBQ3ZCLGdFQUErQyxDQUFBO0lBQy9DLG9FQUFtRCxDQUFBO0lBQ25ELDREQUEyQyxDQUFBO0lBQzNDLCtEQUE4QyxDQUFBO0lBQzlDLDBEQUF5QyxDQUFBO0lBQ3pDLHNEQUFxQyxDQUFBO0FBQ3ZDLENBQUMsRUFQVyxhQUFhLEdBQWIscUJBQWEsS0FBYixxQkFBYSxRQU94QiJ9 \ No newline at end of file diff --git a/lib/Errors/XRayError.d.ts b/lib/Errors/XRayError.d.ts new file mode 100644 index 0000000..7beb12f --- /dev/null +++ b/lib/Errors/XRayError.d.ts @@ -0,0 +1,34 @@ +/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ +/** + * prepare an exception blob for sending to AWS X-Ray + * transform an Error, or Error-like, into an exception parseable by X-Ray's service. + * { + * "name": "CustomException", + * "message": "Something bad happend!", + * "stack": [ + * "exports.handler (/var/function/node_modules/event_invoke.js:3:502) + * ] + * } + * => + * { + * "working_directory": "/var/function", + * "exceptions": [ + * { + * "type": "CustomException", + * "message": "Something bad happend!", + * "stack": [ + * { + * "path": "/var/function/event_invoke.js", + * "line": 502, + * "label": "exports.throw_custom_exception" + * } + * ] + * } + * ], + * "paths": [ + * "/var/function/event_invoke.js" + * ] + * } + */ +export declare const toFormatted: (err: unknown) => string; +//# sourceMappingURL=XRayError.d.ts.map \ No newline at end of file diff --git a/lib/Errors/XRayError.d.ts.map b/lib/Errors/XRayError.d.ts.map new file mode 100644 index 0000000..4fb1046 --- /dev/null +++ b/lib/Errors/XRayError.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"XRayError.d.ts","sourceRoot":"","sources":["../../src/Errors/XRayError.ts"],"names":[],"mappings":"AAAA,8EAA8E;AAM9E;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,eAAO,MAAM,WAAW,QAAS,OAAO,KAAG,MAU1C,CAAC"} \ No newline at end of file diff --git a/lib/Errors/XRayError.js b/lib/Errors/XRayError.js new file mode 100644 index 0000000..c882f58 --- /dev/null +++ b/lib/Errors/XRayError.js @@ -0,0 +1,87 @@ +/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.toFormatted = void 0; +const _1 = require("."); +/** + * prepare an exception blob for sending to AWS X-Ray + * transform an Error, or Error-like, into an exception parseable by X-Ray's service. + * { + * "name": "CustomException", + * "message": "Something bad happend!", + * "stack": [ + * "exports.handler (/var/function/node_modules/event_invoke.js:3:502) + * ] + * } + * => + * { + * "working_directory": "/var/function", + * "exceptions": [ + * { + * "type": "CustomException", + * "message": "Something bad happend!", + * "stack": [ + * { + * "path": "/var/function/event_invoke.js", + * "line": 502, + * "label": "exports.throw_custom_exception" + * } + * ] + * } + * ], + * "paths": [ + * "/var/function/event_invoke.js" + * ] + * } + */ +exports.toFormatted = (err) => { + if (!_1.isError(err)) { + return ""; + } + try { + return JSON.stringify(new XRayFormattedCause(err)); + } + catch (error) { + return ""; + } +}; +class XRayFormattedCause { + constructor(err) { + this.working_directory = process.cwd(); // eslint-disable-line + const stack = []; + if (err.stack) { + const stackLines = err.stack.split("\n"); + stackLines.shift(); + stackLines.forEach((stackLine) => { + let line = stackLine.trim().replace(/\(|\)/g, ""); + line = line.substring(line.indexOf(" ") + 1); + const label = line.lastIndexOf(" ") >= 0 + ? line.slice(0, line.lastIndexOf(" ")) + : null; + const path = label == undefined || label == null || label.length === 0 + ? line + : line.slice(line.lastIndexOf(" ") + 1); + const pathParts = path.split(":"); + const entry = { + path: pathParts[0], + line: parseInt(pathParts[1]), + label: label || "anonymous", + }; + stack.push(entry); + }); + } + this.exceptions = [ + { + type: err.name, + message: err.message, + stack: stack, + }, + ]; + const paths = new Set(); + stack.forEach((entry) => { + paths.add(entry.path); + }); + this.paths = Array.from(paths); + } +} +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiWFJheUVycm9yLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL0Vycm9ycy9YUmF5RXJyb3IudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsOEVBQThFO0FBRTlFLFlBQVksQ0FBQzs7O0FBRWIsd0JBQTRCO0FBRTVCOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7R0E4Qkc7QUFDVSxRQUFBLFdBQVcsR0FBRyxDQUFDLEdBQVksRUFBVSxFQUFFO0lBQ2xELElBQUksQ0FBQyxVQUFPLENBQUMsR0FBRyxDQUFDLEVBQUU7UUFDakIsT0FBTyxFQUFFLENBQUM7S0FDWDtJQUVELElBQUk7UUFDRixPQUFPLElBQUksQ0FBQyxTQUFTLENBQUMsSUFBSSxrQkFBa0IsQ0FBQyxHQUFHLENBQUMsQ0FBQyxDQUFDO0tBQ3BEO0lBQUMsT0FBTyxLQUFLLEVBQUU7UUFDZCxPQUFPLEVBQUUsQ0FBQztLQUNYO0FBQ0gsQ0FBQyxDQUFDO0FBY0YsTUFBTSxrQkFBa0I7SUFLdEIsWUFBWSxHQUFVO1FBQ3BCLElBQUksQ0FBQyxpQkFBaUIsR0FBRyxPQUFPLENBQUMsR0FBRyxFQUFFLENBQUMsQ0FBQyxzQkFBc0I7UUFFOUQsTUFBTSxLQUFLLEdBQXFCLEVBQUUsQ0FBQztRQUNuQyxJQUFJLEdBQUcsQ0FBQyxLQUFLLEVBQUU7WUFDYixNQUFNLFVBQVUsR0FBRyxHQUFHLENBQUMsS0FBSyxDQUFDLEtBQUssQ0FBQyxJQUFJLENBQUMsQ0FBQztZQUN6QyxVQUFVLENBQUMsS0FBSyxFQUFFLENBQUM7WUF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FFRixLQUFLLENBQUMsSUFBSSxDQUFDLEtBQUssQ0FBQyxDQUFDO1lBQ3BCLENBQUMsQ0FBQyxDQUFDO1NBQ0o7UUFFRCxJQUFJLENBQUMsVUFBVSxHQUFHO1lBQ2hCO2dCQUNFLElBQUksRUFBRSxHQUFHLENBQUMsSUFBSTtnQkFDZCxPQUFPLEVBQUUsR0FBRyxDQUFDLE9BQU87Z0JBQ3BCLEtBQUssRUFBRSxLQUFLO2FBQ2I7U0FDRixDQUFDO1FBRUYsTUFBTSxLQUFLLEdBQUcsSUFBSSxHQUFHLEVBQVUsQ0FBQztRQUNoQyxLQUFLLENBQUMsT0FBTyxDQUFDLENBQUMsS0FBSyxFQUFFLEVBQUU7WUFDdEIsS0FBSyxDQUFDLEdBQUcsQ0FBQyxLQUFLLENBQUMsSUFBSSxDQUFDLENBQUM7UUFDeEIsQ0FBQyxDQUFDLENBQUM7UUFDSCxJQUFJLENBQUMsS0FBSyxHQUFHLEtBQUssQ0FBQyxJQUFJLENBQUMsS0FBSyxDQUFDLENBQUM7SUFDakMsQ0FBQztDQUNGIn0= \ No newline at end of file diff --git a/lib/Errors/index.d.ts b/lib/Errors/index.d.ts new file mode 100644 index 0000000..2d22369 --- /dev/null +++ b/lib/Errors/index.d.ts @@ -0,0 +1,41 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Defines custom error types throwable by the runtime. + */ +export declare function isError(obj: any): obj is Error; +interface RuntimeErrorResponse { + errorType: string; + errorMessage: string; + trace: string[]; +} +/** + * Attempt to convert an object into a response object. + * This method accounts for failures when serializing the error object. + */ +export declare function toRuntimeResponse(error: unknown): RuntimeErrorResponse; +/** + * Format an error with the expected properties. + * For compatability, the error string always starts with a tab. + */ +export declare const toFormatted: (error: unknown) => string; +export declare class ExtendedError extends Error { + code?: number; + custom?: string; + reason?: string; + promise?: Promise; + constructor(reason?: string); +} +export declare class ImportModuleError extends ExtendedError { +} +export declare class HandlerNotFound extends ExtendedError { +} +export declare class MalformedHandlerName extends ExtendedError { +} +export declare class UserCodeSyntaxError extends ExtendedError { +} +export declare class UnhandledPromiseRejection extends ExtendedError { + constructor(reason?: string, promise?: Promise); +} +export {}; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib/Errors/index.d.ts.map b/lib/Errors/index.d.ts.map new file mode 100644 index 0000000..6a3ea0f --- /dev/null +++ b/lib/Errors/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Errors/index.ts"],"names":[],"mappings":"AAEA;;;;GAIG;AAMH,wBAAgB,OAAO,CAAC,GAAG,EAAE,GAAG,GAAG,GAAG,IAAI,KAAK,CAU9C;AAED,UAAU,oBAAoB;IAC5B,SAAS,EAAE,MAAM,CAAC;IAClB,YAAY,EAAE,MAAM,CAAC;IACrB,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED;;;GAGG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,OAAO,GAAG,oBAAoB,CA0BtE;AAED;;;GAGG;AACH,eAAO,MAAM,WAAW,UAAW,OAAO,KAAG,MAQ5C,CAAC;AA2BF,qBAAa,aAAc,SAAQ,KAAK;IACtC,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,OAAO,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC;gBAEX,MAAM,CAAC,EAAE,MAAM;CAI5B;AAED,qBAAa,iBAAkB,SAAQ,aAAa;CAAG;AACvD,qBAAa,eAAgB,SAAQ,aAAa;CAAG;AACrD,qBAAa,oBAAqB,SAAQ,aAAa;CAAG;AAC1D,qBAAa,mBAAoB,SAAQ,aAAa;CAAG;AACzD,qBAAa,yBAA0B,SAAQ,aAAa;gBAC9C,MAAM,CAAC,EAAE,MAAM,EAAE,OAAO,CAAC,EAAE,OAAO,CAAC,GAAG,CAAC;CAKpD"} \ No newline at end of file diff --git a/lib/Errors/index.js b/lib/Errors/index.js new file mode 100644 index 0000000..7f2f209 --- /dev/null +++ b/lib/Errors/index.js @@ -0,0 +1,129 @@ +/* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Defines custom error types throwable by the runtime. + */ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.UnhandledPromiseRejection = exports.UserCodeSyntaxError = exports.MalformedHandlerName = exports.HandlerNotFound = exports.ImportModuleError = exports.ExtendedError = exports.toFormatted = exports.toRuntimeResponse = exports.isError = void 0; +const util_1 = __importDefault(require("util")); +function isError(obj) { + return (obj && + obj.name && + obj.message && + obj.stack && + typeof obj.name === "string" && + typeof obj.message === "string" && + typeof obj.stack === "string"); +} +exports.isError = isError; +/** + * Attempt to convert an object into a response object. + * This method accounts for failures when serializing the error object. + */ +function toRuntimeResponse(error) { + try { + if (util_1.default.types.isNativeError(error) || isError(error)) { + if (!error.stack) { + throw new Error("Error stack is missing."); + } + return { + errorType: error.name, + errorMessage: error.message, + trace: error.stack.split("\n") || [], + }; + } + else { + return { + errorType: typeof error, + errorMessage: error.toString(), + trace: [], + }; + } + } + catch (_err) { + return { + errorType: "handled", + errorMessage: "callback called with Error argument, but there was a problem while retrieving one or more of its message, name, and stack", + trace: [], + }; + } +} +exports.toRuntimeResponse = toRuntimeResponse; +/** + * Format an error with the expected properties. + * For compatability, the error string always starts with a tab. + */ +exports.toFormatted = (error) => { + try { + return ("\t" + JSON.stringify(error, (_k, v) => _withEnumerableProperties(v))); + } + catch (err) { + return "\t" + JSON.stringify(toRuntimeResponse(error)); + } +}; +/** + * Error name, message, code, and stack are all members of the superclass, which + * means they aren't enumerable and don't normally show up in JSON.stringify. + * This method ensures those interesting properties are available along with any + * user-provided enumerable properties. + */ +function _withEnumerableProperties(error) { + if (error instanceof ExtendedError) { + const ret = Object.assign({ + errorType: error.name, + errorMessage: error.message, + code: error.code, + }, error); + if (typeof error.stack == "string") { + ret.stack = error.stack.split("\n"); + } + return ret; + } + else { + return error; + } +} +class ExtendedError extends Error { + constructor(reason) { + super(reason); // 'Error' breaks prototype chain here + Object.setPrototypeOf(this, new.target.prototype); // restore prototype chain + } +} +exports.ExtendedError = ExtendedError; +class ImportModuleError extends ExtendedError { +} +exports.ImportModuleError = ImportModuleError; +class HandlerNotFound extends ExtendedError { +} +exports.HandlerNotFound = HandlerNotFound; +class MalformedHandlerName extends ExtendedError { +} +exports.MalformedHandlerName = MalformedHandlerName; +class UserCodeSyntaxError extends ExtendedError { +} +exports.UserCodeSyntaxError = UserCodeSyntaxError; +class UnhandledPromiseRejection extends ExtendedError { + constructor(reason, promise) { + super(reason); + this.reason = reason; + this.promise = promise; + } +} +exports.UnhandledPromiseRejection = UnhandledPromiseRejection; +const errorClasses = [ + ImportModuleError, + HandlerNotFound, + MalformedHandlerName, + UserCodeSyntaxError, + UnhandledPromiseRejection, +]; +errorClasses.forEach((e) => { + e.prototype.name = `Runtime.${e.name}`; +}); +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvRXJyb3JzL2luZGV4LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLHNFQUFzRTtBQUN0RSx1REFBdUQ7QUFDdkQ7Ozs7R0FJRztBQUVILFlBQVksQ0FBQzs7Ozs7O0FBRWIsZ0RBQXdCO0FBRXhCLFNBQWdCLE9BQU8sQ0FBQyxHQUFRO0lBQzlCLE9BQU8sQ0FDTCxHQUFHO1FBQ0gsR0FBRyxDQUFDLElBQUk7UUFDUixHQUFHLENBQUMsT0FBTztRQUNYLEdBQUcsQ0FBQyxLQUF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QUFzQztRQUNyRCxNQUFNLENBQUMsY0FBYyxDQUFDLElBQUksRUFBRSxHQUFHLENBQUMsTUFBTSxDQUFDLFNBQVMsQ0FBQyxDQUFDLENBQUMsMEJBQTBCO0lBQy9FLENBQUM7Q0FDRjtBQVZELHNDQVVDO0FBRUQsTUFBYSxpQkFBa0IsU0FBUSxhQUFhO0NBQUc7QUFBdkQsOENBQXVEO0FBQ3ZELE1BQWEsZUFBZ0IsU0FBUSxhQUFhO0NBQUc7QUFBckQsMENBQXFEO0FBQ3JELE1BQWEsb0JBQXFCLFNBQVEsYUFBYTtDQUFHO0FBQTFELG9EQUEwRDtBQUMxRCxNQUFhLG1CQUFvQixTQUFRLGFBQWE7Q0FBRztBQUF6RCxrREFBeUQ7QUFDekQsTUFBYSx5QkFBMEIsU0FBUSxhQUFhO0lBQzFELFlBQVksTUFBZSxFQUFFLE9BQXNCO1FBQ2pELEtBQUssQ0FBQyxNQUFNLENBQUMsQ0FBQztRQUNkLElBQUksQ0FBQyxNQUFNLEdBQUcsTUFBTSxDQUFDO1FBQ3JCLElBQUksQ0FBQyxPQUFPLEdBQUcsT0FBTyxDQUFDO0lBQ3pCLENBQUM7Q0FDRjtBQU5ELDhEQU1DO0FBRUQsTUFBTSxZQUFZLEdBQUc7SUFDbkIsaUJBQWlCO0lBQ2pCLGVBQWU7SUFDZixvQkFBb0I7SUFDcEIsbUJBQW1CO0lBQ25CLHlCQUF5QjtDQUMxQixDQUFDO0FBRUYsWUFBWSxDQUFDLE9BQU8sQ0FBQyxDQUFDLENBQUMsRUFBRSxFQUFFO0lBQ3pCLENBQUMsQ0FBQyxTQUFTLENBQUMsSUFBSSxHQUFHLFdBQVcsQ0FBQyxDQUFDLElBQUksRUFBRSxDQUFDO0FBQ3pDLENBQUMsQ0FBQyxDQUFDIn0= \ No newline at end of file diff --git a/lib/Runtime/BeforeExitListener.d.ts b/lib/Runtime/BeforeExitListener.d.ts new file mode 100644 index 0000000..d015394 --- /dev/null +++ b/lib/Runtime/BeforeExitListener.d.ts @@ -0,0 +1,20 @@ +/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ +import { IBeforeExitListener } from "../Common"; +declare class BeforeExitListener implements IBeforeExitListener { + constructor(); + /** + * Call the listener function with no arguments. + */ + invoke: () => void; + /** + * Reset the listener to a no-op function. + */ + reset: () => (() => void); + /** + * Set the listener to the provided function. + */ + set: (listener: () => void) => (() => void); +} +declare const beforeExitListener: BeforeExitListener; +export default beforeExitListener; +//# sourceMappingURL=BeforeExitListener.d.ts.map \ No newline at end of file diff --git a/lib/Runtime/BeforeExitListener.d.ts.map b/lib/Runtime/BeforeExitListener.d.ts.map new file mode 100644 index 0000000..411e32b --- /dev/null +++ b/lib/Runtime/BeforeExitListener.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"BeforeExitListener.d.ts","sourceRoot":"","sources":["../../src/Runtime/BeforeExitListener.ts"],"names":[],"mappings":"AACA,8EAA8E;AAI9E,OAAO,EAAE,mBAAmB,EAAE,MAAM,WAAW,CAAC;AAkBhD,cAAM,kBAAmB,YAAW,mBAAmB;;IAKrD;;OAEG;IACH,MAAM,QAAO,IAAI,CAAuC;IAExD;;OAEG;IACH,KAAK,QAAO,CAAC,MAAM,IAAI,CAAC,CAC8B;IAEtD;;OAEG;IACH,GAAG,aAAc,MAAM,IAAI,KAAG,CAAC,MAAM,IAAI,CAAC,CACM;CACjD;AAED,QAAA,MAAM,kBAAkB,oBAA2B,CAAC;AAEpD,eAAe,kBAAkB,CAAC"} \ No newline at end of file diff --git a/lib/Runtime/BeforeExitListener.js b/lib/Runtime/BeforeExitListener.js new file mode 100644 index 0000000..75cb36c --- /dev/null +++ b/lib/Runtime/BeforeExitListener.js @@ -0,0 +1,37 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ +"use strict"; +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * The runtime has a single beforeExit function which is stored in the global + * object with a symbol key. + * The symbol is not exported. + * The process.beforeExit listener is setup in index.js along with all other + * top-level process event listeners. + */ +// define a named symbol for the handler function +const LISTENER_SYMBOL = Symbol.for("aws.lambda.beforeExit"); +const NO_OP_LISTENER = () => { + /* NoOp */ +}; +// export a setter +class BeforeExitListener { + constructor() { + /** + * Call the listener function with no arguments. + */ + this.invoke = () => global[LISTENER_SYMBOL](); + /** + * Reset the listener to a no-op function. + */ + this.reset = () => (global[LISTENER_SYMBOL] = NO_OP_LISTENER); + /** + * Set the listener to the provided function. + */ + this.set = (listener) => (global[LISTENER_SYMBOL] = listener); + this.reset(); + } +} +const beforeExitListener = new BeforeExitListener(); +exports.default = beforeExitListener; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQmVmb3JlRXhpdExpc3RlbmVyLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL1J1bnRpbWUvQmVmb3JlRXhpdExpc3RlbmVyLnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLHVEQUF1RDtBQUN2RCw4RUFBOEU7QUFFOUUsWUFBWSxDQUFDOztBQUliOzs7Ozs7R0FNRztBQUVILGlEQUFpRDtBQUNqRCxNQUFNLGVBQWUsR0FBRyxNQUFNLENBQUMsR0FBRyxDQUFDLHVCQUF1QixDQUFDLENBQUM7QUFFNUQsTUFBTSxjQUFjLEdBQUcsR0FBRyxFQUFFO0lBQzFCLFVBQVU7QUFDWixDQUFDLENBQUM7QUFFRixrQkFBa0I7QUFDbEIsTUFBTSxrQkFBa0I7SUFDdEI7UUFJQTs7V0FFRztRQUNILFdBQU0sR0FBRyxHQUFTLEVBQUUsQ0FBRSxNQUFjLENBQUMsZUFBZSxDQUFDLEVBQUUsQ0FBQztRQUV4RDs7V0FFRztRQUNILFVBQUssR0FBRyxHQUFpQixFQUFFLENBQ3pCLENBQUUsTUFBYyxDQUFDLGVBQWUsQ0FBQyxHQUFHLGNBQWMsQ0FBQyxDQUFDO1FBRXREOztXQUVHO1FBQ0gsUUFBRyxHQUFHLENBQUMsUUFBb0IsRUFBZ0IsRUFBRSxDQUMzQyxDQUFFLE1BQWMsQ0FBQyxlQUFlLENBQUMsR0FBRyxRQUFRLENBQUMsQ0FBQztRQWxCOUMsSUFBSSxDQUFDLEtBQUssRUFBRSxDQUFDO0lBQ2YsQ0FBQztDQWtCRjtBQUVELE1BQU0sa0JBQWtCLEdBQUcsSUFBSSxrQkFBa0IsRUFBRSxDQUFDO0FBRXBELGtCQUFlLGtCQUFrQixDQUFDIn0= \ No newline at end of file diff --git a/lib/Runtime/CallbackContext.d.ts b/lib/Runtime/CallbackContext.d.ts new file mode 100644 index 0000000..36d02a7 --- /dev/null +++ b/lib/Runtime/CallbackContext.d.ts @@ -0,0 +1,21 @@ +/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ +import { ICallbackContext, CallbackFunction } from "../Common"; +import { IRuntimeClient } from "../RuntimeClient"; +/** + * Construct the base-context object which includes the required flags and + * callback methods for the Node programming model. + * + * @param client {Client} + * The Runtime client used to post results/errors. + * @param id {string} + * The invokeId for the current invocation. + * @param scheduleNext {function} + * A function which takes no params and immediately schedules the next + * iteration of the invoke loop. + * @returns [callback, context] + * The same function and context object, but wrapped such that only the + * first call to any function will be successful. All subsequent calls are + * a no-op. + */ +export declare const build: (client: IRuntimeClient, id: string, scheduleNext: () => void) => [CallbackFunction, ICallbackContext]; +//# sourceMappingURL=CallbackContext.d.ts.map \ No newline at end of file diff --git a/lib/Runtime/CallbackContext.d.ts.map b/lib/Runtime/CallbackContext.d.ts.map new file mode 100644 index 0000000..ac4aec3 --- /dev/null +++ b/lib/Runtime/CallbackContext.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"CallbackContext.d.ts","sourceRoot":"","sources":["../../src/Runtime/CallbackContext.ts"],"names":[],"mappings":"AACA,8EAA8E;AAK9E,OAAO,EAEL,gBAAgB,EAEhB,gBAAgB,EACjB,MAAM,WAAW,CAAC;AAEnB,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD;;;;;;;;;;;;;;;GAeG;AACH,eAAO,MAAM,KAAK,WACR,cAAc,MAClB,MAAM,gBACI,MAAM,IAAI,KACvB,CAAC,gBAAgB,EAAE,gBAAgB,CAGrC,CAAC"} \ No newline at end of file diff --git a/lib/Runtime/CallbackContext.js b/lib/Runtime/CallbackContext.js new file mode 100644 index 0000000..e439fa5 --- /dev/null +++ b/lib/Runtime/CallbackContext.js @@ -0,0 +1,157 @@ +/* eslint-disable no-console */ +/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.build = void 0; +const BeforeExitListener_1 = __importDefault(require("./BeforeExitListener")); +const Errors = __importStar(require("../Errors")); +/** + * Construct the base-context object which includes the required flags and + * callback methods for the Node programming model. + * + * @param client {Client} + * The Runtime client used to post results/errors. + * @param id {string} + * The invokeId for the current invocation. + * @param scheduleNext {function} + * A function which takes no params and immediately schedules the next + * iteration of the invoke loop. + * @returns [callback, context] + * The same function and context object, but wrapped such that only the + * first call to any function will be successful. All subsequent calls are + * a no-op. + */ +exports.build = function (client, id, scheduleNext) { + const [callback, context] = _rawCallbackContext(client, id, scheduleNext); + return _wrappedCallbackContext(callback, context); +}; +function _homogeneousError(err) { + if (err instanceof Error) { + return err; + } + else { + return new Error(err); + } +} +/** + * Build the callback function and the part of the context which exposes + * the succeed/fail/done callbacks. + * @param client {Client} + * The Runtime client used to post results/errors. + * @param id {string} + * The invokeId for the current invocation. + * @param scheduleNext {function} + * A function which takes no params and immediately schedules the next + * iteration of the invoke loop. + */ +function _rawCallbackContext(client, id, scheduleNext) { + const postError = (err, callback) => { + const homogeneousError = _homogeneousError(err); + console.error("Invoke Error", Errors.toFormatted(homogeneousError)); + client.postInvocationError(err, id, callback); + }; + const complete = (result, callback) => { + client.postInvocationResponse(result, id, callback); + }; + let waitForEmptyEventLoop = true; + const callback = (err, result) => { + BeforeExitListener_1.default.reset(); + if (err !== undefined && err !== null) { + postError(err, scheduleNext); + } + else { + complete(result, () => { + if (!waitForEmptyEventLoop) { + scheduleNext(); + } + else { + BeforeExitListener_1.default.set(scheduleNext); + } + }); + } + }; + const done = (err, result) => { + BeforeExitListener_1.default.reset(); + if (err !== undefined && err !== null) { + postError(err, scheduleNext); + } + else { + complete(result, scheduleNext); + } + }; + const succeed = (result) => { + done(null, result); + }; + const fail = (err) => { + if (err === undefined || err === null) { + done("handled"); + } + else { + done(err); + } + }; + const callbackContext = { + get callbackWaitsForEmptyEventLoop() { + return waitForEmptyEventLoop; + }, + set callbackWaitsForEmptyEventLoop(value) { + waitForEmptyEventLoop = value; + }, + succeed, + fail, + done, + }; + return [callback, callbackContext]; +} +/** + * Wraps the callback and context so that only the first call to any callback + * succeeds. + * @param callback {function} + * the node-style callback function that was previously generated but not + * yet wrapped. + * @param callbackContext {object} + * The previously generated callbackContext object that contains + * getter/setters for the contextWaitsForEmptyeventLoop flag and the + * succeed/fail/done functions. + * @return [callback, context] + */ +function _wrappedCallbackContext(callback, callbackContext) { + let finished = false; + // eslint-disable-next-line @typescript-eslint/ban-types + const onlyAllowFirstCall = function (toWrap) { + return function (...args) { + if (!finished) { + // eslint-disable-next-line prefer-spread + toWrap.apply(null, args); + finished = true; + } + }; + }; + callbackContext.succeed = onlyAllowFirstCall(callbackContext.succeed); + callbackContext.fail = onlyAllowFirstCall(callbackContext.fail); + callbackContext.done = onlyAllowFirstCall(callbackContext.done); + return [onlyAllowFirstCall(callback), callbackContext]; +} +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiQ2FsbGJhY2tDb250ZXh0LmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL1J1bnRpbWUvQ2FsbGJhY2tDb250ZXh0LnRzIl0sIm5hbWVzIjpbXSwibWFwcGluZ3MiOiJBQUFBLCtCQUErQjtBQUMvQiw4RUFBOEU7QUFFOUUsWUFBWSxDQUFDOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBRWIsOEVBQXNEO0FBT3RELGtEQUFvQztBQUdwQzs7Ozs7Ozs7Ozs7Ozs7O0dBZUc7QUFDVSxRQUFBLEtBQUssR0FBRyxVQUNuQixNQUFzQixFQUN0QixFQUFVLEVBQ1YsWUFBd0I7SUFFeEIsTUFBTSxDQUFDLFFBQVEsRUFBRSxPQUFPLENBQUMsR0FBRyxtQkFBbUIsQ0FBQyxNQUFNLEVBQUUsRUFBRSxFQUFFLFlBQVksQ0FBQyxDQUFDO0lBQzFFLE9BQU8sdUJBQXVCLENBQUMsUUFBUSxFQUFFLE9BQU8sQ0FBQyxDQUFDO0FBQ3BELENBQUMsQ0FBQztBQUVGLFNBQVMsaUJBQWlCLENBQUMsR0FBMkI7SUFDcEQsSUFBSSxHQUFHLFlBQVksS0FBSyxFQUFFO1FBQ3hCLE9BQU8sR0FBRyxDQUFDO0tBQ1o7U0FBTTtRQUNMLE9BQU8sSUFBSSxLQUFLLENBQUMsR0FBRyxDQUFDLENBQUM7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DUCxJQUFJO1FBQ0osSUFBSTtLQUNMLENBQUM7SUFFRixPQUFPLENBQUMsUUFBUSxFQUFFLGVBQWUsQ0FBQyxDQUFDO0FBQ3JDLENBQUM7QUFFRDs7Ozs7Ozs7Ozs7R0FXRztBQUNILFNBQVMsdUJBQXVCLENBQzlCLFFBQTBCLEVBQzFCLGVBQWlDO0lBRWpDLElBQUksUUFBUSxHQUFHLEtBQUssQ0FBQztJQUNyQix3REFBd0Q7SUFDeEQsTUFBTSxrQkFBa0IsR0FBRyxVQUFVLE1BQWdCO1FBQ25ELE9BQU8sVUFBVSxHQUFHLElBQWU7WUFDakMsSUFBSSxDQUFDLFFBQVEsRUFBRTtnQkFDYix5Q0FBeUM7Z0JBQ3pDLE1BQU0sQ0FBQyxLQUFLLENBQUMsSUFBSSxFQUFFLElBQUksQ0FBQyxDQUFDO2dCQUN6QixRQUFRLEdBQUcsSUFBSSxDQUFDO2FBQ2pCO1FBQ0gsQ0FBQyxDQUFDO0lBQ0osQ0FBQyxDQUFDO0lBRUYsZUFBZSxDQUFDLE9BQU8sR0FBRyxrQkFBa0IsQ0FBQyxlQUFlLENBQUMsT0FBTyxDQUFDLENBQUM7SUFDdEUsZUFBZSxDQUFDLElBQUksR0FBRyxrQkFBa0IsQ0FBQyxlQUFlLENBQUMsSUFBSSxDQUFDLENBQUM7SUFDaEUsZUFBZSxDQUFDLElBQUksR0FBRyxrQkFBa0IsQ0FBQyxlQUFlLENBQUMsSUFBSSxDQUFDLENBQUM7SUFFaEUsT0FBTyxDQUFDLGtCQUFrQixDQUFDLFFBQVEsQ0FBQyxFQUFFLGVBQWUsQ0FBQyxDQUFDO0FBQ3pELENBQUMifQ== \ No newline at end of file diff --git a/lib/Runtime/InvokeContext.d.ts b/lib/Runtime/InvokeContext.d.ts new file mode 100644 index 0000000..8e374ce --- /dev/null +++ b/lib/Runtime/InvokeContext.d.ts @@ -0,0 +1,53 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * This module defines the InvokeContext and supporting functions. The + * InvokeContext is responsible for pulling information from the invoke headers + * and for wrapping the Runtime Client object's error and response functions. + */ +/// +import { IncomingHttpHeaders } from "http"; +import { ICallbackContext, IHeaderData, IEnvironmentData } from "../Common"; +export default class InvokeContext { + headers: IncomingHttpHeaders; + constructor(headers: IncomingHttpHeaders); + private getHeaderValue; + /** + * The invokeId for this request. + */ + get invokeId(): string; + /** + * The header data for this request. + */ + get headerData(): IHeaderData; + /** + * Push relevant invoke data into the logging context. + */ + updateLoggingContext(): void; + /** + * Attach all of the relavant environmental and invocation data to the + * provided object. + * This method can throw if the headers are malformed and cannot be parsed. + * @param callbackContext {Object} + * The callbackContext object returned by a call to buildCallbackContext(). + * @return {Object} + * The user context object with all required data populated from the headers + * and environment variables. + */ + attachEnvironmentData(callbackContext: ICallbackContext): ICallbackContext & IEnvironmentData & IHeaderData; + /** + * All parts of the user-facing context object which are provided through + * environment variables. + */ + private _environmentalData; + /** + * All parts of the user-facing context object which are provided through + * request headers. + */ + private _headerData; + /** + * Forward the XRay header into the environment variable. + */ + private _forwardXRay; +} +//# sourceMappingURL=InvokeContext.d.ts.map \ No newline at end of file diff --git a/lib/Runtime/InvokeContext.d.ts.map b/lib/Runtime/InvokeContext.d.ts.map new file mode 100644 index 0000000..a0e2444 --- /dev/null +++ b/lib/Runtime/InvokeContext.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"InvokeContext.d.ts","sourceRoot":"","sources":["../../src/Runtime/InvokeContext.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;;AAKH,OAAO,EAAE,mBAAmB,EAAE,MAAM,MAAM,CAAC;AAC3C,OAAO,EACL,gBAAgB,EAChB,WAAW,EACX,gBAAgB,EAEjB,MAAM,WAAW,CAAC;AAKnB,MAAM,CAAC,OAAO,OAAO,aAAa;IAChC,OAAO,EAAE,mBAAmB,CAAC;gBAEjB,OAAO,EAAE,mBAAmB;IAIxC,OAAO,CAAC,cAAc;IAiBtB;;OAEG;IACH,IAAI,QAAQ,IAAI,MAAM,CAIrB;IAED;;OAEG;IACH,IAAI,UAAU,IAAI,WAAW,CAE5B;IAED;;OAEG;IACH,oBAAoB,IAAI,IAAI;IAI5B;;;;;;;;;OASG;IACH,qBAAqB,CACnB,eAAe,EAAE,gBAAgB,GAChC,gBAAgB,GAAG,gBAAgB,GAAG,WAAW;IASpD;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAU1B;;;OAGG;IACH,OAAO,CAAC,WAAW;IAqBnB;;OAEG;IACH,OAAO,CAAC,YAAY;CASrB"} \ No newline at end of file diff --git a/lib/Runtime/InvokeContext.js b/lib/Runtime/InvokeContext.js new file mode 100644 index 0000000..022d683 --- /dev/null +++ b/lib/Runtime/InvokeContext.js @@ -0,0 +1,140 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * This module defines the InvokeContext and supporting functions. The + * InvokeContext is responsible for pulling information from the invoke headers + * and for wrapping the Runtime Client object's error and response functions. + */ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const assert_1 = require("assert"); +const Common_1 = require("../Common"); +const LogPatch_1 = __importDefault(require("../utils/LogPatch")); +const setCurrentRequestId = LogPatch_1.default.setCurrentRequestId; +class InvokeContext { + constructor(headers) { + this.headers = _enforceLowercaseKeys(headers); + } + getHeaderValue(key) { + const headerVal = this.headers[key]; + switch (typeof headerVal) { + case "undefined": + return undefined; + case "string": + return headerVal; + default: + if (headerVal.length == 0) { + return undefined; + } + return headerVal[0]; + } + } + /** + * The invokeId for this request. + */ + get invokeId() { + const id = this.getHeaderValue(Common_1.INVOKE_HEADER.AWSRequestId); + assert_1.strict.ok(id, "invocation id is missing or invalid"); + return id; + } + /** + * The header data for this request. + */ + get headerData() { + return this._headerData(); + } + /** + * Push relevant invoke data into the logging context. + */ + updateLoggingContext() { + setCurrentRequestId(this.invokeId); + } + /** + * Attach all of the relavant environmental and invocation data to the + * provided object. + * This method can throw if the headers are malformed and cannot be parsed. + * @param callbackContext {Object} + * The callbackContext object returned by a call to buildCallbackContext(). + * @return {Object} + * The user context object with all required data populated from the headers + * and environment variables. + */ + attachEnvironmentData(callbackContext) { + this._forwardXRay(); + return Object.assign(callbackContext, this._environmentalData(), this._headerData()); + } + /** + * All parts of the user-facing context object which are provided through + * environment variables. + */ + _environmentalData() { + return { + functionVersion: process.env["AWS_LAMBDA_FUNCTION_VERSION"], + functionName: process.env["AWS_LAMBDA_FUNCTION_NAME"], + memoryLimitInMB: process.env["AWS_LAMBDA_FUNCTION_MEMORY_SIZE"], + logGroupName: process.env["AWS_LAMBDA_LOG_GROUP_NAME"], + logStreamName: process.env["AWS_LAMBDA_LOG_STREAM_NAME"], + }; + } + /** + * All parts of the user-facing context object which are provided through + * request headers. + */ + _headerData() { + const deadline = parseInt(this.getHeaderValue(Common_1.INVOKE_HEADER.DeadlineMs) || ""); + return { + clientContext: _parseJson(this.getHeaderValue(Common_1.INVOKE_HEADER.ClientContext), "ClientContext"), + identity: _parseJson(this.getHeaderValue(Common_1.INVOKE_HEADER.CognitoIdentity), "CognitoIdentity"), + invokedFunctionArn: this.getHeaderValue(Common_1.INVOKE_HEADER.ARN), + awsRequestId: this.getHeaderValue(Common_1.INVOKE_HEADER.AWSRequestId), + getRemainingTimeInMillis: function () { + return deadline - Date.now(); + }, + }; + } + /** + * Forward the XRay header into the environment variable. + */ + _forwardXRay() { + if (this.getHeaderValue(Common_1.INVOKE_HEADER.XRayTrace)) { + process.env["_X_AMZN_TRACE_ID"] = this.getHeaderValue(Common_1.INVOKE_HEADER.XRayTrace); + } + else { + delete process.env["_X_AMZN_TRACE_ID"]; + } + } +} +exports.default = InvokeContext; +/** + * Parse a JSON string and throw a readable error if something fails. + * @param jsonString {string} - the string to attempt to parse + * @param name {string} - the name to use when describing the string in an error + * @return object - the parsed object + * @throws if jsonString cannot be parsed + */ +function _parseJson(jsonString, name) { + if (jsonString !== undefined) { + try { + return JSON.parse(jsonString); + } + catch (err) { + throw new Error(`Cannot parse ${name} as json: ${err.toString()}`); + } + } + else { + return undefined; + } +} +/** + * Construct a copy of an object such that all of its keys are lowercase. + */ +function _enforceLowercaseKeys(original) { + return Object.keys(original).reduce((enforced, originalKey) => { + enforced[originalKey.toLowerCase()] = original[originalKey]; + return enforced; + }, {}); +} +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiSW52b2tlQ29udGV4dC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9SdW50aW1lL0ludm9rZUNvbnRleHQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7OztHQU1HO0FBRUgsWUFBWSxDQUFDOzs7OztBQUViLG1DQUEwQztBQUUxQyxzQ0FLbUI7QUFDbkIsaUVBQXlDO0FBRXpDLE1BQU0sbUJBQW1CLEdBQUcsa0JBQVEsQ0FBQyxtQkFBbUIsQ0FBQztBQUV6RCxNQUFxQixhQUFhO0lBR2hDLFlBQVksT0FBNEI7UUFDdEMsSUFBSSxDQUFDLE9BQU8sR0FBRyxxQkFBcUIsQ0FBQyxPQUFPLENBQUMsQ0FBQztJQUNoRCxDQUFDO0lBRU8sY0FBYyxDQUFDLEdBQVc7UUFDaEMsTUFBTSxTQUFTLEdBQUcsSUFBSSxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsQ0FBQztRQUVwQyxRQUFRLE9BQU8sU0FBUyxFQUFFO1lBQ3hCLEtBQUssV0FBVztnQkFDZCxPQUFPLFNBQVMsQ0FBQztZQUNuQixLQUFLLFFBQVE7Z0JBQ1gsT0FBTyxTQUFTLENBQUM7WUFDbkI7Z0JBQ0UsSUFBSSxTQUFTLENBQUMsTUFBTSxJQUFJLENBQUMsRUFBRTtvQkFDekIsT0FBTyxTQUFTLENBQUM7aUJBQ2xCO2dCQUVELE9BQU8sU0FB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0FBRyxDQUFDLGtCQUFrQixDQUFDLENBQUM7U0FDeEM7SUFDSCxDQUFDO0NBQ0Y7QUF2SEQsZ0NBdUhDO0FBRUQ7Ozs7OztHQU1HO0FBQ0gsU0FBUyxVQUFVLENBQUMsVUFBbUIsRUFBRSxJQUFhO0lBQ3BELElBQUksVUFBVSxLQUFLLFNBQVMsRUFBRTtRQUM1QixJQUFJO1lBQ0YsT0FBTyxJQUFJLENBQUMsS0FBSyxDQUFDLFVBQVUsQ0FBQyxDQUFDO1NBQy9CO1FBQUMsT0FBTyxHQUFHLEVBQUU7WUFDWixNQUFNLElBQUksS0FBSyxDQUFDLGdCQUFnQixJQUFJLGFBQWEsR0FBRyxDQUFDLFFBQVEsRUFBRSxFQUFFLENBQUMsQ0FBQztTQUNwRTtLQUNGO1NBQU07UUFDTCxPQUFPLFNBQVMsQ0FBQztLQUNsQjtBQUNILENBQUM7QUFFRDs7R0FFRztBQUNILFNBQVMscUJBQXFCLENBQzVCLFFBQTZCO0lBRTdCLE9BQU8sTUFBTSxDQUFDLElBQUksQ0FBQyxRQUFRLENBQUMsQ0FBQyxNQUFNLENBQUMsQ0FBQyxRQUFRLEVBQUUsV0FBVyxFQUFFLEVBQUU7UUFDNUQsUUFBUSxDQUFDLFdBQVcsQ0FBQyxXQUFXLEVBQUUsQ0FBQyxHQUFHLFFBQVEsQ0FBQyxXQUFXLENBQUMsQ0FBQztRQUM1RCxPQUFPLFFBQVEsQ0FBQztJQUNsQixDQUFDLEVBQUUsRUFBeUIsQ0FBQyxDQUFDO0FBQ2hDLENBQUMifQ== \ No newline at end of file diff --git a/lib/Runtime/Runtime.d.ts b/lib/Runtime/Runtime.d.ts new file mode 100644 index 0000000..6505301 --- /dev/null +++ b/lib/Runtime/Runtime.d.ts @@ -0,0 +1,35 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * This module defines the top-level Runtime class which controls the + * bootstrap's execution flow. + */ +import { HandlerFunction, IErrorCallbacks } from "../Common"; +import { IRuntimeClient } from "../RuntimeClient"; +export default class Runtime { + client: IRuntimeClient; + errorCallbacks: IErrorCallbacks; + handler: HandlerFunction; + constructor(client: IRuntimeClient, handler: HandlerFunction, errorCallbacks: IErrorCallbacks); + /** + * Schedule the next loop iteration to start at the beginning of the next time + * around the event loop. + */ + scheduleIteration(): void; + /** + * Wait for the next invocation, process it, and schedule the next iteration. + */ + handleOnce(): Promise; + /** + * Replace the error handler callbacks. + * @param {String} invokeId + */ + private _setErrorCallbacks; + /** + * Setup the 'beforeExit' listener that is used if the callback is never + * called and the handler is not async. + * CallbackContext replaces the listener if a callback is invoked. + */ + private _setDefaultExitListener; +} +//# sourceMappingURL=Runtime.d.ts.map \ No newline at end of file diff --git a/lib/Runtime/Runtime.d.ts.map b/lib/Runtime/Runtime.d.ts.map new file mode 100644 index 0000000..0712b32 --- /dev/null +++ b/lib/Runtime/Runtime.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"Runtime.d.ts","sourceRoot":"","sources":["../../src/Runtime/Runtime.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAG7D,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,MAAM,CAAC,OAAO,OAAO,OAAO;IAC1B,MAAM,EAAE,cAAc,CAAC;IACvB,cAAc,EAAE,eAAe,CAAC;IAChC,OAAO,EAAE,eAAe,CAAC;gBAGvB,MAAM,EAAE,cAAc,EACtB,OAAO,EAAE,eAAe,EACxB,cAAc,EAAE,eAAe;IAOjC;;;OAGG;IACH,iBAAiB,IAAI,IAAI;IAwBzB;;OAEG;IACG,UAAU,IAAI,OAAO,CAAC,IAAI,CAAC;IA+BjC;;;OAGG;IACH,OAAO,CAAC,kBAAkB;IAa1B;;;;OAIG;IACH,OAAO,CAAC,uBAAuB;CAOhC"} \ No newline at end of file diff --git a/lib/Runtime/Runtime.js b/lib/Runtime/Runtime.js new file mode 100644 index 0000000..9556629 --- /dev/null +++ b/lib/Runtime/Runtime.js @@ -0,0 +1,118 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * This module defines the top-level Runtime class which controls the + * bootstrap's execution flow. + */ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const BeforeExitListener_1 = __importDefault(require("./BeforeExitListener")); +const CallbackContext = __importStar(require("./CallbackContext")); +const InvokeContext_1 = __importDefault(require("./InvokeContext")); +class Runtime { + constructor(client, handler, errorCallbacks) { + this.client = client; + this.handler = handler; + this.errorCallbacks = errorCallbacks; + } + /** + * Schedule the next loop iteration to start at the beginning of the next time + * around the event loop. + */ + scheduleIteration() { + setImmediate(() => { + this.handleOnce().then( + // Success is a no-op at this level. There are 2 cases: + // 1 - The user used one of the callback functions which already + // schedules the next iteration. + // 2 - The next iteration is not scheduled because the + // waitForEmptyEventLoop was set. In this case the beforeExit + // handler will automatically start the next iteration. + // eslint-disable-next-line @typescript-eslint/no-empty-function + () => { }, + // Errors should not reach this level in typical execution. If they do + // it's a sign of an issue in the Client or a bug in the runtime. So + // dump it to the console and attempt to report it as a Runtime error. + (err) => { + // eslint-disable-next-line no-console + console.log(`Unexpected Top Level Error: ${err.toString()}`); + this.errorCallbacks.uncaughtException(err); + }); + }); + } + /** + * Wait for the next invocation, process it, and schedule the next iteration. + */ + async handleOnce() { + const { bodyJson, headers } = await this.client.nextInvocation(); + const invokeContext = new InvokeContext_1.default(headers); + invokeContext.updateLoggingContext(); + const [callback, callbackContext] = CallbackContext.build(this.client, invokeContext.invokeId, this.scheduleIteration.bind(this)); + try { + this._setErrorCallbacks(invokeContext.invokeId); + this._setDefaultExitListener(invokeContext.invokeId); + const result = this.handler(JSON.parse(bodyJson), invokeContext.attachEnvironmentData(callbackContext), callback); + if (_isPromise(result)) { + result + .then(callbackContext.succeed, callbackContext.fail) + .catch(callbackContext.fail); + } + } + catch (err) { + callback(err); + } + } + /** + * Replace the error handler callbacks. + * @param {String} invokeId + */ + _setErrorCallbacks(invokeId) { + this.errorCallbacks.uncaughtException = (error) => { + this.client.postInvocationError(error, invokeId, () => { + process.exit(129); + }); + }; + this.errorCallbacks.unhandledRejection = (error) => { + this.client.postInvocationError(error, invokeId, () => { + process.exit(128); + }); + }; + } + /** + * Setup the 'beforeExit' listener that is used if the callback is never + * called and the handler is not async. + * CallbackContext replaces the listener if a callback is invoked. + */ + _setDefaultExitListener(invokeId) { + BeforeExitListener_1.default.set(() => { + this.client.postInvocationResponse(null, invokeId, () => this.scheduleIteration()); + }); + } +} +exports.default = Runtime; +function _isPromise(obj) { + return obj instanceof Promise; +} +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUnVudGltZS5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9SdW50aW1lL1J1bnRpbWUudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7O0dBS0c7QUFFSCxZQUFZLENBQUM7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7OztBQUViLDhFQUFzRDtBQUV0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FQUFFO1lBQzdELElBQUksQ0FBQyxNQUFNLENBQUMsbUJBQW1CLENBQUMsS0FBSyxFQUFFLFFBQVEsRUFBRSxHQUFHLEVBQUU7Z0JBQ3BELE9BQU8sQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUM7WUFDcEIsQ0FBQyxDQUFDLENBQUM7UUFDTCxDQUFDLENBQUM7UUFDRixJQUFJLENBQUMsY0FBYyxDQUFDLGtCQUFrQixHQUFHLENBQUMsS0FBWSxFQUFRLEVBQUU7WUFDOUQsSUFBSSxDQUFDLE1BQU0sQ0FBQyxtQkFBbUIsQ0FBQyxLQUFLLEVBQUUsUUFBUSxFQUFFLEdBQUcsRUFBRTtnQkFDcEQsT0FBTyxDQUFDLElBQUksQ0FBQyxHQUFHLENBQUMsQ0FBQztZQUNwQixDQUFDLENBQUMsQ0FBQztRQUNMLENBQUMsQ0FBQztJQUNKLENBQUM7SUFFRDs7OztPQUlHO0lBQ0ssdUJBQXVCLENBQUMsUUFBZ0I7UUFDOUMsNEJBQWtCLENBQUMsR0FBRyxDQUFDLEdBQUcsRUFBRTtZQUMxQixJQUFJLENBQUMsTUFBTSxDQUFDLHNCQUFzQixDQUFDLElBQUksRUFBRSxRQUFRLEVBQUUsR0FBRyxFQUFFLENBQ3RELElBQUksQ0FBQyxpQkFBaUIsRUFBRSxDQUN6QixDQUFDO1FBQ0osQ0FBQyxDQUFDLENBQUM7SUFDTCxDQUFDO0NBQ0Y7QUExR0QsMEJBMEdDO0FBRUQsU0FBUyxVQUFVLENBQUMsR0FBK0I7SUFDakQsT0FBTyxHQUFHLFlBQVksT0FBTyxDQUFDO0FBQ2hDLENBQUMifQ== \ No newline at end of file diff --git a/lib/Runtime/index.d.ts b/lib/Runtime/index.d.ts new file mode 100644 index 0000000..caea962 --- /dev/null +++ b/lib/Runtime/index.d.ts @@ -0,0 +1,6 @@ +/** + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + */ +import Runtime from "./Runtime"; +export default Runtime; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib/Runtime/index.d.ts.map b/lib/Runtime/index.d.ts.map new file mode 100644 index 0000000..b8d8f10 --- /dev/null +++ b/lib/Runtime/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/Runtime/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,OAAO,MAAM,WAAW,CAAC;AAEhC,eAAe,OAAO,CAAC"} \ No newline at end of file diff --git a/lib/Runtime/index.js b/lib/Runtime/index.js new file mode 100644 index 0000000..6e00f32 --- /dev/null +++ b/lib/Runtime/index.js @@ -0,0 +1,11 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + */ +const Runtime_1 = __importDefault(require("./Runtime")); +exports.default = Runtime_1.default; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvUnVudGltZS9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBOztHQUVHO0FBQ0gsd0RBQWdDO0FBRWhDLGtCQUFlLGlCQUFPLENBQUMifQ== \ No newline at end of file diff --git a/lib/RuntimeClient/RuntimeClient.d.ts b/lib/RuntimeClient/RuntimeClient.d.ts new file mode 100644 index 0000000..7c6820e --- /dev/null +++ b/lib/RuntimeClient/RuntimeClient.d.ts @@ -0,0 +1,79 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * This module defines the Runtime client which is responsible for all HTTP + * interactions with the Runtime layer. + */ +/// +import { Agent, RequestOptions, IncomingMessage, ClientRequest, OutgoingHttpHeaders } from "http"; +import { URL } from "url"; +import { InvocationResponse, NativeClient } from "../Common"; +interface HttpModule { + Agent: typeof Agent; + request(options: RequestOptions | string | URL, callback?: (res: IncomingMessage) => void): ClientRequest; +} +export interface IRuntimeClient { + nextInvocation: () => Promise; + postInvocationError: (error: unknown, id: string, callback: () => void) => void; + postInvocationResponse: (response: unknown, id: string, callback: () => void) => void; +} +/** + * Objects of this class are responsible for all interactions with the Runtime + * API. + */ +export default class RuntimeClient implements IRuntimeClient { + agent: Agent; + http: HttpModule; + nativeClient: NativeClient; + userAgent: string; + useAlternativeClient: boolean; + hostname: string; + port: number; + constructor(hostnamePort: string, httpClient?: HttpModule, nativeClient?: NativeClient); + /** + * Complete and invocation with the provided response. + * @param {Object} response + * An arbitrary object to convert to JSON and send back as as response. + * @param {String} id + * The invocation ID. + * @param {function()} callback + * The callback to run after the POST response ends + */ + postInvocationResponse(response: unknown, id: string, callback: () => void): void; + /** + * Post an initialization error to the Runtime API. + * @param {Error} error + * @param {function()} callback + * The callback to run after the POST response ends + */ + postInitError(error: unknown, callback: () => void): void; + /** + * Post an invocation error to the Runtime API + * @param {Error} error + * @param {String} id + * The invocation ID for the in-progress invocation. + * @param {function()} callback + * The callback to run after the POST response ends + */ + postInvocationError(error: unknown, id: string, callback: () => void): void; + /** + * Get the next invocation. + * @return {PromiseLike.} + * A promise which resolves to an invocation object that contains the body + * as json and the header array. e.g. {bodyJson, headers} + */ + nextInvocation(): Promise; + /** + * HTTP Post to a path. + * @param {String} path + * @param {Object} body + * The body is serialized into JSON before posting. + * @param {Object} headers + * The http headers + * @param {function()} callback + * The callback to run after the POST response ends + */ + _post(path: string, body: unknown, headers: OutgoingHttpHeaders, callback: () => void): void; +} +export {}; +//# sourceMappingURL=RuntimeClient.d.ts.map \ No newline at end of file diff --git a/lib/RuntimeClient/RuntimeClient.d.ts.map b/lib/RuntimeClient/RuntimeClient.d.ts.map new file mode 100644 index 0000000..4e24e24 --- /dev/null +++ b/lib/RuntimeClient/RuntimeClient.d.ts.map @@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BAAsB,CACpB,QAAQ,EAAE,OAAO,EACjB,EAAE,EAAE,MAAM,EACV,QAAQ,EAAE,MAAM,IAAI,GACnB,IAAI;IAMP;;;;;OAKG;IACH,aAAa,CAAC,KAAK,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAUzD;;;;;;;OAOG;IACH,mBAAmB,CAAC,KAAK,EAAE,OAAO,EAAE,EAAE,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,IAAI,GAAG,IAAI;IAQ3E;;;;;OAKG;IACG,cAAc,IAAI,OAAO,CAAC,kBAAkB,CAAC;IAsCnD;;;;;;;;;OASG;IACH,KAAK,CACH,IAAI,EAAE,MAAM,EACZ,IAAI,EAAE,OAAO,EACb,OAAO,EAAE,mBAAmB,EAC5B,QAAQ,EAAE,MAAM,IAAI,GACnB,IAAI;CAiCR"} \ No newline at end of file diff --git a/lib/RuntimeClient/RuntimeClient.js b/lib/RuntimeClient/RuntimeClient.js new file mode 100644 index 0000000..50b2ea9 --- /dev/null +++ b/lib/RuntimeClient/RuntimeClient.js @@ -0,0 +1,192 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * This module defines the Runtime client which is responsible for all HTTP + * interactions with the Runtime layer. + */ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const Errors = __importStar(require("../Errors")); +const XRayError = __importStar(require("../Errors/XRayError")); +const ERROR_TYPE_HEADER = "Lambda-Runtime-Function-Error-Type"; +function userAgent() { + // eslint-disable-next-line @typescript-eslint/no-var-requires + const version = require("../../package.json").version; + return `aws-lambda-nodejs/${process.version}-${version}`; +} +/** + * Objects of this class are responsible for all interactions with the Runtime + * API. + */ +class RuntimeClient { + constructor(hostnamePort, httpClient, nativeClient) { + this.http = httpClient || require("http"); + this.nativeClient = + nativeClient || require("../../build/Release/runtime-client.node"); + this.userAgent = userAgent(); + this.nativeClient.initializeClient(this.userAgent); + this.useAlternativeClient = + process.env["AWS_LAMBDA_NODEJS_USE_ALTERNATIVE_CLIENT_1"] === "true"; + const [hostname, port] = hostnamePort.split(":"); + this.hostname = hostname; + this.port = parseInt(port, 10); + this.agent = new this.http.Agent({ + keepAlive: true, + maxSockets: 1, + }); + } + /** + * Complete and invocation with the provided response. + * @param {Object} response + * An arbitrary object to convert to JSON and send back as as response. + * @param {String} id + * The invocation ID. + * @param {function()} callback + * The callback to run after the POST response ends + */ + postInvocationResponse(response, id, callback) { + const bodyString = _trySerializeResponse(response); + this.nativeClient.done(id, bodyString); + callback(); + } + /** + * Post an initialization error to the Runtime API. + * @param {Error} error + * @param {function()} callback + * The callback to run after the POST response ends + */ + postInitError(error, callback) { + const response = Errors.toRuntimeResponse(error); + this._post(`/2018-06-01/runtime/init/error`, response, { [ERROR_TYPE_HEADER]: response.errorType }, callback); + } + /** + * Post an invocation error to the Runtime API + * @param {Error} error + * @param {String} id + * The invocation ID for the in-progress invocation. + * @param {function()} callback + * The callback to run after the POST response ends + */ + postInvocationError(error, id, callback) { + const response = Errors.toRuntimeResponse(error); + const bodyString = _trySerializeResponse(response); + const xrayString = XRayError.toFormatted(error); + this.nativeClient.error(id, bodyString, xrayString); + callback(); + } + /** + * Get the next invocation. + * @return {PromiseLike.} + * A promise which resolves to an invocation object that contains the body + * as json and the header array. e.g. {bodyJson, headers} + */ + async nextInvocation() { + if (this.useAlternativeClient) { + const options = { + hostname: this.hostname, + port: this.port, + path: "/2018-06-01/runtime/invocation/next", + method: "GET", + agent: this.agent, + headers: { + "User-Agent": this.userAgent, + }, + }; + return new Promise((resolve, reject) => { + const request = this.http.request(options, (response) => { + let data = ""; + response + .setEncoding("utf-8") + .on("data", (chunk) => { + data += chunk; + }) + .on("end", () => { + resolve({ + bodyJson: data, + headers: response.headers, + }); + }); + }); + request + .on("error", (e) => { + reject(e); + }) + .end(); + }); + } + return this.nativeClient.next(); + } + /** + * HTTP Post to a path. + * @param {String} path + * @param {Object} body + * The body is serialized into JSON before posting. + * @param {Object} headers + * The http headers + * @param {function()} callback + * The callback to run after the POST response ends + */ + _post(path, body, headers, callback) { + const bodyString = _trySerializeResponse(body); + const options = { + hostname: this.hostname, + port: this.port, + path: path, + method: "POST", + headers: Object.assign({ + "Content-Type": "application/json", + "Content-Length": Buffer.from(bodyString).length, + }, headers || {}), + agent: this.agent, + }; + const request = this.http.request(options, (response) => { + response + .on("end", () => { + callback(); + }) + .on("error", (e) => { + throw e; + }) + // eslint-disable-next-line @typescript-eslint/no-empty-function + .on("data", () => { }); + }); + request + .on("error", (e) => { + throw e; + }) + .end(bodyString, "utf-8"); + } +} +exports.default = RuntimeClient; +/** + * Attempt to serialize an object as json. Capture the failure if it occurs and + * throw one that's known to be serializable. + */ +function _trySerializeResponse(body) { + try { + return JSON.stringify(body === undefined ? null : body); + } + catch (err) { + throw new Error("Unable to stringify response body"); + } +} +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiUnVudGltZUNsaWVudC5qcyIsInNvdXJjZVJvb3QiOiIiLCJzb3VyY2VzIjpbIi4uLy4uL3NyYy9SdW50aW1lQ2xpZW50L1J1bnRpbWVDbGllbnQudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUE7Ozs7O0dBS0c7QUFFSCxZQUFZLEN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** + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + */ +import RuntimeClient from "./RuntimeClient"; +export default RuntimeClient; +export { IRuntimeClient } from "./RuntimeClient"; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib/RuntimeClient/index.d.ts.map b/lib/RuntimeClient/index.d.ts.map new file mode 100644 index 0000000..94d378c --- /dev/null +++ b/lib/RuntimeClient/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/RuntimeClient/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AACH,OAAO,aAAa,MAAM,iBAAiB,CAAC;AAE5C,eAAe,aAAa,CAAC;AAC7B,OAAO,EAAE,cAAc,EAAE,MAAM,iBAAiB,CAAC"} \ No newline at end of file diff --git a/lib/RuntimeClient/index.js b/lib/RuntimeClient/index.js new file mode 100644 index 0000000..9bbb66c --- /dev/null +++ b/lib/RuntimeClient/index.js @@ -0,0 +1,11 @@ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +/** + * Copyright 2020 Amazon.com, Inc. or its affiliates. All Rights Reserved. + */ +const RuntimeClient_1 = __importDefault(require("./RuntimeClient")); +exports.default = RuntimeClient_1.default; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvUnVudGltZUNsaWVudC9pbmRleC50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiOzs7OztBQUFBOztHQUVHO0FBQ0gsb0VBQTRDO0FBRTVDLGtCQUFlLHVCQUFhLENBQUMifQ== \ No newline at end of file diff --git a/lib/RuntimeClient/runtime-client.cc b/lib/RuntimeClient/runtime-client.cc new file mode 100644 index 0000000..d6edffa --- /dev/null +++ b/lib/RuntimeClient/runtime-client.cc @@ -0,0 +1,153 @@ +/* + * Copyright 2019-present Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Licensed under the Apache License, Version 2.0 (the "License"). + * You may not use this file except in compliance with the License. + * A copy of the License is located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file is distributed + * on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either + * express or implied. See the License for the specific language governing + * permissions and limitations under the License. + */ + +#include +#include "aws/lambda-runtime/runtime.h" +#include "aws/lambda-runtime/version.h" +#include "napi.h" + +#include + +static aws::lambda_runtime::runtime *CLIENT; + +Napi::Value InitializeClient(const Napi::CallbackInfo & info) +{ + Napi::Env env = info.Env(); + if (info.Length() < 1) { + Napi::TypeError::New(env, "Wrong number of arguments, expected 1").ThrowAsJavaScriptException(); + return env.Null(); + } + if (!info[0].IsString()) { + Napi::TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); + return env.Null(); + } + if (CLIENT != nullptr) { + Napi::TypeError::New(env, "Client already initialized").ThrowAsJavaScriptException(); + return env.Null(); + } + auto userAgent = info[0].As().Utf8Value(); + CLIENT = new aws::lambda_runtime::runtime(getenv("AWS_LAMBDA_RUNTIME_API"), userAgent); + return env.Null(); +} + +Napi::Value Next(const Napi::CallbackInfo & info) +{ + Napi::Env env = info.Env(); + if (CLIENT == nullptr) { + Napi::TypeError::New(env, "Client not initialized").ThrowAsJavaScriptException(); + return env.Null(); + } + auto outcome = CLIENT->get_next(); + if (!outcome.is_success()) { + Napi::TypeError::New(env, "Failed to get next!").ThrowAsJavaScriptException(); + return env.Null(); + } + + // TODO: See if json parsing works on V8:Buffer objects, which might be a way to reduce copying large payloads + auto response = outcome.get_result(); + auto response_data = Napi::String::New(env, response.payload.c_str()); + + // TODO: The current javascript code (InvokeContext.js) to handle the header values itself. + // These type conversions might be replaced by returning the final context object. + auto headers = Napi::Object::New(env); + headers.Set( + Napi::String::New(env, "lambda-runtime-deadline-ms"), + Napi::Number::New(env, + std::chrono::duration_cast( + response.deadline.time_since_epoch() + ).count() + )); + headers.Set( + Napi::String::New(env, "lambda-runtime-aws-request-id"), + Napi::String::New(env, response.request_id.c_str())); + headers.Set( + Napi::String::New(env, "lambda-runtime-trace-id"), + Napi::String::New(env, response.xray_trace_id.c_str())); + headers.Set( + Napi::String::New(env, "lambda-runtime-invoked-function-arn"), + Napi::String::New(env, response.function_arn.c_str())); + if (response.client_context != "") { + headers.Set( + Napi::String::New(env, "lambda-runtime-client-context"), + Napi::String::New(env, response.client_context.c_str())); + } + if (response.cognito_identity != "") { + headers.Set( + Napi::String::New(env, "lambda-runtime-cognito-identity"), + Napi::String::New(env, response.cognito_identity.c_str())); + } + + auto ret = Napi::Object::New(env); + ret.Set(Napi::String::New(env, "bodyJson"), response_data); + ret.Set(Napi::String::New(env, "headers"), headers); + + return ret; +} + +Napi::Value Done(const Napi::CallbackInfo & info) +{ + Napi::Env env = info.Env(); + if (CLIENT == nullptr) { + Napi::TypeError::New(env, "Client not initialized").ThrowAsJavaScriptException(); + return env.Null(); + } + if (info.Length() < 2) { + Napi::TypeError::New(env, "Wrong number of arguments, expected 2").ThrowAsJavaScriptException(); + return env.Null(); + } + if (!info[0].IsString() || !info[1].IsString()) { + Napi::TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); + return env.Null(); + } + auto requestId = info[0].As(); + auto responseString = info[1].As(); + auto response = aws::lambda_runtime::invocation_response::success(responseString.Utf8Value(), "application/json"); + auto outcome = CLIENT->post_success(requestId.Utf8Value(), response); + return env.Null(); +} + +Napi::Value Error(const Napi::CallbackInfo & info) +{ + Napi::Env env = info.Env(); + if (CLIENT == nullptr) { + Napi::TypeError::New(env, "Client not initialized").ThrowAsJavaScriptException(); + return env.Null(); + } + if (info.Length() < 3) { + Napi::TypeError::New(env, "Wrong number of arguments, expected 3").ThrowAsJavaScriptException(); + return env.Null(); + } + if (!info[0].IsString() || !info[1].IsString() || !info[2].IsString()) { + Napi::TypeError::New(env, "Wrong arguments").ThrowAsJavaScriptException(); + return env.Null(); + } + auto requestId = info[0].As(); + auto responseString = info[1].As(); + auto xrayResponse = info[2].As(); + auto response = aws::lambda_runtime::invocation_response(responseString.Utf8Value(), "application/json", false, xrayResponse.Utf8Value()); + auto outcome = CLIENT->post_failure(requestId.Utf8Value(), response); + return env.Null(); +} + +Napi::Object Init(Napi::Env env, Napi::Object exports) +{ + exports.Set(Napi::String::New(env, "initializeClient"), Napi::Function::New(env, InitializeClient)); + exports.Set(Napi::String::New(env, "next"), Napi::Function::New(env, Next)); + exports.Set(Napi::String::New(env, "done"), Napi::Function::New(env, Done)); + exports.Set(Napi::String::New(env, "error"), Napi::Function::New(env, Error)); + return exports; +} + +NODE_API_MODULE(addon, Init); diff --git a/lib/index.d.ts b/lib/index.d.ts new file mode 100644 index 0000000..456d8c2 --- /dev/null +++ b/lib/index.d.ts @@ -0,0 +1,8 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * This module is the bootstrap entrypoint. It establishes the top-level event + * listeners and loads the user's code. + */ +export declare function run(appRoot: string, handler: string): void; +//# sourceMappingURL=index.d.ts.map \ No newline at end of file diff --git a/lib/index.d.ts.map b/lib/index.d.ts.map new file mode 100644 index 0000000..89b89a2 --- /dev/null +++ b/lib/index.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AAcH,wBAAgB,GAAG,CAAC,OAAO,EAAE,MAAM,EAAE,OAAO,EAAE,MAAM,GAAG,IAAI,CAoC1D"} \ No newline at end of file diff --git a/lib/index.js b/lib/index.js new file mode 100644 index 0000000..5a0244a --- /dev/null +++ b/lib/index.js @@ -0,0 +1,69 @@ +/* eslint-disable no-console */ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * This module is the bootstrap entrypoint. It establishes the top-level event + * listeners and loads the user's code. + */ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.run = void 0; +const Errors = __importStar(require("./Errors")); +const RuntimeClient_1 = __importDefault(require("./RuntimeClient")); +const Runtime_1 = __importDefault(require("./Runtime")); +const BeforeExitListener_1 = __importDefault(require("./Runtime/BeforeExitListener")); +const LogPatch_1 = __importDefault(require("./utils/LogPatch")); +const UserFunction = __importStar(require("./utils/UserFunction")); +LogPatch_1.default.patchConsole(); +function run(appRoot, handler) { + if (!process.env.AWS_LAMBDA_RUNTIME_API) { + throw new Error("Missing Runtime API Server configuration."); + } + const client = new RuntimeClient_1.default(process.env.AWS_LAMBDA_RUNTIME_API); + const errorCallbacks = { + uncaughtException: (error) => { + client.postInitError(error, () => process.exit(129)); + }, + unhandledRejection: (error) => { + client.postInitError(error, () => process.exit(128)); + }, + }; + process.on("uncaughtException", (error) => { + console.error("Uncaught Exception", Errors.toFormatted(error)); + errorCallbacks.uncaughtException(error); + }); + process.on("unhandledRejection", (reason, promise) => { + const error = new Errors.UnhandledPromiseRejection(reason === null || reason === void 0 ? void 0 : reason.toString(), promise); + console.error("Unhandled Promise Rejection", Errors.toFormatted(error)); + errorCallbacks.unhandledRejection(error); + }); + BeforeExitListener_1.default.reset(); + process.on("beforeExit", BeforeExitListener_1.default.invoke); + const handlerFunc = UserFunction.load(appRoot, handler); + const runtime = new Runtime_1.default(client, handlerFunc, errorCallbacks); + runtime.scheduleIteration(); +} +exports.run = run; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiaW5kZXguanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi9zcmMvaW5kZXgudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsK0JBQStCO0FBQy9COzs7OztHQUtHO0FBRUgsWUFBWSxDQUFDOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7O0FBR2IsaURBQW1DO0FBQ25DLG9FQUE0QztBQUM1Qyx3REFBZ0M7QUFDaEMsc0ZBQThEO0FBQzlELGdFQUF3QztBQUN4QyxtRUFBcUQ7QUFFckQsa0JBQVEsQ0FBQyxZQUFZLEVBQUUsQ0FBQztBQUV4QixTQUFnQixHQUFHLENBQUMsT0FBZSxFQUFFLE9BQWU7SUFDbEQsSUFBSSxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsc0JBQXNCLEVBQUU7UUFDdkMsTUFBTSxJQUFJLEtBQUssQ0FBQywyQ0FBMkMsQ0FBQyxDQUFDO0tBQzlEO0lBQ0QsTUFBTSxNQUFNLEdBQUcsSUFBSSx1QkFBYSxDQUFDLE9BQU8sQ0FBQyxHQUFHLENBQUMsc0JBQXNCLENBQUMsQ0FBQztJQUVyRSxNQUFNLGNBQWMsR0FBRztRQUNyQixpQkFBaUIsRUFBRSxDQUFDLEtBQVksRUFBRSxFQUFFO1lBQ2xDLE1BQU0sQ0FBQyxhQUFhLENBQUMsS0FBSyxFQUFFLEdBQUcsRUFBRSxDQUFDLE9BQU8sQ0FBQyxJQUFJLENBQUMsR0FBRyxDQUFDLENBQUMsQ0FBQztRQUN2RCxDQUFDO1FBQ0Qsa0JBQWtCLEVBQUUsQ0FBQy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UFBRSxPQUFPLENBQW9CLENBQUM7SUFDM0UsTUFBTSxPQUFPLEdBQUcsSUFBSSxpQkFBTyxDQUFDLE1BQU0sRUFBRSxXQUFXLEVBQUUsY0FBYyxDQUFDLENBQUM7SUFFakUsT0FBTyxDQUFDLGlCQUFpQixFQUFFLENBQUM7QUFDOUIsQ0FBQztBQXBDRCxrQkFvQ0MifQ== \ No newline at end of file diff --git a/lib/tsconfig.tsbuildinfo b/lib/tsconfig.tsbuildinfo new file mode 100644 index 0000000..0de7994 --- /dev/null +++ b/lib/tsconfig.tsbuildinfo @@ -0,0 +1,1087 @@ +{ + "program": { + "fileInfos": { + "../node_modules/typescript/lib/lib.es5.d.ts": { + "version": "c9a1f03d6ba0fe3c871eb0dd81622e78fbb61ade70878b34d48a341a690c59e9", + "signature": "c9a1f03d6ba0fe3c871eb0dd81622e78fbb61ade70878b34d48a341a690c59e9", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2015.d.ts": { + "version": "dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6", + "signature": "dc47c4fa66b9b9890cf076304de2a9c5201e94b740cffdf09f87296d877d71f6", + "affectsGlobalScope": false + }, + "../node_modules/typescript/lib/lib.es2016.d.ts": { + "version": "7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467", + "signature": "7a387c58583dfca701b6c85e0adaf43fb17d590fb16d5b2dc0a2fbd89f35c467", + "affectsGlobalScope": false + }, + "../node_modules/typescript/lib/lib.es2017.d.ts": { + "version": "8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9", + "signature": "8a12173c586e95f4433e0c6dc446bc88346be73ffe9ca6eec7aa63c8f3dca7f9", + "affectsGlobalScope": false + }, + "../node_modules/typescript/lib/lib.es2018.d.ts": { + "version": "5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06", + "signature": "5f4e733ced4e129482ae2186aae29fde948ab7182844c3a5a51dd346182c7b06", + "affectsGlobalScope": false + }, + "../node_modules/typescript/lib/lib.es2015.core.d.ts": { + "version": "46ee15e9fefa913333b61eaf6b18885900b139867d89832a515059b62cf16a17", + "signature": "46ee15e9fefa913333b61eaf6b18885900b139867d89832a515059b62cf16a17", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2015.collection.d.ts": { + "version": "43fb1d932e4966a39a41b464a12a81899d9ae5f2c829063f5571b6b87e6d2f9c", + "signature": "43fb1d932e4966a39a41b464a12a81899d9ae5f2c829063f5571b6b87e6d2f9c", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2015.generator.d.ts": { + "version": "cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a", + "signature": "cdccba9a388c2ee3fd6ad4018c640a471a6c060e96f1232062223063b0a5ac6a", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2015.iterable.d.ts": { + "version": "42f5e41e5893da663dbf0394268f54f1da4b43dc0ddd2ea4bf471fe5361d6faf", + "signature": "42f5e41e5893da663dbf0394268f54f1da4b43dc0ddd2ea4bf471fe5361d6faf", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2015.promise.d.ts": { + "version": "0b7a905675e6cb4211c128f0a3aa47d414b275180a299a9aad5d3ec298abbfc4", + "signature": "0b7a905675e6cb4211c128f0a3aa47d414b275180a299a9aad5d3ec298abbfc4", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2015.proxy.d.ts": { + "version": "dfff68b3c34338f6b307a25d4566de15eed7973b0dc5d69f9fde2bcac1c25315", + "signature": "dfff68b3c34338f6b307a25d4566de15eed7973b0dc5d69f9fde2bcac1c25315", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2015.reflect.d.ts": { + "version": "cb609802a8698aa28b9c56331d4b53f590ca3c1c3a255350304ae3d06017779d", + "signature": "cb609802a8698aa28b9c56331d4b53f590ca3c1c3a255350304ae3d06017779d", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2015.symbol.d.ts": { + "version": "3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93", + "signature": "3013574108c36fd3aaca79764002b3717da09725a36a6fc02eac386593110f93", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts": { + "version": "4670208dd7da9d6c774ab1b75c1527a810388c7989c4905de6aaea8561cb9dce", + "signature": "4670208dd7da9d6c774ab1b75c1527a810388c7989c4905de6aaea8561cb9dce", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2016.array.include.d.ts": { + "version": "3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006", + "signature": "3be5a1453daa63e031d266bf342f3943603873d890ab8b9ada95e22389389006", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2017.object.d.ts": { + "version": "17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a", + "signature": "17bb1fc99591b00515502d264fa55dc8370c45c5298f4a5c2083557dccba5a2a", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts": { + "version": "b5e4c2d67aa844ed503b29cd4ca2ede1a229ac7fe874613b2c996fa9c581a25f", + "signature": "b5e4c2d67aa844ed503b29cd4ca2ede1a229ac7fe874613b2c996fa9c581a25f", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2017.string.d.ts": { + "version": "6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577", + "signature": "6a6b173e739a6a99629a8594bfb294cc7329bfb7b227f12e1f7c11bc163b8577", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2017.intl.d.ts": { + "version": "12a310447c5d23c7d0d5ca2af606e3bd08afda69100166730ab92c62999ebb9d", + "signature": "12a310447c5d23c7d0d5ca2af606e3bd08afda69100166730ab92c62999ebb9d", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts": { + "version": "b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e", + "signature": "b0124885ef82641903d232172577f2ceb5d3e60aed4da1153bab4221e1f6dd4e", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts": { + "version": "0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a", + "signature": "0eb85d6c590b0d577919a79e0084fa1744c1beba6fd0d4e951432fa1ede5510a", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts": { + "version": "a40c4d82bf13fcded295ac29f354eb7d40249613c15e07b53f2fc75e45e16359", + "signature": "a40c4d82bf13fcded295ac29f354eb7d40249613c15e07b53f2fc75e45e16359", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2018.intl.d.ts": { + "version": "df9c8a72ca8b0ed62f5470b41208a0587f0f73f0a7db28e5a1272cf92537518e", + "signature": "df9c8a72ca8b0ed62f5470b41208a0587f0f73f0a7db28e5a1272cf92537518e", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2018.promise.d.ts": { + "version": "bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c", + "signature": "bb2d3fb05a1d2ffbca947cc7cbc95d23e1d053d6595391bd325deb265a18d36c", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2018.regexp.d.ts": { + "version": "c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8", + "signature": "c80df75850fea5caa2afe43b9949338ce4e2de086f91713e9af1a06f973872b8", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.es2020.bigint.d.ts": { + "version": "7b5a10e3c897fabece5a51aa85b4111727d7adb53c2734b5d37230ff96802a09", + "signature": "7b5a10e3c897fabece5a51aa85b4111727d7adb53c2734b5d37230ff96802a09", + "affectsGlobalScope": true + }, + "../node_modules/typescript/lib/lib.esnext.intl.d.ts": { + "version": "89bf2b7a601b73ea4311eda9c41f86a58994fec1bee3b87c4a14d68d9adcdcbd", + "signature": "89bf2b7a601b73ea4311eda9c41f86a58994fec1bee3b87c4a14d68d9adcdcbd", + "affectsGlobalScope": true + }, + "../src/common/index.ts": { + "version": "f6de26b757dee187c9f51e949db91239c5b4deed3ab4ec8cf5b4470694fcf209", + "signature": "d84b83f5bea33c9138721b49a1fb89b1edfea8ac6dc4bbad6cf5a246049f78fd", + "affectsGlobalScope": false + }, + "../src/errors/index.ts": { + "version": "a50db1d1e72f9b95cc9d1c43dab6a08c4564339cf5dce6f20a244f1b52f55541", + "signature": "12632106f4c42dd93d95da8f742cfd30391ef29a484d26e089d6432f4c69aabc", + "affectsGlobalScope": false + }, + "../src/errors/xrayerror.ts": { + "version": "a9e4ba40de137cc2599c20027834429df5dd13b4c1fdf86b4dc6ddc06aac6903", + "signature": "f1166d9467e99847a95f22dec28752ef57417315704102ae98fb002e92620caa", + "affectsGlobalScope": false + }, + "../src/runtimeclient/runtimeclient.ts": { + "version": "6f5739deba101d542bca2091bcbe67d3425574efef076f665a6ebfb086720a2b", + "signature": "9a6951b466e3e01fa7540f2af1a5598e48467adfa25ee9f32abc1fde2af6030d", + "affectsGlobalScope": false + }, + "../src/runtimeclient/index.ts": { + "version": "a1febbaf6c1dcbf8f59f2d601f2138a8a4c7f60c69962f48565ffd6b4c75d40f", + "signature": "e8956f26fa94203f3a47b6d4d30cdaf365620cc8ca5b127cd9f1ea1985e90ac3", + "affectsGlobalScope": false + }, + "../src/runtime/beforeexitlistener.ts": { + "version": "4affc75775a07572af2730f708f56ef40029ee8d7e59faf7a4ada5baafb9a96c", + "signature": "558624b6623fe529d1e7126f8b4ada13f12a5ebaabbf2b01c099a4bfdb349317", + "affectsGlobalScope": false + }, + "../src/runtime/callbackcontext.ts": { + "version": "7836b064d8818abc27a7d818269cba4aff9aae08a926beb23f73784aa3de294c", + "signature": "4b1f190ed70ca88c9cbd260d72d45c57a013314a61f437bac0ebe1a26074201c", + "affectsGlobalScope": false + }, + "../src/utils/logpatch.ts": { + "version": "8ebbaf57c512a1cb4d5e1f7ebdf9adfca27b8246b7fd00bcc5b1c50c628c1df6", + "signature": "63750b86db85f22ba955fa770d98606a47ddec71e7b9d3316527becfea60aac8", + "affectsGlobalScope": false + }, + "../src/runtime/invokecontext.ts": { + "version": "58be7784338be00d1dd1acb4a5ef387bc8d4c2f1f87d47cdf774ee29d34034a5", + "signature": "943554ca8dd43816cf0d9b59fa4ce833c86078df86ec29d87321511d648b01e2", + "affectsGlobalScope": false + }, + "../src/runtime/runtime.ts": { + "version": "6ba7ed29e2ed8239c42d415e1d6eec4f6cedff809361986faea2cee92c18ec96", + "signature": "6919612de7a02faefee066221abd6dfb69cf5915cececeedbbc654ce4e1477fb", + "affectsGlobalScope": false + }, + "../src/runtime/index.ts": { + "version": "4ae39b84d6a49a7d564ccffbc81fafd64e872e30098f1a82cdc0db3361750d72", + "signature": "7a43cc7367e07b5c18818e585977d6abe0e9494492db9488c7ed7e1866d920d9", + "affectsGlobalScope": false + }, + "../src/utils/userfunction.ts": { + "version": "ab16d158a33af63cb2dec7584cfcf8635eab4a4e67938ff2e1a1af91439700e0", + "signature": "538c09334ff2e107806beb780fdd45d2fcedcd75b26a47bc59dc41a2eea16090", + "affectsGlobalScope": false + }, + "../src/index.ts": { + "version": "74c73e386a4eb53194fe3c4144f53f48cb5cbe1ff7f8657dcef252577bd625f5", + "signature": "51bd2d09798d8af72b02f6b98f31c474c216f0e2be72e9f87f1e3cd33c87f8f5", + "affectsGlobalScope": false + }, + "../node_modules/@types/color-name/index.d.ts": { + "version": "f0cb4b3ab88193e3e51e9e2622e4c375955003f1f81239d72c5b7a95415dad3e", + "signature": "f0cb4b3ab88193e3e51e9e2622e4c375955003f1f81239d72c5b7a95415dad3e", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/globals.d.ts": { + "version": "68aba9c37b535b42ce96b78a4cfa93813bf4525f86dceb88a6d726c5f7c6c14f", + "signature": "68aba9c37b535b42ce96b78a4cfa93813bf4525f86dceb88a6d726c5f7c6c14f", + "affectsGlobalScope": true + }, + "../node_modules/@types/node/async_hooks.d.ts": { + "version": "c438b413e94ff76dfa20ae005f33a1c84f2480d1d66e0fd687501020d0de9b50", + "signature": "c438b413e94ff76dfa20ae005f33a1c84f2480d1d66e0fd687501020d0de9b50", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/buffer.d.ts": { + "version": "bc6a78961535181265845bf9b9e8a147ffd0ca275097ceb670a9b92afa825152", + "signature": "bc6a78961535181265845bf9b9e8a147ffd0ca275097ceb670a9b92afa825152", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/child_process.d.ts": { + "version": "1fc4b0908c44f39b1f2e5a728d472670a0ea0970d2c6b5691c88167fe541ff82", + "signature": "1fc4b0908c44f39b1f2e5a728d472670a0ea0970d2c6b5691c88167fe541ff82", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/cluster.d.ts": { + "version": "123ec69e4b3a686eb49afd94ebe3292a5c84a867ecbcb6bb84bdd720a12af803", + "signature": "123ec69e4b3a686eb49afd94ebe3292a5c84a867ecbcb6bb84bdd720a12af803", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/console.d.ts": { + "version": "51851805d06a6878796c3a00ccf0839fe18111a38d1bae84964c269f16bcc2b7", + "signature": "51851805d06a6878796c3a00ccf0839fe18111a38d1bae84964c269f16bcc2b7", + "affectsGlobalScope": true + }, + "../node_modules/@types/node/constants.d.ts": { + "version": "90c85ddbb8de82cd19198bda062065fc51b7407c0f206f2e399e65a52e979720", + "signature": "90c85ddbb8de82cd19198bda062065fc51b7407c0f206f2e399e65a52e979720", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/crypto.d.ts": { + "version": "dab288a3d92e6a3323566256ba56987b78b100341866fa3cc245c9cd2fd55706", + "signature": "dab288a3d92e6a3323566256ba56987b78b100341866fa3cc245c9cd2fd55706", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/dgram.d.ts": { + "version": "7ecfe97b43aa6c8b8f90caa599d5648bb559962e74e6f038f73a77320569dd78", + "signature": "7ecfe97b43aa6c8b8f90caa599d5648bb559962e74e6f038f73a77320569dd78", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/dns.d.ts": { + "version": "7db7569fbb3e2b01ba8751c761cdd3f0debd104170d5665b7dc20a11630df3a9", + "signature": "7db7569fbb3e2b01ba8751c761cdd3f0debd104170d5665b7dc20a11630df3a9", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/domain.d.ts": { + "version": "cde4d7f6274468180fa39847b183aec22626e8212ff885d535c53f4cd7c225fd", + "signature": "cde4d7f6274468180fa39847b183aec22626e8212ff885d535c53f4cd7c225fd", + "affectsGlobalScope": true + }, + "../node_modules/@types/node/events.d.ts": { + "version": "072b0ac82ae8fe05b0d4f2eadb7f6edd0ebd84175ecad2f9e09261290a86bcee", + "signature": "072b0ac82ae8fe05b0d4f2eadb7f6edd0ebd84175ecad2f9e09261290a86bcee", + "affectsGlobalScope": true + }, + "../node_modules/@types/node/fs.d.ts": { + "version": "f6eedd1053167b8a651d8d9c70b1772e1b501264a36dfa881d7d4b30d623a9bc", + "signature": "f6eedd1053167b8a651d8d9c70b1772e1b501264a36dfa881d7d4b30d623a9bc", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/fs/promises.d.ts": { + "version": "fb28748ff8d015f52e99daee4f454e57cec1a22141f1257c317f3630a15edeb7", + "signature": "fb28748ff8d015f52e99daee4f454e57cec1a22141f1257c317f3630a15edeb7", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/http.d.ts": { + "version": "08fb2b0e1ef13a2df43f6d8e97019c36dfbc0475cf4d274c6838e2c9223fe39d", + "signature": "08fb2b0e1ef13a2df43f6d8e97019c36dfbc0475cf4d274c6838e2c9223fe39d", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/http2.d.ts": { + "version": "5d9394b829cfd504b2fe17287aaad8ce1dcfb2a2183c962a90a85b96da2c1c90", + "signature": "5d9394b829cfd504b2fe17287aaad8ce1dcfb2a2183c962a90a85b96da2c1c90", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/https.d.ts": { + "version": "c969bf4c7cdfe4d5dd28aa09432f99d09ad1d8d8b839959646579521d0467d1a", + "signature": "c969bf4c7cdfe4d5dd28aa09432f99d09ad1d8d8b839959646579521d0467d1a", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/inspector.d.ts": { + "version": "6c3857edaeeaaf43812f527830ebeece9266b6e8eb5271ab6d2f0008306c9947", + "signature": "6c3857edaeeaaf43812f527830ebeece9266b6e8eb5271ab6d2f0008306c9947", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/module.d.ts": { + "version": "bc6a77e750f4d34584e46b1405b771fb69a224197dd6bafe5b0392a29a70b665", + "signature": "bc6a77e750f4d34584e46b1405b771fb69a224197dd6bafe5b0392a29a70b665", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/net.d.ts": { + "version": "46cac76114704902baa535b30fb66a26aeaf9430f3b3ab44746e329f12e85498", + "signature": "46cac76114704902baa535b30fb66a26aeaf9430f3b3ab44746e329f12e85498", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/os.d.ts": { + "version": "ed4ae81196cccc10f297d228bca8d02e31058e6d723a3c5bc4be5fb3c61c6a34", + "signature": "ed4ae81196cccc10f297d228bca8d02e31058e6d723a3c5bc4be5fb3c61c6a34", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/path.d.ts": { + "version": "84044697c8b3e08ef24e4b32cfe6440143d07e469a5e34bda0635276d32d9f35", + "signature": "84044697c8b3e08ef24e4b32cfe6440143d07e469a5e34bda0635276d32d9f35", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/perf_hooks.d.ts": { + "version": "6999f789ed86a40f3bc4d7e644e8d42ffda569465969df8077cd6c4e3505dd76", + "signature": "6999f789ed86a40f3bc4d7e644e8d42ffda569465969df8077cd6c4e3505dd76", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/process.d.ts": { + "version": "0c9f2b308e5696d0802b613aff47c99f092add29408e654f7ab6026134250c18", + "signature": "0c9f2b308e5696d0802b613aff47c99f092add29408e654f7ab6026134250c18", + "affectsGlobalScope": true + }, + "../node_modules/@types/node/punycode.d.ts": { + "version": "30ec6f9c683b988c3cfaa0c4690692049c4e7ed7dc6f6e94f56194c06b86f5e1", + "signature": "30ec6f9c683b988c3cfaa0c4690692049c4e7ed7dc6f6e94f56194c06b86f5e1", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/querystring.d.ts": { + "version": "884560fda6c3868f925f022adc3a1289fe6507bbb45adb10fa1bbcc73a941bb0", + "signature": "884560fda6c3868f925f022adc3a1289fe6507bbb45adb10fa1bbcc73a941bb0", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/readline.d.ts": { + "version": "6b2bb67b0942bcfce93e1d6fad5f70afd54940a2b13df7f311201fba54b2cbe9", + "signature": "6b2bb67b0942bcfce93e1d6fad5f70afd54940a2b13df7f311201fba54b2cbe9", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/repl.d.ts": { + "version": "dd3706b25d06fe23c73d16079e8c66ac775831ef419da00716bf2aee530a04a4", + "signature": "dd3706b25d06fe23c73d16079e8c66ac775831ef419da00716bf2aee530a04a4", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/stream.d.ts": { + "version": "1298327149e93a60c24a3b5db6048f7cc8fd4e3259e91d05fc44306a04b1b873", + "signature": "1298327149e93a60c24a3b5db6048f7cc8fd4e3259e91d05fc44306a04b1b873", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/string_decoder.d.ts": { + "version": "d67e08745494b000da9410c1ae2fdc9965fc6d593fe0f381a47491f75417d457", + "signature": "d67e08745494b000da9410c1ae2fdc9965fc6d593fe0f381a47491f75417d457", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/timers.d.ts": { + "version": "b40652bf8ce4a18133b31349086523b219724dca8df3448c1a0742528e7ad5b9", + "signature": "b40652bf8ce4a18133b31349086523b219724dca8df3448c1a0742528e7ad5b9", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/tls.d.ts": { + "version": "3181290a158e54a78c1a57c41791ec1cbdc860ae565916daa1bf4e425b7edac7", + "signature": "3181290a158e54a78c1a57c41791ec1cbdc860ae565916daa1bf4e425b7edac7", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/trace_events.d.ts": { + "version": "a77fdb357c78b70142b2fdbbfb72958d69e8f765fd2a3c69946c1018e89d4638", + "signature": "a77fdb357c78b70142b2fdbbfb72958d69e8f765fd2a3c69946c1018e89d4638", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/tty.d.ts": { + "version": "3c2ac350c3baa61fd2b1925844109e098f4376d0768a4643abc82754fd752748", + "signature": "3c2ac350c3baa61fd2b1925844109e098f4376d0768a4643abc82754fd752748", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/url.d.ts": { + "version": "826d48e49c905cedb906cbde6ccaf758827ff5867d4daa006b5a79e0fb489357", + "signature": "826d48e49c905cedb906cbde6ccaf758827ff5867d4daa006b5a79e0fb489357", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/util.d.ts": { + "version": "5ef157fbb39494a581bd24f21b60488fe248d452c479738b5e41b48720ea69b8", + "signature": "5ef157fbb39494a581bd24f21b60488fe248d452c479738b5e41b48720ea69b8", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/v8.d.ts": { + "version": "289be113bad7ee27ee7fa5b1e373c964c9789a5e9ed7db5ddcb631371120b953", + "signature": "289be113bad7ee27ee7fa5b1e373c964c9789a5e9ed7db5ddcb631371120b953", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/vm.d.ts": { + "version": "a1136cf18dbe1b9b600c65538fd48609a1a4772d115a0c1d775839fe6544487c", + "signature": "a1136cf18dbe1b9b600c65538fd48609a1a4772d115a0c1d775839fe6544487c", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/worker_threads.d.ts": { + "version": "e8482f41c6e001657302dcb3a1ba30359a0983574caee9405ef863cb9eac3b95", + "signature": "e8482f41c6e001657302dcb3a1ba30359a0983574caee9405ef863cb9eac3b95", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/zlib.d.ts": { + "version": "ab99ac6bfd84d493602cc1baa2c726a4df8f2ec8f3750b565ad17368c440db3b", + "signature": "ab99ac6bfd84d493602cc1baa2c726a4df8f2ec8f3750b565ad17368c440db3b", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/ts3.4/base.d.ts": { + "version": "d44028ae0127eb3e9fcfa5f55a8b81d64775ce15aca1020fe25c511bbb055834", + "signature": "d44028ae0127eb3e9fcfa5f55a8b81d64775ce15aca1020fe25c511bbb055834", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/globals.global.d.ts": { + "version": "2708349d5a11a5c2e5f3a0765259ebe7ee00cdcc8161cb9990cb4910328442a1", + "signature": "2708349d5a11a5c2e5f3a0765259ebe7ee00cdcc8161cb9990cb4910328442a1", + "affectsGlobalScope": true + }, + "../node_modules/@types/node/wasi.d.ts": { + "version": "4e0a4d84b15692ea8669fe4f3d05a4f204567906b1347da7a58b75f45bae48d3", + "signature": "4e0a4d84b15692ea8669fe4f3d05a4f204567906b1347da7a58b75f45bae48d3", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/ts3.6/base.d.ts": { + "version": "0f04bc8950ad634ac8ac70f704f200ef06f8852af9017f97c446de4def5b3546", + "signature": "0f04bc8950ad634ac8ac70f704f200ef06f8852af9017f97c446de4def5b3546", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/assert.d.ts": { + "version": "3c3aa211dfaba6f6432034d633bba5f1f11054c695a12a607cb71d3e6d5b1aec", + "signature": "3c3aa211dfaba6f6432034d633bba5f1f11054c695a12a607cb71d3e6d5b1aec", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/base.d.ts": { + "version": "d20072cb51d8baad944bedd935a25c7f10c29744e9a648d2c72c215337356077", + "signature": "d20072cb51d8baad944bedd935a25c7f10c29744e9a648d2c72c215337356077", + "affectsGlobalScope": false + }, + "../node_modules/@types/node/index.d.ts": { + "version": "35cbbc58882d2c158032d7f24ba8953d7e1caeb8cb98918d85819496109f55d2", + "signature": "35cbbc58882d2c158032d7f24ba8953d7e1caeb8cb98918d85819496109f55d2", + "affectsGlobalScope": false + }, + "../node_modules/@types/dockerode/index.d.ts": { + "version": "fb0f0a54a949550d5a6d2b5cee944f07ab08924a9e64bdbbfe3f72d883ccc432", + "signature": "fb0f0a54a949550d5a6d2b5cee944f07ab08924a9e64bdbbfe3f72d883ccc432", + "affectsGlobalScope": false + }, + "../node_modules/@types/fs-extra/index.d.ts": { + "version": "b4730e5cbeac402e543a0186f3c7521bd7c3c25c8fc7cf048103fc6487566654", + "signature": "b4730e5cbeac402e543a0186f3c7521bd7c3c25c8fc7cf048103fc6487566654", + "affectsGlobalScope": false + }, + "../node_modules/@types/js-yaml/index.d.ts": { + "version": "c303a72d3128054d400767264e6f5414b86bf29c1b11730c45027f2213e82f34", + "signature": "c303a72d3128054d400767264e6f5414b86bf29c1b11730c45027f2213e82f34", + "affectsGlobalScope": false + }, + "../node_modules/@types/json-schema/index.d.ts": { + "version": "b2be568d8ce95fcb26eebd04c035d94825655fdf689bf67d799f5ff8cbbb1024", + "signature": "b2be568d8ce95fcb26eebd04c035d94825655fdf689bf67d799f5ff8cbbb1024", + "affectsGlobalScope": false + }, + "../node_modules/@types/json5/index.d.ts": { + "version": "96d14f21b7652903852eef49379d04dbda28c16ed36468f8c9fa08f7c14c9538", + "signature": "96d14f21b7652903852eef49379d04dbda28c16ed36468f8c9fa08f7c14c9538", + "affectsGlobalScope": false + }, + "../node_modules/@types/mocha/index.d.ts": { + "version": "060f0636cb83057f9a758cafc817b7be1e8612c4387dfe3fbadda865958cf8c1", + "signature": "060f0636cb83057f9a758cafc817b7be1e8612c4387dfe3fbadda865958cf8c1", + "affectsGlobalScope": true + }, + "../node_modules/@types/parse-json/index.d.ts": { + "version": "2b8264b2fefd7367e0f20e2c04eed5d3038831fe00f5efbc110ff0131aab899b", + "signature": "2b8264b2fefd7367e0f20e2c04eed5d3038831fe00f5efbc110ff0131aab899b", + "affectsGlobalScope": false + }, + "../node_modules/@types/tar-stream/index.d.ts": { + "version": "602329c866980848ab3d79411a3818462240f763769ee36bb56b8ee8db39eca8", + "signature": "602329c866980848ab3d79411a3818462240f763769ee36bb56b8ee8db39eca8", + "affectsGlobalScope": false + }, + "../node_modules/@types/tar-fs/index.d.ts": { + "version": "bed0269f1a3e8423c893856d6c87eb3a7a92805d9a24a332e90ba4695ffd1c6b", + "signature": "bed0269f1a3e8423c893856d6c87eb3a7a92805d9a24a332e90ba4695ffd1c6b", + "affectsGlobalScope": false + } + }, + "options": { + "composite": true, + "target": 5, + "module": 1, + "lib": [ + "lib.es2018.d.ts" + ], + "moduleResolution": 2, + "declaration": true, + "declarationMap": true, + "inlineSourceMap": true, + "esModuleInterop": true, + "strict": true, + "noUnusedLocals": true, + "noUnusedParameters": true, + "noImplicitReturns": true, + "noFallthroughCasesInSwitch": true, + "traceResolution": false, + "listEmittedFiles": false, + "listFiles": false, + "pretty": true, + "typeRoots": [ + "../node_modules/@types", + "../src/types", + "./types" + ], + "outDir": "./", + "configFilePath": "../src/tsconfig.json" + }, + "referencedMap": { + "../node_modules/@types/dockerode/index.d.ts": [ + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/index.d.ts", + "../node_modules/@types/node/stream.d.ts" + ], + "../node_modules/@types/fs-extra/index.d.ts": [ + "../node_modules/@types/node/fs.d.ts", + "../node_modules/@types/node/index.d.ts" + ], + "../node_modules/@types/node/base.d.ts": [ + "../node_modules/@types/node/assert.d.ts", + "../node_modules/@types/node/ts3.6/base.d.ts" + ], + "../node_modules/@types/node/child_process.d.ts": [ + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/fs.d.ts", + "../node_modules/@types/node/net.d.ts", + "../node_modules/@types/node/stream.d.ts" + ], + "../node_modules/@types/node/cluster.d.ts": [ + "../node_modules/@types/node/child_process.d.ts", + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/net.d.ts" + ], + "../node_modules/@types/node/console.d.ts": [ + "../node_modules/@types/node/util.d.ts" + ], + "../node_modules/@types/node/constants.d.ts": [ + "../node_modules/@types/node/crypto.d.ts", + "../node_modules/@types/node/fs.d.ts", + "../node_modules/@types/node/os.d.ts" + ], + "../node_modules/@types/node/crypto.d.ts": [ + "../node_modules/@types/node/stream.d.ts" + ], + "../node_modules/@types/node/dgram.d.ts": [ + "../node_modules/@types/node/dns.d.ts", + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/net.d.ts" + ], + "../node_modules/@types/node/domain.d.ts": [ + "../node_modules/@types/node/events.d.ts" + ], + "../node_modules/@types/node/fs.d.ts": [ + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/fs/promises.d.ts", + "../node_modules/@types/node/stream.d.ts", + "../node_modules/@types/node/url.d.ts" + ], + "../node_modules/@types/node/fs/promises.d.ts": [ + "../node_modules/@types/node/fs.d.ts" + ], + "../node_modules/@types/node/http.d.ts": [ + "../node_modules/@types/node/net.d.ts", + "../node_modules/@types/node/stream.d.ts", + "../node_modules/@types/node/url.d.ts" + ], + "../node_modules/@types/node/http2.d.ts": [ + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/fs.d.ts", + "../node_modules/@types/node/http.d.ts", + "../node_modules/@types/node/net.d.ts", + "../node_modules/@types/node/stream.d.ts", + "../node_modules/@types/node/tls.d.ts", + "../node_modules/@types/node/url.d.ts" + ], + "../node_modules/@types/node/https.d.ts": [ + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/http.d.ts", + "../node_modules/@types/node/tls.d.ts", + "../node_modules/@types/node/url.d.ts" + ], + "../node_modules/@types/node/index.d.ts": [ + "../node_modules/@types/node/base.d.ts" + ], + "../node_modules/@types/node/inspector.d.ts": [ + "../node_modules/@types/node/events.d.ts" + ], + "../node_modules/@types/node/module.d.ts": [ + "../node_modules/@types/node/url.d.ts" + ], + "../node_modules/@types/node/net.d.ts": [ + "../node_modules/@types/node/dns.d.ts", + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/stream.d.ts" + ], + "../node_modules/@types/node/perf_hooks.d.ts": [ + "../node_modules/@types/node/async_hooks.d.ts" + ], + "../node_modules/@types/node/process.d.ts": [ + "../node_modules/@types/node/tty.d.ts" + ], + "../node_modules/@types/node/readline.d.ts": [ + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/stream.d.ts" + ], + "../node_modules/@types/node/repl.d.ts": [ + "../node_modules/@types/node/readline.d.ts", + "../node_modules/@types/node/util.d.ts", + "../node_modules/@types/node/vm.d.ts" + ], + "../node_modules/@types/node/stream.d.ts": [ + "../node_modules/@types/node/events.d.ts" + ], + "../node_modules/@types/node/tls.d.ts": [ + "../node_modules/@types/node/crypto.d.ts", + "../node_modules/@types/node/dns.d.ts", + "../node_modules/@types/node/net.d.ts", + "../node_modules/@types/node/stream.d.ts" + ], + "../node_modules/@types/node/ts3.4/base.d.ts": [ + "../node_modules/@types/node/async_hooks.d.ts", + "../node_modules/@types/node/buffer.d.ts", + "../node_modules/@types/node/child_process.d.ts", + "../node_modules/@types/node/cluster.d.ts", + "../node_modules/@types/node/console.d.ts", + "../node_modules/@types/node/constants.d.ts", + "../node_modules/@types/node/crypto.d.ts", + "../node_modules/@types/node/dgram.d.ts", + "../node_modules/@types/node/dns.d.ts", + "../node_modules/@types/node/domain.d.ts", + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/fs.d.ts", + "../node_modules/@types/node/fs/promises.d.ts", + "../node_modules/@types/node/globals.d.ts", + "../node_modules/@types/node/http.d.ts", + "../node_modules/@types/node/http2.d.ts", + "../node_modules/@types/node/https.d.ts", + "../node_modules/@types/node/inspector.d.ts", + "../node_modules/@types/node/module.d.ts", + "../node_modules/@types/node/net.d.ts", + "../node_modules/@types/node/os.d.ts", + "../node_modules/@types/node/path.d.ts", + "../node_modules/@types/node/perf_hooks.d.ts", + "../node_modules/@types/node/process.d.ts", + "../node_modules/@types/node/punycode.d.ts", + "../node_modules/@types/node/querystring.d.ts", + "../node_modules/@types/node/readline.d.ts", + "../node_modules/@types/node/repl.d.ts", + "../node_modules/@types/node/stream.d.ts", + "../node_modules/@types/node/string_decoder.d.ts", + "../node_modules/@types/node/timers.d.ts", + "../node_modules/@types/node/tls.d.ts", + "../node_modules/@types/node/trace_events.d.ts", + "../node_modules/@types/node/tty.d.ts", + "../node_modules/@types/node/url.d.ts", + "../node_modules/@types/node/util.d.ts", + "../node_modules/@types/node/v8.d.ts", + "../node_modules/@types/node/vm.d.ts", + "../node_modules/@types/node/worker_threads.d.ts", + "../node_modules/@types/node/zlib.d.ts" + ], + "../node_modules/@types/node/ts3.6/base.d.ts": [ + "../node_modules/@types/node/globals.global.d.ts", + "../node_modules/@types/node/ts3.4/base.d.ts", + "../node_modules/@types/node/wasi.d.ts" + ], + "../node_modules/@types/node/tty.d.ts": [ + "../node_modules/@types/node/net.d.ts" + ], + "../node_modules/@types/node/url.d.ts": [ + "../node_modules/@types/node/querystring.d.ts" + ], + "../node_modules/@types/node/v8.d.ts": [ + "../node_modules/@types/node/stream.d.ts" + ], + "../node_modules/@types/node/worker_threads.d.ts": [ + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/stream.d.ts", + "../node_modules/@types/node/url.d.ts", + "../node_modules/@types/node/vm.d.ts" + ], + "../node_modules/@types/node/zlib.d.ts": [ + "../node_modules/@types/node/stream.d.ts" + ], + "../node_modules/@types/tar-fs/index.d.ts": [ + "../node_modules/@types/node/fs.d.ts", + "../node_modules/@types/node/index.d.ts", + "../node_modules/@types/tar-stream/index.d.ts" + ], + "../node_modules/@types/tar-stream/index.d.ts": [ + "../node_modules/@types/node/index.d.ts", + "../node_modules/@types/node/stream.d.ts" + ], + "../src/common/index.ts": [ + "../node_modules/@types/node/http.d.ts" + ], + "../src/errors/index.ts": [ + "../node_modules/@types/node/util.d.ts" + ], + "../src/errors/xrayerror.ts": [ + "../src/errors/index.ts" + ], + "../src/index.ts": [ + "../src/common/index.ts", + "../src/errors/index.ts", + "../src/runtime/beforeexitlistener.ts", + "../src/runtime/index.ts", + "../src/runtimeclient/index.ts", + "../src/utils/logpatch.ts", + "../src/utils/userfunction.ts" + ], + "../src/runtime/beforeexitlistener.ts": [ + "../src/common/index.ts" + ], + "../src/runtime/callbackcontext.ts": [ + "../src/common/index.ts", + "../src/errors/index.ts", + "../src/runtime/beforeexitlistener.ts", + "../src/runtimeclient/index.ts" + ], + "../src/runtime/index.ts": [ + "../src/runtime/runtime.ts" + ], + "../src/runtime/invokecontext.ts": [ + "../node_modules/@types/node/assert.d.ts", + "../node_modules/@types/node/http.d.ts", + "../src/common/index.ts", + "../src/utils/logpatch.ts" + ], + "../src/runtime/runtime.ts": [ + "../src/common/index.ts", + "../src/runtime/beforeexitlistener.ts", + "../src/runtime/callbackcontext.ts", + "../src/runtime/invokecontext.ts", + "../src/runtimeclient/index.ts" + ], + "../src/runtimeclient/index.ts": [ + "../src/runtimeclient/runtimeclient.ts" + ], + "../src/runtimeclient/runtimeclient.ts": [ + "../node_modules/@types/node/http.d.ts", + "../node_modules/@types/node/url.d.ts", + "../src/common/index.ts", + "../src/errors/index.ts", + "../src/errors/xrayerror.ts" + ], + "../src/utils/logpatch.ts": [ + "../node_modules/@types/node/fs.d.ts", + "../node_modules/@types/node/util.d.ts" + ], + "../src/utils/userfunction.ts": [ + "../node_modules/@types/node/fs.d.ts", + "../node_modules/@types/node/path.d.ts", + "../src/common/index.ts", + "../src/errors/index.ts" + ] + }, + "exportedModulesMap": { + "../node_modules/@types/dockerode/index.d.ts": [ + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/index.d.ts", + "../node_modules/@types/node/stream.d.ts" + ], + "../node_modules/@types/fs-extra/index.d.ts": [ + "../node_modules/@types/node/fs.d.ts", + "../node_modules/@types/node/index.d.ts" + ], + "../node_modules/@types/node/base.d.ts": [ + "../node_modules/@types/node/assert.d.ts", + "../node_modules/@types/node/ts3.6/base.d.ts" + ], + "../node_modules/@types/node/child_process.d.ts": [ + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/fs.d.ts", + "../node_modules/@types/node/net.d.ts", + "../node_modules/@types/node/stream.d.ts" + ], + "../node_modules/@types/node/cluster.d.ts": [ + "../node_modules/@types/node/child_process.d.ts", + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/net.d.ts" + ], + "../node_modules/@types/node/console.d.ts": [ + "../node_modules/@types/node/util.d.ts" + ], + "../node_modules/@types/node/constants.d.ts": [ + "../node_modules/@types/node/crypto.d.ts", + "../node_modules/@types/node/fs.d.ts", + "../node_modules/@types/node/os.d.ts" + ], + "../node_modules/@types/node/crypto.d.ts": [ + "../node_modules/@types/node/stream.d.ts" + ], + "../node_modules/@types/node/dgram.d.ts": [ + "../node_modules/@types/node/dns.d.ts", + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/net.d.ts" + ], + "../node_modules/@types/node/domain.d.ts": [ + "../node_modules/@types/node/events.d.ts" + ], + "../node_modules/@types/node/fs.d.ts": [ + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/fs/promises.d.ts", + "../node_modules/@types/node/stream.d.ts", + "../node_modules/@types/node/url.d.ts" + ], + "../node_modules/@types/node/fs/promises.d.ts": [ + "../node_modules/@types/node/fs.d.ts" + ], + "../node_modules/@types/node/http.d.ts": [ + "../node_modules/@types/node/net.d.ts", + "../node_modules/@types/node/stream.d.ts", + "../node_modules/@types/node/url.d.ts" + ], + "../node_modules/@types/node/http2.d.ts": [ + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/fs.d.ts", + "../node_modules/@types/node/http.d.ts", + "../node_modules/@types/node/net.d.ts", + "../node_modules/@types/node/stream.d.ts", + "../node_modules/@types/node/tls.d.ts", + "../node_modules/@types/node/url.d.ts" + ], + "../node_modules/@types/node/https.d.ts": [ + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/http.d.ts", + "../node_modules/@types/node/tls.d.ts", + "../node_modules/@types/node/url.d.ts" + ], + "../node_modules/@types/node/index.d.ts": [ + "../node_modules/@types/node/base.d.ts" + ], + "../node_modules/@types/node/inspector.d.ts": [ + "../node_modules/@types/node/events.d.ts" + ], + "../node_modules/@types/node/module.d.ts": [ + "../node_modules/@types/node/url.d.ts" + ], + "../node_modules/@types/node/net.d.ts": [ + "../node_modules/@types/node/dns.d.ts", + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/stream.d.ts" + ], + "../node_modules/@types/node/perf_hooks.d.ts": [ + "../node_modules/@types/node/async_hooks.d.ts" + ], + "../node_modules/@types/node/process.d.ts": [ + "../node_modules/@types/node/tty.d.ts" + ], + "../node_modules/@types/node/readline.d.ts": [ + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/stream.d.ts" + ], + "../node_modules/@types/node/repl.d.ts": [ + "../node_modules/@types/node/readline.d.ts", + "../node_modules/@types/node/util.d.ts", + "../node_modules/@types/node/vm.d.ts" + ], + "../node_modules/@types/node/stream.d.ts": [ + "../node_modules/@types/node/events.d.ts" + ], + "../node_modules/@types/node/tls.d.ts": [ + "../node_modules/@types/node/crypto.d.ts", + "../node_modules/@types/node/dns.d.ts", + "../node_modules/@types/node/net.d.ts", + "../node_modules/@types/node/stream.d.ts" + ], + "../node_modules/@types/node/ts3.4/base.d.ts": [ + "../node_modules/@types/node/async_hooks.d.ts", + "../node_modules/@types/node/buffer.d.ts", + "../node_modules/@types/node/child_process.d.ts", + "../node_modules/@types/node/cluster.d.ts", + "../node_modules/@types/node/console.d.ts", + "../node_modules/@types/node/constants.d.ts", + "../node_modules/@types/node/crypto.d.ts", + "../node_modules/@types/node/dgram.d.ts", + "../node_modules/@types/node/dns.d.ts", + "../node_modules/@types/node/domain.d.ts", + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/fs.d.ts", + "../node_modules/@types/node/fs/promises.d.ts", + "../node_modules/@types/node/globals.d.ts", + "../node_modules/@types/node/http.d.ts", + "../node_modules/@types/node/http2.d.ts", + "../node_modules/@types/node/https.d.ts", + "../node_modules/@types/node/inspector.d.ts", + "../node_modules/@types/node/module.d.ts", + "../node_modules/@types/node/net.d.ts", + "../node_modules/@types/node/os.d.ts", + "../node_modules/@types/node/path.d.ts", + "../node_modules/@types/node/perf_hooks.d.ts", + "../node_modules/@types/node/process.d.ts", + "../node_modules/@types/node/punycode.d.ts", + "../node_modules/@types/node/querystring.d.ts", + "../node_modules/@types/node/readline.d.ts", + "../node_modules/@types/node/repl.d.ts", + "../node_modules/@types/node/stream.d.ts", + "../node_modules/@types/node/string_decoder.d.ts", + "../node_modules/@types/node/timers.d.ts", + "../node_modules/@types/node/tls.d.ts", + "../node_modules/@types/node/trace_events.d.ts", + "../node_modules/@types/node/tty.d.ts", + "../node_modules/@types/node/url.d.ts", + "../node_modules/@types/node/util.d.ts", + "../node_modules/@types/node/v8.d.ts", + "../node_modules/@types/node/vm.d.ts", + "../node_modules/@types/node/worker_threads.d.ts", + "../node_modules/@types/node/zlib.d.ts" + ], + "../node_modules/@types/node/ts3.6/base.d.ts": [ + "../node_modules/@types/node/globals.global.d.ts", + "../node_modules/@types/node/ts3.4/base.d.ts", + "../node_modules/@types/node/wasi.d.ts" + ], + "../node_modules/@types/node/tty.d.ts": [ + "../node_modules/@types/node/net.d.ts" + ], + "../node_modules/@types/node/url.d.ts": [ + "../node_modules/@types/node/querystring.d.ts" + ], + "../node_modules/@types/node/v8.d.ts": [ + "../node_modules/@types/node/stream.d.ts" + ], + "../node_modules/@types/node/worker_threads.d.ts": [ + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/stream.d.ts", + "../node_modules/@types/node/url.d.ts", + "../node_modules/@types/node/vm.d.ts" + ], + "../node_modules/@types/node/zlib.d.ts": [ + "../node_modules/@types/node/stream.d.ts" + ], + "../node_modules/@types/tar-fs/index.d.ts": [ + "../node_modules/@types/node/fs.d.ts", + "../node_modules/@types/node/index.d.ts", + "../node_modules/@types/tar-stream/index.d.ts" + ], + "../node_modules/@types/tar-stream/index.d.ts": [ + "../node_modules/@types/node/index.d.ts", + "../node_modules/@types/node/stream.d.ts" + ], + "../src/common/index.ts": [ + "../node_modules/@types/node/http.d.ts" + ], + "../src/runtime/beforeexitlistener.ts": [ + "../src/common/index.ts" + ], + "../src/runtime/callbackcontext.ts": [ + "../src/common/index.ts", + "../src/runtimeclient/index.ts" + ], + "../src/runtime/index.ts": [ + "../src/runtime/runtime.ts" + ], + "../src/runtime/invokecontext.ts": [ + "../node_modules/@types/node/http.d.ts", + "../src/common/index.ts" + ], + "../src/runtime/runtime.ts": [ + "../src/common/index.ts", + "../src/runtimeclient/index.ts" + ], + "../src/runtimeclient/index.ts": [ + "../src/runtimeclient/runtimeclient.ts" + ], + "../src/runtimeclient/runtimeclient.ts": [ + "../node_modules/@types/node/http.d.ts", + "../node_modules/@types/node/url.d.ts", + "../src/common/index.ts" + ], + "../src/utils/userfunction.ts": [ + "../src/common/index.ts" + ] + }, + "semanticDiagnosticsPerFile": [ + "../node_modules/@types/color-name/index.d.ts", + "../node_modules/@types/dockerode/index.d.ts", + "../node_modules/@types/fs-extra/index.d.ts", + "../node_modules/@types/js-yaml/index.d.ts", + "../node_modules/@types/json-schema/index.d.ts", + "../node_modules/@types/json5/index.d.ts", + "../node_modules/@types/mocha/index.d.ts", + "../node_modules/@types/node/assert.d.ts", + "../node_modules/@types/node/async_hooks.d.ts", + "../node_modules/@types/node/base.d.ts", + "../node_modules/@types/node/buffer.d.ts", + "../node_modules/@types/node/child_process.d.ts", + "../node_modules/@types/node/cluster.d.ts", + "../node_modules/@types/node/console.d.ts", + "../node_modules/@types/node/constants.d.ts", + "../node_modules/@types/node/crypto.d.ts", + "../node_modules/@types/node/dgram.d.ts", + "../node_modules/@types/node/dns.d.ts", + "../node_modules/@types/node/domain.d.ts", + "../node_modules/@types/node/events.d.ts", + "../node_modules/@types/node/fs.d.ts", + "../node_modules/@types/node/fs/promises.d.ts", + "../node_modules/@types/node/globals.d.ts", + "../node_modules/@types/node/globals.global.d.ts", + "../node_modules/@types/node/http.d.ts", + "../node_modules/@types/node/http2.d.ts", + "../node_modules/@types/node/https.d.ts", + "../node_modules/@types/node/index.d.ts", + "../node_modules/@types/node/inspector.d.ts", + "../node_modules/@types/node/module.d.ts", + "../node_modules/@types/node/net.d.ts", + "../node_modules/@types/node/os.d.ts", + "../node_modules/@types/node/path.d.ts", + "../node_modules/@types/node/perf_hooks.d.ts", + "../node_modules/@types/node/process.d.ts", + "../node_modules/@types/node/punycode.d.ts", + "../node_modules/@types/node/querystring.d.ts", + "../node_modules/@types/node/readline.d.ts", + "../node_modules/@types/node/repl.d.ts", + "../node_modules/@types/node/stream.d.ts", + "../node_modules/@types/node/string_decoder.d.ts", + "../node_modules/@types/node/timers.d.ts", + "../node_modules/@types/node/tls.d.ts", + "../node_modules/@types/node/trace_events.d.ts", + "../node_modules/@types/node/ts3.4/base.d.ts", + "../node_modules/@types/node/ts3.6/base.d.ts", + "../node_modules/@types/node/tty.d.ts", + "../node_modules/@types/node/url.d.ts", + "../node_modules/@types/node/util.d.ts", + "../node_modules/@types/node/v8.d.ts", + "../node_modules/@types/node/vm.d.ts", + "../node_modules/@types/node/wasi.d.ts", + "../node_modules/@types/node/worker_threads.d.ts", + "../node_modules/@types/node/zlib.d.ts", + "../node_modules/@types/parse-json/index.d.ts", + "../node_modules/@types/tar-fs/index.d.ts", + "../node_modules/@types/tar-stream/index.d.ts", + "../node_modules/typescript/lib/lib.es2015.collection.d.ts", + "../node_modules/typescript/lib/lib.es2015.core.d.ts", + "../node_modules/typescript/lib/lib.es2015.d.ts", + "../node_modules/typescript/lib/lib.es2015.generator.d.ts", + "../node_modules/typescript/lib/lib.es2015.iterable.d.ts", + "../node_modules/typescript/lib/lib.es2015.promise.d.ts", + "../node_modules/typescript/lib/lib.es2015.proxy.d.ts", + "../node_modules/typescript/lib/lib.es2015.reflect.d.ts", + "../node_modules/typescript/lib/lib.es2015.symbol.d.ts", + "../node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts", + "../node_modules/typescript/lib/lib.es2016.array.include.d.ts", + "../node_modules/typescript/lib/lib.es2016.d.ts", + "../node_modules/typescript/lib/lib.es2017.d.ts", + "../node_modules/typescript/lib/lib.es2017.intl.d.ts", + "../node_modules/typescript/lib/lib.es2017.object.d.ts", + "../node_modules/typescript/lib/lib.es2017.sharedmemory.d.ts", + "../node_modules/typescript/lib/lib.es2017.string.d.ts", + "../node_modules/typescript/lib/lib.es2017.typedarrays.d.ts", + "../node_modules/typescript/lib/lib.es2018.asyncgenerator.d.ts", + "../node_modules/typescript/lib/lib.es2018.asynciterable.d.ts", + "../node_modules/typescript/lib/lib.es2018.d.ts", + "../node_modules/typescript/lib/lib.es2018.intl.d.ts", + "../node_modules/typescript/lib/lib.es2018.promise.d.ts", + "../node_modules/typescript/lib/lib.es2018.regexp.d.ts", + "../node_modules/typescript/lib/lib.es2020.bigint.d.ts", + "../node_modules/typescript/lib/lib.es5.d.ts", + "../node_modules/typescript/lib/lib.esnext.intl.d.ts", + "../src/common/index.ts", + "../src/errors/index.ts", + "../src/errors/xrayerror.ts", + "../src/index.ts", + "../src/runtime/beforeexitlistener.ts", + "../src/runtime/callbackcontext.ts", + "../src/runtime/index.ts", + "../src/runtime/invokecontext.ts", + "../src/runtime/runtime.ts", + "../src/runtimeclient/index.ts", + "../src/runtimeclient/runtimeclient.ts", + "../src/utils/logpatch.ts", + "../src/utils/userfunction.ts" + ] + }, + "version": "4.0.3" +} \ No newline at end of file diff --git a/lib/utils/LogPatch.d.ts b/lib/utils/LogPatch.d.ts new file mode 100644 index 0000000..bb5c55e --- /dev/null +++ b/lib/utils/LogPatch.d.ts @@ -0,0 +1,7 @@ +/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ +declare const _default: { + setCurrentRequestId: (id: any) => any; + patchConsole: () => void; +}; +export default _default; +//# sourceMappingURL=LogPatch.d.ts.map \ No newline at end of file diff --git a/lib/utils/LogPatch.d.ts.map b/lib/utils/LogPatch.d.ts.map new file mode 100644 index 0000000..35fbf2b --- /dev/null +++ b/lib/utils/LogPatch.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"LogPatch.d.ts","sourceRoot":"","sources":["../../src/utils/LogPatch.ts"],"names":[],"mappings":"AAEA,8EAA8E;;;;;AAsG9E,wBAGE"} \ No newline at end of file diff --git a/lib/utils/LogPatch.js b/lib/utils/LogPatch.js new file mode 100644 index 0000000..9cb6ea4 --- /dev/null +++ b/lib/utils/LogPatch.js @@ -0,0 +1,118 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/* eslint-disable no-console */ +/** Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. */ +"use strict"; +var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + Object.defineProperty(o, k2, { enumerable: true, get: function() { return m[k]; } }); +}) : (function(o, m, k, k2) { + if (k2 === undefined) k2 = k; + o[k2] = m[k]; +})); +var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) { + Object.defineProperty(o, "default", { enumerable: true, value: v }); +}) : function(o, v) { + o["default"] = v; +}); +var __importStar = (this && this.__importStar) || function (mod) { + if (mod && mod.__esModule) return mod; + var result = {}; + if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k); + __setModuleDefault(result, mod); + return result; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +const fs = __importStar(require("fs")); +const util = __importStar(require("util")); +const levels = Object.freeze({ + INFO: { name: "INFO" }, + DEBUG: { name: "DEBUG" }, + WARN: { name: "WARN" }, + ERROR: { name: "ERROR" }, + TRACE: { name: "TRACE" }, + FATAL: { name: "FATAL" }, +}); +/* Use a unique symbol to provide global access without risk of name clashes. */ +const REQUEST_ID_SYMBOL = Symbol.for("aws.lambda.runtime.requestId"); +const _currentRequestId = { + get: () => global[REQUEST_ID_SYMBOL], + set: (id) => (global[REQUEST_ID_SYMBOL] = id), +}; +/** + * Write logs to stdout. + */ +const _logToStdout = (level, message) => { + const time = new Date().toISOString(); + const requestId = _currentRequestId.get(); + let line = `${time}\t${requestId}\t${level.name}\t${message}`; + line = line.replace(/\n/g, "\r"); + process.stdout.write(line + "\n"); +}; +/** + * Write logs to filedescriptor. + * Implements the logging contract between runtimes and the platform. + * Each entry is framed as: + * +----------------------+------------------------+-----------------------+ + * | Frame Type - 4 bytes | Length (len) - 4 bytes | Message - 'len' bytes | + * +----------------------+------------------------+-----------------------+ + * The frist 4 bytes are the frame type. For logs this is always 0xa55a0001. + * The second 4 bytes are the length of the message. + * The remaining bytes ar ethe message itself. Byte order is big-endian. + */ +const _logToFd = function (logTarget) { + const typeAndLength = Buffer.alloc(8); + typeAndLength.writeUInt32BE(0xa55a0001, 0); + typeAndLength.writeUInt32BE(0x00000000, 4); + return (level, message) => { + const time = new Date().toISOString(); + const requestId = _currentRequestId.get(); + const enrichedMessage = `${time}\t${requestId}\t${level.name}\t${message}\n`; + const messageBytes = Buffer.from(enrichedMessage, "utf8"); + typeAndLength.writeInt32BE(messageBytes.length, 4); + fs.writeSync(logTarget, typeAndLength); + fs.writeSync(logTarget, messageBytes); + }; +}; +/** + * Replace console functions with a log function. + * @param {Function(level, String)} log + */ +function _patchConsoleWith(log) { + console.log = (msg, ...params) => { + log(levels.INFO, util.format(msg, ...params)); + }; + console.debug = (msg, ...params) => { + log(levels.DEBUG, util.format(msg, ...params)); + }; + console.info = (msg, ...params) => { + log(levels.INFO, util.format(msg, ...params)); + }; + console.warn = (msg, ...params) => { + log(levels.WARN, util.format(msg, ...params)); + }; + console.error = (msg, ...params) => { + log(levels.ERROR, util.format(msg, ...params)); + }; + console.trace = (msg, ...params) => { + log(levels.TRACE, util.format(msg, ...params)); + }; + console.fatal = (msg, ...params) => { + log(levels.FATAL, util.format(msg, ...params)); + }; +} +const _patchConsole = () => { + if (process.env["_LAMBDA_TELEMETRY_LOG_FD"] != null && + process.env["_LAMBDA_TELEMETRY_LOG_FD"] != undefined) { + const logFd = parseInt(process.env["_LAMBDA_TELEMETRY_LOG_FD"]); + _patchConsoleWith(_logToFd(logFd)); + delete process.env["_LAMBDA_TELEMETRY_LOG_FD"]; + } + else { + _patchConsoleWith(_logToStdout); + } +}; +exports.default = { + setCurrentRequestId: _currentRequestId.set, + patchConsole: _patchConsole, +}; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiTG9nUGF0Y2guanMiLCJzb3VyY2VSb290IjoiIiwic291cmNlcyI6WyIuLi8uLi9zcmMvdXRpbHMvTG9nUGF0Y2gudHMiXSwibmFtZXMiOltdLCJtYXBwaW5ncyI6IkFBQUEsdURBQXVEO0FBQ3ZELCtCQUErQjtBQUMvQiw4RUFBOEU7QUFFOUUsWUFBWSxDQUFDOzs7Ozs7Ozs7Ozs7Ozs7Ozs7Ozs7QUFFYix1Q0FBeUI7QUFDekIsMkNBQTZCO0FBRTdCLE1BQU0sTUFBTSxHQUFHLE1BQU0sQ0FBQyxNQUFNLENBQUM7SUFDM0IsSUFBSSxFQUFFLEVBQUUsSUFBSSxFQUFFLE1BQU0sRUFBRTtJQUN0QixLQUFLLEVBQUUsRUFBRSxJQUFJLEVBQUUsT0FBTyxFQUFFO0lBQ3hCLElBQUksRUFBRSxFQUFFLElBQUksRUFBRSxNQUFNLEVBQUU7SUFDdEIsS0FBSyxFQUFFLEVBQUUsSUFBSSxFQUFFLE9BQU8sRUFBRTtJQUN4QixLQUFLLEVBQUUsRUFBRSxJQUFJLEVBQUUsT0FBTyxFQUFFO0lBQ3hCLEtBQUssRUFBRSxFQUFFLElBQUksRUFBRSxPQUFPLEVBQUU7Q0FDekIsQ0FBQyxDQUFDO0FBRUgsZ0ZBQWdGO0FBQ2hGLE1BQU0saUJBQWlCLEdBQUcsTUFBTSxDQUFDLEdBQUcsQ0FBQyw4QkFBOEIsQ0FBQyxDQUFDO0FBQ3JFLE1BQU0saUJBQWlCLEdBQUc7SUFDeEIsR0FBRyxFQUF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0FBSyxFQUFFLElBQUksQ0FBQyxNQUFNLENBQUMsR0FBRyxFQUFFLEdBQUcsTUFBTSxDQUFDLENBQUMsQ0FBQztJQUNqRCxDQUFDLENBQUM7QUFDSixDQUFDO0FBRUQsTUFBTSxhQUFhLEdBQUcsR0FBUyxFQUFFO0lBQy9CLElBQ0UsT0FBTyxDQUFDLEdBQUcsQ0FBQywwQkFBMEIsQ0FBQyxJQUFJLElBQUk7UUFDL0MsT0FBTyxDQUFDLEdBQUcsQ0FBQywwQkFBMEIsQ0FBQyxJQUFJLFNBQVMsRUFDcEQ7UUFDQSxNQUFNLEtBQUssR0FBRyxRQUFRLENBQUMsT0FBTyxDQUFDLEdBQUcsQ0FBQywwQkFBMEIsQ0FBQyxDQUFDLENBQUM7UUFDaEUsaUJBQWlCLENBQUMsUUFBUSxDQUFDLEtBQUssQ0FBQyxDQUFDLENBQUM7UUFDbkMsT0FBTyxPQUFPLENBQUMsR0FBRyxDQUFDLDBCQUEwQixDQUFDLENBQUM7S0FDaEQ7U0FBTTtRQUNMLGlCQUFpQixDQUFDLFlBQVksQ0FBQyxDQUFDO0tBQ2pDO0FBQ0gsQ0FBQyxDQUFDO0FBRUYsa0JBQWU7SUFDYixtQkFBbUIsRUFBRSxpQkFBaUIsQ0FBQyxHQUFHO0lBQzFDLFlBQVksRUFBRSxhQUFhO0NBQzVCLENBQUMifQ== \ No newline at end of file diff --git a/lib/utils/UserFunction.d.ts b/lib/utils/UserFunction.d.ts new file mode 100644 index 0000000..78e2df8 --- /dev/null +++ b/lib/utils/UserFunction.d.ts @@ -0,0 +1,28 @@ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * This module defines the functions for loading the user's code as specified + * in a handler string. + */ +import { HandlerFunction } from "../Common"; +/** + * Load the user's function with the approot and the handler string. + * @param appRoot {string} + * The path to the application root. + * @param handlerString {string} + * The user-provided handler function in the form 'module.function'. + * @return userFuction {function} + * The user's handler function. This function will be passed the event body, + * the context object, and the callback function. + * @throws In five cases:- + * 1 - if the handler string is incorrectly formatted an error is thrown + * 2 - if the module referenced by the handler cannot be loaded + * 3 - if the function in the handler does not exist in the module + * 4 - if a property with the same name, but isn't a function, exists on the + * module + * 5 - the handler includes illegal character sequences (like relative paths + * for traversing up the filesystem '..') + * Errors for scenarios known by the runtime, will be wrapped by Runtime.* errors. + */ +export declare const load: (appRoot: string, fullHandlerString: string) => HandlerFunction; +//# sourceMappingURL=UserFunction.d.ts.map \ No newline at end of file diff --git a/lib/utils/UserFunction.d.ts.map b/lib/utils/UserFunction.d.ts.map new file mode 100644 index 0000000..f649d92 --- /dev/null +++ b/lib/utils/UserFunction.d.ts.map @@ -0,0 +1 @@ +{"version":3,"file":"UserFunction.d.ts","sourceRoot":"","sources":["../../src/utils/UserFunction.ts"],"names":[],"mappings":"AACA;;;;;GAKG;AAMH,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AA4G5C;;;;;;;;;;;;;;;;;;GAkBG;AACH,eAAO,MAAM,IAAI,YACN,MAAM,qBACI,MAAM,KACxB,eAsBF,CAAC"} \ No newline at end of file diff --git a/lib/utils/UserFunction.js b/lib/utils/UserFunction.js new file mode 100644 index 0000000..8727797 --- /dev/null +++ b/lib/utils/UserFunction.js @@ -0,0 +1,137 @@ +/* eslint-disable @typescript-eslint/no-explicit-any */ +/** + * Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * This module defines the functions for loading the user's code as specified + * in a handler string. + */ +"use strict"; +var __importDefault = (this && this.__importDefault) || function (mod) { + return (mod && mod.__esModule) ? mod : { "default": mod }; +}; +Object.defineProperty(exports, "__esModule", { value: true }); +exports.load = void 0; +const path_1 = __importDefault(require("path")); +const fs_1 = __importDefault(require("fs")); +const Errors_1 = require("../Errors"); +const FUNCTION_EXPR = /^([^.]*)\.(.*)$/; +const RELATIVE_PATH_SUBSTRING = ".."; +/** + * Break the full handler string into two pieces, the module root and the actual + * handler string. + * Given './somepath/something/module.nestedobj.handler' this returns + * ['./somepath/something', 'module.nestedobj.handler'] + */ +function _moduleRootAndHandler(fullHandlerString) { + const handlerString = path_1.default.basename(fullHandlerString); + const moduleRoot = fullHandlerString.substring(0, fullHandlerString.indexOf(handlerString)); + return [moduleRoot, handlerString]; +} +/** + * Split the handler string into two pieces: the module name and the path to + * the handler function. + */ +function _splitHandlerString(handler) { + const match = handler.match(FUNCTION_EXPR); + if (!match || match.length != 3) { + throw new Errors_1.MalformedHandlerName("Bad handler"); + } + return [match[1], match[2]]; // [module, function-path] +} +/** + * Resolve the user's handler function from the module. + */ +function _resolveHandler(object, nestedProperty) { + return nestedProperty.split(".").reduce((nested, key) => { + return nested && nested[key]; + }, object); +} +/** + * Verify that the provided path can be loaded as a file per: + * https://nodejs.org/dist/latest-v10.x/docs/api/modules.html#modules_all_together + * @param string - the fully resolved file path to the module + * @return bool + */ +function _canLoadAsFile(modulePath) { + return fs_1.default.existsSync(modulePath) || fs_1.default.existsSync(modulePath + ".js"); +} +/** + * Attempt to load the user's module. + * Attempts to directly resolve the module relative to the application root, + * then falls back to the more general require(). + */ +function _tryRequire(appRoot, moduleRoot, module) { + const lambdaStylePath = path_1.default.resolve(appRoot, moduleRoot, module); + if (_canLoadAsFile(lambdaStylePath)) { + return require(lambdaStylePath); + } + else { + // Why not just require(module)? + // Because require() is relative to __dirname, not process.cwd() + const nodeStylePath = require.resolve(module, { + paths: [appRoot, moduleRoot], + }); + return require(nodeStylePath); + } +} +/** + * Load the user's application or throw a descriptive error. + * @throws Runtime errors in two cases + * 1 - UserCodeSyntaxError if there's a syntax error while loading the module + * 2 - ImportModuleError if the module cannot be found + */ +function _loadUserApp(appRoot, moduleRoot, module) { + try { + return _tryRequire(appRoot, moduleRoot, module); + } + catch (e) { + if (e instanceof SyntaxError) { + throw new Errors_1.UserCodeSyntaxError(e.message); + } + else if (e.code !== undefined && e.code === "MODULE_NOT_FOUND") { + throw new Errors_1.ImportModuleError(e); + } + else { + throw e; + } + } +} +function _throwIfInvalidHandler(fullHandlerString) { + if (fullHandlerString.includes(RELATIVE_PATH_SUBSTRING)) { + throw new Errors_1.MalformedHandlerName(`'${fullHandlerString}' is not a valid handler name. Use absolute paths when specifying root directories in handler names.`); + } +} +/** + * Load the user's function with the approot and the handler string. + * @param appRoot {string} + * The path to the application root. + * @param handlerString {string} + * The user-provided handler function in the form 'module.function'. + * @return userFuction {function} + * The user's handler function. This function will be passed the event body, + * the context object, and the callback function. + * @throws In five cases:- + * 1 - if the handler string is incorrectly formatted an error is thrown + * 2 - if the module referenced by the handler cannot be loaded + * 3 - if the function in the handler does not exist in the module + * 4 - if a property with the same name, but isn't a function, exists on the + * module + * 5 - the handler includes illegal character sequences (like relative paths + * for traversing up the filesystem '..') + * Errors for scenarios known by the runtime, will be wrapped by Runtime.* errors. + */ +exports.load = function (appRoot, fullHandlerString) { + _throwIfInvalidHandler(fullHandlerString); + const [moduleRoot, moduleAndHandler] = _moduleRootAndHandler(fullHandlerString); + const [module, handlerPath] = _splitHandlerString(moduleAndHandler); + const userApp = _loadUserApp(appRoot, moduleRoot, module); + const handlerFunc = _resolveHandler(userApp, handlerPath); + if (!handlerFunc) { + throw new Errors_1.HandlerNotFound(`${fullHandlerString} is undefined or not exported`); + } + if (typeof handlerFunc !== "function") { + throw new Errors_1.HandlerNotFound(`${fullHandlerString} is not a function`); + } + return handlerFunc; +}; +//# sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiVXNlckZ1bmN0aW9uLmpzIiwic291cmNlUm9vdCI6IiIsInNvdXJjZXMiOlsiLi4vLi4vc3JjL3V0aWxzL1VzZXJGdW5jdGlvbi50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSx1REFBdUQ7QUFDdkQ7Ozs7O0dBS0c7QUFFSCxZQUFZLENBQUM7Ozs7OztBQUViLGdEQUF3QjtBQUN4Qiw0Q0FBb0I7QUFFcEIsc0NBS21CO0FBRW5CLE1BQU0sYUFBYSxHQUFHLGlCQU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BZSxDQUN2QixHQUFHLGlCQUFpQiwrQkFBK0IsQ0FDcEQsQ0FBQztLQUNIO0lBRUQsSUFBSSxPQUFPLFdBQVcsS0FBSyxVQUFVLEVBQUU7UUFDckMsTUFBTSxJQUFJLHdCQUFlLENBQUMsR0FBRyxpQkFBaUIsb0JBQW9CLENBQUMsQ0FBQztLQUNyRTtJQUVELE9BQU8sV0FBVyxDQUFDO0FBQ3JCLENBQUMsQ0FBQyJ9 \ No newline at end of file diff --git a/scripts/postinstall.sh b/scripts/postinstall.sh index 6c4c9b4..62ec132 100755 --- a/scripts/postinstall.sh +++ b/scripts/postinstall.sh @@ -2,11 +2,7 @@ # Copyright 2019 Amazon.com, Inc. or its affiliates. All Rights Reserved. set -e -if [ "$(uname)" = "Darwin" ]; then - echo "aws-lambda-cpp does not build on OS X. Skipping the postinstall step." -else - npm run build:gyp -fi +npm run build:gyp # If the path of this file ends in "node_modules/aws-lambda-ric/scripts" # the package is being installed as a dependency and we can clean the deps folder. diff --git a/scripts/preinstall.sh b/scripts/preinstall.sh index cdc655d..7a094f2 100755 --- a/scripts/preinstall.sh +++ b/scripts/preinstall.sh @@ -4,47 +4,43 @@ set -e ARTIFACTS_DIR=$(pwd)/deps/artifacts -if [ "$(uname)" = "Darwin" ]; then - echo "aws-lambda-cpp does not build on OS X. Skipping the preinstall step." +if [ -x "$(command -v cmake3)" ]; then + CMAKE=cmake3 +elif [ -x "$(command -v cmake)" ]; then + CMAKE=cmake else - if [ -x "$(command -v cmake3)" ]; then - CMAKE=cmake3 - elif [ -x "$(command -v cmake)" ]; then - CMAKE=cmake - else - echo 'Error: cmake is not installed.' >&2 - exit 1 - fi + echo 'Error: cmake is not installed.' >&2 + exit 1 +fi - cd deps - . ./versions +cd deps +. ./versions - # unpack dependencies - tar xzf ./curl-$CURL_VERSION.tar.gz && \ - tar xzf ./aws-lambda-cpp-$AWS_LAMBDA_CPP_RELEASE.tar.gz +# unpack dependencies +tar xzf ./curl-$CURL_VERSION.tar.gz && \ +tar xzf ./aws-lambda-cpp-$AWS_LAMBDA_CPP_RELEASE.tar.gz - ( - # Build Curl - cd curl-curl-$CURL_VERSION && \ - ./buildconf && \ - ./configure \ - --prefix "$ARTIFACTS_DIR" \ - --disable-shared \ - --without-ssl \ - --without-zlib && \ - make && \ - make install - ) +( + # Build Curl + cd curl-curl-$CURL_VERSION && \ + ./buildconf && \ + ./configure \ + --prefix "$ARTIFACTS_DIR" \ + --disable-shared \ + --without-ssl \ + --without-zlib && \ + make && \ + make install +) - ( - # Build aws-lambda-cpp - mkdir -p ./aws-lambda-cpp-$AWS_LAMBDA_CPP_RELEASE/build && \ - cd ./aws-lambda-cpp-$AWS_LAMBDA_CPP_RELEASE/build +( + # Build aws-lambda-cpp + mkdir -p ./aws-lambda-cpp-$AWS_LAMBDA_CPP_RELEASE/build && \ + cd ./aws-lambda-cpp-$AWS_LAMBDA_CPP_RELEASE/build - $CMAKE .. \ - -DCMAKE_CXX_FLAGS="-fPIC" \ - -DCMAKE_INSTALL_PREFIX="$ARTIFACTS_DIR" \ - -DCMAKE_MODULE_PATH="$ARTIFACTS_DIR"/lib/pkgconfig && \ - make && make install - ) -fi + $CMAKE .. \ + -DCMAKE_CXX_FLAGS="-fPIC" \ + -DCMAKE_INSTALL_PREFIX="$ARTIFACTS_DIR" \ + -DCMAKE_MODULE_PATH="$ARTIFACTS_DIR"/lib/pkgconfig && \ + make && make install +) diff --git a/scripts/update_dependencies.sh b/scripts/update_dependencies.sh index 3c087af..a4ae96a 100755 --- a/scripts/update_dependencies.sh +++ b/scripts/update_dependencies.sh @@ -22,7 +22,8 @@ wget -c https://github.com/awslabs/aws-lambda-cpp/archive/v$AWS_LAMBDA_CPP_RELEA patch -p1 < ../patches/aws-lambda-cpp-posting-init-errors.patch && \ patch -p1 < ../patches/aws-lambda-cpp-make-the-runtime-client-user-agent-overrideable.patch && \ patch -p1 < ../patches/aws-lambda-cpp-make-lto-optional.patch && \ - patch -p1 < ../patches/aws-lambda-cpp-add-content-type.patch + patch -p1 < ../patches/aws-lambda-cpp-add-content-type.patch && \ + patch -p1 < ../patches/aws-lambda-cpp-macos-fixes.patch ) # Pack again and remove the folder