UNPKG

2.76 kBJavaScriptView Raw
1"use strict";
2// Copyright IBM Corp. and LoopBack contributors 2019,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.InterceptorProviderDefaults = exports.InterceptorProviderBooter = 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:interceptor-booter');
15/**
16 * A class that extends BaseArtifactBooter to boot the 'InterceptorProvider' 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 - InterceptorProvider Artifact Options Object
23 */
24let InterceptorProviderBooter = class InterceptorProviderBooter extends base_artifact_booter_1.BaseArtifactBooter {
25 constructor(app, projectRoot, interceptorConfig = {}) {
26 super(projectRoot,
27 // Set InterceptorProvider Booter Options if passed in via bootConfig
28 Object.assign({}, exports.InterceptorProviderDefaults, interceptorConfig));
29 this.app = app;
30 this.interceptorConfig = interceptorConfig;
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.interceptors = this.classes;
39 for (const interceptor of this.interceptors) {
40 debug('Bind interceptor: %s', interceptor.name);
41 const binding = this.app.interceptor(interceptor);
42 debug('Binding created for interceptor: %j', binding);
43 }
44 }
45};
46InterceptorProviderBooter = tslib_1.__decorate([
47 (0, types_1.booter)('interceptors'),
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], InterceptorProviderBooter);
53exports.InterceptorProviderBooter = InterceptorProviderBooter;
54/**
55 * Default ArtifactOptions for InterceptorProviderBooter.
56 */
57exports.InterceptorProviderDefaults = {
58 dirs: ['interceptors'],
59 extensions: ['.interceptor.js'],
60 nested: true,
61};
62//# sourceMappingURL=interceptor.booter.js.map
\No newline at end of file