@geekmidas/events 0.0.1
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/README.md +473 -0
- package/dist/BasicConnection-BNi6_olg.mjs +42 -0
- package/dist/BasicConnection-BNi6_olg.mjs.map +1 -0
- package/dist/BasicConnection-C4_Y0nIj.d.mts +26 -0
- package/dist/BasicConnection-CddnULuT.d.cts +26 -0
- package/dist/BasicConnection-CzfMubv_.cjs +48 -0
- package/dist/BasicConnection-CzfMubv_.cjs.map +1 -0
- package/dist/BasicPublisher-BzfzHIfb.cjs +20 -0
- package/dist/BasicPublisher-BzfzHIfb.cjs.map +1 -0
- package/dist/BasicPublisher-Cg3SxIVR.mjs +14 -0
- package/dist/BasicPublisher-Cg3SxIVR.mjs.map +1 -0
- package/dist/BasicPublisher-DCBxaTwC.d.mts +12 -0
- package/dist/BasicPublisher-V5hELHG9.d.cts +12 -0
- package/dist/BasicSubscriber-BB3aKeph.d.mts +12 -0
- package/dist/BasicSubscriber-BEv5N21f.mjs +18 -0
- package/dist/BasicSubscriber-BEv5N21f.mjs.map +1 -0
- package/dist/BasicSubscriber-DOwgFw5j.d.cts +12 -0
- package/dist/BasicSubscriber-DyTKOixe.cjs +24 -0
- package/dist/BasicSubscriber-DyTKOixe.cjs.map +1 -0
- package/dist/EventConnection-ClLMoIUU.mjs +36 -0
- package/dist/EventConnection-ClLMoIUU.mjs.map +1 -0
- package/dist/EventConnection-DZhn1Msl.d.cts +13 -0
- package/dist/EventConnection-DeXfLGom.d.mts +13 -0
- package/dist/EventConnection-F_N81SXu.cjs +41 -0
- package/dist/EventConnection-F_N81SXu.cjs.map +1 -0
- package/dist/EventConnection.cjs +5 -0
- package/dist/EventConnection.d.cts +3 -0
- package/dist/EventConnection.d.mts +3 -0
- package/dist/EventConnection.mjs +4 -0
- package/dist/Publisher-C3m8JFXm.d.mts +19 -0
- package/dist/Publisher-DS0aOh8r.mjs +65 -0
- package/dist/Publisher-DS0aOh8r.mjs.map +1 -0
- package/dist/Publisher-ceu6OxCj.cjs +70 -0
- package/dist/Publisher-ceu6OxCj.cjs.map +1 -0
- package/dist/Publisher-nXNVjL0e.d.cts +19 -0
- package/dist/Publisher.cjs +4 -0
- package/dist/Publisher.d.cts +3 -0
- package/dist/Publisher.d.mts +3 -0
- package/dist/Publisher.mjs +4 -0
- package/dist/RabbitMQConnection-7cWp_-_Q.d.cts +43 -0
- package/dist/RabbitMQConnection-BN_GybOv.cjs +113 -0
- package/dist/RabbitMQConnection-BN_GybOv.cjs.map +1 -0
- package/dist/RabbitMQConnection-C2HC7J7K.d.mts +43 -0
- package/dist/RabbitMQConnection-eVOVS4Dl.mjs +107 -0
- package/dist/RabbitMQConnection-eVOVS4Dl.mjs.map +1 -0
- package/dist/RabbitMQPublisher-BZX0edgL.mjs +39 -0
- package/dist/RabbitMQPublisher-BZX0edgL.mjs.map +1 -0
- package/dist/RabbitMQPublisher-CSCn6gMA.cjs +45 -0
- package/dist/RabbitMQPublisher-CSCn6gMA.cjs.map +1 -0
- package/dist/RabbitMQPublisher-CpcbgrXj.d.cts +23 -0
- package/dist/RabbitMQPublisher-DDZi15Ro.d.mts +23 -0
- package/dist/RabbitMQSubscriber-B5I-hBaT.mjs +57 -0
- package/dist/RabbitMQSubscriber-B5I-hBaT.mjs.map +1 -0
- package/dist/RabbitMQSubscriber-BJ9PTGny.d.cts +25 -0
- package/dist/RabbitMQSubscriber-CIvIw8MG.d.mts +25 -0
- package/dist/RabbitMQSubscriber-Cj7qLIi6.cjs +63 -0
- package/dist/RabbitMQSubscriber-Cj7qLIi6.cjs.map +1 -0
- package/dist/SNSConnection-CAImaMM2.d.mts +40 -0
- package/dist/SNSConnection-Cqbr7-Ho.d.cts +40 -0
- package/dist/SNSConnection-D7wCf9Si.mjs +70 -0
- package/dist/SNSConnection-D7wCf9Si.mjs.map +1 -0
- package/dist/SNSConnection-DVsC_pbB.cjs +76 -0
- package/dist/SNSConnection-DVsC_pbB.cjs.map +1 -0
- package/dist/SNSPublisher-BZ6N3JI9.cjs +48 -0
- package/dist/SNSPublisher-BZ6N3JI9.cjs.map +1 -0
- package/dist/SNSPublisher-BfWjzNiB.mjs +42 -0
- package/dist/SNSPublisher-BfWjzNiB.mjs.map +1 -0
- package/dist/SNSPublisher-Dkhb4LU-.d.mts +21 -0
- package/dist/SNSPublisher-RVZFa7kL.d.cts +21 -0
- package/dist/SNSSubscriber-B31JmkAE.d.mts +54 -0
- package/dist/SNSSubscriber-C9YJWa7m.mjs +143 -0
- package/dist/SNSSubscriber-C9YJWa7m.mjs.map +1 -0
- package/dist/SNSSubscriber-UE0ia4XM.cjs +149 -0
- package/dist/SNSSubscriber-UE0ia4XM.cjs.map +1 -0
- package/dist/SNSSubscriber-k2UwKUxu.d.cts +54 -0
- package/dist/SQSConnection-BwNjUPr4.cjs +76 -0
- package/dist/SQSConnection-BwNjUPr4.cjs.map +1 -0
- package/dist/SQSConnection-C5WFqZW7.d.mts +40 -0
- package/dist/SQSConnection-Eleqqre3.mjs +70 -0
- package/dist/SQSConnection-Eleqqre3.mjs.map +1 -0
- package/dist/SQSConnection-geav2Rsn.d.cts +40 -0
- package/dist/SQSPublisher-CdsayOLV.d.mts +23 -0
- package/dist/SQSPublisher-DG9o4ME3.mjs +57 -0
- package/dist/SQSPublisher-DG9o4ME3.mjs.map +1 -0
- package/dist/SQSPublisher-Dq5353oZ.cjs +63 -0
- package/dist/SQSPublisher-Dq5353oZ.cjs.map +1 -0
- package/dist/SQSPublisher-Utb_FTe5.d.cts +23 -0
- package/dist/SQSSubscriber-B6iL1EnX.d.cts +43 -0
- package/dist/SQSSubscriber-CD66P7hH.mjs +121 -0
- package/dist/SQSSubscriber-CD66P7hH.mjs.map +1 -0
- package/dist/SQSSubscriber-DBeE4XAR.d.mts +43 -0
- package/dist/SQSSubscriber-DZDNgLE5.cjs +127 -0
- package/dist/SQSSubscriber-DZDNgLE5.cjs.map +1 -0
- package/dist/Subscriber-Bd9hb_jp.mjs +74 -0
- package/dist/Subscriber-Bd9hb_jp.mjs.map +1 -0
- package/dist/Subscriber-Cff9EIpv.d.mts +19 -0
- package/dist/Subscriber-CpAwcUzb.d.cts +19 -0
- package/dist/Subscriber-saVOWuMq.cjs +79 -0
- package/dist/Subscriber-saVOWuMq.cjs.map +1 -0
- package/dist/Subscriber.cjs +4 -0
- package/dist/Subscriber.d.cts +3 -0
- package/dist/Subscriber.d.mts +3 -0
- package/dist/Subscriber.mjs +4 -0
- package/dist/basic/BasicConnection.cjs +4 -0
- package/dist/basic/BasicConnection.d.cts +3 -0
- package/dist/basic/BasicConnection.d.mts +3 -0
- package/dist/basic/BasicConnection.mjs +4 -0
- package/dist/basic/BasicPublisher.cjs +3 -0
- package/dist/basic/BasicPublisher.d.cts +4 -0
- package/dist/basic/BasicPublisher.d.mts +4 -0
- package/dist/basic/BasicPublisher.mjs +3 -0
- package/dist/basic/BasicSubscriber.cjs +3 -0
- package/dist/basic/BasicSubscriber.d.cts +4 -0
- package/dist/basic/BasicSubscriber.d.mts +4 -0
- package/dist/basic/BasicSubscriber.mjs +3 -0
- package/dist/basic/index.cjs +8 -0
- package/dist/basic/index.d.cts +5 -0
- package/dist/basic/index.d.mts +5 -0
- package/dist/basic/index.mjs +6 -0
- package/dist/chunk-CUT6urMc.cjs +30 -0
- package/dist/index.cjs +9 -0
- package/dist/index.d.cts +5 -0
- package/dist/index.d.mts +5 -0
- package/dist/index.mjs +6 -0
- package/dist/rabbitmq/RabbitMQConnection.cjs +4 -0
- package/dist/rabbitmq/RabbitMQConnection.d.cts +3 -0
- package/dist/rabbitmq/RabbitMQConnection.d.mts +3 -0
- package/dist/rabbitmq/RabbitMQConnection.mjs +4 -0
- package/dist/rabbitmq/RabbitMQPublisher.cjs +3 -0
- package/dist/rabbitmq/RabbitMQPublisher.d.cts +4 -0
- package/dist/rabbitmq/RabbitMQPublisher.d.mts +4 -0
- package/dist/rabbitmq/RabbitMQPublisher.mjs +3 -0
- package/dist/rabbitmq/RabbitMQSubscriber.cjs +3 -0
- package/dist/rabbitmq/RabbitMQSubscriber.d.cts +4 -0
- package/dist/rabbitmq/RabbitMQSubscriber.d.mts +4 -0
- package/dist/rabbitmq/RabbitMQSubscriber.mjs +3 -0
- package/dist/rabbitmq/index.cjs +8 -0
- package/dist/rabbitmq/index.d.cts +5 -0
- package/dist/rabbitmq/index.d.mts +5 -0
- package/dist/rabbitmq/index.mjs +6 -0
- package/dist/sns/SNSConnection.cjs +4 -0
- package/dist/sns/SNSConnection.d.cts +3 -0
- package/dist/sns/SNSConnection.d.mts +3 -0
- package/dist/sns/SNSConnection.mjs +4 -0
- package/dist/sns/SNSPublisher.cjs +3 -0
- package/dist/sns/SNSPublisher.d.cts +4 -0
- package/dist/sns/SNSPublisher.d.mts +4 -0
- package/dist/sns/SNSPublisher.mjs +3 -0
- package/dist/sns/SNSSubscriber.cjs +6 -0
- package/dist/sns/SNSSubscriber.d.cts +4 -0
- package/dist/sns/SNSSubscriber.d.mts +4 -0
- package/dist/sns/SNSSubscriber.mjs +6 -0
- package/dist/sns/index.cjs +10 -0
- package/dist/sns/index.d.cts +5 -0
- package/dist/sns/index.d.mts +5 -0
- package/dist/sns/index.mjs +8 -0
- package/dist/sqs/SQSConnection.cjs +4 -0
- package/dist/sqs/SQSConnection.d.cts +3 -0
- package/dist/sqs/SQSConnection.d.mts +3 -0
- package/dist/sqs/SQSConnection.mjs +4 -0
- package/dist/sqs/SQSPublisher.cjs +3 -0
- package/dist/sqs/SQSPublisher.d.cts +4 -0
- package/dist/sqs/SQSPublisher.d.mts +4 -0
- package/dist/sqs/SQSPublisher.mjs +3 -0
- package/dist/sqs/SQSSubscriber.cjs +3 -0
- package/dist/sqs/SQSSubscriber.d.cts +4 -0
- package/dist/sqs/SQSSubscriber.d.mts +4 -0
- package/dist/sqs/SQSSubscriber.mjs +3 -0
- package/dist/sqs/index.cjs +8 -0
- package/dist/sqs/index.d.cts +5 -0
- package/dist/sqs/index.d.mts +5 -0
- package/dist/sqs/index.mjs +6 -0
- package/dist/types-B63qHVOG.mjs +17 -0
- package/dist/types-B63qHVOG.mjs.map +1 -0
- package/dist/types-CvSMEO5z.cjs +23 -0
- package/dist/types-CvSMEO5z.cjs.map +1 -0
- package/dist/types-D0g-o6wX.d.mts +65 -0
- package/dist/types-DEGUg5BA.d.cts +65 -0
- package/dist/types.cjs +3 -0
- package/dist/types.d.cts +2 -0
- package/dist/types.d.mts +2 -0
- package/dist/types.mjs +3 -0
- package/package.json +49 -0
- package/src/EventConnection.ts +39 -0
- package/src/Publisher.ts +87 -0
- package/src/Subscriber.ts +102 -0
- package/src/__tests__/Subscriber.spec.ts +41 -0
- package/src/basic/BasicConnection.ts +47 -0
- package/src/basic/BasicPublisher.ts +15 -0
- package/src/basic/BasicSubscriber.ts +24 -0
- package/src/basic/__tests__/BasicSubscriber.spec.ts +166 -0
- package/src/basic/index.ts +3 -0
- package/src/index.ts +25 -0
- package/src/rabbitmq/RabbitMQConnection.ts +148 -0
- package/src/rabbitmq/RabbitMQPublisher.ts +67 -0
- package/src/rabbitmq/RabbitMQSubscriber.ts +113 -0
- package/src/rabbitmq/__tests__/RabbitMQPublisher.spec.ts +378 -0
- package/src/rabbitmq/__tests__/RabbitMQSubscriber.spec.ts +292 -0
- package/src/rabbitmq/index.ts +6 -0
- package/src/sns/SNSConnection.ts +98 -0
- package/src/sns/SNSPublisher.ts +64 -0
- package/src/sns/SNSSubscriber.ts +222 -0
- package/src/sns/__tests__/SNS-SQS-Integration.spec.ts +389 -0
- package/src/sns/index.ts +6 -0
- package/src/sqs/SQSConnection.ts +97 -0
- package/src/sqs/SQSPublisher.ts +105 -0
- package/src/sqs/SQSSubscriber.ts +189 -0
- package/src/sqs/__tests__/SQSPublisher.spec.ts +189 -0
- package/src/sqs/index.ts +6 -0
- package/src/types.ts +76 -0
- package/tsdown.config.ts +5 -0
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import { EventPublisher, PublishableMessage } from "./types-DEGUg5BA.cjs";
|
|
2
|
+
import { SQSConnection } from "./SQSConnection-geav2Rsn.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/sqs/SQSPublisher.d.ts
|
|
5
|
+
interface SQSPublisherOptions {
|
|
6
|
+
maxBatchSize?: number;
|
|
7
|
+
}
|
|
8
|
+
declare class SQSPublisher<TMessage extends PublishableMessage<string, any>> implements EventPublisher<TMessage> {
|
|
9
|
+
readonly connection: SQSConnection;
|
|
10
|
+
readonly options: Required<SQSPublisherOptions>;
|
|
11
|
+
constructor(connection: SQSConnection, options?: SQSPublisherOptions);
|
|
12
|
+
/**
|
|
13
|
+
* Create an SQSPublisher from a connection string
|
|
14
|
+
* Format: sqs://?queueUrl=https://sqs.region.amazonaws.com/accountId/queueName®ion=us-east-1&endpoint=http://localhost:4566&maxBatchSize=10
|
|
15
|
+
*/
|
|
16
|
+
static fromConnectionString<TMessage extends PublishableMessage<string, any>>(connectionString: string): Promise<SQSPublisher<TMessage>>;
|
|
17
|
+
publish(messages: TMessage[]): Promise<void>;
|
|
18
|
+
private sendBatch;
|
|
19
|
+
close(): Promise<void>;
|
|
20
|
+
}
|
|
21
|
+
//#endregion
|
|
22
|
+
export { SQSPublisher, SQSPublisherOptions };
|
|
23
|
+
//# sourceMappingURL=SQSPublisher-Utb_FTe5.d.cts.map
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { EventSubscriber, PublishableMessage } from "./types-DEGUg5BA.cjs";
|
|
2
|
+
import { SQSConnection } from "./SQSConnection-geav2Rsn.cjs";
|
|
3
|
+
|
|
4
|
+
//#region src/sqs/SQSSubscriber.d.ts
|
|
5
|
+
interface SQSSubscriberOptions {
|
|
6
|
+
waitTimeSeconds?: number;
|
|
7
|
+
maxMessages?: number;
|
|
8
|
+
expectedTopicArn?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* SQS Subscriber - receives messages from an SQS queue
|
|
12
|
+
*
|
|
13
|
+
* This subscriber can receive:
|
|
14
|
+
* 1. Direct SQS messages
|
|
15
|
+
* 2. SNS messages that were pushed to the queue (SNS → SQS pattern)
|
|
16
|
+
*
|
|
17
|
+
* When receiving SNS messages, it:
|
|
18
|
+
* - Automatically detects and parses the SNS wrapper format
|
|
19
|
+
* - Filters by TopicArn (if expectedTopicArn is provided)
|
|
20
|
+
* - Filters by message type
|
|
21
|
+
* - Processes the actual message payload
|
|
22
|
+
*/
|
|
23
|
+
declare class SQSSubscriber<TMessage extends PublishableMessage<string, any>> implements EventSubscriber<TMessage> {
|
|
24
|
+
private connection;
|
|
25
|
+
private polling;
|
|
26
|
+
private messageTypes;
|
|
27
|
+
private listener?;
|
|
28
|
+
private options;
|
|
29
|
+
constructor(connection: SQSConnection, options?: SQSSubscriberOptions);
|
|
30
|
+
subscribe(messages: TMessage['type'][], listener: (payload: TMessage) => Promise<void>): Promise<void>;
|
|
31
|
+
stop(): void;
|
|
32
|
+
private poll;
|
|
33
|
+
private processMessages;
|
|
34
|
+
/**
|
|
35
|
+
* Parse message body - handles both direct SQS messages and SNS-wrapped messages
|
|
36
|
+
*/
|
|
37
|
+
private parseMessage;
|
|
38
|
+
private deleteMessage;
|
|
39
|
+
private sleep;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { SQSSubscriber, SQSSubscriberOptions };
|
|
43
|
+
//# sourceMappingURL=SQSSubscriber-B6iL1EnX.d.cts.map
|
|
@@ -0,0 +1,121 @@
|
|
|
1
|
+
import { DeleteMessageCommand, ReceiveMessageCommand } from "@aws-sdk/client-sqs";
|
|
2
|
+
|
|
3
|
+
//#region src/sqs/SQSSubscriber.ts
|
|
4
|
+
/**
|
|
5
|
+
* SQS Subscriber - receives messages from an SQS queue
|
|
6
|
+
*
|
|
7
|
+
* This subscriber can receive:
|
|
8
|
+
* 1. Direct SQS messages
|
|
9
|
+
* 2. SNS messages that were pushed to the queue (SNS → SQS pattern)
|
|
10
|
+
*
|
|
11
|
+
* When receiving SNS messages, it:
|
|
12
|
+
* - Automatically detects and parses the SNS wrapper format
|
|
13
|
+
* - Filters by TopicArn (if expectedTopicArn is provided)
|
|
14
|
+
* - Filters by message type
|
|
15
|
+
* - Processes the actual message payload
|
|
16
|
+
*/
|
|
17
|
+
var SQSSubscriber = class {
|
|
18
|
+
polling = false;
|
|
19
|
+
messageTypes = /* @__PURE__ */ new Set();
|
|
20
|
+
listener;
|
|
21
|
+
options;
|
|
22
|
+
constructor(connection, options = {}) {
|
|
23
|
+
this.connection = connection;
|
|
24
|
+
this.options = {
|
|
25
|
+
waitTimeSeconds: options.waitTimeSeconds ?? 20,
|
|
26
|
+
maxMessages: options.maxMessages ?? 10,
|
|
27
|
+
expectedTopicArn: options.expectedTopicArn ?? ""
|
|
28
|
+
};
|
|
29
|
+
}
|
|
30
|
+
async subscribe(messages, listener) {
|
|
31
|
+
this.messageTypes = new Set(messages);
|
|
32
|
+
this.listener = listener;
|
|
33
|
+
if (!this.connection.isConnected()) await this.connection.connect();
|
|
34
|
+
this.polling = true;
|
|
35
|
+
this.poll();
|
|
36
|
+
}
|
|
37
|
+
stop() {
|
|
38
|
+
this.polling = false;
|
|
39
|
+
}
|
|
40
|
+
async poll() {
|
|
41
|
+
while (this.polling) try {
|
|
42
|
+
const command = new ReceiveMessageCommand({
|
|
43
|
+
QueueUrl: this.connection.queueUrl,
|
|
44
|
+
MaxNumberOfMessages: this.options.maxMessages,
|
|
45
|
+
WaitTimeSeconds: this.options.waitTimeSeconds,
|
|
46
|
+
MessageAttributeNames: ["All"]
|
|
47
|
+
});
|
|
48
|
+
const response = await this.connection.sqsClient.send(command);
|
|
49
|
+
if (response.Messages && response.Messages.length > 0) await this.processMessages(response.Messages);
|
|
50
|
+
} catch (error) {
|
|
51
|
+
console.error("Error receiving messages from SQS:", error);
|
|
52
|
+
await this.sleep(1e3);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
async processMessages(messages) {
|
|
56
|
+
for (const message of messages) try {
|
|
57
|
+
if (!message.Body) continue;
|
|
58
|
+
const parsedMessage = this.parseMessage(message.Body);
|
|
59
|
+
if (!parsedMessage) {
|
|
60
|
+
await this.deleteMessage(message.ReceiptHandle);
|
|
61
|
+
continue;
|
|
62
|
+
}
|
|
63
|
+
const { payload, messageType, topicArn } = parsedMessage;
|
|
64
|
+
if (this.options.expectedTopicArn && topicArn) {
|
|
65
|
+
if (topicArn !== this.options.expectedTopicArn) {
|
|
66
|
+
console.warn(`Received message from unexpected topic: ${topicArn}, expected: ${this.options.expectedTopicArn}`);
|
|
67
|
+
await this.deleteMessage(message.ReceiptHandle);
|
|
68
|
+
continue;
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
if (messageType && this.messageTypes.has(messageType)) {
|
|
72
|
+
if (this.listener) await this.listener(payload);
|
|
73
|
+
await this.deleteMessage(message.ReceiptHandle);
|
|
74
|
+
} else await this.deleteMessage(message.ReceiptHandle);
|
|
75
|
+
} catch (error) {
|
|
76
|
+
console.error("Error processing message:", error);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Parse message body - handles both direct SQS messages and SNS-wrapped messages
|
|
81
|
+
*/
|
|
82
|
+
parseMessage(body) {
|
|
83
|
+
try {
|
|
84
|
+
const parsed = JSON.parse(body);
|
|
85
|
+
if (parsed.Type === "Notification" && parsed.Message) {
|
|
86
|
+
const snsMessage = JSON.parse(parsed.Message);
|
|
87
|
+
const messageType = parsed.MessageAttributes?.type?.Value || snsMessage.type;
|
|
88
|
+
return {
|
|
89
|
+
payload: snsMessage,
|
|
90
|
+
messageType,
|
|
91
|
+
topicArn: parsed.TopicArn
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
return {
|
|
95
|
+
payload: parsed,
|
|
96
|
+
messageType: parsed.type
|
|
97
|
+
};
|
|
98
|
+
} catch (error) {
|
|
99
|
+
console.error("Failed to parse message:", error);
|
|
100
|
+
return null;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
async deleteMessage(receiptHandle) {
|
|
104
|
+
try {
|
|
105
|
+
const command = new DeleteMessageCommand({
|
|
106
|
+
QueueUrl: this.connection.queueUrl,
|
|
107
|
+
ReceiptHandle: receiptHandle
|
|
108
|
+
});
|
|
109
|
+
await this.connection.sqsClient.send(command);
|
|
110
|
+
} catch (error) {
|
|
111
|
+
console.error("Error deleting message:", error);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
sleep(ms) {
|
|
115
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
116
|
+
}
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
//#endregion
|
|
120
|
+
export { SQSSubscriber };
|
|
121
|
+
//# sourceMappingURL=SQSSubscriber-CD66P7hH.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SQSSubscriber-CD66P7hH.mjs","names":["connection: SQSConnection","options: SQSSubscriberOptions","messages: TMessage['type'][]","listener: (payload: TMessage) => Promise<void>","messages: Message[]","body: string","receiptHandle: string","ms: number"],"sources":["../src/sqs/SQSSubscriber.ts"],"sourcesContent":["import {\n DeleteMessageCommand,\n type Message,\n ReceiveMessageCommand,\n} from '@aws-sdk/client-sqs';\nimport type { EventSubscriber, PublishableMessage } from '../types';\nimport type { SQSConnection } from './SQSConnection';\n\nexport interface SQSSubscriberOptions {\n waitTimeSeconds?: number; // SQS long polling (default: 20)\n maxMessages?: number; // Max messages per poll (default: 10)\n expectedTopicArn?: string; // Optional: verify messages are from specific SNS topic\n}\n\n/**\n * SQS Subscriber - receives messages from an SQS queue\n *\n * This subscriber can receive:\n * 1. Direct SQS messages\n * 2. SNS messages that were pushed to the queue (SNS → SQS pattern)\n *\n * When receiving SNS messages, it:\n * - Automatically detects and parses the SNS wrapper format\n * - Filters by TopicArn (if expectedTopicArn is provided)\n * - Filters by message type\n * - Processes the actual message payload\n */\nexport class SQSSubscriber<TMessage extends PublishableMessage<string, any>>\n implements EventSubscriber<TMessage>\n{\n private polling = false;\n private messageTypes: Set<TMessage['type']> = new Set();\n private listener?: (payload: TMessage) => Promise<void>;\n private options: Required<SQSSubscriberOptions>;\n\n constructor(\n private connection: SQSConnection,\n options: SQSSubscriberOptions = {},\n ) {\n this.options = {\n waitTimeSeconds: options.waitTimeSeconds ?? 20,\n maxMessages: options.maxMessages ?? 10,\n expectedTopicArn: options.expectedTopicArn ?? '',\n };\n }\n\n async subscribe(\n messages: TMessage['type'][],\n listener: (payload: TMessage) => Promise<void>,\n ): Promise<void> {\n this.messageTypes = new Set(messages);\n this.listener = listener;\n\n if (!this.connection.isConnected()) {\n await this.connection.connect();\n }\n\n this.polling = true;\n this.poll();\n }\n\n stop(): void {\n this.polling = false;\n }\n\n private async poll(): Promise<void> {\n while (this.polling) {\n try {\n const command = new ReceiveMessageCommand({\n QueueUrl: this.connection.queueUrl,\n MaxNumberOfMessages: this.options.maxMessages,\n WaitTimeSeconds: this.options.waitTimeSeconds,\n MessageAttributeNames: ['All'],\n });\n\n const response = await this.connection.sqsClient.send(command);\n\n if (response.Messages && response.Messages.length > 0) {\n await this.processMessages(response.Messages);\n }\n } catch (error) {\n console.error('Error receiving messages from SQS:', error);\n await this.sleep(1000);\n }\n }\n }\n\n private async processMessages(messages: Message[]): Promise<void> {\n for (const message of messages) {\n try {\n if (!message.Body) continue;\n\n // Try to parse as SNS message first\n const parsedMessage = this.parseMessage(message.Body);\n\n if (!parsedMessage) {\n // Not a valid message format\n await this.deleteMessage(message.ReceiptHandle!);\n continue;\n }\n\n const { payload, messageType, topicArn } = parsedMessage;\n\n // If expectedTopicArn is set, verify the message is from that topic\n if (this.options.expectedTopicArn && topicArn) {\n if (topicArn !== this.options.expectedTopicArn) {\n console.warn(\n `Received message from unexpected topic: ${topicArn}, expected: ${this.options.expectedTopicArn}`,\n );\n await this.deleteMessage(message.ReceiptHandle!);\n continue;\n }\n }\n\n // Check if we're subscribed to this message type\n if (\n messageType &&\n this.messageTypes.has(messageType as TMessage['type'])\n ) {\n // Call listener\n if (this.listener) {\n await this.listener(payload as TMessage);\n }\n\n // Delete message after successful processing\n await this.deleteMessage(message.ReceiptHandle!);\n } else {\n // Delete messages we're not subscribed to\n await this.deleteMessage(message.ReceiptHandle!);\n }\n } catch (error) {\n console.error('Error processing message:', error);\n // Message will become visible again\n }\n }\n }\n\n /**\n * Parse message body - handles both direct SQS messages and SNS-wrapped messages\n */\n private parseMessage(body: string): {\n payload: unknown;\n messageType: string | undefined;\n topicArn?: string;\n } | null {\n try {\n const parsed = JSON.parse(body);\n\n // Check if this is an SNS notification wrapper\n if (parsed.Type === 'Notification' && parsed.Message) {\n // This is an SNS message\n const snsMessage = JSON.parse(parsed.Message);\n const messageType =\n parsed.MessageAttributes?.type?.Value || snsMessage.type;\n\n return {\n payload: snsMessage,\n messageType,\n topicArn: parsed.TopicArn,\n };\n }\n\n // This is a direct SQS message\n return {\n payload: parsed,\n messageType: parsed.type,\n };\n } catch (error) {\n console.error('Failed to parse message:', error);\n return null;\n }\n }\n\n private async deleteMessage(receiptHandle: string): Promise<void> {\n try {\n const command = new DeleteMessageCommand({\n QueueUrl: this.connection.queueUrl,\n ReceiptHandle: receiptHandle,\n });\n await this.connection.sqsClient.send(command);\n } catch (error) {\n console.error('Error deleting message:', error);\n }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;AA2BA,IAAa,gBAAb,MAEA;CACE,AAAQ,UAAU;CAClB,AAAQ,+BAAsC,IAAI;CAClD,AAAQ;CACR,AAAQ;CAER,YACUA,YACRC,UAAgC,CAAE,GAClC;EAFQ;AAGR,OAAK,UAAU;GACb,iBAAiB,QAAQ,mBAAmB;GAC5C,aAAa,QAAQ,eAAe;GACpC,kBAAkB,QAAQ,oBAAoB;EAC/C;CACF;CAED,MAAM,UACJC,UACAC,UACe;AACf,OAAK,eAAe,IAAI,IAAI;AAC5B,OAAK,WAAW;AAEhB,OAAK,KAAK,WAAW,aAAa,CAChC,OAAM,KAAK,WAAW,SAAS;AAGjC,OA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,MAAM,KAAK;AAG/B,OAAI,OAAO,SAAS,kBAAkB,OAAO,SAAS;IAEpD,MAAM,aAAa,KAAK,MAAM,OAAO,QAAQ;IAC7C,MAAM,cACJ,OAAO,mBAAmB,MAAM,SAAS,WAAW;AAEtD,WAAO;KACL,SAAS;KACT;KACA,UAAU,OAAO;IAClB;GACF;AAGD,UAAO;IACL,SAAS;IACT,aAAa,OAAO;GACrB;EACF,SAAQ,OAAO;AACd,WAAQ,MAAM,4BAA4B,MAAM;AAChD,UAAO;EACR;CACF;CAED,MAAc,cAAcC,eAAsC;AAChE,MAAI;GACF,MAAM,UAAU,IAAI,qBAAqB;IACvC,UAAU,KAAK,WAAW;IAC1B,eAAe;GAChB;AACD,SAAM,KAAK,WAAW,UAAU,KAAK,QAAQ;EAC9C,SAAQ,OAAO;AACd,WAAQ,MAAM,2BAA2B,MAAM;EAChD;CACF;CAED,AAAQ,MAAMC,IAA2B;AACvC,SAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAG;CACxD;AACF"}
|
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { EventSubscriber, PublishableMessage } from "./types-D0g-o6wX.mjs";
|
|
2
|
+
import { SQSConnection } from "./SQSConnection-C5WFqZW7.mjs";
|
|
3
|
+
|
|
4
|
+
//#region src/sqs/SQSSubscriber.d.ts
|
|
5
|
+
interface SQSSubscriberOptions {
|
|
6
|
+
waitTimeSeconds?: number;
|
|
7
|
+
maxMessages?: number;
|
|
8
|
+
expectedTopicArn?: string;
|
|
9
|
+
}
|
|
10
|
+
/**
|
|
11
|
+
* SQS Subscriber - receives messages from an SQS queue
|
|
12
|
+
*
|
|
13
|
+
* This subscriber can receive:
|
|
14
|
+
* 1. Direct SQS messages
|
|
15
|
+
* 2. SNS messages that were pushed to the queue (SNS → SQS pattern)
|
|
16
|
+
*
|
|
17
|
+
* When receiving SNS messages, it:
|
|
18
|
+
* - Automatically detects and parses the SNS wrapper format
|
|
19
|
+
* - Filters by TopicArn (if expectedTopicArn is provided)
|
|
20
|
+
* - Filters by message type
|
|
21
|
+
* - Processes the actual message payload
|
|
22
|
+
*/
|
|
23
|
+
declare class SQSSubscriber<TMessage extends PublishableMessage<string, any>> implements EventSubscriber<TMessage> {
|
|
24
|
+
private connection;
|
|
25
|
+
private polling;
|
|
26
|
+
private messageTypes;
|
|
27
|
+
private listener?;
|
|
28
|
+
private options;
|
|
29
|
+
constructor(connection: SQSConnection, options?: SQSSubscriberOptions);
|
|
30
|
+
subscribe(messages: TMessage['type'][], listener: (payload: TMessage) => Promise<void>): Promise<void>;
|
|
31
|
+
stop(): void;
|
|
32
|
+
private poll;
|
|
33
|
+
private processMessages;
|
|
34
|
+
/**
|
|
35
|
+
* Parse message body - handles both direct SQS messages and SNS-wrapped messages
|
|
36
|
+
*/
|
|
37
|
+
private parseMessage;
|
|
38
|
+
private deleteMessage;
|
|
39
|
+
private sleep;
|
|
40
|
+
}
|
|
41
|
+
//#endregion
|
|
42
|
+
export { SQSSubscriber, SQSSubscriberOptions };
|
|
43
|
+
//# sourceMappingURL=SQSSubscriber-DBeE4XAR.d.mts.map
|
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
const require_chunk = require('./chunk-CUT6urMc.cjs');
|
|
2
|
+
const __aws_sdk_client_sqs = require_chunk.__toESM(require("@aws-sdk/client-sqs"));
|
|
3
|
+
|
|
4
|
+
//#region src/sqs/SQSSubscriber.ts
|
|
5
|
+
/**
|
|
6
|
+
* SQS Subscriber - receives messages from an SQS queue
|
|
7
|
+
*
|
|
8
|
+
* This subscriber can receive:
|
|
9
|
+
* 1. Direct SQS messages
|
|
10
|
+
* 2. SNS messages that were pushed to the queue (SNS → SQS pattern)
|
|
11
|
+
*
|
|
12
|
+
* When receiving SNS messages, it:
|
|
13
|
+
* - Automatically detects and parses the SNS wrapper format
|
|
14
|
+
* - Filters by TopicArn (if expectedTopicArn is provided)
|
|
15
|
+
* - Filters by message type
|
|
16
|
+
* - Processes the actual message payload
|
|
17
|
+
*/
|
|
18
|
+
var SQSSubscriber = class {
|
|
19
|
+
polling = false;
|
|
20
|
+
messageTypes = /* @__PURE__ */ new Set();
|
|
21
|
+
listener;
|
|
22
|
+
options;
|
|
23
|
+
constructor(connection, options = {}) {
|
|
24
|
+
this.connection = connection;
|
|
25
|
+
this.options = {
|
|
26
|
+
waitTimeSeconds: options.waitTimeSeconds ?? 20,
|
|
27
|
+
maxMessages: options.maxMessages ?? 10,
|
|
28
|
+
expectedTopicArn: options.expectedTopicArn ?? ""
|
|
29
|
+
};
|
|
30
|
+
}
|
|
31
|
+
async subscribe(messages, listener) {
|
|
32
|
+
this.messageTypes = new Set(messages);
|
|
33
|
+
this.listener = listener;
|
|
34
|
+
if (!this.connection.isConnected()) await this.connection.connect();
|
|
35
|
+
this.polling = true;
|
|
36
|
+
this.poll();
|
|
37
|
+
}
|
|
38
|
+
stop() {
|
|
39
|
+
this.polling = false;
|
|
40
|
+
}
|
|
41
|
+
async poll() {
|
|
42
|
+
while (this.polling) try {
|
|
43
|
+
const command = new __aws_sdk_client_sqs.ReceiveMessageCommand({
|
|
44
|
+
QueueUrl: this.connection.queueUrl,
|
|
45
|
+
MaxNumberOfMessages: this.options.maxMessages,
|
|
46
|
+
WaitTimeSeconds: this.options.waitTimeSeconds,
|
|
47
|
+
MessageAttributeNames: ["All"]
|
|
48
|
+
});
|
|
49
|
+
const response = await this.connection.sqsClient.send(command);
|
|
50
|
+
if (response.Messages && response.Messages.length > 0) await this.processMessages(response.Messages);
|
|
51
|
+
} catch (error) {
|
|
52
|
+
console.error("Error receiving messages from SQS:", error);
|
|
53
|
+
await this.sleep(1e3);
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
async processMessages(messages) {
|
|
57
|
+
for (const message of messages) try {
|
|
58
|
+
if (!message.Body) continue;
|
|
59
|
+
const parsedMessage = this.parseMessage(message.Body);
|
|
60
|
+
if (!parsedMessage) {
|
|
61
|
+
await this.deleteMessage(message.ReceiptHandle);
|
|
62
|
+
continue;
|
|
63
|
+
}
|
|
64
|
+
const { payload, messageType, topicArn } = parsedMessage;
|
|
65
|
+
if (this.options.expectedTopicArn && topicArn) {
|
|
66
|
+
if (topicArn !== this.options.expectedTopicArn) {
|
|
67
|
+
console.warn(`Received message from unexpected topic: ${topicArn}, expected: ${this.options.expectedTopicArn}`);
|
|
68
|
+
await this.deleteMessage(message.ReceiptHandle);
|
|
69
|
+
continue;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
if (messageType && this.messageTypes.has(messageType)) {
|
|
73
|
+
if (this.listener) await this.listener(payload);
|
|
74
|
+
await this.deleteMessage(message.ReceiptHandle);
|
|
75
|
+
} else await this.deleteMessage(message.ReceiptHandle);
|
|
76
|
+
} catch (error) {
|
|
77
|
+
console.error("Error processing message:", error);
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
/**
|
|
81
|
+
* Parse message body - handles both direct SQS messages and SNS-wrapped messages
|
|
82
|
+
*/
|
|
83
|
+
parseMessage(body) {
|
|
84
|
+
try {
|
|
85
|
+
const parsed = JSON.parse(body);
|
|
86
|
+
if (parsed.Type === "Notification" && parsed.Message) {
|
|
87
|
+
const snsMessage = JSON.parse(parsed.Message);
|
|
88
|
+
const messageType = parsed.MessageAttributes?.type?.Value || snsMessage.type;
|
|
89
|
+
return {
|
|
90
|
+
payload: snsMessage,
|
|
91
|
+
messageType,
|
|
92
|
+
topicArn: parsed.TopicArn
|
|
93
|
+
};
|
|
94
|
+
}
|
|
95
|
+
return {
|
|
96
|
+
payload: parsed,
|
|
97
|
+
messageType: parsed.type
|
|
98
|
+
};
|
|
99
|
+
} catch (error) {
|
|
100
|
+
console.error("Failed to parse message:", error);
|
|
101
|
+
return null;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
async deleteMessage(receiptHandle) {
|
|
105
|
+
try {
|
|
106
|
+
const command = new __aws_sdk_client_sqs.DeleteMessageCommand({
|
|
107
|
+
QueueUrl: this.connection.queueUrl,
|
|
108
|
+
ReceiptHandle: receiptHandle
|
|
109
|
+
});
|
|
110
|
+
await this.connection.sqsClient.send(command);
|
|
111
|
+
} catch (error) {
|
|
112
|
+
console.error("Error deleting message:", error);
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
sleep(ms) {
|
|
116
|
+
return new Promise((resolve) => setTimeout(resolve, ms));
|
|
117
|
+
}
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
//#endregion
|
|
121
|
+
Object.defineProperty(exports, 'SQSSubscriber', {
|
|
122
|
+
enumerable: true,
|
|
123
|
+
get: function () {
|
|
124
|
+
return SQSSubscriber;
|
|
125
|
+
}
|
|
126
|
+
});
|
|
127
|
+
//# sourceMappingURL=SQSSubscriber-DZDNgLE5.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SQSSubscriber-DZDNgLE5.cjs","names":["connection: SQSConnection","options: SQSSubscriberOptions","messages: TMessage['type'][]","listener: (payload: TMessage) => Promise<void>","ReceiveMessageCommand","messages: Message[]","body: string","receiptHandle: string","DeleteMessageCommand","ms: number"],"sources":["../src/sqs/SQSSubscriber.ts"],"sourcesContent":["import {\n DeleteMessageCommand,\n type Message,\n ReceiveMessageCommand,\n} from '@aws-sdk/client-sqs';\nimport type { EventSubscriber, PublishableMessage } from '../types';\nimport type { SQSConnection } from './SQSConnection';\n\nexport interface SQSSubscriberOptions {\n waitTimeSeconds?: number; // SQS long polling (default: 20)\n maxMessages?: number; // Max messages per poll (default: 10)\n expectedTopicArn?: string; // Optional: verify messages are from specific SNS topic\n}\n\n/**\n * SQS Subscriber - receives messages from an SQS queue\n *\n * This subscriber can receive:\n * 1. Direct SQS messages\n * 2. SNS messages that were pushed to the queue (SNS → SQS pattern)\n *\n * When receiving SNS messages, it:\n * - Automatically detects and parses the SNS wrapper format\n * - Filters by TopicArn (if expectedTopicArn is provided)\n * - Filters by message type\n * - Processes the actual message payload\n */\nexport class SQSSubscriber<TMessage extends PublishableMessage<string, any>>\n implements EventSubscriber<TMessage>\n{\n private polling = false;\n private messageTypes: Set<TMessage['type']> = new Set();\n private listener?: (payload: TMessage) => Promise<void>;\n private options: Required<SQSSubscriberOptions>;\n\n constructor(\n private connection: SQSConnection,\n options: SQSSubscriberOptions = {},\n ) {\n this.options = {\n waitTimeSeconds: options.waitTimeSeconds ?? 20,\n maxMessages: options.maxMessages ?? 10,\n expectedTopicArn: options.expectedTopicArn ?? '',\n };\n }\n\n async subscribe(\n messages: TMessage['type'][],\n listener: (payload: TMessage) => Promise<void>,\n ): Promise<void> {\n this.messageTypes = new Set(messages);\n this.listener = listener;\n\n if (!this.connection.isConnected()) {\n await this.connection.connect();\n }\n\n this.polling = true;\n this.poll();\n }\n\n stop(): void {\n this.polling = false;\n }\n\n private async poll(): Promise<void> {\n while (this.polling) {\n try {\n const command = new ReceiveMessageCommand({\n QueueUrl: this.connection.queueUrl,\n MaxNumberOfMessages: this.options.maxMessages,\n WaitTimeSeconds: this.options.waitTimeSeconds,\n MessageAttributeNames: ['All'],\n });\n\n const response = await this.connection.sqsClient.send(command);\n\n if (response.Messages && response.Messages.length > 0) {\n await this.processMessages(response.Messages);\n }\n } catch (error) {\n console.error('Error receiving messages from SQS:', error);\n await this.sleep(1000);\n }\n }\n }\n\n private async processMessages(messages: Message[]): Promise<void> {\n for (const message of messages) {\n try {\n if (!message.Body) continue;\n\n // Try to parse as SNS message first\n const parsedMessage = this.parseMessage(message.Body);\n\n if (!parsedMessage) {\n // Not a valid message format\n await this.deleteMessage(message.ReceiptHandle!);\n continue;\n }\n\n const { payload, messageType, topicArn } = parsedMessage;\n\n // If expectedTopicArn is set, verify the message is from that topic\n if (this.options.expectedTopicArn && topicArn) {\n if (topicArn !== this.options.expectedTopicArn) {\n console.warn(\n `Received message from unexpected topic: ${topicArn}, expected: ${this.options.expectedTopicArn}`,\n );\n await this.deleteMessage(message.ReceiptHandle!);\n continue;\n }\n }\n\n // Check if we're subscribed to this message type\n if (\n messageType &&\n this.messageTypes.has(messageType as TMessage['type'])\n ) {\n // Call listener\n if (this.listener) {\n await this.listener(payload as TMessage);\n }\n\n // Delete message after successful processing\n await this.deleteMessage(message.ReceiptHandle!);\n } else {\n // Delete messages we're not subscribed to\n await this.deleteMessage(message.ReceiptHandle!);\n }\n } catch (error) {\n console.error('Error processing message:', error);\n // Message will become visible again\n }\n }\n }\n\n /**\n * Parse message body - handles both direct SQS messages and SNS-wrapped messages\n */\n private parseMessage(body: string): {\n payload: unknown;\n messageType: string | undefined;\n topicArn?: string;\n } | null {\n try {\n const parsed = JSON.parse(body);\n\n // Check if this is an SNS notification wrapper\n if (parsed.Type === 'Notification' && parsed.Message) {\n // This is an SNS message\n const snsMessage = JSON.parse(parsed.Message);\n const messageType =\n parsed.MessageAttributes?.type?.Value || snsMessage.type;\n\n return {\n payload: snsMessage,\n messageType,\n topicArn: parsed.TopicArn,\n };\n }\n\n // This is a direct SQS message\n return {\n payload: parsed,\n messageType: parsed.type,\n };\n } catch (error) {\n console.error('Failed to parse message:', error);\n return null;\n }\n }\n\n private async deleteMessage(receiptHandle: string): Promise<void> {\n try {\n const command = new DeleteMessageCommand({\n QueueUrl: this.connection.queueUrl,\n ReceiptHandle: receiptHandle,\n });\n await this.connection.sqsClient.send(command);\n } catch (error) {\n console.error('Error deleting message:', error);\n }\n }\n\n private sleep(ms: number): Promise<void> {\n return new Promise((resolve) => setTimeout(resolve, ms));\n }\n}\n"],"mappings":";;;;;;;;;;;;;;;;;AA2BA,IAAa,gBAAb,MAEA;CACE,AAAQ,UAAU;CAClB,AAAQ,+BAAsC,IAAI;CAClD,AAAQ;CACR,AAAQ;CAER,YACUA,YACRC,UAAgC,CAAE,GAClC;EAFQ;AAGR,OAAK,UAAU;GACb,iBAAiB,QAAQ,mBAAmB;GAC5C,aAAa,QAAQ,eAAe;GACpC,kBAAkB,QAAQ,oBAAoB;EAC/C;CACF;CAED,MAAM,UACJC,UACAC,UACe;AACf,OAAK,eAAe,IAAI,IAAI;AAC5B,OAAK,WAAW;AAE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EJ;;;;CAKD,AAAQ,aAAaC,MAIZ;AACP,MAAI;GACF,MAAM,SAAS,KAAK,MAAM,KAAK;AAG/B,OAAI,OAAO,SAAS,kBAAkB,OAAO,SAAS;IAEpD,MAAM,aAAa,KAAK,MAAM,OAAO,QAAQ;IAC7C,MAAM,cACJ,OAAO,mBAAmB,MAAM,SAAS,WAAW;AAEtD,WAAO;KACL,SAAS;KACT;KACA,UAAU,OAAO;IAClB;GACF;AAGD,UAAO;IACL,SAAS;IACT,aAAa,OAAO;GACrB;EACF,SAAQ,OAAO;AACd,WAAQ,MAAM,4BAA4B,MAAM;AAChD,UAAO;EACR;CACF;CAED,MAAc,cAAcC,eAAsC;AAChE,MAAI;GACF,MAAM,UAAU,IAAIC,0CAAqB;IACvC,UAAU,KAAK,WAAW;IAC1B,eAAe;GAChB;AACD,SAAM,KAAK,WAAW,UAAU,KAAK,QAAQ;EAC9C,SAAQ,OAAO;AACd,WAAQ,MAAM,2BAA2B,MAAM;EAChD;CACF;CAED,AAAQ,MAAMC,IAA2B;AACvC,SAAO,IAAI,QAAQ,CAAC,YAAY,WAAW,SAAS,GAAG;CACxD;AACF"}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { EventPublisherType } from "./types-B63qHVOG.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/Subscriber.ts
|
|
4
|
+
var Subscriber = class {
|
|
5
|
+
/**
|
|
6
|
+
* Create a subscriber from a connection string
|
|
7
|
+
* This creates both a connection and a subscriber
|
|
8
|
+
*/
|
|
9
|
+
static async fromConnectionString(connectionStr) {
|
|
10
|
+
const url = new URL(connectionStr);
|
|
11
|
+
switch (url.protocol.replace(":", "")) {
|
|
12
|
+
case EventPublisherType.Basic: {
|
|
13
|
+
const { BasicConnection, BasicSubscriber } = await import("./basic/index.mjs");
|
|
14
|
+
const connection = await BasicConnection.fromConnectionString(connectionStr);
|
|
15
|
+
return new BasicSubscriber(connection);
|
|
16
|
+
}
|
|
17
|
+
case EventPublisherType.RabbitMQ: {
|
|
18
|
+
const { RabbitMQSubscriber } = await import("./rabbitmq/index.mjs");
|
|
19
|
+
return RabbitMQSubscriber.fromConnectionString(connectionStr);
|
|
20
|
+
}
|
|
21
|
+
case EventPublisherType.SNS: {
|
|
22
|
+
const { SNSSubscriber } = await import("./sns/index.mjs");
|
|
23
|
+
return SNSSubscriber.fromConnectionString(connectionStr);
|
|
24
|
+
}
|
|
25
|
+
case EventPublisherType.SQS: {
|
|
26
|
+
const url$1 = new URL(connectionStr);
|
|
27
|
+
const topicArn = url$1.searchParams.get("topicArn");
|
|
28
|
+
if (topicArn) {
|
|
29
|
+
const { SNSSubscriber } = await import("./sns/index.mjs");
|
|
30
|
+
const snsConnectionStr = connectionStr.replace("sqs://", "sns://");
|
|
31
|
+
return SNSSubscriber.fromConnectionString(snsConnectionStr);
|
|
32
|
+
}
|
|
33
|
+
const { SQSSubscriber } = await import("./sqs/index.mjs");
|
|
34
|
+
const { SQSConnection } = await import("./sqs/index.mjs");
|
|
35
|
+
const connection = await SQSConnection.fromConnectionString(connectionStr);
|
|
36
|
+
return new SQSSubscriber(connection);
|
|
37
|
+
}
|
|
38
|
+
default: throw new Error(`Unsupported event subscriber type: ${url.protocol}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a subscriber from an existing connection
|
|
43
|
+
* This allows sharing connections between publishers and subscribers
|
|
44
|
+
*/
|
|
45
|
+
static async fromConnection(connection) {
|
|
46
|
+
switch (connection.type) {
|
|
47
|
+
case EventPublisherType.Basic: {
|
|
48
|
+
const { BasicSubscriber } = await import("./basic/index.mjs");
|
|
49
|
+
const { BasicConnection } = await import("./basic/index.mjs");
|
|
50
|
+
return new BasicSubscriber(connection);
|
|
51
|
+
}
|
|
52
|
+
case EventPublisherType.RabbitMQ: {
|
|
53
|
+
const { RabbitMQSubscriber } = await import("./rabbitmq/index.mjs");
|
|
54
|
+
const { RabbitMQConnection } = await import("./rabbitmq/index.mjs");
|
|
55
|
+
return new RabbitMQSubscriber(connection);
|
|
56
|
+
}
|
|
57
|
+
case EventPublisherType.SNS: {
|
|
58
|
+
const { SNSSubscriber } = await import("./sns/index.mjs");
|
|
59
|
+
const { SNSConnection } = await import("./sns/index.mjs");
|
|
60
|
+
return new SNSSubscriber(connection);
|
|
61
|
+
}
|
|
62
|
+
case EventPublisherType.SQS: {
|
|
63
|
+
const { SQSSubscriber } = await import("./sqs/index.mjs");
|
|
64
|
+
const { SQSConnection } = await import("./sqs/index.mjs");
|
|
65
|
+
return new SQSSubscriber(connection);
|
|
66
|
+
}
|
|
67
|
+
default: throw new Error(`Unsupported connection type: ${connection.type}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
export { Subscriber };
|
|
74
|
+
//# sourceMappingURL=Subscriber-Bd9hb_jp.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Subscriber-Bd9hb_jp.mjs","names":["connectionStr: EventSubscriberConnectionString","url","connection: EventConnection"],"sources":["../src/Subscriber.ts"],"sourcesContent":["import type {\n EventConnection,\n EventSubscriber,\n PublishableMessage,\n} from './types';\nimport { EventPublisherType } from './types';\n\nexport class Subscriber {\n /**\n * Create a subscriber from a connection string\n * This creates both a connection and a subscriber\n */\n static async fromConnectionString<\n TMessage extends PublishableMessage<string, any>,\n >(\n connectionStr: EventSubscriberConnectionString,\n ): Promise<EventSubscriber<TMessage>> {\n const url = new URL(connectionStr);\n switch (url.protocol.replace(':', '')) {\n case EventPublisherType.Basic: {\n const { BasicConnection, BasicSubscriber } = await import('./basic');\n const connection =\n await BasicConnection.fromConnectionString(connectionStr);\n return new BasicSubscriber<TMessage>(connection);\n }\n case EventPublisherType.RabbitMQ: {\n const { RabbitMQSubscriber } = await import('./rabbitmq');\n return RabbitMQSubscriber.fromConnectionString<TMessage>(connectionStr);\n }\n case EventPublisherType.SNS: {\n const { SNSSubscriber } = await import('./sns');\n return SNSSubscriber.fromConnectionString<TMessage>(connectionStr);\n }\n case EventPublisherType.SQS: {\n const url = new URL(connectionStr);\n const topicArn = url.searchParams.get('topicArn');\n\n // If topicArn is present, use managed SNS→SQS subscription\n if (topicArn) {\n const { SNSSubscriber } = await import('./sns');\n // Convert SQS connection string to SNS connection string\n const snsConnectionStr = connectionStr.replace('sqs://', 'sns://');\n return SNSSubscriber.fromConnectionString<TMessage>(snsConnectionStr);\n }\n\n // Direct SQS subscriber\n const { SQSSubscriber } = await import('./sqs');\n const { SQSConnection } = await import('./sqs');\n const connection =\n await SQSConnection.fromConnectionString(connectionStr);\n return new SQSSubscriber<TMessage>(connection);\n }\n // Future implementations for EventBridge, Kafka, etc.\n default:\n throw new Error(`Unsupported event subscriber type: ${url.protocol}`);\n }\n }\n\n /**\n * Create a subscriber from an existing connection\n * This allows sharing connections between publishers and subscribers\n */\n static async fromConnection<TMessage extends PublishableMessage<string, any>>(\n connection: EventConnection,\n ): Promise<EventSubscriber<TMessage>> {\n switch (connection.type) {\n case EventPublisherType.Basic: {\n const { BasicSubscriber } = await import('./basic');\n const { BasicConnection } = await import('./basic');\n return new BasicSubscriber<TMessage>(\n connection as InstanceType<typeof BasicConnection>,\n );\n }\n case EventPublisherType.RabbitMQ: {\n const { RabbitMQSubscriber } = await import('./rabbitmq');\n const { RabbitMQConnection } = await import('./rabbitmq');\n return new RabbitMQSubscriber<TMessage>(\n connection as InstanceType<typeof RabbitMQConnection>,\n );\n }\n case EventPublisherType.SNS: {\n const { SNSSubscriber } = await import('./sns');\n const { SNSConnection } = await import('./sns');\n return new SNSSubscriber<TMessage>(\n connection as InstanceType<typeof SNSConnection>,\n );\n }\n case EventPublisherType.SQS: {\n const { SQSSubscriber } = await import('./sqs');\n const { SQSConnection } = await import('./sqs');\n return new SQSSubscriber<TMessage>(\n connection as InstanceType<typeof SQSConnection>,\n );\n }\n default:\n throw new Error(`Unsupported connection type: ${connection.type}`);\n }\n }\n}\n\nexport type EventSub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H;GACD,KAAK,mBAAmB,UAAU;IAChC,MAAM,EAAE,oBAAoB,GAAG,MAAM,OAAO;IAC5C,MAAM,EAAE,oBAAoB,GAAG,MAAM,OAAO;AAC5C,WAAO,IAAI,mBACT;GAEH;GACD,KAAK,mBAAmB,KAAK;IAC3B,MAAM,EAAE,eAAe,GAAG,MAAM,OAAO;IACvC,MAAM,EAAE,eAAe,GAAG,MAAM,OAAO;AACvC,WAAO,IAAI,cACT;GAEH;GACD,KAAK,mBAAmB,KAAK;IAC3B,MAAM,EAAE,eAAe,GAAG,MAAM,OAAO;IACvC,MAAM,EAAE,eAAe,GAAG,MAAM,OAAO;AACvC,WAAO,IAAI,cACT;GAEH;GACD,QACE,OAAM,IAAI,OAAO,+BAA+B,WAAW,KAAK;EACnE;CACF;AACF"}
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EventConnection, EventPublisherType, EventSubscriber, PublishableMessage } from "./types-D0g-o6wX.mjs";
|
|
2
|
+
|
|
3
|
+
//#region src/Subscriber.d.ts
|
|
4
|
+
declare class Subscriber {
|
|
5
|
+
/**
|
|
6
|
+
* Create a subscriber from a connection string
|
|
7
|
+
* This creates both a connection and a subscriber
|
|
8
|
+
*/
|
|
9
|
+
static fromConnectionString<TMessage extends PublishableMessage<string, any>>(connectionStr: EventSubscriberConnectionString): Promise<EventSubscriber<TMessage>>;
|
|
10
|
+
/**
|
|
11
|
+
* Create a subscriber from an existing connection
|
|
12
|
+
* This allows sharing connections between publishers and subscribers
|
|
13
|
+
*/
|
|
14
|
+
static fromConnection<TMessage extends PublishableMessage<string, any>>(connection: EventConnection): Promise<EventSubscriber<TMessage>>;
|
|
15
|
+
}
|
|
16
|
+
type EventSubscriberConnectionString = `${EventPublisherType}://${string}`;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { EventSubscriberConnectionString, Subscriber };
|
|
19
|
+
//# sourceMappingURL=Subscriber-Cff9EIpv.d.mts.map
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { EventConnection, EventPublisherType, EventSubscriber, PublishableMessage } from "./types-DEGUg5BA.cjs";
|
|
2
|
+
|
|
3
|
+
//#region src/Subscriber.d.ts
|
|
4
|
+
declare class Subscriber {
|
|
5
|
+
/**
|
|
6
|
+
* Create a subscriber from a connection string
|
|
7
|
+
* This creates both a connection and a subscriber
|
|
8
|
+
*/
|
|
9
|
+
static fromConnectionString<TMessage extends PublishableMessage<string, any>>(connectionStr: EventSubscriberConnectionString): Promise<EventSubscriber<TMessage>>;
|
|
10
|
+
/**
|
|
11
|
+
* Create a subscriber from an existing connection
|
|
12
|
+
* This allows sharing connections between publishers and subscribers
|
|
13
|
+
*/
|
|
14
|
+
static fromConnection<TMessage extends PublishableMessage<string, any>>(connection: EventConnection): Promise<EventSubscriber<TMessage>>;
|
|
15
|
+
}
|
|
16
|
+
type EventSubscriberConnectionString = `${EventPublisherType}://${string}`;
|
|
17
|
+
//#endregion
|
|
18
|
+
export { EventSubscriberConnectionString, Subscriber };
|
|
19
|
+
//# sourceMappingURL=Subscriber-CpAwcUzb.d.cts.map
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
const require_types = require('./types-CvSMEO5z.cjs');
|
|
2
|
+
|
|
3
|
+
//#region src/Subscriber.ts
|
|
4
|
+
var Subscriber = class {
|
|
5
|
+
/**
|
|
6
|
+
* Create a subscriber from a connection string
|
|
7
|
+
* This creates both a connection and a subscriber
|
|
8
|
+
*/
|
|
9
|
+
static async fromConnectionString(connectionStr) {
|
|
10
|
+
const url = new URL(connectionStr);
|
|
11
|
+
switch (url.protocol.replace(":", "")) {
|
|
12
|
+
case require_types.EventPublisherType.Basic: {
|
|
13
|
+
const { BasicConnection, BasicSubscriber } = await Promise.resolve().then(() => require("./basic/index.cjs"));
|
|
14
|
+
const connection = await BasicConnection.fromConnectionString(connectionStr);
|
|
15
|
+
return new BasicSubscriber(connection);
|
|
16
|
+
}
|
|
17
|
+
case require_types.EventPublisherType.RabbitMQ: {
|
|
18
|
+
const { RabbitMQSubscriber } = await Promise.resolve().then(() => require("./rabbitmq/index.cjs"));
|
|
19
|
+
return RabbitMQSubscriber.fromConnectionString(connectionStr);
|
|
20
|
+
}
|
|
21
|
+
case require_types.EventPublisherType.SNS: {
|
|
22
|
+
const { SNSSubscriber } = await Promise.resolve().then(() => require("./sns/index.cjs"));
|
|
23
|
+
return SNSSubscriber.fromConnectionString(connectionStr);
|
|
24
|
+
}
|
|
25
|
+
case require_types.EventPublisherType.SQS: {
|
|
26
|
+
const url$1 = new URL(connectionStr);
|
|
27
|
+
const topicArn = url$1.searchParams.get("topicArn");
|
|
28
|
+
if (topicArn) {
|
|
29
|
+
const { SNSSubscriber } = await Promise.resolve().then(() => require("./sns/index.cjs"));
|
|
30
|
+
const snsConnectionStr = connectionStr.replace("sqs://", "sns://");
|
|
31
|
+
return SNSSubscriber.fromConnectionString(snsConnectionStr);
|
|
32
|
+
}
|
|
33
|
+
const { SQSSubscriber } = await Promise.resolve().then(() => require("./sqs/index.cjs"));
|
|
34
|
+
const { SQSConnection } = await Promise.resolve().then(() => require("./sqs/index.cjs"));
|
|
35
|
+
const connection = await SQSConnection.fromConnectionString(connectionStr);
|
|
36
|
+
return new SQSSubscriber(connection);
|
|
37
|
+
}
|
|
38
|
+
default: throw new Error(`Unsupported event subscriber type: ${url.protocol}`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Create a subscriber from an existing connection
|
|
43
|
+
* This allows sharing connections between publishers and subscribers
|
|
44
|
+
*/
|
|
45
|
+
static async fromConnection(connection) {
|
|
46
|
+
switch (connection.type) {
|
|
47
|
+
case require_types.EventPublisherType.Basic: {
|
|
48
|
+
const { BasicSubscriber } = await Promise.resolve().then(() => require("./basic/index.cjs"));
|
|
49
|
+
const { BasicConnection } = await Promise.resolve().then(() => require("./basic/index.cjs"));
|
|
50
|
+
return new BasicSubscriber(connection);
|
|
51
|
+
}
|
|
52
|
+
case require_types.EventPublisherType.RabbitMQ: {
|
|
53
|
+
const { RabbitMQSubscriber } = await Promise.resolve().then(() => require("./rabbitmq/index.cjs"));
|
|
54
|
+
const { RabbitMQConnection } = await Promise.resolve().then(() => require("./rabbitmq/index.cjs"));
|
|
55
|
+
return new RabbitMQSubscriber(connection);
|
|
56
|
+
}
|
|
57
|
+
case require_types.EventPublisherType.SNS: {
|
|
58
|
+
const { SNSSubscriber } = await Promise.resolve().then(() => require("./sns/index.cjs"));
|
|
59
|
+
const { SNSConnection } = await Promise.resolve().then(() => require("./sns/index.cjs"));
|
|
60
|
+
return new SNSSubscriber(connection);
|
|
61
|
+
}
|
|
62
|
+
case require_types.EventPublisherType.SQS: {
|
|
63
|
+
const { SQSSubscriber } = await Promise.resolve().then(() => require("./sqs/index.cjs"));
|
|
64
|
+
const { SQSConnection } = await Promise.resolve().then(() => require("./sqs/index.cjs"));
|
|
65
|
+
return new SQSSubscriber(connection);
|
|
66
|
+
}
|
|
67
|
+
default: throw new Error(`Unsupported connection type: ${connection.type}`);
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
//#endregion
|
|
73
|
+
Object.defineProperty(exports, 'Subscriber', {
|
|
74
|
+
enumerable: true,
|
|
75
|
+
get: function () {
|
|
76
|
+
return Subscriber;
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
//# sourceMappingURL=Subscriber-saVOWuMq.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Subscriber-saVOWuMq.cjs","names":["connectionStr: EventSubscriberConnectionString","EventPublisherType","url","connection: EventConnection"],"sources":["../src/Subscriber.ts"],"sourcesContent":["import type {\n EventConnection,\n EventSubscriber,\n PublishableMessage,\n} from './types';\nimport { EventPublisherType } from './types';\n\nexport class Subscriber {\n /**\n * Create a subscriber from a connection string\n * This creates both a connection and a subscriber\n */\n static async fromConnectionString<\n TMessage extends PublishableMessage<string, any>,\n >(\n connectionStr: EventSubscriberConnectionString,\n ): Promise<EventSubscriber<TMessage>> {\n const url = new URL(connectionStr);\n switch (url.protocol.replace(':', '')) {\n case EventPublisherType.Basic: {\n const { BasicConnection, BasicSubscriber } = await import('./basic');\n const connection =\n await BasicConnection.fromConnectionString(connectionStr);\n return new BasicSubscriber<TMessage>(connection);\n }\n case EventPublisherType.RabbitMQ: {\n const { RabbitMQSubscriber } = await import('./rabbitmq');\n return RabbitMQSubscriber.fromConnectionString<TMessage>(connectionStr);\n }\n case EventPublisherType.SNS: {\n const { SNSSubscriber } = await import('./sns');\n return SNSSubscriber.fromConnectionString<TMessage>(connectionStr);\n }\n case EventPublisherType.SQS: {\n const url = new URL(connectionStr);\n const topicArn = url.searchParams.get('topicArn');\n\n // If topicArn is present, use managed SNS→SQS subscription\n if (topicArn) {\n const { SNSSubscriber } = await import('./sns');\n // Convert SQS connection string to SNS connection string\n const snsConnectionStr = connectionStr.replace('sqs://', 'sns://');\n return SNSSubscriber.fromConnectionString<TMessage>(snsConnectionStr);\n }\n\n // Direct SQS subscriber\n const { SQSSubscriber } = await import('./sqs');\n const { SQSConnection } = await import('./sqs');\n const connection =\n await SQSConnection.fromConnectionString(connectionStr);\n return new SQSSubscriber<TMessage>(connection);\n }\n // Future implementations for EventBridge, Kafka, etc.\n default:\n throw new Error(`Unsupported event subscriber type: ${url.protocol}`);\n }\n }\n\n /**\n * Create a subscriber from an existing connection\n * This allows sharing connections between publishers and subscribers\n */\n static async fromConnection<TMessage extends PublishableMessage<string, any>>(\n connection: EventConnection,\n ): Promise<EventSubscriber<TMessage>> {\n switch (connection.type) {\n case EventPublisherType.Basic: {\n const { BasicSubscriber } = await import('./basic');\n const { BasicConnection } = await import('./basic');\n return new BasicSubscriber<TMessage>(\n connection as InstanceType<typeof BasicConnection>,\n );\n }\n case EventPublisherType.RabbitMQ: {\n const { RabbitMQSubscriber } = await import('./rabbitmq');\n const { RabbitMQConnection } = await import('./rabbitmq');\n return new RabbitMQSubscriber<TMessage>(\n connection as InstanceType<typeof RabbitMQConnection>,\n );\n }\n case EventPublisherType.SNS: {\n const { SNSSubscriber } = await import('./sns');\n const { SNSConnection } = await import('./sns');\n return new SNSSubscriber<TMessage>(\n connection as InstanceType<typeof SNSConnection>,\n );\n }\n case EventPublisherType.SQS: {\n const { SQSSubscriber } = await import('./sqs');\n const { SQSConnection } = await import('./sqs');\n return new SQSSubscriber<TMessage>(\n connection as InstanceType<typeof SQSConnection>,\n );\n }\n default:\n throw new Error(`Unsupported connection type: ${connection.type}`);\n }\n }\n}\n\nexport type EventSubscriberConnectionString =\n `${EventPublisherType}://${string}`;\n"],"mappings":";;;AAOA,IAAa,aAAb,MAAwB;;;;;CAKtB,aAAa,qBAGXA,eACoC;EACpC,MAAM,MAAM,IAAI,IAAI;AACpB,UAAQ,IAAI,SAAS,QAAQ,KAAK,GAAG,EAArC;GACE,KAAKC,iCAAmB,OAAO;IAC7B,MAAM,EAAE,iBAAiB,iBAAiB,GAAG,2CAAM;IACnD,MAAM,aACJ,MAAM,gBAAgB,qBAAqB,cAAc;AAC3D,WAAO,IAAI,gBAA0B;GACtC;GACD,KAAKA,iCAAmB,UAAU;IAChC,MAAM,EAAE,oBAAoB,GAAG,2CAAM;AACrC,WAAO,mBAAmB,qBAA+B,cAAc;GACxE;GACD,KAAKA,iCAAmB,KAAK;IAC3B,MAAM,EAAE,eAAe,GAAG,2CAAM;AAChC,WAAO,cAAc,qBAA+B,cAAc;GACnE;GACD,KAAKA,iCAAmB,KAAK;IAC3B,MAAMC,QAAM,IAAI,IAAI;IACpB,MAAM,WAAW,MAAI,aAAa,IAAI,WAAW;AAGjD,QAAI,UAAU;KACZ,MAAM,EAAE,eAAe,GAAG,2CAAM;KAEhC,MAAM,mBAAmB,cAAc,QAAQ,UAAU,SAAS;AAClE,YAAO,cAAc,qBAA+B,iBAAiB;IACtE;IAGD,MAAM,EAAE,eAAe,GAAG,2CAAM;IAChC,MAAM,EAAE,eAAe,GAAG,2CAAM;IAChC,MAAM,aACJ,MAAM,cAAc,qBAAqB,cAAc;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