@nsshunt/stsappframework 2.19.157 → 2.19.159

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 (76) hide show
  1. package/dist/authDefs.js.map +1 -1
  2. package/dist/authutilsnode.js +1 -1
  3. package/dist/authutilsnode.js.map +1 -1
  4. package/dist/commonTypes.js.map +1 -1
  5. package/dist/index.js.map +1 -1
  6. package/dist/masterprocessbase.js +25 -22
  7. package/dist/masterprocessbase.js.map +1 -1
  8. package/dist/network.js.map +1 -1
  9. package/dist/processbase.js +4 -3
  10. package/dist/processbase.js.map +1 -1
  11. package/dist/processbrokerworker.js.map +1 -1
  12. package/dist/processcollectorworker.js.map +1 -1
  13. package/dist/processoptions.js.map +1 -1
  14. package/dist/server.js +1 -1
  15. package/dist/server.js.map +1 -1
  16. package/dist/singleprocessbase.js +3 -1
  17. package/dist/singleprocessbase.js.map +1 -1
  18. package/dist/socketioHelper.js.map +1 -1
  19. package/dist/stscontrollerbase.js.map +1 -1
  20. package/dist/stslatencycontroller.js.map +1 -1
  21. package/dist/stslatencyroute.js.map +1 -1
  22. package/dist/stsrouterbase.js.map +1 -1
  23. package/dist/validation/errors.js.map +1 -1
  24. package/dist/workerprocessbase.js +3 -1
  25. package/dist/workerprocessbase.js.map +1 -1
  26. package/dist/workerprocessbase.test.js +2 -1
  27. package/dist/workerprocessbase.test.js.map +1 -1
  28. package/package.json +4 -1
  29. package/{authutilsnode.ts → src/authutilsnode.ts} +12 -8
  30. package/{commonTypes.ts → src/commonTypes.ts} +8 -8
  31. package/{masterprocessbase.ts → src/masterprocessbase.ts} +37 -39
  32. package/{network.ts → src/network.ts} +1 -1
  33. package/{processbase.ts → src/processbase.ts} +22 -20
  34. package/{processbrokerworker.ts → src/processbrokerworker.ts} +1 -1
  35. package/{processcollectorworker.ts → src/processcollectorworker.ts} +1 -1
  36. package/{server.ts → src/server.ts} +4 -4
  37. package/{singleprocessbase.ts → src/singleprocessbase.ts} +13 -11
  38. package/{stslatencycontroller.ts → src/stslatencycontroller.ts} +1 -1
  39. package/{workerprocessbase.ts → src/workerprocessbase.ts} +20 -17
  40. package/tsconfig.json +16 -14
  41. package/types/authDefs.d.ts.map +1 -1
  42. package/types/authutilsnode.d.ts +5 -2
  43. package/types/authutilsnode.d.ts.map +1 -1
  44. package/types/commonTypes.d.ts +5 -5
  45. package/types/commonTypes.d.ts.map +1 -1
  46. package/types/index.d.ts.map +1 -1
  47. package/types/masterprocessbase.d.ts +3 -3
  48. package/types/masterprocessbase.d.ts.map +1 -1
  49. package/types/network.d.ts.map +1 -1
  50. package/types/processbase.d.ts +4 -4
  51. package/types/processbase.d.ts.map +1 -1
  52. package/types/processbrokerworker.d.ts.map +1 -1
  53. package/types/processcollectorworker.d.ts.map +1 -1
  54. package/types/processoptions.d.ts.map +1 -1
  55. package/types/server.d.ts +2 -1
  56. package/types/server.d.ts.map +1 -1
  57. package/types/singleprocessbase.d.ts +3 -3
  58. package/types/singleprocessbase.d.ts.map +1 -1
  59. package/types/socketioHelper.d.ts.map +1 -1
  60. package/types/stscontrollerbase.d.ts.map +1 -1
  61. package/types/stslatencycontroller.d.ts.map +1 -1
  62. package/types/stslatencyroute.d.ts.map +1 -1
  63. package/types/stsrouterbase.d.ts.map +1 -1
  64. package/types/validation/errors.d.ts.map +1 -1
  65. package/types/workerprocessbase.d.ts +6 -4
  66. package/types/workerprocessbase.d.ts.map +1 -1
  67. package/types/workerprocessbase.test.d.ts.map +1 -1
  68. /package/{authDefs.ts → src/authDefs.ts} +0 -0
  69. /package/{index.ts → src/index.ts} +0 -0
  70. /package/{processoptions.ts → src/processoptions.ts} +0 -0
  71. /package/{socketioHelper.ts → src/socketioHelper.ts} +0 -0
  72. /package/{stscontrollerbase.ts → src/stscontrollerbase.ts} +0 -0
  73. /package/{stslatencyroute.ts → src/stslatencyroute.ts} +0 -0
  74. /package/{stsrouterbase.ts → src/stsrouterbase.ts} +0 -0
  75. /package/{validation → src/validation}/errors.ts +0 -0
  76. /package/{workerprocessbase.test.ts → src/workerprocessbase.test.ts} +0 -0
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@nsshunt/stsappframework",
3
- "version": "2.19.157",
3
+ "version": "2.19.159",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "types": "./types/index.d.ts",
@@ -25,9 +25,12 @@
25
25
  "devDependencies": {
26
26
  "@babel/preset-env": "^7.21.4",
27
27
  "@babel/preset-typescript": "^7.21.4",
28
+ "@types/cookie-parser": "^1.4.3",
28
29
  "@types/debug": "^4.1.7",
29
30
  "@types/express": "^4.17.17",
30
31
  "@types/jest": "^29.5.0",
32
+ "@types/pg": "^8.6.6",
33
+ "@types/uuid": "^9.0.1",
31
34
  "@typescript-eslint/eslint-plugin": "^5.57.1",
32
35
  "@typescript-eslint/parser": "^5.57.1",
33
36
  "eslint": "^8.38.0",
@@ -6,16 +6,20 @@ import { AppFrameworkErrorCode } from './validation/errors'
6
6
 
7
7
  import { StatusCodes } from 'http-status-codes';
8
8
 
9
+ export interface IAuthUtilsNodeOptions {
10
+ permissions: string[]
11
+ }
12
+
9
13
  export class AuthUtilsNode
10
14
  {
11
- #cookiejar: tough.CookieJar = null;
15
+ #cookiejar: tough.CookieJar;
12
16
 
13
17
  constructor() {
14
18
  this.#cookiejar = new tough.CookieJar();
15
19
  }
16
20
 
17
- VerifyRequestMiddlewareFactory(options) {
18
- return async function(req, res, next) {
21
+ VerifyRequestMiddlewareFactory(options: IAuthUtilsNodeOptions) {
22
+ return async function(req: any, res: any, next: any) {
19
23
  if (options.permissions) {
20
24
  const scopes = req.auth.scope.split(' ');
21
25
  const requiredPermissions = [ ];
@@ -51,7 +55,7 @@ export class AuthUtilsNode
51
55
  }
52
56
  */
53
57
 
54
- async verifyRequestMiddleware(req, res, next)
58
+ async verifyRequestMiddleware(req: any, res: any, next: any)
55
59
  {
56
60
  next();
57
61
  /*
@@ -75,15 +79,15 @@ export class AuthUtilsNode
75
79
  */
76
80
  }
77
81
 
78
- SetCookiesToJar = async (headers: string[], endpoint: string): Promise<tough.Cookie[]> =>
82
+ SetCookiesToJar = async (headers: Record<string, any>, endpoint: string): Promise<tough.Cookie[]> =>
79
83
  {
80
84
  if (headers['set-cookie']) {
81
- headers['set-cookie'].map((headerCookie) => {
82
- const cookie = tough.Cookie.parse(headerCookie);
85
+ headers['set-cookie'].map((headerCookie: any) => {
86
+ const cookie: any = tough.Cookie.parse(headerCookie);
83
87
  this.#cookiejar.setCookieSync(cookie, endpoint);
84
88
  });
85
89
  } else {
86
- const cookie = tough.Cookie.parse(headers['set-cookie']);
90
+ const cookie: any = tough.Cookie.parse(headers['set-cookie']);
87
91
  this.#cookiejar.setCookieSync(cookie, endpoint);
88
92
  }
89
93
 
@@ -34,15 +34,15 @@ export interface IProcessBase extends STSOptionsBase {
34
34
  CollectAdditionalTelemetry(): void
35
35
  ProcessStartup: () => void
36
36
  UpdateInstrument: (instrumentName: Gauge, telemetry: InstrumentBaseTelemetry) => void
37
- get InstrumentController(): PublishInstrumentController
38
- LogEx: (message) => void
37
+ get InstrumentController(): PublishInstrumentController | null
38
+ LogEx: (message: any) => void
39
39
  InstrumentExists(instrumentName: Gauge): boolean
40
40
  ProcessTerminate: () => Promise<void>
41
41
  GetUIController(): any
42
- get socketIoHelper(): ISocketIoHelper
43
- set socketIoHelper(value: ISocketIoHelper)
42
+ get socketIoHelper(): ISocketIoHelper | null
43
+ set socketIoHelper(value: ISocketIoHelper | null)
44
44
  TerminateDatabase(): Promise<void>
45
- get accessLayer(): PGAccessLayer
45
+ get accessLayer(): PGAccessLayer | null
46
46
  }
47
47
 
48
48
  export interface IMasterProcessBase extends IProcessBase {
@@ -57,7 +57,7 @@ export interface IMasterProcessBase extends IProcessBase {
57
57
  DecWorkers: () => void
58
58
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
59
59
  AddWorker: (options: any) => number
60
- MasterStarted()
60
+ MasterStarted(): void
61
61
  BroadcastDataToWorkers: (command: any, data: any) => void
62
62
  }
63
63
 
@@ -92,7 +92,7 @@ export interface IWorkerProcessBase extends IProcessBase {
92
92
 
93
93
  // -----------------------------------------------------------------------------
94
94
 
95
- export type ServerEventCb = (socket, data) => void
95
+ export type ServerEventCb = (socket: any, data: any) => void
96
96
 
97
97
  export interface ServerSocketEvent {
98
98
  serverEventName: string,
@@ -180,6 +180,6 @@ export interface ISocketIoHelper
180
180
  LeaveRoom: (namespace: STSSocketIONamespace, room: STSRoom) => void
181
181
  JoinRoom: (namespace: STSSocketIONamespace, socket: STSServerSocket, room: STSRoom) => void
182
182
  SetupNamespace: (io: Server, namespace: STSNamespace, rooms: STSRoom[], autoJoinRooms: boolean, serverSocketEvents: ServerSocketEvent[]) => STSSocketIONamespace
183
- GetNamespace: (namespace) => STSSocketIONamespace
183
+ GetNamespace: (namespace: any) => STSSocketIONamespace
184
184
  DisconnectSockets: () => void
185
185
  }
@@ -4,7 +4,7 @@ import https from 'https'
4
4
 
5
5
  import axios from 'axios';
6
6
 
7
- import cluster from 'cluster'
7
+ import cluster, { Worker } from 'node:cluster'
8
8
 
9
9
  import os from 'os';
10
10
  let numCPUs = os.cpus().length;
@@ -40,18 +40,17 @@ let shuttingDown = false; //@@ make private inside class
40
40
  export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
41
41
  {
42
42
  //static WORKER_MESSAGE_EVENT = 'sts_worker_message_event';
43
-
44
43
  #masterProcessExitTime = masterProcessExitTime;
45
44
  #childProcessExitTime = childProcessExitTime;
46
45
  #siValueObject = {
47
46
  currentLoad: 'currentLoad'
48
47
  }
49
- #httpServer = null; // Prometheus cluster server. See https://github.com/siimon/prom-client/blob/master/example/cluster.js
50
- #metricsServer = null;
51
- #aggregatorRegistry = null;
52
- #httpsAgent;
48
+ #httpServer: any = null; // Prometheus cluster server. See https://github.com/siimon/prom-client/blob/master/example/cluster.js
49
+ #metricsServer: any= null;
50
+ #aggregatorRegistry: any = null;
51
+ #httpsAgent: any;
53
52
  #debug = debugModule(`proc:${process.pid}`);
54
- #checkLatency: NodeJS.Timeout = null;
53
+ #checkLatency: NodeJS.Timeout | null = null;
55
54
  #killWorkers: Record<string, string> = { };
56
55
  #workers = 1; // Start at 1 becuase of main thread
57
56
 
@@ -66,7 +65,7 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
66
65
  });
67
66
  }
68
67
 
69
- override CollectAdditionalTelemetry() {
68
+ override CollectAdditionalTelemetry(): void {
70
69
  si.get(this.#siValueObject).then(data => {
71
70
  this.UpdateInstrument(Gauge.CPU_SYSTEM_LOAD_GAUGE, {
72
71
  val: data.currentLoad.currentLoad
@@ -101,29 +100,25 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
101
100
  }
102
101
  }
103
102
 
104
- #InitCluster = (LogEx) =>
103
+ #InitCluster = (LogEx: any) =>
105
104
  {
106
- cluster.on('listening', () =>
107
- {
105
+ cluster.on('listening', () => {
108
106
  let allListening = true;
109
- for (const [, value] of Object.entries(cluster.workers))
110
- {
111
- if (value.isConnected)
112
- {
107
+ for (const worker of Object.values(cluster.workers as NodeJS.Dict<Worker>)) {
108
+ if (worker?.isConnected) {
113
109
  allListening = false;
114
110
  break;
115
111
  }
116
112
  }
117
113
 
118
- if (allListening)
119
- {
114
+ if (allListening) {
120
115
  LogEx(`Service instance started.`);
121
116
  }
122
117
  });
123
118
  };
124
119
 
125
120
  // https://github.com/siimon/prom-client/blob/master/example/cluster.js
126
- #SetupPrometheusForMaster = (LogEx) => {
121
+ #SetupPrometheusForMaster = (LogEx: any) => {
127
122
  this.#metricsServer = express();
128
123
  this.#aggregatorRegistry = new AggregatorRegistry();
129
124
 
@@ -138,12 +133,12 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
138
133
  }
139
134
  //this.#httpServer.maxConnections = 50;
140
135
 
141
- this.#metricsServer.get('/cluster_metrics', async (req, res) => {
136
+ this.#metricsServer.get('/cluster_metrics', async (req: any, res: any) => {
142
137
  try {
143
138
  const metrics = await this.#aggregatorRegistry.clusterMetrics();
144
139
  res.set('Content-Type', this.#aggregatorRegistry.contentType);
145
140
  res.send(metrics);
146
- } catch (ex) {
141
+ } catch (ex: any) {
147
142
  res.statusCode = 500;
148
143
  res.send(ex.message);
149
144
  }
@@ -196,7 +191,7 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
196
191
  return null;
197
192
  }
198
193
  return retVal.data.detail;
199
- } catch (error) {
194
+ } catch (error: any) {
200
195
  this.#debug(`Error (MasterProcessBase:#GetLatency:catch): [${error}]`.red);
201
196
  this.#debug(` url: [${url}]`.red);
202
197
  if (error.response && error.response.data) {
@@ -205,7 +200,7 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
205
200
  }
206
201
  }
207
202
 
208
- #LatencyRequestCompleted = (start) => {
203
+ #LatencyRequestCompleted = (start: any) => {
209
204
  // Update request duration histo data
210
205
  let timeInMs = 0;
211
206
  const end = process.hrtime(start);
@@ -230,11 +225,12 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
230
225
  }
231
226
 
232
227
  #_KillWorker = (id: string, signal: NodeJS.Signals, killProcess: boolean): boolean => {
233
- if (cluster.workers[id]) {
234
- if (cluster.workers[id].process) {
235
- this.LogEx(`Sending terminate message `.grey + `(initiated by ${signal})`.yellow + ` for worker PID: ${cluster.workers[id].process.pid}`.grey);
228
+ if (cluster.workers && cluster.workers[id]) {
229
+ const worker = cluster.workers[id] as Worker;
230
+ if (worker.process) {
231
+ this.LogEx(`Sending terminate message `.grey + `(initiated by ${signal})`.yellow + ` for worker PID: ${worker.process.pid}`.grey);
236
232
  const command: string = (killProcess ? 'TerminateAndKill' : 'Terminate');
237
- cluster.workers[id].process.send( { command } );
233
+ worker.process.send( { command } );
238
234
  return true;
239
235
  } else {
240
236
  this.LogEx(`Could not kill worker with id: [${id}]. The process does not exists`.red);
@@ -248,9 +244,9 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
248
244
 
249
245
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
250
246
  KillWorker = (id: string, signal: NodeJS.Signals = "SIGTERM", options: any, killProcess: boolean, allowKillAll: boolean): boolean => {
251
- if (allowKillAll || Object.keys(cluster.workers).length > 1) {
247
+ if (allowKillAll || Object.keys(cluster.workers as NodeJS.Dict<Worker>).length > 1) {
252
248
  if (id.localeCompare('0') === 0) {
253
- const keys = Object.keys(cluster.workers);
249
+ const keys = Object.keys(cluster.workers as NodeJS.Dict<Worker>);
254
250
  for (let i=keys.length-1; i > 0; i--) {
255
251
  // Kill the last one added (assumed node keeps them in order)
256
252
  id = keys[i];
@@ -325,15 +321,15 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
325
321
  this.#debug(` Processing message command: [${iPCMessagePayload.command}]`.yellow);
326
322
  switch (iPCMessagePayload.command) {
327
323
  case IPCMessageCommand.AddWorker : {
328
- const workerId = this.AddWorker(iPCMessagePayload.requestDetail.options);
324
+ const workerId = this.AddWorker(iPCMessagePayload.requestDetail?.options);
329
325
  iPCMessagePayload.responseDetail = {
330
326
  workerId
331
327
  }
332
328
  return iPCMessagePayload;
333
329
  }
334
330
  case IPCMessageCommand.DeleteWorker : {
335
- const workerId = iPCMessagePayload.requestDetail.workerId;
336
- const workerKilled = this.KillWorker(workerId, "SIGTERM", iPCMessagePayload.requestDetail.options, true, false);
331
+ const workerId = iPCMessagePayload.requestDetail?.workerId;
332
+ const workerKilled = this.KillWorker(workerId, "SIGTERM", iPCMessagePayload.requestDetail?.options, true, false);
337
333
  this.#debug(` Killed worker with id: [${workerId}]`.yellow);
338
334
  iPCMessagePayload.responseDetail = {
339
335
  workerId,
@@ -351,7 +347,7 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
351
347
 
352
348
  // eslint-disable-next-line @typescript-eslint/no-explicit-any
353
349
  #SpawnWorker = (spawnWorkerOptions?: any): number => {
354
- const workerEnv = { };
350
+ const workerEnv: any = { };
355
351
  workerEnv['STS_GSD_SII'] = JSON.stringify(this.options);
356
352
  if (spawnWorkerOptions) {
357
353
  workerEnv['STS_GSD_OPTIONS'] = JSON.stringify(spawnWorkerOptions);
@@ -385,8 +381,8 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
385
381
  return worker.id;
386
382
  };
387
383
 
388
- MasterStarted() {
389
- return null;
384
+ MasterStarted(): void { // eslint-disable @typescript-eslint/no-empty-function
385
+
390
386
  }
391
387
 
392
388
  SetupServerEx = async () =>
@@ -494,7 +490,7 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
494
490
  });
495
491
 
496
492
 
497
- const GetSignalColour = (signal) =>
493
+ const GetSignalColour = (signal: any) =>
498
494
  {
499
495
  let msgcolor = null;
500
496
  if (signal && signal === 'SIGINT')
@@ -513,7 +509,7 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
513
509
  // instrument timers (gauge etc.)
514
510
  // publisher
515
511
  // terminate UI (if loaded)
516
- const Terminate = async (signal) =>
512
+ const Terminate = async (signal: any) =>
517
513
  {
518
514
  if (shuttingDown === false)
519
515
  {
@@ -565,7 +561,9 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
565
561
  if (this.InstrumentController && this.InstrumentController.Workers.length > 0) {
566
562
  LogEx(`Ending publisher.`);
567
563
  setTimeout(() => {
568
- this.InstrumentController.InstrumentTerminate();
564
+ if (this.InstrumentController) {
565
+ this.InstrumentController.InstrumentTerminate();
566
+ }
569
567
  }, 100);
570
568
  }
571
569
 
@@ -611,12 +609,12 @@ export class MasterProcessBase extends ProcessBase implements IMasterProcessBase
611
609
  LogEx(`Master process:${process.pid} started`.green);
612
610
  }
613
611
 
614
- BroadcastDataToWorkers = (command, data) => {
612
+ BroadcastDataToWorkers = (command: any, data: any) => {
615
613
  try {
616
614
  for (const id in cluster.workers) {
617
615
  try {
618
616
  //@@LogEx(`Sending message to worker PID: ${cluster.workers[id].process.pid}`.grey);
619
- cluster.workers[id].process.send( { command: command, data: data } );
617
+ (cluster.workers[id] as Worker).process.send( { command: command, data: data } );
620
618
  } catch (error) {
621
619
  //@@LogEx(error);
622
620
  }
@@ -6,7 +6,7 @@ export function GetNetworkInterfaces(): NetworkInterfaces {
6
6
  const nets = os.networkInterfaces();
7
7
  const results: NetworkInterfaces = { };
8
8
  for (const name of Object.keys(nets)) {
9
- for (const net of nets[name]) {
9
+ for (const net of nets[name] as any) {
10
10
  // Skip over non-IPv4 and internal (i.e. 127.0.0.1) addresses
11
11
  if (net.family === 'IPv4' && !net.internal) {
12
12
  if (!results[name]) {
@@ -28,16 +28,16 @@ import os from 'os';
28
28
 
29
29
  import { IProcessBase, ISocketIoHelper } from './commonTypes'
30
30
 
31
- type logFunction = (msg) => void
31
+ type logFunction = (msg: any) => void
32
32
 
33
33
  export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
34
34
  {
35
- #instrumentController: PublishInstrumentController = null;
36
- #systemInformationInterval: NodeJS.Timer = null;
37
- #socketIoHelper: ISocketIoHelper = null;
38
- #accessLayer: PGAccessLayer = null;
39
- #poolManager: PGPoolManager = null;
40
- #logEx: logFunction = null;
35
+ #instrumentController: PublishInstrumentController | null = null;
36
+ #systemInformationInterval: NodeJS.Timer | null = null;
37
+ #socketIoHelper: ISocketIoHelper | null = null;
38
+ #accessLayer: PGAccessLayer | null = null;
39
+ #poolManager: PGPoolManager | null = null;
40
+ #logEx: logFunction | null = null;
41
41
 
42
42
  constructor(options: ProcessOptions)
43
43
  {
@@ -60,7 +60,7 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
60
60
  */
61
61
 
62
62
 
63
- #log(appName): logFunction {
63
+ #log(appName: any): logFunction {
64
64
  return (msg) =>
65
65
  {
66
66
  let prefix = '';
@@ -166,8 +166,8 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
166
166
  return [ ];
167
167
  }
168
168
 
169
- CollectAdditionalTelemetry(): void {
170
- return null;
169
+ CollectAdditionalTelemetry(): void { // eslint-disable @typescript-eslint/no-empty-function
170
+
171
171
  }
172
172
 
173
173
  ProcessStartup = () =>
@@ -217,11 +217,11 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
217
217
  }
218
218
  }
219
219
 
220
- get InstrumentController() {
220
+ get InstrumentController(): PublishInstrumentController | null {
221
221
  return this.#instrumentController;
222
222
  }
223
223
 
224
- LogEx = (message) => {
224
+ LogEx = (message: any) => {
225
225
  if (this.#logEx) {
226
226
  this.#logEx(message);
227
227
  } else {
@@ -242,7 +242,9 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
242
242
 
243
243
  ProcessTerminate = async () =>
244
244
  {
245
- clearInterval(this.#systemInformationInterval);
245
+ if (this.#systemInformationInterval) {
246
+ clearInterval(this.#systemInformationInterval);
247
+ }
246
248
  this.#systemInformationInterval = null;
247
249
  }
248
250
 
@@ -250,21 +252,21 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
250
252
  * UIController (instance of UIController) to manage a console based user interface associated for this node application.
251
253
  * @returns UIController instance to manage a console based user interface associated for this node application.
252
254
  */
253
- GetUIController() {
255
+ GetUIController(): any {
254
256
  return null;
255
257
  }
256
258
 
257
- get socketIoHelper(): ISocketIoHelper
259
+ get socketIoHelper(): ISocketIoHelper | null
258
260
  {
259
261
  return this.#socketIoHelper;
260
262
  }
261
263
 
262
- set socketIoHelper(value: ISocketIoHelper)
264
+ set socketIoHelper(value: ISocketIoHelper | null)
263
265
  {
264
266
  this.#socketIoHelper = value;
265
267
  }
266
268
 
267
- #UpdatePGPoolManagerInstrument = (data) => {
269
+ #UpdatePGPoolManagerInstrument = (data: any) => {
268
270
  this.UpdateInstrument(Gauge.CONNECTION_POOL_TOTAL_GAUGE, {
269
271
  val: data.totalCount
270
272
  } as InstrumentGaugeTelemetry);
@@ -279,13 +281,13 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
279
281
  }
280
282
 
281
283
  async TerminateDatabase() {
282
- if (this.#accessLayer) {
284
+ if (this.#accessLayer && this.#poolManager) {
283
285
  this.#poolManager.off(PGPoolManagerEventName.UpdateInstruments, this.#UpdatePGPoolManagerInstrument)
284
286
  await this.#accessLayer.enddatabase();
285
287
  }
286
288
  }
287
289
 
288
- get accessLayer(): PGAccessLayer
290
+ get accessLayer(): PGAccessLayer | null
289
291
  {
290
292
  if (this.options.useDatabase) {
291
293
  if (this.#accessLayer === null) {
@@ -293,7 +295,7 @@ export abstract class ProcessBase extends STSOptionsBase implements IProcessBase
293
295
  this.#accessLayer = new PGAccessLayer(this.#poolManager);
294
296
  (async () => {
295
297
  try {
296
- const retVal = await this.accessLayer.getResourceCount();
298
+ const retVal = await (this.accessLayer as PGAccessLayer).getResourceCount();
297
299
  if (retVal.status !== StatusCodes.OK) {
298
300
  this.LogEx(`Unable to get resources from the database. Is the database running? [${JSON.stringify(retVal)}]`.red);
299
301
  exit(1);
@@ -4,6 +4,6 @@ import { IPublishMessagePayload, PublishBrokerWorker } from '@nsshunt/stspublish
4
4
 
5
5
  const publishBrokerWorker: PublishBrokerWorker = new PublishBrokerWorker();
6
6
 
7
- parentPort.on('message', (message: IPublishMessagePayload) => {
7
+ (parentPort as any).on('message', (message: IPublishMessagePayload) => {
8
8
  publishBrokerWorker.ProcessMessage(message);
9
9
  });
@@ -4,7 +4,7 @@ import { IPublishMessagePayload, PublishCollectorWorker } from '@nsshunt/stspubl
4
4
 
5
5
  const publishCollectorWorker: PublishCollectorWorker = new PublishCollectorWorker();
6
6
 
7
- parentPort.on('message', (message: IPublishMessagePayload) => {
7
+ (parentPort as any).on('message', (message: IPublishMessagePayload) => {
8
8
  publishCollectorWorker.ProcessMessage(message);
9
9
  });
10
10
 
@@ -1,4 +1,4 @@
1
- import express from 'express';
1
+ import express, { Express } from 'express';
2
2
  import cors from 'cors';
3
3
  import cookieParser from 'cookie-parser';
4
4
 
@@ -14,7 +14,7 @@ import { Gauge, InstrumentGaugeTelemetry, InstrumentHistogramTelemetry, Instrume
14
14
 
15
15
  export class STSExpressServer
16
16
  {
17
- #app = null;
17
+ #app: Express;
18
18
 
19
19
  constructor(options: ProcessOptions, stsApp: IProcessBase)
20
20
  {
@@ -93,7 +93,7 @@ export class STSExpressServer
93
93
  }
94
94
 
95
95
  // Express error handling fall-back
96
- app.use(function(err, req, res, next) {
96
+ app.use(function(err: any, req: any, res: any, next: any) {
97
97
  //@@ add to errors metric here - perhaps break down by type
98
98
  if (err) {
99
99
  //@@console.log(err);
@@ -111,7 +111,7 @@ export class STSExpressServer
111
111
  });
112
112
  }
113
113
 
114
- get App()
114
+ get App(): Express
115
115
  {
116
116
  return this.#app;
117
117
  }
@@ -34,15 +34,15 @@ export type EventCb = (socket: any, data: any) => void
34
34
  export class SingleProcessBase extends ProcessBase implements ISingleProcessBase
35
35
  {
36
36
  #masterProcessExitTime = masterProcessExitTime;
37
- #io = null;
37
+ #io: any = null;
38
38
  #expressServer: STSExpressServer | null = null;
39
39
  #shuttingDown = false;
40
40
  #additionalInstruments = null;
41
41
  #siValueObject = {
42
42
  currentLoad: 'currentLoad'
43
43
  }
44
- #httpServer = null;
45
- #Terminate = null;
44
+ #httpServer: any = null;
45
+ #Terminate: any = null;
46
46
 
47
47
  /**
48
48
  *
@@ -57,7 +57,7 @@ export class SingleProcessBase extends ProcessBase implements ISingleProcessBase
57
57
  return this.#httpServer;
58
58
  }
59
59
 
60
- CollectAdditionalTelemetry() {
60
+ override CollectAdditionalTelemetry(): void {
61
61
  si.get(this.#siValueObject).then(data => {
62
62
  this.UpdateInstrument(Gauge.CPU_SYSTEM_LOAD_GAUGE, {
63
63
  val: data.currentLoad.currentLoad
@@ -78,7 +78,7 @@ export class SingleProcessBase extends ProcessBase implements ISingleProcessBase
78
78
  * UIController (instance of UIController) to manage a console based user interface associated for this node application.
79
79
  * @returns UIController instance to manage a console based user interface associated for this node application. Null for no capability.
80
80
  */
81
- override GetUIController() {
81
+ override GetUIController(): any {
82
82
  return null;
83
83
  }
84
84
 
@@ -173,7 +173,7 @@ export class SingleProcessBase extends ProcessBase implements ISingleProcessBase
173
173
  LogEx(`CPU: ${JSON.stringify(sysinfo.cpu)}`);
174
174
  LogEx(`Memory: ${JSON.stringify(sysinfo.mem)}`);
175
175
 
176
- const GetSignalColour = (signal) =>
176
+ const GetSignalColour = (signal: any) =>
177
177
  {
178
178
  let msgcolor = null;
179
179
  if (signal === 'SIGINT')
@@ -194,7 +194,7 @@ export class SingleProcessBase extends ProcessBase implements ISingleProcessBase
194
194
  // instrument timers (gauge etc.)
195
195
  // publisher
196
196
  // terminate UI (if loaded)
197
- const Terminate = async (signal) =>
197
+ const Terminate = async (signal: any) =>
198
198
  {
199
199
  if (this.#shuttingDown === false)
200
200
  {
@@ -249,7 +249,9 @@ export class SingleProcessBase extends ProcessBase implements ISingleProcessBase
249
249
  if (this.InstrumentController && this.InstrumentController.Workers.length > 0) {
250
250
  LogEx(`Ending publisher.`);
251
251
  setTimeout(() => {
252
- this.InstrumentController.InstrumentTerminate();
252
+ if (this.InstrumentController) {
253
+ this.InstrumentController.InstrumentTerminate();
254
+ }
253
255
  }, 100);
254
256
  }
255
257
 
@@ -295,9 +297,9 @@ export class SingleProcessBase extends ProcessBase implements ISingleProcessBase
295
297
  key: fs.readFileSync(this.options.httpsServerKeyPath),
296
298
  cert: fs.readFileSync(this.options.httpsServerCertificatePath)
297
299
  };
298
- this.#httpServer = createServerHttps(options, this.#expressServer.App);
300
+ this.#httpServer = createServerHttps(options, (this.#expressServer as STSExpressServer).App);
299
301
  } else {
300
- this.#httpServer = createServer(this.#expressServer.App);
302
+ this.#httpServer = createServer((this.#expressServer as STSExpressServer).App);
301
303
  }
302
304
 
303
305
  //this.#httpServer.maxConnections = 50;
@@ -320,7 +322,7 @@ export class SingleProcessBase extends ProcessBase implements ISingleProcessBase
320
322
  // this.#io.listen(3006);
321
323
  // LogEx(`socket.io init`);
322
324
 
323
- this.#io.engine.on("connection_error", (err) => {
325
+ this.#io.engine.on("connection_error", (err: any) => {
324
326
  LogEx(err.req); // the request object
325
327
  LogEx(err.code); // the error code, for example 1
326
328
  LogEx(err.message); // the error message, for example "Session ID unknown"
@@ -9,7 +9,7 @@ export class STSLatencyController extends STSControllerBase
9
9
  }
10
10
 
11
11
  // curl http://localhost:3000/api/v1/latency/latency
12
- async stslatency(req, res)
12
+ async stslatency(req: any, res: any)
13
13
  {
14
14
  try {
15
15
  const retVal = { data: `Ping Completed At: ${Date.now()}` };