@opentap/runner-client 2.14.0-alpha.1.4 → 2.14.0

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.js CHANGED
@@ -145,13 +145,20 @@ var BaseClient = /** @class */ (function () {
145
145
  responsePromise = new Promise(function (resolve, reject) {
146
146
  var messages = [];
147
147
  subscription.callback = function (error, message) {
148
- var _a, _b, _c;
148
+ var _a, _b, _c, _d;
149
149
  if (error) {
150
150
  return reject(error);
151
151
  }
152
152
  if (((_a = message.headers) === null || _a === void 0 ? void 0 : _a.code) === 503) {
153
153
  return reject(Error('No responders.'));
154
154
  }
155
+ // If the message isn't chunked, we can assume the message is finished after a single message has been received.
156
+ var chunkNumber = (_b = message.headers) === null || _b === void 0 ? void 0 : _b.get('ChunkNumber');
157
+ // ChunkNumber starts from 1, so this check should be correct
158
+ if (!chunkNumber) {
159
+ subscription.unsubscribe();
160
+ return resolve({ byteArray: message.data, isErrorResponse: ((_c = message.headers) === null || _c === void 0 ? void 0 : _c.get('OpenTapNatsError')) === 'true' });
161
+ }
155
162
  // Put all the response chunks in an array in the order they are received
156
163
  messages.push(message);
157
164
  // If the chunk has a size equal to the chunkSize, we should expect another message
@@ -164,28 +171,22 @@ var BaseClient = /** @class */ (function () {
164
171
  // Check if the number of the final message is equal to the number of
165
172
  // messages we received. If this is not the case, we dropped a chunk,
166
173
  // likely due to a network error. In this case, the entire message is invalid.
167
- var finalMessage = message;
168
- var finalMessageNumber = (_b = finalMessage.headers) === null || _b === void 0 ? void 0 : _b.get('ChunkNumber');
169
- if (!finalMessageNumber) {
170
- return reject(Error('Response is not a valid chunk.'));
171
- }
172
- if (parseInt(finalMessageNumber) !== messages.length) {
174
+ if (parseInt(chunkNumber) !== messages.length) {
173
175
  return reject(Error("Expected {finalMessageNumber} chunks, but received ".concat(messages.length, ". ") +
174
176
  "The connection may have been interrupted."));
175
177
  }
176
178
  // Concatenate the payloads
177
179
  // When there are many chunks, doing a single allocation
178
180
  // is significantly faster than concatenating arrays in sequence
179
- var dataArrays = messages.map(function (m) { return m.data; });
180
- var flattenedSize = dataArrays.reduce(function (sum, array) { return sum + array.length; }, 0);
181
+ var flattenedSize = messages.reduce(function (sum, array) { return sum + array.data.length; }, 0);
181
182
  var flattenedArray = new Uint8Array(flattenedSize);
182
183
  var k = 0;
183
- dataArrays.map(function (m) {
184
- for (var i = 0; i < m.length; i++) {
185
- flattenedArray[k++] = m[i];
184
+ messages.forEach(function (m) {
185
+ for (var i = 0; i < m.data.length; i++) {
186
+ flattenedArray[k++] = m.data[i];
186
187
  }
187
188
  });
188
- return resolve({ byteArray: flattenedArray, isErrorResponse: ((_c = finalMessage.headers) === null || _c === void 0 ? void 0 : _c.get('OpenTapNatsError')) === 'true' });
189
+ return resolve({ byteArray: flattenedArray, isErrorResponse: ((_d = message.headers) === null || _d === void 0 ? void 0 : _d.get('OpenTapNatsError')) === 'true' });
189
190
  };
190
191
  }).then(function (_a) {
191
192
  var byteArray = _a.byteArray, isErrorResponse = _a.isErrorResponse;
package/lib/DTOs.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  export declare class Image implements IImage {
2
2
  name?: string | undefined;
3
- packages?: PackageSpecifier[];
4
- repositories?: string[];
3
+ packages?: PackageSpecifier[] | undefined;
4
+ repositories?: string[] | undefined;
5
5
  id?: string | undefined;
6
6
  constructor(data?: IImage);
7
7
  init(_data?: any): void;
package/lib/DTOs.js CHANGED
@@ -15,8 +15,6 @@ var __extends = (this && this.__extends) || (function () {
15
15
  })();
16
16
  var Image = /** @class */ (function () {
17
17
  function Image(data) {
18
- this.packages = [];
19
- this.repositories = [];
20
18
  if (data) {
21
19
  for (var property in data) {
22
20
  if (Object.prototype.hasOwnProperty.call(data, property))
@@ -1,14 +1,7 @@
1
- import { Image, RepositoryPackageReference, Session } from './DTOs';
1
+ import { Image, Session } from './DTOs';
2
2
  import { BaseClient } from './BaseClient';
3
3
  import { ConnectionOptions } from 'nats.ws';
4
4
  export declare class RunnerClient extends BaseClient {
5
- default: {
6
- startSession: (testPlanRepositoryReference?: RepositoryPackageReference, timeout?: number) => Promise<Session>;
7
- getImage: () => Promise<Image>;
8
- setImage: (image: Image) => Promise<Image>;
9
- getSettings: () => Promise<RepositoryPackageReference | undefined>;
10
- setSettings: (repositoryPackageReference: RepositoryPackageReference) => Promise<void>;
11
- };
12
5
  constructor(baseSubject: string, options: ConnectionOptions);
13
6
  /**
14
7
  * Get the created image with the specified ID.
@@ -33,13 +26,6 @@ export declare class RunnerClient extends BaseClient {
33
26
  * @returns {{Promise<Image>}}
34
27
  */
35
28
  resolveImage(images: Image[], timeout?: number): Promise<Image>;
36
- /**
37
- * Dry runs to resolve an image from a list of images. Dry run means that no packages will be downloaded.
38
- * @param {Image[]} images List of images
39
- * @param {number} timeout Optional timeout in milliseconds
40
- * @returns {{Promise<Image>}}
41
- */
42
- resolveImageDryRun(images: Image[], timeout?: number): Promise<Image>;
43
29
  /**
44
30
  * Shut down a session
45
31
  * @param sessionId the ID of the session to shut down
@@ -13,56 +13,12 @@ var __extends = (this && this.__extends) || (function () {
13
13
  d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __());
14
14
  };
15
15
  })();
16
- import { Image, RepositoryPackageReference, Session } from './DTOs';
16
+ import { Image, Session } from './DTOs';
17
17
  import { BaseClient } from './BaseClient';
18
18
  var RunnerClient = /** @class */ (function (_super) {
19
19
  __extends(RunnerClient, _super);
20
20
  function RunnerClient(baseSubject, options) {
21
- var _this = _super.call(this, baseSubject, options) || this;
22
- // Contains the endpoints for Defaults in the runner plugin.
23
- _this.default = {
24
- /* Create a Session based on the dependencies of a TestPlan. Returned
25
- Session will have referenced TestPlan pre-loaded. The Session will be
26
- created with the base image and base settings. */
27
- startSession: function (testPlanRepositoryReference, timeout) {
28
- return _this.request('StartDefaultSession', testPlanRepositoryReference !== null && testPlanRepositoryReference !== void 0 ? testPlanRepositoryReference : null, { timeout: timeout })
29
- .then(function (sessionJs) { return Session.fromJS(sessionJs); })
30
- .then(_this.success())
31
- .catch(_this.error());
32
- },
33
- /* Gets the base image. The base image is always included in the image
34
- creation process */
35
- getImage: function () {
36
- return _this.request('GetDefaultImage')
37
- .then(function (imageJs) { return Image.fromJS(imageJs); })
38
- .then(_this.success())
39
- .catch(_this.error());
40
- },
41
- /* Sets the base image. The specified image is resolved and set as the
42
- base image */
43
- setImage: function (image) {
44
- return _this.request('SetDefaultImage', image)
45
- .then(function (imageJs) { return Image.fromJS(imageJs); })
46
- .then(_this.success())
47
- .catch(_this.error());
48
- },
49
- /* Gets the base settings package. The base settings is always included
50
- in the image creation process and loaded into the created session */
51
- getSettings: function () {
52
- return _this.request('GetDefaultSettings')
53
- .then(function (repositoryPackageReferenceJs) {
54
- return repositoryPackageReferenceJs ? RepositoryPackageReference.fromJS(repositoryPackageReferenceJs) : undefined;
55
- })
56
- .then(_this.success())
57
- .catch(_this.error());
58
- },
59
- /* Sets the base settings package. The base settings is always included
60
- in the image creation process and loaded into the created session */
61
- setSettings: function (repositoryPackageReference) {
62
- return _this.request('SetDefaultSettings', repositoryPackageReference).then(_this.success()).catch(_this.error());
63
- },
64
- };
65
- return _this;
21
+ return _super.call(this, baseSubject, options) || this;
66
22
  }
67
23
  /**
68
24
  * Get the created image with the specified ID.
@@ -111,20 +67,6 @@ var RunnerClient = /** @class */ (function (_super) {
111
67
  .catch(this.error())
112
68
  : Promise.reject('images list is not defined or is empty');
113
69
  };
114
- /**
115
- * Dry runs to resolve an image from a list of images. Dry run means that no packages will be downloaded.
116
- * @param {Image[]} images List of images
117
- * @param {number} timeout Optional timeout in milliseconds
118
- * @returns {{Promise<Image>}}
119
- */
120
- RunnerClient.prototype.resolveImageDryRun = function (images, timeout) {
121
- return (images === null || images === void 0 ? void 0 : images.length) > 0
122
- ? this.request('ResolveImageDryRun', images, { timeout: timeout })
123
- .then(function (imageJs) { return Image.fromJS(imageJs); })
124
- .then(this.success())
125
- .catch(this.error())
126
- : Promise.reject('images list is not defined or is empty');
127
- };
128
70
  /**
129
71
  * Shut down a session
130
72
  * @param sessionId the ID of the session to shut down
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@opentap/runner-client",
3
- "version": "2.14.0-alpha.1.4",
3
+ "version": "2.14.0",
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",