@opentap/runner-client 2.0.0-alpha.2.7 → 2.0.0-alpha.2.9
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 +16 -0
- package/lib/BaseClient.js +114 -1
- package/lib/DTOs.d.ts +39 -0
- package/lib/DTOs.js +94 -0
- package/lib/SessionClient.d.ts +6 -1
- package/lib/SessionClient.js +15 -2
- package/package.json +4 -2
package/lib/BaseClient.d.ts
CHANGED
|
@@ -48,6 +48,22 @@ export declare class BaseClient {
|
|
|
48
48
|
* @returns Subscription object
|
|
49
49
|
*/
|
|
50
50
|
protected subscribe(subject: string, options: SubscriptionOptions): Subscription;
|
|
51
|
+
/**
|
|
52
|
+
* Send a request to the nats server.
|
|
53
|
+
* @param subject The subject to request
|
|
54
|
+
* @param payload (optional)
|
|
55
|
+
* @param options (optional)
|
|
56
|
+
* @returns Promise of an object
|
|
57
|
+
*/
|
|
58
|
+
protected sendChunked<T>(subject: string, payload?: any, options?: RequestOptions): Promise<T>;
|
|
59
|
+
/**
|
|
60
|
+
* Send a request to the nats server.
|
|
61
|
+
* @param subject The subject to request
|
|
62
|
+
* @param payload (optional)
|
|
63
|
+
* @param options (optional)
|
|
64
|
+
* @returns Promise of an object
|
|
65
|
+
*/
|
|
66
|
+
protected requestChunked<T>(subject: string, options?: RequestOptions): Promise<T>;
|
|
51
67
|
/**
|
|
52
68
|
* Check if the the response is an error from the server.
|
|
53
69
|
* @param {any} response
|
package/lib/BaseClient.js
CHANGED
|
@@ -45,8 +45,18 @@ 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
|
-
|
|
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';
|
|
59
|
+
import { v4 as uuidv4 } from 'uuid';
|
|
50
60
|
var DEFAULT_TIMEOUT = 6000;
|
|
51
61
|
var BaseClient = /** @class */ (function () {
|
|
52
62
|
function BaseClient(baseSubject, options) {
|
|
@@ -178,6 +188,109 @@ var BaseClient = /** @class */ (function () {
|
|
|
178
188
|
var natsSubject = "".concat(this.baseSubject, ".").concat(subject);
|
|
179
189
|
return this.connection.subscribe(natsSubject, options);
|
|
180
190
|
};
|
|
191
|
+
/**
|
|
192
|
+
* Send a request to the nats server.
|
|
193
|
+
* @param subject The subject to request
|
|
194
|
+
* @param payload (optional)
|
|
195
|
+
* @param options (optional)
|
|
196
|
+
* @returns Promise of an object
|
|
197
|
+
*/
|
|
198
|
+
BaseClient.prototype.sendChunked = function (subject, payload, options) {
|
|
199
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
200
|
+
var requestSubject, stringCodec, data, headers, opts, fileDescriptor, getChunk, message, i, response, jsonCodec;
|
|
201
|
+
return __generator(this, function (_a) {
|
|
202
|
+
switch (_a.label) {
|
|
203
|
+
case 0:
|
|
204
|
+
requestSubject = "".concat(this.baseSubject, ".Request.").concat(subject);
|
|
205
|
+
if (!this.connection)
|
|
206
|
+
return [2 /*return*/, Promise.reject("".concat(requestSubject, ": Connection is down! Please try again!"))];
|
|
207
|
+
if (this.connection.isClosed())
|
|
208
|
+
return [2 /*return*/, Promise.reject("".concat(requestSubject, ": Connection has been closed! Please reconnect!"))];
|
|
209
|
+
stringCodec = StringCodec();
|
|
210
|
+
data = payload ? stringCodec.encode(JSON.stringify(payload)) : Empty;
|
|
211
|
+
headers = this.buildHeaders();
|
|
212
|
+
opts = __assign(__assign({}, options), { timeout: this.timeout, headers: headers });
|
|
213
|
+
fileDescriptor = new FileDescriptor(data.length);
|
|
214
|
+
if (!fileDescriptor.numberOfChunks)
|
|
215
|
+
return [2 /*return*/, Promise.reject("".concat(requestSubject, ": File is empty!"))];
|
|
216
|
+
getChunk = function (chunk) {
|
|
217
|
+
var offset = chunk * fileDescriptor.chunkSize;
|
|
218
|
+
return data.slice(offset, offset + fileDescriptor.chunkSize);
|
|
219
|
+
};
|
|
220
|
+
this.request(subject, fileDescriptor);
|
|
221
|
+
i = 0;
|
|
222
|
+
_a.label = 1;
|
|
223
|
+
case 1:
|
|
224
|
+
if (!(i < fileDescriptor.numberOfChunks)) return [3 /*break*/, 4];
|
|
225
|
+
return [4 /*yield*/, this.connection.request(requestSubject, getChunk(i), opts)];
|
|
226
|
+
case 2:
|
|
227
|
+
message = _a.sent();
|
|
228
|
+
_a.label = 3;
|
|
229
|
+
case 3:
|
|
230
|
+
i++;
|
|
231
|
+
return [3 /*break*/, 1];
|
|
232
|
+
case 4:
|
|
233
|
+
if (message && message.data.length !== 0) {
|
|
234
|
+
jsonCodec = JSONCodec();
|
|
235
|
+
response = jsonCodec.decode(message.data);
|
|
236
|
+
}
|
|
237
|
+
return [2 /*return*/, this.isErrorResponse(response) ? Promise.reject(ErrorResponse.fromJS(response)) : Promise.resolve(response)];
|
|
238
|
+
}
|
|
239
|
+
});
|
|
240
|
+
});
|
|
241
|
+
};
|
|
242
|
+
/**
|
|
243
|
+
* Send a request to the nats server.
|
|
244
|
+
* @param subject The subject to request
|
|
245
|
+
* @param payload (optional)
|
|
246
|
+
* @param options (optional)
|
|
247
|
+
* @returns Promise of an object
|
|
248
|
+
*/
|
|
249
|
+
BaseClient.prototype.requestChunked = function (subject, options) {
|
|
250
|
+
return __awaiter(this, void 0, void 0, function () {
|
|
251
|
+
var replySubject, requestSubject, stringCodec, data, headers, opts, fileDescriptor;
|
|
252
|
+
var _this = this;
|
|
253
|
+
return __generator(this, function (_a) {
|
|
254
|
+
switch (_a.label) {
|
|
255
|
+
case 0:
|
|
256
|
+
replySubject = "_INBOX.".concat(uuidv4());
|
|
257
|
+
requestSubject = "".concat(this.baseSubject, ".Request.").concat(subject);
|
|
258
|
+
if (!this.connection)
|
|
259
|
+
return [2 /*return*/, Promise.reject("".concat(requestSubject, ": Connection is down! Please try again!"))];
|
|
260
|
+
if (this.connection.isClosed())
|
|
261
|
+
return [2 /*return*/, Promise.reject("".concat(requestSubject, ": Connection has been closed! Please reconnect!"))];
|
|
262
|
+
stringCodec = StringCodec();
|
|
263
|
+
data = stringCodec.encode(JSON.stringify(replySubject));
|
|
264
|
+
headers = this.buildHeaders();
|
|
265
|
+
opts = __assign(__assign({}, options), { timeout: this.timeout, headers: headers });
|
|
266
|
+
return [4 /*yield*/, this.request(subject, data, opts)];
|
|
267
|
+
case 1:
|
|
268
|
+
fileDescriptor = _a.sent();
|
|
269
|
+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
270
|
+
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
271
|
+
var combinedResult = new Uint8Array([]);
|
|
272
|
+
var received = 0;
|
|
273
|
+
var subscription = _this.connection.subscribe(replySubject);
|
|
274
|
+
subscription.callback = function (error, message) {
|
|
275
|
+
if (error) {
|
|
276
|
+
reject(error);
|
|
277
|
+
}
|
|
278
|
+
combinedResult = new Uint8Array(__spreadArray(__spreadArray([], Array.from(combinedResult), true), Array.from(message === null || message === void 0 ? void 0 : message.data), true));
|
|
279
|
+
received++;
|
|
280
|
+
message.respond(Empty);
|
|
281
|
+
if (received === fileDescriptor.numberOfChunks) {
|
|
282
|
+
resolve(combinedResult);
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
}).then(function (byteArray) {
|
|
286
|
+
var jsonCodec = JSONCodec();
|
|
287
|
+
var response = jsonCodec.decode(byteArray);
|
|
288
|
+
return _this.isErrorResponse(response) ? Promise.reject(ErrorResponse.fromJS(response)) : Promise.resolve(response);
|
|
289
|
+
})];
|
|
290
|
+
}
|
|
291
|
+
});
|
|
292
|
+
});
|
|
293
|
+
};
|
|
181
294
|
/**
|
|
182
295
|
* Check if the the response is an error from the server.
|
|
183
296
|
* @param {any} response
|
package/lib/DTOs.d.ts
CHANGED
|
@@ -418,6 +418,45 @@ 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 PictureControl extends Setting implements IPictureControl {
|
|
422
|
+
description?: string | undefined;
|
|
423
|
+
mimeType?: string | undefined;
|
|
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;
|
|
441
|
+
}
|
|
442
|
+
export interface IResource {
|
|
443
|
+
source?: string | undefined;
|
|
444
|
+
}
|
|
445
|
+
export declare class FileDescriptor implements IFileDescriptor {
|
|
446
|
+
numberOfChunks: number;
|
|
447
|
+
fileSize: number;
|
|
448
|
+
chunkSize: number;
|
|
449
|
+
private readonly defaultChunkSize;
|
|
450
|
+
constructor(fileSize: number, chunkSize?: number);
|
|
451
|
+
init(_data?: any): void;
|
|
452
|
+
static fromJS(data: any): Resource;
|
|
453
|
+
toJSON(data?: any): any;
|
|
454
|
+
}
|
|
455
|
+
export interface IFileDescriptor {
|
|
456
|
+
numberOfChunks: number;
|
|
457
|
+
fileSize: number;
|
|
458
|
+
chunkSize: number;
|
|
459
|
+
}
|
|
421
460
|
export declare class ComponentSettings extends ComponentSettingsBase implements IComponentSettings {
|
|
422
461
|
settings?: Setting[] | undefined;
|
|
423
462
|
constructor(data?: IComponentSettings);
|
package/lib/DTOs.js
CHANGED
|
@@ -1238,6 +1238,100 @@ var PasswordControl = /** @class */ (function (_super) {
|
|
|
1238
1238
|
return PasswordControl;
|
|
1239
1239
|
}(Setting));
|
|
1240
1240
|
export { PasswordControl };
|
|
1241
|
+
var PictureControl = /** @class */ (function (_super) {
|
|
1242
|
+
__extends(PictureControl, _super);
|
|
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
|
+
}
|
|
1281
|
+
}
|
|
1282
|
+
Resource.prototype.init = function (_data) {
|
|
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;
|
|
1299
|
+
}());
|
|
1300
|
+
export { Resource };
|
|
1301
|
+
var FileDescriptor = /** @class */ (function () {
|
|
1302
|
+
function FileDescriptor(fileSize, chunkSize) {
|
|
1303
|
+
var _a;
|
|
1304
|
+
this.defaultChunkSize = 512000;
|
|
1305
|
+
if (chunkSize === 0) {
|
|
1306
|
+
throw Error('chunkSize cannot set to 0');
|
|
1307
|
+
}
|
|
1308
|
+
this.fileSize = fileSize;
|
|
1309
|
+
this.chunkSize = chunkSize !== null && chunkSize !== void 0 ? chunkSize : this.defaultChunkSize;
|
|
1310
|
+
this.numberOfChunks = Math.floor((((_a = this.fileSize) !== null && _a !== void 0 ? _a : 0) + this.chunkSize - 1) / this.chunkSize);
|
|
1311
|
+
}
|
|
1312
|
+
FileDescriptor.prototype.init = function (_data) {
|
|
1313
|
+
if (_data) {
|
|
1314
|
+
this.numberOfChunks = _data['NumberOfChunks'];
|
|
1315
|
+
this.fileSize = _data['FileSize'];
|
|
1316
|
+
this.chunkSize = _data['ChunkSize'];
|
|
1317
|
+
}
|
|
1318
|
+
};
|
|
1319
|
+
FileDescriptor.fromJS = function (data) {
|
|
1320
|
+
data = typeof data === 'object' ? data : {};
|
|
1321
|
+
var result = new Resource();
|
|
1322
|
+
result.init(data);
|
|
1323
|
+
return result;
|
|
1324
|
+
};
|
|
1325
|
+
FileDescriptor.prototype.toJSON = function (data) {
|
|
1326
|
+
data = typeof data === 'object' ? data : {};
|
|
1327
|
+
data['NumberOfChunks'] = this.numberOfChunks;
|
|
1328
|
+
data['FileSize'] = this.fileSize;
|
|
1329
|
+
data['ChunkSize'] = this.chunkSize;
|
|
1330
|
+
return data;
|
|
1331
|
+
};
|
|
1332
|
+
return FileDescriptor;
|
|
1333
|
+
}());
|
|
1334
|
+
export { FileDescriptor };
|
|
1241
1335
|
var ComponentSettings = /** @class */ (function (_super) {
|
|
1242
1336
|
__extends(ComponentSettings, _super);
|
|
1243
1337
|
function ComponentSettings(data) {
|
package/lib/SessionClient.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { BreakPoints, CommonContext, CommonSettings, DataGridControl, Image, Interaction, ListItemType, LogList, Parameter, RepositoryPackageDefinition, RepositoryPackageReference, Result, RunStatus, SessionEvent, Setting, TestPlan, TestRun, TestStepType, TestStepValidationError, WatchDog } from './DTOs';
|
|
1
|
+
import { BreakPoints, CommonContext, CommonSettings, DataGridControl, Image, Interaction, ListItemType, LogList, Parameter, RepositoryPackageDefinition, RepositoryPackageReference, Resource, 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,6 +86,11 @@ 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>;
|
|
89
94
|
/**
|
|
90
95
|
* Load test plan using a test plan TapPackage from a repository
|
|
91
96
|
* @param {RepositoryPackageDefinition} packageReference
|
package/lib/SessionClient.js
CHANGED
|
@@ -197,14 +197,27 @@ var SessionClient = /** @class */ (function (_super) {
|
|
|
197
197
|
* @return Test plan loaded. List of load errors is returned.
|
|
198
198
|
*/
|
|
199
199
|
SessionClient.prototype.setTestPlanXML = function (xml) {
|
|
200
|
-
return this.
|
|
200
|
+
return this.sendChunked('SetTestPlanXML', xml).then(this.success()).catch(this.error());
|
|
201
201
|
};
|
|
202
202
|
/**
|
|
203
203
|
* Retrieve loaded test plan XML
|
|
204
204
|
* @return Test plan retrieved
|
|
205
205
|
*/
|
|
206
206
|
SessionClient.prototype.getTestPlanXML = function () {
|
|
207
|
-
return this.
|
|
207
|
+
return this.requestChunked('GetTestPlanXML').then(this.success()).catch(this.error());
|
|
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).then(this.success()).catch(this.error());
|
|
208
221
|
};
|
|
209
222
|
/**
|
|
210
223
|
* Load test plan using a test plan TapPackage from a repository
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentap/runner-client",
|
|
3
|
-
"version": "2.0.0-alpha.2.
|
|
3
|
+
"version": "2.0.0-alpha.2.9",
|
|
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}": [
|