@futdevpro/nts-dynamo 1.6.21 → 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.
- package/lib/_constants/mocks/app-extended-server.mock.js +2 -2
- package/lib/_constants/mocks/app-server.mock.js +1 -1
- package/lib/_services/core/global.service.d.ts.map +1 -1
- package/lib/_services/core/global.service.js +1 -0
- package/lib/_services/core/global.service.js.map +1 -1
- package/lib/_services/route/routing-module.service.d.ts.map +1 -1
- package/lib/_services/route/routing-module.service.js +3 -0
- package/lib/_services/route/routing-module.service.js.map +1 -1
- package/lib/_services/server/app-extended.server.d.ts.map +1 -1
- package/lib/_services/server/app-extended.server.js +23 -3
- package/lib/_services/server/app-extended.server.js.map +1 -1
- package/lib/_services/server/app.server.d.ts.map +1 -1
- package/lib/_services/server/app.server.js +17 -2
- package/lib/_services/server/app.server.js.map +1 -1
- package/lib/_services/socket/socket-client.service.d.ts +2 -1
- package/lib/_services/socket/socket-client.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-client.service.js +87 -64
- package/lib/_services/socket/socket-client.service.js.map +1 -1
- package/lib/_services/socket/socket-server.service.d.ts +1 -0
- package/lib/_services/socket/socket-server.service.d.ts.map +1 -1
- package/lib/_services/socket/socket-server.service.js +81 -67
- package/lib/_services/socket/socket-server.service.js.map +1 -1
- package/lib/tsconfig.tsbuildinfo +1 -1
- package/package.json +1 -1
- package/src/_constants/mocks/app-extended-server.mock.ts +4 -3
- package/src/_constants/mocks/app-server.mock.ts +1 -1
- package/src/_services/core/global.service.ts +1 -0
- package/src/_services/route/routing-module.service.ts +3 -0
- package/src/_services/server/app-extended.server.ts +21 -2
- package/src/_services/server/app.server.ts +17 -2
- package/src/_services/socket/socket-client.service.ts +27 -15
- package/src/_services/socket/socket-server.service.ts +16 -5
|
@@ -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
|
+
|
|
@@ -47,6 +47,7 @@ export class DynamoNTS_GlobalService extends DynamoNTS_SingletonService {
|
|
|
47
47
|
try {
|
|
48
48
|
this.instance.dbServiceCollection[dbModel.dataName] = new DynamoNTS_DBService(dbModel);
|
|
49
49
|
} catch (error) {
|
|
50
|
+
Dynamo_Log.error(`Failed to create DynamoNTS_DBService (${dbModel.dataName}).`, error);
|
|
50
51
|
error = new Dynamo_Error({
|
|
51
52
|
message: `Failed to create DynamoNTS_DBService (${dbModel.dataName}).\n` + dbModel,
|
|
52
53
|
issuerService: 'DynamoNTS_GlobalService',
|
|
@@ -139,6 +139,7 @@ export class DynamoNTS_RoutingModule {
|
|
|
139
139
|
this.mountSecureRoute(endpoint);
|
|
140
140
|
}
|
|
141
141
|
} catch (error) {
|
|
142
|
+
Dynamo_Log.error(`\nRouting module setup failed (${this.route})`, error);
|
|
142
143
|
throw new Dynamo_Error({
|
|
143
144
|
errorCode: 'NTS-RM9-100',
|
|
144
145
|
addECToUserMsg: true,
|
|
@@ -189,6 +190,7 @@ export class DynamoNTS_RoutingModule {
|
|
|
189
190
|
break;
|
|
190
191
|
|
|
191
192
|
default:
|
|
193
|
+
Dynamo_Log.error(`INVALID route type: ${endpointParams.type} - ${endpointParams.name}`);
|
|
192
194
|
throw new Dynamo_Error({
|
|
193
195
|
errorCode: 'NTS-RM9-200',
|
|
194
196
|
addECToUserMsg: true,
|
|
@@ -232,6 +234,7 @@ export class DynamoNTS_RoutingModule {
|
|
|
232
234
|
break;
|
|
233
235
|
|
|
234
236
|
default:
|
|
237
|
+
Dynamo_Log.error(`DYNAMO-NTS ERROR: INVALID route type: ${endpointParams.type} - ${endpointParams.name}`);
|
|
235
238
|
throw new Dynamo_Error({
|
|
236
239
|
errorCode: 'NTS-RM9-300',
|
|
237
240
|
addECToUserMsg: true,
|
|
@@ -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
|
-
|
|
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
|
-
|
|
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
|
-
|
|
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
|
|
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);
|
|
@@ -51,7 +51,7 @@ export abstract class DynamoNTS_SocketServerService<
|
|
|
51
51
|
protected presences: T_Presence[] = [];
|
|
52
52
|
|
|
53
53
|
protected logSetup: boolean;
|
|
54
|
-
protected logFn: boolean
|
|
54
|
+
protected logFn: boolean;
|
|
55
55
|
|
|
56
56
|
defaultErrorUserMsg =
|
|
57
57
|
`We encountered an unhandled Socket Error, ` +
|
|
@@ -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
|
-
|
|
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
|
|