@arvo-tools/postgres 1.3.0 → 1.3.1

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.
@@ -1,108 +1,10 @@
1
1
  "use strict";
2
- var __extends = (this && this.__extends) || (function () {
3
- var extendStatics = function (d, b) {
4
- extendStatics = Object.setPrototypeOf ||
5
- ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) ||
6
- function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; };
7
- return extendStatics(d, b);
8
- };
9
- return function (d, b) {
10
- if (typeof b !== "function" && b !== null)
11
- throw new TypeError("Class extends value " + String(b) + " is not a constructor or null");
12
- extendStatics(d, b);
13
- function __() { this.constructor = d; }
14
- d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
15
- };
16
- })();
17
- var __assign = (this && this.__assign) || function () {
18
- __assign = Object.assign || function(t) {
19
- for (var s, i = 1, n = arguments.length; i < n; i++) {
20
- s = arguments[i];
21
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
22
- t[p] = s[p];
23
- }
24
- return t;
25
- };
26
- return __assign.apply(this, arguments);
27
- };
28
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
- return new (P || (P = Promise))(function (resolve, reject) {
31
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
- step((generator = generator.apply(thisArg, _arguments || [])).next());
35
- });
36
- };
37
- var __generator = (this && this.__generator) || function (thisArg, body) {
38
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g = Object.create((typeof Iterator === "function" ? Iterator : Object).prototype);
39
- return g.next = verb(0), g["throw"] = verb(1), g["return"] = verb(2), typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
- function verb(n) { return function (v) { return step([n, v]); }; }
41
- function step(op) {
42
- if (f) throw new TypeError("Generator is already executing.");
43
- while (g && (g = 0, op[0] && (_ = 0)), _) try {
44
- if (f = 1, y && (t = op[0] & 2 ? y["return"] : op[0] ? y["throw"] || ((t = y["return"]) && t.call(y), 0) : y.next) && !(t = t.call(y, op[1])).done) return t;
45
- if (y = 0, t) op = [op[0] & 2, t.value];
46
- switch (op[0]) {
47
- case 0: case 1: t = op; break;
48
- case 4: _.label++; return { value: op[1], done: false };
49
- case 5: _.label++; y = op[1]; op = [0]; continue;
50
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
- default:
52
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
- if (t[2]) _.ops.pop();
57
- _.trys.pop(); continue;
58
- }
59
- op = body.call(thisArg, _);
60
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
- }
63
- };
64
- var __rest = (this && this.__rest) || function (s, e) {
65
- var t = {};
66
- for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p) && e.indexOf(p) < 0)
67
- t[p] = s[p];
68
- if (s != null && typeof Object.getOwnPropertySymbols === "function")
69
- for (var i = 0, p = Object.getOwnPropertySymbols(s); i < p.length; i++) {
70
- if (e.indexOf(p[i]) < 0 && Object.prototype.propertyIsEnumerable.call(s, p[i]))
71
- t[p[i]] = s[p[i]];
72
- }
73
- return t;
74
- };
75
- var __read = (this && this.__read) || function (o, n) {
76
- var m = typeof Symbol === "function" && o[Symbol.iterator];
77
- if (!m) return o;
78
- var i = m.call(o), r, ar = [], e;
79
- try {
80
- while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value);
81
- }
82
- catch (error) { e = { error: error }; }
83
- finally {
84
- try {
85
- if (r && !r.done && (m = i["return"])) m.call(i);
86
- }
87
- finally { if (e) throw e.error; }
88
- }
89
- return ar;
90
- };
91
- var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
92
- if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
93
- if (ar || !(i in from)) {
94
- if (!ar) ar = Array.prototype.slice.call(from, 0, i);
95
- ar[i] = from[i];
96
- }
97
- }
98
- return to.concat(ar || Array.prototype.slice.call(from));
99
- };
100
2
  Object.defineProperty(exports, "__esModule", { value: true });
101
3
  exports.PostgresEventBroker = void 0;
102
- var api_1 = require("@opentelemetry/api");
103
- var arvo_core_1 = require("arvo-core");
104
- var pg_boss_1 = require("pg-boss");
105
- var utils_1 = require("./utils");
4
+ const api_1 = require("@opentelemetry/api");
5
+ const arvo_core_1 = require("arvo-core");
6
+ const pg_boss_1 = require("pg-boss");
7
+ const utils_1 = require("./utils");
106
8
  /**
107
9
  * Queue-based event broker for ArvoEvent handlers with automatic routing,
108
10
  * retry logic, and OpenTelemetry tracing support.
@@ -157,51 +59,26 @@ var utils_1 = require("./utils");
157
59
  * const stats = await broker.getStats();
158
60
  * ```
159
61
  */
160
- var PostgresEventBroker = /** @class */ (function (_super) {
161
- __extends(PostgresEventBroker, _super);
162
- function PostgresEventBroker() {
163
- var _this = _super.apply(this, __spreadArray([], __read(arguments), false)) || this;
164
- /**
165
- * Internal registry of handler configurations keyed by handler source.
166
- */
167
- _this.handlers = {};
168
- /**
169
- * Internal list of all registered queue names.
170
- */
171
- _this._queues = [];
172
- /**
173
- * Logger instance used for all broker operational logging.
174
- * Defaults to console but can be replaced via setLogger().
175
- */
176
- _this.logger = console;
177
- /**
178
- * The configured event source for workflow completion.
179
- */
180
- _this.injectionEventSource = null;
181
- /**
182
- * Default callback invoked when an event has no registered destination handler.
183
- */
184
- _this._onHandlerNotFound = function (event) {
185
- return _this.logger.error('Handler not found for event', event.toString(2));
186
- };
187
- /**
188
- * Callback invoked when a domained event is encountered during routing.
189
- */
190
- _this._onDomainedEvent = function (event) {
191
- return _this.logger.info('Domained event encountered', event.toString(2));
192
- };
193
- return _this;
62
+ class PostgresEventBroker extends pg_boss_1.PgBoss {
63
+ /**
64
+ * Internal registry of handler configurations keyed by handler source.
65
+ */
66
+ handlers = {};
67
+ /**
68
+ * Internal list of all registered queue names.
69
+ */
70
+ _queues = [];
71
+ /**
72
+ * List of all registered queue names in the broker.
73
+ */
74
+ get queues() {
75
+ return this._queues;
194
76
  }
195
- Object.defineProperty(PostgresEventBroker.prototype, "queues", {
196
- /**
197
- * List of all registered queue names in the broker.
198
- */
199
- get: function () {
200
- return this._queues;
201
- },
202
- enumerable: false,
203
- configurable: true
204
- });
77
+ /**
78
+ * Logger instance used for all broker operational logging.
79
+ * Defaults to console but can be replaced via setLogger().
80
+ */
81
+ logger = console;
205
82
  /**
206
83
  * Sets a custom logger for broker operations.
207
84
  *
@@ -223,9 +100,21 @@ var PostgresEventBroker = /** @class */ (function (_super) {
223
100
  * broker.setLogger(logger);
224
101
  * ```
225
102
  */
226
- PostgresEventBroker.prototype.setLogger = function (logger) {
103
+ setLogger(logger) {
227
104
  this.logger = logger;
228
- };
105
+ }
106
+ /**
107
+ * The configured event source for workflow completion.
108
+ */
109
+ injectionEventSource = null;
110
+ /**
111
+ * Default callback invoked when an event has no registered destination handler.
112
+ */
113
+ _onHandlerNotFound = (event) => this.logger.error('Handler not found for event', event.toString(2));
114
+ /**
115
+ * Callback invoked when a domained event is encountered during routing.
116
+ */
117
+ _onDomainedEvent = (event) => this.logger.info('Domained event encountered', event.toString(2));
229
118
  /**
230
119
  * Registers a handler for workflow completion events.
231
120
  *
@@ -258,70 +147,30 @@ var PostgresEventBroker = /** @class */ (function (_super) {
258
147
  * });
259
148
  * ```
260
149
  */
261
- PostgresEventBroker.prototype.onWorkflowComplete = function (param) {
262
- return __awaiter(this, void 0, void 0, function () {
263
- var i;
264
- var _this = this;
265
- var _a, _b, _c, _d, _e, _f, _g, _h;
266
- return __generator(this, function (_j) {
267
- switch (_j.label) {
268
- case 0:
269
- this.injectionEventSource = param.source;
270
- this.handlers[param.source] = { options: param.options };
271
- if (!((_a = param.options) === null || _a === void 0 ? void 0 : _a.recreateQueue)) return [3 /*break*/, 2];
272
- return [4 /*yield*/, this.deleteQueue(param.source)];
273
- case 1:
274
- _j.sent();
275
- _j.label = 2;
276
- case 2: return [4 /*yield*/, this.createQueue(param.source, (_b = param.options) === null || _b === void 0 ? void 0 : _b.queue)];
277
- case 3:
278
- _j.sent();
279
- i = 0;
280
- _j.label = 4;
281
- case 4:
282
- if (!(i < Math.max((_e = (_d = (_c = param.options) === null || _c === void 0 ? void 0 : _c.worker) === null || _d === void 0 ? void 0 : _d.concurrency) !== null && _e !== void 0 ? _e : 0, 1))) return [3 /*break*/, 7];
283
- return [4 /*yield*/, this.work(param.source, {
284
- pollingIntervalSeconds: (_h = (_g = (_f = param.options) === null || _f === void 0 ? void 0 : _f.worker) === null || _g === void 0 ? void 0 : _g.pollingIntervalSeconds) !== null && _h !== void 0 ? _h : 2,
285
- batchSize: 1,
286
- }, function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
287
- var eventFromJob_1, error_1;
288
- var _this = this;
289
- var _c = __read(_b, 1), job = _c[0];
290
- return __generator(this, function (_d) {
291
- switch (_d.label) {
292
- case 0:
293
- _d.trys.push([0, 2, , 3]);
294
- eventFromJob_1 = (0, utils_1.createArvoEventFromJob)(job);
295
- return [4 /*yield*/, api_1.context.with((0, utils_1.otelParentContext)(eventFromJob_1), function () { return __awaiter(_this, void 0, void 0, function () {
296
- return __generator(this, function (_a) {
297
- switch (_a.label) {
298
- case 0: return [4 /*yield*/, param.listener(eventFromJob_1)];
299
- case 1: return [2 /*return*/, _a.sent()];
300
- }
301
- });
302
- }); })];
303
- case 1:
304
- _d.sent();
305
- return [3 /*break*/, 3];
306
- case 2:
307
- error_1 = _d.sent();
308
- this.logger.error("[onWorkflowComplete] Error in worker handler for ".concat(param.source), error_1);
309
- return [3 /*break*/, 3];
310
- case 3: return [2 /*return*/];
311
- }
312
- });
313
- }); })];
314
- case 5:
315
- _j.sent();
316
- _j.label = 6;
317
- case 6:
318
- i++;
319
- return [3 /*break*/, 4];
320
- case 7: return [2 /*return*/];
150
+ async onWorkflowComplete(param) {
151
+ this.injectionEventSource = param.source;
152
+ this.handlers[param.source] = { options: param.options };
153
+ if (param.options?.recreateQueue) {
154
+ await this.deleteQueue(param.source);
155
+ }
156
+ await this.createQueue(param.source, param.options?.queue);
157
+ for (let i = 0; i < Math.max(param.options?.worker?.concurrency ?? 0, 1); i++) {
158
+ await this.work(param.source, {
159
+ pollingIntervalSeconds: param.options?.worker?.pollingIntervalSeconds ?? 2,
160
+ batchSize: 1,
161
+ }, async ([job]) => {
162
+ try {
163
+ const eventFromJob = (0, utils_1.createArvoEventFromJob)(job);
164
+ await api_1.context.with((0, utils_1.otelParentContext)(eventFromJob), async () => {
165
+ return await param.listener(eventFromJob);
166
+ });
167
+ }
168
+ catch (error) {
169
+ this.logger.error(`[onWorkflowComplete] Error in worker handler for ${param.source}`, error);
321
170
  }
322
171
  });
323
- });
324
- };
172
+ }
173
+ }
325
174
  /**
326
175
  * Sets a custom handler for events with no registered destination.
327
176
  *
@@ -345,9 +194,9 @@ var PostgresEventBroker = /** @class */ (function (_super) {
345
194
  * });
346
195
  * ```
347
196
  */
348
- PostgresEventBroker.prototype.onHandlerNotFound = function (listner) {
197
+ onHandlerNotFound(listner) {
349
198
  this._onHandlerNotFound = listner;
350
- };
199
+ }
351
200
  /**
352
201
  * Sets a custom handler for domained events.
353
202
  *
@@ -373,9 +222,9 @@ var PostgresEventBroker = /** @class */ (function (_super) {
373
222
  * });
374
223
  * ```
375
224
  */
376
- PostgresEventBroker.prototype.onDomainedEvent = function (listner) {
225
+ onDomainedEvent(listner) {
377
226
  this._onDomainedEvent = listner;
378
- };
227
+ }
379
228
  /**
380
229
  * Creates a queue and tracks it in the internal queue registry.
381
230
  * Overrides the base class method to maintain queue tracking.
@@ -383,14 +232,10 @@ var PostgresEventBroker = /** @class */ (function (_super) {
383
232
  * @param name - Queue name
384
233
  * @param options - Queue configuration options
385
234
  */
386
- PostgresEventBroker.prototype.createQueue = function (name, options) {
387
- return __awaiter(this, void 0, void 0, function () {
388
- return __generator(this, function (_a) {
389
- this._queues.push(name);
390
- return [2 /*return*/, _super.prototype.createQueue.call(this, name, options)];
391
- });
392
- });
393
- };
235
+ async createQueue(name, options) {
236
+ this._queues.push(name);
237
+ return super.createQueue(name, options);
238
+ }
394
239
  /**
395
240
  * Registers an event handler with the broker.
396
241
  *
@@ -417,102 +262,53 @@ var PostgresEventBroker = /** @class */ (function (_super) {
417
262
  * });
418
263
  * ```
419
264
  */
420
- PostgresEventBroker.prototype.register = function (handler, options) {
421
- return __awaiter(this, void 0, void 0, function () {
422
- var handlerSource, workHandler, i;
423
- var _this = this;
424
- var _a, _b, _c, _d;
425
- return __generator(this, function (_e) {
426
- switch (_e.label) {
427
- case 0:
428
- if (this.handlers[handler.source]) {
429
- throw new Error((0, arvo_core_1.cleanString)("\n Handler registration failed: A handler with source '".concat(handler.source, "' is already registered.\n Each handler must have a unique source identifier. Attempted duplicate registration will be\n ignored to prevent queue conflicts.\n ")));
265
+ async register(handler, options) {
266
+ if (this.handlers[handler.source]) {
267
+ throw new Error((0, arvo_core_1.cleanString)(`
268
+ Handler registration failed: A handler with source '${handler.source}' is already registered.
269
+ Each handler must have a unique source identifier. Attempted duplicate registration will be
270
+ ignored to prevent queue conflicts.
271
+ `));
272
+ }
273
+ this.handlers[handler.source] = { options: { ...options } };
274
+ if (options?.recreateQueue) {
275
+ await this.deleteQueue(handler.source);
276
+ }
277
+ await this.createQueue(handler.source, options?.queue);
278
+ const handlerSource = handler.source;
279
+ const workHandler = async ([job]) => {
280
+ try {
281
+ const eventFromJob = (0, utils_1.createArvoEventFromJob)(job);
282
+ const { events } = await api_1.context.with((0, utils_1.otelParentContext)(eventFromJob), async () => {
283
+ return await handler.execute(eventFromJob, {
284
+ inheritFrom: 'EVENT',
285
+ });
286
+ });
287
+ await Promise.all(events.map(async (evt) => {
288
+ if (evt.domain) {
289
+ try {
290
+ await this._onDomainedEvent?.(evt);
430
291
  }
431
- this.handlers[handler.source] = { options: __assign({}, options) };
432
- if (!(options === null || options === void 0 ? void 0 : options.recreateQueue)) return [3 /*break*/, 2];
433
- return [4 /*yield*/, this.deleteQueue(handler.source)];
434
- case 1:
435
- _e.sent();
436
- _e.label = 2;
437
- case 2: return [4 /*yield*/, this.createQueue(handler.source, options === null || options === void 0 ? void 0 : options.queue)];
438
- case 3:
439
- _e.sent();
440
- handlerSource = handler.source;
441
- workHandler = function (_a) { return __awaiter(_this, [_a], void 0, function (_b) {
442
- var eventFromJob_2, events, error_2;
443
- var _this = this;
444
- var _c = __read(_b, 1), job = _c[0];
445
- return __generator(this, function (_d) {
446
- switch (_d.label) {
447
- case 0:
448
- _d.trys.push([0, 3, , 4]);
449
- eventFromJob_2 = (0, utils_1.createArvoEventFromJob)(job);
450
- return [4 /*yield*/, api_1.context.with((0, utils_1.otelParentContext)(eventFromJob_2), function () { return __awaiter(_this, void 0, void 0, function () {
451
- return __generator(this, function (_a) {
452
- switch (_a.label) {
453
- case 0: return [4 /*yield*/, handler.execute(eventFromJob_2, {
454
- inheritFrom: 'EVENT',
455
- })];
456
- case 1: return [2 /*return*/, _a.sent()];
457
- }
458
- });
459
- }); })];
460
- case 1:
461
- events = (_d.sent()).events;
462
- return [4 /*yield*/, Promise.all(events.map(function (evt) { return __awaiter(_this, void 0, void 0, function () {
463
- var error_3;
464
- var _a;
465
- return __generator(this, function (_b) {
466
- switch (_b.label) {
467
- case 0:
468
- if (!evt.domain) return [3 /*break*/, 5];
469
- _b.label = 1;
470
- case 1:
471
- _b.trys.push([1, 3, , 4]);
472
- return [4 /*yield*/, ((_a = this._onDomainedEvent) === null || _a === void 0 ? void 0 : _a.call(this, evt))];
473
- case 2:
474
- _b.sent();
475
- return [3 /*break*/, 4];
476
- case 3:
477
- error_3 = _b.sent();
478
- this.logger.error('Error in onDomainedEvent', error_3);
479
- return [3 /*break*/, 4];
480
- case 4: return [2 /*return*/, undefined];
481
- case 5: return [4 /*yield*/, this._emitArvoEvent(evt)];
482
- case 6: return [2 /*return*/, _b.sent()];
483
- }
484
- });
485
- }); }))];
486
- case 2:
487
- _d.sent();
488
- return [3 /*break*/, 4];
489
- case 3:
490
- error_2 = _d.sent();
491
- this.logger.error("Error in worker handler for ".concat(handlerSource), error_2);
492
- throw error_2;
493
- case 4: return [2 /*return*/];
494
- }
495
- });
496
- }); };
497
- i = 0;
498
- _e.label = 4;
499
- case 4:
500
- if (!(i < Math.max((_b = (_a = options === null || options === void 0 ? void 0 : options.worker) === null || _a === void 0 ? void 0 : _a.concurrency) !== null && _b !== void 0 ? _b : 0, 1))) return [3 /*break*/, 7];
501
- return [4 /*yield*/, this.work(handler.source, {
502
- pollingIntervalSeconds: (_d = (_c = options === null || options === void 0 ? void 0 : options.worker) === null || _c === void 0 ? void 0 : _c.pollingIntervalSeconds) !== null && _d !== void 0 ? _d : 2,
503
- batchSize: 1,
504
- }, workHandler)];
505
- case 5:
506
- _e.sent();
507
- _e.label = 6;
508
- case 6:
509
- i++;
510
- return [3 /*break*/, 4];
511
- case 7: return [2 /*return*/];
512
- }
513
- });
514
- });
515
- };
292
+ catch (error) {
293
+ this.logger.error('Error in onDomainedEvent', error);
294
+ }
295
+ return undefined;
296
+ }
297
+ return await this._emitArvoEvent(evt);
298
+ }));
299
+ }
300
+ catch (error) {
301
+ this.logger.error(`Error in worker handler for ${handlerSource}`, error);
302
+ throw error;
303
+ }
304
+ };
305
+ for (let i = 0; i < Math.max(options?.worker?.concurrency ?? 0, 1); i++) {
306
+ await this.work(handler.source, {
307
+ pollingIntervalSeconds: options?.worker?.pollingIntervalSeconds ?? 2,
308
+ batchSize: 1,
309
+ }, workHandler);
310
+ }
311
+ }
516
312
  /**
517
313
  * Routes an ArvoEvent to its destination queue.
518
314
  *
@@ -523,34 +319,22 @@ var PostgresEventBroker = /** @class */ (function (_super) {
523
319
  * @param event - The ArvoEvent to route
524
320
  * @returns Job ID if sent successfully, null if handler not found
525
321
  */
526
- PostgresEventBroker.prototype._emitArvoEvent = function (event) {
527
- return __awaiter(this, void 0, void 0, function () {
528
- var e_1, _a, concurrency, pollingIntervalSeconds, rest;
529
- var _b, _c, _d;
530
- return __generator(this, function (_e) {
531
- switch (_e.label) {
532
- case 0:
533
- if (!(!event.to || !this._queues.includes(event.to))) return [3 /*break*/, 5];
534
- _e.label = 1;
535
- case 1:
536
- _e.trys.push([1, 3, , 4]);
537
- return [4 /*yield*/, ((_b = this._onHandlerNotFound) === null || _b === void 0 ? void 0 : _b.call(this, event))];
538
- case 2:
539
- _e.sent();
540
- return [3 /*break*/, 4];
541
- case 3:
542
- e_1 = _e.sent();
543
- this.logger.error('Error in onHandlerNotFound ', e_1);
544
- return [3 /*break*/, 4];
545
- case 4: return [2 /*return*/, null];
546
- case 5:
547
- _a = (_d = (_c = this.handlers[event.to].options) === null || _c === void 0 ? void 0 : _c.worker) !== null && _d !== void 0 ? _d : {}, concurrency = _a.concurrency, pollingIntervalSeconds = _a.pollingIntervalSeconds, rest = __rest(_a, ["concurrency", "pollingIntervalSeconds"]);
548
- return [4 /*yield*/, this.send(event.to, event.toJSON(), __assign({}, (rest !== null && rest !== void 0 ? rest : {})))];
549
- case 6: return [2 /*return*/, _e.sent()];
550
- }
551
- });
322
+ async _emitArvoEvent(event) {
323
+ if (!event.to || !this._queues.includes(event.to)) {
324
+ try {
325
+ await this._onHandlerNotFound?.(event);
326
+ }
327
+ catch (e) {
328
+ this.logger.error('Error in onHandlerNotFound ', e);
329
+ }
330
+ return null;
331
+ }
332
+ // biome-ignore lint/correctness/noUnusedVariables: This is need sadly
333
+ const { concurrency, pollingIntervalSeconds, ...rest } = this.handlers[event.to].options?.worker ?? {};
334
+ return await this.send(event.to, event.toJSON(), {
335
+ ...(rest ?? {}),
552
336
  });
553
- };
337
+ }
554
338
  /**
555
339
  * Dispatches an ArvoEvent into the broker system with validation.
556
340
  *
@@ -576,27 +360,31 @@ var PostgresEventBroker = /** @class */ (function (_super) {
576
360
  * await broker.dispatch(event);
577
361
  * ```
578
362
  */
579
- PostgresEventBroker.prototype.dispatch = function (event) {
580
- return __awaiter(this, void 0, void 0, function () {
581
- var _a;
582
- return __generator(this, function (_b) {
583
- switch (_b.label) {
584
- case 0:
585
- if (!this.injectionEventSource) {
586
- throw new Error((0, arvo_core_1.cleanString)("\n Workflow completion handler not configured: Cannot dispatch ArvoEvent without setting up\n the workflow completion handler. Call onWorkflowComplete({ source: string, handler: Function })\n to register the completion point before dispatching events into the system.\n "));
587
- }
588
- if (this.injectionEventSource !== event.source) {
589
- throw new Error((0, arvo_core_1.cleanString)("\n Event source mismatch: The dispatched event source '".concat(event.source, "' does not match the\n configured workflow completion source '").concat(this.injectionEventSource, "'. Events dispatched\n through dispatch() must originate from the source specified in onWorkflowComplete().\n Verify the event's source property matches '").concat(this.injectionEventSource, "'.\n ")));
590
- }
591
- if (!this._queues.includes((_a = event.to) !== null && _a !== void 0 ? _a : '')) {
592
- throw new Error((0, arvo_core_1.cleanString)("\n Handler not registered: No handler found for destination '".concat(event.to, "'. The target handler\n must be registered using register() before events can be routed to it. Register the required\n handler or verify the event's 'to' property is correct.\n ")));
593
- }
594
- return [4 /*yield*/, this._emitArvoEvent(event)];
595
- case 1: return [2 /*return*/, _b.sent()];
596
- }
597
- });
598
- });
599
- };
363
+ async dispatch(event) {
364
+ if (!this.injectionEventSource) {
365
+ throw new Error((0, arvo_core_1.cleanString)(`
366
+ Workflow completion handler not configured: Cannot dispatch ArvoEvent without setting up
367
+ the workflow completion handler. Call onWorkflowComplete({ source: string, handler: Function })
368
+ to register the completion point before dispatching events into the system.
369
+ `));
370
+ }
371
+ if (this.injectionEventSource !== event.source) {
372
+ throw new Error((0, arvo_core_1.cleanString)(`
373
+ Event source mismatch: The dispatched event source '${event.source}' does not match the
374
+ configured workflow completion source '${this.injectionEventSource}'. Events dispatched
375
+ through dispatch() must originate from the source specified in onWorkflowComplete().
376
+ Verify the event's source property matches '${this.injectionEventSource}'.
377
+ `));
378
+ }
379
+ if (!this._queues.includes(event.to ?? '')) {
380
+ throw new Error((0, arvo_core_1.cleanString)(`
381
+ Handler not registered: No handler found for destination '${event.to}'. The target handler
382
+ must be registered using register() before events can be routed to it. Register the required
383
+ handler or verify the event's 'to' property is correct.
384
+ `));
385
+ }
386
+ return await this._emitArvoEvent(event);
387
+ }
600
388
  /**
601
389
  * Retrieves statistics for all registered queues in the broker.
602
390
  *
@@ -610,20 +398,9 @@ var PostgresEventBroker = /** @class */ (function (_super) {
610
398
  * });
611
399
  * ```
612
400
  */
613
- PostgresEventBroker.prototype.getStats = function () {
614
- return __awaiter(this, void 0, void 0, function () {
615
- var _this = this;
616
- return __generator(this, function (_a) {
617
- switch (_a.label) {
618
- case 0: return [4 /*yield*/, Promise.all(this._queues.map(function (q) { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
619
- return [2 /*return*/, this.getQueueStats(q)];
620
- }); }); }))];
621
- case 1: return [2 /*return*/, _a.sent()];
622
- }
623
- });
624
- });
625
- };
626
- return PostgresEventBroker;
627
- }(pg_boss_1.PgBoss));
401
+ async getStats() {
402
+ return await Promise.all(this._queues.map(async (q) => this.getQueueStats(q)));
403
+ }
404
+ }
628
405
  exports.PostgresEventBroker = PostgresEventBroker;
629
406
  //# sourceMappingURL=index.js.map