@geekmidas/events 10.0.0-alpha.79 → 10.0.0-alpha.80
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/dist/{SQSSubscriber-BXLE_1L3.mjs → SQSSubscriber-BEJBfNTe.mjs} +94 -10
- package/dist/SQSSubscriber-BEJBfNTe.mjs.map +1 -0
- package/dist/{SQSSubscriber-DtRUaZB3.cjs → SQSSubscriber-COTqWvOk.cjs} +101 -10
- package/dist/SQSSubscriber-COTqWvOk.cjs.map +1 -0
- package/dist/basic/index.cjs +16 -4
- package/dist/basic/index.cjs.map +1 -1
- package/dist/basic/index.d.cts.map +1 -1
- package/dist/basic/index.d.mts.map +1 -1
- package/dist/basic/index.mjs +16 -4
- package/dist/basic/index.mjs.map +1 -1
- package/dist/index.cjs +11 -4
- package/dist/index.d.cts +60 -1
- package/dist/index.d.cts.map +1 -1
- package/dist/index.d.mts +60 -1
- package/dist/index.d.mts.map +1 -1
- package/dist/index.mjs +3 -3
- package/dist/pgboss/index.cjs +50 -22
- package/dist/pgboss/index.cjs.map +1 -1
- package/dist/pgboss/index.d.cts.map +1 -1
- package/dist/pgboss/index.d.mts.map +1 -1
- package/dist/pgboss/index.mjs +50 -22
- package/dist/pgboss/index.mjs.map +1 -1
- package/dist/rabbitmq/index.cjs +32 -15
- package/dist/rabbitmq/index.cjs.map +1 -1
- package/dist/rabbitmq/index.d.cts.map +1 -1
- package/dist/rabbitmq/index.d.mts.map +1 -1
- package/dist/rabbitmq/index.mjs +32 -15
- package/dist/rabbitmq/index.mjs.map +1 -1
- package/dist/{registry-DLnflkMm.mjs → registry-DXLY1Xf6.mjs} +2 -2
- package/dist/{registry-DLnflkMm.mjs.map → registry-DXLY1Xf6.mjs.map} +1 -1
- package/dist/{registry-DNk5GnGq.cjs → registry-DlT36229.cjs} +3 -3
- package/dist/{registry-DNk5GnGq.cjs.map → registry-DlT36229.cjs.map} +1 -1
- package/dist/sns/index.cjs +17 -8
- package/dist/sns/index.cjs.map +1 -1
- package/dist/sns/index.d.cts.map +1 -1
- package/dist/sns/index.d.mts.map +1 -1
- package/dist/sns/index.mjs +17 -8
- package/dist/sns/index.mjs.map +1 -1
- package/dist/sqs/index.cjs +7 -72
- package/dist/sqs/index.cjs.map +1 -1
- package/dist/sqs/index.d.cts +1 -0
- package/dist/sqs/index.d.cts.map +1 -1
- package/dist/sqs/index.d.mts +1 -0
- package/dist/sqs/index.d.mts.map +1 -1
- package/dist/sqs/index.mjs +3 -66
- package/dist/sqs/index.mjs.map +1 -1
- package/dist/telemetry-DG3l807O.cjs +309 -0
- package/dist/telemetry-DG3l807O.cjs.map +1 -0
- package/dist/telemetry-DjjgJMul.mjs +244 -0
- package/dist/telemetry-DjjgJMul.mjs.map +1 -0
- package/package.json +5 -3
- package/dist/SQSSubscriber-BXLE_1L3.mjs.map +0 -1
- package/dist/SQSSubscriber-DtRUaZB3.cjs.map +0 -1
- package/dist/types-BcZjLxVV.cjs +0 -51
- package/dist/types-BcZjLxVV.cjs.map +0 -1
- package/dist/types-Bk5JM6MP.mjs +0 -40
- package/dist/types-Bk5JM6MP.mjs.map +0 -1
package/dist/index.d.cts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { _ as UnsupportedEventTransport, a as registerEventsDriver, c as Publisher, d as EventPublisher, f as EventPublisherType, g as PublishableMessage, h as MappedEvent, i as eventsDriverFor, l as PublisherOptions, m as ExtractPublisherMessage, n as SubscriberOptions, o as registeredEventsSchemes, p as EventSubscriber, r as UnregisteredEventsScheme, s as EventPublisherConnectionString, t as EventsDriver, u as EventConnection } from "./registry-DIx25Q5s.cjs";
|
|
2
|
+
import { Context } from "@opentelemetry/api";
|
|
2
3
|
//#region src/EventConnection.d.ts
|
|
3
4
|
export declare class EventConnectionFactory {
|
|
4
5
|
/**
|
|
@@ -39,5 +40,63 @@ export declare class Subscriber {
|
|
|
39
40
|
}
|
|
40
41
|
type EventSubscriberConnectionString = `${EventPublisherType}://${string}`;
|
|
41
42
|
//#endregion
|
|
42
|
-
|
|
43
|
+
//#region src/telemetry.d.ts
|
|
44
|
+
/**
|
|
45
|
+
* The key a trace context travels under where a broker has no header field of
|
|
46
|
+
* its own — a pg-boss job's data. Reserved: it is removed before a handler sees
|
|
47
|
+
* the payload, and a payload of the application's own should not use it.
|
|
48
|
+
*/
|
|
49
|
+
export declare const TRACE_CONTEXT_KEY = "__gkmTrace";
|
|
50
|
+
/** A propagated trace context: `traceparent`, and `tracestate` when set. */
|
|
51
|
+
type TraceCarrier = Record<string, string>;
|
|
52
|
+
/** What a message is, as its spans describe it. */
|
|
53
|
+
interface MessagingTarget {
|
|
54
|
+
/** `messaging.system`: `pgboss`, `aws_sqs`, `aws_sns`, `rabbitmq`, `basic`. */
|
|
55
|
+
system: string;
|
|
56
|
+
/** The queue or topic — `messaging.destination.name`. */
|
|
57
|
+
destination: string;
|
|
58
|
+
/** The event's type, when the message has one. */
|
|
59
|
+
type?: string;
|
|
60
|
+
/** The broker's id for the message, when it has one. */
|
|
61
|
+
messageId?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Publish `items`, each with a PRODUCER span of its own, through `send` —
|
|
65
|
+
* which receives the carrier to attach to each item, in order.
|
|
66
|
+
*/
|
|
67
|
+
export declare function publishTraced<T, R>(items: readonly T[], describe: (item: T) => MessagingTarget, send: (carriers: (TraceCarrier | undefined)[]) => Promise<R>): Promise<R>;
|
|
68
|
+
/**
|
|
69
|
+
* The context a carrier holds, or undefined when it holds none — no carrier, a
|
|
70
|
+
* malformed `traceparent`, or a propagator that throws.
|
|
71
|
+
*/
|
|
72
|
+
export declare function extractTraceContext(carrier: TraceCarrier | undefined): Context | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Run `fn` inside a CONSUMER span for one message: a child of the context the
|
|
75
|
+
* message carried, or a new trace when it carried none. The active context of
|
|
76
|
+
* the poller that received it is never the parent — a job is not part of
|
|
77
|
+
* whatever happened to start the poll loop.
|
|
78
|
+
*/
|
|
79
|
+
export declare function consumeTraced<R>(target: MessagingTarget, carrier: TraceCarrier | undefined, fn: () => Promise<R>): Promise<R>;
|
|
80
|
+
/**
|
|
81
|
+
* One CONSUMER span for a batch that arrived together — a Lambda's records.
|
|
82
|
+
* One message with a context is its child; several start a trace of their own
|
|
83
|
+
* that links to each message's producer, since a span has one parent.
|
|
84
|
+
*/
|
|
85
|
+
export declare function consumeBatchTraced<R>(target: MessagingTarget, carriers: readonly (TraceCarrier | undefined)[], fn: () => Promise<R>): Promise<R>;
|
|
86
|
+
/**
|
|
87
|
+
* A carrier from broker message attributes, in any of the shapes they arrive
|
|
88
|
+
* in: SQS's `{ StringValue }`, a Lambda SQS record's `{ stringValue }`, an SNS
|
|
89
|
+
* envelope's `{ Value }`, or plain strings (RabbitMQ headers).
|
|
90
|
+
*/
|
|
91
|
+
export declare function carrierFromAttributes(attributes: Record<string, unknown> | undefined | null): TraceCarrier | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* `data` without {@link TRACE_CONTEXT_KEY}, and the carrier that was under it.
|
|
94
|
+
* What a handler sees never has the key.
|
|
95
|
+
*/
|
|
96
|
+
export declare function withoutTraceKey<T>(data: T): {
|
|
97
|
+
data: T;
|
|
98
|
+
carrier: TraceCarrier | undefined;
|
|
99
|
+
};
|
|
100
|
+
//#endregion
|
|
101
|
+
export { type EventConnection, type EventPublisher, type EventPublisherConnectionString, EventPublisherType, type EventSubscriber, type EventSubscriberConnectionString, type EventsDriver, type ExtractPublisherMessage, type MappedEvent, type MessagingTarget, type PublishableMessage, Publisher, type PublisherOptions, type SubscriberOptions, type TraceCarrier, UnregisteredEventsScheme, UnsupportedEventTransport, eventsDriverFor, registerEventsDriver, registeredEventsSchemes };
|
|
43
102
|
//# sourceMappingURL=index.d.cts.map
|
package/dist/index.d.cts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/EventConnection.ts","../src/Subscriber.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../src/EventConnection.ts","../src/Subscriber.ts","../src/telemetry.ts"],"mappings":";;;qBAGa;;;;;;;;SAQC,qBACZ,wBACE,QAAQ;;;;;;;;qBCDC;;;;;;;;SAQC,qBACZ,iBAAiB,iCAEjB,eAAe,kCACb,QAAQ,gBAAgB;;;;;SAWd,eAAe,iBAAiB,iCAC5C,YAAY,iBAMZ;;;;;;EAAA,UAAS,oBACP,QAAQ,gBAAgB;;KAQhB,qCACR;;;;;;;;qBCjBS;;KAGD,eAAe;;UAGV;;EAEhB;;EAEA;;EAEA;;EAEA;;;;;;wBA+DqB,cAAc,GAAG,GACtC,gBAAgB,KAChB,WAAW,MAAM,MAAM,iBACvB,OAAO,WAAW,gCAAgC,QAAQ,KACxD,QAAQ;;;;;wBAiBK,oBACf,SAAS,2BACP;;;;;;;wBAgBa,cAAc,GAC7B,QAAQ,iBACR,SAAS,0BACT,UAAU,QAAQ,KAChB,QAAQ;;;;;;wBAUK,mBAAmB,GAClC,QAAQ,iBACR,oBAAoB,6BACpB,UAAU,QAAQ,KAChB,QAAQ;;;;;;wBAwDK,sBACf,YAAY,6CACV;;;;;wBA+Da,gBAAgB,GAAG,MAAM;EACxC,MAAM;EACN,SAAS"}
|
package/dist/index.d.mts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { _ as UnsupportedEventTransport, a as registerEventsDriver, c as Publisher, d as EventPublisher, f as EventPublisherType, g as PublishableMessage, h as MappedEvent, i as eventsDriverFor, l as PublisherOptions, m as ExtractPublisherMessage, n as SubscriberOptions, o as registeredEventsSchemes, p as EventSubscriber, r as UnregisteredEventsScheme, s as EventPublisherConnectionString, t as EventsDriver, u as EventConnection } from "./registry-DIx25Q5s.mjs";
|
|
2
|
+
import { Context } from "@opentelemetry/api";
|
|
2
3
|
//#region src/EventConnection.d.ts
|
|
3
4
|
export declare class EventConnectionFactory {
|
|
4
5
|
/**
|
|
@@ -39,5 +40,63 @@ export declare class Subscriber {
|
|
|
39
40
|
}
|
|
40
41
|
type EventSubscriberConnectionString = `${EventPublisherType}://${string}`;
|
|
41
42
|
//#endregion
|
|
42
|
-
|
|
43
|
+
//#region src/telemetry.d.ts
|
|
44
|
+
/**
|
|
45
|
+
* The key a trace context travels under where a broker has no header field of
|
|
46
|
+
* its own — a pg-boss job's data. Reserved: it is removed before a handler sees
|
|
47
|
+
* the payload, and a payload of the application's own should not use it.
|
|
48
|
+
*/
|
|
49
|
+
export declare const TRACE_CONTEXT_KEY = "__gkmTrace";
|
|
50
|
+
/** A propagated trace context: `traceparent`, and `tracestate` when set. */
|
|
51
|
+
type TraceCarrier = Record<string, string>;
|
|
52
|
+
/** What a message is, as its spans describe it. */
|
|
53
|
+
interface MessagingTarget {
|
|
54
|
+
/** `messaging.system`: `pgboss`, `aws_sqs`, `aws_sns`, `rabbitmq`, `basic`. */
|
|
55
|
+
system: string;
|
|
56
|
+
/** The queue or topic — `messaging.destination.name`. */
|
|
57
|
+
destination: string;
|
|
58
|
+
/** The event's type, when the message has one. */
|
|
59
|
+
type?: string;
|
|
60
|
+
/** The broker's id for the message, when it has one. */
|
|
61
|
+
messageId?: string;
|
|
62
|
+
}
|
|
63
|
+
/**
|
|
64
|
+
* Publish `items`, each with a PRODUCER span of its own, through `send` —
|
|
65
|
+
* which receives the carrier to attach to each item, in order.
|
|
66
|
+
*/
|
|
67
|
+
export declare function publishTraced<T, R>(items: readonly T[], describe: (item: T) => MessagingTarget, send: (carriers: (TraceCarrier | undefined)[]) => Promise<R>): Promise<R>;
|
|
68
|
+
/**
|
|
69
|
+
* The context a carrier holds, or undefined when it holds none — no carrier, a
|
|
70
|
+
* malformed `traceparent`, or a propagator that throws.
|
|
71
|
+
*/
|
|
72
|
+
export declare function extractTraceContext(carrier: TraceCarrier | undefined): Context | undefined;
|
|
73
|
+
/**
|
|
74
|
+
* Run `fn` inside a CONSUMER span for one message: a child of the context the
|
|
75
|
+
* message carried, or a new trace when it carried none. The active context of
|
|
76
|
+
* the poller that received it is never the parent — a job is not part of
|
|
77
|
+
* whatever happened to start the poll loop.
|
|
78
|
+
*/
|
|
79
|
+
export declare function consumeTraced<R>(target: MessagingTarget, carrier: TraceCarrier | undefined, fn: () => Promise<R>): Promise<R>;
|
|
80
|
+
/**
|
|
81
|
+
* One CONSUMER span for a batch that arrived together — a Lambda's records.
|
|
82
|
+
* One message with a context is its child; several start a trace of their own
|
|
83
|
+
* that links to each message's producer, since a span has one parent.
|
|
84
|
+
*/
|
|
85
|
+
export declare function consumeBatchTraced<R>(target: MessagingTarget, carriers: readonly (TraceCarrier | undefined)[], fn: () => Promise<R>): Promise<R>;
|
|
86
|
+
/**
|
|
87
|
+
* A carrier from broker message attributes, in any of the shapes they arrive
|
|
88
|
+
* in: SQS's `{ StringValue }`, a Lambda SQS record's `{ stringValue }`, an SNS
|
|
89
|
+
* envelope's `{ Value }`, or plain strings (RabbitMQ headers).
|
|
90
|
+
*/
|
|
91
|
+
export declare function carrierFromAttributes(attributes: Record<string, unknown> | undefined | null): TraceCarrier | undefined;
|
|
92
|
+
/**
|
|
93
|
+
* `data` without {@link TRACE_CONTEXT_KEY}, and the carrier that was under it.
|
|
94
|
+
* What a handler sees never has the key.
|
|
95
|
+
*/
|
|
96
|
+
export declare function withoutTraceKey<T>(data: T): {
|
|
97
|
+
data: T;
|
|
98
|
+
carrier: TraceCarrier | undefined;
|
|
99
|
+
};
|
|
100
|
+
//#endregion
|
|
101
|
+
export { type EventConnection, type EventPublisher, type EventPublisherConnectionString, EventPublisherType, type EventSubscriber, type EventSubscriberConnectionString, type EventsDriver, type ExtractPublisherMessage, type MappedEvent, type MessagingTarget, type PublishableMessage, Publisher, type PublisherOptions, type SubscriberOptions, type TraceCarrier, UnregisteredEventsScheme, UnsupportedEventTransport, eventsDriverFor, registerEventsDriver, registeredEventsSchemes };
|
|
43
102
|
//# sourceMappingURL=index.d.mts.map
|
package/dist/index.d.mts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/EventConnection.ts","../src/Subscriber.ts"],"mappings":"
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../src/EventConnection.ts","../src/Subscriber.ts","../src/telemetry.ts"],"mappings":";;;qBAGa;;;;;;;;SAQC,qBACZ,wBACE,QAAQ;;;;;;;;qBCDC;;;;;;;;SAQC,qBACZ,iBAAiB,iCAEjB,eAAe,kCACb,QAAQ,gBAAgB;;;;;SAWd,eAAe,iBAAiB,iCAC5C,YAAY,iBAMZ;;;;;;EAAA,UAAS,oBACP,QAAQ,gBAAgB;;KAQhB,qCACR;;;;;;;;qBCjBS;;KAGD,eAAe;;UAGV;;EAEhB;;EAEA;;EAEA;;EAEA;;;;;;wBA+DqB,cAAc,GAAG,GACtC,gBAAgB,KAChB,WAAW,MAAM,MAAM,iBACvB,OAAO,WAAW,gCAAgC,QAAQ,KACxD,QAAQ;;;;;wBAiBK,oBACf,SAAS,2BACP;;;;;;;wBAgBa,cAAc,GAC7B,QAAQ,iBACR,SAAS,0BACT,UAAU,QAAQ,KAChB,QAAQ;;;;;;wBAUK,mBAAmB,GAClC,QAAQ,iBACR,oBAAoB,6BACpB,UAAU,QAAQ,KAChB,QAAQ;;;;;;wBAwDK,sBACf,YAAY,6CACV;;;;;wBA+Da,gBAAgB,GAAG,MAAM;EACxC,MAAM;EACN,SAAS"}
|
package/dist/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { i as registeredEventsSchemes, n as eventsDriverFor, r as registerEventsDriver, t as UnregisteredEventsScheme } from "./registry-
|
|
1
|
+
import { a as consumeTraced, d as UnsupportedEventTransport, i as consumeBatchTraced, l as withoutTraceKey, o as extractTraceContext, r as carrierFromAttributes, s as publishTraced, t as TRACE_CONTEXT_KEY, u as EventPublisherType } from "./telemetry-DjjgJMul.mjs";
|
|
2
|
+
import { i as registeredEventsSchemes, n as eventsDriverFor, r as registerEventsDriver, t as UnregisteredEventsScheme } from "./registry-DXLY1Xf6.mjs";
|
|
3
3
|
//#region src/EventConnection.ts
|
|
4
4
|
var EventConnectionFactory = class {
|
|
5
5
|
/**
|
|
@@ -67,6 +67,6 @@ var Subscriber = class {
|
|
|
67
67
|
}
|
|
68
68
|
};
|
|
69
69
|
//#endregion
|
|
70
|
-
export { EventConnectionFactory, EventPublisherType, Publisher, Subscriber, UnregisteredEventsScheme, UnsupportedEventTransport, eventsDriverFor, registerEventsDriver, registeredEventsSchemes };
|
|
70
|
+
export { EventConnectionFactory, EventPublisherType, Publisher, Subscriber, TRACE_CONTEXT_KEY, UnregisteredEventsScheme, UnsupportedEventTransport, carrierFromAttributes, consumeBatchTraced, consumeTraced, eventsDriverFor, extractTraceContext, publishTraced, registerEventsDriver, registeredEventsSchemes, withoutTraceKey };
|
|
71
71
|
|
|
72
72
|
//# sourceMappingURL=index.mjs.map
|
package/dist/pgboss/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_rolldown_runtime = require("../rolldown-runtime-C0BPl7ul.cjs");
|
|
3
|
-
require("../
|
|
3
|
+
const require_telemetry = require("../telemetry-DG3l807O.cjs");
|
|
4
4
|
let pg_boss = require("pg-boss");
|
|
5
5
|
//#region src/pgboss/PgBossConnection.ts
|
|
6
6
|
var PgBossConnection_exports = /* @__PURE__ */ require_rolldown_runtime.__exportAll({ PgBossConnection: () => PgBossConnection });
|
|
@@ -118,22 +118,34 @@ var PgBossPublisher = class PgBossPublisher {
|
|
|
118
118
|
if (!boss) throw new PgBossNotStarted();
|
|
119
119
|
const { topic } = this.options;
|
|
120
120
|
if (topic) {
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
121
|
+
await require_telemetry.publishTraced(messages, (m) => ({
|
|
122
|
+
system: "pgboss",
|
|
123
|
+
destination: topic,
|
|
124
|
+
type: m.type
|
|
125
|
+
}), async (carriers) => {
|
|
126
|
+
for (const [i, m] of messages.entries()) await boss.publish(topicEvent(topic, m.type), require_telemetry.withTraceKey({
|
|
127
|
+
type: m.type,
|
|
128
|
+
payload: m.payload
|
|
129
|
+
}, carriers[i]));
|
|
124
130
|
});
|
|
125
131
|
return;
|
|
126
132
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
133
|
+
await require_telemetry.publishTraced(messages, (m) => ({
|
|
134
|
+
system: "pgboss",
|
|
135
|
+
destination: m.type,
|
|
136
|
+
type: m.type
|
|
137
|
+
}), async (carriers) => {
|
|
138
|
+
const groups = /* @__PURE__ */ new Map();
|
|
139
|
+
for (const [i, m] of messages.entries()) {
|
|
140
|
+
const list = groups.get(m.type) ?? [];
|
|
141
|
+
list.push({ data: require_telemetry.withTraceKey(m.payload, carriers[i]) });
|
|
142
|
+
groups.set(m.type, list);
|
|
143
|
+
}
|
|
144
|
+
for (const [name, jobs] of groups) {
|
|
145
|
+
await boss.createQueue(name);
|
|
146
|
+
await boss.insert(name, jobs);
|
|
147
|
+
}
|
|
148
|
+
});
|
|
137
149
|
}
|
|
138
150
|
async close() {}
|
|
139
151
|
};
|
|
@@ -175,20 +187,36 @@ var PgBossSubscriber = class PgBossSubscriber {
|
|
|
175
187
|
await boss.createQueue(queue);
|
|
176
188
|
for (const type of messages) await boss.subscribe(topicEvent(topic, type), queue);
|
|
177
189
|
await boss.work(queue, work, async (jobs) => {
|
|
178
|
-
for (const job of jobs)
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
190
|
+
for (const job of jobs) {
|
|
191
|
+
const { data, carrier } = require_telemetry.withoutTraceKey(job.data);
|
|
192
|
+
await require_telemetry.consumeTraced({
|
|
193
|
+
system: "pgboss",
|
|
194
|
+
destination: topic,
|
|
195
|
+
type: data.type,
|
|
196
|
+
messageId: job.id
|
|
197
|
+
}, carrier, () => listener({
|
|
198
|
+
type: data.type,
|
|
199
|
+
payload: data.payload
|
|
200
|
+
}));
|
|
201
|
+
}
|
|
182
202
|
});
|
|
183
203
|
return;
|
|
184
204
|
}
|
|
185
205
|
for (const messageType of messages) {
|
|
186
206
|
await boss.createQueue(messageType);
|
|
187
207
|
await boss.work(messageType, work, async (jobs) => {
|
|
188
|
-
for (const job of jobs)
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
208
|
+
for (const job of jobs) {
|
|
209
|
+
const { data, carrier } = require_telemetry.withoutTraceKey(job.data);
|
|
210
|
+
await require_telemetry.consumeTraced({
|
|
211
|
+
system: "pgboss",
|
|
212
|
+
destination: messageType,
|
|
213
|
+
type: job.name,
|
|
214
|
+
messageId: job.id
|
|
215
|
+
}, carrier, () => listener({
|
|
216
|
+
type: job.name,
|
|
217
|
+
payload: data
|
|
218
|
+
}));
|
|
219
|
+
}
|
|
192
220
|
});
|
|
193
221
|
}
|
|
194
222
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.cjs","names":["PgBoss"],"sources":["../../src/pgboss/PgBossConnection.ts","../../src/pgboss/errors.ts","../../src/pgboss/PgBossPublisher.ts","../../src/pgboss/PgBossSubscriber.ts","../../src/pgboss/driver.ts"],"sourcesContent":["import { PgBoss } from 'pg-boss';\nimport type { EventConnection } from '../types';\nimport { EventPublisherType } from '../types';\n\nexport interface PgBossConnectionConfig {\n\tconnectionString: string;\n\tschema?: string;\n\t/**\n\t * Who this connection is to Postgres. Defaults to `GKM_APP_NAME`, which a\n\t * generated entry sets to the construct it runs — so the broker's\n\t * connections are named for the process that holds them, as its database\n\t * pools are, rather than all being `pgboss`.\n\t */\n\tapplicationName?: string;\n}\n\nexport class PgBossConnection implements EventConnection {\n\treadonly type = EventPublisherType.PgBoss;\n\tprivate boss?: PgBoss;\n\tprivate connecting?: Promise<void>;\n\n\tconstructor(private config: PgBossConnectionConfig) {}\n\n\t/**\n\t * Create a PgBossConnection from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss\n\t */\n\tstatic async fromConnectionString(\n\t\tconnectionString: string,\n\t): Promise<PgBossConnection> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst postgresUrl = `postgres://${url.username ? `${url.username}:${url.password}@` : ''}${url.host}${url.pathname}`;\n\n\t\tconst config: PgBossConnectionConfig = {\n\t\t\tconnectionString: postgresUrl,\n\t\t\tschema: params.get('schema') || undefined,\n\t\t};\n\n\t\tconst connection = new PgBossConnection(config);\n\t\tawait connection.connect();\n\t\treturn connection;\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tif (this.boss) return;\n\n\t\tif (this.connecting) {\n\t\t\tawait this.connecting;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.connecting = (async () => {\n\t\t\ttry {\n\t\t\t\tconst applicationName =\n\t\t\t\t\tthis.config.applicationName ?? process.env.GKM_APP_NAME;\n\t\t\t\tconst boss = new PgBoss({\n\t\t\t\t\tconnectionString: this.config.connectionString,\n\t\t\t\t\t...(this.config.schema && { schema: this.config.schema }),\n\t\t\t\t\t...(applicationName && { application_name: applicationName }),\n\t\t\t\t});\n\n\t\t\t\tawait boss.start();\n\t\t\t\tthis.boss = boss;\n\t\t\t} catch (error) {\n\t\t\t\tthis.cleanup();\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t})();\n\n\t\tawait this.connecting;\n\t\tthis.connecting = undefined;\n\t}\n\n\tasync close(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.boss?.stop({ graceful: true });\n\t\t} catch {\n\t\t\t// Ignore errors during close\n\t\t} finally {\n\t\t\tthis.cleanup();\n\t\t}\n\t}\n\n\tisConnected(): boolean {\n\t\treturn !!this.boss;\n\t}\n\n\tprivate cleanup(): void {\n\t\tthis.boss = undefined;\n\t\tthis.connecting = undefined;\n\t}\n\n\t/**\n\t * Get the underlying pg-boss instance for publishing/subscribing\n\t */\n\tget instance(): PgBoss | undefined {\n\t\treturn this.boss;\n\t}\n}\n","// Beside the adapter but apart from its connection module, which imports\n// the broker's client: the publisher and subscriber load that lazily, and\n// importing an error class from it would load it eagerly.\n\n/** pg-boss connected but its instance never started. */\nexport class PgBossNotStarted extends Error {\n\tconstructor() {\n\t\tsuper(\n\t\t\t'pg-boss did not start. Check the database in the connection string is reachable and the role may create the pg-boss schema.',\n\t\t);\n\t\tthis.name = 'PgBossNotStarted';\n\t}\n}\n\n/** A topic subscription with no name to give the subscriber's own queue. */\nexport class PgBossSubscriptionNeedsName extends Error {\n\tconstructor(readonly topic: string) {\n\t\tsuper(\n\t\t\t`Subscribing to topic '${topic}' on pg-boss needs a subscription name: ` +\n\t\t\t\t'each subscriber drains a queue of its own, and that queue is named ' +\n\t\t\t\t'for it. Pass `subscription`.',\n\t\t);\n\t\tthis.name = 'PgBossSubscriptionNeedsName';\n\t}\n}\n","import type { EventPublisher, PublishableMessage } from '../types';\nimport { PgBossNotStarted } from './errors';\nimport type { PgBossConnection } from './PgBossConnection';\n\nexport interface PgBossPublisherOptions {\n\t/**\n\t * Publishing to a topic: each message is fanned out to every subscriber's\n\t * own queue rather than inserted into one shared queue. Without it, a\n\t * message goes to the queue named by its type — a work queue, one consumer.\n\t */\n\ttopic?: string;\n}\n\n/** The pg-boss event a topic's message type is published as. */\nexport function topicEvent(topic: string, type: string): string {\n\treturn `${topic}/${type}`;\n}\n\nexport class PgBossPublisher<TMessage extends PublishableMessage<string, any>>\n\timplements EventPublisher<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: PgBossConnection,\n\t\tprivate options: PgBossPublisherOptions = {},\n\t) {}\n\n\t/**\n\t * Create a PgBossPublisher from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(\n\t\tconnectionString: string,\n\t\toptions: PgBossPublisherOptions = {},\n\t): Promise<PgBossPublisher<TMessage>> {\n\t\tconst { PgBossConnection } = await import('./PgBossConnection');\n\t\tconst connection =\n\t\t\tawait PgBossConnection.fromConnectionString(connectionString);\n\t\treturn new PgBossPublisher<TMessage>(connection, options);\n\t}\n\n\tasync publish(messages: TMessage[]): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst boss = this.connection.instance;\n\t\tif (!boss) {\n\t\t\tthrow new PgBossNotStarted();\n\t\t}\n\n\t\t// A topic: pg-boss copies the job into every queue subscribed to the\n\t\t// event — one per subscriber — so each subscriber sees each message.\n\t\t// The type rides in the data, because the job is named for the queue.\n\t\tconst { topic } = this.options;\n\t\tif (topic) {\n\t\t\tfor (const m of messages) {\n\t\t\t\tawait boss.publish(topicEvent(topic, m.type), {\n\t\t\t\t\ttype: m.type,\n\t\t\t\t\tpayload: m.payload,\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Group jobs by queue name (v11+ requires per-queue insert calls)\n\t\tconst groups = new Map<string, { data: TMessage['payload'] }[]>();\n\t\tfor (const m of messages) {\n\t\t\tconst list = groups.get(m.type) ?? [];\n\t\t\tlist.push({ data: m.payload });\n\t\t\tgroups.set(m.type, list);\n\t\t}\n\n\t\tfor (const [name, jobs] of groups) {\n\t\t\tawait boss.createQueue(name);\n\t\t\tawait boss.insert(name, jobs);\n\t\t}\n\t}\n\n\tasync close(): Promise<void> {\n\t\t// Publisher doesn't own the connection\n\t}\n}\n","import type { EventSubscriber, PublishableMessage } from '../types';\nimport { PgBossNotStarted, PgBossSubscriptionNeedsName } from './errors';\nimport type { PgBossConnection } from './PgBossConnection';\nimport { topicEvent } from './PgBossPublisher';\n\nexport interface PgBossSubscriberOptions {\n\tbatchSize?: number;\n\tpollingIntervalSeconds?: number;\n\t/**\n\t * Subscribing to a topic. Each subscriber then drains a queue of its own,\n\t * `<topic>/<subscription>`, bound to the events it names — so every\n\t * subscriber sees every message, and replicas of one subscriber share it.\n\t * Without it, messages are drained from the queue named by their type:\n\t * work shared among whoever drains it.\n\t */\n\ttopic?: string;\n\t/** The subscriber's own name on the topic. Required with `topic`. */\n\tsubscription?: string;\n}\n\nexport class PgBossSubscriber<TMessage extends PublishableMessage<string, any>>\n\timplements EventSubscriber<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: PgBossConnection,\n\t\tprivate options: PgBossSubscriberOptions = {},\n\t) {}\n\n\t/**\n\t * Create a PgBossSubscriber from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss&batchSize=5\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<PgBossSubscriber<TMessage>> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst { PgBossConnection } = await import('./PgBossConnection');\n\t\tconst connection =\n\t\t\tawait PgBossConnection.fromConnectionString(connectionString);\n\n\t\tconst options: PgBossSubscriberOptions = {\n\t\t\tbatchSize: params.get('batchSize')\n\t\t\t\t? Number.parseInt(params.get('batchSize')!, 10)\n\t\t\t\t: undefined,\n\t\t\tpollingIntervalSeconds: params.get('pollingIntervalSeconds')\n\t\t\t\t? Number.parseInt(params.get('pollingIntervalSeconds')!, 10)\n\t\t\t\t: undefined,\n\t\t};\n\n\t\treturn new PgBossSubscriber<TMessage>(connection, options);\n\t}\n\n\tasync subscribe(\n\t\tmessages: TMessage['type'][],\n\t\tlistener: (payload: TMessage) => Promise<void>,\n\t): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst boss = this.connection.instance;\n\t\tif (!boss) {\n\t\t\tthrow new PgBossNotStarted();\n\t\t}\n\n\t\tconst work = {\n\t\t\t...(this.options.batchSize && { batchSize: this.options.batchSize }),\n\t\t\t...(this.options.pollingIntervalSeconds && {\n\t\t\t\tpollingIntervalSeconds: this.options.pollingIntervalSeconds,\n\t\t\t}),\n\t\t};\n\n\t\tconst { topic, subscription } = this.options;\n\t\tif (topic) {\n\t\t\tif (!subscription) throw new PgBossSubscriptionNeedsName(topic);\n\n\t\t\tconst queue = topicEvent(topic, subscription);\n\t\t\tawait boss.createQueue(queue);\n\t\t\tfor (const type of messages) {\n\t\t\t\tawait boss.subscribe(topicEvent(topic, type), queue);\n\t\t\t}\n\t\t\tawait boss.work<{ type: string; payload: unknown }>(\n\t\t\t\tqueue,\n\t\t\t\twork,\n\t\t\t\tasync (jobs) => {\n\t\t\t\t\tfor (const job of jobs) {\n\t\t\t\t\t\tawait listener({\n\t\t\t\t\t\t\ttype: job.data.type,\n\t\t\t\t\t\t\tpayload: job.data.payload,\n\t\t\t\t\t\t} as TMessage);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const messageType of messages) {\n\t\t\tawait boss.createQueue(messageType);\n\t\t\tawait boss.work(messageType, work, async (jobs) => {\n\t\t\t\tfor (const job of jobs) {\n\t\t\t\t\tconst fullMessage = {\n\t\t\t\t\t\ttype: job.name,\n\t\t\t\t\t\tpayload: job.data,\n\t\t\t\t\t} as TMessage;\n\n\t\t\t\t\tawait listener(fullMessage);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n}\n","import type { EventsDriver } from '../registry';\nimport { EventPublisherType } from '../types';\nimport { PgBossConnection } from './PgBossConnection';\nimport { PgBossPublisher } from './PgBossPublisher';\nimport { PgBossSubscriber } from './PgBossSubscriber';\n\n/**\n * `pgboss://` — queues and topics in Postgres. Register it with\n * `registerEventsDriver(pgbossEventsDriver)`; this subpath is the only one\n * that imports `pg-boss`.\n */\nexport const pgbossEventsDriver: EventsDriver = {\n\tscheme: EventPublisherType.PgBoss,\n\tconnect: (url) => PgBossConnection.fromConnectionString(url),\n\tpublisher: (url, options) =>\n\t\tPgBossPublisher.fromConnectionString(url, options),\n\tpublisherFor: (connection, options) =>\n\t\tnew PgBossPublisher(connection as PgBossConnection, options),\n\tsubscriber: (url) => PgBossSubscriber.fromConnectionString(url),\n\tsubscriberFor: (connection, options) =>\n\t\tnew PgBossSubscriber(connection as PgBossConnection, options),\n};\n"],"mappings":";;;;;;AAgBA,IAAa,mBAAb,MAAa,iBAA4C;CAKpC;CAJpB,OAAS;CACT;CACA;CAEA,YAAY,QAAwC;EAAhC,KAAA,SAAA;CAAiC;;;;;CAMrD,aAAa,qBACZ,kBAC4B;EAC5B,MAAM,MAAM,IAAI,IAAI,gBAAgB;EACpC,MAAM,SAAS,IAAI;EAInB,MAAM,SAAiC;GACtC,kBAAkB,cAHe,IAAI,WAAW,GAAG,IAAI,SAAS,GAAG,IAAI,SAAS,KAAK,KAAK,IAAI,OAAO,IAAI;GAIzG,QAAQ,OAAO,IAAI,QAAQ,KAAK,KAAA;EACjC;EAEA,MAAM,aAAa,IAAI,iBAAiB,MAAM;EAC9C,MAAM,WAAW,QAAQ;EACzB,OAAO;CACR;CAEA,MAAM,UAAyB;EAC9B,IAAI,KAAK,MAAM;EAEf,IAAI,KAAK,YAAY;GACpB,MAAM,KAAK;GACX;EACD;EAEA,KAAK,cAAc,YAAY;GAC9B,IAAI;IACH,MAAM,kBACL,KAAK,OAAO,mBAAmB,QAAQ,IAAI;IAC5C,MAAM,OAAO,IAAIA,QAAAA,OAAO;KACvB,kBAAkB,KAAK,OAAO;KAC9B,GAAI,KAAK,OAAO,UAAU,EAAE,QAAQ,KAAK,OAAO,OAAO;KACvD,GAAI,mBAAmB,EAAE,kBAAkB,gBAAgB;IAC5D,CAAC;IAED,MAAM,KAAK,MAAM;IACjB,KAAK,OAAO;GACb,SAAS,OAAO;IACf,KAAK,QAAQ;IACb,MAAM;GACP;EACD,EAAA,CAAG;EAEH,MAAM,KAAK;EACX,KAAK,aAAa,KAAA;CACnB;CAEA,MAAM,QAAuB;EAC5B,IAAI;GACH,MAAM,KAAK,MAAM,KAAK,EAAE,UAAU,KAAK,CAAC;EACzC,QAAQ,CAER,UAAU;GACT,KAAK,QAAQ;EACd;CACD;CAEA,cAA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K;EACrC,IAAI,OAAO;GACV,IAAI,CAAC,cAAc,MAAM,IAAI,4BAA4B,KAAK;GAE9D,MAAM,QAAQ,WAAW,OAAO,YAAY;GAC5C,MAAM,KAAK,YAAY,KAAK;GAC5B,KAAK,MAAM,QAAQ,UAClB,MAAM,KAAK,UAAU,WAAW,OAAO,IAAI,GAAG,KAAK;GAEpD,MAAM,KAAK,KACV,OACA,MACA,OAAO,SAAS;IACf,KAAK,MAAM,OAAO,MACjB,MAAM,SAAS;KACd,MAAM,IAAI,KAAK;KACf,SAAS,IAAI,KAAK;IACnB,CAAa;GAEf,CACD;GACA;EACD;EAEA,KAAK,MAAM,eAAe,UAAU;GACnC,MAAM,KAAK,YAAY,WAAW;GAClC,MAAM,KAAK,KAAK,aAAa,MAAM,OAAO,SAAS;IAClD,KAAK,MAAM,OAAO,MAMjB,MAAM,SAAS;KAJd,MAAM,IAAI;KACV,SAAS,IAAI;IAGW,CAAC;GAE5B,CAAC;EACF;CACD;AACD;;;;;;;;ACrGA,MAAa,qBAAmC;CAC/C,QAAA;CACA,UAAU,QAAQ,iBAAiB,qBAAqB,GAAG;CAC3D,YAAY,KAAK,YAChB,gBAAgB,qBAAqB,KAAK,OAAO;CAClD,eAAe,YAAY,YAC1B,IAAI,gBAAgB,YAAgC,OAAO;CAC5D,aAAa,QAAQ,iBAAiB,qBAAqB,GAAG;CAC9D,gBAAgB,YAAY,YAC3B,IAAI,iBAAiB,YAAgC,OAAO;AAC9D"}
|
|
1
|
+
{"version":3,"file":"index.cjs","names":["PgBoss","publishTraced","withTraceKey","withoutTraceKey","consumeTraced"],"sources":["../../src/pgboss/PgBossConnection.ts","../../src/pgboss/errors.ts","../../src/pgboss/PgBossPublisher.ts","../../src/pgboss/PgBossSubscriber.ts","../../src/pgboss/driver.ts"],"sourcesContent":["import { PgBoss } from 'pg-boss';\nimport type { EventConnection } from '../types';\nimport { EventPublisherType } from '../types';\n\nexport interface PgBossConnectionConfig {\n\tconnectionString: string;\n\tschema?: string;\n\t/**\n\t * Who this connection is to Postgres. Defaults to `GKM_APP_NAME`, which a\n\t * generated entry sets to the construct it runs — so the broker's\n\t * connections are named for the process that holds them, as its database\n\t * pools are, rather than all being `pgboss`.\n\t */\n\tapplicationName?: string;\n}\n\nexport class PgBossConnection implements EventConnection {\n\treadonly type = EventPublisherType.PgBoss;\n\tprivate boss?: PgBoss;\n\tprivate connecting?: Promise<void>;\n\n\tconstructor(private config: PgBossConnectionConfig) {}\n\n\t/**\n\t * Create a PgBossConnection from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss\n\t */\n\tstatic async fromConnectionString(\n\t\tconnectionString: string,\n\t): Promise<PgBossConnection> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst postgresUrl = `postgres://${url.username ? `${url.username}:${url.password}@` : ''}${url.host}${url.pathname}`;\n\n\t\tconst config: PgBossConnectionConfig = {\n\t\t\tconnectionString: postgresUrl,\n\t\t\tschema: params.get('schema') || undefined,\n\t\t};\n\n\t\tconst connection = new PgBossConnection(config);\n\t\tawait connection.connect();\n\t\treturn connection;\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tif (this.boss) return;\n\n\t\tif (this.connecting) {\n\t\t\tawait this.connecting;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.connecting = (async () => {\n\t\t\ttry {\n\t\t\t\tconst applicationName =\n\t\t\t\t\tthis.config.applicationName ?? process.env.GKM_APP_NAME;\n\t\t\t\tconst boss = new PgBoss({\n\t\t\t\t\tconnectionString: this.config.connectionString,\n\t\t\t\t\t...(this.config.schema && { schema: this.config.schema }),\n\t\t\t\t\t...(applicationName && { application_name: applicationName }),\n\t\t\t\t});\n\n\t\t\t\tawait boss.start();\n\t\t\t\tthis.boss = boss;\n\t\t\t} catch (error) {\n\t\t\t\tthis.cleanup();\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t})();\n\n\t\tawait this.connecting;\n\t\tthis.connecting = undefined;\n\t}\n\n\tasync close(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.boss?.stop({ graceful: true });\n\t\t} catch {\n\t\t\t// Ignore errors during close\n\t\t} finally {\n\t\t\tthis.cleanup();\n\t\t}\n\t}\n\n\tisConnected(): boolean {\n\t\treturn !!this.boss;\n\t}\n\n\tprivate cleanup(): void {\n\t\tthis.boss = undefined;\n\t\tthis.connecting = undefined;\n\t}\n\n\t/**\n\t * Get the underlying pg-boss instance for publishing/subscribing\n\t */\n\tget instance(): PgBoss | undefined {\n\t\treturn this.boss;\n\t}\n}\n","// Beside the adapter but apart from its connection module, which imports\n// the broker's client: the publisher and subscriber load that lazily, and\n// importing an error class from it would load it eagerly.\n\n/** pg-boss connected but its instance never started. */\nexport class PgBossNotStarted extends Error {\n\tconstructor() {\n\t\tsuper(\n\t\t\t'pg-boss did not start. Check the database in the connection string is reachable and the role may create the pg-boss schema.',\n\t\t);\n\t\tthis.name = 'PgBossNotStarted';\n\t}\n}\n\n/** A topic subscription with no name to give the subscriber's own queue. */\nexport class PgBossSubscriptionNeedsName extends Error {\n\tconstructor(readonly topic: string) {\n\t\tsuper(\n\t\t\t`Subscribing to topic '${topic}' on pg-boss needs a subscription name: ` +\n\t\t\t\t'each subscriber drains a queue of its own, and that queue is named ' +\n\t\t\t\t'for it. Pass `subscription`.',\n\t\t);\n\t\tthis.name = 'PgBossSubscriptionNeedsName';\n\t}\n}\n","import { publishTraced, withTraceKey } from '../telemetry';\nimport type { EventPublisher, PublishableMessage } from '../types';\nimport { PgBossNotStarted } from './errors';\nimport type { PgBossConnection } from './PgBossConnection';\n\nexport interface PgBossPublisherOptions {\n\t/**\n\t * Publishing to a topic: each message is fanned out to every subscriber's\n\t * own queue rather than inserted into one shared queue. Without it, a\n\t * message goes to the queue named by its type — a work queue, one consumer.\n\t */\n\ttopic?: string;\n}\n\n/** The pg-boss event a topic's message type is published as. */\nexport function topicEvent(topic: string, type: string): string {\n\treturn `${topic}/${type}`;\n}\n\nexport class PgBossPublisher<TMessage extends PublishableMessage<string, any>>\n\timplements EventPublisher<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: PgBossConnection,\n\t\tprivate options: PgBossPublisherOptions = {},\n\t) {}\n\n\t/**\n\t * Create a PgBossPublisher from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(\n\t\tconnectionString: string,\n\t\toptions: PgBossPublisherOptions = {},\n\t): Promise<PgBossPublisher<TMessage>> {\n\t\tconst { PgBossConnection } = await import('./PgBossConnection');\n\t\tconst connection =\n\t\t\tawait PgBossConnection.fromConnectionString(connectionString);\n\t\treturn new PgBossPublisher<TMessage>(connection, options);\n\t}\n\n\tasync publish(messages: TMessage[]): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst boss = this.connection.instance;\n\t\tif (!boss) {\n\t\t\tthrow new PgBossNotStarted();\n\t\t}\n\n\t\t// A topic: pg-boss copies the job into every queue subscribed to the\n\t\t// event — one per subscriber — so each subscriber sees each message.\n\t\t// The type rides in the data, because the job is named for the queue.\n\t\t//\n\t\t// pg-boss has no header field, so the trace context rides in the data\n\t\t// too, under a reserved key the subscriber removes before the handler.\n\t\tconst { topic } = this.options;\n\t\tif (topic) {\n\t\t\tawait publishTraced(\n\t\t\t\tmessages,\n\t\t\t\t(m) => ({ system: 'pgboss', destination: topic, type: m.type }),\n\t\t\t\tasync (carriers) => {\n\t\t\t\t\tfor (const [i, m] of messages.entries()) {\n\t\t\t\t\t\tawait boss.publish(\n\t\t\t\t\t\t\ttopicEvent(topic, m.type),\n\t\t\t\t\t\t\twithTraceKey({ type: m.type, payload: m.payload }, carriers[i]),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tawait publishTraced(\n\t\t\tmessages,\n\t\t\t(m) => ({ system: 'pgboss', destination: m.type, type: m.type }),\n\t\t\tasync (carriers) => {\n\t\t\t\t// Group jobs by queue name (v11+ requires per-queue insert calls)\n\t\t\t\tconst groups = new Map<string, { data: TMessage['payload'] }[]>();\n\t\t\t\tfor (const [i, m] of messages.entries()) {\n\t\t\t\t\tconst list = groups.get(m.type) ?? [];\n\t\t\t\t\tlist.push({ data: withTraceKey(m.payload, carriers[i]) });\n\t\t\t\t\tgroups.set(m.type, list);\n\t\t\t\t}\n\n\t\t\t\tfor (const [name, jobs] of groups) {\n\t\t\t\t\tawait boss.createQueue(name);\n\t\t\t\t\tawait boss.insert(name, jobs);\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t}\n\n\tasync close(): Promise<void> {\n\t\t// Publisher doesn't own the connection\n\t}\n}\n","import { consumeTraced, withoutTraceKey } from '../telemetry';\nimport type { EventSubscriber, PublishableMessage } from '../types';\nimport { PgBossNotStarted, PgBossSubscriptionNeedsName } from './errors';\nimport type { PgBossConnection } from './PgBossConnection';\nimport { topicEvent } from './PgBossPublisher';\n\nexport interface PgBossSubscriberOptions {\n\tbatchSize?: number;\n\tpollingIntervalSeconds?: number;\n\t/**\n\t * Subscribing to a topic. Each subscriber then drains a queue of its own,\n\t * `<topic>/<subscription>`, bound to the events it names — so every\n\t * subscriber sees every message, and replicas of one subscriber share it.\n\t * Without it, messages are drained from the queue named by their type:\n\t * work shared among whoever drains it.\n\t */\n\ttopic?: string;\n\t/** The subscriber's own name on the topic. Required with `topic`. */\n\tsubscription?: string;\n}\n\nexport class PgBossSubscriber<TMessage extends PublishableMessage<string, any>>\n\timplements EventSubscriber<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: PgBossConnection,\n\t\tprivate options: PgBossSubscriberOptions = {},\n\t) {}\n\n\t/**\n\t * Create a PgBossSubscriber from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss&batchSize=5\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<PgBossSubscriber<TMessage>> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst { PgBossConnection } = await import('./PgBossConnection');\n\t\tconst connection =\n\t\t\tawait PgBossConnection.fromConnectionString(connectionString);\n\n\t\tconst options: PgBossSubscriberOptions = {\n\t\t\tbatchSize: params.get('batchSize')\n\t\t\t\t? Number.parseInt(params.get('batchSize')!, 10)\n\t\t\t\t: undefined,\n\t\t\tpollingIntervalSeconds: params.get('pollingIntervalSeconds')\n\t\t\t\t? Number.parseInt(params.get('pollingIntervalSeconds')!, 10)\n\t\t\t\t: undefined,\n\t\t};\n\n\t\treturn new PgBossSubscriber<TMessage>(connection, options);\n\t}\n\n\tasync subscribe(\n\t\tmessages: TMessage['type'][],\n\t\tlistener: (payload: TMessage) => Promise<void>,\n\t): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst boss = this.connection.instance;\n\t\tif (!boss) {\n\t\t\tthrow new PgBossNotStarted();\n\t\t}\n\n\t\tconst work = {\n\t\t\t...(this.options.batchSize && { batchSize: this.options.batchSize }),\n\t\t\t...(this.options.pollingIntervalSeconds && {\n\t\t\t\tpollingIntervalSeconds: this.options.pollingIntervalSeconds,\n\t\t\t}),\n\t\t};\n\n\t\tconst { topic, subscription } = this.options;\n\t\tif (topic) {\n\t\t\tif (!subscription) throw new PgBossSubscriptionNeedsName(topic);\n\n\t\t\tconst queue = topicEvent(topic, subscription);\n\t\t\tawait boss.createQueue(queue);\n\t\t\tfor (const type of messages) {\n\t\t\t\tawait boss.subscribe(topicEvent(topic, type), queue);\n\t\t\t}\n\t\t\tawait boss.work<{ type: string; payload: unknown }>(\n\t\t\t\tqueue,\n\t\t\t\twork,\n\t\t\t\tasync (jobs) => {\n\t\t\t\t\tfor (const job of jobs) {\n\t\t\t\t\t\tconst { data, carrier } = withoutTraceKey(job.data);\n\t\t\t\t\t\tawait consumeTraced(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tsystem: 'pgboss',\n\t\t\t\t\t\t\t\tdestination: topic,\n\t\t\t\t\t\t\t\ttype: data.type,\n\t\t\t\t\t\t\t\tmessageId: job.id,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tcarrier,\n\t\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\t\tlistener({\n\t\t\t\t\t\t\t\t\ttype: data.type,\n\t\t\t\t\t\t\t\t\tpayload: data.payload,\n\t\t\t\t\t\t\t\t} as TMessage),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const messageType of messages) {\n\t\t\tawait boss.createQueue(messageType);\n\t\t\tawait boss.work(messageType, work, async (jobs) => {\n\t\t\t\tfor (const job of jobs) {\n\t\t\t\t\t// The trace context is taken out of the data here, so the\n\t\t\t\t\t// handler's payload is exactly what was published.\n\t\t\t\t\tconst { data, carrier } = withoutTraceKey(job.data);\n\t\t\t\t\tawait consumeTraced(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsystem: 'pgboss',\n\t\t\t\t\t\t\tdestination: messageType,\n\t\t\t\t\t\t\ttype: job.name,\n\t\t\t\t\t\t\tmessageId: job.id,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcarrier,\n\t\t\t\t\t\t() => listener({ type: job.name, payload: data } as TMessage),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n}\n","import type { EventsDriver } from '../registry';\nimport { EventPublisherType } from '../types';\nimport { PgBossConnection } from './PgBossConnection';\nimport { PgBossPublisher } from './PgBossPublisher';\nimport { PgBossSubscriber } from './PgBossSubscriber';\n\n/**\n * `pgboss://` — queues and topics in Postgres. Register it with\n * `registerEventsDriver(pgbossEventsDriver)`; this subpath is the only one\n * that imports `pg-boss`.\n */\nexport const pgbossEventsDriver: EventsDriver = {\n\tscheme: EventPublisherType.PgBoss,\n\tconnect: (url) => PgBossConnection.fromConnectionString(url),\n\tpublisher: (url, options) =>\n\t\tPgBossPublisher.fromConnectionString(url, options),\n\tpublisherFor: (connection, options) =>\n\t\tnew PgBossPublisher(connection as PgBossConnection, options),\n\tsubscriber: (url) => PgBossSubscriber.fromConnectionString(url),\n\tsubscriberFor: (connection, options) =>\n\t\tnew PgBossSubscriber(connection as PgBossConnection, options),\n};\n"],"mappings":";;;;;;AAgBA,IAAa,mBAAb,MAAa,iBAA4C;CAKpC;CAJpB,OAAS;CACT;CACA;CAEA,YAAY,QAAwC;EAAhC,KAAA,SAAA;CAAiC;;;;;CAMrD,aAAa,qBACZ,kBAC4B;EAC5B,MAAM,MAAM,IAAI,IAAI,gBAAgB;EACpC,MAAM,SAAS,IAAI;EAInB,MAAM,SAAiC;GACtC,kBAAkB,cAHe,IAAI,WAAW,GAAG,IAAI,SAAS,GAAG,IAAI,SAAS,KAAK,KAAK,IAAI,OAAO,IAAI;GAIzG,QAAQ,OAAO,IAAI,QAAQ,KAAK,KAAA;EACjC;EAEA,MAAM,aAAa,IAAI,iBAAiB,MAAM;EAC9C,MAAM,WAAW,QAAQ;EACzB,OAAO;CACR;CAEA,MAAM,UAAyB;EAC9B,IAAI,KAAK,MAAM;EAEf,IAAI,KAAK,YAAY;GACpB,MAAM,KAAK;GACX;EACD;EAEA,KAAK,cAAc,YAAY;GAC9B,IAAI;IACH,MAAM,kBACL,KAAK,OAAO,mBAAmB,QAAQ,IAAI;IAC5C,MAAM,OAAO,IAAIA,QAAAA,OAAO;KACvB,kBAAkB,KAAK,OAAO;KAC9B,GAAI,KAAK,OAAO,UAAU,EAAE,QAAQ,KAAK,OAAO,OAAO;KACvD,GAAI,mBAAmB,EAAE,kBAAkB,gBAAgB;IAC5D,CAAC;IAED,MAAM,KAAK,MAAM;IACjB,KAAK,OAAO;GACb,SAAS,OAAO;IACf,KAAK,QAAQ;IACb,MAAM;GACP;EACD,EAAA,CAAG;EAEH,MAAM,KAAK;EACX,KAAK,aAAa,KAAA;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AI,IAAI;KAClD,MAAMC,kBAAAA,cACL;MACC,QAAQ;MACR,aAAa;MACb,MAAM,IAAI;MACV,WAAW,IAAI;KAChB,GACA,eACM,SAAS;MAAE,MAAM,IAAI;MAAM,SAAS;KAAK,CAAa,CAC7D;IACD;GACD,CAAC;EACF;CACD;AACD;;;;;;;;ACxHA,MAAa,qBAAmC;CAC/C,QAAA;CACA,UAAU,QAAQ,iBAAiB,qBAAqB,GAAG;CAC3D,YAAY,KAAK,YAChB,gBAAgB,qBAAqB,KAAK,OAAO;CAClD,eAAe,YAAY,YAC1B,IAAI,gBAAgB,YAAgC,OAAO;CAC5D,aAAa,QAAQ,iBAAiB,qBAAqB,GAAG;CAC9D,gBAAgB,YAAY,YAC3B,IAAI,iBAAiB,YAAgC,OAAO;AAC9D"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/pgboss/driver.ts","../../src/pgboss/errors.ts","../../src/pgboss/PgBossConnection.ts","../../src/pgboss/PgBossPublisher.ts","../../src/pgboss/PgBossSubscriber.ts"],"mappings":";;;;;;;;qBAWa,oBAAoB;;;;qBCNpB,yBAAyB;EACrC;;;qBASY,oCAAoC;WAC3B;EAArB,YAAqB;;;;UCZL;EAChB;EACA;;;;;;;EAOA;;qBAGY,4BAA4B;UAKpB;WAJX,OAAI,mBAAA;UACL;UACA;EAER,YAAoB,QAAQ;;;;;SAMf,qBACZ,2BACE,QAAQ;EAgBL,WAAW;EA8BX,SAAS;EAUf;UAIQ;;;;MAQJ,YAAY;;;;
|
|
1
|
+
{"version":3,"file":"index.d.cts","names":[],"sources":["../../src/pgboss/driver.ts","../../src/pgboss/errors.ts","../../src/pgboss/PgBossConnection.ts","../../src/pgboss/PgBossPublisher.ts","../../src/pgboss/PgBossSubscriber.ts"],"mappings":";;;;;;;;qBAWa,oBAAoB;;;;qBCNpB,yBAAyB;EACrC;;;qBASY,oCAAoC;WAC3B;EAArB,YAAqB;;;;UCZL;EAChB;EACA;;;;;;;EAOA;;qBAGY,4BAA4B;UAKpB;WAJX,OAAI,mBAAA;UACL;UACA;EAER,YAAoB,QAAQ;;;;;SAMf,qBACZ,2BACE,QAAQ;EAgBL,WAAW;EA8BX,SAAS;EAUf;UAIQ;;;;MAQJ,YAAY;;;;UC5FA;;;;;;EAMhB;;;wBAIe,WAAW,eAAe;qBAI7B,gBAAgB,iBAAiB,4CAClC,eAAe;UAGjB;UACA;EAFT,YACS,YAAY,kBACZ,UAAS;;;;;SAOL,qBACZ,iBAAiB,iCAEjB,0BACA,UAAS,yBACP,QAAQ,gBAAgB;EAOrB,QAAQ,UAAU,aAAa;EAqD/B,SAAS;;;;UC1FC;EAChB;EACA;;;;;;;;EAQA;;EAEA;;qBAGY,iBAAiB,iBAAiB,4CACnC,gBAAgB;UAGlB;UACA;EAFT,YACS,YAAY,kBACZ,UAAS;;;;;SAOL,qBACZ,iBAAiB,iCAChB,2BAA2B,QAAQ,iBAAiB;EAoBhD,UACL,UAAU,oBACV,WAAW,SAAS,aAAa,gBAC/B"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/pgboss/driver.ts","../../src/pgboss/errors.ts","../../src/pgboss/PgBossConnection.ts","../../src/pgboss/PgBossPublisher.ts","../../src/pgboss/PgBossSubscriber.ts"],"mappings":";;;;;;;;qBAWa,oBAAoB;;;;qBCNpB,yBAAyB;EACrC;;;qBASY,oCAAoC;WAC3B;EAArB,YAAqB;;;;UCZL;EAChB;EACA;;;;;;;EAOA;;qBAGY,4BAA4B;UAKpB;WAJX,OAAI,mBAAA;UACL;UACA;EAER,YAAoB,QAAQ;;;;;SAMf,qBACZ,2BACE,QAAQ;EAgBL,WAAW;EA8BX,SAAS;EAUf;UAIQ;;;;MAQJ,YAAY;;;;
|
|
1
|
+
{"version":3,"file":"index.d.mts","names":[],"sources":["../../src/pgboss/driver.ts","../../src/pgboss/errors.ts","../../src/pgboss/PgBossConnection.ts","../../src/pgboss/PgBossPublisher.ts","../../src/pgboss/PgBossSubscriber.ts"],"mappings":";;;;;;;;qBAWa,oBAAoB;;;;qBCNpB,yBAAyB;EACrC;;;qBASY,oCAAoC;WAC3B;EAArB,YAAqB;;;;UCZL;EAChB;EACA;;;;;;;EAOA;;qBAGY,4BAA4B;UAKpB;WAJX,OAAI,mBAAA;UACL;UACA;EAER,YAAoB,QAAQ;;;;;SAMf,qBACZ,2BACE,QAAQ;EAgBL,WAAW;EA8BX,SAAS;EAUf;UAIQ;;;;MAQJ,YAAY;;;;UC5FA;;;;;;EAMhB;;;wBAIe,WAAW,eAAe;qBAI7B,gBAAgB,iBAAiB,4CAClC,eAAe;UAGjB;UACA;EAFT,YACS,YAAY,kBACZ,UAAS;;;;;SAOL,qBACZ,iBAAiB,iCAEjB,0BACA,UAAS,yBACP,QAAQ,gBAAgB;EAOrB,QAAQ,UAAU,aAAa;EAqD/B,SAAS;;;;UC1FC;EAChB;EACA;;;;;;;;EAQA;;EAEA;;qBAGY,iBAAiB,iBAAiB,4CACnC,gBAAgB;UAGlB;UACA;EAFT,YACS,YAAY,kBACZ,UAAS;;;;;SAOL,qBACZ,iBAAiB,iCAChB,2BAA2B,QAAQ,iBAAiB;EAoBhD,UACL,UAAU,oBACV,WAAW,SAAS,aAAa,gBAC/B"}
|
package/dist/pgboss/index.mjs
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { t as __exportAll } from "../rolldown-runtime-D7D4PA-g.mjs";
|
|
2
|
-
import "../
|
|
2
|
+
import { a as consumeTraced, c as withTraceKey, l as withoutTraceKey, s as publishTraced } from "../telemetry-DjjgJMul.mjs";
|
|
3
3
|
import { PgBoss } from "pg-boss";
|
|
4
4
|
//#region src/pgboss/PgBossConnection.ts
|
|
5
5
|
var PgBossConnection_exports = /* @__PURE__ */ __exportAll({ PgBossConnection: () => PgBossConnection });
|
|
@@ -117,22 +117,34 @@ var PgBossPublisher = class PgBossPublisher {
|
|
|
117
117
|
if (!boss) throw new PgBossNotStarted();
|
|
118
118
|
const { topic } = this.options;
|
|
119
119
|
if (topic) {
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
120
|
+
await publishTraced(messages, (m) => ({
|
|
121
|
+
system: "pgboss",
|
|
122
|
+
destination: topic,
|
|
123
|
+
type: m.type
|
|
124
|
+
}), async (carriers) => {
|
|
125
|
+
for (const [i, m] of messages.entries()) await boss.publish(topicEvent(topic, m.type), withTraceKey({
|
|
126
|
+
type: m.type,
|
|
127
|
+
payload: m.payload
|
|
128
|
+
}, carriers[i]));
|
|
123
129
|
});
|
|
124
130
|
return;
|
|
125
131
|
}
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
132
|
+
await publishTraced(messages, (m) => ({
|
|
133
|
+
system: "pgboss",
|
|
134
|
+
destination: m.type,
|
|
135
|
+
type: m.type
|
|
136
|
+
}), async (carriers) => {
|
|
137
|
+
const groups = /* @__PURE__ */ new Map();
|
|
138
|
+
for (const [i, m] of messages.entries()) {
|
|
139
|
+
const list = groups.get(m.type) ?? [];
|
|
140
|
+
list.push({ data: withTraceKey(m.payload, carriers[i]) });
|
|
141
|
+
groups.set(m.type, list);
|
|
142
|
+
}
|
|
143
|
+
for (const [name, jobs] of groups) {
|
|
144
|
+
await boss.createQueue(name);
|
|
145
|
+
await boss.insert(name, jobs);
|
|
146
|
+
}
|
|
147
|
+
});
|
|
136
148
|
}
|
|
137
149
|
async close() {}
|
|
138
150
|
};
|
|
@@ -174,20 +186,36 @@ var PgBossSubscriber = class PgBossSubscriber {
|
|
|
174
186
|
await boss.createQueue(queue);
|
|
175
187
|
for (const type of messages) await boss.subscribe(topicEvent(topic, type), queue);
|
|
176
188
|
await boss.work(queue, work, async (jobs) => {
|
|
177
|
-
for (const job of jobs)
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
189
|
+
for (const job of jobs) {
|
|
190
|
+
const { data, carrier } = withoutTraceKey(job.data);
|
|
191
|
+
await consumeTraced({
|
|
192
|
+
system: "pgboss",
|
|
193
|
+
destination: topic,
|
|
194
|
+
type: data.type,
|
|
195
|
+
messageId: job.id
|
|
196
|
+
}, carrier, () => listener({
|
|
197
|
+
type: data.type,
|
|
198
|
+
payload: data.payload
|
|
199
|
+
}));
|
|
200
|
+
}
|
|
181
201
|
});
|
|
182
202
|
return;
|
|
183
203
|
}
|
|
184
204
|
for (const messageType of messages) {
|
|
185
205
|
await boss.createQueue(messageType);
|
|
186
206
|
await boss.work(messageType, work, async (jobs) => {
|
|
187
|
-
for (const job of jobs)
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
207
|
+
for (const job of jobs) {
|
|
208
|
+
const { data, carrier } = withoutTraceKey(job.data);
|
|
209
|
+
await consumeTraced({
|
|
210
|
+
system: "pgboss",
|
|
211
|
+
destination: messageType,
|
|
212
|
+
type: job.name,
|
|
213
|
+
messageId: job.id
|
|
214
|
+
}, carrier, () => listener({
|
|
215
|
+
type: job.name,
|
|
216
|
+
payload: data
|
|
217
|
+
}));
|
|
218
|
+
}
|
|
191
219
|
});
|
|
192
220
|
}
|
|
193
221
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/pgboss/PgBossConnection.ts","../../src/pgboss/errors.ts","../../src/pgboss/PgBossPublisher.ts","../../src/pgboss/PgBossSubscriber.ts","../../src/pgboss/driver.ts"],"sourcesContent":["import { PgBoss } from 'pg-boss';\nimport type { EventConnection } from '../types';\nimport { EventPublisherType } from '../types';\n\nexport interface PgBossConnectionConfig {\n\tconnectionString: string;\n\tschema?: string;\n\t/**\n\t * Who this connection is to Postgres. Defaults to `GKM_APP_NAME`, which a\n\t * generated entry sets to the construct it runs — so the broker's\n\t * connections are named for the process that holds them, as its database\n\t * pools are, rather than all being `pgboss`.\n\t */\n\tapplicationName?: string;\n}\n\nexport class PgBossConnection implements EventConnection {\n\treadonly type = EventPublisherType.PgBoss;\n\tprivate boss?: PgBoss;\n\tprivate connecting?: Promise<void>;\n\n\tconstructor(private config: PgBossConnectionConfig) {}\n\n\t/**\n\t * Create a PgBossConnection from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss\n\t */\n\tstatic async fromConnectionString(\n\t\tconnectionString: string,\n\t): Promise<PgBossConnection> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst postgresUrl = `postgres://${url.username ? `${url.username}:${url.password}@` : ''}${url.host}${url.pathname}`;\n\n\t\tconst config: PgBossConnectionConfig = {\n\t\t\tconnectionString: postgresUrl,\n\t\t\tschema: params.get('schema') || undefined,\n\t\t};\n\n\t\tconst connection = new PgBossConnection(config);\n\t\tawait connection.connect();\n\t\treturn connection;\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tif (this.boss) return;\n\n\t\tif (this.connecting) {\n\t\t\tawait this.connecting;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.connecting = (async () => {\n\t\t\ttry {\n\t\t\t\tconst applicationName =\n\t\t\t\t\tthis.config.applicationName ?? process.env.GKM_APP_NAME;\n\t\t\t\tconst boss = new PgBoss({\n\t\t\t\t\tconnectionString: this.config.connectionString,\n\t\t\t\t\t...(this.config.schema && { schema: this.config.schema }),\n\t\t\t\t\t...(applicationName && { application_name: applicationName }),\n\t\t\t\t});\n\n\t\t\t\tawait boss.start();\n\t\t\t\tthis.boss = boss;\n\t\t\t} catch (error) {\n\t\t\t\tthis.cleanup();\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t})();\n\n\t\tawait this.connecting;\n\t\tthis.connecting = undefined;\n\t}\n\n\tasync close(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.boss?.stop({ graceful: true });\n\t\t} catch {\n\t\t\t// Ignore errors during close\n\t\t} finally {\n\t\t\tthis.cleanup();\n\t\t}\n\t}\n\n\tisConnected(): boolean {\n\t\treturn !!this.boss;\n\t}\n\n\tprivate cleanup(): void {\n\t\tthis.boss = undefined;\n\t\tthis.connecting = undefined;\n\t}\n\n\t/**\n\t * Get the underlying pg-boss instance for publishing/subscribing\n\t */\n\tget instance(): PgBoss | undefined {\n\t\treturn this.boss;\n\t}\n}\n","// Beside the adapter but apart from its connection module, which imports\n// the broker's client: the publisher and subscriber load that lazily, and\n// importing an error class from it would load it eagerly.\n\n/** pg-boss connected but its instance never started. */\nexport class PgBossNotStarted extends Error {\n\tconstructor() {\n\t\tsuper(\n\t\t\t'pg-boss did not start. Check the database in the connection string is reachable and the role may create the pg-boss schema.',\n\t\t);\n\t\tthis.name = 'PgBossNotStarted';\n\t}\n}\n\n/** A topic subscription with no name to give the subscriber's own queue. */\nexport class PgBossSubscriptionNeedsName extends Error {\n\tconstructor(readonly topic: string) {\n\t\tsuper(\n\t\t\t`Subscribing to topic '${topic}' on pg-boss needs a subscription name: ` +\n\t\t\t\t'each subscriber drains a queue of its own, and that queue is named ' +\n\t\t\t\t'for it. Pass `subscription`.',\n\t\t);\n\t\tthis.name = 'PgBossSubscriptionNeedsName';\n\t}\n}\n","import type { EventPublisher, PublishableMessage } from '../types';\nimport { PgBossNotStarted } from './errors';\nimport type { PgBossConnection } from './PgBossConnection';\n\nexport interface PgBossPublisherOptions {\n\t/**\n\t * Publishing to a topic: each message is fanned out to every subscriber's\n\t * own queue rather than inserted into one shared queue. Without it, a\n\t * message goes to the queue named by its type — a work queue, one consumer.\n\t */\n\ttopic?: string;\n}\n\n/** The pg-boss event a topic's message type is published as. */\nexport function topicEvent(topic: string, type: string): string {\n\treturn `${topic}/${type}`;\n}\n\nexport class PgBossPublisher<TMessage extends PublishableMessage<string, any>>\n\timplements EventPublisher<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: PgBossConnection,\n\t\tprivate options: PgBossPublisherOptions = {},\n\t) {}\n\n\t/**\n\t * Create a PgBossPublisher from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(\n\t\tconnectionString: string,\n\t\toptions: PgBossPublisherOptions = {},\n\t): Promise<PgBossPublisher<TMessage>> {\n\t\tconst { PgBossConnection } = await import('./PgBossConnection');\n\t\tconst connection =\n\t\t\tawait PgBossConnection.fromConnectionString(connectionString);\n\t\treturn new PgBossPublisher<TMessage>(connection, options);\n\t}\n\n\tasync publish(messages: TMessage[]): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst boss = this.connection.instance;\n\t\tif (!boss) {\n\t\t\tthrow new PgBossNotStarted();\n\t\t}\n\n\t\t// A topic: pg-boss copies the job into every queue subscribed to the\n\t\t// event — one per subscriber — so each subscriber sees each message.\n\t\t// The type rides in the data, because the job is named for the queue.\n\t\tconst { topic } = this.options;\n\t\tif (topic) {\n\t\t\tfor (const m of messages) {\n\t\t\t\tawait boss.publish(topicEvent(topic, m.type), {\n\t\t\t\t\ttype: m.type,\n\t\t\t\t\tpayload: m.payload,\n\t\t\t\t});\n\t\t\t}\n\t\t\treturn;\n\t\t}\n\n\t\t// Group jobs by queue name (v11+ requires per-queue insert calls)\n\t\tconst groups = new Map<string, { data: TMessage['payload'] }[]>();\n\t\tfor (const m of messages) {\n\t\t\tconst list = groups.get(m.type) ?? [];\n\t\t\tlist.push({ data: m.payload });\n\t\t\tgroups.set(m.type, list);\n\t\t}\n\n\t\tfor (const [name, jobs] of groups) {\n\t\t\tawait boss.createQueue(name);\n\t\t\tawait boss.insert(name, jobs);\n\t\t}\n\t}\n\n\tasync close(): Promise<void> {\n\t\t// Publisher doesn't own the connection\n\t}\n}\n","import type { EventSubscriber, PublishableMessage } from '../types';\nimport { PgBossNotStarted, PgBossSubscriptionNeedsName } from './errors';\nimport type { PgBossConnection } from './PgBossConnection';\nimport { topicEvent } from './PgBossPublisher';\n\nexport interface PgBossSubscriberOptions {\n\tbatchSize?: number;\n\tpollingIntervalSeconds?: number;\n\t/**\n\t * Subscribing to a topic. Each subscriber then drains a queue of its own,\n\t * `<topic>/<subscription>`, bound to the events it names — so every\n\t * subscriber sees every message, and replicas of one subscriber share it.\n\t * Without it, messages are drained from the queue named by their type:\n\t * work shared among whoever drains it.\n\t */\n\ttopic?: string;\n\t/** The subscriber's own name on the topic. Required with `topic`. */\n\tsubscription?: string;\n}\n\nexport class PgBossSubscriber<TMessage extends PublishableMessage<string, any>>\n\timplements EventSubscriber<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: PgBossConnection,\n\t\tprivate options: PgBossSubscriberOptions = {},\n\t) {}\n\n\t/**\n\t * Create a PgBossSubscriber from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss&batchSize=5\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<PgBossSubscriber<TMessage>> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst { PgBossConnection } = await import('./PgBossConnection');\n\t\tconst connection =\n\t\t\tawait PgBossConnection.fromConnectionString(connectionString);\n\n\t\tconst options: PgBossSubscriberOptions = {\n\t\t\tbatchSize: params.get('batchSize')\n\t\t\t\t? Number.parseInt(params.get('batchSize')!, 10)\n\t\t\t\t: undefined,\n\t\t\tpollingIntervalSeconds: params.get('pollingIntervalSeconds')\n\t\t\t\t? Number.parseInt(params.get('pollingIntervalSeconds')!, 10)\n\t\t\t\t: undefined,\n\t\t};\n\n\t\treturn new PgBossSubscriber<TMessage>(connection, options);\n\t}\n\n\tasync subscribe(\n\t\tmessages: TMessage['type'][],\n\t\tlistener: (payload: TMessage) => Promise<void>,\n\t): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst boss = this.connection.instance;\n\t\tif (!boss) {\n\t\t\tthrow new PgBossNotStarted();\n\t\t}\n\n\t\tconst work = {\n\t\t\t...(this.options.batchSize && { batchSize: this.options.batchSize }),\n\t\t\t...(this.options.pollingIntervalSeconds && {\n\t\t\t\tpollingIntervalSeconds: this.options.pollingIntervalSeconds,\n\t\t\t}),\n\t\t};\n\n\t\tconst { topic, subscription } = this.options;\n\t\tif (topic) {\n\t\t\tif (!subscription) throw new PgBossSubscriptionNeedsName(topic);\n\n\t\t\tconst queue = topicEvent(topic, subscription);\n\t\t\tawait boss.createQueue(queue);\n\t\t\tfor (const type of messages) {\n\t\t\t\tawait boss.subscribe(topicEvent(topic, type), queue);\n\t\t\t}\n\t\t\tawait boss.work<{ type: string; payload: unknown }>(\n\t\t\t\tqueue,\n\t\t\t\twork,\n\t\t\t\tasync (jobs) => {\n\t\t\t\t\tfor (const job of jobs) {\n\t\t\t\t\t\tawait listener({\n\t\t\t\t\t\t\ttype: job.data.type,\n\t\t\t\t\t\t\tpayload: job.data.payload,\n\t\t\t\t\t\t} as TMessage);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const messageType of messages) {\n\t\t\tawait boss.createQueue(messageType);\n\t\t\tawait boss.work(messageType, work, async (jobs) => {\n\t\t\t\tfor (const job of jobs) {\n\t\t\t\t\tconst fullMessage = {\n\t\t\t\t\t\ttype: job.name,\n\t\t\t\t\t\tpayload: job.data,\n\t\t\t\t\t} as TMessage;\n\n\t\t\t\t\tawait listener(fullMessage);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n}\n","import type { EventsDriver } from '../registry';\nimport { EventPublisherType } from '../types';\nimport { PgBossConnection } from './PgBossConnection';\nimport { PgBossPublisher } from './PgBossPublisher';\nimport { PgBossSubscriber } from './PgBossSubscriber';\n\n/**\n * `pgboss://` — queues and topics in Postgres. Register it with\n * `registerEventsDriver(pgbossEventsDriver)`; this subpath is the only one\n * that imports `pg-boss`.\n */\nexport const pgbossEventsDriver: EventsDriver = {\n\tscheme: EventPublisherType.PgBoss,\n\tconnect: (url) => PgBossConnection.fromConnectionString(url),\n\tpublisher: (url, options) =>\n\t\tPgBossPublisher.fromConnectionString(url, options),\n\tpublisherFor: (connection, options) =>\n\t\tnew PgBossPublisher(connection as PgBossConnection, options),\n\tsubscriber: (url) => PgBossSubscriber.fromConnectionString(url),\n\tsubscriberFor: (connection, options) =>\n\t\tnew PgBossSubscriber(connection as PgBossConnection, options),\n};\n"],"mappings":";;;;;AAgBA,IAAa,mBAAb,MAAa,iBAA4C;CAKpC;CAJpB,OAAS;CACT;CACA;CAEA,YAAY,QAAwC;EAAhC,KAAA,SAAA;CAAiC;;;;;CAMrD,aAAa,qBACZ,kBAC4B;EAC5B,MAAM,MAAM,IAAI,IAAI,gBAAgB;EACpC,MAAM,SAAS,IAAI;EAInB,MAAM,SAAiC;GACtC,kBAAkB,cAHe,IAAI,WAAW,GAAG,IAAI,SAAS,GAAG,IAAI,SAAS,KAAK,KAAK,IAAI,OAAO,IAAI;GAIzG,QAAQ,OAAO,IAAI,QAAQ,KAAK,KAAA;EACjC;EAEA,MAAM,aAAa,IAAI,iBAAiB,MAAM;EAC9C,MAAM,WAAW,QAAQ;EACzB,OAAO;CACR;CAEA,MAAM,UAAyB;EAC9B,IAAI,KAAK,MAAM;EAEf,IAAI,KAAK,YAAY;GACpB,MAAM,KAAK;GACX;EACD;EAEA,KAAK,cAAc,YAAY;GAC9B,IAAI;IACH,MAAM,kBACL,KAAK,OAAO,mBAAmB,QAAQ,IAAI;IAC5C,MAAM,OAAO,IAAI,OAAO;KACvB,kBAAkB,KAAK,OAAO;KAC9B,GAAI,KAAK,OAAO,UAAU,EAAE,QAAQ,KAAK,OAAO,OAAO;KACvD,GAAI,mBAAmB,EAAE,kBAAkB,gBAAgB;IAC5D,CAAC;IAED,MAAM,KAAK,MAAM;IACjB,KAAK,OAAO;GACb,SAAS,OAAO;IACf,KAAK,QAAQ;IACb,MAAM;GACP;EACD,EAAA,CAAG;EAEH,MAAM,KAAK;EACX,KAAK,aAAa,KAAA;CACnB;CAEA,MAAM,QAAu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KAAK,QAAQ,UAAU;GAClE,GAAI,KAAK,QAAQ,0BAA0B,EAC1C,wBAAwB,KAAK,QAAQ,uBACtC;EACD;EAEA,MAAM,EAAE,OAAO,iBAAiB,KAAK;EACrC,IAAI,OAAO;GACV,IAAI,CAAC,cAAc,MAAM,IAAI,4BAA4B,KAAK;GAE9D,MAAM,QAAQ,WAAW,OAAO,YAAY;GAC5C,MAAM,KAAK,YAAY,KAAK;GAC5B,KAAK,MAAM,QAAQ,UAClB,MAAM,KAAK,UAAU,WAAW,OAAO,IAAI,GAAG,KAAK;GAEpD,MAAM,KAAK,KACV,OACA,MACA,OAAO,SAAS;IACf,KAAK,MAAM,OAAO,MACjB,MAAM,SAAS;KACd,MAAM,IAAI,KAAK;KACf,SAAS,IAAI,KAAK;IACnB,CAAa;GAEf,CACD;GACA;EACD;EAEA,KAAK,MAAM,eAAe,UAAU;GACnC,MAAM,KAAK,YAAY,WAAW;GAClC,MAAM,KAAK,KAAK,aAAa,MAAM,OAAO,SAAS;IAClD,KAAK,MAAM,OAAO,MAMjB,MAAM,SAAS;KAJd,MAAM,IAAI;KACV,SAAS,IAAI;IAGW,CAAC;GAE5B,CAAC;EACF;CACD;AACD;;;;;;;;ACrGA,MAAa,qBAAmC;CAC/C,QAAA;CACA,UAAU,QAAQ,iBAAiB,qBAAqB,GAAG;CAC3D,YAAY,KAAK,YAChB,gBAAgB,qBAAqB,KAAK,OAAO;CAClD,eAAe,YAAY,YAC1B,IAAI,gBAAgB,YAAgC,OAAO;CAC5D,aAAa,QAAQ,iBAAiB,qBAAqB,GAAG;CAC9D,gBAAgB,YAAY,YAC3B,IAAI,iBAAiB,YAAgC,OAAO;AAC9D"}
|
|
1
|
+
{"version":3,"file":"index.mjs","names":[],"sources":["../../src/pgboss/PgBossConnection.ts","../../src/pgboss/errors.ts","../../src/pgboss/PgBossPublisher.ts","../../src/pgboss/PgBossSubscriber.ts","../../src/pgboss/driver.ts"],"sourcesContent":["import { PgBoss } from 'pg-boss';\nimport type { EventConnection } from '../types';\nimport { EventPublisherType } from '../types';\n\nexport interface PgBossConnectionConfig {\n\tconnectionString: string;\n\tschema?: string;\n\t/**\n\t * Who this connection is to Postgres. Defaults to `GKM_APP_NAME`, which a\n\t * generated entry sets to the construct it runs — so the broker's\n\t * connections are named for the process that holds them, as its database\n\t * pools are, rather than all being `pgboss`.\n\t */\n\tapplicationName?: string;\n}\n\nexport class PgBossConnection implements EventConnection {\n\treadonly type = EventPublisherType.PgBoss;\n\tprivate boss?: PgBoss;\n\tprivate connecting?: Promise<void>;\n\n\tconstructor(private config: PgBossConnectionConfig) {}\n\n\t/**\n\t * Create a PgBossConnection from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss\n\t */\n\tstatic async fromConnectionString(\n\t\tconnectionString: string,\n\t): Promise<PgBossConnection> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst postgresUrl = `postgres://${url.username ? `${url.username}:${url.password}@` : ''}${url.host}${url.pathname}`;\n\n\t\tconst config: PgBossConnectionConfig = {\n\t\t\tconnectionString: postgresUrl,\n\t\t\tschema: params.get('schema') || undefined,\n\t\t};\n\n\t\tconst connection = new PgBossConnection(config);\n\t\tawait connection.connect();\n\t\treturn connection;\n\t}\n\n\tasync connect(): Promise<void> {\n\t\tif (this.boss) return;\n\n\t\tif (this.connecting) {\n\t\t\tawait this.connecting;\n\t\t\treturn;\n\t\t}\n\n\t\tthis.connecting = (async () => {\n\t\t\ttry {\n\t\t\t\tconst applicationName =\n\t\t\t\t\tthis.config.applicationName ?? process.env.GKM_APP_NAME;\n\t\t\t\tconst boss = new PgBoss({\n\t\t\t\t\tconnectionString: this.config.connectionString,\n\t\t\t\t\t...(this.config.schema && { schema: this.config.schema }),\n\t\t\t\t\t...(applicationName && { application_name: applicationName }),\n\t\t\t\t});\n\n\t\t\t\tawait boss.start();\n\t\t\t\tthis.boss = boss;\n\t\t\t} catch (error) {\n\t\t\t\tthis.cleanup();\n\t\t\t\tthrow error;\n\t\t\t}\n\t\t})();\n\n\t\tawait this.connecting;\n\t\tthis.connecting = undefined;\n\t}\n\n\tasync close(): Promise<void> {\n\t\ttry {\n\t\t\tawait this.boss?.stop({ graceful: true });\n\t\t} catch {\n\t\t\t// Ignore errors during close\n\t\t} finally {\n\t\t\tthis.cleanup();\n\t\t}\n\t}\n\n\tisConnected(): boolean {\n\t\treturn !!this.boss;\n\t}\n\n\tprivate cleanup(): void {\n\t\tthis.boss = undefined;\n\t\tthis.connecting = undefined;\n\t}\n\n\t/**\n\t * Get the underlying pg-boss instance for publishing/subscribing\n\t */\n\tget instance(): PgBoss | undefined {\n\t\treturn this.boss;\n\t}\n}\n","// Beside the adapter but apart from its connection module, which imports\n// the broker's client: the publisher and subscriber load that lazily, and\n// importing an error class from it would load it eagerly.\n\n/** pg-boss connected but its instance never started. */\nexport class PgBossNotStarted extends Error {\n\tconstructor() {\n\t\tsuper(\n\t\t\t'pg-boss did not start. Check the database in the connection string is reachable and the role may create the pg-boss schema.',\n\t\t);\n\t\tthis.name = 'PgBossNotStarted';\n\t}\n}\n\n/** A topic subscription with no name to give the subscriber's own queue. */\nexport class PgBossSubscriptionNeedsName extends Error {\n\tconstructor(readonly topic: string) {\n\t\tsuper(\n\t\t\t`Subscribing to topic '${topic}' on pg-boss needs a subscription name: ` +\n\t\t\t\t'each subscriber drains a queue of its own, and that queue is named ' +\n\t\t\t\t'for it. Pass `subscription`.',\n\t\t);\n\t\tthis.name = 'PgBossSubscriptionNeedsName';\n\t}\n}\n","import { publishTraced, withTraceKey } from '../telemetry';\nimport type { EventPublisher, PublishableMessage } from '../types';\nimport { PgBossNotStarted } from './errors';\nimport type { PgBossConnection } from './PgBossConnection';\n\nexport interface PgBossPublisherOptions {\n\t/**\n\t * Publishing to a topic: each message is fanned out to every subscriber's\n\t * own queue rather than inserted into one shared queue. Without it, a\n\t * message goes to the queue named by its type — a work queue, one consumer.\n\t */\n\ttopic?: string;\n}\n\n/** The pg-boss event a topic's message type is published as. */\nexport function topicEvent(topic: string, type: string): string {\n\treturn `${topic}/${type}`;\n}\n\nexport class PgBossPublisher<TMessage extends PublishableMessage<string, any>>\n\timplements EventPublisher<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: PgBossConnection,\n\t\tprivate options: PgBossPublisherOptions = {},\n\t) {}\n\n\t/**\n\t * Create a PgBossPublisher from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(\n\t\tconnectionString: string,\n\t\toptions: PgBossPublisherOptions = {},\n\t): Promise<PgBossPublisher<TMessage>> {\n\t\tconst { PgBossConnection } = await import('./PgBossConnection');\n\t\tconst connection =\n\t\t\tawait PgBossConnection.fromConnectionString(connectionString);\n\t\treturn new PgBossPublisher<TMessage>(connection, options);\n\t}\n\n\tasync publish(messages: TMessage[]): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst boss = this.connection.instance;\n\t\tif (!boss) {\n\t\t\tthrow new PgBossNotStarted();\n\t\t}\n\n\t\t// A topic: pg-boss copies the job into every queue subscribed to the\n\t\t// event — one per subscriber — so each subscriber sees each message.\n\t\t// The type rides in the data, because the job is named for the queue.\n\t\t//\n\t\t// pg-boss has no header field, so the trace context rides in the data\n\t\t// too, under a reserved key the subscriber removes before the handler.\n\t\tconst { topic } = this.options;\n\t\tif (topic) {\n\t\t\tawait publishTraced(\n\t\t\t\tmessages,\n\t\t\t\t(m) => ({ system: 'pgboss', destination: topic, type: m.type }),\n\t\t\t\tasync (carriers) => {\n\t\t\t\t\tfor (const [i, m] of messages.entries()) {\n\t\t\t\t\t\tawait boss.publish(\n\t\t\t\t\t\t\ttopicEvent(topic, m.type),\n\t\t\t\t\t\t\twithTraceKey({ type: m.type, payload: m.payload }, carriers[i]),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tawait publishTraced(\n\t\t\tmessages,\n\t\t\t(m) => ({ system: 'pgboss', destination: m.type, type: m.type }),\n\t\t\tasync (carriers) => {\n\t\t\t\t// Group jobs by queue name (v11+ requires per-queue insert calls)\n\t\t\t\tconst groups = new Map<string, { data: TMessage['payload'] }[]>();\n\t\t\t\tfor (const [i, m] of messages.entries()) {\n\t\t\t\t\tconst list = groups.get(m.type) ?? [];\n\t\t\t\t\tlist.push({ data: withTraceKey(m.payload, carriers[i]) });\n\t\t\t\t\tgroups.set(m.type, list);\n\t\t\t\t}\n\n\t\t\t\tfor (const [name, jobs] of groups) {\n\t\t\t\t\tawait boss.createQueue(name);\n\t\t\t\t\tawait boss.insert(name, jobs);\n\t\t\t\t}\n\t\t\t},\n\t\t);\n\t}\n\n\tasync close(): Promise<void> {\n\t\t// Publisher doesn't own the connection\n\t}\n}\n","import { consumeTraced, withoutTraceKey } from '../telemetry';\nimport type { EventSubscriber, PublishableMessage } from '../types';\nimport { PgBossNotStarted, PgBossSubscriptionNeedsName } from './errors';\nimport type { PgBossConnection } from './PgBossConnection';\nimport { topicEvent } from './PgBossPublisher';\n\nexport interface PgBossSubscriberOptions {\n\tbatchSize?: number;\n\tpollingIntervalSeconds?: number;\n\t/**\n\t * Subscribing to a topic. Each subscriber then drains a queue of its own,\n\t * `<topic>/<subscription>`, bound to the events it names — so every\n\t * subscriber sees every message, and replicas of one subscriber share it.\n\t * Without it, messages are drained from the queue named by their type:\n\t * work shared among whoever drains it.\n\t */\n\ttopic?: string;\n\t/** The subscriber's own name on the topic. Required with `topic`. */\n\tsubscription?: string;\n}\n\nexport class PgBossSubscriber<TMessage extends PublishableMessage<string, any>>\n\timplements EventSubscriber<TMessage>\n{\n\tconstructor(\n\t\tprivate connection: PgBossConnection,\n\t\tprivate options: PgBossSubscriberOptions = {},\n\t) {}\n\n\t/**\n\t * Create a PgBossSubscriber from a connection string.\n\t * Format: pgboss://user:pass@host:5432/database?schema=pgboss&batchSize=5\n\t */\n\tstatic async fromConnectionString<\n\t\tTMessage extends PublishableMessage<string, any>,\n\t>(connectionString: string): Promise<PgBossSubscriber<TMessage>> {\n\t\tconst url = new URL(connectionString);\n\t\tconst params = url.searchParams;\n\n\t\tconst { PgBossConnection } = await import('./PgBossConnection');\n\t\tconst connection =\n\t\t\tawait PgBossConnection.fromConnectionString(connectionString);\n\n\t\tconst options: PgBossSubscriberOptions = {\n\t\t\tbatchSize: params.get('batchSize')\n\t\t\t\t? Number.parseInt(params.get('batchSize')!, 10)\n\t\t\t\t: undefined,\n\t\t\tpollingIntervalSeconds: params.get('pollingIntervalSeconds')\n\t\t\t\t? Number.parseInt(params.get('pollingIntervalSeconds')!, 10)\n\t\t\t\t: undefined,\n\t\t};\n\n\t\treturn new PgBossSubscriber<TMessage>(connection, options);\n\t}\n\n\tasync subscribe(\n\t\tmessages: TMessage['type'][],\n\t\tlistener: (payload: TMessage) => Promise<void>,\n\t): Promise<void> {\n\t\tif (!this.connection.isConnected()) {\n\t\t\tawait this.connection.connect();\n\t\t}\n\n\t\tconst boss = this.connection.instance;\n\t\tif (!boss) {\n\t\t\tthrow new PgBossNotStarted();\n\t\t}\n\n\t\tconst work = {\n\t\t\t...(this.options.batchSize && { batchSize: this.options.batchSize }),\n\t\t\t...(this.options.pollingIntervalSeconds && {\n\t\t\t\tpollingIntervalSeconds: this.options.pollingIntervalSeconds,\n\t\t\t}),\n\t\t};\n\n\t\tconst { topic, subscription } = this.options;\n\t\tif (topic) {\n\t\t\tif (!subscription) throw new PgBossSubscriptionNeedsName(topic);\n\n\t\t\tconst queue = topicEvent(topic, subscription);\n\t\t\tawait boss.createQueue(queue);\n\t\t\tfor (const type of messages) {\n\t\t\t\tawait boss.subscribe(topicEvent(topic, type), queue);\n\t\t\t}\n\t\t\tawait boss.work<{ type: string; payload: unknown }>(\n\t\t\t\tqueue,\n\t\t\t\twork,\n\t\t\t\tasync (jobs) => {\n\t\t\t\t\tfor (const job of jobs) {\n\t\t\t\t\t\tconst { data, carrier } = withoutTraceKey(job.data);\n\t\t\t\t\t\tawait consumeTraced(\n\t\t\t\t\t\t\t{\n\t\t\t\t\t\t\t\tsystem: 'pgboss',\n\t\t\t\t\t\t\t\tdestination: topic,\n\t\t\t\t\t\t\t\ttype: data.type,\n\t\t\t\t\t\t\t\tmessageId: job.id,\n\t\t\t\t\t\t\t},\n\t\t\t\t\t\t\tcarrier,\n\t\t\t\t\t\t\t() =>\n\t\t\t\t\t\t\t\tlistener({\n\t\t\t\t\t\t\t\t\ttype: data.type,\n\t\t\t\t\t\t\t\t\tpayload: data.payload,\n\t\t\t\t\t\t\t\t} as TMessage),\n\t\t\t\t\t\t);\n\t\t\t\t\t}\n\t\t\t\t},\n\t\t\t);\n\t\t\treturn;\n\t\t}\n\n\t\tfor (const messageType of messages) {\n\t\t\tawait boss.createQueue(messageType);\n\t\t\tawait boss.work(messageType, work, async (jobs) => {\n\t\t\t\tfor (const job of jobs) {\n\t\t\t\t\t// The trace context is taken out of the data here, so the\n\t\t\t\t\t// handler's payload is exactly what was published.\n\t\t\t\t\tconst { data, carrier } = withoutTraceKey(job.data);\n\t\t\t\t\tawait consumeTraced(\n\t\t\t\t\t\t{\n\t\t\t\t\t\t\tsystem: 'pgboss',\n\t\t\t\t\t\t\tdestination: messageType,\n\t\t\t\t\t\t\ttype: job.name,\n\t\t\t\t\t\t\tmessageId: job.id,\n\t\t\t\t\t\t},\n\t\t\t\t\t\tcarrier,\n\t\t\t\t\t\t() => listener({ type: job.name, payload: data } as TMessage),\n\t\t\t\t\t);\n\t\t\t\t}\n\t\t\t});\n\t\t}\n\t}\n}\n","import type { EventsDriver } from '../registry';\nimport { EventPublisherType } from '../types';\nimport { PgBossConnection } from './PgBossConnection';\nimport { PgBossPublisher } from './PgBossPublisher';\nimport { PgBossSubscriber } from './PgBossSubscriber';\n\n/**\n * `pgboss://` — queues and topics in Postgres. Register it with\n * `registerEventsDriver(pgbossEventsDriver)`; this subpath is the only one\n * that imports `pg-boss`.\n */\nexport const pgbossEventsDriver: EventsDriver = {\n\tscheme: EventPublisherType.PgBoss,\n\tconnect: (url) => PgBossConnection.fromConnectionString(url),\n\tpublisher: (url, options) =>\n\t\tPgBossPublisher.fromConnectionString(url, options),\n\tpublisherFor: (connection, options) =>\n\t\tnew PgBossPublisher(connection as PgBossConnection, options),\n\tsubscriber: (url) => PgBossSubscriber.fromConnectionString(url),\n\tsubscriberFor: (connection, options) =>\n\t\tnew PgBossSubscriber(connection as PgBossConnection, options),\n};\n"],"mappings":";;;;;AAgBA,IAAa,mBAAb,MAAa,iBAA4C;CAKpC;CAJpB,OAAS;CACT;CACA;CAEA,YAAY,QAAwC;EAAhC,KAAA,SAAA;CAAiC;;;;;CAMrD,aAAa,qBACZ,kBAC4B;EAC5B,MAAM,MAAM,IAAI,IAAI,gBAAgB;EACpC,MAAM,SAAS,IAAI;EAInB,MAAM,SAAiC;GACtC,kBAAkB,cAHe,IAAI,WAAW,GAAG,IAAI,SAAS,GAAG,IAAI,SAAS,KAAK,KAAK,IAAI,OAAO,IAAI;GAIzG,QAAQ,OAAO,IAAI,QAAQ,KAAK,KAAA;EACjC;EAEA,MAAM,aAAa,IAAI,iBAAiB,MAAM;EAC9C,MAAM,WAAW,QAAQ;EACzB,OAAO;CACR;CAEA,MAAM,UAAyB;EAC9B,IAAI,KAAK,MAAM;EAEf,IAAI,KAAK,YAAY;GACpB,MAAM,KAAK;GACX;EACD;EAEA,KAAK,cAAc,YAAY;GAC9B,IAAI;IACH,MAAM,kBACL,KAAK,OAAO,mBAAmB,QAAQ,IAAI;IAC5C,MAAM,OAAO,IAAI,OAAO;KACvB,kBAAkB,KAAK,OAAO;KAC9B,GAAI,KAAK,OAAO,UAAU,EAAE,QAAQ,KAAK,OAAO,OAAO;KACvD,GAAI,mBAAmB,EAAE,kBAAkB,gBAAgB;IAC5D,CAAC;IAED,MAAM,KAAK,MAAM;IACjB,KAAK,OAAO;GACb,SAAS,OAAO;IACf,KAAK,QA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gBAAgB,IAAI,IAAI;KAClD,MAAM,cACL;MACC,QAAQ;MACR,aAAa;MACb,MAAM,IAAI;MACV,WAAW,IAAI;KAChB,GACA,eACM,SAAS;MAAE,MAAM,IAAI;MAAM,SAAS;KAAK,CAAa,CAC7D;IACD;GACD,CAAC;EACF;CACD;AACD;;;;;;;;ACxHA,MAAa,qBAAmC;CAC/C,QAAA;CACA,UAAU,QAAQ,iBAAiB,qBAAqB,GAAG;CAC3D,YAAY,KAAK,YAChB,gBAAgB,qBAAqB,KAAK,OAAO;CAClD,eAAe,YAAY,YAC1B,IAAI,gBAAgB,YAAgC,OAAO;CAC5D,aAAa,QAAQ,iBAAiB,qBAAqB,GAAG;CAC9D,gBAAgB,YAAY,YAC3B,IAAI,iBAAiB,YAAgC,OAAO;AAC9D"}
|
package/dist/rabbitmq/index.cjs
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
2
2
|
const require_rolldown_runtime = require("../rolldown-runtime-C0BPl7ul.cjs");
|
|
3
|
-
require("../
|
|
3
|
+
const require_telemetry = require("../telemetry-DG3l807O.cjs");
|
|
4
4
|
let amqplib = require("amqplib");
|
|
5
5
|
amqplib = require_rolldown_runtime.__toESM(amqplib, 1);
|
|
6
6
|
//#region src/rabbitmq/RabbitMQConnection.ts
|
|
@@ -136,17 +136,27 @@ var RabbitMQPublisher = class RabbitMQPublisher {
|
|
|
136
136
|
const channel = this.connection.amqpChannel;
|
|
137
137
|
if (!channel) throw new RabbitMQChannelUnavailable();
|
|
138
138
|
const exchange = this.connection.exchangeName;
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
139
|
+
await require_telemetry.publishTraced(messages, (message) => ({
|
|
140
|
+
system: "rabbitmq",
|
|
141
|
+
destination: exchange,
|
|
142
|
+
type: message.type
|
|
143
|
+
}), async (carriers) => {
|
|
144
|
+
for (const [i, message] of messages.entries()) {
|
|
145
|
+
const content = Buffer.from(JSON.stringify(message.payload));
|
|
146
|
+
const { headers, ...publishOptions } = this.options.publishOptions ?? {};
|
|
147
|
+
if (!channel.publish(exchange, message.type, content, {
|
|
148
|
+
contentType: "application/json",
|
|
149
|
+
timestamp: Date.now(),
|
|
150
|
+
type: message.type,
|
|
151
|
+
persistent: true,
|
|
152
|
+
...publishOptions,
|
|
153
|
+
...(headers || carriers[i]) && { headers: {
|
|
154
|
+
...headers,
|
|
155
|
+
...carriers[i]
|
|
156
|
+
} }
|
|
157
|
+
})) await new Promise((resolve) => channel.once("drain", resolve));
|
|
158
|
+
}
|
|
159
|
+
});
|
|
150
160
|
}
|
|
151
161
|
async close() {}
|
|
152
162
|
};
|
|
@@ -191,10 +201,17 @@ var RabbitMQSubscriber = class RabbitMQSubscriber {
|
|
|
191
201
|
try {
|
|
192
202
|
const content = msg.content.toString();
|
|
193
203
|
const payload = JSON.parse(content);
|
|
194
|
-
|
|
195
|
-
|
|
204
|
+
const messageType = msg.properties.type;
|
|
205
|
+
const fullMessage = {
|
|
206
|
+
type: messageType,
|
|
196
207
|
payload
|
|
197
|
-
}
|
|
208
|
+
};
|
|
209
|
+
await require_telemetry.consumeTraced({
|
|
210
|
+
system: "rabbitmq",
|
|
211
|
+
destination: queue,
|
|
212
|
+
type: messageType,
|
|
213
|
+
messageId: msg.properties.messageId
|
|
214
|
+
}, require_telemetry.carrierFromAttributes(msg.properties.headers), () => listener(fullMessage));
|
|
198
215
|
channel.ack(msg);
|
|
199
216
|
} catch (_error) {
|
|
200
217
|
channel.nack(msg, false, true);
|