@middy/core 7.2.2 → 7.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/executionModeDurableContext.js +25 -9
- package/executionModeStandard.js +28 -10
- package/executionModeStreamifyResponse.js +17 -2
- package/index.d.ts +4 -0
- package/index.js +20 -1
- package/package.json +3 -15
|
@@ -25,15 +25,31 @@ export const executionModeDurableContext = (
|
|
|
25
25
|
);
|
|
26
26
|
copyKeys(request.context, request.context.lambdaContext, lambdaContextKeys);
|
|
27
27
|
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
28
|
+
// See executionModeStandard for the .cause-chaining rationale.
|
|
29
|
+
let handlerError;
|
|
30
|
+
let response;
|
|
31
|
+
try {
|
|
32
|
+
response = await runRequest(
|
|
33
|
+
request,
|
|
34
|
+
beforeMiddlewares,
|
|
35
|
+
lambdaHandler,
|
|
36
|
+
afterMiddlewares,
|
|
37
|
+
onErrorMiddlewares,
|
|
38
|
+
plugin,
|
|
39
|
+
);
|
|
40
|
+
} catch (err) {
|
|
41
|
+
handlerError = err;
|
|
42
|
+
}
|
|
43
|
+
try {
|
|
44
|
+
await plugin.requestEnd(request);
|
|
45
|
+
} catch (hookErr) {
|
|
46
|
+
if (handlerError) {
|
|
47
|
+
handlerError.cause ??= hookErr;
|
|
48
|
+
} else {
|
|
49
|
+
throw hookErr;
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
if (handlerError) throw handlerError;
|
|
37
53
|
return response;
|
|
38
54
|
});
|
|
39
55
|
middy.handler = (replaceLambdaHandler) => {
|
package/executionModeStandard.js
CHANGED
|
@@ -11,16 +11,34 @@ export const executionModeStandard = (
|
|
|
11
11
|
const middy = async (event, context) => {
|
|
12
12
|
const request = middyRequest(event, context);
|
|
13
13
|
plugin.requestStart(request);
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
14
|
+
// Run requestEnd without letting a throw in the hook replace the
|
|
15
|
+
// handler's original error. If only requestEnd throws, it propagates
|
|
16
|
+
// (same as a naive finally). If both throw, the hook error is attached
|
|
17
|
+
// as `.cause` on the handler error (only if no cause is already set).
|
|
18
|
+
let handlerError;
|
|
19
|
+
let response;
|
|
20
|
+
try {
|
|
21
|
+
response = await runRequest(
|
|
22
|
+
request,
|
|
23
|
+
beforeMiddlewares,
|
|
24
|
+
lambdaHandler,
|
|
25
|
+
afterMiddlewares,
|
|
26
|
+
onErrorMiddlewares,
|
|
27
|
+
plugin,
|
|
28
|
+
);
|
|
29
|
+
} catch (err) {
|
|
30
|
+
handlerError = err;
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
await plugin.requestEnd(request);
|
|
34
|
+
} catch (hookErr) {
|
|
35
|
+
if (handlerError) {
|
|
36
|
+
handlerError.cause ??= hookErr;
|
|
37
|
+
} else {
|
|
38
|
+
throw hookErr;
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
if (handlerError) throw handlerError;
|
|
24
42
|
return response;
|
|
25
43
|
};
|
|
26
44
|
middy.handler = (replaceLambdaHandler) => {
|
|
@@ -54,8 +54,23 @@ export const executionModeStreamifyResponse = (
|
|
|
54
54
|
});
|
|
55
55
|
}
|
|
56
56
|
|
|
57
|
-
|
|
58
|
-
|
|
57
|
+
// See executionModeStandard for the .cause-chaining rationale.
|
|
58
|
+
let handlerError;
|
|
59
|
+
try {
|
|
60
|
+
await pipeline(handlerStream, responseStream);
|
|
61
|
+
} catch (err) {
|
|
62
|
+
handlerError = err;
|
|
63
|
+
}
|
|
64
|
+
try {
|
|
65
|
+
await plugin.requestEnd(request);
|
|
66
|
+
} catch (hookErr) {
|
|
67
|
+
if (handlerError) {
|
|
68
|
+
handlerError.cause ??= hookErr;
|
|
69
|
+
} else {
|
|
70
|
+
throw hookErr;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
if (handlerError) throw handlerError;
|
|
59
74
|
},
|
|
60
75
|
);
|
|
61
76
|
|
package/index.d.ts
CHANGED
package/index.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// Copyright 2017 - 2026 will Farrell, Luciano Mammino, and Middy contributors.
|
|
2
2
|
// SPDX-License-Identifier: MIT
|
|
3
3
|
import { setTimeout } from "node:timers";
|
|
4
|
+
import { validateOptions } from "@middy/util";
|
|
4
5
|
import { executionModeStandard } from "./executionModeStandard.js";
|
|
5
6
|
|
|
6
7
|
const defaultLambdaHandler = () => {};
|
|
@@ -17,6 +18,23 @@ const defaultPluginConfig = {
|
|
|
17
18
|
executionMode: executionModeStandard,
|
|
18
19
|
};
|
|
19
20
|
|
|
21
|
+
const optionSchema = {
|
|
22
|
+
internal: "object?",
|
|
23
|
+
beforePrefetch: "function?",
|
|
24
|
+
requestStart: "function?",
|
|
25
|
+
beforeMiddleware: "function?",
|
|
26
|
+
afterMiddleware: "function?",
|
|
27
|
+
beforeHandler: "function?",
|
|
28
|
+
timeoutEarlyInMillis: "number?",
|
|
29
|
+
timeoutEarlyResponse: "function?",
|
|
30
|
+
afterHandler: "function?",
|
|
31
|
+
requestEnd: "function?",
|
|
32
|
+
executionMode: "function?",
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
export const middyValidateOptions = (options) =>
|
|
36
|
+
validateOptions("@middy/core", optionSchema, options);
|
|
37
|
+
|
|
20
38
|
export const middy = (setupLambdaHandler, pluginConfig) => {
|
|
21
39
|
let lambdaHandler;
|
|
22
40
|
let plugin;
|
|
@@ -183,7 +201,8 @@ const runRequest = async (
|
|
|
183
201
|
await runMiddlewares(request, onErrorMiddlewares, plugin);
|
|
184
202
|
} catch (err) {
|
|
185
203
|
// Save error that wasn't handled
|
|
186
|
-
err.originalError = request.error;
|
|
204
|
+
err.originalError = request.error; // TODO remove in v8, use cause
|
|
205
|
+
err.cause ??= request.error;
|
|
187
206
|
request.error = err;
|
|
188
207
|
|
|
189
208
|
throw request.error;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@middy/core",
|
|
3
|
-
"version": "7.
|
|
3
|
+
"version": "7.3.0",
|
|
4
4
|
"description": "🛵 The stylish Node.js middleware engine for AWS Lambda (core package)",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"engines": {
|
|
@@ -17,36 +17,24 @@
|
|
|
17
17
|
"import": {
|
|
18
18
|
"types": "./index.d.ts",
|
|
19
19
|
"default": "./index.js"
|
|
20
|
-
},
|
|
21
|
-
"require": {
|
|
22
|
-
"default": "./index.js"
|
|
23
20
|
}
|
|
24
21
|
},
|
|
25
22
|
"./Standard": {
|
|
26
23
|
"import": {
|
|
27
24
|
"types": "./executionModeStandard.d.ts",
|
|
28
25
|
"default": "./executionModeStandard.js"
|
|
29
|
-
},
|
|
30
|
-
"require": {
|
|
31
|
-
"default": "./executionModeStandard.js"
|
|
32
26
|
}
|
|
33
27
|
},
|
|
34
28
|
"./DurableContext": {
|
|
35
29
|
"import": {
|
|
36
30
|
"types": "./executionModeDurableContext.d.ts",
|
|
37
31
|
"default": "./executionModeDurableContext.js"
|
|
38
|
-
},
|
|
39
|
-
"require": {
|
|
40
|
-
"default": "./executionModeDurableContext.js"
|
|
41
32
|
}
|
|
42
33
|
},
|
|
43
34
|
"./StreamifyResponse": {
|
|
44
35
|
"import": {
|
|
45
36
|
"types": "./executionModeStreamifyResponse.d.ts",
|
|
46
37
|
"default": "./executionModeStreamifyResponse.js"
|
|
47
|
-
},
|
|
48
|
-
"require": {
|
|
49
|
-
"default": "./executionModeStreamifyResponse.js"
|
|
50
38
|
}
|
|
51
39
|
}
|
|
52
40
|
},
|
|
@@ -97,7 +85,7 @@
|
|
|
97
85
|
"url": "https://github.com/sponsors/willfarrell"
|
|
98
86
|
},
|
|
99
87
|
"dependencies": {
|
|
100
|
-
"@middy/util": "7.
|
|
88
|
+
"@middy/util": "7.3.0"
|
|
101
89
|
},
|
|
102
90
|
"peerDependencies": {
|
|
103
91
|
"@aws/durable-execution-sdk-js": "^1.0.0"
|
|
@@ -110,7 +98,7 @@
|
|
|
110
98
|
"devDependencies": {
|
|
111
99
|
"@aws/durable-execution-sdk-js": "^1.0.0",
|
|
112
100
|
"@aws/durable-execution-sdk-js-testing": "^1.0.0",
|
|
113
|
-
"@datastream/core": "0.
|
|
101
|
+
"@datastream/core": "0.3.2",
|
|
114
102
|
"@types/aws-lambda": "^8.0.0",
|
|
115
103
|
"@types/node": "^22.0.0"
|
|
116
104
|
}
|