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