1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | exports.MiddlewareContainer = void 0;
|
4 | const instance_wrapper_1 = require("../injector/instance-wrapper");
|
5 | const get_class_scope_1 = require("../helpers/get-class-scope");
|
6 | class MiddlewareContainer {
|
7 | constructor(container) {
|
8 | this.container = container;
|
9 | this.middleware = new Map();
|
10 | this.configurationSets = new Map();
|
11 | }
|
12 | getMiddlewareCollection(moduleKey) {
|
13 | if (!this.middleware.has(moduleKey)) {
|
14 | const moduleRef = this.container.getModuleByKey(moduleKey);
|
15 | this.middleware.set(moduleKey, moduleRef.middlewares);
|
16 | }
|
17 | return this.middleware.get(moduleKey);
|
18 | }
|
19 | getConfigurations() {
|
20 | return this.configurationSets;
|
21 | }
|
22 | insertConfig(configList, moduleKey) {
|
23 | const middleware = this.getMiddlewareCollection(moduleKey);
|
24 | const targetConfig = this.getTargetConfig(moduleKey);
|
25 | const configurations = configList || [];
|
26 | const insertMiddleware = (metatype) => {
|
27 | const token = metatype;
|
28 | middleware.set(token, new instance_wrapper_1.InstanceWrapper({
|
29 | scope: (0, get_class_scope_1.getClassScope)(metatype),
|
30 | name: token,
|
31 | metatype,
|
32 | token,
|
33 | }));
|
34 | };
|
35 | configurations.forEach(config => {
|
36 | [].concat(config.middleware).map(insertMiddleware);
|
37 | targetConfig.add(config);
|
38 | });
|
39 | }
|
40 | getTargetConfig(moduleName) {
|
41 | if (!this.configurationSets.has(moduleName)) {
|
42 | this.configurationSets.set(moduleName, new Set());
|
43 | }
|
44 | return this.configurationSets.get(moduleName);
|
45 | }
|
46 | }
|
47 | exports.MiddlewareContainer = MiddlewareContainer;
|