Skip to content

Commit

Permalink
Switch SQS to biome
Browse files Browse the repository at this point in the history
  • Loading branch information
kibertoad committed Jul 11, 2024
1 parent 3020145 commit b8f24e8
Show file tree
Hide file tree
Showing 18 changed files with 92 additions and 199 deletions.
4 changes: 0 additions & 4 deletions packages/sqs/.eslintignore

This file was deleted.

87 changes: 0 additions & 87 deletions packages/sqs/.eslintrc.json

This file was deleted.

9 changes: 0 additions & 9 deletions packages/sqs/.prettierrc.json

This file was deleted.

1 change: 1 addition & 0 deletions packages/sqs/lib/errors/SqsConsumerErrorResolver.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { describe, expect, it } from 'vitest'
import { SqsConsumerErrorResolver } from './SqsConsumerErrorResolver'

describe('SqsConsumerErrorResolver', () => {
Expand Down
28 changes: 14 additions & 14 deletions packages/sqs/lib/sqs/AbstractSqsConsumer.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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: <explanation>
preHandlingOutputs: PreHandlingOutputs<PrehandlerOutput, any>,
): Promise<Either<'retryLater', 'success'>> {
const handler = this.handlerContainer.resolveHandler<PrehandlerOutput>(messageType)
Expand All @@ -301,7 +301,7 @@ export abstract class AbstractSqsConsumer<
return this.processPrehandlersInternal(handlerConfig.preHandlers, message)
}

protected override async preHandlerBarrier<BarrierOutput>(
protected override preHandlerBarrier<BarrierOutput>(
message: MessagePayloadType,
messageType: string,
preHandlerOutput: PrehandlerOutput,
Expand Down Expand Up @@ -449,7 +449,7 @@ export abstract class AbstractSqsConsumer<
}

private async getQueueVisibilityTimeout(): Promise<number | undefined> {
let visibilityTimeoutString
let visibilityTimeoutString: string | undefined
if (this.creationConfig) {
visibilityTimeoutString = this.creationConfig.queue.Attributes?.VisibilityTimeout
} else {
Expand All @@ -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
}
}
5 changes: 3 additions & 2 deletions packages/sqs/lib/sqs/AbstractSqsPublisher.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import type {
MessageInvalidFormatError,
MessageSchemaContainer,
MessageValidationError,
QueuePublisherOptions,
OffloadedPayloadPointerPayload,
QueuePublisherOptions,
ResolvedMessage,
} from '@message-queue-toolkit/core'
import type { ZodSchema } from 'zod'
Expand All @@ -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<MessagePayloadType extends object>
extends AbstractSqsService<MessagePayloadType>
Expand Down Expand Up @@ -70,6 +70,7 @@ export abstract class AbstractSqsPublisher<MessagePayloadType extends object>
this.logMessage(resolvedLogMessage)
}

// biome-ignore lint/style/noParameterAssign: This is expected
message = this.updateInternalProperties(message)
const maybeOffloadedPayloadMessage = await this.offloadMessagePayloadIfNeeded(message, () =>
calculateOutgoingMessageSize(message),
Expand Down
2 changes: 1 addition & 1 deletion packages/sqs/lib/utils/sqsAttributeUtils.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { describe } from 'vitest'
import { describe, expect, it } from 'vitest'

import {
generateQueuePublishForTopicPolicy,
Expand Down
2 changes: 1 addition & 1 deletion packages/sqs/lib/utils/sqsInitter.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down
2 changes: 1 addition & 1 deletion packages/sqs/lib/utils/sqsMessageDeserializer.spec.ts
Original file line number Diff line number Diff line change
@@ -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', () => {
Expand Down
6 changes: 3 additions & 3 deletions packages/sqs/lib/utils/sqsUtils.ts
Original file line number Diff line number Diff line change
@@ -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'
Expand Down
34 changes: 9 additions & 25 deletions packages/sqs/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -34,41 +34,25 @@
"@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",
"repository": {
"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/*"]
}
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down
Loading

0 comments on commit b8f24e8

Please sign in to comment.