@geekmidas/events 9.5.0 → 9.6.0
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/CHANGELOG.md +23 -0
- package/dist/{BasicConnection-hl-Ogz3a.mjs → BasicConnection-CVyEy5R6.mjs} +1 -1
- package/dist/{BasicConnection-hl-Ogz3a.mjs.map → BasicConnection-CVyEy5R6.mjs.map} +1 -1
- package/dist/{BasicConnection-CxfNEvlb.cjs → BasicConnection-DyGmgDSX.cjs} +1 -1
- package/dist/{BasicConnection-CxfNEvlb.cjs.map → BasicConnection-DyGmgDSX.cjs.map} +1 -1
- package/dist/{BasicPublisher-DogbeHAH.mjs → BasicPublisher-7rE-7TTf.mjs} +1 -1
- package/dist/{BasicPublisher-DogbeHAH.mjs.map → BasicPublisher-7rE-7TTf.mjs.map} +1 -1
- package/dist/{BasicPublisher-CXAVKxgq.cjs → BasicPublisher-Bv4TTrtI.cjs} +1 -1
- package/dist/{BasicPublisher-CXAVKxgq.cjs.map → BasicPublisher-Bv4TTrtI.cjs.map} +1 -1
- package/dist/{BasicSubscriber-mVJRMXhZ.cjs → BasicSubscriber-BYemML6q.cjs} +1 -1
- package/dist/{BasicSubscriber-mVJRMXhZ.cjs.map → BasicSubscriber-BYemML6q.cjs.map} +1 -1
- package/dist/{BasicSubscriber-BJSZN22M.mjs → BasicSubscriber-Cm4qZZf4.mjs} +1 -1
- package/dist/{BasicSubscriber-BJSZN22M.mjs.map → BasicSubscriber-Cm4qZZf4.mjs.map} +1 -1
- package/dist/{Publisher-DDee6xau.d.cts → Publisher-BRD9Asio.d.cts} +8 -3
- package/dist/Publisher-BRD9Asio.d.cts.map +1 -0
- package/dist/{Publisher-ChLTrUeP.mjs → Publisher-DpRC2iZf.mjs} +3 -3
- package/dist/Publisher-DpRC2iZf.mjs.map +1 -0
- package/dist/{Publisher-CKloIGh6.cjs → Publisher-QwLaFS2C.cjs} +3 -3
- package/dist/Publisher-QwLaFS2C.cjs.map +1 -0
- package/dist/{Publisher-VHumMkrP.d.mts → Publisher-s3Oj6vUG.d.mts} +8 -3
- package/dist/Publisher-s3Oj6vUG.d.mts.map +1 -0
- package/dist/Publisher.cjs +1 -1
- package/dist/Publisher.d.cts +2 -2
- package/dist/Publisher.d.mts +2 -2
- package/dist/Publisher.mjs +1 -1
- package/dist/{RabbitMQConnection-Cg7mp8u-.mjs → RabbitMQConnection-CniiDhWq.mjs} +1 -1
- package/dist/{RabbitMQConnection-Cg7mp8u-.mjs.map → RabbitMQConnection-CniiDhWq.mjs.map} +1 -1
- package/dist/{RabbitMQConnection-DddqvI3I.cjs → RabbitMQConnection-Dw-HpHyE.cjs} +1 -1
- package/dist/{RabbitMQConnection-DddqvI3I.cjs.map → RabbitMQConnection-Dw-HpHyE.cjs.map} +1 -1
- package/dist/{RabbitMQPublisher-Cxm1zSkD.mjs → RabbitMQPublisher-BZX0edgL.mjs} +1 -1
- package/dist/{RabbitMQPublisher-Cxm1zSkD.mjs.map → RabbitMQPublisher-BZX0edgL.mjs.map} +1 -1
- package/dist/{RabbitMQPublisher-BfTRUnpy.cjs → RabbitMQPublisher-CSCn6gMA.cjs} +1 -1
- package/dist/{RabbitMQPublisher-BfTRUnpy.cjs.map → RabbitMQPublisher-CSCn6gMA.cjs.map} +1 -1
- package/dist/{RabbitMQSubscriber-fP8G9OlK.mjs → RabbitMQSubscriber-CiCsdiOM.mjs} +1 -1
- package/dist/{RabbitMQSubscriber-fP8G9OlK.mjs.map → RabbitMQSubscriber-CiCsdiOM.mjs.map} +1 -1
- package/dist/{RabbitMQSubscriber-CWDdmt1M.cjs → RabbitMQSubscriber-fUmIyY0t.cjs} +1 -1
- package/dist/{RabbitMQSubscriber-CWDdmt1M.cjs.map → RabbitMQSubscriber-fUmIyY0t.cjs.map} +1 -1
- package/dist/{SQSPublisher-DG9o4ME3.mjs → SQSPublisher-Bn1lwlln.mjs} +12 -5
- package/dist/SQSPublisher-Bn1lwlln.mjs.map +1 -0
- package/dist/{SQSPublisher-Dq5353oZ.cjs → SQSPublisher-CT0VFeeh.cjs} +12 -5
- package/dist/SQSPublisher-CT0VFeeh.cjs.map +1 -0
- package/dist/{SQSPublisher-qDE5Fp-N.d.mts → SQSPublisher-D7grG35F.d.mts} +12 -5
- package/dist/SQSPublisher-D7grG35F.d.mts.map +1 -0
- package/dist/{SQSPublisher-kyl5HW3N.d.cts → SQSPublisher-D9MHsTne.d.cts} +12 -5
- package/dist/SQSPublisher-D9MHsTne.d.cts.map +1 -0
- package/dist/basic/BasicConnection.cjs +1 -1
- package/dist/basic/BasicConnection.mjs +1 -1
- package/dist/basic/BasicPublisher.cjs +1 -1
- package/dist/basic/BasicPublisher.mjs +1 -1
- package/dist/basic/BasicSubscriber.cjs +1 -1
- package/dist/basic/BasicSubscriber.mjs +1 -1
- package/dist/basic/index.cjs +3 -3
- package/dist/basic/index.mjs +3 -3
- package/dist/index.cjs +1 -1
- package/dist/index.d.cts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.mjs +1 -1
- package/dist/rabbitmq/RabbitMQConnection.cjs +1 -1
- package/dist/rabbitmq/RabbitMQConnection.mjs +1 -1
- package/dist/rabbitmq/RabbitMQPublisher.cjs +1 -1
- package/dist/rabbitmq/RabbitMQPublisher.mjs +1 -1
- package/dist/rabbitmq/RabbitMQSubscriber.cjs +1 -1
- package/dist/rabbitmq/RabbitMQSubscriber.mjs +1 -1
- package/dist/rabbitmq/index.cjs +3 -3
- package/dist/rabbitmq/index.mjs +3 -3
- package/dist/sqs/SQSPublisher.cjs +1 -1
- package/dist/sqs/SQSPublisher.d.cts +1 -1
- package/dist/sqs/SQSPublisher.d.mts +1 -1
- package/dist/sqs/SQSPublisher.mjs +1 -1
- package/dist/sqs/index.cjs +1 -1
- package/dist/sqs/index.d.cts +1 -1
- package/dist/sqs/index.d.mts +1 -1
- package/dist/sqs/index.mjs +1 -1
- package/package.json +3 -3
- package/src/Publisher.ts +12 -1
- package/src/index.ts +4 -1
- package/src/sqs/SQSPublisher.ts +26 -5
- package/src/sqs/__tests__/SQSPublisher.fifo.spec.ts +63 -0
- package/dist/Publisher-CKloIGh6.cjs.map +0 -1
- package/dist/Publisher-ChLTrUeP.mjs.map +0 -1
- package/dist/Publisher-DDee6xau.d.cts.map +0 -1
- package/dist/Publisher-VHumMkrP.d.mts.map +0 -1
- package/dist/SQSPublisher-DG9o4ME3.mjs.map +0 -1
- package/dist/SQSPublisher-Dq5353oZ.cjs.map +0 -1
- package/dist/SQSPublisher-kyl5HW3N.d.cts.map +0 -1
- package/dist/SQSPublisher-qDE5Fp-N.d.mts.map +0 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# @geekmidas/events
|
|
2
2
|
|
|
3
|
+
## 9.6.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#466](https://github.com/geekmidas/toolbox/pull/466) [`6ca73be`](https://github.com/geekmidas/toolbox/commit/6ca73be57c19d21b7e14048968674a5fea9debd5) Thanks [@geekmidas](https://github.com/geekmidas)! - FIFO queues can be published to, with a message group per message
|
|
8
|
+
|
|
9
|
+
`q(...).fifo({ groupId })` gives each message its FIFO group, and the queue's `publisher` sends it as `MessageGroupId`. Before, the SQS publisher set no group, so publishing to a FIFO queue was refused. Messages in one group keep their order; different groups are processed in parallel.
|
|
10
|
+
|
|
11
|
+
```ts
|
|
12
|
+
export const conversationQueue = q
|
|
13
|
+
.queue('processConversation')
|
|
14
|
+
.message(ConversationEventSchema)
|
|
15
|
+
.fifo({ groupId: (message) => message.conversationId })
|
|
16
|
+
.handle(async ({ records }) => { … });
|
|
17
|
+
```
|
|
18
|
+
|
|
19
|
+
Underneath, `SQSPublisherOptions.groupId` and the new `PublisherOptions` argument to `Publisher.fromConnectionString` carry it; other transports ignore it. The queue must use content-based deduplication, since no deduplication id is sent. `.fifo()` and `.fifo(true)` work as before.
|
|
20
|
+
|
|
21
|
+
### Patch Changes
|
|
22
|
+
|
|
23
|
+
- Updated dependencies []:
|
|
24
|
+
- @geekmidas/schema@9.6.0
|
|
25
|
+
|
|
3
26
|
## 9.5.0
|
|
4
27
|
|
|
5
28
|
### Patch Changes
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BasicConnection-
|
|
1
|
+
{"version":3,"file":"BasicConnection-CVyEy5R6.mjs","names":["_connectionString: string"],"sources":["../src/basic/BasicConnection.ts"],"sourcesContent":["import { EventEmitter } from 'node:events';\nimport type { EventConnection } from '../types';\nimport { EventPublisherType } from '../types';\n\nexport class BasicConnection implements EventConnection {\n\treadonly type = EventPublisherType.Basic;\n\tprivate emitter: EventEmitter;\n\tprivate connected = false;\n\n\tconstructor() {\n\t\tthis.emitter = new EventEmitter();\n\t}\n\n\t/**\n\t * Create a BasicConnection from a connection string\n\t * Format: basic://\n\t */\n\tstatic async fromConnectionString(\n\t\t_connectionString: string,\n\t): Promise<BasicConnection> {\n\t\t// Basic connection doesn't need any configuration\n\t\tconst connection = new BasicConnection();\n\t\tawait connection.connect();\n\t\treturn connection;\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tthis.connected = true;\n\t}\n\n\tasync close(): Promise<void> {\n\t\tthis.emitter.removeAllListeners();\n\t\tthis.connected = false;\n\t}\n\n\tisConnected(): boolean {\n\t\treturn this.connected;\n\t}\n\n\t/**\n\t * Get the underlying EventEmitter\n\t * Used by BasicPublisher and BasicSubscriber\n\t */\n\tget eventEmitter(): EventEmitter {\n\t\treturn this.emitter;\n\t}\n}\n"],"mappings":";;;;AAIA,IAAa,kBAAb,MAAa,gBAA2C;CACvD,AAAS,OAAO,mBAAmB;CACnC,AAAQ;CACR,AAAQ,YAAY;CAEpB,cAAc;AACb,OAAK,UAAU,IAAI;CACnB;;;;;CAMD,aAAa,qBACZA,mBAC2B;EAE3B,MAAM,aAAa,IAAI;AACvB,QAAM,WAAW,SAAS;AAC1B,SAAO;CACP;CAED,MAAM,UAAyB;AAC9B,OAAK,YAAY;CACjB;CAED,MAAM,QAAuB;AAC5B,OAAK,QAAQ,oBAAoB;AACjC,OAAK,YAAY;CACjB;CAED,cAAuB;AACtB,SAAO,KAAK;CACZ;;;;;CAMD,IAAI,eAA6B;AAChC,SAAO,KAAK;CACZ;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BasicConnection-
|
|
1
|
+
{"version":3,"file":"BasicConnection-DyGmgDSX.cjs","names":["EventPublisherType","EventEmitter","_connectionString: string"],"sources":["../src/basic/BasicConnection.ts"],"sourcesContent":["import { EventEmitter } from 'node:events';\nimport type { EventConnection } from '../types';\nimport { EventPublisherType } from '../types';\n\nexport class BasicConnection implements EventConnection {\n\treadonly type = EventPublisherType.Basic;\n\tprivate emitter: EventEmitter;\n\tprivate connected = false;\n\n\tconstructor() {\n\t\tthis.emitter = new EventEmitter();\n\t}\n\n\t/**\n\t * Create a BasicConnection from a connection string\n\t * Format: basic://\n\t */\n\tstatic async fromConnectionString(\n\t\t_connectionString: string,\n\t): Promise<BasicConnection> {\n\t\t// Basic connection doesn't need any configuration\n\t\tconst connection = new BasicConnection();\n\t\tawait connection.connect();\n\t\treturn connection;\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tthis.connected = true;\n\t}\n\n\tasync close(): Promise<void> {\n\t\tthis.emitter.removeAllListeners();\n\t\tthis.connected = false;\n\t}\n\n\tisConnected(): boolean {\n\t\treturn this.connected;\n\t}\n\n\t/**\n\t * Get the underlying EventEmitter\n\t * Used by BasicPublisher and BasicSubscriber\n\t */\n\tget eventEmitter(): EventEmitter {\n\t\treturn this.emitter;\n\t}\n}\n"],"mappings":";;;;;AAIA,IAAa,kBAAb,MAAa,gBAA2C;CACvD,AAAS,OAAOA,iCAAmB;CACnC,AAAQ;CACR,AAAQ,YAAY;CAEpB,cAAc;AACb,OAAK,UAAU,IAAIC;CACnB;;;;;CAMD,aAAa,qBACZC,mBAC2B;EAE3B,MAAM,aAAa,IAAI;AACvB,QAAM,WAAW,SAAS;AAC1B,SAAO;CACP;CAED,MAAM,UAAyB;AAC9B,OAAK,YAAY;CACjB;CAED,MAAM,QAAuB;AAC5B,OAAK,QAAQ,oBAAoB;AACjC,OAAK,YAAY;CACjB;CAED,cAAuB;AACtB,SAAO,KAAK;CACZ;;;;;CAMD,IAAI,eAA6B;AAChC,SAAO,KAAK;CACZ;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BasicPublisher-
|
|
1
|
+
{"version":3,"file":"BasicPublisher-7rE-7TTf.mjs","names":["connection: BasicConnection","messages: TMessage[]"],"sources":["../src/basic/BasicPublisher.ts"],"sourcesContent":["import type { EventPublisher, PublishableMessage } from '../types';\nimport type { BasicConnection } from './BasicConnection';\n\nexport class BasicPublisher<TMessage extends PublishableMessage<string, any>>\n\timplements EventPublisher<TMessage>\n{\n\tconstructor(private connection: BasicConnection) {}\n\n\tasync publish(messages: TMessage[]) {\n\t\tconst emitter = this.connection.eventEmitter;\n\t\tfor (const message of messages) {\n\t\t\temitter.emit(message.type, message);\n\t\t}\n\t}\n}\n"],"mappings":";AAGA,IAAa,iBAAb,MAEA;CACC,YAAoBA,YAA6B;EAA7B;CAA+B;CAEnD,MAAM,QAAQC,UAAsB;EACnC,MAAM,UAAU,KAAK,WAAW;AAChC,OAAK,MAAM,WAAW,SACrB,SAAQ,KAAK,QAAQ,MAAM,QAAQ;CAEpC;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BasicPublisher-
|
|
1
|
+
{"version":3,"file":"BasicPublisher-Bv4TTrtI.cjs","names":["connection: BasicConnection","messages: TMessage[]"],"sources":["../src/basic/BasicPublisher.ts"],"sourcesContent":["import type { EventPublisher, PublishableMessage } from '../types';\nimport type { BasicConnection } from './BasicConnection';\n\nexport class BasicPublisher<TMessage extends PublishableMessage<string, any>>\n\timplements EventPublisher<TMessage>\n{\n\tconstructor(private connection: BasicConnection) {}\n\n\tasync publish(messages: TMessage[]) {\n\t\tconst emitter = this.connection.eventEmitter;\n\t\tfor (const message of messages) {\n\t\t\temitter.emit(message.type, message);\n\t\t}\n\t}\n}\n"],"mappings":";;AAGA,IAAa,iBAAb,MAEA;CACC,YAAoBA,YAA6B;EAA7B;CAA+B;CAEnD,MAAM,QAAQC,UAAsB;EACnC,MAAM,UAAU,KAAK,WAAW;AAChC,OAAK,MAAM,WAAW,SACrB,SAAQ,KAAK,QAAQ,MAAM,QAAQ;CAEpC;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BasicSubscriber-
|
|
1
|
+
{"version":3,"file":"BasicSubscriber-BYemML6q.cjs","names":["connection: BasicConnection","messages: TMessage['type'][]","listener: (payload: TMessage) => Promise<void>","message: TMessage"],"sources":["../src/basic/BasicSubscriber.ts"],"sourcesContent":["import type { EventSubscriber, PublishableMessage } from '../types';\nimport type { BasicConnection } from './BasicConnection';\n\nexport class BasicSubscriber<TMessage extends PublishableMessage<string, any>>\n\timplements EventSubscriber<TMessage>\n{\n\tconstructor(private connection: BasicConnection) {}\n\n\tasync subscribe(\n\t\tmessages: TMessage['type'][],\n\t\tlistener: (payload: TMessage) => Promise<void>,\n\t): Promise<void> {\n\t\tconst emitter = this.connection.eventEmitter;\n\n\t\tfor (const messageType of messages) {\n\t\t\temitter.on(messageType, (message: TMessage) => {\n\t\t\t\tlistener(message).catch((_error) => {});\n\t\t\t});\n\t\t}\n\t}\n}\n"],"mappings":";;AAGA,IAAa,kBAAb,MAEA;CACC,YAAoBA,YAA6B;EAA7B;CAA+B;CAEnD,MAAM,UACLC,UACAC,UACgB;EAChB,MAAM,UAAU,KAAK,WAAW;AAEhC,OAAK,MAAM,eAAe,SACzB,SAAQ,GAAG,aAAa,CAACC,YAAsB;AAC9C,YAAS,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAE,EAAC;EACvC,EAAC;CAEH;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"BasicSubscriber-
|
|
1
|
+
{"version":3,"file":"BasicSubscriber-Cm4qZZf4.mjs","names":["connection: BasicConnection","messages: TMessage['type'][]","listener: (payload: TMessage) => Promise<void>","message: TMessage"],"sources":["../src/basic/BasicSubscriber.ts"],"sourcesContent":["import type { EventSubscriber, PublishableMessage } from '../types';\nimport type { BasicConnection } from './BasicConnection';\n\nexport class BasicSubscriber<TMessage extends PublishableMessage<string, any>>\n\timplements EventSubscriber<TMessage>\n{\n\tconstructor(private connection: BasicConnection) {}\n\n\tasync subscribe(\n\t\tmessages: TMessage['type'][],\n\t\tlistener: (payload: TMessage) => Promise<void>,\n\t): Promise<void> {\n\t\tconst emitter = this.connection.eventEmitter;\n\n\t\tfor (const messageType of messages) {\n\t\t\temitter.on(messageType, (message: TMessage) => {\n\t\t\t\tlistener(message).catch((_error) => {});\n\t\t\t});\n\t\t}\n\t}\n}\n"],"mappings":";AAGA,IAAa,kBAAb,MAEA;CACC,YAAoBA,YAA6B;EAA7B;CAA+B;CAEnD,MAAM,UACLC,UACAC,UACgB;EAChB,MAAM,UAAU,KAAK,WAAW;AAEhC,OAAK,MAAM,eAAe,SACzB,SAAQ,GAAG,aAAa,CAACC,YAAsB;AAC9C,YAAS,QAAQ,CAAC,MAAM,CAAC,WAAW,CAAE,EAAC;EACvC,EAAC;CAEH;AACD"}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { EventConnection, EventPublisher, EventPublisherType, PublishableMessage } from "./types-Dj23od3e.cjs";
|
|
2
2
|
|
|
3
3
|
//#region src/Publisher.d.ts
|
|
4
|
+
/** Options a transport uses when it supports them, ignored by the rest. */
|
|
5
|
+
interface PublisherOptions<TMessage extends PublishableMessage<string, any>> {
|
|
6
|
+
/** The FIFO message group for each message (SQS). */
|
|
7
|
+
groupId?: (message: TMessage) => string;
|
|
8
|
+
}
|
|
4
9
|
declare class Publisher {
|
|
5
10
|
/**
|
|
6
11
|
* Create a publisher from a connection string
|
|
7
12
|
* This creates both a connection and a publisher
|
|
8
13
|
*/
|
|
9
|
-
static fromConnectionString<TMessage extends PublishableMessage<string, any>>(connectionStr: EventPublisherConnectionString): Promise<EventPublisher<TMessage>>;
|
|
14
|
+
static fromConnectionString<TMessage extends PublishableMessage<string, any>>(connectionStr: EventPublisherConnectionString, options?: PublisherOptions<TMessage>): Promise<EventPublisher<TMessage>>;
|
|
10
15
|
/**
|
|
11
16
|
* Create a publisher from an existing connection
|
|
12
17
|
* This allows sharing connections between publishers and subscribers
|
|
@@ -17,5 +22,5 @@ type EventPublisherConnectionString = `${EventPublisherType}://${string}`;
|
|
|
17
22
|
//# sourceMappingURL=Publisher.d.ts.map
|
|
18
23
|
|
|
19
24
|
//#endregion
|
|
20
|
-
export { EventPublisherConnectionString, Publisher };
|
|
21
|
-
//# sourceMappingURL=Publisher-
|
|
25
|
+
export { EventPublisherConnectionString, Publisher, PublisherOptions };
|
|
26
|
+
//# sourceMappingURL=Publisher-BRD9Asio.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Publisher-BRD9Asio.d.cts","names":[],"sources":["../src/Publisher.ts"],"sourcesContent":[],"mappings":";;;;AAQiB,UAAA,gBAAgB,CAAA,iBACf,kBADe,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,CAAA;EAAA;EAAA,OACf,CAAA,EAAA,CAAA,OAAA,EAGG,QAHH,EAAA,GAAA,MAAA;;AAGW,cAGhB,SAAA,CAHgB;EAGhB;;;;EAQkC,OACnB,oBAAA,CAAA,iBAHT,kBAGS,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,CAAA,aAAA,EADX,8BACW,EAAA,OAAA,CAAA,EAAjB,gBAAiB,CAAA,QAAA,CAAA,CAAA,EACxB,OADwB,CAChB,cADgB,CACD,QADC,CAAA,CAAA;EAAQ;;;;EACzB,OAqCmC,cAAA,CAAA,iBAAA,kBAAA,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,CAAA,UAAA,EAChC,eADgC,CAAA,EAE1C,OAF0C,CAElC,cAFkC,CAEnB,QAFmB,CAAA,CAAA;;AAEnB,KA2Cf,8BAAA,GA3Ce,GA4CvB,kBA5CuB,MAAA,MAAA,EAAA"}
|
|
@@ -6,7 +6,7 @@ var Publisher = class {
|
|
|
6
6
|
* Create a publisher from a connection string
|
|
7
7
|
* This creates both a connection and a publisher
|
|
8
8
|
*/
|
|
9
|
-
static async fromConnectionString(connectionStr) {
|
|
9
|
+
static async fromConnectionString(connectionStr, options = {}) {
|
|
10
10
|
const url = new URL(connectionStr);
|
|
11
11
|
switch (url.protocol.replace(":", "")) {
|
|
12
12
|
case EventPublisherType.Basic: {
|
|
@@ -20,7 +20,7 @@ var Publisher = class {
|
|
|
20
20
|
}
|
|
21
21
|
case EventPublisherType.SQS: {
|
|
22
22
|
const { SQSPublisher } = await import("./sqs/index.mjs");
|
|
23
|
-
return SQSPublisher.fromConnectionString(connectionStr);
|
|
23
|
+
return SQSPublisher.fromConnectionString(connectionStr, { groupId: options.groupId });
|
|
24
24
|
}
|
|
25
25
|
case EventPublisherType.SNS: {
|
|
26
26
|
const { SNSPublisher } = await import("./sns/index.mjs");
|
|
@@ -71,4 +71,4 @@ var Publisher = class {
|
|
|
71
71
|
|
|
72
72
|
//#endregion
|
|
73
73
|
export { Publisher };
|
|
74
|
-
//# sourceMappingURL=Publisher-
|
|
74
|
+
//# sourceMappingURL=Publisher-DpRC2iZf.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Publisher-DpRC2iZf.mjs","names":["connectionStr: EventPublisherConnectionString","options: PublisherOptions<TMessage>","connection: EventConnection"],"sources":["../src/Publisher.ts"],"sourcesContent":["import type {\n\tEventConnection,\n\tEventPublisher,\n\tPublishableMessage,\n} from './types';\nimport { EventPublisherType } from './types';\n\n/** Options a transport uses when it supports them, ignored by the rest. */\nexport interface PublisherOptions<\n\tTMessage extends PublishableMessage<string, any>,\n> {\n\t/** The FIFO message group for each message (SQS). */\n\tgroupId?: (message: TMessage) => string;\n}\n\nexport class Publisher {\n\t/**\n\t * Create a publisher from a connection string\n\t * This creates both a connection and a publisher\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(\n\t\tconnectionStr: EventPublisherConnectionString,\n\t\toptions: PublisherOptions<TMessage> = {},\n\t): Promise<EventPublisher<TMessage>> {\n\t\tconst url = new URL(connectionStr);\n\t\tswitch (url.protocol.replace(':', '')) {\n\t\t\tcase EventPublisherType.Basic: {\n\t\t\t\tconst { BasicConnection, BasicPublisher } = await import('./basic');\n\t\t\t\tconst connection =\n\t\t\t\t\tawait BasicConnection.fromConnectionString(connectionStr);\n\t\t\t\treturn new BasicPublisher<TMessage>(connection);\n\t\t\t}\n\t\t\tcase EventPublisherType.RabbitMQ: {\n\t\t\t\tconst { RabbitMQPublisher } = await import('./rabbitmq');\n\t\t\t\treturn RabbitMQPublisher.fromConnectionString<TMessage>(connectionStr);\n\t\t\t}\n\t\t\tcase EventPublisherType.SQS: {\n\t\t\t\tconst { SQSPublisher } = await import('./sqs');\n\t\t\t\treturn SQSPublisher.fromConnectionString<TMessage>(connectionStr, {\n\t\t\t\t\tgroupId: options.groupId,\n\t\t\t\t});\n\t\t\t}\n\t\t\tcase EventPublisherType.SNS: {\n\t\t\t\tconst { SNSPublisher } = await import('./sns');\n\t\t\t\treturn SNSPublisher.fromConnectionString<TMessage>(connectionStr);\n\t\t\t}\n\t\t\tcase EventPublisherType.PgBoss: {\n\t\t\t\tconst { PgBossPublisher } = await import('./pgboss');\n\t\t\t\treturn PgBossPublisher.fromConnectionString<TMessage>(connectionStr);\n\t\t\t}\n\t\t\t// Future implementations for EventBridge, Kafka, etc.\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unsupported event publisher type: ${url.protocol}`);\n\t\t}\n\t}\n\n\t/**\n\t * Create a publisher from an existing connection\n\t * This allows sharing connections between publishers and subscribers\n\t */\n\tstatic async fromConnection<TMessage extends PublishableMessage<string, any>>(\n\t\tconnection: EventConnection,\n\t): Promise<EventPublisher<TMessage>> {\n\t\tswitch (connection.type) {\n\t\t\tcase EventPublisherType.Basic: {\n\t\t\t\tconst { BasicPublisher } = await import('./basic');\n\t\t\t\tconst { BasicConnection } = await import('./basic');\n\t\t\t\treturn new BasicPublisher<TMessage>(\n\t\t\t\t\tconnection as InstanceType<typeof BasicConnection>,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase EventPublisherType.RabbitMQ: {\n\t\t\t\tconst { RabbitMQPublisher } = await import('./rabbitmq');\n\t\t\t\tconst { RabbitMQConnection } = await import('./rabbitmq');\n\t\t\t\treturn new RabbitMQPublisher<TMessage>(\n\t\t\t\t\tconnection as InstanceType<typeof RabbitMQConnection>,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase EventPublisherType.SQS: {\n\t\t\t\tconst { SQSPublisher } = await import('./sqs');\n\t\t\t\tconst { SQSConnection } = await import('./sqs');\n\t\t\t\treturn new SQSPublisher<TMessage>(\n\t\t\t\t\tconnection as InstanceType<typeof SQSConnection>,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase EventPublisherType.SNS: {\n\t\t\t\tconst { SNSPublisher } = await import('./sns');\n\t\t\t\tconst { SNSConnection } = await import('./sns');\n\t\t\t\treturn new SNSPublisher<TMessage>(\n\t\t\t\t\tconnection as InstanceType<typeof SNSConnection>,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase EventPublisherType.PgBoss: {\n\t\t\t\tconst { PgBossPublisher } = await import('./pgboss');\n\t\t\t\tconst { PgBossConnection } = await import('./pgboss');\n\t\t\t\treturn new PgBossPublisher<TMessage>(\n\t\t\t\t\tconnection as InstanceType<typeof PgBossConnection>,\n\t\t\t\t);\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unsupported connection type: ${connection.type}`);\n\t\t}\n\t}\n}\n\nexport type EventPublisherConnectionString =\n\t`${EventPublisherType}://${string}`;\n"],"mappings":";;;AAeA,IAAa,YAAb,MAAuB;;;;;CAKtB,aAAa,qBAGZA,eACAC,UAAsC,CAAE,GACJ;EACpC,MAAM,MAAM,IAAI,IAAI;AACpB,UAAQ,IAAI,SAAS,QAAQ,KAAK,GAAG,EAArC;GACC,KAAK,mBAAmB,OAAO;IAC9B,MAAM,EAAE,iBAAiB,gBAAgB,GAAG,MAAM,OAAO;IACzD,MAAM,aACL,MAAM,gBAAgB,qBAAqB,cAAc;AAC1D,WAAO,IAAI,eAAyB;GACpC;GACD,KAAK,mBAAmB,UAAU;IACjC,MAAM,EAAE,mBAAmB,GAAG,MAAM,OAAO;AAC3C,WAAO,kBAAkB,qBAA+B,cAAc;GACtE;GACD,KAAK,mBAAmB,KAAK;IAC5B,MAAM,EAAE,cAAc,GAAG,MAAM,OAAO;AACtC,WAAO,aAAa,qBAA+B,eAAe,EACjE,SAAS,QAAQ,QACjB,EAAC;GACF;GACD,KAAK,mBAAmB,KAAK;IAC5B,MAAM,EAAE,cAAc,GAAG,MAAM,OAAO;AACtC,WAAO,aAAa,qBAA+B,cAAc;GACjE;GACD,KAAK,mBAAmB,QAAQ;IAC/B,MAAM,EAAE,iBAAiB,GAAG,MAAM,OAAO;AACzC,WAAO,gBAAgB,qBAA+B,cAAc;GACpE;GAED,QACC,OAAM,IAAI,OAAO,oCAAoC,IAAI,SAAS;EACnE;CACD;;;;;CAMD,aAAa,eACZC,YACoC;AACpC,UAAQ,WAAW,MAAnB;GACC,KAAK,mBAAmB,OAAO;IAC9B,MAAM,EAAE,gBAAgB,GAAG,MAAM,OAAO;IACxC,MAAM,EAAE,iBAAiB,GAAG,MAAM,OAAO;AACzC,WAAO,IAAI,eACV;GAED;GACD,KAAK,mBAAmB,UAAU;IACjC,MAAM,EAAE,mBAAmB,GAAG,MAAM,OAAO;IAC3C,MAAM,EAAE,oBAAoB,GAAG,MAAM,OAAO;AAC5C,WAAO,IAAI,kBACV;GAED;GACD,KAAK,mBAAmB,KAAK;IAC5B,MAAM,EAAE,cAAc,GAAG,MAAM,OAAO;IACtC,MAAM,EAAE,eAAe,GAAG,MAAM,OAAO;AACvC,WAAO,IAAI,aACV;GAED;GACD,KAAK,mBAAmB,KAAK;IAC5B,MAAM,EAAE,cAAc,GAAG,MAAM,OAAO;IACtC,MAAM,EAAE,eAAe,GAAG,MAAM,OAAO;AACvC,WAAO,IAAI,aACV;GAED;GACD,KAAK,mBAAmB,QAAQ;IAC/B,MAAM,EAAE,iBAAiB,GAAG,MAAM,OAAO;IACzC,MAAM,EAAE,kBAAkB,GAAG,MAAM,OAAO;AAC1C,WAAO,IAAI,gBACV;GAED;GACD,QACC,OAAM,IAAI,OAAO,+BAA+B,WAAW,KAAK;EACjE;CACD;AACD"}
|
|
@@ -6,7 +6,7 @@ var Publisher = class {
|
|
|
6
6
|
* Create a publisher from a connection string
|
|
7
7
|
* This creates both a connection and a publisher
|
|
8
8
|
*/
|
|
9
|
-
static async fromConnectionString(connectionStr) {
|
|
9
|
+
static async fromConnectionString(connectionStr, options = {}) {
|
|
10
10
|
const url = new URL(connectionStr);
|
|
11
11
|
switch (url.protocol.replace(":", "")) {
|
|
12
12
|
case require_types.EventPublisherType.Basic: {
|
|
@@ -20,7 +20,7 @@ var Publisher = class {
|
|
|
20
20
|
}
|
|
21
21
|
case require_types.EventPublisherType.SQS: {
|
|
22
22
|
const { SQSPublisher } = await Promise.resolve().then(() => require("./sqs/index.cjs"));
|
|
23
|
-
return SQSPublisher.fromConnectionString(connectionStr);
|
|
23
|
+
return SQSPublisher.fromConnectionString(connectionStr, { groupId: options.groupId });
|
|
24
24
|
}
|
|
25
25
|
case require_types.EventPublisherType.SNS: {
|
|
26
26
|
const { SNSPublisher } = await Promise.resolve().then(() => require("./sns/index.cjs"));
|
|
@@ -76,4 +76,4 @@ Object.defineProperty(exports, 'Publisher', {
|
|
|
76
76
|
return Publisher;
|
|
77
77
|
}
|
|
78
78
|
});
|
|
79
|
-
//# sourceMappingURL=Publisher-
|
|
79
|
+
//# sourceMappingURL=Publisher-QwLaFS2C.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Publisher-QwLaFS2C.cjs","names":["connectionStr: EventPublisherConnectionString","options: PublisherOptions<TMessage>","EventPublisherType","connection: EventConnection"],"sources":["../src/Publisher.ts"],"sourcesContent":["import type {\n\tEventConnection,\n\tEventPublisher,\n\tPublishableMessage,\n} from './types';\nimport { EventPublisherType } from './types';\n\n/** Options a transport uses when it supports them, ignored by the rest. */\nexport interface PublisherOptions<\n\tTMessage extends PublishableMessage<string, any>,\n> {\n\t/** The FIFO message group for each message (SQS). */\n\tgroupId?: (message: TMessage) => string;\n}\n\nexport class Publisher {\n\t/**\n\t * Create a publisher from a connection string\n\t * This creates both a connection and a publisher\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(\n\t\tconnectionStr: EventPublisherConnectionString,\n\t\toptions: PublisherOptions<TMessage> = {},\n\t): Promise<EventPublisher<TMessage>> {\n\t\tconst url = new URL(connectionStr);\n\t\tswitch (url.protocol.replace(':', '')) {\n\t\t\tcase EventPublisherType.Basic: {\n\t\t\t\tconst { BasicConnection, BasicPublisher } = await import('./basic');\n\t\t\t\tconst connection =\n\t\t\t\t\tawait BasicConnection.fromConnectionString(connectionStr);\n\t\t\t\treturn new BasicPublisher<TMessage>(connection);\n\t\t\t}\n\t\t\tcase EventPublisherType.RabbitMQ: {\n\t\t\t\tconst { RabbitMQPublisher } = await import('./rabbitmq');\n\t\t\t\treturn RabbitMQPublisher.fromConnectionString<TMessage>(connectionStr);\n\t\t\t}\n\t\t\tcase EventPublisherType.SQS: {\n\t\t\t\tconst { SQSPublisher } = await import('./sqs');\n\t\t\t\treturn SQSPublisher.fromConnectionString<TMessage>(connectionStr, {\n\t\t\t\t\tgroupId: options.groupId,\n\t\t\t\t});\n\t\t\t}\n\t\t\tcase EventPublisherType.SNS: {\n\t\t\t\tconst { SNSPublisher } = await import('./sns');\n\t\t\t\treturn SNSPublisher.fromConnectionString<TMessage>(connectionStr);\n\t\t\t}\n\t\t\tcase EventPublisherType.PgBoss: {\n\t\t\t\tconst { PgBossPublisher } = await import('./pgboss');\n\t\t\t\treturn PgBossPublisher.fromConnectionString<TMessage>(connectionStr);\n\t\t\t}\n\t\t\t// Future implementations for EventBridge, Kafka, etc.\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unsupported event publisher type: ${url.protocol}`);\n\t\t}\n\t}\n\n\t/**\n\t * Create a publisher from an existing connection\n\t * This allows sharing connections between publishers and subscribers\n\t */\n\tstatic async fromConnection<TMessage extends PublishableMessage<string, any>>(\n\t\tconnection: EventConnection,\n\t): Promise<EventPublisher<TMessage>> {\n\t\tswitch (connection.type) {\n\t\t\tcase EventPublisherType.Basic: {\n\t\t\t\tconst { BasicPublisher } = await import('./basic');\n\t\t\t\tconst { BasicConnection } = await import('./basic');\n\t\t\t\treturn new BasicPublisher<TMessage>(\n\t\t\t\t\tconnection as InstanceType<typeof BasicConnection>,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase EventPublisherType.RabbitMQ: {\n\t\t\t\tconst { RabbitMQPublisher } = await import('./rabbitmq');\n\t\t\t\tconst { RabbitMQConnection } = await import('./rabbitmq');\n\t\t\t\treturn new RabbitMQPublisher<TMessage>(\n\t\t\t\t\tconnection as InstanceType<typeof RabbitMQConnection>,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase EventPublisherType.SQS: {\n\t\t\t\tconst { SQSPublisher } = await import('./sqs');\n\t\t\t\tconst { SQSConnection } = await import('./sqs');\n\t\t\t\treturn new SQSPublisher<TMessage>(\n\t\t\t\t\tconnection as InstanceType<typeof SQSConnection>,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase EventPublisherType.SNS: {\n\t\t\t\tconst { SNSPublisher } = await import('./sns');\n\t\t\t\tconst { SNSConnection } = await import('./sns');\n\t\t\t\treturn new SNSPublisher<TMessage>(\n\t\t\t\t\tconnection as InstanceType<typeof SNSConnection>,\n\t\t\t\t);\n\t\t\t}\n\t\t\tcase EventPublisherType.PgBoss: {\n\t\t\t\tconst { PgBossPublisher } = await import('./pgboss');\n\t\t\t\tconst { PgBossConnection } = await import('./pgboss');\n\t\t\t\treturn new PgBossPublisher<TMessage>(\n\t\t\t\t\tconnection as InstanceType<typeof PgBossConnection>,\n\t\t\t\t);\n\t\t\t}\n\t\t\tdefault:\n\t\t\t\tthrow new Error(`Unsupported connection type: ${connection.type}`);\n\t\t}\n\t}\n}\n\nexport type EventPublisherConnectionString =\n\t`${EventPublisherType}://${string}`;\n"],"mappings":";;;AAeA,IAAa,YAAb,MAAuB;;;;;CAKtB,aAAa,qBAGZA,eACAC,UAAsC,CAAE,GACJ;EACpC,MAAM,MAAM,IAAI,IAAI;AACpB,UAAQ,IAAI,SAAS,QAAQ,KAAK,GAAG,EAArC;GACC,KAAKC,iCAAmB,OAAO;IAC9B,MAAM,EAAE,iBAAiB,gBAAgB,GAAG,2CAAM;IAClD,MAAM,aACL,MAAM,gBAAgB,qBAAqB,cAAc;AAC1D,WAAO,IAAI,eAAyB;GACpC;GACD,KAAKA,iCAAmB,UAAU;IACjC,MAAM,EAAE,mBAAmB,GAAG,2CAAM;AACpC,WAAO,kBAAkB,qBAA+B,cAAc;GACtE;GACD,KAAKA,iCAAmB,KAAK;IAC5B,MAAM,EAAE,cAAc,GAAG,2CAAM;AAC/B,WAAO,aAAa,qBAA+B,eAAe,EACjE,SAAS,QAAQ,QACjB,EAAC;GACF;GACD,KAAKA,iCAAmB,KAAK;IAC5B,MAAM,EAAE,cAAc,GAAG,2CAAM;AAC/B,WAAO,aAAa,qBAA+B,cAAc;GACjE;GACD,KAAKA,iCAAmB,QAAQ;IAC/B,MAAM,EAAE,iBAAiB,GAAG,2CAAM;AAClC,WAAO,gBAAgB,qBAA+B,cAAc;GACpE;GAED,QACC,OAAM,IAAI,OAAO,oCAAoC,IAAI,SAAS;EACnE;CACD;;;;;CAMD,aAAa,eACZC,YACoC;AACpC,UAAQ,WAAW,MAAnB;GACC,KAAKD,iCAAmB,OAAO;IAC9B,MAAM,EAAE,gBAAgB,GAAG,2CAAM;IACjC,MAAM,EAAE,iBAAiB,GAAG,2CAAM;AAClC,WAAO,IAAI,eACV;GAED;GACD,KAAKA,iCAAmB,UAAU;IACjC,MAAM,EAAE,mBAAmB,GAAG,2CAAM;IACpC,MAAM,EAAE,oBAAoB,GAAG,2CAAM;AACrC,WAAO,IAAI,kBACV;GAED;GACD,KAAKA,iCAAmB,KAAK;IAC5B,MAAM,EAAE,cAAc,GAAG,2CAAM;IAC/B,MAAM,EAAE,eAAe,GAAG,2CAAM;AAChC,WAAO,IAAI,aACV;GAED;GACD,KAAKA,iCAAmB,KAAK;IAC5B,MAAM,EAAE,cAAc,GAAG,2CAAM;IAC/B,MAAM,EAAE,eAAe,GAAG,2CAAM;AAChC,WAAO,IAAI,aACV;GAED;GACD,KAAKA,iCAAmB,QAAQ;IAC/B,MAAM,EAAE,iBAAiB,GAAG,2CAAM;IAClC,MAAM,EAAE,kBAAkB,GAAG,2CAAM;AACnC,WAAO,IAAI,gBACV;GAED;GACD,QACC,OAAM,IAAI,OAAO,+BAA+B,WAAW,KAAK;EACjE;CACD;AACD"}
|
|
@@ -1,12 +1,17 @@
|
|
|
1
1
|
import { EventConnection, EventPublisher, EventPublisherType, PublishableMessage } from "./types-Dh9Jyinx.mjs";
|
|
2
2
|
|
|
3
3
|
//#region src/Publisher.d.ts
|
|
4
|
+
/** Options a transport uses when it supports them, ignored by the rest. */
|
|
5
|
+
interface PublisherOptions<TMessage extends PublishableMessage<string, any>> {
|
|
6
|
+
/** The FIFO message group for each message (SQS). */
|
|
7
|
+
groupId?: (message: TMessage) => string;
|
|
8
|
+
}
|
|
4
9
|
declare class Publisher {
|
|
5
10
|
/**
|
|
6
11
|
* Create a publisher from a connection string
|
|
7
12
|
* This creates both a connection and a publisher
|
|
8
13
|
*/
|
|
9
|
-
static fromConnectionString<TMessage extends PublishableMessage<string, any>>(connectionStr: EventPublisherConnectionString): Promise<EventPublisher<TMessage>>;
|
|
14
|
+
static fromConnectionString<TMessage extends PublishableMessage<string, any>>(connectionStr: EventPublisherConnectionString, options?: PublisherOptions<TMessage>): Promise<EventPublisher<TMessage>>;
|
|
10
15
|
/**
|
|
11
16
|
* Create a publisher from an existing connection
|
|
12
17
|
* This allows sharing connections between publishers and subscribers
|
|
@@ -17,5 +22,5 @@ type EventPublisherConnectionString = `${EventPublisherType}://${string}`;
|
|
|
17
22
|
//# sourceMappingURL=Publisher.d.ts.map
|
|
18
23
|
|
|
19
24
|
//#endregion
|
|
20
|
-
export { EventPublisherConnectionString, Publisher };
|
|
21
|
-
//# sourceMappingURL=Publisher-
|
|
25
|
+
export { EventPublisherConnectionString, Publisher, PublisherOptions };
|
|
26
|
+
//# sourceMappingURL=Publisher-s3Oj6vUG.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"Publisher-s3Oj6vUG.d.mts","names":[],"sources":["../src/Publisher.ts"],"sourcesContent":[],"mappings":";;;;AAQiB,UAAA,gBAAgB,CAAA,iBACf,kBADe,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,CAAA;EAAA;EAAA,OACf,CAAA,EAAA,CAAA,OAAA,EAGG,QAHH,EAAA,GAAA,MAAA;;AAGW,cAGhB,SAAA,CAHgB;EAGhB;;;;EAQkC,OACnB,oBAAA,CAAA,iBAHT,kBAGS,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,CAAA,aAAA,EADX,8BACW,EAAA,OAAA,CAAA,EAAjB,gBAAiB,CAAA,QAAA,CAAA,CAAA,EACxB,OADwB,CAChB,cADgB,CACD,QADC,CAAA,CAAA;EAAQ;;;;EACzB,OAqCmC,cAAA,CAAA,iBAAA,kBAAA,CAAA,MAAA,EAAA,GAAA,CAAA,CAAA,CAAA,UAAA,EAChC,eADgC,CAAA,EAE1C,OAF0C,CAElC,cAFkC,CAEnB,QAFmB,CAAA,CAAA;;AAEnB,KA2Cf,8BAAA,GA3Ce,GA4CvB,kBA5CuB,MAAA,MAAA,EAAA"}
|
package/dist/Publisher.cjs
CHANGED
package/dist/Publisher.d.cts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "./types-Dj23od3e.cjs";
|
|
2
|
-
import { EventPublisherConnectionString, Publisher } from "./Publisher-
|
|
3
|
-
export { EventPublisherConnectionString, Publisher };
|
|
2
|
+
import { EventPublisherConnectionString, Publisher, PublisherOptions } from "./Publisher-BRD9Asio.cjs";
|
|
3
|
+
export { EventPublisherConnectionString, Publisher, PublisherOptions };
|
package/dist/Publisher.d.mts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import "./types-Dh9Jyinx.mjs";
|
|
2
|
-
import { EventPublisherConnectionString, Publisher } from "./Publisher-
|
|
3
|
-
export { EventPublisherConnectionString, Publisher };
|
|
2
|
+
import { EventPublisherConnectionString, Publisher, PublisherOptions } from "./Publisher-s3Oj6vUG.mjs";
|
|
3
|
+
export { EventPublisherConnectionString, Publisher, PublisherOptions };
|
package/dist/Publisher.mjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RabbitMQConnection-
|
|
1
|
+
{"version":3,"file":"RabbitMQConnection-CniiDhWq.mjs","names":["config: RabbitMQConnectionConfig","connectionString: string","_err: Error"],"sources":["../src/rabbitmq/RabbitMQConnection.ts"],"sourcesContent":["import amqplib from 'amqplib';\nimport type { EventConnection } from '../types';\nimport { EventPublisherType } from '../types';\n\nexport interface RabbitMQConnectionConfig {\n\turl: string;\n\texchange?: string;\n\texchangeType?: 'topic' | 'direct' | 'fanout' | 'headers';\n\texchangeOptions?: amqplib.Options.AssertExchange;\n\ttimeout?: number; // Connection timeout in milliseconds (default: 5000)\n}\n\nexport class RabbitMQConnection implements EventConnection {\n\treadonly type = EventPublisherType.RabbitMQ;\n\tprivate connection?: amqplib.ChannelModel;\n\tprivate channel?: amqplib.Channel;\n\tprivate connecting?: Promise<void>;\n\tprivate config: Required<\n\t\tPick<RabbitMQConnectionConfig, 'exchange' | 'exchangeType' | 'timeout'>\n\t> &\n\t\tRabbitMQConnectionConfig;\n\n\tconstructor(config: RabbitMQConnectionConfig) {\n\t\tthis.config = {\n\t\t\t...config,\n\t\t\texchange: config.exchange || 'geekmidas.events',\n\t\t\texchangeType: config.exchangeType || 'topic',\n\t\t\ttimeout: config.timeout ?? 5000,\n\t\t\texchangeOptions: {\n\t\t\t\tdurable: true,\n\t\t\t\t...config.exchangeOptions,\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Create a RabbitMQConnection from a connection string\n\t * Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&timeout=5000\n\t */\n\tstatic async fromConnectionString(\n\t\tconnectionString: string,\n\t): Promise<RabbitMQConnection> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\t// Extract connection URL without query params\n\t\tconst baseUrl = `amqp://${url.username ? `${url.username}:${url.password}@` : ''}${url.host}${url.pathname}`;\n\n\t\tconst timeoutParam = params.get('timeout');\n\t\tconst config: RabbitMQConnectionConfig = {\n\t\t\turl: baseUrl,\n\t\t\texchange: params.get('exchange') || 'geekmidas.events',\n\t\t\texchangeType: (params.get('type') as any) || 'topic',\n\t\t\ttimeout: timeoutParam ? Number.parseInt(timeoutParam, 10) : undefined,\n\t\t};\n\n\t\tconst connection = new RabbitMQConnection(config);\n\t\tawait connection.connect();\n\t\treturn connection;\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tif (this.channel) return;\n\n\t\t// Prevent multiple simultaneous connection attempts\n\t\tif (this.connecting) {\n\t\t\tawait this.connecting;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.connecting = (async () => {\n\t\t\ttry {\n\t\t\t\tconst connection = await amqplib.connect(this.config.url, {\n\t\t\t\t\ttimeout: this.config.timeout,\n\t\t\t\t});\n\t\t\t\tconst channel = await connection.createChannel();\n\n\t\t\t\t// Assert the exchange exists\n\t\t\t\tawait channel.assertExchange(\n\t\t\t\t\tthis.config.exchange!,\n\t\t\t\t\tthis.config.exchangeType!,\n\t\t\t\t\tthis.config.exchangeOptions,\n\t\t\t\t);\n\n\t\t\t\t// Handle connection errors\n\t\t\t\tconnection.on('error', (_err: Error) => {\n\t\t\t\t\tthis.cleanup();\n\t\t\t\t});\n\n\t\t\t\tconnection.on('close', () => {\n\t\t\t\t\tthis.cleanup();\n\t\t\t\t});\n\n\t\t\t\t// Only set after successful setup\n\t\t\t\tthis.connection = connection;\n\t\t\t\tthis.channel = channel;\n\t\t\t} catch (error) {\n\t\t\t\tthis.cleanup();\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t})();\n\n\t\tawait this.connecting;\n\t\tthis.connecting = undefined;\n\t}\n\n\tasync close(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.channel?.close();\n\t\t\tawait this.connection?.close();\n\t\t} catch (_error) {\n\t\t\t// Ignore errors during close\n\t\t} finally {\n\t\t\tthis.cleanup();\n\t\t}\n\t}\n\n\tisConnected(): boolean {\n\t\treturn !!this.channel;\n\t}\n\n\tprivate cleanup(): void {\n\t\tthis.channel = undefined;\n\t\tthis.connection = undefined;\n\t\tthis.connecting = undefined;\n\t}\n\n\t/**\n\t * Get the underlying channel for publishing/subscribing\n\t */\n\tget amqpChannel(): amqplib.Channel | undefined {\n\t\treturn this.channel;\n\t}\n\n\t/**\n\t * Get the exchange name for this connection\n\t */\n\tget exchangeName(): string {\n\t\treturn this.config.exchange;\n\t}\n\n\t/**\n\t * Get the exchange type for this connection\n\t */\n\tget exchangeType(): string {\n\t\treturn this.config.exchangeType;\n\t}\n}\n"],"mappings":";;;;AAYA,IAAa,qBAAb,MAAa,mBAA8C;CAC1D,AAAS,OAAO,mBAAmB;CACnC,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAKR,YAAYA,QAAkC;AAC7C,OAAK,SAAS;GACb,GAAG;GACH,UAAU,OAAO,YAAY;GAC7B,cAAc,OAAO,gBAAgB;GACrC,SAAS,OAAO,WAAW;GAC3B,iBAAiB;IAChB,SAAS;IACT,GAAG,OAAO;GACV;EACD;CACD;;;;;CAMD,aAAa,qBACZC,kBAC8B;EAC9B,MAAM,MAAM,IAAI,IAAI;EACpB,MAAM,SAAS,IAAI;EAGnB,MAAM,WAAW,SAAS,IAAI,YAAY,EAAE,IAAI,SAAS,GAAG,IAAI,SAAS,KAAK,GAAG,EAAE,IAAI,KAAK,EAAE,IAAI,SAAS;EAE3G,MAAM,eAAe,OAAO,IAAI,UAAU;EAC1C,MAAMD,SAAmC;GACxC,KAAK;GACL,UAAU,OAAO,IAAI,WAAW,IAAI;GACpC,cAAe,OAAO,IAAI,OAAO,IAAY;GAC7C,SAAS,eAAe,OAAO,SAAS,cAAc,GAAG;EACzD;EAED,MAAM,aAAa,IAAI,mBAAmB;AAC1C,QAAM,WAAW,SAAS;AAC1B,SAAO;CACP;CAED,MAAM,UAAyB;AAC9B,MAAI,KAAK,QAAS;AAGlB,MAAI,KAAK,YAAY;AACpB,SAAM,KAAK;AACX;EACA;AAED,OAAK,aAAa,CAAC,YAAY;AAC9B,OAAI;IACH,MAAM,aAAa,MAAM,QAAQ,QAAQ,KAAK,OAAO,KAAK,EACzD,SAAS,KAAK,OAAO,QACrB,EAAC;IACF,MAAM,UAAU,MAAM,WAAW,eAAe;AAGhD,UAAM,QAAQ,eACb,KAAK,OAAO,UACZ,KAAK,OAAO,cACZ,KAAK,OAAO,gBACZ;AAGD,eAAW,GAAG,SAAS,CAACE,SAAgB;AACvC,UAAK,SAAS;IACd,EAAC;AAEF,eAAW,GAAG,SAAS,MAAM;AAC5B,UAAK,SAAS;IACd,EAAC;AAGF,SAAK,aAAa;AAClB,SAAK,UAAU;GACf,SAAQ,OAAO;AACf,SAAK,SAAS;AACd,UAAM;GACN;EACD,IAAG;AAEJ,QAAM,KAAK;AACX,OAAK;CACL;CAED,MAAM,QAAuB;AAC5B,MAAI;AACH,SAAM,KAAK,SAAS,OAAO;AAC3B,SAAM,KAAK,YAAY,OAAO;EAC9B,SAAQ,QAAQ,CAEhB,UAAS;AACT,QAAK,SAAS;EACd;CACD;CAED,cAAuB;AACtB,WAAS,KAAK;CACd;CAED,AAAQ,UAAgB;AACvB,OAAK;AACL,OAAK;AACL,OAAK;CACL;;;;CAKD,IAAI,cAA2C;AAC9C,SAAO,KAAK;CACZ;;;;CAKD,IAAI,eAAuB;AAC1B,SAAO,KAAK,OAAO;CACnB;;;;CAKD,IAAI,eAAuB;AAC1B,SAAO,KAAK,OAAO;CACnB;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RabbitMQConnection-
|
|
1
|
+
{"version":3,"file":"RabbitMQConnection-Dw-HpHyE.cjs","names":["EventPublisherType","config: RabbitMQConnectionConfig","connectionString: string","_err: Error"],"sources":["../src/rabbitmq/RabbitMQConnection.ts"],"sourcesContent":["import amqplib from 'amqplib';\nimport type { EventConnection } from '../types';\nimport { EventPublisherType } from '../types';\n\nexport interface RabbitMQConnectionConfig {\n\turl: string;\n\texchange?: string;\n\texchangeType?: 'topic' | 'direct' | 'fanout' | 'headers';\n\texchangeOptions?: amqplib.Options.AssertExchange;\n\ttimeout?: number; // Connection timeout in milliseconds (default: 5000)\n}\n\nexport class RabbitMQConnection implements EventConnection {\n\treadonly type = EventPublisherType.RabbitMQ;\n\tprivate connection?: amqplib.ChannelModel;\n\tprivate channel?: amqplib.Channel;\n\tprivate connecting?: Promise<void>;\n\tprivate config: Required<\n\t\tPick<RabbitMQConnectionConfig, 'exchange' | 'exchangeType' | 'timeout'>\n\t> &\n\t\tRabbitMQConnectionConfig;\n\n\tconstructor(config: RabbitMQConnectionConfig) {\n\t\tthis.config = {\n\t\t\t...config,\n\t\t\texchange: config.exchange || 'geekmidas.events',\n\t\t\texchangeType: config.exchangeType || 'topic',\n\t\t\ttimeout: config.timeout ?? 5000,\n\t\t\texchangeOptions: {\n\t\t\t\tdurable: true,\n\t\t\t\t...config.exchangeOptions,\n\t\t\t},\n\t\t};\n\t}\n\n\t/**\n\t * Create a RabbitMQConnection from a connection string\n\t * Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&timeout=5000\n\t */\n\tstatic async fromConnectionString(\n\t\tconnectionString: string,\n\t): Promise<RabbitMQConnection> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\t// Extract connection URL without query params\n\t\tconst baseUrl = `amqp://${url.username ? `${url.username}:${url.password}@` : ''}${url.host}${url.pathname}`;\n\n\t\tconst timeoutParam = params.get('timeout');\n\t\tconst config: RabbitMQConnectionConfig = {\n\t\t\turl: baseUrl,\n\t\t\texchange: params.get('exchange') || 'geekmidas.events',\n\t\t\texchangeType: (params.get('type') as any) || 'topic',\n\t\t\ttimeout: timeoutParam ? Number.parseInt(timeoutParam, 10) : undefined,\n\t\t};\n\n\t\tconst connection = new RabbitMQConnection(config);\n\t\tawait connection.connect();\n\t\treturn connection;\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tif (this.channel) return;\n\n\t\t// Prevent multiple simultaneous connection attempts\n\t\tif (this.connecting) {\n\t\t\tawait this.connecting;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.connecting = (async () => {\n\t\t\ttry {\n\t\t\t\tconst connection = await amqplib.connect(this.config.url, {\n\t\t\t\t\ttimeout: this.config.timeout,\n\t\t\t\t});\n\t\t\t\tconst channel = await connection.createChannel();\n\n\t\t\t\t// Assert the exchange exists\n\t\t\t\tawait channel.assertExchange(\n\t\t\t\t\tthis.config.exchange!,\n\t\t\t\t\tthis.config.exchangeType!,\n\t\t\t\t\tthis.config.exchangeOptions,\n\t\t\t\t);\n\n\t\t\t\t// Handle connection errors\n\t\t\t\tconnection.on('error', (_err: Error) => {\n\t\t\t\t\tthis.cleanup();\n\t\t\t\t});\n\n\t\t\t\tconnection.on('close', () => {\n\t\t\t\t\tthis.cleanup();\n\t\t\t\t});\n\n\t\t\t\t// Only set after successful setup\n\t\t\t\tthis.connection = connection;\n\t\t\t\tthis.channel = channel;\n\t\t\t} catch (error) {\n\t\t\t\tthis.cleanup();\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t})();\n\n\t\tawait this.connecting;\n\t\tthis.connecting = undefined;\n\t}\n\n\tasync close(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.channel?.close();\n\t\t\tawait this.connection?.close();\n\t\t} catch (_error) {\n\t\t\t// Ignore errors during close\n\t\t} finally {\n\t\t\tthis.cleanup();\n\t\t}\n\t}\n\n\tisConnected(): boolean {\n\t\treturn !!this.channel;\n\t}\n\n\tprivate cleanup(): void {\n\t\tthis.channel = undefined;\n\t\tthis.connection = undefined;\n\t\tthis.connecting = undefined;\n\t}\n\n\t/**\n\t * Get the underlying channel for publishing/subscribing\n\t */\n\tget amqpChannel(): amqplib.Channel | undefined {\n\t\treturn this.channel;\n\t}\n\n\t/**\n\t * Get the exchange name for this connection\n\t */\n\tget exchangeName(): string {\n\t\treturn this.config.exchange;\n\t}\n\n\t/**\n\t * Get the exchange type for this connection\n\t */\n\tget exchangeType(): string {\n\t\treturn this.config.exchangeType;\n\t}\n}\n"],"mappings":";;;;;AAYA,IAAa,qBAAb,MAAa,mBAA8C;CAC1D,AAAS,OAAOA,iCAAmB;CACnC,AAAQ;CACR,AAAQ;CACR,AAAQ;CACR,AAAQ;CAKR,YAAYC,QAAkC;AAC7C,OAAK,SAAS;GACb,GAAG;GACH,UAAU,OAAO,YAAY;GAC7B,cAAc,OAAO,gBAAgB;GACrC,SAAS,OAAO,WAAW;GAC3B,iBAAiB;IAChB,SAAS;IACT,GAAG,OAAO;GACV;EACD;CACD;;;;;CAMD,aAAa,qBACZC,kBAC8B;EAC9B,MAAM,MAAM,IAAI,IAAI;EACpB,MAAM,SAAS,IAAI;EAGnB,MAAM,WAAW,SAAS,IAAI,YAAY,EAAE,IAAI,SAAS,GAAG,IAAI,SAAS,KAAK,GAAG,EAAE,IAAI,KAAK,EAAE,IAAI,SAAS;EAE3G,MAAM,eAAe,OAAO,IAAI,UAAU;EAC1C,MAAMD,SAAmC;GACxC,KAAK;GACL,UAAU,OAAO,IAAI,WAAW,IAAI;GACpC,cAAe,OAAO,IAAI,OAAO,IAAY;GAC7C,SAAS,eAAe,OAAO,SAAS,cAAc,GAAG;EACzD;EAED,MAAM,aAAa,IAAI,mBAAmB;AAC1C,QAAM,WAAW,SAAS;AAC1B,SAAO;CACP;CAED,MAAM,UAAyB;AAC9B,MAAI,KAAK,QAAS;AAGlB,MAAI,KAAK,YAAY;AACpB,SAAM,KAAK;AACX;EACA;AAED,OAAK,aAAa,CAAC,YAAY;AAC9B,OAAI;IACH,MAAM,aAAa,MAAM,gBAAQ,QAAQ,KAAK,OAAO,KAAK,EACzD,SAAS,KAAK,OAAO,QACrB,EAAC;IACF,MAAM,UAAU,MAAM,WAAW,eAAe;AAGhD,UAAM,QAAQ,eACb,KAAK,OAAO,UACZ,KAAK,OAAO,cACZ,KAAK,OAAO,gBACZ;AAGD,eAAW,GAAG,SAAS,CAACE,SAAgB;AACvC,UAAK,SAAS;IACd,EAAC;AAEF,eAAW,GAAG,SAAS,MAAM;AAC5B,UAAK,SAAS;IACd,EAAC;AAGF,SAAK,aAAa;AAClB,SAAK,UAAU;GACf,SAAQ,OAAO;AACf,SAAK,SAAS;AACd,UAAM;GACN;EACD,IAAG;AAEJ,QAAM,KAAK;AACX,OAAK;CACL;CAED,MAAM,QAAuB;AAC5B,MAAI;AACH,SAAM,KAAK,SAAS,OAAO;AAC3B,SAAM,KAAK,YAAY,OAAO;EAC9B,SAAQ,QAAQ,CAEhB,UAAS;AACT,QAAK,SAAS;EACd;CACD;CAED,cAAuB;AACtB,WAAS,KAAK;CACd;CAED,AAAQ,UAAgB;AACvB,OAAK;AACL,OAAK;AACL,OAAK;CACL;;;;CAKD,IAAI,cAA2C;AAC9C,SAAO,KAAK;CACZ;;;;CAKD,IAAI,eAAuB;AAC1B,SAAO,KAAK,OAAO;CACnB;;;;CAKD,IAAI,eAAuB;AAC1B,SAAO,KAAK,OAAO;CACnB;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RabbitMQPublisher-
|
|
1
|
+
{"version":3,"file":"RabbitMQPublisher-BZX0edgL.mjs","names":["connection: RabbitMQConnection","options: RabbitMQPublisherOptions","connectionString: string","messages: TMessage[]"],"sources":["../src/rabbitmq/RabbitMQPublisher.ts"],"sourcesContent":["import type amqplib from 'amqplib';\nimport type { EventPublisher, PublishableMessage } from '../types';\nimport type { RabbitMQConnection } from './RabbitMQConnection';\n\nexport interface RabbitMQPublisherOptions {\n\tpublishOptions?: amqplib.Options.Publish;\n}\n\nexport class RabbitMQPublisher<TMessage extends PublishableMessage<string, any>>\n\timplements EventPublisher<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: RabbitMQConnection,\n\t\tprivate options: RabbitMQPublisherOptions = {},\n\t) {}\n\n\t/**\n\t * Create a RabbitMQPublisher from a connection string\n\t * Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&timeout=5000\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<RabbitMQPublisher<TMessage>> {\n\t\tconst { RabbitMQConnection } = await import('./RabbitMQConnection');\n\t\tconst connection =\n\t\t\tawait RabbitMQConnection.fromConnectionString(connectionString);\n\t\treturn new RabbitMQPublisher<TMessage>(connection);\n\t}\n\n\tasync publish(messages: TMessage[]): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst channel = this.connection.amqpChannel;\n\t\tif (!channel) {\n\t\t\tthrow new Error('Channel not initialized');\n\t\t}\n\n\t\tconst exchange = this.connection.exchangeName;\n\n\t\tfor (const message of messages) {\n\t\t\tconst content = Buffer.from(JSON.stringify(message.payload));\n\n\t\t\t// Use message type as routing key for topic exchanges\n\t\t\tconst routingKey = message.type;\n\n\t\t\tconst published = channel.publish(exchange, routingKey, content, {\n\t\t\t\tcontentType: 'application/json',\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t\ttype: message.type,\n\t\t\t\tpersistent: true,\n\t\t\t\t...this.options.publishOptions,\n\t\t\t});\n\n\t\t\t// Handle backpressure\n\t\t\tif (!published) {\n\t\t\t\tawait new Promise((resolve) => channel.once('drain', resolve));\n\t\t\t}\n\t\t}\n\t}\n\n\tasync close(): Promise<void> {\n\t\t// Publisher doesn't own the connection\n\t\t// Connection should be closed by whoever created it\n\t}\n}\n"],"mappings":";AAQA,IAAa,oBAAb,MAAa,kBAEb;CACC,YACSA,YACAC,UAAoC,CAAE,GAC7C;EAFO;EACA;CACL;;;;;CAMJ,aAAa,qBAEXC,kBAAgE;EACjE,MAAM,EAAE,oBAAoB,GAAG,MAAM,OAAO;EAC5C,MAAM,aACL,MAAM,mBAAmB,qBAAqB,iBAAiB;AAChE,SAAO,IAAI,kBAA4B;CACvC;CAED,MAAM,QAAQC,UAAqC;AAClD,OAAK,KAAK,WAAW,aAAa,CACjC,OAAM,KAAK,WAAW,SAAS;EAGhC,MAAM,UAAU,KAAK,WAAW;AAChC,OAAK,QACJ,OAAM,IAAI,MAAM;EAGjB,MAAM,WAAW,KAAK,WAAW;AAEjC,OAAK,MAAM,WAAW,UAAU;GAC/B,MAAM,UAAU,OAAO,KAAK,KAAK,UAAU,QAAQ,QAAQ,CAAC;GAG5D,MAAM,aAAa,QAAQ;GAE3B,MAAM,YAAY,QAAQ,QAAQ,UAAU,YAAY,SAAS;IAChE,aAAa;IACb,WAAW,KAAK,KAAK;IACrB,MAAM,QAAQ;IACd,YAAY;IACZ,GAAG,KAAK,QAAQ;GAChB,EAAC;AAGF,QAAK,UACJ,OAAM,IAAI,QAAQ,CAAC,YAAY,QAAQ,KAAK,SAAS,QAAQ;EAE9D;CACD;CAED,MAAM,QAAuB,CAG5B;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RabbitMQPublisher-
|
|
1
|
+
{"version":3,"file":"RabbitMQPublisher-CSCn6gMA.cjs","names":["connection: RabbitMQConnection","options: RabbitMQPublisherOptions","connectionString: string","messages: TMessage[]"],"sources":["../src/rabbitmq/RabbitMQPublisher.ts"],"sourcesContent":["import type amqplib from 'amqplib';\nimport type { EventPublisher, PublishableMessage } from '../types';\nimport type { RabbitMQConnection } from './RabbitMQConnection';\n\nexport interface RabbitMQPublisherOptions {\n\tpublishOptions?: amqplib.Options.Publish;\n}\n\nexport class RabbitMQPublisher<TMessage extends PublishableMessage<string, any>>\n\timplements EventPublisher<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: RabbitMQConnection,\n\t\tprivate options: RabbitMQPublisherOptions = {},\n\t) {}\n\n\t/**\n\t * Create a RabbitMQPublisher from a connection string\n\t * Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&timeout=5000\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<RabbitMQPublisher<TMessage>> {\n\t\tconst { RabbitMQConnection } = await import('./RabbitMQConnection');\n\t\tconst connection =\n\t\t\tawait RabbitMQConnection.fromConnectionString(connectionString);\n\t\treturn new RabbitMQPublisher<TMessage>(connection);\n\t}\n\n\tasync publish(messages: TMessage[]): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst channel = this.connection.amqpChannel;\n\t\tif (!channel) {\n\t\t\tthrow new Error('Channel not initialized');\n\t\t}\n\n\t\tconst exchange = this.connection.exchangeName;\n\n\t\tfor (const message of messages) {\n\t\t\tconst content = Buffer.from(JSON.stringify(message.payload));\n\n\t\t\t// Use message type as routing key for topic exchanges\n\t\t\tconst routingKey = message.type;\n\n\t\t\tconst published = channel.publish(exchange, routingKey, content, {\n\t\t\t\tcontentType: 'application/json',\n\t\t\t\ttimestamp: Date.now(),\n\t\t\t\ttype: message.type,\n\t\t\t\tpersistent: true,\n\t\t\t\t...this.options.publishOptions,\n\t\t\t});\n\n\t\t\t// Handle backpressure\n\t\t\tif (!published) {\n\t\t\t\tawait new Promise((resolve) => channel.once('drain', resolve));\n\t\t\t}\n\t\t}\n\t}\n\n\tasync close(): Promise<void> {\n\t\t// Publisher doesn't own the connection\n\t\t// Connection should be closed by whoever created it\n\t}\n}\n"],"mappings":";;AAQA,IAAa,oBAAb,MAAa,kBAEb;CACC,YACSA,YACAC,UAAoC,CAAE,GAC7C;EAFO;EACA;CACL;;;;;CAMJ,aAAa,qBAEXC,kBAAgE;EACjE,MAAM,EAAE,oBAAoB,GAAG,2CAAM;EACrC,MAAM,aACL,MAAM,mBAAmB,qBAAqB,iBAAiB;AAChE,SAAO,IAAI,kBAA4B;CACvC;CAED,MAAM,QAAQC,UAAqC;AAClD,OAAK,KAAK,WAAW,aAAa,CACjC,OAAM,KAAK,WAAW,SAAS;EAGhC,MAAM,UAAU,KAAK,WAAW;AAChC,OAAK,QACJ,OAAM,IAAI,MAAM;EAGjB,MAAM,WAAW,KAAK,WAAW;AAEjC,OAAK,MAAM,WAAW,UAAU;GAC/B,MAAM,UAAU,OAAO,KAAK,KAAK,UAAU,QAAQ,QAAQ,CAAC;GAG5D,MAAM,aAAa,QAAQ;GAE3B,MAAM,YAAY,QAAQ,QAAQ,UAAU,YAAY,SAAS;IAChE,aAAa;IACb,WAAW,KAAK,KAAK;IACrB,MAAM,QAAQ;IACd,YAAY;IACZ,GAAG,KAAK,QAAQ;GAChB,EAAC;AAGF,QAAK,UACJ,OAAM,IAAI,QAAQ,CAAC,YAAY,QAAQ,KAAK,SAAS,QAAQ;EAE9D;CACD;CAED,MAAM,QAAuB,CAG5B;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RabbitMQSubscriber-
|
|
1
|
+
{"version":3,"file":"RabbitMQSubscriber-CiCsdiOM.mjs","names":["connection: RabbitMQConnection","options: RabbitMQSubscriberOptions","connectionString: string","messages: TMessage['type'][]","listener: (payload: TMessage) => Promise<void>","queueOptions: amqplib.Options.AssertQueue","fullMessage: TMessage"],"sources":["../src/rabbitmq/RabbitMQSubscriber.ts"],"sourcesContent":["import type amqplib from 'amqplib';\nimport type { EventSubscriber, PublishableMessage } from '../types';\nimport type { RabbitMQConnection } from './RabbitMQConnection';\n\nexport interface RabbitMQSubscriberOptions {\n\tqueueName?: string; // If not provided, a unique queue will be generated\n\tqueueOptions?: amqplib.Options.AssertQueue;\n\tconsumeOptions?: amqplib.Options.Consume;\n\tprefetch?: number; // Number of messages to prefetch (default: 1)\n}\n\nexport class RabbitMQSubscriber<\n\tTMessage extends PublishableMessage<string, any>,\n> implements EventSubscriber<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: RabbitMQConnection,\n\t\tprivate options: RabbitMQSubscriberOptions = {},\n\t) {}\n\n\t/**\n\t * Create a RabbitMQSubscriber from a connection string\n\t * Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&queueName=myqueue&prefetch=10\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<RabbitMQSubscriber<TMessage>> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst { RabbitMQConnection } = await import('./RabbitMQConnection');\n\t\tconst connection =\n\t\t\tawait RabbitMQConnection.fromConnectionString(connectionString);\n\n\t\tconst options: RabbitMQSubscriberOptions = {\n\t\t\tqueueName: params.get('queueName') || undefined,\n\t\t\tprefetch: params.get('prefetch')\n\t\t\t\t? Number.parseInt(params.get('prefetch')!, 10)\n\t\t\t\t: undefined,\n\t\t};\n\n\t\treturn new RabbitMQSubscriber<TMessage>(connection, options);\n\t}\n\n\tasync subscribe(\n\t\tmessages: TMessage['type'][],\n\t\tlistener: (payload: TMessage) => Promise<void>,\n\t): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst channel = this.connection.amqpChannel;\n\t\tif (!channel) {\n\t\t\tthrow new Error('Channel not initialized');\n\t\t}\n\n\t\tconst exchange = this.connection.exchangeName;\n\n\t\t// Set prefetch if specified\n\t\tif (this.options.prefetch) {\n\t\t\tawait channel.prefetch(this.options.prefetch);\n\t\t}\n\n\t\t// Assert queue\n\t\tconst queueName = this.options.queueName || '';\n\t\tconst queueOptions: amqplib.Options.AssertQueue = {\n\t\t\tdurable: true,\n\t\t\t...this.options.queueOptions,\n\t\t};\n\n\t\tconst { queue } = await channel.assertQueue(queueName, queueOptions);\n\n\t\t// Bind queue to exchange for each message type\n\t\tfor (const messageType of messages) {\n\t\t\tawait channel.bindQueue(queue, exchange, messageType);\n\t\t}\n\n\t\t// Consume messages\n\t\tawait channel.consume(\n\t\t\tqueue,\n\t\t\tasync (msg) => {\n\t\t\t\tif (!msg) return;\n\n\t\t\t\ttry {\n\t\t\t\t\t// Parse message payload\n\t\t\t\t\tconst content = msg.content.toString();\n\t\t\t\t\tconst payload = JSON.parse(content);\n\n\t\t\t\t\t// Get message type from properties\n\t\t\t\t\tconst messageType = msg.properties.type;\n\n\t\t\t\t\t// Reconstruct full message\n\t\t\t\t\tconst fullMessage: TMessage = {\n\t\t\t\t\t\ttype: messageType,\n\t\t\t\t\t\tpayload,\n\t\t\t\t\t} as TMessage;\n\n\t\t\t\t\t// Call listener\n\t\t\t\t\tawait listener(fullMessage);\n\n\t\t\t\t\t// Ack message\n\t\t\t\t\tchannel.ack(msg);\n\t\t\t\t} catch (_error) {\n\t\t\t\t\tchannel.nack(msg, false, true);\n\t\t\t\t}\n\t\t\t},\n\t\t\tthis.options.consumeOptions,\n\t\t);\n\t}\n}\n"],"mappings":";AAWA,IAAa,qBAAb,MAAa,mBAGb;CACC,YACSA,YACAC,UAAqC,CAAE,GAC9C;EAFO;EACA;CACL;;;;;CAMJ,aAAa,qBAEXC,kBAAiE;EAClE,MAAM,MAAM,IAAI,IAAI;EACpB,MAAM,SAAS,IAAI;EAEnB,MAAM,EAAE,oBAAoB,GAAG,MAAM,OAAO;EAC5C,MAAM,aACL,MAAM,mBAAmB,qBAAqB,iBAAiB;EAEhE,MAAMD,UAAqC;GAC1C,WAAW,OAAO,IAAI,YAAY;GAClC,UAAU,OAAO,IAAI,WAAW,GAC7B,OAAO,SAAS,OAAO,IAAI,WAAW,EAAG,GAAG;EAE/C;AAED,SAAO,IAAI,mBAA6B,YAAY;CACpD;CAED,MAAM,UACLE,UACAC,UACgB;AAChB,OAAK,KAAK,WAAW,aAAa,CACjC,OAAM,KAAK,WAAW,SAAS;EAGhC,MAAM,UAAU,KAAK,WAAW;AAChC,OAAK,QACJ,OAAM,IAAI,MAAM;EAGjB,MAAM,WAAW,KAAK,WAAW;AAGjC,MAAI,KAAK,QAAQ,SAChB,OAAM,QAAQ,SAAS,KAAK,QAAQ,SAAS;EAI9C,MAAM,YAAY,KAAK,QAAQ,aAAa;EAC5C,MAAMC,eAA4C;GACjD,SAAS;GACT,GAAG,KAAK,QAAQ;EAChB;EAED,MAAM,EAAE,OAAO,GAAG,MAAM,QAAQ,YAAY,WAAW,aAAa;AAGpE,OAAK,MAAM,eAAe,SACzB,OAAM,QAAQ,UAAU,OAAO,UAAU,YAAY;AAItD,QAAM,QAAQ,QACb,OACA,OAAO,QAAQ;AACd,QAAK,IAAK;AAEV,OAAI;IAEH,MAAM,UAAU,IAAI,QAAQ,UAAU;IACtC,MAAM,UAAU,KAAK,MAAM,QAAQ;IAGnC,MAAM,cAAc,IAAI,WAAW;IAGnC,MAAMC,cAAwB;KAC7B,MAAM;KACN;IACA;AAGD,UAAM,SAAS,YAAY;AAG3B,YAAQ,IAAI,IAAI;GAChB,SAAQ,QAAQ;AAChB,YAAQ,KAAK,KAAK,OAAO,KAAK;GAC9B;EACD,GACD,KAAK,QAAQ,eACb;CACD;AACD"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"RabbitMQSubscriber-
|
|
1
|
+
{"version":3,"file":"RabbitMQSubscriber-fUmIyY0t.cjs","names":["connection: RabbitMQConnection","options: RabbitMQSubscriberOptions","connectionString: string","messages: TMessage['type'][]","listener: (payload: TMessage) => Promise<void>","queueOptions: amqplib.Options.AssertQueue","fullMessage: TMessage"],"sources":["../src/rabbitmq/RabbitMQSubscriber.ts"],"sourcesContent":["import type amqplib from 'amqplib';\nimport type { EventSubscriber, PublishableMessage } from '../types';\nimport type { RabbitMQConnection } from './RabbitMQConnection';\n\nexport interface RabbitMQSubscriberOptions {\n\tqueueName?: string; // If not provided, a unique queue will be generated\n\tqueueOptions?: amqplib.Options.AssertQueue;\n\tconsumeOptions?: amqplib.Options.Consume;\n\tprefetch?: number; // Number of messages to prefetch (default: 1)\n}\n\nexport class RabbitMQSubscriber<\n\tTMessage extends PublishableMessage<string, any>,\n> implements EventSubscriber<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: RabbitMQConnection,\n\t\tprivate options: RabbitMQSubscriberOptions = {},\n\t) {}\n\n\t/**\n\t * Create a RabbitMQSubscriber from a connection string\n\t * Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&queueName=myqueue&prefetch=10\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<RabbitMQSubscriber<TMessage>> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst { RabbitMQConnection } = await import('./RabbitMQConnection');\n\t\tconst connection =\n\t\t\tawait RabbitMQConnection.fromConnectionString(connectionString);\n\n\t\tconst options: RabbitMQSubscriberOptions = {\n\t\t\tqueueName: params.get('queueName') || undefined,\n\t\t\tprefetch: params.get('prefetch')\n\t\t\t\t? Number.parseInt(params.get('prefetch')!, 10)\n\t\t\t\t: undefined,\n\t\t};\n\n\t\treturn new RabbitMQSubscriber<TMessage>(connection, options);\n\t}\n\n\tasync subscribe(\n\t\tmessages: TMessage['type'][],\n\t\tlistener: (payload: TMessage) => Promise<void>,\n\t): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst channel = this.connection.amqpChannel;\n\t\tif (!channel) {\n\t\t\tthrow new Error('Channel not initialized');\n\t\t}\n\n\t\tconst exchange = this.connection.exchangeName;\n\n\t\t// Set prefetch if specified\n\t\tif (this.options.prefetch) {\n\t\t\tawait channel.prefetch(this.options.prefetch);\n\t\t}\n\n\t\t// Assert queue\n\t\tconst queueName = this.options.queueName || '';\n\t\tconst queueOptions: amqplib.Options.AssertQueue = {\n\t\t\tdurable: true,\n\t\t\t...this.options.queueOptions,\n\t\t};\n\n\t\tconst { queue } = await channel.assertQueue(queueName, queueOptions);\n\n\t\t// Bind queue to exchange for each message type\n\t\tfor (const messageType of messages) {\n\t\t\tawait channel.bindQueue(queue, exchange, messageType);\n\t\t}\n\n\t\t// Consume messages\n\t\tawait channel.consume(\n\t\t\tqueue,\n\t\t\tasync (msg) => {\n\t\t\t\tif (!msg) return;\n\n\t\t\t\ttry {\n\t\t\t\t\t// Parse message payload\n\t\t\t\t\tconst content = msg.content.toString();\n\t\t\t\t\tconst payload = JSON.parse(content);\n\n\t\t\t\t\t// Get message type from properties\n\t\t\t\t\tconst messageType = msg.properties.type;\n\n\t\t\t\t\t// Reconstruct full message\n\t\t\t\t\tconst fullMessage: TMessage = {\n\t\t\t\t\t\ttype: messageType,\n\t\t\t\t\t\tpayload,\n\t\t\t\t\t} as TMessage;\n\n\t\t\t\t\t// Call listener\n\t\t\t\t\tawait listener(fullMessage);\n\n\t\t\t\t\t// Ack message\n\t\t\t\t\tchannel.ack(msg);\n\t\t\t\t} catch (_error) {\n\t\t\t\t\tchannel.nack(msg, false, true);\n\t\t\t\t}\n\t\t\t},\n\t\t\tthis.options.consumeOptions,\n\t\t);\n\t}\n}\n"],"mappings":";;AAWA,IAAa,qBAAb,MAAa,mBAGb;CACC,YACSA,YACAC,UAAqC,CAAE,GAC9C;EAFO;EACA;CACL;;;;;CAMJ,aAAa,qBAEXC,kBAAiE;EAClE,MAAM,MAAM,IAAI,IAAI;EACpB,MAAM,SAAS,IAAI;EAEnB,MAAM,EAAE,oBAAoB,GAAG,2CAAM;EACrC,MAAM,aACL,MAAM,mBAAmB,qBAAqB,iBAAiB;EAEhE,MAAMD,UAAqC;GAC1C,WAAW,OAAO,IAAI,YAAY;GAClC,UAAU,OAAO,IAAI,WAAW,GAC7B,OAAO,SAAS,OAAO,IAAI,WAAW,EAAG,GAAG;EAE/C;AAED,SAAO,IAAI,mBAA6B,YAAY;CACpD;CAED,MAAM,UACLE,UACAC,UACgB;AAChB,OAAK,KAAK,WAAW,aAAa,CACjC,OAAM,KAAK,WAAW,SAAS;EAGhC,MAAM,UAAU,KAAK,WAAW;AAChC,OAAK,QACJ,OAAM,IAAI,MAAM;EAGjB,MAAM,WAAW,KAAK,WAAW;AAGjC,MAAI,KAAK,QAAQ,SAChB,OAAM,QAAQ,SAAS,KAAK,QAAQ,SAAS;EAI9C,MAAM,YAAY,KAAK,QAAQ,aAAa;EAC5C,MAAMC,eAA4C;GACjD,SAAS;GACT,GAAG,KAAK,QAAQ;EAChB;EAED,MAAM,EAAE,OAAO,GAAG,MAAM,QAAQ,YAAY,WAAW,aAAa;AAGpE,OAAK,MAAM,eAAe,SACzB,OAAM,QAAQ,UAAU,OAAO,UAAU,YAAY;AAItD,QAAM,QAAQ,QACb,OACA,OAAO,QAAQ;AACd,QAAK,IAAK;AAEV,OAAI;IAEH,MAAM,UAAU,IAAI,QAAQ,UAAU;IACtC,MAAM,UAAU,KAAK,MAAM,QAAQ;IAGnC,MAAM,cAAc,IAAI,WAAW;IAGnC,MAAMC,cAAwB;KAC7B,MAAM;KACN;IACA;AAGD,UAAM,SAAS,YAAY;AAG3B,YAAQ,IAAI,IAAI;GAChB,SAAQ,QAAQ;AAChB,YAAQ,KAAK,KAAK,OAAO,KAAK;GAC9B;EACD,GACD,KAAK,QAAQ,eACb;CACD;AACD"}
|
|
@@ -6,18 +6,24 @@ var SQSPublisher = class SQSPublisher {
|
|
|
6
6
|
options;
|
|
7
7
|
constructor(connection, options = {}) {
|
|
8
8
|
this.connection = connection;
|
|
9
|
-
this.options = {
|
|
9
|
+
this.options = {
|
|
10
|
+
maxBatchSize: options.maxBatchSize ?? 10,
|
|
11
|
+
groupId: options.groupId
|
|
12
|
+
};
|
|
10
13
|
}
|
|
11
14
|
/**
|
|
12
15
|
* Create an SQSPublisher from a connection string
|
|
13
16
|
* Format: sqs://?queueUrl=https://sqs.region.amazonaws.com/accountId/queueName®ion=us-east-1&endpoint=http://localhost:4566&maxBatchSize=10
|
|
14
17
|
*/
|
|
15
|
-
static async fromConnectionString(connectionString) {
|
|
18
|
+
static async fromConnectionString(connectionString, publisherOptions = {}) {
|
|
16
19
|
const url = new URL(connectionString);
|
|
17
20
|
const params = url.searchParams;
|
|
18
21
|
const { SQSConnection } = await import("./sqs/SQSConnection.mjs");
|
|
19
22
|
const connection = await SQSConnection.fromConnectionString(connectionString);
|
|
20
|
-
const options = {
|
|
23
|
+
const options = {
|
|
24
|
+
maxBatchSize: params.get("maxBatchSize") ? Number.parseInt(params.get("maxBatchSize"), 10) : void 0,
|
|
25
|
+
groupId: publisherOptions.groupId
|
|
26
|
+
};
|
|
21
27
|
return new SQSPublisher(connection, options);
|
|
22
28
|
}
|
|
23
29
|
async publish(messages) {
|
|
@@ -36,7 +42,8 @@ var SQSPublisher = class SQSPublisher {
|
|
|
36
42
|
MessageAttributes: { type: {
|
|
37
43
|
DataType: "String",
|
|
38
44
|
StringValue: message.type
|
|
39
|
-
} }
|
|
45
|
+
} },
|
|
46
|
+
...this.options.groupId && { MessageGroupId: this.options.groupId(message) }
|
|
40
47
|
}));
|
|
41
48
|
const input = {
|
|
42
49
|
QueueUrl: this.connection.queueUrl,
|
|
@@ -54,4 +61,4 @@ var SQSPublisher = class SQSPublisher {
|
|
|
54
61
|
|
|
55
62
|
//#endregion
|
|
56
63
|
export { SQSPublisher };
|
|
57
|
-
//# sourceMappingURL=SQSPublisher-
|
|
64
|
+
//# sourceMappingURL=SQSPublisher-Bn1lwlln.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"SQSPublisher-Bn1lwlln.mjs","names":["connection: SQSConnection","options: SQSPublisherOptions<TMessage>","connectionString: string","publisherOptions: Pick<SQSPublisherOptions<TMessage>, 'groupId'>","messages: TMessage[]","entries: SendMessageBatchRequestEntry[]","input: SendMessageBatchCommandInput"],"sources":["../src/sqs/SQSPublisher.ts"],"sourcesContent":["import {\n\tSendMessageBatchCommand,\n\ttype SendMessageBatchCommandInput,\n\ttype SendMessageBatchRequestEntry,\n} from '@aws-sdk/client-sqs';\nimport chunk from 'lodash.chunk';\nimport type { EventPublisher, PublishableMessage } from '../types';\nimport type { SQSConnection } from './SQSConnection';\n\nexport interface SQSPublisherOptions<\n\tTMessage extends PublishableMessage<string, any> = PublishableMessage<\n\t\tstring,\n\t\tany\n\t>,\n> {\n\tmaxBatchSize?: number; // Default: 10 (SQS limit)\n\t/**\n\t * The FIFO message group for each message. Required to publish to a FIFO\n\t * queue, which refuses a message without one. Messages in one group are\n\t * delivered in order; different groups are processed in parallel. The queue\n\t * must use content-based deduplication, as no deduplication id is sent.\n\t */\n\tgroupId?: (message: TMessage) => string;\n}\n\nexport class SQSPublisher<TMessage extends PublishableMessage<string, any>>\n\timplements EventPublisher<TMessage>\n{\n\treadonly options: Required<Omit<SQSPublisherOptions<TMessage>, 'groupId'>> &\n\t\tPick<SQSPublisherOptions<TMessage>, 'groupId'>;\n\n\tconstructor(\n\t\treadonly connection: SQSConnection,\n\t\toptions: SQSPublisherOptions<TMessage> = {},\n\t) {\n\t\tthis.options = {\n\t\t\tmaxBatchSize: options.maxBatchSize ?? 10, // SQS limit\n\t\t\tgroupId: options.groupId,\n\t\t};\n\t}\n\n\t/**\n\t * Create an SQSPublisher from a connection string\n\t * Format: sqs://?queueUrl=https://sqs.region.amazonaws.com/accountId/queueName®ion=us-east-1&endpoint=http://localhost:4566&maxBatchSize=10\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(\n\t\tconnectionString: string,\n\t\tpublisherOptions: Pick<SQSPublisherOptions<TMessage>, 'groupId'> = {},\n\t): Promise<SQSPublisher<TMessage>> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst { SQSConnection } = await import('./SQSConnection');\n\t\tconst connection =\n\t\t\tawait SQSConnection.fromConnectionString(connectionString);\n\n\t\tconst options: SQSPublisherOptions<TMessage> = {\n\t\t\tmaxBatchSize: params.get('maxBatchSize')\n\t\t\t\t? Number.parseInt(params.get('maxBatchSize')!, 10)\n\t\t\t\t: undefined,\n\t\t\tgroupId: publisherOptions.groupId,\n\t\t};\n\n\t\treturn new SQSPublisher<TMessage>(connection, options);\n\t}\n\n\tasync publish(messages: TMessage[]): Promise<void> {\n\t\tif (messages.length === 0) return;\n\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\t// Split messages into batches (SQS limit is 10 messages per batch)\n\t\tconst batches = chunk(messages, this.options.maxBatchSize);\n\n\t\t// Send all batches\n\t\tawait Promise.all(batches.map((batch) => this.sendBatch(batch)));\n\t}\n\n\tprivate async sendBatch(messages: TMessage[]): Promise<void> {\n\t\tconst entries: SendMessageBatchRequestEntry[] = messages.map(\n\t\t\t(message, index) => ({\n\t\t\t\tId: `${index}`,\n\t\t\t\tMessageBody: JSON.stringify({\n\t\t\t\t\ttype: message.type,\n\t\t\t\t\tpayload: message.payload,\n\t\t\t\t}),\n\t\t\t\tMessageAttributes: {\n\t\t\t\t\ttype: {\n\t\t\t\t\t\tDataType: 'String',\n\t\t\t\t\t\tStringValue: message.type,\n\t\t\t\t\t},\n\t\t\t\t},\n\t\t\t\t...(this.options.groupId && {\n\t\t\t\t\tMessageGroupId: this.options.groupId(message),\n\t\t\t\t}),\n\t\t\t}),\n\t\t);\n\n\t\tconst input: SendMessageBatchCommandInput = {\n\t\t\tQueueUrl: this.connection.queueUrl,\n\t\t\tEntries: entries,\n\t\t};\n\n\t\tconst command = new SendMessageBatchCommand(input);\n\t\tconst response = await this.connection.sqsClient.send(command);\n\n\t\t// Check for failures\n\t\tif (response.Failed && response.Failed.length > 0) {\n\t\t\tconst errors = response.Failed.map(\n\t\t\t\t(f) => `${f.Id}: ${f.Code} - ${f.Message}`,\n\t\t\t).join(', ');\n\t\t\tthrow new Error(\n\t\t\t\t`Failed to send ${response.Failed.length} messages: ${errors}`,\n\t\t\t);\n\t\t}\n\t}\n\n\tasync close(): Promise<void> {\n\t\t// Publisher doesn't own the connection\n\t\t// Connection should be closed by whoever created it\n\t}\n}\n"],"mappings":";;;;AAyBA,IAAa,eAAb,MAAa,aAEb;CACC,AAAS;CAGT,YACUA,YACTC,UAAyC,CAAE,GAC1C;EAFQ;AAGT,OAAK,UAAU;GACd,cAAc,QAAQ,gBAAgB;GACtC,SAAS,QAAQ;EACjB;CACD;;;;;CAMD,aAAa,qBAGZC,kBACAC,mBAAmE,CAAE,GACnC;EAClC,MAAM,MAAM,IAAI,IAAI;EACpB,MAAM,SAAS,IAAI;EAEnB,MAAM,EAAE,eAAe,GAAG,MAAM,OAAO;EACvC,MAAM,aACL,MAAM,cAAc,qBAAqB,iBAAiB;EAE3D,MAAMF,UAAyC;GAC9C,cAAc,OAAO,IAAI,eAAe,GACrC,OAAO,SAAS,OAAO,IAAI,eAAe,EAAG,GAAG;GAEnD,SAAS,iBAAiB;EAC1B;AAED,SAAO,IAAI,aAAuB,YAAY;CAC9C;CAED,MAAM,QAAQG,UAAqC;AAClD,MAAI,SAAS,WAAW,EAAG;AAE3B,OAAK,KAAK,WAAW,aAAa,CACjC,OAAM,KAAK,WAAW,SAAS;EAIhC,MAAM,UAAU,MAAM,UAAU,KAAK,QAAQ,aAAa;AAG1D,QAAM,QAAQ,IAAI,QAAQ,IAAI,CAAC,UAAU,KAAK,UAAU,MAAM,CAAC,CAAC;CAChE;CAED,MAAc,UAAUA,UAAqC;EAC5D,MAAMC,UAA0C,SAAS,IACxD,CAAC,SAAS,WAAW;GACpB,KAAK,EAAE,MAAM;GACb,aAAa,KAAK,UAAU;IAC3B,MAAM,QAAQ;IACd,SAAS,QAAQ;GACjB,EAAC;GACF,mBAAmB,EAClB,MAAM;IACL,UAAU;IACV,aAAa,QAAQ;GACrB,EACD;GACD,GAAI,KAAK,QAAQ,WAAW,EAC3B,gBAAgB,KAAK,QAAQ,QAAQ,QAAQ,CAC7C;EACD,GACD;EAED,MAAMC,QAAsC;GAC3C,UAAU,KAAK,WAAW;GAC1B,SAAS;EACT;EAED,MAAM,UAAU,IAAI,wBAAwB;EAC5C,MAAM,WAAW,MAAM,KAAK,WAAW,UAAU,KAAK,QAAQ;AAG9D,MAAI,SAAS,UAAU,SAAS,OAAO,SAAS,GAAG;GAClD,MAAM,SAAS,SAAS,OAAO,IAC9B,CAAC,OAAO,EAAE,EAAE,GAAG,IAAI,EAAE,KAAK,KAAK,EAAE,QAAQ,EACzC,CAAC,KAAK,KAAK;AACZ,SAAM,IAAI,OACR,iBAAiB,SAAS,OAAO,OAAO,aAAa,OAAO;EAE9D;CACD;CAED,MAAM,QAAuB,CAG5B;AACD"}
|