All files / src/classes CoreElement.ts

100% Statements 6/6
100% Branches 0/0
100% Functions 5/5
100% Lines 6/6

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 56 57 58 59 60 61 62 63 64 65                                                                                        15x 15x       3x       8x       1x       1x      
import type {
  ICoreCache,
  ICoreCClient,
  ICoreClient,
  ICoreElement,
  ICoreKernel,
  ICoreKernelModule,
  ICorePresenter,
  IDataBase,
  IStore,
} from '../lib';
import CoreLogChannel from './CoreLogChannel';
 
/**
 * A fundamental building block of the kernel architecture.
 * Each {@link CoreElement} encapsulates a specific kernel module and exposes
 * convenient accessors for the underlying kernel, module, configuration store,
 * and cryptographic client.
 *
 * @template K  The type of the kernel instance (extends {@link ICoreKernel}).
 * @template T  The type of the database used by the module; may be {@code null}.
 * @template P  The type of the client component; may be {@code null}.
 * @template C  The type of the cache component; may be {@code null}.
 * @template E  The type of the presenter component; may be {@code null}.
 *
 * @extends CoreLogChannel
 * @implements ICoreElement<K, T, P, C, E>
 *
 * @param {string} channel - Identifier used for logging and tracing.
 * @param {ICoreKernelModule<K, T, P, C, E>} module - The module that this element manages.
 */
export default abstract class CoreElement<
    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 CoreLogChannel
  implements ICoreElement<K, T, P, C, E>
{
  private readonly module: ICoreKernelModule<K, T, P, C, E>;
 
  constructor(channel: string, module: ICoreKernelModule<K, T, P, C, E>) {
    super(channel, module);
    this.module = module;
  }
 
  getKernel(): K {
    return this.module.getKernel();
  }
 
  getModule(): ICoreKernelModule<K, T, P, C, E> {
    return this.module;
  }
 
  getConfigStore(): IStore {
    return this.getKernel().getConfigStore();
  }
 
  getCClient<X extends ICoreCClient>(): X {
    return this.getKernel().getCryptoClient();
  }
}