@futdevpro/nts-dynamo 1.6.22 → 1.6.23

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.
@@ -104,7 +104,7 @@ export class DynamoNTS_AppExtendedFull_Mock extends DynamoNTS_AppExtended {
104
104
  }),
105
105
 
106
106
  getTestRoutingModule(),
107
- getUsageRoutingModule()
107
+ getUsageRoutingModule(),
108
108
  ];
109
109
  }
110
110
 
@@ -173,7 +173,7 @@ export class DynamoNTS_AppWbMock_Mock extends DynamoNTS_AppExtended {
173
173
  }),
174
174
 
175
175
  getTestRoutingModule(),
176
- getUsageRoutingModule()
176
+ getUsageRoutingModule(),
177
177
  ];
178
178
  }
179
179
 
@@ -188,4 +188,5 @@ export class DynamoNTS_AppWbMock_Mock extends DynamoNTS_AppExtended {
188
188
  SocketClient_Mock.getInstance(),
189
189
  ];
190
190
  }
191
- }
191
+ }
192
+
@@ -95,7 +95,7 @@ export class DynamoNTS_AppFull_Mock extends DynamoNTS_App {
95
95
  }),
96
96
 
97
97
  getTestRoutingModule(),
98
- getUsageRoutingModule()
98
+ getUsageRoutingModule(),
99
99
  ];
100
100
  }
101
101
 
@@ -136,7 +136,9 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
136
136
  constructor(){
137
137
  super(true);
138
138
 
139
- this.asyncConstructExt();
139
+ this.asyncConstructExt().catch((error: any) => {
140
+ Dynamo_Log.error(`\nExtended Application: ${this.params?.name} start failed.\n`, error, '\n');
141
+ });
140
142
  }
141
143
 
142
144
  private async asyncConstructExt(): Promise<void> {
@@ -162,7 +164,24 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
162
164
 
163
165
  Dynamo_Log.test(`${this.params.name} started successfully.`);
164
166
  } catch (error) {
165
- Dynamo_Log.error(`\nExtended Application: ${this.params?.name} start failed.\n`, error, '\n');
167
+ throw new Dynamo_Error({
168
+ errorCode: 'NTS-AES-001',
169
+ error: error,
170
+ additionalContent: {
171
+ constructErrors: this.constructErrors,
172
+ systemControls: this.systemControls,
173
+ systemControlsExt: this.systemControlsExt,
174
+ systemReadies: {
175
+ app: this.systemControls.app.getReady(),
176
+ appExtended: this.systemControlsExt.appExtended.getReady(),
177
+ mongoose: this.systemControls.mongoose.getReady(),
178
+ httpServer: this.systemControls.httpServer.getReady(),
179
+ httpsServer: this.systemControls.httpsServer.getReady(),
180
+ httpSocketServer: this.systemControlsExt.httpSocketServer.getReady(),
181
+ httpsSocketServer: this.systemControlsExt.httpsSocketServer.getReady(),
182
+ },
183
+ },
184
+ });
166
185
  }
167
186
  }
168
187
 
@@ -224,7 +224,9 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
224
224
  constructor(extended?: boolean){
225
225
  super();
226
226
 
227
- this.asyncConstruct(extended);
227
+ this.asyncConstruct(extended).catch((error: any) => {
228
+ Dynamo_Log.error(`\nApplication: ${this._params.name} start failed.\n`, error);
229
+ });
228
230
  }
229
231
 
230
232
  private async asyncConstruct(extended?: boolean): Promise<void> {
@@ -301,7 +303,20 @@ export abstract class DynamoNTS_App extends DynamoNTS_SingletonService {
301
303
  }
302
304
  } catch (error) {
303
305
  this.constructErrors.push(error);
304
- Dynamo_Log.error(`\nApplication: ${this._params.name} start failed.\n`, error);
306
+ throw new Dynamo_Error({
307
+ errorCode: 'NTS-AS0-001',
308
+ error: error,
309
+ additionalContent: {
310
+ constructErrors: this.constructErrors,
311
+ systemControls: this.systemControls,
312
+ systemReadies: {
313
+ app: this.systemControls.app.getReady(),
314
+ mongoose: this.systemControls.mongoose.getReady(),
315
+ httpServer: this.systemControls.httpServer.getReady(),
316
+ httpsServer: this.systemControls.httpsServer.getReady(),
317
+ },
318
+ },
319
+ });
305
320
  }
306
321
  }
307
322
 
@@ -4,8 +4,8 @@
4
4
  import * as SocketIO from 'socket.io-client';
5
5
 
6
6
  import { DynamoNTS_SingletonService } from '../base/singleton.service';
7
- import { Dynamo_Log } from '@futdevpro/fsm-dynamo';
8
- import { delay } from '@futdevpro/fsm-dynamo/utils';
7
+ import { Dynamo_Error, Dynamo_Log } from '@futdevpro/fsm-dynamo';
8
+ import { delay, Dynamo_Array } from '@futdevpro/fsm-dynamo/utils';
9
9
  import { DynamoNTS_SocketClientServiceParams } from '../../_models/control-models/socket-client-service-params.control-model';
10
10
  import { dynamoNTS_globalSettings } from '../../_constants/global-settings.const';
11
11
  import { DynamoNTS_SocketEvent } from '../../_models/control-models/socket-event.control-model';
@@ -60,28 +60,36 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
60
60
  }),
61
61
  ];
62
62
 
63
-
64
63
  protected constructor() {
65
64
  super();
66
65
 
66
+ this.asyncConstructor().catch((error: any) => {
67
+ Dynamo_Log.error(`${this.params?.name} Socket Client Service setup failed!`, error);
68
+ });
69
+ }
70
+
71
+ private async asyncConstructor(): Promise<void> {
67
72
  try {
68
73
  this._params = this.getParams();
69
74
  this.incomingEvents = this.getIncomingEvents() ?? [];
70
75
  this.socket = SocketIO.io(`${this.params.address}:${this.params.port}`/* , this._params.socketOptions */);
71
76
 
72
- this.setupDefaultEvents();
77
+ await this.setupDefaultEvents();
73
78
 
74
- this.setupSocketEvents();
79
+ await this.setupSocketEvents();
75
80
 
76
81
  console.log(`\n${this.params?.name} Socket Client Service setup finished`);
77
82
 
78
- this.connectSocket();
83
+ await this.connectSocket();
79
84
  } catch (error) {
80
- Dynamo_Log.error(`${this.params?.name} Socket Client Service setup failed!`, error);
85
+ throw new Dynamo_Error({
86
+ errorCode: 'NTS-SCS-001',
87
+ error: error,
88
+ });
81
89
  }
82
90
  }
83
91
 
84
- private setupDefaultEvents(): void {
92
+ private async setupDefaultEvents(): Promise<void> {
85
93
  try {
86
94
  this.defaultEvents.forEach((defaultEvent: DynamoNTS_SocketEvent<any>) => {
87
95
  const eventDeclared = this.incomingEvents.find((event: DynamoNTS_SocketEvent<any>) => event.eventType === defaultEvent.eventType);
@@ -93,14 +101,15 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
93
101
  });
94
102
  } catch (error) {
95
103
  Dynamo_Log.error(`Socket Client Service Setup Default Events failed: ${this.params?.name} (${this.params?.port})`, error);
104
+ throw error;
96
105
  }
97
106
  }
98
107
 
99
- private setupSocketEvents(): void {
108
+ private async setupSocketEvents(): Promise<void> {
100
109
  try {
101
110
  if (this.log) console.log(`Setup Socket Events... (${this.params.name})`);
102
111
 
103
- this.incomingEvents.forEach((event: DynamoNTS_SocketEvent<any>) => {
112
+ await Dynamo_Array.asyncForEach(this.incomingEvents, async (event: DynamoNTS_SocketEvent<any>) => {
104
113
  if (!event.socketName) {
105
114
  event.socketName = this.name;
106
115
  }
@@ -109,26 +118,28 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
109
118
  await event.executeEventTasks(content, this.params.service);
110
119
  } catch (error) {
111
120
  Dynamo_Log.error(`Socket Event failed: ${this.params.name} (${this.params.port})`, error);
112
- this.emitEvent(DynamoNTS_SocketEventType.error, error);
121
+ await this.emitEvent(DynamoNTS_SocketEventType.error, error);
113
122
  }
114
123
  });
115
124
  });
116
125
  } catch (error) {
117
126
  Dynamo_Log.error(`Socket Client Service Setup Socket Events failed: ${this.params?.name} (${this.params?.port})`, error);
127
+ throw error;
118
128
  }
119
129
  }
120
130
 
121
- private connectSocket(): void {
131
+ private async connectSocket(): Promise<void> {
122
132
  try {
123
133
  console.log(`${this.params.name} Socket Client connecting to ${this.params.address}:${this.params.port} ...`);
124
134
 
125
135
  this.socket.connect();
126
136
 
127
137
  if (this.params.reconnect) {
128
- this.tryReconnectIfNeeded();
138
+ await this.tryReconnectIfNeeded();
129
139
  }
130
140
  } catch (error) {
131
141
  Dynamo_Log.error(`Socket Client Service Connect Socket failed: ${this.params?.name} (${this.params?.port})`, error);
142
+ throw error;
132
143
  }
133
144
  }
134
145
 
@@ -137,10 +148,11 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
137
148
  await delay(this._params.reconnectDelay);
138
149
 
139
150
  if (!this._connected) {
140
- this.connectSocket();
151
+ await this.connectSocket();
141
152
  }
142
153
  } catch (error) {
143
154
  Dynamo_Log.error(`Socket Client Service Try Reconnect failed: ${this.params?.name} (${this.params?.port})`, error);
155
+ throw error;
144
156
  }
145
157
  }
146
158
 
@@ -149,7 +161,7 @@ export abstract class DynamoNTS_SocketClientService extends DynamoNTS_SingletonS
149
161
  * @param eventType event name
150
162
  * @param content event content
151
163
  */
152
- protected emitEvent(eventType: string, content: any): void {
164
+ protected async emitEvent(eventType: string, content: any): Promise<void> {
153
165
  try {
154
166
  console.log(`\n<== outgoing ${this.name} socket event: ${eventType}`);
155
167
  this.socket.emit(eventType, content);
@@ -60,23 +60,32 @@ export abstract class DynamoNTS_SocketServerService<
60
60
  constructor(){
61
61
  super();
62
62
 
63
+ this.asyncConstructor().catch((error: any) => {
64
+ Dynamo_Log.error(`Socket Server Service setup failed: ${this.params?.name} (${this.params?.port})`, error);
65
+ });
66
+ }
67
+
68
+ private async asyncConstructor(): Promise<void> {
63
69
  try {
64
70
  this.logSetup = dynamoNTS_globalSettings.logSetup;
65
71
  this.params = this.getServiceParams();
66
72
  this.incomingEvents = this.getIncomingEvents() ?? [];
67
-
68
- this.prepareEvents();
73
+
74
+ await this.prepareEvents();
69
75
 
70
76
  if (this.logSetup) console.log(`Socket Server Service setup done: ${this.params.name} (${this.params.port}) serurity: ${this.params.security}\n`);
71
77
  } catch (error) {
72
- Dynamo_Log.error(`Socket Server Service setup failed: ${this.params?.name} (${this.params?.port})`, error);
78
+ throw new Dynamo_Error({
79
+ errorCode: 'NTS-SSS-001',
80
+ error: error,
81
+ });
73
82
  }
74
83
  }
75
84
 
76
85
  /**
77
86
  * You must setup events and required services for this function
78
87
  */
79
- private prepareEvents(): void {
88
+ private async prepareEvents(): Promise<void> {
80
89
  try {
81
90
  const connectEventIndex = this.incomingEvents.findIndex((event: DynamoNTS_SocketEvent<any>) => event.eventType === DynamoNTS_SocketEventType.connection);
82
91
  if (0 <= connectEventIndex) {
@@ -142,6 +151,7 @@ export abstract class DynamoNTS_SocketServerService<
142
151
  });
143
152
  } catch (error) {
144
153
  Dynamo_Log.error(`Socket Server Service - Event Preparation setup failed: ${this.params?.name} (${this.params?.port})`, error);
154
+ throw error;
145
155
  }
146
156
  }
147
157
 
@@ -266,6 +276,7 @@ export abstract class DynamoNTS_SocketServerService<
266
276
  }
267
277
  } catch (error) {
268
278
  Dynamo_Log.error(`Socket Subscription Removal failed: ${this.params?.name} (${this.params?.port})`, error);
279
+ throw error;
269
280
  }
270
281
  }
271
282