@geekmidas/events 10.0.0-alpha.15 → 10.0.0-alpha.151
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 +46 -1
- package/dist/{SQSSubscriber-BXLE_1L3.mjs → SQSSubscriber-BEJBfNTe.mjs} +94 -10
- package/dist/SQSSubscriber-BEJBfNTe.mjs.map +1 -0
- package/dist/{SQSSubscriber-DtRUaZB3.cjs → SQSSubscriber-COTqWvOk.cjs} +101 -10
- package/dist/SQSSubscriber-COTqWvOk.cjs.map +1 -0
- package/dist/basic/index.cjs +35 -4
- package/dist/basic/index.cjs.map +1 -1
- package/dist/basic/index.d.cts +8 -1
- package/dist/basic/index.d.cts.map +1 -1
- package/dist/basic/index.d.mts +8 -1
- package/dist/basic/index.d.mts.map +1 -1
- package/dist/basic/index.mjs +35 -5
- package/dist/basic/index.mjs.map +1 -1
- package/dist/index.cjs +45 -142
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +80 -20
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +80 -20
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +33 -141
- package/dist/index.mjs.map +1 -1
- package/dist/pgboss/index.cjs +121 -34
- package/dist/pgboss/index.cjs.map +1 -1
- package/dist/pgboss/index.d.cts +45 -4
- package/dist/pgboss/index.d.cts.map +1 -1
- package/dist/pgboss/index.d.mts +45 -4
- package/dist/pgboss/index.d.mts.map +1 -1
- package/dist/pgboss/index.mjs +119 -34
- package/dist/pgboss/index.mjs.map +1 -1
- package/dist/rabbitmq/index.cjs +60 -27
- package/dist/rabbitmq/index.cjs.map +1 -1
- package/dist/rabbitmq/index.d.cts +9 -1
- package/dist/rabbitmq/index.d.cts.map +1 -1
- package/dist/rabbitmq/index.d.mts +9 -1
- package/dist/rabbitmq/index.d.mts.map +1 -1
- package/dist/rabbitmq/index.mjs +61 -27
- package/dist/rabbitmq/index.mjs.map +1 -1
- package/dist/{types-gGaoT8qc.d.cts → registry-DIx25Q5s.d.cts} +108 -2
- package/dist/registry-DIx25Q5s.d.cts.map +1 -0
- package/dist/{types-gGaoT8qc.d.mts → registry-DIx25Q5s.d.mts} +108 -2
- package/dist/registry-DIx25Q5s.d.mts.map +1 -0
- package/dist/registry-DXLY1Xf6.mjs +99 -0
- package/dist/registry-DXLY1Xf6.mjs.map +1 -0
- package/dist/registry-DlT36229.cjs +122 -0
- package/dist/registry-DlT36229.cjs.map +1 -0
- package/dist/sns/index.cjs +425 -11
- package/dist/sns/index.cjs.map +1 -1
- package/dist/sns/index.d.cts +255 -8
- package/dist/sns/index.d.cts.map +1 -1
- package/dist/sns/index.d.mts +255 -8
- package/dist/sns/index.d.mts.map +1 -1
- package/dist/sns/index.mjs +410 -12
- package/dist/sns/index.mjs.map +1 -1
- package/dist/sns/snsUrl.d.cts.map +1 -1
- package/dist/sns/snsUrl.d.mts.map +1 -1
- package/dist/sqs/index.cjs +22 -66
- package/dist/sqs/index.cjs.map +1 -1
- package/dist/sqs/index.d.cts +10 -1
- package/dist/sqs/index.d.cts.map +1 -1
- package/dist/sqs/index.d.mts +10 -1
- package/dist/sqs/index.d.mts.map +1 -1
- package/dist/sqs/index.mjs +20 -63
- package/dist/sqs/index.mjs.map +1 -1
- package/dist/sqs/sqsUrl.d.cts.map +1 -1
- package/dist/sqs/sqsUrl.d.mts.map +1 -1
- package/dist/telemetry-DG3l807O.cjs +309 -0
- package/dist/telemetry-DG3l807O.cjs.map +1 -0
- package/dist/telemetry-DjjgJMul.mjs +244 -0
- package/dist/telemetry-DjjgJMul.mjs.map +1 -0
- package/package.json +8 -3
- package/dist/PgBossConnection-CywKoAZU.cjs +0 -2
- package/dist/PgBossConnection-DjoqT84r.mjs +0 -2
- package/dist/RabbitMQConnection-C9eccBL8.cjs +0 -2
- package/dist/RabbitMQConnection-CAp7VqyT.mjs +0 -2
- package/dist/SNSConnection-BWDC1wAF.cjs +0 -2
- package/dist/SNSConnection-ezQvVrDv.mjs +0 -2
- package/dist/SQSSubscriber-BXLE_1L3.mjs.map +0 -1
- package/dist/SQSSubscriber-DtRUaZB3.cjs.map +0 -1
- package/dist/types-BcZjLxVV.cjs +0 -51
- package/dist/types-BcZjLxVV.cjs.map +0 -1
- package/dist/types-Bk5JM6MP.mjs +0 -40
- package/dist/types-Bk5JM6MP.mjs.map +0 -1
- package/dist/types-gGaoT8qc.d.cts.map +0 -1
- package/dist/types-gGaoT8qc.d.mts.map +0 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/rabbitmq/errors.ts","../../src/rabbitmq/RabbitMQConnection.ts","../../src/rabbitmq/RabbitMQPublisher.ts","../../src/rabbitmq/RabbitMQSubscriber.ts"],"mappings":";;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/rabbitmq/driver.ts","../../src/rabbitmq/errors.ts","../../src/rabbitmq/RabbitMQConnection.ts","../../src/rabbitmq/RabbitMQPublisher.ts","../../src/rabbitmq/RabbitMQSubscriber.ts"],"mappings":";;;;;;;;qBAWa,sBAAsB;;;;qBCNtB,mCAAmC;EAC/C;;;;UCFgB;EAChB;EACA;EACA;EACA,kBAAkB,QAAQ,QAAQ;EAClC;;qBAGY,8BAA8B;WACjC,OAAI,mBAAA;UACL;UACA;UACA;UACA;EAKR,YAAY,QAAQ;;;;;SAiBP,qBACZ,2BACE,QAAQ;EAoBL,WAAW;EA6CX,SAAS;EAWf;UAIQ;;;;MASJ,eAAe,QAAQ;;;;MAOvB;;;;MAOA;;;;UC1IY;EAChB,iBAAiB,QAAQ,QAAQ;;qBAGrB,kBAAkB,iBAAiB,4CACpC,eAAe;UAGjB;UACA;EAFT,YACS,YAAY,oBACZ,UAAS;;;;;SAOL,qBACZ,iBAAiB,iCAChB,2BAA2B,QAAQ,kBAAkB;EAOjD,QAAQ,UAAU,aAAa;EA+C/B,SAAS;;;;UCxEC;EAChB;EACA,eAAe,QAAQ,QAAQ;EAC/B,iBAAiB,QAAQ,QAAQ;EACjC;;qBAGY,mBACZ,iBAAiB,4CACL,gBAAgB;UAGnB;UACA;EAFT,YACS,YAAY,oBACZ,UAAS;;;;;SAOL,qBACZ,iBAAiB,iCAChB,2BAA2B,QAAQ,mBAAmB;EAkBlD,UACL,UAAU,oBACV,WAAW,SAAS,aAAa,gBAC/B"}
|
package/dist/rabbitmq/index.mjs
CHANGED
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import "../
|
|
1
|
+
import { t as __exportAll } from "../rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
+
import { a as consumeTraced, r as carrierFromAttributes, s as publishTraced } from "../telemetry-DjjgJMul.mjs";
|
|
2
3
|
import amqplib from "amqplib";
|
|
3
|
-
//#region src/rabbitmq/errors.ts
|
|
4
|
-
/** The connection opened but has no channel to publish or consume on. */
|
|
5
|
-
var RabbitMQChannelUnavailable = class extends Error {
|
|
6
|
-
constructor() {
|
|
7
|
-
super("RabbitMQ connected without a channel. Check the broker is reachable and the connection string names a vhost the user can open channels on.");
|
|
8
|
-
this.name = "RabbitMQChannelUnavailable";
|
|
9
|
-
}
|
|
10
|
-
};
|
|
11
|
-
//#endregion
|
|
12
4
|
//#region src/rabbitmq/RabbitMQConnection.ts
|
|
5
|
+
var RabbitMQConnection_exports = /* @__PURE__ */ __exportAll({ RabbitMQConnection: () => RabbitMQConnection });
|
|
13
6
|
var RabbitMQConnection = class RabbitMQConnection {
|
|
14
7
|
type = "rabbitmq";
|
|
15
8
|
connection;
|
|
@@ -110,6 +103,15 @@ var RabbitMQConnection = class RabbitMQConnection {
|
|
|
110
103
|
}
|
|
111
104
|
};
|
|
112
105
|
//#endregion
|
|
106
|
+
//#region src/rabbitmq/errors.ts
|
|
107
|
+
/** The connection opened but has no channel to publish or consume on. */
|
|
108
|
+
var RabbitMQChannelUnavailable = class extends Error {
|
|
109
|
+
constructor() {
|
|
110
|
+
super("RabbitMQ connected without a channel. Check the broker is reachable and the connection string names a vhost the user can open channels on.");
|
|
111
|
+
this.name = "RabbitMQChannelUnavailable";
|
|
112
|
+
}
|
|
113
|
+
};
|
|
114
|
+
//#endregion
|
|
113
115
|
//#region src/rabbitmq/RabbitMQPublisher.ts
|
|
114
116
|
var RabbitMQPublisher = class RabbitMQPublisher {
|
|
115
117
|
connection;
|
|
@@ -123,7 +125,7 @@ var RabbitMQPublisher = class RabbitMQPublisher {
|
|
|
123
125
|
* Format: rabbitmq://user:pass@host:port/vhost?exchange=name&type=topic&timeout=5000
|
|
124
126
|
*/
|
|
125
127
|
static async fromConnectionString(connectionString) {
|
|
126
|
-
const { RabbitMQConnection } = await
|
|
128
|
+
const { RabbitMQConnection } = await Promise.resolve().then(() => RabbitMQConnection_exports);
|
|
127
129
|
const connection = await RabbitMQConnection.fromConnectionString(connectionString);
|
|
128
130
|
return new RabbitMQPublisher(connection);
|
|
129
131
|
}
|
|
@@ -132,17 +134,27 @@ var RabbitMQPublisher = class RabbitMQPublisher {
|
|
|
132
134
|
const channel = this.connection.amqpChannel;
|
|
133
135
|
if (!channel) throw new RabbitMQChannelUnavailable();
|
|
134
136
|
const exchange = this.connection.exchangeName;
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
137
|
+
await publishTraced(messages, (message) => ({
|
|
138
|
+
system: "rabbitmq",
|
|
139
|
+
destination: exchange,
|
|
140
|
+
type: message.type
|
|
141
|
+
}), async (carriers) => {
|
|
142
|
+
for (const [i, message] of messages.entries()) {
|
|
143
|
+
const content = Buffer.from(JSON.stringify(message.payload));
|
|
144
|
+
const { headers, ...publishOptions } = this.options.publishOptions ?? {};
|
|
145
|
+
if (!channel.publish(exchange, message.type, content, {
|
|
146
|
+
contentType: "application/json",
|
|
147
|
+
timestamp: Date.now(),
|
|
148
|
+
type: message.type,
|
|
149
|
+
persistent: true,
|
|
150
|
+
...publishOptions,
|
|
151
|
+
...(headers || carriers[i]) && { headers: {
|
|
152
|
+
...headers,
|
|
153
|
+
...carriers[i]
|
|
154
|
+
} }
|
|
155
|
+
})) await new Promise((resolve) => channel.once("drain", resolve));
|
|
156
|
+
}
|
|
157
|
+
});
|
|
146
158
|
}
|
|
147
159
|
async close() {}
|
|
148
160
|
};
|
|
@@ -161,7 +173,7 @@ var RabbitMQSubscriber = class RabbitMQSubscriber {
|
|
|
161
173
|
*/
|
|
162
174
|
static async fromConnectionString(connectionString) {
|
|
163
175
|
const params = new URL(connectionString).searchParams;
|
|
164
|
-
const { RabbitMQConnection } = await
|
|
176
|
+
const { RabbitMQConnection } = await Promise.resolve().then(() => RabbitMQConnection_exports);
|
|
165
177
|
const connection = await RabbitMQConnection.fromConnectionString(connectionString);
|
|
166
178
|
const options = {
|
|
167
179
|
queueName: params.get("queueName") || void 0,
|
|
@@ -187,10 +199,17 @@ var RabbitMQSubscriber = class RabbitMQSubscriber {
|
|
|
187
199
|
try {
|
|
188
200
|
const content = msg.content.toString();
|
|
189
201
|
const payload = JSON.parse(content);
|
|
190
|
-
|
|
191
|
-
|
|
202
|
+
const messageType = msg.properties.type;
|
|
203
|
+
const fullMessage = {
|
|
204
|
+
type: messageType,
|
|
192
205
|
payload
|
|
193
|
-
}
|
|
206
|
+
};
|
|
207
|
+
await consumeTraced({
|
|
208
|
+
system: "rabbitmq",
|
|
209
|
+
destination: queue,
|
|
210
|
+
type: messageType,
|
|
211
|
+
messageId: msg.properties.messageId
|
|
212
|
+
}, carrierFromAttributes(msg.properties.headers), () => listener(fullMessage));
|
|
194
213
|
channel.ack(msg);
|
|
195
214
|
} catch (_error) {
|
|
196
215
|
channel.nack(msg, false, true);
|
|
@@ -199,6 +218,21 @@ var RabbitMQSubscriber = class RabbitMQSubscriber {
|
|
|
199
218
|
}
|
|
200
219
|
};
|
|
201
220
|
//#endregion
|
|
202
|
-
|
|
221
|
+
//#region src/rabbitmq/driver.ts
|
|
222
|
+
/**
|
|
223
|
+
* `rabbitmq://` — an AMQP exchange. Register it with
|
|
224
|
+
* `registerEventsDriver(rabbitmqEventsDriver)`; this subpath is the only one
|
|
225
|
+
* that imports `amqplib`.
|
|
226
|
+
*/
|
|
227
|
+
const rabbitmqEventsDriver = {
|
|
228
|
+
scheme: "rabbitmq",
|
|
229
|
+
connect: (url) => RabbitMQConnection.fromConnectionString(url),
|
|
230
|
+
publisher: (url) => RabbitMQPublisher.fromConnectionString(url),
|
|
231
|
+
publisherFor: (connection) => new RabbitMQPublisher(connection),
|
|
232
|
+
subscriber: (url) => RabbitMQSubscriber.fromConnectionString(url),
|
|
233
|
+
subscriberFor: (connection) => new RabbitMQSubscriber(connection)
|
|
234
|
+
};
|
|
235
|
+
//#endregion
|
|
236
|
+
export { RabbitMQChannelUnavailable, RabbitMQConnection, RabbitMQPublisher, RabbitMQSubscriber, rabbitmqEventsDriver };
|
|
203
237
|
|
|
204
238
|
//# sourceMappingURL=index.mjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/rabbitmq/errors.ts","../../src/rabbitmq/RabbitMQConnection.ts","../../src/rabbitmq/RabbitMQPublisher.ts","../../src/rabbitmq/RabbitMQSubscriber.ts"],"sourcesContent":["// Beside the adapter but apart from its connection module, which imports\n// the broker's client: the publisher and subscriber load that lazily, and\n// importing an error class from it would load it eagerly.\n\n/** The connection opened but has no channel to publish or consume on. */\nexport class RabbitMQChannelUnavailable extends Error {\n\tconstructor() {\n\t\tsuper(\n\t\t\t'RabbitMQ connected without a channel. Check the broker is reachable and the connection string names a vhost the user can open channels on.',\n\t\t);\n\t\tthis.name = 'RabbitMQChannelUnavailable';\n\t}\n}\n","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","import type amqplib from 'amqplib';\nimport type { EventPublisher, PublishableMessage } from '../types';\nimport { RabbitMQChannelUnavailable } from './errors';\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 RabbitMQChannelUnavailable();\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","import type amqplib from 'amqplib';\nimport type { EventSubscriber, PublishableMessage } from '../types';\nimport { RabbitMQChannelUnavailable } from './errors';\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 RabbitMQChannelUnavailable();\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":";;;;AAKA,IAAa,6BAAb,cAAgD,MAAM;CACrD,cAAc;EACb,MACC,4IACD;EACA,KAAK,OAAO;CACb;AACD;;;ACAA,IAAa,qBAAb,MAAa,mBAA8C;CAC1D,OAAS;CACT;CACA;CACA;CACA;CAKA,YAAY,QAAkC;EAC7C,KAAK,SAAS;GACb,GAAG;GACH,UAAU,OAAO,YAAY;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AI,WAAW;KAKlC;IAIwB,CAAC;IAG1B,QAAQ,IAAI,GAAG;GAChB,SAAS,QAAQ;IAChB,QAAQ,KAAK,KAAK,OAAO,IAAI;GAC9B;EACD,GACA,KAAK,QAAQ,cACd;CACD;AACD"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/rabbitmq/RabbitMQConnection.ts","../../src/rabbitmq/errors.ts","../../src/rabbitmq/RabbitMQPublisher.ts","../../src/rabbitmq/RabbitMQSubscriber.ts","../../src/rabbitmq/driver.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","// Beside the adapter but apart from its connection module, which imports\n// the broker's client: the publisher and subscriber load that lazily, and\n// importing an error class from it would load it eagerly.\n\n/** The connection opened but has no channel to publish or consume on. */\nexport class RabbitMQChannelUnavailable extends Error {\n\tconstructor() {\n\t\tsuper(\n\t\t\t'RabbitMQ connected without a channel. Check the broker is reachable and the connection string names a vhost the user can open channels on.',\n\t\t);\n\t\tthis.name = 'RabbitMQChannelUnavailable';\n\t}\n}\n","import type amqplib from 'amqplib';\nimport { publishTraced } from '../telemetry';\nimport type { EventPublisher, PublishableMessage } from '../types';\nimport { RabbitMQChannelUnavailable } from './errors';\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 RabbitMQChannelUnavailable();\n\t\t}\n\n\t\tconst exchange = this.connection.exchangeName;\n\n\t\tawait publishTraced(\n\t\t\tmessages,\n\t\t\t(message) => ({\n\t\t\t\tsystem: 'rabbitmq',\n\t\t\t\tdestination: exchange,\n\t\t\t\ttype: message.type,\n\t\t\t}),\n\t\t\tasync (carriers) => {\n\t\t\t\tfor (const [i, message] of messages.entries()) {\n\t\t\t\t\tconst content = Buffer.from(JSON.stringify(message.payload));\n\t\t\t\t\tconst { headers, ...publishOptions } =\n\t\t\t\t\t\tthis.options.publishOptions ?? {};\n\n\t\t\t\t\t// Use message type as routing key for topic exchanges; the trace\n\t\t\t\t\t// context goes in the message's headers.\n\t\t\t\t\tconst published = channel.publish(exchange, message.type, content, {\n\t\t\t\t\t\tcontentType: 'application/json',\n\t\t\t\t\t\ttimestamp: Date.now(),\n\t\t\t\t\t\ttype: message.type,\n\t\t\t\t\t\tpersistent: true,\n\t\t\t\t\t\t...publishOptions,\n\t\t\t\t\t\t...((headers || carriers[i]) && {\n\t\t\t\t\t\t\theaders: { ...headers, ...carriers[i] },\n\t\t\t\t\t\t}),\n\t\t\t\t\t});\n\n\t\t\t\t\t// Handle backpressure\n\t\t\t\t\tif (!published) {\n\t\t\t\t\t\tawait new Promise((resolve) => channel.once('drain', resolve));\n\t\t\t\t\t}\n\t\t\t\t}\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","import type amqplib from 'amqplib';\nimport { carrierFromAttributes, consumeTraced } from '../telemetry';\nimport type { EventSubscriber, PublishableMessage } from '../types';\nimport { RabbitMQChannelUnavailable } from './errors';\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 RabbitMQChannelUnavailable();\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, as a child of the publisher's span\n\t\t\t\t\tawait consumeTraced(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsystem: 'rabbitmq',\n\t\t\t\t\t\t\tdestination: queue,\n\t\t\t\t\t\t\ttype: messageType,\n\t\t\t\t\t\t\tmessageId: msg.properties.messageId,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcarrierFromAttributes(msg.properties.headers),\n\t\t\t\t\t\t() => listener(fullMessage),\n\t\t\t\t\t);\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","import type { EventsDriver } from '../registry';\nimport { EventPublisherType } from '../types';\nimport { RabbitMQConnection } from './RabbitMQConnection';\nimport { RabbitMQPublisher } from './RabbitMQPublisher';\nimport { RabbitMQSubscriber } from './RabbitMQSubscriber';\n\n/**\n * `rabbitmq://` — an AMQP exchange. Register it with\n * `registerEventsDriver(rabbitmqEventsDriver)`; this subpath is the only one\n * that imports `amqplib`.\n */\nexport const rabbitmqEventsDriver: EventsDriver = {\n\tscheme: EventPublisherType.RabbitMQ,\n\tconnect: (url) => RabbitMQConnection.fromConnectionString(url),\n\tpublisher: (url) => RabbitMQPublisher.fromConnectionString(url),\n\tpublisherFor: (connection) =>\n\t\tnew RabbitMQPublisher(connection as RabbitMQConnection),\n\tsubscriber: (url) => RabbitMQSubscriber.fromConnectionString(url),\n\tsubscriberFor: (connection) =>\n\t\tnew RabbitMQSubscriber(connection as RabbitMQConnection),\n};\n"],"mappings":";;;;;AAYA,IAAa,qBAAb,MAAa,mBAA8C;CAC1D,OAAS;CACT;CACA;CACA;CACA;CAKA,YAAY,QAAkC;EAC7C,KAAK,SAAS;GACb,GAAG;GACH,UAAU,OAAO,YAAY;GAC7B,cAAc,OAAO,gBAAgB;GACrC,SAAS,OAAO,WAAW;GAC3B,iBAAiB;IAChB,SAAS;IACT,GAAG,OAAO;GACX;EACD;CACD;;;;;CAMA,aAAa,qBACZ,kBAC8B;EAC9B,MAAM,MAAM,IAAI,IAAI,gBAAgB;EACpC,MAAM,SAAS,IAAI;EAGnB,MAAM,UAAU,UAAU,IAAI,WAAW,GAAG,IAAI,SAAS,GAAG,IAAI,SAAS,KAAK,KAAK,IAAI,OAAO,IAAI;EAElG,MAAM,eAAe,OAAO,IAAI,SAAS;EACzC,MAAM,SAAmC;GACxC,KAAK;GACL,UAAU,OAAO,IAAI,UAAU,KAAK;GACpC,cAAe,OAAO,IAAI,MAAM,KAAa;GAC7C,SAAS,eAAe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KACR,aAAa;KACb,MAAM;KACN,WAAW,IAAI,WAAW;IAC3B,GACA,sBAAsB,IAAI,WAAW,OAAO,SACtC,SAAS,WAAW,CAC3B;IAGA,QAAQ,IAAI,GAAG;GAChB,SAAS,QAAQ;IAChB,QAAQ,KAAK,KAAK,OAAO,IAAI;GAC9B;EACD,GACA,KAAK,QAAQ,cACd;CACD;AACD;;;;;;;;AC9GA,MAAa,uBAAqC;CACjD,QAAA;CACA,UAAU,QAAQ,mBAAmB,qBAAqB,GAAG;CAC7D,YAAY,QAAQ,kBAAkB,qBAAqB,GAAG;CAC9D,eAAe,eACd,IAAI,kBAAkB,UAAgC;CACvD,aAAa,QAAQ,mBAAmB,qBAAqB,GAAG;CAChE,gBAAgB,eACf,IAAI,mBAAmB,UAAgC;AACzD"}
|
|
@@ -145,5 +145,111 @@ type MappedEvent<T extends EventPublisher<any> | undefined, OutSchema extends St
|
|
|
145
145
|
when?: (ctx: InferStandardSchema<OutSchema>) => boolean;
|
|
146
146
|
};
|
|
147
147
|
//#endregion
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
//#region src/Publisher.d.ts
|
|
149
|
+
/** How a publisher is used, beyond the address it reaches. */
|
|
150
|
+
interface PublisherOptions {
|
|
151
|
+
/**
|
|
152
|
+
* The topic this publisher fans out to. SNS and RabbitMQ name the topic in
|
|
153
|
+
* their address already; pg-boss has one address for every topic and queue,
|
|
154
|
+
* so it is told here that a message goes to every subscriber rather than to
|
|
155
|
+
* one queue.
|
|
156
|
+
*/
|
|
157
|
+
topic?: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Publishers for a connection string or a connection, through whichever
|
|
161
|
+
* driver is registered for its scheme — see `registerEventsDriver`.
|
|
162
|
+
*/
|
|
163
|
+
declare class Publisher {
|
|
164
|
+
/**
|
|
165
|
+
* Create a publisher from a connection string
|
|
166
|
+
* This creates both a connection and a publisher
|
|
167
|
+
*
|
|
168
|
+
* @throws {UnregisteredEventsScheme} when the broker's driver is not
|
|
169
|
+
* registered.
|
|
170
|
+
*/
|
|
171
|
+
static fromConnectionString<TMessage extends PublishableMessage<string, any>>(connectionStr: EventPublisherConnectionString, options?: PublisherOptions): Promise<EventPublisher<TMessage>>;
|
|
172
|
+
/**
|
|
173
|
+
* Create a publisher from an existing connection
|
|
174
|
+
* This allows sharing connections between publishers and subscribers
|
|
175
|
+
*/
|
|
176
|
+
static fromConnection<TMessage extends PublishableMessage<string, any>>(connection: EventConnection, options?: PublisherOptions): Promise<EventPublisher<TMessage>>;
|
|
177
|
+
}
|
|
178
|
+
type EventPublisherConnectionString = `${EventPublisherType}://${string}`;
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/registry.d.ts
|
|
181
|
+
type AnyMessage = PublishableMessage<string, any>;
|
|
182
|
+
/** How a subscriber built from a connection is used, beyond its address. */
|
|
183
|
+
interface SubscriberOptions {
|
|
184
|
+
/**
|
|
185
|
+
* The topic subscribed to. pg-boss needs it, with {@link subscription}, to
|
|
186
|
+
* give each subscriber a queue of its own; the other brokers carry the topic
|
|
187
|
+
* in their address and ignore it.
|
|
188
|
+
*/
|
|
189
|
+
topic?: string;
|
|
190
|
+
/** The subscriber's name — its own queue on pg-boss. */
|
|
191
|
+
subscription?: string;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* One broker: the connections, publishers and subscribers for its scheme.
|
|
195
|
+
*
|
|
196
|
+
* A driver owns parsing — the shape of an `sns://` string is SNS's business —
|
|
197
|
+
* and is the only module that imports its broker's client library.
|
|
198
|
+
*/
|
|
199
|
+
interface EventsDriver {
|
|
200
|
+
/**
|
|
201
|
+
* The scheme this driver handles, without the colon — `'pgboss'`, `'sns'`.
|
|
202
|
+
* It is also the `type` of every connection the driver builds, which is how
|
|
203
|
+
* a connection finds its way back here.
|
|
204
|
+
*/
|
|
205
|
+
readonly scheme: `${EventPublisherType}`;
|
|
206
|
+
/** A connection, connected, for a connection string. */
|
|
207
|
+
connect(connectionString: string): Promise<EventConnection>;
|
|
208
|
+
/** A publisher, with a connection of its own, for a connection string. */
|
|
209
|
+
publisher<TMessage extends AnyMessage>(connectionString: string, options: PublisherOptions): Promise<EventPublisher<TMessage>>;
|
|
210
|
+
/** A publisher on a connection this driver built. */
|
|
211
|
+
publisherFor<TMessage extends AnyMessage>(connection: EventConnection, options: PublisherOptions): EventPublisher<TMessage>;
|
|
212
|
+
/** A subscriber, with a connection of its own, for a connection string. */
|
|
213
|
+
subscriber<TMessage extends AnyMessage>(connectionString: string): Promise<EventSubscriber<TMessage>>;
|
|
214
|
+
/** A subscriber on a connection this driver built. */
|
|
215
|
+
subscriberFor<TMessage extends AnyMessage>(connection: EventConnection, options: SubscriberOptions): EventSubscriber<TMessage>;
|
|
216
|
+
}
|
|
217
|
+
/** Make a driver available to `Publisher`, `Subscriber` and friends. Idempotent. */
|
|
218
|
+
declare function registerEventsDriver(driver: EventsDriver): void;
|
|
219
|
+
/** Which schemes are currently registered — the useful half of a failure. */
|
|
220
|
+
declare function registeredEventsSchemes(): string[];
|
|
221
|
+
/**
|
|
222
|
+
* The driver for a scheme — `'pgboss'`, `'pgboss:'`, or a whole connection
|
|
223
|
+
* string, whichever the caller has.
|
|
224
|
+
*
|
|
225
|
+
* @throws {UnregisteredEventsScheme} when the scheme is a broker this package
|
|
226
|
+
* implements but nothing registered its driver.
|
|
227
|
+
* @throws {UnsupportedEventTransport} when no broker here has that scheme.
|
|
228
|
+
*/
|
|
229
|
+
declare function eventsDriverFor(scheme: string, role?: 'publisher' | 'subscriber' | 'connection'): EventsDriver;
|
|
230
|
+
/**
|
|
231
|
+
* A connection string for a broker whose driver nothing registered.
|
|
232
|
+
*
|
|
233
|
+
* The broker exists — this is not a typo'd scheme — but the process was never
|
|
234
|
+
* told about it. Usually a script building its own publisher, or a build that
|
|
235
|
+
* registered the drivers for a different target than the one that composed
|
|
236
|
+
* the connection string.
|
|
237
|
+
*/
|
|
238
|
+
declare class UnregisteredEventsScheme extends Error {
|
|
239
|
+
/** The scheme with no driver, without the colon — `'pgboss'`. */
|
|
240
|
+
readonly scheme: string;
|
|
241
|
+
/** What is registered, so the caller can see what was chosen instead. */
|
|
242
|
+
readonly registered: readonly string[];
|
|
243
|
+
/** The subpath that exports the missing driver. */
|
|
244
|
+
readonly subpath: string;
|
|
245
|
+
/** The driver's export name. */
|
|
246
|
+
readonly driver: string;
|
|
247
|
+
constructor(
|
|
248
|
+
/** The scheme with no driver, without the colon — `'pgboss'`. */
|
|
249
|
+
scheme: string,
|
|
250
|
+
/** What is registered, so the caller can see what was chosen instead. */
|
|
251
|
+
registered: readonly string[]);
|
|
252
|
+
}
|
|
253
|
+
//#endregion
|
|
254
|
+
export { UnsupportedEventTransport as _, registerEventsDriver as a, Publisher as c, EventPublisher as d, EventPublisherType as f, PublishableMessage as g, MappedEvent as h, eventsDriverFor as i, PublisherOptions as l, ExtractPublisherMessage as m, SubscriberOptions as n, registeredEventsSchemes as o, EventSubscriber as p, UnregisteredEventsScheme as r, EventPublisherConnectionString as s, EventsDriver as t, EventConnection as u };
|
|
255
|
+
//# sourceMappingURL=registry-DIx25Q5s.d.cts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry-DIx25Q5s.d.cts","names":[],"sources":["../../../node_modules/.pnpm/@standard-schema+spec@1.1.0/node_modules/@standard-schema/spec/dist/index.d.ts","../src/types.ts","../src/Publisher.ts","../src/registry.ts"],"x_google_ignoreList":[0],"mappings":";;;UACU,gBAAgB,iBAAiB,SAAS;;WAEvC,aAAa,gBAAgB,MAAM,OAAO;;kBAErC;;YAEJ,MAAM,iBAAiB,SAAS;;aAE7B;;aAEA;;aAEA,QAAQ,MAAM,OAAO;;;YAGxB,MAAM,iBAAiB,SAAS;;aAE7B,OAAO;;aAEP,QAAQ;;;OAGhB,WAAW,eAAe,mBAAmB,YAAY;;OAEzD,YAAY,eAAe,mBAAmB,YAAY;;;UAGzD,iBAAiB,iBAAiB,SAAS;;WAExC,aAAa,iBAAiB,MAAM,OAAO;;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WAMP,WAAW;;EAEpB,QAAQ,2BAA2B,QAAQ;;EAE3C,UAAU,iBAAiB,YAC1B,0BACA,SAAS,mBACP,QAAQ,eAAe;;EAE1B,aAAa,iBAAiB,YAC7B,YAAY,iBACZ,SAAS,mBACP,eAAe;;EAElB,WAAW,iBAAiB,YAC3B,2BACE,QAAQ,gBAAgB;;EAE3B,cAAc,iBAAiB,YAC9B,YAAY,iBACZ,SAAS,oBACP,gBAAgB;;;iBA6CJ,qBAAqB,QAAQ;;iBAK7B;;;;;;;;;iBAYA,gBACf,gBACA,mDACE;;;;;;;;;cAyBU,iCAAiC;;WAQnC;;WAEA;;WARD;;WAEA;EAET,YAEU;;EAAA,gBAEA;;EAAA"}
|
|
@@ -145,5 +145,111 @@ type MappedEvent<T extends EventPublisher<any> | undefined, OutSchema extends St
|
|
|
145
145
|
when?: (ctx: InferStandardSchema<OutSchema>) => boolean;
|
|
146
146
|
};
|
|
147
147
|
//#endregion
|
|
148
|
-
|
|
149
|
-
|
|
148
|
+
//#region src/Publisher.d.ts
|
|
149
|
+
/** How a publisher is used, beyond the address it reaches. */
|
|
150
|
+
interface PublisherOptions {
|
|
151
|
+
/**
|
|
152
|
+
* The topic this publisher fans out to. SNS and RabbitMQ name the topic in
|
|
153
|
+
* their address already; pg-boss has one address for every topic and queue,
|
|
154
|
+
* so it is told here that a message goes to every subscriber rather than to
|
|
155
|
+
* one queue.
|
|
156
|
+
*/
|
|
157
|
+
topic?: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Publishers for a connection string or a connection, through whichever
|
|
161
|
+
* driver is registered for its scheme — see `registerEventsDriver`.
|
|
162
|
+
*/
|
|
163
|
+
declare class Publisher {
|
|
164
|
+
/**
|
|
165
|
+
* Create a publisher from a connection string
|
|
166
|
+
* This creates both a connection and a publisher
|
|
167
|
+
*
|
|
168
|
+
* @throws {UnregisteredEventsScheme} when the broker's driver is not
|
|
169
|
+
* registered.
|
|
170
|
+
*/
|
|
171
|
+
static fromConnectionString<TMessage extends PublishableMessage<string, any>>(connectionStr: EventPublisherConnectionString, options?: PublisherOptions): Promise<EventPublisher<TMessage>>;
|
|
172
|
+
/**
|
|
173
|
+
* Create a publisher from an existing connection
|
|
174
|
+
* This allows sharing connections between publishers and subscribers
|
|
175
|
+
*/
|
|
176
|
+
static fromConnection<TMessage extends PublishableMessage<string, any>>(connection: EventConnection, options?: PublisherOptions): Promise<EventPublisher<TMessage>>;
|
|
177
|
+
}
|
|
178
|
+
type EventPublisherConnectionString = `${EventPublisherType}://${string}`;
|
|
179
|
+
//#endregion
|
|
180
|
+
//#region src/registry.d.ts
|
|
181
|
+
type AnyMessage = PublishableMessage<string, any>;
|
|
182
|
+
/** How a subscriber built from a connection is used, beyond its address. */
|
|
183
|
+
interface SubscriberOptions {
|
|
184
|
+
/**
|
|
185
|
+
* The topic subscribed to. pg-boss needs it, with {@link subscription}, to
|
|
186
|
+
* give each subscriber a queue of its own; the other brokers carry the topic
|
|
187
|
+
* in their address and ignore it.
|
|
188
|
+
*/
|
|
189
|
+
topic?: string;
|
|
190
|
+
/** The subscriber's name — its own queue on pg-boss. */
|
|
191
|
+
subscription?: string;
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* One broker: the connections, publishers and subscribers for its scheme.
|
|
195
|
+
*
|
|
196
|
+
* A driver owns parsing — the shape of an `sns://` string is SNS's business —
|
|
197
|
+
* and is the only module that imports its broker's client library.
|
|
198
|
+
*/
|
|
199
|
+
interface EventsDriver {
|
|
200
|
+
/**
|
|
201
|
+
* The scheme this driver handles, without the colon — `'pgboss'`, `'sns'`.
|
|
202
|
+
* It is also the `type` of every connection the driver builds, which is how
|
|
203
|
+
* a connection finds its way back here.
|
|
204
|
+
*/
|
|
205
|
+
readonly scheme: `${EventPublisherType}`;
|
|
206
|
+
/** A connection, connected, for a connection string. */
|
|
207
|
+
connect(connectionString: string): Promise<EventConnection>;
|
|
208
|
+
/** A publisher, with a connection of its own, for a connection string. */
|
|
209
|
+
publisher<TMessage extends AnyMessage>(connectionString: string, options: PublisherOptions): Promise<EventPublisher<TMessage>>;
|
|
210
|
+
/** A publisher on a connection this driver built. */
|
|
211
|
+
publisherFor<TMessage extends AnyMessage>(connection: EventConnection, options: PublisherOptions): EventPublisher<TMessage>;
|
|
212
|
+
/** A subscriber, with a connection of its own, for a connection string. */
|
|
213
|
+
subscriber<TMessage extends AnyMessage>(connectionString: string): Promise<EventSubscriber<TMessage>>;
|
|
214
|
+
/** A subscriber on a connection this driver built. */
|
|
215
|
+
subscriberFor<TMessage extends AnyMessage>(connection: EventConnection, options: SubscriberOptions): EventSubscriber<TMessage>;
|
|
216
|
+
}
|
|
217
|
+
/** Make a driver available to `Publisher`, `Subscriber` and friends. Idempotent. */
|
|
218
|
+
declare function registerEventsDriver(driver: EventsDriver): void;
|
|
219
|
+
/** Which schemes are currently registered — the useful half of a failure. */
|
|
220
|
+
declare function registeredEventsSchemes(): string[];
|
|
221
|
+
/**
|
|
222
|
+
* The driver for a scheme — `'pgboss'`, `'pgboss:'`, or a whole connection
|
|
223
|
+
* string, whichever the caller has.
|
|
224
|
+
*
|
|
225
|
+
* @throws {UnregisteredEventsScheme} when the scheme is a broker this package
|
|
226
|
+
* implements but nothing registered its driver.
|
|
227
|
+
* @throws {UnsupportedEventTransport} when no broker here has that scheme.
|
|
228
|
+
*/
|
|
229
|
+
declare function eventsDriverFor(scheme: string, role?: 'publisher' | 'subscriber' | 'connection'): EventsDriver;
|
|
230
|
+
/**
|
|
231
|
+
* A connection string for a broker whose driver nothing registered.
|
|
232
|
+
*
|
|
233
|
+
* The broker exists — this is not a typo'd scheme — but the process was never
|
|
234
|
+
* told about it. Usually a script building its own publisher, or a build that
|
|
235
|
+
* registered the drivers for a different target than the one that composed
|
|
236
|
+
* the connection string.
|
|
237
|
+
*/
|
|
238
|
+
declare class UnregisteredEventsScheme extends Error {
|
|
239
|
+
/** The scheme with no driver, without the colon — `'pgboss'`. */
|
|
240
|
+
readonly scheme: string;
|
|
241
|
+
/** What is registered, so the caller can see what was chosen instead. */
|
|
242
|
+
readonly registered: readonly string[];
|
|
243
|
+
/** The subpath that exports the missing driver. */
|
|
244
|
+
readonly subpath: string;
|
|
245
|
+
/** The driver's export name. */
|
|
246
|
+
readonly driver: string;
|
|
247
|
+
constructor(
|
|
248
|
+
/** The scheme with no driver, without the colon — `'pgboss'`. */
|
|
249
|
+
scheme: string,
|
|
250
|
+
/** What is registered, so the caller can see what was chosen instead. */
|
|
251
|
+
registered: readonly string[]);
|
|
252
|
+
}
|
|
253
|
+
//#endregion
|
|
254
|
+
export { UnsupportedEventTransport as _, registerEventsDriver as a, Publisher as c, EventPublisher as d, EventPublisherType as f, PublishableMessage as g, MappedEvent as h, eventsDriverFor as i, PublisherOptions as l, ExtractPublisherMessage as m, SubscriberOptions as n, registeredEventsSchemes as o, EventSubscriber as p, UnregisteredEventsScheme as r, EventPublisherConnectionString as s, EventsDriver as t, EventConnection as u };
|
|
255
|
+
//# sourceMappingURL=registry-DIx25Q5s.d.mts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry-DIx25Q5s.d.mts","names":[],"sources":["../../../node_modules/.pnpm/@standard-schema+spec@1.1.0/node_modules/@standard-schema/spec/dist/index.d.ts","../src/types.ts","../src/Publisher.ts","../src/registry.ts"],"x_google_ignoreList":[0],"mappings":";;;UACU,gBAAgB,iBAAiB,SAAS;;WAEvC,aAAa,gBAAgB,MAAM,OAAO;;kBAErC;;YAEJ,MAAM,iBAAiB,SAAS;;aAE7B;;aAEA;;aAEA,QAAQ,MAAM,OAAO;;;YAGxB,MAAM,iBAAiB,SAAS;;aAE7B,OAAO;;aAEP,QAAQ;;;OAGhB,WAAW,eAAe,mBAAmB,YAAY;;OAEzD,YAAY,eAAe,mBAAmB,YAAY;;;UAGzD,iBAAiB,iBAAiB,SAAS;;WAExC,aAAa,iBAAiB,MAAM,OAAO;;kBAEtC;;YAEJ,MAAM,iBAAiB,SAAS,eAAe,gBAAgB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,UAAU,iBAAiB,YAC1B,0BACA,SAAS,mBACP,QAAQ,eAAe;;EAE1B,aAAa,iBAAiB,YAC7B,YAAY,iBACZ,SAAS,mBACP,eAAe;;EAElB,WAAW,iBAAiB,YAC3B,2BACE,QAAQ,gBAAgB;;EAE3B,cAAc,iBAAiB,YAC9B,YAAY,iBACZ,SAAS,oBACP,gBAAgB;;;iBA6CJ,qBAAqB,QAAQ;;iBAK7B;;;;;;;;;iBAYA,gBACf,gBACA,mDACE;;;;;;;;;cAyBU,iCAAiC;;WAQnC;;WAEA;;WARD;;WAEA;EAET,YAEU;;EAAA,gBAEA;;EAAA"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { d as UnsupportedEventTransport } from "./telemetry-DjjgJMul.mjs";
|
|
2
|
+
//#region src/registry.ts
|
|
3
|
+
/**
|
|
4
|
+
* Where each built-in driver lives, so a missing one can be named exactly —
|
|
5
|
+
* the subpath to import and the export to register.
|
|
6
|
+
*/
|
|
7
|
+
const BUILT_IN = {
|
|
8
|
+
["basic"]: {
|
|
9
|
+
subpath: "@geekmidas/events/basic",
|
|
10
|
+
driver: "basicEventsDriver"
|
|
11
|
+
},
|
|
12
|
+
["pgboss"]: {
|
|
13
|
+
subpath: "@geekmidas/events/pgboss",
|
|
14
|
+
driver: "pgbossEventsDriver"
|
|
15
|
+
},
|
|
16
|
+
["sns"]: {
|
|
17
|
+
subpath: "@geekmidas/events/sns",
|
|
18
|
+
driver: "snsEventsDriver"
|
|
19
|
+
},
|
|
20
|
+
["sqs"]: {
|
|
21
|
+
subpath: "@geekmidas/events/sqs",
|
|
22
|
+
driver: "sqsEventsDriver"
|
|
23
|
+
},
|
|
24
|
+
["rabbitmq"]: {
|
|
25
|
+
subpath: "@geekmidas/events/rabbitmq",
|
|
26
|
+
driver: "rabbitmqEventsDriver"
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
/**
|
|
30
|
+
* The registry lives on `globalThis`, so one registration is seen by every
|
|
31
|
+
* copy of this module — the ESM and the CJS build of one install, which a
|
|
32
|
+
* process can load side by side, as `Credentials` already has to allow for.
|
|
33
|
+
*/
|
|
34
|
+
const REGISTRY = Symbol.for("@geekmidas/events/drivers");
|
|
35
|
+
function drivers() {
|
|
36
|
+
const global = globalThis;
|
|
37
|
+
global[REGISTRY] ??= /* @__PURE__ */ new Map();
|
|
38
|
+
return global[REGISTRY];
|
|
39
|
+
}
|
|
40
|
+
/** Make a driver available to `Publisher`, `Subscriber` and friends. Idempotent. */
|
|
41
|
+
function registerEventsDriver(driver) {
|
|
42
|
+
drivers().set(driver.scheme, driver);
|
|
43
|
+
}
|
|
44
|
+
/** Which schemes are currently registered — the useful half of a failure. */
|
|
45
|
+
function registeredEventsSchemes() {
|
|
46
|
+
return [...drivers().keys()].sort();
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* The driver for a scheme — `'pgboss'`, `'pgboss:'`, or a whole connection
|
|
50
|
+
* string, whichever the caller has.
|
|
51
|
+
*
|
|
52
|
+
* @throws {UnregisteredEventsScheme} when the scheme is a broker this package
|
|
53
|
+
* implements but nothing registered its driver.
|
|
54
|
+
* @throws {UnsupportedEventTransport} when no broker here has that scheme.
|
|
55
|
+
*/
|
|
56
|
+
function eventsDriverFor(scheme, role = "connection") {
|
|
57
|
+
const name = schemeOf(scheme);
|
|
58
|
+
const driver = drivers().get(name);
|
|
59
|
+
if (driver) return driver;
|
|
60
|
+
if (BUILT_IN[name]) throw new UnregisteredEventsScheme(name, registeredEventsSchemes());
|
|
61
|
+
throw new UnsupportedEventTransport(name, role);
|
|
62
|
+
}
|
|
63
|
+
/** `pgboss` from `pgboss`, `pgboss:` or `pgboss://…`. */
|
|
64
|
+
function schemeOf(value) {
|
|
65
|
+
const separator = value.indexOf(":");
|
|
66
|
+
return separator === -1 ? value : value.slice(0, separator);
|
|
67
|
+
}
|
|
68
|
+
/**
|
|
69
|
+
* A connection string for a broker whose driver nothing registered.
|
|
70
|
+
*
|
|
71
|
+
* The broker exists — this is not a typo'd scheme — but the process was never
|
|
72
|
+
* told about it. Usually a script building its own publisher, or a build that
|
|
73
|
+
* registered the drivers for a different target than the one that composed
|
|
74
|
+
* the connection string.
|
|
75
|
+
*/
|
|
76
|
+
var UnregisteredEventsScheme = class extends Error {
|
|
77
|
+
scheme;
|
|
78
|
+
registered;
|
|
79
|
+
/** The subpath that exports the missing driver. */
|
|
80
|
+
subpath;
|
|
81
|
+
/** The driver's export name. */
|
|
82
|
+
driver;
|
|
83
|
+
constructor(scheme, registered) {
|
|
84
|
+
const { subpath, driver } = BUILT_IN[scheme] ?? {
|
|
85
|
+
subpath: `@geekmidas/events/${scheme}`,
|
|
86
|
+
driver: `${scheme}EventsDriver`
|
|
87
|
+
};
|
|
88
|
+
super(`No events driver is registered for '${scheme}://'. ` + (registered.length ? `Registered: ${registered.join(", ")}. ` : "Nothing is registered. ") + `Register it once where the process starts: import { registerEventsDriver } from '@geekmidas/events'; import { ${driver} } from '${subpath}'; registerEventsDriver(${driver});`);
|
|
89
|
+
this.scheme = scheme;
|
|
90
|
+
this.registered = registered;
|
|
91
|
+
this.name = "UnregisteredEventsScheme";
|
|
92
|
+
this.subpath = subpath;
|
|
93
|
+
this.driver = driver;
|
|
94
|
+
}
|
|
95
|
+
};
|
|
96
|
+
//#endregion
|
|
97
|
+
export { registeredEventsSchemes as i, eventsDriverFor as n, registerEventsDriver as r, UnregisteredEventsScheme as t };
|
|
98
|
+
|
|
99
|
+
//# sourceMappingURL=registry-DXLY1Xf6.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry-DXLY1Xf6.mjs","names":[],"sources":["../src/registry.ts"],"sourcesContent":["/**\n * Events drivers, keyed by connection-string scheme.\n *\n * The same shape `@geekmidas/storage` and `@geekmidas/cache` use, for the same\n * reason: a topic or a queue is handed one connection string, and the scheme in\n * it (`pgboss://`, `sns://`, …) picks the broker. Which brokers exist is the\n * entry point's decision — a generated server registering pg-boss, a Lambda\n * registering SNS and SQS — so a bundle only ever contains the broker its\n * target uses, and never resolves the others' optional peer dependencies.\n *\n * Registration is explicit rather than an import side effect, because a\n * side-effecting module is exactly what a bundler is entitled to drop.\n */\n\nimport type { PublisherOptions } from './Publisher';\nimport type {\n\tEventConnection,\n\tEventPublisher,\n\tEventSubscriber,\n\tPublishableMessage,\n} from './types';\nimport { EventPublisherType, UnsupportedEventTransport } from './types';\n\ntype AnyMessage = PublishableMessage<string, any>;\n\n/** How a subscriber built from a connection is used, beyond its address. */\nexport interface SubscriberOptions {\n\t/**\n\t * The topic subscribed to. pg-boss needs it, with {@link subscription}, to\n\t * give each subscriber a queue of its own; the other brokers carry the topic\n\t * in their address and ignore it.\n\t */\n\ttopic?: string;\n\t/** The subscriber's name — its own queue on pg-boss. */\n\tsubscription?: string;\n}\n\n/**\n * One broker: the connections, publishers and subscribers for its scheme.\n *\n * A driver owns parsing — the shape of an `sns://` string is SNS's business —\n * and is the only module that imports its broker's client library.\n */\nexport interface EventsDriver {\n\t/**\n\t * The scheme this driver handles, without the colon — `'pgboss'`, `'sns'`.\n\t * It is also the `type` of every connection the driver builds, which is how\n\t * a connection finds its way back here.\n\t */\n\treadonly scheme: `${EventPublisherType}`;\n\t/** A connection, connected, for a connection string. */\n\tconnect(connectionString: string): Promise<EventConnection>;\n\t/** A publisher, with a connection of its own, for a connection string. */\n\tpublisher<TMessage extends AnyMessage>(\n\t\tconnectionString: string,\n\t\toptions: PublisherOptions,\n\t): Promise<EventPublisher<TMessage>>;\n\t/** A publisher on a connection this driver built. */\n\tpublisherFor<TMessage extends AnyMessage>(\n\t\tconnection: EventConnection,\n\t\toptions: PublisherOptions,\n\t): EventPublisher<TMessage>;\n\t/** A subscriber, with a connection of its own, for a connection string. */\n\tsubscriber<TMessage extends AnyMessage>(\n\t\tconnectionString: string,\n\t): Promise<EventSubscriber<TMessage>>;\n\t/** A subscriber on a connection this driver built. */\n\tsubscriberFor<TMessage extends AnyMessage>(\n\t\tconnection: EventConnection,\n\t\toptions: SubscriberOptions,\n\t): EventSubscriber<TMessage>;\n}\n\n/**\n * Where each built-in driver lives, so a missing one can be named exactly —\n * the subpath to import and the export to register.\n */\nconst BUILT_IN: Readonly<Record<string, { subpath: string; driver: string }>> =\n\t{\n\t\t[EventPublisherType.Basic]: {\n\t\t\tsubpath: '@geekmidas/events/basic',\n\t\t\tdriver: 'basicEventsDriver',\n\t\t},\n\t\t[EventPublisherType.PgBoss]: {\n\t\t\tsubpath: '@geekmidas/events/pgboss',\n\t\t\tdriver: 'pgbossEventsDriver',\n\t\t},\n\t\t[EventPublisherType.SNS]: {\n\t\t\tsubpath: '@geekmidas/events/sns',\n\t\t\tdriver: 'snsEventsDriver',\n\t\t},\n\t\t[EventPublisherType.SQS]: {\n\t\t\tsubpath: '@geekmidas/events/sqs',\n\t\t\tdriver: 'sqsEventsDriver',\n\t\t},\n\t\t[EventPublisherType.RabbitMQ]: {\n\t\t\tsubpath: '@geekmidas/events/rabbitmq',\n\t\t\tdriver: 'rabbitmqEventsDriver',\n\t\t},\n\t};\n\n/**\n * The registry lives on `globalThis`, so one registration is seen by every\n * copy of this module — the ESM and the CJS build of one install, which a\n * process can load side by side, as `Credentials` already has to allow for.\n */\nconst REGISTRY = Symbol.for('@geekmidas/events/drivers');\n\nfunction drivers(): Map<string, EventsDriver> {\n\tconst global = globalThis as { [REGISTRY]?: Map<string, EventsDriver> };\n\tglobal[REGISTRY] ??= new Map();\n\treturn global[REGISTRY];\n}\n\n/** Make a driver available to `Publisher`, `Subscriber` and friends. Idempotent. */\nexport function registerEventsDriver(driver: EventsDriver): void {\n\tdrivers().set(driver.scheme, driver);\n}\n\n/** Which schemes are currently registered — the useful half of a failure. */\nexport function registeredEventsSchemes(): string[] {\n\treturn [...drivers().keys()].sort();\n}\n\n/**\n * The driver for a scheme — `'pgboss'`, `'pgboss:'`, or a whole connection\n * string, whichever the caller has.\n *\n * @throws {UnregisteredEventsScheme} when the scheme is a broker this package\n * implements but nothing registered its driver.\n * @throws {UnsupportedEventTransport} when no broker here has that scheme.\n */\nexport function eventsDriverFor(\n\tscheme: string,\n\trole: 'publisher' | 'subscriber' | 'connection' = 'connection',\n): EventsDriver {\n\tconst name = schemeOf(scheme);\n\tconst driver = drivers().get(name);\n\tif (driver) return driver;\n\n\tif (BUILT_IN[name]) {\n\t\tthrow new UnregisteredEventsScheme(name, registeredEventsSchemes());\n\t}\n\tthrow new UnsupportedEventTransport(name, role);\n}\n\n/** `pgboss` from `pgboss`, `pgboss:` or `pgboss://…`. */\nfunction schemeOf(value: string): string {\n\tconst separator = value.indexOf(':');\n\treturn separator === -1 ? value : value.slice(0, separator);\n}\n\n/**\n * A connection string for a broker whose driver nothing registered.\n *\n * The broker exists — this is not a typo'd scheme — but the process was never\n * told about it. Usually a script building its own publisher, or a build that\n * registered the drivers for a different target than the one that composed\n * the connection string.\n */\nexport class UnregisteredEventsScheme extends Error {\n\t/** The subpath that exports the missing driver. */\n\treadonly subpath: string;\n\t/** The driver's export name. */\n\treadonly driver: string;\n\n\tconstructor(\n\t\t/** The scheme with no driver, without the colon — `'pgboss'`. */\n\t\treadonly scheme: string,\n\t\t/** What is registered, so the caller can see what was chosen instead. */\n\t\treadonly registered: readonly string[],\n\t) {\n\t\tconst { subpath, driver } = BUILT_IN[scheme] ?? {\n\t\t\tsubpath: `@geekmidas/events/${scheme}`,\n\t\t\tdriver: `${scheme}EventsDriver`,\n\t\t};\n\t\tsuper(\n\t\t\t`No events driver is registered for '${scheme}://'. ` +\n\t\t\t\t(registered.length\n\t\t\t\t\t? `Registered: ${registered.join(', ')}. `\n\t\t\t\t\t: 'Nothing is registered. ') +\n\t\t\t\t`Register it once where the process starts: ` +\n\t\t\t\t`import { registerEventsDriver } from '@geekmidas/events'; ` +\n\t\t\t\t`import { ${driver} } from '${subpath}'; ` +\n\t\t\t\t`registerEventsDriver(${driver});`,\n\t\t);\n\t\tthis.name = 'UnregisteredEventsScheme';\n\t\tthis.subpath = subpath;\n\t\tthis.driver = driver;\n\t}\n}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