@opentap/runner-client
Version:
This is the web client for the OpenTAP Runner.
169 lines (168 loc) • 8.03 kB
JavaScript
;
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 DTOs_1 = require("./DTOs");
var nats_ws_1 = require("nats.ws");
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 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 eventJson = jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data);
var testPlanRunStartEventArgs = DTOs_1.TestPlanRunStartEvent.fromJS(eventJson);
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 eventJson = jsonCodec.decode(message === null || message === void 0 ? void 0 : message.data);
var testPlanRunCompletedEventArgs = DTOs_1.TestPlanRunCompletedEvent.fromJS(eventJson);
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;