arvo-event-handler 1.1.6 → 1.1.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/CHANGELOG.md +1 -1
- package/README.md +5 -6
- package/dist/AbstractArvoEventHandler/index.d.ts +1 -1
- package/dist/ArvoEventHandler/index.d.ts +3 -1
- package/dist/ArvoEventHandler/index.js +25 -9
- package/dist/ArvoEventRouter/index.js +2 -1
- package/dist/MultiArvoEventHandler/index.d.ts +3 -1
- package/dist/MultiArvoEventHandler/index.js +24 -8
- package/dist/index.d.ts +1 -1
- package/dist/utils.d.ts +3 -3
- package/dist/utils.js +1 -1
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
package/README.md
CHANGED
|
@@ -27,12 +27,11 @@ Whether you're building a small microservice or a large-scale distributed system
|
|
|
27
27
|
|
|
28
28
|
Arvo is a collection of libraries which allows you to build the event driven system in the Arvo pattern. However, if you feel you don't have to use them or you can use them as you see fit.
|
|
29
29
|
|
|
30
|
-
| Scope
|
|
31
|
-
|
|
|
32
|
-
| Orchestration
|
|
33
|
-
| Core
|
|
34
|
-
| Event Handling | https://www.npmjs.com/package/arvo-event-handler?activeTab=readme
|
|
35
|
-
|
|
30
|
+
| Scope | NPM | Github | Documentation |
|
|
31
|
+
| -------------- | ----------------------------------------------------------------- | -------------------------------------------------- | ------------------------------------------------------------ |
|
|
32
|
+
| Orchestration | https://www.npmjs.com/package/arvo-xstate?activeTab=readme | https://github.com/SaadAhmad123/arvo-xstate | https://saadahmad123.github.io/arvo-xstate/index.html |
|
|
33
|
+
| Core | https://www.npmjs.com/package/arvo-core?activeTab=readme | https://github.com/SaadAhmad123/arvo-core | https://saadahmad123.github.io/arvo-core/index.html |
|
|
34
|
+
| Event Handling | https://www.npmjs.com/package/arvo-event-handler?activeTab=readme | https://github.com/SaadAhmad123/arvo-event-handler | https://saadahmad123.github.io/arvo-event-handler/index.html |
|
|
36
35
|
|
|
37
36
|
# Arvo - Event Handler
|
|
38
37
|
|
|
@@ -88,7 +88,9 @@ export default class ArvoEventHandler<TContract extends ArvoContract> extends Ab
|
|
|
88
88
|
* - Propagates trace context to output events
|
|
89
89
|
* - Handles error cases and sets appropriate span status
|
|
90
90
|
*/
|
|
91
|
-
execute(event: ArvoEvent<ResolveArvoContractRecord<TContract['accepts']>, Record<string, any>, TContract['accepts']['type']
|
|
91
|
+
execute(event: ArvoEvent<ResolveArvoContractRecord<TContract['accepts']>, Record<string, any>, TContract['accepts']['type']>, opentelemetry?: {
|
|
92
|
+
inheritFrom: 'event' | 'execution';
|
|
93
|
+
}): Promise<ArvoEvent[]>;
|
|
92
94
|
/**
|
|
93
95
|
* Provides the schema for system error events.
|
|
94
96
|
*
|
|
@@ -60,6 +60,7 @@ var api_1 = require("@opentelemetry/api");
|
|
|
60
60
|
var utils_1 = require("../utils");
|
|
61
61
|
var utils_2 = require("../OpenTelemetry/utils");
|
|
62
62
|
var AbstractArvoEventHandler_1 = __importDefault(require("../AbstractArvoEventHandler"));
|
|
63
|
+
var OpenTelemetry_1 = require("../OpenTelemetry");
|
|
63
64
|
/**
|
|
64
65
|
* Represents an event handler for Arvo contracts.
|
|
65
66
|
*
|
|
@@ -156,18 +157,33 @@ var ArvoEventHandler = /** @class */ (function (_super) {
|
|
|
156
157
|
* - Propagates trace context to output events
|
|
157
158
|
* - Handles error cases and sets appropriate span status
|
|
158
159
|
*/
|
|
159
|
-
ArvoEventHandler.prototype.execute = function (
|
|
160
|
-
return __awaiter(this,
|
|
161
|
-
var span, eventFactory;
|
|
160
|
+
ArvoEventHandler.prototype.execute = function (event_1) {
|
|
161
|
+
return __awaiter(this, arguments, void 0, function (event, opentelemetry) {
|
|
162
|
+
var spanName, spanKinds, spanOptions, span, eventFactory;
|
|
163
|
+
var _a;
|
|
162
164
|
var _this = this;
|
|
163
|
-
|
|
164
|
-
|
|
165
|
+
if (opentelemetry === void 0) { opentelemetry = {
|
|
166
|
+
inheritFrom: 'event',
|
|
167
|
+
}; }
|
|
168
|
+
return __generator(this, function (_b) {
|
|
169
|
+
switch (_b.label) {
|
|
165
170
|
case 0:
|
|
166
|
-
|
|
171
|
+
spanName = "ArvoEventHandler<".concat(this.contract.uri, ">.execute<").concat(event.type, ">");
|
|
172
|
+
spanKinds = {
|
|
167
173
|
kind: this.openTelemetrySpanKind,
|
|
168
174
|
openInference: this.openInferenceSpanKind,
|
|
169
|
-
arvoExecution: this.arvoExecutionSpanKind
|
|
170
|
-
}
|
|
175
|
+
arvoExecution: this.arvoExecutionSpanKind,
|
|
176
|
+
};
|
|
177
|
+
spanOptions = {
|
|
178
|
+
kind: spanKinds.kind,
|
|
179
|
+
attributes: (_a = {},
|
|
180
|
+
_a[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = spanKinds.openInference,
|
|
181
|
+
_a[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = spanKinds.arvoExecution,
|
|
182
|
+
_a),
|
|
183
|
+
};
|
|
184
|
+
span = opentelemetry.inheritFrom === 'event'
|
|
185
|
+
? (0, utils_2.createSpanFromEvent)(spanName, event, spanKinds)
|
|
186
|
+
: OpenTelemetry_1.ArvoEventHandlerTracer.startSpan(spanName, spanOptions);
|
|
171
187
|
eventFactory = (0, arvo_core_1.createArvoEventFactory)(this.contract);
|
|
172
188
|
return [4 /*yield*/, api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), function () { return __awaiter(_this, void 0, void 0, function () {
|
|
173
189
|
var otelSpanHeaders, inputEventValidation, _handleOutput, outputs, error_1, result;
|
|
@@ -241,7 +257,7 @@ var ArvoEventHandler = /** @class */ (function (_super) {
|
|
|
241
257
|
}
|
|
242
258
|
});
|
|
243
259
|
}); })];
|
|
244
|
-
case 1: return [2 /*return*/,
|
|
260
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
245
261
|
}
|
|
246
262
|
});
|
|
247
263
|
});
|
|
@@ -188,7 +188,8 @@ var ArvoEventRouter = /** @class */ (function (_super) {
|
|
|
188
188
|
case 1:
|
|
189
189
|
_a.trys.push([1, 3, 4, 5]);
|
|
190
190
|
span.setStatus({ code: api_1.SpanStatusCode.OK });
|
|
191
|
-
if (!(0, utils_1.isNullOrUndefined)(this._source) &&
|
|
191
|
+
if (!(0, utils_1.isNullOrUndefined)(this._source) &&
|
|
192
|
+
newEvent.to !== this._source) {
|
|
192
193
|
throw new Error((0, arvo_core_1.cleanString)("\n Invalid event. The 'event.to' is ".concat(newEvent.to, " while this handler \n listens to only 'event.to' equal to ").concat(this._source, ". If this is a mistake,\n please update the 'source' field of the handler\n ")));
|
|
193
194
|
}
|
|
194
195
|
if (!this.handlersMap[newEvent.type]) {
|
|
@@ -90,7 +90,9 @@ export default class MultiArvoEventHandler extends AbstractArvoEventHandler {
|
|
|
90
90
|
* - If they don't match, an error is thrown with a descriptive message.
|
|
91
91
|
* - This ensures that the handler only processes events intended for it.
|
|
92
92
|
*/
|
|
93
|
-
execute(event: ArvoEvent
|
|
93
|
+
execute(event: ArvoEvent, opentelemetry?: {
|
|
94
|
+
inheritFrom: 'event' | 'execution';
|
|
95
|
+
}): Promise<ArvoEvent[]>;
|
|
94
96
|
/**
|
|
95
97
|
* Provides the schema for system error events.
|
|
96
98
|
*
|
|
@@ -59,6 +59,7 @@ var arvo_core_1 = require("arvo-core");
|
|
|
59
59
|
var utils_1 = require("../utils");
|
|
60
60
|
var utils_2 = require("../OpenTelemetry/utils");
|
|
61
61
|
var AbstractArvoEventHandler_1 = __importDefault(require("../AbstractArvoEventHandler"));
|
|
62
|
+
var OpenTelemetry_1 = require("../OpenTelemetry");
|
|
62
63
|
/**
|
|
63
64
|
* Represents a Multi ArvoEvent handler that can process multiple event types.
|
|
64
65
|
*
|
|
@@ -149,18 +150,33 @@ var MultiArvoEventHandler = /** @class */ (function (_super) {
|
|
|
149
150
|
* - If they don't match, an error is thrown with a descriptive message.
|
|
150
151
|
* - This ensures that the handler only processes events intended for it.
|
|
151
152
|
*/
|
|
152
|
-
MultiArvoEventHandler.prototype.execute = function (
|
|
153
|
-
return __awaiter(this,
|
|
154
|
-
var span;
|
|
153
|
+
MultiArvoEventHandler.prototype.execute = function (event_1) {
|
|
154
|
+
return __awaiter(this, arguments, void 0, function (event, opentelemetry) {
|
|
155
|
+
var spanName, spanKinds, spanOptions, span;
|
|
156
|
+
var _a;
|
|
155
157
|
var _this = this;
|
|
156
|
-
|
|
157
|
-
|
|
158
|
+
if (opentelemetry === void 0) { opentelemetry = {
|
|
159
|
+
inheritFrom: 'event',
|
|
160
|
+
}; }
|
|
161
|
+
return __generator(this, function (_b) {
|
|
162
|
+
switch (_b.label) {
|
|
158
163
|
case 0:
|
|
159
|
-
|
|
164
|
+
spanName = "MutliArvoEventHandler.source<".concat(this.source, ">.execute<").concat(event.type, ">");
|
|
165
|
+
spanKinds = {
|
|
160
166
|
kind: this.openTelemetrySpanKind,
|
|
161
167
|
openInference: this.openInferenceSpanKind,
|
|
162
168
|
arvoExecution: this.arvoExecutionSpanKind,
|
|
163
|
-
}
|
|
169
|
+
};
|
|
170
|
+
spanOptions = {
|
|
171
|
+
kind: spanKinds.kind,
|
|
172
|
+
attributes: (_a = {},
|
|
173
|
+
_a[arvo_core_1.OpenInference.ATTR_SPAN_KIND] = spanKinds.openInference,
|
|
174
|
+
_a[arvo_core_1.ArvoExecution.ATTR_SPAN_KIND] = spanKinds.arvoExecution,
|
|
175
|
+
_a),
|
|
176
|
+
};
|
|
177
|
+
span = opentelemetry.inheritFrom === 'event'
|
|
178
|
+
? (0, utils_2.createSpanFromEvent)(spanName, event, spanKinds)
|
|
179
|
+
: OpenTelemetry_1.ArvoEventHandlerTracer.startSpan(spanName, spanOptions);
|
|
164
180
|
return [4 /*yield*/, api_1.context.with(api_1.trace.setSpan(api_1.context.active(), span), function () { return __awaiter(_this, void 0, void 0, function () {
|
|
165
181
|
var otelSpanHeaders, _handlerOutput, outputs, error_1;
|
|
166
182
|
return __generator(this, function (_a) {
|
|
@@ -216,7 +232,7 @@ var MultiArvoEventHandler = /** @class */ (function (_super) {
|
|
|
216
232
|
}
|
|
217
233
|
});
|
|
218
234
|
}); })];
|
|
219
|
-
case 1: return [2 /*return*/,
|
|
235
|
+
case 1: return [2 /*return*/, _b.sent()];
|
|
220
236
|
}
|
|
221
237
|
});
|
|
222
238
|
});
|
package/dist/index.d.ts
CHANGED
|
@@ -11,4 +11,4 @@ import { ArvoEventRouter } from './ArvoEventRouter';
|
|
|
11
11
|
import { createArvoEventRouter } from './ArvoEventRouter/helpers';
|
|
12
12
|
import AbstractArvoEventHandler from './AbstractArvoEventHandler';
|
|
13
13
|
import { createSpanFromEvent } from './OpenTelemetry/utils';
|
|
14
|
-
export { ArvoEventHandler, createArvoEventHandler, IArvoEventHandler, ArvoEventHandlerFunctionOutput, ArvoEventHandlerFunctionInput, ArvoEventHandlerFunction, PartialExcept, MultiArvoEventHandler, MultiArvoEventHandlerFunctionInput, MultiArvoEventHandlerFunctionOutput, MultiArvoEventHandlerFunction, IMultiArvoEventHandler, createMultiArvoEventHandler, isNullOrUndefined, getValueOrDefault, coalesce, coalesceOrDefault, IArvoEventRouter, ArvoEventRouter, createArvoEventRouter, AbstractArvoEventHandler, createSpanFromEvent as createOtelSpanFromEvent };
|
|
14
|
+
export { ArvoEventHandler, createArvoEventHandler, IArvoEventHandler, ArvoEventHandlerFunctionOutput, ArvoEventHandlerFunctionInput, ArvoEventHandlerFunction, PartialExcept, MultiArvoEventHandler, MultiArvoEventHandlerFunctionInput, MultiArvoEventHandlerFunctionOutput, MultiArvoEventHandlerFunction, IMultiArvoEventHandler, createMultiArvoEventHandler, isNullOrUndefined, getValueOrDefault, coalesce, coalesceOrDefault, IArvoEventRouter, ArvoEventRouter, createArvoEventRouter, AbstractArvoEventHandler, createSpanFromEvent as createOtelSpanFromEvent, };
|
package/dist/utils.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { ArvoEvent, CreateArvoEvent, OpenTelemetryHeaders } from
|
|
2
|
-
import { ArvoEventHandlerFunctionOutput } from
|
|
3
|
-
import { MultiArvoEventHandlerFunctionOutput } from
|
|
1
|
+
import { ArvoEvent, CreateArvoEvent, OpenTelemetryHeaders } from 'arvo-core';
|
|
2
|
+
import { ArvoEventHandlerFunctionOutput } from './ArvoEventHandler/types';
|
|
3
|
+
import { MultiArvoEventHandlerFunctionOutput } from './MultiArvoEventHandler/types';
|
|
4
4
|
/**
|
|
5
5
|
* Checks if the item is null or undefined.
|
|
6
6
|
*
|
package/dist/utils.js
CHANGED
|
@@ -140,7 +140,7 @@ var createHandlerErrorOutputEvent = function (error, otelSpanHeaders, type, sour
|
|
|
140
140
|
errorMessage: error.message,
|
|
141
141
|
errorStack: (_d = error.stack) !== null && _d !== void 0 ? _d : null,
|
|
142
142
|
},
|
|
143
|
-
accesscontrol: (_e = originalEvent.accesscontrol) !== null && _e !== void 0 ? _e : undefined
|
|
143
|
+
accesscontrol: (_e = originalEvent.accesscontrol) !== null && _e !== void 0 ? _e : undefined,
|
|
144
144
|
});
|
|
145
145
|
Object.entries(result.otelAttributes).forEach(function (_a) {
|
|
146
146
|
var _b;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arvo-event-handler",
|
|
3
|
-
"version": "1.1.
|
|
3
|
+
"version": "1.1.7",
|
|
4
4
|
"description": "This package contains class and function for event handlers in an Arvo Event Driven system",
|
|
5
5
|
"main": "dist/index.js",
|
|
6
6
|
"scripts": {
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
},
|
|
50
50
|
"dependencies": {
|
|
51
51
|
"@opentelemetry/api": "^1.9.0",
|
|
52
|
-
"arvo-core": "^1.1.
|
|
52
|
+
"arvo-core": "^1.1.16",
|
|
53
53
|
"uuid": "^10.0.0",
|
|
54
54
|
"zod": "^3.23.8"
|
|
55
55
|
}
|