UNPKG

@inversifyjs/core

Version:

InversifyJs core package

56 lines 2.08 kB
import { chain } from '../../common/calculations/chain.js'; import { OneToManyMapStar } from '../../common/models/OneToManyMapStar.js'; var ActivationRelationKind; (function (ActivationRelationKind) { ActivationRelationKind["moduleId"] = "moduleId"; ActivationRelationKind["serviceId"] = "serviceId"; })(ActivationRelationKind || (ActivationRelationKind = {})); export class ActivationsService { #activationMaps; #getParent; constructor(getParent, activationMaps) { this.#activationMaps = activationMaps ?? new OneToManyMapStar({ moduleId: { isOptional: true, }, serviceId: { isOptional: false, }, }); this.#getParent = getParent; } static build(getParent) { return new ActivationsService(getParent); } add(activation, relation) { this.#activationMaps.add(activation, relation); } clone() { const clone = new ActivationsService(this.#getParent, this.#activationMaps.clone()); return clone; } get(serviceIdentifier) { const activationIterables = []; const activations = this.#activationMaps.get(ActivationRelationKind.serviceId, serviceIdentifier); if (activations !== undefined) { activationIterables.push(activations); } const parentActivations = this.#getParent()?.get(serviceIdentifier); if (parentActivations !== undefined) { activationIterables.push(parentActivations); } if (activationIterables.length === 0) { return undefined; } return chain(...activationIterables); } removeAllByModuleId(moduleId) { this.#activationMaps.removeByRelation(ActivationRelationKind.moduleId, moduleId); } removeAllByServiceId(serviceId) { this.#activationMaps.removeByRelation(ActivationRelationKind.serviceId, serviceId); } } //# sourceMappingURL=ActivationsService.js.map