forked from aws/aws-lambda-nodejs-runtime-interface-client
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.ts
84 lines (70 loc) · 2.2 KB
/
index.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/**
* 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<InvocationResponse>;
}
export 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 type ErrorStringOrUndefined = Error | string | undefined;
export type ErrorStringOrUndefinedOrNull = ErrorStringOrUndefined | null;
/**
*
*/
export interface ICallbackContext {
callbackWaitsForEmptyEventLoop: boolean;
succeed: (result: unknown) => void;
fail: (err: ErrorStringOrUndefinedOrNull) => void;
done: (err: ErrorStringOrUndefinedOrNull, result?: unknown) => void;
}
export 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 type HandlerFunction = (
body: unknown,
data: IEnvironmentData & IHeaderData,
callback: CallbackFunction
) => PromiseLike<unknown> | unknown;
export function isHandlerFunction(value: any): value is HandlerFunction {
return typeof value === "function";
}