UNPKG

@mdf.js/service-registry

Version:

MMS - API - Service Registry

156 lines 6.32 kB
"use strict"; /** * Copyright 2024 Mytra Control S.L. All rights reserved. * * Use of this source code is governed by an MIT-style license that can be found in the LICENSE file * or at https://opensource.org/licenses/MIT. */ Object.defineProperty(exports, "__esModule", { value: true }); exports.SettingsManagerAccessors = void 0; const tslib_1 = require("tslib"); const core_1 = require("@mdf.js/core"); const cluster_1 = tslib_1.__importDefault(require("cluster")); const Router_1 = require("./Router"); const SettingsManagerBase_1 = require("./SettingsManagerBase"); const types_1 = require("./types"); /** * SettingsManager is responsible for managing the application's settings, including the * configuration for the service registry and custom settings specified by the user. It extends * EventEmitter to allow for emitting events related to settings management and implements the * Service interface from the Layer.App namespace, indicating its role in the application's service * architecture. It utilizes configuration managers for both service registry and custom settings, * supporting dynamic loading and management of these configurations. * * Additionally, it can load application metadata from package.json and README.md content, providing * a centralized way to access application information and documentation. */ class SettingsManagerAccessors extends SettingsManagerBase_1.SettingsManagerBase { /** * Constructs a SettingsManager instance, initializing configuration providers and loading * `package.json` and README information. * @param bootstrapOptions - Bootstrap settings, define how the Custom and the Service Registry * settings should be loaded. * @param serviceRegistryOptions - Service Registry settings, used as a base for the Service * Registry configuration manager. * @param customSettings - Custom settings provided by the user, used as a base for the Custom * configuration manager. */ constructor(bootstrapOptions, serviceRegistryOptions, customSettings) { super(bootstrapOptions, serviceRegistryOptions, customSettings); this._router = new Router_1.Router(this); } /** @returns Service name */ get name() { return types_1.CONFIG_SERVICE_NAME; } /** @returns Service instance identifier */ get componentId() { return this.metadata.instanceId; } /** @returns Settings manager status */ get status() { return core_1.Health.overallStatus(this.checks); } /** @returns Settings manager checks */ get checks() { const _checks = { [`${this.metadata.name}:settings`]: [] }; const _unwindChecks = (_value) => { for (const [key, entries] of Object.entries(_value)) { const _key = key.split(':')[0]; _checks[`${this.metadata.name}:settings`].push(...entries.map(entry => ({ ...entry, scope: `${_key}`, componentId: this.componentId, observedUnit: 'status', }))); } }; _unwindChecks(this.serviceRegistrySettingsProvider.checks); _unwindChecks(this.customSettingsProvider.checks); return _checks; } /** @returns A validation error, if exist, in the configuration loaded */ get error() { return this._error; } /** @returns Service Metadata */ get metadata() { return this.serviceRegistrySettingsProvider.client.config.metadata; } /** @returns Application namespace */ get namespace() { return this.metadata.namespace; } /** @returns Application release */ get release() { return this.metadata.release; } /** @returns Observability options */ get observability() { return { metadata: this.metadata, service: this.serviceRegistrySettingsProvider.client.config.observabilityOptions, }; } /** @returns Logger configuration */ get logger() { return this.serviceRegistrySettingsProvider.client.config.loggerOptions; } /** @returns If the application is the primary node in the cluster */ get isPrimary() { var _a; return ((_a = this.serviceRegistrySettingsProvider.client.config.observabilityOptions) === null || _a === void 0 ? void 0 : _a.isCluster) ? cluster_1.default.isPrimary : false; } /** @returns If the application is a worker node in the cluster */ get isWorker() { var _a; return ((_a = this.serviceRegistrySettingsProvider.client.config.observabilityOptions) === null || _a === void 0 ? void 0 : _a.isCluster) ? cluster_1.default.isWorker : false; } /** @returns Service Register Configuration Manager */ get serviceRegisterConfigManager() { return this.serviceRegistrySettingsProvider.client; } /** @returns Service Register settings */ get serviceRegistrySettings() { return this.serviceRegistrySettingsProvider.client.config; } /** @returns Custom Configuration Manager */ get customRegisterConfigManager() { return this.customSettingsProvider.client; } /** @returns Custom settings */ get customSettings() { return this.customSettingsProvider.client.config; } /** @returns Service settings */ get settings() { return { ...this.serviceRegistrySettings, custom: this.customSettings, }; } /** Get the retry options */ get retryOptions() { return this.serviceRegistrySettingsProvider.client.config.retryOptions; } /** @returns Express router with access to config information */ get router() { return this._router.router; } /** @returns Links offered by this service */ get links() { return { [`${types_1.CONFIG_SERVICE_NAME}`]: { config: `/${types_1.CONFIG_SERVICE_NAME}/config`, presets: `/${types_1.CONFIG_SERVICE_NAME}/presets`, readme: `/${types_1.CONFIG_SERVICE_NAME}/readme`, }, }; } } exports.SettingsManagerAccessors = SettingsManagerAccessors; //# sourceMappingURL=SettingsManagerAccessors.js.map