@opentap/runner-client 2.19.0-alpha.1.9 → 2.19.0-alpha.2.10.8328217069

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.
@@ -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) {
@@ -57,11 +60,11 @@ var Events;
57
60
  var BaseClient = /** @class */ (function () {
58
61
  function BaseClient(baseSubject, options) {
59
62
  this.domainAccess = new Map();
60
- this._headers = new Headers();
63
+ this._headers = {};
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:
@@ -246,11 +249,14 @@ var BaseClient = /** @class */ (function () {
246
249
  * @returns {MsgHdrs} Header object
247
250
  */
248
251
  BaseClient.prototype.buildHeaders = function () {
249
- var _a, _b;
250
- var _headers = headers();
252
+ var _a;
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
- (_b = this._headers) === null || _b === void 0 ? void 0 : _b.forEach(function (value, key) { return _headers.append(key, value); });
256
+ Object.entries(this._headers).forEach(function (_a) {
257
+ var key = _a[0], value = _a[1];
258
+ return _headers.append(key, value);
259
+ });
254
260
  return _headers;
255
261
  };
256
262
  /**
@@ -271,12 +277,12 @@ var BaseClient = /** @class */ (function () {
271
277
  };
272
278
  BaseClient.prototype.encode = function (payload) {
273
279
  if (!payload) {
274
- return Empty;
280
+ return nats_ws_1.Empty;
275
281
  }
276
282
  if (payload instanceof Uint8Array) {
277
283
  return payload;
278
284
  }
279
- return StringCodec().encode(JSON.stringify(payload));
285
+ return (0, nats_ws_1.StringCodec)().encode(JSON.stringify(payload));
280
286
  };
281
287
  /**
282
288
  * Create a connection to the nats server.
@@ -296,7 +302,7 @@ var BaseClient = /** @class */ (function () {
296
302
  _a.label = 1;
297
303
  case 1:
298
304
  _a.trys.push([1, 3, , 4]);
299
- return [4 /*yield*/, connect(this.connectionOptions)
305
+ return [4 /*yield*/, (0, nats_ws_1.connect)(this.connectionOptions)
300
306
  .then(function (connection) {
301
307
  _this.connection = connection;
302
308
  return Promise.resolve();
@@ -386,7 +392,7 @@ var BaseClient = /** @class */ (function () {
386
392
  return this.request('GetComponentSettingsOverview')
387
393
  .then(function (componentSettingsIdentifiers) {
388
394
  return componentSettingsIdentifiers.map(function (componentSettingsIdentifier) {
389
- return ComponentSettingsIdentifier.fromJS(componentSettingsIdentifier);
395
+ return DTOs_1.ComponentSettingsIdentifier.fromJS(componentSettingsIdentifier);
390
396
  });
391
397
  })
392
398
  .then(this.success())
@@ -402,7 +408,7 @@ var BaseClient = /** @class */ (function () {
402
408
  BaseClient.prototype.setComponentSettings = function (groupName, name, returnedSettings) {
403
409
  var setComponentSettingsRequest = { groupName: groupName, name: name, returnedSettings: returnedSettings };
404
410
  return this.request('SetComponentSettings', setComponentSettingsRequest)
405
- .then(function (componentSettingsBase) { return ComponentSettingsBase.fromJS(componentSettingsBase); })
411
+ .then(function (componentSettingsBase) { return DTOs_1.ComponentSettingsBase.fromJS(componentSettingsBase); })
406
412
  .then(this.success())
407
413
  .catch(this.error());
408
414
  };
@@ -415,7 +421,7 @@ var BaseClient = /** @class */ (function () {
415
421
  BaseClient.prototype.getComponentSettings = function (groupName, name) {
416
422
  var getComponentSettingsRequest = { groupName: groupName, name: name };
417
423
  return this.request('GetComponentSettings', getComponentSettingsRequest)
418
- .then(function (componentSettingsBase) { return ComponentSettingsBase.fromJS(componentSettingsBase); })
424
+ .then(function (componentSettingsBase) { return DTOs_1.ComponentSettingsBase.fromJS(componentSettingsBase); })
419
425
  .then(this.success())
420
426
  .catch(this.error());
421
427
  };
@@ -429,7 +435,7 @@ var BaseClient = /** @class */ (function () {
429
435
  BaseClient.prototype.getComponentSettingsListItem = function (groupName, name, index) {
430
436
  var getComponentSettingsListItemRequest = { groupName: groupName, name: name, index: index };
431
437
  return this.request('GetComponentSettingsListItem', getComponentSettingsListItemRequest)
432
- .then(function (componentSettingsListItem) { return ComponentSettingsListItem.fromJS(componentSettingsListItem); })
438
+ .then(function (componentSettingsListItem) { return DTOs_1.ComponentSettingsListItem.fromJS(componentSettingsListItem); })
433
439
  .then(this.success())
434
440
  .catch(this.error());
435
441
  };
@@ -444,7 +450,7 @@ var BaseClient = /** @class */ (function () {
444
450
  BaseClient.prototype.setComponentSettingsListItem = function (groupName, name, index, item) {
445
451
  var setComponentSettingsListItemRequest = { groupName: groupName, name: name, index: index, item: item };
446
452
  return this.request('SetComponentSettingsListItem', setComponentSettingsListItemRequest)
447
- .then(function (componentSettingsListItem) { return ComponentSettingsListItem.fromJS(componentSettingsListItem); })
453
+ .then(function (componentSettingsListItem) { return DTOs_1.ComponentSettingsListItem.fromJS(componentSettingsListItem); })
448
454
  .then(this.success())
449
455
  .catch(this.error());
450
456
  };
@@ -464,7 +470,7 @@ var BaseClient = /** @class */ (function () {
464
470
  propertyName: propertyName,
465
471
  };
466
472
  return this.request('GetComponentSettingDataGrid', getComponentSettingDataGridRequest)
467
- .then(function (dataGridControl) { return DataGridControl.fromJS(dataGridControl); })
473
+ .then(function (dataGridControl) { return DTOs_1.DataGridControl.fromJS(dataGridControl); })
468
474
  .then(this.success())
469
475
  .catch(this.error());
470
476
  };
@@ -486,7 +492,7 @@ var BaseClient = /** @class */ (function () {
486
492
  dataGridControl: dataGridControl,
487
493
  };
488
494
  return this.request('SetComponentSettingDataGrid', setComponentSettingDataGridRequest)
489
- .then(function (dataGridControl) { return DataGridControl.fromJS(dataGridControl); })
495
+ .then(function (dataGridControl) { return DTOs_1.DataGridControl.fromJS(dataGridControl); })
490
496
  .then(this.success())
491
497
  .catch(this.error());
492
498
  };
@@ -508,7 +514,7 @@ var BaseClient = /** @class */ (function () {
508
514
  typeName: typeName,
509
515
  };
510
516
  return this.request('AddComponentSettingDataGridItemType', addComponentSettingDataGridItemTypeRequest)
511
- .then(function (dataGridControl) { return DataGridControl.fromJS(dataGridControl); })
517
+ .then(function (dataGridControl) { return DTOs_1.DataGridControl.fromJS(dataGridControl); })
512
518
  .then(this.success())
513
519
  .catch(this.error());
514
520
  };
@@ -528,7 +534,7 @@ var BaseClient = /** @class */ (function () {
528
534
  propertyName: propertyName,
529
535
  };
530
536
  return this.request('AddComponentSettingDataGridItem', getComponentSettingDataGridRequest)
531
- .then(function (dataGridControl) { return DataGridControl.fromJS(dataGridControl); })
537
+ .then(function (dataGridControl) { return DTOs_1.DataGridControl.fromJS(dataGridControl); })
532
538
  .then(this.success())
533
539
  .catch(this.error());
534
540
  };
@@ -548,7 +554,7 @@ var BaseClient = /** @class */ (function () {
548
554
  propertyName: propertyName,
549
555
  };
550
556
  return this.request('GetComponentSettingDataGridTypes', getComponentSettingDataGridRequest)
551
- .then(function (listItemTypes) { return listItemTypes.map(function (listItemType) { return ListItemType.fromJS(listItemType); }); })
557
+ .then(function (listItemTypes) { return listItemTypes.map(function (listItemType) { return DTOs_1.ListItemType.fromJS(listItemType); }); })
552
558
  .then(this.success())
553
559
  .catch(this.error());
554
560
  };
@@ -559,7 +565,7 @@ var BaseClient = /** @class */ (function () {
559
565
  */
560
566
  BaseClient.prototype.setComponentSettingsProfiles = function (returnedSettings) {
561
567
  return this.request('SetComponentSettingsProfiles', returnedSettings)
562
- .then(function (profileGroups) { return profileGroups.map(function (profileGroup) { return ProfileGroup.fromJS(profileGroup); }); })
568
+ .then(function (profileGroups) { return profileGroups.map(function (profileGroup) { return DTOs_1.ProfileGroup.fromJS(profileGroup); }); })
563
569
  .then(this.success())
564
570
  .catch(this.error());
565
571
  };
@@ -569,7 +575,7 @@ var BaseClient = /** @class */ (function () {
569
575
  */
570
576
  BaseClient.prototype.getComponentSettingsProfiles = function () {
571
577
  return this.request('GetComponentSettingsProfiles')
572
- .then(function (profileGroups) { return profileGroups.map(function (profileGroup) { return ProfileGroup.fromJS(profileGroup); }); })
578
+ .then(function (profileGroups) { return profileGroups.map(function (profileGroup) { return DTOs_1.ProfileGroup.fromJS(profileGroup); }); })
573
579
  .then(this.success())
574
580
  .catch(this.error());
575
581
  };
@@ -600,7 +606,7 @@ var BaseClient = /** @class */ (function () {
600
606
  */
601
607
  BaseClient.prototype.loadComponentSettingsFromRepository = function (packageReference) {
602
608
  return this.request('LoadComponentSettingsFromRepository', packageReference)
603
- .then(function (errorResponses) { return errorResponses.map(function (errorResponse) { return ErrorResponse.fromJS(errorResponse); }); })
609
+ .then(function (errorResponses) { return errorResponses.map(function (errorResponse) { return DTOs_1.ErrorResponse.fromJS(errorResponse); }); })
604
610
  .then(this.success())
605
611
  .catch(this.error());
606
612
  };
@@ -623,7 +629,7 @@ var BaseClient = /** @class */ (function () {
623
629
  BaseClient.prototype.getComponentSettingsListAvailableTypes = function (groupName, name) {
624
630
  var getComponentSettingsRequest = { groupName: groupName, name: name };
625
631
  return this.request('GetComponentSettingsListAvailableTypes', getComponentSettingsRequest)
626
- .then(function (listItemTypes) { return listItemTypes.map(function (listItemType) { return ListItemType.fromJS(listItemType); }); })
632
+ .then(function (listItemTypes) { return listItemTypes.map(function (listItemType) { return DTOs_1.ListItemType.fromJS(listItemType); }); })
627
633
  .then(this.success())
628
634
  .catch(this.error());
629
635
  };
@@ -637,7 +643,7 @@ var BaseClient = /** @class */ (function () {
637
643
  BaseClient.prototype.addComponentSettingsListItem = function (groupName, name, typeName) {
638
644
  var addComponentSettingsListItemRequest = { groupName: groupName, name: name, typeName: typeName };
639
645
  return this.request('AddComponentSettingsListItem', addComponentSettingsListItemRequest)
640
- .then(function (componentSettingsBase) { return ComponentSettingsBase.fromJS(componentSettingsBase); })
646
+ .then(function (componentSettingsBase) { return DTOs_1.ComponentSettingsBase.fromJS(componentSettingsBase); })
641
647
  .then(this.success())
642
648
  .catch(this.error());
643
649
  };
@@ -657,4 +663,4 @@ var BaseClient = /** @class */ (function () {
657
663
  };
658
664
  return BaseClient;
659
665
  }());
660
- export { BaseClient };
666
+ exports.BaseClient = BaseClient;