@opentap/runner-client 2.0.0-alpha.2.15 → 2.0.0-alpha.2.17
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 +6 -4
- package/lib/BaseClient.js +28 -22
- package/lib/SessionClient.js +1 -1
- package/package.json +1 -1
package/lib/BaseClient.d.ts
CHANGED
|
@@ -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
|
|
@@ -49,7 +51,7 @@ export declare class BaseClient {
|
|
|
49
51
|
*/
|
|
50
52
|
protected subscribe(subject: string, options: SubscriptionOptions): Subscription;
|
|
51
53
|
/**
|
|
52
|
-
* Send
|
|
54
|
+
* Send an object to the nats server with chunks.
|
|
53
55
|
* @param subject The subject to request
|
|
54
56
|
* @param payload (optional)
|
|
55
57
|
* @param options (optional)
|
|
@@ -57,13 +59,13 @@ export declare class BaseClient {
|
|
|
57
59
|
*/
|
|
58
60
|
protected sendChunked<T>(subject: string, payload?: any, options?: RequestOptions): Promise<T>;
|
|
59
61
|
/**
|
|
60
|
-
*
|
|
62
|
+
* Request an object to the nats server with chunks.
|
|
61
63
|
* @param subject The subject to request
|
|
62
64
|
* @param payload (optional)
|
|
63
65
|
* @param options (optional)
|
|
64
66
|
* @returns Promise of an object
|
|
65
67
|
*/
|
|
66
|
-
protected requestChunked<T>(subject: string, options?: RequestOptions): Promise<T>;
|
|
68
|
+
protected requestChunked<T>(subject: string, options?: RequestOptions, isFullSubject?: boolean): Promise<T>;
|
|
67
69
|
/**
|
|
68
70
|
* Check if the the response is an error from the server.
|
|
69
71
|
* @param {any} response
|
package/lib/BaseClient.js
CHANGED
|
@@ -107,16 +107,18 @@ var BaseClient = /** @class */ (function () {
|
|
|
107
107
|
* @param subject The subject to request
|
|
108
108
|
* @param payload (optional)
|
|
109
109
|
* @param options (optional)
|
|
110
|
+
* @param isFullSubject (optional) If true, use the subject as request subject
|
|
111
|
+
* without appending it to the baseSubject
|
|
110
112
|
* @returns Promise of an object
|
|
111
113
|
*/
|
|
112
|
-
BaseClient.prototype.request = function (subject, payload, options) {
|
|
114
|
+
BaseClient.prototype.request = function (subject, payload, options, isFullSubject) {
|
|
113
115
|
return __awaiter(this, void 0, void 0, function () {
|
|
114
116
|
var stringCodec, data, headers, opts;
|
|
115
117
|
var _this = this;
|
|
116
118
|
return __generator(this, function (_a) {
|
|
117
119
|
switch (_a.label) {
|
|
118
120
|
case 0:
|
|
119
|
-
subject = "".concat(this.baseSubject, ".Request.").concat(subject);
|
|
121
|
+
subject = isFullSubject ? subject : "".concat(this.baseSubject, ".Request.").concat(subject);
|
|
120
122
|
if (!this.connection)
|
|
121
123
|
return [2 /*return*/, Promise.reject("".concat(subject, ": Connection is down! Please try again!"))];
|
|
122
124
|
if (this.connection.isClosed())
|
|
@@ -189,7 +191,7 @@ var BaseClient = /** @class */ (function () {
|
|
|
189
191
|
return this.connection.subscribe(natsSubject, options);
|
|
190
192
|
};
|
|
191
193
|
/**
|
|
192
|
-
* Send
|
|
194
|
+
* Send an object to the nats server with chunks.
|
|
193
195
|
* @param subject The subject to request
|
|
194
196
|
* @param payload (optional)
|
|
195
197
|
* @param options (optional)
|
|
@@ -197,22 +199,21 @@ var BaseClient = /** @class */ (function () {
|
|
|
197
199
|
*/
|
|
198
200
|
BaseClient.prototype.sendChunked = function (subject, payload, options) {
|
|
199
201
|
return __awaiter(this, void 0, void 0, function () {
|
|
200
|
-
var
|
|
202
|
+
var stringCodec, data, headers, opts, fileDescriptor, getChunk, dataSubject, message, i, response, jsonCodec;
|
|
201
203
|
return __generator(this, function (_a) {
|
|
202
204
|
switch (_a.label) {
|
|
203
205
|
case 0:
|
|
204
|
-
requestSubject = "".concat(this.baseSubject, ".Request.").concat(subject);
|
|
205
206
|
if (!this.connection)
|
|
206
|
-
return [2 /*return*/, Promise.reject("".concat(
|
|
207
|
+
return [2 /*return*/, Promise.reject("".concat(subject, ": Connection is down! Please try again!"))];
|
|
207
208
|
if (this.connection.isClosed())
|
|
208
|
-
return [2 /*return*/, Promise.reject("".concat(
|
|
209
|
+
return [2 /*return*/, Promise.reject("".concat(subject, ": Connection has been closed! Please reconnect!"))];
|
|
209
210
|
stringCodec = StringCodec();
|
|
210
211
|
data = payload ? stringCodec.encode(JSON.stringify(payload)) : Empty;
|
|
211
212
|
headers = this.buildHeaders();
|
|
212
213
|
opts = __assign(__assign({}, options), { timeout: this.timeout, headers: headers });
|
|
213
214
|
fileDescriptor = new FileDescriptor(data.length);
|
|
214
215
|
if (!fileDescriptor.numberOfChunks)
|
|
215
|
-
return [2 /*return*/, Promise.reject("".concat(
|
|
216
|
+
return [2 /*return*/, Promise.reject("".concat(subject, ": File is empty!"))];
|
|
216
217
|
getChunk = function (chunk) {
|
|
217
218
|
var offset = chunk * fileDescriptor.chunkSize;
|
|
218
219
|
return data.slice(offset, offset + fileDescriptor.chunkSize);
|
|
@@ -226,6 +227,8 @@ var BaseClient = /** @class */ (function () {
|
|
|
226
227
|
if (!(i < fileDescriptor.numberOfChunks)) return [3 /*break*/, 5];
|
|
227
228
|
return [4 /*yield*/, this.connection.request(dataSubject, getChunk(i), opts)];
|
|
228
229
|
case 3:
|
|
230
|
+
// The main response will be received after the last chunk is sent, the intermediate ones
|
|
231
|
+
// are empty acknowledgement messages
|
|
229
232
|
message = _a.sent();
|
|
230
233
|
_a.label = 4;
|
|
231
234
|
case 4:
|
|
@@ -242,49 +245,52 @@ var BaseClient = /** @class */ (function () {
|
|
|
242
245
|
});
|
|
243
246
|
};
|
|
244
247
|
/**
|
|
245
|
-
*
|
|
248
|
+
* Request an object to the nats server with chunks.
|
|
246
249
|
* @param subject The subject to request
|
|
247
250
|
* @param payload (optional)
|
|
248
251
|
* @param options (optional)
|
|
249
252
|
* @returns Promise of an object
|
|
250
253
|
*/
|
|
251
|
-
BaseClient.prototype.requestChunked = function (subject, options) {
|
|
254
|
+
BaseClient.prototype.requestChunked = function (subject, options, isFullSubject) {
|
|
252
255
|
return __awaiter(this, void 0, void 0, function () {
|
|
253
|
-
var replySubject, requestSubject, headers, opts;
|
|
254
256
|
var _this = this;
|
|
255
257
|
return __generator(this, function (_a) {
|
|
256
|
-
replySubject = "_INBOX.".concat(uuidv4());
|
|
257
|
-
requestSubject = "".concat(this.baseSubject, ".Request.").concat(subject);
|
|
258
258
|
if (!this.connection)
|
|
259
|
-
return [2 /*return*/, Promise.reject("".concat(
|
|
259
|
+
return [2 /*return*/, Promise.reject("".concat(subject, ": Connection is down! Please try again!"))];
|
|
260
260
|
if (this.connection.isClosed())
|
|
261
|
-
return [2 /*return*/, Promise.reject("".concat(
|
|
262
|
-
headers = this.buildHeaders();
|
|
263
|
-
opts = __assign(__assign({}, options), { timeout: this.timeout, headers: headers });
|
|
264
|
-
// eslint-disable-next-line @typescript-eslint/no-unused-vars
|
|
261
|
+
return [2 /*return*/, Promise.reject("".concat(subject, ": Connection has been closed! Please reconnect!"))];
|
|
265
262
|
return [2 /*return*/, new Promise(function (resolve, reject) {
|
|
266
|
-
var numberOfChunks =
|
|
267
|
-
var combinedResult = new Uint8Array([]);
|
|
263
|
+
var numberOfChunks = -1;
|
|
268
264
|
var received = 0;
|
|
265
|
+
var combinedResult = new Uint8Array([]);
|
|
266
|
+
// Resolves the promise if the all of the chunks are received
|
|
269
267
|
var resolveIfComplete = function () {
|
|
270
268
|
if (received === numberOfChunks) {
|
|
271
269
|
resolve(combinedResult);
|
|
272
270
|
}
|
|
273
271
|
};
|
|
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
|
|
274
275
|
var subscription = _this.connection.subscribe(replySubject);
|
|
275
276
|
subscription.callback = function (error, message) {
|
|
276
277
|
if (error) {
|
|
277
278
|
reject(error);
|
|
278
279
|
}
|
|
280
|
+
// Combine each chunk
|
|
279
281
|
combinedResult = new Uint8Array(__spreadArray(__spreadArray([], Array.from(combinedResult), true), Array.from(message === null || message === void 0 ? void 0 : message.data), true));
|
|
280
282
|
received++;
|
|
281
|
-
message.respond(Empty);
|
|
283
|
+
message.respond(Empty); // Respond acknowledgement
|
|
282
284
|
resolveIfComplete();
|
|
283
285
|
};
|
|
284
|
-
|
|
286
|
+
var headers = _this.buildHeaders();
|
|
287
|
+
var opts = __assign(__assign({}, options), { timeout: _this.timeout, headers: headers });
|
|
288
|
+
// Request the file descriptor from the runner by posting the reply subject
|
|
289
|
+
return _this.request(subject, replySubject, opts, isFullSubject)
|
|
285
290
|
.then(function (fileDescriptor) { return FileDescriptor.fromJS(fileDescriptor); })
|
|
286
291
|
.then(function (fileDescriptor) {
|
|
287
292
|
numberOfChunks = fileDescriptor.numberOfChunks;
|
|
293
|
+
// Check if the chunks are already received
|
|
288
294
|
resolveIfComplete();
|
|
289
295
|
});
|
|
290
296
|
}).then(function (byteArray) {
|
package/lib/SessionClient.js
CHANGED
|
@@ -217,7 +217,7 @@ var SessionClient = /** @class */ (function (_super) {
|
|
|
217
217
|
return Promise.reject('The source of the provided resource is not a nats subject.');
|
|
218
218
|
}
|
|
219
219
|
var subject = resource.source.replace(runnerResourcePrefix, '');
|
|
220
|
-
return this.requestChunked(subject).then(this.success()).catch(this.error());
|
|
220
|
+
return this.requestChunked(subject, undefined, true).then(this.success()).catch(this.error());
|
|
221
221
|
};
|
|
222
222
|
/**
|
|
223
223
|
* Load test plan using a test plan TapPackage from a repository
|