arvo-event-handler 1.0.2 → 1.0.3

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.
@@ -86,7 +86,7 @@ var ArvoEventHandler = /** @class */ (function () {
86
86
  * If no source is provided, it defaults to the contract's accepted event type.
87
87
  */
88
88
  function ArvoEventHandler(param) {
89
- var _a, _b, _c;
89
+ var _a, _b, _c, _d, _e, _f, _g;
90
90
  this.openInferenceSpanKind = arvo_core_1.OpenInferenceSpanKind.CHAIN;
91
91
  this.arvoExecutionSpanKind = arvo_core_1.ArvoExecutionSpanKind.EVENT_HANDLER;
92
92
  this.openTelemetrySpanKind = api_1.SpanKind.INTERNAL;
@@ -101,13 +101,13 @@ var ArvoEventHandler = /** @class */ (function () {
101
101
  throw new Error("The provided 'source' is not a valid string. Error: ".concat(error.message));
102
102
  }
103
103
  }
104
- this.source = param.source || this.contract.accepts.type;
104
+ this.source = (_a = param.source) !== null && _a !== void 0 ? _a : this.contract.accepts.type;
105
105
  this.arvoExecutionSpanKind =
106
- ((_a = param.spanKind) === null || _a === void 0 ? void 0 : _a.arvoExecution) || this.arvoExecutionSpanKind;
106
+ (_c = (_b = param.spanKind) === null || _b === void 0 ? void 0 : _b.arvoExecution) !== null && _c !== void 0 ? _c : this.arvoExecutionSpanKind;
107
107
  this.openInferenceSpanKind =
108
- ((_b = param.spanKind) === null || _b === void 0 ? void 0 : _b.openInference) || this.openInferenceSpanKind;
108
+ (_e = (_d = param.spanKind) === null || _d === void 0 ? void 0 : _d.openInference) !== null && _e !== void 0 ? _e : this.openInferenceSpanKind;
109
109
  this.openTelemetrySpanKind =
110
- ((_c = param.spanKind) === null || _c === void 0 ? void 0 : _c.openTelemetry) || this.openTelemetrySpanKind;
110
+ (_g = (_f = param.spanKind) === null || _f === void 0 ? void 0 : _f.openTelemetry) !== null && _g !== void 0 ? _g : this.openTelemetrySpanKind;
111
111
  }
112
112
  /**
113
113
  * Executes the event handler for a given event.
@@ -43,7 +43,6 @@ export type ArvoEventHandlerFunction<TContract extends ArvoContract> = (params:
43
43
  export interface IArvoEventHandler<TContract extends ArvoContract> {
44
44
  /**
45
45
  * An override source for emitted events.
46
- * @deprecated This field is deprecated and should be used with caution.
47
46
  * @remarks
48
47
  * When provided, this value will be used as the source for emitted events
49
48
  * instead of the `contract.accepts.type`. Use this very carefully as it may
@@ -155,15 +155,15 @@ var ArvoEventRouter = /** @class */ (function () {
155
155
  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 () {
156
156
  var otelSpanHeaders, newEvent, results, error_1, result;
157
157
  var _this = this;
158
- var _a, _b;
159
- return __generator(this, function (_c) {
160
- switch (_c.label) {
158
+ var _a, _b, _c, _d;
159
+ return __generator(this, function (_e) {
160
+ switch (_e.label) {
161
161
  case 0:
162
162
  otelSpanHeaders = (0, arvo_core_1.currentOpenTelemetryHeaders)();
163
163
  newEvent = (0, utils_2.deleteOtelHeaders)(event);
164
- _c.label = 1;
164
+ _e.label = 1;
165
165
  case 1:
166
- _c.trys.push([1, 3, 4, 5]);
166
+ _e.trys.push([1, 3, 4, 5]);
167
167
  span.setStatus({ code: api_1.SpanStatusCode.OK });
168
168
  if (!(0, utils_1.isNullOrUndefined)(this.source) && newEvent.to !== this.source) {
169
169
  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 ")));
@@ -173,7 +173,7 @@ var ArvoEventRouter = /** @class */ (function () {
173
173
  }
174
174
  return [4 /*yield*/, this.handlersMap[newEvent.type].execute(newEvent)];
175
175
  case 2:
176
- results = _c.sent();
176
+ results = _e.sent();
177
177
  return [2 /*return*/, results.map(function (event) {
178
178
  var _a;
179
179
  return new arvo_core_1.ArvoEvent({
@@ -194,7 +194,7 @@ var ArvoEventRouter = /** @class */ (function () {
194
194
  }, event.data, event.cloudevent.extensions);
195
195
  })];
196
196
  case 3:
197
- error_1 = _c.sent();
197
+ error_1 = _e.sent();
198
198
  (0, arvo_core_1.exceptionToSpan)(error_1);
199
199
  span.setStatus({
200
200
  code: api_1.SpanStatusCode.ERROR,
@@ -206,18 +206,18 @@ var ArvoEventRouter = /** @class */ (function () {
206
206
  });
207
207
  result = (0, arvo_core_1.createArvoEvent)({
208
208
  type: "sys.arvo.event.router.error",
209
- source: this.source || "arvo.event.router",
209
+ source: (_a = this.source) !== null && _a !== void 0 ? _a : "arvo.event.router",
210
210
  subject: event.subject,
211
211
  // The system error must always got back to
212
212
  // the source
213
213
  to: event.source,
214
214
  executionunits: this.executionunits,
215
- traceparent: (_a = otelSpanHeaders.traceparent) !== null && _a !== void 0 ? _a : undefined,
216
- tracestate: (_b = otelSpanHeaders.tracestate) !== null && _b !== void 0 ? _b : undefined,
215
+ traceparent: (_b = otelSpanHeaders.traceparent) !== null && _b !== void 0 ? _b : undefined,
216
+ tracestate: (_c = otelSpanHeaders.tracestate) !== null && _c !== void 0 ? _c : undefined,
217
217
  data: {
218
218
  errorName: error_1.name,
219
219
  errorMessage: error_1.message,
220
- errorStack: error_1.stack || null,
220
+ errorStack: (_d = error_1.stack) !== null && _d !== void 0 ? _d : null,
221
221
  },
222
222
  });
223
223
  Object.entries(result.otelAttributes).forEach(function (_a) {
@@ -179,13 +179,14 @@ var MultiArvoEventHandler = /** @class */ (function () {
179
179
  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 () {
180
180
  var otelSpanHeaders, _handlerOutput, outputs, error_1, result;
181
181
  var _this = this;
182
- return __generator(this, function (_a) {
183
- switch (_a.label) {
182
+ var _a, _b, _c;
183
+ return __generator(this, function (_d) {
184
+ switch (_d.label) {
184
185
  case 0:
185
186
  otelSpanHeaders = (0, arvo_core_1.currentOpenTelemetryHeaders)();
186
- _a.label = 1;
187
+ _d.label = 1;
187
188
  case 1:
188
- _a.trys.push([1, 3, 4, 5]);
189
+ _d.trys.push([1, 3, 4, 5]);
189
190
  span.setStatus({ code: api_1.SpanStatusCode.OK });
190
191
  Object.entries(event.otelAttributes).forEach(function (_a) {
191
192
  var key = _a[0], value = _a[1];
@@ -199,7 +200,7 @@ var MultiArvoEventHandler = /** @class */ (function () {
199
200
  source: this.source,
200
201
  })];
201
202
  case 2:
202
- _handlerOutput = _a.sent();
203
+ _handlerOutput = _d.sent();
203
204
  if (!_handlerOutput)
204
205
  return [2 /*return*/, []];
205
206
  outputs = [];
@@ -224,7 +225,7 @@ var MultiArvoEventHandler = /** @class */ (function () {
224
225
  return result;
225
226
  })];
226
227
  case 3:
227
- error_1 = _a.sent();
228
+ error_1 = _d.sent();
228
229
  (0, arvo_core_1.exceptionToSpan)(error_1);
229
230
  span.setStatus({
230
231
  code: api_1.SpanStatusCode.ERROR,
@@ -238,12 +239,12 @@ var MultiArvoEventHandler = /** @class */ (function () {
238
239
  // the source
239
240
  to: event.source,
240
241
  executionunits: this.executionunits,
241
- traceparent: otelSpanHeaders.traceparent || undefined,
242
- tracestate: otelSpanHeaders.tracestate || undefined,
242
+ traceparent: (_a = otelSpanHeaders.traceparent) !== null && _a !== void 0 ? _a : undefined,
243
+ tracestate: (_b = otelSpanHeaders.tracestate) !== null && _b !== void 0 ? _b : undefined,
243
244
  data: {
244
245
  errorName: error_1.name,
245
246
  errorMessage: error_1.message,
246
- errorStack: error_1.stack || null,
247
+ errorStack: (_c = error_1.stack) !== null && _c !== void 0 ? _c : null,
247
248
  },
248
249
  });
249
250
  Object.entries(result.otelAttributes).forEach(function (_a) {
@@ -12,7 +12,7 @@ exports.ArvoEventHandlerTracer = api_1.trace.getTracer(pkg.name, pkg.version);
12
12
  var extractContext = function (traceparent, tracestate) {
13
13
  var extractedContext = api_1.propagation.extract(api_1.context.active(), {
14
14
  traceparent: traceparent,
15
- tracestate: tracestate || undefined,
15
+ tracestate: tracestate !== null && tracestate !== void 0 ? tracestate : undefined,
16
16
  });
17
17
  return extractedContext;
18
18
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "arvo-event-handler",
3
- "version": "1.0.2",
3
+ "version": "1.0.3",
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": {