Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(internal): support Middy.js 5.x #2748

Merged
merged 4 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/core/logger.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ This functionality will include the following keys in your structured logs:
=== "Middy Middleware"

!!! tip "A note about Middy"
We guarantee support only for Middy.js `v4.x`, that you can install it by running `npm i @middy/core@~4`.
We guarantee support for both Middy.js `v4.x` & `v5.x` with the latter being available only if you are using ES modules.
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"}.

```typescript hl_lines="2 14"
Expand Down
2 changes: 1 addition & 1 deletion docs/core/metrics.md
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ You can add default dimensions to your metrics by passing them as parameters in
=== "Middy middleware"

!!! tip "A note about Middy"
Currently we support up to Middy `v4.x` that you can install it by running `npm i @middy/core@~4`.
We guarantee support for both Middy.js `v4.x` & `v5.x` with the latter being available only if you are using ES modules.
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"}.

```typescript hl_lines="24-26"
Expand Down
2 changes: 1 addition & 1 deletion docs/core/tracer.md
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,7 @@ You can quickly start by importing the `Tracer` class, initialize it outside the
=== "Middy Middleware"

!!! tip "A note about Middy"
We guarantee support only for Middy.js `v4.x`, that you can install it by running `npm i @middy/core@~4`.
We guarantee support for both Middy.js `v4.x` & `v5.x` with the latter being available only if you are using ES modules.
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"}.

```typescript hl_lines="2 15 17"
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ aws lambda get-layer-version-by-arn --arn arn:aws:lambda:{aws::region}:094274105

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

- **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.
- **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.
- **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.
- **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.

Expand Down
2 changes: 1 addition & 1 deletion docs/utilities/idempotency.md
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@ The configuration options for the `@idempotent` decorator are the same as the on
### MakeHandlerIdempotent Middy middleware

!!! tip "A note about Middy"
Currently we support Middy up to `v4.x` that you can install it by running `npm i @middy/core@~4`.
We guarantee support for both Middy.js `v4.x` & `v5.x` with the latter being available only if you are using ES modules.
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"}.

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.
Expand Down
144 changes: 138 additions & 6 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@
},
"homepage": "https://github.com/aws-powertools/powertools-lambda-typescript#readme",
"devDependencies": {
"@middy/core": "^4.7.0",
"@types/aws-lambda": "^8.10.140",
"@types/jest": "^29.5.12",
"@types/node": "^20.14.9",
Expand All @@ -67,6 +66,8 @@
"lerna": "8.1.2",
"lint-staged": "^15.2.7",
"markdownlint-cli2": "^0.13.0",
"middy4": "npm:@middy/core@^4.7.0",
"middy5": "npm:@middy/core@^5.4.3",
"prettier": "^3.3.2",
"ts-jest": "^29.1.5",
"ts-node": "^10.9.2",
Expand Down
2 changes: 1 addition & 1 deletion packages/idempotency/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
"peerDependencies": {
"@aws-sdk/client-dynamodb": ">=3.x",
"@aws-sdk/lib-dynamodb": ">=3.x",
"@middy/core": ">=3.x"
"@middy/core": "4.x || 5.x"
},
"peerDependenciesMeta": {
"@aws-sdk/client-dynamodb": {
Expand Down
2 changes: 1 addition & 1 deletion packages/logger/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@
"@types/lodash.merge": "^4.6.9"
},
"peerDependencies": {
"@middy/core": ">=3.x"
"@middy/core": "4.x || 5.x"
},
"peerDependenciesMeta": {
"@middy/core": {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Logger } from '../../src/index.js';
import { injectLambdaContext } from '../../src/middleware/middy.js';
import type { Context, APIGatewayAuthorizerResult } from 'aws-lambda';
import type { TestEvent, TestOutput } from '../helpers/types.js';
import middy from '@middy/core';
import middy from 'middy5';

const PERSISTENT_KEY = process.env.PERSISTENT_KEY || 'persistentKey';
const PERSISTENT_VALUE = process.env.PERSISTENT_VALUE || 'persistentValue';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { Logger } from '../../src/index.js';
import { injectLambdaContext } from '../../src/middleware/middy.js';
import type { TestEvent, TestOutput } from '../helpers/types.js';
import type { Context } from 'aws-lambda';
import middy from '@middy/core';
import middy from 'middy4';

const logger = new Logger();

Expand Down
2 changes: 1 addition & 1 deletion packages/metrics/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@
"promise-retry": "^2.0.1"
},
"peerDependencies": {
"@middy/core": ">=3.x"
"@middy/core": "4.x || 5.x"
},
"peerDependenciesMeta": {
"@middy/core": {
Expand Down
2 changes: 1 addition & 1 deletion packages/parameters/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@
"@aws-sdk/client-secrets-manager": ">=3.x",
"@aws-sdk/client-ssm": ">=3.x",
"@aws-sdk/util-dynamodb": ">=3.x",
"@middy/core": ">=3.x"
"@middy/core": "4.x || 5.x"
},
"peerDependenciesMeta": {
"@middy/core": {
Expand Down
11 changes: 10 additions & 1 deletion packages/parser/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,16 @@
"nodejs"
],
"peerDependencies": {
"zod": ">=3.x"
"zod": ">=3.x",
"@middy/core": "4.x || 5.x"
},
"peerDependenciesMeta": {
"zod": {
"optional": true
},
"@middy/core": {
"optional": true
}
},
"devDependencies": {
"@anatine/zod-mock": "^3.13.3",
Expand Down
2 changes: 1 addition & 1 deletion packages/tracer/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
"promise-retry": "^2.0.1"
},
"peerDependencies": {
"@middy/core": ">=3.x"
"@middy/core": "4.x || 5.x"
},
"peerDependenciesMeta": {
"@middy/core": {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import middy from '@middy/core';
import middy from 'middy5';
import { Tracer } from '../../src/index.js';
import { captureLambdaHandler } from '../../src/middleware/middy.js';
import type { Context } from 'aws-lambda';
Expand Down