@loopback/core 4.0.0-alpha.9 → 4.0.2
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/LICENSE +25 -0
- package/README.md +77 -2
- package/dist/application.d.ts +341 -0
- package/dist/application.js +554 -0
- package/dist/application.js.map +1 -0
- package/dist/component.d.ts +80 -0
- package/dist/component.js +59 -0
- package/dist/component.js.map +1 -0
- package/dist/extension-point.d.ts +121 -0
- package/dist/extension-point.js +227 -0
- package/dist/extension-point.js.map +1 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +31 -0
- package/dist/index.js.map +1 -0
- package/dist/keys.d.ts +97 -0
- package/dist/keys.js +109 -0
- package/dist/keys.js.map +1 -0
- package/dist/lifecycle-registry.d.ts +91 -0
- package/dist/lifecycle-registry.js +191 -0
- package/dist/lifecycle-registry.js.map +1 -0
- package/dist/lifecycle.d.ts +47 -0
- package/dist/lifecycle.js +56 -0
- package/dist/lifecycle.js.map +1 -0
- package/dist/mixin-target.d.ts +60 -0
- package/{lib6/internal-types.js → dist/mixin-target.js} +2 -3
- package/dist/mixin-target.js.map +1 -0
- package/dist/server.d.ts +16 -0
- package/{lib6/component.js → dist/server.js} +2 -2
- package/dist/server.js.map +1 -0
- package/dist/service.d.ts +63 -0
- package/dist/service.js +151 -0
- package/dist/service.js.map +1 -0
- package/package.json +39 -37
- package/src/application.ts +719 -0
- package/src/component.ts +155 -0
- package/src/extension-point.ts +312 -0
- package/src/index.ts +29 -0
- package/src/keys.ts +144 -0
- package/src/lifecycle-registry.ts +268 -0
- package/src/lifecycle.ts +90 -0
- package/src/mixin-target.ts +69 -0
- package/src/server.ts +22 -0
- package/src/service.ts +211 -0
- package/index.d.ts +0 -6
- package/index.js +0 -9
- package/lib/application.d.ts +0 -54
- package/lib/application.js +0 -81
- package/lib/application.js.map +0 -1
- package/lib/component.d.ts +0 -2
- package/lib/component.js +0 -7
- package/lib/component.js.map +0 -1
- package/lib/http-handler.d.ts +0 -16
- package/lib/http-handler.js +0 -62
- package/lib/http-handler.js.map +0 -1
- package/lib/index.d.ts +0 -17
- package/lib/index.js +0 -37
- package/lib/index.js.map +0 -1
- package/lib/internal-types.d.ts +0 -29
- package/lib/internal-types.js +0 -8
- package/lib/internal-types.js.map +0 -1
- package/lib/keys.d.ts +0 -7
- package/lib/keys.js +0 -16
- package/lib/keys.js.map +0 -1
- package/lib/parser.d.ts +0 -11
- package/lib/parser.js +0 -96
- package/lib/parser.js.map +0 -1
- package/lib/promisify.d.ts +0 -3
- package/lib/promisify.js +0 -34
- package/lib/promisify.js.map +0 -1
- package/lib/router/metadata.d.ts +0 -12
- package/lib/router/metadata.js +0 -30
- package/lib/router/metadata.js.map +0 -1
- package/lib/router/routing-table.d.ts +0 -16
- package/lib/router/routing-table.js +0 -97
- package/lib/router/routing-table.js.map +0 -1
- package/lib/sequence.d.ts +0 -55
- package/lib/sequence.js +0 -99
- package/lib/sequence.js.map +0 -1
- package/lib/server.d.ts +0 -23
- package/lib/server.js +0 -64
- package/lib/server.js.map +0 -1
- package/lib/writer.d.ts +0 -11
- package/lib/writer.js +0 -34
- package/lib/writer.js.map +0 -1
- package/lib6/application.d.ts +0 -54
- package/lib6/application.js +0 -81
- package/lib6/application.js.map +0 -1
- package/lib6/component.d.ts +0 -2
- package/lib6/component.js.map +0 -1
- package/lib6/http-handler.d.ts +0 -16
- package/lib6/http-handler.js +0 -72
- package/lib6/http-handler.js.map +0 -1
- package/lib6/index.d.ts +0 -17
- package/lib6/index.js +0 -37
- package/lib6/index.js.map +0 -1
- package/lib6/internal-types.d.ts +0 -29
- package/lib6/internal-types.js.map +0 -1
- package/lib6/keys.d.ts +0 -7
- package/lib6/keys.js +0 -16
- package/lib6/keys.js.map +0 -1
- package/lib6/parser.d.ts +0 -11
- package/lib6/parser.js +0 -106
- package/lib6/parser.js.map +0 -1
- package/lib6/promisify.d.ts +0 -3
- package/lib6/promisify.js +0 -34
- package/lib6/promisify.js.map +0 -1
- package/lib6/router/metadata.d.ts +0 -12
- package/lib6/router/metadata.js +0 -30
- package/lib6/router/metadata.js.map +0 -1
- package/lib6/router/routing-table.d.ts +0 -16
- package/lib6/router/routing-table.js +0 -97
- package/lib6/router/routing-table.js.map +0 -1
- package/lib6/sequence.d.ts +0 -55
- package/lib6/sequence.js +0 -109
- package/lib6/sequence.js.map +0 -1
- package/lib6/server.d.ts +0 -23
- package/lib6/server.js +0 -74
- package/lib6/server.js.map +0 -1
- package/lib6/writer.d.ts +0 -11
- package/lib6/writer.js +0 -34
- package/lib6/writer.js.map +0 -1
package/dist/keys.js
ADDED
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. and LoopBack contributors 2017,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/core
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.CoreTags = exports.CoreBindings = void 0;
|
|
8
|
+
const context_1 = require("@loopback/context");
|
|
9
|
+
/**
|
|
10
|
+
* Namespace for core binding keys
|
|
11
|
+
*/
|
|
12
|
+
var CoreBindings;
|
|
13
|
+
(function (CoreBindings) {
|
|
14
|
+
// application
|
|
15
|
+
/**
|
|
16
|
+
* Binding key for application instance itself
|
|
17
|
+
*/
|
|
18
|
+
CoreBindings.APPLICATION_INSTANCE = context_1.BindingKey.create('application.instance');
|
|
19
|
+
/**
|
|
20
|
+
* Binding key for application configuration
|
|
21
|
+
*/
|
|
22
|
+
CoreBindings.APPLICATION_CONFIG = context_1.BindingKey.create('application.config');
|
|
23
|
+
/**
|
|
24
|
+
* Binding key for the content of `package.json`
|
|
25
|
+
*/
|
|
26
|
+
CoreBindings.APPLICATION_METADATA = context_1.BindingKey.create('application.metadata');
|
|
27
|
+
// server
|
|
28
|
+
/**
|
|
29
|
+
* Binding key for servers
|
|
30
|
+
*/
|
|
31
|
+
CoreBindings.SERVERS = 'servers';
|
|
32
|
+
// component
|
|
33
|
+
/**
|
|
34
|
+
* Binding key for components
|
|
35
|
+
*/
|
|
36
|
+
CoreBindings.COMPONENTS = 'components';
|
|
37
|
+
// controller
|
|
38
|
+
CoreBindings.CONTROLLERS = 'controllers';
|
|
39
|
+
/**
|
|
40
|
+
* Binding key for the controller class resolved in the current request
|
|
41
|
+
* context
|
|
42
|
+
*/
|
|
43
|
+
CoreBindings.CONTROLLER_CLASS = context_1.BindingKey.create('controller.current.ctor');
|
|
44
|
+
/**
|
|
45
|
+
* Binding key for the controller method resolved in the current request
|
|
46
|
+
* context
|
|
47
|
+
*/
|
|
48
|
+
CoreBindings.CONTROLLER_METHOD_NAME = context_1.BindingKey.create('controller.current.operation');
|
|
49
|
+
/**
|
|
50
|
+
* Binding key for the controller method metadata resolved in the current
|
|
51
|
+
* request context
|
|
52
|
+
*/
|
|
53
|
+
CoreBindings.CONTROLLER_METHOD_META = 'controller.method.meta';
|
|
54
|
+
/**
|
|
55
|
+
* Binding key for the controller instance resolved in the current request
|
|
56
|
+
* context
|
|
57
|
+
*/
|
|
58
|
+
CoreBindings.CONTROLLER_CURRENT = context_1.BindingKey.create('controller.current');
|
|
59
|
+
CoreBindings.LIFE_CYCLE_OBSERVERS = 'lifeCycleObservers';
|
|
60
|
+
/**
|
|
61
|
+
* Binding key for life cycle observer options
|
|
62
|
+
*/
|
|
63
|
+
CoreBindings.LIFE_CYCLE_OBSERVER_REGISTRY = context_1.BindingKey.create('lifeCycleObserver.registry');
|
|
64
|
+
/**
|
|
65
|
+
* Binding key for life cycle observer options
|
|
66
|
+
*/
|
|
67
|
+
CoreBindings.LIFE_CYCLE_OBSERVER_OPTIONS = context_1.BindingKey.create('lifeCycleObserver.options');
|
|
68
|
+
})(CoreBindings = exports.CoreBindings || (exports.CoreBindings = {}));
|
|
69
|
+
var CoreTags;
|
|
70
|
+
(function (CoreTags) {
|
|
71
|
+
/**
|
|
72
|
+
* Binding tag for components
|
|
73
|
+
*/
|
|
74
|
+
CoreTags.COMPONENT = 'component';
|
|
75
|
+
/**
|
|
76
|
+
* Binding tag for servers
|
|
77
|
+
*/
|
|
78
|
+
CoreTags.SERVER = 'server';
|
|
79
|
+
/**
|
|
80
|
+
* Binding tag for controllers
|
|
81
|
+
*/
|
|
82
|
+
CoreTags.CONTROLLER = 'controller';
|
|
83
|
+
/**
|
|
84
|
+
* Binding tag for services
|
|
85
|
+
*/
|
|
86
|
+
CoreTags.SERVICE = 'service';
|
|
87
|
+
/**
|
|
88
|
+
* Binding tag for the service interface
|
|
89
|
+
*/
|
|
90
|
+
CoreTags.SERVICE_INTERFACE = 'serviceInterface';
|
|
91
|
+
/**
|
|
92
|
+
* Binding tag for life cycle observers
|
|
93
|
+
*/
|
|
94
|
+
CoreTags.LIFE_CYCLE_OBSERVER = 'lifeCycleObserver';
|
|
95
|
+
/**
|
|
96
|
+
* Binding tag for group name of life cycle observers
|
|
97
|
+
*/
|
|
98
|
+
CoreTags.LIFE_CYCLE_OBSERVER_GROUP = 'lifeCycleObserverGroup';
|
|
99
|
+
/**
|
|
100
|
+
* Binding tag for extensions to specify name of the extension point that an
|
|
101
|
+
* extension contributes to.
|
|
102
|
+
*/
|
|
103
|
+
CoreTags.EXTENSION_FOR = 'extensionFor';
|
|
104
|
+
/**
|
|
105
|
+
* Binding tag for an extension point to specify name of the extension point
|
|
106
|
+
*/
|
|
107
|
+
CoreTags.EXTENSION_POINT = 'extensionPoint';
|
|
108
|
+
})(CoreTags = exports.CoreTags || (exports.CoreTags = {}));
|
|
109
|
+
//# sourceMappingURL=keys.js.map
|
package/dist/keys.js.map
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"keys.js","sourceRoot":"","sources":["../src/keys.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;AAEhE,+CAA6C;AAY7C;;GAEG;AACH,IAAiB,YAAY,CA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AiB,GAAG,kBAAkB,CAAC;IAEpD;;OAEG;IACU,4BAAmB,GAAG,mBAAmB,CAAC;IAEvD;;OAEG;IACU,kCAAyB,GAAG,wBAAwB,CAAC;IAElE;;;OAGG;IACU,sBAAa,GAAG,cAAc,CAAC;IAE5C;;OAEG;IACU,wBAAe,GAAG,gBAAgB,CAAC;AAClD,CAAC,EA7CgB,QAAQ,GAAR,gBAAQ,KAAR,gBAAQ,QA6CxB"}
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
import { Binding, Context, ContextView } from '@loopback/context';
|
|
2
|
+
import { LifeCycleObserver } from './lifecycle';
|
|
3
|
+
/**
|
|
4
|
+
* A group of life cycle observers
|
|
5
|
+
*/
|
|
6
|
+
export declare type LifeCycleObserverGroup = {
|
|
7
|
+
/**
|
|
8
|
+
* Observer group name
|
|
9
|
+
*/
|
|
10
|
+
group: string;
|
|
11
|
+
/**
|
|
12
|
+
* Bindings for observers within the group
|
|
13
|
+
*/
|
|
14
|
+
bindings: Readonly<Binding<LifeCycleObserver>>[];
|
|
15
|
+
};
|
|
16
|
+
export declare type LifeCycleObserverOptions = {
|
|
17
|
+
/**
|
|
18
|
+
* Control the order of observer groups for notifications. For example,
|
|
19
|
+
* with `['datasource', 'server']`, the observers in `datasource` group are
|
|
20
|
+
* notified before those in `server` group during `start`. Please note that
|
|
21
|
+
* observers are notified in the reverse order during `stop`.
|
|
22
|
+
*/
|
|
23
|
+
orderedGroups: string[];
|
|
24
|
+
/**
|
|
25
|
+
* Override and disable lifecycle observer groups. This setting applies to
|
|
26
|
+
* both ordered groups (i.e. those defined in `orderedGroups`) and unordered
|
|
27
|
+
* groups.
|
|
28
|
+
*/
|
|
29
|
+
disabledGroups?: string[];
|
|
30
|
+
/**
|
|
31
|
+
* Notify observers of the same group in parallel, default to `true`
|
|
32
|
+
*/
|
|
33
|
+
parallel?: boolean;
|
|
34
|
+
};
|
|
35
|
+
export declare const DEFAULT_ORDERED_GROUPS: string[];
|
|
36
|
+
/**
|
|
37
|
+
* A context-based registry for life cycle observers
|
|
38
|
+
*/
|
|
39
|
+
export declare class LifeCycleObserverRegistry implements LifeCycleObserver {
|
|
40
|
+
protected readonly context: Context;
|
|
41
|
+
protected readonly observersView: ContextView<LifeCycleObserver>;
|
|
42
|
+
protected readonly options: LifeCycleObserverOptions;
|
|
43
|
+
constructor(context: Context, observersView: ContextView<LifeCycleObserver>, options?: LifeCycleObserverOptions);
|
|
44
|
+
setOrderedGroups(groups: string[]): void;
|
|
45
|
+
/**
|
|
46
|
+
* Get observer groups ordered by the group
|
|
47
|
+
*/
|
|
48
|
+
getObserverGroupsByOrder(): LifeCycleObserverGroup[];
|
|
49
|
+
/**
|
|
50
|
+
* Get the group for a given life cycle observer binding
|
|
51
|
+
* @param binding - Life cycle observer binding
|
|
52
|
+
*/
|
|
53
|
+
protected getObserverGroup(binding: Readonly<Binding<LifeCycleObserver>>): string;
|
|
54
|
+
/**
|
|
55
|
+
* Sort the life cycle observer bindings so that we can start/stop them
|
|
56
|
+
* in the right order. By default, we can start other observers before servers
|
|
57
|
+
* and stop them in the reverse order
|
|
58
|
+
* @param bindings - Life cycle observer bindings
|
|
59
|
+
*/
|
|
60
|
+
protected sortObserverBindingsByGroup(bindings: Readonly<Binding<LifeCycleObserver>>[]): LifeCycleObserverGroup[];
|
|
61
|
+
/**
|
|
62
|
+
* Notify an observer group of the given event
|
|
63
|
+
* @param group - A group of bindings for life cycle observers
|
|
64
|
+
* @param event - Event name
|
|
65
|
+
*/
|
|
66
|
+
protected notifyObservers(observers: LifeCycleObserver[], bindings: Readonly<Binding<LifeCycleObserver>>[], event: keyof LifeCycleObserver): Promise<void>;
|
|
67
|
+
/**
|
|
68
|
+
* Invoke an observer for the given event
|
|
69
|
+
* @param observer - A life cycle observer
|
|
70
|
+
* @param event - Event name
|
|
71
|
+
*/
|
|
72
|
+
protected invokeObserver(observer: LifeCycleObserver, event: keyof LifeCycleObserver): Promise<void>;
|
|
73
|
+
/**
|
|
74
|
+
* Emit events to the observer groups
|
|
75
|
+
* @param events - Event names
|
|
76
|
+
* @param groups - Observer groups
|
|
77
|
+
*/
|
|
78
|
+
protected notifyGroups(events: (keyof LifeCycleObserver)[], groups: LifeCycleObserverGroup[], reverse?: boolean): Promise<void>;
|
|
79
|
+
/**
|
|
80
|
+
* Notify all life cycle observers by group of `init`
|
|
81
|
+
*/
|
|
82
|
+
init(): Promise<void>;
|
|
83
|
+
/**
|
|
84
|
+
* Notify all life cycle observers by group of `start`
|
|
85
|
+
*/
|
|
86
|
+
start(): Promise<void>;
|
|
87
|
+
/**
|
|
88
|
+
* Notify all life cycle observers by group of `stop`
|
|
89
|
+
*/
|
|
90
|
+
stop(): Promise<void>;
|
|
91
|
+
}
|
|
@@ -0,0 +1,191 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/core
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.LifeCycleObserverRegistry = exports.DEFAULT_ORDERED_GROUPS = void 0;
|
|
8
|
+
const tslib_1 = require("tslib");
|
|
9
|
+
const context_1 = require("@loopback/context");
|
|
10
|
+
const debug_1 = tslib_1.__importDefault(require("debug"));
|
|
11
|
+
const keys_1 = require("./keys");
|
|
12
|
+
const lifecycle_1 = require("./lifecycle");
|
|
13
|
+
const debug = (0, debug_1.default)('loopback:core:lifecycle');
|
|
14
|
+
exports.DEFAULT_ORDERED_GROUPS = ['server'];
|
|
15
|
+
/**
|
|
16
|
+
* A context-based registry for life cycle observers
|
|
17
|
+
*/
|
|
18
|
+
let LifeCycleObserverRegistry = class LifeCycleObserverRegistry {
|
|
19
|
+
constructor(context, observersView, options = {
|
|
20
|
+
parallel: true,
|
|
21
|
+
orderedGroups: exports.DEFAULT_ORDERED_GROUPS,
|
|
22
|
+
}) {
|
|
23
|
+
this.context = context;
|
|
24
|
+
this.observersView = observersView;
|
|
25
|
+
this.options = options;
|
|
26
|
+
}
|
|
27
|
+
setOrderedGroups(groups) {
|
|
28
|
+
this.options.orderedGroups = groups;
|
|
29
|
+
}
|
|
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
|
+
})));
|
|
41
|
+
}
|
|
42
|
+
return groups;
|
|
43
|
+
}
|
|
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;
|
|
58
|
+
}
|
|
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
|
+
(0, 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);
|
|
77
|
+
}
|
|
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;
|
|
84
|
+
}
|
|
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);
|
|
106
|
+
}
|
|
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
|
+
// Supply `undefined` for legacy callback function expected by
|
|
115
|
+
// DataSource.stop()
|
|
116
|
+
await (0, context_1.invokeMethod)(observer, event, this.context, [undefined], {
|
|
117
|
+
skipInterceptors: true,
|
|
118
|
+
});
|
|
119
|
+
}
|
|
120
|
+
}
|
|
121
|
+
/**
|
|
122
|
+
* Emit events to the observer groups
|
|
123
|
+
* @param events - Event names
|
|
124
|
+
* @param groups - Observer groups
|
|
125
|
+
*/
|
|
126
|
+
async notifyGroups(events, groups, reverse = false) {
|
|
127
|
+
var _a;
|
|
128
|
+
const observers = await this.observersView.values();
|
|
129
|
+
const bindings = this.observersView.bindings;
|
|
130
|
+
const found = observers.some(observer => events.some(e => typeof observer[e] === 'function'));
|
|
131
|
+
if (!found)
|
|
132
|
+
return;
|
|
133
|
+
if (reverse) {
|
|
134
|
+
// Do not reverse the original `groups` in place
|
|
135
|
+
groups = [...groups].reverse();
|
|
136
|
+
}
|
|
137
|
+
for (const group of groups) {
|
|
138
|
+
if ((_a = this.options.disabledGroups) === null || _a === void 0 ? void 0 : _a.includes(group.group)) {
|
|
139
|
+
debug('Notification skipped (Group is disabled): %s', group.group);
|
|
140
|
+
continue;
|
|
141
|
+
}
|
|
142
|
+
const observersForGroup = [];
|
|
143
|
+
const bindingsInGroup = reverse
|
|
144
|
+
? group.bindings.reverse()
|
|
145
|
+
: group.bindings;
|
|
146
|
+
for (const binding of bindingsInGroup) {
|
|
147
|
+
const index = bindings.indexOf(binding);
|
|
148
|
+
observersForGroup.push(observers[index]);
|
|
149
|
+
}
|
|
150
|
+
for (const event of events) {
|
|
151
|
+
debug('Beginning notification %s of %s...', event);
|
|
152
|
+
await this.notifyObservers(observersForGroup, group.bindings, event);
|
|
153
|
+
debug('Finished notification %s of %s', event);
|
|
154
|
+
}
|
|
155
|
+
}
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Notify all life cycle observers by group of `init`
|
|
159
|
+
*/
|
|
160
|
+
async init() {
|
|
161
|
+
debug('Initializing the %s...');
|
|
162
|
+
const groups = this.getObserverGroupsByOrder();
|
|
163
|
+
await this.notifyGroups(['init'], groups);
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Notify all life cycle observers by group of `start`
|
|
167
|
+
*/
|
|
168
|
+
async start() {
|
|
169
|
+
debug('Starting the %s...');
|
|
170
|
+
const groups = this.getObserverGroupsByOrder();
|
|
171
|
+
await this.notifyGroups(['start'], groups);
|
|
172
|
+
}
|
|
173
|
+
/**
|
|
174
|
+
* Notify all life cycle observers by group of `stop`
|
|
175
|
+
*/
|
|
176
|
+
async stop() {
|
|
177
|
+
debug('Stopping the %s...');
|
|
178
|
+
const groups = this.getObserverGroupsByOrder();
|
|
179
|
+
// Stop in the reverse order
|
|
180
|
+
await this.notifyGroups(['stop'], groups, true);
|
|
181
|
+
}
|
|
182
|
+
};
|
|
183
|
+
LifeCycleObserverRegistry = tslib_1.__decorate([
|
|
184
|
+
tslib_1.__param(0, context_1.inject.context()),
|
|
185
|
+
tslib_1.__param(1, context_1.inject.view(lifecycle_1.lifeCycleObserverFilter)),
|
|
186
|
+
tslib_1.__param(2, (0, context_1.inject)(keys_1.CoreBindings.LIFE_CYCLE_OBSERVER_OPTIONS, { optional: true })),
|
|
187
|
+
tslib_1.__metadata("design:paramtypes", [context_1.Context,
|
|
188
|
+
context_1.ContextView, Object])
|
|
189
|
+
], LifeCycleObserverRegistry);
|
|
190
|
+
exports.LifeCycleObserverRegistry = LifeCycleObserverRegistry;
|
|
191
|
+
//# sourceMappingURL=lifecycle-registry.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle-registry.js","sourceRoot":"","sources":["../src/lifecycle-registry.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,+CAO2B;AAC3B,0DAAiC;AACjC,iCAA8C;AAC9C,2CAAuE;AACvE,MAAM,KAAK,GAAG,IAAA,eAAY,EAAC,yBAAyB,CAAC,C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,MAAM,CAAC,CAAC;IAC5C,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,KAAK;QAChB,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAC5B,MAAM,MAAM,GAAG,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC/C,MAAM,IAAI,CAAC,YAAY,CAAC,CAAC,OAAO,CAAC,EAAE,MAAM,CAAC,CAAC;IAC7C,CAAC;IAED;;OAEG;IACI,KAAK,CAAC,IAAI;QACf,KAAK,CAAC,oBAAoB,CAAC,CAAC;QAC5B,MAAM,MAAM,GAAG,IAAI,CAAC,wBAAwB,EAAE,CAAC;QAC/C,4BAA4B;QAC5B,MAAM,IAAI,CAAC,YAAY,CAAC,CAAC,MAAM,CAAC,EAAE,MAAM,EAAE,IAAI,CAAC,CAAC;IAClD,CAAC;CACF,CAAA;AAlNY,yBAAyB;IAEjC,mBAAA,gBAAM,CAAC,OAAO,EAAE,CAAA;IAEhB,mBAAA,gBAAM,CAAC,IAAI,CAAC,mCAAuB,CAAC,CAAA;IAEpC,mBAAA,IAAA,gBAAM,EAAC,mBAAY,CAAC,2BAA2B,EAAE,EAAC,QAAQ,EAAE,IAAI,EAAC,CAAC,CAAA;6CAHvC,iBAAO;QAED,qBAAW;GALpC,yBAAyB,CAkNrC;AAlNY,8DAAyB"}
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import { Binding, BindingSpec, BindingTagFilter, Constructor, ValueOrPromise } from '@loopback/context';
|
|
2
|
+
/**
|
|
3
|
+
* Observers to handle life cycle init/start/stop events
|
|
4
|
+
*/
|
|
5
|
+
export interface LifeCycleObserver {
|
|
6
|
+
/**
|
|
7
|
+
* The method to be invoked during `init`. It will only be called at most once
|
|
8
|
+
* for a given application instance.
|
|
9
|
+
*/
|
|
10
|
+
init?(...injectedArgs: unknown[]): ValueOrPromise<void>;
|
|
11
|
+
/**
|
|
12
|
+
* The method to be invoked during `start`
|
|
13
|
+
*/
|
|
14
|
+
start?(...injectedArgs: unknown[]): ValueOrPromise<void>;
|
|
15
|
+
/**
|
|
16
|
+
* The method to be invoked during `stop`
|
|
17
|
+
*/
|
|
18
|
+
stop?(...injectedArgs: unknown[]): ValueOrPromise<void>;
|
|
19
|
+
}
|
|
20
|
+
/**
|
|
21
|
+
* Test if an object implements LifeCycleObserver
|
|
22
|
+
* @param obj - An object
|
|
23
|
+
*/
|
|
24
|
+
export declare function isLifeCycleObserver(obj: object): obj is LifeCycleObserver;
|
|
25
|
+
/**
|
|
26
|
+
* Test if a class implements LifeCycleObserver
|
|
27
|
+
* @param ctor - A class
|
|
28
|
+
*/
|
|
29
|
+
export declare function isLifeCycleObserverClass(ctor: Constructor<unknown>): ctor is Constructor<LifeCycleObserver>;
|
|
30
|
+
/**
|
|
31
|
+
* A `BindingTemplate` function to configure the binding as life cycle observer
|
|
32
|
+
* by tagging it with `CoreTags.LIFE_CYCLE_OBSERVER`.
|
|
33
|
+
*
|
|
34
|
+
* @param binding - Binding object
|
|
35
|
+
*/
|
|
36
|
+
export declare function asLifeCycleObserver<T = unknown>(binding: Binding<T>): Binding<T>;
|
|
37
|
+
/**
|
|
38
|
+
* Find all life cycle observer bindings. By default, a binding tagged with
|
|
39
|
+
* `CoreTags.LIFE_CYCLE_OBSERVER`. It's used as `BindingFilter`.
|
|
40
|
+
*/
|
|
41
|
+
export declare const lifeCycleObserverFilter: BindingTagFilter;
|
|
42
|
+
/**
|
|
43
|
+
* Sugar decorator to mark a class as life cycle observer
|
|
44
|
+
* @param group - Optional observer group name
|
|
45
|
+
* @param specs - Optional bindings specs
|
|
46
|
+
*/
|
|
47
|
+
export declare function lifeCycleObserver(group?: string, ...specs: BindingSpec[]): ClassDecorator;
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
// Copyright IBM Corp. and LoopBack contributors 2018,2020. All Rights Reserved.
|
|
3
|
+
// Node module: @loopback/core
|
|
4
|
+
// This file is licensed under the MIT License.
|
|
5
|
+
// License text available at https://opensource.org/licenses/MIT
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.lifeCycleObserver = exports.lifeCycleObserverFilter = exports.asLifeCycleObserver = exports.isLifeCycleObserverClass = exports.isLifeCycleObserver = void 0;
|
|
8
|
+
const context_1 = require("@loopback/context");
|
|
9
|
+
const keys_1 = require("./keys");
|
|
10
|
+
const lifeCycleMethods = ['init', 'start', 'stop'];
|
|
11
|
+
/**
|
|
12
|
+
* Test if an object implements LifeCycleObserver
|
|
13
|
+
* @param obj - An object
|
|
14
|
+
*/
|
|
15
|
+
function isLifeCycleObserver(obj) {
|
|
16
|
+
const candidate = obj;
|
|
17
|
+
return lifeCycleMethods.some(m => typeof candidate[m] === 'function');
|
|
18
|
+
}
|
|
19
|
+
exports.isLifeCycleObserver = isLifeCycleObserver;
|
|
20
|
+
/**
|
|
21
|
+
* Test if a class implements LifeCycleObserver
|
|
22
|
+
* @param ctor - A class
|
|
23
|
+
*/
|
|
24
|
+
function isLifeCycleObserverClass(ctor) {
|
|
25
|
+
return ctor.prototype && isLifeCycleObserver(ctor.prototype);
|
|
26
|
+
}
|
|
27
|
+
exports.isLifeCycleObserverClass = isLifeCycleObserverClass;
|
|
28
|
+
/**
|
|
29
|
+
* A `BindingTemplate` function to configure the binding as life cycle observer
|
|
30
|
+
* by tagging it with `CoreTags.LIFE_CYCLE_OBSERVER`.
|
|
31
|
+
*
|
|
32
|
+
* @param binding - Binding object
|
|
33
|
+
*/
|
|
34
|
+
function asLifeCycleObserver(binding) {
|
|
35
|
+
return binding.tag(keys_1.CoreTags.LIFE_CYCLE_OBSERVER);
|
|
36
|
+
}
|
|
37
|
+
exports.asLifeCycleObserver = asLifeCycleObserver;
|
|
38
|
+
/**
|
|
39
|
+
* Find all life cycle observer bindings. By default, a binding tagged with
|
|
40
|
+
* `CoreTags.LIFE_CYCLE_OBSERVER`. It's used as `BindingFilter`.
|
|
41
|
+
*/
|
|
42
|
+
exports.lifeCycleObserverFilter = (0, context_1.filterByTag)(keys_1.CoreTags.LIFE_CYCLE_OBSERVER);
|
|
43
|
+
/**
|
|
44
|
+
* Sugar decorator to mark a class as life cycle observer
|
|
45
|
+
* @param group - Optional observer group name
|
|
46
|
+
* @param specs - Optional bindings specs
|
|
47
|
+
*/
|
|
48
|
+
function lifeCycleObserver(group = '', ...specs) {
|
|
49
|
+
return (0, context_1.injectable)(asLifeCycleObserver, {
|
|
50
|
+
tags: {
|
|
51
|
+
[keys_1.CoreTags.LIFE_CYCLE_OBSERVER_GROUP]: group,
|
|
52
|
+
},
|
|
53
|
+
}, ...specs);
|
|
54
|
+
}
|
|
55
|
+
exports.lifeCycleObserver = lifeCycleObserver;
|
|
56
|
+
//# sourceMappingURL=lifecycle.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"lifecycle.js","sourceRoot":"","sources":["../src/lifecycle.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;AAEhE,+CAQ2B;AAC3B,iCAAgC;AAqBhC,MAAM,gBAAgB,GAAgC,CAAC,MAAM,EAAE,OAAO,EAAE,MAAM,CAAC,CAAC;AAEhF;;;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,IAAA,qBAAW,EAClE,eAAQ,CAAC,mBAAmB,CAC7B,CAAC;AAEF;;;;GAIG;AACH,SAAgB,iBAAiB,CAAC,KAAK,GAAG,EAAE,EAAE,GAAG,KAAoB;IACnE,OAAO,IAAA,oBAAU,EACf,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,60 @@
|
|
|
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
|
+
* // eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
|
24
|
+
* // @ts-ignore
|
|
25
|
+
* (this as unknown as {YourBaseClass}).protectedMember
|
|
26
|
+
* ```
|
|
27
|
+
*
|
|
28
|
+
* The directive `@ts-ignore` suppresses compiler error about accessing
|
|
29
|
+
* a protected member from outside. Unfortunately, it also disables other
|
|
30
|
+
* compile-time checks (e.g. to verify that a protected method was invoked
|
|
31
|
+
* with correct arguments, and so on). This is the same behavior you
|
|
32
|
+
* would get by using `Constructor<any>` instead of `MixinTarget<Application>`.
|
|
33
|
+
* The major improvement is that TypeScript can still infer the return
|
|
34
|
+
* type of the protected member, therefore `any` is NOT introduced to subsequent
|
|
35
|
+
* code.
|
|
36
|
+
*
|
|
37
|
+
* TypeScript also does not allow mixin class to overwrite a method inherited
|
|
38
|
+
* from a mapped type, see https://github.com/microsoft/TypeScript/issues/38496
|
|
39
|
+
* As a workaround, use `@ts-ignore` to disable the error.
|
|
40
|
+
*
|
|
41
|
+
* ```ts
|
|
42
|
+
* export function RepositoryMixin<T extends MixinTarget<Application>>(
|
|
43
|
+
* superClass: T,
|
|
44
|
+
* ) {
|
|
45
|
+
* return class extends superClass {
|
|
46
|
+
* // @ts-ignore
|
|
47
|
+
* public component<C extends Component = Component>(
|
|
48
|
+
* componentCtor: Constructor<C>,
|
|
49
|
+
* nameOrOptions?: string | BindingFromClassOptions,
|
|
50
|
+
* ) {
|
|
51
|
+
* const binding = super.component(componentCtor, nameOrOptions);
|
|
52
|
+
* // ...
|
|
53
|
+
* return binding;
|
|
54
|
+
* }
|
|
55
|
+
* }
|
|
56
|
+
* ```
|
|
57
|
+
*/
|
|
58
|
+
export declare type MixinTarget<T extends object> = Constructor<{
|
|
59
|
+
[P in keyof T]: T[P];
|
|
60
|
+
}>;
|
|
@@ -1,8 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright IBM Corp.
|
|
2
|
+
// Copyright IBM Corp. and LoopBack contributors 2020. All Rights Reserved.
|
|
3
3
|
// Node module: @loopback/core
|
|
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
|
-
|
|
8
|
-
//# sourceMappingURL=internal-types.js.map
|
|
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,2EAA2E;AAC3E,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE"}
|
package/dist/server.d.ts
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { LifeCycleObserver } from './lifecycle';
|
|
2
|
+
/**
|
|
3
|
+
* Defines the requirements to implement a Server for LoopBack applications:
|
|
4
|
+
* start() : Promise<void>
|
|
5
|
+
* stop() : Promise<void>
|
|
6
|
+
* It is recommended that each Server implementation creates its own child
|
|
7
|
+
* Context, which inherits from the parent Application context. This way,
|
|
8
|
+
* any Server-specific bindings will remain local to the Server instance,
|
|
9
|
+
* and will avoid polluting its parent module scope.
|
|
10
|
+
*/
|
|
11
|
+
export interface Server extends LifeCycleObserver {
|
|
12
|
+
/**
|
|
13
|
+
* Tells whether the server is listening for connections or not
|
|
14
|
+
*/
|
|
15
|
+
readonly listening: boolean;
|
|
16
|
+
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
-
// Copyright IBM Corp. 2017. All Rights Reserved.
|
|
2
|
+
// Copyright IBM Corp. and LoopBack contributors 2017,2020. All Rights Reserved.
|
|
3
3
|
// Node module: @loopback/core
|
|
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
|
-
//# sourceMappingURL=
|
|
7
|
+
//# sourceMappingURL=server.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"server.js","sourceRoot":"","sources":["../src/server.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE"}
|