@remit/sqs-client 0.0.17 → 0.0.18
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/producer.d.ts +4 -9
- package/dist/producer.js +8 -24
- package/package.json +1 -1
package/dist/producer.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { SQSClient } from "@aws-sdk/client-sqs";
|
|
2
|
-
import type {
|
|
2
|
+
import type { FifoQueueProducer, GroupedQueueProducer, QueueProducer } from "@remit/data-ports";
|
|
3
3
|
import { type SqsStaticCredentials } from "./index.js";
|
|
4
4
|
export interface CreateSqsClientOptions {
|
|
5
5
|
readonly queueUrl: string;
|
|
@@ -43,11 +43,6 @@ export declare const isLocalEndpoint: (queueUrl: string) => boolean;
|
|
|
43
43
|
* `SQS_ACCESS_KEY_ID`/`SQS_SECRET_ACCESS_KEY` are present.
|
|
44
44
|
*/
|
|
45
45
|
export declare const createSqsClient: (options: CreateSqsClientOptions) => SQSClient;
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
* (otherwise the queue deduplicates by content); a standard queue rejects
|
|
50
|
-
* both, so they are left off. A local queue server (ElasticMQ) does not honour
|
|
51
|
-
* a per-message delay on its FIFO queues, so the delay is dropped there.
|
|
52
|
-
*/
|
|
53
|
-
export declare const createQueueProducer: <T, M extends QueueMessage<T> = QueueMessage<T>>(options: CreateSqsClientOptions) => QueueProducer<T, M>;
|
|
46
|
+
export declare const createStandardQueueProducer: <T>(options: CreateSqsClientOptions) => QueueProducer<T>;
|
|
47
|
+
export declare const createGroupedQueueProducer: <T>(options: CreateSqsClientOptions) => GroupedQueueProducer<T>;
|
|
48
|
+
export declare const createFifoQueueProducer: <T>(options: CreateSqsClientOptions) => FifoQueueProducer<T>;
|
package/dist/producer.js
CHANGED
|
@@ -54,33 +54,11 @@ export const createSqsClient = (options) => {
|
|
|
54
54
|
credentials: (local ? localCredentials : undefined) ?? resolveSqsCredentials(env),
|
|
55
55
|
});
|
|
56
56
|
};
|
|
57
|
-
const
|
|
58
|
-
const isGrouped = (message) => "groupId" in message && typeof message.groupId === "string";
|
|
59
|
-
const isDeduplicated = (message) => isGrouped(message) &&
|
|
60
|
-
"deduplicationId" in message &&
|
|
61
|
-
typeof message.deduplicationId === "string";
|
|
62
|
-
/**
|
|
63
|
-
* The SQS adapter for the `QueueProducer` port. A FIFO queue (`.fifo`) gets
|
|
64
|
-
* the message group, and the deduplication id when the message carries one
|
|
65
|
-
* (otherwise the queue deduplicates by content); a standard queue rejects
|
|
66
|
-
* both, so they are left off. A local queue server (ElasticMQ) does not honour
|
|
67
|
-
* a per-message delay on its FIFO queues, so the delay is dropped there.
|
|
68
|
-
*/
|
|
69
|
-
export const createQueueProducer = (options) => {
|
|
57
|
+
const createProducer = (kind, options, attributes) => {
|
|
70
58
|
const { queueUrl } = options;
|
|
71
59
|
const client = createSqsClient(options);
|
|
72
|
-
const fifo = isFifoQueue(queueUrl);
|
|
73
|
-
const local = isLocalEndpoint(queueUrl);
|
|
74
|
-
const attributes = (message) => ({
|
|
75
|
-
...(fifo && isGrouped(message) && { MessageGroupId: message.groupId }),
|
|
76
|
-
...(fifo &&
|
|
77
|
-
isDeduplicated(message) && {
|
|
78
|
-
MessageDeduplicationId: message.deduplicationId,
|
|
79
|
-
}),
|
|
80
|
-
...(message.delaySeconds &&
|
|
81
|
-
!local && { DelaySeconds: message.delaySeconds }),
|
|
82
|
-
});
|
|
83
60
|
return {
|
|
61
|
+
kind,
|
|
84
62
|
send: async (message) => {
|
|
85
63
|
await client.send(new SendMessageCommand({
|
|
86
64
|
QueueUrl: queueUrl,
|
|
@@ -103,3 +81,9 @@ export const createQueueProducer = (options) => {
|
|
|
103
81
|
},
|
|
104
82
|
};
|
|
105
83
|
};
|
|
84
|
+
export const createStandardQueueProducer = (options) => createProducer("Standard", options, () => ({}));
|
|
85
|
+
export const createGroupedQueueProducer = (options) => createProducer("Grouped", options, (message) => ({ MessageGroupId: message.groupId }));
|
|
86
|
+
export const createFifoQueueProducer = (options) => createProducer("Fifo", options, (message) => ({
|
|
87
|
+
MessageGroupId: message.groupId,
|
|
88
|
+
MessageDeduplicationId: message.deduplicationId,
|
|
89
|
+
}));
|