Skip to content

Commit 1d7ad61

Browse files
authored
feat(internal): support Middy.js 5.x (#2748)
1 parent 12f8e5f commit 1d7ad61

16 files changed

+163
-21
lines changed

Diff for: docs/core/logger.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ This functionality will include the following keys in your structured logs:
111111
=== "Middy Middleware"
112112

113113
!!! tip "A note about Middy"
114-
We guarantee support only for Middy.js `v4.x`, that you can install it by running `npm i @middy/core@~4`.
114+
We guarantee support for both Middy.js `v4.x` & `v5.x` with the latter being available only if you are using ES modules.
115115
Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}.
116116

117117
```typescript hl_lines="2 14"

Diff for: docs/core/metrics.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -199,7 +199,7 @@ You can add default dimensions to your metrics by passing them as parameters in
199199
=== "Middy middleware"
200200

201201
!!! tip "A note about Middy"
202-
Currently we support up to Middy `v4.x` that you can install it by running `npm i @middy/core@~4`.
202+
We guarantee support for both Middy.js `v4.x` & `v5.x` with the latter being available only if you are using ES modules.
203203
Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}.
204204

205205
```typescript hl_lines="24-26"

Diff for: docs/core/tracer.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ You can quickly start by importing the `Tracer` class, initialize it outside the
154154
=== "Middy Middleware"
155155

156156
!!! tip "A note about Middy"
157-
We guarantee support only for Middy.js `v4.x`, that you can install it by running `npm i @middy/core@~4`.
157+
We guarantee support for both Middy.js `v4.x` & `v5.x` with the latter being available only if you are using ES modules.
158158
Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}.
159159

160160
```typescript hl_lines="2 15 17"

Diff for: docs/index.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ aws lambda get-layer-version-by-arn --arn arn:aws:lambda:{aws::region}:094274105
299299

300300
Many of the utilities provided by Powertools for AWS Lambda (TypeScript) can be used with different programming paradigms:
301301

302-
- **Middy** middleware. It is the best choice if your existing code base relies on the [Middy 4.x](https://middy.js.org/docs/) middleware engine. Powertools for AWS Lambda (TypeScript) offers compatible Middy middleware to make this integration seamless.
302+
- **Middy** middleware. It is the best choice if your existing code base relies on the [Middy.js](https://middy.js.org/docs/) middleware engine. Powertools for AWS Lambda (TypeScript) offers compatible Middy middleware to make this integration seamless.
303303
- **Method decorator**. Use [TypeScript method decorators](https://www.typescriptlang.org/docs/handbook/decorators.html#method-decorators) if you prefer writing your business logic using [TypeScript Classes](https://www.typescriptlang.org/docs/handbook/classes.html). If you aren’t using Classes, this requires the most significant refactoring.
304304
- **Manually**. It provides the most granular control. It’s the most verbose approach, with the added benefit of no additional dependency and no refactoring to TypeScript Classes.
305305

Diff for: docs/utilities/idempotency.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,7 @@ The configuration options for the `@idempotent` decorator are the same as the on
189189
### MakeHandlerIdempotent Middy middleware
190190

191191
!!! tip "A note about Middy"
192-
Currently we support Middy up to `v4.x` that you can install it by running `npm i @middy/core@~4`.
192+
We guarantee support for both Middy.js `v4.x` & `v5.x` with the latter being available only if you are using ES modules.
193193
Check their docs to learn more about [Middy and its middleware stack](https://middy.js.org/docs/intro/getting-started){target="_blank"} as well as [best practices when working with Powertools](https://middy.js.org/docs/integrations/lambda-powertools#best-practices){target="_blank"}.
194194

195195
If you are using [Middy.js](https://middy.js.org){target="_blank"} as your middleware engine, you can use the `makeHandlerIdempotent` middleware to make your Lambda handler idempotent.

Diff for: package-lock.json

+138-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Diff for: package.json

+2-1
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
},
5050
"homepage": "https://github.com/aws-powertools/powertools-lambda-typescript#readme",
5151
"devDependencies": {
52-
"@middy/core": "^4.7.0",
5352
"@types/aws-lambda": "^8.10.140",
5453
"@types/jest": "^29.5.12",
5554
"@types/node": "^20.14.9",
@@ -67,6 +66,8 @@
6766
"lerna": "8.1.2",
6867
"lint-staged": "^15.2.7",
6968
"markdownlint-cli2": "^0.13.0",
69+
"middy4": "npm:@middy/core@^4.7.0",
70+
"middy5": "npm:@middy/core@^5.4.3",
7071
"prettier": "^3.3.2",
7172
"ts-jest": "^29.1.5",
7273
"ts-node": "^10.9.2",

Diff for: packages/idempotency/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@
102102
"peerDependencies": {
103103
"@aws-sdk/client-dynamodb": ">=3.x",
104104
"@aws-sdk/lib-dynamodb": ">=3.x",
105-
"@middy/core": ">=3.x"
105+
"@middy/core": "4.x || 5.x"
106106
},
107107
"peerDependenciesMeta": {
108108
"@aws-sdk/client-dynamodb": {

Diff for: packages/logger/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@
6666
"@types/lodash.merge": "^4.6.9"
6767
},
6868
"peerDependencies": {
69-
"@middy/core": ">=3.x"
69+
"@middy/core": "4.x || 5.x"
7070
},
7171
"peerDependenciesMeta": {
7272
"@middy/core": {

Diff for: packages/logger/tests/e2e/basicFeatures.middy.test.FunctionCode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Logger } from '../../src/index.js';
22
import { injectLambdaContext } from '../../src/middleware/middy.js';
33
import type { Context, APIGatewayAuthorizerResult } from 'aws-lambda';
44
import type { TestEvent, TestOutput } from '../helpers/types.js';
5-
import middy from '@middy/core';
5+
import middy from 'middy5';
66

77
const PERSISTENT_KEY = process.env.PERSISTENT_KEY || 'persistentKey';
88
const PERSISTENT_VALUE = process.env.PERSISTENT_VALUE || 'persistentValue';

Diff for: packages/logger/tests/e2e/logEventEnvVarSetting.middy.test.FunctionCode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import { Logger } from '../../src/index.js';
22
import { injectLambdaContext } from '../../src/middleware/middy.js';
33
import type { TestEvent, TestOutput } from '../helpers/types.js';
44
import type { Context } from 'aws-lambda';
5-
import middy from '@middy/core';
5+
import middy from 'middy4';
66

77
const logger = new Logger();
88

Diff for: packages/metrics/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@
6767
"promise-retry": "^2.0.1"
6868
},
6969
"peerDependencies": {
70-
"@middy/core": ">=3.x"
70+
"@middy/core": "4.x || 5.x"
7171
},
7272
"peerDependenciesMeta": {
7373
"@middy/core": {

Diff for: packages/parameters/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@
172172
"@aws-sdk/client-secrets-manager": ">=3.x",
173173
"@aws-sdk/client-ssm": ">=3.x",
174174
"@aws-sdk/util-dynamodb": ">=3.x",
175-
"@middy/core": ">=3.x"
175+
"@middy/core": "4.x || 5.x"
176176
},
177177
"peerDependenciesMeta": {
178178
"@middy/core": {

Diff for: packages/parser/package.json

+10-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,16 @@
117117
"nodejs"
118118
],
119119
"peerDependencies": {
120-
"zod": ">=3.x"
120+
"zod": ">=3.x",
121+
"@middy/core": "4.x || 5.x"
122+
},
123+
"peerDependenciesMeta": {
124+
"zod": {
125+
"optional": true
126+
},
127+
"@middy/core": {
128+
"optional": true
129+
}
121130
},
122131
"devDependencies": {
123132
"@anatine/zod-mock": "^3.13.3",

Diff for: packages/tracer/package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
"promise-retry": "^2.0.1"
3636
},
3737
"peerDependencies": {
38-
"@middy/core": ">=3.x"
38+
"@middy/core": "4.x || 5.x"
3939
},
4040
"peerDependenciesMeta": {
4141
"@middy/core": {

Diff for: packages/tracer/tests/e2e/allFeatures.middy.test.functionCode.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import middy from '@middy/core';
1+
import middy from 'middy5';
22
import { Tracer } from '../../src/index.js';
33
import { captureLambdaHandler } from '../../src/middleware/middy.js';
44
import type { Context } from 'aws-lambda';

0 commit comments

Comments
 (0)