@geekmidas/events 10.0.0-alpha.9 → 10.0.0-alpha.90
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-BEJBfNTe.mjs +264 -0
- package/dist/SQSSubscriber-BEJBfNTe.mjs.map +1 -0
- package/dist/SQSSubscriber-COTqWvOk.cjs +288 -0
- package/dist/SQSSubscriber-COTqWvOk.cjs.map +1 -0
- package/dist/basic/index.cjs +41 -11
- package/dist/basic/index.cjs.map +1 -1
- package/dist/basic/index.d.cts +11 -10
- package/dist/basic/index.d.cts.map +1 -1
- package/dist/basic/index.d.mts +11 -10
- package/dist/basic/index.d.mts.map +1 -1
- package/dist/basic/index.mjs +39 -10
- package/dist/basic/index.mjs.map +1 -1
- package/dist/index.cjs +47 -151
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.cts +82 -26
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +82 -26
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +34 -151
- package/dist/index.mjs.map +1 -1
- package/dist/pgboss/index.cjs +198 -34
- package/dist/pgboss/index.cjs.map +1 -1
- package/dist/pgboss/index.d.cts +54 -12
- package/dist/pgboss/index.d.cts.map +1 -1
- package/dist/pgboss/index.d.mts +54 -12
- package/dist/pgboss/index.d.mts.map +1 -1
- package/dist/pgboss/index.mjs +193 -34
- package/dist/pgboss/index.mjs.map +1 -1
- package/dist/rabbitmq/index.cjs +173 -27
- package/dist/rabbitmq/index.cjs.map +1 -1
- package/dist/rabbitmq/index.d.cts +19 -10
- package/dist/rabbitmq/index.d.cts.map +1 -1
- package/dist/rabbitmq/index.d.mts +19 -10
- package/dist/rabbitmq/index.d.mts.map +1 -1
- package/dist/rabbitmq/index.mjs +169 -27
- package/dist/rabbitmq/index.mjs.map +1 -1
- package/dist/registry-DIx25Q5s.d.cts +255 -0
- package/dist/registry-DIx25Q5s.d.cts.map +1 -0
- package/dist/registry-DIx25Q5s.d.mts +255 -0
- 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/{chunk-CsX-DzYB.cjs → rolldown-runtime-C0BPl7ul.cjs} +17 -16
- package/dist/rolldown-runtime-D7D4PA-g.mjs +13 -0
- package/dist/sns/index.cjs +403 -40
- package/dist/sns/index.cjs.map +1 -1
- package/dist/sns/index.d.cts +175 -11
- package/dist/sns/index.d.cts.map +1 -1
- package/dist/sns/index.d.mts +175 -11
- package/dist/sns/index.d.mts.map +1 -1
- package/dist/sns/index.mjs +372 -24
- package/dist/sns/index.mjs.map +1 -1
- package/dist/sns/snsUrl.cjs +91 -6
- package/dist/sns/snsUrl.cjs.map +1 -0
- package/dist/sns/snsUrl.d.cts +57 -2
- package/dist/sns/snsUrl.d.cts.map +1 -0
- package/dist/sns/snsUrl.d.mts +57 -2
- package/dist/sns/snsUrl.d.mts.map +1 -0
- package/dist/sns/snsUrl.mjs +81 -2
- package/dist/sns/snsUrl.mjs.map +1 -0
- package/dist/sqs/index.cjs +31 -65
- package/dist/sqs/index.cjs.map +1 -1
- package/dist/sqs/index.d.cts +28 -11
- package/dist/sqs/index.d.cts.map +1 -1
- package/dist/sqs/index.d.mts +28 -11
- package/dist/sqs/index.d.mts.map +1 -1
- package/dist/sqs/index.mjs +22 -58
- package/dist/sqs/index.mjs.map +1 -1
- package/dist/sqs/sqsUrl.cjs +92 -6
- package/dist/sqs/sqsUrl.cjs.map +1 -0
- package/dist/sqs/sqsUrl.d.cts +56 -2
- package/dist/sqs/sqsUrl.d.cts.map +1 -0
- package/dist/sqs/sqsUrl.d.mts +56 -2
- package/dist/sqs/sqsUrl.d.mts.map +1 -0
- package/dist/sqs/sqsUrl.mjs +82 -2
- package/dist/sqs/sqsUrl.mjs.map +1 -0
- 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-23soZ_aM.cjs +0 -80
- package/dist/PgBossConnection-23soZ_aM.cjs.map +0 -1
- package/dist/PgBossConnection-CCXhoNzb.cjs +0 -4
- package/dist/PgBossConnection-DvNbd4Zk.mjs +0 -74
- package/dist/PgBossConnection-DvNbd4Zk.mjs.map +0 -1
- package/dist/PgBossConnection-_gdM40JB.mjs +0 -4
- package/dist/RabbitMQConnection-BKEdCUro.cjs +0 -113
- package/dist/RabbitMQConnection-BKEdCUro.cjs.map +0 -1
- package/dist/RabbitMQConnection-CCOqDDnb.cjs +0 -4
- package/dist/RabbitMQConnection-DJEyM-Bu.mjs +0 -4
- package/dist/RabbitMQConnection-DJgUPc19.mjs +0 -107
- package/dist/RabbitMQConnection-DJgUPc19.mjs.map +0 -1
- package/dist/SNSConnection-B2K86hpz.cjs +0 -75
- package/dist/SNSConnection-B2K86hpz.cjs.map +0 -1
- package/dist/SNSConnection-BVo84FeW.mjs +0 -5
- package/dist/SNSConnection-DIHRjrQF.cjs +0 -5
- package/dist/SNSConnection-v9jjF99w.mjs +0 -69
- package/dist/SNSConnection-v9jjF99w.mjs.map +0 -1
- package/dist/SQSConnection-4tBMkVZE.mjs +0 -69
- package/dist/SQSConnection-4tBMkVZE.mjs.map +0 -1
- package/dist/SQSConnection-BBLAvF-1.cjs +0 -5
- package/dist/SQSConnection-BaC7rGhI.cjs +0 -75
- package/dist/SQSConnection-BaC7rGhI.cjs.map +0 -1
- package/dist/SQSConnection-DbavOq8_.mjs +0 -5
- package/dist/SQSSubscriber-BMWZ3s5q.mjs +0 -114
- package/dist/SQSSubscriber-BMWZ3s5q.mjs.map +0 -1
- package/dist/SQSSubscriber-YXPlg2rm.cjs +0 -120
- package/dist/SQSSubscriber-YXPlg2rm.cjs.map +0 -1
- package/dist/chunk-B9dir_RE.mjs +0 -11
- package/dist/snsUrl-ASdc0D1v.d.cts +0 -61
- package/dist/snsUrl-ASdc0D1v.d.cts.map +0 -1
- package/dist/snsUrl-CifYhPAa.mjs +0 -79
- package/dist/snsUrl-CifYhPAa.mjs.map +0 -1
- package/dist/snsUrl-FRbRcwF0.d.mts +0 -61
- package/dist/snsUrl-FRbRcwF0.d.mts.map +0 -1
- package/dist/snsUrl-f2gU3CzK.cjs +0 -114
- package/dist/snsUrl-f2gU3CzK.cjs.map +0 -1
- package/dist/sqsUrl-BV6zS-mi.d.mts +0 -60
- package/dist/sqsUrl-BV6zS-mi.d.mts.map +0 -1
- package/dist/sqsUrl-CbAsBFHI.mjs +0 -80
- package/dist/sqsUrl-CbAsBFHI.mjs.map +0 -1
- package/dist/sqsUrl-CdisN3GU.cjs +0 -115
- package/dist/sqsUrl-CdisN3GU.cjs.map +0 -1
- package/dist/sqsUrl-DZDPHxIk.d.cts +0 -60
- package/dist/sqsUrl-DZDPHxIk.d.cts.map +0 -1
- package/dist/types-BmixGrOD.d.cts +0 -67
- package/dist/types-BmixGrOD.d.cts.map +0 -1
- package/dist/types-Byv8N9ma.cjs +0 -24
- package/dist/types-Byv8N9ma.cjs.map +0 -1
- package/dist/types-CYDt-2RQ.mjs +0 -18
- package/dist/types-CYDt-2RQ.mjs.map +0 -1
- package/dist/types-DycjsYms.d.mts +0 -67
- package/dist/types-DycjsYms.d.mts.map +0 -1
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { InferStandardSchema } from "@geekmidas/schema";
|
|
2
|
+
//#region ../../node_modules/.pnpm/@standard-schema+spec@1.1.0/node_modules/@standard-schema/spec/dist/index.d.ts
|
|
3
|
+
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
4
|
+
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
5
|
+
/** The Standard properties. */
|
|
6
|
+
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
|
7
|
+
}
|
|
8
|
+
declare namespace StandardTypedV1 {
|
|
9
|
+
/** The Standard Typed properties interface. */
|
|
10
|
+
interface Props<Input = unknown, Output = Input> {
|
|
11
|
+
/** The version number of the standard. */
|
|
12
|
+
readonly version: 1;
|
|
13
|
+
/** The vendor name of the schema library. */
|
|
14
|
+
readonly vendor: string;
|
|
15
|
+
/** Inferred types associated with the schema. */
|
|
16
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
17
|
+
}
|
|
18
|
+
/** The Standard Typed types interface. */
|
|
19
|
+
interface Types<Input = unknown, Output = Input> {
|
|
20
|
+
/** The input type of the schema. */
|
|
21
|
+
readonly input: Input;
|
|
22
|
+
/** The output type of the schema. */
|
|
23
|
+
readonly output: Output;
|
|
24
|
+
}
|
|
25
|
+
/** Infers the input type of a Standard Typed. */
|
|
26
|
+
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
27
|
+
/** Infers the output type of a Standard Typed. */
|
|
28
|
+
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
29
|
+
}
|
|
30
|
+
/** The Standard Schema interface. */
|
|
31
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
32
|
+
/** The Standard Schema properties. */
|
|
33
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
34
|
+
}
|
|
35
|
+
declare namespace StandardSchemaV1 {
|
|
36
|
+
/** The Standard Schema properties interface. */
|
|
37
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
38
|
+
/** Validates unknown input values. */
|
|
39
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
40
|
+
}
|
|
41
|
+
/** The result interface of the validate function. */
|
|
42
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
43
|
+
/** The result interface if validation succeeds. */
|
|
44
|
+
interface SuccessResult<Output> {
|
|
45
|
+
/** The typed output value. */
|
|
46
|
+
readonly value: Output;
|
|
47
|
+
/** A falsy value for `issues` indicates success. */
|
|
48
|
+
readonly issues?: undefined;
|
|
49
|
+
}
|
|
50
|
+
interface Options {
|
|
51
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
52
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
53
|
+
}
|
|
54
|
+
/** The result interface if validation fails. */
|
|
55
|
+
interface FailureResult {
|
|
56
|
+
/** The issues of failed validation. */
|
|
57
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
58
|
+
}
|
|
59
|
+
/** The issue interface of the failure output. */
|
|
60
|
+
interface Issue {
|
|
61
|
+
/** The error message of the issue. */
|
|
62
|
+
readonly message: string;
|
|
63
|
+
/** The path of the issue, if any. */
|
|
64
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
65
|
+
}
|
|
66
|
+
/** The path segment interface of the issue. */
|
|
67
|
+
interface PathSegment {
|
|
68
|
+
/** The key representing a path segment. */
|
|
69
|
+
readonly key: PropertyKey;
|
|
70
|
+
}
|
|
71
|
+
/** The Standard types interface. */
|
|
72
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
|
|
73
|
+
/** Infers the input type of a Standard. */
|
|
74
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
75
|
+
/** Infers the output type of a Standard. */
|
|
76
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/types.d.ts
|
|
80
|
+
/**
|
|
81
|
+
* Represents a publishable event message with a type and payload.
|
|
82
|
+
*
|
|
83
|
+
* @template TType - The event type/name (e.g., 'user.created')
|
|
84
|
+
* @template TPayload - The event payload data
|
|
85
|
+
*/
|
|
86
|
+
type PublishableMessage<TType extends string, TPayload> = {
|
|
87
|
+
type: TType;
|
|
88
|
+
payload: TPayload;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Event publisher/subscriber types
|
|
92
|
+
*/
|
|
93
|
+
declare enum EventPublisherType {
|
|
94
|
+
Basic = "basic",
|
|
95
|
+
EventBridge = "eventbridge",
|
|
96
|
+
SQS = "sqs",
|
|
97
|
+
SNS = "sns",
|
|
98
|
+
Kafka = "kafka",
|
|
99
|
+
RabbitMQ = "rabbitmq",
|
|
100
|
+
PgBoss = "pgboss"
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* A connection string or connection whose transport nothing here implements —
|
|
104
|
+
* a typo'd scheme, or one of the listed-but-unbuilt ones (EventBridge, Kafka).
|
|
105
|
+
*/
|
|
106
|
+
declare class UnsupportedEventTransport extends Error {
|
|
107
|
+
readonly transport: string;
|
|
108
|
+
readonly role: 'publisher' | 'subscriber' | 'connection';
|
|
109
|
+
constructor(transport: string, role: 'publisher' | 'subscriber' | 'connection');
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Base interface for event connections
|
|
113
|
+
* Connections manage the underlying transport (RabbitMQ channel, SQS client, etc.)
|
|
114
|
+
*/
|
|
115
|
+
interface EventConnection {
|
|
116
|
+
readonly type: EventPublisherType;
|
|
117
|
+
connect(): Promise<void>;
|
|
118
|
+
close(): Promise<void>;
|
|
119
|
+
isConnected(): boolean;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Interface for event publishers that handle the actual publishing of events.
|
|
123
|
+
* Implementations can send to EventBridge, SQS, Kafka, or any other event system.
|
|
124
|
+
*
|
|
125
|
+
* @template TMessage - The union type of all publishable messages
|
|
126
|
+
*/
|
|
127
|
+
type EventPublisher<TMessage extends PublishableMessage<string, any>> = {
|
|
128
|
+
publish: (message: TMessage[]) => Promise<void>;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Interface for event subscribers that handle receiving and processing events.
|
|
132
|
+
*
|
|
133
|
+
* @template TMessage - The union type of all publishable messages
|
|
134
|
+
*/
|
|
135
|
+
type EventSubscriber<TMessage extends PublishableMessage<string, any>> = {
|
|
136
|
+
subscribe: (messages: TMessage['type'][], listener: (payload: TMessage) => Promise<void>) => Promise<void>;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Utility type to extract the message from EventPublisher
|
|
140
|
+
*/
|
|
141
|
+
type ExtractPublisherMessage<T> = T extends EventPublisher<infer M> ? M : never;
|
|
142
|
+
type MappedEvent<T extends EventPublisher<any> | undefined, OutSchema extends StandardSchemaV1 | undefined = undefined> = {
|
|
143
|
+
type: ExtractPublisherMessage<T>['type'];
|
|
144
|
+
payload: (ctx: InferStandardSchema<OutSchema>) => ExtractPublisherMessage<T>['payload'];
|
|
145
|
+
when?: (ctx: InferStandardSchema<OutSchema>) => boolean;
|
|
146
|
+
};
|
|
147
|
+
//#endregion
|
|
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;;kBAEtC;;YAEJ,MAAM,iBAAiB,SAAS,eAAe,gBAAgB,MAAM,OAAO;;aAEzE,WAAW,gBAAgB,UAAU,iBAAiB,wBAAwB,OAAO,UAAU,QAAQ,OAAO;;;OAGtH,OAAO,UAAU,cAAc,UAAU;;YAEpC,cAAc;;aAEX,OAAO;;aAEP;;YAEH;;aAEG,iBAAiB;;;YAGpB;;aAEG,QAAQ,cAAc;;;YAGzB;;aAEG;;aAEA,OAAO,cAAc,cAAc;;;YAGtC;;aAEG,KAAK;;;YAGR,MAAM,iBAAiB,SAAS,eAAe,gBAAgB,MAAM,OAAO;;OAGjF,WAAW,eAAe,mBAAmB,gBAAgB,WAAW;;OAExE,YAAY,eAAe,mBAAmB,gBAAgB,YAAY;;;;;;;;;;KCjEvE,mBAAmB,sBAAsB;EACpD,MAAM;EACN,SAAS;;;;;aAME;EACX;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;cAgBY,kCAAkC;WAEpC;WACA;EAFV,YACU,mBACA;;;;;;UAaM;WACP,MAAM;EACf,WAAW;EACX,SAAS;EACT;;;;;;;;KASW,eAAe,iBAAiB;EAC3C,UAAU,SAAS,eAAe;;;;;;;KAQvB,gBAAgB,iBAAiB;EAE3C,YACC,UAAU,oBACV,WAAW,SAAS,aAAa,kBAC7B;;;;;KAKK,wBAAwB,KACnC,UAAU,qBAAqB,KAAK;KAEzB,YACX,UAAU,iCACV,kBAAkB;EAElB,MAAM,wBAAwB;EAC9B,UACC,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"}
|
|
@@ -0,0 +1,255 @@
|
|
|
1
|
+
import { InferStandardSchema } from "@geekmidas/schema";
|
|
2
|
+
//#region ../../node_modules/.pnpm/@standard-schema+spec@1.1.0/node_modules/@standard-schema/spec/dist/index.d.ts
|
|
3
|
+
/** The Standard Typed interface. This is a base type extended by other specs. */
|
|
4
|
+
interface StandardTypedV1<Input = unknown, Output = Input> {
|
|
5
|
+
/** The Standard properties. */
|
|
6
|
+
readonly "~standard": StandardTypedV1.Props<Input, Output>;
|
|
7
|
+
}
|
|
8
|
+
declare namespace StandardTypedV1 {
|
|
9
|
+
/** The Standard Typed properties interface. */
|
|
10
|
+
interface Props<Input = unknown, Output = Input> {
|
|
11
|
+
/** The version number of the standard. */
|
|
12
|
+
readonly version: 1;
|
|
13
|
+
/** The vendor name of the schema library. */
|
|
14
|
+
readonly vendor: string;
|
|
15
|
+
/** Inferred types associated with the schema. */
|
|
16
|
+
readonly types?: Types<Input, Output> | undefined;
|
|
17
|
+
}
|
|
18
|
+
/** The Standard Typed types interface. */
|
|
19
|
+
interface Types<Input = unknown, Output = Input> {
|
|
20
|
+
/** The input type of the schema. */
|
|
21
|
+
readonly input: Input;
|
|
22
|
+
/** The output type of the schema. */
|
|
23
|
+
readonly output: Output;
|
|
24
|
+
}
|
|
25
|
+
/** Infers the input type of a Standard Typed. */
|
|
26
|
+
type InferInput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["input"];
|
|
27
|
+
/** Infers the output type of a Standard Typed. */
|
|
28
|
+
type InferOutput<Schema extends StandardTypedV1> = NonNullable<Schema["~standard"]["types"]>["output"];
|
|
29
|
+
}
|
|
30
|
+
/** The Standard Schema interface. */
|
|
31
|
+
interface StandardSchemaV1<Input = unknown, Output = Input> {
|
|
32
|
+
/** The Standard Schema properties. */
|
|
33
|
+
readonly "~standard": StandardSchemaV1.Props<Input, Output>;
|
|
34
|
+
}
|
|
35
|
+
declare namespace StandardSchemaV1 {
|
|
36
|
+
/** The Standard Schema properties interface. */
|
|
37
|
+
interface Props<Input = unknown, Output = Input> extends StandardTypedV1.Props<Input, Output> {
|
|
38
|
+
/** Validates unknown input values. */
|
|
39
|
+
readonly validate: (value: unknown, options?: StandardSchemaV1.Options | undefined) => Result<Output> | Promise<Result<Output>>;
|
|
40
|
+
}
|
|
41
|
+
/** The result interface of the validate function. */
|
|
42
|
+
type Result<Output> = SuccessResult<Output> | FailureResult;
|
|
43
|
+
/** The result interface if validation succeeds. */
|
|
44
|
+
interface SuccessResult<Output> {
|
|
45
|
+
/** The typed output value. */
|
|
46
|
+
readonly value: Output;
|
|
47
|
+
/** A falsy value for `issues` indicates success. */
|
|
48
|
+
readonly issues?: undefined;
|
|
49
|
+
}
|
|
50
|
+
interface Options {
|
|
51
|
+
/** Explicit support for additional vendor-specific parameters, if needed. */
|
|
52
|
+
readonly libraryOptions?: Record<string, unknown> | undefined;
|
|
53
|
+
}
|
|
54
|
+
/** The result interface if validation fails. */
|
|
55
|
+
interface FailureResult {
|
|
56
|
+
/** The issues of failed validation. */
|
|
57
|
+
readonly issues: ReadonlyArray<Issue>;
|
|
58
|
+
}
|
|
59
|
+
/** The issue interface of the failure output. */
|
|
60
|
+
interface Issue {
|
|
61
|
+
/** The error message of the issue. */
|
|
62
|
+
readonly message: string;
|
|
63
|
+
/** The path of the issue, if any. */
|
|
64
|
+
readonly path?: ReadonlyArray<PropertyKey | PathSegment> | undefined;
|
|
65
|
+
}
|
|
66
|
+
/** The path segment interface of the issue. */
|
|
67
|
+
interface PathSegment {
|
|
68
|
+
/** The key representing a path segment. */
|
|
69
|
+
readonly key: PropertyKey;
|
|
70
|
+
}
|
|
71
|
+
/** The Standard types interface. */
|
|
72
|
+
interface Types<Input = unknown, Output = Input> extends StandardTypedV1.Types<Input, Output> {}
|
|
73
|
+
/** Infers the input type of a Standard. */
|
|
74
|
+
type InferInput<Schema extends StandardTypedV1> = StandardTypedV1.InferInput<Schema>;
|
|
75
|
+
/** Infers the output type of a Standard. */
|
|
76
|
+
type InferOutput<Schema extends StandardTypedV1> = StandardTypedV1.InferOutput<Schema>;
|
|
77
|
+
}
|
|
78
|
+
//#endregion
|
|
79
|
+
//#region src/types.d.ts
|
|
80
|
+
/**
|
|
81
|
+
* Represents a publishable event message with a type and payload.
|
|
82
|
+
*
|
|
83
|
+
* @template TType - The event type/name (e.g., 'user.created')
|
|
84
|
+
* @template TPayload - The event payload data
|
|
85
|
+
*/
|
|
86
|
+
type PublishableMessage<TType extends string, TPayload> = {
|
|
87
|
+
type: TType;
|
|
88
|
+
payload: TPayload;
|
|
89
|
+
};
|
|
90
|
+
/**
|
|
91
|
+
* Event publisher/subscriber types
|
|
92
|
+
*/
|
|
93
|
+
declare enum EventPublisherType {
|
|
94
|
+
Basic = "basic",
|
|
95
|
+
EventBridge = "eventbridge",
|
|
96
|
+
SQS = "sqs",
|
|
97
|
+
SNS = "sns",
|
|
98
|
+
Kafka = "kafka",
|
|
99
|
+
RabbitMQ = "rabbitmq",
|
|
100
|
+
PgBoss = "pgboss"
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* A connection string or connection whose transport nothing here implements —
|
|
104
|
+
* a typo'd scheme, or one of the listed-but-unbuilt ones (EventBridge, Kafka).
|
|
105
|
+
*/
|
|
106
|
+
declare class UnsupportedEventTransport extends Error {
|
|
107
|
+
readonly transport: string;
|
|
108
|
+
readonly role: 'publisher' | 'subscriber' | 'connection';
|
|
109
|
+
constructor(transport: string, role: 'publisher' | 'subscriber' | 'connection');
|
|
110
|
+
}
|
|
111
|
+
/**
|
|
112
|
+
* Base interface for event connections
|
|
113
|
+
* Connections manage the underlying transport (RabbitMQ channel, SQS client, etc.)
|
|
114
|
+
*/
|
|
115
|
+
interface EventConnection {
|
|
116
|
+
readonly type: EventPublisherType;
|
|
117
|
+
connect(): Promise<void>;
|
|
118
|
+
close(): Promise<void>;
|
|
119
|
+
isConnected(): boolean;
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Interface for event publishers that handle the actual publishing of events.
|
|
123
|
+
* Implementations can send to EventBridge, SQS, Kafka, or any other event system.
|
|
124
|
+
*
|
|
125
|
+
* @template TMessage - The union type of all publishable messages
|
|
126
|
+
*/
|
|
127
|
+
type EventPublisher<TMessage extends PublishableMessage<string, any>> = {
|
|
128
|
+
publish: (message: TMessage[]) => Promise<void>;
|
|
129
|
+
};
|
|
130
|
+
/**
|
|
131
|
+
* Interface for event subscribers that handle receiving and processing events.
|
|
132
|
+
*
|
|
133
|
+
* @template TMessage - The union type of all publishable messages
|
|
134
|
+
*/
|
|
135
|
+
type EventSubscriber<TMessage extends PublishableMessage<string, any>> = {
|
|
136
|
+
subscribe: (messages: TMessage['type'][], listener: (payload: TMessage) => Promise<void>) => Promise<void>;
|
|
137
|
+
};
|
|
138
|
+
/**
|
|
139
|
+
* Utility type to extract the message from EventPublisher
|
|
140
|
+
*/
|
|
141
|
+
type ExtractPublisherMessage<T> = T extends EventPublisher<infer M> ? M : never;
|
|
142
|
+
type MappedEvent<T extends EventPublisher<any> | undefined, OutSchema extends StandardSchemaV1 | undefined = undefined> = {
|
|
143
|
+
type: ExtractPublisherMessage<T>['type'];
|
|
144
|
+
payload: (ctx: InferStandardSchema<OutSchema>) => ExtractPublisherMessage<T>['payload'];
|
|
145
|
+
when?: (ctx: InferStandardSchema<OutSchema>) => boolean;
|
|
146
|
+
};
|
|
147
|
+
//#endregion
|
|
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,MAAM,OAAO;;aAEzE,WAAW,gBAAgB,UAAU,iBAAiB,wBAAwB,OAAO,UAAU,QAAQ,OAAO;;;OAGtH,OAAO,UAAU,cAAc,UAAU;;YAEpC,cAAc;;aAEX,OAAO;;aAEP;;YAEH;;aAEG,iBAAiB;;;YAGpB;;aAEG,QAAQ,cAAc;;;YAGzB;;aAEG;;aAEA,OAAO,cAAc,cAAc;;;YAGtC;;aAEG,KAAK;;;YAGR,MAAM,iBAAiB,SAAS,eAAe,gBAAgB,MAAM,OAAO;;OAGjF,WAAW,eAAe,mBAAmB,gBAAgB,WAAW;;OAExE,YAAY,eAAe,mBAAmB,gBAAgB,YAAY;;;;;;;;;;KCjEvE,mBAAmB,sBAAsB;EACpD,MAAM;EACN,SAAS;;;;;aAME;EACX;EACA;EACA;EACA;EACA;EACA;EACA;;;;;;cAgBY,kCAAkC;WAEpC;WACA;EAFV,YACU,mBACA;;;;;;UAaM;WACP,MAAM;EACf,WAAW;EACX,SAAS;EACT;;;;;;;;KASW,eAAe,iBAAiB;EAC3C,UAAU,SAAS,eAAe;;;;;;;KAQvB,gBAAgB,iBAAiB;EAE3C,YACC,UAAU,oBACV,WAAW,SAAS,aAAa,kBAC7B;;;;;KAKK,wBAAwB,KACnC,UAAU,qBAAqB,KAAK;KAEzB,YACX,UAAU,iCACV,kBAAkB;EAElB,MAAM,wBAAwB;EAC9B,UACC,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"}
|
|
@@ -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}\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"}
|