dependency-injection-cat
Version:
DI Cat is a truly clean DI-container, which allows you not to pollute your business logic with decorators from DI/IOC libraries!
57 lines (56 loc) • 2.61 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.ContextRepository = void 0;
var removeQuotesFromString_1 = require("../utils/removeQuotesFromString");
var constants_1 = require("./constants");
var md5_1 = __importDefault(require("md5"));
var ContextRepository = /** @class */ (function () {
function ContextRepository() {
}
ContextRepository.registerContext = function (name, classDeclaration) {
var sourceFile = classDeclaration.getSourceFile();
var id = (0, md5_1.default)(sourceFile.fileName);
var descriptor = {
id: id,
name: name,
isGlobal: false,
className: (0, removeQuotesFromString_1.removeQuotesFromString)(classDeclaration.name.getText()),
absolutePath: sourceFile.fileName,
node: classDeclaration,
};
this.contextMap.set(name, descriptor);
this.contextPathToContextDescriptor.set(sourceFile.fileName, descriptor);
return descriptor;
};
ContextRepository.registerGlobalContext = function (classDeclaration) {
var sourceFile = classDeclaration.getSourceFile();
var id = (0, md5_1.default)(sourceFile.fileName);
var descriptor = {
id: id,
name: constants_1.GLOBAL_CONTEXT_NAME,
isGlobal: true,
absolutePath: sourceFile.fileName,
node: classDeclaration,
className: (0, removeQuotesFromString_1.removeQuotesFromString)(classDeclaration.name.getText()),
};
this.globalContexts.set(id, descriptor);
this.contextPathToContextDescriptor.set(sourceFile.fileName, descriptor);
return descriptor;
};
ContextRepository.getContextByName = function (name) {
var _a;
return (_a = this.contextMap.get(name)) !== null && _a !== void 0 ? _a : null;
};
ContextRepository.registerTBeanType = function (contextDescriptor, nodeSourceDescriptor) {
this.contextNameToTBeanNodeSourceDescriptor.set(contextDescriptor.name, { contextDescriptor: contextDescriptor, nodeSourceDescriptor: nodeSourceDescriptor });
};
ContextRepository.contextMap = new Map();
ContextRepository.globalContexts = new Map();
ContextRepository.contextNameToTBeanNodeSourceDescriptor = new Map();
ContextRepository.contextPathToContextDescriptor = new Map();
return ContextRepository;
}());
exports.ContextRepository = ContextRepository;