Skip to content

Commit f6e73e7

Browse files
kibertoadIgor Savinkamilwylegala
authored
Support a mix of locator and creation configs for SNS (#210)
Co-authored-by: Igor Savin <[email protected]> Co-authored-by: Kamil Wylegała <[email protected]>
1 parent 08b0764 commit f6e73e7

34 files changed

+452
-183
lines changed

packages/amqp/lib/AbstractAmqpQueuePublisher.ts

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,14 @@ export abstract class AbstractAmqpQueuePublisher<
3232
options: AMQPPublisherOptions<MessagePayloadType, AMQPQueueCreationConfig, AMQPQueueLocator>,
3333
) {
3434
super(dependencies, options)
35+
36+
if (!options.locatorConfig?.queueName && !options.creationConfig?.queueName) {
37+
throw new Error('Either locatorConfig or creationConfig must provide queueName')
38+
}
39+
3540
this.queueName = options.locatorConfig
3641
? options.locatorConfig.queueName
37-
: options.creationConfig.queueName
42+
: options.creationConfig!.queueName
3843
}
3944

4045
protected publishInternal(message: Buffer, options: AmqpQueueMessageOptions): void {

packages/amqp/package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
"prepublishOnly": "npm run build:release"
2626
},
2727
"dependencies": {
28-
"@lokalise/node-core": "^12.0.0",
28+
"@lokalise/node-core": "^13.0.1",
2929
"zod": "^3.23.8"
3030
},
3131
"peerDependencies": {
@@ -38,14 +38,14 @@
3838
"@kibertoad/biome-config": "^1.2.1",
3939
"@message-queue-toolkit/core": "*",
4040
"@types/amqplib": "^0.10.5",
41-
"@types/node": "^22.0.0",
42-
"@vitest/coverage-v8": "^2.0.4",
41+
"@types/node": "^22.7.5",
42+
"@vitest/coverage-v8": "^2.1.2",
4343
"amqplib": "^0.10.4",
4444
"awilix": "^12.0.1",
4545
"awilix-manager": "^5.4.0",
4646
"del-cli": "^6.0.0",
47-
"typescript": "^5.5.2",
48-
"vitest": "^2.0.4"
47+
"typescript": "^5.6.3",
48+
"vitest": "^2.1.2"
4949
},
5050
"homepage": "https://github.com/kibertoad/message-queue-toolkit",
5151
"repository": {

packages/amqp/vitest.config.mts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,10 @@ export default defineConfig({
2626
reporter: ['text'],
2727
all: true,
2828
thresholds: {
29-
lines: 90,
29+
lines: 89,
3030
functions: 95,
3131
branches: 79,
32-
statements: 90,
32+
statements: 89,
3333
},
3434
},
3535
},

packages/core/lib/types/queueOptionsTypes.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,20 +38,18 @@ export type DeletionConfig = {
3838
}
3939

4040
type NewQueueOptions<CreationConfigType extends CommonCreationConfigType> = {
41-
locatorConfig?: never
42-
creationConfig: CreationConfigType
41+
creationConfig?: CreationConfigType
4342
}
4443

4544
type ExistingQueueOptions<QueueLocatorType extends object> = {
46-
locatorConfig: QueueLocatorType
47-
creationConfig?: never
45+
locatorConfig?: QueueLocatorType
4846
}
4947

5048
export type QueueOptions<
5149
CreationConfigType extends CommonCreationConfigType,
5250
QueueLocatorType extends object,
5351
> = CommonQueueOptions &
54-
(NewQueueOptions<CreationConfigType> | ExistingQueueOptions<QueueLocatorType>)
52+
(NewQueueOptions<CreationConfigType> & ExistingQueueOptions<QueueLocatorType>)
5553

5654
export type QueuePublisherOptions<
5755
CreationConfigType extends CommonCreationConfigType,
@@ -68,7 +66,8 @@ export type DeadLetterQueueOptions<
6866
> = {
6967
deletionConfig?: DeletionConfig
7068
} & DeadLetterQueueIntegrationOptions &
71-
(NewQueueOptions<CreationConfigType> | ExistingQueueOptions<QueueLocatorType>)
69+
NewQueueOptions<CreationConfigType> &
70+
ExistingQueueOptions<QueueLocatorType>
7271

7372
export type QueueConsumerOptions<
7473
CreationConfigType extends object,

packages/core/package.json

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -25,25 +25,25 @@
2525
"prepublishOnly": "npm run build:release"
2626
},
2727
"dependencies": {
28-
"@lokalise/node-core": "^12.0.0",
28+
"@lokalise/node-core": "^13.0.1",
2929
"@message-queue-toolkit/schemas": "^4.0.0",
3030
"fast-equals": "^5.0.1",
31-
"json-stream-stringify": "^3.1.4",
31+
"json-stream-stringify": "^3.1.6",
3232
"tmp": "^0.2.3",
3333
"toad-cache": "^3.7.0",
3434
"zod": "^3.23.8"
3535
},
3636
"devDependencies": {
3737
"@biomejs/biome": "1.9.3",
3838
"@kibertoad/biome-config": "^1.2.1",
39-
"@types/node": "^22.0.0",
39+
"@types/node": "^22.7.5",
4040
"@types/tmp": "^0.2.6",
41-
"@vitest/coverage-v8": "^2.0.4",
41+
"@vitest/coverage-v8": "^2.1.2",
4242
"awilix": "^12.0.1",
4343
"awilix-manager": "^5.4.0",
4444
"del-cli": "^6.0.0",
45-
"typescript": "^5.5.4",
46-
"vitest": "^2.0.4"
45+
"typescript": "^5.6.3",
46+
"vitest": "^2.1.2"
4747
},
4848
"homepage": "https://github.com/kibertoad/message-queue-toolkit",
4949
"repository": {

packages/schemas/package.json

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@
1717
"build:release": "del-cli dist && npm run lint && tsc --project tsconfig.release.json",
1818
"lint": "biome check . && tsc --project tsconfig.json --noEmit",
1919
"lint:fix": "biome check --write .",
20-
"test:coverage": "",
21-
"test:ci": "",
20+
"test": "vitest",
21+
"test:coverage": "npm test -- --coverage",
22+
"test:ci": "npm test",
2223
"docker:start:dev": "",
2324
"docker:stop:dev": "",
2425
"prepublishOnly": "npm run build:release"
@@ -29,11 +30,11 @@
2930
"devDependencies": {
3031
"@biomejs/biome": "1.9.3",
3132
"@kibertoad/biome-config": "^1.2.1",
32-
"@types/node": "^22.0.0",
33-
"@vitest/coverage-v8": "^2.0.4",
33+
"@types/node": "^22.7.5",
34+
"@vitest/coverage-v8": "^2.1.2",
3435
"del-cli": "^6.0.0",
35-
"typescript": "^5.5.3",
36-
"vitest": "^2.0.4"
36+
"typescript": "^5.6.3",
37+
"vitest": "^2.1.2"
3738
},
3839
"homepage": "https://github.com/kibertoad/message-queue-toolkit",
3940
"repository": {

packages/schemas/vitest.config.mts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import { defineConfig } from 'vitest/config'
2+
3+
export default defineConfig({
4+
test: {
5+
globals: true,
6+
poolOptions: {
7+
threads: {
8+
singleThread: true,
9+
},
10+
},
11+
pool: 'threads',
12+
watch: false,
13+
environment: 'node',
14+
reporters: ['default'],
15+
coverage: {
16+
provider: 'v8',
17+
include: ['lib/**/*.ts'],
18+
exclude: [
19+
'lib/**/*.spec.ts',
20+
'lib/**/*.test.ts',
21+
'test/**/*.*',
22+
'lib/types/**/*.*',
23+
'lib/sns/fakes',
24+
],
25+
reporter: ['text'],
26+
all: true,
27+
thresholds: {
28+
lines: 8,
29+
functions: 71,
30+
branches: 70,
31+
statements: 8,
32+
},
33+
},
34+
},
35+
})

packages/sns/index.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
export type {
22
SNSTopicAWSConfig,
33
SNSTopicConfig,
4-
SNSQueueLocatorType,
4+
SNSTopicLocatorType,
55
SNSCreationConfig,
66
SNSDependencies,
77
} from './lib/sns/AbstractSnsService'

packages/sns/lib/sns/AbstractSnsPublisher.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ import { resolveOutgoingMessageAttributes } from '@message-queue-toolkit/sqs'
1616

1717
import { calculateOutgoingMessageSize } from '../utils/snsUtils'
1818

19-
import type { SNSCreationConfig, SNSDependencies, SNSQueueLocatorType } from './AbstractSnsService'
19+
import type { SNSCreationConfig, SNSDependencies, SNSTopicLocatorType } from './AbstractSnsService'
2020
import { AbstractSnsService } from './AbstractSnsService'
2121

2222
export type SNSMessageOptions = {
@@ -26,7 +26,7 @@ export type SNSMessageOptions = {
2626

2727
export type SNSPublisherOptions<MessagePayloadType extends object> = QueuePublisherOptions<
2828
SNSCreationConfig,
29-
SNSQueueLocatorType,
29+
SNSTopicLocatorType,
3030
MessagePayloadType
3131
>
3232

packages/sns/lib/sns/AbstractSnsService.ts

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,15 +34,16 @@ export type ExtraSNSCreationParams = {
3434
}
3535

3636
export type SNSCreationConfig = {
37-
topic: SNSTopicAWSConfig
37+
topic?: SNSTopicAWSConfig
3838
updateAttributesIfExists?: boolean
3939
} & ExtraSNSCreationParams
4040

41-
export type SNSQueueLocatorType = {
42-
topicArn: string
41+
export type SNSTopicLocatorType = {
42+
topicArn?: string
43+
topicName?: string
4344
}
4445

45-
export type SNSOptions = QueueOptions<SNSCreationConfig, SNSQueueLocatorType>
46+
export type SNSOptions = QueueOptions<SNSCreationConfig, SNSTopicLocatorType>
4647

4748
export abstract class AbstractSnsService<
4849
MessagePayloadType extends object,
@@ -54,7 +55,7 @@ export abstract class AbstractSnsService<
5455
MessageEnvelopeType,
5556
DependenciesType,
5657
SNSCreationConfig,
57-
SNSQueueLocatorType,
58+
SNSTopicLocatorType,
5859
SNSOptionsType
5960
> {
6061
protected readonly snsClient: SNSClient

0 commit comments

Comments
 (0)