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 +}