@futdevpro/nts-dynamo 1.6.19 → 1.6.20

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 (63) hide show
  1. package/lib/_constants/mocks/app-extended-server.mock.d.ts +29 -0
  2. package/lib/_constants/mocks/app-extended-server.mock.d.ts.map +1 -0
  3. package/lib/_constants/mocks/app-extended-server.mock.js +99 -0
  4. package/lib/_constants/mocks/app-extended-server.mock.js.map +1 -0
  5. package/lib/_constants/mocks/app-server.mock.d.ts +1 -1
  6. package/lib/_constants/mocks/app-server.mock.d.ts.map +1 -1
  7. package/lib/_constants/mocks/app-server.mock.js +9 -5
  8. package/lib/_constants/mocks/app-server.mock.js.map +1 -1
  9. package/lib/_constants/mocks/socket-server.mock.d.ts +1 -0
  10. package/lib/_constants/mocks/socket-server.mock.d.ts.map +1 -1
  11. package/lib/_constants/mocks/socket-server.mock.js +4 -1
  12. package/lib/_constants/mocks/socket-server.mock.js.map +1 -1
  13. package/lib/_models/control-models/app-system-controls.control-model copy.d.ts +7 -0
  14. package/lib/_models/control-models/app-system-controls.control-model copy.d.ts.map +1 -0
  15. package/lib/_models/control-models/app-system-controls.control-model copy.js +13 -0
  16. package/lib/_models/control-models/app-system-controls.control-model copy.js.map +1 -0
  17. package/lib/_models/control-models/app-system-controls.control-model.d.ts +8 -0
  18. package/lib/_models/control-models/app-system-controls.control-model.d.ts.map +1 -0
  19. package/lib/_models/control-models/app-system-controls.control-model.js +14 -0
  20. package/lib/_models/control-models/app-system-controls.control-model.js.map +1 -0
  21. package/lib/_models/control-models/system-control.control-model.d.ts +6 -0
  22. package/lib/_models/control-models/system-control.control-model.d.ts.map +1 -0
  23. package/lib/_models/control-models/system-control.control-model.js +15 -0
  24. package/lib/_models/control-models/system-control.control-model.js.map +1 -0
  25. package/lib/_services/base/db.service.d.ts +1 -2
  26. package/lib/_services/base/db.service.d.ts.map +1 -1
  27. package/lib/_services/base/db.service.js +23 -15
  28. package/lib/_services/base/db.service.js.map +1 -1
  29. package/lib/_services/server/app-extended.server.d.ts +9 -0
  30. package/lib/_services/server/app-extended.server.d.ts.map +1 -1
  31. package/lib/_services/server/app-extended.server.js +230 -81
  32. package/lib/_services/server/app-extended.server.js.map +1 -1
  33. package/lib/_services/server/app-extended.server.spec.d.ts +2 -0
  34. package/lib/_services/server/app-extended.server.spec.d.ts.map +1 -0
  35. package/lib/_services/server/app-extended.server.spec.js +39 -0
  36. package/lib/_services/server/app-extended.server.spec.js.map +1 -0
  37. package/lib/_services/server/app.server.d.ts +17 -17
  38. package/lib/_services/server/app.server.d.ts.map +1 -1
  39. package/lib/_services/server/app.server.js +401 -275
  40. package/lib/_services/server/app.server.js.map +1 -1
  41. package/lib/_services/server/app.server.spec.js +17 -5
  42. package/lib/_services/server/app.server.spec.js.map +1 -1
  43. package/lib/_services/shared.service.spec.js +7 -1
  44. package/lib/_services/shared.service.spec.js.map +1 -1
  45. package/lib/_services/socket/socket-server.service.d.ts +5 -3
  46. package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
  47. package/lib/_services/socket/socket-server.service.js +32 -7
  48. package/lib/_services/socket/socket-server.service.js.map +1 -1
  49. package/lib/tsconfig.tsbuildinfo +1 -1
  50. package/package.json +2 -2
  51. package/src/_constants/mocks/app-extended-server.mock.ts +113 -0
  52. package/src/_constants/mocks/app-server.mock.ts +7 -5
  53. package/src/_constants/mocks/socket-server.mock.ts +5 -1
  54. package/src/_models/control-models/app-system-controls.control-model copy.ts +9 -0
  55. package/src/_models/control-models/app-system-controls.control-model.ts +9 -0
  56. package/src/_models/control-models/system-control.control-model.ts +13 -0
  57. package/src/_services/base/db.service.ts +25 -15
  58. package/src/_services/server/app-extended.server.spec.ts +45 -0
  59. package/src/_services/server/app-extended.server.ts +208 -41
  60. package/src/_services/server/app.server.spec.ts +17 -7
  61. package/src/_services/server/app.server.ts +277 -167
  62. package/src/_services/shared.service.spec.ts +10 -1
  63. package/src/_services/socket/socket-server.service.ts +36 -11
@@ -0,0 +1,113 @@
1
+
2
+
3
+ import { usageSessionModelParams } from '@futdevpro/fsm-dynamo/usage-module';
4
+ import { customDataModelParams } from '@futdevpro/fsm-dynamo/custom-data-module';
5
+
6
+ import { DynamoNTS_AppParams } from '../../_models/control-models/app-params.control-model';
7
+ import { DynamoNTS_GlobalServiceSettings } from '../../_models/interfaces/global-service-settings.interface';
8
+ import { DynamoNTS_PortSettings } from '../../_models/interfaces/port-settings.interface';
9
+ import { getTestRoutingModule } from '../../_modules/test';
10
+ import { getUsageRoutingModule } from '../../_modules/usage';
11
+ import { DynamoNTS_SingletonService } from '../../_services';
12
+ import { DynamoNTS_RoutingModule } from '../../_services/route/routing-module.service';
13
+ import { DynamoNTS_App } from '../../_services/server/app.server';
14
+ import { DynamoNTS_Controller_Mock } from './controller.mock';
15
+ import { AuthService_Mock } from './auth-service.mock';
16
+ import { DynamoNTS_AppExtended, dynamoNTS_globalSettings, DynamoNTS_SocketServerService } from '../../_modules/app-extended.index';
17
+ import { DynamoNTS_SocketServer_Mock } from './socket-server.mock';
18
+
19
+ /**
20
+ *
21
+ */
22
+ export class DynamoNTS_AppExtendedBase_Mock extends DynamoNTS_AppExtended {
23
+ getAppParams(): DynamoNTS_AppParams {
24
+ return new DynamoNTS_AppParams({
25
+ name: 'test-extended-base',
26
+ version: '1.0.1',
27
+ dbName: 'test-base',
28
+ });
29
+ }
30
+
31
+ getGlobalServiceCollection(): DynamoNTS_GlobalServiceSettings {
32
+ return {
33
+ authService: AuthService_Mock.getInstance(),
34
+ };
35
+ }
36
+
37
+ getPortSettings(): DynamoNTS_PortSettings {
38
+ return {};
39
+ }
40
+
41
+ getRoutingModules(): DynamoNTS_RoutingModule[] {
42
+ return [];
43
+ }
44
+
45
+ getSocketServices(): DynamoNTS_SocketServerService[] {
46
+ return [];
47
+ }
48
+ }
49
+
50
+ ////////////////////////////////////////////////////////////////////
51
+ ////////////////////////////////////////////////////////////////////
52
+ ////////////////////////////////////////////////////////////////////
53
+
54
+ /**
55
+ *
56
+ */
57
+ export class DynamoNTS_AppExtendedFull_Mock extends DynamoNTS_AppExtended {
58
+ getAppParams(): DynamoNTS_AppParams {
59
+ return new DynamoNTS_AppParams({
60
+ name: 'test-extended-full',
61
+ version: 'x.0.101',
62
+ dbName: 'test-full',
63
+ });
64
+ }
65
+
66
+
67
+ overrideDynamoNTSGlobalSettings(): void {
68
+ /* dynamoNTS_globalSettings.logSetup = true; */
69
+ /* dynamoNTS_globalSettings.defaultRouteSecurity = DynamoNTS_RouteSecurity.open; */
70
+ }
71
+
72
+ getGlobalServiceCollection(): DynamoNTS_GlobalServiceSettings {
73
+ return {
74
+ authService: AuthService_Mock.getInstance(),
75
+ /* emailServiceCollection: EmailServiceCollectionService.getInstance(), */
76
+ dbModels: [
77
+
78
+ usageSessionModelParams,
79
+ customDataModelParams,
80
+ ],
81
+ };
82
+ }
83
+
84
+ getPortSettings(): DynamoNTS_PortSettings {
85
+ return {
86
+ httpPort: 53535,
87
+ };
88
+ }
89
+
90
+ getRoutingModules(): DynamoNTS_RoutingModule[] {
91
+ return [
92
+ new DynamoNTS_RoutingModule({
93
+ route: '/test-0',
94
+ controllers: [
95
+ DynamoNTS_Controller_Mock.getInstance(),
96
+ ],
97
+ }),
98
+
99
+ getTestRoutingModule(),
100
+ getUsageRoutingModule()
101
+ ];
102
+ }
103
+
104
+ getSocketServices(): DynamoNTS_SocketServerService[] {
105
+ return [
106
+ DynamoNTS_SocketServer_Mock.getInstance(),
107
+ ];
108
+ }
109
+
110
+ async getRootServices(): Promise<DynamoNTS_SingletonService[]> {
111
+ return [];
112
+ }
113
+ }
@@ -13,6 +13,7 @@ import { DynamoNTS_RoutingModule } from '../../_services/route/routing-module.se
13
13
  import { DynamoNTS_App } from '../../_services/server/app.server';
14
14
  import { DynamoNTS_Controller_Mock } from './controller.mock';
15
15
  import { AuthService_Mock } from './auth-service.mock';
16
+ import { dynamoNTS_globalSettings } from '../global-settings.const';
16
17
 
17
18
  /**
18
19
  *
@@ -21,7 +22,7 @@ export class DynamoNTS_AppBase_Mock extends DynamoNTS_App {
21
22
  getAppParams(): DynamoNTS_AppParams {
22
23
  return new DynamoNTS_AppParams({
23
24
  name: 'test-base',
24
- version: '1.0.1',
25
+ version: 'x1.0.1',
25
26
  dbName: 'test-base',
26
27
  });
27
28
  }
@@ -52,13 +53,14 @@ export class DynamoNTS_AppFull_Mock extends DynamoNTS_App {
52
53
  getAppParams(): DynamoNTS_AppParams {
53
54
  return new DynamoNTS_AppParams({
54
55
  name: 'test-full',
55
- version: 'x.0.101',
56
+ version: 'xx.0.101',
56
57
  dbName: 'test-full',
57
58
  });
58
59
  }
59
60
 
60
61
 
61
62
  overrideDynamoNTSGlobalSettings(): void {
63
+ /* dynamoNTS_globalSettings.logSetup = true; */
62
64
  /* dynamoNTS_globalSettings.defaultRouteSecurity = DynamoNTS_RouteSecurity.open; */
63
65
  }
64
66
 
@@ -76,14 +78,14 @@ export class DynamoNTS_AppFull_Mock extends DynamoNTS_App {
76
78
 
77
79
  getPortSettings(): DynamoNTS_PortSettings {
78
80
  return {
79
- httpPort: 39393
81
+ httpPort: 10101,
80
82
  };
81
83
  }
82
84
 
83
85
  getRoutingModules(): DynamoNTS_RoutingModule[] {
84
86
  return [
85
87
  new DynamoNTS_RoutingModule({
86
- route: '/test-0',
88
+ route: '/test-extended-0',
87
89
  controllers: [
88
90
  DynamoNTS_Controller_Mock.getInstance(),
89
91
  ],
@@ -94,7 +96,7 @@ export class DynamoNTS_AppFull_Mock extends DynamoNTS_App {
94
96
  ];
95
97
  }
96
98
 
97
- getRootServices(): DynamoNTS_SingletonService[] {
99
+ async getRootServices(): Promise<DynamoNTS_SingletonService[]> {
98
100
  return [];
99
101
  }
100
102
  }
@@ -8,10 +8,14 @@ import { DynamoNTS_SocketServerService } from '../../_services/socket/socket-ser
8
8
 
9
9
  export class DynamoNTS_SocketServer_Mock extends DynamoNTS_SocketServerService<DynamoNTS_SocketPresence> {
10
10
 
11
+ static getInstance(): DynamoNTS_SocketServer_Mock {
12
+ return DynamoNTS_SocketServer_Mock.getSingletonInstance();
13
+ }
14
+
11
15
  getServiceParams(): DynamoNTS_SocketServerServiceParams<any> {
12
16
  return new DynamoNTS_SocketServerServiceParams({
13
17
  name: 'test',
14
- port: 3000,
18
+ port: 9393,
15
19
  });
16
20
  }
17
21
 
@@ -0,0 +1,9 @@
1
+
2
+
3
+ import { DynamoNTS_SystemControl } from './system-control.control-model'
4
+
5
+ export class DynamoNTS_AppExtSysControls {
6
+ appExtended: DynamoNTS_SystemControl = new DynamoNTS_SystemControl();
7
+ httpSocketServer: DynamoNTS_SystemControl = new DynamoNTS_SystemControl();
8
+ httpsSocketServer: DynamoNTS_SystemControl = new DynamoNTS_SystemControl();
9
+ }
@@ -0,0 +1,9 @@
1
+ import { DynamoNTS_SystemControl } from './system-control.control-model'
2
+
3
+
4
+ export class DynamoNTS_AppSystemControls {
5
+ app: DynamoNTS_SystemControl = new DynamoNTS_SystemControl();
6
+ mongoose: DynamoNTS_SystemControl = new DynamoNTS_SystemControl();
7
+ httpServer: DynamoNTS_SystemControl = new DynamoNTS_SystemControl();
8
+ httpsServer: DynamoNTS_SystemControl = new DynamoNTS_SystemControl();
9
+ }
@@ -0,0 +1,13 @@
1
+
2
+
3
+
4
+ export class DynamoNTS_SystemControl {
5
+ init: boolean = false;
6
+ /* failed: boolean = false; */
7
+ started: boolean = false;
8
+
9
+ getReady(): boolean {
10
+ return this.init ? this.started : true;
11
+ }
12
+ }
13
+
@@ -17,7 +17,7 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
17
17
 
18
18
  serviceName: string;
19
19
 
20
- dataModel = mongoose.model(this.dataParams.dbName, this.getSchema());
20
+ dataModel; // = mongoose.model(this.dataParams.dbName, this.getSchema());
21
21
 
22
22
  private depDataName: string;
23
23
 
@@ -34,21 +34,31 @@ export class DynamoNTS_DBService<T extends Dynamo_Metadata> {
34
34
  constructor(
35
35
  public dataParams: Dynamo_DataParams
36
36
  ){
37
- try {
38
- this.serviceName = this.constructor?.name;
39
- this.lookForDependencyDataSettings();
40
- } catch (error) {
41
- Dynamo_Log.error(
42
- `\nDynamoNTS_DBService ERROR, The dbService construction failed for ${dataParams.dataName}. ${this.serviceName}`,
43
- new Error()
44
- );
45
- /* error = new Dynamo_Error({
46
- message: `\nDynamoNTS_DBService ERROR, The construction failed for ${dataParams.dataName}. ${this.serviceName}`,
47
- error
48
- });
37
+ async () => {
38
+ try {
39
+ this.serviceName = this.constructor?.name;
40
+
41
+ try {
42
+ this.dataModel = mongoose.model(this.dataParams.dbName, this.getSchema());
43
+ } catch {
44
+ this.dataModel = mongoose.models[this.dataParams.dbName];
45
+ }
49
46
 
50
- throw error; */
51
- }
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
+ });
58
+
59
+ throw error; */
60
+ }
61
+ };
52
62
  }
53
63
 
54
64
  /**
@@ -0,0 +1,45 @@
1
+ import { DynamoNTS_AppExtendedBase_Mock, DynamoNTS_AppExtendedFull_Mock } from '../../_constants/mocks/app-extended-server.mock';
2
+
3
+ describe('DynamoNTS_AppExtended;', () => {
4
+ describe('a extended-base instance;', () => {
5
+ let app: DynamoNTS_AppExtendedBase_Mock;
6
+
7
+ beforeEach(async () => {
8
+ app = new DynamoNTS_AppExtendedBase_Mock();
9
+ await app.ready();
10
+ });
11
+
12
+ afterEach(async () => {
13
+ await app.stop();
14
+ });
15
+
16
+ it('should be created', () => {
17
+ expect(app).toBeDefined();
18
+ });
19
+
20
+ it('should be started', () => {
21
+ expect(app.started).toBeTrue();
22
+ });
23
+ });
24
+
25
+ describe('a extended-full instance;', () => {
26
+ let app: DynamoNTS_AppExtendedFull_Mock;
27
+
28
+ beforeEach(async () => {
29
+ app = new DynamoNTS_AppExtendedFull_Mock();
30
+ await app.ready();
31
+ });
32
+
33
+ afterEach(async () => {
34
+ await app.stop();
35
+ });
36
+
37
+ it('should be created', () => {
38
+ expect(app).toBeDefined();
39
+ });
40
+
41
+ it('should be started', () => {
42
+ expect(app.started).toBeTrue();
43
+ });
44
+ });
45
+ });
@@ -2,12 +2,13 @@
2
2
  import * as SocketIO from 'socket.io';
3
3
  import * as Http from 'http';
4
4
 
5
- import { Dynamo_Log } from '@futdevpro/fsm-dynamo';
5
+ import { delay, Dynamo_Array, Dynamo_Error, Dynamo_Log, second, wait } from '@futdevpro/fsm-dynamo';
6
6
 
7
7
  import { DynamoNTS_App } from './app.server';
8
8
  import { DynamoNTS_RouteSecurity } from '../../_enums/route-security.enum';
9
9
  import { DynamoNTS_SocketServerService } from '../socket/socket-server.service';
10
10
  import { DynamoNTS_SocketSecurity } from '../../_enums/socket-security.enum';
11
+ import { DynamoNTS_AppExtSysControls } from '../../_models/control-models/app-system-controls.control-model copy';
11
12
 
12
13
  /**
13
14
  * This will be the MAIN service of our server project,
@@ -110,8 +111,15 @@ import { DynamoNTS_SocketSecurity } from '../../_enums/socket-security.enum';
110
111
  * }
111
112
  */
112
113
  export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
114
+
115
+ private systemControlsExt: DynamoNTS_AppExtSysControls = new DynamoNTS_AppExtSysControls();
116
+ override get started(): boolean { return this.systemControlsExt.appExtended.started; }
117
+ private httpsSocketCount: number = 0;
118
+ private httpSocketCount: number = 0;
113
119
 
114
120
  private socketSecurity: DynamoNTS_RouteSecurity;
121
+
122
+ private httpSocketServer: Http.Server;
115
123
 
116
124
  /**
117
125
  * @example
@@ -123,27 +131,150 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
123
131
  * ];
124
132
  */
125
133
  protected socketServices: DynamoNTS_SocketServerService<any>[];
134
+ private allSocketServers: SocketIO.Server[] = [];
126
135
 
127
136
  constructor(){
128
- super();
137
+ super(true);
138
+
139
+ this.asyncConstructExt();
140
+ }
129
141
 
142
+ private async asyncConstructExt(): Promise<void> {
143
+ if (this.logFn && this.deepLog) console.log('\nfn:. asyncConstruct-extended');
130
144
  try {
145
+ this.systemControlsExt.appExtended.init = true;
146
+
131
147
  this.socketServices = this.getSocketServices();
132
148
 
133
149
  if (this.socketServices?.length) {
134
150
  this.setSocketSecurity();
135
151
 
136
- this.setupSocketServerServices();
137
-
138
- if (this.debugLog) console.log(`\nAll sockets setted up.... sockets using security: ${this.socketSecurity}`);
152
+ await this.setupSocketServerServices();
153
+ if (this.logSetup) console.log(`\nAll sockets setted up.... sockets using security: ${this.socketSecurity}`);
139
154
  } else {
140
- Dynamo_Log.warn(
155
+ Dynamo_Log.testWarn(
141
156
  '\nNo socketServices setted up while using Extended Application.',
142
157
  '\nYou should use DynamoNTS_App if you don`t need socket services.\n'
143
158
  );
144
159
  }
160
+
161
+ await this.ready();
162
+
163
+ Dynamo_Log.test(`${this.params.name} started successfully.`);
145
164
  } catch (error) {
146
- Dynamo_Log.error('\nExtended Application start failed.\n', error, '\n');
165
+ Dynamo_Log.error(`\nExtended Application: ${this.params?.name} start failed.\n`, error, '\n');
166
+ }
167
+ }
168
+
169
+ override async ready(timeout: number = 4 * second): Promise<void> {
170
+ if (this.logFn) console.log('\nfn:. ready-extended');
171
+ /* return new Promise(async (resolve, reject) => { */
172
+ /* try { */
173
+ await super.ready(timeout);
174
+
175
+ let ready: boolean = false;
176
+ const start: number = +new Date();
177
+
178
+ if (this.constructErrors.length) {
179
+ throw new Dynamo_Error({
180
+ message: `${this.params?.name} start failed. ERRORS`,
181
+ additionalContent: this.constructErrors,
182
+ error: this.constructErrors?.[0] ?? new Error()
183
+ });
184
+ }
185
+
186
+ if (this.logFn && this.deepLog) console.log('\nfn:. ready-extended: bef while', this.systemControls, this.systemControlsExt);
187
+ while (!ready && +new Date() - start < timeout) {
188
+ if (this.systemControlsExt.appExtended.init) {
189
+ ready = (
190
+ this.superStarted &&
191
+ this.systemControlsExt.httpSocketServer.getReady() &&
192
+ this.systemControlsExt.httpsSocketServer.getReady()
193
+ );
194
+ }
195
+
196
+ await wait(100);
197
+ }
198
+
199
+ if (this.constructErrors.length) {
200
+ throw new Dynamo_Error({
201
+ message: `${this.params?.name} start failed. TIMEOUT`,
202
+ additionalContent: this.constructErrors,
203
+ error: this.constructErrors?.[0] ?? new Error()
204
+ });
205
+ }
206
+
207
+ /* ready = (
208
+ this.superStarted &&
209
+ this.systemControlsExt.httpSocketServer.getReady() &&
210
+ this.systemControlsExt.httpsSocketServer.getReady()
211
+ ); */
212
+ /* console.log('T1000', ready, this.started, this.systemControlsExt.httpSocketServer.getReady(), this.systemControlsExt.httpsSocketServer.getReady(), this.systemControls, this.systemControlsExt); */
213
+ if (ready) {
214
+ this.systemControlsExt.appExtended.started = true;
215
+
216
+ if (this.logFn && this.deepLog) console.log('\nfn:. ready-extended: return');
217
+ return;
218
+ } else {
219
+ this.systemControlsExt.appExtended.started = false;
220
+
221
+ let msg: string = `${this.params?.name} start failed. UNKNOWN`;
222
+ if (this.systemControlsExt.httpSocketServer.init && !this.systemControlsExt.httpSocketServer.started) {
223
+ msg += '\nhttpSocketServer start failed.';
224
+ }
225
+ if (this.systemControlsExt.httpsSocketServer.init && !this.systemControlsExt.httpsSocketServer.started) {
226
+ msg += '\nhttpsSocketServer start failed.';
227
+ }
228
+
229
+ throw new Dynamo_Error({
230
+ errorCode: 'NTS-AES-110',
231
+ message: msg,
232
+ additionalContent: {
233
+ constructErrors: this.constructErrors,
234
+ systemControls: this.systemControls,
235
+ systemControlsExt: this.systemControlsExt,
236
+ systemReadies: {
237
+ app: this.systemControls.app.getReady(),
238
+ appExtended: this.systemControlsExt.appExtended.getReady(),
239
+ mongoose: this.systemControls.mongoose.getReady(),
240
+ httpServer: this.systemControls.httpServer.getReady(),
241
+ httpsServer: this.systemControls.httpsServer.getReady(),
242
+ httpSocketServer: this.systemControlsExt.httpSocketServer.getReady(),
243
+ httpsSocketServer: this.systemControlsExt.httpsSocketServer.getReady(),
244
+ },
245
+ },
246
+ error: this.constructErrors?.[0] ?? new Error()
247
+ });
248
+ }
249
+ /* } catch (error) {
250
+ reject(error);
251
+ } */
252
+ /* }); */
253
+ }
254
+
255
+ override async stop(): Promise<void> {
256
+ if (this.logFn) console.log('\nfn:. stop-extended');
257
+ if (this.started) {
258
+ await super.stop(true);
259
+
260
+ this.systemControlsExt.httpSocketServer.started = false;
261
+ this.systemControlsExt.httpsSocketServer.started = false;
262
+ await Dynamo_Array.asyncForEach(this.allSocketServers, async (socketServer: SocketIO.Server) => {
263
+ await new Promise<void>((resolve, reject) => {
264
+ socketServer.disconnectSockets(true);
265
+ socketServer.close((err) => {
266
+ if (err) {
267
+ reject(err);
268
+ } else {
269
+ resolve();
270
+ }
271
+ });
272
+ });
273
+ });
274
+ this.systemControlsExt.httpSocketServer.init = false;
275
+ this.systemControlsExt.httpsSocketServer.init = false;
276
+
277
+ Dynamo_Log.test(`${this.params.name} stopped successfully.`);
147
278
  }
148
279
  }
149
280
 
@@ -151,6 +282,7 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
151
282
  *
152
283
  */
153
284
  private setSocketSecurity(): void {
285
+ if (this.logFn) console.log('\nfn:. setSocketSecurity');
154
286
  this.socketServices.forEach((service: DynamoNTS_SocketServerService<any>) => {
155
287
  if (!this.socketSecurity) {
156
288
  this.socketSecurity = DynamoNTS_RouteSecurity[service.security];
@@ -163,20 +295,23 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
163
295
  /**
164
296
  *
165
297
  */
166
- private setupSocketServerServices(): void {
298
+ private async setupSocketServerServices(): Promise<void> {
167
299
  try {
168
- let httpSocketServer: Http.Server;
300
+ if (this.logFn) console.log('\nfn:. setupSocketServerServices');
301
+ /* let httpServer: Http.Server; */
169
302
  if (this.socketSecurity !== DynamoNTS_RouteSecurity.secure) {
170
303
  if (!this.openExpress) {
171
- this.initOpenExpress();
304
+ await this.initOpenExpress();
305
+ }
306
+ if (!this.httpSocketServer) {
307
+ this.httpSocketServer = Http.createServer(this.openExpress);
172
308
  }
173
- httpSocketServer = Http.createServer(this.openExpress);
174
309
  }
175
310
 
176
311
  if (this.socketSecurity !== DynamoNTS_RouteSecurity.open) {
177
312
  if (!this.httpsServer) {
178
313
  if (this.cert) {
179
- this.initSecureExpress();
314
+ await this.initSecureExpress();
180
315
  } else {
181
316
  let errorMsg: string =
182
317
  `\nYou have secure socket service, but the certification paths are not set!` +
@@ -190,7 +325,7 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
190
325
  errorMsg += '\n\nThe socket services setted to use secure server:';
191
326
  this.socketServices.forEach((service: DynamoNTS_SocketServerService<any>) => {
192
327
  if (service.security != DynamoNTS_SocketSecurity.open) {
193
- errorMsg += `\n ${service.name} (port: ${service.port})`;
328
+ errorMsg += `\n ${service?.name} (port: ${service.port})`;
194
329
  }
195
330
  });
196
331
  Dynamo_Log.error(errorMsg);
@@ -205,42 +340,74 @@ export abstract class DynamoNTS_AppExtended extends DynamoNTS_App {
205
340
  }
206
341
  }
207
342
 
208
- this.socketServices.forEach((service: DynamoNTS_SocketServerService<any>) => {
209
- try {
210
- const existingPorts: DynamoNTS_SocketServerService<any>[] = this.socketServices.filter(
211
- (mod: DynamoNTS_SocketServerService<any>) => mod.port === service.port
212
- );
343
+ await Dynamo_Array.asyncForEach(
344
+ this.socketServices,
345
+ async (service: DynamoNTS_SocketServerService<any>) => {
346
+ try {
347
+ this.systemControlsExt.httpSocketServer.init = true;
348
+ const existingPorts: DynamoNTS_SocketServerService<any>[] = this.socketServices.filter(
349
+ (mod: DynamoNTS_SocketServerService<any>) => mod.port === service.port
350
+ );
213
351
 
214
- if (1 < existingPorts.length || this.ports.httpPort === service.port || this.ports.httpsPort === service.port) {
215
- let error = new Error(`PORT DUPLICATION: ${service.port}`);
216
- let errorStack: string[] = error.stack.split('\n');
217
- errorStack.splice(1, 4);
218
- error.stack = errorStack.join('\n');
352
+ if (1 < existingPorts.length || this.ports.httpPort === service.port || this.ports.httpsPort === service.port) {
353
+ let error = new Error(`PORT DUPLICATION: ${service.port}`);
354
+ let errorStack: string[] = error.stack.split('\n');
355
+ errorStack.splice(1, 4);
356
+ error.stack = errorStack.join('\n');
219
357
 
220
- throw error;
221
- }
358
+ throw error;
359
+ }
222
360
 
223
- if (service.security === DynamoNTS_SocketSecurity.open) {
224
- if (this.debugLog) console.log(`\nsocket setup (open): ${service.name}:${service.port}`);
225
- service.setupSocketServer(new SocketIO.Server(httpSocketServer));
361
+ if (service.security === DynamoNTS_SocketSecurity.open) {
362
+ if (this.logSetup) console.log(`\nsocket setup (open): ${service?.name}:${service.port}`);
363
+ this.httpSocketCount++;
364
+ this.systemControlsExt.httpSocketServer.started = false;
226
365
 
227
- } else if (service.security === DynamoNTS_SocketSecurity.secure) {
228
- if (this.debugLog) console.log(`\nsocket setup (secure): ${service.name}:${service.port}`);
229
- service.setupSocketServer(new SocketIO.Server(this.httpsServer));
230
-
231
- } else {
232
- let error = new Error(`INVALID Socket Service security: ${service.security} on ${service.name}`);
233
- let errorStack: string[] = error.stack.split('\n');
234
- errorStack.splice(1, 4);
235
- error.stack = errorStack.join('\n');
366
+ this.allSocketServers.push(
367
+ await service.setupSocketServer(
368
+ new SocketIO.Server(this.httpSocketServer),
369
+ DynamoNTS_SocketSecurity.open,
370
+ () => {
371
+ this.httpSocketCount--;
372
+ if (this.httpSocketCount === 0) {
373
+ this.systemControlsExt.httpSocketServer.started = true;
374
+ }
375
+ }
376
+ )
377
+ );
378
+
379
+ } else if (service.security === DynamoNTS_SocketSecurity.secure) {
380
+ if (this.logSetup) console.log(`\nsocket setup (secure): ${service?.name}:${service.port}`);
381
+ this.httpsSocketCount++;
382
+ this.systemControlsExt.httpsSocketServer.started = false;
236
383
 
384
+ this.allSocketServers.push(
385
+ await service.setupSocketServer(
386
+ new SocketIO.Server(this.httpsServer),
387
+ DynamoNTS_SocketSecurity.secure,
388
+ () => {
389
+ this.httpsSocketCount--;
390
+ if (this.httpsSocketCount === 0) {
391
+ this.systemControlsExt.httpsSocketServer.started = true;
392
+ }
393
+ }
394
+ )
395
+ );
396
+
397
+ } else {
398
+ let error = new Error(`INVALID Socket Service security: ${service.security} on ${service?.name}`);
399
+ let errorStack: string[] = error.stack.split('\n');
400
+ errorStack.splice(1, 4);
401
+ error.stack = errorStack.join('\n');
402
+
403
+ throw error;
404
+ }
405
+ } catch (error) {
406
+ Dynamo_Log.error(`\nSocket Server service setup failed. (${service?.name})\n`, error, '\n');
237
407
  throw error;
238
408
  }
239
- } catch (error) {
240
- Dynamo_Log.error(`\nSocket Server service setup failed. (${service.name})\n`, error, '\n');
241
- throw error;
242
409
  }
243
- });
410
+ );
244
411
  } catch (error) {
245
412
  Dynamo_Log.error(`\nSocket Server services setup failed. (${this.socketServices?.length} services)\n`, error, '\n');
246
413
  throw error;