Skip to content

Commit b9db070

Browse files
authored
chore(maintenance): migrate batch utility to biome (#2804)
1 parent 6e5dd9a commit b9db070

18 files changed

+75
-92
lines changed

packages/batch/package.json

+4-9
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
"build:cjs": "tsc --build tsconfig.json && echo '{ \"type\": \"commonjs\" }' > lib/cjs/package.json",
2121
"build:esm": "tsc --build tsconfig.esm.json && echo '{ \"type\": \"module\" }' > lib/esm/package.json",
2222
"build": "npm run build:esm & npm run build:cjs",
23-
"lint": "eslint --ext .ts,.js --no-error-on-unmatched-pattern .",
24-
"lint-fix": "eslint --fix --ext .ts,.js --no-error-on-unmatched-pattern .",
23+
"lint": "biome lint .",
24+
"lint:fix": "biome check --write .",
2525
"prepack": "node ../../.github/scripts/release_patch_package_json.js ."
2626
},
2727
"homepage": "https://github.com/aws-powertools/powertools-lambda-typescript/tree/main/packages/batch#readme",
@@ -45,17 +45,12 @@
4545
},
4646
"typesVersions": {
4747
"*": {
48-
"types": [
49-
"lib/cjs/types.d.ts",
50-
"lib/esm/types.d.ts"
51-
]
48+
"types": ["lib/cjs/types.d.ts", "lib/esm/types.d.ts"]
5249
}
5350
},
5451
"types": "./lib/cjs/index.d.ts",
5552
"main": "./lib/cjs/index.js",
56-
"files": [
57-
"lib"
58-
],
53+
"files": ["lib"],
5954
"repository": {
6055
"type": "git",
6156
"url": "git+https://github.com/aws-powertools/powertools-lambda-typescript.git"

packages/batch/src/BasePartialBatchProcessor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ abstract class BasePartialBatchProcessor extends BasePartialProcessor {
147147
* entire batch failed and this method will return `true`.
148148
*/
149149
public entireBatchFailed(): boolean {
150-
return this.errors.length == this.records.length;
150+
return this.errors.length === this.records.length;
151151
}
152152

153153
/**
@@ -167,7 +167,7 @@ abstract class BasePartialBatchProcessor extends BasePartialProcessor {
167167
* and this method will return `false`.
168168
*/
169169
public hasMessagesToReport(): boolean {
170-
return this.failureMessages.length != 0;
170+
return this.failureMessages.length !== 0;
171171
}
172172

173173
/**

packages/batch/src/SqsFifoPartialProcessor.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
1-
import { SQSRecord } from 'aws-lambda';
1+
import type { SQSRecord } from 'aws-lambda';
22
import { BatchProcessorSync } from './BatchProcessorSync.js';
33
import { EventType } from './constants.js';
44
import {
5-
BatchProcessingError,
5+
type BatchProcessingError,
66
SqsFifoMessageGroupShortCircuitError,
77
SqsFifoShortCircuitError,
88
} from './errors.js';

packages/batch/src/constants.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type {
44
SQSRecord,
55
} from 'aws-lambda';
66
import type {
7-
PartialItemFailureResponse,
87
EventSourceDataClassTypes,
8+
PartialItemFailureResponse,
99
} from './types.js';
1010

1111
/**

packages/batch/src/processPartialResponse.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js';
1+
import type { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js';
22
import { UnexpectedBatchTypeError } from './errors.js';
33
import type {
44
BaseRecord,

packages/batch/src/processPartialResponseSync.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js';
1+
import type { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js';
22
import { UnexpectedBatchTypeError } from './errors.js';
33
import type {
44
BaseRecord,

packages/batch/src/types.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import type {
44
KinesisStreamRecord,
55
SQSRecord,
66
} from 'aws-lambda';
7-
import { SqsFifoPartialProcessor } from './SqsFifoPartialProcessor.js';
8-
import { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js';
7+
import type { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js';
8+
import type { SqsFifoPartialProcessor } from './SqsFifoPartialProcessor.js';
99

1010
/**
1111
* Options for batch processing

packages/batch/tests/helpers/factories.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1+
import { randomInt, randomUUID } from 'node:crypto';
12
import type {
23
DynamoDBRecord,
34
KinesisStreamRecord,
45
SQSRecord,
56
} from 'aws-lambda';
6-
import { randomInt, randomUUID } from 'node:crypto';
77

88
const sqsRecordFactory = (body: string, messageGroupId?: string): SQSRecord => {
99
return {
@@ -41,7 +41,7 @@ const kinesisRecordFactory = (body: string): KinesisStreamRecord => {
4141
},
4242
eventSource: 'aws:kinesis',
4343
eventVersion: '1.0',
44-
eventID: 'shardId-000000000006:' + seq,
44+
eventID: `shardId-000000000006:${seq}`,
4545
eventName: 'aws:kinesis:record',
4646
invokeIdentityArn: 'arn:aws:iam::123456789012:role/lambda-role',
4747
awsRegion: 'us-east-2',

packages/batch/tests/helpers/handlers.ts

+7-7
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import type {
2+
Context,
23
DynamoDBRecord,
34
KinesisStreamRecord,
45
SQSRecord,
5-
Context,
66
} from 'aws-lambda';
77

88
const sqsRecordHandler = (record: SQSRecord): string => {
@@ -45,7 +45,7 @@ const asyncKinesisRecordHandler = async (
4545

4646
const dynamodbRecordHandler = (record: DynamoDBRecord): object => {
4747
const body = record.dynamodb?.NewImage?.Message || { S: 'fail' };
48-
if (body['S']?.includes('fail')) {
48+
if (body.S?.includes('fail')) {
4949
throw Error('Failed to process record.');
5050
}
5151

@@ -56,7 +56,7 @@ const asyncDynamodbRecordHandler = async (
5656
record: DynamoDBRecord
5757
): Promise<object> => {
5858
const body = record.dynamodb?.NewImage?.Message || { S: 'fail' };
59-
if (body['S']?.includes('fail')) {
59+
if (body.S?.includes('fail')) {
6060
throw Error('Failed to process record.');
6161
}
6262

@@ -65,11 +65,11 @@ const asyncDynamodbRecordHandler = async (
6565

6666
const handlerWithContext = (record: SQSRecord, context: Context): string => {
6767
try {
68-
if (context.getRemainingTimeInMillis() == 0) {
68+
if (context.getRemainingTimeInMillis() === 0) {
6969
throw Error('No time remaining.');
7070
}
7171
} catch (e) {
72-
throw Error('Context possibly malformed. Displaying context:\n' + context);
72+
throw Error(`Context possibly malformed. Displaying context:\n${context}`);
7373
}
7474

7575
return record.body;
@@ -80,11 +80,11 @@ const asyncHandlerWithContext = async (
8080
context: Context
8181
): Promise<string> => {
8282
try {
83-
if (context.getRemainingTimeInMillis() == 0) {
83+
if (context.getRemainingTimeInMillis() === 0) {
8484
throw Error('No time remaining.');
8585
}
8686
} catch (e) {
87-
throw Error('Context possibly malformed. Displaying context:\n' + context);
87+
throw Error(`Context possibly malformed. Displaying context:\n${context}`);
8888
}
8989

9090
return Promise.resolve(record.body);

packages/batch/tests/tsconfig.json

+7-10
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
{
2-
"extends": "../tsconfig.json",
3-
"compilerOptions": {
4-
"rootDir": "../",
5-
"noEmit": true
6-
},
7-
"include": [
8-
"../src/**/*",
9-
"./**/*",
10-
]
11-
}
2+
"extends": "../tsconfig.json",
3+
"compilerOptions": {
4+
"rootDir": "../",
5+
"noEmit": true
6+
},
7+
"include": ["../src/**/*", "./**/*"]
8+
}

packages/batch/tests/unit/BatchProcessor.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
*
44
* @group unit/batch/class/batchprocessor
55
*/
6-
import type { Context } from 'aws-lambda';
76
import context from '@aws-lambda-powertools/testing-utils/context';
7+
import type { Context } from 'aws-lambda';
88
import {
9+
BatchProcessingError,
910
BatchProcessor,
1011
EventType,
11-
BatchProcessingError,
1212
FullBatchFailureError,
1313
} from '../../src/index.js';
1414
import type { BatchProcessingOptions } from '../../src/types.js';
@@ -19,9 +19,9 @@ import {
1919
} from '../helpers/factories.js';
2020
import {
2121
asyncDynamodbRecordHandler,
22+
asyncHandlerWithContext,
2223
asyncKinesisRecordHandler,
2324
asyncSqsRecordHandler,
24-
asyncHandlerWithContext,
2525
} from '../helpers/handlers.js';
2626

2727
describe('Class: AsyncBatchProcessor', () => {

packages/batch/tests/unit/BatchProcessorSync.test.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
*
44
* @group unit/batch/class/batchprocessorsync
55
*/
6-
import type { Context } from 'aws-lambda';
76
import context from '@aws-lambda-powertools/testing-utils/context';
7+
import type { Context } from 'aws-lambda';
88
import {
9+
BatchProcessingError,
910
BatchProcessorSync,
1011
EventType,
11-
BatchProcessingError,
1212
FullBatchFailureError,
1313
} from '../../src/index.js';
1414
import type { BatchProcessingOptions } from '../../src/types.js';

packages/batch/tests/unit/SqsFifoPartialProcessor.test.ts

+20-20
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
* @group unit/batch/class/sqsfifobatchprocessor
55
*/
66
import {
7+
SqsFifoMessageGroupShortCircuitError,
78
SqsFifoPartialProcessor,
8-
processPartialResponseSync,
99
SqsFifoShortCircuitError,
10-
SqsFifoMessageGroupShortCircuitError,
10+
processPartialResponseSync,
1111
} from '../../src/index.js';
1212
import { sqsRecordFactory } from '../helpers/factories.js';
1313
import { sqsRecordHandler } from '../helpers/handlers.js';
@@ -41,7 +41,7 @@ describe('Class: SqsFifoBatchProcessor', () => {
4141
);
4242

4343
// Assess
44-
expect(result['batchItemFailures']).toStrictEqual([]);
44+
expect(result.batchItemFailures).toStrictEqual([]);
4545
});
4646

4747
test('SQS FIFO Batch processor with failures', () => {
@@ -60,11 +60,11 @@ describe('Class: SqsFifoBatchProcessor', () => {
6060
);
6161

6262
// Assess
63-
expect(result['batchItemFailures'].length).toBe(2);
64-
expect(result['batchItemFailures'][0]['itemIdentifier']).toBe(
63+
expect(result.batchItemFailures.length).toBe(2);
64+
expect(result.batchItemFailures[0].itemIdentifier).toBe(
6565
secondRecord.messageId
6666
);
67-
expect(result['batchItemFailures'][1]['itemIdentifier']).toBe(
67+
expect(result.batchItemFailures[1].itemIdentifier).toBe(
6868
thirdRecord.messageId
6969
);
7070
expect(processor.errors[1]).toBeInstanceOf(SqsFifoShortCircuitError);
@@ -99,17 +99,17 @@ describe('Class: SqsFifoBatchProcessor', () => {
9999
);
100100

101101
// Assess
102-
expect(result['batchItemFailures'].length).toBe(4);
103-
expect(result['batchItemFailures'][0]['itemIdentifier']).toBe(
102+
expect(result.batchItemFailures.length).toBe(4);
103+
expect(result.batchItemFailures[0].itemIdentifier).toBe(
104104
firstRecord.messageId
105105
);
106-
expect(result['batchItemFailures'][1]['itemIdentifier']).toBe(
106+
expect(result.batchItemFailures[1].itemIdentifier).toBe(
107107
secondRecord.messageId
108108
);
109-
expect(result['batchItemFailures'][2]['itemIdentifier']).toBe(
109+
expect(result.batchItemFailures[2].itemIdentifier).toBe(
110110
thirdRecord.messageId
111111
);
112-
expect(result['batchItemFailures'][3]['itemIdentifier']).toBe(
112+
expect(result.batchItemFailures[3].itemIdentifier).toBe(
113113
fourthRecord.messageId
114114
);
115115
expect(processor.errors.length).toBe(4);
@@ -150,11 +150,11 @@ describe('Class: SqsFifoBatchProcessor', () => {
150150
);
151151

152152
// Assess
153-
expect(result['batchItemFailures'].length).toBe(2);
154-
expect(result['batchItemFailures'][0]['itemIdentifier']).toBe(
153+
expect(result.batchItemFailures.length).toBe(2);
154+
expect(result.batchItemFailures[0].itemIdentifier).toBe(
155155
thirdRecord.messageId
156156
);
157-
expect(result['batchItemFailures'][1]['itemIdentifier']).toBe(
157+
expect(result.batchItemFailures[1].itemIdentifier).toBe(
158158
fourthRecord.messageId
159159
);
160160
expect(processor.errors.length).toBe(2);
@@ -185,7 +185,7 @@ describe('Class: SqsFifoBatchProcessor', () => {
185185
);
186186

187187
// Assess
188-
expect(result['batchItemFailures'].length).toBe(0);
188+
expect(result.batchItemFailures.length).toBe(0);
189189
expect(processor.errors.length).toBe(0);
190190
});
191191

@@ -211,7 +211,7 @@ describe('Class: SqsFifoBatchProcessor', () => {
211211
);
212212

213213
// Assess
214-
expect(result['batchItemFailures'].length).toBe(0);
214+
expect(result.batchItemFailures.length).toBe(0);
215215
expect(processor.errors.length).toBe(0);
216216
});
217217

@@ -237,14 +237,14 @@ describe('Class: SqsFifoBatchProcessor', () => {
237237
);
238238

239239
// Assess
240-
expect(result['batchItemFailures'].length).toBe(3);
241-
expect(result['batchItemFailures'][0]['itemIdentifier']).toBe(
240+
expect(result.batchItemFailures.length).toBe(3);
241+
expect(result.batchItemFailures[0].itemIdentifier).toBe(
242242
secondRecord.messageId
243243
);
244-
expect(result['batchItemFailures'][1]['itemIdentifier']).toBe(
244+
expect(result.batchItemFailures[1].itemIdentifier).toBe(
245245
thirdRecord.messageId
246246
);
247-
expect(result['batchItemFailures'][2]['itemIdentifier']).toBe(
247+
expect(result.batchItemFailures[2].itemIdentifier).toBe(
248248
fourthRecord.messageId
249249
);
250250
expect(processor.errors.length).toBe(3);

packages/batch/tests/unit/processPartialResponse.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -3,19 +3,20 @@
33
*
44
* @group unit/batch/function/asyncProcesspartialresponse
55
*/
6+
import assert from 'node:assert';
7+
import context from '@aws-lambda-powertools/testing-utils/context';
68
import type {
79
Context,
810
DynamoDBStreamEvent,
911
KinesisStreamEvent,
1012
SQSEvent,
1113
} from 'aws-lambda';
12-
import context from '@aws-lambda-powertools/testing-utils/context';
1314
import {
1415
BatchProcessor,
15-
processPartialResponse,
1616
EventType,
17-
UnexpectedBatchTypeError,
1817
FullBatchFailureError,
18+
UnexpectedBatchTypeError,
19+
processPartialResponse,
1920
} from '../../src/index.js';
2021
import type {
2122
BatchProcessingOptions,
@@ -32,7 +33,6 @@ import {
3233
asyncKinesisRecordHandler,
3334
asyncSqsRecordHandler,
3435
} from '../helpers/handlers.js';
35-
import assert from 'node:assert';
3636

3737
describe('Function: processPartialResponse()', () => {
3838
const ENVIRONMENT_VARIABLES = process.env;

0 commit comments

Comments
 (0)