@opentap/runner-client 2.19.0-alpha.1.3 → 2.20.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.
@@ -9,7 +9,6 @@ interface BaseClientRequestOptions {
9
9
  }
10
10
  export declare class BaseClient {
11
11
  private connection;
12
- private subscriptionConnection;
13
12
  private baseSubject;
14
13
  private connectionOptions;
15
14
  private domainAccess;
package/lib/BaseClient.js CHANGED
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __assign = (this && this.__assign) || function () {
2
3
  __assign = Object.assign || function(t) {
3
4
  for (var s, i = 1, n = arguments.length; i < n; i++) {
@@ -45,10 +46,12 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
46
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
47
  }
47
48
  };
48
- import { ComponentSettingsBase, ComponentSettingsIdentifier, ComponentSettingsListItem, DataGridControl, ErrorResponse, FileDescriptor, ListItemType, ProfileGroup, } from './DTOs';
49
- import { Empty, ErrorCode, JSONCodec, StringCodec, connect, headers, } from 'nats.ws';
50
- import { EventEmitter } from 'events';
51
- import { v4 as uuidv4 } from 'uuid';
49
+ Object.defineProperty(exports, "__esModule", { value: true });
50
+ exports.BaseClient = void 0;
51
+ var DTOs_1 = require("./DTOs");
52
+ var nats_ws_1 = require("nats.ws");
53
+ var events_1 = require("events");
54
+ var uuid_1 = require("uuid");
52
55
  var DEFAULT_TIMEOUT = 40000; // default timeout of 40 seconds
53
56
  var Events;
54
57
  (function (Events) {
@@ -61,7 +64,7 @@ var BaseClient = /** @class */ (function () {
61
64
  this.baseSubject = baseSubject;
62
65
  this.connectionOptions = __assign({}, options) || {};
63
66
  this.connectionOptions.timeout = (options === null || options === void 0 ? void 0 : options.timeout) || DEFAULT_TIMEOUT;
64
- this.eventEmitter = new EventEmitter();
67
+ this.eventEmitter = new events_1.EventEmitter();
65
68
  }
66
69
  Object.defineProperty(BaseClient.prototype, "accessToken", {
67
70
  /** Get request access token */
@@ -100,7 +103,7 @@ var BaseClient = /** @class */ (function () {
100
103
  configurable: true
101
104
  });
102
105
  BaseClient.prototype.withTimeout = function (promise, timeout) {
103
- return Promise.race([promise, new Promise(function (_, reject) { return setTimeout(function () { return reject(new Error(ErrorCode.Timeout)); }, timeout); })]);
106
+ return Promise.race([promise, new Promise(function (_, reject) { return setTimeout(function () { return reject(new Error(nats_ws_1.ErrorCode.Timeout)); }, timeout); })]);
104
107
  };
105
108
  /**
106
109
  * Send a request to the nats server.
@@ -126,15 +129,15 @@ var BaseClient = /** @class */ (function () {
126
129
  data = this.encode(payload);
127
130
  headers = this.buildHeaders();
128
131
  timeout = (options === null || options === void 0 ? void 0 : options.timeout) || this.timeout;
129
- replySubject = "".concat(subject, ".Reply.").concat(uuidv4());
132
+ replySubject = "".concat(subject, ".Reply.").concat((0, uuid_1.v4)());
130
133
  serverMaxPayload = (_b = (_a = this.connection) === null || _a === void 0 ? void 0 : _a.info) === null || _b === void 0 ? void 0 : _b.max_payload;
131
134
  chunkSize = serverMaxPayload ? serverMaxPayload - 50000 : 512000;
132
135
  // The Session and the Client need to agree on the chunk size. Put it in a header.
133
136
  headers.append('ChunkSize', chunkSize.toString());
134
- requestId = uuidv4();
137
+ requestId = (0, uuid_1.v4)();
135
138
  headers.append('RequestId', requestId);
136
139
  opts = __assign(__assign({}, options === null || options === void 0 ? void 0 : options.publishOptions), { headers: headers, reply: replySubject });
137
- fileDescriptor = new FileDescriptor(data.length, chunkSize);
140
+ fileDescriptor = new DTOs_1.FileDescriptor(data.length, chunkSize);
138
141
  chunkNumber = 1;
139
142
  headers.set('ChunkNumber', chunkNumber.toString());
140
143
  getChunk = function (chunk) {
@@ -193,10 +196,10 @@ var BaseClient = /** @class */ (function () {
193
196
  if (byteArray.length === 0) {
194
197
  return Promise.resolve(undefined);
195
198
  }
196
- var jsonCodec = JSONCodec();
199
+ var jsonCodec = (0, nats_ws_1.JSONCodec)();
197
200
  // If a raw response is requested, we should avoid decoding the bytes.
198
201
  var response = (options === null || options === void 0 ? void 0 : options.rawResponse) ? byteArray : jsonCodec.decode(byteArray);
199
- return isErrorResponse ? Promise.reject(ErrorResponse.fromJS(response)) : Promise.resolve(response);
202
+ return isErrorResponse ? Promise.reject(DTOs_1.ErrorResponse.fromJS(response)) : Promise.resolve(response);
200
203
  });
201
204
  chunk = getChunk(0);
202
205
  this.connection.publish(subject, chunk, opts);
@@ -211,7 +214,7 @@ var BaseClient = /** @class */ (function () {
211
214
  // an empty message
212
215
  if (data.length > 0 && data.length % fileDescriptor.chunkSize === 0) {
213
216
  headers.set('ChunkNumber', chunkNumber.toString());
214
- this.connection.publish(subject, Empty, opts);
217
+ this.connection.publish(subject, nats_ws_1.Empty, opts);
215
218
  }
216
219
  // Now that we have sent the terminating chunk, the result should arrive on our promise.
217
220
  return [2 /*return*/, this.withTimeout(responsePromise, timeout).catch(function (err) {
@@ -228,11 +231,11 @@ var BaseClient = /** @class */ (function () {
228
231
  * @returns
229
232
  */
230
233
  BaseClient.prototype.natsErrorHandler = function (error, subject) {
231
- var errorResponse = new ErrorResponse(error);
234
+ var errorResponse = new DTOs_1.ErrorResponse(error);
232
235
  errorResponse.subject = subject;
233
236
  errorResponse.stackTrace = error === null || error === void 0 ? void 0 : error.stack;
234
237
  switch (error === null || error === void 0 ? void 0 : error.code) {
235
- case ErrorCode.NoResponders:
238
+ case nats_ws_1.ErrorCode.NoResponders:
236
239
  errorResponse.message = 'No Responders';
237
240
  break;
238
241
  default:
@@ -247,7 +250,7 @@ var BaseClient = /** @class */ (function () {
247
250
  */
248
251
  BaseClient.prototype.buildHeaders = function () {
249
252
  var _a, _b;
250
- var _headers = headers();
253
+ var _headers = (0, nats_ws_1.headers)();
251
254
  this._accessToken && _headers.set('Authorization', this._accessToken);
252
255
  (_a = this.domainAccess) === null || _a === void 0 ? void 0 : _a.forEach(function (value, key) { return _headers.append('DomainAuthorization', "".concat(key, "|").concat(value)); });
253
256
  (_b = this._headers) === null || _b === void 0 ? void 0 : _b.forEach(function (value, key) { return _headers.append(key, value); });
@@ -262,21 +265,21 @@ var BaseClient = /** @class */ (function () {
262
265
  BaseClient.prototype.subscribe = function (subject, options) {
263
266
  if (!subject)
264
267
  throw Error('Subject is not defined!');
265
- if (!this.subscriptionConnection)
268
+ if (!this.connection)
266
269
  throw Error('Connection is not up yet! Please try again later!');
267
- if (this.subscriptionConnection.isClosed())
270
+ if (this.connection.isClosed())
268
271
  throw Error('Connection has been closed! Please reconnect!');
269
272
  var natsSubject = "".concat(this.baseSubject, ".").concat(subject);
270
- return this.subscriptionConnection.subscribe(natsSubject, options);
273
+ return this.connection.subscribe(natsSubject, options);
271
274
  };
272
275
  BaseClient.prototype.encode = function (payload) {
273
276
  if (!payload) {
274
- return Empty;
277
+ return nats_ws_1.Empty;
275
278
  }
276
279
  if (payload instanceof Uint8Array) {
277
280
  return payload;
278
281
  }
279
- return StringCodec().encode(JSON.stringify(payload));
282
+ return (0, nats_ws_1.StringCodec)().encode(JSON.stringify(payload));
280
283
  };
281
284
  /**
282
285
  * Create a connection to the nats server.
@@ -296,11 +299,9 @@ var BaseClient = /** @class */ (function () {
296
299
  _a.label = 1;
297
300
  case 1:
298
301
  _a.trys.push([1, 3, , 4]);
299
- return [4 /*yield*/, Promise.all([connect(this.connectionOptions), connect(this.connectionOptions)])
300
- .then(function (_a) {
301
- var connection = _a[0], subscriptionConnection = _a[1];
302
+ return [4 /*yield*/, (0, nats_ws_1.connect)(this.connectionOptions)
303
+ .then(function (connection) {
302
304
  _this.connection = connection;
303
- _this.subscriptionConnection = subscriptionConnection;
304
305
  return Promise.resolve();
305
306
  })
306
307
  .catch(function (error) { return Promise.reject("Failed to connect to ".concat(_this.connectionOptions.servers, " with ").concat(error)); })];
@@ -317,24 +318,21 @@ var BaseClient = /** @class */ (function () {
317
318
  * Close the connection.
318
319
  */
319
320
  BaseClient.prototype.close = function () {
320
- var _a, _b;
321
+ var _a;
321
322
  return __awaiter(this, void 0, void 0, function () {
322
323
  var _this = this;
323
- return __generator(this, function (_c) {
324
- switch (_c.label) {
324
+ return __generator(this, function (_b) {
325
+ switch (_b.label) {
325
326
  case 0:
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 () {
327
+ if (!this.connection) return [3 /*break*/, 2];
328
+ return [4 /*yield*/, ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.close().then(function () {
329
329
  _this.connection = null;
330
- _this.subscriptionConnection = null;
331
- })
332
- .catch(function (error) {
330
+ }).catch(function (error) {
333
331
  throw new Error("failed to close connection: ".concat(error));
334
- })];
332
+ }))];
335
333
  case 1:
336
- _c.sent();
337
- _c.label = 2;
334
+ _b.sent();
335
+ _b.label = 2;
338
336
  case 2: return [2 /*return*/];
339
337
  }
340
338
  });
@@ -391,7 +389,7 @@ var BaseClient = /** @class */ (function () {
391
389
  return this.request('GetComponentSettingsOverview')
392
390
  .then(function (componentSettingsIdentifiers) {
393
391
  return componentSettingsIdentifiers.map(function (componentSettingsIdentifier) {
394
- return ComponentSettingsIdentifier.fromJS(componentSettingsIdentifier);
392
+ return DTOs_1.ComponentSettingsIdentifier.fromJS(componentSettingsIdentifier);
395
393
  });
396
394
  })
397
395
  .then(this.success())
@@ -407,7 +405,7 @@ var BaseClient = /** @class */ (function () {
407
405
  BaseClient.prototype.setComponentSettings = function (groupName, name, returnedSettings) {
408
406
  var setComponentSettingsRequest = { groupName: groupName, name: name, returnedSettings: returnedSettings };
409
407
  return this.request('SetComponentSettings', setComponentSettingsRequest)
410
- .then(function (componentSettingsBase) { return ComponentSettingsBase.fromJS(componentSettingsBase); })
408
+ .then(function (componentSettingsBase) { return DTOs_1.ComponentSettingsBase.fromJS(componentSettingsBase); })
411
409
  .then(this.success())
412
410
  .catch(this.error());
413
411
  };
@@ -420,7 +418,7 @@ var BaseClient = /** @class */ (function () {
420
418
  BaseClient.prototype.getComponentSettings = function (groupName, name) {
421
419
  var getComponentSettingsRequest = { groupName: groupName, name: name };
422
420
  return this.request('GetComponentSettings', getComponentSettingsRequest)
423
- .then(function (componentSettingsBase) { return ComponentSettingsBase.fromJS(componentSettingsBase); })
421
+ .then(function (componentSettingsBase) { return DTOs_1.ComponentSettingsBase.fromJS(componentSettingsBase); })
424
422
  .then(this.success())
425
423
  .catch(this.error());
426
424
  };
@@ -434,7 +432,7 @@ var BaseClient = /** @class */ (function () {
434
432
  BaseClient.prototype.getComponentSettingsListItem = function (groupName, name, index) {
435
433
  var getComponentSettingsListItemRequest = { groupName: groupName, name: name, index: index };
436
434
  return this.request('GetComponentSettingsListItem', getComponentSettingsListItemRequest)
437
- .then(function (componentSettingsListItem) { return ComponentSettingsListItem.fromJS(componentSettingsListItem); })
435
+ .then(function (componentSettingsListItem) { return DTOs_1.ComponentSettingsListItem.fromJS(componentSettingsListItem); })
438
436
  .then(this.success())
439
437
  .catch(this.error());
440
438
  };
@@ -449,7 +447,7 @@ var BaseClient = /** @class */ (function () {
449
447
  BaseClient.prototype.setComponentSettingsListItem = function (groupName, name, index, item) {
450
448
  var setComponentSettingsListItemRequest = { groupName: groupName, name: name, index: index, item: item };
451
449
  return this.request('SetComponentSettingsListItem', setComponentSettingsListItemRequest)
452
- .then(function (componentSettingsListItem) { return ComponentSettingsListItem.fromJS(componentSettingsListItem); })
450
+ .then(function (componentSettingsListItem) { return DTOs_1.ComponentSettingsListItem.fromJS(componentSettingsListItem); })
453
451
  .then(this.success())
454
452
  .catch(this.error());
455
453
  };
@@ -469,7 +467,7 @@ var BaseClient = /** @class */ (function () {
469
467
  propertyName: propertyName,
470
468
  };
471
469
  return this.request('GetComponentSettingDataGrid', getComponentSettingDataGridRequest)
472
- .then(function (dataGridControl) { return DataGridControl.fromJS(dataGridControl); })
470
+ .then(function (dataGridControl) { return DTOs_1.DataGridControl.fromJS(dataGridControl); })
473
471
  .then(this.success())
474
472
  .catch(this.error());
475
473
  };
@@ -491,7 +489,7 @@ var BaseClient = /** @class */ (function () {
491
489
  dataGridControl: dataGridControl,
492
490
  };
493
491
  return this.request('SetComponentSettingDataGrid', setComponentSettingDataGridRequest)
494
- .then(function (dataGridControl) { return DataGridControl.fromJS(dataGridControl); })
492
+ .then(function (dataGridControl) { return DTOs_1.DataGridControl.fromJS(dataGridControl); })
495
493
  .then(this.success())
496
494
  .catch(this.error());
497
495
  };
@@ -513,7 +511,7 @@ var BaseClient = /** @class */ (function () {
513
511
  typeName: typeName,
514
512
  };
515
513
  return this.request('AddComponentSettingDataGridItemType', addComponentSettingDataGridItemTypeRequest)
516
- .then(function (dataGridControl) { return DataGridControl.fromJS(dataGridControl); })
514
+ .then(function (dataGridControl) { return DTOs_1.DataGridControl.fromJS(dataGridControl); })
517
515
  .then(this.success())
518
516
  .catch(this.error());
519
517
  };
@@ -533,7 +531,7 @@ var BaseClient = /** @class */ (function () {
533
531
  propertyName: propertyName,
534
532
  };
535
533
  return this.request('AddComponentSettingDataGridItem', getComponentSettingDataGridRequest)
536
- .then(function (dataGridControl) { return DataGridControl.fromJS(dataGridControl); })
534
+ .then(function (dataGridControl) { return DTOs_1.DataGridControl.fromJS(dataGridControl); })
537
535
  .then(this.success())
538
536
  .catch(this.error());
539
537
  };
@@ -553,7 +551,7 @@ var BaseClient = /** @class */ (function () {
553
551
  propertyName: propertyName,
554
552
  };
555
553
  return this.request('GetComponentSettingDataGridTypes', getComponentSettingDataGridRequest)
556
- .then(function (listItemTypes) { return listItemTypes.map(function (listItemType) { return ListItemType.fromJS(listItemType); }); })
554
+ .then(function (listItemTypes) { return listItemTypes.map(function (listItemType) { return DTOs_1.ListItemType.fromJS(listItemType); }); })
557
555
  .then(this.success())
558
556
  .catch(this.error());
559
557
  };
@@ -564,7 +562,7 @@ var BaseClient = /** @class */ (function () {
564
562
  */
565
563
  BaseClient.prototype.setComponentSettingsProfiles = function (returnedSettings) {
566
564
  return this.request('SetComponentSettingsProfiles', returnedSettings)
567
- .then(function (profileGroups) { return profileGroups.map(function (profileGroup) { return ProfileGroup.fromJS(profileGroup); }); })
565
+ .then(function (profileGroups) { return profileGroups.map(function (profileGroup) { return DTOs_1.ProfileGroup.fromJS(profileGroup); }); })
568
566
  .then(this.success())
569
567
  .catch(this.error());
570
568
  };
@@ -574,7 +572,7 @@ var BaseClient = /** @class */ (function () {
574
572
  */
575
573
  BaseClient.prototype.getComponentSettingsProfiles = function () {
576
574
  return this.request('GetComponentSettingsProfiles')
577
- .then(function (profileGroups) { return profileGroups.map(function (profileGroup) { return ProfileGroup.fromJS(profileGroup); }); })
575
+ .then(function (profileGroups) { return profileGroups.map(function (profileGroup) { return DTOs_1.ProfileGroup.fromJS(profileGroup); }); })
578
576
  .then(this.success())
579
577
  .catch(this.error());
580
578
  };
@@ -605,7 +603,7 @@ var BaseClient = /** @class */ (function () {
605
603
  */
606
604
  BaseClient.prototype.loadComponentSettingsFromRepository = function (packageReference) {
607
605
  return this.request('LoadComponentSettingsFromRepository', packageReference)
608
- .then(function (errorResponses) { return errorResponses.map(function (errorResponse) { return ErrorResponse.fromJS(errorResponse); }); })
606
+ .then(function (errorResponses) { return errorResponses.map(function (errorResponse) { return DTOs_1.ErrorResponse.fromJS(errorResponse); }); })
609
607
  .then(this.success())
610
608
  .catch(this.error());
611
609
  };
@@ -628,7 +626,7 @@ var BaseClient = /** @class */ (function () {
628
626
  BaseClient.prototype.getComponentSettingsListAvailableTypes = function (groupName, name) {
629
627
  var getComponentSettingsRequest = { groupName: groupName, name: name };
630
628
  return this.request('GetComponentSettingsListAvailableTypes', getComponentSettingsRequest)
631
- .then(function (listItemTypes) { return listItemTypes.map(function (listItemType) { return ListItemType.fromJS(listItemType); }); })
629
+ .then(function (listItemTypes) { return listItemTypes.map(function (listItemType) { return DTOs_1.ListItemType.fromJS(listItemType); }); })
632
630
  .then(this.success())
633
631
  .catch(this.error());
634
632
  };
@@ -642,7 +640,7 @@ var BaseClient = /** @class */ (function () {
642
640
  BaseClient.prototype.addComponentSettingsListItem = function (groupName, name, typeName) {
643
641
  var addComponentSettingsListItemRequest = { groupName: groupName, name: name, typeName: typeName };
644
642
  return this.request('AddComponentSettingsListItem', addComponentSettingsListItemRequest)
645
- .then(function (componentSettingsBase) { return ComponentSettingsBase.fromJS(componentSettingsBase); })
643
+ .then(function (componentSettingsBase) { return DTOs_1.ComponentSettingsBase.fromJS(componentSettingsBase); })
646
644
  .then(this.success())
647
645
  .catch(this.error());
648
646
  };
@@ -662,4 +660,4 @@ var BaseClient = /** @class */ (function () {
662
660
  };
663
661
  return BaseClient;
664
662
  }());
665
- export { BaseClient };
663
+ exports.BaseClient = BaseClient;