diff --git a/packages/idempotency/src/idempotencyDecorator.ts b/packages/idempotency/src/idempotencyDecorator.ts index 6b20a38e21..8e2d7f9265 100644 --- a/packages/idempotency/src/idempotencyDecorator.ts +++ b/packages/idempotency/src/idempotencyDecorator.ts @@ -14,9 +14,9 @@ import { makeIdempotent } from './makeIdempotent'; * } from '@aws-lambda-powertools/idempotency'; * import type { LambdaInterface } from '@aws-lambda-powertools/commons'; * - * class MyLambdaFunction implements LambdaInterface{ - * @idempotent({ persistenceStore: new DynamoDBPersistenceLayer() }) - * async handler(event: any, context: any) { + * class MyLambdaFunction implements LambdaInterface { + * ⁣@idempotent({ persistenceStore: new DynamoDBPersistenceLayer() }) + * async handler(event: unknown, _context: unknown) { * return "Hello World"; * } * } @@ -28,23 +28,23 @@ import { makeIdempotent } from './makeIdempotent'; * @example * ```ts * import { - * DynamoDBPersistenceLayer, - * idempotentFunction - * } from '@aws-lambda-powertools/idempotency'; - * import type { LambdaInterface } from '@aws-lambda-powertools/commons'; - * - * class MyClass implements LambdaInterface { + * DynamoDBPersistenceLayer, + * idempotentFunction + * } from '@aws-lambda-powertools/idempotency'; + * import type { LambdaInterface } from '@aws-lambda-powertools/commons'; * - * public async handler(_event: any, _context: any) { - * for(const record of _event.records){ - * await this.process(record); - * } - * } + * class MyClass implements LambdaInterface { + * public async handler(event: unknown, _context: unknown) { + * for(const record of event.records){ + * await this.process(record); + * } + * } * - * @idemptent({ persistenceStore: new DynamoDBPersistenceLayer() }) - * public async process(record: Record) { * // do some processing - * } + * } + * } * ``` * @see {@link DynamoDBPersistenceLayer} * @see https://www.typescriptlang.org/docs/handbook/decorators.html diff --git a/packages/logger/src/Logger.ts b/packages/logger/src/Logger.ts index 679086ac37..ec82ff066f 100644 --- a/packages/logger/src/Logger.ts +++ b/packages/logger/src/Logger.ts @@ -58,7 +58,7 @@ import type { * * const logger = new Logger(); * - * const lambdaHandler = async (_event: any, _context: any) => { + * const lambdaHandler = async (_event: unknown, _context: unknown) => { * logger.info('This is an INFO log with some context'); * }; * @@ -77,12 +77,9 @@ import type { * const logger = new Logger(); * * class Lambda implements LambdaInterface { - * - * // FYI: Decorator might not render properly in VSCode mouse over due to https://github.com/microsoft/TypeScript/issues/47679 and might show as *@logger* instead of `@logger.injectLambdaContext` - * * // Decorate your handler class method - * @logger.injectLambdaContext() - * public async handler(_event: any, _context: any): Promise { + * ⁣@logger.injectLambdaContext() + * public async handler(_event: unknown, _context: unknown): Promise { * logger.info('This is an INFO log with some context'); * } * } @@ -358,8 +355,8 @@ class Logger extends Utility implements ClassThatLogs { * * class Lambda implements LambdaInterface { * // Decorate your handler class method - * @logger.injectLambdaContext() - * public async handler(_event: any, _context: any): Promise { + * ⁣@logger.injectLambdaContext() + * public async handler(_event: unknown, _context: unknown): Promise { * logger.info('This is an INFO log with some context'); * } * } diff --git a/packages/metrics/src/Metrics.ts b/packages/metrics/src/Metrics.ts index b2a1c1e34e..e729c9946a 100644 --- a/packages/metrics/src/Metrics.ts +++ b/packages/metrics/src/Metrics.ts @@ -54,7 +54,7 @@ import { * * const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' }); * - * const lambdaHandler = async (_event: any, _context: any) => { + * const lambdaHandler = async (_event: unknown, _context: unknown) => { * ... * }; * @@ -77,11 +77,9 @@ import { * const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' }); * * class Lambda implements LambdaInterface { - * - * // FYI: Decorator might not render properly in VSCode mouse over due to https://github.com/microsoft/TypeScript/issues/47679 and might show as *@metrics* instead of `@metrics.logMetrics` - * - * @metrics.logMetrics({ captureColdStartMetric: true, throwOnEmptyMetrics: true }) - * public handler(_event: any, _context: any): Promise { + * // Decorate your handler with the logMetrics decorator + * ⁣@metrics.logMetrics({ captureColdStartMetric: true, throwOnEmptyMetrics: true }) + * public handler(_event: unknown, _context: unknown): Promise { * // ... * metrics.addMetric('test-metric', MetricUnits.Count, 10); * // ... @@ -103,7 +101,7 @@ import { * * const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' }); * - * export const handler = async (_event: any, _context: any): Promise => { + * export const handler = async (_event: unknown, __context: unknown): Promise => { * metrics.captureColdStartMetric(); * metrics.addMetric('test-metric', MetricUnits.Count, 10); * metrics.publishStoredMetrics(); @@ -243,7 +241,7 @@ class Metrics extends Utility implements MetricsInterface { * * const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' }); * - * export const handler = async (event: any, _context: any): Promise => { + * export const handler = async (_event: unknown, __context: unknown): Promise => { * metrics.captureColdStartMetric(); * }; * ``` @@ -305,7 +303,7 @@ class Metrics extends Utility implements MetricsInterface { * class Lambda implements LambdaInterface { * * @metrics.logMetrics({ captureColdStartMetric: true }) - * public handler(_event: any, _context: any): Promise { + * public handler(_event: unknown, __context: unknown): Promise { * // ... * } * } @@ -373,7 +371,7 @@ class Metrics extends Utility implements MetricsInterface { * * const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName: 'orders' }); // Sets metric namespace, and service as a metric dimension * - * export const handler = async (_event: any, _context: any): Promise => { + * export const handler = async (_event: unknown, __context: unknown): Promise => { * metrics.addMetric('test-metric', MetricUnits.Count, 10); * metrics.publishStoredMetrics(); * }; @@ -523,7 +521,7 @@ class Metrics extends Utility implements MetricsInterface { * * const metrics = new Metrics({ namespace: 'serverlessAirline', serviceName:'orders' }); * - * export const handler = async (_event: any, _context: any): Promise => { + * export const handler = async (_event: unknown, __context: unknown): Promise => { * metrics.throwOnEmptyMetrics(); * metrics.publishStoredMetrics(); // will throw since no metrics added. * }; diff --git a/packages/tracer/src/Tracer.ts b/packages/tracer/src/Tracer.ts index 434c0d0f2c..4d1fb11267 100644 --- a/packages/tracer/src/Tracer.ts +++ b/packages/tracer/src/Tracer.ts @@ -51,7 +51,7 @@ import { type Segment, Subsegment } from 'aws-xray-sdk-core'; * * const tracer = new Tracer({ serviceName: 'serverlessAirline' }); * - * const lambdaHandler = async (_event: any, _context: any) => { + * const lambdaHandler = async (_event: unknown, _context: unknown) => { * ... * }; * @@ -73,11 +73,9 @@ import { type Segment, Subsegment } from 'aws-xray-sdk-core'; * * const tracer = new Tracer({ serviceName: 'serverlessAirline' }); * - * // FYI: Decorator might not render properly in VSCode mouse over due to https://github.com/microsoft/TypeScript/issues/47679 and might show as *@tracer* instead of `@tracer.captureLambdaHandler` - * * class Lambda implements LambdaInterface { - * @tracer.captureLambdaHandler() - * public handler(event: any, context: any) { + * ⁣@tracer.captureLambdaHandler() + * public handler(_event: unknown, _context: unknown) { * ... * } * } @@ -96,7 +94,7 @@ import { type Segment, Subsegment } from 'aws-xray-sdk-core'; * * const tracer = new Tracer({ serviceName: 'serverlessAirline' }); * - * export const handler = async (_event: any, context: any) => { + * export const handler = async (_event: unknown, _context: unknown) => { * const segment = tracer.getSegment(); // This is the facade segment (the one that is created by AWS Lambda) * // Create subsegment for the function & set it as active * const subsegment = segment.addNewSubsegment(`## ${process.env._HANDLER}`); @@ -246,7 +244,7 @@ class Tracer extends Utility implements TracerInterface { * const tracer = new Tracer({ serviceName: 'serverlessAirline' }); * const AWS = tracer.captureAWS(require('aws-sdk')); * - * export const handler = async (_event: any, _context: any) => { + * export const handler = async (_event: unknown, _context: unknown) => { * ... * } * ``` @@ -275,7 +273,7 @@ class Tracer extends Utility implements TracerInterface { * const tracer = new Tracer({ serviceName: 'serverlessAirline' }); * const s3 = tracer.captureAWSClient(new S3({ apiVersion: '2006-03-01' })); * - * export const handler = async (_event: any, _context: any) => { + * export const handler = async (_event: unknown, _context: unknown) => { * ... * } * ``` @@ -318,7 +316,7 @@ class Tracer extends Utility implements TracerInterface { * const client = new S3Client({}); * tracer.captureAWSv3Client(client); * - * export const handler = async (_event: any, _context: any) => { + * export const handler = async (_event: unknown, _context: unknown) => { * ... * } * ``` @@ -352,9 +350,9 @@ class Tracer extends Utility implements TracerInterface { * const tracer = new Tracer({ serviceName: 'serverlessAirline' }); * * class Lambda implements LambdaInterface { - * @tracer.captureLambdaHandler() - * public handler(event: any, context: any) { - * ... + * ⁣@tracer.captureLambdaHandler() + * public handler(_event: unknown, _context: unknown) { + * // ... * } * } * @@ -445,13 +443,13 @@ class Tracer extends Utility implements TracerInterface { * const tracer = new Tracer({ serviceName: 'serverlessAirline' }); * * class Lambda implements LambdaInterface { - * @tracer.captureMethod() - * public myMethod(param: any) { - * ... + * ⁣@tracer.captureMethod() + * public myMethod(param: string) { + * // ... * } * - * public handler(event: any, context: any) { - * ... + * public handler(_event: unknown, _context: unknown) { + * this.myMethod('foo'); * } * } * @@ -567,7 +565,7 @@ class Tracer extends Utility implements TracerInterface { * * const tracer = new Tracer({ serviceName: 'serverlessAirline' }); * - * export const handler = async (_event: any, _context: any) => { + * export const handler = async (_event: unknown, _context: unknown) => { * const currentSegment = tracer.getSegment(); * ... // Do something with segment * } @@ -627,7 +625,7 @@ class Tracer extends Utility implements TracerInterface { * * const tracer = new Tracer({ serviceName: 'serverlessAirline' }); * - * export const handler = async (_event: any, _context: any) => { + * export const handler = async (_event: unknown, _context: unknown) => { * tracer.putAnnotation('successfulBooking', true); * } * ``` @@ -652,7 +650,7 @@ class Tracer extends Utility implements TracerInterface { * * const tracer = new Tracer({ serviceName: 'serverlessAirline' }); * - * export const handler = async (_event: any, _context: any) => { + * export const handler = async (_event: unknown, _context: unknown) => { * const res = someLogic(); * tracer.putMetadata('paymentResponse', res); * } @@ -686,7 +684,7 @@ class Tracer extends Utility implements TracerInterface { * * const tracer = new Tracer({ serviceName: 'serverlessAirline' }); * - * export const handler = async (_event: any, _context: any) => { + * export const handler = async (_event: unknown, _context: unknown) => { * const subsegment = new Subsegment('### foo.bar'); * tracer.setSegment(subsegment); * }