1 | "use strict";
|
2 |
|
3 |
|
4 |
|
5 |
|
6 | Object.defineProperty(exports, "__esModule", { value: true });
|
7 | exports.bind = exports.injectable = void 0;
|
8 | const metadata_1 = require("@loopback/metadata");
|
9 | const binding_inspector_1 = require("./binding-inspector");
|
10 |
|
11 |
|
12 |
|
13 | class InjectableDecoratorFactory extends metadata_1.ClassDecoratorFactory {
|
14 | mergeWithInherited(inherited, target) {
|
15 | if (inherited) {
|
16 | return {
|
17 | templates: [
|
18 | ...inherited.templates,
|
19 | binding_inspector_1.removeNameAndKeyTags,
|
20 | ...this.spec.templates,
|
21 | ],
|
22 | target: this.spec.target,
|
23 | };
|
24 | }
|
25 | else {
|
26 | this.withTarget(this.spec, target);
|
27 | return this.spec;
|
28 | }
|
29 | }
|
30 | mergeWithOwn(ownMetadata) {
|
31 | return {
|
32 | templates: [...ownMetadata.templates, ...this.spec.templates],
|
33 | target: this.spec.target,
|
34 | };
|
35 | }
|
36 | withTarget(spec, target) {
|
37 | spec.target = target;
|
38 | return spec;
|
39 | }
|
40 | }
|
41 |
|
42 |
|
43 |
|
44 |
|
45 |
|
46 |
|
47 |
|
48 |
|
49 |
|
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 | function injectable(...specs) {
|
57 | const templateFunctions = specs.map(t => {
|
58 | if (typeof t === 'function') {
|
59 | return t;
|
60 | }
|
61 | else {
|
62 | return (0, binding_inspector_1.asBindingTemplate)(t);
|
63 | }
|
64 | });
|
65 | return (target) => {
|
66 | const cls = target;
|
67 | const spec = {
|
68 | templates: [(0, binding_inspector_1.asClassOrProvider)(cls), ...templateFunctions],
|
69 | target: cls,
|
70 | };
|
71 | const decorator = InjectableDecoratorFactory.createDecorator(binding_inspector_1.BINDING_METADATA_KEY, spec, { decoratorName: '@injectable' });
|
72 | decorator(target);
|
73 | };
|
74 | }
|
75 | exports.injectable = injectable;
|
76 |
|
77 |
|
78 |
|
79 | (function (injectable) {
|
80 | |
81 |
|
82 |
|
83 |
|
84 |
|
85 | function provider(...specs) {
|
86 | return (target) => {
|
87 | if (!(0, binding_inspector_1.isProviderClass)(target)) {
|
88 | throw new Error(`Target ${target} is not a Provider`);
|
89 | }
|
90 | injectable(
|
91 |
|
92 | (0, binding_inspector_1.asProvider)(target),
|
93 |
|
94 | ...specs)(target);
|
95 | };
|
96 | }
|
97 | injectable.provider = provider;
|
98 | })(injectable || (exports.injectable = injectable = {}));
|
99 |
|
100 |
|
101 |
|
102 |
|
103 | function bind(...specs) {
|
104 | return injectable(...specs);
|
105 | }
|
106 | exports.bind = bind;
|
107 |
|
108 |
|
109 |
|
110 |
|
111 |
|
112 | (function (bind) {
|
113 | |
114 |
|
115 |
|
116 | bind.provider = injectable.provider;
|
117 | })(bind || (exports.bind = bind = {}));
|
118 |
|
\ | No newline at end of file |