@opentap/runner-client 2.25.1 → 2.25.2-alpha.1.2.11280720052

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.
@@ -25,11 +25,55 @@ var __assign = (this && this.__assign) || function () {
25
25
  };
26
26
  return __assign.apply(this, arguments);
27
27
  };
28
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
+ return new (P || (P = Promise))(function (resolve, reject) {
31
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
35
+ });
36
+ };
37
+ var __generator = (this && this.__generator) || function (thisArg, body) {
38
+ var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
+ return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
+ function verb(n) { return function (v) { return step([n, v]); }; }
41
+ function step(op) {
42
+ if (f) throw new TypeError("Generator is already executing.");
43
+ while (_) try {
44
+ 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;
45
+ if (y = 0, t) op = [op[0] & 2, t.value];
46
+ switch (op[0]) {
47
+ case 0: case 1: t = op; break;
48
+ case 4: _.label++; return { value: op[1], done: false };
49
+ case 5: _.label++; y = op[1]; op = [0]; continue;
50
+ case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
+ default:
52
+ if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
+ if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
+ if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
+ if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
+ if (t[2]) _.ops.pop();
57
+ _.trys.pop(); continue;
58
+ }
59
+ op = body.call(thisArg, _);
60
+ } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
+ if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
+ }
63
+ };
64
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
65
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
66
+ var m = o[Symbol.asyncIterator], i;
67
+ 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);
68
+ 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); }); }; }
69
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
70
+ };
28
71
  Object.defineProperty(exports, "__esModule", { value: true });
29
72
  exports.RunnerClient = void 0;
30
73
  var nats_ws_1 = require("nats.ws");
31
74
  var DTOs_1 = require("./DTOs");
32
75
  var BaseClient_1 = require("./BaseClient");
76
+ var utils_1 = require("./utils");
33
77
  var RunnerClient = /** @class */ (function (_super) {
34
78
  __extends(RunnerClient, _super);
35
79
  function RunnerClient(baseSubject, options) {
@@ -92,6 +136,7 @@ var RunnerClient = /** @class */ (function (_super) {
92
136
  return _this.request('SetDefaultSettings', repositoryPackageReference).then(_this.success()).catch(_this.error());
93
137
  },
94
138
  };
139
+ _this.runnerId = (0, utils_1.getSubjectParts)(baseSubject).runnerId;
95
140
  return _this;
96
141
  }
97
142
  /**
@@ -235,6 +280,121 @@ var RunnerClient = /** @class */ (function (_super) {
235
280
  }
236
281
  } }));
237
282
  };
283
+ /**
284
+ * Connect to metrics published for the given SessionMetricInfo from the idle session
285
+ * @param {ISessionMetricInfo} metricInfo
286
+ * @param {(result:MetricValue|undefined,err:NatsError|Error|null)=>void} handler
287
+ * @param {SubscriptionOptions} options?
288
+ * @returns Subscription
289
+ */
290
+ RunnerClient.prototype.connectMetric = function (metricInfo, inactiveThresholdMilliseconds, maxBatchSize, handler) {
291
+ var _this = this;
292
+ return this.createJetStreamConsumer('Metrics', "M.".concat(metricInfo.subjectPostfix), {
293
+ domain: this.runnerId,
294
+ }, { inactive_threshold: (0, nats_ws_1.nanos)(inactiveThresholdMilliseconds) }).then(function (consumer) {
295
+ var isCloseInitiated = false;
296
+ var deleteConsumer = consumer.delete.bind(consumer);
297
+ consumer.delete = function () {
298
+ isCloseInitiated = true;
299
+ return deleteConsumer();
300
+ };
301
+ // Async function here so the loop starts without blocking returning a consumer
302
+ (function () { return __awaiter(_this, void 0, void 0, function () {
303
+ var _loop_1, state_1;
304
+ var _this = this;
305
+ var e_1, _a;
306
+ return __generator(this, function (_b) {
307
+ switch (_b.label) {
308
+ case 0:
309
+ _loop_1 = function () {
310
+ var consumerInfo, arraySize, metricData_1, messages, index, messages_1, messages_1_1, message, e_1_1, error_1, error_2;
311
+ return __generator(this, function (_c) {
312
+ switch (_c.label) {
313
+ case 0:
314
+ _c.trys.push([0, 18, , 19]);
315
+ return [4 /*yield*/, consumer.info()];
316
+ case 1:
317
+ consumerInfo = _c.sent();
318
+ arraySize = Math.min(maxBatchSize, consumerInfo.num_pending);
319
+ metricData_1 = {
320
+ encodedMetrics: new Array(arraySize),
321
+ timestamps: new Array(arraySize),
322
+ };
323
+ _c.label = 2;
324
+ case 2:
325
+ _c.trys.push([2, 16, , 17]);
326
+ return [4 /*yield*/, consumer.fetch({ max_messages: arraySize })];
327
+ case 3:
328
+ messages = _c.sent();
329
+ index = 0;
330
+ _c.label = 4;
331
+ case 4:
332
+ _c.trys.push([4, 9, 10, 15]);
333
+ messages_1 = (e_1 = void 0, __asyncValues(messages));
334
+ _c.label = 5;
335
+ case 5: return [4 /*yield*/, messages_1.next()];
336
+ case 6:
337
+ if (!(messages_1_1 = _c.sent(), !messages_1_1.done)) return [3 /*break*/, 8];
338
+ message = messages_1_1.value;
339
+ // Store the message data and timestamp
340
+ metricData_1.encodedMetrics[index] = message.data;
341
+ metricData_1.timestamps[index] = message.info.timestampNanos;
342
+ // If we are at the last message or there are no more pending messages, call the handler
343
+ if (index === arraySize - 1 || message.info.pending === 0) {
344
+ (function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
345
+ return [2 /*return*/, handler(metricData_1)];
346
+ }); }); })();
347
+ return [3 /*break*/, 8];
348
+ }
349
+ // Increment the index
350
+ index++;
351
+ _c.label = 7;
352
+ case 7: return [3 /*break*/, 5];
353
+ case 8: return [3 /*break*/, 15];
354
+ case 9:
355
+ e_1_1 = _c.sent();
356
+ e_1 = { error: e_1_1 };
357
+ return [3 /*break*/, 15];
358
+ case 10:
359
+ _c.trys.push([10, , 13, 14]);
360
+ if (!(messages_1_1 && !messages_1_1.done && (_a = messages_1.return))) return [3 /*break*/, 12];
361
+ return [4 /*yield*/, _a.call(messages_1)];
362
+ case 11:
363
+ _c.sent();
364
+ _c.label = 12;
365
+ case 12: return [3 /*break*/, 14];
366
+ case 13:
367
+ if (e_1) throw e_1.error;
368
+ return [7 /*endfinally*/];
369
+ case 14: return [7 /*endfinally*/];
370
+ case 15: return [3 /*break*/, 17];
371
+ case 16:
372
+ error_1 = _c.sent();
373
+ return [2 /*return*/, "break"];
374
+ case 17: return [3 /*break*/, 19];
375
+ case 18:
376
+ error_2 = _c.sent();
377
+ return [2 /*return*/, "break"];
378
+ case 19: return [2 /*return*/];
379
+ }
380
+ });
381
+ };
382
+ _b.label = 1;
383
+ case 1:
384
+ if (!!isCloseInitiated) return [3 /*break*/, 3];
385
+ return [5 /*yield**/, _loop_1()];
386
+ case 2:
387
+ state_1 = _b.sent();
388
+ if (state_1 === "break")
389
+ return [3 /*break*/, 3];
390
+ return [3 /*break*/, 1];
391
+ case 3: return [2 /*return*/];
392
+ }
393
+ });
394
+ }); })();
395
+ return consumer;
396
+ });
397
+ };
238
398
  return RunnerClient;
239
399
  }(BaseClient_1.BaseClient));
240
400
  exports.RunnerClient = RunnerClient;
@@ -25,61 +25,16 @@ var __assign = (this && this.__assign) || function () {
25
25
  };
26
26
  return __assign.apply(this, arguments);
27
27
  };
28
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
29
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
30
- return new (P || (P = Promise))(function (resolve, reject) {
31
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
32
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
33
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
34
- step((generator = generator.apply(thisArg, _arguments || [])).next());
35
- });
36
- };
37
- var __generator = (this && this.__generator) || function (thisArg, body) {
38
- var _ = { label: 0, sent: function() { if (t[0] & 1) throw t[1]; return t[1]; }, trys: [], ops: [] }, f, y, t, g;
39
- return g = { next: verb(0), "throw": verb(1), "return": verb(2) }, typeof Symbol === "function" && (g[Symbol.iterator] = function() { return this; }), g;
40
- function verb(n) { return function (v) { return step([n, v]); }; }
41
- function step(op) {
42
- if (f) throw new TypeError("Generator is already executing.");
43
- while (_) try {
44
- 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;
45
- if (y = 0, t) op = [op[0] & 2, t.value];
46
- switch (op[0]) {
47
- case 0: case 1: t = op; break;
48
- case 4: _.label++; return { value: op[1], done: false };
49
- case 5: _.label++; y = op[1]; op = [0]; continue;
50
- case 7: op = _.ops.pop(); _.trys.pop(); continue;
51
- default:
52
- if (!(t = _.trys, t = t.length > 0 && t[t.length - 1]) && (op[0] === 6 || op[0] === 2)) { _ = 0; continue; }
53
- if (op[0] === 3 && (!t || (op[1] > t[0] && op[1] < t[3]))) { _.label = op[1]; break; }
54
- if (op[0] === 6 && _.label < t[1]) { _.label = t[1]; t = op; break; }
55
- if (t && _.label < t[2]) { _.label = t[2]; _.ops.push(op); break; }
56
- if (t[2]) _.ops.pop();
57
- _.trys.pop(); continue;
58
- }
59
- op = body.call(thisArg, _);
60
- } catch (e) { op = [6, e]; y = 0; } finally { f = t = 0; }
61
- if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
62
- }
63
- };
64
- var __asyncValues = (this && this.__asyncValues) || function (o) {
65
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
66
- var m = o[Symbol.asyncIterator], i;
67
- 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);
68
- 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); }); }; }
69
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
70
- };
71
28
  Object.defineProperty(exports, "__esModule", { value: true });
72
29
  exports.SessionClient = void 0;
73
30
  var DTOs_1 = require("./DTOs");
74
31
  var nats_ws_1 = require("nats.ws");
75
32
  var BaseClient_1 = require("./BaseClient");
76
- var utils_1 = require("./utils");
77
33
  var SessionClient = /** @class */ (function (_super) {
78
34
  __extends(SessionClient, _super);
79
35
  function SessionClient(baseSubject, options) {
80
36
  var _this = _super.call(this, baseSubject, options) || this;
81
37
  _this.subscriptions = [];
82
- _this.runnerId = (0, utils_1.getSubjectParts)(baseSubject).runnerId;
83
38
  return _this;
84
39
  }
85
40
  /**
@@ -340,120 +295,6 @@ var SessionClient = /** @class */ (function (_super) {
340
295
  }
341
296
  } }));
342
297
  };
343
- /**
344
- * Connect to metrics published for the given SessionMetricInfo
345
- * @param {ISessionMetricInfo} metricInfo
346
- * @param {(result:MetricValue|undefined,err:NatsError|Error|null)=>void} handler
347
- * @param {SubscriptionOptions} options?
348
- * @returns Subscription
349
- */
350
- SessionClient.prototype.connectMetric = function (metricInfo, inactiveThresholdMilliseconds, maxBatchSize, handler) {
351
- var _this = this;
352
- return this.createJetStreamConsumer('Metrics', "M.".concat(metricInfo.subjectPostfix), {
353
- domain: this.runnerId,
354
- }, { inactive_threshold: (0, nats_ws_1.nanos)(inactiveThresholdMilliseconds) }).then(function (consumer) {
355
- var isCloseInitiated = false;
356
- var deleteConsumer = consumer.delete.bind(consumer);
357
- consumer.delete = function () {
358
- isCloseInitiated = true;
359
- return deleteConsumer();
360
- };
361
- // Async function here so the loop starts without blocking returning a consumer
362
- (function () { return __awaiter(_this, void 0, void 0, function () {
363
- var _loop_1, state_1;
364
- var _this = this;
365
- var e_1, _a;
366
- return __generator(this, function (_b) {
367
- switch (_b.label) {
368
- case 0:
369
- _loop_1 = function () {
370
- var consumerInfo, arraySize, metricData_1, messages, index, messages_1, messages_1_1, message, e_1_1, error_1, error_2;
371
- return __generator(this, function (_c) {
372
- switch (_c.label) {
373
- case 0:
374
- _c.trys.push([0, 18, , 19]);
375
- return [4 /*yield*/, consumer.info()];
376
- case 1:
377
- consumerInfo = _c.sent();
378
- arraySize = Math.min(maxBatchSize, consumerInfo.num_pending);
379
- metricData_1 = {
380
- encodedMetrics: new Array(arraySize),
381
- timestamps: new Array(arraySize),
382
- };
383
- _c.label = 2;
384
- case 2:
385
- _c.trys.push([2, 16, , 17]);
386
- return [4 /*yield*/, consumer.fetch({ max_messages: arraySize })];
387
- case 3:
388
- messages = _c.sent();
389
- index = 0;
390
- _c.label = 4;
391
- case 4:
392
- _c.trys.push([4, 9, 10, 15]);
393
- messages_1 = (e_1 = void 0, __asyncValues(messages));
394
- _c.label = 5;
395
- case 5: return [4 /*yield*/, messages_1.next()];
396
- case 6:
397
- if (!(messages_1_1 = _c.sent(), !messages_1_1.done)) return [3 /*break*/, 8];
398
- message = messages_1_1.value;
399
- // Store the message data and timestamp
400
- metricData_1.encodedMetrics[index] = message.data;
401
- metricData_1.timestamps[index] = message.info.timestampNanos;
402
- // If we are at the last message or there are no more pending messages, call the handler
403
- if (index === arraySize - 1 || message.info.pending === 0) {
404
- (function () { return __awaiter(_this, void 0, void 0, function () { return __generator(this, function (_a) {
405
- return [2 /*return*/, handler(metricData_1)];
406
- }); }); })();
407
- }
408
- // Increment the index
409
- index++;
410
- _c.label = 7;
411
- case 7: return [3 /*break*/, 5];
412
- case 8: return [3 /*break*/, 15];
413
- case 9:
414
- e_1_1 = _c.sent();
415
- e_1 = { error: e_1_1 };
416
- return [3 /*break*/, 15];
417
- case 10:
418
- _c.trys.push([10, , 13, 14]);
419
- if (!(messages_1_1 && !messages_1_1.done && (_a = messages_1.return))) return [3 /*break*/, 12];
420
- return [4 /*yield*/, _a.call(messages_1)];
421
- case 11:
422
- _c.sent();
423
- _c.label = 12;
424
- case 12: return [3 /*break*/, 14];
425
- case 13:
426
- if (e_1) throw e_1.error;
427
- return [7 /*endfinally*/];
428
- case 14: return [7 /*endfinally*/];
429
- case 15: return [3 /*break*/, 17];
430
- case 16:
431
- error_1 = _c.sent();
432
- return [2 /*return*/, "break"];
433
- case 17: return [3 /*break*/, 19];
434
- case 18:
435
- error_2 = _c.sent();
436
- return [2 /*return*/, "break"];
437
- case 19: return [2 /*return*/];
438
- }
439
- });
440
- };
441
- _b.label = 1;
442
- case 1:
443
- if (!!isCloseInitiated) return [3 /*break*/, 3];
444
- return [5 /*yield**/, _loop_1()];
445
- case 2:
446
- state_1 = _b.sent();
447
- if (state_1 === "break")
448
- return [3 /*break*/, 3];
449
- return [3 /*break*/, 1];
450
- case 3: return [2 /*return*/];
451
- }
452
- });
453
- }); })();
454
- return consumer;
455
- });
456
- };
457
298
  /**
458
299
  * Unsubscibe from session events
459
300
  */
@@ -1,8 +1,9 @@
1
- import { ConnectionOptions, NatsError, Subscription, SubscriptionOptions } from 'nats.ws';
1
+ import { ConnectionOptions, Consumer, NatsError, Subscription, SubscriptionOptions } from 'nats.ws';
2
2
  import { RunnerUpdateRequest } from './requestDTOs';
3
- import { ISession, Image, MetadataUpdatedEvent, RepositoryPackageReference, Session } from './DTOs';
3
+ import { ISession, ISessionMetricInfo, Image, MetadataUpdatedEvent, RepositoryPackageReference, Session } from './DTOs';
4
4
  import { BaseClient } from './BaseClient';
5
5
  export declare class RunnerClient extends BaseClient {
6
+ private runnerId;
6
7
  default: {
7
8
  startSession: (testPlanRepositoryReference?: RepositoryPackageReference, timeout?: number) => Promise<Session>;
8
9
  startSessionWithOverriddenImage: (testPlanReference?: RepositoryPackageReference, imageOverride?: Image, timeout?: number) => Promise<Session>;
@@ -78,4 +79,15 @@ export declare class RunnerClient extends BaseClient {
78
79
  * @returns Subscription
79
80
  */
80
81
  connectMetadataUpdatedEvents(handler: (event: MetadataUpdatedEvent | undefined, err: NatsError | Error | null) => void, options?: SubscriptionOptions): Subscription;
82
+ /**
83
+ * Connect to metrics published for the given SessionMetricInfo from the idle session
84
+ * @param {ISessionMetricInfo} metricInfo
85
+ * @param {(result:MetricValue|undefined,err:NatsError|Error|null)=>void} handler
86
+ * @param {SubscriptionOptions} options?
87
+ * @returns Subscription
88
+ */
89
+ connectMetric(metricInfo: ISessionMetricInfo, inactiveThresholdMilliseconds: number, maxBatchSize: number, handler: (metricData: {
90
+ encodedMetrics: Uint8Array[];
91
+ timestamps: number[];
92
+ }) => void): Promise<Consumer>;
81
93
  }
@@ -1,6 +1,23 @@
1
- import { JSONCodec } from 'nats.ws';
1
+ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
+ function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
+ return new (P || (P = Promise))(function (resolve, reject) {
4
+ function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
+ function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
+ function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
+ step((generator = generator.apply(thisArg, _arguments || [])).next());
8
+ });
9
+ };
10
+ var __asyncValues = (this && this.__asyncValues) || function (o) {
11
+ if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
12
+ var m = o[Symbol.asyncIterator], i;
13
+ 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);
14
+ 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); }); }; }
15
+ function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
16
+ };
17
+ import { JSONCodec, nanos } from 'nats.ws';
2
18
  import { Image, MetadataUpdatedEvent, RepositoryPackageReference, Session, } from './DTOs';
3
19
  import { BaseClient } from './BaseClient';
20
+ import { getSubjectParts } from './utils';
4
21
  export class RunnerClient extends BaseClient {
5
22
  constructor(baseSubject, options) {
6
23
  super(baseSubject, options);
@@ -60,6 +77,7 @@ export class RunnerClient extends BaseClient {
60
77
  return this.request('SetDefaultSettings', repositoryPackageReference).then(this.success()).catch(this.error());
61
78
  },
62
79
  };
80
+ this.runnerId = getSubjectParts(baseSubject).runnerId;
63
81
  }
64
82
  /**
65
83
  * Get the created image with the specified ID.
@@ -202,4 +220,76 @@ export class RunnerClient extends BaseClient {
202
220
  }
203
221
  } }));
204
222
  }
223
+ /**
224
+ * Connect to metrics published for the given SessionMetricInfo from the idle session
225
+ * @param {ISessionMetricInfo} metricInfo
226
+ * @param {(result:MetricValue|undefined,err:NatsError|Error|null)=>void} handler
227
+ * @param {SubscriptionOptions} options?
228
+ * @returns Subscription
229
+ */
230
+ connectMetric(metricInfo, inactiveThresholdMilliseconds, maxBatchSize, handler) {
231
+ return this.createJetStreamConsumer('Metrics', `M.${metricInfo.subjectPostfix}`, {
232
+ domain: this.runnerId,
233
+ }, { inactive_threshold: nanos(inactiveThresholdMilliseconds) }).then(consumer => {
234
+ let isCloseInitiated = false;
235
+ const deleteConsumer = consumer.delete.bind(consumer);
236
+ consumer.delete = () => {
237
+ isCloseInitiated = true;
238
+ return deleteConsumer();
239
+ };
240
+ // Async function here so the loop starts without blocking returning a consumer
241
+ (() => __awaiter(this, void 0, void 0, function* () {
242
+ var e_1, _a;
243
+ // eslint-disable-next-line no-constant-condition
244
+ while (!isCloseInitiated) {
245
+ try {
246
+ // Get the consumer info to determine the number of pending messages
247
+ const consumerInfo = yield consumer.info();
248
+ // We want to define the batch size based on how many message we will consume in the next fetch
249
+ const arraySize = Math.min(maxBatchSize, consumerInfo.num_pending);
250
+ // Create the object with preallocated arrays for better performance
251
+ const metricData = {
252
+ encodedMetrics: new Array(arraySize),
253
+ timestamps: new Array(arraySize),
254
+ };
255
+ try {
256
+ // Fetch the messages
257
+ const messages = yield consumer.fetch({ max_messages: arraySize });
258
+ // for await of doesn't return the index, so we need to keep track of it
259
+ let index = 0;
260
+ try {
261
+ for (var messages_1 = (e_1 = void 0, __asyncValues(messages)), messages_1_1; messages_1_1 = yield messages_1.next(), !messages_1_1.done;) {
262
+ const message = messages_1_1.value;
263
+ // Store the message data and timestamp
264
+ metricData.encodedMetrics[index] = message.data;
265
+ metricData.timestamps[index] = message.info.timestampNanos;
266
+ // If we are at the last message or there are no more pending messages, call the handler
267
+ if (index === arraySize - 1 || message.info.pending === 0) {
268
+ (() => __awaiter(this, void 0, void 0, function* () { return handler(metricData); }))();
269
+ break;
270
+ }
271
+ // Increment the index
272
+ index++;
273
+ }
274
+ }
275
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
276
+ finally {
277
+ try {
278
+ if (messages_1_1 && !messages_1_1.done && (_a = messages_1.return)) yield _a.call(messages_1);
279
+ }
280
+ finally { if (e_1) throw e_1.error; }
281
+ }
282
+ }
283
+ catch (error) {
284
+ break;
285
+ }
286
+ }
287
+ catch (error) {
288
+ break;
289
+ }
290
+ }
291
+ }))();
292
+ return consumer;
293
+ });
294
+ }
205
295
  }
@@ -1,9 +1,8 @@
1
- import { BreakPoints, CommonContext, CommonSettings, DataGridControl, IMetricsConfiguration, ISessionMetricInfo, Image, Interaction, ListItemType, LogList, MetricsConfiguration, OnTestPlanRun, OnTestStepRun, Parameter, RepositoryPackageDefinition, RepositoryPackageReference, Resource, Result, RunStatus, SessionEvent, Setting, TestPlan, TestRun, TestStepType, TestStepValidationError, WatchDog } from './DTOs';
2
- import { ConnectionOptions, Consumer, NatsError, Subscription, SubscriptionOptions } from 'nats.ws';
1
+ import { BreakPoints, CommonContext, CommonSettings, DataGridControl, IMetricsConfiguration, Image, Interaction, ListItemType, LogList, MetricsConfiguration, OnTestPlanRun, OnTestStepRun, Parameter, RepositoryPackageDefinition, RepositoryPackageReference, Resource, Result, RunStatus, SessionEvent, Setting, TestPlan, TestRun, TestStepType, TestStepValidationError, WatchDog } from './DTOs';
2
+ import { ConnectionOptions, NatsError, Subscription, SubscriptionOptions } from 'nats.ws';
3
3
  import { BaseClient } from './BaseClient';
4
4
  export declare class SessionClient extends BaseClient {
5
5
  private subscriptions;
6
- private runnerId;
7
6
  constructor(baseSubject: string, options: ConnectionOptions);
8
7
  /**
9
8
  * @param sessionLogsHandler Function to be called when log list or error is received
@@ -82,17 +81,6 @@ export declare class SessionClient extends BaseClient {
82
81
  * @returns Subscription
83
82
  */
84
83
  connectTestStepRunResults(testPlanRunId: string, testStepRunId: string, resultName: string, handler: (result: Result | undefined, err: NatsError | Error | null) => void, options?: SubscriptionOptions): Subscription;
85
- /**
86
- * Connect to metrics published for the given SessionMetricInfo
87
- * @param {ISessionMetricInfo} metricInfo
88
- * @param {(result:MetricValue|undefined,err:NatsError|Error|null)=>void} handler
89
- * @param {SubscriptionOptions} options?
90
- * @returns Subscription
91
- */
92
- connectMetric(metricInfo: ISessionMetricInfo, inactiveThresholdMilliseconds: number, maxBatchSize: number, handler: (metricData: {
93
- encodedMetrics: Uint8Array[];
94
- timestamps: number[];
95
- }) => void): Promise<Consumer>;
96
84
  /**
97
85
  * Unsubscibe from session events
98
86
  */
@@ -1,28 +1,10 @@
1
- var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
- function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
- return new (P || (P = Promise))(function (resolve, reject) {
4
- function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
5
- function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
6
- function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
7
- step((generator = generator.apply(thisArg, _arguments || [])).next());
8
- });
9
- };
10
- var __asyncValues = (this && this.__asyncValues) || function (o) {
11
- if (!Symbol.asyncIterator) throw new TypeError("Symbol.asyncIterator is not defined.");
12
- var m = o[Symbol.asyncIterator], i;
13
- 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);
14
- 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); }); }; }
15
- function settle(resolve, reject, d, v) { Promise.resolve(v).then(function(v) { resolve({ value: v, done: d }); }, reject); }
16
- };
17
1
  import { BreakPoints, CommonContext, CommonSettings, DataGridControl, Image, Interaction, ListItemType, LogList, MetricsConfiguration, OnTestPlanRun, OnTestStepRun, Parameter, Result, RunStatus, SessionEvent, Setting, TestPlan, TestRun, TestStepType, TestStepValidationError, WatchDog, } from './DTOs';
18
- import { JSONCodec, nanos } from 'nats.ws';
2
+ import { JSONCodec } from 'nats.ws';
19
3
  import { BaseClient } from './BaseClient';
20
- import { getSubjectParts } from './utils';
21
4
  export class SessionClient extends BaseClient {
22
5
  constructor(baseSubject, options) {
23
6
  super(baseSubject, options);
24
7
  this.subscriptions = [];
25
- this.runnerId = getSubjectParts(baseSubject).runnerId;
26
8
  }
27
9
  /**
28
10
  * @param sessionLogsHandler Function to be called when log list or error is received
@@ -282,77 +264,6 @@ export class SessionClient extends BaseClient {
282
264
  }
283
265
  } }));
284
266
  }
285
- /**
286
- * Connect to metrics published for the given SessionMetricInfo
287
- * @param {ISessionMetricInfo} metricInfo
288
- * @param {(result:MetricValue|undefined,err:NatsError|Error|null)=>void} handler
289
- * @param {SubscriptionOptions} options?
290
- * @returns Subscription
291
- */
292
- connectMetric(metricInfo, inactiveThresholdMilliseconds, maxBatchSize, handler) {
293
- return this.createJetStreamConsumer('Metrics', `M.${metricInfo.subjectPostfix}`, {
294
- domain: this.runnerId,
295
- }, { inactive_threshold: nanos(inactiveThresholdMilliseconds) }).then(consumer => {
296
- let isCloseInitiated = false;
297
- const deleteConsumer = consumer.delete.bind(consumer);
298
- consumer.delete = () => {
299
- isCloseInitiated = true;
300
- return deleteConsumer();
301
- };
302
- // Async function here so the loop starts without blocking returning a consumer
303
- (() => __awaiter(this, void 0, void 0, function* () {
304
- var e_1, _a;
305
- // eslint-disable-next-line no-constant-condition
306
- while (!isCloseInitiated) {
307
- try {
308
- // Get the consumer info to determine the number of pending messages
309
- const consumerInfo = yield consumer.info();
310
- // We want to define the batch size based on how many message we will consume in the next fetch
311
- const arraySize = Math.min(maxBatchSize, consumerInfo.num_pending);
312
- // Create the object with preallocated arrays for better performance
313
- const metricData = {
314
- encodedMetrics: new Array(arraySize),
315
- timestamps: new Array(arraySize),
316
- };
317
- try {
318
- // Fetch the messages
319
- const messages = yield consumer.fetch({ max_messages: arraySize });
320
- // for await of doesn't return the index, so we need to keep track of it
321
- let index = 0;
322
- try {
323
- for (var messages_1 = (e_1 = void 0, __asyncValues(messages)), messages_1_1; messages_1_1 = yield messages_1.next(), !messages_1_1.done;) {
324
- const message = messages_1_1.value;
325
- // Store the message data and timestamp
326
- metricData.encodedMetrics[index] = message.data;
327
- metricData.timestamps[index] = message.info.timestampNanos;
328
- // If we are at the last message or there are no more pending messages, call the handler
329
- if (index === arraySize - 1 || message.info.pending === 0) {
330
- (() => __awaiter(this, void 0, void 0, function* () { return handler(metricData); }))();
331
- }
332
- // Increment the index
333
- index++;
334
- }
335
- }
336
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
337
- finally {
338
- try {
339
- if (messages_1_1 && !messages_1_1.done && (_a = messages_1.return)) yield _a.call(messages_1);
340
- }
341
- finally { if (e_1) throw e_1.error; }
342
- }
343
- }
344
- catch (error) {
345
- break;
346
- }
347
- }
348
- catch (error) {
349
- break;
350
- }
351
- }
352
- }))();
353
- return consumer;
354
- });
355
- }
356
267
  /**
357
268
  * Unsubscibe from session events
358
269
  */
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentap/runner-client",
3
- "version": "2.25.1",
3
+ "version": "2.25.2-alpha.1.2.11280720052",
4
4
  "description": "This is the web client for the OpenTAP Runner.",
5
5
  "main": "./dist/cjs/index.js",
6
6
  "module": "./dist/mjs/index.js",