Skip to content

Commit

Permalink
merged update from v2
Browse files Browse the repository at this point in the history
  • Loading branch information
am29d committed Nov 10, 2023
2 parents 2b3317f + 3a072aa commit f54e1b5
Show file tree
Hide file tree
Showing 349 changed files with 5,655 additions and 7,551 deletions.
14 changes: 7 additions & 7 deletions .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
@@ -1,14 +1,14 @@
name: Bug report
description: Report a reproducible bug to help us improve
title: "Bug: TITLE"
labels: ["type/bug", "triage"]
projects: ["aws-powertools/7"]
title: 'Bug: TITLE'
labels: ['type/bug', 'triage']
projects: ['aws-powertools/7']
body:
- type: markdown
attributes:
value: |
Thank you for submitting a bug report. Before you start, make sure that [the bug hasn't been reported already](https://github.com/aws-powertools/powertools-lambda-typescript/issues).
Please add as much information as possible to help us reproduce, and remove any potential sensitive data.
- type: textarea
id: expected_behaviour
Expand Down Expand Up @@ -58,7 +58,7 @@ body:
id: version
attributes:
label: Powertools for AWS Lambda (TypeScript) version
placeholder: "latest, 1.3.0"
placeholder: 'latest, 2.0.0'
value: latest
validations:
required: true
Expand All @@ -67,9 +67,9 @@ body:
attributes:
label: AWS Lambda function runtime
options:
- 20.x
- 18.x
- 16.x
- 14.x
validations:
required: true
- type: dropdown
Expand All @@ -95,4 +95,4 @@ body:
value: |
---
**Disclaimer**: After creating an issue, please wait until it is triaged and confirmed by a maintainer before implementing it. This will reduce amount of rework and the chance that a pull request gets rejected.
**Disclaimer**: After creating an issue, please wait until it is triaged and confirmed by a maintainer before implementing it. This will reduce amount of rework and the chance that a pull request gets rejected.
7 changes: 5 additions & 2 deletions .github/actions/cached-node-modules/action.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ inputs:
nodeVersion: # id of input
description: 'Node.js version to use in the cache key'
default: '18'
build:
description: 'Whether to build the packages or not'
default: 'true'
outputs:
cache-hit:
description: "Whether the cache was hit or not"
Expand All @@ -28,8 +31,8 @@ runs:
run: npm ci
shell: bash
- name: Build packages
# Regardless of whether the cache was hit or not, we need to build the packages.
#
# Regardless of whether the cache was hit or not, we need to build the packages, unless the caller says otherwise
if: inputs.build == 'true'
# We build the shared package first, then the others in parallel to speed up the process
# even though we could just run `npm run build` in the root folder and build them in
# sequence, but still in the correct order.
Expand Down
23 changes: 21 additions & 2 deletions .github/scripts/release_patch_package_json.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,15 @@ if (process.argv.length < 3) {
}
const basePath = resolve(process.argv[2]);
const packageJsonPath = join(basePath, 'package.json');
const alphaPackages = [];
const alphaPackages = [
'@aws-lambda-powertools/batch',
'@aws-lambda-powertools/commons',
'@aws-lambda-powertools/idempotency',
'@aws-lambda-powertools/logger',
'@aws-lambda-powertools/metrics',
'@aws-lambda-powertools/parameters',
'@aws-lambda-powertools/tracer',
];
const betaPackages = [];

(() => {
Expand All @@ -44,12 +52,22 @@ const betaPackages = [];
types,
files,
private,
type,
} = pkgJson;

let version = originalVersion;
// If the package is an alpha or beta package, update the version number to include a suffix
if (alphaPackages.includes(name)) {
version = `${version}-alpha`;
const iteration = JSON.parse(
readFileSync(resolve('..', '..', 'v2.json'), 'utf8')
).iteration;
version = `${version}-alpha.${iteration}`;
dependencies &&
Object.entries(dependencies).forEach(([dependencyName, version]) => {
if (alphaPackages.includes(dependencyName)) {
dependencies[dependencyName] = `${version}-alpha.${iteration}`;
}
});
} else if (betaPackages.includes(name)) {
version = `${version}-beta`;
}
Expand All @@ -71,6 +89,7 @@ const betaPackages = [];
main,
types,
files,
type,
};

// Not all utilities have these fields, so only add them if they exist to avoid
Expand Down
9 changes: 6 additions & 3 deletions .github/workflows/make-v2-release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ jobs:
npm set "//registry.npmjs.org/:_authToken=${{ secrets.NPM_TOKEN }}"
- name: Setup dependencies
uses: ./.github/actions/cached-node-modules
with:
# We don't build the packages here as we want to version them first
build: false
- name: Version
run: |
# Version all packages to next major version (2.0.0) without pushing to git, generating changelog or running commit hooks
Expand All @@ -36,17 +39,17 @@ jobs:
- name: Set alpha iteration
run: |
# Get the current alpha version from npm i.e 2.0.0-alpha.0 -> 0, 2.0.0-alpha.1 -> 1 (default to -1 if no alpha versions exist = first pre-release)
ITERATION=$(npm show @aws-lambda-powertools/commons time --json | jq -r 'to_entries | map(select(.key | startswith("2.0.0-alpha"))) | sort_by(.key) | last | .key // "-1"')
ITERATION=$(npm show @aws-lambda-powertools/commons time --json | jq -r 'to_entries | map(select(.key | startswith("2.0.0-alpha"))) | sort_by(.key) | last | .key // "-1"' | cut -d '.' -f 4)
# Write the new version to the file
echo "{ \"iteration\": $((ITERATION + 1)) }" > v2.json
- name: Increment version in UA
run: |
# Increment the version in the UA
echo "// this file is auto generated, do not modify\nexport const PT_VERSION = '2.0.0-alpha.$(jq -r '.iteration' v2.json)';" > packages/commons/src/version.ts
echo -e "// this file is auto generated, do not modify\nexport const PT_VERSION = '2.0.0-alpha.$(jq -r '.iteration' v2.json)';" > packages/commons/src/version.ts
- name: Build
run: |
npm run build -w packages/commons &
npm run build -w packages/batch \
-w packages/commons \
-w packages/idempotency \
-w packages/logger \
-w packages/metrics \
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/reusable-publish-docs.yml
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ jobs:
run: |
rm -rf site
mkdocs build
mike deploy --update-aliases --no-redirect ${{ env.VERSION }} ${{ env.ALIAS }} --branch backup-gh-pages
# mike deploy --update-aliases --no-redirect ${{ env.VERSION }} ${{ env.ALIAS }} --branch backup-gh-pages
# Set latest version as a default
mike set-default latest --branch backup-gh-pages
# mike set-default latest --branch backup-gh-pages
- name: Build API docs
run: |
rm -rf api
Expand Down
20 changes: 10 additions & 10 deletions .github/workflows/reusable-run-linting-check-and-unit-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ jobs:
NODE_ENV: dev
strategy:
matrix:
version: [14, 16, 18]
version: [16, 18]
fail-fast: false
steps:
- name: Checkout code
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: Setup NodeJS
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: ${{ matrix.version }}
cache: "npm"
cache: 'npm'
- name: Setup dependencies
uses: ./.github/actions/cached-node-modules
with:
Expand All @@ -34,19 +34,19 @@ jobs:
NODE_ENV: dev
strategy:
matrix:
example: ["sam", "cdk"]
example: ['sam', 'cdk']
fail-fast: false
defaults:
run:
working-directory: examples/${{ matrix.example }}
steps:
- name: Checkout code
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: Setup NodeJS
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: 18
cache: "npm"
cache: 'npm'
- name: Setup dependencies
uses: ./.github/actions/cached-node-modules
- name: Run linting
Expand All @@ -59,12 +59,12 @@ jobs:
NODE_ENV: dev
steps:
- name: Checkout code
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: Setup NodeJS
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: 18
cache: "npm"
cache: 'npm'
- name: Setup dependencies
uses: ./.github/actions/cached-node-modules
- name: Run linting
Expand All @@ -77,12 +77,12 @@ jobs:
NODE_ENV: dev
steps:
- name: Checkout code
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
uses: actions/checkout@8e5e7e5ab8b370d6c329ec480221332ada57f0ab # v3.5.2
- name: Setup NodeJS
uses: actions/setup-node@64ed1c7eab4cce3362f8c340dee64e5eaeef8f7c # v3.6.0
with:
node-version: 18
cache: "npm"
cache: 'npm'
- name: Setup dependencies
uses: ./.github/actions/cached-node-modules
- name: Run linting
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/run-e2e-tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ jobs:
packages/parameters,
packages/idempotency,
]
version: [14, 16, 18]
version: [16, 18]
arch: [x86_64, arm64]
fail-fast: false
steps:
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@ site
tmp

# TS build files
tsconfig.tsbuildinfo
*.tsbuildinfo
2 changes: 1 addition & 1 deletion MAINTAINERS.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
> [!IMPORTANT]
> Maintainers' playbook moved: https://docs.powertools.aws.dev/lambda/typescript/latest/maintainers/
> Maintainers' playbook moved: https://docs.powertools.aws.dev/lambda/typescript/latest/maintainers/
2 changes: 1 addition & 1 deletion docs/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
mike==1.1.2
mkdocs-material==9.3.2
mkdocs-material==9.4.6
mkdocs-git-revision-date-plugin==0.3.2
mkdocs-exclude==1.0.2
13 changes: 11 additions & 2 deletions docs/snippets/logger/bringYourOwnFormatterClass.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ import {
LogAttributes,
UnformattedAttributes,
} from '@aws-lambda-powertools/logger/lib/types';
import { LogItem } from '@aws-lambda-powertools/logger/lib/log';

// Replace this line with your own type
type MyCompanyLog = LogAttributes;

class MyCompanyLogFormatter extends LogFormatter {
public formatAttributes(attributes: UnformattedAttributes): MyCompanyLog {
return {
public formatAttributes(
attributes: UnformattedAttributes,
additionalLogAttributes: LogAttributes
): LogItem {
const baseAttributes: MyCompanyLog = {
message: attributes.message,
service: attributes.serviceName,
environment: attributes.environment,
Expand All @@ -31,6 +35,11 @@ class MyCompanyLogFormatter extends LogFormatter {
sampleRateValue: attributes.sampleRateValue,
},
};

const logItem = new LogItem({ attributes: baseAttributes });
logItem.addAttributes(additionalLogAttributes); // add any attributes not explicitly defined

return logItem;
}
}

Expand Down
2 changes: 1 addition & 1 deletion docs/snippets/package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "docs",
"version": "1.9.0",
"version": "1.14.0",
"description": "A collection code snippets for the Powertools for AWS Lambda (TypeScript) docs",
"author": {
"name": "Amazon Web Services",
Expand Down
11 changes: 10 additions & 1 deletion docs/upgrade.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@ title: Upgrade guide
description: Guide to update between major Powertools for AWS Lambda (TypeScript) versions
---

## Migrate to v2 from v1

This release includes some breaking changes, please take some time to review this guide to make your transition to v2 as smooth as possible.

### Quick summary

!!! warning
This guide is a work in progress. We'll update it as we get closer to the 2.0 release. If you have any questions, or want to follow the progress, please join the discussion on the [GitHub issue](https://github.com/aws-powertools/powertools-lambda-typescript/issues/1714).
This guide is a work in progress. We'll update it as we get closer to the 2.0 release. If you have any questions, or want to follow the progress, please join the discussion on the [GitHub issue](https://github.com/aws-powertools/powertools-lambda-typescript/issues/1714).

| Area | Change | Code change required |
| ---- | ------ | -------------------- |
2 changes: 1 addition & 1 deletion examples/cdk/functions/common/powertools.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Logger } from '@aws-lambda-powertools/logger';
import { Metrics } from '@aws-lambda-powertools/metrics';
import { Tracer } from '@aws-lambda-powertools/tracer';
import { PT_VERSION } from '@aws-lambda-powertools/commons/lib/version';
import { PT_VERSION } from '@aws-lambda-powertools/commons';

const defaultValues = {
region: process.env.AWS_REGION || 'N/A',
Expand Down
6 changes: 3 additions & 3 deletions examples/cdk/functions/get-all-items.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { injectLambdaContext } from '@aws-lambda-powertools/logger';
import { logMetrics } from '@aws-lambda-powertools/metrics';
import { captureLambdaHandler } from '@aws-lambda-powertools/tracer';
import { injectLambdaContext } from '@aws-lambda-powertools/logger/middleware';
import { logMetrics } from '@aws-lambda-powertools/metrics/middleware';
import { captureLambdaHandler } from '@aws-lambda-powertools/tracer/middleware';
import { ScanCommand } from '@aws-sdk/lib-dynamodb';
import middy from '@middy/core';
import {
Expand Down
2 changes: 1 addition & 1 deletion examples/cdk/functions/get-by-id.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LambdaInterface } from '@aws-lambda-powertools/commons';
import type { LambdaInterface } from '@aws-lambda-powertools/commons/types';
import { GetCommand } from '@aws-sdk/lib-dynamodb';
import {
APIGatewayProxyEvent,
Expand Down
2 changes: 1 addition & 1 deletion examples/cdk/functions/uuid.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { randomUUID } from 'node:crypto';

exports.handler = async (_event) => {
exports.handler = async () => {
return {
statusCode: 200,
body: JSON.stringify(randomUUID()),
Expand Down
2 changes: 1 addition & 1 deletion examples/cdk/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,4 +49,4 @@
"phin": "^3.7.0",
"source-map-support": "^0.5.21"
}
}
}
2 changes: 1 addition & 1 deletion examples/sam/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,4 +41,4 @@
"esbuild": "^0.19.3",
"phin": "^3.7.0"
}
}
}
2 changes: 1 addition & 1 deletion examples/sam/src/common/powertools.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Logger } from '@aws-lambda-powertools/logger';
import { Metrics } from '@aws-lambda-powertools/metrics';
import { Tracer } from '@aws-lambda-powertools/tracer';
import { PT_VERSION } from '@aws-lambda-powertools/commons/lib/version';
import { PT_VERSION } from '@aws-lambda-powertools/commons';

const defaultValues = {
region: process.env.AWS_REGION || 'N/A',
Expand Down
6 changes: 3 additions & 3 deletions examples/sam/src/get-all-items.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import {
import middy from '@middy/core';
import { tableName } from './common/constants';
import { logger, tracer, metrics } from './common/powertools';
import { logMetrics } from '@aws-lambda-powertools/metrics';
import { injectLambdaContext } from '@aws-lambda-powertools/logger';
import { captureLambdaHandler } from '@aws-lambda-powertools/tracer';
import { logMetrics } from '@aws-lambda-powertools/metrics/middleware';
import { injectLambdaContext } from '@aws-lambda-powertools/logger/middleware';
import { captureLambdaHandler } from '@aws-lambda-powertools/tracer/middleware';
import { docClient } from './common/dynamodb-client';
import { ScanCommand } from '@aws-sdk/lib-dynamodb';
import { getUuid } from './common/getUuid';
Expand Down
2 changes: 1 addition & 1 deletion examples/sam/src/get-by-id.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { LambdaInterface } from '@aws-lambda-powertools/commons';
import type { LambdaInterface } from '@aws-lambda-powertools/commons/types';
import { GetCommand } from '@aws-sdk/lib-dynamodb';
import {
APIGatewayProxyEvent,
Expand Down
Loading

0 comments on commit f54e1b5

Please sign in to comment.