Skip to content

chore(maintenance): migrate batch utility to biome #2804

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 4 additions & 9 deletions packages/batch/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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"
Expand Down
4 changes: 2 additions & 2 deletions packages/batch/src/BasePartialBatchProcessor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand All @@ -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;
}

/**
Expand Down
4 changes: 2 additions & 2 deletions packages/batch/src/SqsFifoPartialProcessor.ts
Original file line number Diff line number Diff line change
@@ -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';
Expand Down
2 changes: 1 addition & 1 deletion packages/batch/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import type {
SQSRecord,
} from 'aws-lambda';
import type {
PartialItemFailureResponse,
EventSourceDataClassTypes,
PartialItemFailureResponse,
} from './types.js';

/**
Expand Down
2 changes: 1 addition & 1 deletion packages/batch/src/processPartialResponse.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js';
import type { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js';
import { UnexpectedBatchTypeError } from './errors.js';
import type {
BaseRecord,
Expand Down
2 changes: 1 addition & 1 deletion packages/batch/src/processPartialResponseSync.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js';
import type { BasePartialBatchProcessor } from './BasePartialBatchProcessor.js';
import { UnexpectedBatchTypeError } from './errors.js';
import type {
BaseRecord,
Expand Down
4 changes: 2 additions & 2 deletions packages/batch/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions packages/batch/tests/helpers/factories.ts
Original file line number Diff line number Diff line change
@@ -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 {
Expand Down Expand Up @@ -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',
Expand Down
14 changes: 7 additions & 7 deletions packages/batch/tests/helpers/handlers.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type {
Context,
DynamoDBRecord,
KinesisStreamRecord,
SQSRecord,
Context,
} from 'aws-lambda';

const sqsRecordHandler = (record: SQSRecord): string => {
Expand Down Expand Up @@ -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.');
}

Expand All @@ -56,7 +56,7 @@ const asyncDynamodbRecordHandler = async (
record: DynamoDBRecord
): Promise<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.');
}

Expand All @@ -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;
Expand All @@ -80,11 +80,11 @@ const asyncHandlerWithContext = async (
context: Context
): Promise<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 Promise.resolve(record.body);
Expand Down
17 changes: 7 additions & 10 deletions packages/batch/tests/tsconfig.json
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
{
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../",
"noEmit": true
},
"include": [
"../src/**/*",
"./**/*",
]
}
"extends": "../tsconfig.json",
"compilerOptions": {
"rootDir": "../",
"noEmit": true
},
"include": ["../src/**/*", "./**/*"]
}
6 changes: 3 additions & 3 deletions packages/batch/tests/unit/BatchProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -19,9 +19,9 @@ import {
} from '../helpers/factories.js';
import {
asyncDynamodbRecordHandler,
asyncHandlerWithContext,
asyncKinesisRecordHandler,
asyncSqsRecordHandler,
asyncHandlerWithContext,
} from '../helpers/handlers.js';

describe('Class: AsyncBatchProcessor', () => {
Expand Down
4 changes: 2 additions & 2 deletions packages/batch/tests/unit/BatchProcessorSync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
40 changes: 20 additions & 20 deletions packages/batch/tests/unit/SqsFifoPartialProcessor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -41,7 +41,7 @@ describe('Class: SqsFifoBatchProcessor', () => {
);

// Assess
expect(result['batchItemFailures']).toStrictEqual([]);
expect(result.batchItemFailures).toStrictEqual([]);
});

test('SQS FIFO Batch processor with failures', () => {
Expand All @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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);
});

Expand All @@ -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);
});

Expand All @@ -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);
Expand Down
8 changes: 4 additions & 4 deletions packages/batch/tests/unit/processPartialResponse.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -32,7 +33,6 @@ import {
asyncKinesisRecordHandler,
asyncSqsRecordHandler,
} from '../helpers/handlers.js';
import assert from 'node:assert';

describe('Function: processPartialResponse()', () => {
const ENVIRONMENT_VARIABLES = process.env;
Expand Down
Loading