arvo-event-handler 3.0.1 → 3.0.2
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.
|
@@ -270,7 +270,7 @@ var ArvoEventHandler = /** @class */ (function (_super) {
|
|
|
270
270
|
try {
|
|
271
271
|
handlerContract = this.contract.version((_p = parsedDataSchema === null || parsedDataSchema === void 0 ? void 0 : parsedDataSchema.version) !== null && _p !== void 0 ? _p : 'latest');
|
|
272
272
|
}
|
|
273
|
-
catch (
|
|
273
|
+
catch (_0) {
|
|
274
274
|
throw new errors_1.ConfigViolation("Invalid contract version: ".concat(parsedDataSchema === null || parsedDataSchema === void 0 ? void 0 : parsedDataSchema.version, ". Available versions: ").concat(Object.keys(this.contract.versions).join(', ')));
|
|
275
275
|
}
|
|
276
276
|
(0, arvo_core_1.logToSpan)({
|
|
@@ -186,7 +186,7 @@ var ArvoOrchestrator = /** @class */ (function (_super) {
|
|
|
186
186
|
try {
|
|
187
187
|
arvo_core_1.ArvoOrchestrationSubject.parse(event.data.parentSubject$$);
|
|
188
188
|
}
|
|
189
|
-
catch (
|
|
189
|
+
catch (_v) {
|
|
190
190
|
throw new errors_1.ExecutionViolation("Invalid parentSubject$$ for the event(type='".concat(event.type, "', uri='").concat((_j = event.dataschema) !== null && _j !== void 0 ? _j : arvo_core_1.EventDataschemaUtil.create(contract), "').It must be follow the ArvoOrchestrationSubject schema. The easiest way is to use the current orchestration subject by storing the subject via the context block in the machine definition."));
|
|
191
191
|
}
|
|
192
192
|
}
|
|
@@ -553,7 +553,7 @@ var ArvoOrchestrator = /** @class */ (function (_super) {
|
|
|
553
553
|
// Otherwise, use event id. If the error is in init event
|
|
554
554
|
// then it will be the same as initEventId. Otherwise,
|
|
555
555
|
// we still would know what cause this error
|
|
556
|
-
parentid: initEventId ? initEventId : event.id,
|
|
556
|
+
parentid: initEventId !== null && initEventId !== void 0 ? initEventId : event.id,
|
|
557
557
|
domain: _dom,
|
|
558
558
|
}));
|
|
559
559
|
for (_j = 0, _k = Object.entries(result[result.length - 1].otelAttributes); _j < _k.length; _j++) {
|
|
@@ -247,7 +247,7 @@ var ArvoResumable = /** @class */ (function (_super) {
|
|
|
247
247
|
try {
|
|
248
248
|
arvo_core_1.ArvoOrchestrationSubject.parse(event.data.parentSubject$$);
|
|
249
249
|
}
|
|
250
|
-
catch (
|
|
250
|
+
catch (_v) {
|
|
251
251
|
throw new errors_1.ExecutionViolation("Invalid parentSubject$$ for the event(type='".concat(event.type, "', uri='").concat((_j = event.dataschema) !== null && _j !== void 0 ? _j : arvo_core_1.EventDataschemaUtil.create(contract), "').It must be follow the ArvoOrchestrationSubject schema. The easiest way is to use the current orchestration subject by storing the subject via the context block in the machine definition."));
|
|
252
252
|
}
|
|
253
253
|
}
|
|
@@ -396,9 +396,9 @@ var ArvoResumable = /** @class */ (function (_super) {
|
|
|
396
396
|
disableSpanManagement: true,
|
|
397
397
|
fn: function (span) { return __awaiter(_this, void 0, void 0, function () {
|
|
398
398
|
var otelHeaders, orchestrationParentSubject, acquiredLock, initEventId, parsedEventSubject, contractType, state, eventTypeToExpectedEvent, _i, _a, _b, _, eventList, _c, eventList_1, _evt, handler, executionResult, emittables, _d, _e, item, domains, _f, _g, _dom, evt, _h, _j, _k, key, value, eventTrackingState, error_2, e, parsedEventSubject, result, _l, _m, _dom, _o, _p, _q, key, value;
|
|
399
|
-
var _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11;
|
|
400
|
-
return __generator(this, function (
|
|
401
|
-
switch (
|
|
399
|
+
var _r, _s, _t, _u, _v, _w, _x, _y, _z, _0, _1, _2, _3, _4, _5, _6, _7, _8, _9, _10, _11, _12;
|
|
400
|
+
return __generator(this, function (_13) {
|
|
401
|
+
switch (_13.label) {
|
|
402
402
|
case 0:
|
|
403
403
|
(0, arvo_core_1.logToSpan)({
|
|
404
404
|
level: 'INFO',
|
|
@@ -408,9 +408,9 @@ var ArvoResumable = /** @class */ (function (_super) {
|
|
|
408
408
|
orchestrationParentSubject = null;
|
|
409
409
|
acquiredLock = null;
|
|
410
410
|
initEventId = null;
|
|
411
|
-
|
|
411
|
+
_13.label = 1;
|
|
412
412
|
case 1:
|
|
413
|
-
|
|
413
|
+
_13.trys.push([1, 6, 7, 9]);
|
|
414
414
|
///////////////////////////////////////////////////////////////
|
|
415
415
|
// Subject resolution, handler resolution and input validation
|
|
416
416
|
///////////////
|
|
@@ -457,7 +457,7 @@ var ArvoResumable = /** @class */ (function (_super) {
|
|
|
457
457
|
///////////////////////////////////////////////////////////////
|
|
458
458
|
// State locking, acquiry and handler exection
|
|
459
459
|
///////////////////////////////////////////////////////////////
|
|
460
|
-
acquiredLock =
|
|
460
|
+
acquiredLock = _13.sent();
|
|
461
461
|
if (acquiredLock === 'NOT_ACQUIRED') {
|
|
462
462
|
throw new error_1.TransactionViolation({
|
|
463
463
|
cause: error_1.TransactionViolationCause.LOCK_UNACQUIRED,
|
|
@@ -473,7 +473,7 @@ var ArvoResumable = /** @class */ (function (_super) {
|
|
|
473
473
|
}
|
|
474
474
|
return [4 /*yield*/, this.syncEventResource.acquireState(event)];
|
|
475
475
|
case 3:
|
|
476
|
-
state =
|
|
476
|
+
state = _13.sent();
|
|
477
477
|
orchestrationParentSubject = (_r = state === null || state === void 0 ? void 0 : state.parentSubject) !== null && _r !== void 0 ? _r : null;
|
|
478
478
|
initEventId = (_s = state === null || state === void 0 ? void 0 : state.initEventId) !== null && _s !== void 0 ? _s : event.id;
|
|
479
479
|
if ((state === null || state === void 0 ? void 0 : state.status) === 'done') {
|
|
@@ -544,7 +544,7 @@ var ArvoResumable = /** @class */ (function (_super) {
|
|
|
544
544
|
},
|
|
545
545
|
})];
|
|
546
546
|
case 4:
|
|
547
|
-
executionResult =
|
|
547
|
+
executionResult = _13.sent();
|
|
548
548
|
emittables = [];
|
|
549
549
|
for (_d = 0, _e = __spreadArray(__spreadArray([], ((executionResult === null || executionResult === void 0 ? void 0 : executionResult.output)
|
|
550
550
|
? [
|
|
@@ -557,9 +557,9 @@ var ArvoResumable = /** @class */ (function (_super) {
|
|
|
557
557
|
: [undefined],
|
|
558
558
|
},
|
|
559
559
|
]
|
|
560
|
-
: []), true), ((executionResult === null || executionResult === void 0 ? void 0 : executionResult.services) ?
|
|
560
|
+
: []), true), ((_4 = executionResult === null || executionResult === void 0 ? void 0 : executionResult.services) !== null && _4 !== void 0 ? _4 : []), true); _d < _e.length; _d++) {
|
|
561
561
|
item = _e[_d];
|
|
562
|
-
domains = (
|
|
562
|
+
domains = (_5 = item.domain) !== null && _5 !== void 0 ? _5 : [null];
|
|
563
563
|
for (_f = 0, _g = Array.from(new Set(domains)); _f < _g.length; _f++) {
|
|
564
564
|
_dom = _g[_f];
|
|
565
565
|
evt = this.createEmittableEvent(item, otelHeaders, orchestrationParentSubject, event, this.contracts.self.version(parsedEventSubject.orchestrator.version), initEventId, _dom);
|
|
@@ -578,7 +578,7 @@ var ArvoResumable = /** @class */ (function (_super) {
|
|
|
578
578
|
consumed: event.toJSON(),
|
|
579
579
|
expected: emittables.length
|
|
580
580
|
? Object.fromEntries(emittables.map(function (item) { return [item.id, []]; }))
|
|
581
|
-
: ((
|
|
581
|
+
: ((_6 = state === null || state === void 0 ? void 0 : state.events.expected) !== null && _6 !== void 0 ? _6 : null),
|
|
582
582
|
produced: emittables.map(function (item) { return item.toJSON(); }),
|
|
583
583
|
};
|
|
584
584
|
// Write to the memory
|
|
@@ -588,11 +588,11 @@ var ArvoResumable = /** @class */ (function (_super) {
|
|
|
588
588
|
parentSubject: orchestrationParentSubject,
|
|
589
589
|
subject: event.subject,
|
|
590
590
|
events: eventTrackingState,
|
|
591
|
-
state$$: (
|
|
591
|
+
state$$: (_8 = (_7 = executionResult === null || executionResult === void 0 ? void 0 : executionResult.context) !== null && _7 !== void 0 ? _7 : state === null || state === void 0 ? void 0 : state.state$$) !== null && _8 !== void 0 ? _8 : null,
|
|
592
592
|
}, state, span)];
|
|
593
593
|
case 5:
|
|
594
594
|
// Write to the memory
|
|
595
|
-
|
|
595
|
+
_13.sent();
|
|
596
596
|
(0, arvo_core_1.logToSpan)({
|
|
597
597
|
level: 'INFO',
|
|
598
598
|
message: "State update persisted in memory for subject ".concat(event.subject),
|
|
@@ -603,7 +603,7 @@ var ArvoResumable = /** @class */ (function (_super) {
|
|
|
603
603
|
});
|
|
604
604
|
return [2 /*return*/, { events: emittables }];
|
|
605
605
|
case 6:
|
|
606
|
-
error_2 =
|
|
606
|
+
error_2 = _13.sent();
|
|
607
607
|
e = (0, index_2.isError)(error_2)
|
|
608
608
|
? error_2
|
|
609
609
|
: new errors_1.ExecutionViolation("Non-Error object thrown during machine execution: ".concat(typeof error_2, ". This indicates a serious implementation flaw."));
|
|
@@ -648,17 +648,17 @@ var ArvoResumable = /** @class */ (function (_super) {
|
|
|
648
648
|
subject: orchestrationParentSubject !== null && orchestrationParentSubject !== void 0 ? orchestrationParentSubject : event.subject,
|
|
649
649
|
// The system error must always go back to
|
|
650
650
|
// the source which initiated it
|
|
651
|
-
to: (
|
|
651
|
+
to: (_9 = parsedEventSubject === null || parsedEventSubject === void 0 ? void 0 : parsedEventSubject.execution.initiator) !== null && _9 !== void 0 ? _9 : event.source,
|
|
652
652
|
error: e,
|
|
653
|
-
traceparent: (
|
|
654
|
-
tracestate: (
|
|
655
|
-
accesscontrol: (
|
|
653
|
+
traceparent: (_10 = otelHeaders.traceparent) !== null && _10 !== void 0 ? _10 : undefined,
|
|
654
|
+
tracestate: (_11 = otelHeaders.tracestate) !== null && _11 !== void 0 ? _11 : undefined,
|
|
655
|
+
accesscontrol: (_12 = event.accesscontrol) !== null && _12 !== void 0 ? _12 : undefined,
|
|
656
656
|
executionunits: this.executionunits,
|
|
657
657
|
// If there is initEventID then use that.
|
|
658
658
|
// Otherwise, use event id. If the error is in init event
|
|
659
659
|
// then it will be the same as initEventId. Otherwise,
|
|
660
660
|
// we still would know what cause this error
|
|
661
|
-
parentid: initEventId ? initEventId : event.id,
|
|
661
|
+
parentid: initEventId !== null && initEventId !== void 0 ? initEventId : event.id,
|
|
662
662
|
domain: _dom,
|
|
663
663
|
}));
|
|
664
664
|
for (_o = 0, _p = Object.entries(result[result.length - 1].otelAttributes); _o < _p.length; _o++) {
|
|
@@ -671,7 +671,7 @@ var ArvoResumable = /** @class */ (function (_super) {
|
|
|
671
671
|
}];
|
|
672
672
|
case 7: return [4 /*yield*/, this.syncEventResource.releaseLock(event, acquiredLock, span)];
|
|
673
673
|
case 8:
|
|
674
|
-
|
|
674
|
+
_13.sent();
|
|
675
675
|
span.end();
|
|
676
676
|
return [7 /*endfinally*/];
|
|
677
677
|
case 9: return [2 /*return*/];
|
|
@@ -107,7 +107,7 @@ var MachineExecutionEngine = /** @class */ (function () {
|
|
|
107
107
|
});
|
|
108
108
|
var extractedSnapshot = actor.getPersistedSnapshot();
|
|
109
109
|
if ((_b = (_a = extractedSnapshot === null || extractedSnapshot === void 0 ? void 0 : extractedSnapshot.context) === null || _a === void 0 ? void 0 : _a.arvo$$) === null || _b === void 0 ? void 0 : _b.volatile$$) {
|
|
110
|
-
// biome-ignore lint/complexity/noForEach:
|
|
110
|
+
// biome-ignore lint/complexity/noForEach: This is fine
|
|
111
111
|
((_e = (_d = (_c = extractedSnapshot === null || extractedSnapshot === void 0 ? void 0 : extractedSnapshot.context) === null || _c === void 0 ? void 0 : _c.arvo$$) === null || _d === void 0 ? void 0 : _d.volatile$$) === null || _e === void 0 ? void 0 : _e.eventQueue$$).forEach(function (item) { return eventQueue.push(item); });
|
|
112
112
|
extractedSnapshot.context.arvo$$.volatile$$ = undefined;
|
|
113
113
|
}
|
|
@@ -192,8 +192,6 @@ var _1 = require(".");
|
|
|
192
192
|
*/
|
|
193
193
|
var createSimpleEventBroker = function (eventHandlers, options) {
|
|
194
194
|
var _a;
|
|
195
|
-
var resolvedHandlerName = 'broker.arvo.simple.handle';
|
|
196
|
-
var resolvedHandlerNameDuplicated = false;
|
|
197
195
|
var broker = new _1.SimpleEventBroker({
|
|
198
196
|
maxQueueSize: 1000,
|
|
199
197
|
errorHandler: (_a = options === null || options === void 0 ? void 0 : options.onError) !== null && _a !== void 0 ? _a : (function (error, event) {
|
|
@@ -204,10 +202,7 @@ var createSimpleEventBroker = function (eventHandlers, options) {
|
|
|
204
202
|
});
|
|
205
203
|
}),
|
|
206
204
|
});
|
|
207
|
-
|
|
208
|
-
// biome-ignore lint/complexity/noForEach: TODO - fix later
|
|
209
|
-
eventHandlers.forEach(function (handler) {
|
|
210
|
-
resolvedHandlerNameDuplicated = broker.topics.includes(resolvedHandlerName);
|
|
205
|
+
var _loop_1 = function (handler) {
|
|
211
206
|
broker.subscribe(handler.source, function (event) { return __awaiter(void 0, void 0, void 0, function () {
|
|
212
207
|
var response, _i, _a, evt;
|
|
213
208
|
var _b;
|
|
@@ -243,7 +238,12 @@ var createSimpleEventBroker = function (eventHandlers, options) {
|
|
|
243
238
|
}
|
|
244
239
|
});
|
|
245
240
|
}); }, true);
|
|
246
|
-
}
|
|
241
|
+
};
|
|
242
|
+
// Wire up each handler to its source topic
|
|
243
|
+
for (var _i = 0, eventHandlers_1 = eventHandlers; _i < eventHandlers_1.length; _i++) {
|
|
244
|
+
var handler = eventHandlers_1[_i];
|
|
245
|
+
_loop_1(handler);
|
|
246
|
+
}
|
|
247
247
|
return {
|
|
248
248
|
broker: broker,
|
|
249
249
|
resolve: function (_event) { return __awaiter(void 0, void 0, void 0, function () {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arvo-event-handler",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.2",
|
|
4
4
|
"description": "Type-safe event handler system with versioning, telemetry, and contract validation for distributed Arvo event-driven architectures, featuring routing and multi-handler support.",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|