arvo-event-handler 2.3.3 → 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.
- package/dist/AbstractArvoEventHandler/index.d.ts +1 -1
- package/dist/ArvoEventHandler/helpers.d.ts +40 -6
- package/dist/ArvoEventHandler/helpers.js +40 -6
- package/dist/ArvoEventHandler/index.d.ts +78 -49
- package/dist/ArvoEventHandler/index.js +152 -83
- package/dist/ArvoEventHandler/types.d.ts +25 -2
- package/dist/ArvoMachine/createMachine.d.ts +208 -0
- package/dist/ArvoMachine/createMachine.js +283 -0
- package/dist/ArvoMachine/index.d.ts +93 -0
- package/dist/ArvoMachine/index.js +160 -0
- package/dist/ArvoMachine/types.d.ts +194 -0
- package/dist/ArvoMachine/utils.d.ts +40 -0
- package/dist/ArvoMachine/utils.js +70 -0
- package/dist/ArvoOrchestrator/error.d.ts +16 -0
- package/dist/ArvoOrchestrator/error.js +43 -0
- package/dist/ArvoOrchestrator/factory.d.ts +28 -0
- package/dist/ArvoOrchestrator/factory.js +56 -0
- package/dist/ArvoOrchestrator/index.d.ts +69 -0
- package/dist/ArvoOrchestrator/index.js +597 -0
- package/dist/ArvoOrchestrator/types.d.ts +98 -0
- package/dist/ArvoResumable/factory.d.ts +50 -0
- package/dist/ArvoResumable/factory.js +70 -0
- package/dist/ArvoResumable/index.d.ts +141 -0
- package/dist/ArvoResumable/index.js +694 -0
- package/dist/ArvoResumable/types.d.ts +147 -0
- package/dist/ArvoResumable/types.js +2 -0
- package/dist/MachineExecutionEngine/index.d.ts +29 -0
- package/dist/MachineExecutionEngine/index.js +132 -0
- package/dist/MachineExecutionEngine/interface.d.ts +14 -0
- package/dist/MachineExecutionEngine/interface.js +2 -0
- package/dist/MachineExecutionEngine/types.d.ts +14 -0
- package/dist/MachineExecutionEngine/types.js +2 -0
- package/dist/MachineMemory/Simple.d.ts +51 -0
- package/dist/MachineMemory/Simple.js +158 -0
- package/dist/MachineMemory/TelemetredSimple.d.ts +51 -0
- package/dist/MachineMemory/TelemetredSimple.js +230 -0
- package/dist/MachineMemory/interface.d.ts +57 -0
- package/dist/MachineMemory/interface.js +2 -0
- package/dist/MachineMemory/utils.d.ts +1 -0
- package/dist/MachineMemory/utils.js +18 -0
- package/dist/MachineRegistry/index.d.ts +37 -0
- package/dist/MachineRegistry/index.js +87 -0
- package/dist/MachineRegistry/interface.d.ts +21 -0
- package/dist/MachineRegistry/interface.js +2 -0
- package/dist/SyncEventResource/index.d.ts +110 -0
- package/dist/SyncEventResource/index.js +280 -0
- package/dist/SyncEventResource/types.d.ts +2 -0
- package/dist/SyncEventResource/types.js +2 -0
- package/dist/index.d.ts +26 -8
- package/dist/index.js +39 -16
- package/dist/utils/SimpleEventBroker/helper.d.ts +166 -0
- package/dist/utils/SimpleEventBroker/helper.js +276 -0
- package/dist/utils/SimpleEventBroker/index.d.ts +96 -0
- package/dist/utils/SimpleEventBroker/index.js +259 -0
- package/dist/utils/SimpleEventBroker/types.d.ts +6 -0
- package/dist/utils/SimpleEventBroker/types.js +2 -0
- package/dist/utils/SimpleEventBroker/utils.d.ts +1 -0
- package/dist/utils/SimpleEventBroker/utils.js +10 -0
- package/dist/{utils.d.ts → utils/index.d.ts} +3 -36
- package/dist/utils/index.js +91 -0
- package/dist/utils/object/index.d.ts +37 -0
- package/dist/utils/object/index.js +63 -0
- package/package.json +5 -3
- package/dist/ArvoEventRouter/helpers.d.ts +0 -19
- package/dist/ArvoEventRouter/helpers.js +0 -22
- package/dist/ArvoEventRouter/index.d.ts +0 -89
- package/dist/ArvoEventRouter/index.js +0 -268
- package/dist/ArvoEventRouter/types.d.ts +0 -36
- package/dist/ArvoEventRouter/utils.d.ts +0 -30
- package/dist/ArvoEventRouter/utils.js +0 -43
- package/dist/MultiArvoEventHandler/helpers.d.ts +0 -48
- package/dist/MultiArvoEventHandler/helpers.js +0 -56
- package/dist/MultiArvoEventHandler/index.d.ts +0 -68
- package/dist/MultiArvoEventHandler/index.js +0 -205
- package/dist/MultiArvoEventHandler/types.d.ts +0 -64
- package/dist/utils.js +0 -191
- /package/dist/{ArvoEventRouter → ArvoMachine}/types.js +0 -0
- /package/dist/{MultiArvoEventHandler → ArvoOrchestrator}/types.js +0 -0
|
@@ -1,268 +0,0 @@
|
|
|
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 __importDefault = (this && this.__importDefault) || function (mod) {
|
|
65
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
66
|
-
};
|
|
67
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
68
|
-
exports.ArvoEventRouter = void 0;
|
|
69
|
-
var api_1 = require("@opentelemetry/api");
|
|
70
|
-
var arvo_core_1 = require("arvo-core");
|
|
71
|
-
var AbstractArvoEventHandler_1 = __importDefault(require("../AbstractArvoEventHandler"));
|
|
72
|
-
var errors_1 = require("../errors");
|
|
73
|
-
var utils_1 = require("../utils");
|
|
74
|
-
var utils_2 = require("./utils");
|
|
75
|
-
/**
|
|
76
|
-
* ArvoEventRouter manages event routing and execution within the Arvo event system. It directs
|
|
77
|
-
* incoming events to appropriate handlers based on event type while maintaining telemetry
|
|
78
|
-
* and error handling.
|
|
79
|
-
*
|
|
80
|
-
* The router enforces contract validation, manages execution costs, and provides comprehensive
|
|
81
|
-
* telemetry via OpenTelemetry integration. It handles event lifecycle management from initial
|
|
82
|
-
* receipt through processing and response generation.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```typescript
|
|
86
|
-
* const router = createArvoEventRouter({
|
|
87
|
-
* source: "payment.service",
|
|
88
|
-
* executionunits: 1,
|
|
89
|
-
* handlers: [paymentProcessedHandler, paymentFailedHandler]
|
|
90
|
-
* });
|
|
91
|
-
*
|
|
92
|
-
* // Route an incoming event
|
|
93
|
-
* const results = await router.execute(incomingEvent);
|
|
94
|
-
* ```
|
|
95
|
-
*/
|
|
96
|
-
var ArvoEventRouter = /** @class */ (function (_super) {
|
|
97
|
-
__extends(ArvoEventRouter, _super);
|
|
98
|
-
/**
|
|
99
|
-
* Creates an ArvoEventRouter instance with specified configuration.
|
|
100
|
-
*
|
|
101
|
-
* @param param - Router configuration containing source, handlers, and execution parameters
|
|
102
|
-
*
|
|
103
|
-
* @throws {Error} When source contains invalid characters (non-alphanumeric)
|
|
104
|
-
* @throws {Error} When multiple handlers are registered for the same event type
|
|
105
|
-
*/
|
|
106
|
-
function ArvoEventRouter(param) {
|
|
107
|
-
var _a;
|
|
108
|
-
var _b, _c;
|
|
109
|
-
var _this = _super.call(this) || this;
|
|
110
|
-
/** Registry mapping event types to their handlers */
|
|
111
|
-
_this.handlersMap = {};
|
|
112
|
-
if (param.source && !(0, utils_1.isLowerAlphanumeric)(param.source)) {
|
|
113
|
-
throw new Error("Invalid source identifier '".concat(param.source, "': Must contain only alphanumeric characters (example: payment.service)"));
|
|
114
|
-
}
|
|
115
|
-
_this.source = param.source;
|
|
116
|
-
_this.executionunits = param.executionunits;
|
|
117
|
-
for (var _i = 0, _d = param.handlers; _i < _d.length; _i++) {
|
|
118
|
-
var handler = _d[_i];
|
|
119
|
-
if (_this.handlersMap[handler.contract.type]) {
|
|
120
|
-
var existingHandler = _this.handlersMap[handler.contract.type];
|
|
121
|
-
throw new Error("Duplicate handler registration detected for event type '".concat(handler.contract.type, "'. ") +
|
|
122
|
-
"Conflicts between contracts: ".concat(existingHandler.contract.uri, " and ").concat(handler.contract.uri));
|
|
123
|
-
}
|
|
124
|
-
_this.handlersMap[handler.contract.type] = handler;
|
|
125
|
-
}
|
|
126
|
-
_this.spanOptions = __assign(__assign({ kind: api_1.SpanKind.CONSUMER }, param.spanOptions), { attributes: __assign(__assign((_a = {}, _a[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = arvo_core_1.ArvoExecutionSpanKind.EVENT_HANDLER, _a[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = arvo_core_1.OpenInferenceSpanKind.CHAIN, _a), ((_c = (_b = param.spanOptions) === null || _b === void 0 ? void 0 : _b.attributes) !== null && _c !== void 0 ? _c : {})), { 'arvo.handler.source': _this.source }) });
|
|
127
|
-
return _this;
|
|
128
|
-
}
|
|
129
|
-
/**
|
|
130
|
-
* Routes and executes an event through its appropriate handler. Creates a telemetry span,
|
|
131
|
-
* validates the event destination, finds a matching handler, and processes the event.
|
|
132
|
-
* Handles routing errors, missing handlers, and execution failures by returning error
|
|
133
|
-
* events with telemetry context. Tracks performance through execution units and span
|
|
134
|
-
* propagation.
|
|
135
|
-
*
|
|
136
|
-
* @param event The event to be routed and processed
|
|
137
|
-
* @param opentelemetry Configuration for telemetry context inheritance
|
|
138
|
-
* @returns Promise resolving to resulting events or error events
|
|
139
|
-
*
|
|
140
|
-
* @throws {ConfigViolation} When event destination does not match router's source
|
|
141
|
-
* @throws {ConfigViolation} When no registered handler exists for the event type
|
|
142
|
-
* @throws Other Violation error which are thrown by the registered event handlers
|
|
143
|
-
*/
|
|
144
|
-
ArvoEventRouter.prototype.execute = function (event_1) {
|
|
145
|
-
return __awaiter(this, arguments, void 0, function (event, opentelemetry) {
|
|
146
|
-
var _this = this;
|
|
147
|
-
if (opentelemetry === void 0) { opentelemetry = {
|
|
148
|
-
inheritFrom: 'EVENT',
|
|
149
|
-
}; }
|
|
150
|
-
return __generator(this, function (_a) {
|
|
151
|
-
switch (_a.label) {
|
|
152
|
-
case 0: return [4 /*yield*/, arvo_core_1.ArvoOpenTelemetry.getInstance().startActiveSpan({
|
|
153
|
-
name: 'ArvoEventRouter',
|
|
154
|
-
spanOptions: this.spanOptions,
|
|
155
|
-
disableSpanManagement: true,
|
|
156
|
-
context: opentelemetry.inheritFrom === 'EVENT'
|
|
157
|
-
? {
|
|
158
|
-
inheritFrom: 'TRACE_HEADERS',
|
|
159
|
-
traceHeaders: {
|
|
160
|
-
traceparent: event.traceparent,
|
|
161
|
-
tracestate: event.tracestate,
|
|
162
|
-
},
|
|
163
|
-
}
|
|
164
|
-
: {
|
|
165
|
-
inheritFrom: 'CONTEXT',
|
|
166
|
-
context: api_1.context.active(),
|
|
167
|
-
},
|
|
168
|
-
fn: function (span) { return __awaiter(_this, void 0, void 0, function () {
|
|
169
|
-
var otelSpanHeaders, newEvent, _i, _a, _b, key, value, results, resultingEvents, index, _c, _d, _e, key, value, error_1, events;
|
|
170
|
-
var _this = this;
|
|
171
|
-
return __generator(this, function (_f) {
|
|
172
|
-
switch (_f.label) {
|
|
173
|
-
case 0:
|
|
174
|
-
otelSpanHeaders = (0, arvo_core_1.currentOpenTelemetryHeaders)();
|
|
175
|
-
newEvent = (0, utils_2.deleteOtelHeaders)(event);
|
|
176
|
-
_f.label = 1;
|
|
177
|
-
case 1:
|
|
178
|
-
_f.trys.push([1, 3, 4, 5]);
|
|
179
|
-
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
180
|
-
for (_i = 0, _a = Object.entries(event.otelAttributes); _i < _a.length; _i++) {
|
|
181
|
-
_b = _a[_i], key = _b[0], value = _b[1];
|
|
182
|
-
span.setAttribute("to_process.0.".concat(key), value);
|
|
183
|
-
}
|
|
184
|
-
(0, arvo_core_1.logToSpan)({
|
|
185
|
-
level: 'INFO',
|
|
186
|
-
message: "Initiating event resolution - Type: ".concat(newEvent.type, ", Source: ").concat(newEvent.source, ", Destination: ").concat(newEvent.to),
|
|
187
|
-
});
|
|
188
|
-
if (newEvent.to !== this.source) {
|
|
189
|
-
throw new errors_1.ConfigViolation("Event destination mismatch: Received destination '".concat(newEvent.to, "', ") +
|
|
190
|
-
"but router accepts only '".concat(this.source, "'"));
|
|
191
|
-
}
|
|
192
|
-
if (!this.handlersMap[newEvent.type]) {
|
|
193
|
-
throw new errors_1.ConfigViolation("No registered handler found for event type '".concat(newEvent.type, "'"));
|
|
194
|
-
}
|
|
195
|
-
(0, arvo_core_1.logToSpan)({
|
|
196
|
-
level: 'INFO',
|
|
197
|
-
message: "Handler found for event type '".concat(newEvent.type, "' - Beginning event processing"),
|
|
198
|
-
});
|
|
199
|
-
return [4 /*yield*/, this.handlersMap[newEvent.type].execute(newEvent, {
|
|
200
|
-
inheritFrom: 'CONTEXT',
|
|
201
|
-
})];
|
|
202
|
-
case 2:
|
|
203
|
-
results = _f.sent();
|
|
204
|
-
resultingEvents = results.events.map(function (event) {
|
|
205
|
-
var _a;
|
|
206
|
-
return new arvo_core_1.ArvoEvent({
|
|
207
|
-
id: event.id,
|
|
208
|
-
time: event.time,
|
|
209
|
-
source: _this.source,
|
|
210
|
-
specversion: '1.0',
|
|
211
|
-
type: event.type,
|
|
212
|
-
subject: event.subject,
|
|
213
|
-
datacontenttype: event.datacontenttype,
|
|
214
|
-
dataschema: event.dataschema,
|
|
215
|
-
to: event.to,
|
|
216
|
-
accesscontrol: event.accesscontrol,
|
|
217
|
-
redirectto: event.redirectto,
|
|
218
|
-
executionunits: ((_a = event.executionunits) !== null && _a !== void 0 ? _a : 0) + _this.executionunits,
|
|
219
|
-
traceparent: otelSpanHeaders.traceparent,
|
|
220
|
-
tracestate: otelSpanHeaders.tracestate,
|
|
221
|
-
parentid: event.parentid,
|
|
222
|
-
}, event.data, event.cloudevent.extensions);
|
|
223
|
-
});
|
|
224
|
-
(0, arvo_core_1.logToSpan)({
|
|
225
|
-
level: 'INFO',
|
|
226
|
-
message: "Event processing completed successfully - Generated ".concat(resultingEvents.length, " new event(s)"),
|
|
227
|
-
});
|
|
228
|
-
for (index = 0; index < resultingEvents.length; index++) {
|
|
229
|
-
for (_c = 0, _d = Object.entries(resultingEvents[index].otelAttributes); _c < _d.length; _c++) {
|
|
230
|
-
_e = _d[_c], key = _e[0], value = _e[1];
|
|
231
|
-
span.setAttribute("to_emit.".concat(index, ".").concat(key), value);
|
|
232
|
-
}
|
|
233
|
-
}
|
|
234
|
-
return [2 /*return*/, { events: resultingEvents }];
|
|
235
|
-
case 3:
|
|
236
|
-
error_1 = _f.sent();
|
|
237
|
-
events = (0, utils_1.handleArvoEventHandlerCommonError)(error_1, otelSpanHeaders, this.systemErrorSchema.type, this.source, event, this.executionunits, function (param, extensions) { return (0, arvo_core_1.createArvoEvent)(param, extensions); });
|
|
238
|
-
return [2 /*return*/, { events: events }];
|
|
239
|
-
case 4:
|
|
240
|
-
span.end();
|
|
241
|
-
return [7 /*endfinally*/];
|
|
242
|
-
case 5: return [2 /*return*/];
|
|
243
|
-
}
|
|
244
|
-
});
|
|
245
|
-
}); },
|
|
246
|
-
})];
|
|
247
|
-
case 1: return [2 /*return*/, _a.sent()];
|
|
248
|
-
}
|
|
249
|
-
});
|
|
250
|
-
});
|
|
251
|
-
};
|
|
252
|
-
Object.defineProperty(ArvoEventRouter.prototype, "systemErrorSchema", {
|
|
253
|
-
/**
|
|
254
|
-
* System error schema configuration.
|
|
255
|
-
* Error events follow format: sys.<handler-source>.error
|
|
256
|
-
*/
|
|
257
|
-
get: function () {
|
|
258
|
-
return {
|
|
259
|
-
type: "sys.".concat(this.source, ".error"),
|
|
260
|
-
schema: arvo_core_1.ArvoErrorSchema,
|
|
261
|
-
};
|
|
262
|
-
},
|
|
263
|
-
enumerable: false,
|
|
264
|
-
configurable: true
|
|
265
|
-
});
|
|
266
|
-
return ArvoEventRouter;
|
|
267
|
-
}(AbstractArvoEventHandler_1.default));
|
|
268
|
-
exports.ArvoEventRouter = ArvoEventRouter;
|
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import type { SpanOptions } from '@opentelemetry/api';
|
|
2
|
-
import type { ArvoContract } from 'arvo-core';
|
|
3
|
-
import type ArvoEventHandler from '../ArvoEventHandler';
|
|
4
|
-
/**
|
|
5
|
-
* Interface for defining an Arvo Event Router.
|
|
6
|
-
*/
|
|
7
|
-
export interface IArvoEventRouter {
|
|
8
|
-
/**
|
|
9
|
-
* Defines the source name of the router.
|
|
10
|
-
*
|
|
11
|
-
* @remarks
|
|
12
|
-
* If this field is defined:
|
|
13
|
-
* - The router will only listen to events with a `to` field matching this `source`.
|
|
14
|
-
* - If an event's `to` field doesn't match, a system error event will be emitted.
|
|
15
|
-
* - For all emitted events, the `source` field will be overridden by this value.
|
|
16
|
-
*/
|
|
17
|
-
source: string;
|
|
18
|
-
/**
|
|
19
|
-
* The default execution cost of the function.
|
|
20
|
-
* This can represent a dollar value or some other number with a rate card.
|
|
21
|
-
*/
|
|
22
|
-
executionunits: number;
|
|
23
|
-
/**
|
|
24
|
-
* A list of all available event handlers to be used by the router.
|
|
25
|
-
*
|
|
26
|
-
* @remarks
|
|
27
|
-
* This array contains instances of `ArvoEventHandler<ArvoContract>` which define
|
|
28
|
-
* how different types of events should be processed. The router will use these
|
|
29
|
-
* handlers to manage incoming events and generate appropriate responses or actions.
|
|
30
|
-
*/
|
|
31
|
-
handlers: ArvoEventHandler<ArvoContract<any, any, any>>[];
|
|
32
|
-
/**
|
|
33
|
-
* The OpenTelemetry span options
|
|
34
|
-
*/
|
|
35
|
-
spanOptions?: SpanOptions;
|
|
36
|
-
}
|
|
@@ -1,30 +0,0 @@
|
|
|
1
|
-
import { ArvoEvent } from 'arvo-core';
|
|
2
|
-
/**
|
|
3
|
-
* Creates a new ArvoEvent with telemetry headers (traceparent and tracestate) removed.
|
|
4
|
-
*
|
|
5
|
-
* @param event - The original ArvoEvent to process
|
|
6
|
-
* @returns A new ArvoEvent instance with all original properties except telemetry headers
|
|
7
|
-
*
|
|
8
|
-
* @remarks
|
|
9
|
-
* This function creates a clean copy of an ArvoEvent by:
|
|
10
|
-
* 1. Preserving all standard event properties
|
|
11
|
-
* 2. Setting telemetry headers (traceparent and tracestate) to null
|
|
12
|
-
* 3. Maintaining the original data and extensions
|
|
13
|
-
*
|
|
14
|
-
* It's useful when you need to:
|
|
15
|
-
* - Clear existing telemetry context
|
|
16
|
-
* - Start a new telemetry trace
|
|
17
|
-
* - Remove distributed tracing information
|
|
18
|
-
*
|
|
19
|
-
* @see {@link ArvoEvent} for complete event structure
|
|
20
|
-
*/
|
|
21
|
-
export declare const deleteOtelHeaders: (event: ArvoEvent) => ArvoEvent<Record<string, any>, Record<string, string | number | boolean | null> & {
|
|
22
|
-
to: string | null;
|
|
23
|
-
accesscontrol: string | null;
|
|
24
|
-
redirectto: string | null;
|
|
25
|
-
executionunits: number | null;
|
|
26
|
-
parentid: string | null;
|
|
27
|
-
} & {
|
|
28
|
-
traceparent: string | null;
|
|
29
|
-
tracestate: string | null;
|
|
30
|
-
}, string>;
|
|
@@ -1,43 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.deleteOtelHeaders = void 0;
|
|
4
|
-
var arvo_core_1 = require("arvo-core");
|
|
5
|
-
/**
|
|
6
|
-
* Creates a new ArvoEvent with telemetry headers (traceparent and tracestate) removed.
|
|
7
|
-
*
|
|
8
|
-
* @param event - The original ArvoEvent to process
|
|
9
|
-
* @returns A new ArvoEvent instance with all original properties except telemetry headers
|
|
10
|
-
*
|
|
11
|
-
* @remarks
|
|
12
|
-
* This function creates a clean copy of an ArvoEvent by:
|
|
13
|
-
* 1. Preserving all standard event properties
|
|
14
|
-
* 2. Setting telemetry headers (traceparent and tracestate) to null
|
|
15
|
-
* 3. Maintaining the original data and extensions
|
|
16
|
-
*
|
|
17
|
-
* It's useful when you need to:
|
|
18
|
-
* - Clear existing telemetry context
|
|
19
|
-
* - Start a new telemetry trace
|
|
20
|
-
* - Remove distributed tracing information
|
|
21
|
-
*
|
|
22
|
-
* @see {@link ArvoEvent} for complete event structure
|
|
23
|
-
*/
|
|
24
|
-
var deleteOtelHeaders = function (event) {
|
|
25
|
-
return new arvo_core_1.ArvoEvent({
|
|
26
|
-
id: event.id,
|
|
27
|
-
time: event.time,
|
|
28
|
-
source: event.source,
|
|
29
|
-
specversion: '1.0',
|
|
30
|
-
type: event.type,
|
|
31
|
-
subject: event.subject,
|
|
32
|
-
datacontenttype: event.datacontenttype,
|
|
33
|
-
dataschema: event.dataschema,
|
|
34
|
-
to: event.to,
|
|
35
|
-
accesscontrol: event.accesscontrol,
|
|
36
|
-
redirectto: event.redirectto,
|
|
37
|
-
executionunits: event.executionunits,
|
|
38
|
-
traceparent: null,
|
|
39
|
-
tracestate: null,
|
|
40
|
-
parentid: event.parentid,
|
|
41
|
-
}, event.data, event.cloudevent.extensions);
|
|
42
|
-
};
|
|
43
|
-
exports.deleteOtelHeaders = deleteOtelHeaders;
|
|
@@ -1,48 +0,0 @@
|
|
|
1
|
-
import MultiArvoEventHandler from '.';
|
|
2
|
-
import type { IMultiArvoEventHandler } from './types';
|
|
3
|
-
/**
|
|
4
|
-
* Creates a MultiArvoEventHandler instance capable of handling multiple event types across different ArvoContracts.
|
|
5
|
-
*
|
|
6
|
-
* @param param - The configuration parameters for the event handler.
|
|
7
|
-
* @returns A new instance of MultiArvoEventHandler.
|
|
8
|
-
*
|
|
9
|
-
* @remarks
|
|
10
|
-
* This factory function instantiates a MultiArvoEventHandler, which is designed to process
|
|
11
|
-
* multiple event types from various ArvoContracts. Unlike the more specialized ArvoEventHandler,
|
|
12
|
-
* MultiArvoEventHandler offers greater flexibility by not being bound to a specific contract
|
|
13
|
-
* or event type.
|
|
14
|
-
*
|
|
15
|
-
* Key features of MultiArvoEventHandler:
|
|
16
|
-
* - Handles multiple event types
|
|
17
|
-
* - Works across different ArvoContracts
|
|
18
|
-
* - Provides a unified interface for diverse event processing
|
|
19
|
-
*
|
|
20
|
-
* The handler's behavior and resource allocation are determined by the provided configuration
|
|
21
|
-
* parameters, including execution units and the event processing logic.
|
|
22
|
-
*
|
|
23
|
-
* @example
|
|
24
|
-
* ```typescript
|
|
25
|
-
* const multiEventHandler = createMultiArvoEventHandler({
|
|
26
|
-
* source: 'com.multi.handler',
|
|
27
|
-
* executionunits: 100,
|
|
28
|
-
* handler: async ({ event }) => {
|
|
29
|
-
* switch(event.type) {
|
|
30
|
-
* case 'com.user.registered':
|
|
31
|
-
* // Handle user registration event
|
|
32
|
-
* break;
|
|
33
|
-
* case 'com.transaction.complete':
|
|
34
|
-
* // Handle transaction completion event
|
|
35
|
-
* break;
|
|
36
|
-
* // ... handle other event types
|
|
37
|
-
* }
|
|
38
|
-
* }
|
|
39
|
-
* });
|
|
40
|
-
*
|
|
41
|
-
* // Use the handler
|
|
42
|
-
* await multiEventHandler.handleEvent(someEvent);
|
|
43
|
-
* ```
|
|
44
|
-
*
|
|
45
|
-
* @see {@link IMultiArvoEventHandler} for the full configuration options
|
|
46
|
-
* @see {@link MultiArvoEventHandler} for the handler class implementation
|
|
47
|
-
*/
|
|
48
|
-
export declare const createMultiArvoEventHandler: (param: IMultiArvoEventHandler) => MultiArvoEventHandler;
|
|
@@ -1,56 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
3
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
|
-
};
|
|
5
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.createMultiArvoEventHandler = void 0;
|
|
7
|
-
var _1 = __importDefault(require("."));
|
|
8
|
-
/**
|
|
9
|
-
* Creates a MultiArvoEventHandler instance capable of handling multiple event types across different ArvoContracts.
|
|
10
|
-
*
|
|
11
|
-
* @param param - The configuration parameters for the event handler.
|
|
12
|
-
* @returns A new instance of MultiArvoEventHandler.
|
|
13
|
-
*
|
|
14
|
-
* @remarks
|
|
15
|
-
* This factory function instantiates a MultiArvoEventHandler, which is designed to process
|
|
16
|
-
* multiple event types from various ArvoContracts. Unlike the more specialized ArvoEventHandler,
|
|
17
|
-
* MultiArvoEventHandler offers greater flexibility by not being bound to a specific contract
|
|
18
|
-
* or event type.
|
|
19
|
-
*
|
|
20
|
-
* Key features of MultiArvoEventHandler:
|
|
21
|
-
* - Handles multiple event types
|
|
22
|
-
* - Works across different ArvoContracts
|
|
23
|
-
* - Provides a unified interface for diverse event processing
|
|
24
|
-
*
|
|
25
|
-
* The handler's behavior and resource allocation are determined by the provided configuration
|
|
26
|
-
* parameters, including execution units and the event processing logic.
|
|
27
|
-
*
|
|
28
|
-
* @example
|
|
29
|
-
* ```typescript
|
|
30
|
-
* const multiEventHandler = createMultiArvoEventHandler({
|
|
31
|
-
* source: 'com.multi.handler',
|
|
32
|
-
* executionunits: 100,
|
|
33
|
-
* handler: async ({ event }) => {
|
|
34
|
-
* switch(event.type) {
|
|
35
|
-
* case 'com.user.registered':
|
|
36
|
-
* // Handle user registration event
|
|
37
|
-
* break;
|
|
38
|
-
* case 'com.transaction.complete':
|
|
39
|
-
* // Handle transaction completion event
|
|
40
|
-
* break;
|
|
41
|
-
* // ... handle other event types
|
|
42
|
-
* }
|
|
43
|
-
* }
|
|
44
|
-
* });
|
|
45
|
-
*
|
|
46
|
-
* // Use the handler
|
|
47
|
-
* await multiEventHandler.handleEvent(someEvent);
|
|
48
|
-
* ```
|
|
49
|
-
*
|
|
50
|
-
* @see {@link IMultiArvoEventHandler} for the full configuration options
|
|
51
|
-
* @see {@link MultiArvoEventHandler} for the handler class implementation
|
|
52
|
-
*/
|
|
53
|
-
var createMultiArvoEventHandler = function (param) {
|
|
54
|
-
return new _1.default(param);
|
|
55
|
-
};
|
|
56
|
-
exports.createMultiArvoEventHandler = createMultiArvoEventHandler;
|
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { type SpanOptions } from '@opentelemetry/api';
|
|
2
|
-
import { type ArvoEvent } from 'arvo-core';
|
|
3
|
-
import AbstractArvoEventHandler from '../AbstractArvoEventHandler';
|
|
4
|
-
import type { ArvoEventHandlerOpenTelemetryOptions } from '../types';
|
|
5
|
-
import type { IMultiArvoEventHandler, MultiArvoEventHandlerFunction } from './types';
|
|
6
|
-
/**
|
|
7
|
-
* MultiArvoEventHandler processes multiple event types without being bound to specific contracts.
|
|
8
|
-
* Manages event execution, telemetry tracking, and error handling for diverse event streams.
|
|
9
|
-
*
|
|
10
|
-
* @example
|
|
11
|
-
* const handler = createMultiArvoEventHandler({
|
|
12
|
-
* source: "order.handler",
|
|
13
|
-
* executionunits: 1,
|
|
14
|
-
* handler: async ({ event }) => {
|
|
15
|
-
* // Handle multiple event types
|
|
16
|
-
* }
|
|
17
|
-
* });
|
|
18
|
-
*/
|
|
19
|
-
export default class MultiArvoEventHandler extends AbstractArvoEventHandler {
|
|
20
|
-
/** Computational cost metric for handler operations */
|
|
21
|
-
readonly executionunits: number;
|
|
22
|
-
/** Source identifier for event routing */
|
|
23
|
-
readonly source: string;
|
|
24
|
-
/** OpenTelemetry configuration */
|
|
25
|
-
readonly spanOptions: SpanOptions;
|
|
26
|
-
/** Event processing function */
|
|
27
|
-
readonly handler: MultiArvoEventHandlerFunction;
|
|
28
|
-
/**
|
|
29
|
-
* Creates handler instance with specified configuration.
|
|
30
|
-
* @param param Handler configuration including source and execution parameters
|
|
31
|
-
* @throws When source contains invalid characters
|
|
32
|
-
*/
|
|
33
|
-
constructor(param: IMultiArvoEventHandler);
|
|
34
|
-
/**
|
|
35
|
-
* Processes an event through configured handler function. Creates telemetry span,
|
|
36
|
-
* validates event destination, executes handler, and manages errors.
|
|
37
|
-
*
|
|
38
|
-
* @param event Event to process
|
|
39
|
-
* @param opentelemetry Telemetry context configuration
|
|
40
|
-
* @returns Resulting events or error events
|
|
41
|
-
*
|
|
42
|
-
* @throws {ConfigViolation} When event destination does not match handler source
|
|
43
|
-
* @throws Other Violation error which are thrown by the event handler function
|
|
44
|
-
*/
|
|
45
|
-
execute(event: ArvoEvent, opentelemetry?: ArvoEventHandlerOpenTelemetryOptions): Promise<{
|
|
46
|
-
events: ArvoEvent[];
|
|
47
|
-
}>;
|
|
48
|
-
/**
|
|
49
|
-
* System error schema configuration.
|
|
50
|
-
* Error events follow format: sys.<handler-source>.error
|
|
51
|
-
*/
|
|
52
|
-
get systemErrorSchema(): {
|
|
53
|
-
type: string;
|
|
54
|
-
schema: import("zod").ZodObject<{
|
|
55
|
-
errorName: import("zod").ZodString;
|
|
56
|
-
errorMessage: import("zod").ZodString;
|
|
57
|
-
errorStack: import("zod").ZodNullable<import("zod").ZodString>;
|
|
58
|
-
}, "strip", import("zod").ZodTypeAny, {
|
|
59
|
-
errorName: string;
|
|
60
|
-
errorMessage: string;
|
|
61
|
-
errorStack: string | null;
|
|
62
|
-
}, {
|
|
63
|
-
errorName: string;
|
|
64
|
-
errorMessage: string;
|
|
65
|
-
errorStack: string | null;
|
|
66
|
-
}>;
|
|
67
|
-
};
|
|
68
|
-
}
|