@middy/core
Advanced tools
Comparing version 4.6.1 to 4.6.2
24
index.js
@@ -1,2 +0,2 @@ | ||
import { Readable } from 'node:stream'; | ||
/* global awslambda */ import { Readable } from 'node:stream'; | ||
import { pipeline } from 'node:stream/promises'; | ||
@@ -10,5 +10,6 @@ import { setTimeout } from 'node:timers/promises'; | ||
}, | ||
streamifyResponse: false | ||
streamifyResponse: false // Deprecate need for this when AWS provides a flag for when it's looking for it | ||
}; | ||
const middy = (lambdaHandler = defaultLambdaHandler, plugin = {})=>{ | ||
// Allow base handler to be set using .handler() | ||
if (typeof lambdaHandler !== 'function') { | ||
@@ -51,2 +52,3 @@ plugin = lambdaHandler; | ||
} | ||
// Source @datastream/core (MIT) | ||
let handlerStream; | ||
@@ -57,3 +59,4 @@ if (handlerBody._readableState) { | ||
function* iterator(input) { | ||
const size = 16384; | ||
const size = 16384 // 16 * 1024 // Node.js default | ||
; | ||
let position = 0; | ||
@@ -90,2 +93,3 @@ const length = input.length; | ||
}; | ||
// Inline Middlewares | ||
middy.before = (beforeMiddleware)=>{ | ||
@@ -111,5 +115,7 @@ beforeMiddlewares.push(beforeMiddleware); | ||
let timeoutAbort; | ||
const timeoutEarly = plugin.timeoutEarly && request.context.getRemainingTimeInMillis; | ||
const timeoutEarly = plugin.timeoutEarly && request.context.getRemainingTimeInMillis // disable when AWS context missing (tests, containers) | ||
; | ||
try { | ||
await runMiddlewares(request, beforeMiddlewares, plugin); | ||
// Check if before stack hasn't exit early | ||
if (typeof request.response === 'undefined') { | ||
@@ -130,3 +136,4 @@ plugin.beforeHandler?.(); | ||
]); | ||
timeoutAbort?.abort(); | ||
timeoutAbort?.abort() // lambdaHandler may not be a promise | ||
; | ||
plugin.afterHandler?.(); | ||
@@ -136,3 +143,5 @@ await runMiddlewares(request, afterMiddlewares, plugin); | ||
} catch (e) { | ||
timeoutAbort?.abort(); | ||
timeoutAbort?.abort() // timeout should be aborted on errors | ||
; | ||
// Reset response changes made by after stack before error thrown | ||
request.response = undefined; | ||
@@ -143,2 +152,3 @@ request.error = e; | ||
} catch (e) { | ||
// Save error that wasn't handled | ||
e.originalError = request.error; | ||
@@ -148,2 +158,3 @@ request.error = e; | ||
} | ||
// Catch if onError stack hasn't handled the error | ||
if (typeof request.response === 'undefined') throw request.error; | ||
@@ -160,2 +171,3 @@ } finally{ | ||
plugin.afterMiddleware?.(nextMiddleware.name); | ||
// short circuit chaining and respond early | ||
if (typeof res !== 'undefined') { | ||
@@ -162,0 +174,0 @@ request.response = res; |
{ | ||
"name": "@middy/core", | ||
"version": "4.6.1", | ||
"version": "4.6.2", | ||
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda (core package)", | ||
@@ -69,3 +69,3 @@ "type": "module", | ||
}, | ||
"gitHead": "253ed0e4ca95623decbade03938a07d837a1eba2" | ||
"gitHead": "8b03a01abf5a9c08231ec5ced775e87f8be8f67d" | ||
} |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
30695
683