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

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;
@@ -22,9 +21,13 @@ export declare class BaseClient {
22
21
  /** Set request access token */
23
22
  set accessToken(value: string);
24
23
  /** Get request headers */
25
- get headers(): Headers;
24
+ get headers(): {
25
+ [key: string]: string;
26
+ };
26
27
  /** Set request headers */
27
- set headers(value: Headers);
28
+ set headers(value: {
29
+ [key: string]: string;
30
+ });
28
31
  /** Get timeout */
29
32
  get timeout(): number;
30
33
  /** Set timeout in milliseconds. Default is 40000 milliseconds */
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) {
@@ -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
  /**
@@ -262,21 +268,21 @@ var BaseClient = /** @class */ (function () {
262
268
  BaseClient.prototype.subscribe = function (subject, options) {
263
269
  if (!subject)
264
270
  throw Error('Subject is not defined!');
265
- if (!this.subscriptionConnection)
271
+ if (!this.connection)
266
272
  throw Error('Connection is not up yet! Please try again later!');
267
- if (this.subscriptionConnection.isClosed())
273
+ if (this.connection.isClosed())
268
274
  throw Error('Connection has been closed! Please reconnect!');
269
275
  var natsSubject = "".concat(this.baseSubject, ".").concat(subject);
270
- return this.subscriptionConnection.subscribe(natsSubject, options);
276
+ return this.connection.subscribe(natsSubject, options);
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,11 +302,9 @@ 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*/, Promise.all([connect(this.connectionOptions), connect(this.connectionOptions)])
300
- .then(function (_a) {
301
- var connection = _a[0], subscriptionConnection = _a[1];
305
+ return [4 /*yield*/, (0, nats_ws_1.connect)(this.connectionOptions)
306
+ .then(function (connection) {
302
307
  _this.connection = connection;
303
- _this.subscriptionConnection = subscriptionConnection;
304
308
  return Promise.resolve();
305
309
  })
306
310
  .catch(function (error) { return Promise.reject("Failed to connect to ".concat(_this.connectionOptions.servers, " with ").concat(error)); })];
@@ -317,24 +321,21 @@ var BaseClient = /** @class */ (function () {
317
321
  * Close the connection.
318
322
  */
319
323
  BaseClient.prototype.close = function () {
320
- var _a, _b;
324
+ var _a;
321
325
  return __awaiter(this, void 0, void 0, function () {
322
326
  var _this = this;
323
- return __generator(this, function (_c) {
324
- switch (_c.label) {
327
+ return __generator(this, function (_b) {
328
+ switch (_b.label) {
325
329
  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 () {
330
+ if (!this.connection) return [3 /*break*/, 2];
331
+ return [4 /*yield*/, ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.close().then(function () {
329
332
  _this.connection = null;
330
- _this.subscriptionConnection = null;
331
- })
332
- .catch(function (error) {
333
+ }).catch(function (error) {
333
334
  throw new Error("failed to close connection: ".concat(error));
334
- })];
335
+ }))];
335
336
  case 1:
336
- _c.sent();
337
- _c.label = 2;
337
+ _b.sent();
338
+ _b.label = 2;
338
339
  case 2: return [2 /*return*/];
339
340
  }
340
341
  });
@@ -391,7 +392,7 @@ var BaseClient = /** @class */ (function () {
391
392
  return this.request('GetComponentSettingsOverview')
392
393
  .then(function (componentSettingsIdentifiers) {
393
394
  return componentSettingsIdentifiers.map(function (componentSettingsIdentifier) {
394
- return ComponentSettingsIdentifier.fromJS(componentSettingsIdentifier);
395
+ return DTOs_1.ComponentSettingsIdentifier.fromJS(componentSettingsIdentifier);
395
396
  });
396
397
  })
397
398
  .then(this.success())
@@ -407,7 +408,7 @@ var BaseClient = /** @class */ (function () {
407
408
  BaseClient.prototype.setComponentSettings = function (groupName, name, returnedSettings) {
408
409
  var setComponentSettingsRequest = { groupName: groupName, name: name, returnedSettings: returnedSettings };
409
410
  return this.request('SetComponentSettings', setComponentSettingsRequest)
410
- .then(function (componentSettingsBase) { return ComponentSettingsBase.fromJS(componentSettingsBase); })
411
+ .then(function (componentSettingsBase) { return DTOs_1.ComponentSettingsBase.fromJS(componentSettingsBase); })
411
412
  .then(this.success())
412
413
  .catch(this.error());
413
414
  };
@@ -420,7 +421,7 @@ var BaseClient = /** @class */ (function () {
420
421
  BaseClient.prototype.getComponentSettings = function (groupName, name) {
421
422
  var getComponentSettingsRequest = { groupName: groupName, name: name };
422
423
  return this.request('GetComponentSettings', getComponentSettingsRequest)
423
- .then(function (componentSettingsBase) { return ComponentSettingsBase.fromJS(componentSettingsBase); })
424
+ .then(function (componentSettingsBase) { return DTOs_1.ComponentSettingsBase.fromJS(componentSettingsBase); })
424
425
  .then(this.success())
425
426
  .catch(this.error());
426
427
  };
@@ -434,7 +435,7 @@ var BaseClient = /** @class */ (function () {
434
435
  BaseClient.prototype.getComponentSettingsListItem = function (groupName, name, index) {
435
436
  var getComponentSettingsListItemRequest = { groupName: groupName, name: name, index: index };
436
437
  return this.request('GetComponentSettingsListItem', getComponentSettingsListItemRequest)
437
- .then(function (componentSettingsListItem) { return ComponentSettingsListItem.fromJS(componentSettingsListItem); })
438
+ .then(function (componentSettingsListItem) { return DTOs_1.ComponentSettingsListItem.fromJS(componentSettingsListItem); })
438
439
  .then(this.success())
439
440
  .catch(this.error());
440
441
  };
@@ -449,7 +450,7 @@ var BaseClient = /** @class */ (function () {
449
450
  BaseClient.prototype.setComponentSettingsListItem = function (groupName, name, index, item) {
450
451
  var setComponentSettingsListItemRequest = { groupName: groupName, name: name, index: index, item: item };
451
452
  return this.request('SetComponentSettingsListItem', setComponentSettingsListItemRequest)
452
- .then(function (componentSettingsListItem) { return ComponentSettingsListItem.fromJS(componentSettingsListItem); })
453
+ .then(function (componentSettingsListItem) { return DTOs_1.ComponentSettingsListItem.fromJS(componentSettingsListItem); })
453
454
  .then(this.success())
454
455
  .catch(this.error());
455
456
  };
@@ -469,7 +470,7 @@ var BaseClient = /** @class */ (function () {
469
470
  propertyName: propertyName,
470
471
  };
471
472
  return this.request('GetComponentSettingDataGrid', getComponentSettingDataGridRequest)
472
- .then(function (dataGridControl) { return DataGridControl.fromJS(dataGridControl); })
473
+ .then(function (dataGridControl) { return DTOs_1.DataGridControl.fromJS(dataGridControl); })
473
474
  .then(this.success())
474
475
  .catch(this.error());
475
476
  };
@@ -491,7 +492,7 @@ var BaseClient = /** @class */ (function () {
491
492
  dataGridControl: dataGridControl,
492
493
  };
493
494
  return this.request('SetComponentSettingDataGrid', setComponentSettingDataGridRequest)
494
- .then(function (dataGridControl) { return DataGridControl.fromJS(dataGridControl); })
495
+ .then(function (dataGridControl) { return DTOs_1.DataGridControl.fromJS(dataGridControl); })
495
496
  .then(this.success())
496
497
  .catch(this.error());
497
498
  };
@@ -513,7 +514,7 @@ var BaseClient = /** @class */ (function () {
513
514
  typeName: typeName,
514
515
  };
515
516
  return this.request('AddComponentSettingDataGridItemType', addComponentSettingDataGridItemTypeRequest)
516
- .then(function (dataGridControl) { return DataGridControl.fromJS(dataGridControl); })
517
+ .then(function (dataGridControl) { return DTOs_1.DataGridControl.fromJS(dataGridControl); })
517
518
  .then(this.success())
518
519
  .catch(this.error());
519
520
  };
@@ -533,7 +534,7 @@ var BaseClient = /** @class */ (function () {
533
534
  propertyName: propertyName,
534
535
  };
535
536
  return this.request('AddComponentSettingDataGridItem', getComponentSettingDataGridRequest)
536
- .then(function (dataGridControl) { return DataGridControl.fromJS(dataGridControl); })
537
+ .then(function (dataGridControl) { return DTOs_1.DataGridControl.fromJS(dataGridControl); })
537
538
  .then(this.success())
538
539
  .catch(this.error());
539
540
  };
@@ -553,7 +554,7 @@ var BaseClient = /** @class */ (function () {
553
554
  propertyName: propertyName,
554
555
  };
555
556
  return this.request('GetComponentSettingDataGridTypes', getComponentSettingDataGridRequest)
556
- .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); }); })
557
558
  .then(this.success())
558
559
  .catch(this.error());
559
560
  };
@@ -564,7 +565,7 @@ var BaseClient = /** @class */ (function () {
564
565
  */
565
566
  BaseClient.prototype.setComponentSettingsProfiles = function (returnedSettings) {
566
567
  return this.request('SetComponentSettingsProfiles', returnedSettings)
567
- .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); }); })
568
569
  .then(this.success())
569
570
  .catch(this.error());
570
571
  };
@@ -574,7 +575,7 @@ var BaseClient = /** @class */ (function () {
574
575
  */
575
576
  BaseClient.prototype.getComponentSettingsProfiles = function () {
576
577
  return this.request('GetComponentSettingsProfiles')
577
- .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); }); })
578
579
  .then(this.success())
579
580
  .catch(this.error());
580
581
  };
@@ -605,7 +606,7 @@ var BaseClient = /** @class */ (function () {
605
606
  */
606
607
  BaseClient.prototype.loadComponentSettingsFromRepository = function (packageReference) {
607
608
  return this.request('LoadComponentSettingsFromRepository', packageReference)
608
- .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); }); })
609
610
  .then(this.success())
610
611
  .catch(this.error());
611
612
  };
@@ -628,7 +629,7 @@ var BaseClient = /** @class */ (function () {
628
629
  BaseClient.prototype.getComponentSettingsListAvailableTypes = function (groupName, name) {
629
630
  var getComponentSettingsRequest = { groupName: groupName, name: name };
630
631
  return this.request('GetComponentSettingsListAvailableTypes', getComponentSettingsRequest)
631
- .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); }); })
632
633
  .then(this.success())
633
634
  .catch(this.error());
634
635
  };
@@ -642,7 +643,7 @@ var BaseClient = /** @class */ (function () {
642
643
  BaseClient.prototype.addComponentSettingsListItem = function (groupName, name, typeName) {
643
644
  var addComponentSettingsListItemRequest = { groupName: groupName, name: name, typeName: typeName };
644
645
  return this.request('AddComponentSettingsListItem', addComponentSettingsListItemRequest)
645
- .then(function (componentSettingsBase) { return ComponentSettingsBase.fromJS(componentSettingsBase); })
646
+ .then(function (componentSettingsBase) { return DTOs_1.ComponentSettingsBase.fromJS(componentSettingsBase); })
646
647
  .then(this.success())
647
648
  .catch(this.error());
648
649
  };
@@ -662,4 +663,4 @@ var BaseClient = /** @class */ (function () {
662
663
  };
663
664
  return BaseClient;
664
665
  }());
665
- export { BaseClient };
666
+ exports.BaseClient = BaseClient;