@geekmidas/events 10.0.0-alpha.71 → 10.0.0-alpha.72
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/basic/index.cjs +19 -0
- 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 +19 -1
- package/dist/basic/index.mjs.map +1 -1
- package/dist/index.cjs +33 -137
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +15 -33
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +15 -33
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +30 -138
- package/dist/index.mjs.map +1 -1
- package/dist/pgboss/index.cjs +38 -21
- package/dist/pgboss/index.cjs.map +1 -1
- package/dist/pgboss/index.d.cts +9 -1
- package/dist/pgboss/index.d.cts.map +1 -1
- package/dist/pgboss/index.d.mts +9 -1
- package/dist/pgboss/index.d.mts.map +1 -1
- package/dist/pgboss/index.mjs +38 -21
- package/dist/pgboss/index.mjs.map +1 -1
- package/dist/rabbitmq/index.cjs +28 -12
- 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 +29 -12
- 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-DLnflkMm.mjs +99 -0
- package/dist/registry-DLnflkMm.mjs.map +1 -0
- package/dist/registry-DNk5GnGq.cjs +122 -0
- package/dist/registry-DNk5GnGq.cjs.map +1 -0
- package/dist/sns/index.cjs +261 -244
- package/dist/sns/index.cjs.map +1 -1
- package/dist/sns/index.d.cts +9 -1
- package/dist/sns/index.d.cts.map +1 -1
- package/dist/sns/index.d.mts +9 -1
- package/dist/sns/index.d.mts.map +1 -1
- package/dist/sns/index.mjs +261 -244
- package/dist/sns/index.mjs.map +1 -1
- package/dist/sqs/index.cjs +21 -0
- package/dist/sqs/index.cjs.map +1 -1
- package/dist/sqs/index.d.cts +9 -1
- package/dist/sqs/index.d.cts.map +1 -1
- package/dist/sqs/index.d.mts +9 -1
- package/dist/sqs/index.d.mts.map +1 -1
- package/dist/sqs/index.mjs +21 -1
- package/dist/sqs/index.mjs.map +1 -1
- package/package.json +3 -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/types-gGaoT8qc.d.cts.map +0 -1
- package/dist/types-gGaoT8qc.d.mts.map +0 -1
|
@@ -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,iBA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KAAK,oBAAoB,eACrB,wBAAwB;EAC7B,QAAQ,KAAK,oBAAoB;;;;;UC1FjB;;;;;;;EAOhB;;;;;;cAOY;;;;;;;;SAQC,qBACZ,iBAAiB,iCAEjB,eAAe,gCACf,UAAS,mBACP,QAAQ,eAAe;;;;;SAYb,eAAe,iBAAiB,iCAC5C,YAAY,iBACZ,UAAS,mBACP,QAAQ,eAAe;;KAQf,oCACR;;;KCrCC,aAAa;;UAGD;;;;;;EAMhB;;EAEA;;;;;;;;UASgB;;;;;;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;;kBA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BAAoB;;;;;UC1FjB;;;;;;;EAOhB;;;;;;cAOY;;;;;;;;SAQC,qBACZ,iBAAiB,iCAEjB,eAAe,gCACf,UAAS,mBACP,QAAQ,eAAe;;;;;SAYb,eAAe,iBAAiB,iCAC5C,YAAY,iBACZ,UAAS,mBACP,QAAQ,eAAe;;KAQf,oCACR;;;KCrCC,aAAa;;UAGD;;;;;;EAMhB;;EAEA;;;;;;;;UASgB;;;;;;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"}
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
import { n as UnsupportedEventTransport } from "./types-Bk5JM6MP.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-DLnflkMm.mjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry-DLnflkMm.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}\n"],"mappings":";;;;;;AA6EA,MAAM,WACL;EAC6B,UAAA;EAC3B,SAAS;EACT,QAAQ;CACT;EAC6B,WAAA;EAC5B,SAAS;EACT,QAAQ;CACT;EAC0B,QAAA;EACzB,SAAS;EACT,QAAQ;CACT;EAC0B,QAAA;EACzB,SAAS;EACT,QAAQ;CACT;EAC+B,aAAA;EAC9B,SAAS;EACT,QAAQ;CACT;AACD;;;;;;AAOD,MAAM,WAAW,OAAO,IAAI,2BAA2B;AAEvD,SAAS,UAAqC;CAC7C,MAAM,SAAS;CACf,OAAO,8BAAc,IAAI,IAAI;CAC7B,OAAO,OAAO;AACf;;AAGA,SAAgB,qBAAqB,QAA4B;CAChE,QAAQ,CAAC,CAAC,IAAI,OAAO,QAAQ,MAAM;AACpC;;AAGA,SAAgB,0BAAoC;CACnD,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;AACnC;;;;;;;;;AAUA,SAAgB,gBACf,QACA,OAAkD,cACnC;CACf,MAAM,OAAO,SAAS,MAAM;CAC5B,MAAM,SAAS,QAAQ,CAAC,CAAC,IAAI,IAAI;CACjC,IAAI,QAAQ,OAAO;CAEnB,IAAI,SAAS,OACZ,MAAM,IAAI,yBAAyB,MAAM,wBAAwB,CAAC;CAEnE,MAAM,IAAI,0BAA0B,MAAM,IAAI;AAC/C;;AAGA,SAAS,SAAS,OAAuB;CACxC,MAAM,YAAY,MAAM,QAAQ,GAAG;CACnC,OAAO,cAAc,KAAK,QAAQ,MAAM,MAAM,GAAG,SAAS;AAC3D;;;;;;;;;AAUA,IAAa,2BAAb,cAA8C,MAAM;CAQzC;CAEA;;CARV;;CAEA;CAEA,YAEC,QAEA,YACC;EACD,MAAM,EAAE,SAAS,WAAW,SAAS,WAAW;GAC/C,SAAS,qBAAqB;GAC9B,QAAQ,GAAG,OAAO;EACnB;EACA,MACC,uCAAuC,OAAO,WAC5C,WAAW,SACT,eAAe,WAAW,KAAK,IAAI,EAAE,MACrC,6BACH,iHAEY,OAAO,WAAW,QAAQ,0BACd,OAAO,GACjC;EAjBS,KAAA,SAAA;EAEA,KAAA,aAAA;EAgBT,KAAK,OAAO;EACZ,KAAK,UAAU;EACf,KAAK,SAAS;CACf;AACD"}
|
|
@@ -0,0 +1,122 @@
|
|
|
1
|
+
const require_types = require("./types-BcZjLxVV.cjs");
|
|
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 require_types.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
|
+
Object.defineProperty(exports, "UnregisteredEventsScheme", {
|
|
98
|
+
enumerable: true,
|
|
99
|
+
get: function() {
|
|
100
|
+
return UnregisteredEventsScheme;
|
|
101
|
+
}
|
|
102
|
+
});
|
|
103
|
+
Object.defineProperty(exports, "eventsDriverFor", {
|
|
104
|
+
enumerable: true,
|
|
105
|
+
get: function() {
|
|
106
|
+
return eventsDriverFor;
|
|
107
|
+
}
|
|
108
|
+
});
|
|
109
|
+
Object.defineProperty(exports, "registerEventsDriver", {
|
|
110
|
+
enumerable: true,
|
|
111
|
+
get: function() {
|
|
112
|
+
return registerEventsDriver;
|
|
113
|
+
}
|
|
114
|
+
});
|
|
115
|
+
Object.defineProperty(exports, "registeredEventsSchemes", {
|
|
116
|
+
enumerable: true,
|
|
117
|
+
get: function() {
|
|
118
|
+
return registeredEventsSchemes;
|
|
119
|
+
}
|
|
120
|
+
});
|
|
121
|
+
|
|
122
|
+
//# sourceMappingURL=registry-DNk5GnGq.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"registry-DNk5GnGq.cjs","names":["UnsupportedEventTransport"],"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}\n"],"mappings":";;;;;;AA6EA,MAAM,WACL;EAC6B,UAAA;EAC3B,SAAS;EACT,QAAQ;CACT;EAC6B,WAAA;EAC5B,SAAS;EACT,QAAQ;CACT;EAC0B,QAAA;EACzB,SAAS;EACT,QAAQ;CACT;EAC0B,QAAA;EACzB,SAAS;EACT,QAAQ;CACT;EAC+B,aAAA;EAC9B,SAAS;EACT,QAAQ;CACT;AACD;;;;;;AAOD,MAAM,WAAW,OAAO,IAAI,2BAA2B;AAEvD,SAAS,UAAqC;CAC7C,MAAM,SAAS;CACf,OAAO,8BAAc,IAAI,IAAI;CAC7B,OAAO,OAAO;AACf;;AAGA,SAAgB,qBAAqB,QAA4B;CAChE,QAAQ,CAAC,CAAC,IAAI,OAAO,QAAQ,MAAM;AACpC;;AAGA,SAAgB,0BAAoC;CACnD,OAAO,CAAC,GAAG,QAAQ,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,KAAK;AACnC;;;;;;;;;AAUA,SAAgB,gBACf,QACA,OAAkD,cACnC;CACf,MAAM,OAAO,SAAS,MAAM;CAC5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