arvo-event-handler 2.2.6 → 2.2.7
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/biome.json +58 -0
- package/dist/AbstractArvoEventHandler/index.d.ts +2 -2
- package/dist/ArvoEventHandler/helpers.d.ts +2 -2
- package/dist/ArvoEventHandler/index.d.ts +68 -31
- package/dist/ArvoEventHandler/index.js +97 -52
- package/dist/ArvoEventHandler/types.d.ts +3 -3
- package/dist/ArvoEventRouter/helpers.d.ts +1 -1
- package/dist/ArvoEventRouter/helpers.js +1 -3
- package/dist/ArvoEventRouter/index.d.ts +5 -5
- package/dist/ArvoEventRouter/index.js +20 -20
- package/dist/ArvoEventRouter/types.d.ts +3 -3
- package/dist/MultiArvoEventHandler/helpers.d.ts +1 -1
- package/dist/MultiArvoEventHandler/helpers.js +3 -1
- package/dist/MultiArvoEventHandler/index.d.ts +4 -4
- package/dist/MultiArvoEventHandler/index.js +12 -12
- package/dist/MultiArvoEventHandler/types.d.ts +2 -2
- package/dist/errors.d.ts +22 -21
- package/dist/errors.js +22 -21
- package/dist/index.d.ts +9 -9
- package/dist/index.js +16 -16
- package/dist/types.d.ts +1 -1
- package/dist/utils.d.ts +5 -5
- package/dist/utils.js +11 -11
- package/package.json +5 -11
package/biome.json
ADDED
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
{
|
|
2
|
+
"$schema": "https://biomejs.dev/schemas/1.9.4/schema.json",
|
|
3
|
+
"vcs": {
|
|
4
|
+
"enabled": false,
|
|
5
|
+
"clientKind": "git",
|
|
6
|
+
"useIgnoreFile": false
|
|
7
|
+
},
|
|
8
|
+
"files": {
|
|
9
|
+
"ignoreUnknown": false,
|
|
10
|
+
"ignore": [
|
|
11
|
+
"**/dist/**",
|
|
12
|
+
"**/node_modules/**",
|
|
13
|
+
"**/.turbo/**",
|
|
14
|
+
"**/coverage/**",
|
|
15
|
+
"**/.github/**",
|
|
16
|
+
"**/docs/**",
|
|
17
|
+
"*.md"
|
|
18
|
+
]
|
|
19
|
+
},
|
|
20
|
+
"formatter": {
|
|
21
|
+
"enabled": true,
|
|
22
|
+
"formatWithErrors": false,
|
|
23
|
+
"ignore": [],
|
|
24
|
+
"attributePosition": "auto",
|
|
25
|
+
"indentStyle": "space",
|
|
26
|
+
"indentWidth": 2,
|
|
27
|
+
"lineWidth": 120,
|
|
28
|
+
"lineEnding": "lf"
|
|
29
|
+
},
|
|
30
|
+
"organizeImports": {
|
|
31
|
+
"enabled": true
|
|
32
|
+
},
|
|
33
|
+
"linter": {
|
|
34
|
+
"enabled": true,
|
|
35
|
+
"rules": {
|
|
36
|
+
"recommended": true,
|
|
37
|
+
"correctness": {
|
|
38
|
+
"noUnusedImports": "warn"
|
|
39
|
+
},
|
|
40
|
+
"suspicious": {
|
|
41
|
+
"noExplicitAny": "off"
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
},
|
|
45
|
+
"javascript": {
|
|
46
|
+
"jsxRuntime": "reactClassic",
|
|
47
|
+
"formatter": {
|
|
48
|
+
"quoteStyle": "single",
|
|
49
|
+
"arrowParentheses": "always",
|
|
50
|
+
"bracketSameLine": false,
|
|
51
|
+
"bracketSpacing": true,
|
|
52
|
+
"jsxQuoteStyle": "single",
|
|
53
|
+
"quoteProperties": "asNeeded",
|
|
54
|
+
"semicolons": "always",
|
|
55
|
+
"trailingCommas": "all"
|
|
56
|
+
}
|
|
57
|
+
}
|
|
58
|
+
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { ArvoContractRecord, ArvoEvent } from 'arvo-core';
|
|
2
|
-
import { ArvoEventHandlerOpenTelemetryOptions } from '../types';
|
|
1
|
+
import type { ArvoContractRecord, ArvoEvent } from 'arvo-core';
|
|
2
|
+
import type { ArvoEventHandlerOpenTelemetryOptions } from '../types';
|
|
3
3
|
/**
|
|
4
4
|
* Abstract base class for Arvo event handlers.
|
|
5
5
|
*
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ArvoContract } from 'arvo-core';
|
|
2
|
-
import { IArvoEventHandler } from './types';
|
|
1
|
+
import type { ArvoContract } from 'arvo-core';
|
|
3
2
|
import ArvoEventHandler from '.';
|
|
3
|
+
import type { IArvoEventHandler } from './types';
|
|
4
4
|
/**
|
|
5
5
|
* Creates an ArvoEventHandler for processing events defined by a specific contract.
|
|
6
6
|
* Each handler manages event validation, processing, and telemetry for its contract.
|
|
@@ -1,17 +1,49 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import { SpanOptions } from '@opentelemetry/api';
|
|
1
|
+
import { type SpanOptions } from '@opentelemetry/api';
|
|
2
|
+
import { type ArvoContract, type ArvoEvent } from 'arvo-core';
|
|
4
3
|
import AbstractArvoEventHandler from '../AbstractArvoEventHandler';
|
|
5
|
-
import { ArvoEventHandlerOpenTelemetryOptions } from '../types';
|
|
4
|
+
import type { ArvoEventHandlerOpenTelemetryOptions } from '../types';
|
|
5
|
+
import type { ArvoEventHandlerFunction, IArvoEventHandler } from './types';
|
|
6
6
|
/**
|
|
7
|
-
* ArvoEventHandler
|
|
8
|
-
*
|
|
9
|
-
* integrating contract validation, telemetry management, and event processing.
|
|
7
|
+
* ArvoEventHandler is the core component for processing events in the Arvo system. It enforces
|
|
8
|
+
* contracts between services by ensuring that all events follow their specified formats and rules.
|
|
10
9
|
*
|
|
11
|
-
* The handler
|
|
12
|
-
*
|
|
13
|
-
*
|
|
14
|
-
*
|
|
10
|
+
* The handler is built on two fundamental patterns: Meyer's Design by Contract and Fowler's
|
|
11
|
+
* Tolerant Reader. It binds to an ArvoContract that defines what events it can receive and send
|
|
12
|
+
* across all versions. This versioning is strict - the handler must implement every version defined
|
|
13
|
+
* in its contract, or it will fail both at compile time and runtime.
|
|
14
|
+
*
|
|
15
|
+
* Following the Tolerant Reader pattern, the handler accepts any incoming event but only processes
|
|
16
|
+
* those that exactly match one of its contract versions. When an event matches, it's handled by
|
|
17
|
+
* the specific implementation for that version. This approach maintains compatibility while
|
|
18
|
+
* ensuring precise contract adherence.
|
|
19
|
+
*
|
|
20
|
+
* The handler uses Zod for validation, automatically checking both incoming and outgoing events.
|
|
21
|
+
* This means it not only verifies data formats but also applies default values where needed and
|
|
22
|
+
* ensures all conditions are met before and after processing.
|
|
23
|
+
*
|
|
24
|
+
* Error handling in the handler divides issues into two categories:
|
|
25
|
+
*
|
|
26
|
+
* - `Violations` are serious contract breaches that indicate fundamental problems with how services
|
|
27
|
+
* are communicating. These errors bubble up to the calling code, allowing developers to handle
|
|
28
|
+
* these critical issues explicitly.
|
|
29
|
+
*
|
|
30
|
+
* - `System Error Events` cover normal runtime errors that occur during event processing. These are
|
|
31
|
+
* typically workflow-related issues that need to be reported back to the event's source but don't
|
|
32
|
+
* indicate a broken contract.
|
|
33
|
+
*
|
|
34
|
+
* * @example
|
|
35
|
+
* const handler = createArvoEventHandler({
|
|
36
|
+
* contract: userContract,
|
|
37
|
+
* executionunits: 1,
|
|
38
|
+
* handler: {
|
|
39
|
+
* '1.0.0': async ({ event }) => {
|
|
40
|
+
* // Process event according to contract v1.0.0
|
|
41
|
+
* },
|
|
42
|
+
* '2.0.0': async ({ event }) => {
|
|
43
|
+
* // Process event according to contract v2.0.0
|
|
44
|
+
* }
|
|
45
|
+
* }
|
|
46
|
+
* });
|
|
15
47
|
*/
|
|
16
48
|
export default class ArvoEventHandler<TContract extends ArvoContract> extends AbstractArvoEventHandler {
|
|
17
49
|
/** Contract instance that defines the event schema and validation rules */
|
|
@@ -36,31 +68,36 @@ export default class ArvoEventHandler<TContract extends ArvoContract> extends Ab
|
|
|
36
68
|
*/
|
|
37
69
|
constructor(param: IArvoEventHandler<TContract>);
|
|
38
70
|
/**
|
|
39
|
-
* Processes an event according to the contract specifications.
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
* Event Routing Logic:
|
|
43
|
-
* - Success events: Routes based on priority (handler result -> redirectto -> source)
|
|
44
|
-
* - Error events: Always routes back to the source
|
|
71
|
+
* Processes an incoming event according to the handler's contract specifications. This method
|
|
72
|
+
* handles the complete lifecycle of event processing including validation, execution, and error
|
|
73
|
+
* handling, while maintaining detailed telemetry through OpenTelemetry.
|
|
45
74
|
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
*
|
|
49
|
-
* -
|
|
75
|
+
* The execution follows a careful sequence to ensure reliability:
|
|
76
|
+
* First, it validates that the event matches the handler's contract type. Then it extracts
|
|
77
|
+
* and validates the event's schema version, defaulting to the latest version if none is specified.
|
|
78
|
+
* After validation passes, it executes the version-specific handler function and processes its
|
|
79
|
+
* output into new events.
|
|
50
80
|
*
|
|
51
|
-
*
|
|
52
|
-
* -
|
|
53
|
-
*
|
|
54
|
-
*
|
|
81
|
+
* The method handles routing through three distinct paths:
|
|
82
|
+
* - For successful execution, events are routed based on handler output or configuration.
|
|
83
|
+
* - The 'to' field in the handler's result (if specified)
|
|
84
|
+
* - The 'redirectto' field from the source event (if present)
|
|
85
|
+
* - Falls back to the source event's 'source' field
|
|
86
|
+
* - For violations (mismatched types, invalid data), errors bubble up to the caller
|
|
87
|
+
* - For runtime errors, system error events are created and sent back to the source
|
|
55
88
|
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* - Ensures proper error event routing
|
|
89
|
+
* Throughout execution, comprehensive telemetry is maintained through OpenTelemetry spans,
|
|
90
|
+
* tracking the complete event journey including validation steps, processing time, and any
|
|
91
|
+
* errors that occur. This enables detailed monitoring and debugging of the event flow.
|
|
60
92
|
*
|
|
61
|
-
* @param event - The event to process
|
|
93
|
+
* @param event - The incoming event to process
|
|
62
94
|
* @param opentelemetry - Configuration for OpenTelemetry context inheritance
|
|
63
|
-
* @returns Promise resolving to array of
|
|
95
|
+
* @returns Promise resolving to an array of output events or error events
|
|
96
|
+
* @throws `ContractViolation` when input or output event data violates the contract
|
|
97
|
+
* @throws `ConfigViolation` when event type doesn't match contract type or the
|
|
98
|
+
* contract version expected by the event does not exist
|
|
99
|
+
* in handler configuration
|
|
100
|
+
* @throws `ExecutionViolation` for explicitly handled runtime errors
|
|
64
101
|
*/
|
|
65
102
|
execute(event: ArvoEvent, opentelemetry?: ArvoEventHandlerOpenTelemetryOptions): Promise<ArvoEvent[]>;
|
|
66
103
|
/**
|
|
@@ -65,20 +65,52 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
65
65
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
66
66
|
};
|
|
67
67
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
68
|
-
var arvo_core_1 = require("arvo-core");
|
|
69
68
|
var api_1 = require("@opentelemetry/api");
|
|
70
|
-
var
|
|
69
|
+
var arvo_core_1 = require("arvo-core");
|
|
71
70
|
var AbstractArvoEventHandler_1 = __importDefault(require("../AbstractArvoEventHandler"));
|
|
72
71
|
var errors_1 = require("../errors");
|
|
72
|
+
var utils_1 = require("../utils");
|
|
73
73
|
/**
|
|
74
|
-
* ArvoEventHandler
|
|
75
|
-
*
|
|
76
|
-
*
|
|
74
|
+
* ArvoEventHandler is the core component for processing events in the Arvo system. It enforces
|
|
75
|
+
* contracts between services by ensuring that all events follow their specified formats and rules.
|
|
76
|
+
*
|
|
77
|
+
* The handler is built on two fundamental patterns: Meyer's Design by Contract and Fowler's
|
|
78
|
+
* Tolerant Reader. It binds to an ArvoContract that defines what events it can receive and send
|
|
79
|
+
* across all versions. This versioning is strict - the handler must implement every version defined
|
|
80
|
+
* in its contract, or it will fail both at compile time and runtime.
|
|
81
|
+
*
|
|
82
|
+
* Following the Tolerant Reader pattern, the handler accepts any incoming event but only processes
|
|
83
|
+
* those that exactly match one of its contract versions. When an event matches, it's handled by
|
|
84
|
+
* the specific implementation for that version. This approach maintains compatibility while
|
|
85
|
+
* ensuring precise contract adherence.
|
|
86
|
+
*
|
|
87
|
+
* The handler uses Zod for validation, automatically checking both incoming and outgoing events.
|
|
88
|
+
* This means it not only verifies data formats but also applies default values where needed and
|
|
89
|
+
* ensures all conditions are met before and after processing.
|
|
90
|
+
*
|
|
91
|
+
* Error handling in the handler divides issues into two categories:
|
|
92
|
+
*
|
|
93
|
+
* - `Violations` are serious contract breaches that indicate fundamental problems with how services
|
|
94
|
+
* are communicating. These errors bubble up to the calling code, allowing developers to handle
|
|
95
|
+
* these critical issues explicitly.
|
|
77
96
|
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
*
|
|
97
|
+
* - `System Error Events` cover normal runtime errors that occur during event processing. These are
|
|
98
|
+
* typically workflow-related issues that need to be reported back to the event's source but don't
|
|
99
|
+
* indicate a broken contract.
|
|
100
|
+
*
|
|
101
|
+
* * @example
|
|
102
|
+
* const handler = createArvoEventHandler({
|
|
103
|
+
* contract: userContract,
|
|
104
|
+
* executionunits: 1,
|
|
105
|
+
* handler: {
|
|
106
|
+
* '1.0.0': async ({ event }) => {
|
|
107
|
+
* // Process event according to contract v1.0.0
|
|
108
|
+
* },
|
|
109
|
+
* '2.0.0': async ({ event }) => {
|
|
110
|
+
* // Process event according to contract v2.0.0
|
|
111
|
+
* }
|
|
112
|
+
* }
|
|
113
|
+
* });
|
|
82
114
|
*/
|
|
83
115
|
var ArvoEventHandler = /** @class */ (function (_super) {
|
|
84
116
|
__extends(ArvoEventHandler, _super);
|
|
@@ -117,31 +149,36 @@ var ArvoEventHandler = /** @class */ (function (_super) {
|
|
|
117
149
|
configurable: true
|
|
118
150
|
});
|
|
119
151
|
/**
|
|
120
|
-
* Processes an event according to the contract specifications.
|
|
121
|
-
*
|
|
122
|
-
*
|
|
123
|
-
* Event Routing Logic:
|
|
124
|
-
* - Success events: Routes based on priority (handler result -> redirectto -> source)
|
|
125
|
-
* - Error events: Always routes back to the source
|
|
152
|
+
* Processes an incoming event according to the handler's contract specifications. This method
|
|
153
|
+
* handles the complete lifecycle of event processing including validation, execution, and error
|
|
154
|
+
* handling, while maintaining detailed telemetry through OpenTelemetry.
|
|
126
155
|
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* -
|
|
156
|
+
* The execution follows a careful sequence to ensure reliability:
|
|
157
|
+
* First, it validates that the event matches the handler's contract type. Then it extracts
|
|
158
|
+
* and validates the event's schema version, defaulting to the latest version if none is specified.
|
|
159
|
+
* After validation passes, it executes the version-specific handler function and processes its
|
|
160
|
+
* output into new events.
|
|
131
161
|
*
|
|
132
|
-
*
|
|
133
|
-
* -
|
|
134
|
-
*
|
|
135
|
-
*
|
|
162
|
+
* The method handles routing through three distinct paths:
|
|
163
|
+
* - For successful execution, events are routed based on handler output or configuration.
|
|
164
|
+
* - The 'to' field in the handler's result (if specified)
|
|
165
|
+
* - The 'redirectto' field from the source event (if present)
|
|
166
|
+
* - Falls back to the source event's 'source' field
|
|
167
|
+
* - For violations (mismatched types, invalid data), errors bubble up to the caller
|
|
168
|
+
* - For runtime errors, system error events are created and sent back to the source
|
|
136
169
|
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
* - Ensures proper error event routing
|
|
170
|
+
* Throughout execution, comprehensive telemetry is maintained through OpenTelemetry spans,
|
|
171
|
+
* tracking the complete event journey including validation steps, processing time, and any
|
|
172
|
+
* errors that occur. This enables detailed monitoring and debugging of the event flow.
|
|
141
173
|
*
|
|
142
|
-
* @param event - The event to process
|
|
174
|
+
* @param event - The incoming event to process
|
|
143
175
|
* @param opentelemetry - Configuration for OpenTelemetry context inheritance
|
|
144
|
-
* @returns Promise resolving to array of
|
|
176
|
+
* @returns Promise resolving to an array of output events or error events
|
|
177
|
+
* @throws `ContractViolation` when input or output event data violates the contract
|
|
178
|
+
* @throws `ConfigViolation` when event type doesn't match contract type or the
|
|
179
|
+
* contract version expected by the event does not exist
|
|
180
|
+
* in handler configuration
|
|
181
|
+
* @throws `ExecutionViolation` for explicitly handled runtime errors
|
|
145
182
|
*/
|
|
146
183
|
ArvoEventHandler.prototype.execute = function (event_1) {
|
|
147
184
|
return __awaiter(this, arguments, void 0, function (event, opentelemetry) {
|
|
@@ -155,39 +192,47 @@ var ArvoEventHandler = /** @class */ (function (_super) {
|
|
|
155
192
|
case 0:
|
|
156
193
|
otelConfig = (0, utils_1.createEventHandlerTelemetryConfig)("ArvoEventHandler<".concat(this.contract.uri, ">"), this.spanOptions, opentelemetry, event);
|
|
157
194
|
return [4 /*yield*/, arvo_core_1.ArvoOpenTelemetry.getInstance().startActiveSpan(__assign(__assign({}, otelConfig), { fn: function (span) { return __awaiter(_this, void 0, void 0, function () {
|
|
158
|
-
var otelSpanHeaders, parsedDataSchema, handlerContract, inputEventValidation, _handleOutput, outputs, eventFactory_1, result, error_1, eventFactory, result;
|
|
159
|
-
var
|
|
160
|
-
return __generator(this, function (
|
|
161
|
-
switch (
|
|
195
|
+
var otelSpanHeaders, _i, _a, _b, key, value, parsedDataSchema, handlerContract, inputEventValidation, _handleOutput, outputs, eventFactory_1, result, error_1, eventFactory, result, _c, _d, _e, key, value;
|
|
196
|
+
var _f, _g, _h, _j;
|
|
197
|
+
return __generator(this, function (_k) {
|
|
198
|
+
switch (_k.label) {
|
|
162
199
|
case 0:
|
|
163
200
|
otelSpanHeaders = (0, arvo_core_1.currentOpenTelemetryHeaders)();
|
|
164
|
-
|
|
201
|
+
_k.label = 1;
|
|
165
202
|
case 1:
|
|
166
|
-
|
|
203
|
+
_k.trys.push([1, 3, 4, 5]);
|
|
167
204
|
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
168
|
-
Object.entries(event.otelAttributes).
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
205
|
+
for (_i = 0, _a = Object.entries(event.otelAttributes); _i < _a.length; _i++) {
|
|
206
|
+
_b = _a[_i], key = _b[0], value = _b[1];
|
|
207
|
+
span.setAttribute("to_process.0.".concat(key), value);
|
|
208
|
+
}
|
|
172
209
|
if (this.contract.type !== event.type) {
|
|
173
|
-
throw new errors_1.
|
|
210
|
+
throw new errors_1.ConfigViolation("Event type mismatch: Received '".concat(event.type, "', expected '").concat(this.contract.type, "'"));
|
|
174
211
|
}
|
|
175
212
|
(0, arvo_core_1.logToSpan)({
|
|
176
213
|
level: 'INFO',
|
|
177
214
|
message: "Event type '".concat(event.type, "' validated against contract '").concat(this.contract.uri, "'"),
|
|
178
215
|
});
|
|
179
216
|
parsedDataSchema = arvo_core_1.EventDataschemaUtil.parse(event);
|
|
180
|
-
|
|
181
|
-
|
|
217
|
+
// If the URI exists but conflicts with the contract's URI
|
|
218
|
+
// Here we are only concerned with the URI bit not the version
|
|
219
|
+
if ((parsedDataSchema === null || parsedDataSchema === void 0 ? void 0 : parsedDataSchema.uri) && (parsedDataSchema === null || parsedDataSchema === void 0 ? void 0 : parsedDataSchema.uri) !== this.contract.uri) {
|
|
182
220
|
throw new errors_1.ContractViolation("Contract URI mismatch: Handler expects '".concat(this.contract.uri, "' but event dataschema specifies '").concat(event.dataschema, "'. Events must reference the same contract URI as their handler."));
|
|
183
221
|
}
|
|
222
|
+
// If the version does not exist then just warn. The latest version will be used in this case
|
|
184
223
|
if (!(parsedDataSchema === null || parsedDataSchema === void 0 ? void 0 : parsedDataSchema.version)) {
|
|
185
224
|
(0, arvo_core_1.logToSpan)({
|
|
186
225
|
level: 'WARNING',
|
|
187
226
|
message: "Version resolution failed for event with dataschema '".concat(event.dataschema, "'. Defaulting to latest version (=").concat(this.contract.version('latest').version, ") of contract (uri=").concat(this.contract.uri, ")"),
|
|
188
227
|
});
|
|
189
228
|
}
|
|
190
|
-
handlerContract =
|
|
229
|
+
handlerContract = void 0;
|
|
230
|
+
try {
|
|
231
|
+
handlerContract = this.contract.version((_f = parsedDataSchema === null || parsedDataSchema === void 0 ? void 0 : parsedDataSchema.version) !== null && _f !== void 0 ? _f : 'latest');
|
|
232
|
+
}
|
|
233
|
+
catch (error) {
|
|
234
|
+
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(', ')));
|
|
235
|
+
}
|
|
191
236
|
(0, arvo_core_1.logToSpan)({
|
|
192
237
|
level: 'INFO',
|
|
193
238
|
message: "Processing event with contract version ".concat(handlerContract.version),
|
|
@@ -210,7 +255,7 @@ var ArvoEventHandler = /** @class */ (function (_super) {
|
|
|
210
255
|
span: span,
|
|
211
256
|
})];
|
|
212
257
|
case 2:
|
|
213
|
-
_handleOutput =
|
|
258
|
+
_handleOutput = _k.sent();
|
|
214
259
|
if (!_handleOutput)
|
|
215
260
|
return [2 /*return*/, []];
|
|
216
261
|
outputs = [];
|
|
@@ -239,7 +284,7 @@ var ArvoEventHandler = /** @class */ (function (_super) {
|
|
|
239
284
|
});
|
|
240
285
|
return [2 /*return*/, result];
|
|
241
286
|
case 3:
|
|
242
|
-
error_1 =
|
|
287
|
+
error_1 = _k.sent();
|
|
243
288
|
(0, arvo_core_1.exceptionToSpan)(error_1);
|
|
244
289
|
span.setStatus({
|
|
245
290
|
code: api_1.SpanStatusCode.ERROR,
|
|
@@ -257,14 +302,14 @@ var ArvoEventHandler = /** @class */ (function (_super) {
|
|
|
257
302
|
to: event.source,
|
|
258
303
|
error: error_1,
|
|
259
304
|
executionunits: this.executionunits,
|
|
260
|
-
traceparent: (
|
|
261
|
-
tracestate: (
|
|
262
|
-
accesscontrol: (
|
|
305
|
+
traceparent: (_g = otelSpanHeaders.traceparent) !== null && _g !== void 0 ? _g : undefined,
|
|
306
|
+
tracestate: (_h = otelSpanHeaders.tracestate) !== null && _h !== void 0 ? _h : undefined,
|
|
307
|
+
accesscontrol: (_j = event.accesscontrol) !== null && _j !== void 0 ? _j : undefined,
|
|
263
308
|
}, {});
|
|
264
|
-
Object.entries(result.otelAttributes).
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
}
|
|
309
|
+
for (_c = 0, _d = Object.entries(result.otelAttributes); _c < _d.length; _c++) {
|
|
310
|
+
_e = _d[_c], key = _e[0], value = _e[1];
|
|
311
|
+
span.setAttribute("to_emit.0.".concat(key), value);
|
|
312
|
+
}
|
|
268
313
|
return [2 /*return*/, [result]];
|
|
269
314
|
case 4:
|
|
270
315
|
span.end();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { Span, SpanOptions } from '@opentelemetry/api';
|
|
2
|
-
import { ArvoContract, ArvoEvent, CreateArvoEvent, VersionedArvoContract
|
|
3
|
-
import { z } from 'zod';
|
|
1
|
+
import type { Span, SpanOptions } from '@opentelemetry/api';
|
|
2
|
+
import type { ArvoContract, ArvoEvent, ArvoSemanticVersion, CreateArvoEvent, VersionedArvoContract } from 'arvo-core';
|
|
3
|
+
import type { z } from 'zod';
|
|
4
4
|
/**
|
|
5
5
|
* Represents the input for an ArvoEvent handler function.
|
|
6
6
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { ArvoEventRouter } from '.';
|
|
2
|
-
import { IArvoEventRouter } from './types';
|
|
2
|
+
import type { IArvoEventRouter } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Creates a new ArvoEventRouter instance with the provided configuration.
|
|
5
5
|
* Validates source format and ensures unique handlers per event type.
|
|
@@ -18,7 +18,5 @@ var _1 = require(".");
|
|
|
18
18
|
* executionunits: 10
|
|
19
19
|
* });
|
|
20
20
|
*/
|
|
21
|
-
var createArvoEventRouter = function (param) {
|
|
22
|
-
return new _1.ArvoEventRouter(param);
|
|
23
|
-
};
|
|
21
|
+
var createArvoEventRouter = function (param) { return new _1.ArvoEventRouter(param); };
|
|
24
22
|
exports.createArvoEventRouter = createArvoEventRouter;
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import { IArvoEventRouter } from './types';
|
|
4
|
-
import { SpanOptions } from '@opentelemetry/api';
|
|
1
|
+
import { type SpanOptions } from '@opentelemetry/api';
|
|
2
|
+
import { type ArvoContract, ArvoEvent } from 'arvo-core';
|
|
5
3
|
import AbstractArvoEventHandler from '../AbstractArvoEventHandler';
|
|
6
|
-
import
|
|
4
|
+
import type ArvoEventHandler from '../ArvoEventHandler';
|
|
5
|
+
import type { ArvoEventHandlerOpenTelemetryOptions } from '../types';
|
|
6
|
+
import type { IArvoEventRouter } from './types';
|
|
7
7
|
/**
|
|
8
8
|
* ArvoEventRouter manages event routing and execution within the Arvo event system. It directs
|
|
9
9
|
* incoming events to appropriate handlers based on event type while maintaining telemetry
|
|
@@ -66,12 +66,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
66
66
|
};
|
|
67
67
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
68
68
|
exports.ArvoEventRouter = void 0;
|
|
69
|
-
var arvo_core_1 = require("arvo-core");
|
|
70
|
-
var utils_1 = require("../utils");
|
|
71
69
|
var api_1 = require("@opentelemetry/api");
|
|
72
|
-
var
|
|
70
|
+
var arvo_core_1 = require("arvo-core");
|
|
73
71
|
var AbstractArvoEventHandler_1 = __importDefault(require("../AbstractArvoEventHandler"));
|
|
74
72
|
var errors_1 = require("../errors");
|
|
73
|
+
var utils_1 = require("../utils");
|
|
74
|
+
var utils_2 = require("./utils");
|
|
75
75
|
/**
|
|
76
76
|
* ArvoEventRouter manages event routing and execution within the Arvo event system. It directs
|
|
77
77
|
* incoming events to appropriate handlers based on event type while maintaining telemetry
|
|
@@ -162,21 +162,21 @@ var ArvoEventRouter = /** @class */ (function (_super) {
|
|
|
162
162
|
context: api_1.context.active(),
|
|
163
163
|
},
|
|
164
164
|
fn: function (span) { return __awaiter(_this, void 0, void 0, function () {
|
|
165
|
-
var otelSpanHeaders, newEvent, results, resultingEvents, error_1;
|
|
165
|
+
var otelSpanHeaders, newEvent, _i, _a, _b, key, value, results, resultingEvents, index, _c, _d, _e, key, value, error_1;
|
|
166
166
|
var _this = this;
|
|
167
|
-
return __generator(this, function (
|
|
168
|
-
switch (
|
|
167
|
+
return __generator(this, function (_f) {
|
|
168
|
+
switch (_f.label) {
|
|
169
169
|
case 0:
|
|
170
170
|
otelSpanHeaders = (0, arvo_core_1.currentOpenTelemetryHeaders)();
|
|
171
171
|
newEvent = (0, utils_2.deleteOtelHeaders)(event);
|
|
172
|
-
|
|
172
|
+
_f.label = 1;
|
|
173
173
|
case 1:
|
|
174
|
-
|
|
174
|
+
_f.trys.push([1, 3, 4, 5]);
|
|
175
175
|
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
176
|
-
Object.entries(event.otelAttributes).
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
}
|
|
176
|
+
for (_i = 0, _a = Object.entries(event.otelAttributes); _i < _a.length; _i++) {
|
|
177
|
+
_b = _a[_i], key = _b[0], value = _b[1];
|
|
178
|
+
span.setAttribute("to_process.0.".concat(key), value);
|
|
179
|
+
}
|
|
180
180
|
(0, arvo_core_1.logToSpan)({
|
|
181
181
|
level: 'INFO',
|
|
182
182
|
message: "Initiating event resolution - Type: ".concat(newEvent.type, ", Source: ").concat(newEvent.source, ", Destination: ").concat(newEvent.to),
|
|
@@ -196,7 +196,7 @@ var ArvoEventRouter = /** @class */ (function (_super) {
|
|
|
196
196
|
inheritFrom: 'CONTEXT',
|
|
197
197
|
})];
|
|
198
198
|
case 2:
|
|
199
|
-
results =
|
|
199
|
+
results = _f.sent();
|
|
200
200
|
resultingEvents = results.map(function (event) {
|
|
201
201
|
var _a;
|
|
202
202
|
return new arvo_core_1.ArvoEvent({
|
|
@@ -220,15 +220,15 @@ var ArvoEventRouter = /** @class */ (function (_super) {
|
|
|
220
220
|
level: 'INFO',
|
|
221
221
|
message: "Event processing completed successfully - Generated ".concat(resultingEvents.length, " new event(s)"),
|
|
222
222
|
});
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
}
|
|
228
|
-
}
|
|
223
|
+
for (index = 0; index < resultingEvents.length; index++) {
|
|
224
|
+
for (_c = 0, _d = Object.entries(resultingEvents[index].otelAttributes); _c < _d.length; _c++) {
|
|
225
|
+
_e = _d[_c], key = _e[0], value = _e[1];
|
|
226
|
+
span.setAttribute("to_emit.".concat(index, ".").concat(key), value);
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
229
|
return [2 /*return*/, resultingEvents];
|
|
230
230
|
case 3:
|
|
231
|
-
error_1 =
|
|
231
|
+
error_1 = _f.sent();
|
|
232
232
|
return [2 /*return*/, (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); })];
|
|
233
233
|
case 4:
|
|
234
234
|
span.end();
|
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import
|
|
3
|
-
import
|
|
1
|
+
import type { SpanOptions } from '@opentelemetry/api';
|
|
2
|
+
import type { ArvoContract } from 'arvo-core';
|
|
3
|
+
import type ArvoEventHandler from '../ArvoEventHandler';
|
|
4
4
|
/**
|
|
5
5
|
* Interface for defining an Arvo Event Router.
|
|
6
6
|
*/
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import MultiArvoEventHandler from '.';
|
|
2
|
-
import { IMultiArvoEventHandler } from './types';
|
|
2
|
+
import type { IMultiArvoEventHandler } from './types';
|
|
3
3
|
/**
|
|
4
4
|
* Creates a MultiArvoEventHandler instance capable of handling multiple event types across different ArvoContracts.
|
|
5
5
|
*
|
|
@@ -50,5 +50,7 @@ var _1 = __importDefault(require("."));
|
|
|
50
50
|
* @see {@link IMultiArvoEventHandler} for the full configuration options
|
|
51
51
|
* @see {@link MultiArvoEventHandler} for the handler class implementation
|
|
52
52
|
*/
|
|
53
|
-
var createMultiArvoEventHandler = function (param) {
|
|
53
|
+
var createMultiArvoEventHandler = function (param) {
|
|
54
|
+
return new _1.default(param);
|
|
55
|
+
};
|
|
54
56
|
exports.createMultiArvoEventHandler = createMultiArvoEventHandler;
|
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import { SpanOptions } from '@opentelemetry/api';
|
|
2
|
-
import { ArvoEvent } from 'arvo-core';
|
|
3
|
-
import { IMultiArvoEventHandler, MultiArvoEventHandlerFunction } from './types';
|
|
1
|
+
import { type SpanOptions } from '@opentelemetry/api';
|
|
2
|
+
import { type ArvoEvent } from 'arvo-core';
|
|
4
3
|
import AbstractArvoEventHandler from '../AbstractArvoEventHandler';
|
|
5
|
-
import { ArvoEventHandlerOpenTelemetryOptions } from '../types';
|
|
4
|
+
import type { ArvoEventHandlerOpenTelemetryOptions } from '../types';
|
|
5
|
+
import type { IMultiArvoEventHandler, MultiArvoEventHandlerFunction } from './types';
|
|
6
6
|
/**
|
|
7
7
|
* MultiArvoEventHandler processes multiple event types without being bound to specific contracts.
|
|
8
8
|
* Manages event execution, telemetry tracking, and error handling for diverse event streams.
|
|
@@ -67,9 +67,9 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
67
67
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
68
68
|
var api_1 = require("@opentelemetry/api");
|
|
69
69
|
var arvo_core_1 = require("arvo-core");
|
|
70
|
-
var utils_1 = require("../utils");
|
|
71
70
|
var AbstractArvoEventHandler_1 = __importDefault(require("../AbstractArvoEventHandler"));
|
|
72
71
|
var errors_1 = require("../errors");
|
|
72
|
+
var utils_1 = require("../utils");
|
|
73
73
|
/**
|
|
74
74
|
* MultiArvoEventHandler processes multiple event types without being bound to specific contracts.
|
|
75
75
|
* Manages event execution, telemetry tracking, and error handling for diverse event streams.
|
|
@@ -123,19 +123,19 @@ var MultiArvoEventHandler = /** @class */ (function (_super) {
|
|
|
123
123
|
case 0:
|
|
124
124
|
otelConfig = (0, utils_1.createEventHandlerTelemetryConfig)('MutliArvoEventHandler', this.spanOptions, opentelemetry, event);
|
|
125
125
|
return [4 /*yield*/, arvo_core_1.ArvoOpenTelemetry.getInstance().startActiveSpan(__assign(__assign({}, otelConfig), { fn: function (span) { return __awaiter(_this, void 0, void 0, function () {
|
|
126
|
-
var otelSpanHeaders, _handlerOutput, outputs, resultingEvents, error_1;
|
|
127
|
-
return __generator(this, function (
|
|
128
|
-
switch (
|
|
126
|
+
var otelSpanHeaders, _i, _a, _b, key, value, _handlerOutput, outputs, resultingEvents, error_1;
|
|
127
|
+
return __generator(this, function (_c) {
|
|
128
|
+
switch (_c.label) {
|
|
129
129
|
case 0:
|
|
130
130
|
otelSpanHeaders = (0, arvo_core_1.currentOpenTelemetryHeaders)();
|
|
131
|
-
|
|
131
|
+
_c.label = 1;
|
|
132
132
|
case 1:
|
|
133
|
-
|
|
133
|
+
_c.trys.push([1, 3, 4, 5]);
|
|
134
134
|
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
135
|
-
Object.entries(event.otelAttributes).
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
}
|
|
135
|
+
for (_i = 0, _a = Object.entries(event.otelAttributes); _i < _a.length; _i++) {
|
|
136
|
+
_b = _a[_i], key = _b[0], value = _b[1];
|
|
137
|
+
span.setAttribute("to_process.0.".concat(key), value);
|
|
138
|
+
}
|
|
139
139
|
(0, arvo_core_1.logToSpan)({
|
|
140
140
|
level: 'INFO',
|
|
141
141
|
message: "Initiating event resolution - Type: ".concat(event.type, ", Source: ").concat(event.source, ", Destination: ").concat(event.to),
|
|
@@ -149,7 +149,7 @@ var MultiArvoEventHandler = /** @class */ (function (_super) {
|
|
|
149
149
|
span: span,
|
|
150
150
|
})];
|
|
151
151
|
case 2:
|
|
152
|
-
_handlerOutput =
|
|
152
|
+
_handlerOutput = _c.sent();
|
|
153
153
|
if (!_handlerOutput)
|
|
154
154
|
return [2 /*return*/, []];
|
|
155
155
|
outputs = [];
|
|
@@ -166,7 +166,7 @@ var MultiArvoEventHandler = /** @class */ (function (_super) {
|
|
|
166
166
|
});
|
|
167
167
|
return [2 /*return*/, resultingEvents];
|
|
168
168
|
case 3:
|
|
169
|
-
error_1 =
|
|
169
|
+
error_1 = _c.sent();
|
|
170
170
|
return [2 /*return*/, (0, utils_1.handleArvoEventHandlerCommonError)(error_1, otelSpanHeaders, "sys.".concat(this.source, ".error"), this.source, event, this.executionunits, function (param, extensions) { return (0, arvo_core_1.createArvoEvent)(param, extensions); })];
|
|
171
171
|
case 4:
|
|
172
172
|
span.end();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { Span, SpanOptions } from '@opentelemetry/api';
|
|
2
|
-
import { ArvoEvent, CreateArvoEvent } from 'arvo-core';
|
|
1
|
+
import type { Span, SpanOptions } from '@opentelemetry/api';
|
|
2
|
+
import type { ArvoEvent, CreateArvoEvent } from 'arvo-core';
|
|
3
3
|
/**
|
|
4
4
|
* Represents the input for a Multi ArvoEvent handler function.
|
|
5
5
|
*/
|
package/dist/errors.d.ts
CHANGED
|
@@ -1,37 +1,38 @@
|
|
|
1
1
|
import { ViolationError } from 'arvo-core';
|
|
2
2
|
/**
|
|
3
|
-
*
|
|
4
|
-
*
|
|
3
|
+
* ContractViolation indicates a critical mismatch between services where event data
|
|
4
|
+
* violates the receiving handler's contract. This represents a serious system issue
|
|
5
|
+
* where services are out of sync with their contracts. Common causes include:
|
|
6
|
+
* - Upstream services sending malformed data
|
|
7
|
+
* - Breaking changes in contracts without proper version management
|
|
8
|
+
* - Implicit assumptions in handlers not covered by contracts
|
|
9
|
+
*
|
|
10
|
+
* Requires explicit handling as it signals potential system-wide contract violations.
|
|
5
11
|
*/
|
|
6
12
|
export declare class ContractViolation extends ViolationError<'Contract'> {
|
|
7
13
|
constructor(message: string, metadata?: Record<string, any>);
|
|
8
14
|
}
|
|
9
15
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
16
|
+
* ConfigViolation indicates system configuration or routing issues where events
|
|
17
|
+
* are mismatched with their handlers. This occurs separately from contract
|
|
18
|
+
* violations and represents problems with the system topology itself, such as:
|
|
19
|
+
* - Events sent to handlers not configured to process them
|
|
20
|
+
* - Mismatched event types not covered by handler contracts
|
|
21
|
+
* - Configuration conflicts between services
|
|
22
|
+
*
|
|
23
|
+
* Requires explicit resolution as it indicates fundamental routing or setup issues.
|
|
13
24
|
*/
|
|
14
25
|
export declare class ConfigViolation extends ViolationError<'Config'> {
|
|
15
26
|
constructor(message: string, metadata?: Record<string, any>);
|
|
16
27
|
}
|
|
17
28
|
/**
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* of an Arvo event handler. Otherwise, the the error throw during exection are
|
|
22
|
-
* converted to system error event and require to be handled by the workflow
|
|
23
|
-
* orchestration.
|
|
29
|
+
* ExecutionViolation represents runtime failures requiring explicit intervention
|
|
30
|
+
* outside normal error flow. Unlike regular errors that convert to system error
|
|
31
|
+
* events, these violations demand special handling at the handler's .execute level.
|
|
24
32
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* 'API rate limit exceeded',
|
|
29
|
-
* {
|
|
30
|
-
* rateLimitRemaining: 0,
|
|
31
|
-
* resetAfterSeconds: 60
|
|
32
|
-
* }
|
|
33
|
-
* );
|
|
34
|
-
* ```
|
|
33
|
+
* Use sparingly - most runtime errors should flow through standard system error
|
|
34
|
+
* events. Reserve ExecutionViolation for cases requiring custom error handling
|
|
35
|
+
* logic that can't be managed through normal event patterns.
|
|
35
36
|
*/
|
|
36
37
|
export declare class ExecutionViolation extends ViolationError<'Execution'> {
|
|
37
38
|
constructor(message: string, metadata?: Record<string, any>);
|
package/dist/errors.js
CHANGED
|
@@ -18,8 +18,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
18
18
|
exports.ExecutionViolation = exports.ConfigViolation = exports.ContractViolation = void 0;
|
|
19
19
|
var arvo_core_1 = require("arvo-core");
|
|
20
20
|
/**
|
|
21
|
-
*
|
|
22
|
-
*
|
|
21
|
+
* ContractViolation indicates a critical mismatch between services where event data
|
|
22
|
+
* violates the receiving handler's contract. This represents a serious system issue
|
|
23
|
+
* where services are out of sync with their contracts. Common causes include:
|
|
24
|
+
* - Upstream services sending malformed data
|
|
25
|
+
* - Breaking changes in contracts without proper version management
|
|
26
|
+
* - Implicit assumptions in handlers not covered by contracts
|
|
27
|
+
*
|
|
28
|
+
* Requires explicit handling as it signals potential system-wide contract violations.
|
|
23
29
|
*/
|
|
24
30
|
var ContractViolation = /** @class */ (function (_super) {
|
|
25
31
|
__extends(ContractViolation, _super);
|
|
@@ -34,9 +40,14 @@ var ContractViolation = /** @class */ (function (_super) {
|
|
|
34
40
|
}(arvo_core_1.ViolationError));
|
|
35
41
|
exports.ContractViolation = ContractViolation;
|
|
36
42
|
/**
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
43
|
+
* ConfigViolation indicates system configuration or routing issues where events
|
|
44
|
+
* are mismatched with their handlers. This occurs separately from contract
|
|
45
|
+
* violations and represents problems with the system topology itself, such as:
|
|
46
|
+
* - Events sent to handlers not configured to process them
|
|
47
|
+
* - Mismatched event types not covered by handler contracts
|
|
48
|
+
* - Configuration conflicts between services
|
|
49
|
+
*
|
|
50
|
+
* Requires explicit resolution as it indicates fundamental routing or setup issues.
|
|
40
51
|
*/
|
|
41
52
|
var ConfigViolation = /** @class */ (function (_super) {
|
|
42
53
|
__extends(ConfigViolation, _super);
|
|
@@ -51,23 +62,13 @@ var ConfigViolation = /** @class */ (function (_super) {
|
|
|
51
62
|
}(arvo_core_1.ViolationError));
|
|
52
63
|
exports.ConfigViolation = ConfigViolation;
|
|
53
64
|
/**
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
* of an Arvo event handler. Otherwise, the the error throw during exection are
|
|
58
|
-
* converted to system error event and require to be handled by the workflow
|
|
59
|
-
* orchestration.
|
|
65
|
+
* ExecutionViolation represents runtime failures requiring explicit intervention
|
|
66
|
+
* outside normal error flow. Unlike regular errors that convert to system error
|
|
67
|
+
* events, these violations demand special handling at the handler's .execute level.
|
|
60
68
|
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* 'API rate limit exceeded',
|
|
65
|
-
* {
|
|
66
|
-
* rateLimitRemaining: 0,
|
|
67
|
-
* resetAfterSeconds: 60
|
|
68
|
-
* }
|
|
69
|
-
* );
|
|
70
|
-
* ```
|
|
69
|
+
* Use sparingly - most runtime errors should flow through standard system error
|
|
70
|
+
* events. Reserve ExecutionViolation for cases requiring custom error handling
|
|
71
|
+
* logic that can't be managed through normal event patterns.
|
|
71
72
|
*/
|
|
72
73
|
var ExecutionViolation = /** @class */ (function (_super) {
|
|
73
74
|
__extends(ExecutionViolation, _super);
|
package/dist/index.d.ts
CHANGED
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import AbstractArvoEventHandler from './AbstractArvoEventHandler';
|
|
1
2
|
import ArvoEventHandler from './ArvoEventHandler';
|
|
2
|
-
import { ArvoEventHandlerFunctionInput, ArvoEventHandlerFunctionOutput, ArvoEventHandlerFunction, IArvoEventHandler } from './ArvoEventHandler/types';
|
|
3
3
|
import { createArvoEventHandler } from './ArvoEventHandler/helpers';
|
|
4
|
-
import {
|
|
5
|
-
import MultiArvoEventHandler from './MultiArvoEventHandler';
|
|
6
|
-
import { MultiArvoEventHandlerFunctionInput, MultiArvoEventHandlerFunctionOutput, MultiArvoEventHandlerFunction, IMultiArvoEventHandler } from './MultiArvoEventHandler/types';
|
|
7
|
-
import { createMultiArvoEventHandler } from './MultiArvoEventHandler/helpers';
|
|
8
|
-
import { isNullOrUndefined, getValueOrDefault, coalesce, coalesceOrDefault } from './utils';
|
|
9
|
-
import { IArvoEventRouter } from './ArvoEventRouter/types';
|
|
4
|
+
import { ArvoEventHandlerFunction, ArvoEventHandlerFunctionInput, ArvoEventHandlerFunctionOutput, IArvoEventHandler } from './ArvoEventHandler/types';
|
|
10
5
|
import { ArvoEventRouter } from './ArvoEventRouter';
|
|
11
6
|
import { createArvoEventRouter } from './ArvoEventRouter/helpers';
|
|
12
|
-
import
|
|
7
|
+
import { IArvoEventRouter } from './ArvoEventRouter/types';
|
|
13
8
|
import { deleteOtelHeaders } from './ArvoEventRouter/utils';
|
|
14
|
-
import
|
|
9
|
+
import MultiArvoEventHandler from './MultiArvoEventHandler';
|
|
10
|
+
import { createMultiArvoEventHandler } from './MultiArvoEventHandler/helpers';
|
|
11
|
+
import { IMultiArvoEventHandler, MultiArvoEventHandlerFunction, MultiArvoEventHandlerFunctionInput, MultiArvoEventHandlerFunctionOutput } from './MultiArvoEventHandler/types';
|
|
12
|
+
import { ConfigViolation, ContractViolation, ExecutionViolation } from './errors';
|
|
13
|
+
import { ArvoEventHandlerOpenTelemetryOptions, EventHandlerFactory, PartialExcept } from './types';
|
|
14
|
+
import { coalesce, coalesceOrDefault, getValueOrDefault, isNullOrUndefined } from './utils';
|
|
15
15
|
export { ArvoEventHandler, createArvoEventHandler, IArvoEventHandler, ArvoEventHandlerFunctionOutput, ArvoEventHandlerFunctionInput, ArvoEventHandlerFunction, PartialExcept, MultiArvoEventHandler, MultiArvoEventHandlerFunctionInput, MultiArvoEventHandlerFunctionOutput, MultiArvoEventHandlerFunction, IMultiArvoEventHandler, createMultiArvoEventHandler, isNullOrUndefined, getValueOrDefault, coalesce, coalesceOrDefault, IArvoEventRouter, ArvoEventRouter, createArvoEventRouter, AbstractArvoEventHandler, deleteOtelHeaders, ArvoEventHandlerOpenTelemetryOptions, EventHandlerFactory, ContractViolation, ConfigViolation, ExecutionViolation, };
|
package/dist/index.js
CHANGED
|
@@ -4,28 +4,28 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
6
|
exports.ExecutionViolation = exports.ConfigViolation = exports.ContractViolation = exports.deleteOtelHeaders = exports.AbstractArvoEventHandler = exports.createArvoEventRouter = exports.ArvoEventRouter = exports.coalesceOrDefault = exports.coalesce = exports.getValueOrDefault = exports.isNullOrUndefined = exports.createMultiArvoEventHandler = exports.MultiArvoEventHandler = exports.createArvoEventHandler = exports.ArvoEventHandler = void 0;
|
|
7
|
+
var AbstractArvoEventHandler_1 = __importDefault(require("./AbstractArvoEventHandler"));
|
|
8
|
+
exports.AbstractArvoEventHandler = AbstractArvoEventHandler_1.default;
|
|
7
9
|
var ArvoEventHandler_1 = __importDefault(require("./ArvoEventHandler"));
|
|
8
10
|
exports.ArvoEventHandler = ArvoEventHandler_1.default;
|
|
9
11
|
var helpers_1 = require("./ArvoEventHandler/helpers");
|
|
10
12
|
Object.defineProperty(exports, "createArvoEventHandler", { enumerable: true, get: function () { return helpers_1.createArvoEventHandler; } });
|
|
11
|
-
var MultiArvoEventHandler_1 = __importDefault(require("./MultiArvoEventHandler"));
|
|
12
|
-
exports.MultiArvoEventHandler = MultiArvoEventHandler_1.default;
|
|
13
|
-
var helpers_2 = require("./MultiArvoEventHandler/helpers");
|
|
14
|
-
Object.defineProperty(exports, "createMultiArvoEventHandler", { enumerable: true, get: function () { return helpers_2.createMultiArvoEventHandler; } });
|
|
15
|
-
var utils_1 = require("./utils");
|
|
16
|
-
Object.defineProperty(exports, "isNullOrUndefined", { enumerable: true, get: function () { return utils_1.isNullOrUndefined; } });
|
|
17
|
-
Object.defineProperty(exports, "getValueOrDefault", { enumerable: true, get: function () { return utils_1.getValueOrDefault; } });
|
|
18
|
-
Object.defineProperty(exports, "coalesce", { enumerable: true, get: function () { return utils_1.coalesce; } });
|
|
19
|
-
Object.defineProperty(exports, "coalesceOrDefault", { enumerable: true, get: function () { return utils_1.coalesceOrDefault; } });
|
|
20
13
|
var ArvoEventRouter_1 = require("./ArvoEventRouter");
|
|
21
14
|
Object.defineProperty(exports, "ArvoEventRouter", { enumerable: true, get: function () { return ArvoEventRouter_1.ArvoEventRouter; } });
|
|
22
|
-
var
|
|
23
|
-
Object.defineProperty(exports, "createArvoEventRouter", { enumerable: true, get: function () { return
|
|
24
|
-
var
|
|
25
|
-
exports
|
|
26
|
-
var
|
|
27
|
-
|
|
15
|
+
var helpers_2 = require("./ArvoEventRouter/helpers");
|
|
16
|
+
Object.defineProperty(exports, "createArvoEventRouter", { enumerable: true, get: function () { return helpers_2.createArvoEventRouter; } });
|
|
17
|
+
var utils_1 = require("./ArvoEventRouter/utils");
|
|
18
|
+
Object.defineProperty(exports, "deleteOtelHeaders", { enumerable: true, get: function () { return utils_1.deleteOtelHeaders; } });
|
|
19
|
+
var MultiArvoEventHandler_1 = __importDefault(require("./MultiArvoEventHandler"));
|
|
20
|
+
exports.MultiArvoEventHandler = MultiArvoEventHandler_1.default;
|
|
21
|
+
var helpers_3 = require("./MultiArvoEventHandler/helpers");
|
|
22
|
+
Object.defineProperty(exports, "createMultiArvoEventHandler", { enumerable: true, get: function () { return helpers_3.createMultiArvoEventHandler; } });
|
|
28
23
|
var errors_1 = require("./errors");
|
|
29
|
-
Object.defineProperty(exports, "ContractViolation", { enumerable: true, get: function () { return errors_1.ContractViolation; } });
|
|
30
24
|
Object.defineProperty(exports, "ConfigViolation", { enumerable: true, get: function () { return errors_1.ConfigViolation; } });
|
|
25
|
+
Object.defineProperty(exports, "ContractViolation", { enumerable: true, get: function () { return errors_1.ContractViolation; } });
|
|
31
26
|
Object.defineProperty(exports, "ExecutionViolation", { enumerable: true, get: function () { return errors_1.ExecutionViolation; } });
|
|
27
|
+
var utils_2 = require("./utils");
|
|
28
|
+
Object.defineProperty(exports, "coalesce", { enumerable: true, get: function () { return utils_2.coalesce; } });
|
|
29
|
+
Object.defineProperty(exports, "coalesceOrDefault", { enumerable: true, get: function () { return utils_2.coalesceOrDefault; } });
|
|
30
|
+
Object.defineProperty(exports, "getValueOrDefault", { enumerable: true, get: function () { return utils_2.getValueOrDefault; } });
|
|
31
|
+
Object.defineProperty(exports, "isNullOrUndefined", { enumerable: true, get: function () { return utils_2.isNullOrUndefined; } });
|
package/dist/types.d.ts
CHANGED
package/dist/utils.d.ts
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
5
|
-
import { ArvoEventHandlerOpenTelemetryOptions } from './types';
|
|
1
|
+
import { type SpanOptions } from '@opentelemetry/api';
|
|
2
|
+
import { type ArvoEvent, type CreateArvoEvent, type OpenTelemetryHeaders } from 'arvo-core';
|
|
3
|
+
import type { ArvoEventHandlerFunctionOutput } from './ArvoEventHandler/types';
|
|
4
|
+
import type { MultiArvoEventHandlerFunctionOutput } from './MultiArvoEventHandler/types';
|
|
5
|
+
import type { ArvoEventHandlerOpenTelemetryOptions } from './types';
|
|
6
6
|
/**
|
|
7
7
|
* Checks if the item is null or undefined.
|
|
8
8
|
*
|
package/dist/utils.js
CHANGED
|
@@ -28,8 +28,8 @@ exports.getValueOrDefault = getValueOrDefault;
|
|
|
28
28
|
exports.coalesce = coalesce;
|
|
29
29
|
exports.coalesceOrDefault = coalesceOrDefault;
|
|
30
30
|
exports.isLowerAlphanumeric = isLowerAlphanumeric;
|
|
31
|
-
var arvo_core_1 = require("arvo-core");
|
|
32
31
|
var api_1 = require("@opentelemetry/api");
|
|
32
|
+
var arvo_core_1 = require("arvo-core");
|
|
33
33
|
/**
|
|
34
34
|
* Checks if the item is null or undefined.
|
|
35
35
|
*
|
|
@@ -111,11 +111,11 @@ var eventHandlerOutputEventCreator = function (events, otelSpanHeaders, source,
|
|
|
111
111
|
// prioritise returned 'to', 'redirectto' and then
|
|
112
112
|
// 'source'
|
|
113
113
|
to: coalesceOrDefault([handlerResult.to, originalEvent.redirectto], originalEvent.source), executionunits: coalesce(handlerResult.executionunits, handlerExectionUnits), accesscontrol: (_b = (_a = handlerResult.accesscontrol) !== null && _a !== void 0 ? _a : originalEvent.accesscontrol) !== null && _b !== void 0 ? _b : undefined }), __extensions);
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
var key =
|
|
117
|
-
|
|
118
|
-
}
|
|
114
|
+
var activeSpan = api_1.trace.getActiveSpan();
|
|
115
|
+
for (var _i = 0, _c = Object.entries(result.otelAttributes); _i < _c.length; _i++) {
|
|
116
|
+
var _d = _c[_i], key = _d[0], value = _d[1];
|
|
117
|
+
activeSpan === null || activeSpan === void 0 ? void 0 : activeSpan.setAttribute("to_emit.".concat(index, ".").concat(key), value);
|
|
118
|
+
}
|
|
119
119
|
return result;
|
|
120
120
|
});
|
|
121
121
|
};
|
|
@@ -145,11 +145,11 @@ var handleArvoEventHandlerCommonError = function (error, otelSpanHeaders, type,
|
|
|
145
145
|
},
|
|
146
146
|
accesscontrol: (_e = originalEvent.accesscontrol) !== null && _e !== void 0 ? _e : undefined,
|
|
147
147
|
});
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
var key =
|
|
151
|
-
|
|
152
|
-
}
|
|
148
|
+
var activeSpan = api_1.trace.getActiveSpan();
|
|
149
|
+
for (var _i = 0, _f = Object.entries(result.otelAttributes); _i < _f.length; _i++) {
|
|
150
|
+
var _g = _f[_i], key = _g[0], value = _g[1];
|
|
151
|
+
activeSpan === null || activeSpan === void 0 ? void 0 : activeSpan.setAttribute("to_emit.0.".concat(key), value);
|
|
152
|
+
}
|
|
153
153
|
return [result];
|
|
154
154
|
};
|
|
155
155
|
exports.handleArvoEventHandlerCommonError = handleArvoEventHandlerCommonError;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arvo-event-handler",
|
|
3
|
-
"version": "2.2.
|
|
3
|
+
"version": "2.2.7",
|
|
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": {
|
|
@@ -8,21 +8,15 @@
|
|
|
8
8
|
"start": "node ./dist/index.js",
|
|
9
9
|
"dev": "ts-node ./src/index.ts",
|
|
10
10
|
"test": "jest --passWithNoTests --runInBand --detectOpenHandles --forceExit",
|
|
11
|
-
"
|
|
11
|
+
"lint": "biome check --fix",
|
|
12
|
+
"format": "biome format --fix",
|
|
12
13
|
"doc": "npx typedoc"
|
|
13
14
|
},
|
|
14
|
-
"keywords": [
|
|
15
|
-
"arvo",
|
|
16
|
-
"event-driven architecture",
|
|
17
|
-
"xorca",
|
|
18
|
-
"core",
|
|
19
|
-
"cloudevent",
|
|
20
|
-
"opentelemetry",
|
|
21
|
-
"orchestrator"
|
|
22
|
-
],
|
|
15
|
+
"keywords": ["arvo", "event-driven architecture", "xorca", "core", "cloudevent", "opentelemetry", "orchestrator"],
|
|
23
16
|
"author": "Saad Ahmad <saadkwi12@hotmail.com>",
|
|
24
17
|
"license": "MIT",
|
|
25
18
|
"devDependencies": {
|
|
19
|
+
"@biomejs/biome": "^1.9.4",
|
|
26
20
|
"@jest/globals": "^29.7.0",
|
|
27
21
|
"@opentelemetry/auto-instrumentations-node": "^0.49.1",
|
|
28
22
|
"@opentelemetry/exporter-metrics-otlp-proto": "^0.52.1",
|