Skip to content

Commit 84b6fd8

Browse files
authored
Merge pull request #1320 from middyjs/develop
6.2.2
2 parents a13ba2c + ebaedf6 commit 84b6fd8

File tree

43 files changed

+8150
-8871
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+8150
-8871
lines changed

package-lock.json

Lines changed: 7977 additions & 8757 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@middy/monorepo",
3-
"version": "6.2.1",
3+
"version": "6.2.2",
44
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda",
55
"private": true,
66
"type": "module",
@@ -13,10 +13,11 @@
1313
"preinstall": "npm link --workspaces",
1414
"git:pre-commit": "npm run git:lint-staged && npm run git:test-staged",
1515
"git:commit-msg": "commitlint --config commitlint.config.cjs --edit",
16-
"git:lint-staged": "biome check --staged --no-errors-on-unmatched --files-ignore-unknown=true",
16+
"git:lint-staged": "npm run test:lint",
1717
"git:test-staged": "node --test",
18+
"lint": "biome check --write --no-errors-on-unmatched --files-ignore-unknown=true",
1819
"test": "npm run test:lint && npm run test:unit && npm run test:types && npm run test:sast && npm run test:perf && npm run test:dast",
19-
"test:lint": "biome check --write --no-errors-on-unmatched --files-ignore-unknown=true",
20+
"test:lint": "biome check --staged --no-errors-on-unmatched --files-ignore-unknown=true",
2021
"test:unit": "node --test",
2122
"test:sast": "npm run test:sast:sandworm && npm run test:sast:semgrep && npm run test:sast:trufflehog",
2223
"test:sast:sandworm": "sandworm-audit --skip-all --show-tips false",
@@ -36,7 +37,7 @@
3637
"update": "npm update --workspaces && npm install --workspaces",
3738
"outdated": "npm outdated --workspaces",
3839
"audit": "npm audit fix --workspaces",
39-
"release:sync": "npm version $npm_package_version --workspaces && find ./packages -name \"package.json\" -exec sed -i '' -E \"s#\\\"@middy/(.*)\\\": ([^,]*)#\\\"@middy/\\1\\\": $(npm pkg get version)#g\" {} \\; && npm run rm:node_modules && npm link --workspaces && npm install && npm run test:lint",
40+
"release:sync": "npm version $npm_package_version --workspaces && find ./packages -name \"package.json\" -exec sed -i '' -E \"s#\\\"@middy/(.*)\\\": ([^,]*)#\\\"@middy/\\1\\\": $(npm pkg get version)#g\" {} \\; && npm run rm:node_modules && npm link --workspaces && npm install && npm run lint",
4041
"release:tag": "git tag $npm_package_version"
4142
},
4243
"repository": {
@@ -67,8 +68,6 @@
6768
"aws-sdk-client-mock": "^4.0.0",
6869
"fast-check": "^4.0.0",
6970
"husky": "^9.0.0",
70-
"lint-staged": "^15.0.0",
71-
"prettier": "^3.0.0",
7271
"tinybench": "^4.0.0",
7372
"tsd": "^0.32.0",
7473
"typescript": "^5.0.0"

packages/appconfig/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@middy/appconfig",
3-
"version": "6.2.1",
3+
"version": "6.2.2",
44
"description": "AppConfig middleware for the middy framework",
55
"type": "module",
66
"engines": {

packages/cloudformation-response/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@middy/cloudformation-response",
3-
"version": "6.2.1",
3+
"version": "6.2.2",
44
"description": "CloudFormation Custom Response event response handling for the middy framework",
55
"type": "module",
66
"engines": {
@@ -59,7 +59,7 @@
5959
"url": "https://github.com/sponsors/willfarrell"
6060
},
6161
"devDependencies": {
62-
"@middy/core": "6.2.1",
62+
"@middy/core": "6.2.2",
6363
"@types/aws-lambda": "^8.10.100"
6464
},
6565
"gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"

packages/cloudformation-router/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@middy/cloudformation-router",
3-
"version": "6.2.1",
3+
"version": "6.2.2",
44
"description": "CloudFormation Custom Response event router for the middy framework",
55
"type": "module",
66
"engines": {
@@ -60,7 +60,7 @@
6060
"url": "https://github.com/sponsors/willfarrell"
6161
},
6262
"devDependencies": {
63-
"@middy/core": "6.2.1",
63+
"@middy/core": "6.2.2",
6464
"@types/aws-lambda": "^8.10.100"
6565
},
6666
"gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431"

packages/cloudwatch-metrics/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@middy/cloudwatch-metrics",
3-
"version": "6.2.1",
3+
"version": "6.2.2",
44
"description": "Embedded CloudWatch metrics middleware for the middy framework",
55
"type": "module",
66
"engines": {

packages/core/index.js

Lines changed: 28 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -35,29 +35,28 @@ const middy = (setupLambdaHandler, pluginConfig) => {
3535
const afterMiddlewares = [];
3636
const onErrorMiddlewares = [];
3737

38-
const middyHandler = (event = {}, context = {}) => {
39-
plugin.requestStart?.();
40-
const request = {
38+
const middyRequest = (event = {}, context = {}) => {
39+
return {
4140
event,
4241
context,
4342
response: undefined,
4443
error: undefined,
4544
internal: plugin.internal ?? {},
4645
};
47-
48-
return runRequest(
49-
request,
50-
beforeMiddlewares,
51-
lambdaHandler,
52-
afterMiddlewares,
53-
onErrorMiddlewares,
54-
plugin,
55-
);
5646
};
5747
const middy = plugin.streamifyResponse
5848
? awslambda.streamifyResponse(
5949
async (event, lambdaResponseStream, context) => {
60-
const handlerResponse = await middyHandler(event, context);
50+
plugin.requestStart?.();
51+
const request = middyRequest(event, context);
52+
const handlerResponse = await runRequest(
53+
request,
54+
beforeMiddlewares,
55+
lambdaHandler,
56+
afterMiddlewares,
57+
onErrorMiddlewares,
58+
plugin,
59+
);
6160
let responseStream = lambdaResponseStream;
6261
let handlerBody = handlerResponse;
6362
if (handlerResponse.statusCode) {
@@ -89,9 +88,24 @@ const middy = (setupLambdaHandler, pluginConfig) => {
8988
}
9089

9190
await pipeline(handlerStream, responseStream);
91+
await plugin.requestEnd?.(request);
9292
},
9393
)
94-
: middyHandler;
94+
: async (event, context) => {
95+
plugin.requestStart?.();
96+
const request = middyRequest(event, context);
97+
98+
const response = await runRequest(
99+
request,
100+
beforeMiddlewares,
101+
lambdaHandler,
102+
afterMiddlewares,
103+
onErrorMiddlewares,
104+
plugin,
105+
);
106+
await plugin.requestEnd?.(request);
107+
return response;
108+
};
95109

96110
middy.use = (inputMiddleware) => {
97111
const middlewares = Array.isArray(inputMiddleware)
@@ -226,8 +240,6 @@ const runRequest = async (
226240
}
227241
// Catch if onError stack hasn't handled the error
228242
if (typeof request.response === "undefined") throw request.error;
229-
} finally {
230-
await plugin.requestEnd?.(request);
231243
}
232244

233245
return request.response;

packages/core/index.test.js

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,6 +1075,33 @@ test("Should trigger all plugin hooks", async (t) => {
10751075
equal(plugin.requestEnd.mock.callCount(), 1);
10761076
});
10771077

1078+
test("Should trigger requestEnd hook after stream ends", async (t) => {
1079+
const input = "x".repeat(1024 * 1024);
1080+
let streamEnd = false;
1081+
const handler = middy(
1082+
async (event, context, { signal }) => {
1083+
return pipejoin([
1084+
createReadableStream(input),
1085+
createPassThroughStream(
1086+
() => {},
1087+
() => {
1088+
streamEnd = true;
1089+
},
1090+
),
1091+
]);
1092+
},
1093+
{
1094+
streamifyResponse: true,
1095+
requestEnd: () => {
1096+
equal(streamEnd, true);
1097+
},
1098+
},
1099+
);
1100+
1101+
const { responseStream } = createResponseStreamMockAndCapture();
1102+
await handler(event, responseStream, context);
1103+
});
1104+
10781105
test("Should abort handler when timeout expires", async (t) => {
10791106
const plugin = {
10801107
timeoutEarlyInMillis: 1,

packages/core/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@middy/core",
3-
"version": "6.2.1",
3+
"version": "6.2.2",
44
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda (core package)",
55
"type": "module",
66
"engines": {

packages/do-not-wait-for-empty-event-loop/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@middy/do-not-wait-for-empty-event-loop",
3-
"version": "6.2.1",
3+
"version": "6.2.2",
44
"description": "Middleware for the middy framework that allows to easily disable the wait for empty event loop in a Lambda function",
55
"type": "module",
66
"engines": {
@@ -60,7 +60,7 @@
6060
},
6161
"gitHead": "7a6c0fbb8ab71d6a2171e678697de9f237568431",
6262
"devDependencies": {
63-
"@middy/core": "6.2.1",
63+
"@middy/core": "6.2.2",
6464
"@types/aws-lambda": "^8.10.76"
6565
}
6666
}

0 commit comments

Comments
 (0)