UNPKG

diffusion

Version:

Diffusion JavaScript client

98 lines (97 loc) 3.9 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.MetricsRequestImpl = exports.RequestType = void 0; var errors_1 = require("./../../../errors/errors"); var Services = require("./../../services/metrics-services"); var require_non_null_1 = require("./../../util/require-non-null"); /** * The request type */ var RequestType; (function (RequestType) { /** * Request metrics from the current server. */ RequestType[RequestType["CURRENT_SERVER"] = 0] = "CURRENT_SERVER"; /** * Request metrics from all servers. */ RequestType[RequestType["ALL_SERVERS"] = 1] = "ALL_SERVERS"; /** * Request metrics from a named server. */ RequestType[RequestType["NAMED_SERVER"] = 2] = "NAMED_SERVER"; })(RequestType = exports.RequestType || (exports.RequestType = {})); /** * Implementation of {@link MetricsRequest}. */ var MetricsRequestImpl = /** @class */ (function () { /** * Constructs a new instance of MetricsRequestImpl. * * @param filters the filters to be applied * @param server the server name * @param requestType the request type * @param internal the internal session */ function MetricsRequestImpl(filters, pattern, server, requestType, internal) { this.theFilters = filters; this.pattern = pattern; this.theServer = server; this.theRequestType = requestType; this.internal = internal; } /** * Creates a new MetricsRequestImpl instance with the specified service reference. * * @param internal the internal session * @return a new MetricsRequestImpl instance */ MetricsRequestImpl.create = function (internal) { return new MetricsRequestImpl(new Set(), undefined, undefined, RequestType.ALL_SERVERS, internal); }; MetricsRequestImpl.prototype.filter = function (newFilters) { require_non_null_1.requireNonNull(newFilters, 'filters'); if (typeof newFilters === 'string' || newFilters instanceof RegExp) { return new MetricsRequestImpl(new Set(), newFilters instanceof RegExp ? newFilters.source : newFilters, this.theServer, this.theRequestType, this.internal); } else { return new MetricsRequestImpl(new Set(newFilters), undefined, this.theServer, this.theRequestType, this.internal); } }; MetricsRequestImpl.prototype.server = function (newServer) { require_non_null_1.requireNonNull(newServer, 'server'); if (newServer === '') { throw new errors_1.IllegalArgumentError('server must not be empty'); } return new MetricsRequestImpl(this.theFilters, this.pattern, newServer, RequestType.NAMED_SERVER, this.internal); }; MetricsRequestImpl.prototype.currentServer = function () { return new MetricsRequestImpl(this.theFilters, this.pattern, undefined, RequestType.CURRENT_SERVER, this.internal); }; MetricsRequestImpl.prototype.fetch = function () { var _this = this; var _a; var request = { filters: this.theFilters, pattern: (_a = this.pattern) !== null && _a !== void 0 ? _a : '', server: this.theServer, requestType: this.theRequestType }; return new Promise(function (resolve, reject) { if (_this.internal.checkConnected(reject)) { var GET_METRICS = _this.internal.getServiceLocator().obtain(Services.GET_METRICS); GET_METRICS.send(request, function (err, response) { if (err) { reject(err); } else { resolve(response); } }); } }); }; return MetricsRequestImpl; }()); exports.MetricsRequestImpl = MetricsRequestImpl;