@opentap/runner-client 2.39.0 → 2.40.0-alpha.1.1.18464550965

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.
@@ -3,7 +3,6 @@ import { ConnectionOptions, NatsError, Subscription, SubscriptionOptions } from
3
3
  import { BaseClient } from './BaseClient';
4
4
  export declare class SessionClient extends BaseClient {
5
5
  private _sessionId;
6
- private subscriptions;
7
6
  private static readonly sessionEventFactories;
8
7
  get sessionId(): string | undefined;
9
8
  constructor(baseSubject: string, options: ConnectionOptions);
@@ -32,7 +31,7 @@ export declare class SessionClient extends BaseClient {
32
31
  * @param options (optional) Subscription options
33
32
  * @returns Subscription object
34
33
  */
35
- connectSessionEvents(eventHandler: (sessionEvent: SessionEvent | undefined, err: NatsError | Error | null) => void, options?: SubscriptionOptions): void;
34
+ connectSessionEvents(eventHandler: (sessionEvent: SessionEvent | undefined, err: NatsError | Error | null) => void, options?: SubscriptionOptions): Subscription;
36
35
  /**
37
36
  * Connect to listen to the TestPlanRun events for the given test plan run ID.
38
37
  * @param {string} testPlanRunId
@@ -68,10 +67,6 @@ export declare class SessionClient extends BaseClient {
68
67
  * @returns Subscription
69
68
  */
70
69
  connectTestStepRunResults(testPlanRunId: string, testStepRunId: string, resultName: string, handler: (result: Result | undefined, err: NatsError | Error | null) => void, options?: SubscriptionOptions): Subscription;
71
- /**
72
- * Unsubscibe from session events
73
- */
74
- unsubscribeSessionEvents(): void;
75
70
  /**
76
71
  * Retrieve session logs
77
72
  * @param id (optional)
@@ -35,7 +35,6 @@ var SessionClient = /** @class */ (function (_super) {
35
35
  __extends(SessionClient, _super);
36
36
  function SessionClient(baseSubject, options) {
37
37
  var _this = _super.call(this, baseSubject, options) || this;
38
- _this.subscriptions = [];
39
38
  _this._sessionId = _this.getSessionIdFromSubject(baseSubject);
40
39
  return _this;
41
40
  }
@@ -52,7 +51,7 @@ var SessionClient = /** @class */ (function (_super) {
52
51
  * @returns sessionId or undefined if not found
53
52
  */
54
53
  SessionClient.prototype.getSessionIdFromSubject = function (subject) {
55
- var match = subject.match(/Session\.(.+)$/);
54
+ var match = subject.match(/Session\.([^.]+)/);
56
55
  if (match && match[1]) {
57
56
  return match[1];
58
57
  }
@@ -90,16 +89,15 @@ var SessionClient = /** @class */ (function (_super) {
90
89
  var _this = this;
91
90
  var factory = SessionClient.sessionEventFactories[eventName];
92
91
  return this.subscribe("Events.".concat(eventName), __assign(__assign({}, options), { callback: function (error, encodedMessage) {
93
- var _a;
94
92
  if (error) {
95
93
  eventHandler(undefined, error);
96
94
  return;
97
95
  }
98
96
  try {
99
- if (((_a = encodedMessage === null || encodedMessage === void 0 ? void 0 : encodedMessage.data) === null || _a === void 0 ? void 0 : _a.length) > 0) {
97
+ if (encodedMessage.data.length > 0) {
100
98
  var payload = encoders_1.jsonCodec.decode(encodedMessage.data);
101
99
  var sessionEvent = factory(payload);
102
- sessionEvent.sessionId = _this._sessionId;
100
+ sessionEvent.sessionId = _this.getSessionIdFromSubject(encodedMessage.subject);
103
101
  eventHandler(sessionEvent, null);
104
102
  }
105
103
  }
@@ -115,13 +113,29 @@ var SessionClient = /** @class */ (function (_super) {
115
113
  */
116
114
  SessionClient.prototype.connectSessionEvents = function (eventHandler, options) {
117
115
  var _this = this;
118
- this.unsubscribeSessionEvents();
119
- this.subscriptions = [];
120
- // Subscribe to all session events using the new connectSessionEvent method
121
- Object.keys(SessionClient.sessionEventFactories).forEach(function (eventName) {
122
- var subscription = _this.connectSessionEvent(eventName, eventHandler, options);
123
- _this.subscriptions.push(subscription);
124
- });
116
+ return this.subscribe("Events.*", __assign(__assign({}, options), { callback: function (error, encodedMessage) {
117
+ if (error) {
118
+ eventHandler(undefined, error);
119
+ return;
120
+ }
121
+ try {
122
+ var subject = encodedMessage.subject;
123
+ var eventName = subject ? subject.split('.').pop() : undefined;
124
+ var factory = eventName ? SessionClient.sessionEventFactories[eventName] : undefined;
125
+ if (!factory) {
126
+ throw new Error("Unknown session event: ".concat(eventName));
127
+ }
128
+ if (encodedMessage.data.length > 0) {
129
+ var payload = encoders_1.jsonCodec.decode(encodedMessage.data);
130
+ var sessionEvent = factory(payload);
131
+ sessionEvent.sessionId = _this.getSessionIdFromSubject(subject);
132
+ eventHandler(sessionEvent, null);
133
+ }
134
+ }
135
+ catch (err) {
136
+ eventHandler(undefined, err);
137
+ }
138
+ } }));
125
139
  };
126
140
  /**
127
141
  * Connect to listen to the TestPlanRun events for the given test plan run ID.
@@ -240,13 +254,6 @@ var SessionClient = /** @class */ (function (_super) {
240
254
  }
241
255
  } }));
242
256
  };
243
- /**
244
- * Unsubscibe from session events
245
- */
246
- SessionClient.prototype.unsubscribeSessionEvents = function () {
247
- this.subscriptions.forEach(function (subscription) { return subscription.unsubscribe(); });
248
- this.subscriptions = [];
249
- };
250
257
  /**
251
258
  * Retrieve session logs
252
259
  * @param id (optional)
@@ -3,7 +3,6 @@ import { ConnectionOptions, NatsError, Subscription, SubscriptionOptions } from
3
3
  import { BaseClient } from './BaseClient';
4
4
  export declare class SessionClient extends BaseClient {
5
5
  private _sessionId;
6
- private subscriptions;
7
6
  private static readonly sessionEventFactories;
8
7
  get sessionId(): string | undefined;
9
8
  constructor(baseSubject: string, options: ConnectionOptions);
@@ -32,7 +31,7 @@ export declare class SessionClient extends BaseClient {
32
31
  * @param options (optional) Subscription options
33
32
  * @returns Subscription object
34
33
  */
35
- connectSessionEvents(eventHandler: (sessionEvent: SessionEvent | undefined, err: NatsError | Error | null) => void, options?: SubscriptionOptions): void;
34
+ connectSessionEvents(eventHandler: (sessionEvent: SessionEvent | undefined, err: NatsError | Error | null) => void, options?: SubscriptionOptions): Subscription;
36
35
  /**
37
36
  * Connect to listen to the TestPlanRun events for the given test plan run ID.
38
37
  * @param {string} testPlanRunId
@@ -68,10 +67,6 @@ export declare class SessionClient extends BaseClient {
68
67
  * @returns Subscription
69
68
  */
70
69
  connectTestStepRunResults(testPlanRunId: string, testStepRunId: string, resultName: string, handler: (result: Result | undefined, err: NatsError | Error | null) => void, options?: SubscriptionOptions): Subscription;
71
- /**
72
- * Unsubscibe from session events
73
- */
74
- unsubscribeSessionEvents(): void;
75
70
  /**
76
71
  * Retrieve session logs
77
72
  * @param id (optional)
@@ -4,7 +4,6 @@ import { jsonCodec } from './encoders';
4
4
  export class SessionClient extends BaseClient {
5
5
  constructor(baseSubject, options) {
6
6
  super(baseSubject, options);
7
- this.subscriptions = [];
8
7
  this._sessionId = this.getSessionIdFromSubject(baseSubject);
9
8
  }
10
9
  get sessionId() {
@@ -16,7 +15,7 @@ export class SessionClient extends BaseClient {
16
15
  * @returns sessionId or undefined if not found
17
16
  */
18
17
  getSessionIdFromSubject(subject) {
19
- const match = subject.match(/Session\.(.+)$/);
18
+ const match = subject.match(/Session\.([^.]+)/);
20
19
  if (match && match[1]) {
21
20
  return match[1];
22
21
  }
@@ -53,16 +52,15 @@ export class SessionClient extends BaseClient {
53
52
  connectSessionEvent(eventName, eventHandler, options) {
54
53
  const factory = SessionClient.sessionEventFactories[eventName];
55
54
  return this.subscribe(`Events.${eventName}`, Object.assign(Object.assign({}, options), { callback: (error, encodedMessage) => {
56
- var _a;
57
55
  if (error) {
58
56
  eventHandler(undefined, error);
59
57
  return;
60
58
  }
61
59
  try {
62
- if (((_a = encodedMessage === null || encodedMessage === void 0 ? void 0 : encodedMessage.data) === null || _a === void 0 ? void 0 : _a.length) > 0) {
60
+ if (encodedMessage.data.length > 0) {
63
61
  const payload = jsonCodec.decode(encodedMessage.data);
64
62
  const sessionEvent = factory(payload);
65
- sessionEvent.sessionId = this._sessionId;
63
+ sessionEvent.sessionId = this.getSessionIdFromSubject(encodedMessage.subject);
66
64
  eventHandler(sessionEvent, null);
67
65
  }
68
66
  }
@@ -77,13 +75,29 @@ export class SessionClient extends BaseClient {
77
75
  * @returns Subscription object
78
76
  */
79
77
  connectSessionEvents(eventHandler, options) {
80
- this.unsubscribeSessionEvents();
81
- this.subscriptions = [];
82
- // Subscribe to all session events using the new connectSessionEvent method
83
- Object.keys(SessionClient.sessionEventFactories).forEach(eventName => {
84
- const subscription = this.connectSessionEvent(eventName, eventHandler, options);
85
- this.subscriptions.push(subscription);
86
- });
78
+ return this.subscribe(`Events.*`, Object.assign(Object.assign({}, options), { callback: (error, encodedMessage) => {
79
+ if (error) {
80
+ eventHandler(undefined, error);
81
+ return;
82
+ }
83
+ try {
84
+ const subject = encodedMessage.subject;
85
+ const eventName = subject ? subject.split('.').pop() : undefined;
86
+ const factory = eventName ? SessionClient.sessionEventFactories[eventName] : undefined;
87
+ if (!factory) {
88
+ throw new Error(`Unknown session event: ${eventName}`);
89
+ }
90
+ if (encodedMessage.data.length > 0) {
91
+ const payload = jsonCodec.decode(encodedMessage.data);
92
+ const sessionEvent = factory(payload);
93
+ sessionEvent.sessionId = this.getSessionIdFromSubject(subject);
94
+ eventHandler(sessionEvent, null);
95
+ }
96
+ }
97
+ catch (err) {
98
+ eventHandler(undefined, err);
99
+ }
100
+ } }));
87
101
  }
88
102
  /**
89
103
  * Connect to listen to the TestPlanRun events for the given test plan run ID.
@@ -202,13 +216,6 @@ export class SessionClient extends BaseClient {
202
216
  }
203
217
  } }));
204
218
  }
205
- /**
206
- * Unsubscibe from session events
207
- */
208
- unsubscribeSessionEvents() {
209
- this.subscriptions.forEach(subscription => subscription.unsubscribe());
210
- this.subscriptions = [];
211
- }
212
219
  /**
213
220
  * Retrieve session logs
214
221
  * @param id (optional)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentap/runner-client",
3
- "version": "2.39.0",
3
+ "version": "2.40.0-alpha.1.1.18464550965",
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",