application-services
Version:
Out of the box application environment and configuration service.
47 lines (46 loc) • 1.7 kB
TypeScript
import process from 'node:process';
import { type FatalErrorService, type Knifecycle, type ServiceProperties } from 'knifecycle';
import { type LogService } from 'common-services';
import { type AppEnvVars, type BaseAppEnv } from './ENV.js';
export interface ProcessService {
service: NodeJS.Process;
dispose: () => Promise<void>;
}
export interface ProcessServiceConfig {
PROCESS_NAME?: string;
SIGNALS?: NodeJS.Signals[];
}
export type ProcessServiceDependencies<T extends BaseAppEnv> = ProcessServiceConfig & {
ENV: AppEnvVars;
APP_ENV: T;
exit: typeof process.exit;
$instance: Knifecycle;
$fatalError: FatalErrorService;
log?: LogService;
};
/**
* Instantiate the process service
* @name initProcess
* @function
* @param {Object} services
* The services `process` depends on
* @param {Object} services.APP_ENV
* The injected `APP_ENV` value
* @param {Object} [services.PROCESS_NAME]
* The process name to display
* @param {Object} [services.SIGNALS]
* The process signals that interrupt the process
* @param {Object} [services.exit]
* A `process.exit` like function
* @param {Object} services.$instance
* The Knifecycle instance
* @param {Object} services.$fatalError
* The Knifecycle fatal error manager
* @param {Object} [services.log=noop]
* An optional logging service
* @return {Promise<Object>}
* A promise of the process object
*/
declare function initProcess<T extends BaseAppEnv>({ ENV, APP_ENV, PROCESS_NAME, SIGNALS, log, exit, $instance, $fatalError, }: ProcessServiceDependencies<T>): Promise<ProcessService>;
declare const _default: ServiceProperties & typeof initProcess;
export default _default;