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

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,26 +1,14 @@
1
- import { ConnectionOptions, NatsConnection, RequestOptions } from 'nats.ws/cjs/nats.js';
1
+ import { ConnectionOptions, RequestOptions } from 'nats.ws/cjs/nats.js';
2
2
  import { ComponentSettingsBase, ComponentSettingsIdentifier, ComponentSettingsListItem, DataGridControl, ErrorResponse, FileParameter, FileResponse, ListItemType, ProfileGroup, RepositoryPackageReference, RepositorySettingsPackageDefinition, SettingsTapPackage } from './DTOs';
3
3
  export declare class BaseClient {
4
- private _accessToken;
5
- /** Get access token */
6
- get accessToken(): string;
7
- /** Set access token */
8
- set accessToken(value: string);
4
+ private connection;
5
+ private baseSubject;
6
+ private connectionOptions;
9
7
  private _timeout;
10
8
  /** Get timeout */
11
9
  get timeout(): number;
12
10
  /** Set timeout */
13
11
  set timeout(value: number);
14
- private _baseSubject;
15
- /** Get subject */
16
- get baseSubject(): string;
17
- private _connectionOptions;
18
- /** Get connection options */
19
- get connectionOptions(): ConnectionOptions;
20
- private _connection;
21
- /** Get connection instance */
22
- get connection(): NatsConnection;
23
- private domainAccess;
24
12
  constructor(baseSubject: string, options: ConnectionOptions);
25
13
  /**
26
14
  * Send a request to the nats server.
@@ -40,7 +28,7 @@ export declare class BaseClient {
40
28
  * Create a connection to the nats server.
41
29
  * @param {ConnectionOptions} options
42
30
  */
43
- private connect;
31
+ connect(): Promise<void>;
44
32
  /**
45
33
  * Close the connection.
46
34
  */
@@ -50,7 +38,6 @@ export declare class BaseClient {
50
38
  * @param domain
51
39
  * @param accessToken
52
40
  */
53
- protected setDomainAccessToken(domain: string, accessToken: string): void;
54
41
  /**
55
42
  * Generic error callback function.
56
43
  * @returns
package/lib/BaseClient.js CHANGED
@@ -1,3 +1,14 @@
1
+ var __assign = (this && this.__assign) || function () {
2
+ __assign = Object.assign || function(t) {
3
+ for (var s, i = 1, n = arguments.length; i < n; i++) {
4
+ s = arguments[i];
5
+ for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p))
6
+ t[p] = s[p];
7
+ }
8
+ return t;
9
+ };
10
+ return __assign.apply(this, arguments);
11
+ };
1
12
  var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
2
13
  function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
3
14
  return new (P || (P = Promise))(function (resolve, reject) {
@@ -37,32 +48,18 @@ var __generator = (this && this.__generator) || function (thisArg, body) {
37
48
  // ! import { connect, ConnectionOptions, Empty, JSONCodec, NatsConnection, RequestOptions, StringCodec } from 'nats.ws' if consuming this library in angular >= 13.
38
49
  import { connect, Empty, ErrorCode, JSONCodec, StringCodec } from 'nats.ws/cjs/nats.js';
39
50
  import { ErrorResponse, } from './DTOs';
51
+ var DEFAULT_TIMEOUT = 6000;
40
52
  var BaseClient = /** @class */ (function () {
41
53
  function BaseClient(baseSubject, options) {
42
- this.domainAccess = new Map();
43
- this._baseSubject = baseSubject;
44
- this._connectionOptions = options || { servers: 'ws://localhost:443' };
45
- var undefinedSubject = function () {
46
- throw new Error('A base subject must be specified');
47
- };
48
- baseSubject ? this.connect(this._connectionOptions) : undefinedSubject();
54
+ //this.domainAccess = new Map<string, string>();
55
+ this.baseSubject = baseSubject;
56
+ this.connectionOptions = __assign({}, options) || {};
57
+ this.connectionOptions.timeout = (options === null || options === void 0 ? void 0 : options.timeout) || DEFAULT_TIMEOUT;
49
58
  }
50
- Object.defineProperty(BaseClient.prototype, "accessToken", {
51
- /** Get access token */
52
- get: function () {
53
- return this._accessToken;
54
- },
55
- /** Set access token */
56
- set: function (value) {
57
- this._accessToken = value;
58
- },
59
- enumerable: false,
60
- configurable: true
61
- });
62
59
  Object.defineProperty(BaseClient.prototype, "timeout", {
63
60
  /** Get timeout */
64
61
  get: function () {
65
- return this._timeout;
62
+ return this._timeout || DEFAULT_TIMEOUT;
66
63
  },
67
64
  /** Set timeout */
68
65
  set: function (value) {
@@ -71,30 +68,6 @@ var BaseClient = /** @class */ (function () {
71
68
  enumerable: false,
72
69
  configurable: true
73
70
  });
74
- Object.defineProperty(BaseClient.prototype, "baseSubject", {
75
- /** Get subject */
76
- get: function () {
77
- return this._baseSubject;
78
- },
79
- enumerable: false,
80
- configurable: true
81
- });
82
- Object.defineProperty(BaseClient.prototype, "connectionOptions", {
83
- /** Get connection options */
84
- get: function () {
85
- return this._connectionOptions;
86
- },
87
- enumerable: false,
88
- configurable: true
89
- });
90
- Object.defineProperty(BaseClient.prototype, "connection", {
91
- /** Get connection instance */
92
- get: function () {
93
- return this._connection;
94
- },
95
- enumerable: false,
96
- configurable: true
97
- });
98
71
  /**
99
72
  * Send a request to the nats server.
100
73
  * @param subject The subject to request
@@ -103,20 +76,24 @@ var BaseClient = /** @class */ (function () {
103
76
  * @returns Promise of an object
104
77
  */
105
78
  BaseClient.prototype.request = function (subject, payload, options) {
106
- var _a;
107
79
  return __awaiter(this, void 0, void 0, function () {
108
- var stringCodec, data;
80
+ var stringCodec, data, opts;
109
81
  var _this = this;
110
- return __generator(this, function (_b) {
111
- switch (_b.label) {
82
+ return __generator(this, function (_a) {
83
+ switch (_a.label) {
112
84
  case 0:
113
- if (!subject || ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.isClosed()))
114
- return [2 /*return*/, Promise.reject()];
85
+ if (!subject)
86
+ return [2 /*return*/, Promise.reject('Subject is not defined!')];
87
+ if (!this.connection)
88
+ return [2 /*return*/, Promise.reject('Connection is not up yet! Please try again later!')];
89
+ if (this.connection.isClosed())
90
+ return [2 /*return*/, Promise.reject('Connection has been closed! Please reconnect!')];
115
91
  subject = "".concat(this.baseSubject, ".Request.").concat(subject);
116
92
  stringCodec = StringCodec();
117
93
  data = payload ? stringCodec.encode(JSON.stringify(payload)) : Empty;
94
+ opts = __assign(__assign({}, options), { timeout: this.timeout });
118
95
  return [4 /*yield*/, this.connection
119
- .request(subject, data, options)
96
+ .request(subject, data, opts)
120
97
  .then(function (message) {
121
98
  var jsonCodec = JSONCodec();
122
99
  var response = jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data);
@@ -134,7 +111,7 @@ var BaseClient = /** @class */ (function () {
134
111
  return Promise.reject(error);
135
112
  }
136
113
  })];
137
- case 1: return [2 /*return*/, _b.sent()];
114
+ case 1: return [2 /*return*/, _a.sent()];
138
115
  }
139
116
  });
140
117
  });
@@ -151,24 +128,31 @@ var BaseClient = /** @class */ (function () {
151
128
  * Create a connection to the nats server.
152
129
  * @param {ConnectionOptions} options
153
130
  */
154
- BaseClient.prototype.connect = function (options) {
131
+ BaseClient.prototype.connect = function () {
155
132
  return __awaiter(this, void 0, void 0, function () {
156
133
  var error_1;
157
134
  var _this = this;
158
135
  return __generator(this, function (_a) {
159
136
  switch (_a.label) {
160
137
  case 0:
161
- _a.trys.push([0, 2, , 3]);
162
- return [4 /*yield*/, connect(options).then(function (connection) {
163
- _this._connection = connection;
164
- })];
138
+ if (!this.baseSubject)
139
+ return [2 /*return*/, Promise.reject('Subject must be given')];
140
+ if (this.connection)
141
+ return [2 /*return*/, Promise.resolve()];
142
+ _a.label = 1;
165
143
  case 1:
166
- _a.sent();
167
- return [3 /*break*/, 3];
168
- case 2:
144
+ _a.trys.push([1, 3, , 4]);
145
+ return [4 /*yield*/, connect(this.connectionOptions)
146
+ .then(function (connection) {
147
+ _this.connection = connection;
148
+ return Promise.resolve();
149
+ })
150
+ .catch(function (error) { return Promise.reject("Failed to connect to ".concat(_this.connectionOptions.servers, " with ").concat(error)); })];
151
+ case 2: return [2 /*return*/, _a.sent()];
152
+ case 3:
169
153
  error_1 = _a.sent();
170
- throw new Error("connection to ".concat(options.servers, " failed due to ").concat(error_1));
171
- case 3: return [2 /*return*/];
154
+ return [2 /*return*/, Promise.reject("Failed to connect to ".concat(this.connectionOptions.servers, " with ").concat(error_1))];
155
+ case 4: return [2 /*return*/];
172
156
  }
173
157
  });
174
158
  });
@@ -182,8 +166,8 @@ var BaseClient = /** @class */ (function () {
182
166
  return __generator(this, function (_b) {
183
167
  switch (_b.label) {
184
168
  case 0:
185
- if (!this._connection) return [3 /*break*/, 2];
186
- return [4 /*yield*/, ((_a = this._connection) === null || _a === void 0 ? void 0 : _a.close().catch(function (error) {
169
+ if (!this.connection) return [3 /*break*/, 2];
170
+ return [4 /*yield*/, ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.close().catch(function (error) {
187
171
  throw new Error("failed to close connection: ".concat(error));
188
172
  }))];
189
173
  case 1:
@@ -199,11 +183,11 @@ var BaseClient = /** @class */ (function () {
199
183
  * @param domain
200
184
  * @param accessToken
201
185
  */
202
- BaseClient.prototype.setDomainAccessToken = function (domain, accessToken) {
203
- if (!domain)
204
- return;
186
+ /* protected setDomainAccessToken(domain: string, accessToken: string): void {
187
+ if (!domain) return;
188
+
205
189
  this.domainAccess.set(domain, accessToken);
206
- };
190
+ } */
207
191
  /**
208
192
  * Generic error callback function.
209
193
  * @returns
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export { RunnerClient } from './RunnerClient';
2
2
  export { SessionClient } from './SessionClient';
3
3
  export * from './DTOs';
4
+ export * from 'nats.ws/lib/nats-base-client/types';
package/lib/index.js CHANGED
@@ -1,3 +1,4 @@
1
1
  export { RunnerClient } from './RunnerClient';
2
2
  export { SessionClient } from './SessionClient';
3
3
  export * from './DTOs';
4
+ export * from 'nats.ws/lib/nats-base-client/types'; // TODO: Delete this line if you are consuming this library in angular > v11. The types export will be done automatically.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentap/runner-client",
3
- "version": "1.0.0-beta.74",
3
+ "version": "1.0.0-beta.76",
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",
package/readme.md CHANGED
@@ -1,7 +1,7 @@
1
1
 
2
2
  # OpenTap Runner Client
3
3
 
4
- This is the TypeScript Client for the OpenTAP Runner Plugin.
4
+ This is the web client for the OpenTAP Runner.
5
5
 
6
6
 
7
7
  ## Authors
@@ -14,18 +14,32 @@ This is the TypeScript Client for the OpenTAP Runner Plugin.
14
14
  Install my-project with npm
15
15
 
16
16
  ```bash
17
- npm install my-project
18
- cd my-project
17
+ npm install @opentap/runner-client
19
18
  ```
20
19
 
21
- ## Usage/Examples
22
-
23
- ```javascript
24
- import Component from 'my-project'
25
-
26
- function App() {
27
- return <Component />
20
+ ## Usage example
21
+
22
+ ```typescript
23
+ import { RunnerClient } from "@openTap/runner-client";
24
+
25
+ class client {
26
+ runnerClient: RunnerClient;
27
+
28
+ constructor() {
29
+ this.runnerClient = new RunnerClient('<BASE_SUBJECT>', { servers: '<SERVER_ADDRESS>' });
30
+ }
31
+
32
+ getImages() {
33
+ try {
34
+ this.data = this.runnerClient?.getImages()
35
+ .then(res => console.log(res))
36
+ .catch(error => console.error(error));
37
+ } catch (error) {
38
+ console.error(error);
39
+ }
40
+ }
28
41
  }
42
+
29
43
  ```
30
44
 
31
45
 
@@ -49,19 +63,13 @@ Install dependencies
49
63
  npm install
50
64
  ```
51
65
 
52
- Start the server
66
+ Build the library
53
67
 
54
68
  ```bash
55
69
  npm run build
56
70
  ```
57
71
 
58
72
 
59
- ## Test
60
-
61
- ```bash
62
- npm run test
63
- ```
64
73
  ## License
65
74
 
66
75
  [MIT](https://choosealicense.com/licenses/mit/)
67
-