UNPKG

express-service-bootstrap

Version:

This is a convenience package for starting a express API with security, health checks, process exits etc.

76 lines (75 loc) 4.59 kB
import { BootstrapConstructor } from "./bootstrap-constructor"; /** * DisposableSingletonContainer is a class that is used to create instances of classes and manage their lifecycle via singleton methods. */ export declare class DisposableSingletonContainer { private readonly singletonContainer; private readonly disposeSequenceMap; private disposeSequence; readonly bootstrap: BootstrapConstructor; /** * Creates an instance of DisposableSingletonContainer. * @param singletonContainer The singleton container map(defaults to an empty map) * @param disposeSequenceMap The dispose sequence map(defaults to an empty map, to be filled if singletonContainer is not empty) * @param disposeSequence The dispose sequence number(defaults to 0, to be incremented appropriately if singletonContainer is not empty) * @param bootstrap The bootstrap constructor. */ constructor(singletonContainer?: Map<string, unknown>, disposeSequenceMap?: Map<number, Set<string>>, disposeSequence?: number, bootstrap?: BootstrapConstructor); /** * Creates a new instance of a class with a constructor or returns an existing one based on name. * @param {string} name The name of the instance, has to be unique across all instances. * @param typeConstructor The class constructor * @param constructorArguments The arguments to pass to the constructor(optional) * @param {number} disposeSequence The dispose sequence number(optional) * @returns The instance of the class */ createInstance<InstanceType>(name: string, typeConstructor: new (...constructorArguments: any[]) => InstanceType, constructorArguments?: any[], disposeSequence?: number): InstanceType; /** * Creates a new instance of a class without a constructor asynchronously or returns an existing one based on name. * @param {string} name The name of the instance, has to be unique across all instances. * @param typeConstructorFunction The class constructor ASYNC function. * @param constructorFunctionArguments The arguments to pass to the constructor(optional) * @param {number} disposeSequence The dispose sequence number(optional) * @returns The instance of the class */ createAsyncInstanceWithoutConstructor<InstanceType>(name: string, typeConstructorFunction: (...constructorArguments: any[]) => Promise<InstanceType>, constructorFunctionArguments?: any[], disposeSequence?: number): Promise<InstanceType>; /** * Creates a new instance of a class without a constructor or returns an existing one based on name. * @param {string} name The name of the instance, has to be unique across all instances. * @param typeConstructorFunction The class constructor * @param constructorFunctionArguments The arguments to pass to the constructor(optional) * @param {number} disposeSequence The dispose sequence number(optional) * @returns The instance of the class * @template InstanceType The type of the instance * @returns {InstanceType} The instance of the class */ createInstanceWithoutConstructor<InstanceType>(name: string, typeConstructorFunction: (...constructorArguments: any[]) => InstanceType, constructorFunctionArguments?: any[], disposeSequence?: number): InstanceType; /** * Fetches an existing instance based on name. * @param {string} name The name of the instance * @returns The instance of the class or undefined if it does not exist * @template InstanceType The type of the instance * @returns {InstanceType | undefined} The instance of the class or undefined if it does not exist */ fetchInstance<InstanceType>(name: string): InstanceType | undefined; /** * Registers an existing instance based on name. * @param {string} name The name of the instance * @param {InstanceType} instance The instance of the class * @param {number} disposeSequence The dispose sequence number(optional) * @template InstanceType The type of the instance * @returns {void} void */ registerInstance<InstanceType>(name: string, instance: InstanceType, disposeSequence?: number, overrideExistingInstance?: boolean): boolean; /** * Disposes an existing instance based on name. * @param {string} name The name of the instance * @returns {Promise<void>} void */ disposeInstance(name: string): Promise<void>; /** * Disposes all existing instances based on the dispose sequence. * @returns {Promise<void>} void */ disposeAll(): Promise<void>; }