@opentap/runner-client 2.1.3 → 2.2.0-alpha.1.1

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.
@@ -5,6 +5,7 @@ export declare class BaseClient {
5
5
  private baseSubject;
6
6
  private connectionOptions;
7
7
  private domainAccess;
8
+ private eventEmitter;
8
9
  private _accessToken;
9
10
  private _headers;
10
11
  private _timeout;
@@ -97,6 +98,17 @@ export declare class BaseClient {
97
98
  * @returns
98
99
  */
99
100
  protected success<T>(): ((value: T) => T | PromiseLike<T>) | null | undefined;
101
+ /**
102
+ * Add an error-event listener.
103
+ * @param listener
104
+ * @returns {EventEmitter}
105
+ */
106
+ addErrorEventListener(listener: (...args: any[]) => void): void;
107
+ /**
108
+ * Remove an error-event listener.
109
+ * @param listener
110
+ */
111
+ removeErrorEventListener(listener: (...args: any[]) => void): void;
100
112
  /**
101
113
  * Retrieve component settings overview
102
114
  * @returns {{Promise<ComponentSettingsIdentifier[]>}}
package/lib/BaseClient.js CHANGED
@@ -56,7 +56,12 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
56
56
  };
57
57
  import { ComponentSettingsBase, ComponentSettingsIdentifier, ComponentSettingsListItem, DataGridControl, ErrorResponse, FileDescriptor, ListItemType, ProfileGroup, } from './DTOs';
58
58
  import { Empty, ErrorCode, JSONCodec, StringCodec, connect, headers, } from 'nats.ws';
59
+ import { EventEmitter } from 'events';
59
60
  var DEFAULT_TIMEOUT = 6000;
61
+ var Events;
62
+ (function (Events) {
63
+ Events["ERROR"] = "error_event";
64
+ })(Events || (Events = {}));
60
65
  var BaseClient = /** @class */ (function () {
61
66
  function BaseClient(baseSubject, options) {
62
67
  this.domainAccess = new Map();
@@ -64,6 +69,7 @@ var BaseClient = /** @class */ (function () {
64
69
  this.baseSubject = baseSubject;
65
70
  this.connectionOptions = __assign({}, options) || {};
66
71
  this.connectionOptions.timeout = (options === null || options === void 0 ? void 0 : options.timeout) || DEFAULT_TIMEOUT;
72
+ this.eventEmitter = new EventEmitter();
67
73
  }
68
74
  Object.defineProperty(BaseClient.prototype, "accessToken", {
69
75
  /** Get request access token */
@@ -135,7 +141,12 @@ var BaseClient = /** @class */ (function () {
135
141
  var jsonCodec = JSONCodec();
136
142
  response = jsonCodec.decode(message.data);
137
143
  }
138
- return _this.isErrorResponse(response) ? Promise.reject(ErrorResponse.fromJS(response)) : Promise.resolve(response);
144
+ if (_this.isErrorResponse(response)) {
145
+ var error = ErrorResponse.fromJS(response);
146
+ _this.eventEmitter.emit('errorEvent', error);
147
+ return Promise.reject(error);
148
+ }
149
+ return Promise.resolve(response);
139
150
  })
140
151
  .catch(function (error) { return Promise.reject(_this.natsErrorHandler(error, subject)); })];
141
152
  case 1: return [2 /*return*/, _a.sent()];
@@ -160,6 +171,7 @@ var BaseClient = /** @class */ (function () {
160
171
  default:
161
172
  errorResponse.message = error.message;
162
173
  }
174
+ this.eventEmitter.emit(Events.ERROR, errorResponse);
163
175
  return errorResponse;
164
176
  };
165
177
  /**
@@ -277,6 +289,8 @@ var BaseClient = /** @class */ (function () {
277
289
  return [2 /*return*/, Promise.reject("".concat(subject, ": Connection has been closed! Please reconnect!"))];
278
290
  fileSize = -1;
279
291
  return [2 /*return*/, new Promise(function (resolve, reject) {
292
+ if (!_this.connection)
293
+ return Promise.reject("".concat(subject, ": Connection is down! Please try again!"));
280
294
  var combinedResult = new Uint8Array([]);
281
295
  // Subscribe to the subject before starting the process
282
296
  var subscription = _this.connection.subscribe(replySubject);
@@ -410,6 +424,23 @@ var BaseClient = /** @class */ (function () {
410
424
  BaseClient.prototype.success = function () {
411
425
  return function (response) { return response; };
412
426
  };
427
+ /**
428
+ * Add an error-event listener.
429
+ * @param listener
430
+ * @returns {EventEmitter}
431
+ */
432
+ BaseClient.prototype.addErrorEventListener = function (listener) {
433
+ var _a;
434
+ (_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.addListener(Events.ERROR, listener);
435
+ };
436
+ /**
437
+ * Remove an error-event listener.
438
+ * @param listener
439
+ */
440
+ BaseClient.prototype.removeErrorEventListener = function (listener) {
441
+ var _a;
442
+ (_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.removeListener(Events.ERROR, listener);
443
+ };
413
444
  /**
414
445
  * Retrieve component settings overview
415
446
  * @returns {{Promise<ComponentSettingsIdentifier[]>}}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentap/runner-client",
3
- "version": "2.1.3",
3
+ "version": "2.2.0-alpha.1.1",
4
4
  "description": "This is the web client for the OpenTAP Runner.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -26,6 +26,7 @@
26
26
  "url": "git://github.com/opentap/runner-client-web.git"
27
27
  },
28
28
  "devDependencies": {
29
+ "@types/node": "^18.11.9",
29
30
  "@types/uuid": "^8.3.4",
30
31
  "@typescript-eslint/eslint-plugin": "^5.36.1",
31
32
  "@typescript-eslint/parser": "^5.36.1",