All files / src/classes CoreService.ts

80% Statements 4/5
100% Branches 2/2
50% Functions 1/2
80% Lines 4/5

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55                                                                              5x 5x     5x   5x                  
import CoreElement from './CoreElement';
import type {
  ICoreCache,
  ICoreClient,
  ICoreKernel,
  ICoreKernelModule,
  ICorePresenter,
  ICoreService,
  IDataBase,
  ServiceStates,
} from '../lib';
 
/**
 * Abstract service class that represents a unit of functionality within the Core framework.
 * Concrete implementations must provide the `start` and `stop` lifecycle methods.
 *
 * @template K - Kernel type extending {@link ICoreKernel}.
 * @template T - DataBase type or {@code null} extending {@link IDataBase}.
 * @template P - Client type or {@code null} extending {@link ICoreClient}.
 * @template C - Cache type or {@code null} extending {@link ICoreCache}.
 * @template E - Presenter type or {@code null} extending {@link ICorePresenter}.
 */
export default abstract class CoreService<
    K extends ICoreKernel<any> = ICoreKernel<any>,
    T extends IDataBase<any, any> | null = any,
    P extends ICoreClient | null = any,
    C extends ICoreCache | null = any,
    E extends ICorePresenter<any> | null = any,
  >
  extends CoreElement<K, T, P, C, E>
  implements ICoreService<K, T, P, C, E>
{
  skipAutoStart: boolean;
 
  constructor(
    name: string,
    module: ICoreKernelModule<K, T, P, C, E>,
    skipAutoStart?: boolean,
  ) {
    super(name, module);
    this.skipAutoStart = skipAutoStart || false;
  }
 
  public forceStop = false;
 
  public state: ServiceStates = 'INIT';
 
  abstract start(): Promise<any>;
 
  abstract stop(): Promise<any>;
  isRunning(): boolean {
    return this.state === 'RUNNING';
  }
}