@futdevpro/nts-dynamo 1.6.23 → 1.6.25

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 (27) hide show
  1. package/lib/_services/base/db.service.d.ts.map +1 -1
  2. package/lib/_services/base/db.service.js +22 -19
  3. package/lib/_services/base/db.service.js.map +1 -1
  4. package/lib/_services/route/controller.service.js +1 -1
  5. package/lib/_services/route/controller.service.js.map +1 -1
  6. package/lib/_services/server/app-extended.server.d.ts.map +1 -1
  7. package/lib/_services/server/app-extended.server.js +12 -4
  8. package/lib/_services/server/app-extended.server.js.map +1 -1
  9. package/lib/_services/server/app.server.d.ts +1 -1
  10. package/lib/_services/server/app.server.d.ts.map +1 -1
  11. package/lib/_services/server/app.server.js +12 -6
  12. package/lib/_services/server/app.server.js.map +1 -1
  13. package/lib/_services/socket/socket-client.service.d.ts +2 -1
  14. package/lib/_services/socket/socket-client.service.d.ts.map +1 -1
  15. package/lib/_services/socket/socket-client.service.js +7 -2
  16. package/lib/_services/socket/socket-client.service.js.map +1 -1
  17. package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
  18. package/lib/_services/socket/socket-server.service.js +2 -1
  19. package/lib/_services/socket/socket-server.service.js.map +1 -1
  20. package/lib/tsconfig.tsbuildinfo +1 -1
  21. package/package.json +2 -2
  22. package/src/_services/base/db.service.ts +23 -20
  23. package/src/_services/route/controller.service.ts +1 -1
  24. package/src/_services/server/app-extended.server.ts +11 -4
  25. package/src/_services/server/app.server.ts +13 -9
  26. package/src/_services/socket/socket-client.service.ts +6 -2
  27. package/src/_services/socket/socket-server.service.ts +1 -0
@@ -34,31 +34,34 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
34
34
  constructor(
35
35
  public dataParams: Dynamo_DataParams
36
36
  ){
37
- async () => {
38
- try {
39
- this.serviceName = this.constructor?.name;
37
+ try {
38
+ this.serviceName = this.constructor?.name;
40
39
 
41
- try {
42
- this.dataModel = mongoose.model(this.dataParams.dbName, this.getSchema());
43
- } catch {
40
+ try {
41
+ this.dataModel = mongoose.model(this.dataParams.dbName, this.getSchema());
42
+ } catch (error) {
43
+ if (mongoose.models[this.dataParams.dbName]) {
44
44
  this.dataModel = mongoose.models[this.dataParams.dbName];
45
+ } else {
46
+ throw error;
45
47
  }
48
+ }
46
49
 
47
- this.lookForDependencyDataSettings();
48
- // Dynamo_Log.testLog(`${this.dataParams.dbName}: ${this.dataModel === mongoose.models[this.dataParams.dbName]}`);
49
- } catch (error) {
50
- Dynamo_Log.error(
51
- `\nDynamoNTS_DBService ERROR, The dbService construction failed for ${dataParams.dataName}. ${this.serviceName}`,
52
- new Error()
53
- );
54
- /* error = new Dynamo_Error({
55
- message: `\nDynamoNTS_DBService ERROR, The construction failed for ${dataParams.dataName}. ${this.serviceName}`,
56
- error
57
- });
50
+ this.lookForDependencyDataSettings();
51
+ // Dynamo_Log.testLog(`${this.dataParams.dbName}: ${this.dataModel === mongoose.models[this.dataParams.dbName]}`);
52
+ } catch (error) {
53
+ Dynamo_Log.error(
54
+ `\nDynamoNTS_DBService ERROR, The dbService construction failed for ${dataParams.dataName}. ${this.serviceName}`,
55
+ error,
56
+ new Error()
57
+ );
58
+ /* error = new Dynamo_Error({
59
+ message: `\nDynamoNTS_DBService ERROR, The construction failed for ${dataParams.dataName}. ${this.serviceName}`,
60
+ error
61
+ });
58
62
 
59
- throw error; */
60
- }
61
- };
63
+ throw error; */
64
+ }
62
65
  }
63
66
 
64
67
  /**
@@ -82,7 +82,7 @@ export abstract class DynamoNTS_Controller extends DynamoNTS_SingletonService {
82
82
  try {
83
83
  this.setupEndpoints();
84
84
  } catch (error) {
85
- Dynamo_Log.error(`\nDynamoNTS_Controller ERROR setup failed`, error);
85
+ Dynamo_Log.error(`DynamoBEController ERROR setup failed:`, error);
86
86
  }
87
87
  }
88
88
 
@@ -155,8 +155,8 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
155
155
  if (this.logSetup) console.log(`\nAll sockets setted up.... sockets using security: ${this.socketSecurity}`);
156
156
  } else {
157
157
  Dynamo_Log.testWarn(
158
- '\nNo socketServices setted up while using Extended Application.',
159
- '\nYou should use DynamoNTS_App if you don`t need socket services.\n'
158
+ 'No socketServices setted up while using Extended Application.',
159
+ '\nYou should use DynamoNTS_App if you don`t need socket services.'
160
160
  );
161
161
  }
162
162
 
@@ -164,6 +164,7 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
164
164
 
165
165
  Dynamo_Log.test(`${this.params.name} started successfully.`);
166
166
  } catch (error) {
167
+ Dynamo_Log.error(`\nExtended Application: ${this.params?.name} start failed.\n`, error, '\n');
167
168
  throw new Dynamo_Error({
168
169
  errorCode: 'NTS-AES-001',
169
170
  error: error,
@@ -208,9 +209,13 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
208
209
  this.systemControlsExt.httpSocketServer.getReady() &&
209
210
  this.systemControlsExt.httpsSocketServer.getReady()
210
211
  );
212
+ } else {
213
+ Dynamo_Log.error(`${this.params.name} APP NOT INITIALIZED while trying to get ready.`);
211
214
  }
212
215
 
213
- await wait(100);
216
+ if (!ready) {
217
+ await wait(100);
218
+ }
214
219
  }
215
220
 
216
221
  if (this.constructErrors.length) {
@@ -344,13 +349,13 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
344
349
  errorMsg += `\n ${service?.name} (port: ${service.port})`;
345
350
  }
346
351
  });
347
- Dynamo_Log.error(errorMsg);
348
352
 
349
353
  let error = new Error('Secure routes cannot be established!');
350
354
  let errorStack: string[] = error.stack.split('\n');
351
355
  errorStack.splice(1, 2);
352
356
  error.stack = errorStack.join('\n');
353
357
 
358
+ Dynamo_Log.error(errorMsg);
354
359
  throw error;
355
360
  }
356
361
  }
@@ -371,6 +376,7 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
371
376
  errorStack.splice(1, 4);
372
377
  error.stack = errorStack.join('\n');
373
378
 
379
+ Dynamo_Log.error(`\n${error.message}`);
374
380
  throw error;
375
381
  }
376
382
 
@@ -416,6 +422,7 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
416
422
  errorStack.splice(1, 4);
417
423
  error.stack = errorStack.join('\n');
418
424
 
425
+ Dynamo_Log.error(`\n${error.message}`);
419
426
  throw error;
420
427
  }
421
428
  } catch (error) {
@@ -208,11 +208,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
208
208
  protected httpServer: Http.Server;
209
209
 
210
210
  private globalService: DynamoNTS_GlobalService;
211
+ private _rootServices: DynamoNTS_SingletonService[] = [];
211
212
 
212
213
  private _routingModules: DynamoNTS_RoutingModule[] = [];
213
- /* protected get routingModules(): DynamoNTS_RoutingModule[] { return this._routingModules; } */
214
-
215
- private _rootServices: DynamoNTS_SingletonService[] = [];
216
214
 
217
215
  /**
218
216
  * setting this value to true, enables this service debug logs
@@ -303,6 +301,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
303
301
  }
304
302
  } catch (error) {
305
303
  this.constructErrors.push(error);
304
+ Dynamo_Log.error(`${this._params.name} start failed. ERRORS`, this.constructErrors);
306
305
  throw new Dynamo_Error({
307
306
  errorCode: 'NTS-AS0-001',
308
307
  error: error,
@@ -340,14 +339,18 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
340
339
  this.systemControls.httpServer.getReady() &&
341
340
  this.systemControls.httpsServer.getReady()
342
341
  );
342
+ } else {
343
+ Dynamo_Log.error(`${this.params.name} APP NOT INITIALIZED while trying to get ready.`);
343
344
  }
344
345
 
345
- await wait(100);
346
+ if (!ready) {
347
+ await wait(100);
348
+ }
346
349
  }
347
350
 
348
351
  if (timeout < +new Date() - start) {
349
352
  Dynamo_Log.error(`${this._params.name} start failed. TIMEOUT`, this.constructErrors);
350
- throw new Dynamo_Error({
353
+ throw new Dynamo_Error({
351
354
  message: `${this._params.name} start failed. TIMEOUT`,
352
355
  additionalContent: {
353
356
  constructErrors: this.constructErrors,
@@ -363,7 +366,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
363
366
 
364
367
  if (this.constructErrors.length) {
365
368
  Dynamo_Log.error(`${this._params.name} start failed. ERROR`, this.constructErrors);
366
- throw new Dynamo_Error({
369
+ throw new Dynamo_Error({
367
370
  message: `${this._params.name} start failed. ERROR`,
368
371
  additionalContent: this.constructErrors,
369
372
  });
@@ -515,13 +518,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
515
518
  });
516
519
  }
517
520
  });
518
- Dynamo_Log.error(errorMsg);
519
521
 
520
522
  let error = new Error('Open routes cannot be established!');
521
523
  let errorStack: string[] = error.stack.split('\n');
522
524
  errorStack.splice(1, 2);
523
525
  error.stack = errorStack.join('\n');
524
526
 
527
+ Dynamo_Log.error(errorMsg);
525
528
  throw error;
526
529
  }
527
530
 
@@ -552,13 +555,13 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
552
555
  });
553
556
  }
554
557
  });
555
- Dynamo_Log.error(errorMsg);
556
558
 
557
559
  let error = new Error('Secure routes cannot be established!');
558
560
  let errorStack: string[] = error.stack.split('\n');
559
561
  errorStack.splice(1, 2);
560
562
  error.stack = errorStack.join('\n');
561
563
 
564
+ Dynamo_Log.error(errorMsg);
562
565
  throw error;
563
566
  }
564
567
 
@@ -668,6 +671,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
668
671
  }
669
672
  } catch (error) {
670
673
  Dynamo_Log.error(`startExpresses failed...`, error);
674
+ throw error;
671
675
  }
672
676
  }
673
677
 
@@ -746,7 +750,7 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
746
750
  if (this.logFn && this.deepLog) console.log('\nfn:. setSecurity');
747
751
  this._routingModules.forEach((module: DynamoNTS_RoutingModule) => {
748
752
  if (!module.security) {
749
- Dynamo_Log.error(`RoutingModule security is not set for ${module.route}\n`);
753
+ Dynamo_Log.warn(`RoutingModule security is not set for ${module.route}\n`);
750
754
  } else if (!this._security) {
751
755
  this._security = module.security;
752
756
  } else if (this._security !== module.security) {
@@ -17,8 +17,6 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
17
17
  protected get params(): DynamoNTS_SocketClientServiceParams { return this._params; }
18
18
  get name(): string { return this.params.name; }
19
19
 
20
- protected log: boolean = dynamoNTS_globalSettings.logSetup;
21
-
22
20
  protected socket: SocketIO.Socket
23
21
 
24
22
  protected incomingEvents: DynamoNTS_SocketEvent<any>[];
@@ -26,6 +24,9 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
26
24
  protected _connected: boolean = false;
27
25
  get connected(): boolean { return this._connected; }
28
26
 
27
+ protected log: boolean = dynamoNTS_globalSettings.logSetup;
28
+ protected logFn: boolean;
29
+
29
30
  private defaultEvents: DynamoNTS_SocketEvent<any>[] = [
30
31
  new DynamoNTS_SocketEvent<any>({
31
32
  eventType: DynamoNTS_SocketEventType.connect,
@@ -82,6 +83,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
82
83
 
83
84
  await this.connectSocket();
84
85
  } catch (error) {
86
+ Dynamo_Log.error(`${this.params?.name} Socket Client Service setup failed!`, error);
85
87
  throw new Dynamo_Error({
86
88
  errorCode: 'NTS-SCS-001',
87
89
  error: error,
@@ -91,6 +93,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
91
93
 
92
94
  private async setupDefaultEvents(): Promise<void> {
93
95
  try {
96
+ if (this.logFn) console.log('\nFn:. setupDefaultEvents')
94
97
  this.defaultEvents.forEach((defaultEvent: DynamoNTS_SocketEvent<any>) => {
95
98
  const eventDeclared = this.incomingEvents.find((event: DynamoNTS_SocketEvent<any>) => event.eventType === defaultEvent.eventType);
96
99
  if (!eventDeclared) {
@@ -145,6 +148,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
145
148
 
146
149
  private async tryReconnectIfNeeded(): Promise<void> {
147
150
  try {
151
+ if (this.logFn) console.log(`\nFn:. tryReconnectIfNeeded`);
148
152
  await delay(this._params.reconnectDelay);
149
153
 
150
154
  if (!this._connected) {
@@ -75,6 +75,7 @@ export abstract class DynamoNTS_SocketServerService<
75
75
 
76
76
  if (this.logSetup) console.log(`Socket Server Service setup done: ${this.params.name} (${this.params.port}) serurity: ${this.params.security}\n`);
77
77
  } catch (error) {
78
+ Dynamo_Log.error(`Socket Server Service setup failed: ${this.params?.name} (${this.params?.port})`, error);
78
79
  throw new Dynamo_Error({
79
80
  errorCode: 'NTS-SSS-001',
80
81
  error: error,