arvo-event-handler 3.0.8 → 3.0.10
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/ArvoEventHandler/index.d.ts +2 -3
- package/dist/ArvoEventHandler/index.js +52 -70
- package/dist/ArvoEventHandler/types.d.ts +3 -2
- package/dist/ArvoOrchestrationUtils/createEmitableEvent.js +1 -1
- package/dist/ArvoOrchestrationUtils/handlerErrors.d.ts +3 -2
- package/dist/ArvoOrchestrationUtils/handlerErrors.js +6 -7
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.d.ts +5 -3
- package/dist/ArvoOrchestrationUtils/orchestrationExecutionWrapper/index.js +135 -142
- package/dist/ArvoOrchestrationUtils/servicesValidation.d.ts +22 -0
- package/dist/ArvoOrchestrationUtils/servicesValidation.js +56 -0
- package/dist/ArvoOrchestrationUtils/types.d.ts +7 -1
- package/dist/ArvoOrchestrationUtils/types.js +7 -0
- package/dist/ArvoOrchestrator/factory.d.ts +2 -2
- package/dist/ArvoOrchestrator/factory.js +2 -1
- package/dist/ArvoOrchestrator/index.d.ts +2 -1
- package/dist/ArvoOrchestrator/index.js +23 -8
- package/dist/ArvoOrchestrator/types.d.ts +16 -19
- package/dist/ArvoResumable/factory.d.ts +2 -0
- package/dist/ArvoResumable/factory.js +6 -25
- package/dist/ArvoResumable/index.d.ts +5 -3
- package/dist/ArvoResumable/index.js +20 -3
- package/dist/IArvoEventHandler/index.d.ts +1 -1
- package/dist/index.d.ts +4 -4
- package/dist/index.js +3 -3
- package/dist/types.d.ts +8 -0
- package/package.json +2 -2
|
@@ -1,7 +1,6 @@
|
|
|
1
|
-
import { type SpanOptions } from '@opentelemetry/api';
|
|
2
1
|
import { type ArvoContract, type ArvoEvent } from 'arvo-core';
|
|
3
2
|
import type IArvoEventHandler from '../IArvoEventHandler';
|
|
4
|
-
import type { ArvoEventHandlerOpenTelemetryOptions } from '../types';
|
|
3
|
+
import type { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions } from '../types';
|
|
5
4
|
import type { ArvoEventHandlerFunction, ArvoEventHandlerParam } from './types';
|
|
6
5
|
/**
|
|
7
6
|
* `ArvoEventHandler` is the foundational component for building stateless,
|
|
@@ -89,7 +88,7 @@ export default class ArvoEventHandler<TContract extends ArvoContract> implements
|
|
|
89
88
|
/** Computational cost metric associated with event handling operations */
|
|
90
89
|
readonly executionunits: number;
|
|
91
90
|
/** OpenTelemetry configuration for event handling spans */
|
|
92
|
-
readonly spanOptions:
|
|
91
|
+
readonly spanOptions: ArvoEventHandlerOtelSpanOptions;
|
|
93
92
|
/** Version-specific event handler implementation map */
|
|
94
93
|
readonly handler: ArvoEventHandlerFunction<TContract>;
|
|
95
94
|
/** The source identifier for events produced by this handler */
|
|
@@ -61,6 +61,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
61
61
|
var api_1 = require("@opentelemetry/api");
|
|
62
62
|
var arvo_core_1 = require("arvo-core");
|
|
63
63
|
var ArvoDomain_1 = require("../ArvoDomain");
|
|
64
|
+
var handlerErrors_1 = require("../ArvoOrchestrationUtils/handlerErrors");
|
|
65
|
+
var orchestrationExecutionWrapper_1 = require("../ArvoOrchestrationUtils/orchestrationExecutionWrapper");
|
|
64
66
|
var errors_1 = require("../errors");
|
|
65
67
|
var utils_1 = require("../utils");
|
|
66
68
|
/**
|
|
@@ -208,32 +210,32 @@ var ArvoEventHandler = /** @class */ (function () {
|
|
|
208
210
|
* in handler configuration, or when contract URI mismatch occurs
|
|
209
211
|
* @throws {ExecutionViolation} for explicitly handled runtime errors that should bubble up
|
|
210
212
|
*/
|
|
211
|
-
ArvoEventHandler.prototype.execute = function (
|
|
212
|
-
return __awaiter(this,
|
|
213
|
+
ArvoEventHandler.prototype.execute = function (event, opentelemetry) {
|
|
214
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
213
215
|
var otelConfig;
|
|
214
216
|
var _this = this;
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
return __generator(this, function (_a) {
|
|
219
|
-
switch (_a.label) {
|
|
217
|
+
var _a, _b;
|
|
218
|
+
return __generator(this, function (_c) {
|
|
219
|
+
switch (_c.label) {
|
|
220
220
|
case 0:
|
|
221
|
-
otelConfig = (0, utils_1.createEventHandlerTelemetryConfig)(
|
|
221
|
+
otelConfig = (0, utils_1.createEventHandlerTelemetryConfig)(((_b = (_a = this.spanOptions).spanName) === null || _b === void 0 ? void 0 : _b.call(_a, { selfContractUri: this.contract.uri, consumedEvent: event })) ||
|
|
222
|
+
"Handler<".concat(this.contract.uri, ">"), this.spanOptions, opentelemetry !== null && opentelemetry !== void 0 ? opentelemetry : { inheritFrom: 'EVENT' }, event);
|
|
222
223
|
return [4 /*yield*/, arvo_core_1.ArvoOpenTelemetry.getInstance().startActiveSpan(__assign(__assign({}, otelConfig), { fn: function (span) { return __awaiter(_this, void 0, void 0, function () {
|
|
223
|
-
var otelSpanHeaders, _i, _a, _b, key, value, parsedDataSchema, handlerContract_1, inputEventValidation, _handleOutput, outputs, result, _c, outputs_1, item, __extensions, handlerResult, domains, _d, _e, _dom, _f, _g, _h, key, value, error_1,
|
|
224
|
-
var
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
switch (_z.label) {
|
|
224
|
+
var otelSpanHeaders, _i, _a, _b, key, value, parsedDataSchema, handlerContract_1, inputEventValidation, _handleOutput, outputs, result, _c, outputs_1, item, __extensions, handlerResult, domains, _d, _e, _dom, _f, _g, _h, key, value, error_1, errorEvents, _j, _k, _l, errEvtIdx, errEvt, _m, _o, _p, key, value;
|
|
225
|
+
var _q, _r, _s, _t, _u, _v;
|
|
226
|
+
return __generator(this, function (_w) {
|
|
227
|
+
switch (_w.label) {
|
|
228
228
|
case 0:
|
|
229
229
|
otelSpanHeaders = (0, arvo_core_1.currentOpenTelemetryHeaders)();
|
|
230
|
-
|
|
230
|
+
_w.label = 1;
|
|
231
231
|
case 1:
|
|
232
|
-
|
|
232
|
+
_w.trys.push([1, 3, 4, 5]);
|
|
233
|
+
span.setAttribute('arvo.handler.execution.status', 'normal');
|
|
234
|
+
span.setAttribute('arvo.handler.execution.type', 'handler');
|
|
233
235
|
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
234
236
|
for (_i = 0, _a = Object.entries(event.otelAttributes); _i < _a.length; _i++) {
|
|
235
237
|
_b = _a[_i], key = _b[0], value = _b[1];
|
|
236
|
-
span.setAttribute("
|
|
238
|
+
span.setAttribute("consumable.0.".concat(key), value);
|
|
237
239
|
}
|
|
238
240
|
if (this.contract.type !== event.type) {
|
|
239
241
|
throw new errors_1.ConfigViolation("Event type mismatch: Received '".concat(event.type, "', expected '").concat(this.contract.type, "'"));
|
|
@@ -256,9 +258,9 @@ var ArvoEventHandler = /** @class */ (function () {
|
|
|
256
258
|
});
|
|
257
259
|
}
|
|
258
260
|
try {
|
|
259
|
-
handlerContract_1 = this.contract.version((
|
|
261
|
+
handlerContract_1 = this.contract.version((_q = parsedDataSchema === null || parsedDataSchema === void 0 ? void 0 : parsedDataSchema.version) !== null && _q !== void 0 ? _q : 'latest');
|
|
260
262
|
}
|
|
261
|
-
catch (
|
|
263
|
+
catch (_x) {
|
|
262
264
|
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(', ')));
|
|
263
265
|
}
|
|
264
266
|
(0, arvo_core_1.logToSpan)({
|
|
@@ -289,7 +291,7 @@ var ArvoEventHandler = /** @class */ (function () {
|
|
|
289
291
|
spanHeaders: otelSpanHeaders,
|
|
290
292
|
})];
|
|
291
293
|
case 2:
|
|
292
|
-
_handleOutput =
|
|
294
|
+
_handleOutput = _w.sent();
|
|
293
295
|
if (!_handleOutput)
|
|
294
296
|
return [2 /*return*/, {
|
|
295
297
|
events: [],
|
|
@@ -306,85 +308,65 @@ var ArvoEventHandler = /** @class */ (function () {
|
|
|
306
308
|
item = outputs_1[_c];
|
|
307
309
|
try {
|
|
308
310
|
__extensions = item.__extensions, handlerResult = __rest(item, ["__extensions"]);
|
|
309
|
-
domains = (
|
|
311
|
+
domains = (_s = (_r = handlerResult.domain) === null || _r === void 0 ? void 0 : _r.map(function (item) {
|
|
310
312
|
return (0, ArvoDomain_1.resolveEventDomain)({
|
|
311
313
|
domainToResolve: item,
|
|
312
314
|
handlerSelfContract: handlerContract_1,
|
|
313
315
|
eventContract: handlerContract_1,
|
|
314
316
|
triggeringEvent: event,
|
|
315
317
|
});
|
|
316
|
-
})) !== null &&
|
|
318
|
+
})) !== null && _s !== void 0 ? _s : [null];
|
|
317
319
|
for (_d = 0, _e = Array.from(new Set(domains)); _d < _e.length; _d++) {
|
|
318
320
|
_dom = _e[_d];
|
|
319
321
|
result.push((0, arvo_core_1.createArvoEventFactory)(handlerContract_1).emits(__assign(__assign({}, handlerResult), { traceparent: otelSpanHeaders.traceparent || undefined, tracestate: otelSpanHeaders.tracestate || undefined, source: this.source, subject: event.subject,
|
|
320
322
|
// 'source'
|
|
321
323
|
// prioritise returned 'to', 'redirectto' and then
|
|
322
|
-
to: (0, utils_1.coalesceOrDefault)([handlerResult.to, event.redirectto], event.source), executionunits: (0, utils_1.coalesce)(handlerResult.executionunits, this.executionunits), accesscontrol: (
|
|
324
|
+
to: (0, utils_1.coalesceOrDefault)([handlerResult.to, event.redirectto], event.source), executionunits: (0, utils_1.coalesce)(handlerResult.executionunits, this.executionunits), accesscontrol: (_u = (_t = handlerResult.accesscontrol) !== null && _t !== void 0 ? _t : event.accesscontrol) !== null && _u !== void 0 ? _u : undefined, parentid: event.id, domain: _dom }), __extensions));
|
|
323
325
|
for (_f = 0, _g = Object.entries(result[result.length - 1].otelAttributes); _f < _g.length; _f++) {
|
|
324
326
|
_h = _g[_f], key = _h[0], value = _h[1];
|
|
325
|
-
span.setAttribute("
|
|
327
|
+
span.setAttribute("emittables.".concat(result.length - 1, ".").concat(key), value);
|
|
326
328
|
}
|
|
327
329
|
}
|
|
328
330
|
}
|
|
329
331
|
catch (e) {
|
|
330
|
-
throw new errors_1.ContractViolation((
|
|
332
|
+
throw new errors_1.ContractViolation((_v = e === null || e === void 0 ? void 0 : e.message) !== null && _v !== void 0 ? _v : 'Invalid data');
|
|
331
333
|
}
|
|
332
334
|
}
|
|
333
|
-
(0,
|
|
334
|
-
level: 'INFO',
|
|
335
|
-
message: "Event processing completed successfully. Generated ".concat(result.length, " event(s)"),
|
|
336
|
-
});
|
|
337
|
-
(0, arvo_core_1.logToSpan)({
|
|
338
|
-
level: 'INFO',
|
|
339
|
-
message: 'Event handled successfully',
|
|
340
|
-
});
|
|
341
|
-
return [2 /*return*/, {
|
|
342
|
-
events: result,
|
|
343
|
-
}];
|
|
335
|
+
return [2 /*return*/, (0, orchestrationExecutionWrapper_1.returnEventsWithLogging)({ events: result }, span)];
|
|
344
336
|
case 3:
|
|
345
|
-
error_1 =
|
|
337
|
+
error_1 = _w.sent();
|
|
338
|
+
span.setAttribute('arvo.handler.execution.status', 'failure');
|
|
346
339
|
(0, arvo_core_1.exceptionToSpan)(error_1);
|
|
347
340
|
span.setStatus({
|
|
348
341
|
code: api_1.SpanStatusCode.ERROR,
|
|
349
342
|
message: "Event processing failed: ".concat(error_1.message),
|
|
350
343
|
});
|
|
351
|
-
if (
|
|
344
|
+
if ((0, arvo_core_1.isViolationError)(error_1)) {
|
|
352
345
|
throw error_1;
|
|
353
346
|
}
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
:
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
error: error_1,
|
|
373
|
-
executionunits: this.executionunits,
|
|
374
|
-
traceparent: (_v = otelSpanHeaders.traceparent) !== null && _v !== void 0 ? _v : undefined,
|
|
375
|
-
tracestate: (_w = otelSpanHeaders.tracestate) !== null && _w !== void 0 ? _w : undefined,
|
|
376
|
-
accesscontrol: (_x = event.accesscontrol) !== null && _x !== void 0 ? _x : undefined,
|
|
377
|
-
parentid: (_y = event.id) !== null && _y !== void 0 ? _y : undefined,
|
|
378
|
-
domain: _dom,
|
|
379
|
-
}));
|
|
380
|
-
for (_l = 0, _m = Object.entries(result[result.length - 1].otelAttributes); _l < _m.length; _l++) {
|
|
381
|
-
_o = _m[_l], key = _o[0], value = _o[1];
|
|
382
|
-
span.setAttribute("to_emit.".concat(result.length - 1, ".").concat(key), value);
|
|
347
|
+
errorEvents = (0, handlerErrors_1.createSystemErrorEvents)({
|
|
348
|
+
error: error_1,
|
|
349
|
+
event: event,
|
|
350
|
+
otelHeaders: otelSpanHeaders,
|
|
351
|
+
orchestrationParentSubject: null,
|
|
352
|
+
initEventId: event.id,
|
|
353
|
+
selfContract: this.contract.version('any'),
|
|
354
|
+
systemErrorDomain: undefined,
|
|
355
|
+
executionunits: this.executionunits,
|
|
356
|
+
source: this.source,
|
|
357
|
+
domain: this.domain,
|
|
358
|
+
handlerType: 'handler',
|
|
359
|
+
});
|
|
360
|
+
for (_j = 0, _k = Object.entries(errorEvents); _j < _k.length; _j++) {
|
|
361
|
+
_l = _k[_j], errEvtIdx = _l[0], errEvt = _l[1];
|
|
362
|
+
for (_m = 0, _o = Object.entries(errEvt.otelAttributes); _m < _o.length; _m++) {
|
|
363
|
+
_p = _o[_m], key = _p[0], value = _p[1];
|
|
364
|
+
span.setAttribute("emittables.".concat(errEvtIdx, ".").concat(key), value);
|
|
383
365
|
}
|
|
384
366
|
}
|
|
385
|
-
return [2 /*return*/, {
|
|
386
|
-
events:
|
|
387
|
-
}];
|
|
367
|
+
return [2 /*return*/, (0, orchestrationExecutionWrapper_1.returnEventsWithLogging)({
|
|
368
|
+
events: errorEvents,
|
|
369
|
+
}, span)];
|
|
388
370
|
case 4:
|
|
389
371
|
span.end();
|
|
390
372
|
return [7 /*endfinally*/];
|
|
@@ -392,7 +374,7 @@ var ArvoEventHandler = /** @class */ (function () {
|
|
|
392
374
|
}
|
|
393
375
|
});
|
|
394
376
|
}); } }))];
|
|
395
|
-
case 1: return [2 /*return*/,
|
|
377
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
396
378
|
}
|
|
397
379
|
});
|
|
398
380
|
});
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import type { Span
|
|
1
|
+
import type { Span } from '@opentelemetry/api';
|
|
2
2
|
import type { ArvoContract, ArvoEvent, ArvoSemanticVersion, CreateArvoEvent, InferArvoEvent, OpenTelemetryHeaders, VersionedArvoContract } from 'arvo-core';
|
|
3
3
|
import type { z } from 'zod';
|
|
4
|
+
import type { ArvoEventHandlerOtelSpanOptions } from '../types';
|
|
4
5
|
/**
|
|
5
6
|
* Represents the input for an ArvoEvent handler function.
|
|
6
7
|
*/
|
|
@@ -90,7 +91,7 @@ export type ArvoEventHandlerParam<TContract extends ArvoContract> = {
|
|
|
90
91
|
/**
|
|
91
92
|
* The OpenTelemetry span options
|
|
92
93
|
*/
|
|
93
|
-
spanOptions?:
|
|
94
|
+
spanOptions?: ArvoEventHandlerOtelSpanOptions;
|
|
94
95
|
/**
|
|
95
96
|
* Optional configuration to customize where system error events are emitted.
|
|
96
97
|
*
|
|
@@ -151,7 +151,7 @@ var processRawEventsIntoEmittables = function (params, span) {
|
|
|
151
151
|
emittables.push(evt);
|
|
152
152
|
for (var _e = 0, _f = Object.entries(emittables[emittables.length - 1].otelAttributes); _e < _f.length; _e++) {
|
|
153
153
|
var _g = _f[_e], key = _g[0], value = _g[1];
|
|
154
|
-
span.setAttribute("
|
|
154
|
+
span.setAttribute("emittables.".concat(emittables.length - 1, ".").concat(key), value);
|
|
155
155
|
}
|
|
156
156
|
}
|
|
157
157
|
}
|
|
@@ -2,7 +2,7 @@ import { type Span } from '@opentelemetry/api';
|
|
|
2
2
|
import { type ArvoEvent, type ArvoOrchestratorContract, type ArvoSemanticVersion, type OpenTelemetryHeaders, type VersionedArvoContract, type ViolationError } from 'arvo-core';
|
|
3
3
|
import type { SyncEventResource } from '../SyncEventResource';
|
|
4
4
|
import type { OrchestrationExecutionMemoryRecord } from './orchestrationExecutionState';
|
|
5
|
-
import type
|
|
5
|
+
import { type ArvoOrchestrationHandlerType } from './types';
|
|
6
6
|
/**
|
|
7
7
|
* Parameters for system error event creation
|
|
8
8
|
*/
|
|
@@ -17,11 +17,12 @@ export type CreateSystemErrorEventsParams = {
|
|
|
17
17
|
executionunits: number;
|
|
18
18
|
source: string;
|
|
19
19
|
domain: string | null;
|
|
20
|
+
handlerType: ArvoOrchestrationHandlerType;
|
|
20
21
|
};
|
|
21
22
|
/**
|
|
22
23
|
* Creates system error events
|
|
23
24
|
*/
|
|
24
|
-
export declare const createSystemErrorEvents: ({ error, event, otelHeaders, orchestrationParentSubject, initEventId, selfContract, systemErrorDomain, executionunits, source, domain, }: CreateSystemErrorEventsParams & {
|
|
25
|
+
export declare const createSystemErrorEvents: ({ error, event, otelHeaders, orchestrationParentSubject, initEventId, selfContract, systemErrorDomain, executionunits, source, domain, handlerType, }: CreateSystemErrorEventsParams & {
|
|
25
26
|
error: Error;
|
|
26
27
|
}) => ArvoEvent[];
|
|
27
28
|
export declare const handleOrchestrationErrors: (_handlerType: ArvoOrchestrationHandlerType, param: CreateSystemErrorEventsParams & {
|
|
@@ -53,12 +53,13 @@ var arvo_core_1 = require("arvo-core");
|
|
|
53
53
|
var ArvoDomain_1 = require("../ArvoDomain");
|
|
54
54
|
var errors_1 = require("../errors");
|
|
55
55
|
var utils_1 = require("../utils");
|
|
56
|
+
var types_1 = require("./types");
|
|
56
57
|
/**
|
|
57
58
|
* Creates system error events
|
|
58
59
|
*/
|
|
59
60
|
var createSystemErrorEvents = function (_a) {
|
|
60
61
|
var _b, _c, _d, _e;
|
|
61
|
-
var error = _a.error, event = _a.event, otelHeaders = _a.otelHeaders, orchestrationParentSubject = _a.orchestrationParentSubject, initEventId = _a.initEventId, selfContract = _a.selfContract, systemErrorDomain = _a.systemErrorDomain, executionunits = _a.executionunits, source = _a.source, domain = _a.domain;
|
|
62
|
+
var error = _a.error, event = _a.event, otelHeaders = _a.otelHeaders, orchestrationParentSubject = _a.orchestrationParentSubject, initEventId = _a.initEventId, selfContract = _a.selfContract, systemErrorDomain = _a.systemErrorDomain, executionunits = _a.executionunits, source = _a.source, domain = _a.domain, handlerType = _a.handlerType;
|
|
62
63
|
// In case of none transaction errors like errors from
|
|
63
64
|
// the machine or the event creation etc, the are workflow
|
|
64
65
|
// error and shuold be handled by the workflow. Then are
|
|
@@ -87,7 +88,8 @@ var createSystemErrorEvents = function (_a) {
|
|
|
87
88
|
var result = [];
|
|
88
89
|
for (var _i = 0, _f = Array.from(domainSets); _i < _f.length; _i++) {
|
|
89
90
|
var _dom = _f[_i];
|
|
90
|
-
|
|
91
|
+
var factoryBuilder = handlerType === 'handler' ? arvo_core_1.createArvoEventFactory : arvo_core_1.createArvoOrchestratorEventFactory;
|
|
92
|
+
result.push(factoryBuilder(selfContract).systemError({
|
|
91
93
|
source: source,
|
|
92
94
|
// If the initiator of the workflow exist then match the
|
|
93
95
|
// subject so that it can incorporate it in its state. If
|
|
@@ -118,10 +120,7 @@ var handleOrchestrationErrors = function (_handlerType, param, span) { return __
|
|
|
118
120
|
return __generator(this, function (_f) {
|
|
119
121
|
switch (_f.label) {
|
|
120
122
|
case 0:
|
|
121
|
-
handlerType =
|
|
122
|
-
orchestrator: 'ArvoOrchestrator',
|
|
123
|
-
resumable: 'ArvoResumable',
|
|
124
|
-
}[_handlerType];
|
|
123
|
+
handlerType = types_1.ArvoOrchestrationHandlerMap[_handlerType];
|
|
125
124
|
error = (0, utils_1.isError)(param.error)
|
|
126
125
|
? param.error
|
|
127
126
|
: new errors_1.ExecutionViolation("Non-Error object thrown during machine execution: ".concat(typeof param.error, ". This indicates a serious implementation flaw."));
|
|
@@ -171,7 +170,7 @@ var handleOrchestrationErrors = function (_handlerType, param, span) { return __
|
|
|
171
170
|
_b = _a[_i], errEvtIdx = _b[0], errEvt = _b[1];
|
|
172
171
|
for (_c = 0, _d = Object.entries(errEvt.otelAttributes); _c < _d.length; _c++) {
|
|
173
172
|
_e = _d[_c], key = _e[0], value = _e[1];
|
|
174
|
-
span.setAttribute("
|
|
173
|
+
span.setAttribute("emittables.".concat(errEvtIdx, ".").concat(key), value);
|
|
175
174
|
}
|
|
176
175
|
}
|
|
177
176
|
return [2 /*return*/, {
|
|
@@ -2,13 +2,12 @@ import { type Span } from '@opentelemetry/api';
|
|
|
2
2
|
import { type ArvoEvent, type ArvoOrchestrationSubjectContent, type ArvoOrchestratorContract, type ArvoSemanticVersion, type OpenTelemetryHeaders, type VersionedArvoContract } from 'arvo-core';
|
|
3
3
|
import type IArvoEventHandler from '../../IArvoEventHandler';
|
|
4
4
|
import type { SyncEventResource } from '../../SyncEventResource';
|
|
5
|
-
import type { ArvoEventHandlerOpenTelemetryOptions } from '../../types';
|
|
5
|
+
import type { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions } from '../../types';
|
|
6
6
|
import type { OrchestrationExecutionMemoryRecord } from '../orchestrationExecutionState';
|
|
7
7
|
import type { ArvoOrchestrationHandlerType } from '../types';
|
|
8
8
|
export type OrchestrationExecutionContext<TState extends OrchestrationExecutionMemoryRecord<Record<string, any>>> = {
|
|
9
9
|
event: ArvoEvent;
|
|
10
10
|
opentelemetry: ArvoEventHandlerOpenTelemetryOptions;
|
|
11
|
-
spanName: string;
|
|
12
11
|
source: string;
|
|
13
12
|
syncEventResource: SyncEventResource<TState>;
|
|
14
13
|
executionunits: number;
|
|
@@ -16,6 +15,9 @@ export type OrchestrationExecutionContext<TState extends OrchestrationExecutionM
|
|
|
16
15
|
selfContract: VersionedArvoContract<ArvoOrchestratorContract, ArvoSemanticVersion>;
|
|
17
16
|
domain: string | null;
|
|
18
17
|
_handlerType: ArvoOrchestrationHandlerType;
|
|
18
|
+
spanOptions: ArvoEventHandlerOtelSpanOptions & {
|
|
19
|
+
spanName: NonNullable<ArvoEventHandlerOtelSpanOptions['spanName']>;
|
|
20
|
+
};
|
|
19
21
|
};
|
|
20
22
|
export type CoreExecutionFn<TState extends OrchestrationExecutionMemoryRecord<Record<string, any>>> = (params: {
|
|
21
23
|
span: any;
|
|
@@ -37,4 +39,4 @@ export declare const returnEventsWithLogging: (param: Awaited<ReturnType<IArvoEv
|
|
|
37
39
|
* - State management
|
|
38
40
|
* - Error handling and system error generation
|
|
39
41
|
*/
|
|
40
|
-
export declare const executeWithOrchestrationWrapper: <TState extends OrchestrationExecutionMemoryRecord<Record<string, any>>>({ event, opentelemetry,
|
|
42
|
+
export declare const executeWithOrchestrationWrapper: <TState extends OrchestrationExecutionMemoryRecord<Record<string, any>>>({ event, opentelemetry, spanOptions, source, syncEventResource, executionunits, systemErrorDomain, selfContract, domain, _handlerType, }: OrchestrationExecutionContext<TState>, coreExecutionFn: CoreExecutionFn<TState>) => Promise<Awaited<ReturnType<IArvoEventHandler["execute"]>>>;
|
|
@@ -50,6 +50,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
50
50
|
exports.executeWithOrchestrationWrapper = exports.returnEventsWithLogging = void 0;
|
|
51
51
|
var api_1 = require("@opentelemetry/api");
|
|
52
52
|
var arvo_core_1 = require("arvo-core");
|
|
53
|
+
var utils_1 = require("../../utils");
|
|
53
54
|
var handlerErrors_1 = require("../handlerErrors");
|
|
54
55
|
var acquireLockWithValidation_1 = require("./acquireLockWithValidation");
|
|
55
56
|
var validateAndParseSubject_1 = require("./validateAndParseSubject");
|
|
@@ -70,158 +71,150 @@ exports.returnEventsWithLogging = returnEventsWithLogging;
|
|
|
70
71
|
* - Error handling and system error generation
|
|
71
72
|
*/
|
|
72
73
|
var executeWithOrchestrationWrapper = function (_a, coreExecutionFn_1) { return __awaiter(void 0, [_a, coreExecutionFn_1], void 0, function (_b, coreExecutionFn) {
|
|
73
|
-
var
|
|
74
|
-
var event = _b.event, opentelemetry = _b.opentelemetry,
|
|
75
|
-
return __generator(this, function (
|
|
76
|
-
switch (
|
|
77
|
-
case 0:
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
},
|
|
93
|
-
}
|
|
94
|
-
: {
|
|
95
|
-
inheritFrom: 'CONTEXT',
|
|
96
|
-
context: api_1.context.active(),
|
|
97
|
-
},
|
|
98
|
-
disableSpanManagement: true,
|
|
99
|
-
fn: function (span) { return __awaiter(void 0, void 0, void 0, function () {
|
|
100
|
-
var otelHeaders, orchestrationParentSubject, initEventId, acquiredLock, parsedEventSubject, state, _a, emittables, newState, i, _i, _b, _c, key, value, error_1, _d, errorToThrow, errorEvents;
|
|
101
|
-
var _e, _f, _g, _h;
|
|
102
|
-
return __generator(this, function (_j) {
|
|
103
|
-
switch (_j.label) {
|
|
104
|
-
case 0:
|
|
105
|
-
(0, arvo_core_1.logToSpan)({
|
|
106
|
-
level: 'INFO',
|
|
107
|
-
message: "Starting execution for ".concat(event.type, " on subject ").concat(event.subject),
|
|
108
|
-
}, span);
|
|
109
|
-
otelHeaders = (0, arvo_core_1.currentOpenTelemetryHeaders)();
|
|
110
|
-
orchestrationParentSubject = null;
|
|
111
|
-
initEventId = null;
|
|
112
|
-
acquiredLock = null;
|
|
113
|
-
_j.label = 1;
|
|
114
|
-
case 1:
|
|
115
|
-
_j.trys.push([1, 6, 8, 10]);
|
|
116
|
-
parsedEventSubject = (0, validateAndParseSubject_1.validateAndParseSubject)(event, source, syncEventResource, span, 'orchestrator');
|
|
117
|
-
if (!parsedEventSubject) {
|
|
118
|
-
return [2 /*return*/, (0, exports.returnEventsWithLogging)({ events: [] }, span)];
|
|
119
|
-
}
|
|
120
|
-
return [4 /*yield*/, (0, acquireLockWithValidation_1.acquireLockWithValidation)(syncEventResource, event, span)];
|
|
121
|
-
case 2:
|
|
122
|
-
// Lock acquisition
|
|
123
|
-
acquiredLock = _j.sent();
|
|
124
|
-
return [4 /*yield*/, syncEventResource.acquireState(event, span)];
|
|
125
|
-
case 3:
|
|
126
|
-
state = _j.sent();
|
|
127
|
-
if ((state === null || state === void 0 ? void 0 : state.executionStatus) === 'failure') {
|
|
128
|
-
(0, arvo_core_1.logToSpan)({
|
|
129
|
-
level: 'WARNING',
|
|
130
|
-
message: "The orchestration has failed in a previous event. Ignoring event id: ".concat(event.id, " with event subject: ").concat(event.subject),
|
|
131
|
-
}, span);
|
|
132
|
-
return [2 /*return*/, (0, exports.returnEventsWithLogging)({ events: [] }, span)];
|
|
133
|
-
}
|
|
134
|
-
orchestrationParentSubject = (_e = state === null || state === void 0 ? void 0 : state.parentSubject) !== null && _e !== void 0 ? _e : null;
|
|
135
|
-
initEventId = (_f = state === null || state === void 0 ? void 0 : state.initEventId) !== null && _f !== void 0 ? _f : null;
|
|
136
|
-
if (!state) {
|
|
74
|
+
var otelConfig;
|
|
75
|
+
var event = _b.event, opentelemetry = _b.opentelemetry, spanOptions = _b.spanOptions, source = _b.source, syncEventResource = _b.syncEventResource, executionunits = _b.executionunits, systemErrorDomain = _b.systemErrorDomain, selfContract = _b.selfContract, domain = _b.domain, _handlerType = _b._handlerType;
|
|
76
|
+
return __generator(this, function (_c) {
|
|
77
|
+
switch (_c.label) {
|
|
78
|
+
case 0:
|
|
79
|
+
otelConfig = (0, utils_1.createEventHandlerTelemetryConfig)(spanOptions.spanName({ selfContractUri: selfContract.uri, consumedEvent: event }), spanOptions, opentelemetry, event);
|
|
80
|
+
return [4 /*yield*/, arvo_core_1.ArvoOpenTelemetry.getInstance().startActiveSpan(__assign(__assign({}, otelConfig), { fn: function (span) { return __awaiter(void 0, void 0, void 0, function () {
|
|
81
|
+
var _i, _a, _b, key, value, otelHeaders, orchestrationParentSubject, initEventId, acquiredLock, parsedEventSubject, state, _c, emittables, newState, i, _d, _e, _f, key, value, error_1, _g, errorToThrow, errorEvents;
|
|
82
|
+
var _h, _j, _k, _l;
|
|
83
|
+
return __generator(this, function (_m) {
|
|
84
|
+
switch (_m.label) {
|
|
85
|
+
case 0:
|
|
86
|
+
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
87
|
+
span.setAttribute('arvo.handler.execution.type', _handlerType);
|
|
88
|
+
span.setAttribute('arvo.handler.execution.status', 'normal');
|
|
89
|
+
for (_i = 0, _a = Object.entries(event.otelAttributes); _i < _a.length; _i++) {
|
|
90
|
+
_b = _a[_i], key = _b[0], value = _b[1];
|
|
91
|
+
span.setAttribute("consumable.0.".concat(key), value);
|
|
92
|
+
}
|
|
137
93
|
(0, arvo_core_1.logToSpan)({
|
|
138
94
|
level: 'INFO',
|
|
139
|
-
message: "
|
|
140
|
-
});
|
|
141
|
-
|
|
95
|
+
message: "Starting execution for ".concat(event.type, " on subject ").concat(event.subject),
|
|
96
|
+
}, span);
|
|
97
|
+
otelHeaders = (0, arvo_core_1.currentOpenTelemetryHeaders)();
|
|
98
|
+
orchestrationParentSubject = null;
|
|
99
|
+
initEventId = null;
|
|
100
|
+
acquiredLock = null;
|
|
101
|
+
_m.label = 1;
|
|
102
|
+
case 1:
|
|
103
|
+
_m.trys.push([1, 6, 8, 10]);
|
|
104
|
+
parsedEventSubject = (0, validateAndParseSubject_1.validateAndParseSubject)(event, source, syncEventResource, span, 'orchestrator');
|
|
105
|
+
if (!parsedEventSubject) {
|
|
106
|
+
return [2 /*return*/, (0, exports.returnEventsWithLogging)({ events: [] }, span)];
|
|
107
|
+
}
|
|
108
|
+
return [4 /*yield*/, (0, acquireLockWithValidation_1.acquireLockWithValidation)(syncEventResource, event, span)];
|
|
109
|
+
case 2:
|
|
110
|
+
// Lock acquisition
|
|
111
|
+
acquiredLock = _m.sent();
|
|
112
|
+
return [4 /*yield*/, syncEventResource.acquireState(event, span)];
|
|
113
|
+
case 3:
|
|
114
|
+
state = _m.sent();
|
|
115
|
+
if ((state === null || state === void 0 ? void 0 : state.executionStatus) === 'failure') {
|
|
116
|
+
span.setAttribute('arvo.handler.execution.status', state.executionStatus);
|
|
142
117
|
(0, arvo_core_1.logToSpan)({
|
|
143
118
|
level: 'WARNING',
|
|
144
|
-
message: "
|
|
119
|
+
message: "The orchestration has failed in a previous event. Ignoring event id: ".concat(event.id, " with event subject: ").concat(event.subject),
|
|
120
|
+
}, span);
|
|
121
|
+
span.setStatus({
|
|
122
|
+
code: api_1.SpanStatusCode.ERROR,
|
|
123
|
+
message: "The orchestration has failed in a previous event. Ignoring event id: ".concat(event.id, " with event subject: ").concat(event.subject),
|
|
145
124
|
});
|
|
146
125
|
return [2 /*return*/, (0, exports.returnEventsWithLogging)({ events: [] }, span)];
|
|
147
126
|
}
|
|
148
|
-
|
|
149
|
-
|
|
127
|
+
orchestrationParentSubject = (_h = state === null || state === void 0 ? void 0 : state.parentSubject) !== null && _h !== void 0 ? _h : null;
|
|
128
|
+
initEventId = (_j = state === null || state === void 0 ? void 0 : state.initEventId) !== null && _j !== void 0 ? _j : null;
|
|
129
|
+
if (!state) {
|
|
130
|
+
(0, arvo_core_1.logToSpan)({
|
|
131
|
+
level: 'INFO',
|
|
132
|
+
message: "Initializing new execution state for subject: ".concat(event.subject),
|
|
133
|
+
});
|
|
134
|
+
if (event.type !== source) {
|
|
135
|
+
(0, arvo_core_1.logToSpan)({
|
|
136
|
+
level: 'WARNING',
|
|
137
|
+
message: "Invalid initialization event detected. Expected type '".concat(source, "' but received '").concat(event.type, "'."),
|
|
138
|
+
});
|
|
139
|
+
return [2 /*return*/, (0, exports.returnEventsWithLogging)({ events: [] }, span)];
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
else {
|
|
143
|
+
(0, arvo_core_1.logToSpan)({
|
|
144
|
+
level: 'INFO',
|
|
145
|
+
message: "Resuming execution with existing state for subject: ".concat(event.subject),
|
|
146
|
+
});
|
|
147
|
+
}
|
|
148
|
+
// Extract parent subject from init event if applicable
|
|
149
|
+
if (event.type === source) {
|
|
150
|
+
orchestrationParentSubject = (_l = (_k = event === null || event === void 0 ? void 0 : event.data) === null || _k === void 0 ? void 0 : _k.parentSubject$$) !== null && _l !== void 0 ? _l : null;
|
|
151
|
+
}
|
|
152
|
+
return [4 /*yield*/, coreExecutionFn({
|
|
153
|
+
span: span,
|
|
154
|
+
otelHeaders: otelHeaders,
|
|
155
|
+
orchestrationParentSubject: orchestrationParentSubject,
|
|
156
|
+
initEventId: initEventId !== null && initEventId !== void 0 ? initEventId : event.id,
|
|
157
|
+
parsedEventSubject: parsedEventSubject,
|
|
158
|
+
state: state,
|
|
159
|
+
_handlerType: _handlerType,
|
|
160
|
+
})];
|
|
161
|
+
case 4:
|
|
162
|
+
_c = _m.sent(), emittables = _c.emittables, newState = _c.newState;
|
|
163
|
+
// Add OpenTelemetry attributes for emitted events
|
|
164
|
+
for (i = 0; i < emittables.length; i++) {
|
|
165
|
+
for (_d = 0, _e = Object.entries(emittables[i].otelAttributes); _d < _e.length; _d++) {
|
|
166
|
+
_f = _e[_d], key = _f[0], value = _f[1];
|
|
167
|
+
span.setAttribute("emittables.".concat(i, ".").concat(key), value);
|
|
168
|
+
}
|
|
169
|
+
}
|
|
170
|
+
// Persist state
|
|
171
|
+
return [4 /*yield*/, syncEventResource.persistState(event, newState, state, span)];
|
|
172
|
+
case 5:
|
|
173
|
+
// Persist state
|
|
174
|
+
_m.sent();
|
|
150
175
|
(0, arvo_core_1.logToSpan)({
|
|
151
176
|
level: 'INFO',
|
|
152
|
-
message: "
|
|
177
|
+
message: "State update persisted in memory for subject ".concat(event.subject),
|
|
153
178
|
});
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
(
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
error_1 = _j.sent();
|
|
194
|
-
return [4 /*yield*/, (0, handlerErrors_1.handleOrchestrationErrors)(_handlerType, {
|
|
195
|
-
error: error_1,
|
|
196
|
-
event: event,
|
|
197
|
-
otelHeaders: otelHeaders,
|
|
198
|
-
orchestrationParentSubject: orchestrationParentSubject,
|
|
199
|
-
initEventId: initEventId,
|
|
200
|
-
selfContract: selfContract,
|
|
201
|
-
systemErrorDomain: systemErrorDomain,
|
|
202
|
-
executionunits: executionunits,
|
|
203
|
-
source: source,
|
|
204
|
-
domain: domain,
|
|
205
|
-
syncEventResource: syncEventResource,
|
|
206
|
-
}, span)];
|
|
207
|
-
case 7:
|
|
208
|
-
_d = _j.sent(), errorToThrow = _d.errorToThrow, errorEvents = _d.events;
|
|
209
|
-
if (errorToThrow)
|
|
210
|
-
throw errorToThrow;
|
|
211
|
-
return [2 /*return*/, {
|
|
212
|
-
events: errorEvents,
|
|
213
|
-
}];
|
|
214
|
-
case 8: return [4 /*yield*/, syncEventResource.releaseLock(event, acquiredLock, span)];
|
|
215
|
-
case 9:
|
|
216
|
-
_j.sent();
|
|
217
|
-
span.end();
|
|
218
|
-
return [7 /*endfinally*/];
|
|
219
|
-
case 10: return [2 /*return*/];
|
|
220
|
-
}
|
|
221
|
-
});
|
|
222
|
-
}); },
|
|
223
|
-
})];
|
|
224
|
-
case 1: return [2 /*return*/, _d.sent()];
|
|
179
|
+
(0, arvo_core_1.logToSpan)({
|
|
180
|
+
level: 'INFO',
|
|
181
|
+
message: "Execution successfully completed and emitted ".concat(emittables.length, " events"),
|
|
182
|
+
});
|
|
183
|
+
return [2 /*return*/, (0, exports.returnEventsWithLogging)({ events: emittables }, span)];
|
|
184
|
+
case 6:
|
|
185
|
+
error_1 = _m.sent();
|
|
186
|
+
span.setAttribute('arvo.handler.execution.status', 'failure');
|
|
187
|
+
return [4 /*yield*/, (0, handlerErrors_1.handleOrchestrationErrors)(_handlerType, {
|
|
188
|
+
error: error_1,
|
|
189
|
+
event: event,
|
|
190
|
+
otelHeaders: otelHeaders,
|
|
191
|
+
orchestrationParentSubject: orchestrationParentSubject,
|
|
192
|
+
initEventId: initEventId,
|
|
193
|
+
selfContract: selfContract,
|
|
194
|
+
systemErrorDomain: systemErrorDomain,
|
|
195
|
+
executionunits: executionunits,
|
|
196
|
+
source: source,
|
|
197
|
+
domain: domain,
|
|
198
|
+
syncEventResource: syncEventResource,
|
|
199
|
+
handlerType: _handlerType,
|
|
200
|
+
}, span)];
|
|
201
|
+
case 7:
|
|
202
|
+
_g = _m.sent(), errorToThrow = _g.errorToThrow, errorEvents = _g.events;
|
|
203
|
+
if (errorToThrow)
|
|
204
|
+
throw errorToThrow;
|
|
205
|
+
return [2 /*return*/, {
|
|
206
|
+
events: errorEvents,
|
|
207
|
+
}];
|
|
208
|
+
case 8: return [4 /*yield*/, syncEventResource.releaseLock(event, acquiredLock, span)];
|
|
209
|
+
case 9:
|
|
210
|
+
_m.sent();
|
|
211
|
+
span.end();
|
|
212
|
+
return [7 /*endfinally*/];
|
|
213
|
+
case 10: return [2 /*return*/];
|
|
214
|
+
}
|
|
215
|
+
});
|
|
216
|
+
}); } }))];
|
|
217
|
+
case 1: return [2 /*return*/, _c.sent()];
|
|
225
218
|
}
|
|
226
219
|
});
|
|
227
220
|
}); };
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
import type { ArvoContract, VersionedArvoContract } from 'arvo-core';
|
|
2
|
+
import { type ArvoOrchestrationHandlerType } from './types';
|
|
3
|
+
/**
|
|
4
|
+
* Validates that all service contracts in a collection have unique URIs.
|
|
5
|
+
*
|
|
6
|
+
* Iterates through the provided contracts and checks if any URI appears more than once.
|
|
7
|
+
* Multiple versions of the same contract (with the same URI) are not allowed.
|
|
8
|
+
*
|
|
9
|
+
* @param contracts - A record mapping contract keys to their respective ArvoContract objects
|
|
10
|
+
* @returns An object with a boolean result indicating if all contracts are unique, and the error keys if not
|
|
11
|
+
*/
|
|
12
|
+
export declare const areServiceContractsUnique: (contracts: Record<string, ArvoContract | VersionedArvoContract<any, any>>) => {
|
|
13
|
+
result: false;
|
|
14
|
+
keys: [string, string];
|
|
15
|
+
contractUri: string;
|
|
16
|
+
} | {
|
|
17
|
+
result: true;
|
|
18
|
+
};
|
|
19
|
+
export declare const servicesValidation: (contracts: {
|
|
20
|
+
self: ArvoContract | VersionedArvoContract<any, any>;
|
|
21
|
+
services: Record<string, VersionedArvoContract<any, any>>;
|
|
22
|
+
}, _handlerType: ArvoOrchestrationHandlerType) => void;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
13
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
|
+
exports.servicesValidation = exports.areServiceContractsUnique = void 0;
|
|
15
|
+
var uuid_1 = require("uuid");
|
|
16
|
+
var errors_1 = require("../errors");
|
|
17
|
+
var types_1 = require("./types");
|
|
18
|
+
/**
|
|
19
|
+
* Validates that all service contracts in a collection have unique URIs.
|
|
20
|
+
*
|
|
21
|
+
* Iterates through the provided contracts and checks if any URI appears more than once.
|
|
22
|
+
* Multiple versions of the same contract (with the same URI) are not allowed.
|
|
23
|
+
*
|
|
24
|
+
* @param contracts - A record mapping contract keys to their respective ArvoContract objects
|
|
25
|
+
* @returns An object with a boolean result indicating if all contracts are unique, and the error keys if not
|
|
26
|
+
*/
|
|
27
|
+
var areServiceContractsUnique = function (contracts) {
|
|
28
|
+
var uriToKeyMap = {};
|
|
29
|
+
for (var _i = 0, _a = Object.entries(contracts); _i < _a.length; _i++) {
|
|
30
|
+
var _b = _a[_i], key = _b[0], contract = _b[1];
|
|
31
|
+
if (uriToKeyMap[contract.uri]) {
|
|
32
|
+
return {
|
|
33
|
+
result: false,
|
|
34
|
+
keys: [key, uriToKeyMap[contract.uri]],
|
|
35
|
+
contractUri: contract.uri,
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
uriToKeyMap[contract.uri] = key;
|
|
39
|
+
}
|
|
40
|
+
return {
|
|
41
|
+
result: true,
|
|
42
|
+
};
|
|
43
|
+
};
|
|
44
|
+
exports.areServiceContractsUnique = areServiceContractsUnique;
|
|
45
|
+
var servicesValidation = function (contracts, _handlerType) {
|
|
46
|
+
var _a;
|
|
47
|
+
var __areServiceContractsUnique = (0, exports.areServiceContractsUnique)(contracts.services);
|
|
48
|
+
if (!__areServiceContractsUnique.result) {
|
|
49
|
+
throw new errors_1.ConfigViolation("In ".concat(types_1.ArvoOrchestrationHandlerMap[_handlerType], ", the service contracts must have unique URIs. Multiple versions of the same contract are not allow. The contracts '").concat(__areServiceContractsUnique.keys[0], "' and '").concat(__areServiceContractsUnique.keys[1], "' have the same URI '").concat(__areServiceContractsUnique.contractUri, "'"));
|
|
50
|
+
}
|
|
51
|
+
var __checkIfSelfIsAService = (0, exports.areServiceContractsUnique)(__assign(__assign({}, contracts.services), (_a = {}, _a[(0, uuid_1.v4)()] = contracts.self, _a)));
|
|
52
|
+
if (!__checkIfSelfIsAService.result) {
|
|
53
|
+
throw new errors_1.ConfigViolation("In ".concat(types_1.ArvoOrchestrationHandlerMap[_handlerType], ", Circular dependency detected: Machine with URI '").concat(contracts.self.uri, "' is registered as service '").concat(__checkIfSelfIsAService.keys[1], "'. Self-referential services create execution loops and are prohibited."));
|
|
54
|
+
}
|
|
55
|
+
};
|
|
56
|
+
exports.servicesValidation = servicesValidation;
|
|
@@ -1 +1,7 @@
|
|
|
1
|
-
export
|
|
1
|
+
export declare const ArvoOrchestrationHandlerMap: {
|
|
2
|
+
readonly orchestrator: "ArvoOrchestrator";
|
|
3
|
+
readonly resumable: "ArvoResumable";
|
|
4
|
+
readonly machine: "ArvoMachine";
|
|
5
|
+
readonly handler: "ArvoEventHandler";
|
|
6
|
+
};
|
|
7
|
+
export type ArvoOrchestrationHandlerType = keyof typeof ArvoOrchestrationHandlerMap;
|
|
@@ -1,2 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.ArvoOrchestrationHandlerMap = void 0;
|
|
4
|
+
exports.ArvoOrchestrationHandlerMap = {
|
|
5
|
+
orchestrator: 'ArvoOrchestrator',
|
|
6
|
+
resumable: 'ArvoResumable',
|
|
7
|
+
machine: 'ArvoMachine',
|
|
8
|
+
handler: 'ArvoEventHandler',
|
|
9
|
+
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ArvoOrchestrator } from '.';
|
|
2
|
-
import type {
|
|
2
|
+
import type { CreateArvoOrchestratorParam } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Creates a new Arvo orchestrator instance with default components.
|
|
5
5
|
* For custom components, use ArvoOrchestrator constructor directly.
|
|
@@ -26,4 +26,4 @@ import type { ICreateArvoOrchestrator } from './types';
|
|
|
26
26
|
* });
|
|
27
27
|
* ```
|
|
28
28
|
*/
|
|
29
|
-
export declare const createArvoOrchestrator: ({ executionunits, memory, machines, systemErrorDomain, }:
|
|
29
|
+
export declare const createArvoOrchestrator: ({ executionunits, memory, machines, systemErrorDomain, spanOptions, }: CreateArvoOrchestratorParam) => ArvoOrchestrator;
|
|
@@ -41,7 +41,7 @@ var errors_1 = require("../errors");
|
|
|
41
41
|
* ```
|
|
42
42
|
*/
|
|
43
43
|
var createArvoOrchestrator = function (_a) {
|
|
44
|
-
var executionunits = _a.executionunits, memory = _a.memory, machines = _a.machines, systemErrorDomain = _a.systemErrorDomain;
|
|
44
|
+
var executionunits = _a.executionunits, memory = _a.memory, machines = _a.machines, systemErrorDomain = _a.systemErrorDomain, spanOptions = _a.spanOptions;
|
|
45
45
|
if (!(machines === null || machines === void 0 ? void 0 : machines.length)) {
|
|
46
46
|
throw new Error('At least one machine must be provided');
|
|
47
47
|
}
|
|
@@ -66,6 +66,7 @@ var createArvoOrchestrator = function (_a) {
|
|
|
66
66
|
executionEngine: new MachineExecutionEngine_1.MachineExecutionEngine(),
|
|
67
67
|
requiresResourceLocking: requiresResourceLocking,
|
|
68
68
|
systemErrorDomain: systemErrorDomain,
|
|
69
|
+
spanOptions: spanOptions,
|
|
69
70
|
});
|
|
70
71
|
};
|
|
71
72
|
exports.createArvoOrchestrator = createArvoOrchestrator;
|
|
@@ -16,6 +16,7 @@ export declare class ArvoOrchestrator implements IArvoEventHandler {
|
|
|
16
16
|
readonly executionEngine: IMachineExectionEngine;
|
|
17
17
|
readonly syncEventResource: SyncEventResource<MachineMemoryRecord>;
|
|
18
18
|
readonly systemErrorDomain?: (string | null)[];
|
|
19
|
+
private readonly spanOptions;
|
|
19
20
|
get source(): any;
|
|
20
21
|
get requiresResourceLocking(): boolean;
|
|
21
22
|
get memory(): IMachineMemory<MachineMemoryRecord>;
|
|
@@ -25,7 +26,7 @@ export declare class ArvoOrchestrator implements IArvoEventHandler {
|
|
|
25
26
|
* @param params - Configuration parameters
|
|
26
27
|
* @throws Error if machines in registry have different sources
|
|
27
28
|
*/
|
|
28
|
-
constructor({ executionunits, memory, registry, executionEngine, requiresResourceLocking, systemErrorDomain, }: ArvoOrchestratorParam);
|
|
29
|
+
constructor({ executionunits, memory, registry, executionEngine, requiresResourceLocking, systemErrorDomain, spanOptions, }: ArvoOrchestratorParam);
|
|
29
30
|
/**
|
|
30
31
|
* Core orchestration method that executes state machines in response to events.
|
|
31
32
|
*
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -37,6 +48,7 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
|
|
|
37
48
|
};
|
|
38
49
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
39
50
|
exports.ArvoOrchestrator = void 0;
|
|
51
|
+
var api_1 = require("@opentelemetry/api");
|
|
40
52
|
var arvo_core_1 = require("arvo-core");
|
|
41
53
|
var createEmitableEvent_1 = require("../ArvoOrchestrationUtils/createEmitableEvent");
|
|
42
54
|
var orchestrationExecutionWrapper_1 = require("../ArvoOrchestrationUtils/orchestrationExecutionWrapper");
|
|
@@ -53,13 +65,16 @@ var ArvoOrchestrator = /** @class */ (function () {
|
|
|
53
65
|
* @throws Error if machines in registry have different sources
|
|
54
66
|
*/
|
|
55
67
|
function ArvoOrchestrator(_a) {
|
|
56
|
-
var
|
|
68
|
+
var _b;
|
|
69
|
+
var executionunits = _a.executionunits, memory = _a.memory, registry = _a.registry, executionEngine = _a.executionEngine, requiresResourceLocking = _a.requiresResourceLocking, systemErrorDomain = _a.systemErrorDomain, spanOptions = _a.spanOptions;
|
|
70
|
+
var _c, _d, _e, _f, _g, _h, _j;
|
|
57
71
|
this.systemErrorDomain = [];
|
|
58
72
|
this.executionunits = executionunits;
|
|
59
73
|
this.registry = registry;
|
|
60
74
|
this.executionEngine = executionEngine;
|
|
61
75
|
this.syncEventResource = new SyncEventResource_1.SyncEventResource(memory, requiresResourceLocking);
|
|
62
76
|
this.systemErrorDomain = systemErrorDomain;
|
|
77
|
+
this.spanOptions = __assign(__assign({ kind: api_1.SpanKind.PRODUCER }, spanOptions), { attributes: __assign(__assign((_b = {}, _b[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.ORCHESTRATOR, _b[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _b), ((_c = spanOptions === null || spanOptions === void 0 ? void 0 : spanOptions.attributes) !== null && _c !== void 0 ? _c : {})), { 'arvo.handler.source': this.source, 'arvo.contract.uri': (_j = (_h = (_g = (_f = (_e = (_d = this === null || this === void 0 ? void 0 : this.registry) === null || _d === void 0 ? void 0 : _d.machines) === null || _e === void 0 ? void 0 : _e[0]) === null || _f === void 0 ? void 0 : _f.contracts) === null || _g === void 0 ? void 0 : _g.self) === null || _h === void 0 ? void 0 : _h.uri) !== null && _j !== void 0 ? _j : 'N/A' }) });
|
|
63
78
|
}
|
|
64
79
|
Object.defineProperty(ArvoOrchestrator.prototype, "source", {
|
|
65
80
|
get: function () {
|
|
@@ -101,19 +116,19 @@ var ArvoOrchestrator = /** @class */ (function () {
|
|
|
101
116
|
* @throws {ContractViolation} Schema/contract mismatch
|
|
102
117
|
* @throws {ConfigViolation} Missing/invalid machine version
|
|
103
118
|
*/
|
|
104
|
-
ArvoOrchestrator.prototype.execute = function (
|
|
105
|
-
return __awaiter(this,
|
|
119
|
+
ArvoOrchestrator.prototype.execute = function (event, opentelemetry) {
|
|
120
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
106
121
|
var _this = this;
|
|
107
|
-
if (opentelemetry === void 0) { opentelemetry = {
|
|
108
|
-
inheritFrom: 'EVENT',
|
|
109
|
-
}; }
|
|
110
122
|
return __generator(this, function (_a) {
|
|
111
123
|
switch (_a.label) {
|
|
112
124
|
case 0: return [4 /*yield*/, (0, orchestrationExecutionWrapper_1.executeWithOrchestrationWrapper)({
|
|
113
125
|
_handlerType: 'orchestrator',
|
|
114
126
|
event: event,
|
|
115
|
-
opentelemetry: opentelemetry,
|
|
116
|
-
spanName:
|
|
127
|
+
opentelemetry: opentelemetry !== null && opentelemetry !== void 0 ? opentelemetry : { inheritFrom: 'EVENT' },
|
|
128
|
+
spanOptions: __assign({ spanName: function (_a) {
|
|
129
|
+
var selfContractUri = _a.selfContractUri, consumedEvent = _a.consumedEvent;
|
|
130
|
+
return "Orchestrator<".concat(selfContractUri, ">@<").concat(consumedEvent.type, ">");
|
|
131
|
+
} }, this.spanOptions),
|
|
117
132
|
source: this.source,
|
|
118
133
|
syncEventResource: this.syncEventResource,
|
|
119
134
|
executionunits: this.executionunits,
|
|
@@ -5,6 +5,7 @@ import type { OrchestrationExecutionMemoryRecord } from '../ArvoOrchestrationUti
|
|
|
5
5
|
import type { IMachineExectionEngine } from '../MachineExecutionEngine/interface';
|
|
6
6
|
import type { IMachineMemory } from '../MachineMemory/interface';
|
|
7
7
|
import type { IMachineRegistry } from '../MachineRegistry/interface';
|
|
8
|
+
import type { ArvoEventHandlerOtelSpanOptions } from '../types';
|
|
8
9
|
export type TryFunctionOutput<TData, TError extends Error> = {
|
|
9
10
|
type: 'success';
|
|
10
11
|
data: TData;
|
|
@@ -82,24 +83,6 @@ export type ArvoOrchestratorParam = {
|
|
|
82
83
|
/** Engine responsible for machine execution */
|
|
83
84
|
executionEngine: IMachineExectionEngine;
|
|
84
85
|
requiresResourceLocking: boolean;
|
|
85
|
-
/**
|
|
86
|
-
* Optional configuration to customize where system error events are emitted.
|
|
87
|
-
*/
|
|
88
|
-
systemErrorDomain?: (string | null)[];
|
|
89
|
-
};
|
|
90
|
-
/**
|
|
91
|
-
* Configuration interface for creating an Arvo orchestrator instance.
|
|
92
|
-
*/
|
|
93
|
-
export interface ICreateArvoOrchestrator {
|
|
94
|
-
/** Memory interface for storing and retrieving machine state */
|
|
95
|
-
memory: IMachineMemory<MachineMemoryRecord>;
|
|
96
|
-
/** The cost of the execution of the orchestrator */
|
|
97
|
-
executionunits: number;
|
|
98
|
-
/**
|
|
99
|
-
* Collection of state machines to be managed by the orchestrator.
|
|
100
|
-
* All machines must have the same source identifier.
|
|
101
|
-
*/
|
|
102
|
-
machines: ArvoMachine<any, any, any, any, any>[];
|
|
103
86
|
/**
|
|
104
87
|
* Optional configuration to customize where system error events are emitted.
|
|
105
88
|
*
|
|
@@ -114,4 +97,18 @@ export interface ICreateArvoOrchestrator {
|
|
|
114
97
|
* @default undefined — uses standard fallback broadcast domains
|
|
115
98
|
*/
|
|
116
99
|
systemErrorDomain?: (string | null)[];
|
|
117
|
-
|
|
100
|
+
/**
|
|
101
|
+
* The OpenTelemetry span options
|
|
102
|
+
*/
|
|
103
|
+
spanOptions?: ArvoEventHandlerOtelSpanOptions;
|
|
104
|
+
};
|
|
105
|
+
/**
|
|
106
|
+
* Configuration interface for creating an Arvo orchestrator instance.
|
|
107
|
+
*/
|
|
108
|
+
export type CreateArvoOrchestratorParam = Pick<ArvoOrchestratorParam, 'memory' | 'executionunits' | 'spanOptions' | 'systemErrorDomain'> & {
|
|
109
|
+
/**
|
|
110
|
+
* Collection of state machines to be managed by the orchestrator.
|
|
111
|
+
* All machines must have the same source identifier.
|
|
112
|
+
*/
|
|
113
|
+
machines: ArvoMachine<any, any, any, any, any>[];
|
|
114
|
+
};
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import type { ArvoOrchestratorContract, VersionedArvoContract } from 'arvo-core';
|
|
2
2
|
import { ArvoResumable } from '.';
|
|
3
3
|
import type { IMachineMemory } from '../MachineMemory/interface';
|
|
4
|
+
import type { ArvoEventHandlerOtelSpanOptions } from '../types';
|
|
4
5
|
import type { ArvoResumableHandler, ArvoResumableState } from './types';
|
|
5
6
|
/**
|
|
6
7
|
* Factory function for creating ArvoResumable orchestrator instances
|
|
@@ -39,4 +40,5 @@ export declare const createArvoResumable: <TMemory extends Record<string, any>,
|
|
|
39
40
|
executionunits?: number;
|
|
40
41
|
requiresResourceLocking?: boolean;
|
|
41
42
|
systemErrorDomain?: (string | null)[];
|
|
43
|
+
spanOptions?: ArvoEventHandlerOtelSpanOptions;
|
|
42
44
|
}) => ArvoResumable<TMemory, TSelfContract, TServiceContract>;
|
|
@@ -1,20 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
var __assign = (this && this.__assign) || function () {
|
|
3
|
-
__assign = Object.assign || function(t) {
|
|
4
|
-
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
-
s = arguments[i];
|
|
6
|
-
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
-
t[p] = s[p];
|
|
8
|
-
}
|
|
9
|
-
return t;
|
|
10
|
-
};
|
|
11
|
-
return __assign.apply(this, arguments);
|
|
12
|
-
};
|
|
13
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
14
3
|
exports.createArvoResumable = void 0;
|
|
15
|
-
var uuid_1 = require("uuid");
|
|
16
4
|
var _1 = require(".");
|
|
17
|
-
var
|
|
5
|
+
var servicesValidation_1 = require("../ArvoOrchestrationUtils/servicesValidation");
|
|
18
6
|
/**
|
|
19
7
|
* Factory function for creating ArvoResumable orchestrator instances
|
|
20
8
|
*
|
|
@@ -40,23 +28,16 @@ var utils_1 = require("../ArvoMachine/utils");
|
|
|
40
28
|
* @throws {Error} Circular dependency detected - Self contract is registered as a service, creating execution loops
|
|
41
29
|
*/
|
|
42
30
|
var createArvoResumable = function (param) {
|
|
43
|
-
var _a;
|
|
44
|
-
|
|
45
|
-
var __areServiceContractsUnique = (0, utils_1.areServiceContractsUnique)(param.contracts.services);
|
|
46
|
-
if (!__areServiceContractsUnique.result) {
|
|
47
|
-
throw new Error("The service contracts must have unique URIs. Multiple versions of the same contract are not allow. The contracts '".concat(__areServiceContractsUnique.keys[0], "' and '").concat(__areServiceContractsUnique.keys[1], "' have the same URI '").concat(__areServiceContractsUnique.contractUri, "'"));
|
|
48
|
-
}
|
|
49
|
-
var __checkIfSelfIsAService = (0, utils_1.areServiceContractsUnique)(__assign(__assign({}, param.contracts.services), (_a = {}, _a[(0, uuid_1.v4)()] = param.contracts.self, _a)));
|
|
50
|
-
if (!__checkIfSelfIsAService.result) {
|
|
51
|
-
throw new Error("Circular dependency detected: Machine with URI '".concat(param.contracts.self.uri, "' is registered as service '").concat(__checkIfSelfIsAService.keys[1], "'. Self-referential services create execution loops and are prohibited."));
|
|
52
|
-
}
|
|
31
|
+
var _a, _b;
|
|
32
|
+
(0, servicesValidation_1.servicesValidation)(param.contracts, 'resumable');
|
|
53
33
|
return new _1.ArvoResumable({
|
|
54
34
|
contracts: param.contracts,
|
|
55
35
|
memory: param.memory,
|
|
56
36
|
handler: param.handler,
|
|
57
|
-
executionunits: (
|
|
58
|
-
requiresResourceLocking: (
|
|
37
|
+
executionunits: (_a = param.executionunits) !== null && _a !== void 0 ? _a : 0,
|
|
38
|
+
requiresResourceLocking: (_b = param.requiresResourceLocking) !== null && _b !== void 0 ? _b : Object.keys(param.contracts.services).length > 1,
|
|
59
39
|
systemErrorDomain: param.systemErrorDomain,
|
|
40
|
+
spanOptions: param.spanOptions,
|
|
60
41
|
});
|
|
61
42
|
};
|
|
62
43
|
exports.createArvoResumable = createArvoResumable;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import type
|
|
1
|
+
import { type Span } from '@opentelemetry/api';
|
|
2
2
|
import { type ArvoEvent, type ArvoOrchestratorContract, type VersionedArvoContract } from 'arvo-core';
|
|
3
3
|
import type { z } from 'zod';
|
|
4
4
|
import type IArvoEventHandler from '../IArvoEventHandler';
|
|
5
5
|
import type { IMachineMemory } from '../MachineMemory/interface';
|
|
6
6
|
import { SyncEventResource } from '../SyncEventResource/index';
|
|
7
|
-
import type { ArvoEventHandlerOpenTelemetryOptions } from '../types';
|
|
7
|
+
import type { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions } from '../types';
|
|
8
8
|
import type { ArvoResumableHandler, ArvoResumableState } from './types';
|
|
9
9
|
/**
|
|
10
10
|
* ArvoResumable - A stateful orchestration handler for managing distributed workflows
|
|
@@ -43,6 +43,7 @@ export declare class ArvoResumable<TMemory extends Record<string, any> = Record<
|
|
|
43
43
|
readonly source: string;
|
|
44
44
|
readonly handler: ArvoResumableHandler<ArvoResumableState<TMemory>, TSelfContract, TServiceContract>;
|
|
45
45
|
readonly systemErrorDomain?: (string | null)[];
|
|
46
|
+
private readonly spanOptions;
|
|
46
47
|
readonly contracts: {
|
|
47
48
|
self: TSelfContract;
|
|
48
49
|
services: TServiceContract;
|
|
@@ -60,6 +61,7 @@ export declare class ArvoResumable<TMemory extends Record<string, any> = Record<
|
|
|
60
61
|
requiresResourceLocking?: boolean;
|
|
61
62
|
handler: ArvoResumableHandler<ArvoResumableState<TMemory>, TSelfContract, TServiceContract>;
|
|
62
63
|
systemErrorDomain?: (string | null)[];
|
|
64
|
+
spanOptions?: ArvoEventHandlerOtelSpanOptions;
|
|
63
65
|
});
|
|
64
66
|
protected validateInput(event: ArvoEvent, span: Span): {
|
|
65
67
|
contractType: 'self' | 'service';
|
|
@@ -77,7 +79,7 @@ export declare class ArvoResumable<TMemory extends Record<string, any> = Record<
|
|
|
77
79
|
* @throws {ContractViolation} When event schema validation fails
|
|
78
80
|
* @throws {ExecutionViolation} When workflow execution encounters critical errors
|
|
79
81
|
*/
|
|
80
|
-
execute(event: ArvoEvent, opentelemetry
|
|
82
|
+
execute(event: ArvoEvent, opentelemetry?: ArvoEventHandlerOpenTelemetryOptions): Promise<{
|
|
81
83
|
events: ArvoEvent[];
|
|
82
84
|
}>;
|
|
83
85
|
get systemErrorSchema(): import("arvo-core").ArvoContractRecord<`sys.arvo.orc.${string}.error`, z.ZodObject<{
|
|
@@ -1,4 +1,15 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __assign = (this && this.__assign) || function () {
|
|
3
|
+
__assign = Object.assign || function(t) {
|
|
4
|
+
for (var s, i = 1, n = arguments.length; i < n; i++) {
|
|
5
|
+
s = arguments[i];
|
|
6
|
+
for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
|
|
7
|
+
t[p] = s[p];
|
|
8
|
+
}
|
|
9
|
+
return t;
|
|
10
|
+
};
|
|
11
|
+
return __assign.apply(this, arguments);
|
|
12
|
+
};
|
|
2
13
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
14
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
15
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -46,6 +57,7 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
46
57
|
};
|
|
47
58
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
48
59
|
exports.ArvoResumable = void 0;
|
|
60
|
+
var api_1 = require("@opentelemetry/api");
|
|
49
61
|
var arvo_core_1 = require("arvo-core");
|
|
50
62
|
var createEmitableEvent_1 = require("../ArvoOrchestrationUtils/createEmitableEvent");
|
|
51
63
|
var orchestrationExecutionWrapper_1 = require("../ArvoOrchestrationUtils/orchestrationExecutionWrapper");
|
|
@@ -85,13 +97,15 @@ var errors_1 = require("../errors");
|
|
|
85
97
|
var ArvoResumable = /** @class */ (function () {
|
|
86
98
|
function ArvoResumable(param) {
|
|
87
99
|
var _a;
|
|
100
|
+
var _b, _c, _d;
|
|
88
101
|
this.systemErrorDomain = [];
|
|
89
102
|
this.executionunits = param.executionunits;
|
|
90
103
|
this.source = param.contracts.self.type;
|
|
91
|
-
this.syncEventResource = new index_1.SyncEventResource(param.memory, (
|
|
104
|
+
this.syncEventResource = new index_1.SyncEventResource(param.memory, (_b = param.requiresResourceLocking) !== null && _b !== void 0 ? _b : true);
|
|
92
105
|
this.contracts = param.contracts;
|
|
93
106
|
this.handler = param.handler;
|
|
94
107
|
this.systemErrorDomain = param.systemErrorDomain;
|
|
108
|
+
this.spanOptions = __assign(__assign({ kind: api_1.SpanKind.PRODUCER }, param.spanOptions), { attributes: __assign(__assign((_a = {}, _a[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.ORCHESTRATOR, _a[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _a), ((_d = (_c = param.spanOptions) === null || _c === void 0 ? void 0 : _c.attributes) !== null && _d !== void 0 ? _d : {})), { 'arvo.handler.source': this.source, 'arvo.contract.uri': this.contracts.self.uri }) });
|
|
95
109
|
}
|
|
96
110
|
Object.defineProperty(ArvoResumable.prototype, "requiresResourceLocking", {
|
|
97
111
|
get: function () {
|
|
@@ -183,8 +197,11 @@ var ArvoResumable = /** @class */ (function () {
|
|
|
183
197
|
case 0: return [4 /*yield*/, (0, orchestrationExecutionWrapper_1.executeWithOrchestrationWrapper)({
|
|
184
198
|
_handlerType: 'resumable',
|
|
185
199
|
event: event,
|
|
186
|
-
opentelemetry: opentelemetry,
|
|
187
|
-
spanName:
|
|
200
|
+
opentelemetry: opentelemetry !== null && opentelemetry !== void 0 ? opentelemetry : { inheritFrom: 'EVENT' },
|
|
201
|
+
spanOptions: __assign({ spanName: function (_a) {
|
|
202
|
+
var selfContractUri = _a.selfContractUri, consumedEvent = _a.consumedEvent;
|
|
203
|
+
return "Resumable<".concat(selfContractUri, ">@<").concat(consumedEvent.type, ">");
|
|
204
|
+
} }, this.spanOptions),
|
|
188
205
|
source: this.source,
|
|
189
206
|
syncEventResource: this.syncEventResource,
|
|
190
207
|
executionunits: this.executionunits,
|
|
@@ -21,7 +21,7 @@ export default interface IArvoEventHandler {
|
|
|
21
21
|
* @returns A promise that resolves to an array of resulting Arvo events.
|
|
22
22
|
* These events represent the outcome of processing the input event.
|
|
23
23
|
*/
|
|
24
|
-
execute(event: ArvoEvent, opentelemetry
|
|
24
|
+
execute(event: ArvoEvent, opentelemetry?: ArvoEventHandlerOpenTelemetryOptions): Promise<{
|
|
25
25
|
events: ArvoEvent[];
|
|
26
26
|
}>;
|
|
27
27
|
/**
|
package/dist/index.d.ts
CHANGED
|
@@ -6,7 +6,8 @@ import { ArvoEventHandlerFunction, ArvoEventHandlerFunctionInput, ArvoEventHandl
|
|
|
6
6
|
import ArvoMachine from './ArvoMachine';
|
|
7
7
|
import { setupArvoMachine } from './ArvoMachine/createMachine';
|
|
8
8
|
import { ArvoMachineContext, EnqueueArvoEventActionParam } from './ArvoMachine/types';
|
|
9
|
-
import {
|
|
9
|
+
import { TransactionViolation, TransactionViolationCause, isTransactionViolationError } from './ArvoOrchestrationUtils/error';
|
|
10
|
+
import { OrchestrationExecutionStatus } from './ArvoOrchestrationUtils/orchestrationExecutionState';
|
|
10
11
|
import { ArvoOrchestrator } from './ArvoOrchestrator';
|
|
11
12
|
import { createArvoOrchestrator } from './ArvoOrchestrator/factory';
|
|
12
13
|
import { ArvoOrchestratorParam, MachineMemoryRecord } from './ArvoOrchestrator/types';
|
|
@@ -23,13 +24,12 @@ import { IMachineMemory } from './MachineMemory/interface';
|
|
|
23
24
|
import { MachineRegistry } from './MachineRegistry';
|
|
24
25
|
import { IMachineRegistry } from './MachineRegistry/interface';
|
|
25
26
|
import { ConfigViolation, ContractViolation, ExecutionViolation } from './errors';
|
|
26
|
-
import { ArvoEventHandlerOpenTelemetryOptions, EventHandlerFactory, PartialExcept } from './types';
|
|
27
|
+
import { ArvoEventHandlerOpenTelemetryOptions, ArvoEventHandlerOtelSpanOptions, EventHandlerFactory, PartialExcept } from './types';
|
|
27
28
|
import { coalesce, coalesceOrDefault, getValueOrDefault, isNullOrUndefined } from './utils';
|
|
28
29
|
import { SimpleEventBroker } from './utils/SimpleEventBroker';
|
|
29
30
|
import { createSimpleEventBroker } from './utils/SimpleEventBroker/helper';
|
|
30
|
-
import { OrchestrationExecutionStatus } from './ArvoOrchestrationUtils/orchestrationExecutionState';
|
|
31
31
|
declare const xstate: {
|
|
32
32
|
emit: typeof emit;
|
|
33
33
|
assign: typeof assign;
|
|
34
34
|
};
|
|
35
|
-
export { ArvoEventHandler, createArvoEventHandler, IArvoEventHandler, ArvoEventHandlerFunctionOutput, ArvoEventHandlerFunctionInput, ArvoEventHandlerFunction, PartialExcept, isNullOrUndefined, getValueOrDefault, coalesce, coalesceOrDefault, ArvoEventHandlerOpenTelemetryOptions, EventHandlerFactory, ContractViolation, ConfigViolation, ExecutionViolation, ArvoMachine, setupArvoMachine, ArvoMachineContext, EnqueueArvoEventActionParam, IMachineRegistry, MachineRegistry, MachineExecutionEngine, IMachineExectionEngine, ExecuteMachineInput, ExecuteMachineOutput, IMachineMemory, SimpleMachineMemory, MachineMemoryRecord, ArvoOrchestratorParam, TransactionViolation, TransactionViolationCause, ArvoOrchestrator, createArvoOrchestrator, SimpleEventBroker, createSimpleEventBroker, TelemetredSimpleMachineMemory, xstate, ArvoResumable, createArvoResumable, ArvoResumableHandler, ArvoResumableState, ArvoDomain, resolveEventDomain, isTransactionViolationError, OrchestrationExecutionStatus };
|
|
35
|
+
export { ArvoEventHandler, createArvoEventHandler, IArvoEventHandler, ArvoEventHandlerFunctionOutput, ArvoEventHandlerFunctionInput, ArvoEventHandlerFunction, PartialExcept, isNullOrUndefined, getValueOrDefault, coalesce, coalesceOrDefault, ArvoEventHandlerOpenTelemetryOptions, EventHandlerFactory, ContractViolation, ConfigViolation, ExecutionViolation, ArvoMachine, setupArvoMachine, ArvoMachineContext, EnqueueArvoEventActionParam, IMachineRegistry, MachineRegistry, MachineExecutionEngine, IMachineExectionEngine, ExecuteMachineInput, ExecuteMachineOutput, IMachineMemory, SimpleMachineMemory, MachineMemoryRecord, ArvoOrchestratorParam, TransactionViolation, TransactionViolationCause, ArvoOrchestrator, createArvoOrchestrator, SimpleEventBroker, createSimpleEventBroker, TelemetredSimpleMachineMemory, xstate, ArvoResumable, createArvoResumable, ArvoResumableHandler, ArvoResumableState, ArvoDomain, resolveEventDomain, isTransactionViolationError, OrchestrationExecutionStatus, ArvoEventHandlerOtelSpanOptions, };
|
package/dist/index.js
CHANGED
|
@@ -17,9 +17,11 @@ exports.ArvoMachine = ArvoMachine_1.default;
|
|
|
17
17
|
var createMachine_1 = require("./ArvoMachine/createMachine");
|
|
18
18
|
Object.defineProperty(exports, "setupArvoMachine", { enumerable: true, get: function () { return createMachine_1.setupArvoMachine; } });
|
|
19
19
|
var error_1 = require("./ArvoOrchestrationUtils/error");
|
|
20
|
-
Object.defineProperty(exports, "isTransactionViolationError", { enumerable: true, get: function () { return error_1.isTransactionViolationError; } });
|
|
21
20
|
Object.defineProperty(exports, "TransactionViolation", { enumerable: true, get: function () { return error_1.TransactionViolation; } });
|
|
22
21
|
Object.defineProperty(exports, "TransactionViolationCause", { enumerable: true, get: function () { return error_1.TransactionViolationCause; } });
|
|
22
|
+
Object.defineProperty(exports, "isTransactionViolationError", { enumerable: true, get: function () { return error_1.isTransactionViolationError; } });
|
|
23
|
+
var orchestrationExecutionState_1 = require("./ArvoOrchestrationUtils/orchestrationExecutionState");
|
|
24
|
+
Object.defineProperty(exports, "OrchestrationExecutionStatus", { enumerable: true, get: function () { return orchestrationExecutionState_1.OrchestrationExecutionStatus; } });
|
|
23
25
|
var ArvoOrchestrator_1 = require("./ArvoOrchestrator");
|
|
24
26
|
Object.defineProperty(exports, "ArvoOrchestrator", { enumerable: true, get: function () { return ArvoOrchestrator_1.ArvoOrchestrator; } });
|
|
25
27
|
var factory_1 = require("./ArvoOrchestrator/factory");
|
|
@@ -49,8 +51,6 @@ var SimpleEventBroker_1 = require("./utils/SimpleEventBroker");
|
|
|
49
51
|
Object.defineProperty(exports, "SimpleEventBroker", { enumerable: true, get: function () { return SimpleEventBroker_1.SimpleEventBroker; } });
|
|
50
52
|
var helper_1 = require("./utils/SimpleEventBroker/helper");
|
|
51
53
|
Object.defineProperty(exports, "createSimpleEventBroker", { enumerable: true, get: function () { return helper_1.createSimpleEventBroker; } });
|
|
52
|
-
var orchestrationExecutionState_1 = require("./ArvoOrchestrationUtils/orchestrationExecutionState");
|
|
53
|
-
Object.defineProperty(exports, "OrchestrationExecutionStatus", { enumerable: true, get: function () { return orchestrationExecutionState_1.OrchestrationExecutionStatus; } });
|
|
54
54
|
var xstate = {
|
|
55
55
|
emit: xstate_1.emit,
|
|
56
56
|
assign: xstate_1.assign,
|
package/dist/types.d.ts
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
import type { SpanOptions } from '@opentelemetry/api';
|
|
2
|
+
import type { ArvoEvent } from 'arvo-core';
|
|
1
3
|
import type IArvoEventHandler from './IArvoEventHandler';
|
|
2
4
|
/**
|
|
3
5
|
* Makes properties optional except specified keys
|
|
@@ -30,3 +32,9 @@ export type ArvoEventHandlerOpenTelemetryOptions = {
|
|
|
30
32
|
* @template T - Configuration object type
|
|
31
33
|
*/
|
|
32
34
|
export type EventHandlerFactory<T = void> = T extends void ? () => IArvoEventHandler : (config: T) => IArvoEventHandler;
|
|
35
|
+
export type ArvoEventHandlerOtelSpanOptions = SpanOptions & {
|
|
36
|
+
spanName?: (param: {
|
|
37
|
+
selfContractUri: string;
|
|
38
|
+
consumedEvent: ArvoEvent;
|
|
39
|
+
}) => string;
|
|
40
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arvo-event-handler",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.10",
|
|
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": {
|
|
@@ -46,7 +46,7 @@
|
|
|
46
46
|
"dependencies": {
|
|
47
47
|
"@opentelemetry/api": "^1.9.0",
|
|
48
48
|
"@opentelemetry/core": "^1.30.1",
|
|
49
|
-
"arvo-core": "^3.0.
|
|
49
|
+
"arvo-core": "^3.0.10",
|
|
50
50
|
"uuid": "^11.1.0",
|
|
51
51
|
"xstate": "^5.23.0",
|
|
52
52
|
"zod": "^3.25.74",
|