UNPKG

3.03 kBJavaScriptView Raw
1"use strict";
2// Copyright IBM Corp. and LoopBack contributors 2018,2019. 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.RepositoryDefaults = exports.RepositoryBooter = void 0;
8const tslib_1 = require("tslib");
9const core_1 = require("@loopback/core");
10const keys_1 = require("../keys");
11const types_1 = require("../types");
12const base_artifact_booter_1 = require("./base-artifact.booter");
13/**
14 * A class that extends BaseArtifactBooter to boot the 'Repository' artifact type.
15 * Discovered repositories are bound using `app.repository()` which must be added
16 * to an Application using the `RepositoryMixin` from `@loopback/repository`.
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 - Repository Artifact Options Object
23 */
24let RepositoryBooter = class RepositoryBooter extends base_artifact_booter_1.BaseArtifactBooter {
25 constructor(app, projectRoot, repositoryOptions = {}) {
26 super(projectRoot,
27 // Set Repository Booter Options if passed in via bootConfig
28 Object.assign({}, exports.RepositoryDefaults, repositoryOptions));
29 this.app = app;
30 this.repositoryOptions = repositoryOptions;
31 }
32 /**
33 * Uses super method to get a list of Artifact classes. Boot each class by
34 * binding it to the application using `app.repository(repository);` if present.
35 */
36 async load() {
37 await super.load();
38 /**
39 * If Repository Classes were discovered, we need to make sure RepositoryMixin
40 * was used (so we have `app.repository()`) to perform the binding of a
41 * Repository Class.
42 */
43 if (this.classes.length > 0) {
44 if (!this.app.repository) {
45 console.warn('app.repository() function is needed for RepositoryBooter. You can add ' +
46 'it to your Application using RepositoryMixin from @loopback/repository.');
47 }
48 else {
49 this.classes.forEach(cls => {
50 this.app.repository(cls);
51 });
52 }
53 }
54 }
55};
56RepositoryBooter = tslib_1.__decorate([
57 (0, types_1.booter)('repositories'),
58 tslib_1.__param(0, (0, core_1.inject)(core_1.CoreBindings.APPLICATION_INSTANCE)),
59 tslib_1.__param(1, (0, core_1.inject)(keys_1.BootBindings.PROJECT_ROOT)),
60 tslib_1.__param(2, (0, core_1.config)()),
61 tslib_1.__metadata("design:paramtypes", [Object, String, Object])
62], RepositoryBooter);
63exports.RepositoryBooter = RepositoryBooter;
64/**
65 * Default ArtifactOptions for RepositoryBooter.
66 */
67exports.RepositoryDefaults = {
68 dirs: ['repositories'],
69 extensions: ['.repository.js'],
70 nested: true,
71};
72//# sourceMappingURL=repository.booter.js.map
\No newline at end of file