1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.LifeCycleObserverDefaults = exports.LifeCycleObserverBooter = 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 base_artifact_booter_1 = require("./base-artifact.booter");
|
14 | const debug = (0, debug_1.default)('loopback:boot:lifecycle-observer-booter');
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 | let LifeCycleObserverBooter = class LifeCycleObserverBooter extends base_artifact_booter_1.BaseArtifactBooter {
|
25 | constructor(app, projectRoot, observerConfig = {}) {
|
26 | super(projectRoot,
|
27 |
|
28 | Object.assign({}, exports.LifeCycleObserverDefaults, observerConfig));
|
29 | this.app = app;
|
30 | this.observerConfig = observerConfig;
|
31 | }
|
32 | |
33 |
|
34 |
|
35 |
|
36 | async load() {
|
37 | await super.load();
|
38 | this.observers = this.classes.filter(core_1.isLifeCycleObserverClass);
|
39 | for (const observer of this.observers) {
|
40 | debug('Bind life cycle observer: %s', observer.name);
|
41 | const binding = this.app.lifeCycleObserver(observer);
|
42 | debug('Binding created for life cycle observer: %j', binding);
|
43 | }
|
44 | }
|
45 | };
|
46 | LifeCycleObserverBooter = tslib_1.__decorate([
|
47 | (0, types_1.booter)('observers'),
|
48 | tslib_1.__param(0, (0, core_1.inject)(core_1.CoreBindings.APPLICATION_INSTANCE)),
|
49 | tslib_1.__param(1, (0, core_1.inject)(keys_1.BootBindings.PROJECT_ROOT)),
|
50 | tslib_1.__param(2, (0, core_1.config)()),
|
51 | tslib_1.__metadata("design:paramtypes", [core_1.Application, String, Object])
|
52 | ], LifeCycleObserverBooter);
|
53 | exports.LifeCycleObserverBooter = LifeCycleObserverBooter;
|
54 |
|
55 |
|
56 |
|
57 | exports.LifeCycleObserverDefaults = {
|
58 | dirs: ['observers'],
|
59 | extensions: ['.observer.js'],
|
60 | nested: true,
|
61 | };
|
62 |
|
\ | No newline at end of file |