1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const shared_utils_1 = require("@nestjs/common/utils/shared.utils");
|
4 | const iterare_1 = require("iterare");
|
5 | const transient_instances_1 = require("../injector/transient-instances");
|
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 | function hasOnAppBootstrapHook(instance) {
|
12 | return !shared_utils_1.isNil(instance.onApplicationBootstrap);
|
13 | }
|
14 |
|
15 |
|
16 |
|
17 | function callOperator(instances) {
|
18 | return iterare_1.default(instances)
|
19 | .filter(instance => !shared_utils_1.isNil(instance))
|
20 | .filter(hasOnAppBootstrapHook)
|
21 | .map(async (instance) => instance.onApplicationBootstrap())
|
22 | .toArray();
|
23 | }
|
24 |
|
25 |
|
26 |
|
27 |
|
28 |
|
29 |
|
30 | async function callModuleBootstrapHook(module) {
|
31 | const providers = module.getNonAliasProviders();
|
32 |
|
33 |
|
34 | const [_, { instance: moduleClassInstance }] = providers.shift();
|
35 | const instances = [
|
36 | ...module.controllers,
|
37 | ...providers,
|
38 | ...module.injectables,
|
39 | ...module.middlewares,
|
40 | ];
|
41 | const nonTransientInstances = transient_instances_1.getNonTransientInstances(instances);
|
42 | await Promise.all(callOperator(nonTransientInstances));
|
43 | const transientInstances = transient_instances_1.getTransientInstances(instances);
|
44 | await Promise.all(callOperator(transientInstances));
|
45 |
|
46 | if (moduleClassInstance && hasOnAppBootstrapHook(moduleClassInstance)) {
|
47 | await moduleClassInstance.onApplicationBootstrap();
|
48 | }
|
49 | }
|
50 | exports.callModuleBootstrapHook = callModuleBootstrapHook;
|