@opentap/runner-client 1.0.0-beta.76 → 1.0.0-beta.78

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,5 +1,5 @@
1
- import { ConnectionOptions, RequestOptions } from 'nats.ws/cjs/nats.js';
2
1
  import { ComponentSettingsBase, ComponentSettingsIdentifier, ComponentSettingsListItem, DataGridControl, ErrorResponse, FileParameter, FileResponse, ListItemType, ProfileGroup, RepositoryPackageReference, RepositorySettingsPackageDefinition, SettingsTapPackage } from './DTOs';
2
+ import { ConnectionOptions, RequestOptions, Subscription, SubscriptionOptions } from 'nats.ws/cjs/nats.js';
3
3
  export declare class BaseClient {
4
4
  private connection;
5
5
  private baseSubject;
@@ -18,6 +18,13 @@ export declare class BaseClient {
18
18
  * @returns Promise of an object
19
19
  */
20
20
  protected request<T>(subject: string, payload?: any, options?: RequestOptions): Promise<T>;
21
+ /**
22
+ * Subscribes to given subject.
23
+ * @param subject The subject to subscribe
24
+ * @param options Subscription options
25
+ * @returns Subscription object
26
+ */
27
+ protected subscribe(subject: string, options: SubscriptionOptions): Subscription;
21
28
  /**
22
29
  * Check if the the response is an error from the server.
23
30
  * @param {any} response
package/lib/BaseClient.js CHANGED
@@ -45,9 +45,8 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
45
45
  if (op[0] & 5) throw op[1]; return { value: op[0] ? op[1] : void 0, done: true };
46
46
  }
47
47
  };
48
- // ! import { connect, ConnectionOptions, Empty, JSONCodec, NatsConnection, RequestOptions, StringCodec } from 'nats.ws' if consuming this library in angular >= 13.
49
- import { connect, Empty, ErrorCode, JSONCodec, StringCodec } from 'nats.ws/cjs/nats.js';
50
48
  import { ErrorResponse, } from './DTOs';
49
+ import { Empty, ErrorCode, JSONCodec, StringCodec, connect, } from 'nats.ws/cjs/nats.js';
51
50
  var DEFAULT_TIMEOUT = 6000;
52
51
  var BaseClient = /** @class */ (function () {
53
52
  function BaseClient(baseSubject, options) {
@@ -116,6 +115,22 @@ var BaseClient = /** @class */ (function () {
116
115
  });
117
116
  });
118
117
  };
118
+ /**
119
+ * Subscribes to given subject.
120
+ * @param subject The subject to subscribe
121
+ * @param options Subscription options
122
+ * @returns Subscription object
123
+ */
124
+ BaseClient.prototype.subscribe = function (subject, options) {
125
+ if (!subject)
126
+ throw Error('Subject is not defined!');
127
+ if (!this.connection)
128
+ throw Error('Connection is not up yet! Please try again later!');
129
+ if (this.connection.isClosed())
130
+ throw Error('Connection has been closed! Please reconnect!');
131
+ var natsSubject = "".concat(this.baseSubject, ".").concat(subject);
132
+ return this.connection.subscribe(natsSubject, options);
133
+ };
119
134
  /**
120
135
  * Check if the the response is an error from the server.
121
136
  * @param {any} response
package/lib/DTOs.d.ts CHANGED
@@ -61,18 +61,16 @@ export interface IImageResolveErrorResponse extends IErrorResponse {
61
61
  dotGraph?: string | undefined;
62
62
  }
63
63
  export declare class Session implements ISession {
64
- url?: string | undefined;
64
+ subject?: string | undefined;
65
65
  id?: string;
66
- imageId?: string | undefined;
67
66
  constructor(data?: ISession);
68
67
  init(_data?: any): void;
69
68
  static fromJS(data: any): Session;
70
69
  toJSON(data?: any): any;
71
70
  }
72
71
  export interface ISession {
73
- url?: string | undefined;
72
+ subject?: string | undefined;
74
73
  id?: string;
75
- imageId?: string | undefined;
76
74
  }
77
75
  export declare class Links implements ILinks {
78
76
  editor?: string | undefined;
package/lib/DTOs.js CHANGED
@@ -180,9 +180,8 @@ var Session = /** @class */ (function () {
180
180
  }
181
181
  Session.prototype.init = function (_data) {
182
182
  if (_data) {
183
- this.url = _data['Url'];
183
+ this.subject = _data['Subject'];
184
184
  this.id = _data['Id'];
185
- this.imageId = _data['ImageId'];
186
185
  }
187
186
  };
188
187
  Session.fromJS = function (data) {
@@ -193,9 +192,8 @@ var Session = /** @class */ (function () {
193
192
  };
194
193
  Session.prototype.toJSON = function (data) {
195
194
  data = typeof data === 'object' ? data : {};
196
- data['Url'] = this.url;
195
+ data['Subject'] = this.subject;
197
196
  data['Id'] = this.id;
198
- data['ImageId'] = this.imageId;
199
197
  return data;
200
198
  };
201
199
  return Session;
@@ -1,8 +1,27 @@
1
- import { BreakPoints, CommonContext, CommonSettings, DataGridControl, Image, Interaction, ListItemType, LogList, Parameter, RepositoryPackageDefinition, RepositoryPackageReference, RunStatus, Setting, TestPlan, TestStepType, TestStepValidationError, WatchDog } from './DTOs';
1
+ import { BreakPoints, CommonContext, CommonSettings, DataGridControl, Image, Interaction, ListItemType, LogList, Parameter, RepositoryPackageDefinition, RepositoryPackageReference, Result, RunStatus, SessionEvent, Setting, TestPlan, TestRun, TestStepType, TestStepValidationError, WatchDog } from './DTOs';
2
+ import { ConnectionOptions, NatsError, Subscription, SubscriptionOptions } from 'nats.ws/cjs/nats.js';
2
3
  import { BaseClient } from './BaseClient';
3
- import { ConnectionOptions } from 'nats.ws';
4
4
  export declare class SessionClient extends BaseClient {
5
5
  constructor(baseSubject: string, options: ConnectionOptions);
6
+ /**
7
+ * @param sessionLogsHandler Function to be called when log list or error is received
8
+ * @param options (optional) Subscription options
9
+ * @returns Subscription object
10
+ */
11
+ connectSessionLogs(sessionLogsHandler: (logList: LogList | undefined, err: NatsError | Error | null) => void, options?: SubscriptionOptions): Subscription;
12
+ /**
13
+ * @param eventHandler Function to be called when session event or error is received
14
+ * @param options (optional) Subscription options
15
+ * @returns Subscription object
16
+ */
17
+ connectSessionEvents(eventHandler: (sessionEvent: SessionEvent | undefined, err: NatsError | Error | null) => void, options?: SubscriptionOptions): Subscription;
18
+ /**
19
+ * @param resultHandler Function to be called when result or error is received
20
+ * @param testRunHandler Function to be called when test run or error is received
21
+ * @param options (optional) Subscription options
22
+ * @returns Subscription array: Result and Test Run subscriptions
23
+ */
24
+ connectSessionResults(resultHandler: (result: Result | undefined, err: NatsError | Error | null) => void, testRunHandler: (testRun: TestRun | undefined, err: NatsError | Error | null) => void, options?: SubscriptionOptions): [Subscription, Subscription];
6
25
  /**
7
26
  * Retrieve session logs
8
27
  * @param id (optional)
@@ -13,12 +13,109 @@ var __extends = (this && this.__extends) || (function () {
13
13
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
14
  };
15
15
  })();
16
+ var __assign = (this && this.__assign) || function () {
17
+ __assign = Object.assign || function(t) {
18
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
19
+ s = arguments[i];
20
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
21
+ t[p] = s[p];
22
+ }
23
+ return t;
24
+ };
25
+ return __assign.apply(this, arguments);
26
+ };
27
+ import { LogList, Result, SessionEvent, TestRun, } from './DTOs';
28
+ import { JSONCodec } from 'nats.ws/cjs/nats.js';
16
29
  import { BaseClient } from './BaseClient';
17
30
  var SessionClient = /** @class */ (function (_super) {
18
31
  __extends(SessionClient, _super);
19
32
  function SessionClient(baseSubject, options) {
20
33
  return _super.call(this, baseSubject, options) || this;
21
34
  }
35
+ /**
36
+ * @param sessionLogsHandler Function to be called when log list or error is received
37
+ * @param options (optional) Subscription options
38
+ * @returns Subscription object
39
+ */
40
+ SessionClient.prototype.connectSessionLogs = function (sessionLogsHandler, options) {
41
+ return this.subscribe('SessionLogs', __assign(__assign({}, options), { callback: function (error, encodedMessage) {
42
+ if (error) {
43
+ sessionLogsHandler(undefined, error);
44
+ return;
45
+ }
46
+ try {
47
+ var jsonCodec = JSONCodec();
48
+ var logListJson = jsonCodec.decode(encodedMessage === null || encodedMessage === void 0 ? void 0 : encodedMessage.data);
49
+ var logList = LogList.fromJS(logListJson);
50
+ sessionLogsHandler(logList, error);
51
+ }
52
+ catch (error) {
53
+ sessionLogsHandler(undefined, error);
54
+ }
55
+ } }));
56
+ };
57
+ /**
58
+ * @param eventHandler Function to be called when session event or error is received
59
+ * @param options (optional) Subscription options
60
+ * @returns Subscription object
61
+ */
62
+ SessionClient.prototype.connectSessionEvents = function (eventHandler, options) {
63
+ return this.subscribe('Events', __assign(__assign({}, options), { callback: function (error, encodedMessage) {
64
+ if (error) {
65
+ eventHandler(undefined, error);
66
+ return;
67
+ }
68
+ try {
69
+ var jsonCodec = JSONCodec();
70
+ var sessionEventJs = jsonCodec.decode(encodedMessage === null || encodedMessage === void 0 ? void 0 : encodedMessage.data);
71
+ var sessionEvent = SessionEvent.fromJS(sessionEventJs);
72
+ eventHandler(sessionEvent, error);
73
+ }
74
+ catch (error) {
75
+ eventHandler(undefined, error);
76
+ }
77
+ } }));
78
+ };
79
+ /**
80
+ * @param resultHandler Function to be called when result or error is received
81
+ * @param testRunHandler Function to be called when test run or error is received
82
+ * @param options (optional) Subscription options
83
+ * @returns Subscription array: Result and Test Run subscriptions
84
+ */
85
+ SessionClient.prototype.connectSessionResults = function (resultHandler, testRunHandler, options) {
86
+ return [
87
+ this.subscribe('OnResult', __assign(__assign({}, options), { callback: function (error, encodedMessage) {
88
+ if (error) {
89
+ resultHandler(undefined, error);
90
+ return;
91
+ }
92
+ try {
93
+ var jsonCodec = JSONCodec();
94
+ var resultJs = jsonCodec.decode(encodedMessage === null || encodedMessage === void 0 ? void 0 : encodedMessage.data);
95
+ var result = Result.fromJS(resultJs);
96
+ resultHandler(result, error);
97
+ }
98
+ catch (error) {
99
+ resultHandler(undefined, error);
100
+ }
101
+ } })),
102
+ this.subscribe('OnTestRun', __assign(__assign({}, options), { callback: function (error, encodedMessage) {
103
+ if (error) {
104
+ testRunHandler(undefined, error);
105
+ return;
106
+ }
107
+ try {
108
+ var jsonCodec = JSONCodec();
109
+ var testRunJs = jsonCodec.decode(encodedMessage === null || encodedMessage === void 0 ? void 0 : encodedMessage.data);
110
+ var testRun = TestRun.fromJS(testRunJs);
111
+ testRunHandler(testRun, error);
112
+ }
113
+ catch (error) {
114
+ testRunHandler(undefined, error);
115
+ }
116
+ } })),
117
+ ];
118
+ };
22
119
  /**
23
120
  * Retrieve session logs
24
121
  * @param id (optional)
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentap/runner-client",
3
- "version": "1.0.0-beta.76",
3
+ "version": "1.0.0-beta.78",
4
4
  "description": "This is the TypeScript Client for the OpenTAP Runner Plugin.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",