UNPKG

@opentap/runner-client

Version:

This is the web client for the OpenTAP Runner.

223 lines (222 loc) 11.1 kB
"use strict"; var __extends = (this && this.__extends) || (function () { var extendStatics = function (d, b) { extendStatics = Object.setPrototypeOf || ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || function (d, b) { for (var p in b) if (Object.prototype.hasOwnProperty.call(b, p)) d[p] = b[p]; }; return extendStatics(d, b); }; return function (d, b) { if (typeof b !== "function" && b !== null) throw new TypeError("Class extends value " + String(b) + " is not a constructor or null"); extendStatics(d, b); function __() { this.constructor = d; } d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); }; })(); var __assign = (this && this.__assign) || function () { __assign = Object.assign || function(t) { for (var s, i = 1, n = arguments.length; i < n; i++) { s = arguments[i]; for (var p in s) if (Object.prototype.hasOwnProperty.call(s, p)) t[p] = s[p]; } return t; }; return __assign.apply(this, arguments); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.SystemClient = void 0; var nats_ws_1 = require("nats.ws"); var DTOs_1 = require("./DTOs"); var BaseClient_1 = require("./BaseClient"); var SystemClient = /** @class */ (function (_super) { __extends(SystemClient, _super); function SystemClient(baseSubject, options) { return _super.call(this, baseSubject, options) || this; } /** * Subscribe to the lifetime event. * @param listener * @param {SubscriptionOptions} options * @returns {Subscription} */ SystemClient.prototype.subscribeLifetimeEventListener = function (listener, options) { var _this = this; var subject = 'Runner.*.Events.Lifetime'; return this.subscribe(subject, __assign(__assign({}, options), { callback: function (error, message) { if (error) { listener(_this.natsErrorHandler(error, subject), null); return; } try { var jsonCodec = (0, nats_ws_1.JSONCodec)(); var data = jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data); listener(null, data); } catch (error) { listener(_this.natsErrorHandler(error, subject), null); } } })); }; /** * Subscribe to the runner updated events for the given Runner ID. * Wildcard can be used to receive all runner updated events. * @param {string} runnerId * @param {(error:ErrorResponse|null,message:RunnerEvent|null)=>void} listener * @param {SubscriptionOptions} options? */ SystemClient.prototype.subscribeRunnerUpdatedEvents = function (runnerId, listener, options) { var _this = this; var subject = "RunnerRegistry.".concat(runnerId, ".Events.Updated"); return this.subscribe(subject, __assign(__assign({}, options), { callback: function (error, message) { if (error) { listener(_this.natsErrorHandler(error, subject), null); return; } try { var jsonCodec = (0, nats_ws_1.JSONCodec)(); var data = DTOs_1.RunnerEvent.fromJS(jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data)); listener(null, data); } catch (error) { listener(_this.natsErrorHandler(error, subject), null); } } })); }; /** * Subscribe to the test step run start events for the given Runner and Run ID. * Wildcard can be used for the Runner or Run ID to receive all test step run start events. * @param {string} runnerId * @param {string} runId * @param {(error:ErrorResponse|null,message:TestStepRunStartEventArgs|null)=>void} listener * @param {SubscriptionOptions} options? */ SystemClient.prototype.subscribeTestStepRunStartEventListener = function (runnerId, runId, listener, options) { var _this = this; var subject = "Runner.".concat(runnerId, ".Runs.").concat(runId, ".Events.TestStepRunStart"); return this.subscribe(subject, __assign(__assign({}, options), { callback: function (error, message) { if (error) { listener(_this.natsErrorHandler(error, subject), null); return; } try { var jsonCodec = (0, nats_ws_1.JSONCodec)(); var testStepRunStartEventArgsJs = jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data); var testStepRunStartEventArgs = DTOs_1.TestStepRunStartEventArgs.fromJS(testStepRunStartEventArgsJs); listener(null, testStepRunStartEventArgs); } catch (error) { listener(_this.natsErrorHandler(error, subject), null); } } })); }; /** * Subscribe to the test step run completed events for the given Runner and Run ID. * Wildcard can be used for the Runner or Run ID to receive all test step run completed events. * @param {string} runnerId * @param {string} runId * @param {(error:ErrorResponse|null,message:TestStepRunStartEventArgs|null)=>void} listener * @param {SubscriptionOptions} options? */ SystemClient.prototype.subscribeTestStepRunCompletedEventListener = function (runnerId, runId, listener, options) { var _this = this; var subject = "Runner.".concat(runnerId, ".Runs.").concat(runId, ".Events.TestStepRunCompleted"); return this.subscribe(subject, __assign(__assign({}, options), { callback: function (error, message) { if (error) { listener(_this.natsErrorHandler(error, subject), null); return; } try { var jsonCodec = (0, nats_ws_1.JSONCodec)(); var testStepRunCompletedEventArgsJs = jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data); var testStepRunCompletedEventArgs = DTOs_1.TestStepRunCompletedEventArgs.fromJS(testStepRunCompletedEventArgsJs); listener(null, testStepRunCompletedEventArgs); } catch (error) { listener(_this.natsErrorHandler(error, subject), null); } } })); }; /** * Subscribe to the test plan run start events for the given Runner and Run ID. * Wildcard can be used for the Runner or Run ID to receive all test plan run start events. * @param {string} runnerId * @param {string} runId * @param {(error:ErrorResponse|null,message:TestStepRunStartEventArgs|null)=>void} listener * @param {SubscriptionOptions} options? */ SystemClient.prototype.subscribeTestPlanRunStartEventListener = function (runnerId, runId, listener, options) { var _this = this; var subject = "Runner.".concat(runnerId, ".Runs.").concat(runId, ".Events.TestPlanRunStart"); return this.subscribe(subject, __assign(__assign({}, options), { callback: function (error, message) { if (error) { listener(_this.natsErrorHandler(error, subject), null); return; } try { var jsonCodec = (0, nats_ws_1.JSONCodec)(); var testPlanRunStartEventArgsJs = jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data); var testPlanRunStartEventArgs = DTOs_1.TestPlanRunStartEventArgs.fromJS(testPlanRunStartEventArgsJs); listener(null, testPlanRunStartEventArgs); } catch (error) { listener(_this.natsErrorHandler(error, subject), null); } } })); }; /** * Subscribe to the test plan run completed events for the given Runner and Run ID. * Wildcard can be used for the Runner or Run ID to receive all test plan run completed events. * @param {string} runnerId * @param {string} runId * @param {(error:ErrorResponse|null,message:TestStepRunStartEventArgs|null)=>void} listener * @param {SubscriptionOptions} options? */ SystemClient.prototype.subscribeTestPlanRunCompletedEventListener = function (runnerId, runId, listener, options) { var _this = this; var subject = "Runner.".concat(runnerId, ".Runs.").concat(runId, ".Events.TestPlanRunCompleted"); return this.subscribe(subject, __assign(__assign({}, options), { callback: function (error, message) { if (error) { listener(_this.natsErrorHandler(error, subject), null); return; } try { var jsonCodec = (0, nats_ws_1.JSONCodec)(); var testPlanRunCompletedEventArgsJs = jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data); var testPlanRunCompletedEventArgs = DTOs_1.TestPlanRunCompletedEventArgs.fromJS(testPlanRunCompletedEventArgsJs); listener(null, testPlanRunCompletedEventArgs); } catch (error) { listener(_this.natsErrorHandler(error, subject), null); } } })); }; /** * Subscribe to the asset update events for the given Runner ID. * Wildcard can be used to receive all asset update events. * @param {string} runnerId * @param {(error:ErrorResponse|null,message:AssetUpdatedEvent|null)=>void} listener * @param {SubscriptionOptions} options? */ SystemClient.prototype.subscribeAssetUpdatedEvents = function (runnerId, listener, options) { var _this = this; var subject = "RunnerRegistry.".concat(runnerId, ".Events.AssetsUpdated"); return this.subscribe(subject, __assign(__assign({}, options), { callback: function (error, message) { if (error) { listener(_this.natsErrorHandler(error, subject), null); return; } try { var jsonCodec = (0, nats_ws_1.JSONCodec)(); var data = DTOs_1.AssetUpdatedEvent.fromJS(jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data)); listener(null, data); } catch (error) { listener(_this.natsErrorHandler(error, subject), null); } } })); }; return SystemClient; }(BaseClient_1.BaseClient)); exports.SystemClient = SystemClient;