@opentap/runner-client 2.0.0-alpha.2.16 → 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.
@@ -26,6 +26,8 @@ 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
33
  protected request<T>(subject: string, payload?: any, options?: RequestOptions, isFullSubject?: boolean): Promise<T>;
@@ -49,7 +51,7 @@ export declare class BaseClient {
49
51
  */
50
52
  protected subscribe(subject: string, options: SubscriptionOptions): Subscription;
51
53
  /**
52
- * Send a request to the nats server.
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,7 +59,7 @@ export declare class BaseClient {
57
59
  */
58
60
  protected sendChunked<T>(subject: string, payload?: any, options?: RequestOptions): Promise<T>;
59
61
  /**
60
- * Send a request to the nats server.
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)
package/lib/BaseClient.js CHANGED
@@ -107,6 +107,8 @@ 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
114
  BaseClient.prototype.request = function (subject, payload, options, isFullSubject) {
@@ -189,7 +191,7 @@ var BaseClient = /** @class */ (function () {
189
191
  return this.connection.subscribe(natsSubject, options);
190
192
  };
191
193
  /**
192
- * Send a request to the nats server.
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 requestSubject, stringCodec, data, headers, opts, fileDescriptor, getChunk, dataSubject, message, i, response, jsonCodec;
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(requestSubject, ": Connection is down! Please try again!"))];
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(requestSubject, ": Connection has been closed! Please reconnect!"))];
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(requestSubject, ": File is empty!"))];
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,7 +245,7 @@ var BaseClient = /** @class */ (function () {
242
245
  });
243
246
  };
244
247
  /**
245
- * Send a request to the nats server.
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)
@@ -250,41 +253,44 @@ var BaseClient = /** @class */ (function () {
250
253
  */
251
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(requestSubject, ": Connection is down! Please try again!"))];
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(requestSubject, ": Connection has been closed! Please reconnect!"))];
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
263
  var numberOfChunks = -1;
267
264
  var received = 0;
268
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
  };
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
284
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/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentap/runner-client",
3
- "version": "2.0.0-alpha.2.16",
3
+ "version": "2.0.0-alpha.2.17",
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",