1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.ServiceDefaults = exports.ServiceBooter = 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:service-booter');
|
15 |
|
16 |
|
17 |
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 | let ServiceBooter = class ServiceBooter extends base_artifact_booter_1.BaseArtifactBooter {
|
26 | constructor(app, projectRoot, serviceConfig = {}) {
|
27 | super(projectRoot,
|
28 |
|
29 | Object.assign({}, exports.ServiceDefaults, serviceConfig));
|
30 | this.app = app;
|
31 | this.serviceConfig = serviceConfig;
|
32 | }
|
33 | |
34 |
|
35 |
|
36 |
|
37 | async load() {
|
38 | await super.load();
|
39 | for (const cls of this.classes) {
|
40 | if (!isBindableClass(cls))
|
41 | continue;
|
42 | debug('Bind class: %s', cls.name);
|
43 | const binding = this.app.service(cls);
|
44 | debug('Binding created for class: %j', binding);
|
45 | }
|
46 | }
|
47 | };
|
48 | ServiceBooter = tslib_1.__decorate([
|
49 | (0, types_1.booter)('services'),
|
50 | tslib_1.__param(0, (0, core_1.inject)(core_1.CoreBindings.APPLICATION_INSTANCE)),
|
51 | tslib_1.__param(1, (0, core_1.inject)(keys_1.BootBindings.PROJECT_ROOT)),
|
52 | tslib_1.__param(2, (0, core_1.config)()),
|
53 | tslib_1.__metadata("design:paramtypes", [Object, String, Object])
|
54 | ], ServiceBooter);
|
55 | exports.ServiceBooter = ServiceBooter;
|
56 |
|
57 |
|
58 |
|
59 | exports.ServiceDefaults = {
|
60 | dirs: ['services'],
|
61 | extensions: ['.service.js'],
|
62 | nested: true,
|
63 | };
|
64 | function isServiceProvider(cls) {
|
65 | const hasSupportedName = cls.name.endsWith('Provider');
|
66 | const hasValueMethod = typeof cls.prototype.value === 'function';
|
67 | return hasSupportedName && hasValueMethod;
|
68 | }
|
69 | function isBindableClass(cls) {
|
70 | if (core_1.MetadataInspector.getClassMetadata(core_1.BINDING_METADATA_KEY, cls)) {
|
71 | return true;
|
72 | }
|
73 | if ((0, core_1.hasInjections)(cls)) {
|
74 | return true;
|
75 | }
|
76 | if (isServiceProvider(cls)) {
|
77 | debug('Provider class found: %s', cls.name);
|
78 | return true;
|
79 | }
|
80 | if ((0, core_1.isDynamicValueProviderClass)(cls)) {
|
81 | debug('Dynamic value provider class found: %s', cls.name);
|
82 | return true;
|
83 | }
|
84 | debug('Skip class not decorated with @injectable: %s', cls.name);
|
85 | return false;
|
86 | }
|
87 |
|
\ | No newline at end of file |