diff --git a/packages/sqs/.eslintignore b/packages/sqs/.eslintignore deleted file mode 100644 index dcaed66f..00000000 --- a/packages/sqs/.eslintignore +++ /dev/null @@ -1,4 +0,0 @@ -node_modules/ -coverage/ -dist/ -vitest.config.mts diff --git a/packages/sqs/.eslintrc.json b/packages/sqs/.eslintrc.json deleted file mode 100644 index c3989a69..00000000 --- a/packages/sqs/.eslintrc.json +++ /dev/null @@ -1,87 +0,0 @@ -{ - "parser": "@typescript-eslint/parser", - "parserOptions": { - "ecmaVersion": 2022, - "sourceType": "module", - "project": "./tsconfig.json" - }, - "ignorePatterns": ["node_modules"], - "plugins": ["@typescript-eslint", "vitest", "import"], - "extends": [ - "eslint:recommended", - "plugin:@typescript-eslint/recommended", - "plugin:@typescript-eslint/recommended-requiring-type-checking", - "plugin:import/recommended", - "plugin:import/typescript", - "plugin:vitest/recommended" - ], - "rules": { - "no-empty": "off", - "@typescript-eslint/no-empty-function": "off", - "@typescript-eslint/no-empty-interface": "warn", - "@typescript-eslint/ban-ts-comment": "off", - "@typescript-eslint/no-use-before-define": "off", - "@typescript-eslint/no-non-null-assertion": "warn", - "@typescript-eslint/no-var-requires": "off", - "@typescript-eslint/indent": "off", - "@typescript-eslint/no-explicit-any": "warn", - "@typescript-eslint/restrict-template-expressions": "off", - "@typescript-eslint/no-unsafe-assignment": "off", - "@typescript-eslint/no-unsafe-argument": "off", - "@typescript-eslint/no-unsafe-call": "off", - "@typescript-eslint/no-unsafe-member-access": "warn", - "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/consistent-type-imports": "warn", - "@typescript-eslint/no-unused-vars": [ - "warn", - { - "argsIgnorePattern": "^_", - "varsIgnorePattern": "^_", - "caughtErrorsIgnorePattern": "^_" - } - ], - "@typescript-eslint/require-await": "off", - "@typescript-eslint/member-delimiter-style": [ - "error", - { - "multiline": { - "delimiter": "none", - "requireLast": false - }, - "singleline": { - "delimiter": "comma", - "requireLast": false - } - } - ], - "import/no-default-export": "error", - "import/order": [ - "warn", - { - "alphabetize": { "order": "asc" }, - "newlines-between": "always" - } - ], - "max-lines": ["error", { "max": 600 }], - "max-params": ["error", { "max": 4 }], - "max-statements": ["error", { "max": 30 }], - "complexity": ["error", { "max": 20 }] - }, - "overrides": [ - { - "files": ["test/**/*.ts", "*.test.ts", "*.spec.ts"], - "rules": { - "@typescript-eslint/no-unsafe-argument": "off", - "@typescript-eslint/no-explicit-any": "off", - "@typescript-eslint/no-empty-function": "off", - "@typescript-eslint/no-non-null-assertion": "off", - "@typescript-eslint/no-unsafe-return": "off", - "@typescript-eslint/no-unsafe-assignment": "off", - "@typescript-eslint/no-unsafe-member-access": "off", - "@typescript-eslint/no-unsafe-call": "off", - "@typescript-eslint/restrict-template-expressions": "off", - "max-statements": ["off"] - } - } - ] -} diff --git a/packages/sqs/.prettierrc.json b/packages/sqs/.prettierrc.json deleted file mode 100644 index b59d4dd3..00000000 --- a/packages/sqs/.prettierrc.json +++ /dev/null @@ -1,9 +0,0 @@ -{ - "printWidth": 100, - "singleQuote": true, - "bracketSpacing": true, - "semi": false, - "arrowParens": "always", - "endOfLine": "lf", - "trailingComma": "all" -} diff --git a/packages/sqs/lib/errors/SqsConsumerErrorResolver.spec.ts b/packages/sqs/lib/errors/SqsConsumerErrorResolver.spec.ts index ccf1f6e1..9105e69b 100644 --- a/packages/sqs/lib/errors/SqsConsumerErrorResolver.spec.ts +++ b/packages/sqs/lib/errors/SqsConsumerErrorResolver.spec.ts @@ -1,3 +1,4 @@ +import { describe, expect, it } from 'vitest' import { SqsConsumerErrorResolver } from './SqsConsumerErrorResolver' describe('SqsConsumerErrorResolver', () => { diff --git a/packages/sqs/lib/sqs/AbstractSqsConsumer.ts b/packages/sqs/lib/sqs/AbstractSqsConsumer.ts index 1087dace..74fbcb25 100644 --- a/packages/sqs/lib/sqs/AbstractSqsConsumer.ts +++ b/packages/sqs/lib/sqs/AbstractSqsConsumer.ts @@ -1,18 +1,18 @@ import { SendMessageCommand, SetQueueAttributesCommand } from '@aws-sdk/client-sqs' import type { Either, ErrorResolver } from '@lokalise/node-core' import type { - QueueConsumer, - TransactionObservabilityManager, - QueueConsumerOptions, - PreHandlingOutputs, - Prehandler, BarrierResult, - QueueConsumerDependencies, DeadLetterQueueOptions, - ParseMessageResult, MessageSchemaContainer, + ParseMessageResult, + PreHandlingOutputs, + Prehandler, + QueueConsumer, + QueueConsumerDependencies, + QueueConsumerOptions, + TransactionObservabilityManager, } from '@message-queue-toolkit/core' -import { isMessageError, parseMessage, HandlerContainer } from '@message-queue-toolkit/core' +import { HandlerContainer, isMessageError, parseMessage } from '@message-queue-toolkit/core' import { Consumer } from 'sqs-consumer' import type { ConsumerOptions } from 'sqs-consumer/src/types' @@ -182,7 +182,7 @@ export abstract class AbstractSqsConsumer< sqs: this.sqsClient, queueUrl: this.queueUrl, visibilityTimeout, - messageAttributeNames: [PAYLOAD_OFFLOADING_ATTRIBUTE_PREFIX + '*'], + messageAttributeNames: [`${PAYLOAD_OFFLOADING_ATTRIBUTE_PREFIX}*`], ...this.consumerOptionsOverride, handleMessage: async (message: SQSMessage) => { if (message === null) return @@ -284,10 +284,10 @@ export abstract class AbstractSqsConsumer< return { error: 'retryLater' } } - protected override async processMessage( + protected override processMessage( message: MessagePayloadType, messageType: string, - // eslint-disable-next-line @typescript-eslint/no-explicit-any + // biome-ignore lint/suspicious/noExplicitAny: preHandlingOutputs: PreHandlingOutputs, ): Promise> { const handler = this.handlerContainer.resolveHandler(messageType) @@ -301,7 +301,7 @@ export abstract class AbstractSqsConsumer< return this.processPrehandlersInternal(handlerConfig.preHandlers, message) } - protected override async preHandlerBarrier( + protected override preHandlerBarrier( message: MessagePayloadType, messageType: string, preHandlerOutput: PrehandlerOutput, @@ -449,7 +449,7 @@ export abstract class AbstractSqsConsumer< } private async getQueueVisibilityTimeout(): Promise { - let visibilityTimeoutString + let visibilityTimeoutString: string | undefined if (this.creationConfig) { visibilityTimeoutString = this.creationConfig.queue.Attributes?.VisibilityTimeout } else { @@ -463,6 +463,6 @@ export abstract class AbstractSqsConsumer< } // parseInt is safe because if the value is not a number process should have failed on init - return visibilityTimeoutString ? parseInt(visibilityTimeoutString) : undefined + return visibilityTimeoutString ? Number.parseInt(visibilityTimeoutString) : undefined } } diff --git a/packages/sqs/lib/sqs/AbstractSqsPublisher.ts b/packages/sqs/lib/sqs/AbstractSqsPublisher.ts index 26f831d1..0ee2f590 100644 --- a/packages/sqs/lib/sqs/AbstractSqsPublisher.ts +++ b/packages/sqs/lib/sqs/AbstractSqsPublisher.ts @@ -8,8 +8,8 @@ import type { MessageInvalidFormatError, MessageSchemaContainer, MessageValidationError, - QueuePublisherOptions, OffloadedPayloadPointerPayload, + QueuePublisherOptions, ResolvedMessage, } from '@message-queue-toolkit/core' import type { ZodSchema } from 'zod' @@ -27,7 +27,7 @@ export type SQSMessageOptions = { } export const PAYLOAD_OFFLOADING_ATTRIBUTE_PREFIX = 'payloadOffloading.' -export const OFFLOADED_PAYLOAD_SIZE_ATTRIBUTE = PAYLOAD_OFFLOADING_ATTRIBUTE_PREFIX + 'size' +export const OFFLOADED_PAYLOAD_SIZE_ATTRIBUTE = `${PAYLOAD_OFFLOADING_ATTRIBUTE_PREFIX}size` export abstract class AbstractSqsPublisher extends AbstractSqsService @@ -70,6 +70,7 @@ export abstract class AbstractSqsPublisher this.logMessage(resolvedLogMessage) } + // biome-ignore lint/style/noParameterAssign: This is expected message = this.updateInternalProperties(message) const maybeOffloadedPayloadMessage = await this.offloadMessagePayloadIfNeeded(message, () => calculateOutgoingMessageSize(message), diff --git a/packages/sqs/lib/utils/sqsAttributeUtils.spec.ts b/packages/sqs/lib/utils/sqsAttributeUtils.spec.ts index 62a99d50..c2810e04 100644 --- a/packages/sqs/lib/utils/sqsAttributeUtils.spec.ts +++ b/packages/sqs/lib/utils/sqsAttributeUtils.spec.ts @@ -1,4 +1,4 @@ -import { describe } from 'vitest' +import { describe, expect, it } from 'vitest' import { generateQueuePublishForTopicPolicy, diff --git a/packages/sqs/lib/utils/sqsInitter.ts b/packages/sqs/lib/utils/sqsInitter.ts index 268bb138..cf3f1bb5 100644 --- a/packages/sqs/lib/utils/sqsInitter.ts +++ b/packages/sqs/lib/utils/sqsInitter.ts @@ -1,5 +1,5 @@ import { SetQueueAttributesCommand } from '@aws-sdk/client-sqs' -import type { SQSClient, QueueAttributeName } from '@aws-sdk/client-sqs' +import type { QueueAttributeName, SQSClient } from '@aws-sdk/client-sqs' import type { DeletionConfig } from '@message-queue-toolkit/core' import { isProduction } from '@message-queue-toolkit/core' diff --git a/packages/sqs/lib/utils/sqsMessageDeserializer.spec.ts b/packages/sqs/lib/utils/sqsMessageDeserializer.spec.ts index a98c6215..1d845e89 100644 --- a/packages/sqs/lib/utils/sqsMessageDeserializer.spec.ts +++ b/packages/sqs/lib/utils/sqsMessageDeserializer.spec.ts @@ -1,8 +1,8 @@ +import { describe, expect, it } from 'vitest' import type { PERMISSIONS_MESSAGE_TYPE } from '../../test/consumers/userConsumerSchemas' import { PERMISSIONS_MESSAGE_SCHEMA } from '../../test/consumers/userConsumerSchemas' import { SqsConsumerErrorResolver } from '../errors/SqsConsumerErrorResolver' import type { SQSMessage } from '../types/MessageTypes' - import { deserializeSQSMessage } from './sqsMessageDeserializer' describe('messageDeserializer', () => { diff --git a/packages/sqs/lib/utils/sqsUtils.ts b/packages/sqs/lib/utils/sqsUtils.ts index 4faa2f43..d60c15ad 100644 --- a/packages/sqs/lib/utils/sqsUtils.ts +++ b/packages/sqs/lib/utils/sqsUtils.ts @@ -1,15 +1,15 @@ import { CreateQueueCommand, - GetQueueUrlCommand, DeleteQueueCommand, GetQueueAttributesCommand, - SetQueueAttributesCommand, + GetQueueUrlCommand, ListQueuesCommand, + SetQueueAttributesCommand, } from '@aws-sdk/client-sqs' import type { CreateQueueCommandInput, - SQSClient, QueueAttributeName, + SQSClient, SendMessageCommandInput, } from '@aws-sdk/client-sqs' import type { Either } from '@lokalise/node-core' diff --git a/packages/sqs/package.json b/packages/sqs/package.json index 44bbf084..76be3bff 100644 --- a/packages/sqs/package.json +++ b/packages/sqs/package.json @@ -18,8 +18,8 @@ "test": "vitest", "test:coverage": "npm test -- --coverage", "test:ci": "npm run docker:start:dev && npm run test:coverage && npm run docker:stop:dev", - "lint": "eslint . --ext .ts && tsc --noEmit", - "lint:fix": "prettier --write . && eslint . --ext .ts --fix", + "lint": "biome check && tsc --project tsconfig.json --noEmit", + "lint:fix": "biome check --write .", "docker:start:dev": "docker compose up -d", "docker:stop:dev": "docker compose down", "prepublishOnly": "npm run build:release" @@ -34,22 +34,18 @@ "@message-queue-toolkit/core": "^15.0.0" }, "devDependencies": { - "@aws-sdk/client-s3": "^3.608.0", - "@aws-sdk/client-sqs": "^3.606.0", + "@aws-sdk/client-s3": "^3.614.0", + "@aws-sdk/client-sqs": "^3.614.0", + "@biomejs/biome": "1.8.3", + "@kibertoad/biome-config": "^1.2.1", "@message-queue-toolkit/core": "*", "@message-queue-toolkit/s3-payload-store": "*", "@types/node": "^20.12.8", - "@typescript-eslint/eslint-plugin": "^7.1.1", - "@typescript-eslint/parser": "^7.1.1", "@vitest/coverage-v8": "^1.6.0", "awilix": "^10.0.1", "awilix-manager": "^5.1.0", "del-cli": "^5.1.0", - "eslint": "^8.57.0", - "eslint-plugin-import": "^2.29.1", - "eslint-plugin-vitest": "0.4.1", - "prettier": "^3.2.5", - "typescript": "^5.4.5", + "typescript": "^5.5.3", "vitest": "^1.6.0" }, "homepage": "https://github.com/kibertoad/message-queue-toolkit", @@ -57,18 +53,6 @@ "type": "git", "url": "git://github.com/kibertoad/message-queue-toolkit.git" }, - "keywords": [ - "message", - "queue", - "queues", - "abstract", - "common", - "utils", - "sqs" - ], - "files": [ - "README.md", - "LICENSE", - "dist/*" - ] + "keywords": ["message", "queue", "queues", "abstract", "common", "utils", "sqs"], + "files": ["README.md", "LICENSE", "dist/*"] } diff --git a/packages/sqs/test/consumers/SqsPermissionConsumer.payloadOffloading.spec.ts b/packages/sqs/test/consumers/SqsPermissionConsumer.payloadOffloading.spec.ts index b35527c7..53643608 100644 --- a/packages/sqs/test/consumers/SqsPermissionConsumer.payloadOffloading.spec.ts +++ b/packages/sqs/test/consumers/SqsPermissionConsumer.payloadOffloading.spec.ts @@ -3,7 +3,7 @@ import type { PayloadStoreConfig } from '@message-queue-toolkit/core' import { S3PayloadStore } from '@message-queue-toolkit/s3-payload-store' import type { AwilixContainer } from 'awilix' import { asValue } from 'awilix' -import { describe, beforeEach, afterEach, expect, it } from 'vitest' +import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest' import { SQS_MESSAGE_MAX_SIZE } from '../../lib/sqs/AbstractSqsService' import { SqsPermissionPublisher } from '../publishers/SqsPermissionPublisher' diff --git a/packages/sqs/test/consumers/SqsPermissionConsumer.spec.ts b/packages/sqs/test/consumers/SqsPermissionConsumer.spec.ts index 7e67c3d0..86dafbe5 100644 --- a/packages/sqs/test/consumers/SqsPermissionConsumer.spec.ts +++ b/packages/sqs/test/consumers/SqsPermissionConsumer.spec.ts @@ -1,20 +1,19 @@ -/* eslint-disable max-lines */ import { setTimeout } from 'node:timers/promises' -import type { SendMessageCommandInput, SQSClient } from '@aws-sdk/client-sqs' -import { SendMessageCommand, ReceiveMessageCommand } from '@aws-sdk/client-sqs' +import type { SQSClient, SendMessageCommandInput } from '@aws-sdk/client-sqs' +import { ReceiveMessageCommand, SendMessageCommand } from '@aws-sdk/client-sqs' import { waitAndRetry } from '@lokalise/node-core' import type { BarrierResult } from '@message-queue-toolkit/core' import type { AwilixContainer } from 'awilix' -import { asValue, asClass, asFunction } from 'awilix' -import { describe, beforeEach, afterEach, expect, it } from 'vitest' +import { asClass, asFunction, asValue } from 'awilix' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { ZodError } from 'zod' import { FakeConsumerErrorResolver } from '../../lib/fakes/FakeConsumerErrorResolver' import { assertQueue, deleteQueue, getQueueAttributes } from '../../lib/utils/sqsUtils' import { FakeLogger } from '../fakes/FakeLogger' import { SqsPermissionPublisher } from '../publishers/SqsPermissionPublisher' -import { registerDependencies, SINGLETON_CONFIG } from '../utils/testContext' +import { SINGLETON_CONFIG, registerDependencies } from '../utils/testContext' import type { Dependencies } from '../utils/testContext' import { SqsPermissionConsumer } from './SqsPermissionConsumer' @@ -230,15 +229,15 @@ describe('SqsPermissionConsumer', () => { QueueName: publisher.queueProps.name, }, }, - addPreHandlerBarrier: async (_msg): Promise> => { + addPreHandlerBarrier: (_msg): Promise> => { barrierCounter++ if (barrierCounter < 2) { - return { + return Promise.resolve({ isPassing: false, - } + }) } - return { isPassing: true, output: barrierCounter } + return Promise.resolve({ isPassing: true, output: barrierCounter }) }, }) await newConsumer.start() @@ -263,14 +262,14 @@ describe('SqsPermissionConsumer', () => { QueueName: publisher.queueProps.name, }, }, - addPreHandlerBarrier: async ( + addPreHandlerBarrier: ( message, - executionContext, + _executionContext, preHandlerOutput, ): Promise> => { expect(preHandlerOutput.messageId).toBe(message.id) - return { isPassing: true, output: 1 } + return Promise.resolve({ isPassing: true, output: 1 }) }, }) await newConsumer.start() @@ -338,14 +337,14 @@ describe('SqsPermissionConsumer', () => { QueueName: publisher.queueProps.name, }, }, - removeHandlerOverride: async (message, _context, preHandlerOutputs) => { + removeHandlerOverride: (message, _context, preHandlerOutputs) => { expect(preHandlerOutputs.preHandlerOutput.messageId).toEqual(message.id) - return { + return Promise.resolve({ result: 'success', - } + }) }, removePreHandlers: [ - (message, context, preHandlerOutput, next) => { + (message, _context, preHandlerOutput, next) => { preHandlerOutput.messageId = message.id next({ result: 'success', @@ -374,21 +373,21 @@ describe('SqsPermissionConsumer', () => { QueueName: publisher.queueProps.name, }, }, - removeHandlerOverride: async (message, _context, preHandlerOutputs) => { - expect(preHandlerOutputs.preHandlerOutput.messageId).toEqual(message.id + ' adjusted') - return { + removeHandlerOverride: (message, _context, preHandlerOutputs) => { + expect(preHandlerOutputs.preHandlerOutput.messageId).toEqual(`${message.id} adjusted`) + return Promise.resolve({ result: 'success', - } + }) }, removePreHandlers: [ - (message, context, preHandlerOutput, next) => { + (message, _context, preHandlerOutput, next) => { preHandlerOutput.messageId = message.id next({ result: 'success', }) }, - (message, context, preHandlerOutput, next) => { + (_message, _context, preHandlerOutput, next) => { preHandlerOutput.messageId += ' adjusted' next({ result: 'success', @@ -535,9 +534,9 @@ describe('SqsPermissionConsumer', () => { const consumer2 = new SqsPermissionConsumer(diContainer.cradle, { locatorConfig: { queueUrl: consumer1.queueProps.url }, - removeHandlerOverride: async () => { + removeHandlerOverride: () => { consumer2Counter++ - return { result: 'success' } + return Promise.resolve({ result: 'success' }) }, }) const publisher = new SqsPermissionPublisher(diContainer.cradle, { diff --git a/packages/sqs/test/consumers/SqsPermissionConsumer.ts b/packages/sqs/test/consumers/SqsPermissionConsumer.ts index dd350b71..1385e8f5 100644 --- a/packages/sqs/test/consumers/SqsPermissionConsumer.ts +++ b/packages/sqs/test/consumers/SqsPermissionConsumer.ts @@ -1,6 +1,6 @@ import type { Either } from '@lokalise/node-core' import { MessageHandlerConfigBuilder } from '@message-queue-toolkit/core' -import type { BarrierResult, Prehandler, PreHandlingOutputs } from '@message-queue-toolkit/core' +import type { BarrierResult, PreHandlingOutputs, Prehandler } from '@message-queue-toolkit/core' import type { SQSConsumerDependencies, SQSConsumerOptions } from '../../lib/sqs/AbstractSqsConsumer' import { AbstractSqsConsumer } from '../../lib/sqs/AbstractSqsConsumer' @@ -66,15 +66,15 @@ export class SqsPermissionConsumer extends AbstractSqsConsumer< }, }, ) { - const defaultRemoveHandler = async ( + const defaultRemoveHandler = ( _message: SupportedMessages, context: ExecutionContext, _preHandlingOutputs: PreHandlingOutputs, ): Promise> => { this.removeCounter += context.incrementAmount - return { + return Promise.resolve({ result: 'success', - } + }) } super( @@ -106,14 +106,14 @@ export class SqsPermissionConsumer extends AbstractSqsConsumer< >() .addConfig( PERMISSIONS_ADD_MESSAGE_SCHEMA, - async (_message, context, barrierOutput) => { + (_message, context, barrierOutput) => { if (options.addPreHandlerBarrier && !barrierOutput) { - return { error: 'retryLater' } + return Promise.resolve({ error: 'retryLater' }) } this.addCounter += context.incrementAmount - return { + return Promise.resolve({ result: 'success', - } + }) }, { preHandlerBarrier: options.addPreHandlerBarrier, diff --git a/packages/sqs/test/consumers/SqsPermisssionConsumer.deadLetterQueue.spec.ts b/packages/sqs/test/consumers/SqsPermisssionConsumer.deadLetterQueue.spec.ts index 44b27f83..95e22a19 100644 --- a/packages/sqs/test/consumers/SqsPermisssionConsumer.deadLetterQueue.spec.ts +++ b/packages/sqs/test/consumers/SqsPermisssionConsumer.deadLetterQueue.spec.ts @@ -3,7 +3,7 @@ import { SendMessageCommand } from '@aws-sdk/client-sqs' import { waitAndRetry } from '@lokalise/node-core' import type { AwilixContainer } from 'awilix' import { Consumer } from 'sqs-consumer' -import { afterEach, beforeEach, describe, expect, it } from 'vitest' +import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest' import type { SQSMessage } from '../../lib/types/MessageTypes' import { assertQueue, deleteQueue, getQueueAttributes } from '../../lib/utils/sqsUtils' @@ -224,7 +224,7 @@ describe('SqsPermissionConsumer - deadLetterQueue', () => { creationConfig: { queue: { QueueName: deadLetterQueueName } }, redrivePolicy: { maxReceiveCount: 2 }, }, - removeHandlerOverride: async () => { + removeHandlerOverride: () => { counter++ throw new Error('Error') }, @@ -235,15 +235,16 @@ describe('SqsPermissionConsumer - deadLetterQueue', () => { const dlqConsumer = Consumer.create({ sqs: diContainer.cradle.sqsClient, queueUrl: consumer.dlqUrl, - handleMessage: async (message: SQSMessage) => { + handleMessage: (message: SQSMessage) => { dlqMessage = message + return Promise.resolve() }, }) dlqConsumer.start() await permissionPublisher.publish({ id: '1', messageType: 'remove' }) - await waitAndRetry(async () => dlqMessage, 50, 20) + await waitAndRetry(() => dlqMessage, 50, 20) expect(counter).toBe(2) expect(JSON.parse(dlqMessage.Body)).toEqual({ @@ -265,13 +266,15 @@ describe('SqsPermissionConsumer - deadLetterQueue', () => { creationConfig: { queue: { QueueName: deadLetterQueueName } }, redrivePolicy: { maxReceiveCount: 1 }, }, - removeHandlerOverride: async (message) => { + removeHandlerOverride: (message) => { if (message.id !== sqsMessage.id) { throw new Error('not expected message') } counter++ messageArrivalTime.push(new Date().getTime()) - return counter < 2 ? { error: 'retryLater' } : { result: 'success' } + return counter < 2 + ? Promise.resolve({ error: 'retryLater' }) + : Promise.resolve({ result: 'success' }) }, }) await consumer.start() @@ -303,8 +306,9 @@ describe('SqsPermissionConsumer - deadLetterQueue', () => { const dlqConsumer = Consumer.create({ sqs: diContainer.cradle.sqsClient, queueUrl: consumer.dlqUrl, - handleMessage: async (message: SQSMessage) => { + handleMessage: (message: SQSMessage) => { dlqMessage = message + return Promise.resolve() }, }) dlqConsumer.start() @@ -344,8 +348,9 @@ describe('SqsPermissionConsumer - deadLetterQueue', () => { const dlqConsumer = Consumer.create({ sqs: diContainer.cradle.sqsClient, queueUrl: consumer.dlqUrl, - handleMessage: async (message: SQSMessage) => { + handleMessage: (message: SQSMessage) => { dlqMessage = message + return Promise.resolve() }, }) dlqConsumer.start() @@ -385,7 +390,7 @@ describe('SqsPermissionConsumer - deadLetterQueue', () => { redrivePolicy: { maxReceiveCount: 200 }, }, maxRetryDuration: 2, - removeHandlerOverride: async () => { + removeHandlerOverride: () => { counter++ return Promise.resolve({ error: 'retryLater' }) }, @@ -396,8 +401,9 @@ describe('SqsPermissionConsumer - deadLetterQueue', () => { const dlqConsumer = Consumer.create({ sqs: diContainer.cradle.sqsClient, queueUrl: consumer.dlqUrl, - handleMessage: async (message: SQSMessage) => { + handleMessage: (message: SQSMessage) => { dlqMessage = message + return Promise.resolve() }, }) dlqConsumer.start() diff --git a/packages/sqs/test/publishers/SqsPermissionPublisher.payloadOffloading.spec.ts b/packages/sqs/test/publishers/SqsPermissionPublisher.payloadOffloading.spec.ts index d5e68e34..d04ae891 100644 --- a/packages/sqs/test/publishers/SqsPermissionPublisher.payloadOffloading.spec.ts +++ b/packages/sqs/test/publishers/SqsPermissionPublisher.payloadOffloading.spec.ts @@ -14,7 +14,7 @@ import { import type { AwilixContainer } from 'awilix' import { asValue } from 'awilix' import { Consumer } from 'sqs-consumer' -import { describe, beforeEach, afterEach, expect, it } from 'vitest' +import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest' import type { PERMISSIONS_ADD_MESSAGE_TYPE } from '../consumers/userConsumerSchemas' import { assertBucket, getObjectContent } from '../utils/s3Utils' @@ -60,11 +60,12 @@ describe('SqsPermissionPublisher', () => { receivedSqsMessages = [] consumer = Consumer.create({ queueUrl, - handleMessage: async (message: Message) => { + handleMessage: (message: Message) => { if (message === null) { - return + return Promise.resolve() } receivedSqsMessages.push(message) + return Promise.resolve() }, sqs: sqsClient, messageAttributeNames: [OFFLOADED_PAYLOAD_SIZE_ATTRIBUTE], diff --git a/packages/sqs/test/publishers/SqsPermissionPublisher.spec.ts b/packages/sqs/test/publishers/SqsPermissionPublisher.spec.ts index 9baecd1b..69869afa 100644 --- a/packages/sqs/test/publishers/SqsPermissionPublisher.spec.ts +++ b/packages/sqs/test/publishers/SqsPermissionPublisher.spec.ts @@ -2,7 +2,7 @@ import type { SQSClient } from '@aws-sdk/client-sqs' import { waitAndRetry } from '@lokalise/node-core' import type { AwilixContainer } from 'awilix' import { Consumer } from 'sqs-consumer' -import { afterEach, beforeEach, describe, expect, it } from 'vitest' +import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest' import { FakeConsumerErrorResolver } from '../../lib/fakes/FakeConsumerErrorResolver' import type { SQSMessage } from '../../lib/types/MessageTypes' @@ -202,9 +202,9 @@ describe('SqsPermissionPublisher', () => { let receivedMessage: unknown const consumer = Consumer.create({ queueUrl: queueUrl, - handleMessage: async (message: SQSMessage) => { + handleMessage: (message: SQSMessage) => { if (message === null) { - return + return Promise.resolve() } const decodedMessage = deserializeSQSMessage( message as any, @@ -212,6 +212,7 @@ describe('SqsPermissionPublisher', () => { new FakeConsumerErrorResolver(), ) receivedMessage = decodedMessage.result! + return Promise.resolve() }, sqs: diContainer.cradle.sqsClient, }) diff --git a/packages/sqs/test/utils/testContext.ts b/packages/sqs/test/utils/testContext.ts index 4b5d4fde..0bad3f5b 100644 --- a/packages/sqs/test/utils/testContext.ts +++ b/packages/sqs/test/utils/testContext.ts @@ -3,7 +3,7 @@ import { SQSClient } from '@aws-sdk/client-sqs' import type { ErrorReporter, ErrorResolver } from '@lokalise/node-core' import type { Logger, TransactionObservabilityManager } from '@message-queue-toolkit/core' import type { Resolver } from 'awilix' -import { asClass, asFunction, createContainer, Lifetime } from 'awilix' +import { Lifetime, asClass, asFunction, createContainer } from 'awilix' import { AwilixManager } from 'awilix-manager' import { SqsConsumerErrorResolver } from '../../lib/errors/SqsConsumerErrorResolver' @@ -88,7 +88,7 @@ export async function registerDependencies(dependencyOverrides: DependencyOverri return diContainer } -// eslint-disable-next-line @typescript-eslint/no-explicit-any +// biome-ignore lint/suspicious/noExplicitAny: This is expected type DiConfig = Record> export interface Dependencies {