UNPKG

2.77 kBJavaScriptView Raw
1"use strict";
2// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
3// Node module: @loopback/boot
4// This file is licensed under the MIT License.
5// License text available at https://opensource.org/licenses/MIT
6Object.defineProperty(exports, "__esModule", { value: true });
7exports.LifeCycleObserverDefaults = exports.LifeCycleObserverBooter = void 0;
8const tslib_1 = require("tslib");
9const core_1 = require("@loopback/core");
10const debug_1 = tslib_1.__importDefault(require("debug"));
11const keys_1 = require("../keys");
12const types_1 = require("../types");
13const base_artifact_booter_1 = require("./base-artifact.booter");
14const debug = (0, debug_1.default)('loopback:boot:lifecycle-observer-booter');
15/**
16 * A class that extends BaseArtifactBooter to boot the 'LifeCycleObserver' artifact type.
17 *
18 * Supported phases: configure, discover, load
19 *
20 * @param app - Application instance
21 * @param projectRoot - Root of User Project relative to which all paths are resolved
22 * @param bootConfig - LifeCycleObserver Artifact Options Object
23 */
24let LifeCycleObserverBooter = class LifeCycleObserverBooter extends base_artifact_booter_1.BaseArtifactBooter {
25 constructor(app, projectRoot, observerConfig = {}) {
26 super(projectRoot,
27 // Set LifeCycleObserver Booter Options if passed in via bootConfig
28 Object.assign({}, exports.LifeCycleObserverDefaults, observerConfig));
29 this.app = app;
30 this.observerConfig = observerConfig;
31 }
32 /**
33 * Uses super method to get a list of Artifact classes. Boot each file by
34 * creating a DataSourceConstructor and binding it to the application class.
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};
46LifeCycleObserverBooter = 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);
53exports.LifeCycleObserverBooter = LifeCycleObserverBooter;
54/**
55 * Default ArtifactOptions for DataSourceBooter.
56 */
57exports.LifeCycleObserverDefaults = {
58 dirs: ['observers'],
59 extensions: ['.observer.js'],
60 nested: true,
61};
62//# sourceMappingURL=lifecyle-observer.booter.js.map
\No newline at end of file