@futdevpro/nts-dynamo 1.7.23 → 1.7.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@futdevpro/nts-dynamo",
3
- "version": "01.07.23",
3
+ "version": "01.07.25",
4
4
  "description": "Dynamic NodeTS (NodeJS-Typescript), MongoDB Backend System Framework by Future Development Program Ltd.",
5
5
  "scripts": {
6
6
  "prep": "npm i rimraf nodemon -g",
@@ -8,6 +8,7 @@ export enum DynamoNTS_SocketEventKey {
8
8
  subscribe = 'subscribe',
9
9
  subscriptionSuccessful = 'subscriptionSuccessful',
10
10
  unsubscribe = 'unsubscribe',
11
+ unsubscribeSuccessful = 'unsubscribeSuccessful',
11
12
  disconnect = 'disconnection',
12
13
 
13
14
  ping = 'ping',
@@ -4,7 +4,8 @@ import { dynamoNTS_globalSettings } from '../../_constants/global-settings.const
4
4
  import { DynamoNTS_SocketEventKey } from '../../_enums/http/socket-event-type.enum';
5
5
 
6
6
 
7
- export type DynamoNTS_SocketEventPreprocessTask<T = any, R = any> = (content?: T, issuer?: string) => Promise<R>;
7
+ export type DynamoNTS_SocketEventPreprocessTask<T = any, R = any> =
8
+ (content?: T, issuer?: string) => Promise<R>;
8
9
  export type DynamoNTS_SocketEventTask<T> = (content?: T, issuer?: string) => Promise<void>;
9
10
 
10
11
  /**
@@ -77,14 +78,19 @@ export class DynamoNTS_SocketEvent<T>{
77
78
  DynamoNTS_SocketEventKey.disconnect,
78
79
  ] as string[]).includes(this.eventKey)
79
80
  ) {
80
- this.logEvent = dynamoNTS_globalSettings.logMainSocketEvents || dynamoNTS_globalSettings.logAllSocketEvent;
81
+ this.logEvent = dynamoNTS_globalSettings.logMainSocketEvents ||
82
+ dynamoNTS_globalSettings.logAllSocketEvent;
81
83
  } else {
82
84
  this.logEvent = dynamoNTS_globalSettings.logAllSocketEvent;
83
85
  }
84
- this.logEventContent = set.logEventContent !== undefined ? set.logEventContent : dynamoNTS_globalSettings.logSocketEventContent;
86
+ this.logEventContent = set.logEventContent !== undefined ?
87
+ set.logEventContent : dynamoNTS_globalSettings.logSocketEventContent;
85
88
  } catch (error) {
86
89
  Dynamo_Log.error(
87
- `\nSocket Event params setup failed (${this.serviceName}): ${set.eventKey}`, error);
90
+ `\nSocket Event params setup failed (${this.serviceName}): ${set.eventKey}`,
91
+ error
92
+ );
93
+
88
94
  throw error;
89
95
  }
90
96
  }
@@ -118,15 +124,23 @@ export class DynamoNTS_SocketEvent<T>{
118
124
  await this.getPreLog(content, issuer);
119
125
  }
120
126
 
121
- await Dynamo_Array.asyncForEach(this.preProcessess, async (preProcess: DynamoNTS_SocketEventPreprocessTask<any, any>) => {
122
- content = await preProcess(content);
123
- });
127
+ await Dynamo_Array.asyncForEach(
128
+ this.preProcessess,
129
+ async (preProcess: DynamoNTS_SocketEventPreprocessTask<any, any>) => {
130
+ content = await preProcess(content);
131
+ }
132
+ );
124
133
 
125
134
  await Dynamo_Array.asyncForEach(this.tasks, async (task: DynamoNTS_SocketEventTask<T>) => {
126
135
  await task(content, issuer);
127
136
  });
128
137
  } catch (error) {
129
- Dynamo_Log.error(`Socket Event tasks failed to execute on ${this.serviceName}.... (${this.eventKey})`, error, 'content:', content);
138
+ Dynamo_Log.error(
139
+ `Socket Event tasks failed to execute on ${this.serviceName}.... (${this.eventKey})`,
140
+ error,
141
+ 'content:',
142
+ content
143
+ );
130
144
  }
131
145
  }
132
146
  }
@@ -1,5 +1,7 @@
1
1
 
2
- import { Dynamo_AnyError, Dynamo_Error, Dynamo_Error_Settings, Dynamo_Log } from '@futdevpro/fsm-dynamo';
2
+ import {
3
+ Dynamo_AnyError, Dynamo_Error, Dynamo_Error_Settings, Dynamo_Log
4
+ } from '@futdevpro/fsm-dynamo';
3
5
  import * as SocketIO from 'socket.io';
4
6
 
5
7
  /**
@@ -11,8 +13,8 @@ export class DynamoNTS_SocketPresence {
11
13
  onDestroy?: (issuerId: string) => void = id => {};
12
14
 
13
15
  defaultErrorUserMsg?: string =
14
- `We encountered an unhandled Socket Error, ` +
15
- `\nplease contact the responsible development team.`;
16
+ `We encountered an unhandled Socket Error, ` +
17
+ `\nplease contact the responsible development team.`;
16
18
 
17
19
  sockets: SocketIO.Socket[] = [];
18
20
 
@@ -26,7 +28,7 @@ export class DynamoNTS_SocketPresence {
26
28
  sockets: SocketIO.Socket[],
27
29
 
28
30
  issuer: string,
29
- },
31
+ }
30
32
  ) {
31
33
  if (!set?.issuerId) {
32
34
  throw new Dynamo_Error({
@@ -48,9 +50,11 @@ export class DynamoNTS_SocketPresence {
48
50
  if (set.serviceName) {
49
51
  this.serviceName = set.serviceName;
50
52
  }
53
+
51
54
  if (set.onDestroy) {
52
55
  this.onDestroy = set.onDestroy;
53
56
  }
57
+
54
58
  if (set.defaultErrorUserMsg) {
55
59
  this.defaultErrorUserMsg = set.defaultErrorUserMsg;
56
60
  }
@@ -78,7 +82,7 @@ export class DynamoNTS_SocketPresence {
78
82
  * @param event
79
83
  * @param content
80
84
  */
81
- emitEvent?(event: string, content: any, issuer: string) {
85
+ emitEvent?(event: string, content: any, issuer: string): void {
82
86
  /* let anyFailed: boolean = false; */
83
87
  const errors: any = [];
84
88
  const inactiveSockets: SocketIO.Socket[] = [];
@@ -95,7 +99,9 @@ export class DynamoNTS_SocketPresence {
95
99
  status: 500,
96
100
  errorCode: 'NTS-SPC-EE1',
97
101
  addECToUserMsg: true,
98
- message: `Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!\nERROR: socket[${socket.id}] is not connected!`,
102
+ message:
103
+ `Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!`+
104
+ `\nERROR: socket[${socket.id}] is not connected!`,
99
105
  userMessage: 'We encountered an unhandled Server Error, please contact the responsible development team.',
100
106
  })
101
107
  ); */
@@ -105,7 +111,9 @@ export class DynamoNTS_SocketPresence {
105
111
  }
106
112
  });
107
113
 
108
- this.sockets = this.sockets.filter(socket => !inactiveSockets.includes(socket) && socket?.connected);
114
+ this.sockets = this.sockets.filter(
115
+ socket => !inactiveSockets.includes(socket) && socket?.connected
116
+ );
109
117
 
110
118
  this.sockets.forEach((socket: SocketIO.Socket, index: number) => {
111
119
  const success: boolean = socket.emit(event, content, error => {
@@ -117,7 +125,9 @@ export class DynamoNTS_SocketPresence {
117
125
  });
118
126
 
119
127
  if (!success) {
120
- Dynamo_Log.error(`Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!(1)`);
128
+ Dynamo_Log.error(
129
+ `Emitting event '${event}' on socket(${this.serviceName})-(${index}) failed!(1)`
130
+ );
121
131
  }
122
132
  });
123
133
 
@@ -137,7 +147,7 @@ export class DynamoNTS_SocketPresence {
137
147
  additionalContent: {
138
148
  inactiveSockets: inactiveSockets,
139
149
  errors: errors,
140
- }
150
+ },
141
151
  });
142
152
 
143
153
  } else if (this.sockets.length === 0) {