@itee/server 8.0.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.
@@ -0,0 +1,510 @@
1
+ /**
2
+ * ┳ ┏┓ ┏┓ ┏┓ ┏┓ ┏┓ ┏┳
3
+ * ┃╋┏┓┏┓ ┗┓┏┓┏┓┓┏┏┓┏┓ ┓┏┣┓ ┫ ┃┫ ━━ ┃ ┏┓┏┳┓┏┳┓┏┓┏┓ ┃┏
4
+ * ┻┗┗ ┗ •┗┛┗ ┛ ┗┛┗ ┛ ┗┛┗┛•┗┛•┗┛ ┗┛┗┛┛┗┗┛┗┗┗┛┛┗┗┛┛
5
+ *
6
+ * @desc The server side of the Itee solution for 3d web content, this package is design to work with an Itee client.
7
+ * @author [Tristan Valcke]{@link https://github.com/Itee}
8
+ * @license [BSD-3-Clause]{@link https://opensource.org/licenses/BSD-3-Clause}
9
+ *
10
+ */
11
+ 'use strict';
12
+
13
+ var express = require('express');
14
+ var http = require('http');
15
+ var https = require('https');
16
+ var iteeCore = require('itee-core');
17
+ var iteeValidators = require('itee-validators');
18
+ var path = require('path');
19
+
20
+ function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
21
+
22
+ var express__default = /*#__PURE__*/_interopDefault(express);
23
+ var http__default = /*#__PURE__*/_interopDefault(http);
24
+ var https__default = /*#__PURE__*/_interopDefault(https);
25
+ var path__default = /*#__PURE__*/_interopDefault(path);
26
+
27
+ /**
28
+ * @author [Tristan Valcke]{@link https://github.com/Itee}
29
+ * @license [BSD-3-Clause]{@link https://opensource.org/licenses/BSD-3-Clause}
30
+ *
31
+ * @file Todo
32
+ *
33
+ * @example Todo
34
+ *
35
+ */
36
+
37
+
38
+ class TBackendManager extends iteeCore.TAbstractObject {
39
+
40
+ constructor( parameters = {} ) {
41
+
42
+ const _parameters = {
43
+ ...{
44
+ logger: iteeCore.DefaultLogger,
45
+ rootPath: __dirname,
46
+ applications: [],
47
+ databases: [],
48
+ servers: []
49
+ },
50
+ ...parameters
51
+ };
52
+
53
+ super( _parameters );
54
+
55
+ this.logger = _parameters.logger;
56
+ this.rootPath = _parameters.rootPath;
57
+ this.applications = express__default.default();
58
+ this.router = express__default.default.Router;
59
+ this.databases = new Map();
60
+ this.servers = new Map();
61
+ this.connections = [];
62
+
63
+ this._initApplications( _parameters.applications );
64
+ this._initDatabases( _parameters.databases );
65
+ this._initServers( _parameters.servers );
66
+
67
+ }
68
+ get applications() {
69
+ return this._applications
70
+ }
71
+ set applications( value ) {
72
+ this._applications = value;
73
+ }
74
+ get router() {
75
+ return this._router
76
+ }
77
+
78
+ // Todo remove middleware
79
+ set router( value ) {
80
+ this._router = value;
81
+ }
82
+ get databases() {
83
+ return this._databases
84
+ }
85
+ set databases( value ) {
86
+ this._databases = value;
87
+ }
88
+ get servers() {
89
+ return this._servers
90
+ }
91
+ set servers( value ) {
92
+ this._servers = value;
93
+ }
94
+ get rootPath() {
95
+
96
+ return this._rootPath
97
+
98
+ }
99
+ set rootPath( value ) {
100
+
101
+ if ( iteeValidators.isNull( value ) ) { throw new TypeError( 'Root path cannot be null ! Expect a non empty string.' ) }
102
+ if ( iteeValidators.isUndefined( value ) ) { throw new TypeError( 'Root path cannot be undefined ! Expect a non empty string.' ) }
103
+ if ( iteeValidators.isNotString( value ) ) { throw new TypeError( `Root path cannot be an instance of ${ value.constructor.name } ! Expect a non empty string.` ) }
104
+ if ( iteeValidators.isEmptyString( value ) ) { throw new TypeError( 'Root path cannot be empty ! Expect a non empty string.' ) }
105
+ if ( iteeValidators.isBlankString( value ) ) { throw new TypeError( 'Root path cannot contain only whitespace ! Expect a non empty string.' ) }
106
+
107
+ this._rootPath = value;
108
+
109
+ }
110
+ setApplications( value ) {
111
+
112
+ this.applications = value;
113
+ return this
114
+
115
+ }
116
+ addMiddleware( middleware ) {
117
+
118
+ this.applications.use( middleware );
119
+ return this
120
+
121
+ }
122
+ setRouter( value ) {
123
+
124
+ this.router = value;
125
+ return this
126
+
127
+ }
128
+ setDatabases( value ) {
129
+
130
+ this.databases = value;
131
+ return this
132
+
133
+ }
134
+ addDatabase( databaseName, database ) {
135
+
136
+ this._databases.set( databaseName, database );
137
+ return this
138
+
139
+ }
140
+ setServers( value ) {
141
+
142
+ this.servers = value;
143
+ return this
144
+
145
+ }
146
+ setRootPath( value ) {
147
+
148
+ this.rootPath = value;
149
+ return this
150
+
151
+ }
152
+
153
+ _initApplications( config ) {
154
+
155
+ if ( config.case_sensitive_routing ) { this.applications.set( 'case sensitive routing', config.case_sensitive_routing ); }
156
+ if ( config.env ) { this.applications.set( 'env', config.env ); }
157
+ if ( config.etag ) { this.applications.set( 'etag', config.etag ); }
158
+ if ( config.jsonp_callback_name ) { this.applications.set( 'jsonp callback name', config.jsonp_callback_name ); }
159
+ if ( config.jsonp_escape ) { this.applications.set( 'json escape', config.jsonp_escape ); }
160
+ if ( config.jsonp_replacer ) { this.applications.set( 'json replacer', config.jsonp_replacer ); }
161
+ if ( config.jsonp_spaces ) { this.applications.set( 'json spaces', config.jsonp_spaces ); }
162
+ if ( config.query_parser ) { this.applications.set( 'query parser', config.query_parser ); }
163
+ if ( config.strict_routing ) { this.applications.set( 'strict routing', config.strict_routing ); }
164
+ if ( config.subdomain_offset ) { this.applications.set( 'subdomain offset', config.subdomain_offset ); }
165
+ if ( config.trust_proxy ) { this.applications.set( 'trust proxy', config.trust_proxy ); }
166
+ if ( config.views ) { this.applications.set( 'views', config.views ); }
167
+ if ( config.view_cache ) { this.applications.set( 'view cache', config.view_cache ); }
168
+ if ( config.view_engine ) { this.applications.set( 'view engine', config.view_engine ); }
169
+ if ( config.x_powered_by ) { this.applications.set( 'x-powered-by', config.x_powered_by ); }
170
+
171
+ this._initMiddlewares( config.middlewares );
172
+ this._initRouters( config.routers );
173
+
174
+ }
175
+
176
+ _initMiddlewares( middlewaresConfig ) {
177
+
178
+ for ( let [ name, config ] of Object.entries( middlewaresConfig ) ) {
179
+
180
+ if ( iteeValidators.isNotArray( config ) ) {
181
+ throw new TypeError( `Invalid middlware configuration for ${ name }, expecting an array of arguments to spread to middleware module, got ${ config.constructor.name }` )
182
+ }
183
+
184
+ if ( this._initPackageMiddleware( name, config ) ) {
185
+
186
+ this.logger.log( `Use ${ name } middleware from node_modules` );
187
+
188
+ } else if ( this._initLocalMiddleware( name, config ) ) {
189
+
190
+ this.logger.log( `Use ${ name } middleware from local folder` );
191
+
192
+ } else {
193
+
194
+ this.logger.error( `Unable to register the middleware ${ name } the package and/or local file doesn't seem to exist ! Skip it.` );
195
+
196
+ }
197
+
198
+ }
199
+
200
+ }
201
+
202
+ _initPackageMiddleware( name, config ) {
203
+
204
+ let success = false;
205
+
206
+ try {
207
+
208
+ this.applications.use( require( name )( ...config ) );
209
+ success = true;
210
+
211
+ } catch ( error ) {
212
+
213
+ if ( !error.code || error.code !== 'MODULE_NOT_FOUND' ) {
214
+
215
+ this.logger.error( `The middleware "${ name }" seems to encounter internal error.` );
216
+ this.logger.error( error );
217
+
218
+ }
219
+
220
+ }
221
+
222
+ return success
223
+
224
+ }
225
+
226
+ _initLocalMiddleware( name, config ) {
227
+
228
+ let success = false;
229
+
230
+ try {
231
+
232
+ const localMiddlewaresPath = path__default.default.join( this.rootPath, 'middlewares', name );
233
+ this.applications.use( require( localMiddlewaresPath )( ...config ) );
234
+ success = true;
235
+
236
+ } catch ( error ) {
237
+
238
+ this.logger.error( error );
239
+
240
+ }
241
+
242
+ return success
243
+
244
+ }
245
+
246
+ _initRouters( routers ) {
247
+
248
+ for ( let [ baseRoute, routerPath ] of Object.entries( routers ) ) {
249
+
250
+ if ( this._initPackageRouter( baseRoute, routerPath ) ) {
251
+
252
+ this.logger.log( `Use ${ routerPath } router from node_modules over base route: ${ baseRoute }` );
253
+
254
+ } else if ( this._initLocalRouter( baseRoute, routerPath ) ) {
255
+
256
+ this.logger.log( `Use ${ routerPath } router from local folder over base route: ${ baseRoute }` );
257
+
258
+ } else {
259
+
260
+ this.logger.error( `Unable to register the router ${ routerPath } the package and/or local file doesn't seem to exist ! Skip it.` );
261
+
262
+ }
263
+
264
+ }
265
+
266
+ }
267
+
268
+ _initPackageRouter( baseRoute, routerPath ) {
269
+
270
+ let success = false;
271
+
272
+ try {
273
+
274
+ this.applications.use( baseRoute, require( routerPath ) );
275
+ success = true;
276
+
277
+ } catch ( error ) {
278
+
279
+ if ( !error.code || error.code !== 'MODULE_NOT_FOUND' ) {
280
+
281
+ this.logger.error( `The router "${ baseRoute }" seems to encounter internal error.` );
282
+ this.logger.error( error );
283
+
284
+ }
285
+
286
+ }
287
+
288
+ return success
289
+
290
+ }
291
+
292
+ _initLocalRouter( baseRoute, routerPath ) {
293
+
294
+ let success = false;
295
+
296
+ try {
297
+
298
+ const localRoutersPath = path__default.default.join( this.rootPath, 'routers', routerPath );
299
+ this.applications.use( baseRoute, require( localRoutersPath ) );
300
+ success = true;
301
+
302
+ } catch ( error ) {
303
+
304
+ if ( error instanceof TypeError && error.message === 'Found non-callable @@iterator' ) {
305
+
306
+ this.logger.error( `The router "${ baseRoute }" seems to encounter error ! Are you using an object instead an array for router configuration ?` );
307
+
308
+ }
309
+
310
+ this.logger.error( error );
311
+
312
+ }
313
+
314
+ return success
315
+
316
+ }
317
+
318
+ _initDatabases( config ) {
319
+
320
+ for ( let configIndex = 0, numberOfDatabasesConfigs = config.length ; configIndex < numberOfDatabasesConfigs ; configIndex++ ) {
321
+
322
+ const databaseConfig = config[ configIndex ];
323
+ const dbType = databaseConfig.type;
324
+ const dbFrom = databaseConfig.from;
325
+ const dbName = `${ ( databaseConfig.name ) ? databaseConfig.name : `${ dbType }_${ configIndex }` }`;
326
+
327
+ try {
328
+
329
+ let database = null;
330
+
331
+ if ( iteeValidators.isDefined( dbFrom ) ) {
332
+
333
+ // In case user specify a package where take the database of type...
334
+ const databasePackage = require( dbFrom );
335
+ database = new databasePackage[ dbType ]( {
336
+ ...{
337
+ application: this.applications,
338
+ router: this.router
339
+ },
340
+ ...databaseConfig
341
+ } );
342
+
343
+ } else {
344
+
345
+ // // Else try to use auto registered database
346
+ // database = new Databases[ dbType ]( {
347
+ // ...{
348
+ // application: this.applications,
349
+ // router: this.router
350
+ // },
351
+ // ...databaseConfig
352
+ // } )
353
+
354
+ }
355
+
356
+ // Todo move in start
357
+ database.connect();
358
+
359
+ this.databases.set( dbName, database );
360
+
361
+ } catch ( error ) {
362
+
363
+ this.logger.error( `Unable to create database of type ${ dbType } due to ${ error.name }` );
364
+ this.logger.error( error.message );
365
+ this.logger.error( error.stack );
366
+
367
+ }
368
+
369
+ }
370
+
371
+ }
372
+
373
+ _initServers( config ) {
374
+
375
+ const _config = ( iteeValidators.isArray( config ) ) ? config : [ config ];
376
+
377
+ for ( let configId = 0, numberOfConfigs = _config.length ; configId < numberOfConfigs ; configId++ ) {
378
+
379
+ let configElement = _config[ configId ];
380
+ let server = null;
381
+
382
+ if ( configElement.type === 'https' ) {
383
+
384
+ const options = {
385
+ pfx: configElement.pfx,
386
+ passphrase: configElement.passphrase
387
+ };
388
+
389
+ server = https__default.default.createServer( options, this.applications );
390
+
391
+ } else {
392
+
393
+ server = http__default.default.createServer( this.applications );
394
+
395
+ }
396
+
397
+ server.name = configElement.name || `${ ( configElement.name ) ? configElement.name : `Server_${ configId }` }`;
398
+ server.maxHeadersCount = configElement.max_headers_count;
399
+ server.timeout = configElement.timeout;
400
+ server.type = configElement.type;
401
+ server.host = configElement.host;
402
+ server.port = configElement.port;
403
+ server.env = configElement.env;
404
+ server.listen( configElement.port, configElement.host, () => {
405
+ this.logger.log( `${ server.name } start listening on ${ server.type }://${ server.host }:${ server.port } at ${ new Date() } under ${ server.env } environment.` );
406
+ } );
407
+ server.on( 'connection', connection => {
408
+ this.connections.push( connection );
409
+ connection.on( 'close', () => {
410
+ this.connections = this.connections.filter( curr => curr !== connection );
411
+ } );
412
+ } );
413
+
414
+ this.servers.set( server.name, server );
415
+
416
+ }
417
+
418
+ }
419
+
420
+ /**
421
+ *
422
+ * @param databaseKey
423
+ * @param eventName
424
+ * @param callback
425
+ */
426
+ databaseOn( databaseKey, eventName, callback ) {} // eslint-disable-line no-unused-vars
427
+
428
+ serverOn( serverName, eventName, callback ) {
429
+
430
+ this.servers[ serverName ].on( eventName, callback );
431
+
432
+ }
433
+
434
+ serversOn( serverKey, eventName, callback ) {
435
+
436
+ //TODO: filter availaible events
437
+ // [ 'request', 'connection', 'close', 'timeout', 'checkContinue', 'connect', 'upgrade', 'clientError' ]
438
+ for ( let serverKey in this.servers ) {
439
+ this.serverOn( serverKey, eventName, callback );
440
+ }
441
+
442
+ }
443
+
444
+ start() {
445
+
446
+ }
447
+
448
+ stop( callback ) {
449
+
450
+ const numberOfServers = this.servers.size;
451
+ const numberOfDatabases = this.databases.size;
452
+ let shutDownServers = 0;
453
+ let closedDatabases = 0;
454
+
455
+ if ( allClosed() ) { return }
456
+
457
+ for ( const [ databaseName, database ] of this.databases ) {
458
+
459
+ database.close( () => {
460
+
461
+ closedDatabases++;
462
+ this.logger.log( `Connection to ${ databaseName } is closed.` );
463
+
464
+ allClosed();
465
+
466
+ } );
467
+
468
+ }
469
+
470
+ for ( let connection of this.connections ) {
471
+ connection.end();
472
+ }
473
+
474
+ for ( const [ serverName, server ] of this.servers ) {
475
+
476
+ server.close( () => {
477
+
478
+ shutDownServers++;
479
+ this.logger.log( `The ${ serverName } listening on ${ server.type }://${ server.host }:${ server.port } is shutted down.` );
480
+
481
+ allClosed();
482
+
483
+ } );
484
+
485
+ }
486
+
487
+ function allClosed() {
488
+
489
+ if ( shutDownServers < numberOfServers ) {
490
+ return false
491
+ }
492
+
493
+ if ( closedDatabases < numberOfDatabases ) {
494
+ return false
495
+ }
496
+
497
+ if ( callback ) { callback(); }
498
+
499
+ }
500
+
501
+ }
502
+
503
+ closeServers() {
504
+
505
+ }
506
+
507
+ }
508
+
509
+ exports.TBackendManager = TBackendManager;
510
+ //# sourceMappingURL=itee-server.cjs.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"itee-server.cjs.js","sources":["../sources/TBackendManager.js"],"sourcesContent":["/**\n * @author [Tristan Valcke]{@link https://github.com/Itee}\n * @license [BSD-3-Clause]{@link https://opensource.org/licenses/BSD-3-Clause}\n *\n * @file Todo\n *\n * @example Todo\n *\n */\n\nimport express from 'express'\nimport http from 'http'\nimport https from 'https'\nimport {\n DefaultLogger,\n TAbstractObject\n} from 'itee-core'\n//todo: import Databases from 'itee-database'\nimport {\n isArray,\n isBlankString,\n isDefined,\n isEmptyString,\n isNotArray,\n isNotString,\n isNull,\n isUndefined\n} from 'itee-validators'\nimport path from 'path'\n\nclass TBackendManager extends TAbstractObject {\n\n constructor( parameters = {} ) {\n\n const _parameters = {\n ...{\n logger: DefaultLogger,\n rootPath: __dirname,\n applications: [],\n databases: [],\n servers: []\n },\n ...parameters\n }\n\n super( _parameters )\n\n this.logger = _parameters.logger\n this.rootPath = _parameters.rootPath\n this.applications = express()\n this.router = express.Router\n this.databases = new Map()\n this.servers = new Map()\n this.connections = []\n\n this._initApplications( _parameters.applications )\n this._initDatabases( _parameters.databases )\n this._initServers( _parameters.servers )\n\n }\n get applications() {\n return this._applications\n }\n set applications( value ) {\n this._applications = value\n }\n get router() {\n return this._router\n }\n\n // Todo remove middleware\n set router( value ) {\n this._router = value\n }\n get databases() {\n return this._databases\n }\n set databases( value ) {\n this._databases = value\n }\n get servers() {\n return this._servers\n }\n set servers( value ) {\n this._servers = value\n }\n get rootPath() {\n\n return this._rootPath\n\n }\n set rootPath( value ) {\n\n if ( isNull( value ) ) { throw new TypeError( 'Root path cannot be null ! Expect a non empty string.' ) }\n if ( isUndefined( value ) ) { throw new TypeError( 'Root path cannot be undefined ! Expect a non empty string.' ) }\n if ( isNotString( value ) ) { throw new TypeError( `Root path cannot be an instance of ${ value.constructor.name } ! Expect a non empty string.` ) }\n if ( isEmptyString( value ) ) { throw new TypeError( 'Root path cannot be empty ! Expect a non empty string.' ) }\n if ( isBlankString( value ) ) { throw new TypeError( 'Root path cannot contain only whitespace ! Expect a non empty string.' ) }\n\n this._rootPath = value\n\n }\n setApplications( value ) {\n\n this.applications = value\n return this\n\n }\n addMiddleware( middleware ) {\n\n this.applications.use( middleware )\n return this\n\n }\n setRouter( value ) {\n\n this.router = value\n return this\n\n }\n setDatabases( value ) {\n\n this.databases = value\n return this\n\n }\n addDatabase( databaseName, database ) {\n\n this._databases.set( databaseName, database )\n return this\n\n }\n setServers( value ) {\n\n this.servers = value\n return this\n\n }\n setRootPath( value ) {\n\n this.rootPath = value\n return this\n\n }\n\n _initApplications( config ) {\n\n if ( config.case_sensitive_routing ) { this.applications.set( 'case sensitive routing', config.case_sensitive_routing ) }\n if ( config.env ) { this.applications.set( 'env', config.env ) }\n if ( config.etag ) { this.applications.set( 'etag', config.etag ) }\n if ( config.jsonp_callback_name ) { this.applications.set( 'jsonp callback name', config.jsonp_callback_name ) }\n if ( config.jsonp_escape ) { this.applications.set( 'json escape', config.jsonp_escape ) }\n if ( config.jsonp_replacer ) { this.applications.set( 'json replacer', config.jsonp_replacer ) }\n if ( config.jsonp_spaces ) { this.applications.set( 'json spaces', config.jsonp_spaces ) }\n if ( config.query_parser ) { this.applications.set( 'query parser', config.query_parser ) }\n if ( config.strict_routing ) { this.applications.set( 'strict routing', config.strict_routing ) }\n if ( config.subdomain_offset ) { this.applications.set( 'subdomain offset', config.subdomain_offset ) }\n if ( config.trust_proxy ) { this.applications.set( 'trust proxy', config.trust_proxy ) }\n if ( config.views ) { this.applications.set( 'views', config.views ) }\n if ( config.view_cache ) { this.applications.set( 'view cache', config.view_cache ) }\n if ( config.view_engine ) { this.applications.set( 'view engine', config.view_engine ) }\n if ( config.x_powered_by ) { this.applications.set( 'x-powered-by', config.x_powered_by ) }\n\n this._initMiddlewares( config.middlewares )\n this._initRouters( config.routers )\n\n }\n\n _initMiddlewares( middlewaresConfig ) {\n\n for ( let [ name, config ] of Object.entries( middlewaresConfig ) ) {\n\n if ( isNotArray( config ) ) {\n throw new TypeError( `Invalid middlware configuration for ${ name }, expecting an array of arguments to spread to middleware module, got ${ config.constructor.name }` )\n }\n\n if ( this._initPackageMiddleware( name, config ) ) {\n\n this.logger.log( `Use ${ name } middleware from node_modules` )\n\n } else if ( this._initLocalMiddleware( name, config ) ) {\n\n this.logger.log( `Use ${ name } middleware from local folder` )\n\n } else {\n\n this.logger.error( `Unable to register the middleware ${ name } the package and/or local file doesn't seem to exist ! Skip it.` )\n\n }\n\n }\n\n }\n\n _initPackageMiddleware( name, config ) {\n\n let success = false\n\n try {\n\n this.applications.use( require( name )( ...config ) )\n success = true\n\n } catch ( error ) {\n\n if ( !error.code || error.code !== 'MODULE_NOT_FOUND' ) {\n\n this.logger.error( `The middleware \"${ name }\" seems to encounter internal error.` )\n this.logger.error( error )\n\n }\n\n }\n\n return success\n\n }\n\n _initLocalMiddleware( name, config ) {\n\n let success = false\n\n try {\n\n const localMiddlewaresPath = path.join( this.rootPath, 'middlewares', name )\n this.applications.use( require( localMiddlewaresPath )( ...config ) )\n success = true\n\n } catch ( error ) {\n\n this.logger.error( error )\n\n }\n\n return success\n\n }\n\n _initRouters( routers ) {\n\n for ( let [ baseRoute, routerPath ] of Object.entries( routers ) ) {\n\n if ( this._initPackageRouter( baseRoute, routerPath ) ) {\n\n this.logger.log( `Use ${ routerPath } router from node_modules over base route: ${ baseRoute }` )\n\n } else if ( this._initLocalRouter( baseRoute, routerPath ) ) {\n\n this.logger.log( `Use ${ routerPath } router from local folder over base route: ${ baseRoute }` )\n\n } else {\n\n this.logger.error( `Unable to register the router ${ routerPath } the package and/or local file doesn't seem to exist ! Skip it.` )\n\n }\n\n }\n\n }\n\n _initPackageRouter( baseRoute, routerPath ) {\n\n let success = false\n\n try {\n\n this.applications.use( baseRoute, require( routerPath ) )\n success = true\n\n } catch ( error ) {\n\n if ( !error.code || error.code !== 'MODULE_NOT_FOUND' ) {\n\n this.logger.error( `The router \"${ baseRoute }\" seems to encounter internal error.` )\n this.logger.error( error )\n\n }\n\n }\n\n return success\n\n }\n\n _initLocalRouter( baseRoute, routerPath ) {\n\n let success = false\n\n try {\n\n const localRoutersPath = path.join( this.rootPath, 'routers', routerPath )\n this.applications.use( baseRoute, require( localRoutersPath ) )\n success = true\n\n } catch ( error ) {\n\n if ( error instanceof TypeError && error.message === 'Found non-callable @@iterator' ) {\n\n this.logger.error( `The router \"${ baseRoute }\" seems to encounter error ! Are you using an object instead an array for router configuration ?` )\n\n }\n\n this.logger.error( error )\n\n }\n\n return success\n\n }\n\n _initDatabases( config ) {\n\n for ( let configIndex = 0, numberOfDatabasesConfigs = config.length ; configIndex < numberOfDatabasesConfigs ; configIndex++ ) {\n\n const databaseConfig = config[ configIndex ]\n const dbType = databaseConfig.type\n const dbFrom = databaseConfig.from\n const dbName = `${ ( databaseConfig.name ) ? databaseConfig.name : `${ dbType }_${ configIndex }` }`\n\n try {\n\n let database = null\n\n if ( isDefined( dbFrom ) ) {\n\n // In case user specify a package where take the database of type...\n const databasePackage = require( dbFrom )\n database = new databasePackage[ dbType ]( {\n ...{\n application: this.applications,\n router: this.router\n },\n ...databaseConfig\n } )\n\n } else {\n\n // // Else try to use auto registered database\n // database = new Databases[ dbType ]( {\n // ...{\n // application: this.applications,\n // router: this.router\n // },\n // ...databaseConfig\n // } )\n\n }\n\n // Todo move in start\n database.connect()\n\n this.databases.set( dbName, database )\n\n } catch ( error ) {\n\n this.logger.error( `Unable to create database of type ${ dbType } due to ${ error.name }` )\n this.logger.error( error.message )\n this.logger.error( error.stack )\n\n }\n\n }\n\n }\n\n _initServers( config ) {\n\n const _config = ( isArray( config ) ) ? config : [ config ]\n\n for ( let configId = 0, numberOfConfigs = _config.length ; configId < numberOfConfigs ; configId++ ) {\n\n let configElement = _config[ configId ]\n let server = null\n\n if ( configElement.type === 'https' ) {\n\n const options = {\n pfx: configElement.pfx,\n passphrase: configElement.passphrase\n }\n\n server = https.createServer( options, this.applications )\n\n } else {\n\n server = http.createServer( this.applications )\n\n }\n\n server.name = configElement.name || `${ ( configElement.name ) ? configElement.name : `Server_${ configId }` }`\n server.maxHeadersCount = configElement.max_headers_count\n server.timeout = configElement.timeout\n server.type = configElement.type\n server.host = configElement.host\n server.port = configElement.port\n server.env = configElement.env\n server.listen( configElement.port, configElement.host, () => {\n this.logger.log( `${ server.name } start listening on ${ server.type }://${ server.host }:${ server.port } at ${ new Date() } under ${ server.env } environment.` )\n } )\n server.on( 'connection', connection => {\n this.connections.push( connection )\n connection.on( 'close', () => {\n this.connections = this.connections.filter( curr => curr !== connection )\n } )\n } )\n\n this.servers.set( server.name, server )\n\n }\n\n }\n\n /**\n *\n * @param databaseKey\n * @param eventName\n * @param callback\n */\n databaseOn( databaseKey, eventName, callback ) {} // eslint-disable-line no-unused-vars\n\n serverOn( serverName, eventName, callback ) {\n\n this.servers[ serverName ].on( eventName, callback )\n\n }\n\n serversOn( serverKey, eventName, callback ) {\n\n //TODO: filter availaible events\n // [ 'request', 'connection', 'close', 'timeout', 'checkContinue', 'connect', 'upgrade', 'clientError' ]\n for ( let serverKey in this.servers ) {\n this.serverOn( serverKey, eventName, callback )\n }\n\n }\n\n start() {\n\n }\n\n stop( callback ) {\n\n const numberOfServers = this.servers.size\n const numberOfDatabases = this.databases.size\n let shutDownServers = 0\n let closedDatabases = 0\n\n if ( allClosed() ) { return }\n\n for ( const [ databaseName, database ] of this.databases ) {\n\n database.close( () => {\n\n closedDatabases++\n this.logger.log( `Connection to ${ databaseName } is closed.` )\n\n allClosed()\n\n } )\n\n }\n\n for ( let connection of this.connections ) {\n connection.end()\n }\n\n for ( const [ serverName, server ] of this.servers ) {\n\n server.close( () => {\n\n shutDownServers++\n this.logger.log( `The ${ serverName } listening on ${ server.type }://${ server.host }:${ server.port } is shutted down.` )\n\n allClosed()\n\n } )\n\n }\n\n function allClosed() {\n\n if ( shutDownServers < numberOfServers ) {\n return false\n }\n\n if ( closedDatabases < numberOfDatabases ) {\n return false\n }\n\n if ( callback ) { callback() }\n\n }\n\n }\n\n closeServers() {\n\n }\n\n}\n\nexport { TBackendManager }\n"],"names":["TAbstractObject","DefaultLogger","express","isNull","isU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return e&&e.__esModule?e:{default:e}}var n=a(e),c=a(t),l=a(s),p=a(o);
2
+ /**
3
+ * @author [Tristan Valcke]{@link https://github.com/Itee}
4
+ * @license [BSD-3-Clause]{@link https://opensource.org/licenses/BSD-3-Clause}
5
+ *
6
+ * @file Todo
7
+ *
8
+ * @example Todo
9
+ *
10
+ */
11
+ class h extends r.TAbstractObject{constructor(e={}){const t={logger:r.DefaultLogger,rootPath:__dirname,applications:[],databases:[],servers:[],...e};super(t),this.logger=t.logger,this.rootPath=t.rootPath,this.applications=n.default(),this.router=n.default.Router,this.databases=new Map,this.servers=new Map,this.connections=[],this._initApplications(t.applications),this._initDatabases(t.databases),this._initServers(t.servers)}get applications(){return this._applications}set applications(e){this._applications=e}get router(){return this._router}set router(e){this._router=e}get databases(){return this._databases}set databases(e){this._databases=e}get servers(){return this._servers}set servers(e){this._servers=e}get rootPath(){return this._rootPath}set rootPath(e){if(i.isNull(e))throw new TypeError("Root path cannot be null ! Expect a non empty string.");if(i.isUndefined(e))throw new TypeError("Root path cannot be undefined ! Expect a non empty string.");if(i.isNotString(e))throw new TypeError(`Root path cannot be an instance of ${e.constructor.name} ! Expect a non empty string.`);if(i.isEmptyString(e))throw new TypeError("Root path cannot be empty ! Expect a non empty string.");if(i.isBlankString(e))throw new TypeError("Root path cannot contain only whitespace ! Expect a non empty string.");this._rootPath=e}setApplications(e){return this.applications=e,this}addMiddleware(e){return this.applications.use(e),this}setRouter(e){return this.router=e,this}setDatabases(e){return this.databases=e,this}addDatabase(e,t){return this._databases.set(e,t),this}setServers(e){return this.servers=e,this}setRootPath(e){return this.rootPath=e,this}_initApplications(e){e.case_sensitive_routing&&this.applications.set("case sensitive routing",e.case_sensitive_routing),e.env&&this.applications.set("env",e.env),e.etag&&this.applications.set("etag",e.etag),e.jsonp_callback_name&&this.applications.set("jsonp callback name",e.jsonp_callback_name),e.jsonp_escape&&this.applications.set("json escape",e.jsonp_escape),e.jsonp_replacer&&this.applications.set("json replacer",e.jsonp_replacer),e.jsonp_spaces&&this.applications.set("json spaces",e.jsonp_spaces),e.query_parser&&this.applications.set("query parser",e.query_parser),e.strict_routing&&this.applications.set("strict routing",e.strict_routing),e.subdomain_offset&&this.applications.set("subdomain offset",e.subdomain_offset),e.trust_proxy&&this.applications.set("trust proxy",e.trust_proxy),e.views&&this.applications.set("views",e.views),e.view_cache&&this.applications.set("view cache",e.view_cache),e.view_engine&&this.applications.set("view engine",e.view_engine),e.x_powered_by&&this.applications.set("x-powered-by",e.x_powered_by),this._initMiddlewares(e.middlewares),this._initRouters(e.routers)}_initMiddlewares(e){for(let[t,s]of Object.entries(e)){if(i.isNotArray(s))throw new TypeError(`Invalid middlware configuration for ${t}, expecting an array of arguments to spread to middleware module, got ${s.constructor.name}`);this._initPackageMiddleware(t,s)?this.logger.log(`Use ${t} middleware from node_modules`):this._initLocalMiddleware(t,s)?this.logger.log(`Use ${t} middleware from local folder`):this.logger.error(`Unable to register the middleware ${t} the package and/or local file doesn't seem to exist ! Skip it.`)}}_initPackageMiddleware(e,t){let s=!1;try{this.applications.use(require(e)(...t)),s=!0}catch(t){t.code&&"MODULE_NOT_FOUND"===t.code||(this.logger.error(`The middleware "${e}" seems to encounter internal error.`),this.logger.error(t))}return s}_initLocalMiddleware(e,t){let s=!1;try{const r=p.default.join(this.rootPath,"middlewares",e);this.applications.use(require(r)(...t)),s=!0}catch(e){this.logger.error(e)}return s}_initRouters(e){for(let[t,s]of Object.entries(e))this._initPackageRouter(t,s)?this.logger.log(`Use ${s} router from node_modules over base route: ${t}`):this._initLocalRouter(t,s)?this.logger.log(`Use ${s} router from local folder over base route: ${t}`):this.logger.error(`Unable to register the router ${s} the package and/or local file doesn't seem to exist ! Skip it.`)}_initPackageRouter(e,t){let s=!1;try{this.applications.use(e,require(t)),s=!0}catch(t){t.code&&"MODULE_NOT_FOUND"===t.code||(this.logger.error(`The router "${e}" seems to encounter internal error.`),this.logger.error(t))}return s}_initLocalRouter(e,t){let s=!1;try{const r=p.default.join(this.rootPath,"routers",t);this.applications.use(e,require(r)),s=!0}catch(t){t instanceof TypeError&&"Found non-callable @@iterator"===t.message&&this.logger.error(`The router "${e}" seems to encounter error ! Are you using an object instead an array for router configuration ?`),this.logger.error(t)}return s}_initDatabases(e){for(let t=0,s=e.length;t<s;t++){const s=e[t],r=s.type,o=s.from,a=`${s.name?s.name:`${r}_${t}`}`;try{let e=null;if(i.isDefined(o)){e=new(require(o)[r])({application:this.applications,router:this.router,...s})}e.connect(),this.databases.set(a,e)}catch(e){this.logger.error(`Unable to create database of type ${r} due to ${e.name}`),this.logger.error(e.message),this.logger.error(e.stack)}}}_initServers(e){const t=i.isArray(e)?e:[e];for(let e=0,s=t.length;e<s;e++){let s=t[e],r=null;if("https"===s.type){const e={pfx:s.pfx,passphrase:s.passphrase};r=l.default.createServer(e,this.applications)}else r=c.default.createServer(this.applications);r.name=s.name||`${s.name?s.name:`Server_${e}`}`,r.maxHeadersCount=s.max_headers_count,r.timeout=s.timeout,r.type=s.type,r.host=s.host,r.port=s.port,r.env=s.env,r.listen(s.port,s.host,()=>{this.logger.log(`${r.name} start listening on ${r.type}://${r.host}:${r.port} at ${new Date} under ${r.env} environment.`)}),r.on("connection",e=>{this.connections.push(e),e.on("close",()=>{this.connections=this.connections.filter(t=>t!==e)})}),this.servers.set(r.name,r)}}databaseOn(e,t,s){}serverOn(e,t,s){this.servers[e].on(t,s)}serversOn(e,t,s){for(let e in this.servers)this.serverOn(e,t,s)}start(){}stop(e){const t=this.servers.size,s=this.databases.size;let r=0,i=0;if(!o()){for(const[e,t]of this.databases)t.close(()=>{i++,this.logger.log(`Connection to ${e} is closed.`),o()});for(let e of this.connections)e.end();for(const[e,t]of this.servers)t.close(()=>{r++,this.logger.log(`The ${e} listening on ${t.type}://${t.host}:${t.port} is shutted down.`),o()})}function o(){return!(r<t)&&(!(i<s)&&void(e&&e()))}}closeServers(){}}exports.TBackendManager=h;