@opentap/runner-client 2.0.0-alpha.2.8 → 2.0.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.
@@ -26,9 +26,11 @@ export declare class BaseClient {
26
26
  * @param subject The subject to request
27
27
  * @param payload (optional)
28
28
  * @param options (optional)
29
+ * @param isFullSubject (optional) If true, use the subject as request subject
30
+ * without appending it to the baseSubject
29
31
  * @returns Promise of an object
30
32
  */
31
- protected request<T>(subject: string, payload?: any, options?: RequestOptions): Promise<T>;
33
+ protected request<T>(subject: string, payload?: any, options?: RequestOptions, isFullSubject?: boolean): Promise<T>;
32
34
  /**
33
35
  * Handle the error
34
36
  * @param error
@@ -48,6 +50,22 @@ export declare class BaseClient {
48
50
  * @returns Subscription object
49
51
  */
50
52
  protected subscribe(subject: string, options: SubscriptionOptions): Subscription;
53
+ /**
54
+ * Send an object to the nats server with chunks.
55
+ * @param subject The subject to request
56
+ * @param payload (optional)
57
+ * @param options (optional)
58
+ * @returns Promise of an object
59
+ */
60
+ protected sendChunked<T>(subject: string, payload?: any, options?: RequestOptions): Promise<T>;
61
+ /**
62
+ * Request an object to the nats server with chunks.
63
+ * @param subject The subject to request
64
+ * @param payload (optional)
65
+ * @param options (optional)
66
+ * @returns Promise of an object
67
+ */
68
+ protected requestChunked<T>(subject: string, replySubject: string, payload: any, options?: RequestOptions, isFullSubject?: boolean): Promise<T>;
51
69
  /**
52
70
  * Check if the the response is an error from the server.
53
71
  * @param {any} response
package/lib/BaseClient.js CHANGED
@@ -45,7 +45,16 @@ 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 { ComponentSettingsBase, ComponentSettingsIdentifier, ComponentSettingsListItem, DataGridControl, ErrorResponse, ListItemType, ProfileGroup, } from './DTOs';
48
+ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
49
+ if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) {
50
+ if (ar || !(i in from)) {
51
+ if (!ar) ar = Array.prototype.slice.call(from, 0, i);
52
+ ar[i] = from[i];
53
+ }
54
+ }
55
+ return to.concat(ar || Array.prototype.slice.call(from));
56
+ };
57
+ import { ComponentSettingsBase, ComponentSettingsIdentifier, ComponentSettingsListItem, DataGridControl, ErrorResponse, FileDescriptor, ListItemType, ProfileGroup, } from './DTOs';
49
58
  import { Empty, ErrorCode, JSONCodec, StringCodec, connect, headers, } from 'nats.ws';
50
59
  var DEFAULT_TIMEOUT = 6000;
51
60
  var BaseClient = /** @class */ (function () {
@@ -97,16 +106,18 @@ var BaseClient = /** @class */ (function () {
97
106
  * @param subject The subject to request
98
107
  * @param payload (optional)
99
108
  * @param options (optional)
109
+ * @param isFullSubject (optional) If true, use the subject as request subject
110
+ * without appending it to the baseSubject
100
111
  * @returns Promise of an object
101
112
  */
102
- BaseClient.prototype.request = function (subject, payload, options) {
113
+ BaseClient.prototype.request = function (subject, payload, options, isFullSubject) {
103
114
  return __awaiter(this, void 0, void 0, function () {
104
115
  var stringCodec, data, headers, opts;
105
116
  var _this = this;
106
117
  return __generator(this, function (_a) {
107
118
  switch (_a.label) {
108
119
  case 0:
109
- subject = "".concat(this.baseSubject, ".Request.").concat(subject);
120
+ subject = isFullSubject ? subject : "".concat(this.baseSubject, ".Request.").concat(subject);
110
121
  if (!this.connection)
111
122
  return [2 /*return*/, Promise.reject("".concat(subject, ": Connection is down! Please try again!"))];
112
123
  if (this.connection.isClosed())
@@ -178,6 +189,132 @@ var BaseClient = /** @class */ (function () {
178
189
  var natsSubject = "".concat(this.baseSubject, ".").concat(subject);
179
190
  return this.connection.subscribe(natsSubject, options);
180
191
  };
192
+ /**
193
+ * Send an object to the nats server with chunks.
194
+ * @param subject The subject to request
195
+ * @param payload (optional)
196
+ * @param options (optional)
197
+ * @returns Promise of an object
198
+ */
199
+ BaseClient.prototype.sendChunked = function (subject, payload, options) {
200
+ return __awaiter(this, void 0, void 0, function () {
201
+ var stringCodec, data, headers, opts, fileDescriptor, getChunk, dataSubject, i;
202
+ var _this = this;
203
+ return __generator(this, function (_a) {
204
+ switch (_a.label) {
205
+ case 0:
206
+ if (!this.connection)
207
+ return [2 /*return*/, Promise.reject("".concat(subject, ": Connection is down! Please try again!"))];
208
+ if (this.connection.isClosed())
209
+ return [2 /*return*/, Promise.reject("".concat(subject, ": Connection has been closed! Please reconnect!"))];
210
+ stringCodec = StringCodec();
211
+ data = payload ? stringCodec.encode(JSON.stringify(payload)) : Empty;
212
+ headers = this.buildHeaders();
213
+ opts = __assign(__assign({}, options), { timeout: this.timeout, headers: headers });
214
+ fileDescriptor = new FileDescriptor(data.length);
215
+ if (!fileDescriptor.numberOfChunks)
216
+ return [2 /*return*/, Promise.reject("".concat(subject, ": File is empty!"))];
217
+ getChunk = function (chunk) {
218
+ var offset = chunk * fileDescriptor.chunkSize;
219
+ return data.slice(offset, offset + fileDescriptor.chunkSize);
220
+ };
221
+ return [4 /*yield*/, this.request(subject, fileDescriptor, opts)];
222
+ case 1:
223
+ dataSubject = _a.sent();
224
+ for (i = 0; i < fileDescriptor.numberOfChunks; i++) {
225
+ this.connection.publish(dataSubject, getChunk(i), opts);
226
+ }
227
+ return [2 /*return*/, new Promise(function (resolve, reject) {
228
+ if (!_this.connection) {
229
+ return Promise.reject('No nats connection.');
230
+ }
231
+ var combinedResult = new Uint8Array([]);
232
+ // Subscribe to dataSubject before sending the terminating message to ensure we are listening before the server starts responding
233
+ var subscription = _this.connection.subscribe(dataSubject);
234
+ // Publish an empty message to indicate that we are ready to listen
235
+ _this.connection.publish(dataSubject, Empty, opts);
236
+ var first = true;
237
+ subscription.callback = function (error, message) {
238
+ // The first message is the empty message we published above.
239
+ // We should discard this message before we proceed
240
+ if (first === true) {
241
+ first = false;
242
+ return;
243
+ }
244
+ if (error) {
245
+ reject(error);
246
+ }
247
+ combinedResult = new Uint8Array(__spreadArray(__spreadArray([], Array.from(combinedResult), true), Array.from(message === null || message === void 0 ? void 0 : message.data), true));
248
+ if ((message === null || message === void 0 ? void 0 : message.data.length) === 0) {
249
+ resolve(combinedResult);
250
+ }
251
+ };
252
+ }).then(function (byteArray) {
253
+ var jsonCodec = JSONCodec();
254
+ var response = jsonCodec.decode(byteArray);
255
+ return _this.isErrorResponse(response) ? Promise.reject(ErrorResponse.fromJS(response)) : Promise.resolve(response);
256
+ })];
257
+ }
258
+ });
259
+ });
260
+ };
261
+ /**
262
+ * Request an object to the nats server with chunks.
263
+ * @param subject The subject to request
264
+ * @param payload (optional)
265
+ * @param options (optional)
266
+ * @returns Promise of an object
267
+ */
268
+ BaseClient.prototype.requestChunked = function (subject, replySubject, payload, options, isFullSubject) {
269
+ return __awaiter(this, void 0, void 0, function () {
270
+ var fileSize;
271
+ var _this = this;
272
+ return __generator(this, function (_a) {
273
+ if (!this.connection)
274
+ return [2 /*return*/, Promise.reject("".concat(subject, ": Connection is down! Please try again!"))];
275
+ if (this.connection.isClosed())
276
+ return [2 /*return*/, Promise.reject("".concat(subject, ": Connection has been closed! Please reconnect!"))];
277
+ fileSize = -1;
278
+ return [2 /*return*/, new Promise(function (resolve, reject) {
279
+ var combinedResult = new Uint8Array([]);
280
+ // Subscribe to the subject before starting the process
281
+ var subscription = _this.connection.subscribe(replySubject);
282
+ var resolveIfCompleted = function () {
283
+ if (combinedResult.length === fileSize) {
284
+ subscription.unsubscribe();
285
+ resolve(combinedResult);
286
+ }
287
+ };
288
+ subscription.callback = function (error, message) {
289
+ if (error) {
290
+ reject(error);
291
+ }
292
+ combinedResult = new Uint8Array(__spreadArray(__spreadArray([], Array.from(combinedResult), true), Array.from(message === null || message === void 0 ? void 0 : message.data), true));
293
+ resolveIfCompleted();
294
+ };
295
+ var headers = _this.buildHeaders();
296
+ var opts = __assign(__assign({}, options), { timeout: _this.timeout, headers: headers });
297
+ // Request the file descriptor from the runner by posting the reply subject
298
+ return _this.request(subject, payload, opts, isFullSubject)
299
+ .then(function (fileDescriptor) { return FileDescriptor.fromJS(fileDescriptor); })
300
+ .then(function (fileDescriptor) {
301
+ fileSize = fileDescriptor.fileSize;
302
+ resolveIfCompleted();
303
+ })
304
+ .catch(function (error) {
305
+ subscription.unsubscribe();
306
+ throw error;
307
+ });
308
+ }).then(function (byteArray) {
309
+ if (byteArray.length !== fileSize)
310
+ return Promise.reject("Unexpected response size. Expected ".concat(fileSize, " bytes, but got ").concat(byteArray.length, "."));
311
+ var jsonCodec = JSONCodec();
312
+ var response = jsonCodec.decode(byteArray);
313
+ return _this.isErrorResponse(response) ? Promise.reject(ErrorResponse.fromJS(response)) : Promise.resolve(response);
314
+ })];
315
+ });
316
+ });
317
+ };
181
318
  /**
182
319
  * Check if the the response is an error from the server.
183
320
  * @param {any} response
package/lib/DTOs.d.ts CHANGED
@@ -418,6 +418,29 @@ export declare class PasswordControl extends Setting implements IPasswordControl
418
418
  export interface IPasswordControl extends ISetting {
419
419
  password?: string | undefined;
420
420
  }
421
+ export declare class TestPlanRequest implements ITestPlanRequest {
422
+ properties?: string[] | null | undefined;
423
+ subject?: string | undefined;
424
+ }
425
+ export interface ITestPlanRequest {
426
+ properties?: string[] | null | undefined;
427
+ subject?: string | undefined;
428
+ }
429
+ export declare class FileDescriptor implements IFileDescriptor {
430
+ numberOfChunks: number;
431
+ fileSize: number;
432
+ chunkSize: number;
433
+ private readonly defaultChunkSize;
434
+ constructor(fileSize: number, chunkSize?: number);
435
+ init(_data?: any): void;
436
+ static fromJS(data: any): FileDescriptor;
437
+ toJSON(data?: any): any;
438
+ }
439
+ export interface IFileDescriptor {
440
+ numberOfChunks: number;
441
+ fileSize: number;
442
+ chunkSize: number;
443
+ }
421
444
  export declare class ComponentSettings extends ComponentSettingsBase implements IComponentSettings {
422
445
  settings?: Setting[] | undefined;
423
446
  constructor(data?: IComponentSettings);
@@ -756,7 +779,6 @@ export declare class TestStep implements ITestStep {
756
779
  typeName?: string | undefined;
757
780
  typeDisplay?: DisplayAttribute | undefined;
758
781
  name?: string | undefined;
759
- expandedName?: string | undefined;
760
782
  protected _discriminator: string;
761
783
  constructor(data?: ITestStep);
762
784
  init(_data?: any): void;
@@ -772,7 +794,6 @@ export interface ITestStep {
772
794
  typeName?: string | undefined;
773
795
  typeDisplay?: DisplayAttribute | undefined;
774
796
  name?: string | undefined;
775
- expandedName?: string | undefined;
776
797
  }
777
798
  export declare class TestStepType extends TestStep implements ITestStepType {
778
799
  availableChildrenTypes?: string[] | undefined;
package/lib/DTOs.js CHANGED
@@ -1238,6 +1238,46 @@ var PasswordControl = /** @class */ (function (_super) {
1238
1238
  return PasswordControl;
1239
1239
  }(Setting));
1240
1240
  export { PasswordControl };
1241
+ var TestPlanRequest = /** @class */ (function () {
1242
+ function TestPlanRequest() {
1243
+ }
1244
+ return TestPlanRequest;
1245
+ }());
1246
+ export { TestPlanRequest };
1247
+ var FileDescriptor = /** @class */ (function () {
1248
+ function FileDescriptor(fileSize, chunkSize) {
1249
+ var _a;
1250
+ this.defaultChunkSize = 512000;
1251
+ if (chunkSize === 0) {
1252
+ throw Error('chunkSize cannot set to 0');
1253
+ }
1254
+ this.fileSize = fileSize;
1255
+ this.chunkSize = chunkSize !== null && chunkSize !== void 0 ? chunkSize : this.defaultChunkSize;
1256
+ this.numberOfChunks = Math.floor((((_a = this.fileSize) !== null && _a !== void 0 ? _a : 0) + this.chunkSize - 1) / this.chunkSize);
1257
+ }
1258
+ FileDescriptor.prototype.init = function (_data) {
1259
+ if (_data) {
1260
+ this.numberOfChunks = _data['NumberOfChunks'];
1261
+ this.fileSize = _data['FileSize'];
1262
+ this.chunkSize = _data['ChunkSize'];
1263
+ }
1264
+ };
1265
+ FileDescriptor.fromJS = function (data) {
1266
+ data = typeof data === 'object' ? data : {};
1267
+ var result = new FileDescriptor(0);
1268
+ result.init(data);
1269
+ return result;
1270
+ };
1271
+ FileDescriptor.prototype.toJSON = function (data) {
1272
+ data = typeof data === 'object' ? data : {};
1273
+ data['NumberOfChunks'] = this.numberOfChunks;
1274
+ data['FileSize'] = this.fileSize;
1275
+ data['ChunkSize'] = this.chunkSize;
1276
+ return data;
1277
+ };
1278
+ return FileDescriptor;
1279
+ }());
1280
+ export { FileDescriptor };
1241
1281
  var ComponentSettings = /** @class */ (function (_super) {
1242
1282
  __extends(ComponentSettings, _super);
1243
1283
  function ComponentSettings(data) {
@@ -2195,7 +2235,6 @@ var TestStep = /** @class */ (function () {
2195
2235
  this.typeName = _data['TypeName'];
2196
2236
  this.typeDisplay = _data['TypeDisplay'] ? DisplayAttribute.fromJS(_data['TypeDisplay']) : undefined;
2197
2237
  this.name = _data['Name'];
2198
- this.expandedName = _data['ExpandedName'];
2199
2238
  }
2200
2239
  };
2201
2240
  TestStep.fromJS = function (data) {
@@ -2232,7 +2271,6 @@ var TestStep = /** @class */ (function () {
2232
2271
  data['TypeName'] = this.typeName;
2233
2272
  data['TypeDisplay'] = this.typeDisplay ? this.typeDisplay.toJSON() : undefined;
2234
2273
  data['Name'] = this.name;
2235
- data['ExpandedName'] = this.expandedName;
2236
2274
  return data;
2237
2275
  };
2238
2276
  return TestStep;
@@ -27,6 +27,7 @@ var __assign = (this && this.__assign) || function () {
27
27
  import { BreakPoints, CommonContext, CommonSettings, DataGridControl, Image, Interaction, ListItemType, LogList, Result, RunStatus, SessionEvent, Setting, TestPlan, TestRun, TestStepType, TestStepValidationError, WatchDog, } from './DTOs';
28
28
  import { JSONCodec } from 'nats.ws';
29
29
  import { BaseClient } from './BaseClient';
30
+ import { v4 as uuidv4 } from 'uuid';
30
31
  var SessionClient = /** @class */ (function (_super) {
31
32
  __extends(SessionClient, _super);
32
33
  function SessionClient(baseSubject, options) {
@@ -197,14 +198,16 @@ var SessionClient = /** @class */ (function (_super) {
197
198
  * @return Test plan loaded. List of load errors is returned.
198
199
  */
199
200
  SessionClient.prototype.setTestPlanXML = function (xml) {
200
- return this.request('SetTestPlanXML', xml).then(this.success()).catch(this.error());
201
+ return this.sendChunked('SetTestPlanXML', xml).then(this.success()).catch(this.error());
201
202
  };
202
203
  /**
203
204
  * Retrieve loaded test plan XML
204
205
  * @return Test plan retrieved
205
206
  */
206
207
  SessionClient.prototype.getTestPlanXML = function () {
207
- return this.request('GetTestPlanXML').then(this.success()).catch(this.error());
208
+ // Generate a unique subject where the Runner will publish the chunks
209
+ var replySubject = "_INBOX.".concat(uuidv4());
210
+ return this.requestChunked('GetTestPlanXML', replySubject, replySubject).then(this.success()).catch(this.error());
208
211
  };
209
212
  /**
210
213
  * Load test plan using a test plan TapPackage from a repository
@@ -227,7 +230,8 @@ var SessionClient = /** @class */ (function (_super) {
227
230
  * @return Test plan resources opened.
228
231
  */
229
232
  SessionClient.prototype.resourcesOpen = function () {
230
- return this.request('ResourcesOpen')
233
+ var replySubject = "_INBOX.".concat(uuidv4());
234
+ return this.requestChunked('ResourcesOpen', replySubject, replySubject)
231
235
  .then(function (testPlanJs) { return TestPlan.fromJS(testPlanJs); })
232
236
  .then(this.success())
233
237
  .catch(this.error());
@@ -237,7 +241,8 @@ var SessionClient = /** @class */ (function (_super) {
237
241
  * @return Test plan resources closed.
238
242
  */
239
243
  SessionClient.prototype.resourcesClose = function () {
240
- return this.request('ResourcesClose')
244
+ var replySubject = "_INBOX.".concat(uuidv4());
245
+ return this.requestChunked('ResourcesClose', replySubject, replySubject)
241
246
  .then(function (testPlanJs) { return TestPlan.fromJS(testPlanJs); })
242
247
  .then(this.success())
243
248
  .catch(this.error());
@@ -272,7 +277,12 @@ var SessionClient = /** @class */ (function (_super) {
272
277
  * @return Test plan retrieved
273
278
  */
274
279
  SessionClient.prototype.getTestPlan = function (properties) {
275
- return this.request('GetTestPlan', properties)
280
+ var replySubject = "_INBOX.".concat(uuidv4());
281
+ var payload = {
282
+ subject: replySubject,
283
+ properties: properties,
284
+ };
285
+ return this.requestChunked('GetTestPlan', replySubject, payload)
276
286
  .then(function (testPlanJs) { return TestPlan.fromJS(testPlanJs); })
277
287
  .then(this.success())
278
288
  .catch(this.error());
@@ -283,7 +293,7 @@ var SessionClient = /** @class */ (function (_super) {
283
293
  * @return Test plan changed
284
294
  */
285
295
  SessionClient.prototype.setTestPlan = function (plan) {
286
- return this.request('SetTestPlan', plan)
296
+ return this.sendChunked('SetTestPlan', plan)
287
297
  .then(function (testPlanJs) { return TestPlan.fromJS(testPlanJs); })
288
298
  .then(this.success())
289
299
  .catch(this.error());
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentap/runner-client",
3
- "version": "2.0.0-alpha.2.8",
3
+ "version": "2.0.0",
4
4
  "description": "This is the web client for the OpenTAP Runner.",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -26,6 +26,7 @@
26
26
  "url": "git://github.com/opentap/runner-client-web.git"
27
27
  },
28
28
  "devDependencies": {
29
+ "@types/uuid": "^8.3.4",
29
30
  "@typescript-eslint/eslint-plugin": "^5.36.1",
30
31
  "@typescript-eslint/parser": "^5.36.1",
31
32
  "eslint": "^8.23.0",
@@ -38,7 +39,8 @@
38
39
  "typescript": "^4.8.2"
39
40
  },
40
41
  "dependencies": {
41
- "nats.ws": "^1.9.0"
42
+ "nats.ws": "^1.9.0",
43
+ "uuid": "^9.0.0"
42
44
  },
43
45
  "lint-staged": {
44
46
  "*.{ts,js,html}": [