@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.
Files changed (121) hide show
  1. package/LICENSE +25 -0
  2. package/README.md +77 -2
  3. package/dist/application.d.ts +341 -0
  4. package/dist/application.js +554 -0
  5. package/dist/application.js.map +1 -0
  6. package/dist/component.d.ts +80 -0
  7. package/dist/component.js +59 -0
  8. package/dist/component.js.map +1 -0
  9. package/dist/extension-point.d.ts +121 -0
  10. package/dist/extension-point.js +227 -0
  11. package/dist/extension-point.js.map +1 -0
  12. package/dist/index.d.ts +21 -0
  13. package/dist/index.js +31 -0
  14. package/dist/index.js.map +1 -0
  15. package/dist/keys.d.ts +97 -0
  16. package/dist/keys.js +109 -0
  17. package/dist/keys.js.map +1 -0
  18. package/dist/lifecycle-registry.d.ts +91 -0
  19. package/dist/lifecycle-registry.js +191 -0
  20. package/dist/lifecycle-registry.js.map +1 -0
  21. package/dist/lifecycle.d.ts +47 -0
  22. package/dist/lifecycle.js +56 -0
  23. package/dist/lifecycle.js.map +1 -0
  24. package/dist/mixin-target.d.ts +60 -0
  25. package/{lib6/internal-types.js → dist/mixin-target.js} +2 -3
  26. package/dist/mixin-target.js.map +1 -0
  27. package/dist/server.d.ts +16 -0
  28. package/{lib6/component.js → dist/server.js} +2 -2
  29. package/dist/server.js.map +1 -0
  30. package/dist/service.d.ts +63 -0
  31. package/dist/service.js +151 -0
  32. package/dist/service.js.map +1 -0
  33. package/package.json +39 -37
  34. package/src/application.ts +719 -0
  35. package/src/component.ts +155 -0
  36. package/src/extension-point.ts +312 -0
  37. package/src/index.ts +29 -0
  38. package/src/keys.ts +144 -0
  39. package/src/lifecycle-registry.ts +268 -0
  40. package/src/lifecycle.ts +90 -0
  41. package/src/mixin-target.ts +69 -0
  42. package/src/server.ts +22 -0
  43. package/src/service.ts +211 -0
  44. package/index.d.ts +0 -6
  45. package/index.js +0 -9
  46. package/lib/application.d.ts +0 -54
  47. package/lib/application.js +0 -81
  48. package/lib/application.js.map +0 -1
  49. package/lib/component.d.ts +0 -2
  50. package/lib/component.js +0 -7
  51. package/lib/component.js.map +0 -1
  52. package/lib/http-handler.d.ts +0 -16
  53. package/lib/http-handler.js +0 -62
  54. package/lib/http-handler.js.map +0 -1
  55. package/lib/index.d.ts +0 -17
  56. package/lib/index.js +0 -37
  57. package/lib/index.js.map +0 -1
  58. package/lib/internal-types.d.ts +0 -29
  59. package/lib/internal-types.js +0 -8
  60. package/lib/internal-types.js.map +0 -1
  61. package/lib/keys.d.ts +0 -7
  62. package/lib/keys.js +0 -16
  63. package/lib/keys.js.map +0 -1
  64. package/lib/parser.d.ts +0 -11
  65. package/lib/parser.js +0 -96
  66. package/lib/parser.js.map +0 -1
  67. package/lib/promisify.d.ts +0 -3
  68. package/lib/promisify.js +0 -34
  69. package/lib/promisify.js.map +0 -1
  70. package/lib/router/metadata.d.ts +0 -12
  71. package/lib/router/metadata.js +0 -30
  72. package/lib/router/metadata.js.map +0 -1
  73. package/lib/router/routing-table.d.ts +0 -16
  74. package/lib/router/routing-table.js +0 -97
  75. package/lib/router/routing-table.js.map +0 -1
  76. package/lib/sequence.d.ts +0 -55
  77. package/lib/sequence.js +0 -99
  78. package/lib/sequence.js.map +0 -1
  79. package/lib/server.d.ts +0 -23
  80. package/lib/server.js +0 -64
  81. package/lib/server.js.map +0 -1
  82. package/lib/writer.d.ts +0 -11
  83. package/lib/writer.js +0 -34
  84. package/lib/writer.js.map +0 -1
  85. package/lib6/application.d.ts +0 -54
  86. package/lib6/application.js +0 -81
  87. package/lib6/application.js.map +0 -1
  88. package/lib6/component.d.ts +0 -2
  89. package/lib6/component.js.map +0 -1
  90. package/lib6/http-handler.d.ts +0 -16
  91. package/lib6/http-handler.js +0 -72
  92. package/lib6/http-handler.js.map +0 -1
  93. package/lib6/index.d.ts +0 -17
  94. package/lib6/index.js +0 -37
  95. package/lib6/index.js.map +0 -1
  96. package/lib6/internal-types.d.ts +0 -29
  97. package/lib6/internal-types.js.map +0 -1
  98. package/lib6/keys.d.ts +0 -7
  99. package/lib6/keys.js +0 -16
  100. package/lib6/keys.js.map +0 -1
  101. package/lib6/parser.d.ts +0 -11
  102. package/lib6/parser.js +0 -106
  103. package/lib6/parser.js.map +0 -1
  104. package/lib6/promisify.d.ts +0 -3
  105. package/lib6/promisify.js +0 -34
  106. package/lib6/promisify.js.map +0 -1
  107. package/lib6/router/metadata.d.ts +0 -12
  108. package/lib6/router/metadata.js +0 -30
  109. package/lib6/router/metadata.js.map +0 -1
  110. package/lib6/router/routing-table.d.ts +0 -16
  111. package/lib6/router/routing-table.js +0 -97
  112. package/lib6/router/routing-table.js.map +0 -1
  113. package/lib6/sequence.d.ts +0 -55
  114. package/lib6/sequence.js +0 -109
  115. package/lib6/sequence.js.map +0 -1
  116. package/lib6/server.d.ts +0 -23
  117. package/lib6/server.js +0 -74
  118. package/lib6/server.js.map +0 -1
  119. package/lib6/writer.d.ts +0 -11
  120. package/lib6/writer.js +0 -34
  121. package/lib6/writer.js.map +0 -1
@@ -0,0 +1,554 @@
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.Application = void 0;
8
+ const tslib_1 = require("tslib");
9
+ const context_1 = require("@loopback/context");
10
+ const assert_1 = tslib_1.__importDefault(require("assert"));
11
+ const debug_1 = tslib_1.__importDefault(require("debug"));
12
+ const events_1 = require("events");
13
+ const component_1 = require("./component");
14
+ const keys_1 = require("./keys");
15
+ const lifecycle_1 = require("./lifecycle");
16
+ const lifecycle_registry_1 = require("./lifecycle-registry");
17
+ const service_1 = require("./service");
18
+ const debug = (0, debug_1.default)('loopback:core:application');
19
+ const debugShutdown = (0, debug_1.default)('loopback:core:application:shutdown');
20
+ const debugWarning = (0, debug_1.default)('loopback:core:application:warning');
21
+ /**
22
+ * A helper function to build constructor args for `Context`
23
+ * @param configOrParent - Application config or parent context
24
+ * @param parent - Parent context if the first arg is application config
25
+ */
26
+ function buildConstructorArgs(configOrParent, parent) {
27
+ let name;
28
+ let parentCtx;
29
+ if (configOrParent instanceof context_1.Context) {
30
+ parentCtx = configOrParent;
31
+ name = undefined;
32
+ }
33
+ else {
34
+ parentCtx = parent;
35
+ name = configOrParent === null || configOrParent === void 0 ? void 0 : configOrParent.name;
36
+ }
37
+ return [parentCtx, name];
38
+ }
39
+ /**
40
+ * Application is the container for various types of artifacts, such as
41
+ * components, servers, controllers, repositories, datasources, connectors,
42
+ * and models.
43
+ */
44
+ class Application extends context_1.Context {
45
+ constructor(configOrParent, parent) {
46
+ // super() has to be first statement for a constructor
47
+ super(...buildConstructorArgs(configOrParent, parent));
48
+ /**
49
+ * A flag to indicate that the application is being shut down
50
+ */
51
+ this._isShuttingDown = false;
52
+ this._initialized = false;
53
+ /**
54
+ * State of the application
55
+ */
56
+ this._state = 'created';
57
+ this.scope = context_1.BindingScope.APPLICATION;
58
+ this.options =
59
+ configOrParent instanceof context_1.Context ? {} : configOrParent !== null && configOrParent !== void 0 ? configOrParent : {};
60
+ // Configure debug
61
+ this._debug = debug;
62
+ // Bind the life cycle observer registry
63
+ this.bind(keys_1.CoreBindings.LIFE_CYCLE_OBSERVER_REGISTRY)
64
+ .toClass(lifecycle_registry_1.LifeCycleObserverRegistry)
65
+ .inScope(context_1.BindingScope.SINGLETON);
66
+ // Bind to self to allow injection of application context in other modules.
67
+ this.bind(keys_1.CoreBindings.APPLICATION_INSTANCE).to(this);
68
+ // Make options available to other modules as well.
69
+ this.bind(keys_1.CoreBindings.APPLICATION_CONFIG).to(this.options);
70
+ // Also configure the application instance to allow `@config`
71
+ this.configure(keys_1.CoreBindings.APPLICATION_INSTANCE).toAlias(keys_1.CoreBindings.APPLICATION_CONFIG);
72
+ this._shutdownOptions = { signals: ['SIGTERM'], ...this.options.shutdown };
73
+ }
74
+ /**
75
+ * Get the state of the application. The initial state is `created` and it can
76
+ * transition as follows by `start` and `stop`:
77
+ *
78
+ * 1. start
79
+ * - !started -> starting -> started
80
+ * - started -> started (no-op)
81
+ * 2. stop
82
+ * - (started | initialized) -> stopping -> stopped
83
+ * - ! (started || initialized) -> stopped (no-op)
84
+ *
85
+ * Two types of states are expected:
86
+ * - stable, such as `started` and `stopped`
87
+ * - in process, such as `booting` and `starting`
88
+ *
89
+ * Operations such as `start` and `stop` can only be called at a stable state.
90
+ * The logic should immediately set the state to a new one indicating work in
91
+ * process, such as `starting` and `stopping`.
92
+ */
93
+ get state() {
94
+ return this._state;
95
+ }
96
+ /**
97
+ * Register a controller class with this application.
98
+ *
99
+ * @param controllerCtor - The controller class
100
+ * (constructor function).
101
+ * @param name - Optional controller name, default to the class name
102
+ * @returns The newly created binding, you can use the reference to
103
+ * further modify the binding, e.g. lock the value to prevent further
104
+ * modifications.
105
+ *
106
+ * @example
107
+ * ```ts
108
+ * class MyController {
109
+ * }
110
+ * app.controller(MyController).lock();
111
+ * ```
112
+ */
113
+ controller(controllerCtor, nameOrOptions) {
114
+ this.debug('Adding controller %s', nameOrOptions !== null && nameOrOptions !== void 0 ? nameOrOptions : controllerCtor.name);
115
+ const binding = (0, context_1.createBindingFromClass)(controllerCtor, {
116
+ namespace: keys_1.CoreBindings.CONTROLLERS,
117
+ type: keys_1.CoreTags.CONTROLLER,
118
+ defaultScope: context_1.BindingScope.TRANSIENT,
119
+ ...toOptions(nameOrOptions),
120
+ });
121
+ this.add(binding);
122
+ return binding;
123
+ }
124
+ /**
125
+ * Bind a Server constructor to the Application's master context.
126
+ * Each server constructor added in this way must provide a unique prefix
127
+ * to prevent binding overlap.
128
+ *
129
+ * @example
130
+ * ```ts
131
+ * app.server(RestServer);
132
+ * // This server constructor will be bound under "servers.RestServer".
133
+ * app.server(RestServer, "v1API");
134
+ * // This server instance will be bound under "servers.v1API".
135
+ * ```
136
+ *
137
+ * @param server - The server constructor.
138
+ * @param nameOrOptions - Optional override for name or options.
139
+ * @returns Binding for the server class
140
+ *
141
+ */
142
+ server(ctor, nameOrOptions) {
143
+ this.debug('Adding server %s', nameOrOptions !== null && nameOrOptions !== void 0 ? nameOrOptions : ctor.name);
144
+ const binding = (0, context_1.createBindingFromClass)(ctor, {
145
+ namespace: keys_1.CoreBindings.SERVERS,
146
+ type: keys_1.CoreTags.SERVER,
147
+ defaultScope: context_1.BindingScope.SINGLETON,
148
+ ...toOptions(nameOrOptions),
149
+ }).apply(lifecycle_1.asLifeCycleObserver);
150
+ this.add(binding);
151
+ return binding;
152
+ }
153
+ /**
154
+ * Bind an array of Server constructors to the Application's master
155
+ * context.
156
+ * Each server added in this way will automatically be named based on the
157
+ * class constructor name with the "servers." prefix.
158
+ *
159
+ * @remarks
160
+ * If you wish to control the binding keys for particular server instances,
161
+ * use the app.server function instead.
162
+ * ```ts
163
+ * app.servers([
164
+ * RestServer,
165
+ * GRPCServer,
166
+ * ]);
167
+ * // Creates a binding for "servers.RestServer" and a binding for
168
+ * // "servers.GRPCServer";
169
+ * ```
170
+ *
171
+ * @param ctors - An array of Server constructors.
172
+ * @returns An array of bindings for the registered server classes
173
+ *
174
+ */
175
+ servers(ctors) {
176
+ return ctors.map(ctor => this.server(ctor));
177
+ }
178
+ /**
179
+ * Retrieve the singleton instance for a bound server.
180
+ *
181
+ * @typeParam T - Server type
182
+ * @param ctor - The constructor that was used to make the
183
+ * binding.
184
+ * @returns A Promise of server instance
185
+ *
186
+ */
187
+ async getServer(target) {
188
+ let key;
189
+ // instanceof check not reliable for string.
190
+ if (typeof target === 'string') {
191
+ key = `${keys_1.CoreBindings.SERVERS}.${target}`;
192
+ }
193
+ else {
194
+ const ctor = target;
195
+ key = `${keys_1.CoreBindings.SERVERS}.${ctor.name}`;
196
+ }
197
+ return this.get(key);
198
+ }
199
+ /**
200
+ * Assert there is no other operation is in progress, i.e., the state is not
201
+ * `*ing`, such as `starting` or `stopping`.
202
+ *
203
+ * @param op - The operation name, such as 'boot', 'start', or 'stop'
204
+ */
205
+ assertNotInProcess(op) {
206
+ (0, assert_1.default)(!this._state.endsWith('ing'), `Cannot ${op} the application as it is ${this._state}.`);
207
+ }
208
+ /**
209
+ * Assert current state of the application to be one of the expected values
210
+ * @param op - The operation name, such as 'boot', 'start', or 'stop'
211
+ * @param states - Valid states
212
+ */
213
+ assertInStates(op, ...states) {
214
+ (0, assert_1.default)(states.includes(this._state), `Cannot ${op} the application as it is ${this._state}. Valid states are ${states}.`);
215
+ }
216
+ /**
217
+ * Transition the application to a new state and emit an event
218
+ * @param state - The new state
219
+ */
220
+ setState(state) {
221
+ const oldState = this._state;
222
+ this._state = state;
223
+ if (oldState !== state) {
224
+ this.emit('stateChanged', { from: oldState, to: this._state });
225
+ this.emit(state);
226
+ }
227
+ }
228
+ async awaitState(state) {
229
+ await (0, events_1.once)(this, state);
230
+ }
231
+ /**
232
+ * Initialize the application, and all of its registered observers. The
233
+ * application state is checked to ensure the integrity of `initialize`.
234
+ *
235
+ * If the application is already initialized, no operation is performed.
236
+ *
237
+ * This method is automatically invoked by `start()` if the application is not
238
+ * initialized.
239
+ */
240
+ async init() {
241
+ if (this._initialized)
242
+ return;
243
+ if (this._state === 'initializing')
244
+ return this.awaitState('initialized');
245
+ this.assertNotInProcess('initialize');
246
+ this.setState('initializing');
247
+ const registry = await this.getLifeCycleObserverRegistry();
248
+ await registry.init();
249
+ this._initialized = true;
250
+ this.setState('initialized');
251
+ }
252
+ /**
253
+ * Register a function to be called when the application initializes.
254
+ *
255
+ * This is a shortcut for adding a binding for a LifeCycleObserver
256
+ * implementing a `init()` method.
257
+ *
258
+ * @param fn The function to invoke, it can be synchronous (returning `void`)
259
+ * or asynchronous (returning `Promise<void>`).
260
+ * @returns The LifeCycleObserver binding created.
261
+ */
262
+ onInit(fn) {
263
+ const key = [
264
+ keys_1.CoreBindings.LIFE_CYCLE_OBSERVERS,
265
+ fn.name || '<onInit>',
266
+ (0, context_1.generateUniqueId)(),
267
+ ].join('.');
268
+ return this.bind(key)
269
+ .to({ init: fn })
270
+ .apply(lifecycle_1.asLifeCycleObserver);
271
+ }
272
+ /**
273
+ * Start the application, and all of its registered observers. The application
274
+ * state is checked to ensure the integrity of `start`.
275
+ *
276
+ * If the application is not initialized, it calls first `init()` to
277
+ * initialize the application. This only happens if `start()` is called for
278
+ * the first time.
279
+ *
280
+ * If the application is already started, no operation is performed.
281
+ */
282
+ async start() {
283
+ if (!this._initialized)
284
+ await this.init();
285
+ if (this._state === 'starting')
286
+ return this.awaitState('started');
287
+ this.assertNotInProcess('start');
288
+ // No-op if it's started
289
+ if (this._state === 'started')
290
+ return;
291
+ this.setState('starting');
292
+ this.setupShutdown();
293
+ const registry = await this.getLifeCycleObserverRegistry();
294
+ await registry.start();
295
+ this.setState('started');
296
+ }
297
+ /**
298
+ * Register a function to be called when the application starts.
299
+ *
300
+ * This is a shortcut for adding a binding for a LifeCycleObserver
301
+ * implementing a `start()` method.
302
+ *
303
+ * @param fn The function to invoke, it can be synchronous (returning `void`)
304
+ * or asynchronous (returning `Promise<void>`).
305
+ * @returns The LifeCycleObserver binding created.
306
+ */
307
+ onStart(fn) {
308
+ const key = [
309
+ keys_1.CoreBindings.LIFE_CYCLE_OBSERVERS,
310
+ fn.name || '<onStart>',
311
+ (0, context_1.generateUniqueId)(),
312
+ ].join('.');
313
+ return this.bind(key)
314
+ .to({ start: fn })
315
+ .apply(lifecycle_1.asLifeCycleObserver);
316
+ }
317
+ /**
318
+ * Stop the application instance and all of its registered observers. The
319
+ * application state is checked to ensure the integrity of `stop`.
320
+ *
321
+ * If the application is already stopped or not started, no operation is
322
+ * performed.
323
+ */
324
+ async stop() {
325
+ if (this._state === 'stopping')
326
+ return this.awaitState('stopped');
327
+ this.assertNotInProcess('stop');
328
+ // No-op if it's created or stopped
329
+ if (this._state !== 'started' && this._state !== 'initialized')
330
+ return;
331
+ this.setState('stopping');
332
+ if (!this._isShuttingDown) {
333
+ // Explicit stop is called, let's remove signal listeners to avoid
334
+ // memory leak and max listener warning
335
+ this.removeSignalListener();
336
+ }
337
+ const registry = await this.getLifeCycleObserverRegistry();
338
+ await registry.stop();
339
+ this.setState('stopped');
340
+ }
341
+ /**
342
+ * Register a function to be called when the application starts.
343
+ *
344
+ * This is a shortcut for adding a binding for a LifeCycleObserver
345
+ * implementing a `start()` method.
346
+ *
347
+ * @param fn The function to invoke, it can be synchronous (returning `void`)
348
+ * or asynchronous (returning `Promise<void>`).
349
+ * @returns The LifeCycleObserver binding created.
350
+ */
351
+ onStop(fn) {
352
+ const key = [
353
+ keys_1.CoreBindings.LIFE_CYCLE_OBSERVERS,
354
+ fn.name || '<onStop>',
355
+ (0, context_1.generateUniqueId)(),
356
+ ].join('.');
357
+ return this.bind(key)
358
+ .to({ stop: fn })
359
+ .apply(lifecycle_1.asLifeCycleObserver);
360
+ }
361
+ async getLifeCycleObserverRegistry() {
362
+ return this.get(keys_1.CoreBindings.LIFE_CYCLE_OBSERVER_REGISTRY);
363
+ }
364
+ /**
365
+ * Add a component to this application and register extensions such as
366
+ * controllers, providers, and servers from the component.
367
+ *
368
+ * @param componentCtor - The component class to add.
369
+ * @param nameOrOptions - Optional component name or options, default to the
370
+ * class name
371
+ *
372
+ * @example
373
+ * ```ts
374
+ *
375
+ * export class ProductComponent {
376
+ * controllers = [ProductController];
377
+ * repositories = [ProductRepo, UserRepo];
378
+ * providers = {
379
+ * [AUTHENTICATION_STRATEGY]: AuthStrategy,
380
+ * [AUTHORIZATION_ROLE]: Role,
381
+ * };
382
+ * };
383
+ *
384
+ * app.component(ProductComponent);
385
+ * ```
386
+ */
387
+ component(componentCtor, nameOrOptions) {
388
+ this.debug('Adding component: %s', nameOrOptions !== null && nameOrOptions !== void 0 ? nameOrOptions : componentCtor.name);
389
+ const binding = (0, context_1.createBindingFromClass)(componentCtor, {
390
+ namespace: keys_1.CoreBindings.COMPONENTS,
391
+ type: keys_1.CoreTags.COMPONENT,
392
+ defaultScope: context_1.BindingScope.SINGLETON,
393
+ ...toOptions(nameOrOptions),
394
+ });
395
+ if ((0, lifecycle_1.isLifeCycleObserverClass)(componentCtor)) {
396
+ binding.apply(lifecycle_1.asLifeCycleObserver);
397
+ }
398
+ this.add(binding);
399
+ // Assuming components can be synchronously instantiated
400
+ const instance = this.getSync(binding.key);
401
+ (0, component_1.mountComponent)(this, instance);
402
+ return binding;
403
+ }
404
+ /**
405
+ * Set application metadata. `@loopback/boot` calls this method to populate
406
+ * the metadata from `package.json`.
407
+ *
408
+ * @param metadata - Application metadata
409
+ */
410
+ setMetadata(metadata) {
411
+ this.bind(keys_1.CoreBindings.APPLICATION_METADATA).to(metadata);
412
+ }
413
+ /**
414
+ * Register a life cycle observer class
415
+ * @param ctor - A class implements LifeCycleObserver
416
+ * @param nameOrOptions - Optional name or options for the life cycle observer
417
+ */
418
+ lifeCycleObserver(ctor, nameOrOptions) {
419
+ this.debug('Adding life cycle observer %s', nameOrOptions !== null && nameOrOptions !== void 0 ? nameOrOptions : ctor.name);
420
+ const binding = (0, context_1.createBindingFromClass)(ctor, {
421
+ namespace: keys_1.CoreBindings.LIFE_CYCLE_OBSERVERS,
422
+ type: keys_1.CoreTags.LIFE_CYCLE_OBSERVER,
423
+ defaultScope: context_1.BindingScope.SINGLETON,
424
+ ...toOptions(nameOrOptions),
425
+ }).apply(lifecycle_1.asLifeCycleObserver);
426
+ this.add(binding);
427
+ return binding;
428
+ }
429
+ /**
430
+ * Add a service to this application.
431
+ *
432
+ * @param cls - The service or provider class
433
+ *
434
+ * @example
435
+ *
436
+ * ```ts
437
+ * // Define a class to be bound via ctx.toClass()
438
+ * @injectable({scope: BindingScope.SINGLETON})
439
+ * export class LogService {
440
+ * log(msg: string) {
441
+ * console.log(msg);
442
+ * }
443
+ * }
444
+ *
445
+ * // Define a class to be bound via ctx.toProvider()
446
+ * import {v4 as uuidv4} from 'uuid';
447
+ * export class UuidProvider implements Provider<string> {
448
+ * value() {
449
+ * return uuidv4();
450
+ * }
451
+ * }
452
+ *
453
+ * // Register the local services
454
+ * app.service(LogService);
455
+ * app.service(UuidProvider, 'uuid');
456
+ *
457
+ * export class MyController {
458
+ * constructor(
459
+ * @inject('services.uuid') private uuid: string,
460
+ * @inject('services.LogService') private log: LogService,
461
+ * ) {
462
+ * }
463
+ *
464
+ * greet(name: string) {
465
+ * this.log(`Greet request ${this.uuid} received: ${name}`);
466
+ * return `${this.uuid}: ${name}`;
467
+ * }
468
+ * }
469
+ * ```
470
+ */
471
+ service(cls, nameOrOptions) {
472
+ const options = toOptions(nameOrOptions);
473
+ const binding = (0, service_1.createServiceBinding)(cls, options);
474
+ this.add(binding);
475
+ return binding;
476
+ }
477
+ /**
478
+ * Register an interceptor
479
+ * @param interceptor - An interceptor function or provider class
480
+ * @param nameOrOptions - Binding name or options
481
+ */
482
+ interceptor(interceptor, nameOrOptions) {
483
+ const options = toOptions(nameOrOptions);
484
+ return (0, context_1.registerInterceptor)(this, interceptor, options);
485
+ }
486
+ /**
487
+ * Set up signals that are captured to shutdown the application
488
+ */
489
+ setupShutdown() {
490
+ if (this._signalListener != null) {
491
+ this.registerSignalListener();
492
+ return this._signalListener;
493
+ }
494
+ const gracePeriod = this._shutdownOptions.gracePeriod;
495
+ this._signalListener = async (signal) => {
496
+ const kill = () => {
497
+ this.removeSignalListener();
498
+ process.kill(process.pid, signal);
499
+ };
500
+ debugShutdown('[%s] Signal %s received for process %d', this.name, signal, process.pid);
501
+ if (!this._isShuttingDown) {
502
+ this._isShuttingDown = true;
503
+ let timer;
504
+ if (typeof gracePeriod === 'number' && !isNaN(gracePeriod)) {
505
+ timer = setTimeout(kill, gracePeriod);
506
+ }
507
+ try {
508
+ await this.stop();
509
+ }
510
+ finally {
511
+ if (timer != null)
512
+ clearTimeout(timer);
513
+ kill();
514
+ }
515
+ }
516
+ };
517
+ this.registerSignalListener();
518
+ return this._signalListener;
519
+ }
520
+ registerSignalListener() {
521
+ const { signals = [] } = this._shutdownOptions;
522
+ debugShutdown('[%s] Registering signal listeners on the process %d', this.name, process.pid, signals);
523
+ signals.forEach(sig => {
524
+ if (process.getMaxListeners() <= process.listenerCount(sig)) {
525
+ if (debugWarning.enabled) {
526
+ debugWarning('[%s] %d %s listeners are added to process %d', this.name, process.listenerCount(sig), sig, process.pid, new Error('MaxListenersExceededWarning'));
527
+ }
528
+ }
529
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
530
+ process.on(sig, this._signalListener);
531
+ });
532
+ }
533
+ removeSignalListener() {
534
+ if (this._signalListener == null)
535
+ return;
536
+ const { signals = [] } = this._shutdownOptions;
537
+ debugShutdown('[%s] Removing signal listeners on the process %d', this.name, process.pid, signals);
538
+ signals.forEach(sig =>
539
+ // eslint-disable-next-line @typescript-eslint/no-misused-promises
540
+ process.removeListener(sig, this._signalListener));
541
+ }
542
+ }
543
+ exports.Application = Application;
544
+ /**
545
+ * Normalize name or options to `BindingFromClassOptions`
546
+ * @param nameOrOptions - Name or options for binding from class
547
+ */
548
+ function toOptions(nameOrOptions) {
549
+ if (typeof nameOrOptions === 'string') {
550
+ return { name: nameOrOptions };
551
+ }
552
+ return nameOrOptions !== null && nameOrOptions !== void 0 ? nameOrOptions : {};
553
+ }
554
+ //# sourceMappingURL=application.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"application.js","sourceRoot":"","sources":["../src/application.ts"],"names":[],"mappings":";AAAA,gFAAgF;AAChF,8BAA8B;AAC9B,+CAA+C;AAC/C,gEAAgE;;;;AAEhE,+CAe2B;AAC3B,4DAA4B;AAC5B,0DAAiC;AACjC,mCAA4B;AAC5B,2CAAsD;AACtD,iCAA8C;AAC9C,2CAIqB;AACrB,6DAA+D;AAE/D,uCAA+D;AAC/D,MAAM,KAAK,GAAG,IAAA,eAAY,EAAC,2BAA2B,CAAC,CAAC;AACxD,MAAM,aAAa,GAAG,IAAA,eAAY,EAAC,oCAAoC,CAAC,CAAC;AACzE,MAAM,YAAY,GAAG,IAAA,eAAY,EAAC,mCAAmC,CAAC,CAAC;AAEvE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D,CAAC;IACJ,CAAC;CACF;AA9kBD,kCA8kBC;AAED;;;GAGG;AACH,SAAS,SAAS,CAAC,aAAgD;IACjE,IAAI,OAAO,aAAa,KAAK,QAAQ,EAAE;QACrC,OAAO,EAAC,IAAI,EAAE,aAAa,EAAC,CAAC;KAC9B;IACD,OAAO,aAAa,aAAb,aAAa,cAAb,aAAa,GAAI,EAAE,CAAC;AAC7B,CAAC"}
@@ -0,0 +1,80 @@
1
+ import { Binding, BoundValue, Constructor, Provider } from '@loopback/context';
2
+ import { Application, ControllerClass, ServiceOrProviderClass } from './application';
3
+ import { LifeCycleObserver } from './lifecycle';
4
+ import { Server } from './server';
5
+ /**
6
+ * A map of provider classes to be bound to a context
7
+ */
8
+ export interface ProviderMap {
9
+ [key: string]: Constructor<Provider<BoundValue>>;
10
+ }
11
+ /**
12
+ * A map of classes to be bound to a context
13
+ */
14
+ export interface ClassMap {
15
+ [key: string]: Constructor<BoundValue>;
16
+ }
17
+ /**
18
+ * A component declares a set of artifacts so that they can be contributed to
19
+ * an application as a group
20
+ */
21
+ export interface Component {
22
+ /**
23
+ * An array of controller classes
24
+ */
25
+ controllers?: ControllerClass[];
26
+ /**
27
+ * A map of providers to be bound to the application context
28
+ *
29
+ * @example
30
+ * ```ts
31
+ * {
32
+ * 'authentication.strategies.ldap': LdapStrategyProvider
33
+ * }
34
+ * ```
35
+ */
36
+ providers?: ProviderMap;
37
+ /**
38
+ * A map of classes to be bound to the application context.
39
+ *
40
+ * @example
41
+ * ```ts
42
+ * {
43
+ * 'rest.body-parsers.xml': XmlBodyParser
44
+ * }
45
+ * ```
46
+ */
47
+ classes?: ClassMap;
48
+ /**
49
+ * A map of name/class pairs for servers
50
+ */
51
+ servers?: {
52
+ [name: string]: Constructor<Server>;
53
+ };
54
+ lifeCycleObservers?: Constructor<LifeCycleObserver>[];
55
+ /**
56
+ * An array of service or provider classes
57
+ */
58
+ services?: ServiceOrProviderClass[];
59
+ /**
60
+ * An array of bindings to be aded to the application context.
61
+ *
62
+ * @example
63
+ * ```ts
64
+ * const bindingX = Binding.bind('x').to('Value X');
65
+ * this.bindings = [bindingX]
66
+ * ```
67
+ */
68
+ bindings?: Binding[];
69
+ /**
70
+ * Other properties
71
+ */
72
+ [prop: string]: any;
73
+ }
74
+ /**
75
+ * Mount a component to an Application.
76
+ *
77
+ * @param app - Application
78
+ * @param component - Component instance
79
+ */
80
+ export declare function mountComponent(app: Application, component: Component): void;