From 266301e36b3349d1e5dc9bd3f95cd45ea27b264c Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Mon, 22 Jul 2024 13:12:42 +0200 Subject: [PATCH 1/3] chore(maintenance): add biome.js --- biome.json | 26 ++++++++ package-lock.json | 156 ++++++++++++++++++++++++++++++++++++++++++++++ package.json | 1 + 3 files changed, 183 insertions(+) create mode 100644 biome.json diff --git a/biome.json b/biome.json new file mode 100644 index 0000000000..19d23a030d --- /dev/null +++ b/biome.json @@ -0,0 +1,26 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.8.3/schema.json", + "organizeImports": { + "enabled": true + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true + } + }, + "formatter": { + "enabled": true, + "indentStyle": "space", + "indentWidth": 2, + "lineEnding": "lf" + }, + "javascript": { + "formatter": { + "semicolons": "always", + "bracketSpacing": true, + "quoteStyle": "single", + "trailingComma": "es5" + } + } +} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index ea890dc6e3..80d5733127 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "examples/app" ], "devDependencies": { + "@biomejs/biome": "^1.8.3", "@types/aws-lambda": "^8.10.141", "@types/jest": "^29.5.12", "@types/node": "^20.14.10", @@ -1848,6 +1849,161 @@ "integrity": "sha512-0hYQ8SB4Db5zvZB4axdMHGwEaQjkZzFjQiN9LVYvIFB2nSUHW9tYpxWriPrWDASIxiaXax83REcLxuSdnGPZtw==", "dev": true }, + "node_modules/@biomejs/biome": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/biome/-/biome-1.8.3.tgz", + "integrity": "sha512-/uUV3MV+vyAczO+vKrPdOW0Iaet7UnJMU4bNMinggGJTAnBPjCoLEYcyYtYHNnUNYlv4xZMH6hVIQCAozq8d5w==", + "dev": true, + "hasInstallScript": true, + "bin": { + "biome": "bin/biome" + }, + "engines": { + "node": ">=14.21.3" + }, + "funding": { + "type": "opencollective", + "url": "https://opencollective.com/biome" + }, + "optionalDependencies": { + "@biomejs/cli-darwin-arm64": "1.8.3", + "@biomejs/cli-darwin-x64": "1.8.3", + "@biomejs/cli-linux-arm64": "1.8.3", + "@biomejs/cli-linux-arm64-musl": "1.8.3", + "@biomejs/cli-linux-x64": "1.8.3", + "@biomejs/cli-linux-x64-musl": "1.8.3", + "@biomejs/cli-win32-arm64": "1.8.3", + "@biomejs/cli-win32-x64": "1.8.3" + } + }, + "node_modules/@biomejs/cli-darwin-arm64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-arm64/-/cli-darwin-arm64-1.8.3.tgz", + "integrity": "sha512-9DYOjclFpKrH/m1Oz75SSExR8VKvNSSsLnVIqdnKexj6NwmiMlKk94Wa1kZEdv6MCOHGHgyyoV57Cw8WzL5n3A==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-darwin-x64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-darwin-x64/-/cli-darwin-x64-1.8.3.tgz", + "integrity": "sha512-UeW44L/AtbmOF7KXLCoM+9PSgPo0IDcyEUfIoOXYeANaNXXf9mLUwV1GeF2OWjyic5zj6CnAJ9uzk2LT3v/wAw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "darwin" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-arm64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64/-/cli-linux-arm64-1.8.3.tgz", + "integrity": "sha512-fed2ji8s+I/m8upWpTJGanqiJ0rnlHOK3DdxsyVLZQ8ClY6qLuPc9uehCREBifRJLl/iJyQpHIRufLDeotsPtw==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-arm64-musl": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-arm64-musl/-/cli-linux-arm64-musl-1.8.3.tgz", + "integrity": "sha512-9yjUfOFN7wrYsXt/T/gEWfvVxKlnh3yBpnScw98IF+oOeCYb5/b/+K7YNqKROV2i1DlMjg9g/EcN9wvj+NkMuQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-x64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64/-/cli-linux-x64-1.8.3.tgz", + "integrity": "sha512-I8G2QmuE1teISyT8ie1HXsjFRz9L1m5n83U1O6m30Kw+kPMPSKjag6QGUn+sXT8V+XWIZxFFBoTDEDZW2KPDDw==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-linux-x64-musl": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-linux-x64-musl/-/cli-linux-x64-musl-1.8.3.tgz", + "integrity": "sha512-UHrGJX7PrKMKzPGoEsooKC9jXJMa28TUSMjcIlbDnIO4EAavCoVmNQaIuUSH0Ls2mpGMwUIf+aZJv657zfWWjA==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "linux" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-win32-arm64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-arm64/-/cli-win32-arm64-1.8.3.tgz", + "integrity": "sha512-J+Hu9WvrBevfy06eU1Na0lpc7uR9tibm9maHynLIoAjLZpQU3IW+OKHUtyL8p6/3pT2Ju5t5emReeIS2SAxhkQ==", + "cpu": [ + "arm64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.21.3" + } + }, + "node_modules/@biomejs/cli-win32-x64": { + "version": "1.8.3", + "resolved": "https://registry.npmjs.org/@biomejs/cli-win32-x64/-/cli-win32-x64-1.8.3.tgz", + "integrity": "sha512-/PJ59vA1pnQeKahemaQf4Nyj7IKUvGQSc3Ze1uIGi+Wvr1xF7rGobSrAAG01T/gUDG21vkDsZYM03NAmPiVkqg==", + "cpu": [ + "x64" + ], + "dev": true, + "optional": true, + "os": [ + "win32" + ], + "engines": { + "node": ">=14.21.3" + } + }, "node_modules/@cspotcode/source-map-support": { "version": "0.8.1", "resolved": "https://registry.npmjs.org/@cspotcode/source-map-support/-/source-map-support-0.8.1.tgz", diff --git a/package.json b/package.json index 66fcd8ef7d..4efd18859e 100644 --- a/package.json +++ b/package.json @@ -49,6 +49,7 @@ }, "homepage": "https://github.com/aws-powertools/powertools-lambda-typescript#readme", "devDependencies": { + "@biomejs/biome": "^1.8.3", "@types/aws-lambda": "^8.10.141", "@types/jest": "^29.5.12", "@types/node": "^20.14.10", From 0ed3e1c55fb81bf175a5129cfab99c4109861dfb Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Mon, 22 Jul 2024 15:52:41 +0200 Subject: [PATCH 2/3] chore(maintenance): add biome to project --- biome.json | 15 +++++++++++++-- examples/app/cdk/example-stack.ts | 4 ++-- .../app/functions/commons/helpers/get-item.ts | 4 ++-- .../app/functions/commons/helpers/put-item.ts | 6 +++--- .../app/functions/commons/helpers/scan-items.ts | 4 ++-- examples/app/package.json | 10 +++------- package.json | 4 ++-- 7 files changed, 27 insertions(+), 20 deletions(-) diff --git a/biome.json b/biome.json index 19d23a030d..46c5a0c5d5 100644 --- a/biome.json +++ b/biome.json @@ -13,14 +13,25 @@ "enabled": true, "indentStyle": "space", "indentWidth": 2, - "lineEnding": "lf" + "lineEnding": "lf", + "lineWidth": 80 }, "javascript": { "formatter": { "semicolons": "always", "bracketSpacing": true, "quoteStyle": "single", - "trailingComma": "es5" + "trailingCommas": "es5" } + }, + "files": { + "ignore": [ + "node_modules", + "coverage", + "lib", + "cdk.out", + "site", + ".aws-sam" + ] } } \ No newline at end of file diff --git a/examples/app/cdk/example-stack.ts b/examples/app/cdk/example-stack.ts index b5e7f66284..067ef6752f 100644 --- a/examples/app/cdk/example-stack.ts +++ b/examples/app/cdk/example-stack.ts @@ -1,4 +1,4 @@ -import { RemovalPolicy, Stack, StackProps } from 'aws-cdk-lib'; +import { RemovalPolicy, Stack, type StackProps } from 'aws-cdk-lib'; import { LambdaIntegration, RestApi } from 'aws-cdk-lib/aws-apigateway'; import { AttributeType, @@ -18,7 +18,7 @@ import { DynamoEventSource } from 'aws-cdk-lib/aws-lambda-event-sources'; import { OutputFormat } from 'aws-cdk-lib/aws-lambda-nodejs'; import { Queue } from 'aws-cdk-lib/aws-sqs'; import { StringParameter } from 'aws-cdk-lib/aws-ssm'; -import { Construct } from 'constructs'; +import type { Construct } from 'constructs'; import { FunctionWithLogGroup } from './function-with-logstream-construct.js'; export class PowertoolsExampleStack extends Stack { diff --git a/examples/app/functions/commons/helpers/get-item.ts b/examples/app/functions/commons/helpers/get-item.ts index 3ce1030ea7..165b01f0d0 100644 --- a/examples/app/functions/commons/helpers/get-item.ts +++ b/examples/app/functions/commons/helpers/get-item.ts @@ -1,7 +1,7 @@ +import { GetCommand, type GetCommandOutput } from '@aws-sdk/lib-dynamodb'; import { docClient } from '#clients/dynamodb'; import { itemsTableName } from '#constants'; import type { DebugLogger } from '#types'; -import { GetCommand, type GetCommandOutput } from '@aws-sdk/lib-dynamodb'; /** * Fetch an item from the DynamoDB table. @@ -22,7 +22,7 @@ const getItemDynamoDB = async ( }) ); - logger.debug(`ddb response`, { + logger.debug('ddb response', { response, }); diff --git a/examples/app/functions/commons/helpers/put-item.ts b/examples/app/functions/commons/helpers/put-item.ts index a978e0382c..853756899d 100644 --- a/examples/app/functions/commons/helpers/put-item.ts +++ b/examples/app/functions/commons/helpers/put-item.ts @@ -1,8 +1,8 @@ +import { randomUUID } from 'node:crypto'; +import { PutCommand } from '@aws-sdk/lib-dynamodb'; import { docClient } from '#clients/dynamodb'; import { itemsTableName } from '#constants'; import type { DebugLogger } from '#types'; -import { PutCommand } from '@aws-sdk/lib-dynamodb'; -import { randomUUID } from 'node:crypto'; /** * Put an item in the DynamoDB table. @@ -28,7 +28,7 @@ const putItemInDynamoDB = async ( }) ); - logger.debug(`ddb response`, { + logger.debug('ddb response', { response, }); diff --git a/examples/app/functions/commons/helpers/scan-items.ts b/examples/app/functions/commons/helpers/scan-items.ts index 858b752c1d..d528085f28 100644 --- a/examples/app/functions/commons/helpers/scan-items.ts +++ b/examples/app/functions/commons/helpers/scan-items.ts @@ -1,7 +1,7 @@ +import { ScanCommand, type ScanCommandOutput } from '@aws-sdk/lib-dynamodb'; import { docClient } from '#clients/dynamodb'; import { itemsTableName } from '#constants'; import type { DebugLogger } from '#types'; -import { ScanCommand, type ScanCommandOutput } from '@aws-sdk/lib-dynamodb'; /** * Scan the DynamoDB table and return all items. @@ -19,7 +19,7 @@ const scanItemsDynamoDB = async ( }) ); - logger.debug(`ddb response`, { + logger.debug('ddb response', { response, }); diff --git a/examples/app/package.json b/examples/app/package.json index 30b84d438e..8f6c790d63 100644 --- a/examples/app/package.json +++ b/examples/app/package.json @@ -11,16 +11,12 @@ "scripts": { "build": "echo 'Not applicable, run `npx cdk synth` instead to build the stack'", "test": "npm run test:unit", - "lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .", - "lint-fix": "eslint --fix --ext .ts,.js --fix --no-error-on-unmatched-pattern .", + "lint": "biome lint .", + "lint:fix": "biome check --write .", "test:unit": "export POWERTOOLS_DEV=true && jest --silent", "test:e2e": "echo 'To be implemented ...'", "cdk": "cdk" }, - "lint-staged": { - "*.ts": "npm run lint-fix", - "*.js": "npm run lint-fix" - }, "type": "module", "imports": { "#types": "./functions/commons/types.js", @@ -64,4 +60,4 @@ "ts-node": "^10.9.2", "typescript": "^5.4.5" } -} +} \ No newline at end of file diff --git a/package.json b/package.json index 4efd18859e..c1f422af13 100644 --- a/package.json +++ b/package.json @@ -78,7 +78,7 @@ "typescript": "^5.4.5" }, "lint-staged": { - "*.{js,ts}": "eslint --fix", + "*.{js,ts}": "biome check --write", "*.md": "markdownlint-cli2 --fix" }, "engines": { @@ -89,4 +89,4 @@ "tar": "6.2.1" } } -} +} \ No newline at end of file From 7972956f2833b639e3accbcdddafa4440657ff8a Mon Sep 17 00:00:00 2001 From: Andrea Amorosi Date: Mon, 22 Jul 2024 16:21:05 +0200 Subject: [PATCH 3/3] chore(maintenance): migrate batch utility to biome --- packages/batch/package.json | 13 ++---- .../batch/src/BasePartialBatchProcessor.ts | 4 +- packages/batch/src/SqsFifoPartialProcessor.ts | 4 +- packages/batch/src/constants.ts | 2 +- packages/batch/src/processPartialResponse.ts | 2 +- .../batch/src/processPartialResponseSync.ts | 2 +- packages/batch/src/types.ts | 4 +- packages/batch/tests/helpers/factories.ts | 4 +- packages/batch/tests/helpers/handlers.ts | 14 +++---- packages/batch/tests/tsconfig.json | 17 ++++---- .../batch/tests/unit/BatchProcessor.test.ts | 6 +-- .../tests/unit/BatchProcessorSync.test.ts | 4 +- .../unit/SqsFifoPartialProcessor.test.ts | 40 +++++++++---------- .../tests/unit/processPartialResponse.test.ts | 8 ++-- .../unit/processPartialResponseSync.test.ts | 8 ++-- packages/batch/tsconfig.esm.json | 6 +-- packages/batch/tsconfig.json | 18 ++++----- packages/batch/typedoc.json | 11 ++--- 18 files changed, 75 insertions(+), 92 deletions(-) diff --git a/packages/batch/package.json b/packages/batch/package.json index 9ec5a21271..8ce33cd6c1 100644 --- a/packages/batch/package.json +++ b/packages/batch/package.json @@ -20,8 +20,8 @@ "build:cjs": "tsc --build tsconfig.json && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json", "build:esm": "tsc --build tsconfig.esm.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json", "build": "npm run build:esm & npm run build:cjs", - "lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .", - "lint-fix": "eslint --fix --ext .ts,.js --no-error-on-unmatched-pattern .", + "lint": "biome lint .", + "lint:fix": "biome check --write .", "prepack": "node ../../.github/scripts/release_patch_package_json.js ." }, "homepage": "https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/packages/batch#readme", @@ -45,17 +45,12 @@ }, "typesVersions": { "*": { - "types": [ - "lib/cjs/types.d.ts", - "lib/esm/types.d.ts" - ] + "types": ["lib/cjs/types.d.ts", "lib/esm/types.d.ts"] } }, "types": "./lib/cjs/index.d.ts", "main": "./lib/cjs/index.js", - "files": [ - "lib" - ], + "files": ["lib"], "repository": { "type": "git", "url": "git+https://github.com/aws-powertools/powertools-lambda-typescript.git" diff --git a/packages/batch/src/BasePartialBatchProcessor.ts b/packages/batch/src/BasePartialBatchProcessor.ts index d89f584c37..7a6c422f57 100644 --- a/packages/batch/src/BasePartialBatchProcessor.ts +++ b/packages/batch/src/BasePartialBatchProcessor.ts @@ -147,7 +147,7 @@ abstract class BasePartialBatchProcessor extends BasePartialProcessor { * entire batch failed and this method will return `true`. */ public entireBatchFailed(): boolean { - return this.errors.length == this.records.length; + return this.errors.length === this.records.length; } /** @@ -167,7 +167,7 @@ abstract class BasePartialBatchProcessor extends BasePartialProcessor { * and this method will return `false`. */ public hasMessagesToReport(): boolean { - return this.failureMessages.length != 0; + return this.failureMessages.length !== 0; } /** diff --git a/packages/batch/src/SqsFifoPartialProcessor.ts b/packages/batch/src/SqsFifoPartialProcessor.ts index 26354f3715..6a9546fcb6 100644 --- a/packages/batch/src/SqsFifoPartialProcessor.ts +++ b/packages/batch/src/SqsFifoPartialProcessor.ts @@ -1,8 +1,8 @@ -import { SQSRecord } from 'aws-lambda'; +import type { SQSRecord } from 'aws-lambda'; import { BatchProcessorSync } from './BatchProcessorSync.js'; import { EventType } from './constants.js'; import { - BatchProcessingError, + type BatchProcessingError, SqsFifoMessageGroupShortCircuitError, SqsFifoShortCircuitError, } from './errors.js'; diff --git a/packages/batch/src/constants.ts b/packages/batch/src/constants.ts index a794ec0ef0..159b12df6a 100644 --- a/packages/batch/src/constants.ts +++ b/packages/batch/src/constants.ts @@ -4,8 +4,8 @@ import type { SQSRecord, } from 'aws-lambda'; import type { - PartialItemFailureResponse, EventSourceDataClassTypes, + PartialItemFailureResponse, } from './types.js'; /** diff --git a/packages/batch/src/processPartialResponse.ts b/packages/batch/src/processPartialResponse.ts index 4423e1c179..daba2e862a 100644 --- a/packages/batch/src/processPartialResponse.ts +++ b/packages/batch/src/processPartialResponse.ts @@ -1,4 +1,4 @@ -import { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js'; +import type { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js'; import { UnexpectedBatchTypeError } from './errors.js'; import type { BaseRecord, diff --git a/packages/batch/src/processPartialResponseSync.ts b/packages/batch/src/processPartialResponseSync.ts index c8eca684e7..d3216e57fd 100644 --- a/packages/batch/src/processPartialResponseSync.ts +++ b/packages/batch/src/processPartialResponseSync.ts @@ -1,4 +1,4 @@ -import { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js'; +import type { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js'; import { UnexpectedBatchTypeError } from './errors.js'; import type { BaseRecord, diff --git a/packages/batch/src/types.ts b/packages/batch/src/types.ts index a267f092b6..7e60704535 100644 --- a/packages/batch/src/types.ts +++ b/packages/batch/src/types.ts @@ -4,8 +4,8 @@ import type { KinesisStreamRecord, SQSRecord, } from 'aws-lambda'; -import { SqsFifoPartialProcessor } from './SqsFifoPartialProcessor.js'; -import { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js'; +import type { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js'; +import type { SqsFifoPartialProcessor } from './SqsFifoPartialProcessor.js'; /** * Options for batch processing diff --git a/packages/batch/tests/helpers/factories.ts b/packages/batch/tests/helpers/factories.ts index ce51736788..bf3b75a7cb 100644 --- a/packages/batch/tests/helpers/factories.ts +++ b/packages/batch/tests/helpers/factories.ts @@ -1,9 +1,9 @@ +import { randomInt, randomUUID } from 'node:crypto'; import type { DynamoDBRecord, KinesisStreamRecord, SQSRecord, } from 'aws-lambda'; -import { randomInt, randomUUID } from 'node:crypto'; const sqsRecordFactory = (body: string, messageGroupId?: string): SQSRecord => { return { @@ -41,7 +41,7 @@ const kinesisRecordFactory = (body: string): KinesisStreamRecord => { }, eventSource: 'aws:kinesis', eventVersion: '1.0', - eventID: 'shardId-000000000006:' + seq, + eventID: `shardId-000000000006:${seq}`, eventName: 'aws:kinesis:record', invokeIdentityArn: 'arn:aws:iam::123456789012:role/lambda-role', awsRegion: 'us-east-2', diff --git a/packages/batch/tests/helpers/handlers.ts b/packages/batch/tests/helpers/handlers.ts index d8f9a638a0..1902cd1a2b 100644 --- a/packages/batch/tests/helpers/handlers.ts +++ b/packages/batch/tests/helpers/handlers.ts @@ -1,8 +1,8 @@ import type { + Context, DynamoDBRecord, KinesisStreamRecord, SQSRecord, - Context, } from 'aws-lambda'; const sqsRecordHandler = (record: SQSRecord): string => { @@ -45,7 +45,7 @@ const asyncKinesisRecordHandler = async ( const dynamodbRecordHandler = (record: DynamoDBRecord): object => { const body = record.dynamodb?.NewImage?.Message || { S: 'fail' }; - if (body['S']?.includes('fail')) { + if (body.S?.includes('fail')) { throw Error('Failed to process record.'); } @@ -56,7 +56,7 @@ const asyncDynamodbRecordHandler = async ( record: DynamoDBRecord ): Promise => { const body = record.dynamodb?.NewImage?.Message || { S: 'fail' }; - if (body['S']?.includes('fail')) { + if (body.S?.includes('fail')) { throw Error('Failed to process record.'); } @@ -65,11 +65,11 @@ const asyncDynamodbRecordHandler = async ( const handlerWithContext = (record: SQSRecord, context: Context): string => { try { - if (context.getRemainingTimeInMillis() == 0) { + if (context.getRemainingTimeInMillis() === 0) { throw Error('No time remaining.'); } } catch (e) { - throw Error('Context possibly malformed. Displaying context:\n' + context); + throw Error(`Context possibly malformed. Displaying context:\n${context}`); } return record.body; @@ -80,11 +80,11 @@ const asyncHandlerWithContext = async ( context: Context ): Promise => { try { - if (context.getRemainingTimeInMillis() == 0) { + if (context.getRemainingTimeInMillis() === 0) { throw Error('No time remaining.'); } } catch (e) { - throw Error('Context possibly malformed. Displaying context:\n' + context); + throw Error(`Context possibly malformed. Displaying context:\n${context}`); } return Promise.resolve(record.body); diff --git a/packages/batch/tests/tsconfig.json b/packages/batch/tests/tsconfig.json index 5654b3e15f..45ba862a85 100644 --- a/packages/batch/tests/tsconfig.json +++ b/packages/batch/tests/tsconfig.json @@ -1,11 +1,8 @@ { - "extends": "../tsconfig.json", - "compilerOptions": { - "rootDir": "../", - "noEmit": true - }, - "include": [ - "../src/**/*", - "./**/*", - ] -} \ No newline at end of file + "extends": "../tsconfig.json", + "compilerOptions": { + "rootDir": "../", + "noEmit": true + }, + "include": ["../src/**/*", "./**/*"] +} diff --git a/packages/batch/tests/unit/BatchProcessor.test.ts b/packages/batch/tests/unit/BatchProcessor.test.ts index 1b1114ca86..2160865a05 100644 --- a/packages/batch/tests/unit/BatchProcessor.test.ts +++ b/packages/batch/tests/unit/BatchProcessor.test.ts @@ -3,12 +3,12 @@ * * @group unit/batch/class/batchprocessor */ -import type { Context } from 'aws-lambda'; import context from '@aws-lambda-powertools/testing-utils/context'; +import type { Context } from 'aws-lambda'; import { + BatchProcessingError, BatchProcessor, EventType, - BatchProcessingError, FullBatchFailureError, } from '../../src/index.js'; import type { BatchProcessingOptions } from '../../src/types.js'; @@ -19,9 +19,9 @@ import { } from '../helpers/factories.js'; import { asyncDynamodbRecordHandler, + asyncHandlerWithContext, asyncKinesisRecordHandler, asyncSqsRecordHandler, - asyncHandlerWithContext, } from '../helpers/handlers.js'; describe('Class: AsyncBatchProcessor', () => { diff --git a/packages/batch/tests/unit/BatchProcessorSync.test.ts b/packages/batch/tests/unit/BatchProcessorSync.test.ts index bf93f590a0..07f9257a63 100644 --- a/packages/batch/tests/unit/BatchProcessorSync.test.ts +++ b/packages/batch/tests/unit/BatchProcessorSync.test.ts @@ -3,12 +3,12 @@ * * @group unit/batch/class/batchprocessorsync */ -import type { Context } from 'aws-lambda'; import context from '@aws-lambda-powertools/testing-utils/context'; +import type { Context } from 'aws-lambda'; import { + BatchProcessingError, BatchProcessorSync, EventType, - BatchProcessingError, FullBatchFailureError, } from '../../src/index.js'; import type { BatchProcessingOptions } from '../../src/types.js'; diff --git a/packages/batch/tests/unit/SqsFifoPartialProcessor.test.ts b/packages/batch/tests/unit/SqsFifoPartialProcessor.test.ts index 54f463caa8..4ef46e4f70 100644 --- a/packages/batch/tests/unit/SqsFifoPartialProcessor.test.ts +++ b/packages/batch/tests/unit/SqsFifoPartialProcessor.test.ts @@ -4,10 +4,10 @@ * @group unit/batch/class/sqsfifobatchprocessor */ import { + SqsFifoMessageGroupShortCircuitError, SqsFifoPartialProcessor, - processPartialResponseSync, SqsFifoShortCircuitError, - SqsFifoMessageGroupShortCircuitError, + processPartialResponseSync, } from '../../src/index.js'; import { sqsRecordFactory } from '../helpers/factories.js'; import { sqsRecordHandler } from '../helpers/handlers.js'; @@ -41,7 +41,7 @@ describe('Class: SqsFifoBatchProcessor', () => { ); // Assess - expect(result['batchItemFailures']).toStrictEqual([]); + expect(result.batchItemFailures).toStrictEqual([]); }); test('SQS FIFO Batch processor with failures', () => { @@ -60,11 +60,11 @@ describe('Class: SqsFifoBatchProcessor', () => { ); // Assess - expect(result['batchItemFailures'].length).toBe(2); - expect(result['batchItemFailures'][0]['itemIdentifier']).toBe( + expect(result.batchItemFailures.length).toBe(2); + expect(result.batchItemFailures[0].itemIdentifier).toBe( secondRecord.messageId ); - expect(result['batchItemFailures'][1]['itemIdentifier']).toBe( + expect(result.batchItemFailures[1].itemIdentifier).toBe( thirdRecord.messageId ); expect(processor.errors[1]).toBeInstanceOf(SqsFifoShortCircuitError); @@ -99,17 +99,17 @@ describe('Class: SqsFifoBatchProcessor', () => { ); // Assess - expect(result['batchItemFailures'].length).toBe(4); - expect(result['batchItemFailures'][0]['itemIdentifier']).toBe( + expect(result.batchItemFailures.length).toBe(4); + expect(result.batchItemFailures[0].itemIdentifier).toBe( firstRecord.messageId ); - expect(result['batchItemFailures'][1]['itemIdentifier']).toBe( + expect(result.batchItemFailures[1].itemIdentifier).toBe( secondRecord.messageId ); - expect(result['batchItemFailures'][2]['itemIdentifier']).toBe( + expect(result.batchItemFailures[2].itemIdentifier).toBe( thirdRecord.messageId ); - expect(result['batchItemFailures'][3]['itemIdentifier']).toBe( + expect(result.batchItemFailures[3].itemIdentifier).toBe( fourthRecord.messageId ); expect(processor.errors.length).toBe(4); @@ -150,11 +150,11 @@ describe('Class: SqsFifoBatchProcessor', () => { ); // Assess - expect(result['batchItemFailures'].length).toBe(2); - expect(result['batchItemFailures'][0]['itemIdentifier']).toBe( + expect(result.batchItemFailures.length).toBe(2); + expect(result.batchItemFailures[0].itemIdentifier).toBe( thirdRecord.messageId ); - expect(result['batchItemFailures'][1]['itemIdentifier']).toBe( + expect(result.batchItemFailures[1].itemIdentifier).toBe( fourthRecord.messageId ); expect(processor.errors.length).toBe(2); @@ -185,7 +185,7 @@ describe('Class: SqsFifoBatchProcessor', () => { ); // Assess - expect(result['batchItemFailures'].length).toBe(0); + expect(result.batchItemFailures.length).toBe(0); expect(processor.errors.length).toBe(0); }); @@ -211,7 +211,7 @@ describe('Class: SqsFifoBatchProcessor', () => { ); // Assess - expect(result['batchItemFailures'].length).toBe(0); + expect(result.batchItemFailures.length).toBe(0); expect(processor.errors.length).toBe(0); }); @@ -237,14 +237,14 @@ describe('Class: SqsFifoBatchProcessor', () => { ); // Assess - expect(result['batchItemFailures'].length).toBe(3); - expect(result['batchItemFailures'][0]['itemIdentifier']).toBe( + expect(result.batchItemFailures.length).toBe(3); + expect(result.batchItemFailures[0].itemIdentifier).toBe( secondRecord.messageId ); - expect(result['batchItemFailures'][1]['itemIdentifier']).toBe( + expect(result.batchItemFailures[1].itemIdentifier).toBe( thirdRecord.messageId ); - expect(result['batchItemFailures'][2]['itemIdentifier']).toBe( + expect(result.batchItemFailures[2].itemIdentifier).toBe( fourthRecord.messageId ); expect(processor.errors.length).toBe(3); diff --git a/packages/batch/tests/unit/processPartialResponse.test.ts b/packages/batch/tests/unit/processPartialResponse.test.ts index 1d379e6398..2ebd22d5ec 100644 --- a/packages/batch/tests/unit/processPartialResponse.test.ts +++ b/packages/batch/tests/unit/processPartialResponse.test.ts @@ -3,19 +3,20 @@ * * @group unit/batch/function/asyncProcesspartialresponse */ +import assert from 'node:assert'; +import context from '@aws-lambda-powertools/testing-utils/context'; import type { Context, DynamoDBStreamEvent, KinesisStreamEvent, SQSEvent, } from 'aws-lambda'; -import context from '@aws-lambda-powertools/testing-utils/context'; import { BatchProcessor, - processPartialResponse, EventType, - UnexpectedBatchTypeError, FullBatchFailureError, + UnexpectedBatchTypeError, + processPartialResponse, } from '../../src/index.js'; import type { BatchProcessingOptions, @@ -32,7 +33,6 @@ import { asyncKinesisRecordHandler, asyncSqsRecordHandler, } from '../helpers/handlers.js'; -import assert from 'node:assert'; describe('Function: processPartialResponse()', () => { const ENVIRONMENT_VARIABLES = process.env; diff --git a/packages/batch/tests/unit/processPartialResponseSync.test.ts b/packages/batch/tests/unit/processPartialResponseSync.test.ts index 8d4bb1e263..56519ec63b 100644 --- a/packages/batch/tests/unit/processPartialResponseSync.test.ts +++ b/packages/batch/tests/unit/processPartialResponseSync.test.ts @@ -3,19 +3,20 @@ * * @group unit/batch/function/processpartialresponse */ +import assert from 'node:assert'; +import context from '@aws-lambda-powertools/testing-utils/context'; import type { Context, DynamoDBStreamEvent, KinesisStreamEvent, SQSEvent, } from 'aws-lambda'; -import context from '@aws-lambda-powertools/testing-utils/context'; import { BatchProcessorSync, - processPartialResponseSync, EventType, - UnexpectedBatchTypeError, FullBatchFailureError, + UnexpectedBatchTypeError, + processPartialResponseSync, } from '../../src/index.js'; import type { BatchProcessingOptions, @@ -32,7 +33,6 @@ import { kinesisRecordHandler, sqsRecordHandler, } from '../helpers/handlers.js'; -import assert from 'node:assert'; describe('Function: processPartialResponse()', () => { const ENVIRONMENT_VARIABLES = process.env; diff --git a/packages/batch/tsconfig.esm.json b/packages/batch/tsconfig.esm.json index 123291b0cf..82486b64fa 100644 --- a/packages/batch/tsconfig.esm.json +++ b/packages/batch/tsconfig.esm.json @@ -6,7 +6,5 @@ "rootDir": "./src", "tsBuildInfoFile": ".tsbuildinfo/esm.json" }, - "include": [ - "./src/**/*" - ] -} \ No newline at end of file + "include": ["./src/**/*"] +} diff --git a/packages/batch/tsconfig.json b/packages/batch/tsconfig.json index 4836a14962..4923c4f6f4 100644 --- a/packages/batch/tsconfig.json +++ b/packages/batch/tsconfig.json @@ -1,11 +1,9 @@ { - "extends": "../../tsconfig.json", - "compilerOptions": { - "outDir": "./lib/cjs/", - "rootDir": "./src", - "tsBuildInfoFile": ".tsbuildinfo/cjs.json" - }, - "include": [ - "./src/**/*" - ], -} \ No newline at end of file + "extends": "../../tsconfig.json", + "compilerOptions": { + "outDir": "./lib/cjs/", + "rootDir": "./src", + "tsBuildInfoFile": ".tsbuildinfo/cjs.json" + }, + "include": ["./src/**/*"] +} diff --git a/packages/batch/typedoc.json b/packages/batch/typedoc.json index 7b5f0117b6..2cc575bc18 100644 --- a/packages/batch/typedoc.json +++ b/packages/batch/typedoc.json @@ -1,10 +1,5 @@ { - "extends": [ - "../../typedoc.base.json" - ], - "entryPoints": [ - "./src/index.ts", - "./src/types.ts" - ], + "extends": ["../../typedoc.base.json"], + "entryPoints": ["./src/index.ts", "./src/types.ts"], "readme": "README.md" -} \ No newline at end of file +}