• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

ialopezg / corejs / #5

03 Nov 2023 08:38PM UTC coverage: 42.153% (-47.5%) from 89.623%
#5

push

ialopezg
feat: add microservice feature

10 of 84 branches covered (0.0%)

Branch coverage included in aggregate %.

49 of 77 new or added lines in 20 files covered. (63.64%)

155 existing lines in 21 files now uncovered.

221 of 464 relevant lines covered (47.63%)

0.51 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

6.45
/src/core/injector/module.ts
1
import {
2
  IController,
3
  IInjectable,
4
  IModule,
5
  MetaType,
6
  ModuleMetaType,
7
} from '../../common/interfaces';
8
import { UnknownExportableComponentException } from '../../errors';
1✔
9
import { InstanceWrapper } from './container';
10

11
/**
12
 * Represents a set of code encapsulated to be injected into an application.
13
 */
14
export class Module {
1✔
15
  private _instance: IModule;
16
  private _modules = new Set<Module>();
×
17
  private _components = new Map<string, InstanceWrapper<IInjectable>>();
×
18
  private _controllers = new Map<string, InstanceWrapper<IController>>();
×
19
  private _exports = new Set<string>();
×
20

21
  /**
22
   * Creates a new instance of the Module class.
23
   *
24
   * @param {ModuleMetaType} _metaType Module meta-type information.
25
   */
26
  constructor(private _metaType: ModuleMetaType) {
×
27
    this._instance = new _metaType();
×
28
  }
29

30
  /**
31
   * Gets current exportable component objects.
32
   */
33
  get exports(): Set<string> {
34
    return this._exports;
×
35
  }
36

37
  /**
38
   * Gets current component objects.
39
   */
40
  get components(): Map<string, InstanceWrapper<IInjectable>> {
41
    return this._components;
×
42
  }
43

44
  /**
45
   * Gets current controller objects.
46
   */
47
  get controllers(): Map<string, InstanceWrapper<IController>> {
48
    return this._controllers;
×
49
  }
50

51
  /**
52
   * Gets current module instance.
53
   */
54
  get instance(): IModule {
55
    return this._instance;
×
56
  }
57

58
  /**
59
   * Gets current module meta-type data.
60
   */
61
  get metaType(): ModuleMetaType {
62
    return this._metaType;
×
63
  }
64

65
  /**
66
   * Gets current child modules.
67
   */
68
  get modules(): Set<Module> {
69
    return this._modules;
×
70
  }
71

72
  set instance(value: IModule) {
73
    this._instance = value;
×
74
  }
75

76
  /**
77
   * Registers the given object as an exportable component. If component does not exist,
78
   * will throw an UnknownExportableComponentException object.
79
   *
80
   * @param {MetaType<IInjectable>} target Exportable component.
81
   */
82
  public addExportedComponent(target: MetaType<IInjectable>): void {
83
    if (!this._components.has(target.name)) {
×
84
      throw new UnknownExportableComponentException(target.name);
×
85
    }
86

87
    this._exports.add(target.name);
×
88
  }
89

90
  /**
91
   * Registers the given object as a child module.
92
   *
93
   * @param {Module} child Child module.
94
   */
95
  public addChildModule(child: Module): void {
96
    this.modules.add(child);
×
97
  }
98

99
  /**
100
   * Registers the given object as a component.
101
   *
102
   * @param {MetaType<IInjectable> & { provide?: any, useValue?: any }} target Component to be registered.
103
   */
104
  public addComponent(
105
    target: MetaType<IInjectable> & { provide?: any, useValue?: any },
106
  ): void {
107
    if (target.provide && target.useValue) {
×
108
      return this.addProvider(target);
×
109
    }
110

111
    this._components.set(target.name, {
×
112
      instance: null,
113
      metaType: target,
114
      resolved: false,
115
    });
116
  }
117

118
  /**
119
   * Registers the given object as a controller.
120
   *
121
   * @param {MetaType<IController>} target Controller to be registered.
122
   */
123
  public addController(target: MetaType<IController>): void {
124
    this._controllers.set(target.name, {
×
125
      instance: null,
126
      metaType: target,
127
      resolved: false,
128
    });
129
  }
130

131
  /**
132
   * Registers the given object as a provider.
133
   *
134
   * @param {MetaType<IInjectable> & { provide?: any, useValue?: any }} target Provider to be registered.
135
   */
136
  public addProvider(
137
    target: MetaType<IInjectable> & { provide?: any, useValue?: any },
138
  ): void {
139
    const { provide: type, useValue: value } = target;
×
NEW
140
    this._components.set(type.name, {
×
141
      instance: value,
142
      metaType: type,
143
      resolved: true,
144
    });
145
  }
146
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc