@loopback/core 2.4.1 → 2.7.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +43 -0
- package/dist/application.d.ts +16 -9
- package/dist/application.js +40 -19
- package/dist/application.js.map +1 -1
- package/dist/component.js +1 -0
- package/dist/component.js.map +1 -1
- package/dist/extension-point.d.ts +2 -2
- package/dist/extension-point.js +4 -3
- package/dist/extension-point.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/keys.d.ts +2 -2
- package/dist/keys.js +1 -0
- package/dist/keys.js.map +1 -1
- package/dist/lifecycle-registry.js +141 -137
- package/dist/lifecycle-registry.js.map +1 -1
- package/dist/lifecycle.d.ts +2 -2
- package/dist/lifecycle.js +1 -0
- package/dist/lifecycle.js.map +1 -1
- package/dist/mixin-target.d.ts +59 -0
- package/{index.d.ts → dist/mixin-target.js} +3 -2
- package/dist/mixin-target.js.map +1 -0
- package/dist/service.d.ts +4 -5
- package/dist/service.js +2 -0
- package/dist/service.js.map +1 -1
- package/package.json +10 -11
- package/src/application.ts +52 -20
- package/src/extension-point.ts +5 -3
- package/src/index.ts +1 -0
- package/src/keys.ts +6 -6
- package/src/lifecycle.ts +2 -1
- package/src/mixin-target.ts +70 -0
- package/src/service.ts +5 -4
- package/index.js +0 -6
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.LifeCycleObserverRegistry = exports.DEFAULT_ORDERED_GROUPS = void 0;
|
|
7
8
|
const tslib_1 = require("tslib");
|
|
8
9
|
const context_1 = require("@loopback/context");
|
|
9
10
|
const keys_1 = require("./keys");
|
|
@@ -14,154 +15,157 @@ exports.DEFAULT_ORDERED_GROUPS = ['server'];
|
|
|
14
15
|
/**
|
|
15
16
|
* A context-based registry for life cycle observers
|
|
16
17
|
*/
|
|
17
|
-
let LifeCycleObserverRegistry = class
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
setOrderedGroups(groups) {
|
|
26
|
-
this.options.orderedGroups = groups;
|
|
27
|
-
}
|
|
28
|
-
/**
|
|
29
|
-
* Get observer groups ordered by the group
|
|
30
|
-
*/
|
|
31
|
-
getObserverGroupsByOrder() {
|
|
32
|
-
const bindings = this.observersView.bindings;
|
|
33
|
-
const groups = this.sortObserverBindingsByGroup(bindings);
|
|
34
|
-
if (debug.enabled) {
|
|
35
|
-
debug('Observer groups: %j', groups.map(g => ({
|
|
36
|
-
group: g.group,
|
|
37
|
-
bindings: g.bindings.map(b => b.key),
|
|
38
|
-
})));
|
|
18
|
+
let LifeCycleObserverRegistry = /** @class */ (() => {
|
|
19
|
+
let LifeCycleObserverRegistry = class LifeCycleObserverRegistry {
|
|
20
|
+
constructor(observersView, options = {
|
|
21
|
+
parallel: true,
|
|
22
|
+
orderedGroups: exports.DEFAULT_ORDERED_GROUPS,
|
|
23
|
+
}) {
|
|
24
|
+
this.observersView = observersView;
|
|
25
|
+
this.options = options;
|
|
39
26
|
}
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* Get the group for a given life cycle observer binding
|
|
44
|
-
* @param binding - Life cycle observer binding
|
|
45
|
-
*/
|
|
46
|
-
getObserverGroup(binding) {
|
|
47
|
-
// First check if there is an explicit group name in the tag
|
|
48
|
-
let group = binding.tagMap[keys_1.CoreTags.LIFE_CYCLE_OBSERVER_GROUP];
|
|
49
|
-
if (!group) {
|
|
50
|
-
// Fall back to a tag that matches one of the groups
|
|
51
|
-
group = this.options.orderedGroups.find(g => binding.tagMap[g] === g);
|
|
27
|
+
setOrderedGroups(groups) {
|
|
28
|
+
this.options.orderedGroups = groups;
|
|
52
29
|
}
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
// Group bindings in a map
|
|
65
|
-
const groupMap = new Map();
|
|
66
|
-
context_1.sortBindingsByPhase(bindings, keys_1.CoreTags.LIFE_CYCLE_OBSERVER_GROUP, this.options.orderedGroups);
|
|
67
|
-
for (const binding of bindings) {
|
|
68
|
-
const group = this.getObserverGroup(binding);
|
|
69
|
-
let bindingsInGroup = groupMap.get(group);
|
|
70
|
-
if (bindingsInGroup == null) {
|
|
71
|
-
bindingsInGroup = [];
|
|
72
|
-
groupMap.set(group, bindingsInGroup);
|
|
30
|
+
/**
|
|
31
|
+
* Get observer groups ordered by the group
|
|
32
|
+
*/
|
|
33
|
+
getObserverGroupsByOrder() {
|
|
34
|
+
const bindings = this.observersView.bindings;
|
|
35
|
+
const groups = this.sortObserverBindingsByGroup(bindings);
|
|
36
|
+
if (debug.enabled) {
|
|
37
|
+
debug('Observer groups: %j', groups.map(g => ({
|
|
38
|
+
group: g.group,
|
|
39
|
+
bindings: g.bindings.map(b => b.key),
|
|
40
|
+
})));
|
|
73
41
|
}
|
|
74
|
-
|
|
42
|
+
return groups;
|
|
75
43
|
}
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
44
|
+
/**
|
|
45
|
+
* Get the group for a given life cycle observer binding
|
|
46
|
+
* @param binding - Life cycle observer binding
|
|
47
|
+
*/
|
|
48
|
+
getObserverGroup(binding) {
|
|
49
|
+
// First check if there is an explicit group name in the tag
|
|
50
|
+
let group = binding.tagMap[keys_1.CoreTags.LIFE_CYCLE_OBSERVER_GROUP];
|
|
51
|
+
if (!group) {
|
|
52
|
+
// Fall back to a tag that matches one of the groups
|
|
53
|
+
group = this.options.orderedGroups.find(g => binding.tagMap[g] === g);
|
|
54
|
+
}
|
|
55
|
+
group = group || '';
|
|
56
|
+
debug('Binding %s is configured with observer group %s', binding.key, group);
|
|
57
|
+
return group;
|
|
80
58
|
}
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
for (const
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
59
|
+
/**
|
|
60
|
+
* Sort the life cycle observer bindings so that we can start/stop them
|
|
61
|
+
* in the right order. By default, we can start other observers before servers
|
|
62
|
+
* and stop them in the reverse order
|
|
63
|
+
* @param bindings - Life cycle observer bindings
|
|
64
|
+
*/
|
|
65
|
+
sortObserverBindingsByGroup(bindings) {
|
|
66
|
+
// Group bindings in a map
|
|
67
|
+
const groupMap = new Map();
|
|
68
|
+
context_1.sortBindingsByPhase(bindings, keys_1.CoreTags.LIFE_CYCLE_OBSERVER_GROUP, this.options.orderedGroups);
|
|
69
|
+
for (const binding of bindings) {
|
|
70
|
+
const group = this.getObserverGroup(binding);
|
|
71
|
+
let bindingsInGroup = groupMap.get(group);
|
|
72
|
+
if (bindingsInGroup == null) {
|
|
73
|
+
bindingsInGroup = [];
|
|
74
|
+
groupMap.set(group, bindingsInGroup);
|
|
75
|
+
}
|
|
76
|
+
bindingsInGroup.push(binding);
|
|
95
77
|
}
|
|
96
|
-
|
|
78
|
+
// Create an array for group entries
|
|
79
|
+
const groups = [];
|
|
80
|
+
for (const [group, bindingsInGroup] of groupMap) {
|
|
81
|
+
groups.push({ group, bindings: bindingsInGroup });
|
|
82
|
+
}
|
|
83
|
+
return groups;
|
|
97
84
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
85
|
+
/**
|
|
86
|
+
* Notify an observer group of the given event
|
|
87
|
+
* @param group - A group of bindings for life cycle observers
|
|
88
|
+
* @param event - Event name
|
|
89
|
+
*/
|
|
90
|
+
async notifyObservers(observers, bindings, event) {
|
|
91
|
+
if (!this.options.parallel) {
|
|
92
|
+
let index = 0;
|
|
93
|
+
for (const observer of observers) {
|
|
94
|
+
debug('Invoking %s observer for binding %s', event, bindings[index].key);
|
|
95
|
+
index++;
|
|
96
|
+
await this.invokeObserver(observer, event);
|
|
97
|
+
}
|
|
98
|
+
return;
|
|
99
|
+
}
|
|
100
|
+
// Parallel invocation
|
|
101
|
+
const notifiers = observers.map((observer, index) => {
|
|
102
|
+
debug('Invoking %s observer for binding %s', event, bindings[index].key);
|
|
103
|
+
return this.invokeObserver(observer, event);
|
|
104
|
+
});
|
|
105
|
+
await Promise.all(notifiers);
|
|
113
106
|
}
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
if (reverse) {
|
|
124
|
-
// Do not reverse the original `groups` in place
|
|
125
|
-
groups = [...groups].reverse();
|
|
107
|
+
/**
|
|
108
|
+
* Invoke an observer for the given event
|
|
109
|
+
* @param observer - A life cycle observer
|
|
110
|
+
* @param event - Event name
|
|
111
|
+
*/
|
|
112
|
+
async invokeObserver(observer, event) {
|
|
113
|
+
if (typeof observer[event] === 'function') {
|
|
114
|
+
await observer[event]();
|
|
115
|
+
}
|
|
126
116
|
}
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
117
|
+
/**
|
|
118
|
+
* Emit events to the observer groups
|
|
119
|
+
* @param events - Event names
|
|
120
|
+
* @param groups - Observer groups
|
|
121
|
+
*/
|
|
122
|
+
async notifyGroups(events, groups, reverse = false) {
|
|
123
|
+
const observers = await this.observersView.values();
|
|
124
|
+
const bindings = this.observersView.bindings;
|
|
125
|
+
if (reverse) {
|
|
126
|
+
// Do not reverse the original `groups` in place
|
|
127
|
+
groups = [...groups].reverse();
|
|
135
128
|
}
|
|
136
|
-
for (const
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
129
|
+
for (const group of groups) {
|
|
130
|
+
const observersForGroup = [];
|
|
131
|
+
const bindingsInGroup = reverse
|
|
132
|
+
? group.bindings.reverse()
|
|
133
|
+
: group.bindings;
|
|
134
|
+
for (const binding of bindingsInGroup) {
|
|
135
|
+
const index = bindings.indexOf(binding);
|
|
136
|
+
observersForGroup.push(observers[index]);
|
|
137
|
+
}
|
|
138
|
+
for (const event of events) {
|
|
139
|
+
debug('Beginning notification %s of %s...', event);
|
|
140
|
+
await this.notifyObservers(observersForGroup, group.bindings, event);
|
|
141
|
+
debug('Finished notification %s of %s', event);
|
|
142
|
+
}
|
|
140
143
|
}
|
|
141
144
|
}
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
145
|
+
/**
|
|
146
|
+
* Notify all life cycle observers by group of `start`
|
|
147
|
+
*/
|
|
148
|
+
async start() {
|
|
149
|
+
debug('Starting the %s...');
|
|
150
|
+
const groups = this.getObserverGroupsByOrder();
|
|
151
|
+
await this.notifyGroups(['start'], groups);
|
|
152
|
+
}
|
|
153
|
+
/**
|
|
154
|
+
* Notify all life cycle observers by group of `stop`
|
|
155
|
+
*/
|
|
156
|
+
async stop() {
|
|
157
|
+
debug('Stopping the %s...');
|
|
158
|
+
const groups = this.getObserverGroupsByOrder();
|
|
159
|
+
// Stop in the reverse order
|
|
160
|
+
await this.notifyGroups(['stop'], groups, true);
|
|
161
|
+
}
|
|
162
|
+
};
|
|
163
|
+
LifeCycleObserverRegistry = tslib_1.__decorate([
|
|
164
|
+
tslib_1.__param(0, context_1.inject.view(lifecycle_1.lifeCycleObserverFilter)),
|
|
165
|
+
tslib_1.__param(1, context_1.inject(keys_1.CoreBindings.LIFE_CYCLE_OBSERVER_OPTIONS, { optional: true })),
|
|
166
|
+
tslib_1.__metadata("design:paramtypes", [context_1.ContextView, Object])
|
|
167
|
+
], LifeCycleObserverRegistry);
|
|
168
|
+
return LifeCycleObserverRegistry;
|
|
169
|
+
})();
|
|
166
170
|
exports.LifeCycleObserverRegistry = LifeCycleObserverRegistry;
|
|
167
171
|
//# sourceMappingURL=lifecycle-registry.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle-registry.js","sourceRoot":"","sources":["../src/lifecycle-registry.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE
|
|
1
|
+
{"version":3,"file":"lifecycle-registry.js","sourceRoot":"","sources":["../src/lifecycle-registry.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,+CAK2B;AAC3B,iCAA8C;AAC9C,2CAAuE;AACvE,sCAAuC;AACvC,MAAM,KAAK,GAAG,YAAY,CAAC,yBAAyB,CAAC,CAAC;AA8BzC,QAAA,sBAAsB,GAAG,CAAC,QAAQ,CAAC,CAAC;AAEjD;;GAEG;AACH;IAAA,IAAa,yBAAyB,GAAtC,MAAa,yBAAyB;QACpC,YAEqB,aAA6C,EAE7C,UAAoC;YACrD,QAAQ,EAAE,IAAI;YACd,aAAa,EAAE,8BAAsB;SACtC;YALkB,kBAAa,GAAb,aAAa,CAAgC;YAE7C,YAAO,GAAP,OAAO,CAGzB;QACA,CAAC;QAEJ,gBAAgB,CAAC,MAAgB;YAC/B,IAAI,CAAC,OAAO,CAAC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AAC,eAAe,CAAC,iBAAiB,EAAE,KAAK,CAAC,QAAQ,EAAE,KAAK,CAAC,CAAC;oBACrE,KAAK,CAAC,gCAAgC,EAAE,KAAK,CAAC,CAAC;iBAChD;aACF;QACH,CAAC;QAED;;WAEG;QACI,KAAK,CAAC,KAAK;YAChB,KAAK,CAAC,oBAAoB,CAAC,CAAC;YAC5B,MAAM,MAAM,GAAG,IAAI,CAAC,wBAAwB,EAAE,CAAC;YAC/C,MAAM,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;QAC7C,CAAC;QAED;;WAEG;QACI,KAAK,CAAC,IAAI;YACf,KAAK,CAAC,oBAAoB,CAAC,CAAC;YAC5B,MAAM,MAAM,GAAG,IAAI,CAAC,wBAAwB,EAAE,CAAC;YAC/C,4BAA4B;YAC5B,MAAM,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;QAClD,CAAC;KACF,CAAA;IA7LY,yBAAyB;QAEjC,mBAAA,gBAAM,CAAC,IAAI,CAAC,mCAAuB,CAAC,CAAA;QAEpC,mBAAA,gBAAM,CAAC,mBAAY,CAAC,2BAA2B,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAA;iDADjC,qBAAW;OAHpC,yBAAyB,CA6LrC;IAAD,gCAAC;KAAA;AA7LY,8DAAyB"}
|
package/dist/lifecycle.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Binding, BindingSpec, Constructor, ValueOrPromise } from '@loopback/context';
|
|
1
|
+
import { Binding, BindingSpec, BindingTagFilter, Constructor, ValueOrPromise } from '@loopback/context';
|
|
2
2
|
/**
|
|
3
3
|
* Observers to handle life cycle start/stop events
|
|
4
4
|
*/
|
|
@@ -33,7 +33,7 @@ export declare function asLifeCycleObserver<T = unknown>(binding: Binding<T>): B
|
|
|
33
33
|
* Find all life cycle observer bindings. By default, a binding tagged with
|
|
34
34
|
* `CoreTags.LIFE_CYCLE_OBSERVER`. It's used as `BindingFilter`.
|
|
35
35
|
*/
|
|
36
|
-
export declare const lifeCycleObserverFilter:
|
|
36
|
+
export declare const lifeCycleObserverFilter: BindingTagFilter;
|
|
37
37
|
/**
|
|
38
38
|
* Sugar decorator to mark a class as life cycle observer
|
|
39
39
|
* @param group - Optional observer group name
|
package/dist/lifecycle.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.lifeCycleObserver = exports.lifeCycleObserverFilter = exports.asLifeCycleObserver = exports.isLifeCycleObserverClass = exports.isLifeCycleObserver = void 0;
|
|
7
8
|
const context_1 = require("@loopback/context");
|
|
8
9
|
const keys_1 = require("./keys");
|
|
9
10
|
const lifeCycleMethods = ['start', 'stop'];
|
package/dist/lifecycle.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;AAEhE,+CAQ2B;AAC3B,iCAAgC;AAgBhC,MAAM,gBAAgB,GAAgC,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAExE;;;GAGG;AACH,SAAgB,mBAAmB,CAAC,GAAW;IAC7C,MAAM,SAAS,GAAG,GAAiC,CAAC;IACpD,OAAO,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,OAAO,SAAS,CAAC,CAAC,CAAC,KAAK,UAAU,CAAC,CAAC;AACxE,CAAC;AAHD,kDAGC;AAED;;;GAGG;AACH,SAAgB,wBAAwB,CACtC,IAA0B;IAE1B,OAAO,IAAI,CAAC,SAAS,IAAI,mBAAmB,CAAC,IAAI,CAAC,SAAS,CAAC,CAAC;AAC/D,CAAC;AAJD,4DAIC;AAED;;;;;GAKG;AACH,SAAgB,mBAAmB,CAAc,OAAmB;IAClE,OAAO,OAAO,CAAC,GAAG,CAAC,eAAQ,CAAC,mBAAmB,CAAC,CAAC;AACnD,CAAC;AAFD,kDAEC;AAED;;;GAGG;AACU,QAAA,uBAAuB,GAAqB,qBAAW,CAClE,eAAQ,CAAC,mBAAmB,CAC7B,CAAC;AAEF;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,KAAK,GAAG,EAAE,EAAE,GAAG,KAAoB;IACnE,OAAO,cAAI,CACT,mBAAmB,EACnB;QACE,IAAI,EAAE;YACJ,CAAC,eAAQ,CAAC,yBAAyB,CAAC,EAAE,KAAK;SAC5C;KACF,EACD,GAAG,KAAK,CACT,CAAC;AACJ,CAAC;AAVD,8CAUC"}
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
import { Constructor } from '@loopback/context';
|
|
2
|
+
/**
|
|
3
|
+
* A replacement for `typeof Target` to be used in mixin class definitions.
|
|
4
|
+
* This is a workaround for TypeScript limitation described in
|
|
5
|
+
* - https://github.com/microsoft/TypeScript/issues/17293
|
|
6
|
+
* - https://github.com/microsoft/TypeScript/issues/17744
|
|
7
|
+
* - https://github.com/microsoft/TypeScript/issues/36060
|
|
8
|
+
*
|
|
9
|
+
* @example
|
|
10
|
+
*
|
|
11
|
+
* ```ts
|
|
12
|
+
* export function MyMixin<T extends MixinTarget<Application>>(superClass: T) {
|
|
13
|
+
* return class extends superClass {
|
|
14
|
+
* // contribute new class members
|
|
15
|
+
* }
|
|
16
|
+
* };
|
|
17
|
+
* ```
|
|
18
|
+
*
|
|
19
|
+
* TypeScript does not allow class mixins to access protected members from
|
|
20
|
+
* the base class. You can use the following approach as a workaround:
|
|
21
|
+
*
|
|
22
|
+
* ```ts
|
|
23
|
+
* // @ts-ignore
|
|
24
|
+
* (this as unknown as {YourBaseClass}).protectedMember
|
|
25
|
+
* ```
|
|
26
|
+
*
|
|
27
|
+
* The directive `@ts-ignore` suppresses compiler error about accessing
|
|
28
|
+
* a protected member from outside. Unfortunately, it also disables other
|
|
29
|
+
* compile-time checks (e.g. to verify that a protected method was invoked
|
|
30
|
+
* with correct arguments, and so on). This is the same behavior you
|
|
31
|
+
* would get by using `Constructor<any>` instead of `MixinTarget<Application>`.
|
|
32
|
+
* The major improvement is that TypeScript can still infer the return
|
|
33
|
+
* type of the protected member, therefore `any` is NOT introduced to subsequent
|
|
34
|
+
* code.
|
|
35
|
+
*
|
|
36
|
+
* TypeScript also does not allow mixin class to overwrite a method inherited
|
|
37
|
+
* from a mapped type, see https://github.com/microsoft/TypeScript/issues/38496
|
|
38
|
+
* As a workaround, use `@ts-ignore` to disable the error.
|
|
39
|
+
*
|
|
40
|
+
* ```ts
|
|
41
|
+
* export function RepositoryMixin<T extends MixinTarget<Application>>(
|
|
42
|
+
* superClass: T,
|
|
43
|
+
* ) {
|
|
44
|
+
* return class extends superClass {
|
|
45
|
+
* // @ts-ignore
|
|
46
|
+
* public component<C extends Component = Component>(
|
|
47
|
+
* componentCtor: Constructor<C>,
|
|
48
|
+
* nameOrOptions?: string | BindingFromClassOptions,
|
|
49
|
+
* ) {
|
|
50
|
+
* const binding = super.component(componentCtor, nameOrOptions);
|
|
51
|
+
* // ...
|
|
52
|
+
* return binding;
|
|
53
|
+
* }
|
|
54
|
+
* }
|
|
55
|
+
* ```
|
|
56
|
+
*/
|
|
57
|
+
export declare type MixinTarget<T extends object> = Constructor<{
|
|
58
|
+
[P in keyof T]: T[P];
|
|
59
|
+
}>;
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
+
"use strict";
|
|
1
2
|
// Copyright IBM Corp. 2017,2020. All Rights Reserved.
|
|
2
3
|
// Node module: @loopback/core
|
|
3
4
|
// This file is licensed under the MIT License.
|
|
4
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
5
|
-
|
|
6
|
-
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
//# sourceMappingURL=mixin-target.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"mixin-target.js","sourceRoot":"","sources":["../src/mixin-target.ts"],"names":[],"mappings":";AAAA,sDAAsD;AACtD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE"}
|
package/dist/service.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Binding, BindingFilter, BindingTemplate, Constructor, InjectionMetadata, Provider } from '@loopback/context';
|
|
1
|
+
import { Binding, BindingFilter, BindingFromClassOptions, BindingTemplate, Constructor, InjectionMetadata, Provider } from '@loopback/context';
|
|
2
2
|
/**
|
|
3
3
|
* Representing an interface for services. In TypeScript, the `interface` does
|
|
4
4
|
* not have reflections at runtime. We use a string, a symbol or a Function as
|
|
@@ -8,10 +8,9 @@ export declare type ServiceInterface = string | symbol | Function;
|
|
|
8
8
|
/**
|
|
9
9
|
* Options to register a service binding
|
|
10
10
|
*/
|
|
11
|
-
export
|
|
12
|
-
name?: string;
|
|
11
|
+
export interface ServiceOptions extends BindingFromClassOptions {
|
|
13
12
|
interface?: ServiceInterface;
|
|
14
|
-
}
|
|
13
|
+
}
|
|
15
14
|
/**
|
|
16
15
|
* `@service` injects a service instance that matches the class or interface.
|
|
17
16
|
*
|
|
@@ -55,7 +54,7 @@ export declare function filterByServiceInterface(serviceInterface: ServiceInterf
|
|
|
55
54
|
* @param cls - Service class or provider
|
|
56
55
|
* @param options - Service options
|
|
57
56
|
*/
|
|
58
|
-
export declare function createServiceBinding<S>(cls: Constructor<S
|
|
57
|
+
export declare function createServiceBinding<S>(cls: Constructor<S | Provider<S>>, options?: ServiceOptions): Binding<S>;
|
|
59
58
|
/**
|
|
60
59
|
* Create a binding template for a service interface
|
|
61
60
|
* @param serviceInterface - Service interface
|
package/dist/service.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
// This file is licensed under the MIT License.
|
|
5
5
|
// License text available at https://opensource.org/licenses/MIT
|
|
6
6
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.asService = exports.createServiceBinding = exports.filterByServiceInterface = exports.service = void 0;
|
|
7
8
|
const context_1 = require("@loopback/context");
|
|
8
9
|
const keys_1 = require("./keys");
|
|
9
10
|
/**
|
|
@@ -107,6 +108,7 @@ function createServiceBinding(cls, options = {}) {
|
|
|
107
108
|
const binding = context_1.createBindingFromClass(cls, {
|
|
108
109
|
name,
|
|
109
110
|
type: keys_1.CoreTags.SERVICE,
|
|
111
|
+
...options,
|
|
110
112
|
}).apply(asService((_a = options.interface) !== null && _a !== void 0 ? _a : cls));
|
|
111
113
|
return binding;
|
|
112
114
|
}
|
package/dist/service.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE
|
|
1
|
+
{"version":3,"file":"service.js","sourceRoot":"","sources":["../src/service.ts"],"names":[],"mappings":";AAAA,iDAAiD;AACjD,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;AAEhE,+CAgB2B;AAC3B,iCAAgC;AAgBhC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8BG;AACH,SAAgB,OAAO,CACrB,gBAAmC,EACnC,QAA4B;IAE5B,OAAO,gBAAM,CACX,EAAE,EACF,EAAC,SAAS,EAAE,UAAU,EAAE,GAAG,QAAQ,EAAC,EACpC,CAAC,GAAG,EAAE,SAAS,EAAE,OAAO,EAAE,EAAE;QAC1B,IAAI,WAAW,GAAG,gBAAgB,CAAC;QACnC,IAAI,CAAC,WAAW,EAAE;YAChB,IAAI,OAAO,SAAS,CAAC,gCA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BAAkC;IAC1D,OAAO,SAAS,eAAe,CAAC,OAAgB;QAC9C,OAAO,CAAC,GAAG,CAAC;YACV,CAAC,qBAAW,CAAC,IAAI,CAAC,EAAE,eAAQ,CAAC,OAAO;YACpC,CAAC,eAAQ,CAAC,iBAAiB,CAAC,EAAE,gBAAgB;SAC/C,CAAC,CAAC;IACL,CAAC,CAAC;AACJ,CAAC;AAPD,8BAOC"}
|
package/package.json
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@loopback/core",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.7.0",
|
|
4
4
|
"description": "LoopBack 4 core",
|
|
5
|
+
"main": "dist/index.js",
|
|
6
|
+
"types": "dist/index.d.ts",
|
|
5
7
|
"engines": {
|
|
6
8
|
"node": ">=10"
|
|
7
9
|
},
|
|
@@ -19,22 +21,19 @@
|
|
|
19
21
|
"copyright.owner": "IBM Corp.",
|
|
20
22
|
"license": "MIT",
|
|
21
23
|
"dependencies": {
|
|
22
|
-
"@loopback/context": "^3.
|
|
24
|
+
"@loopback/context": "^3.8.1",
|
|
23
25
|
"debug": "^4.1.1",
|
|
24
|
-
"
|
|
25
|
-
"tslib": "^1.11.1"
|
|
26
|
+
"tslib": "^2.0.0"
|
|
26
27
|
},
|
|
27
28
|
"devDependencies": {
|
|
28
|
-
"@loopback/build": "^5.
|
|
29
|
-
"@loopback/eslint-config": "^
|
|
30
|
-
"@loopback/testlab": "^3.1.
|
|
29
|
+
"@loopback/build": "^5.4.1",
|
|
30
|
+
"@loopback/eslint-config": "^7.0.1",
|
|
31
|
+
"@loopback/testlab": "^3.1.5",
|
|
31
32
|
"@types/debug": "^4.1.5",
|
|
32
|
-
"@types/node": "^10.17.
|
|
33
|
+
"@types/node": "^10.17.24"
|
|
33
34
|
},
|
|
34
35
|
"files": [
|
|
35
36
|
"README.md",
|
|
36
|
-
"index.js",
|
|
37
|
-
"index.d.ts",
|
|
38
37
|
"dist",
|
|
39
38
|
"src",
|
|
40
39
|
"!*/__tests__"
|
|
@@ -44,5 +43,5 @@
|
|
|
44
43
|
"url": "https://github.com/strongloop/loopback-next.git",
|
|
45
44
|
"directory": "packages/core"
|
|
46
45
|
},
|
|
47
|
-
"gitHead": "
|
|
46
|
+
"gitHead": "62aea854bf85c5a5995b59e6908fe5409f7eea96"
|
|
48
47
|
}
|