@opentap/runner-client 2.19.0-alpha.1.2 → 2.19.0-alpha.1.4

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.
@@ -9,6 +9,7 @@ interface BaseClientRequestOptions {
9
9
  }
10
10
  export declare class BaseClient {
11
11
  private connection;
12
+ private subscriptionConnection;
12
13
  private baseSubject;
13
14
  private connectionOptions;
14
15
  private domainAccess;
package/lib/BaseClient.js CHANGED
@@ -262,12 +262,12 @@ var BaseClient = /** @class */ (function () {
262
262
  BaseClient.prototype.subscribe = function (subject, options) {
263
263
  if (!subject)
264
264
  throw Error('Subject is not defined!');
265
- if (!this.connection)
265
+ if (!this.subscriptionConnection)
266
266
  throw Error('Connection is not up yet! Please try again later!');
267
- if (this.connection.isClosed())
267
+ if (this.subscriptionConnection.isClosed())
268
268
  throw Error('Connection has been closed! Please reconnect!');
269
269
  var natsSubject = "".concat(this.baseSubject, ".").concat(subject);
270
- return this.connection.subscribe(natsSubject, options);
270
+ return this.subscriptionConnection.subscribe(natsSubject, options);
271
271
  };
272
272
  BaseClient.prototype.encode = function (payload) {
273
273
  if (!payload) {
@@ -296,9 +296,11 @@ var BaseClient = /** @class */ (function () {
296
296
  _a.label = 1;
297
297
  case 1:
298
298
  _a.trys.push([1, 3, , 4]);
299
- return [4 /*yield*/, connect(this.connectionOptions)
300
- .then(function (connection) {
299
+ return [4 /*yield*/, Promise.all([connect(this.connectionOptions), connect(this.connectionOptions)])
300
+ .then(function (_a) {
301
+ var connection = _a[0], subscriptionConnection = _a[1];
301
302
  _this.connection = connection;
303
+ _this.subscriptionConnection = subscriptionConnection;
302
304
  return Promise.resolve();
303
305
  })
304
306
  .catch(function (error) { return Promise.reject("Failed to connect to ".concat(_this.connectionOptions.servers, " with ").concat(error)); })];
@@ -315,21 +317,24 @@ var BaseClient = /** @class */ (function () {
315
317
  * Close the connection.
316
318
  */
317
319
  BaseClient.prototype.close = function () {
318
- var _a;
320
+ var _a, _b;
319
321
  return __awaiter(this, void 0, void 0, function () {
320
322
  var _this = this;
321
- return __generator(this, function (_b) {
322
- switch (_b.label) {
323
+ return __generator(this, function (_c) {
324
+ switch (_c.label) {
323
325
  case 0:
324
- if (!this.connection) return [3 /*break*/, 2];
325
- return [4 /*yield*/, ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.close().then(function () {
326
+ if (!(this.connection || this.subscriptionConnection)) return [3 /*break*/, 2];
327
+ return [4 /*yield*/, Promise.all([(_a = this.connection) === null || _a === void 0 ? void 0 : _a.close(), (_b = this.subscriptionConnection) === null || _b === void 0 ? void 0 : _b.close()])
328
+ .then(function () {
326
329
  _this.connection = null;
327
- }).catch(function (error) {
330
+ _this.subscriptionConnection = null;
331
+ })
332
+ .catch(function (error) {
328
333
  throw new Error("failed to close connection: ".concat(error));
329
- }))];
334
+ })];
330
335
  case 1:
331
- _b.sent();
332
- _b.label = 2;
336
+ _c.sent();
337
+ _c.label = 2;
333
338
  case 2: return [2 /*return*/];
334
339
  }
335
340
  });
@@ -24,52 +24,10 @@ var __assign = (this && this.__assign) || function () {
24
24
  };
25
25
  return __assign.apply(this, arguments);
26
26
  };
27
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
28
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
29
- return new (P || (P = Promise))(function (resolve, reject) {
30
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
31
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
32
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
33
- step((generator = generator.apply(thisArg, _arguments || [])).next());
34
- });
35
- };
36
- var __generator = (this && this.__generator) || function (thisArg, body) {
37
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
38
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
39
- function verb(n) { return function (v) { return step([n, v]); }; }
40
- function step(op) {
41
- if (f) throw new TypeError("Generator is already executing.");
42
- while (_) try {
43
- 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;
44
- if (y = 0, t) op = [op[0] & 2, t.value];
45
- switch (op[0]) {
46
- case 0: case 1: t = op; break;
47
- case 4: _.label++; return { value: op[1], done: false };
48
- case 5: _.label++; y = op[1]; op = [0]; continue;
49
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
50
- default:
51
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
52
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
53
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
54
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
55
- if (t[2]) _.ops.pop();
56
- _.trys.pop(); continue;
57
- }
58
- op = body.call(thisArg, _);
59
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
60
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
61
- }
62
- };
63
- var __asyncValues = (this && this.__asyncValues) || function (o) {
64
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
65
- var m = o[Symbol.asyncIterator], i;
66
- return m ? m.call(o) : (o = typeof __values === "function" ? __values(o) : o[Symbol.iterator](), i = {}, verb("next"), verb("throw"), verb("return"), i[Symbol.asyncIterator] = function () { return this; }, i);
67
- function verb(n) { i[n] = o[n] && function (v) { return new Promise(function (resolve, reject) { v = o[n](v), settle(resolve, reject, v.done, v.value); }); }; }
68
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
69
- };
70
27
  import { BreakPoints, CommonContext, CommonSettings, DataGridControl, Image, Interaction, ListItemType, LogList, Result, RunStatus, SessionEvent, Setting, TestPlan, TestRun, TestStepType, TestStepValidationError, WatchDog, } from './DTOs';
71
28
  import { JSONCodec } from 'nats.ws';
72
29
  import { BaseClient } from './BaseClient';
30
+ import { Subject } from 'rxjs';
73
31
  var SessionClient = /** @class */ (function (_super) {
74
32
  __extends(SessionClient, _super);
75
33
  function SessionClient(baseSubject, options) {
@@ -130,99 +88,47 @@ var SessionClient = /** @class */ (function (_super) {
130
88
  * @returns Subscription array: Result and Test Run subscriptions
131
89
  */
132
90
  SessionClient.prototype.connectSessionResults = function (resultHandler, testRunHandler, options) {
133
- var _this = this;
134
91
  var jsonCodec = JSONCodec();
135
- var resultSubscription = this.subscribe('OnResult', __assign({}, options));
136
- var testRunSubscription = this.subscribe('OnTestRun', __assign({}, options));
137
- (function () { return __awaiter(_this, void 0, void 0, function () {
138
- var resultSubscription_1, resultSubscription_1_1, message, resultJs, result, e_1_1;
139
- var e_1, _a;
140
- return __generator(this, function (_b) {
141
- switch (_b.label) {
142
- case 0:
143
- _b.trys.push([0, 5, 6, 11]);
144
- resultSubscription_1 = __asyncValues(resultSubscription);
145
- _b.label = 1;
146
- case 1: return [4 /*yield*/, resultSubscription_1.next()];
147
- case 2:
148
- if (!(resultSubscription_1_1 = _b.sent(), !resultSubscription_1_1.done)) return [3 /*break*/, 4];
149
- message = resultSubscription_1_1.value;
150
- try {
151
- resultJs = jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data);
152
- result = Result.fromJS(resultJs);
153
- resultHandler(result, null);
154
- }
155
- catch (error) {
156
- resultHandler(undefined, error);
157
- }
158
- _b.label = 3;
159
- case 3: return [3 /*break*/, 1];
160
- case 4: return [3 /*break*/, 11];
161
- case 5:
162
- e_1_1 = _b.sent();
163
- e_1 = { error: e_1_1 };
164
- return [3 /*break*/, 11];
165
- case 6:
166
- _b.trys.push([6, , 9, 10]);
167
- if (!(resultSubscription_1_1 && !resultSubscription_1_1.done && (_a = resultSubscription_1.return))) return [3 /*break*/, 8];
168
- return [4 /*yield*/, _a.call(resultSubscription_1)];
169
- case 7:
170
- _b.sent();
171
- _b.label = 8;
172
- case 8: return [3 /*break*/, 10];
173
- case 9:
174
- if (e_1) throw e_1.error;
175
- return [7 /*endfinally*/];
176
- case 10: return [7 /*endfinally*/];
177
- case 11: return [2 /*return*/];
178
- }
179
- });
180
- }); })();
181
- (function () { return __awaiter(_this, void 0, void 0, function () {
182
- var testRunSubscription_1, testRunSubscription_1_1, message, testRunJs, testRun, e_2_1;
183
- var e_2, _a;
184
- return __generator(this, function (_b) {
185
- switch (_b.label) {
186
- case 0:
187
- _b.trys.push([0, 5, 6, 11]);
188
- testRunSubscription_1 = __asyncValues(testRunSubscription);
189
- _b.label = 1;
190
- case 1: return [4 /*yield*/, testRunSubscription_1.next()];
191
- case 2:
192
- if (!(testRunSubscription_1_1 = _b.sent(), !testRunSubscription_1_1.done)) return [3 /*break*/, 4];
193
- message = testRunSubscription_1_1.value;
194
- try {
195
- testRunJs = jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data);
196
- testRun = TestRun.fromJS(testRunJs);
197
- testRunHandler(testRun, null);
198
- }
199
- catch (error) {
200
- testRunHandler(undefined, error);
201
- }
202
- _b.label = 3;
203
- case 3: return [3 /*break*/, 1];
204
- case 4: return [3 /*break*/, 11];
205
- case 5:
206
- e_2_1 = _b.sent();
207
- e_2 = { error: e_2_1 };
208
- return [3 /*break*/, 11];
209
- case 6:
210
- _b.trys.push([6, , 9, 10]);
211
- if (!(testRunSubscription_1_1 && !testRunSubscription_1_1.done && (_a = testRunSubscription_1.return))) return [3 /*break*/, 8];
212
- return [4 /*yield*/, _a.call(testRunSubscription_1)];
213
- case 7:
214
- _b.sent();
215
- _b.label = 8;
216
- case 8: return [3 /*break*/, 10];
217
- case 9:
218
- if (e_2) throw e_2.error;
219
- return [7 /*endfinally*/];
220
- case 10: return [7 /*endfinally*/];
221
- case 11: return [2 /*return*/];
222
- }
223
- });
224
- }); })();
225
- return [resultSubscription, testRunSubscription];
92
+ var resultSubject = new Subject();
93
+ var testRunSubject = new Subject();
94
+ resultSubject.subscribe(function (_a) {
95
+ var error = _a.error, msg = _a.msg;
96
+ if (error) {
97
+ resultHandler(undefined, error);
98
+ return;
99
+ }
100
+ try {
101
+ var resultJs = jsonCodec.decode(msg === null || msg === void 0 ? void 0 : msg.data);
102
+ var result = Result.fromJS(resultJs);
103
+ resultHandler(result, error);
104
+ }
105
+ catch (error) {
106
+ resultHandler(undefined, error);
107
+ }
108
+ });
109
+ testRunSubject.subscribe(function (_a) {
110
+ var error = _a.error, msg = _a.msg;
111
+ if (error) {
112
+ testRunHandler(undefined, error);
113
+ return;
114
+ }
115
+ try {
116
+ var testRunJs = jsonCodec.decode(msg === null || msg === void 0 ? void 0 : msg.data);
117
+ var testRun = TestRun.fromJS(testRunJs);
118
+ testRunHandler(testRun, error);
119
+ }
120
+ catch (error) {
121
+ testRunHandler(undefined, error);
122
+ }
123
+ });
124
+ return [
125
+ this.subscribe('OnResult', __assign(__assign({}, options), { callback: function (error, msg) {
126
+ resultSubject.next({ error: error, msg: msg });
127
+ } })),
128
+ this.subscribe('OnTestRun', __assign(__assign({}, options), { callback: function (error, msg) {
129
+ testRunSubject.next({ error: error, msg: msg });
130
+ } })),
131
+ ];
226
132
  };
227
133
  /**
228
134
  * Unsubscibe from session events
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentap/runner-client",
3
- "version": "2.19.0-alpha.1.2",
3
+ "version": "2.19.0-alpha.1.4",
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",
@@ -40,9 +40,10 @@
40
40
  "typescript": "^4.8.2"
41
41
  },
42
42
  "dependencies": {
43
+ "events": "^3.3.0",
43
44
  "nats.ws": "^1.9.0",
44
- "uuid": "^9.0.0",
45
- "events": "^3.3.0"
45
+ "rxjs": "^7.8.1",
46
+ "uuid": "^9.0.0"
46
47
  },
47
48
  "lint-staged": {
48
49
  "*.{ts,js,html}": [