@opentap/runner-client 2.1.3-alpha.1.1 → 2.1.3-alpha.1.4
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 +14 -0
- package/lib/BaseClient.js +32 -6
- package/package.json +2 -1
package/lib/BaseClient.d.ts
CHANGED
|
@@ -1,10 +1,13 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
1
2
|
import { ComponentSettingsBase, ComponentSettingsIdentifier, ComponentSettingsListItem, DataGridControl, ErrorResponse, FileParameter, FileResponse, ListItemType, ProfileGroup, RepositoryPackageReference, RepositorySettingsPackageDefinition, SettingsTapPackage } from './DTOs';
|
|
2
3
|
import { ConnectionOptions, RequestOptions, Subscription, SubscriptionOptions } from 'nats.ws';
|
|
4
|
+
import { EventEmitter } from 'events';
|
|
3
5
|
export declare class BaseClient {
|
|
4
6
|
private connection;
|
|
5
7
|
private baseSubject;
|
|
6
8
|
private connectionOptions;
|
|
7
9
|
private domainAccess;
|
|
10
|
+
private eventEmitter;
|
|
8
11
|
private _accessToken;
|
|
9
12
|
private _headers;
|
|
10
13
|
private _timeout;
|
|
@@ -97,6 +100,17 @@ export declare class BaseClient {
|
|
|
97
100
|
* @returns
|
|
98
101
|
*/
|
|
99
102
|
protected success<T>(): ((value: T) => T | PromiseLike<T>) | null | undefined;
|
|
103
|
+
/**
|
|
104
|
+
* Add an error-event listener.
|
|
105
|
+
* @param listener
|
|
106
|
+
* @returns {EventEmitter}
|
|
107
|
+
*/
|
|
108
|
+
addErrorEventListener(listener: (...args: any[]) => void): EventEmitter;
|
|
109
|
+
/**
|
|
110
|
+
* Remove an error-event listener.
|
|
111
|
+
* @param listener
|
|
112
|
+
*/
|
|
113
|
+
removeAllErrorEventListener(): void;
|
|
100
114
|
/**
|
|
101
115
|
* Retrieve component settings overview
|
|
102
116
|
* @returns {{Promise<ComponentSettingsIdentifier[]>}}
|
package/lib/BaseClient.js
CHANGED
|
@@ -56,6 +56,7 @@ 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 { EventEmitter } from 'events';
|
|
59
60
|
var DEFAULT_TIMEOUT = 6000;
|
|
60
61
|
var BaseClient = /** @class */ (function () {
|
|
61
62
|
function BaseClient(baseSubject, options) {
|
|
@@ -64,6 +65,7 @@ var BaseClient = /** @class */ (function () {
|
|
|
64
65
|
this.baseSubject = baseSubject;
|
|
65
66
|
this.connectionOptions = __assign({}, options) || {};
|
|
66
67
|
this.connectionOptions.timeout = (options === null || options === void 0 ? void 0 : options.timeout) || DEFAULT_TIMEOUT;
|
|
68
|
+
this.eventEmitter = new EventEmitter();
|
|
67
69
|
}
|
|
68
70
|
Object.defineProperty(BaseClient.prototype, "accessToken", {
|
|
69
71
|
/** Get request access token */
|
|
@@ -135,7 +137,12 @@ var BaseClient = /** @class */ (function () {
|
|
|
135
137
|
var jsonCodec = JSONCodec();
|
|
136
138
|
response = jsonCodec.decode(message.data);
|
|
137
139
|
}
|
|
138
|
-
|
|
140
|
+
if (_this.isErrorResponse(response)) {
|
|
141
|
+
var error = ErrorResponse.fromJS(response);
|
|
142
|
+
_this.eventEmitter.emit('errorEvent', error);
|
|
143
|
+
return Promise.reject(error);
|
|
144
|
+
}
|
|
145
|
+
return Promise.resolve(response);
|
|
139
146
|
})
|
|
140
147
|
.catch(function (error) { return Promise.reject(_this.natsErrorHandler(error, subject)); })];
|
|
141
148
|
case 1: return [2 /*return*/, _a.sent()];
|
|
@@ -160,6 +167,7 @@ var BaseClient = /** @class */ (function () {
|
|
|
160
167
|
default:
|
|
161
168
|
errorResponse.message = error.message;
|
|
162
169
|
}
|
|
170
|
+
this.eventEmitter.emit('errorEvent', errorResponse);
|
|
163
171
|
return errorResponse;
|
|
164
172
|
};
|
|
165
173
|
/**
|
|
@@ -267,16 +275,17 @@ var BaseClient = /** @class */ (function () {
|
|
|
267
275
|
* @returns Promise of an object
|
|
268
276
|
*/
|
|
269
277
|
BaseClient.prototype.requestChunked = function (subject, replySubject, payload, options, isFullSubject, rawResponse) {
|
|
278
|
+
var _a;
|
|
270
279
|
return __awaiter(this, void 0, void 0, function () {
|
|
271
280
|
var fileSize;
|
|
272
281
|
var _this = this;
|
|
273
|
-
return __generator(this, function (
|
|
274
|
-
if (
|
|
275
|
-
return [2 /*return*/, Promise.reject("".concat(subject, ": Connection is down! Please try again!"))];
|
|
276
|
-
if (this.connection.isClosed())
|
|
282
|
+
return __generator(this, function (_b) {
|
|
283
|
+
if ((_a = this.connection) === null || _a === void 0 ? void 0 : _a.isClosed())
|
|
277
284
|
return [2 /*return*/, Promise.reject("".concat(subject, ": Connection has been closed! Please reconnect!"))];
|
|
278
285
|
fileSize = -1;
|
|
279
286
|
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
287
|
+
if (!_this.connection)
|
|
288
|
+
return Promise.reject("".concat(subject, ": Connection is down! Please try again!"));
|
|
280
289
|
var combinedResult = new Uint8Array([]);
|
|
281
290
|
// Subscribe to the subject before starting the process
|
|
282
291
|
var subscription = _this.connection.subscribe(replySubject);
|
|
@@ -375,7 +384,7 @@ var BaseClient = /** @class */ (function () {
|
|
|
375
384
|
_this.connection = null;
|
|
376
385
|
}).catch(function (error) {
|
|
377
386
|
throw new Error("failed to close connection: ".concat(error));
|
|
378
|
-
}))];
|
|
387
|
+
}).finally(function () { return _this === null || _this === void 0 ? void 0 : _this.removeAllErrorEventListener(); }))];
|
|
379
388
|
case 1:
|
|
380
389
|
_b.sent();
|
|
381
390
|
_b.label = 2;
|
|
@@ -410,6 +419,23 @@ var BaseClient = /** @class */ (function () {
|
|
|
410
419
|
BaseClient.prototype.success = function () {
|
|
411
420
|
return function (response) { return response; };
|
|
412
421
|
};
|
|
422
|
+
/**
|
|
423
|
+
* Add an error-event listener.
|
|
424
|
+
* @param listener
|
|
425
|
+
* @returns {EventEmitter}
|
|
426
|
+
*/
|
|
427
|
+
BaseClient.prototype.addErrorEventListener = function (listener) {
|
|
428
|
+
var _a;
|
|
429
|
+
return (_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.addListener('errorEvent', listener);
|
|
430
|
+
};
|
|
431
|
+
/**
|
|
432
|
+
* Remove an error-event listener.
|
|
433
|
+
* @param listener
|
|
434
|
+
*/
|
|
435
|
+
BaseClient.prototype.removeAllErrorEventListener = function () {
|
|
436
|
+
var _a;
|
|
437
|
+
(_a = this.eventEmitter) === null || _a === void 0 ? void 0 : _a.removeAllListeners('errorEvent');
|
|
438
|
+
};
|
|
413
439
|
/**
|
|
414
440
|
* Retrieve component settings overview
|
|
415
441
|
* @returns {{Promise<ComponentSettingsIdentifier[]>}}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@opentap/runner-client",
|
|
3
|
-
"version": "2.1.3-alpha.1.
|
|
3
|
+
"version": "2.1.3-alpha.1.4",
|
|
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/node": "^18.11.9",
|
|
29
30
|
"@types/uuid": "^8.3.4",
|
|
30
31
|
"@typescript-eslint/eslint-plugin": "^5.36.1",
|
|
31
32
|
"@typescript-eslint/parser": "^5.36.1",
|