From 172580d4864cd6f973e2d8dc3f2df24ca5fa8fac Mon Sep 17 00:00:00 2001 From: CarlosGamero Date: Wed, 28 Aug 2024 12:52:25 +0200 Subject: [PATCH 1/6] s3-payload-store biome migration --- packages/s3-payload-store/.eslintignore | 4 - packages/s3-payload-store/.eslintrc.json | 80 ------------------- packages/s3-payload-store/.prettierignore | 2 - packages/s3-payload-store/.prettierrc.json | 9 --- packages/s3-payload-store/package.json | 18 ++--- .../test/store/S3PayloadStore.spec.ts | 4 +- .../s3-payload-store/test/utils/s3Utils.ts | 6 +- 7 files changed, 11 insertions(+), 112 deletions(-) delete mode 100644 packages/s3-payload-store/.eslintignore delete mode 100644 packages/s3-payload-store/.eslintrc.json delete mode 100644 packages/s3-payload-store/.prettierignore delete mode 100644 packages/s3-payload-store/.prettierrc.json diff --git a/packages/s3-payload-store/.eslintignore b/packages/s3-payload-store/.eslintignore deleted file mode 100644 index dcaed66f..00000000 --- a/packages/s3-payload-store/.eslintignore +++ /dev/null @@ -1,4 +0,0 @@ -node_modules/ -coverage/ -dist/ -vitest.config.mts diff --git a/packages/s3-payload-store/.eslintrc.json b/packages/s3-payload-store/.eslintrc.json deleted file mode 100644 index 3e54957f..00000000 --- a/packages/s3-payload-store/.eslintrc.json +++ /dev/null @@ -1,80 +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": { - "@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/restrict-template-expressions": "off", - "@typescript-eslint/no-explicit-any": "warn", - "@typescript-eslint/no-unsafe-member-access": "off", - "@typescript-eslint/no-unsafe-assignment": "off", - "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/consistent-type-imports": "warn", - "@typescript-eslint/no-unused-vars": [ - "warn", - { - "argsIgnorePattern": "^_", - "varsIgnorePattern": "^_", - "caughtErrorsIgnorePattern": "^_" - } - ], - "@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/require-await": "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", - "max-statements": ["off"] - } - } - ] -} diff --git a/packages/s3-payload-store/.prettierignore b/packages/s3-payload-store/.prettierignore deleted file mode 100644 index bd95794d..00000000 --- a/packages/s3-payload-store/.prettierignore +++ /dev/null @@ -1,2 +0,0 @@ -package-lock.json -dist diff --git a/packages/s3-payload-store/.prettierrc.json b/packages/s3-payload-store/.prettierrc.json deleted file mode 100644 index b59d4dd3..00000000 --- a/packages/s3-payload-store/.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/s3-payload-store/package.json b/packages/s3-payload-store/package.json index fd12c573..a435ca79 100644 --- a/packages/s3-payload-store/package.json +++ b/packages/s3-payload-store/package.json @@ -22,8 +22,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" @@ -35,15 +35,11 @@ }, "devDependencies": { "@message-queue-toolkit/core": "*", + "@biomejs/biome": "1.8.3", + "@kibertoad/biome-config": "^1.2.1", "@types/node": "^22.0.0", - "@typescript-eslint/eslint-plugin": "^8.0.1", - "@typescript-eslint/parser": "^8.0.1", "@vitest/coverage-v8": "^2.0.4", "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.5.3", "vitest": "^2.0.4" }, @@ -64,9 +60,5 @@ "store", "claim-check" ], - "files": [ - "README.md", - "LICENSE", - "dist/*" - ] + "files": ["README.md", "LICENSE", "dist/*"] } diff --git a/packages/s3-payload-store/test/store/S3PayloadStore.spec.ts b/packages/s3-payload-store/test/store/S3PayloadStore.spec.ts index 61c5596d..0eb77a69 100644 --- a/packages/s3-payload-store/test/store/S3PayloadStore.spec.ts +++ b/packages/s3-payload-store/test/store/S3PayloadStore.spec.ts @@ -1,7 +1,7 @@ import { Readable } from 'node:stream' import { S3 } from '@aws-sdk/client-s3' -import { describe, beforeEach, expect, it, beforeAll } from 'vitest' +import { beforeAll, beforeEach, describe, expect, it } from 'vitest' import { S3PayloadStore } from '../../lib/S3PayloadStore' import { assertEmptyBucket, getObjectContent, objectExists } from '../utils/s3Utils' @@ -14,7 +14,7 @@ describe('S3PayloadStore', () => { let s3: S3 let store: S3PayloadStore - beforeAll(async () => { + beforeAll(() => { s3 = new S3(TEST_AWS_CONFIG) store = new S3PayloadStore({ s3 }, { bucketName: TEST_BUCKET }) }) diff --git a/packages/s3-payload-store/test/utils/s3Utils.ts b/packages/s3-payload-store/test/utils/s3Utils.ts index 056a0fbc..e9f8b940 100644 --- a/packages/s3-payload-store/test/utils/s3Utils.ts +++ b/packages/s3-payload-store/test/utils/s3Utils.ts @@ -8,7 +8,9 @@ export async function assertEmptyBucket(s3: S3, bucketName: string) { if (objects.Contents?.length) { await s3.deleteObjects({ Bucket: bucketName, - Delete: { Objects: objects.Contents?.map((object) => ({ Key: object.Key })) }, + Delete: { + Objects: objects.Contents?.map((object) => ({ Key: object.Key })), + }, }) } } catch (e) { @@ -28,7 +30,7 @@ export async function objectExists(s3: S3, bucket: string, key: string) { try { await s3.headObject({ Bucket: bucket, Key: key }) return true - } catch (e) { + } catch (_) { return false } } From 7087a65743c257aa3eaedbf40e22bed3bb7cb716 Mon Sep 17 00:00:00 2001 From: CarlosGamero Date: Wed, 28 Aug 2024 12:54:50 +0200 Subject: [PATCH 2/6] schemas biome migration --- packages/schemas/.eslintignore | 4 - packages/schemas/.eslintrc.json | 80 ------------------- packages/schemas/.prettierignore | 2 - packages/schemas/.prettierrc.json | 9 --- .../schemas/lib/events/baseEventSchemas.ts | 2 +- packages/schemas/package.json | 18 ++--- 6 files changed, 6 insertions(+), 109 deletions(-) delete mode 100644 packages/schemas/.eslintignore delete mode 100644 packages/schemas/.eslintrc.json delete mode 100644 packages/schemas/.prettierignore delete mode 100644 packages/schemas/.prettierrc.json diff --git a/packages/schemas/.eslintignore b/packages/schemas/.eslintignore deleted file mode 100644 index dcaed66f..00000000 --- a/packages/schemas/.eslintignore +++ /dev/null @@ -1,4 +0,0 @@ -node_modules/ -coverage/ -dist/ -vitest.config.mts diff --git a/packages/schemas/.eslintrc.json b/packages/schemas/.eslintrc.json deleted file mode 100644 index a637755b..00000000 --- a/packages/schemas/.eslintrc.json +++ /dev/null @@ -1,80 +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": { - "@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/restrict-template-expressions": "off", - "@typescript-eslint/no-explicit-any": "warn", - "@typescript-eslint/no-unsafe-member-access": "off", - "@typescript-eslint/no-unsafe-assignment": "off", - "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/consistent-type-imports": "warn", - "@typescript-eslint/no-unused-vars": [ - "warn", - { - "argsIgnorePattern": "^_", - "varsIgnorePattern": "^_", - "caughtErrorsIgnorePattern": "^_" - } - ], - "@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": 15 }], - "complexity": ["error", { "max": 20 }] - }, - "overrides": [ - { - "files": ["test/**/*.ts", "*.test.ts", "*.spec.ts"], - "rules": { - "@typescript-eslint/require-await": "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", - "max-statements": ["off"] - } - } - ] -} diff --git a/packages/schemas/.prettierignore b/packages/schemas/.prettierignore deleted file mode 100644 index bd95794d..00000000 --- a/packages/schemas/.prettierignore +++ /dev/null @@ -1,2 +0,0 @@ -package-lock.json -dist diff --git a/packages/schemas/.prettierrc.json b/packages/schemas/.prettierrc.json deleted file mode 100644 index b59d4dd3..00000000 --- a/packages/schemas/.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/schemas/lib/events/baseEventSchemas.ts b/packages/schemas/lib/events/baseEventSchemas.ts index 7bb732e4..0a84d064 100644 --- a/packages/schemas/lib/events/baseEventSchemas.ts +++ b/packages/schemas/lib/events/baseEventSchemas.ts @@ -1,4 +1,4 @@ -import type { ZodLiteral, ZodObject, ZodOptional, ZodString, ZodRawShape } from 'zod' +import type { ZodLiteral, ZodObject, ZodOptional, ZodRawShape, ZodString } from 'zod' import { z } from 'zod' // External message metadata that describe the context in which the message was created, primarily used for debugging purposes diff --git a/packages/schemas/package.json b/packages/schemas/package.json index 9200253b..9e2a6c1f 100644 --- a/packages/schemas/package.json +++ b/packages/schemas/package.json @@ -15,8 +15,8 @@ "scripts": { "build": "del-cli dist && del-cli coverage && tsc", "build:release": "del-cli dist && npm run lint && tsc --project tsconfig.release.json", - "lint": "eslint . --ext .ts", - "lint:fix": "prettier --write . && eslint . --ext .ts --fix", + "lint": "biome check . && tsc --project tsconfig.json --noEmit", + "lint:fix": "biome check --write .", "test:coverage": "", "test:ci": "", "docker:start:dev": "", @@ -27,14 +27,10 @@ "zod": "^3.23.8" }, "devDependencies": { + "@biomejs/biome": "1.8.3", + "@kibertoad/biome-config": "^1.2.1", "@types/node": "^22.0.0", - "@typescript-eslint/eslint-plugin": "^8.0.1", - "@typescript-eslint/parser": "^8.0.1", "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.5.3" }, "homepage": "https://github.com/kibertoad/message-queue-toolkit", @@ -54,9 +50,5 @@ "rabbitmq", "rabbit" ], - "files": [ - "README.md", - "LICENSE", - "dist/*" - ] + "files": ["README.md", "LICENSE", "dist/*"] } From c31e99d3c2e1701a05e5e10fe5d4f9cd526f2f79 Mon Sep 17 00:00:00 2001 From: CarlosGamero Date: Wed, 28 Aug 2024 12:58:59 +0200 Subject: [PATCH 3/6] sns biome migration --- packages/sns/.eslintignore | 4 - packages/sns/.eslintrc.json | 84 ------------------- packages/sns/.prettierignore | 2 - packages/sns/.prettierrc.json | 9 -- packages/sns/lib/sns/AbstractSnsPublisher.ts | 4 +- packages/sns/lib/sns/AbstractSnsService.ts | 2 +- .../sns/lib/sns/SnsPublisherManager.spec.ts | 2 +- packages/sns/lib/utils/snsInitter.ts | 4 +- packages/sns/lib/utils/snsSubscriber.ts | 2 +- packages/sns/package.json | 29 ++----- ...PermissionConsumer.deadLetterQueue.spec.ts | 4 +- ...rmissionConsumer.payloadOffloading.spec.ts | 2 +- .../SnsSqsPermissionConsumer.spec.ts | 2 +- .../consumers/SnsSqsPermissionConsumer.ts | 4 +- ...missionPublisher.payloadOffloading.spec.ts | 2 +- .../publishers/SnsPermissionPublisher.spec.ts | 4 +- packages/sns/test/utils/testContext.ts | 4 +- 17 files changed, 24 insertions(+), 140 deletions(-) delete mode 100644 packages/sns/.eslintignore delete mode 100644 packages/sns/.eslintrc.json delete mode 100644 packages/sns/.prettierignore delete mode 100644 packages/sns/.prettierrc.json diff --git a/packages/sns/.eslintignore b/packages/sns/.eslintignore deleted file mode 100644 index dcaed66f..00000000 --- a/packages/sns/.eslintignore +++ /dev/null @@ -1,4 +0,0 @@ -node_modules/ -coverage/ -dist/ -vitest.config.mts diff --git a/packages/sns/.eslintrc.json b/packages/sns/.eslintrc.json deleted file mode 100644 index d80dfa92..00000000 --- a/packages/sns/.eslintrc.json +++ /dev/null @@ -1,84 +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/no-unsafe-member-access": "warn", - "@typescript-eslint/no-unsafe-assignment": "off", - "@typescript-eslint/no-unsafe-argument": "off", - "@typescript-eslint/explicit-function-return-type": "off", - "@typescript-eslint/consistent-type-imports": "warn", - "@typescript-eslint/no-unused-vars": [ - "warn", - { - "argsIgnorePattern": "^_", - "varsIgnorePattern": "^_", - "caughtErrorsIgnorePattern": "^_" - } - ], - "@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" - } - ], - "prefer-const": "off", - "max-lines": ["error", { "max": 600 }], - "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/require-await": "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/sns/.prettierignore b/packages/sns/.prettierignore deleted file mode 100644 index bd95794d..00000000 --- a/packages/sns/.prettierignore +++ /dev/null @@ -1,2 +0,0 @@ -package-lock.json -dist diff --git a/packages/sns/.prettierrc.json b/packages/sns/.prettierrc.json deleted file mode 100644 index b59d4dd3..00000000 --- a/packages/sns/.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/sns/lib/sns/AbstractSnsPublisher.ts b/packages/sns/lib/sns/AbstractSnsPublisher.ts index 1e86ca56..49c29235 100644 --- a/packages/sns/lib/sns/AbstractSnsPublisher.ts +++ b/packages/sns/lib/sns/AbstractSnsPublisher.ts @@ -6,10 +6,10 @@ import type { AsyncPublisher, BarrierResult, MessageInvalidFormatError, - MessageValidationError, - QueuePublisherOptions, MessageSchemaContainer, + MessageValidationError, OffloadedPayloadPointerPayload, + QueuePublisherOptions, ResolvedMessage, } from '@message-queue-toolkit/core' import { resolveOutgoingMessageAttributes } from '@message-queue-toolkit/sqs' diff --git a/packages/sns/lib/sns/AbstractSnsService.ts b/packages/sns/lib/sns/AbstractSnsService.ts index 07cec467..b68a34b3 100644 --- a/packages/sns/lib/sns/AbstractSnsService.ts +++ b/packages/sns/lib/sns/AbstractSnsService.ts @@ -1,4 +1,4 @@ -import type { SNSClient, CreateTopicCommandInput, Tag } from '@aws-sdk/client-sns' +import type { CreateTopicCommandInput, SNSClient, Tag } from '@aws-sdk/client-sns' import type { QueueDependencies, QueueOptions } from '@message-queue-toolkit/core' import { AbstractQueueService } from '@message-queue-toolkit/core' diff --git a/packages/sns/lib/sns/SnsPublisherManager.spec.ts b/packages/sns/lib/sns/SnsPublisherManager.spec.ts index 7a42321e..db1c9f2a 100644 --- a/packages/sns/lib/sns/SnsPublisherManager.spec.ts +++ b/packages/sns/lib/sns/SnsPublisherManager.spec.ts @@ -10,7 +10,7 @@ import type { TestEventPublishPayloadsType, TestEventsType, } from '../../test/utils/testContext' -import { registerDependencies, TestEvents } from '../../test/utils/testContext' +import { TestEvents, registerDependencies } from '../../test/utils/testContext' import { CommonSnsPublisher } from './CommonSnsPublisherFactory' import type { SnsPublisherManager } from './SnsPublisherManager' diff --git a/packages/sns/lib/utils/snsInitter.ts b/packages/sns/lib/utils/snsInitter.ts index b6b33986..81fe7e62 100644 --- a/packages/sns/lib/utils/snsInitter.ts +++ b/packages/sns/lib/utils/snsInitter.ts @@ -1,5 +1,5 @@ -import type { SNSClient, CreateTopicCommandInput } from '@aws-sdk/client-sns' -import type { SQSClient, CreateQueueCommandInput } from '@aws-sdk/client-sqs' +import type { CreateTopicCommandInput, SNSClient } from '@aws-sdk/client-sns' +import type { CreateQueueCommandInput, SQSClient } from '@aws-sdk/client-sqs' import type { DeletionConfig, ExtraParams } from '@message-queue-toolkit/core' import { isProduction } from '@message-queue-toolkit/core' import type { SQSCreationConfig } from '@message-queue-toolkit/sqs' diff --git a/packages/sns/lib/utils/snsSubscriber.ts b/packages/sns/lib/utils/snsSubscriber.ts index 4a0b5aaa..6c3ba82c 100644 --- a/packages/sns/lib/utils/snsSubscriber.ts +++ b/packages/sns/lib/utils/snsSubscriber.ts @@ -104,7 +104,7 @@ async function tryToUpdateSubscription( }) }) - for (let command of setSubscriptionAttributesCommands) { + for (const command of setSubscriptionAttributesCommands) { await snsClient.send(command) } diff --git a/packages/sns/package.json b/packages/sns/package.json index 7097d52e..38ed386a 100644 --- a/packages/sns/package.json +++ b/packages/sns/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" @@ -43,17 +43,13 @@ "@message-queue-toolkit/core": "*", "@message-queue-toolkit/s3-payload-store": "*", "@message-queue-toolkit/sqs": "*", + "@biomejs/biome": "1.8.3", + "@kibertoad/biome-config": "^1.2.1", "@types/node": "^22.0.0", - "@typescript-eslint/eslint-plugin": "^8.0.1", - "@typescript-eslint/parser": "^8.0.1", "@vitest/coverage-v8": "^2.0.4", "awilix": "^11.0.0", "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.5.3", "vitest": "^2.0.4" }, @@ -62,19 +58,6 @@ "type": "git", "url": "git://github.com/kibertoad/message-queue-toolkit.git" }, - "keywords": [ - "message", - "queue", - "queues", - "abstract", - "common", - "utils", - "notification", - "sns" - ], - "files": [ - "README.md", - "LICENSE", - "dist/*" - ] + "keywords": ["message", "queue", "queues", "abstract", "common", "utils", "notification", "sns"], + "files": ["README.md", "LICENSE", "dist/*"] } diff --git a/packages/sns/test/consumers/SnsSqsPermissionConsumer.deadLetterQueue.spec.ts b/packages/sns/test/consumers/SnsSqsPermissionConsumer.deadLetterQueue.spec.ts index 4c0aeb70..44ec554c 100644 --- a/packages/sns/test/consumers/SnsSqsPermissionConsumer.deadLetterQueue.spec.ts +++ b/packages/sns/test/consumers/SnsSqsPermissionConsumer.deadLetterQueue.spec.ts @@ -2,14 +2,14 @@ import type { SNSClient } from '@aws-sdk/client-sns' import type { SQSClient } from '@aws-sdk/client-sqs' import { waitAndRetry } from '@lokalise/node-core' import { + type SQSMessage, assertQueue, deleteQueue, getQueueAttributes, - type SQSMessage, } from '@message-queue-toolkit/sqs' import type { AwilixContainer } from 'awilix' import { Consumer } from 'sqs-consumer' -import { describe, beforeEach, afterEach, expect, it, beforeAll } from 'vitest' +import { afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest' import { deleteTopic } from '../../lib/utils/snsUtils' import type { SnsPermissionPublisher } from '../publishers/SnsPermissionPublisher' diff --git a/packages/sns/test/consumers/SnsSqsPermissionConsumer.payloadOffloading.spec.ts b/packages/sns/test/consumers/SnsSqsPermissionConsumer.payloadOffloading.spec.ts index 50e0a907..7407ba6e 100644 --- a/packages/sns/test/consumers/SnsSqsPermissionConsumer.payloadOffloading.spec.ts +++ b/packages/sns/test/consumers/SnsSqsPermissionConsumer.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 { afterEach, beforeEach, describe, expect, it } from 'vitest' import { SNS_MESSAGE_MAX_SIZE } from '../../lib/sns/AbstractSnsService' import { SnsPermissionPublisher } from '../publishers/SnsPermissionPublisher' diff --git a/packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts b/packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts index dd15db27..c20ada3a 100644 --- a/packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts +++ b/packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts @@ -6,7 +6,7 @@ import { waitAndRetry } from '@lokalise/node-core' import { assertQueue, deleteQueue, getQueueAttributes } from '@message-queue-toolkit/sqs' import type { AwilixContainer } from 'awilix' import { asValue } from 'awilix' -import { describe, beforeEach, afterEach, expect, it, beforeAll } from 'vitest' +import { afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest' import { assertTopic, deleteTopic } from '../../lib/utils/snsUtils' import { SnsPermissionPublisher } from '../publishers/SnsPermissionPublisher' diff --git a/packages/sns/test/consumers/SnsSqsPermissionConsumer.ts b/packages/sns/test/consumers/SnsSqsPermissionConsumer.ts index d2b68b3a..29a2176b 100644 --- a/packages/sns/test/consumers/SnsSqsPermissionConsumer.ts +++ b/packages/sns/test/consumers/SnsSqsPermissionConsumer.ts @@ -1,9 +1,9 @@ import type { Either } from '@lokalise/node-core' import type { - PrehandlerResult, BarrierResult, - Prehandler, PreHandlingOutputs, + Prehandler, + PrehandlerResult, } from '@message-queue-toolkit/core' import { MessageHandlerConfigBuilder } from '@message-queue-toolkit/core' diff --git a/packages/sns/test/publishers/SnsPermissionPublisher.payloadOffloading.spec.ts b/packages/sns/test/publishers/SnsPermissionPublisher.payloadOffloading.spec.ts index 1ce032b6..e385a2b6 100644 --- a/packages/sns/test/publishers/SnsPermissionPublisher.payloadOffloading.spec.ts +++ b/packages/sns/test/publishers/SnsPermissionPublisher.payloadOffloading.spec.ts @@ -15,7 +15,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 { afterEach, beforeEach, describe, expect, it } from 'vitest' import { SNS_MESSAGE_BODY_SCHEMA } from '../../lib/types/MessageTypes' import { subscribeToTopic } from '../../lib/utils/snsSubscriber' diff --git a/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts b/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts index 4ffc6fe6..52617933 100644 --- a/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts +++ b/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts @@ -3,10 +3,10 @@ import type { SQSClient } from '@aws-sdk/client-sqs' import type { InternalError } from '@lokalise/node-core' import { waitAndRetry } from '@lokalise/node-core' import type { SQSMessage } from '@message-queue-toolkit/sqs' -import { assertQueue, deleteQueue, FakeConsumerErrorResolver } from '@message-queue-toolkit/sqs' +import { FakeConsumerErrorResolver, assertQueue, deleteQueue } from '@message-queue-toolkit/sqs' import type { AwilixContainer } from 'awilix' import { Consumer } from 'sqs-consumer' -import { describe, beforeEach, afterEach, expect, it, beforeAll } from 'vitest' +import { afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest' import { deserializeSNSMessage } from '../../lib/utils/snsMessageDeserializer' import { subscribeToTopic } from '../../lib/utils/snsSubscriber' diff --git a/packages/sns/test/utils/testContext.ts b/packages/sns/test/utils/testContext.ts index 68058594..f3048e15 100644 --- a/packages/sns/test/utils/testContext.ts +++ b/packages/sns/test/utils/testContext.ts @@ -4,13 +4,13 @@ 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 { - enrichMessageSchemaWithBase, CommonMetadataFiller, EventRegistry, + enrichMessageSchemaWithBase, } from '@message-queue-toolkit/core' import { FakeConsumerErrorResolver } from '@message-queue-toolkit/sqs' 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 { z } from 'zod' From 4746333174501a7b90df8521b503cbc28ea272de Mon Sep 17 00:00:00 2001 From: CarlosGamero Date: Wed, 28 Aug 2024 13:13:30 +0200 Subject: [PATCH 4/6] SNS lint fixes --- .../sns/lib/sns/SnsPublisherManager.spec.ts | 1 + .../sns/lib/utils/snsAttributeUtils.spec.ts | 3 +- .../lib/utils/snsMessageDeserializer.spec.ts | 1 + ...PermissionConsumer.deadLetterQueue.spec.ts | 12 ++++-- ...rmissionConsumer.payloadOffloading.spec.ts | 9 ++++- .../SnsSqsPermissionConsumer.spec.ts | 33 +++++++-------- .../handlers/EntityCreatedHandler.ts | 4 +- ...missionPublisher.payloadOffloading.spec.ts | 25 +++++++----- .../publishers/SnsPermissionPublisher.spec.ts | 40 ++++++++++--------- 9 files changed, 75 insertions(+), 53 deletions(-) diff --git a/packages/sns/lib/sns/SnsPublisherManager.spec.ts b/packages/sns/lib/sns/SnsPublisherManager.spec.ts index db1c9f2a..2008cbca 100644 --- a/packages/sns/lib/sns/SnsPublisherManager.spec.ts +++ b/packages/sns/lib/sns/SnsPublisherManager.spec.ts @@ -12,6 +12,7 @@ import type { } from '../../test/utils/testContext' import { TestEvents, registerDependencies } from '../../test/utils/testContext' +import { afterAll, beforeAll, describe, expect, it } from 'vitest' import { CommonSnsPublisher } from './CommonSnsPublisherFactory' import type { SnsPublisherManager } from './SnsPublisherManager' diff --git a/packages/sns/lib/utils/snsAttributeUtils.spec.ts b/packages/sns/lib/utils/snsAttributeUtils.spec.ts index 3a73f59c..1244529c 100644 --- a/packages/sns/lib/utils/snsAttributeUtils.spec.ts +++ b/packages/sns/lib/utils/snsAttributeUtils.spec.ts @@ -1,5 +1,4 @@ -import { describe } from 'vitest' - +import { describe, expect, it } from 'vitest' import { PERMISSIONS_ADD_MESSAGE_SCHEMA, PERMISSIONS_REMOVE_MESSAGE_SCHEMA, diff --git a/packages/sns/lib/utils/snsMessageDeserializer.spec.ts b/packages/sns/lib/utils/snsMessageDeserializer.spec.ts index 042bbcf3..eab011fc 100644 --- a/packages/sns/lib/utils/snsMessageDeserializer.spec.ts +++ b/packages/sns/lib/utils/snsMessageDeserializer.spec.ts @@ -1,6 +1,7 @@ import type { SQSMessage } from '@message-queue-toolkit/sqs' import { SqsConsumerErrorResolver } from '@message-queue-toolkit/sqs' +import { describe, expect, it } from 'vitest' import type { PERMISSIONS_MESSAGE_TYPE } from '../../test/consumers/userConsumerSchemas' import { PERMISSIONS_MESSAGE_SCHEMA } from '../../test/consumers/userConsumerSchemas' import { SnsConsumerErrorResolver } from '../errors/SnsConsumerErrorResolver' diff --git a/packages/sns/test/consumers/SnsSqsPermissionConsumer.deadLetterQueue.spec.ts b/packages/sns/test/consumers/SnsSqsPermissionConsumer.deadLetterQueue.spec.ts index 44ec554c..7db03c25 100644 --- a/packages/sns/test/consumers/SnsSqsPermissionConsumer.deadLetterQueue.spec.ts +++ b/packages/sns/test/consumers/SnsSqsPermissionConsumer.deadLetterQueue.spec.ts @@ -9,7 +9,7 @@ import { } from '@message-queue-toolkit/sqs' import type { AwilixContainer } from 'awilix' import { Consumer } from 'sqs-consumer' -import { afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest' +import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest' import { deleteTopic } from '../../lib/utils/snsUtils' import type { SnsPermissionPublisher } from '../publishers/SnsPermissionPublisher' @@ -133,13 +133,16 @@ describe('SnsSqsPermissionConsumer - dead letter queue', () => { it('Stuck messages are sent to DLQ', async () => { let counter = 0 consumer = new SnsSqsPermissionConsumer(diContainer.cradle, { - creationConfig: { queue: { QueueName: queueName }, topic: { Name: topicName } }, + creationConfig: { + queue: { QueueName: queueName }, + topic: { Name: topicName }, + }, deadLetterQueue: { creationConfig: { queue: { QueueName: deadLetterQueueName } }, redrivePolicy: { maxReceiveCount: 200 }, }, maxRetryDuration: 3, - removeHandlerOverride: async () => { + removeHandlerOverride: () => { counter++ return Promise.resolve({ error: 'retryLater' }) }, @@ -150,8 +153,9 @@ describe('SnsSqsPermissionConsumer - dead letter queue', () => { const dlqConsumer = Consumer.create({ sqs: diContainer.cradle.sqsClient, queueUrl: consumer.subscriptionProps.deadLetterQueueUrl ?? '', - handleMessage: async (message: SQSMessage) => { + handleMessage: (message: SQSMessage) => { dlqMessage = message + return Promise.resolve() }, }) dlqConsumer.start() diff --git a/packages/sns/test/consumers/SnsSqsPermissionConsumer.payloadOffloading.spec.ts b/packages/sns/test/consumers/SnsSqsPermissionConsumer.payloadOffloading.spec.ts index 7407ba6e..c66b1e28 100644 --- a/packages/sns/test/consumers/SnsSqsPermissionConsumer.payloadOffloading.spec.ts +++ b/packages/sns/test/consumers/SnsSqsPermissionConsumer.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 { afterEach, beforeEach, describe, expect, it } from 'vitest' +import { afterAll, afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest' import { SNS_MESSAGE_MAX_SIZE } from '../../lib/sns/AbstractSnsService' import { SnsPermissionPublisher } from '../publishers/SnsPermissionPublisher' @@ -36,9 +36,12 @@ describe('SnsSqsPermissionConsumer', () => { await assertBucket(s3, s3BucketName) payloadStoreConfig = { messageSizeThreshold: largeMessageSizeThreshold, - store: new S3PayloadStore(diContainer.cradle, { bucketName: s3BucketName }), + store: new S3PayloadStore(diContainer.cradle, { + bucketName: s3BucketName, + }), } }) + beforeEach(async () => { consumer = new SnsSqsPermissionConsumer(diContainer.cradle, { payloadStoreConfig, @@ -49,10 +52,12 @@ describe('SnsSqsPermissionConsumer', () => { await consumer.start() await publisher.init() }) + afterEach(async () => { await publisher.close() await consumer.close() }) + afterAll(async () => { await emptyBucket(s3, s3BucketName) diff --git a/packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts b/packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts index c20ada3a..b1a62cf5 100644 --- a/packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts +++ b/packages/sns/test/consumers/SnsSqsPermissionConsumer.spec.ts @@ -6,7 +6,7 @@ import { waitAndRetry } from '@lokalise/node-core' import { assertQueue, deleteQueue, getQueueAttributes } from '@message-queue-toolkit/sqs' import type { AwilixContainer } from 'awilix' import { asValue } from 'awilix' -import { afterEach, beforeAll, beforeEach, describe, expect, it } from 'vitest' +import { afterEach, beforeAll, beforeEach, describe, expect, it, vi } from 'vitest' import { assertTopic, deleteTopic } from '../../lib/utils/snsUtils' import { SnsPermissionPublisher } from '../publishers/SnsPermissionPublisher' @@ -298,14 +298,12 @@ describe('SnsSqsPermissionConsumer', () => { deletionConfig: { deleteIfExists: true, }, - removeHandlerOverride: async (message, _context, preHandlerOutputs) => { + removeHandlerOverride: (_message, _context, preHandlerOutputs) => { expect(preHandlerOutputs.preHandlerOutput.preHandlerCount).toBe(1) - return { - result: 'success', - } + return Promise.resolve({ result: 'success' }) }, removePreHandlers: [ - (message, context, preHandlerOutput, next) => { + (_message, _context, preHandlerOutput, next) => { preHandlerOutput.preHandlerCount = preHandlerOutput.preHandlerCount ? preHandlerOutput.preHandlerCount + 1 : 1 @@ -343,14 +341,12 @@ describe('SnsSqsPermissionConsumer', () => { deletionConfig: { deleteIfExists: true, }, - removeHandlerOverride: async (message, _context, preHandlerOutputs) => { + removeHandlerOverride: (_message, _context, preHandlerOutputs) => { expect(preHandlerOutputs.preHandlerOutput.preHandlerCount).toBe(11) - return { - result: 'success', - } + return Promise.resolve({ result: 'success' }) }, removePreHandlers: [ - (message, context, preHandlerOutput, next) => { + (_message, _context, preHandlerOutput, next) => { preHandlerOutput.preHandlerCount = preHandlerOutput.preHandlerCount ? preHandlerOutput.preHandlerCount + 10 : 10 @@ -359,7 +355,7 @@ describe('SnsSqsPermissionConsumer', () => { }) }, - (message, context, preHandlerOutput, next) => { + (_message, _context, preHandlerOutput, next) => { preHandlerOutput.preHandlerCount = preHandlerOutput.preHandlerCount ? preHandlerOutput.preHandlerCount + 1 : 1 @@ -475,9 +471,14 @@ describe('SnsSqsPermissionConsumer', () => { const consumer1 = new SnsSqsPermissionConsumer(diContainer.cradle, { creationConfig: { topic: { Name: topicName }, - queue: { QueueName: queueName, Attributes: { VisibilityTimeout: '2' } }, + queue: { + QueueName: queueName, + Attributes: { VisibilityTimeout: '2' }, + }, + }, + consumerOverrides: { + heartbeatInterval: heartbeatEnabled ? 1 : undefined, }, - consumerOverrides: { heartbeatInterval: heartbeatEnabled ? 1 : undefined }, removeHandlerOverride: async () => { consumer1IsProcessing = true await setTimeout(3100) // Wait to the visibility timeout to expire @@ -494,9 +495,9 @@ describe('SnsSqsPermissionConsumer', () => { topicArn: consumer1.subscriptionProps.topicArn, subscriptionArn: consumer1.subscriptionProps.subscriptionArn, }, - removeHandlerOverride: async () => { + removeHandlerOverride: () => { consumer2Counter++ - return { result: 'success' } + return Promise.resolve({ result: 'success' }) }, }) const publisher = new SnsPermissionPublisher(diContainer.cradle, { diff --git a/packages/sns/test/consumers/handlers/EntityCreatedHandler.ts b/packages/sns/test/consumers/handlers/EntityCreatedHandler.ts index cd5509a4..7d05890e 100644 --- a/packages/sns/test/consumers/handlers/EntityCreatedHandler.ts +++ b/packages/sns/test/consumers/handlers/EntityCreatedHandler.ts @@ -5,10 +5,10 @@ import type { TestEvents } from '../../utils/testContext' let _latestData: string -export async function entityCreatedHandler( +export function entityCreatedHandler( message: z.infer, ): Promise> { _latestData = message.payload.newData - return { result: 'success' } + return Promise.resolve({ result: 'success' }) } diff --git a/packages/sns/test/publishers/SnsPermissionPublisher.payloadOffloading.spec.ts b/packages/sns/test/publishers/SnsPermissionPublisher.payloadOffloading.spec.ts index e385a2b6..552ea448 100644 --- a/packages/sns/test/publishers/SnsPermissionPublisher.payloadOffloading.spec.ts +++ b/packages/sns/test/publishers/SnsPermissionPublisher.payloadOffloading.spec.ts @@ -15,7 +15,7 @@ import { import type { AwilixContainer } from 'awilix' import { asValue } 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 { SNS_MESSAGE_BODY_SCHEMA } from '../../lib/types/MessageTypes' import { subscribeToTopic } from '../../lib/utils/snsSubscriber' @@ -56,13 +56,18 @@ describe('SnsPermissionPublisher', () => { await assertBucket(s3, s3BucketName) payloadStoreConfig = { messageSizeThreshold: largeMessageSizeThreshold, - store: new S3PayloadStore(diContainer.cradle, { bucketName: s3BucketName }), + store: new S3PayloadStore(diContainer.cradle, { + bucketName: s3BucketName, + }), } }) + beforeEach(async () => { await deleteQueue(sqsClient, queueName) await deleteTopic(snsClient, SnsPermissionPublisher.TOPIC_NAME) - const { queueUrl } = await assertQueue(sqsClient, { QueueName: queueName }) + const { queueUrl } = await assertQueue(sqsClient, { + QueueName: queueName, + }) await subscribeToTopic( sqsClient, snsClient, @@ -78,24 +83,26 @@ describe('SnsPermissionPublisher', () => { receivedSnsMessages = [] consumer = Consumer.create({ queueUrl, - handleMessage: async (message: Message) => { - if (message === null) { - return - } - receivedSnsMessages.push(message) + handleMessage: (message: Message) => { + if (message !== null) receivedSnsMessages.push(message) + return Promise.resolve() }, sqs: sqsClient, messageAttributeNames: [OFFLOADED_PAYLOAD_SIZE_ATTRIBUTE], }) - publisher = new SnsPermissionPublisher(diContainer.cradle, { payloadStoreConfig }) + publisher = new SnsPermissionPublisher(diContainer.cradle, { + payloadStoreConfig, + }) consumer.start() await publisher.init() }) + afterEach(async () => { await publisher.close() consumer.stop() }) + afterAll(async () => { const { awilixManager } = diContainer.cradle await awilixManager.executeDispose() diff --git a/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts b/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts index 52617933..c9376e32 100644 --- a/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts +++ b/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts @@ -151,16 +151,16 @@ describe('SnsPermissionPublisher', () => { let receivedMessage: unknown = null consumer = Consumer.create({ queueUrl: queueUrl, - handleMessage: async (message: SQSMessage) => { - if (message === null) { - return + handleMessage: (message: SQSMessage) => { + if (message !== null) { + const decodedMessage = deserializeSNSMessage( + message as any, + PERMISSIONS_ADD_MESSAGE_SCHEMA, + new FakeConsumerErrorResolver(), + ) + receivedMessage = decodedMessage.result! } - const decodedMessage = deserializeSNSMessage( - message as any, - PERMISSIONS_ADD_MESSAGE_SCHEMA, - new FakeConsumerErrorResolver(), - ) - receivedMessage = decodedMessage.result! + return Promise.resolve() }, sqs: diContainer.cradle.sqsClient, }) @@ -173,7 +173,11 @@ describe('SnsPermissionPublisher', () => { await waitAndRetry(() => !!receivedMessage) expect(receivedMessage).toEqual({ - originalMessage: { ...message, _internalNumberOfRetries: 0, timestamp: expect.any(String) }, + originalMessage: { + ...message, + _internalNumberOfRetries: 0, + timestamp: expect.any(String), + }, parsedMessage: message, }) @@ -209,16 +213,16 @@ describe('SnsPermissionPublisher', () => { let receivedMessage: unknown consumer = Consumer.create({ queueUrl: queueUrl, - handleMessage: async (message: SQSMessage) => { + handleMessage: (message: SQSMessage) => { if (message === null) { - return + const decodedMessage = deserializeSNSMessage( + message as any, + PERMISSIONS_ADD_MESSAGE_SCHEMA, + new FakeConsumerErrorResolver(), + ) + receivedMessage = decodedMessage.result! } - const decodedMessage = deserializeSNSMessage( - message as any, - PERMISSIONS_ADD_MESSAGE_SCHEMA, - new FakeConsumerErrorResolver(), - ) - receivedMessage = decodedMessage.result! + return Promise.resolve() }, sqs: diContainer.cradle.sqsClient, }) From abb4efce6ddf603c591ebc443b6760f32b6b628a Mon Sep 17 00:00:00 2001 From: CarlosGamero Date: Wed, 28 Aug 2024 13:19:12 +0200 Subject: [PATCH 5/6] More lint fixes --- packages/sns/lib/sns/AbstractSnsPublisher.ts | 7 +++-- packages/sns/lib/utils/snsAttributeUtils.ts | 2 +- packages/sns/lib/utils/snsUtils.ts | 4 +-- .../consumers/SnsSqsPermissionConsumer.ts | 30 ++++++++----------- .../handlers/EntityUpdatedHandler.ts | 4 +-- packages/sns/test/utils/snsSubscriber.spec.ts | 3 +- 6 files changed, 24 insertions(+), 26 deletions(-) diff --git a/packages/sns/lib/sns/AbstractSnsPublisher.ts b/packages/sns/lib/sns/AbstractSnsPublisher.ts index 49c29235..5088bf89 100644 --- a/packages/sns/lib/sns/AbstractSnsPublisher.ts +++ b/packages/sns/lib/sns/AbstractSnsPublisher.ts @@ -69,9 +69,10 @@ export abstract class AbstractSnsPublisher this.logMessage(resolvedLogMessage) } - message = this.updateInternalProperties(message) - const maybeOffloadedPayloadMessage = await this.offloadMessagePayloadIfNeeded(message, () => - calculateOutgoingMessageSize(message), + const updatedMessage = this.updateInternalProperties(message) + const maybeOffloadedPayloadMessage = await this.offloadMessagePayloadIfNeeded( + updatedMessage, + () => calculateOutgoingMessageSize(updatedMessage), ) await this.sendMessage(maybeOffloadedPayloadMessage, options) diff --git a/packages/sns/lib/utils/snsAttributeUtils.ts b/packages/sns/lib/utils/snsAttributeUtils.ts index f787d624..b02ae029 100644 --- a/packages/sns/lib/utils/snsAttributeUtils.ts +++ b/packages/sns/lib/utils/snsAttributeUtils.ts @@ -23,7 +23,7 @@ export function generateTopicSubscriptionPolicy(params: TopicSubscriptionPolicyP } export function generateFilterAttributes( - // eslint-disable-next-line @typescript-eslint/no-explicit-any + // biome-ignore lint/suspicious/noExplicitAny: messageSchemas: ZodSchema[], messageTypeField: string, ) { diff --git a/packages/sns/lib/utils/snsUtils.ts b/packages/sns/lib/utils/snsUtils.ts index 58c54a90..85b038a5 100644 --- a/packages/sns/lib/utils/snsUtils.ts +++ b/packages/sns/lib/utils/snsUtils.ts @@ -113,7 +113,7 @@ export async function deleteTopic(client: SNSClient, topicName: string) { }) await client.send(command) - } catch (err) { + } catch (_) { // we don't care it operation has failed } } @@ -124,7 +124,7 @@ export async function deleteSubscription(client: SNSClient, subscriptionArn: str }) try { await client.send(command) - } catch (err) { + } catch (_) { // we don't care it operation has failed } } diff --git a/packages/sns/test/consumers/SnsSqsPermissionConsumer.ts b/packages/sns/test/consumers/SnsSqsPermissionConsumer.ts index 29a2176b..1935fc5f 100644 --- a/packages/sns/test/consumers/SnsSqsPermissionConsumer.ts +++ b/packages/sns/test/consumers/SnsSqsPermissionConsumer.ts @@ -79,15 +79,13 @@ export class SnsSqsPermissionConsumer extends AbstractSnsSqsConsumer< }, }, ) { - const defaultRemoveHandler = async ( + const defaultRemoveHandler = ( _message: SupportedMessages, context: ExecutionContext, _preHandlingOutputs: PreHandlingOutputs, ): Promise> => { this.removeCounter += context.incrementAmount - return { - result: 'success', - } + return Promise.resolve({ result: 'success' }) } super( @@ -101,18 +99,16 @@ export class SnsSqsPermissionConsumer extends AbstractSnsSqsConsumer< >() .addConfig( PERMISSIONS_ADD_MESSAGE_SCHEMA, - async (_message, context, _preHandlingOutputs) => { + (_message, context, _preHandlingOutputs) => { this.addCounter += context.incrementAmount - return { - result: 'success', - } + return Promise.resolve({ result: 'success' }) }, { preHandlers: [ ( message: SupportedMessages, - context: ExecutionContext, - preHandlerOutput: Partial, + _context: ExecutionContext, + _preHandlerOutput: Partial, next: (result: PrehandlerResult) => void, ) => { if (message.preHandlerIncrement) { @@ -123,18 +119,16 @@ export class SnsSqsPermissionConsumer extends AbstractSnsSqsConsumer< }) }, ], - preHandlerBarrier: async (_message, context) => { + preHandlerBarrier: (_message, context) => { this.addBarrierCounter += context.incrementAmount if (this.addBarrierCounter < 3) { - return { - isPassing: false, - } + return Promise.resolve({ isPassing: false }) } - return { + return Promise.resolve({ isPassing: true, output: this.addBarrierCounter, - } + }) }, }, ) @@ -158,7 +152,9 @@ export class SnsSqsPermissionConsumer extends AbstractSnsSqsConsumer< ? { locatorConfig: options.locatorConfig } : { creationConfig: options.creationConfig ?? { - queue: { QueueName: SnsSqsPermissionConsumer.CONSUMED_QUEUE_NAME }, + queue: { + QueueName: SnsSqsPermissionConsumer.CONSUMED_QUEUE_NAME, + }, topic: { Name: SnsSqsPermissionConsumer.SUBSCRIBED_TOPIC_NAME }, }, }), diff --git a/packages/sns/test/consumers/handlers/EntityUpdatedHandler.ts b/packages/sns/test/consumers/handlers/EntityUpdatedHandler.ts index 3dce5d2d..33bf660c 100644 --- a/packages/sns/test/consumers/handlers/EntityUpdatedHandler.ts +++ b/packages/sns/test/consumers/handlers/EntityUpdatedHandler.ts @@ -5,10 +5,10 @@ import type { TestEvents } from '../../utils/testContext' let _latestData: string -export async function entityUpdatedHandler( +export function entityUpdatedHandler( message: z.infer, ): Promise> { _latestData = message.payload.updatedData - return { result: 'success' } + return Promise.resolve({ result: 'success' }) } diff --git a/packages/sns/test/utils/snsSubscriber.spec.ts b/packages/sns/test/utils/snsSubscriber.spec.ts index 5f043cf5..29084578 100644 --- a/packages/sns/test/utils/snsSubscriber.spec.ts +++ b/packages/sns/test/utils/snsSubscriber.spec.ts @@ -2,7 +2,7 @@ import type { SNSClient } from '@aws-sdk/client-sns' import type { SQSClient } from '@aws-sdk/client-sqs' import { deleteQueue } from '@message-queue-toolkit/sqs' import type { AwilixContainer } from 'awilix' -import { afterEach, describe, expect } from 'vitest' +import { afterEach, beforeEach, describe, expect, it } from 'vitest' import { subscribeToTopic } from '../../lib/utils/snsSubscriber' import { @@ -22,6 +22,7 @@ describe('snsSubscriber', () => { let diContainer: AwilixContainer let snsClient: SNSClient let sqsClient: SQSClient + beforeEach(async () => { diContainer = await registerDependencies({}, false) snsClient = diContainer.cradle.snsClient From 2ce82069c5e0e5ba078db036bac6d3b81e4e3428 Mon Sep 17 00:00:00 2001 From: CarlosGamero Date: Wed, 28 Aug 2024 13:43:41 +0200 Subject: [PATCH 6/6] Fixing test error --- packages/sns/test/publishers/SnsPermissionPublisher.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts b/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts index c9376e32..37d3288b 100644 --- a/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts +++ b/packages/sns/test/publishers/SnsPermissionPublisher.spec.ts @@ -214,7 +214,7 @@ describe('SnsPermissionPublisher', () => { consumer = Consumer.create({ queueUrl: queueUrl, handleMessage: (message: SQSMessage) => { - if (message === null) { + if (message !== null) { const decodedMessage = deserializeSNSMessage( message as any, PERMISSIONS_ADD_MESSAGE_SCHEMA,