@opentap/runner-client 2.0.0-alpha.2.17 → 2.0.0-alpha.2.19
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.
- package/lib/BaseClient.d.ts +1 -1
- package/lib/BaseClient.js +47 -39
- package/lib/DTOs.d.ts +6 -22
- package/lib/DTOs.js +4 -58
- package/lib/SessionClient.d.ts +1 -6
- package/lib/SessionClient.js +15 -18
- package/package.json +1 -1
package/lib/BaseClient.d.ts
CHANGED
|
@@ -65,7 +65,7 @@ export declare class BaseClient {
|
|
|
65
65
|
* @param options (optional)
|
|
66
66
|
* @returns Promise of an object
|
|
67
67
|
*/
|
|
68
|
-
protected requestChunked<T>(subject: string, options?: RequestOptions, isFullSubject?: boolean): Promise<T>;
|
|
68
|
+
protected requestChunked<T>(subject: string, replySubject: string, payload: any, options?: RequestOptions, isFullSubject?: boolean): Promise<T>;
|
|
69
69
|
/**
|
|
70
70
|
* Check if the the response is an error from the server.
|
|
71
71
|
* @param {any} response
|
package/lib/BaseClient.js
CHANGED
|
@@ -56,7 +56,6 @@ var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) {
|
|
|
56
56
|
};
|
|
57
57
|
import { ComponentSettingsBase, ComponentSettingsIdentifier, ComponentSettingsListItem, DataGridControl, ErrorResponse, FileDescriptor, ListItemType, ProfileGroup, } from './DTOs';
|
|
58
58
|
import { Empty, ErrorCode, JSONCodec, StringCodec, connect, headers, } from 'nats.ws';
|
|
59
|
-
import { v4 as uuidv4 } from 'uuid';
|
|
60
59
|
var DEFAULT_TIMEOUT = 6000;
|
|
61
60
|
var BaseClient = /** @class */ (function () {
|
|
62
61
|
function BaseClient(baseSubject, options) {
|
|
@@ -199,7 +198,8 @@ var BaseClient = /** @class */ (function () {
|
|
|
199
198
|
*/
|
|
200
199
|
BaseClient.prototype.sendChunked = function (subject, payload, options) {
|
|
201
200
|
return __awaiter(this, void 0, void 0, function () {
|
|
202
|
-
var stringCodec, data, headers, opts, fileDescriptor, getChunk, dataSubject,
|
|
201
|
+
var stringCodec, data, headers, opts, fileDescriptor, getChunk, dataSubject, i;
|
|
202
|
+
var _this = this;
|
|
203
203
|
return __generator(this, function (_a) {
|
|
204
204
|
switch (_a.label) {
|
|
205
205
|
case 0:
|
|
@@ -218,28 +218,36 @@ var BaseClient = /** @class */ (function () {
|
|
|
218
218
|
var offset = chunk * fileDescriptor.chunkSize;
|
|
219
219
|
return data.slice(offset, offset + fileDescriptor.chunkSize);
|
|
220
220
|
};
|
|
221
|
-
return [4 /*yield*/, this.request(subject, fileDescriptor)];
|
|
221
|
+
return [4 /*yield*/, this.request(subject, fileDescriptor, opts)];
|
|
222
222
|
case 1:
|
|
223
223
|
dataSubject = _a.sent();
|
|
224
|
-
i = 0;
|
|
225
|
-
|
|
226
|
-
case 2:
|
|
227
|
-
if (!(i < fileDescriptor.numberOfChunks)) return [3 /*break*/, 5];
|
|
228
|
-
return [4 /*yield*/, this.connection.request(dataSubject, getChunk(i), opts)];
|
|
229
|
-
case 3:
|
|
230
|
-
// The main response will be received after the last chunk is sent, the intermediate ones
|
|
231
|
-
// are empty acknowledgement messages
|
|
232
|
-
message = _a.sent();
|
|
233
|
-
_a.label = 4;
|
|
234
|
-
case 4:
|
|
235
|
-
i++;
|
|
236
|
-
return [3 /*break*/, 2];
|
|
237
|
-
case 5:
|
|
238
|
-
if (message && message.data.length !== 0) {
|
|
239
|
-
jsonCodec = JSONCodec();
|
|
240
|
-
response = jsonCodec.decode(message.data);
|
|
224
|
+
for (i = 0; i < fileDescriptor.numberOfChunks; i++) {
|
|
225
|
+
this.connection.publish(dataSubject, getChunk(i), opts);
|
|
241
226
|
}
|
|
242
|
-
return [2 /*return*/,
|
|
227
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
228
|
+
var combinedResult = new Uint8Array([]);
|
|
229
|
+
// Subscribe to dataSubject before sending the terminating message to ensure we are listening before the server starts responding
|
|
230
|
+
var subscription = _this.connection.subscribe(dataSubject);
|
|
231
|
+
// Publish an empty message to indicate that we are ready to listen
|
|
232
|
+
_this.connection.publish(dataSubject, Empty, opts);
|
|
233
|
+
var first = true;
|
|
234
|
+
subscription.callback = function (error, message) {
|
|
235
|
+
if (error) {
|
|
236
|
+
reject(error);
|
|
237
|
+
}
|
|
238
|
+
combinedResult = new Uint8Array(__spreadArray(__spreadArray([], Array.from(combinedResult), true), Array.from(message === null || message === void 0 ? void 0 : message.data), true));
|
|
239
|
+
// We shouldn't resolve after the first message since this is going to be the empty message we just sent
|
|
240
|
+
// We should resolve after the server terminates the message with an empty message
|
|
241
|
+
if (first === false && (message === null || message === void 0 ? void 0 : message.data.length) === 0) {
|
|
242
|
+
resolve(combinedResult);
|
|
243
|
+
}
|
|
244
|
+
first = false;
|
|
245
|
+
};
|
|
246
|
+
}).then(function (byteArray) {
|
|
247
|
+
var jsonCodec = JSONCodec();
|
|
248
|
+
var response = jsonCodec.decode(byteArray);
|
|
249
|
+
return _this.isErrorResponse(response) ? Promise.reject(ErrorResponse.fromJS(response)) : Promise.resolve(response);
|
|
250
|
+
})];
|
|
243
251
|
}
|
|
244
252
|
});
|
|
245
253
|
});
|
|
@@ -251,49 +259,49 @@ var BaseClient = /** @class */ (function () {
|
|
|
251
259
|
* @param options (optional)
|
|
252
260
|
* @returns Promise of an object
|
|
253
261
|
*/
|
|
254
|
-
BaseClient.prototype.requestChunked = function (subject, options, isFullSubject) {
|
|
262
|
+
BaseClient.prototype.requestChunked = function (subject, replySubject, payload, options, isFullSubject) {
|
|
255
263
|
return __awaiter(this, void 0, void 0, function () {
|
|
264
|
+
var fileSize;
|
|
256
265
|
var _this = this;
|
|
257
266
|
return __generator(this, function (_a) {
|
|
258
267
|
if (!this.connection)
|
|
259
268
|
return [2 /*return*/, Promise.reject("".concat(subject, ": Connection is down! Please try again!"))];
|
|
260
269
|
if (this.connection.isClosed())
|
|
261
270
|
return [2 /*return*/, Promise.reject("".concat(subject, ": Connection has been closed! Please reconnect!"))];
|
|
271
|
+
fileSize = -1;
|
|
262
272
|
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
263
|
-
var numberOfChunks = -1;
|
|
264
|
-
var received = 0;
|
|
265
273
|
var combinedResult = new Uint8Array([]);
|
|
266
|
-
//
|
|
267
|
-
var
|
|
268
|
-
|
|
274
|
+
// Subscribe to the subject before starting the process
|
|
275
|
+
var subscription = _this.connection.subscribe(replySubject);
|
|
276
|
+
var resolveIfCompleted = function () {
|
|
277
|
+
if (combinedResult.length === fileSize) {
|
|
278
|
+
subscription.unsubscribe();
|
|
269
279
|
resolve(combinedResult);
|
|
270
280
|
}
|
|
271
281
|
};
|
|
272
|
-
// Generate a unique subject where the Runner will publish the chunks
|
|
273
|
-
var replySubject = "_INBOX.".concat(uuidv4());
|
|
274
|
-
// Subscribe to the subject before starting the process
|
|
275
|
-
var subscription = _this.connection.subscribe(replySubject);
|
|
276
282
|
subscription.callback = function (error, message) {
|
|
277
283
|
if (error) {
|
|
278
284
|
reject(error);
|
|
279
285
|
}
|
|
280
|
-
// Combine each chunk
|
|
281
286
|
combinedResult = new Uint8Array(__spreadArray(__spreadArray([], Array.from(combinedResult), true), Array.from(message === null || message === void 0 ? void 0 : message.data), true));
|
|
282
|
-
|
|
283
|
-
message.respond(Empty); // Respond acknowledgement
|
|
284
|
-
resolveIfComplete();
|
|
287
|
+
resolveIfCompleted();
|
|
285
288
|
};
|
|
286
289
|
var headers = _this.buildHeaders();
|
|
287
290
|
var opts = __assign(__assign({}, options), { timeout: _this.timeout, headers: headers });
|
|
288
291
|
// Request the file descriptor from the runner by posting the reply subject
|
|
289
|
-
return _this.request(subject,
|
|
292
|
+
return _this.request(subject, payload, opts, isFullSubject)
|
|
290
293
|
.then(function (fileDescriptor) { return FileDescriptor.fromJS(fileDescriptor); })
|
|
291
294
|
.then(function (fileDescriptor) {
|
|
292
|
-
|
|
293
|
-
|
|
294
|
-
|
|
295
|
+
fileSize = fileDescriptor.fileSize;
|
|
296
|
+
resolveIfCompleted();
|
|
297
|
+
})
|
|
298
|
+
.catch(function (error) {
|
|
299
|
+
subscription.unsubscribe();
|
|
300
|
+
throw error;
|
|
295
301
|
});
|
|
296
302
|
}).then(function (byteArray) {
|
|
303
|
+
if (byteArray.length !== fileSize)
|
|
304
|
+
return Promise.reject("Unexpected response size. Expected ".concat(fileSize, " bytes, but got ").concat(byteArray.length, "."));
|
|
297
305
|
var jsonCodec = JSONCodec();
|
|
298
306
|
var response = jsonCodec.decode(byteArray);
|
|
299
307
|
return _this.isErrorResponse(response) ? Promise.reject(ErrorResponse.fromJS(response)) : Promise.resolve(response);
|
package/lib/DTOs.d.ts
CHANGED
|
@@ -418,29 +418,13 @@ 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
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
resource?: Resource | undefined;
|
|
425
|
-
constructor(data?: IPictureControl);
|
|
426
|
-
init(_data?: any): void;
|
|
427
|
-
static fromJS(data: any): PictureControl;
|
|
428
|
-
toJSON(data?: any): any;
|
|
429
|
-
}
|
|
430
|
-
export interface IPictureControl extends ISetting {
|
|
431
|
-
description?: string | undefined;
|
|
432
|
-
mimeType?: string | undefined;
|
|
433
|
-
resource?: Resource | undefined;
|
|
434
|
-
}
|
|
435
|
-
export declare class Resource implements IResource {
|
|
436
|
-
source?: string | undefined;
|
|
437
|
-
constructor(data?: IResource);
|
|
438
|
-
init(_data?: any): void;
|
|
439
|
-
static fromJS(data: any): Resource;
|
|
440
|
-
toJSON(data?: any): any;
|
|
421
|
+
export declare class TestPlanRequest implements ITestPlanRequest {
|
|
422
|
+
properties?: string[] | null | undefined;
|
|
423
|
+
subject?: string | undefined;
|
|
441
424
|
}
|
|
442
|
-
export interface
|
|
443
|
-
|
|
425
|
+
export interface ITestPlanRequest {
|
|
426
|
+
properties?: string[] | null | undefined;
|
|
427
|
+
subject?: string | undefined;
|
|
444
428
|
}
|
|
445
429
|
export declare class FileDescriptor implements IFileDescriptor {
|
|
446
430
|
numberOfChunks: number;
|
package/lib/DTOs.js
CHANGED
|
@@ -1238,66 +1238,12 @@ var PasswordControl = /** @class */ (function (_super) {
|
|
|
1238
1238
|
return PasswordControl;
|
|
1239
1239
|
}(Setting));
|
|
1240
1240
|
export { PasswordControl };
|
|
1241
|
-
var
|
|
1242
|
-
|
|
1243
|
-
function PictureControl(data) {
|
|
1244
|
-
var _this = _super.call(this, data) || this;
|
|
1245
|
-
_this._discriminator = 'PictureControl';
|
|
1246
|
-
return _this;
|
|
1247
|
-
}
|
|
1248
|
-
PictureControl.prototype.init = function (_data) {
|
|
1249
|
-
_super.prototype.init.call(this, _data);
|
|
1250
|
-
if (_data) {
|
|
1251
|
-
this.description = _data['Description'];
|
|
1252
|
-
this.mimeType = _data['MimeType'];
|
|
1253
|
-
this.resource = _data['Resource'] ? Resource.fromJS(_data['Resource']) : undefined;
|
|
1254
|
-
}
|
|
1255
|
-
};
|
|
1256
|
-
PictureControl.fromJS = function (data) {
|
|
1257
|
-
data = typeof data === 'object' ? data : {};
|
|
1258
|
-
var result = new PictureControl();
|
|
1259
|
-
result.init(data);
|
|
1260
|
-
return result;
|
|
1261
|
-
};
|
|
1262
|
-
PictureControl.prototype.toJSON = function (data) {
|
|
1263
|
-
data = typeof data === 'object' ? data : {};
|
|
1264
|
-
data['Description'] = this.description;
|
|
1265
|
-
data['MimeType'] = this.mimeType;
|
|
1266
|
-
data['Resource'] = this.resource ? this.resource.toJSON() : undefined;
|
|
1267
|
-
_super.prototype.toJSON.call(this, data);
|
|
1268
|
-
return data;
|
|
1269
|
-
};
|
|
1270
|
-
return PictureControl;
|
|
1271
|
-
}(Setting));
|
|
1272
|
-
export { PictureControl };
|
|
1273
|
-
var Resource = /** @class */ (function () {
|
|
1274
|
-
function Resource(data) {
|
|
1275
|
-
if (data) {
|
|
1276
|
-
for (var property in data) {
|
|
1277
|
-
if (Object.prototype.hasOwnProperty.call(data, property))
|
|
1278
|
-
this[property] = data[property];
|
|
1279
|
-
}
|
|
1280
|
-
}
|
|
1241
|
+
var TestPlanRequest = /** @class */ (function () {
|
|
1242
|
+
function TestPlanRequest() {
|
|
1281
1243
|
}
|
|
1282
|
-
|
|
1283
|
-
if (_data) {
|
|
1284
|
-
this.source = _data['Source'];
|
|
1285
|
-
}
|
|
1286
|
-
};
|
|
1287
|
-
Resource.fromJS = function (data) {
|
|
1288
|
-
data = typeof data === 'object' ? data : {};
|
|
1289
|
-
var result = new Resource();
|
|
1290
|
-
result.init(data);
|
|
1291
|
-
return result;
|
|
1292
|
-
};
|
|
1293
|
-
Resource.prototype.toJSON = function (data) {
|
|
1294
|
-
data = typeof data === 'object' ? data : {};
|
|
1295
|
-
data['Source'] = this.source;
|
|
1296
|
-
return data;
|
|
1297
|
-
};
|
|
1298
|
-
return Resource;
|
|
1244
|
+
return TestPlanRequest;
|
|
1299
1245
|
}());
|
|
1300
|
-
export {
|
|
1246
|
+
export { TestPlanRequest };
|
|
1301
1247
|
var FileDescriptor = /** @class */ (function () {
|
|
1302
1248
|
function FileDescriptor(fileSize, chunkSize) {
|
|
1303
1249
|
var _a;
|
package/lib/SessionClient.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BreakPoints, CommonContext, CommonSettings, DataGridControl, Image, Interaction, ListItemType, LogList, Parameter, RepositoryPackageDefinition, RepositoryPackageReference,
|
|
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
2
|
import { ConnectionOptions, NatsError, Subscription, SubscriptionOptions } from 'nats.ws';
|
|
3
3
|
import { BaseClient } from './BaseClient';
|
|
4
4
|
export declare class SessionClient extends BaseClient {
|
|
@@ -86,11 +86,6 @@ export declare class SessionClient extends BaseClient {
|
|
|
86
86
|
* @return Test plan retrieved
|
|
87
87
|
*/
|
|
88
88
|
getTestPlanXML(): Promise<string>;
|
|
89
|
-
/**
|
|
90
|
-
* Retrieve loaded test plan XML
|
|
91
|
-
* @return Test plan retrieved
|
|
92
|
-
*/
|
|
93
|
-
downloadResource(resource: Resource): Promise<Uint8Array>;
|
|
94
89
|
/**
|
|
95
90
|
* Load test plan using a test plan TapPackage from a repository
|
|
96
91
|
* @param {RepositoryPackageDefinition} packageReference
|
package/lib/SessionClient.js
CHANGED
|
@@ -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) {
|
|
@@ -204,20 +205,9 @@ var SessionClient = /** @class */ (function (_super) {
|
|
|
204
205
|
* @return Test plan retrieved
|
|
205
206
|
*/
|
|
206
207
|
SessionClient.prototype.getTestPlanXML = function () {
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
* Retrieve loaded test plan XML
|
|
211
|
-
* @return Test plan retrieved
|
|
212
|
-
*/
|
|
213
|
-
SessionClient.prototype.downloadResource = function (resource) {
|
|
214
|
-
var _a;
|
|
215
|
-
var runnerResourcePrefix = 'subject://';
|
|
216
|
-
if (!((_a = resource.source) === null || _a === void 0 ? void 0 : _a.startsWith(runnerResourcePrefix))) {
|
|
217
|
-
return Promise.reject('The source of the provided resource is not a nats subject.');
|
|
218
|
-
}
|
|
219
|
-
var subject = resource.source.replace(runnerResourcePrefix, '');
|
|
220
|
-
return this.requestChunked(subject, undefined, true).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());
|
|
221
211
|
};
|
|
222
212
|
/**
|
|
223
213
|
* Load test plan using a test plan TapPackage from a repository
|
|
@@ -240,7 +230,8 @@ var SessionClient = /** @class */ (function (_super) {
|
|
|
240
230
|
* @return Test plan resources opened.
|
|
241
231
|
*/
|
|
242
232
|
SessionClient.prototype.resourcesOpen = function () {
|
|
243
|
-
|
|
233
|
+
var replySubject = "_INBOX.".concat(uuidv4());
|
|
234
|
+
return this.requestChunked('ResourcesOpen', replySubject, replySubject)
|
|
244
235
|
.then(function (testPlanJs) { return TestPlan.fromJS(testPlanJs); })
|
|
245
236
|
.then(this.success())
|
|
246
237
|
.catch(this.error());
|
|
@@ -250,7 +241,8 @@ var SessionClient = /** @class */ (function (_super) {
|
|
|
250
241
|
* @return Test plan resources closed.
|
|
251
242
|
*/
|
|
252
243
|
SessionClient.prototype.resourcesClose = function () {
|
|
253
|
-
|
|
244
|
+
var replySubject = "_INBOX.".concat(uuidv4());
|
|
245
|
+
return this.requestChunked('ResourcesClose', replySubject, replySubject)
|
|
254
246
|
.then(function (testPlanJs) { return TestPlan.fromJS(testPlanJs); })
|
|
255
247
|
.then(this.success())
|
|
256
248
|
.catch(this.error());
|
|
@@ -285,7 +277,12 @@ var SessionClient = /** @class */ (function (_super) {
|
|
|
285
277
|
* @return Test plan retrieved
|
|
286
278
|
*/
|
|
287
279
|
SessionClient.prototype.getTestPlan = function (properties) {
|
|
288
|
-
|
|
280
|
+
var replySubject = "_INBOX.".concat(uuidv4());
|
|
281
|
+
var payload = {
|
|
282
|
+
subject: replySubject,
|
|
283
|
+
properties: properties,
|
|
284
|
+
};
|
|
285
|
+
return this.requestChunked('GetTestPlan', replySubject, payload)
|
|
289
286
|
.then(function (testPlanJs) { return TestPlan.fromJS(testPlanJs); })
|
|
290
287
|
.then(this.success())
|
|
291
288
|
.catch(this.error());
|
|
@@ -296,7 +293,7 @@ var SessionClient = /** @class */ (function (_super) {
|
|
|
296
293
|
* @return Test plan changed
|
|
297
294
|
*/
|
|
298
295
|
SessionClient.prototype.setTestPlan = function (plan) {
|
|
299
|
-
return this.
|
|
296
|
+
return this.sendChunked('SetTestPlan', plan)
|
|
300
297
|
.then(function (testPlanJs) { return TestPlan.fromJS(testPlanJs); })
|
|
301
298
|
.then(this.success())
|
|
302
299
|
.catch(this.error());
|