UNPKG

@mdf.js/service-registry

Version:

MMS - API - Service Registry

98 lines 4.04 kB
/** * 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. */ import { Health, Layer } from '@mdf.js/core'; import EventEmitter from 'events'; import express from 'express'; import { ErrorRecord, HandleableError, RegistryOptions } from './types'; /** * The RegisterFacade class provides a centralized solution for error monitoring across all * components of an application. It acts as a facade over various underlying mechanisms to * facilitate error aggregation, error information exposure through REST APIs, and error registry * management. * * It integrates with: * - Port: To handle inter-process communication for error information in clustered environments, * distinguishing between master and worker processes. * - Aggregator: To aggregate error information from different components of the application. * * This class also provides a REST API endpoint for accessing collected error information and * supports operations for registering errors and clearing the error registry. */ export declare class RegisterFacade extends EventEmitter implements Layer.App.Service { private readonly options; /** Debug logger for development and deep troubleshooting */ private readonly logger; /** Health aggregator */ private readonly aggregator; /** Health registry */ private readonly port?; /** Health router */ private readonly _router; /** * Create an instance of register manager * @param options - registry options */ constructor(options: RegistryOptions); /** * Determines and initializes the appropriate Port instance based on the operating context * (master, worker, or standalone process) to manage error registry communication and updates. * * @param options - Registry and operational options. * @param aggregator - The aggregator instance for error collection. * @param logger - Logger instance for logging activities. * @returns An instance of Port or undefined if running in a standalone process. */ private getPort; /** @returns The application name */ get name(): string; /** @returns The application identifier */ get componentId(): string; /** @returns An Express router with access to registered errors */ get router(): express.Router; /** @returns Links offered by this service */ get links(): { [link: string]: string; }; /** @returns The health status of the component */ get status(): Health.Status; /** @returns Health checks for this service */ get checks(): Health.Checks; /** * Registers one or multiple components to be monitored. * @param component - The component or components to register. */ register(component: Layer.Observable | Layer.Observable[]): void; /** * Adds an error to the registry, converting it to a structured format. * @param error - The error to register. */ push(error: HandleableError): void; /** Clear the error registry */ clear(): void; /** @returns Returns a combined list of all the registered errors */ get errors(): ErrorRecord[]; /** @returns The current number of registered errors */ get size(): number; /** @returns Last update date */ get lastUpdate(): string; /** * Starts the error registry service, including the communication port and error event listeners. */ start(): Promise<void>; /** * Stops the error registry service, including halting communication and removing event listeners. */ stop(): Promise<void>; /** Closes the error registry service, performing cleanup actions as necessary. */ close(): Promise<void>; /** * Event handler for error event * @param error - Error triggered by the component */ private readonly errorEventHandler; } //# sourceMappingURL=RegisterFacade.d.ts.map