MCPcopy Index your code
hub / github.com/heygen-com/hyperframes / unwrapEvent

Function unwrapEvent

packages/aws-lambda/src/handler.ts:135–157  ·  view source on GitHub ↗
(event: LambdaEvent)

Source from the content-addressed store, hash-verified

133const MAX_ENVELOPE_DEPTH = 4;
134
135export function unwrapEvent(event: LambdaEvent): PlanEvent | RenderChunkEvent | AssembleEvent {
136 let cursor: LambdaEvent = event;
137 for (let i = 0; i < MAX_ENVELOPE_DEPTH; i++) {
138 if (cursor && typeof cursor === "object") {
139 const obj = cursor as Record<string, unknown>;
140 if (typeof obj.Action === "string" && isLambdaAction(obj.Action)) {
141 return cursor as PlanEvent | RenderChunkEvent | AssembleEvent;
142 }
143 if ("Payload" in obj) {
144 cursor = obj.Payload as LambdaEvent;
145 continue;
146 }
147 if ("Input" in obj) {
148 cursor = obj.Input as LambdaEvent;
149 continue;
150 }
151 }
152 break;
153 }
154 throw new Error(
155 `[handler] event has no recognised Action; unwrapped ${MAX_ENVELOPE_DEPTH} levels of Payload/Input without finding one.`,
156 );
157}
158
159function isLambdaAction(value: string): value is LambdaAction {
160 return value === "plan" || value === "renderChunk" || value === "assemble";

Callers 2

handlerFunction · 0.70
handler.test.tsFile · 0.70

Calls 1

isLambdaActionFunction · 0.85

Tested by

no test coverage detected