@nsshunt/stsappframework 3.0.104 → 3.0.105

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 (140) hide show
  1. package/dist/authutilsnode.js +6 -7
  2. package/dist/authutilsnode.js.map +1 -1
  3. package/dist/influxdb/influxDBManager.js +16 -17
  4. package/dist/influxdb/influxDBManager.js.map +1 -1
  5. package/dist/influxdb/influxDBManagerAgent.js +9 -13
  6. package/dist/influxdb/influxDBManagerAgent.js.map +1 -1
  7. package/dist/influxdb/influxDBManagerBase.js +2 -6
  8. package/dist/influxdb/influxDBManagerBase.js.map +1 -1
  9. package/dist/influxdb/influxDBManagerService.js +10 -14
  10. package/dist/influxdb/influxDBManagerService.js.map +1 -1
  11. package/dist/instrumentationsubscriber.js +11 -15
  12. package/dist/instrumentationsubscriber.js.map +1 -1
  13. package/dist/kafka/IMKafkaManager.js +2 -6
  14. package/dist/kafka/IMKafkaManager.js.map +1 -1
  15. package/dist/kafkatesting/produce.js +1 -5
  16. package/dist/kafkatesting/produce.js.map +1 -1
  17. package/dist/masterprocessbase.js +19 -20
  18. package/dist/masterprocessbase.js.map +1 -1
  19. package/dist/processbase.js +7 -8
  20. package/dist/processbase.js.map +1 -1
  21. package/dist/server.js +1 -1
  22. package/dist/server.js.map +1 -1
  23. package/dist/singleprocessbase.js +3 -4
  24. package/dist/singleprocessbase.js.map +1 -1
  25. package/dist/tcpclient/app2.js +2 -2
  26. package/dist/tcpserver/appmaster.js +39 -16
  27. package/dist/tcpserver/appmaster.js.map +1 -1
  28. package/dist/workerprocessbase.js +3 -4
  29. package/dist/workerprocessbase.js.map +1 -1
  30. package/package.json +7 -7
  31. package/src/authutilsnode.ts +8 -10
  32. package/src/influxdb/influxDBManager.ts +16 -18
  33. package/src/influxdb/influxDBManagerAgent.ts +9 -11
  34. package/src/influxdb/influxDBManagerBase.ts +2 -4
  35. package/src/influxdb/influxDBManagerService.ts +10 -12
  36. package/src/instrumentationsubscriber.ts +11 -14
  37. package/src/kafka/IMKafkaManager.ts +2 -4
  38. package/src/kafkatesting/produce.ts +1 -3
  39. package/src/masterprocessbase.ts +32 -24
  40. package/src/processbase.ts +7 -9
  41. package/src/server.ts +1 -1
  42. package/src/singleprocessbase.ts +3 -5
  43. package/src/tcpclient/app2.ts +2 -2
  44. package/src/tcpserver/appmaster.ts +39 -17
  45. package/src/workerprocessbase.ts +3 -5
  46. package/types/authutilsnode.d.ts.map +1 -1
  47. package/types/influxdb/influxDBManager.d.ts.map +1 -1
  48. package/types/influxdb/influxDBManagerAgent.d.ts.map +1 -1
  49. package/types/influxdb/influxDBManagerBase.d.ts.map +1 -1
  50. package/types/influxdb/influxDBManagerService.d.ts.map +1 -1
  51. package/types/instrumentationsubscriber.d.ts.map +1 -1
  52. package/types/kafka/IMKafkaManager.d.ts.map +1 -1
  53. package/types/masterprocessbase.d.ts.map +1 -1
  54. package/types/processbase.d.ts +2 -2
  55. package/types/processbase.d.ts.map +1 -1
  56. package/types/singleprocessbase.d.ts.map +1 -1
  57. package/types/tcpserver/appmaster.d.ts.map +1 -1
  58. package/types/workerprocessbase.d.ts.map +1 -1
  59. package/src_working/authDefs.ts +0 -37
  60. package/src_working/authutilsnode.ts +0 -373
  61. package/src_working/commonTypes.ts +0 -239
  62. package/src_working/index.ts +0 -22
  63. package/src_working/influxdb/influxDBManager.ts +0 -970
  64. package/src_working/influxdb/influxDBManagerAgent.ts +0 -314
  65. package/src_working/influxdb/influxDBManagerBase.ts +0 -109
  66. package/src_working/influxdb/influxDBManagerService.ts +0 -373
  67. package/src_working/instrumentationsubscriber.ts +0 -283
  68. package/src_working/kafka/IMKafkaManager.ts +0 -152
  69. package/src_working/kafka/kafkaconsumer.ts +0 -82
  70. package/src_working/kafka/kafkamanager.ts +0 -186
  71. package/src_working/kafka/kafkaproducer.ts +0 -58
  72. package/src_working/kafkatesting/config.ts +0 -10
  73. package/src_working/kafkatesting/consume.ts +0 -116
  74. package/src_working/kafkatesting/produce.ts +0 -153
  75. package/src_working/masterprocessbase.ts +0 -598
  76. package/src_working/middleware/serverNetworkMiddleware.ts +0 -240
  77. package/src_working/network.ts +0 -36
  78. package/src_working/processbase.ts +0 -411
  79. package/src_working/processoptions.ts +0 -164
  80. package/src_working/publishertransports/publishTransportDirect.ts +0 -45
  81. package/src_working/publishertransports/publishTransportUtils.ts +0 -53
  82. package/src_working/server.ts +0 -141
  83. package/src_working/serverprocessbase.ts +0 -393
  84. package/src_working/singleprocessbase.ts +0 -121
  85. package/src_working/socketIoServerHelper.ts +0 -177
  86. package/src_working/stscontrollerbase.ts +0 -15
  87. package/src_working/stslatencycontroller.ts +0 -27
  88. package/src_working/stslatencyroute.ts +0 -16
  89. package/src_working/stsrouterbase.ts +0 -22
  90. package/src_working/tcpclient/app.ts +0 -19
  91. package/src_working/tcpclient/app2.ts +0 -56
  92. package/src_working/tcpserver/app.ts +0 -11
  93. package/src_working/tcpserver/appConfig.ts +0 -65
  94. package/src_working/tcpserver/appmaster.ts +0 -544
  95. package/src_working/validation/errors.ts +0 -6
  96. package/src_working/webworkertesting/app.ts +0 -49
  97. package/src_working/webworkertesting/worker.ts +0 -24
  98. package/src_working/workerprocessbase.test.ts +0 -47
  99. package/src_working/workerprocessbase.ts +0 -185
  100. package/src_working2/authDefs.ts +0 -37
  101. package/src_working2/authutilsnode.ts +0 -375
  102. package/src_working2/commonTypes.ts +0 -239
  103. package/src_working2/index.ts +0 -22
  104. package/src_working2/influxdb/influxDBManager.ts +0 -972
  105. package/src_working2/influxdb/influxDBManagerAgent.ts +0 -316
  106. package/src_working2/influxdb/influxDBManagerBase.ts +0 -111
  107. package/src_working2/influxdb/influxDBManagerService.ts +0 -375
  108. package/src_working2/instrumentationsubscriber.ts +0 -286
  109. package/src_working2/kafka/IMKafkaManager.ts +0 -154
  110. package/src_working2/kafka/kafkaconsumer.ts +0 -82
  111. package/src_working2/kafka/kafkamanager.ts +0 -186
  112. package/src_working2/kafka/kafkaproducer.ts +0 -58
  113. package/src_working2/kafkatesting/config.ts +0 -10
  114. package/src_working2/kafkatesting/consume.ts +0 -116
  115. package/src_working2/kafkatesting/produce.ts +0 -155
  116. package/src_working2/masterprocessbase.ts +0 -590
  117. package/src_working2/middleware/serverNetworkMiddleware.ts +0 -240
  118. package/src_working2/network.ts +0 -36
  119. package/src_working2/processbase.ts +0 -415
  120. package/src_working2/processoptions.ts +0 -164
  121. package/src_working2/publishertransports/publishTransportDirect.ts +0 -45
  122. package/src_working2/publishertransports/publishTransportUtils.ts +0 -53
  123. package/src_working2/server.ts +0 -141
  124. package/src_working2/serverprocessbase.ts +0 -393
  125. package/src_working2/singleprocessbase.ts +0 -123
  126. package/src_working2/socketIoServerHelper.ts +0 -177
  127. package/src_working2/stscontrollerbase.ts +0 -15
  128. package/src_working2/stslatencycontroller.ts +0 -27
  129. package/src_working2/stslatencyroute.ts +0 -16
  130. package/src_working2/stsrouterbase.ts +0 -22
  131. package/src_working2/tcpclient/app.ts +0 -19
  132. package/src_working2/tcpclient/app2.ts +0 -56
  133. package/src_working2/tcpserver/app.ts +0 -11
  134. package/src_working2/tcpserver/appConfig.ts +0 -65
  135. package/src_working2/tcpserver/appmaster.ts +0 -522
  136. package/src_working2/validation/errors.ts +0 -6
  137. package/src_working2/webworkertesting/app.ts +0 -49
  138. package/src_working2/webworkertesting/worker.ts +0 -24
  139. package/src_working2/workerprocessbase.test.ts +0 -47
  140. package/src_working2/workerprocessbase.ts +0 -187
@@ -1,187 +0,0 @@
1
- /* eslint @typescript-eslint/no-explicit-any: 0 */ // --> OFF
2
- import debugModule from 'debug'
3
- const debug = debugModule(`proc:${process.pid}`);
4
-
5
- import chalk from 'chalk';
6
-
7
- import { Gauge, InstrumentGaugeTelemetry } from '@nsshunt/stsinstrumentation'
8
- import { JSONObject } from '@nsshunt/stsutils'
9
- import { ProcessOptions } from './processoptions'
10
- import { IPCMessage, IPCMessages, IPCMessagePayload, IPCMessageCommand, IWorkerProcessBase } from './commonTypes'
11
- import { STSExpressServer } from './server';
12
- import { ServerProcessBase } from './serverprocessbase'
13
-
14
- import { v4 as uuidv4 } from 'uuid';
15
-
16
- import colors from 'colors'
17
-
18
- /**
19
- * todo
20
- * @typedef {Object} options - todo
21
- * @property {boolean} [wssServer=false] - Create a web socket server on this worker instance
22
- */
23
- export class WorkerProcessBase extends ServerProcessBase implements IWorkerProcessBase
24
- {
25
- #inFlightMessage: IPCMessages = { }
26
- #requestResponseMessageTimeout = 2000; //@@ config
27
-
28
- constructor(options: ProcessOptions) {
29
- super(options);
30
- }
31
-
32
- WorkerStarted() {
33
- return null;
34
- }
35
-
36
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unused-vars
37
- ReceivedMessageFromMaster(msg: any) {
38
- // Override in subclass if required
39
- }
40
-
41
- override CollectAdditionalTelemetry(): void {
42
- this.httpServer.getConnections((error: any, count: any) => {
43
- //@@this.instruments[Gauge.CONNECTION_COUNT_GAUGE].val = count;
44
- this.UpdateInstrument(Gauge.CONNECTION_COUNT_GAUGE, {
45
- val: count
46
- } as InstrumentGaugeTelemetry);
47
- });
48
- }
49
-
50
- #SendMessageToParentProcess = (message: IPCMessagePayload): Promise<JSONObject> => {
51
- return new Promise((resolve, reject) => {
52
- if (this.#inFlightMessage[message.id]) {
53
- reject(`Message with id: [${message.id}] already exists within the Request/Response record structure`);
54
- } else {
55
- this.#inFlightMessage[message.id] = {
56
- iPCMessagePayload: { ...message },
57
- cb: () => {
58
- const detail: JSONObject = this.#inFlightMessage[message.id].iPCMessagePayload.responseDetail as JSONObject
59
- clearTimeout(this.#inFlightMessage[message.id].timeout);
60
- setTimeout(() => {
61
- delete this.#inFlightMessage[message.id];
62
- }, 0).unref();
63
- debug(chalk.green(`Resolving response message with id: [${message.id}] from parent process via IPC. Details: [${JSON.stringify(this.#inFlightMessage[message.id].iPCMessagePayload)}]`));
64
- resolve(detail);
65
- },
66
- timeout: setTimeout(() => {
67
- setTimeout(() => {
68
- delete this.#inFlightMessage[message.id];
69
- }, 0).unref();
70
- debug(chalk.red(`Timeout has occurred after: [${this.#requestResponseMessageTimeout}]ms with message id: [${message.id}]. Details: [${JSON.stringify(this.#inFlightMessage[message.id].iPCMessagePayload)}]`));
71
- reject('Did not receive response form parent process.');
72
- }, this.#requestResponseMessageTimeout) // max message timeout allowed
73
- }
74
- debug(`Sending message with id: [${message.id}] to parent process via IPC. Details: [${JSON.stringify(this.#inFlightMessage[message.id].iPCMessagePayload)}]`.yellow);
75
- (process as any).send(message);
76
- }
77
- });
78
- }
79
-
80
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
81
- AddWorker = async (options: any): Promise<string> => {
82
- const workerResponse: JSONObject = await this.#SendMessageToParentProcess({
83
- requestResponse: true,
84
- id: uuidv4(),
85
- command: IPCMessageCommand.AddWorker,
86
- requestDetail: {
87
- options
88
- }
89
- });
90
- return workerResponse.workerId;
91
- }
92
-
93
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
94
- DeleteWorker = async (workerId: string, options: any): Promise<JSONObject> => {
95
- const workerResponse: JSONObject = await this.#SendMessageToParentProcess({
96
- requestResponse: true,
97
- id: uuidv4(),
98
- command: IPCMessageCommand.DeleteWorker,
99
- requestDetail: {
100
- options,
101
- workerId
102
- }
103
- });
104
- return workerResponse;
105
- }
106
-
107
- ProcessTerminating = async (): Promise<void> => {
108
- return;
109
- }
110
-
111
- SetupServer = async () =>
112
- {
113
- this.SetupInstrumentation();
114
- setTimeout(() => {
115
- this.SetupServerEx();
116
- }, 100);
117
- }
118
-
119
- SetupServerEx = async () => {
120
- this.ProcessStartup();
121
-
122
- if (this.options.expressServerRouteFactory || this.options.expressServerRouteStaticFactory) {
123
- this.expressServer = new STSExpressServer(this.options, this);
124
- }
125
-
126
- this.LogEx(`Worker instance starting. Service instance Id: [${this.options.serviceInstanceId}]`);
127
-
128
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
129
- process.on('message', async (msg: any) => {
130
- if (msg.requestResponse) {
131
- const iPCMessagePayload: IPCMessagePayload = msg as IPCMessagePayload;
132
- if (iPCMessagePayload.id) {
133
- if (this.#inFlightMessage[iPCMessagePayload.id]) {
134
- const responseMessage: IPCMessage = this.#inFlightMessage[iPCMessagePayload.id];
135
- responseMessage.iPCMessagePayload.responseDetail = { ...iPCMessagePayload.responseDetail }
136
- responseMessage.cb();
137
- } else {
138
- throw new Error(`Could not find Request/Response message with id: [${iPCMessagePayload.id}]`);
139
- }
140
- } else {
141
- throw new Error(`Message does not have id attribute. [${JSON.stringify(iPCMessagePayload)}]`);
142
- }
143
- return;
144
- }
145
- if (msg.command) //@@ constants
146
- {
147
- switch (msg.command)
148
- {
149
- case 'Terminate' :
150
- this.LogEx((`Received ` + colors.bold(`Terminate`.italic) + ` message from master thread`).gray);
151
- await this.Terminate(true, false); // Don't kill the child process here, the master will take care of that ...
152
- break;
153
- case 'TerminateAndKill' :
154
- this.LogEx((`Received ` + colors.bold(`Terminate`.italic) + ` message from master thread`).gray);
155
- await this.Terminate(true, true);
156
- break;
157
- case 'Message' :
158
- //this.LogEx((`Received ` + colors.bold(`Message`.italic) + ` message from master thread`).gray);
159
- this.ReceivedMessageFromMaster(msg.data);
160
- break;
161
- case 'Response' : // General response to a req/response interaction
162
- msg.details
163
- }
164
- }
165
- });
166
-
167
- // Signal Codes
168
- // https://en.wikipedia.org/wiki/Signal_(IPC)
169
- process.on('SIGTERM', async () =>
170
- {
171
- this.LogEx(`SIGTERM signal received for worker: ${process.pid}`);
172
- await this.Terminate(true, true);
173
- });
174
-
175
- process.on('SIGINT', async () =>
176
- {
177
- this.LogEx(`SIGINT signal received for worker: ${process.pid}`);
178
- await this.Terminate(true, true);
179
- });
180
-
181
- await this.SetupSTSServer();
182
-
183
- this.WorkerStarted();
184
-
185
- this.LogEx(chalk.green(`Worker process:${process.pid} started`));
186
- };
187
- }