UNPKG

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!

70 lines (69 loc) 3.54 kB
"use strict"; var __read = (this && this.__read) || function (o, n) { var m = typeof Symbol === "function" && o[Symbol.iterator]; if (!m) return o; var i = m.call(o), r, ar = [], e; try { while ((n === void 0 || n-- > 0) && !(r = i.next()).done) ar.push(r.value); } catch (error) { e = { error: error }; } finally { try { if (r && !r.done && (m = i["return"])) m.call(i); } finally { if (e) throw e.error; } } return ar; }; var __spreadArray = (this && this.__spreadArray) || function (to, from, pack) { if (pack || arguments.length === 2) for (var i = 0, l = from.length, ar; i < l; i++) { if (ar || !(i in from)) { if (!ar) ar = Array.prototype.slice.call(from, 0, i); ar[i] = from[i]; } } return to.concat(ar || Array.prototype.slice.call(from)); }; Object.defineProperty(exports, "__esModule", { value: true }); exports.registerGlobalCatContext = void 0; var isExtendsCatContextContext_1 = require("../ts-helpers/predicates/isExtendsCatContextContext"); var ContextRepository_1 = require("./ContextRepository"); var isNamedClassDeclaration_1 = require("../ts-helpers/predicates/isNamedClassDeclaration"); var CompilationContext_1 = require("../../compilation-context/CompilationContext"); var isExtendsGlobalCatContext_1 = require("../ts-helpers/predicates/isExtendsGlobalCatContext"); var registerGlobalCatContext = function (sourceFile) { CompilationContext_1.CompilationContext.clearErrorsByFilePath(sourceFile.fileName); var catContextClassDeclarations = sourceFile.statements.filter(isExtendsCatContextContext_1.isExtendsCatContextContext); var globalCatContextClassDeclarations = sourceFile.statements.filter(isExtendsGlobalCatContext_1.isExtendsGlobalCatContextContext); if (catContextClassDeclarations.length > 0 && globalCatContextClassDeclarations.length > 0) { CompilationContext_1.CompilationContext.reportErrorWithMultipleNodes({ message: 'Only one type of CatContext should be defined in one file.', nodes: __spreadArray(__spreadArray([], __read(catContextClassDeclarations), false), __read(globalCatContextClassDeclarations), false), filePath: sourceFile.fileName, }); return; } if (globalCatContextClassDeclarations.length > 1) { var excessCatContextClasses = catContextClassDeclarations.slice(1); var excessGlobalCatContextClasses = globalCatContextClassDeclarations.slice(1); CompilationContext_1.CompilationContext.reportErrorWithMultipleNodes({ nodes: __spreadArray(__spreadArray([], __read(excessCatContextClasses), false), __read(excessGlobalCatContextClasses), false), message: 'Only one context should be defined in file.', filePath: sourceFile.fileName, }); return; } if (globalCatContextClassDeclarations.length === 1) { var classDeclaration = globalCatContextClassDeclarations[0]; if (!(0, isNamedClassDeclaration_1.isNamedClassDeclaration)(classDeclaration)) { CompilationContext_1.CompilationContext.reportError({ message: 'Global Context should be a named class declaration', node: classDeclaration, filePath: sourceFile.fileName, }); return; } ContextRepository_1.ContextRepository.registerGlobalContext(classDeclaration); } }; exports.registerGlobalCatContext = registerGlobalCatContext;