@thzero/library_server 0.15.9 → 0.15.17

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 (66) hide show
  1. package/README.md +89 -89
  2. package/boot/index.js +387 -384
  3. package/boot/koa/index.js +157 -157
  4. package/boot/plugins/admin/index.js +6 -6
  5. package/boot/plugins/admin/news.js +35 -35
  6. package/boot/plugins/admin/users.js +35 -35
  7. package/boot/plugins/api.js +58 -58
  8. package/boot/plugins/apiFront.js +31 -31
  9. package/boot/plugins/index.js +71 -71
  10. package/boot/plugins/news.js +46 -46
  11. package/boot/plugins/users.js +48 -48
  12. package/boot/plugins/usersExtended.js +32 -32
  13. package/constants.js +45 -45
  14. package/data/baseNews.js +42 -42
  15. package/data/baseSettingsUser.js +9 -9
  16. package/data/baseUser.js +28 -28
  17. package/data/index.js +24 -24
  18. package/data/named.js +20 -20
  19. package/errors/tokenExpired.js +7 -7
  20. package/license.md +8 -8
  21. package/middleware/authentication.js +67 -67
  22. package/middleware/authorization.js +180 -180
  23. package/package.json +50 -60
  24. package/repository/index.js +151 -151
  25. package/repository/usageMetrics/devnull.js +11 -11
  26. package/routes/admin/index.js +111 -111
  27. package/routes/admin/news.js +14 -14
  28. package/routes/admin/users.js +18 -18
  29. package/routes/baseNews.js +27 -27
  30. package/routes/baseUsers.js +106 -106
  31. package/routes/home.js +16 -16
  32. package/routes/index.js +31 -31
  33. package/routes/news.js +6 -6
  34. package/routes/plans.js +24 -24
  35. package/routes/users.js +6 -6
  36. package/routes/utility.js +34 -34
  37. package/routes/version.js +24 -24
  38. package/service/admin/baseNews.js +45 -45
  39. package/service/admin/index.js +130 -130
  40. package/service/admin/news.js +6 -6
  41. package/service/admin/users.js +107 -107
  42. package/service/baseSecurity.js +44 -44
  43. package/service/baseUser.js +122 -122
  44. package/service/communication.js +6 -6
  45. package/service/config.js +32 -32
  46. package/service/crypto.js +16 -16
  47. package/service/discovery/index.js +6 -6
  48. package/service/discovery/resources/index.js +101 -101
  49. package/service/external.js +19 -19
  50. package/service/externalRest.js +19 -19
  51. package/service/index.js +20 -20
  52. package/service/monitoring.js +13 -0
  53. package/service/news/base.js +49 -49
  54. package/service/news/index.js +6 -6
  55. package/service/news/validation/index.js +6 -6
  56. package/service/plans.js +27 -27
  57. package/service/restCommunication.js +21 -21
  58. package/service/usageMetrics.js +63 -63
  59. package/service/utility.js +37 -37
  60. package/service/version.js +32 -32
  61. package/utility/injector.js +59 -59
  62. package/utility/internalIp/index.js +48 -48
  63. package/utility/list/doubleLinked.js +88 -88
  64. package/utility/list/priorityQueue.js +109 -109
  65. package/utility/list/queue.js +72 -72
  66. package/utility/os.js +22 -22
package/boot/index.js CHANGED
@@ -1,384 +1,387 @@
1
- import http from 'http';
2
- import {internalIpV6, internalIpV4} from '@thzero/library_server/utility/internalIp';
3
-
4
- import { createTerminus } from '@godaddy/terminus';
5
-
6
- import config from 'config';
7
-
8
- import LibraryConstants from '../constants';
9
- import LibraryCommonServiceConstants from '@thzero/library_common_service/constants';
10
-
11
- import Utility from '@thzero/library_common/utility';
12
-
13
- import NotImplementedError from '@thzero/library_common/errors/notImplemented';
14
-
15
- // require('@thzero/library_server/utility/string.cjs');
16
- String.isNullOrEmpty = function(value) {
17
- //return !(typeof value === 'string' && value.length > 0)
18
- return !value;
19
- }
20
-
21
- String.isString = function(value) {
22
- return (typeof value === "string" || value instanceof String);
23
- }
24
-
25
- String.trim = function(value) {
26
- if (!value || !String.isString(value))
27
- return value;
28
- return value.trim();
29
- }
30
-
31
- import injector from '@thzero/library_common/utility/injector';
32
-
33
- import usageMetricsRepository from '../repository/usageMetrics/devnull';
34
-
35
- import configService from '../service/config';
36
- import loggerService from '@thzero/library_common_service/service/logger';
37
- import usageMetricsService from '../service/usageMetrics';
38
-
39
- class BootMain {
40
- async start(...args) {
41
- process.on('uncaughtException', function(err) {
42
- console.log('Caught exception', err);
43
- return process.exit(99);
44
- });
45
-
46
- this._injector = injector;
47
-
48
- // https://github.com/lorenwest/node-config/wiki
49
- this._appConfig = new configService(config.get('app'));
50
-
51
- this._servicesPost = new Map();
52
-
53
- const plugins = this._determinePlugins(args);
54
- await await this._initPlugins(plugins);
55
-
56
- const app = await this._initApp(args, plugins);
57
-
58
- this.port = this._appConfig.get('port');
59
- this.loggerServiceI.info2(`config.port: ${this.port}`);
60
- this.loggerServiceI.info2(`process.env.PORT: ${process.env.PORT}`);
61
- this.port = process.env.PORT || this.port;
62
- this.loggerServiceI.info2(`selected.port: ${this.port}`);
63
- const serverHttp = http.createServer(app.callback());
64
-
65
- function onSignal() {
66
- this.loggerServiceI.info2(`server is starting cleanup`);
67
- const cleanupFuncs = [];
68
- this._initCleanup(cleanupFuncs);
69
- this._initCleanupDiscovery(cleanupFuncs);
70
- return Promise.all(cleanupFuncs);
71
- }
72
-
73
- function onShutdown() {
74
- this._initShutdown();
75
- this.loggerServiceI.info2(`cleanup finished, server is shutting down`);
76
- }
77
-
78
- function healthCheck() {
79
- return Promise.resolve(
80
- // optionally include a resolve value to be included as
81
- // info in the health check response
82
- )
83
- }
84
-
85
- const healthcheckPath = this._appConfig.get('healthcheck.path', LibraryConstants.HealthCheck.DefaultPath);
86
- if (!healthcheckPath.startsWith('/'))
87
- healthcheckPath = '/' + healthcheckPath;
88
-
89
- const healthCheckOptions = {
90
- verbatim: true // [optional = false] use object returned from /healthcheck verbatim in response
91
- };
92
- if (healthCheck)
93
- healthCheckOptions[healthcheckPath] = healthCheck;
94
-
95
- const terminusOptions = {
96
- // health check options
97
- // healthChecks: {
98
- // healthcheckPath: healthCheck, // a function returning a promise indicating service health,
99
- // verbatim: true // [optional = false] use object returned from /healthcheck verbatim in response
100
- // },
101
- healthChecks: healthCheckOptions,
102
-
103
- // cleanup options
104
- signals: [ 'SIGINT', 'SIGTERM' ],
105
- onSignal: onSignal.bind(this), // [optional] cleanup function, returning a promise (used to be onSigterm)
106
- onShutdown: onShutdown.bind(this) // [optional] called right before exiting
107
- };
108
-
109
- createTerminus(serverHttp, terminusOptions);
110
-
111
- const listen = async (port) => new Promise((resolve, reject) => {
112
- serverHttp.listen(port, (err) => {
113
- if (err) {
114
- reject(err);
115
- return;
116
- }
117
-
118
- resolve();
119
- });
120
- });
121
- await listen(this.port);
122
- this.address = serverHttp.address() ? serverHttp.address().address : null;
123
- if (this.address === '::')
124
- this.address = await internalIpV4();
125
-
126
- await this._initServer(serverHttp);
127
-
128
- for (const [key, value] of this._servicesPost) {
129
- console.log(`services.init.post - ${key}`);
130
- if (value.initPost)
131
- await value.initPost();
132
- }
133
- this._initAppPost(app, args);
134
-
135
- await this._initServerDiscovery(serverHttp);
136
-
137
- this.loggerServiceI.info2(`Starting HTTP on: `, this.address);
138
- }
139
-
140
- async _initApp(args, plugins) {
141
- throw new NotImplementedError();
142
- }
143
-
144
- async _initAppPost(app, args) {
145
- }
146
-
147
- _determinePlugins(args) {
148
- let obj;
149
- const results = [];
150
- for (const plugin of args) {
151
- obj = plugin;
152
- if (!this._isObject(obj))
153
- obj = new plugin();
154
- obj.init(this._appConfig, injector);
155
- results.push(obj);
156
- }
157
- return results;
158
- }
159
-
160
- async _initPlugins(plugins) {
161
- try {
162
- injector.addSingleton(LibraryCommonServiceConstants.InjectorKeys.SERVICE_CONFIG, this._appConfig);
163
-
164
- this._repositories = new Map();
165
-
166
- for (const pluginRepository of plugins)
167
- await pluginRepository.initRepositories(this._repositories);
168
-
169
- await this._initRepositories();
170
- this._injectRepository(LibraryConstants.InjectorKeys.REPOSITORY_USAGE_METRIC, this._initRepositoriesUsageMetrics());
171
-
172
- this._services = new Map();
173
-
174
- this.loggerServiceI = this._initServicesLogger();
175
- this._initServicesLoggers();
176
- this._injectService(LibraryCommonServiceConstants.InjectorKeys.SERVICE_LOGGER, this.loggerServiceI);
177
-
178
- const monitoringService = this._initServicesMonitoring();
179
- if (monitoringService)
180
- this._injectService(LibraryCommonServiceConstants.InjectorKeys.SERVICE_MONITORING, monitoringService);
181
-
182
- this.usageMetricsServiceI = this._initServicesUsageMetrics();
183
- this._injectService(LibraryConstants.InjectorKeys.SERVICE_USAGE_METRIC, this.usageMetricsServiceI);
184
-
185
- this.resourceDiscoveryServiceI = this._initServicesDiscoveryResources();
186
- if (this.resourceDiscoveryServiceI)
187
- this._injectService(LibraryConstants.InjectorKeys.SERVICE_DISCOVERY_RESOURCES, this.resourceDiscoveryServiceI);
188
-
189
- this.mdnsDiscoveryServiceI = this._initServicesDiscoveryMdns();
190
- if (this.mdnsDiscoveryServiceI)
191
- this._injectService(LibraryConstants.InjectorKeys.SERVICE_DISCOVERY_MDNS, this.mdnsDiscoveryServiceI);
192
-
193
- for (const pluginService of plugins)
194
- await pluginService.initServices(this._services);
195
-
196
- await this._initServices();
197
-
198
- for (const [key, value] of this._repositories) {
199
- console.log(`repositories.init - ${key}`);
200
- await value.init(injector);
201
- }
202
-
203
- for (const [key, value] of this._services) {
204
- console.log(`services.init - ${key}`);
205
- await value.init(injector);
206
-
207
- this._servicesPost.set(key, value);
208
- }
209
-
210
- this._services = new Map();
211
-
212
- await this._initServicesSecondary();
213
-
214
- for (const pluginService of plugins)
215
- await pluginService.initServicesSecondary(this._services);
216
-
217
- for (const [key, value] of this._services) {
218
- if (value.initialized)
219
- continue;
220
-
221
- console.log(`services.init.secondary - ${key}`);
222
- await value.init(injector);
223
-
224
- this._servicesPost.set(key, value);
225
- }
226
-
227
- Utility.initDateTime();
228
- }
229
- finally {
230
- this._repositories = null;
231
- this._services = null;
232
- }
233
- }
234
-
235
- _initCleanup(cleanupFuncs) {
236
- // your clean logic, like closing database connections
237
- }
238
-
239
- _initCleanupDiscovery(cleanupFuncs) {
240
- if (this.resourceDiscoveryServiceI)
241
- cleanupFuncs.push(this.resourceDiscoveryServiceI.cleanup());
242
- if (this.mdnsDiscoveryServiceI)
243
- cleanupFuncs.push(this.mdnsDiscoveryServiceI.cleanup());
244
- }
245
-
246
- _initPostAuth(app) {
247
- }
248
-
249
- _initPreAuth(app) {
250
- }
251
-
252
- _initPostRoutes(app) {
253
- }
254
-
255
- _initPreRoutes(app) {
256
- }
257
-
258
- async _initRepositories() {
259
- }
260
-
261
- _initRepositoriesUsageMetrics() {
262
- return new usageMetricsRepository();
263
- }
264
-
265
- _initRoute(route) {
266
- }
267
-
268
- async _initRoutes() {
269
- }
270
-
271
- async _initServices() {
272
- }
273
-
274
- async _initServicesSecondary() {
275
- }
276
-
277
- _initServicesDiscoveryResources() {
278
- return null;
279
- }
280
-
281
- _initServicesDiscoveryMdns() {
282
- return null;
283
- }
284
-
285
- _initServicesLogger() {
286
- return new loggerService();
287
- }
288
-
289
- _initServicesLoggers() {
290
- throw new NotImplementedError();
291
- }
292
-
293
- _initServicesMonitoring() {
294
- return null;
295
- }
296
-
297
- _initServicesUsageMetrics() {
298
- return new usageMetricsService();
299
- }
300
-
301
- async _initServer(serverHttp) {
302
- }
303
-
304
- async _initServerDiscovery(serverHttp) {
305
- if (!this.resourceDiscoveryServiceI && !this.mdnsDiscoveryServiceI)
306
- return;
307
-
308
- const opts = await this._initServerDiscoveryOpts();
309
-
310
- await this._initServerDiscoveryMdns(Utility.cloneDeep(opts));
311
- await this._initServerDiscoveryResources(Utility.cloneDeep(opts));
312
- }
313
-
314
- async _initServerDiscoveryMdns(opts) {
315
- if (!this.mdnsDiscoveryServiceI)
316
- return;
317
-
318
- await this.mdnsDiscoveryServiceI.initialize(Utility.generateId(), await this._initServerDiscoveryOptsMdns(opts));
319
- }
320
-
321
- async _initServerDiscoveryOpts() {
322
- const dns = this._appConfig.get('dns', null);
323
- const grpc = this._appConfig.get('grpc', null);
324
- const secure = this._appConfig.get('secure', false);
325
-
326
- const opts = {
327
- address: this.address,
328
- port: this.port,
329
- healthCheck: 'healthcheck',
330
- secure: secure ? secure : false,
331
- dns: dns
332
- };
333
-
334
- if (grpc) {
335
- opts.grpc = {
336
- port: grpc ? grpc.port : null,
337
- secure: grpc ? (grpc.secure ? grpc.secure : false) : false
338
- };
339
- }
340
-
341
- return opts;
342
- }
343
-
344
- async _initServerDiscoveryOptsMdns(opts) {
345
- return opts;
346
- }
347
-
348
- async _initServerDiscoveryOptsResources(opts) {
349
- return opts;
350
- }
351
-
352
- async _initServerDiscoveryResources(opts) {
353
- if (!this.resourceDiscoveryServiceI)
354
- return;
355
-
356
- await this.resourceDiscoveryServiceI.initialize(Utility.generateId(), await this._initServerDiscoveryOptsResources(opts));
357
- }
358
-
359
- _injectRepository(key, repository) {
360
- console.log(`repositories.inject - ${key}`);
361
- this._repositories.set(key, repository);
362
- injector.addSingleton(key, repository);
363
- }
364
-
365
- _injectService(key, service) {
366
- console.log(`services.inject - ${key}`);
367
- this._services.set(key, service);
368
- injector.addSingleton(key, service);
369
- }
370
-
371
- _initShutdown() {
372
- }
373
-
374
- _isObject(objValue) {
375
- return objValue && typeof objValue === 'object';
376
- }
377
-
378
- _registerServicesLogger(key, service) {
379
- this._injectService(key, service);
380
- this.loggerServiceI.register(key);
381
- }
382
- }
383
-
384
- export default BootMain;
1
+ import http from 'http';
2
+ import {internalIpV6, internalIpV4} from '@thzero/library_server/utility/internalIp';
3
+
4
+ import { createTerminus } from '@godaddy/terminus';
5
+
6
+ import config from 'config';
7
+
8
+ import LibraryConstants from '../constants';
9
+ import LibraryCommonServiceConstants from '@thzero/library_common_service/constants';
10
+
11
+ import Utility from '@thzero/library_common/utility';
12
+
13
+ import NotImplementedError from '@thzero/library_common/errors/notImplemented';
14
+
15
+ import nullMonitoringService from '../service/monitoring';
16
+
17
+ // require('@thzero/library_server/utility/string.cjs');
18
+ String.isNullOrEmpty = function(value) {
19
+ //return !(typeof value === 'string' && value.length > 0)
20
+ return !value;
21
+ }
22
+
23
+ String.isString = function(value) {
24
+ return (typeof value === "string" || value instanceof String);
25
+ }
26
+
27
+ String.trim = function(value) {
28
+ if (!value || !String.isString(value))
29
+ return value;
30
+ return value.trim();
31
+ }
32
+
33
+ import injector from '@thzero/library_common/utility/injector';
34
+
35
+ import usageMetricsRepository from '../repository/usageMetrics/devnull';
36
+
37
+ import configService from '../service/config';
38
+ import loggerService from '@thzero/library_common_service/service/logger';
39
+ import usageMetricsService from '../service/usageMetrics';
40
+
41
+ class BootMain {
42
+ async start(...args) {
43
+ process.on('uncaughtException', function(err) {
44
+ console.log('Caught exception', err);
45
+ return process.exit(99);
46
+ });
47
+
48
+ this._injector = injector;
49
+
50
+ // https://github.com/lorenwest/node-config/wiki
51
+ this._appConfig = new configService(config.get('app'));
52
+
53
+ this._servicesPost = new Map();
54
+
55
+ const plugins = this._determinePlugins(args);
56
+ await await this._initPlugins(plugins);
57
+
58
+ const app = await this._initApp(args, plugins);
59
+
60
+ this.port = this._appConfig.get('port');
61
+ this.loggerServiceI.info2(`config.port: ${this.port}`);
62
+ this.loggerServiceI.info2(`process.env.PORT: ${process.env.PORT}`);
63
+ this.port = process.env.PORT || this.port;
64
+ this.loggerServiceI.info2(`selected.port: ${this.port}`);
65
+ const serverHttp = http.createServer(app.callback());
66
+
67
+ function onSignal() {
68
+ this.loggerServiceI.info2(`server is starting cleanup`);
69
+ const cleanupFuncs = [];
70
+ this._initCleanup(cleanupFuncs);
71
+ this._initCleanupDiscovery(cleanupFuncs);
72
+ return Promise.all(cleanupFuncs);
73
+ }
74
+
75
+ function onShutdown() {
76
+ this._initShutdown();
77
+ this.loggerServiceI.info2(`cleanup finished, server is shutting down`);
78
+ }
79
+
80
+ function healthCheck() {
81
+ return Promise.resolve(
82
+ // optionally include a resolve value to be included as
83
+ // info in the health check response
84
+ )
85
+ }
86
+
87
+ const healthcheckPath = this._appConfig.get('healthcheck.path', LibraryConstants.HealthCheck.DefaultPath);
88
+ if (!healthcheckPath.startsWith('/'))
89
+ healthcheckPath = '/' + healthcheckPath;
90
+
91
+ const healthCheckOptions = {
92
+ verbatim: true // [optional = false] use object returned from /healthcheck verbatim in response
93
+ };
94
+ if (healthCheck)
95
+ healthCheckOptions[healthcheckPath] = healthCheck;
96
+
97
+ const terminusOptions = {
98
+ // health check options
99
+ // healthChecks: {
100
+ // healthcheckPath: healthCheck, // a function returning a promise indicating service health,
101
+ // verbatim: true // [optional = false] use object returned from /healthcheck verbatim in response
102
+ // },
103
+ healthChecks: healthCheckOptions,
104
+
105
+ // cleanup options
106
+ signals: [ 'SIGINT', 'SIGTERM' ],
107
+ onSignal: onSignal.bind(this), // [optional] cleanup function, returning a promise (used to be onSigterm)
108
+ onShutdown: onShutdown.bind(this) // [optional] called right before exiting
109
+ };
110
+
111
+ createTerminus(serverHttp, terminusOptions);
112
+
113
+ const listen = async (port) => new Promise((resolve, reject) => {
114
+ serverHttp.listen(port, (err) => {
115
+ if (err) {
116
+ reject(err);
117
+ return;
118
+ }
119
+
120
+ resolve();
121
+ });
122
+ });
123
+ await listen(this.port);
124
+ this.address = serverHttp.address() ? serverHttp.address().address : null;
125
+ if (this.address === '::')
126
+ this.address = await internalIpV4();
127
+
128
+ await this._initServer(serverHttp);
129
+
130
+ for (const [key, value] of this._servicesPost) {
131
+ console.log(`services.init.post - ${key}`);
132
+ if (value.initPost)
133
+ await value.initPost();
134
+ }
135
+ this._initAppPost(app, args);
136
+
137
+ await this._initServerDiscovery(serverHttp);
138
+
139
+ this.loggerServiceI.info2(`Starting HTTP on: `, this.address);
140
+ }
141
+
142
+ async _initApp(args, plugins) {
143
+ throw new NotImplementedError();
144
+ }
145
+
146
+ async _initAppPost(app, args) {
147
+ }
148
+
149
+ _determinePlugins(args) {
150
+ let obj;
151
+ const results = [];
152
+ for (const plugin of args) {
153
+ obj = plugin;
154
+ if (!this._isObject(obj))
155
+ obj = new plugin();
156
+ obj.init(this._appConfig, injector);
157
+ results.push(obj);
158
+ }
159
+ return results;
160
+ }
161
+
162
+ async _initPlugins(plugins) {
163
+ try {
164
+ injector.addSingleton(LibraryCommonServiceConstants.InjectorKeys.SERVICE_CONFIG, this._appConfig);
165
+
166
+ this._repositories = new Map();
167
+
168
+ for (const pluginRepository of plugins)
169
+ await pluginRepository.initRepositories(this._repositories);
170
+
171
+ await this._initRepositories();
172
+ this._injectRepository(LibraryConstants.InjectorKeys.REPOSITORY_USAGE_METRIC, this._initRepositoriesUsageMetrics());
173
+
174
+ this._services = new Map();
175
+
176
+ this.loggerServiceI = this._initServicesLogger();
177
+ this._initServicesLoggers();
178
+ this._injectService(LibraryCommonServiceConstants.InjectorKeys.SERVICE_LOGGER, this.loggerServiceI);
179
+
180
+ const monitoringService = this._initServicesMonitoring();
181
+ if (!monitoringService)
182
+ monitoringService = nullMonitoringService();
183
+ this._injectService(LibraryCommonServiceConstants.InjectorKeys.SERVICE_MONITORING, monitoringService);
184
+
185
+ this.usageMetricsServiceI = this._initServicesUsageMetrics();
186
+ this._injectService(LibraryConstants.InjectorKeys.SERVICE_USAGE_METRIC, this.usageMetricsServiceI);
187
+
188
+ this.resourceDiscoveryServiceI = this._initServicesDiscoveryResources();
189
+ if (this.resourceDiscoveryServiceI)
190
+ this._injectService(LibraryConstants.InjectorKeys.SERVICE_DISCOVERY_RESOURCES, this.resourceDiscoveryServiceI);
191
+
192
+ this.mdnsDiscoveryServiceI = this._initServicesDiscoveryMdns();
193
+ if (this.mdnsDiscoveryServiceI)
194
+ this._injectService(LibraryConstants.InjectorKeys.SERVICE_DISCOVERY_MDNS, this.mdnsDiscoveryServiceI);
195
+
196
+ for (const pluginService of plugins)
197
+ await pluginService.initServices(this._services);
198
+
199
+ await this._initServices();
200
+
201
+ for (const [key, value] of this._repositories) {
202
+ console.log(`repositories.init - ${key}`);
203
+ await value.init(injector);
204
+ }
205
+
206
+ for (const [key, value] of this._services) {
207
+ console.log(`services.init - ${key}`);
208
+ await value.init(injector);
209
+
210
+ this._servicesPost.set(key, value);
211
+ }
212
+
213
+ this._services = new Map();
214
+
215
+ await this._initServicesSecondary();
216
+
217
+ for (const pluginService of plugins)
218
+ await pluginService.initServicesSecondary(this._services);
219
+
220
+ for (const [key, value] of this._services) {
221
+ if (value.initialized)
222
+ continue;
223
+
224
+ console.log(`services.init.secondary - ${key}`);
225
+ await value.init(injector);
226
+
227
+ this._servicesPost.set(key, value);
228
+ }
229
+
230
+ Utility.initDateTime();
231
+ }
232
+ finally {
233
+ this._repositories = null;
234
+ this._services = null;
235
+ }
236
+ }
237
+
238
+ _initCleanup(cleanupFuncs) {
239
+ // your clean logic, like closing database connections
240
+ }
241
+
242
+ _initCleanupDiscovery(cleanupFuncs) {
243
+ if (this.resourceDiscoveryServiceI)
244
+ cleanupFuncs.push(this.resourceDiscoveryServiceI.cleanup());
245
+ if (this.mdnsDiscoveryServiceI)
246
+ cleanupFuncs.push(this.mdnsDiscoveryServiceI.cleanup());
247
+ }
248
+
249
+ _initPostAuth(app) {
250
+ }
251
+
252
+ _initPreAuth(app) {
253
+ }
254
+
255
+ _initPostRoutes(app) {
256
+ }
257
+
258
+ _initPreRoutes(app) {
259
+ }
260
+
261
+ async _initRepositories() {
262
+ }
263
+
264
+ _initRepositoriesUsageMetrics() {
265
+ return new usageMetricsRepository();
266
+ }
267
+
268
+ _initRoute(route) {
269
+ }
270
+
271
+ async _initRoutes() {
272
+ }
273
+
274
+ async _initServices() {
275
+ }
276
+
277
+ async _initServicesSecondary() {
278
+ }
279
+
280
+ _initServicesDiscoveryResources() {
281
+ return null;
282
+ }
283
+
284
+ _initServicesDiscoveryMdns() {
285
+ return null;
286
+ }
287
+
288
+ _initServicesLogger() {
289
+ return new loggerService();
290
+ }
291
+
292
+ _initServicesLoggers() {
293
+ throw new NotImplementedError();
294
+ }
295
+
296
+ _initServicesMonitoring() {
297
+ return null;
298
+ }
299
+
300
+ _initServicesUsageMetrics() {
301
+ return new usageMetricsService();
302
+ }
303
+
304
+ async _initServer(serverHttp) {
305
+ }
306
+
307
+ async _initServerDiscovery(serverHttp) {
308
+ if (!this.resourceDiscoveryServiceI && !this.mdnsDiscoveryServiceI)
309
+ return;
310
+
311
+ const opts = await this._initServerDiscoveryOpts();
312
+
313
+ await this._initServerDiscoveryMdns(Utility.cloneDeep(opts));
314
+ await this._initServerDiscoveryResources(Utility.cloneDeep(opts));
315
+ }
316
+
317
+ async _initServerDiscoveryMdns(opts) {
318
+ if (!this.mdnsDiscoveryServiceI)
319
+ return;
320
+
321
+ await this.mdnsDiscoveryServiceI.initialize(Utility.generateId(), await this._initServerDiscoveryOptsMdns(opts));
322
+ }
323
+
324
+ async _initServerDiscoveryOpts() {
325
+ const dns = this._appConfig.get('dns', null);
326
+ const grpc = this._appConfig.get('grpc', null);
327
+ const secure = this._appConfig.get('secure', false);
328
+
329
+ const opts = {
330
+ address: this.address,
331
+ port: this.port,
332
+ healthCheck: 'healthcheck',
333
+ secure: secure ? secure : false,
334
+ dns: dns
335
+ };
336
+
337
+ if (grpc) {
338
+ opts.grpc = {
339
+ port: grpc ? grpc.port : null,
340
+ secure: grpc ? (grpc.secure ? grpc.secure : false) : false
341
+ };
342
+ }
343
+
344
+ return opts;
345
+ }
346
+
347
+ async _initServerDiscoveryOptsMdns(opts) {
348
+ return opts;
349
+ }
350
+
351
+ async _initServerDiscoveryOptsResources(opts) {
352
+ return opts;
353
+ }
354
+
355
+ async _initServerDiscoveryResources(opts) {
356
+ if (!this.resourceDiscoveryServiceI)
357
+ return;
358
+
359
+ await this.resourceDiscoveryServiceI.initialize(Utility.generateId(), await this._initServerDiscoveryOptsResources(opts));
360
+ }
361
+
362
+ _injectRepository(key, repository) {
363
+ console.log(`repositories.inject - ${key}`);
364
+ this._repositories.set(key, repository);
365
+ injector.addSingleton(key, repository);
366
+ }
367
+
368
+ _injectService(key, service) {
369
+ console.log(`services.inject - ${key}`);
370
+ this._services.set(key, service);
371
+ injector.addSingleton(key, service);
372
+ }
373
+
374
+ _initShutdown() {
375
+ }
376
+
377
+ _isObject(objValue) {
378
+ return objValue && typeof objValue === 'object';
379
+ }
380
+
381
+ _registerServicesLogger(key, service) {
382
+ this._injectService(key, service);
383
+ this.loggerServiceI.register(key);
384
+ }
385
+ }
386
+
387
+ export default BootMain;