@inversifyjs/core
Version:
InversifyJs core package
93 lines • 3.44 kB
JavaScript
Object.defineProperty(exports, "__esModule", { value: true });
exports.BindingService = exports.OneToManyBindingMapStar = void 0;
const OneToManyMapStar_1 = require("../../common/models/OneToManyMapStar");
const cloneBinding_1 = require("../calculations/cloneBinding");
var BindingRelationKind;
(function (BindingRelationKind) {
BindingRelationKind["id"] = "id";
BindingRelationKind["moduleId"] = "moduleId";
BindingRelationKind["serviceId"] = "serviceId";
})(BindingRelationKind || (BindingRelationKind = {}));
class OneToManyBindingMapStar extends OneToManyMapStar_1.OneToManyMapStar {
_buildNewInstance(spec) {
return new OneToManyBindingMapStar(spec);
}
_cloneModel(model) {
return (0, cloneBinding_1.cloneBinding)(model);
}
}
exports.OneToManyBindingMapStar = OneToManyBindingMapStar;
class BindingService {
#bindingMaps;
#parent;
constructor(parent, bindingMaps) {
this.#bindingMaps =
bindingMaps ??
new OneToManyBindingMapStar({
id: {
isOptional: false,
},
moduleId: {
isOptional: true,
},
serviceId: {
isOptional: false,
},
});
this.#parent = parent;
}
static build(parent) {
return new BindingService(parent);
}
clone() {
const clone = new BindingService(this.#parent, this.#bindingMaps.clone());
return clone;
}
get(serviceIdentifier) {
return (this.getNonParentBindings(serviceIdentifier) ??
this.#parent?.get(serviceIdentifier));
}
getBoundServices() {
const serviceIdentifierSet = new Set(this.#bindingMaps.getAllKeys(BindingRelationKind.serviceId));
if (this.#parent !== undefined) {
for (const serviceIdentifier of this.#parent.getBoundServices()) {
serviceIdentifierSet.add(serviceIdentifier);
}
}
return serviceIdentifierSet;
}
getById(id) {
return (this.#bindingMaps.get(BindingRelationKind.id, id) ?? this.#parent?.getById(id));
}
getByModuleId(moduleId) {
return (this.#bindingMaps.get(BindingRelationKind.moduleId, moduleId) ?? this.#parent?.getByModuleId(moduleId));
}
getNonParentBindings(serviceId) {
return this.#bindingMaps.get(BindingRelationKind.serviceId, serviceId);
}
getNonParentBoundServices() {
return this.#bindingMaps.getAllKeys(BindingRelationKind.serviceId);
}
removeById(id) {
this.#bindingMaps.removeByRelation(BindingRelationKind.id, id);
}
removeAllByModuleId(moduleId) {
this.#bindingMaps.removeByRelation(BindingRelationKind.moduleId, moduleId);
}
removeAllByServiceId(serviceId) {
this.#bindingMaps.removeByRelation(BindingRelationKind.serviceId, serviceId);
}
set(binding) {
const relation = {
[BindingRelationKind.id]: binding.id,
[BindingRelationKind.serviceId]: binding.serviceIdentifier,
};
if (binding.moduleId !== undefined) {
relation[BindingRelationKind.moduleId] = binding.moduleId;
}
this.#bindingMaps.add(binding, relation);
}
}
exports.BindingService = BindingService;
//# sourceMappingURL=BindingService.js.map
;