Code coverage report for core/src/bootstrap.ts

Statements: 84.21% (16 / 19)      Branches: 85.71% (12 / 14)      Functions: 100% (1 / 1)      Lines: 84.21% (16 / 19)      Ignored: none     

All files » core/src/ » bootstrap.ts
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 501 1 1 1 1                                       1 21 21 1 1   21   21 19 18       21       21              
import {APM_ENV, ApmFeatures} from './apm';
import {Env} from './env';
import {ConsoleLog, Log} from './log';
import {Profiler} from './profiling';
import {Providers} from './providers';
import {Supplier} from './util';
 
 
export type LogBoostrap = { root: Log };
export type ApmBootstrap = {
  features: Partial<Record<ApmFeatures, any>>;
};
 
 
export type BootstrapOptions = {
  appName: string;
  envLoaders?: Supplier<Record<string, string>>[];
  log?: LogBoostrap;
  apm?: ApmBootstrap;
  profiler?: Profiler;
  register?: [[any, string | { name: string }]];
}
 
 
export function bootstrap(options: BootstrapOptions) {
  const providers = Providers.get();
  if (options.envLoaders) {
    const env = Env.load(options.envLoaders);
    providers.register(env, Env);
  }
  providers.register(options.log?.root || ConsoleLog.create({ name: options.appName }), Log);
 
  if (options.apm) {
    for (const feature in options.apm.features) {
      providers.register(options.apm.features[feature], APM_ENV[feature].type);
    }
  }
 
  Iif (options.profiler) {
    providers.register(options.profiler, Profiler);
  }
 
  Iif (options.register) {
    for (const [service, name] of options.register) {
      providers.register(service, name);
    }
  }
}