@opentap/runner-client 2.23.0-alpha.5.5.10792848470 → 2.23.0

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.
@@ -275,6 +275,26 @@ var BaseClient = /** @class */ (function () {
275
275
  var natsSubject = "".concat(this.baseSubject, ".").concat(subject);
276
276
  return this.connection.subscribe(natsSubject, options);
277
277
  };
278
+ /**
279
+ * Subscribes to given subject.
280
+ * @param subject The subject to subscribe
281
+ * @param options Subscription options
282
+ * @returns Subscription object
283
+ */
284
+ BaseClient.prototype.createJetStreamConsumer = function (stream, subject, options) {
285
+ var _this = this;
286
+ if (!this.connection) {
287
+ throw Error('Connection is not established');
288
+ }
289
+ return this.connection.jetstreamManager(__assign({}, options)).then(function (jetStreamManager) {
290
+ return jetStreamManager.consumers
291
+ .add(stream, {
292
+ filter_subject: subject,
293
+ ack_policy: nats_ws_1.AckPolicy.None,
294
+ })
295
+ .then(function (consumerInfo) { return _this.connection.jetstream(options).consumers.get(consumerInfo.stream_name, consumerInfo.name); });
296
+ });
297
+ };
278
298
  BaseClient.prototype.encode = function (payload) {
279
299
  if (!payload) {
280
300
  return nats_ws_1.Empty;
@@ -31,11 +31,13 @@ var DTOs_1 = require("./DTOs");
31
31
  var nats_ws_1 = require("nats.ws");
32
32
  var encoders_1 = require("./encoders");
33
33
  var BaseClient_1 = require("./BaseClient");
34
+ var utils_1 = require("./utils");
34
35
  var SessionClient = /** @class */ (function (_super) {
35
36
  __extends(SessionClient, _super);
36
37
  function SessionClient(baseSubject, options) {
37
38
  var _this = _super.call(this, baseSubject, options) || this;
38
39
  _this.subscriptions = [];
40
+ _this.runnerId = (0, utils_1.getSubjectParts)(baseSubject).runnerId;
39
41
  return _this;
40
42
  }
41
43
  /**
@@ -303,46 +305,45 @@ var SessionClient = /** @class */ (function (_super) {
303
305
  * @param {SubscriptionOptions} options?
304
306
  * @returns Subscription
305
307
  */
306
- SessionClient.prototype.connectMetric = function (metricInfo, handler) {
307
- var _this = this;
308
- return this.connection.jetstreamManager({ checkAPI: false }).then(function (jetStreamManager) {
309
- var stream = "".concat(_this.baseSubject, ".Events.Metrics.").concat(metricInfo.subjectPostfix);
310
- return jetStreamManager.consumers
311
- .add(stream, {
312
- name: "runner-web-client-metric-consumer-".concat(nats_ws_1.nuid.next()),
313
- })
314
- .then(function (consumerInfo) { var _a; return (_a = _this.connection) === null || _a === void 0 ? void 0 : _a.jetstream().consumers.get(consumerInfo.stream_name, consumerInfo.name); })
315
- .then(function (consumer) {
316
- consumer === null || consumer === void 0 ? void 0 : consumer.consume({
317
- callback: function (encodedMessage) {
318
- var _a, _b;
319
- try {
320
- var time = Number.parseInt((_b = (_a = encodedMessage.headers) === null || _a === void 0 ? void 0 : _a.get('timestamp')) !== null && _b !== void 0 ? _b : '');
321
- var value = void 0;
322
- // Decode the value based on the metric value type given in the metric info
323
- switch (metricInfo.type) {
324
- case DTOs_1.SessionMetricType.Boolean:
325
- value = encoders_1.booleanCodec.decode(encodedMessage.data);
326
- break;
327
- case DTOs_1.SessionMetricType.Double:
328
- value = encoders_1.numberCodec.decode(encodedMessage.data);
329
- break;
330
- case DTOs_1.SessionMetricType.String:
331
- value = encoders_1.stringCodec.decode(encodedMessage.data);
332
- break;
333
- default:
334
- value = encoders_1.jsonCodec.decode(encodedMessage.data);
335
- break;
336
- }
337
- handler(new DTOs_1.MetricValue({ value: value, time: time }), null);
338
- }
339
- catch (error) {
340
- handler(undefined, error);
308
+ SessionClient.prototype.connectMetric = function (metricInfo, handler, sessionId) {
309
+ var baseSubject = sessionId
310
+ ? this.baseSubject
311
+ .split('.')
312
+ .map(function (part, index) { return (index === 4 ? sessionId : part); })
313
+ .join('.')
314
+ : this.baseSubject;
315
+ return this.createJetStreamConsumer('Metrics', "".concat(baseSubject, ".Events.Metrics.").concat(metricInfo.subjectPostfix), {
316
+ domain: this.runnerId,
317
+ }).then(function (consumer) {
318
+ consumer === null || consumer === void 0 ? void 0 : consumer.consume({
319
+ callback: function (encodedMessage) {
320
+ var _a, _b;
321
+ try {
322
+ var time = Number.parseInt((_b = (_a = encodedMessage.headers) === null || _a === void 0 ? void 0 : _a.get('timestamp')) !== null && _b !== void 0 ? _b : '');
323
+ var value = void 0;
324
+ // Decode the value based on the metric value type given in the metric info
325
+ switch (metricInfo.type) {
326
+ case DTOs_1.SessionMetricType.Boolean:
327
+ value = encoders_1.booleanCodec.decode(encodedMessage.data);
328
+ break;
329
+ case DTOs_1.SessionMetricType.Double:
330
+ value = encoders_1.numberCodec.decode(encodedMessage.data);
331
+ break;
332
+ case DTOs_1.SessionMetricType.String:
333
+ value = encoders_1.stringCodec.decode(encodedMessage.data);
334
+ break;
335
+ default:
336
+ value = encoders_1.jsonCodec.decode(encodedMessage.data);
337
+ break;
341
338
  }
342
- },
343
- });
344
- return consumer;
339
+ handler(new DTOs_1.MetricValue({ value: value, time: time }), null);
340
+ }
341
+ catch (error) {
342
+ handler(undefined, error);
343
+ }
344
+ },
345
345
  });
346
+ return consumer;
346
347
  });
347
348
  };
348
349
  /**
@@ -35,6 +35,13 @@ var SystemClient = /** @class */ (function (_super) {
35
35
  function SystemClient(baseSubject, options) {
36
36
  return _super.call(this, baseSubject, options) || this;
37
37
  }
38
+ SystemClient.prototype.changeIdleSession = function (request) {
39
+ return this.request("".concat(this.baseSubject, ".RunnerRegistry.Request.ChangeIdleSession"), request, {
40
+ fullSubject: true,
41
+ })
42
+ .then(this.success())
43
+ .catch(this.error());
44
+ };
38
45
  /**
39
46
  * Subscribe to the lifetime event.
40
47
  * @param listener
@@ -0,0 +1,16 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getSubjectParts = void 0;
4
+ /**
5
+ * Get the runner ID and session ID from the subject as SubjectParts.
6
+ * @param {string} subject
7
+ * @returns SubjectParts
8
+ */
9
+ var getSubjectParts = function (subject) {
10
+ var parts = subject.split('.');
11
+ return {
12
+ runnerId: parts[2],
13
+ sessionId: parts[4],
14
+ };
15
+ };
16
+ exports.getSubjectParts = getSubjectParts;
@@ -1,6 +1,6 @@
1
1
  import { DownloadTapSettingsRequest } from './requestDTOs';
2
2
  import { ComponentSettingsBase, ComponentSettingsIdentifier, ComponentSettingsListItem, DataGridControl, ErrorResponse, FileParameter, ListItemType, ProfileGroup, RepositoryPackageReference, RepositorySettingsPackageDefinition } from './DTOs';
3
- import { ConnectionOptions, NatsConnection, NatsError, Subscription, SubscriptionOptions, PublishOptions } from 'nats.ws';
3
+ import { ConnectionOptions, NatsError, Subscription, SubscriptionOptions, PublishOptions, JetStreamOptions, Consumer } from 'nats.ws';
4
4
  interface BaseClientRequestOptions {
5
5
  publishOptions?: PublishOptions;
6
6
  rawResponse?: boolean;
@@ -9,7 +9,7 @@ interface BaseClientRequestOptions {
9
9
  }
10
10
  export declare class BaseClient {
11
11
  readonly baseSubject: string;
12
- protected connection: NatsConnection | null;
12
+ private connection;
13
13
  private connectionOptions;
14
14
  private domainAccess;
15
15
  private eventEmitter;
@@ -61,6 +61,13 @@ export declare class BaseClient {
61
61
  * @returns Subscription object
62
62
  */
63
63
  protected subscribe(subject: string, options: SubscriptionOptions): Subscription;
64
+ /**
65
+ * Subscribes to given subject.
66
+ * @param subject The subject to subscribe
67
+ * @param options Subscription options
68
+ * @returns Subscription object
69
+ */
70
+ protected createJetStreamConsumer(stream: string, subject: string, options: JetStreamOptions): Promise<Consumer>;
64
71
  protected encode(payload: any): Uint8Array;
65
72
  /**
66
73
  * Create a connection to the nats server.
@@ -8,7 +8,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
8
8
  });
9
9
  };
10
10
  import { ComponentSettingsBase, ComponentSettingsIdentifier, ComponentSettingsListItem, DataGridControl, ErrorResponse, FileDescriptor, ListItemType, ProfileGroup, } from './DTOs';
11
- import { Empty, ErrorCode, JSONCodec, StringCodec, connect, headers, } from 'nats.ws';
11
+ import { Empty, ErrorCode, JSONCodec, StringCodec, connect, headers, AckPolicy, } from 'nats.ws';
12
12
  import { EventEmitter } from 'events';
13
13
  import { v4 as uuidv4 } from 'uuid';
14
14
  const DEFAULT_TIMEOUT = 40000; // default timeout of 40 seconds
@@ -229,6 +229,23 @@ export class BaseClient {
229
229
  const natsSubject = `${this.baseSubject}.${subject}`;
230
230
  return this.connection.subscribe(natsSubject, options);
231
231
  }
232
+ /**
233
+ * Subscribes to given subject.
234
+ * @param subject The subject to subscribe
235
+ * @param options Subscription options
236
+ * @returns Subscription object
237
+ */
238
+ createJetStreamConsumer(stream, subject, options) {
239
+ if (!this.connection) {
240
+ throw Error('Connection is not established');
241
+ }
242
+ return this.connection.jetstreamManager(Object.assign({}, options)).then(jetStreamManager => jetStreamManager.consumers
243
+ .add(stream, {
244
+ filter_subject: subject,
245
+ ack_policy: AckPolicy.None,
246
+ })
247
+ .then(consumerInfo => this.connection.jetstream(options).consumers.get(consumerInfo.stream_name, consumerInfo.name)));
248
+ }
232
249
  encode(payload) {
233
250
  if (!payload) {
234
251
  return Empty;
@@ -1145,6 +1145,10 @@ export interface IMetricValue {
1145
1145
  time: number;
1146
1146
  value: boolean | number | string | object;
1147
1147
  }
1148
+ export interface ChangeIdleSessionRequest {
1149
+ runnerId: string;
1150
+ sessionId: string;
1151
+ }
1148
1152
  export declare class SessionEvent implements ISessionEvent {
1149
1153
  eventType?: SessionEventType;
1150
1154
  sessionId?: string;
@@ -3,6 +3,7 @@ import { ConnectionOptions, Consumer, NatsError, Subscription, SubscriptionOptio
3
3
  import { BaseClient } from './BaseClient';
4
4
  export declare class SessionClient extends BaseClient {
5
5
  private subscriptions;
6
+ private runnerId;
6
7
  constructor(baseSubject: string, options: ConnectionOptions);
7
8
  /**
8
9
  * @param sessionLogsHandler Function to be called when log list or error is received
@@ -88,7 +89,7 @@ export declare class SessionClient extends BaseClient {
88
89
  * @param {SubscriptionOptions} options?
89
90
  * @returns Subscription
90
91
  */
91
- connectMetric(metricInfo: ISessionMetricInfo, handler: (result: IMetricValue | undefined, err: NatsError | Error | null) => void): Promise<Consumer | undefined>;
92
+ connectMetric(metricInfo: ISessionMetricInfo, handler: (result: IMetricValue | undefined, err: NatsError | Error | null) => void, sessionId?: string): Promise<Consumer>;
92
93
  /**
93
94
  * Unsubscibe from session events
94
95
  */
@@ -1,11 +1,13 @@
1
1
  import { BreakPoints, CommonContext, CommonSettings, DataGridControl, Image, Interaction, ListItemType, LogList, MetricValue, MetricsConfiguration, OnTestPlanRun, OnTestStepRun, Parameter, Result, RunStatus, SessionEvent, SessionMetricType, Setting, TestPlan, TestRun, TestStepType, TestStepValidationError, WatchDog, } from './DTOs';
2
- import { JSONCodec, nuid } from 'nats.ws';
2
+ import { JSONCodec } from 'nats.ws';
3
3
  import { booleanCodec, jsonCodec, numberCodec, stringCodec } from './encoders';
4
4
  import { BaseClient } from './BaseClient';
5
+ import { getSubjectParts } from './utils';
5
6
  export class SessionClient extends BaseClient {
6
7
  constructor(baseSubject, options) {
7
8
  super(baseSubject, options);
8
9
  this.subscriptions = [];
10
+ this.runnerId = getSubjectParts(baseSubject).runnerId;
9
11
  }
10
12
  /**
11
13
  * @param sessionLogsHandler Function to be called when log list or error is received
@@ -272,45 +274,45 @@ export class SessionClient extends BaseClient {
272
274
  * @param {SubscriptionOptions} options?
273
275
  * @returns Subscription
274
276
  */
275
- connectMetric(metricInfo, handler) {
276
- return this.connection.jetstreamManager({ checkAPI: false }).then(jetStreamManager => {
277
- const stream = `${this.baseSubject}.Events.Metrics.${metricInfo.subjectPostfix}`;
278
- return jetStreamManager.consumers
279
- .add(stream, {
280
- name: `runner-web-client-metric-consumer-${nuid.next()}`,
281
- })
282
- .then(consumerInfo => { var _a; return (_a = this.connection) === null || _a === void 0 ? void 0 : _a.jetstream().consumers.get(consumerInfo.stream_name, consumerInfo.name); })
283
- .then(consumer => {
284
- consumer === null || consumer === void 0 ? void 0 : consumer.consume({
285
- callback(encodedMessage) {
286
- var _a, _b;
287
- try {
288
- const time = Number.parseInt((_b = (_a = encodedMessage.headers) === null || _a === void 0 ? void 0 : _a.get('timestamp')) !== null && _b !== void 0 ? _b : '');
289
- let value;
290
- // Decode the value based on the metric value type given in the metric info
291
- switch (metricInfo.type) {
292
- case SessionMetricType.Boolean:
293
- value = booleanCodec.decode(encodedMessage.data);
294
- break;
295
- case SessionMetricType.Double:
296
- value = numberCodec.decode(encodedMessage.data);
297
- break;
298
- case SessionMetricType.String:
299
- value = stringCodec.decode(encodedMessage.data);
300
- break;
301
- default:
302
- value = jsonCodec.decode(encodedMessage.data);
303
- break;
304
- }
305
- handler(new MetricValue({ value, time }), null);
306
- }
307
- catch (error) {
308
- handler(undefined, error);
277
+ connectMetric(metricInfo, handler, sessionId) {
278
+ const baseSubject = sessionId
279
+ ? this.baseSubject
280
+ .split('.')
281
+ .map((part, index) => (index === 4 ? sessionId : part))
282
+ .join('.')
283
+ : this.baseSubject;
284
+ return this.createJetStreamConsumer('Metrics', `${baseSubject}.Events.Metrics.${metricInfo.subjectPostfix}`, {
285
+ domain: this.runnerId,
286
+ }).then(consumer => {
287
+ consumer === null || consumer === void 0 ? void 0 : consumer.consume({
288
+ callback(encodedMessage) {
289
+ var _a, _b;
290
+ try {
291
+ const time = Number.parseInt((_b = (_a = encodedMessage.headers) === null || _a === void 0 ? void 0 : _a.get('timestamp')) !== null && _b !== void 0 ? _b : '');
292
+ let value;
293
+ // Decode the value based on the metric value type given in the metric info
294
+ switch (metricInfo.type) {
295
+ case SessionMetricType.Boolean:
296
+ value = booleanCodec.decode(encodedMessage.data);
297
+ break;
298
+ case SessionMetricType.Double:
299
+ value = numberCodec.decode(encodedMessage.data);
300
+ break;
301
+ case SessionMetricType.String:
302
+ value = stringCodec.decode(encodedMessage.data);
303
+ break;
304
+ default:
305
+ value = jsonCodec.decode(encodedMessage.data);
306
+ break;
309
307
  }
310
- },
311
- });
312
- return consumer;
308
+ handler(new MetricValue({ value, time }), null);
309
+ }
310
+ catch (error) {
311
+ handler(undefined, error);
312
+ }
313
+ },
313
314
  });
315
+ return consumer;
314
316
  });
315
317
  }
316
318
  /**
@@ -1,5 +1,5 @@
1
1
  import { ConnectionOptions, Subscription, SubscriptionOptions } from 'nats.ws';
2
- import { ErrorResponse, RunnerEvent, TestPlanRunCompletedEventArgs, TestPlanRunStartEventArgs, TestStepRunCompletedEventArgs, TestStepRunStartEventArgs } from './DTOs';
2
+ import { ChangeIdleSessionRequest, ErrorResponse, RunnerEvent, TestPlanRunCompletedEventArgs, TestPlanRunStartEventArgs, TestStepRunCompletedEventArgs, TestStepRunStartEventArgs } from './DTOs';
3
3
  import { BaseClient } from './BaseClient';
4
4
  export interface RunnerLifetimeEvent {
5
5
  RunnerId: string;
@@ -8,6 +8,7 @@ export interface RunnerLifetimeEvent {
8
8
  }
9
9
  export declare class SystemClient extends BaseClient {
10
10
  constructor(baseSubject: string, options: ConnectionOptions);
11
+ changeIdleSession(request: ChangeIdleSessionRequest): Promise<void>;
11
12
  /**
12
13
  * Subscribe to the lifetime event.
13
14
  * @param listener
@@ -5,6 +5,13 @@ export class SystemClient extends BaseClient {
5
5
  constructor(baseSubject, options) {
6
6
  super(baseSubject, options);
7
7
  }
8
+ changeIdleSession(request) {
9
+ return this.request(`${this.baseSubject}.RunnerRegistry.Request.ChangeIdleSession`, request, {
10
+ fullSubject: true,
11
+ })
12
+ .then(this.success())
13
+ .catch(this.error());
14
+ }
8
15
  /**
9
16
  * Subscribe to the lifetime event.
10
17
  * @param listener
@@ -0,0 +1,11 @@
1
+ interface SubjectParts {
2
+ runnerId: string | undefined;
3
+ sessionId: string | undefined;
4
+ }
5
+ /**
6
+ * Get the runner ID and session ID from the subject as SubjectParts.
7
+ * @param {string} subject
8
+ * @returns SubjectParts
9
+ */
10
+ export declare const getSubjectParts: (subject: string) => SubjectParts;
11
+ export {};
@@ -0,0 +1,12 @@
1
+ /**
2
+ * Get the runner ID and session ID from the subject as SubjectParts.
3
+ * @param {string} subject
4
+ * @returns SubjectParts
5
+ */
6
+ export const getSubjectParts = (subject) => {
7
+ const parts = subject.split('.');
8
+ return {
9
+ runnerId: parts[2],
10
+ sessionId: parts[4],
11
+ };
12
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentap/runner-client",
3
- "version": "2.23.0-alpha.5.5.10792848470",
3
+ "version": "2.23.0",
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",