1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.createComponentApplicationBooterBinding = exports.createBooterForComponentApplication = exports.bindingKeysExcludedFromSubApp = void 0;
|
8 | const tslib_1 = require("tslib");
|
9 | const core_1 = require("@loopback/core");
|
10 | const debug_1 = tslib_1.__importDefault(require("debug"));
|
11 | const keys_1 = require("../keys");
|
12 | const types_1 = require("../types");
|
13 | const debug = (0, debug_1.default)('loopback:boot:booter:component-application');
|
14 |
|
15 |
|
16 |
|
17 |
|
18 | exports.bindingKeysExcludedFromSubApp = [
|
19 | keys_1.BootBindings.BOOT_OPTIONS.key,
|
20 | keys_1.BootBindings.PROJECT_ROOT.key,
|
21 | keys_1.BootBindings.BOOTSTRAPPER_KEY.key,
|
22 | core_1.CoreBindings.APPLICATION_CONFIG.key,
|
23 | core_1.CoreBindings.APPLICATION_INSTANCE.key,
|
24 | core_1.CoreBindings.APPLICATION_METADATA.key,
|
25 | core_1.CoreBindings.LIFE_CYCLE_OBSERVER_REGISTRY.key,
|
26 | core_1.CoreBindings.LIFE_CYCLE_OBSERVER_OPTIONS.key,
|
27 | ];
|
28 |
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 | function createBooterForComponentApplication(componentApp, filter = () => true) {
|
37 | |
38 |
|
39 |
|
40 | let ComponentApplicationBooter = class ComponentApplicationBooter {
|
41 | constructor(mainApp) {
|
42 | this.mainApp = mainApp;
|
43 | }
|
44 | async load() {
|
45 | |
46 |
|
47 |
|
48 | let bindings = componentApp.find(() => true);
|
49 | const bindingsBeforeBoot = new Set(bindings);
|
50 |
|
51 | await componentApp.boot();
|
52 | |
53 |
|
54 |
|
55 | bindings = componentApp.find(filter);
|
56 | for (const binding of bindings) {
|
57 |
|
58 | if (exports.bindingKeysExcludedFromSubApp.includes(binding.key))
|
59 | continue;
|
60 |
|
61 | if (bindingsBeforeBoot.has(binding)) {
|
62 | debug('Skipping binding %s that exists before booting %s', binding.key, componentApp.name);
|
63 | continue;
|
64 | }
|
65 |
|
66 | const locked = this.mainApp.find(binding.key).some(b => b.isLocked);
|
67 | if (locked) {
|
68 | debug('Skipping binding %s from %s - locked in %s', binding.key, componentApp.name, this.mainApp.name);
|
69 | continue;
|
70 | }
|
71 | debug('Adding binding from %s to %s', componentApp.name, this.mainApp.name, binding);
|
72 | this.mainApp.add(binding);
|
73 | }
|
74 | }
|
75 | };
|
76 | ComponentApplicationBooter = tslib_1.__decorate([
|
77 | (0, types_1.booter)('componentApplications'),
|
78 | tslib_1.__param(0, (0, core_1.inject)(core_1.CoreBindings.APPLICATION_INSTANCE)),
|
79 | tslib_1.__metadata("design:paramtypes", [core_1.Application])
|
80 | ], ComponentApplicationBooter);
|
81 | return ComponentApplicationBooter;
|
82 | }
|
83 | exports.createBooterForComponentApplication = createBooterForComponentApplication;
|
84 |
|
85 |
|
86 |
|
87 |
|
88 |
|
89 |
|
90 |
|
91 |
|
92 | function createComponentApplicationBooterBinding(componentApp, filter) {
|
93 | return (0, core_1.createBindingFromClass)(createBooterForComponentApplication(componentApp, filter), { key: `booters.${componentApp.name}` });
|
94 | }
|
95 | exports.createComponentApplicationBooterBinding = createComponentApplicationBooterBinding;
|
96 |
|
\ | No newline at end of file |