UNPKG

@nestjs/core

Version:

Nest - modern, fast, powerful node.js web framework (@core)

51 lines (50 loc) 1.8 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const constants_1 = require("@nestjs/common/constants"); const instance_wrapper_1 = require("./../injector/instance-wrapper"); class MiddlewareContainer { constructor() { this.middleware = new Map(); this.configurationSets = new Map(); } getMiddlewareCollection(module) { return this.middleware.get(module) || new Map(); } getConfigurations() { return this.configurationSets; } insertConfig(configList, module) { const middleware = this.getTargetMiddleware(module); const targetConfig = this.getTargetConfig(module); const configurations = configList || []; const insertMiddleware = (metatype) => { const token = metatype.name; middleware.set(token, new instance_wrapper_1.InstanceWrapper({ scope: this.getClassScope(metatype), metatype, name: token, })); }; configurations.forEach(config => { [].concat(config.middleware).map(insertMiddleware); targetConfig.add(config); }); } getTargetMiddleware(module) { if (!this.middleware.has(module)) { this.middleware.set(module, new Map()); } return this.middleware.get(module); } getTargetConfig(module) { if (!this.configurationSets.has(module)) { this.configurationSets.set(module, new Set()); } return this.configurationSets.get(module); } getClassScope(type) { const metadata = Reflect.getMetadata(constants_1.SCOPE_OPTIONS_METADATA, type); return metadata && metadata.scope; } } exports.MiddlewareContainer = MiddlewareContainer;