@nsshunt/stsappframework 3.3.186 → 4.0.1
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/dist/commonTypes.js +1 -12
- package/dist/commonTypes.js.map +1 -1
- package/dist/exampleapp/app.js +238 -0
- package/dist/exampleapp/app.js.map +1 -0
- package/dist/index.js +11 -7
- package/dist/index.js.map +1 -1
- package/dist/logger/stsTransportLoggerSocket.js +0 -1
- package/dist/logger/stsTransportLoggerSocket.js.map +1 -1
- package/dist/{process → plugins}/clusterworkermanager.js +37 -36
- package/dist/plugins/clusterworkermanager.js.map +1 -0
- package/dist/plugins/pgpoolmanager.js +186 -0
- package/dist/plugins/pgpoolmanager.js.map +1 -0
- package/dist/{process → plugins}/servertypes/serverUtils.js.map +1 -1
- package/dist/{process → plugins}/servertypes/stsexpressserver.js +44 -19
- package/dist/plugins/servertypes/stsexpressserver.js.map +1 -0
- package/dist/{process → plugins}/servertypes/stsjsonrpcserver.js +2 -3
- package/dist/plugins/servertypes/stsjsonrpcserver.js.map +1 -0
- package/dist/{process → plugins}/servertypes/stsserverfactory.js +2 -2
- package/dist/plugins/servertypes/stsserverfactory.js.map +1 -0
- package/dist/{process → plugins}/servertypes/ststcprawserver.js +2 -2
- package/dist/plugins/servertypes/ststcprawserver.js.map +1 -0
- package/dist/plugins/stsclusterworkermanagerplugin.js +54 -0
- package/dist/plugins/stsclusterworkermanagerplugin.js.map +1 -0
- package/dist/{process/plugins → plugins}/stsconfigplugin.js +2 -2
- package/dist/plugins/stsconfigplugin.js.map +1 -0
- package/dist/plugins/stsexpresscontrollerplugin.js +47 -0
- package/dist/plugins/stsexpresscontrollerplugin.js.map +1 -0
- package/dist/{process/plugins/stsmetricsplugin.js → plugins/stsinstrumentmanagerplugin.js} +36 -23
- package/dist/plugins/stsinstrumentmanagerplugin.js.map +1 -0
- package/dist/plugins/stslatencymanager.js +122 -0
- package/dist/plugins/stslatencymanager.js.map +1 -0
- package/dist/plugins/stslatencyplugin.js +29 -0
- package/dist/plugins/stslatencyplugin.js.map +1 -0
- package/dist/plugins/stslifecycleplugin.js +48 -0
- package/dist/plugins/stslifecycleplugin.js.map +1 -0
- package/dist/plugins/stsloggerplugin.js +60 -0
- package/dist/plugins/stsloggerplugin.js.map +1 -0
- package/dist/{process/metrics.js → plugins/stsmetricsplugin.js} +33 -9
- package/dist/plugins/stsmetricsplugin.js.map +1 -0
- package/dist/plugins/stspgpoolmanagerplugin.js +67 -0
- package/dist/plugins/stspgpoolmanagerplugin.js.map +1 -0
- package/dist/plugins/stsserverplugin.js +89 -0
- package/dist/plugins/stsserverplugin.js.map +1 -0
- package/dist/route/stsrootroute.js +10 -0
- package/dist/route/stsrootroute.js.map +1 -0
- package/dist/stsapp.js +190 -0
- package/dist/stsapp.js.map +1 -0
- package/package.json +15 -22
- package/types/commonTypes.d.ts +28 -203
- package/types/commonTypes.d.ts.map +1 -1
- package/types/exampleapp/app.d.ts +2 -0
- package/types/exampleapp/app.d.ts.map +1 -0
- package/types/index.d.ts +11 -7
- package/types/index.d.ts.map +1 -1
- package/types/logger/stsTransportLoggerSocket.d.ts.map +1 -1
- package/types/{process → plugins}/clusterworkermanager.d.ts +5 -1
- package/types/plugins/clusterworkermanager.d.ts.map +1 -0
- package/types/plugins/pgpoolmanager.d.ts +34 -0
- package/types/plugins/pgpoolmanager.d.ts.map +1 -0
- package/types/{process → plugins}/servertypes/serverUtils.d.ts.map +1 -1
- package/types/plugins/servertypes/stsexpressserver.d.ts +22 -0
- package/types/plugins/servertypes/stsexpressserver.d.ts.map +1 -0
- package/types/{process → plugins}/servertypes/stsjsonrpcserver.d.ts +1 -9
- package/types/plugins/servertypes/stsjsonrpcserver.d.ts.map +1 -0
- package/types/{process → plugins}/servertypes/stsserverfactory.d.ts +2 -4
- package/types/plugins/servertypes/stsserverfactory.d.ts.map +1 -0
- package/types/{process → plugins}/servertypes/ststcprawserver.d.ts +1 -9
- package/types/plugins/servertypes/ststcprawserver.d.ts.map +1 -0
- package/types/plugins/stsclusterworkermanagerplugin.d.ts +16 -0
- package/types/plugins/stsclusterworkermanagerplugin.d.ts.map +1 -0
- package/types/{process/plugins → plugins}/stsconfigplugin.d.ts +1 -1
- package/types/plugins/stsconfigplugin.d.ts.map +1 -0
- package/types/plugins/stsexpresscontrollerplugin.d.ts +25 -0
- package/types/plugins/stsexpresscontrollerplugin.d.ts.map +1 -0
- package/types/plugins/stsinstrumentmanagerplugin.d.ts +31 -0
- package/types/plugins/stsinstrumentmanagerplugin.d.ts.map +1 -0
- package/types/plugins/stslatencymanager.d.ts +24 -0
- package/types/plugins/stslatencymanager.d.ts.map +1 -0
- package/types/plugins/stslatencyplugin.d.ts +12 -0
- package/types/plugins/stslatencyplugin.d.ts.map +1 -0
- package/types/plugins/stslifecycleplugin.d.ts +25 -0
- package/types/plugins/stslifecycleplugin.d.ts.map +1 -0
- package/types/plugins/stsloggerplugin.d.ts +19 -0
- package/types/plugins/stsloggerplugin.d.ts.map +1 -0
- package/types/{process/metrics.d.ts → plugins/stsmetricsplugin.d.ts} +12 -5
- package/types/plugins/stsmetricsplugin.d.ts.map +1 -0
- package/types/plugins/stspgpoolmanagerplugin.d.ts +14 -0
- package/types/plugins/stspgpoolmanagerplugin.d.ts.map +1 -0
- package/types/plugins/stsserverplugin.d.ts +16 -0
- package/types/plugins/stsserverplugin.d.ts.map +1 -0
- package/types/route/stsrootroute.d.ts +5 -0
- package/types/route/stsrootroute.d.ts.map +1 -0
- package/types/{process/stsapp.d.ts → stsapp.d.ts} +6 -2
- package/types/stsapp.d.ts.map +1 -0
- package/dist/grpc/grpcServer.js +0 -415
- package/dist/grpc/grpcServer.js.map +0 -1
- package/dist/process/appConfig.js +0 -103
- package/dist/process/appConfig.js.map +0 -1
- package/dist/process/clusterworkermanager.js.map +0 -1
- package/dist/process/datamanager.js +0 -78
- package/dist/process/datamanager.js.map +0 -1
- package/dist/process/latencyManager.js +0 -56
- package/dist/process/latencyManager.js.map +0 -1
- package/dist/process/logManager.js +0 -36
- package/dist/process/logManager.js.map +0 -1
- package/dist/process/masterprocessbase.js +0 -154
- package/dist/process/masterprocessbase.js.map +0 -1
- package/dist/process/metrics.js.map +0 -1
- package/dist/process/plugins/plugintypes.js +0 -2
- package/dist/process/plugins/plugintypes.js.map +0 -1
- package/dist/process/plugins/stsconfigplugin.js.map +0 -1
- package/dist/process/plugins/stsloggerplugin.js +0 -26
- package/dist/process/plugins/stsloggerplugin.js.map +0 -1
- package/dist/process/plugins/stsmetricsplugin.js.map +0 -1
- package/dist/process/plugins/ststestplugin.js +0 -26
- package/dist/process/plugins/ststestplugin.js.map +0 -1
- package/dist/process/processbase.js +0 -203
- package/dist/process/processbase.js.map +0 -1
- package/dist/process/prometheusmanager.js +0 -112
- package/dist/process/prometheusmanager.js.map +0 -1
- package/dist/process/server.js +0 -4
- package/dist/process/server.js.map +0 -1
- package/dist/process/serverprocessbase.js +0 -204
- package/dist/process/serverprocessbase.js.map +0 -1
- package/dist/process/servertypes/stsexpressserver.js.map +0 -1
- package/dist/process/servertypes/stsjsonrpcserver.js.map +0 -1
- package/dist/process/servertypes/stsserverfactory.js.map +0 -1
- package/dist/process/servertypes/ststcprawserver.js.map +0 -1
- package/dist/process/singleprocessbase.js +0 -48
- package/dist/process/singleprocessbase.js.map +0 -1
- package/dist/process/stsapp.js +0 -48
- package/dist/process/stsapp.js.map +0 -1
- package/dist/process/sysinfo.js +0 -56
- package/dist/process/sysinfo.js.map +0 -1
- package/dist/process/workerprocessbase.js +0 -35
- package/dist/process/workerprocessbase.js.map +0 -1
- package/dist/publishertransports/publishTransportUtils.js +0 -43
- package/dist/publishertransports/publishTransportUtils.js.map +0 -1
- package/dist/sysinfo/network.js +0 -31
- package/dist/sysinfo/network.js.map +0 -1
- package/types/grpc/grpcServer.d.ts +0 -31
- package/types/grpc/grpcServer.d.ts.map +0 -1
- package/types/process/appConfig.d.ts +0 -3
- package/types/process/appConfig.d.ts.map +0 -1
- package/types/process/clusterworkermanager.d.ts.map +0 -1
- package/types/process/datamanager.d.ts +0 -15
- package/types/process/datamanager.d.ts.map +0 -1
- package/types/process/latencyManager.d.ts +0 -10
- package/types/process/latencyManager.d.ts.map +0 -1
- package/types/process/logManager.d.ts +0 -9
- package/types/process/logManager.d.ts.map +0 -1
- package/types/process/masterprocessbase.d.ts +0 -13
- package/types/process/masterprocessbase.d.ts.map +0 -1
- package/types/process/metrics.d.ts.map +0 -1
- package/types/process/plugins/plugintypes.d.ts +0 -7
- package/types/process/plugins/plugintypes.d.ts.map +0 -1
- package/types/process/plugins/stsconfigplugin.d.ts.map +0 -1
- package/types/process/plugins/stsloggerplugin.d.ts +0 -14
- package/types/process/plugins/stsloggerplugin.d.ts.map +0 -1
- package/types/process/plugins/stsmetricsplugin.d.ts +0 -19
- package/types/process/plugins/stsmetricsplugin.d.ts.map +0 -1
- package/types/process/plugins/ststestplugin.d.ts +0 -10
- package/types/process/plugins/ststestplugin.d.ts.map +0 -1
- package/types/process/processbase.d.ts +0 -19
- package/types/process/processbase.d.ts.map +0 -1
- package/types/process/prometheusmanager.d.ts +0 -10
- package/types/process/prometheusmanager.d.ts.map +0 -1
- package/types/process/server.d.ts +0 -5
- package/types/process/server.d.ts.map +0 -1
- package/types/process/serverprocessbase.d.ts +0 -18
- package/types/process/serverprocessbase.d.ts.map +0 -1
- package/types/process/servertypes/stsexpressserver.d.ts +0 -34
- package/types/process/servertypes/stsexpressserver.d.ts.map +0 -1
- package/types/process/servertypes/stsjsonrpcserver.d.ts.map +0 -1
- package/types/process/servertypes/stsserverfactory.d.ts.map +0 -1
- package/types/process/servertypes/ststcprawserver.d.ts.map +0 -1
- package/types/process/singleprocessbase.d.ts +0 -14
- package/types/process/singleprocessbase.d.ts.map +0 -1
- package/types/process/stsapp.d.ts.map +0 -1
- package/types/process/sysinfo.d.ts +0 -8
- package/types/process/sysinfo.d.ts.map +0 -1
- package/types/process/workerprocessbase.d.ts +0 -8
- package/types/process/workerprocessbase.d.ts.map +0 -1
- package/types/publishertransports/publishTransportUtils.d.ts +0 -5
- package/types/publishertransports/publishTransportUtils.d.ts.map +0 -1
- package/types/sysinfo/network.d.ts +0 -4
- package/types/sysinfo/network.d.ts.map +0 -1
- /package/dist/{process → plugins}/servertypes/serverUtils.js +0 -0
- /package/types/{process → plugins}/servertypes/serverUtils.d.ts +0 -0
package/dist/stsapp.js
ADDED
|
@@ -0,0 +1,190 @@
|
|
|
1
|
+
// processbase.ts
|
|
2
|
+
/* eslint @typescript-eslint/no-explicit-any: 0, @typescript-eslint/no-unused-vars: 0 */ // --> OFF
|
|
3
|
+
import chalk from "chalk";
|
|
4
|
+
import { inject } from "@nsshunt/stsutils";
|
|
5
|
+
import { Injector } from "@nsshunt/stsutils";
|
|
6
|
+
import { STSLoggerPluginToken } from "./plugins/stsloggerplugin.js";
|
|
7
|
+
import { TinyEmitter } from "tiny-emitter";
|
|
8
|
+
import cluster from "cluster";
|
|
9
|
+
import { ISTSLifeCycleState, STSLifeCyclePluginToken, } from "./plugins/stslifecycleplugin.js";
|
|
10
|
+
export class STSApp extends TinyEmitter {
|
|
11
|
+
rootInjector;
|
|
12
|
+
plugins = [];
|
|
13
|
+
constructor() {
|
|
14
|
+
super();
|
|
15
|
+
this.rootInjector = new Injector([]);
|
|
16
|
+
}
|
|
17
|
+
use = (plugin, options) => {
|
|
18
|
+
this.rootInjector.runInContext(() => {
|
|
19
|
+
plugin.install(this.rootInjector, options);
|
|
20
|
+
});
|
|
21
|
+
this.plugins.push(plugin);
|
|
22
|
+
};
|
|
23
|
+
run = (fn) => {
|
|
24
|
+
this.rootInjector.runInContext(() => {
|
|
25
|
+
fn();
|
|
26
|
+
});
|
|
27
|
+
};
|
|
28
|
+
createPlugin = (Plugin) => {
|
|
29
|
+
return this.rootInjector.runInContext(() => new Plugin());
|
|
30
|
+
};
|
|
31
|
+
Start = async () => {
|
|
32
|
+
await this.rootInjector.runInContext(async () => {
|
|
33
|
+
const lc = inject(STSLifeCyclePluginToken);
|
|
34
|
+
lc.state = ISTSLifeCycleState.starting;
|
|
35
|
+
this.#SetupProcessEvents();
|
|
36
|
+
for (const plugin of this.plugins) {
|
|
37
|
+
await plugin.Start();
|
|
38
|
+
}
|
|
39
|
+
lc.state = ISTSLifeCycleState.started;
|
|
40
|
+
});
|
|
41
|
+
};
|
|
42
|
+
Terminate = async (signalText) => {
|
|
43
|
+
console.log(chalk.yellow(`${process.pid} Terminate()`));
|
|
44
|
+
process.off("SIGTERM", this.#SigTerm);
|
|
45
|
+
process.off("SIGINT", this.#sigInt);
|
|
46
|
+
this.emit("Terminate");
|
|
47
|
+
await this.Stop();
|
|
48
|
+
};
|
|
49
|
+
Stop = async () => {
|
|
50
|
+
await this.rootInjector.runInContext(async () => {
|
|
51
|
+
const lc = inject(STSLifeCyclePluginToken);
|
|
52
|
+
if (lc.state !== ISTSLifeCycleState.stopping) {
|
|
53
|
+
console.log(chalk.magenta(`${process.pid} STSApp:Stop(): Stopping ...`));
|
|
54
|
+
lc.state = ISTSLifeCycleState.stopping;
|
|
55
|
+
for (const plugin of this.plugins.toReversed()) {
|
|
56
|
+
await plugin.Stop();
|
|
57
|
+
}
|
|
58
|
+
console.log(chalk.magenta(`${process.pid} STSApp:Stop(): Stopped.`));
|
|
59
|
+
lc.state = ISTSLifeCycleState.stopped;
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
console.log(chalk.cyan(`${process.pid}: STSApp:Stop() - Already stopping.`));
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
};
|
|
66
|
+
#SigTerm = async (code) => {
|
|
67
|
+
this.#LogProcessEvent("SIGTERM", code);
|
|
68
|
+
await this.Terminate("SIGTERM");
|
|
69
|
+
if (cluster.isWorker) {
|
|
70
|
+
cluster.worker?.disconnect();
|
|
71
|
+
}
|
|
72
|
+
/*
|
|
73
|
+
this.rootInjector.runInContext(async () => {
|
|
74
|
+
const logger = inject(STSLoggerPluginToken);
|
|
75
|
+
if (logger) {
|
|
76
|
+
logger.info(
|
|
77
|
+
`ServerProcessBase:SetupServerEx(): SIGTERM signal received for worker: ${process.pid}`
|
|
78
|
+
);
|
|
79
|
+
}
|
|
80
|
+
this.Terminate("SIGTERM");
|
|
81
|
+
});
|
|
82
|
+
*/
|
|
83
|
+
};
|
|
84
|
+
#sigInt = async (code) => {
|
|
85
|
+
this.#LogProcessEvent("SIGINT", code);
|
|
86
|
+
await this.Terminate("SIGINT");
|
|
87
|
+
if (cluster.isWorker) {
|
|
88
|
+
cluster.worker?.disconnect();
|
|
89
|
+
}
|
|
90
|
+
/*
|
|
91
|
+
this.rootInjector.runInContext(async () => {
|
|
92
|
+
const logger = inject(STSLoggerPluginToken);
|
|
93
|
+
if (logger) {
|
|
94
|
+
logger.info(
|
|
95
|
+
`ServerProcessBase:SetupServerEx(): SIGINT signal received for worker: ${process.pid}`
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
this.Terminate("SIGINT");
|
|
99
|
+
});
|
|
100
|
+
*/
|
|
101
|
+
};
|
|
102
|
+
#LogProcessEvent = (event, code) => {
|
|
103
|
+
try {
|
|
104
|
+
this.rootInjector.runInContext(async () => {
|
|
105
|
+
try {
|
|
106
|
+
const logger = inject(STSLoggerPluginToken);
|
|
107
|
+
if (logger) {
|
|
108
|
+
logger.info(chalk.yellow(`${process.pid} stsapp:#LogProcessEvent(): Process: [${process.pid}] Event: [${event}] Code: ${code}`));
|
|
109
|
+
}
|
|
110
|
+
}
|
|
111
|
+
catch (error) { }
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
catch (error) { }
|
|
115
|
+
};
|
|
116
|
+
#SetupProcessEvents = () => {
|
|
117
|
+
if (cluster.isPrimary) {
|
|
118
|
+
// Signal Codes
|
|
119
|
+
// https://en.wikipedia.org/wiki/Signal_(IPC)
|
|
120
|
+
process.on("SIGTERM", this.#SigTerm);
|
|
121
|
+
process.on("SIGINT", this.#sigInt);
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
// Attach a dummy function to stop the standard nodejs way of terminating
|
|
125
|
+
// The terminate message will be received from the master process to shutdown
|
|
126
|
+
// When a kill -2 <pid> is run, we are targeting one PID: the cluster primary. The primary gets SIGINT, runs the
|
|
127
|
+
// shutdown path, then tells the workers to terminate cleanly. When you press Ctrl+C in the terminal, the terminal
|
|
128
|
+
// generally sends SIGINT to the entire foreground process group, not just the primary. Your cluster workers are
|
|
129
|
+
// separate OS processes, but they normally belong to that same foreground process group. So the workers can receive
|
|
130
|
+
// SIGINT directly at essentially the same time as the primary.
|
|
131
|
+
// We omit the SIGTERM signal to let the os/nodejs terminate as expected in this case. If the config allows for
|
|
132
|
+
// cluster workers to respawn, they will respawn automatically from that config.
|
|
133
|
+
process.on("SIGINT", () => true);
|
|
134
|
+
}
|
|
135
|
+
process.on("disconnect", () => {
|
|
136
|
+
this.#LogProcessEvent("disconnect", "");
|
|
137
|
+
});
|
|
138
|
+
process.on("exit", (code) => {
|
|
139
|
+
this.#LogProcessEvent("exit", code);
|
|
140
|
+
});
|
|
141
|
+
process.on("message", async (msg) => {
|
|
142
|
+
if (msg.command) {
|
|
143
|
+
switch (msg.command) {
|
|
144
|
+
case "Terminate":
|
|
145
|
+
try {
|
|
146
|
+
this.rootInjector.runInContext(() => {
|
|
147
|
+
const logger = inject(STSLoggerPluginToken);
|
|
148
|
+
if (logger) {
|
|
149
|
+
logger.info(chalk.grey(`Received ` +
|
|
150
|
+
chalk.bold.italic(`Terminate`) +
|
|
151
|
+
` message from master thread`));
|
|
152
|
+
}
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
catch (error) {
|
|
156
|
+
console.error(error);
|
|
157
|
+
}
|
|
158
|
+
finally {
|
|
159
|
+
await this.Terminate("SIGTERM"); // Don't kill the child process here, the master will take care of that ...
|
|
160
|
+
}
|
|
161
|
+
break;
|
|
162
|
+
case "TerminateAndKill":
|
|
163
|
+
try {
|
|
164
|
+
this.rootInjector.runInContext(() => {
|
|
165
|
+
const logger = inject(STSLoggerPluginToken);
|
|
166
|
+
if (logger) {
|
|
167
|
+
logger.info(chalk.grey(`Received ` +
|
|
168
|
+
chalk.bold.italic(`Terminate`) +
|
|
169
|
+
` message from master thread`));
|
|
170
|
+
}
|
|
171
|
+
});
|
|
172
|
+
}
|
|
173
|
+
catch (error) {
|
|
174
|
+
console.error(error);
|
|
175
|
+
}
|
|
176
|
+
finally {
|
|
177
|
+
await this.Terminate("SIGTERM");
|
|
178
|
+
}
|
|
179
|
+
break;
|
|
180
|
+
}
|
|
181
|
+
}
|
|
182
|
+
});
|
|
183
|
+
// IMPORTANT
|
|
184
|
+
// Without this, killing the process (parent PID) (SIGTERM) will not close the workers - the IPC message channel does not let the
|
|
185
|
+
// process die, i.e. its still held open.
|
|
186
|
+
// With a SIGINT (Ctrl-C), the process however does die with or without this.
|
|
187
|
+
process.channel?.unref();
|
|
188
|
+
};
|
|
189
|
+
}
|
|
190
|
+
//# sourceMappingURL=stsapp.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"stsapp.js","sourceRoot":"","sources":["../src/stsapp.ts"],"names":[],"mappings":"AAAA,iBAAiB;AACjB,wFAAwF,CAAC,UAAU;AACnG,OAAO,KAAK,MAAM,OAAO,CAAC;AAE1B,OAAO,EAAE,MAAM,EAAE,MAAM,mBAAmB,CAAC;AAE3C,OAAO,EAAE,QAAQ,EAAE,MAAM,mBAAmB,CAAC;AAI7C,OAAO,EAAE,oBAAoB,EAAE,MAAM,8BAA8B,CAAC;AACpE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,OAAO,MAAM,SAAS,CAAC;AAE9B,OAAO,EACH,kBAAkB,EAClB,uBAAuB,GAC1B,MAAM,iCAAiC,CAAC;AAEzC,MAAM,OAAO,MAAO,SAAQ,WAAW;IAChB,YAAY,CAAW;IACvB,OAAO,GAAmB,EAAE,CAAC;IAEhD;QACI,KAAK,EAAE,CAAC;QACR,IAAI,CAAC,YAAY,GAAG,IAAI,QAAQ,CAAC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,KAAK,EAAE,CAAC;4BACb,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;wBACzB,CAAC;gCAAS,CAAC;4BACP,MAAM,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC,CAAC,2EAA2E;wBAChH,CAAC;wBACD,MAAM;oBACV,KAAK,kBAAkB;wBACnB,IAAI,CAAC;4BACD,IAAI,CAAC,YAAY,CAAC,YAAY,CAAC,GAAG,EAAE;gCAChC,MAAM,MAAM,GAAG,MAAM,CAAC,oBAAoB,CAAC,CAAC;gCAC5C,IAAI,MAAM,EAAE,CAAC;oCACT,MAAM,CAAC,IAAI,CACP,KAAK,CAAC,IAAI,CACN,WAAW;wCACP,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC;wCAC9B,6BAA6B,CACpC,CACJ,CAAC;gCACN,CAAC;4BACL,CAAC,CAAC,CAAC;wBACP,CAAC;wBAAC,OAAO,KAAK,EAAE,CAAC;4BACb,OAAO,CAAC,KAAK,CAAC,KAAK,CAAC,CAAC;wBACzB,CAAC;gCAAS,CAAC;4BACP,MAAM,IAAI,CAAC,SAAS,CAAC,SAAS,CAAC,CAAC;wBACpC,CAAC;wBACD,MAAM;gBACd,CAAC;YACL,CAAC;QACL,CAAC,CAAC,CAAC;QAEH,YAAY;QACZ,iIAAiI;QACjI,yCAAyC;QACzC,6EAA6E;QAC7E,OAAO,CAAC,OAAO,EAAE,KAAK,EAAE,CAAC;IAC7B,CAAC,CAAC;CACL"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@nsshunt/stsappframework",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "4.0.1",
|
|
4
4
|
"description": "",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/index.js",
|
|
@@ -35,28 +35,23 @@
|
|
|
35
35
|
"@types/cookie-parser": "^1.4.10",
|
|
36
36
|
"@types/debug": "^4.1.13",
|
|
37
37
|
"@types/express": "^5.0.6",
|
|
38
|
-
"@types/node": "^26.6.
|
|
39
|
-
"@
|
|
40
|
-
"@typescript-eslint/
|
|
38
|
+
"@types/node": "^26.6.3",
|
|
39
|
+
"@types/pg": "^8",
|
|
40
|
+
"@typescript-eslint/eslint-plugin": "^8.70.1",
|
|
41
|
+
"@typescript-eslint/parser": "^8.70.1",
|
|
41
42
|
"eslint": "^10.11.0",
|
|
42
43
|
"eslint-config-prettier": "^10.1.8",
|
|
43
44
|
"globals": "^17.12.0",
|
|
44
45
|
"typescript": "^6.0.3",
|
|
45
|
-
"vite": "^8.3.
|
|
46
|
-
"vitest": "^5.0.
|
|
46
|
+
"vite": "^8.3.1",
|
|
47
|
+
"vitest": "^5.0.2"
|
|
47
48
|
},
|
|
48
49
|
"dependencies": {
|
|
49
|
-
"@
|
|
50
|
-
"@
|
|
51
|
-
"@nsshunt/
|
|
52
|
-
"@nsshunt/
|
|
53
|
-
"@nsshunt/
|
|
54
|
-
"@nsshunt/stsmessaging": "^1.0.82",
|
|
55
|
-
"@nsshunt/stsobservability": "^1.0.168",
|
|
56
|
-
"@nsshunt/stssocketioutils": "^2.0.63",
|
|
57
|
-
"@nsshunt/stsutils": "^1.19.143",
|
|
58
|
-
"@socket.io/cluster-adapter": "^0.3.0",
|
|
59
|
-
"@socket.io/redis-streams-adapter": "^0.3.1",
|
|
50
|
+
"@nsshunt/stsconfig": "^1.27.79",
|
|
51
|
+
"@nsshunt/stsinstrumentmanagerclient": "^1.0.54",
|
|
52
|
+
"@nsshunt/stsobservability": "^1.0.170",
|
|
53
|
+
"@nsshunt/stssocketioutils": "^2.0.65",
|
|
54
|
+
"@nsshunt/stsutils": "^1.19.145",
|
|
60
55
|
"@types/on-headers": "^1.0.4",
|
|
61
56
|
"@types/pidusage": "^2.0.5",
|
|
62
57
|
"axios": "^1.20.0",
|
|
@@ -66,15 +61,13 @@
|
|
|
66
61
|
"debug": "^4.4.3",
|
|
67
62
|
"express": "^5.2.1",
|
|
68
63
|
"http-status-codes": "^2.3.0",
|
|
69
|
-
"ioredis": "^5.11.1",
|
|
70
64
|
"jayson": "^4.3.0",
|
|
71
65
|
"on-headers": "^1.1.0",
|
|
66
|
+
"pg": "^8.23.0",
|
|
72
67
|
"pidusage": "^4.0.1",
|
|
73
|
-
"
|
|
74
|
-
"socket.io": "^4.8.3",
|
|
75
|
-
"socket.io-adapter": "^2.5.8",
|
|
76
|
-
"systeminformation": "^5.33.12",
|
|
68
|
+
"socket.io-client": "^4.8.4",
|
|
77
69
|
"tiny-emitter": "^2.1.0",
|
|
70
|
+
"winston": "^3.19.0",
|
|
78
71
|
"winston-transport": "^4.9.0"
|
|
79
72
|
},
|
|
80
73
|
"packageManager": "yarn@4.13.0"
|
package/types/commonTypes.d.ts
CHANGED
|
@@ -1,18 +1,12 @@
|
|
|
1
1
|
import express from "express";
|
|
2
2
|
import type jayson from "jayson";
|
|
3
|
-
import
|
|
4
|
-
import { ISTSLogger, IAgentManager, InjectionToken } from "@nsshunt/stsutils";
|
|
3
|
+
import { Injector, ISTSLogger } from "@nsshunt/stsutils";
|
|
5
4
|
import { InstrumentBaseTelemetry, Gauge } from "@nsshunt/stsobservability";
|
|
6
|
-
import {
|
|
7
|
-
import { TinyEmitter } from "tiny-emitter";
|
|
8
|
-
import { Worker, Address } from "node:cluster";
|
|
5
|
+
import { IContextBase } from "@nsshunt/stsinstrumentmanagerclient";
|
|
9
6
|
import { Server as HTTPSServer } from "node:https";
|
|
10
7
|
import { Server as HTTPServer } from "node:http";
|
|
11
8
|
import tls from "node:tls";
|
|
12
|
-
import { IDBAccessLayer } from "@nsshunt/stsdatamanagement";
|
|
13
9
|
export interface IMetrics {
|
|
14
|
-
Start: () => void;
|
|
15
|
-
Stop: () => void;
|
|
16
10
|
AddMetricsProvider: (provider: () => Promise<void>) => void;
|
|
17
11
|
UpdateInstrument: (instrumentName: Gauge, telemetry: InstrumentBaseTelemetry) => void;
|
|
18
12
|
LogMessageToLoggerInstrument: (message: any) => void;
|
|
@@ -31,35 +25,6 @@ export interface IServiceProcessContext extends IContextBase {
|
|
|
31
25
|
serviceVersion?: string;
|
|
32
26
|
}
|
|
33
27
|
export declare function CreateServiceProcessContext(serviceName: string, serviceVersion: string, serviceInstanceId: string, hostName: string, processId: number, parentProcessId: number): IServiceProcessContext;
|
|
34
|
-
export interface IProcessBaseEvents {
|
|
35
|
-
processSigint: [];
|
|
36
|
-
processSigterm: [];
|
|
37
|
-
processExit: [workerid: number];
|
|
38
|
-
ProcessTerminate: [];
|
|
39
|
-
clusterListening: [worker: Worker, address: Address];
|
|
40
|
-
clusterOnline: [worker: Worker];
|
|
41
|
-
clusterExit: [worker: Worker, code: number, signal: string];
|
|
42
|
-
workerMessage: [id: number, payload: any];
|
|
43
|
-
workerError: [error: Error];
|
|
44
|
-
workerAdded: [id: number];
|
|
45
|
-
workerExit: [code: number, signal: string];
|
|
46
|
-
prometheusScrapesListening: [
|
|
47
|
-
url: string,
|
|
48
|
-
endpoint: string,
|
|
49
|
-
prometheusClusterPort: string
|
|
50
|
-
];
|
|
51
|
-
}
|
|
52
|
-
export interface IProcessBase extends TinyEmitter {
|
|
53
|
-
ProcessStartup: () => void;
|
|
54
|
-
ProcessTerminate(): Promise<void>;
|
|
55
|
-
emit<K extends keyof IProcessBaseEvents>(event: K, ...arg: IProcessBaseEvents[K]): this;
|
|
56
|
-
on<K extends keyof IProcessBaseEvents>(event: K, callback: (...arg: IProcessBaseEvents[K]) => void): this;
|
|
57
|
-
off<K extends keyof IProcessBaseEvents>(event: K, callback: (...arg: IProcessBaseEvents[K]) => void): this;
|
|
58
|
-
}
|
|
59
|
-
export interface IMasterProcessBase extends IProcessBase {
|
|
60
|
-
SetupServer: () => Promise<void>;
|
|
61
|
-
MasterStarted(): void;
|
|
62
|
-
}
|
|
63
28
|
export interface IClusterWorkerManager {
|
|
64
29
|
KillWorker: (id: string, signal: NodeJS.Signals, options: any, killProcess: boolean, allowKillAll: boolean) => boolean;
|
|
65
30
|
AddWorker: (options: any) => number;
|
|
@@ -69,183 +34,43 @@ export interface IClusterWorkerManager {
|
|
|
69
34
|
SpawnWorker: (spawnWorkerOptions?: any) => number;
|
|
70
35
|
BroadcastDataToWorkers: (command: any, data: any) => void;
|
|
71
36
|
}
|
|
72
|
-
export interface IServerProcessBase extends IProcessBase {
|
|
73
|
-
Terminate: (clusterPerformExit: boolean, signal?: any) => Promise<void>;
|
|
74
|
-
SetupServer(): Promise<boolean>;
|
|
75
|
-
ProcessStarted(): void;
|
|
76
|
-
}
|
|
77
|
-
export interface ISingleProcessBase extends IServerProcessBase {
|
|
78
|
-
TerminateApplication(): Promise<void>;
|
|
79
|
-
}
|
|
80
|
-
export interface IWorkerProcessBase extends IServerProcessBase {
|
|
81
|
-
}
|
|
82
37
|
export interface STSExpressServer {
|
|
83
38
|
get App(): express.Express;
|
|
84
39
|
}
|
|
85
|
-
/**
|
|
86
|
-
* Factory method that adds express routes to the express app object.
|
|
87
|
-
*/
|
|
88
|
-
export type ExpressRouteFactory = (app: express.Express) => void;
|
|
89
40
|
export type STSServerType = "NONE" | "EXPRESS" | "EXPRESS_TLS" | "TCPRAW_TLS" | "JSONRPC2_TLS";
|
|
90
|
-
export interface ProcessOptions {
|
|
91
|
-
/**
|
|
92
|
-
* Is this service worker the master worker (thread).
|
|
93
|
-
*/
|
|
94
|
-
isMaster: boolean;
|
|
95
|
-
/**
|
|
96
|
-
* Unique service instance ID
|
|
97
|
-
*/
|
|
98
|
-
serviceInstanceId: string;
|
|
99
|
-
/**
|
|
100
|
-
* HTTPS service public key path.
|
|
101
|
-
*/
|
|
102
|
-
httpsServerKeyPath: string;
|
|
103
|
-
/**
|
|
104
|
-
* HTTPS service certificate (private key) path.
|
|
105
|
-
*/
|
|
106
|
-
httpsServerCertificatePath: string;
|
|
107
|
-
/**
|
|
108
|
-
* Determines whether the process will explicitly exit (using code 0) when any terminate signal is received.
|
|
109
|
-
*/
|
|
110
|
-
processExitOnTerminate: boolean;
|
|
111
|
-
/**
|
|
112
|
-
* Does this service run a Web Socket Server (wss).
|
|
113
|
-
*/
|
|
114
|
-
wssServer: boolean;
|
|
115
|
-
/**
|
|
116
|
-
* If this service run a Web Socket Server (wss), this is the path to use (Note: The default is /socket.io/)
|
|
117
|
-
* https://socket.io/docs/v4/reverse-proxy/
|
|
118
|
-
* https://socket.io/docs/v4/namespaces/
|
|
119
|
-
* Custom Paths should use: ['/__custom_path__/socket.io/'] as the path and in NGINX reverse proxy, e.g. /nsstsfhir/socket.io/
|
|
120
|
-
* Note: The custom path has nothing to do with the name of any namespaces being used within a server on a custom path.
|
|
121
|
-
* ---------------------------------------
|
|
122
|
-
* Server Setup:
|
|
123
|
-
* ---------------------------------------
|
|
124
|
-
* import { Server } from "socket.io";
|
|
125
|
-
* const io = new Server({
|
|
126
|
-
* path: "/my-custom-path/"
|
|
127
|
-
* });
|
|
128
|
-
* ---------------------------------------
|
|
129
|
-
* Client Setup:
|
|
130
|
-
* ---------------------------------------
|
|
131
|
-
* import { io } from "socket.io-client";
|
|
132
|
-
* const socket = io({
|
|
133
|
-
* path: "/my-custom-path/"
|
|
134
|
-
* });
|
|
135
|
-
*/
|
|
136
|
-
wssCustomPath: string;
|
|
137
|
-
/**
|
|
138
|
-
* Service Prometheus metric support.
|
|
139
|
-
*/
|
|
140
|
-
prometheusSupport: boolean;
|
|
141
|
-
/**
|
|
142
|
-
* Service endpoint (without trailing /). Example: https://localhost
|
|
143
|
-
*/
|
|
144
|
-
endpoint: string;
|
|
145
|
-
/**
|
|
146
|
-
* Service API root (without trailing /). Example: /stsrest01/v1
|
|
147
|
-
*/
|
|
148
|
-
apiRoot: string;
|
|
149
|
-
/**
|
|
150
|
-
* Service listen port. Example: 3001.
|
|
151
|
-
* Note that unix domain sockets are also supported. Example: /tmp/stsrest01.sock.
|
|
152
|
-
* The socket file may also need permissions changed, i.e. chmodSync(port, 511); or chmodSync(port, 777);
|
|
153
|
-
* Axios client calls will also need to use socketPath. Example: ..., socketPath: '/tmp/stsrest01.sock'
|
|
154
|
-
* Ref: https://stackoverflow.com/questions/21342828/node-express-unix-domain-socket-permissions
|
|
155
|
-
* To setup side car service (per running machine/node)
|
|
156
|
-
* sudo mkdir /var/run/sts
|
|
157
|
-
* sudo chown stsuser /var/run/sts
|
|
158
|
-
* In .env file per service
|
|
159
|
-
* PORT=/var/run/sts/stsrest01.sock
|
|
160
|
-
*/
|
|
161
|
-
listenPort: string;
|
|
162
|
-
/**
|
|
163
|
-
* Port that this service will be exposed externally on, i.e. clients will use this port to invoke APIs on this service.
|
|
164
|
-
*/
|
|
165
|
-
port: string;
|
|
166
|
-
/**
|
|
167
|
-
* Prometheus Cluster Server port (port used for cluster prometheus scrapes). Example: 3011.
|
|
168
|
-
*/
|
|
169
|
-
prometheusClusterPort: string;
|
|
170
|
-
/**
|
|
171
|
-
* Service Name. Example: Rest01
|
|
172
|
-
*/
|
|
173
|
-
serviceName: string;
|
|
174
|
-
/**
|
|
175
|
-
* Service Version. Example: 1.0.0
|
|
176
|
-
*/
|
|
177
|
-
serviceVersion: string;
|
|
178
|
-
/**
|
|
179
|
-
* Determines where logging is output to the console (stdout).
|
|
180
|
-
*/
|
|
181
|
-
consoleLogging: boolean;
|
|
182
|
-
/**
|
|
183
|
-
* Determines where logging is output to the logging instrument (if present).
|
|
184
|
-
*/
|
|
185
|
-
instrumentLogging: boolean;
|
|
186
|
-
serviceProcessContext?: IServiceProcessContext;
|
|
187
|
-
/**
|
|
188
|
-
* Factory method that adds express routes to the express app object. Used for non-static content.
|
|
189
|
-
* Non-Static content is applied after logging middleware.
|
|
190
|
-
*/
|
|
191
|
-
expressServerRouteFactory?: ExpressRouteFactory;
|
|
192
|
-
/**
|
|
193
|
-
* Factory method that adds express routes to the express app object for static content.
|
|
194
|
-
* Static content is applied before logging middleware.
|
|
195
|
-
*/
|
|
196
|
-
expressServerRouteStaticFactory?: ExpressRouteFactory;
|
|
197
|
-
/**
|
|
198
|
-
* Determines whether the service will monitor its own health via the /latency API endpoint.
|
|
199
|
-
* Note: The service must implement the /latency end-point for this to work.
|
|
200
|
-
*/
|
|
201
|
-
useLatency: boolean;
|
|
202
|
-
/**
|
|
203
|
-
* Determines whether this service is going to need database access.
|
|
204
|
-
*/
|
|
205
|
-
useDatabase: boolean;
|
|
206
|
-
instrumentationObservationInterval: number;
|
|
207
|
-
instrumentationTimeWindow: number;
|
|
208
|
-
useSocketIoRedisAdaptor: boolean;
|
|
209
|
-
socketIoRedisAdaptorUrl?: string;
|
|
210
|
-
useRedisInstrumentationTransport?: boolean;
|
|
211
|
-
redisInstrumentationTransportUrl?: string;
|
|
212
|
-
/**
|
|
213
|
-
* Is this application using nodejs cluster mode?
|
|
214
|
-
*/
|
|
215
|
-
clusterMode: boolean;
|
|
216
|
-
logger: ISTSLogger;
|
|
217
|
-
publisherLogger: ISTSLogger;
|
|
218
|
-
publishInterval: number;
|
|
219
|
-
}
|
|
220
41
|
export interface ISTSServer {
|
|
221
42
|
Stop(): Promise<void>;
|
|
222
43
|
GetAttributes(): Record<string, any>;
|
|
223
44
|
GetServerType(): STSServerType;
|
|
224
45
|
GetHttpServer(): jayson.TlsServer | HTTPSServer | HTTPServer | tls.Server | undefined;
|
|
225
46
|
}
|
|
226
|
-
export interface
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
47
|
+
export interface IPlugin<TOptions = Record<string, unknown>> {
|
|
48
|
+
install(injector: Injector, options?: TOptions): void;
|
|
49
|
+
Start(): void | Promise<void>;
|
|
50
|
+
Stop(): void | Promise<void>;
|
|
51
|
+
}
|
|
52
|
+
export interface ISTSServerBaseOptions {
|
|
53
|
+
httpsServerKeyPath?: string;
|
|
54
|
+
httpsServerCertificatePath?: string;
|
|
55
|
+
listenPort: number;
|
|
56
|
+
endpoint: string;
|
|
57
|
+
apiRoot: string;
|
|
58
|
+
logger: ISTSLogger;
|
|
59
|
+
}
|
|
60
|
+
export interface ISTSExpressServerOptions extends ISTSServerBaseOptions {
|
|
61
|
+
serviceName: string;
|
|
62
|
+
useTls: boolean;
|
|
63
|
+
prometheusSupport: boolean;
|
|
64
|
+
wssServer: boolean;
|
|
65
|
+
wssCustomPath?: string;
|
|
66
|
+
useSocketIoRedisAdaptor: boolean;
|
|
67
|
+
socketIoRedisAdaptorUrl?: string;
|
|
68
|
+
clusterMode: boolean;
|
|
230
69
|
}
|
|
231
|
-
export interface
|
|
232
|
-
|
|
70
|
+
export interface ISTSJsonRPCServerOptions extends ISTSServerBaseOptions {
|
|
71
|
+
coreDomain: string;
|
|
233
72
|
}
|
|
234
|
-
export interface
|
|
235
|
-
|
|
236
|
-
LogInfoMessage(message: any): void;
|
|
237
|
-
LogWarnMessage(message: any): void;
|
|
238
|
-
LogDebugMessage(message: any): void;
|
|
73
|
+
export interface ISTSRPCRawServerOptions extends ISTSServerBaseOptions {
|
|
74
|
+
coreDomain: string;
|
|
239
75
|
}
|
|
240
|
-
export declare const AgentManagerToken: InjectionToken<IAgentManager>;
|
|
241
|
-
export declare const PublishInstrumentControllerToken: InjectionToken<PublishInstrumentController | undefined>;
|
|
242
|
-
export declare const ProcessOptionsToken: InjectionToken<ProcessOptions>;
|
|
243
|
-
export declare const DataManagerToken: InjectionToken<IDataManager | undefined>;
|
|
244
|
-
export declare const STSLoggerToken: InjectionToken<ISTSLogger>;
|
|
245
|
-
export declare const LogManagerToken: InjectionToken<ILogManager>;
|
|
246
|
-
export declare const STSServerToken: InjectionToken<ISTSServer | undefined>;
|
|
247
|
-
export declare const ProcessBaseToken: InjectionToken<IProcessBase>;
|
|
248
|
-
export declare const ProcessMetricsToken: InjectionToken<IMetrics>;
|
|
249
|
-
export declare const STSTransportLoggerWinstonToken: InjectionToken<Transport>;
|
|
250
|
-
export declare const LatencyManagerToken: InjectionToken<ILatencyManager>;
|
|
251
76
|
//# sourceMappingURL=commonTypes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"commonTypes.d.ts","sourceRoot":"","sources":["../src/commonTypes.ts"],"names":[],"mappings":"AAEA,OAA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AW,GACX,UAAU,GACV,GAAG,CAAC,MAAM,GACV,SAAS,CAAC;CACnB;AAED,MAAM,WAAW,OAAO,CAAC,QAAQ,GAAG,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC;IACvD,OAAO,CAAC,QAAQ,EAAE,QAAQ,EAAE,OAAO,CAAC,EAAE,QAAQ,GAAG,IAAI,CAAC;IAEtD,KAAK,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;IAC9B,IAAI,IAAI,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC,CAAC;CAChC;AAED,MAAM,WAAW,qBAAqB;IAClC,kBAAkB,CAAC,EAAE,MAAM,CAAC;IAC5B,0BAA0B,CAAC,EAAE,MAAM,CAAC;IACpC,UAAU,EAAE,MAAM,CAAC;IACnB,QAAQ,EAAE,MAAM,CAAC;IACjB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,EAAE,UAAU,CAAC;CACtB;AAED,MAAM,WAAW,wBAAyB,SAAQ,qBAAqB;IACnE,WAAW,EAAE,MAAM,CAAC;IACpB,MAAM,EAAE,OAAO,CAAC;IAChB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,SAAS,EAAE,OAAO,CAAC;IACnB,aAAa,CAAC,EAAE,MAAM,CAAC;IACvB,uBAAuB,EAAE,OAAO,CAAC;IACjC,uBAAuB,CAAC,EAAE,MAAM,CAAC;IACjC,WAAW,EAAE,OAAO,CAAC;CACxB;AAED,MAAM,WAAW,wBAAyB,SAAQ,qBAAqB;IACnE,UAAU,EAAE,MAAM,CAAC;CACtB;AAED,MAAM,WAAW,uBAAwB,SAAQ,qBAAqB;IAClE,UAAU,EAAE,MAAM,CAAC;CACtB"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"app.d.ts","sourceRoot":"","sources":["../../src/exampleapp/app.ts"],"names":[],"mappings":""}
|
package/types/index.d.ts
CHANGED
|
@@ -1,15 +1,19 @@
|
|
|
1
1
|
export * from "./commonTypes.js";
|
|
2
|
-
export * from "./process/masterprocessbase.js";
|
|
3
|
-
export * from "./process/processbase.js";
|
|
4
|
-
export * from "./process/serverprocessbase.js";
|
|
5
|
-
export * from "./process/singleprocessbase.js";
|
|
6
|
-
export * from "./process/workerprocessbase.js";
|
|
7
|
-
export * from "./process/datamanager.js";
|
|
8
2
|
export * from "./controller/stslatencycontroller.js";
|
|
9
3
|
export * from "./route/stslatencyroute.js";
|
|
10
|
-
export * from "./publishertransports/publishTransportUtils.js";
|
|
11
4
|
export * from "./logger/stsTransportLoggerWinston.js";
|
|
12
5
|
export * from "./logger/stsTransportWinston.js";
|
|
13
6
|
export * from "./logger/stsTransportLoggerSocket.js";
|
|
14
7
|
export * from "./logger/socketClientLogPublisher.js";
|
|
8
|
+
export * from "./plugins/stsclusterworkermanagerplugin.js";
|
|
9
|
+
export * from "./plugins/stsconfigplugin.js";
|
|
10
|
+
export * from "./plugins/stsexpresscontrollerplugin.js";
|
|
11
|
+
export * from "./plugins/stsinstrumentmanagerplugin.js";
|
|
12
|
+
export * from "./plugins/stslatencyplugin.js";
|
|
13
|
+
export * from "./plugins/stslifecycleplugin.js";
|
|
14
|
+
export * from "./plugins/stsloggerplugin.js";
|
|
15
|
+
export * from "./plugins/stsmetricsplugin.js";
|
|
16
|
+
export * from "./plugins/stspgpoolmanagerplugin.js";
|
|
17
|
+
export * from "./plugins/stsserverplugin.js";
|
|
18
|
+
export * from "./stsapp.js";
|
|
15
19
|
//# sourceMappingURL=index.d.ts.map
|
package/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,kBAAkB,CAAC;AACjC,cAAc,sCAAsC,CAAC;AACrD,cAAc,4BAA4B,CAAC;AAC3C,cAAc,uCAAuC,CAAC;AACtD,cAAc,iCAAiC,CAAC;AAChD,cAAc,sCAAsC,CAAC;AACrD,cAAc,sCAAsC,CAAC;AAErD,cAAc,4CAA4C,CAAC;AAC3D,cAAc,8BAA8B,CAAC;AAC7C,cAAc,yCAAyC,CAAC;AACxD,cAAc,yCAAyC,CAAC;AACxD,cAAc,+BAA+B,CAAC;AAC9C,cAAc,iCAAiC,CAAC;AAChD,cAAc,8BAA8B,CAAC;AAC7C,cAAc,+BAA+B,CAAC;AAC9C,cAAc,qCAAqC,CAAC;AACpD,cAAc,8BAA8B,CAAC;AAE7C,cAAc,aAAa,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"stsTransportLoggerSocket.d.ts","sourceRoot":"","sources":["../../src/logger/stsTransportLoggerSocket.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,EAAE,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAStE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,MAAM,WAAW,gCAAiC,SAAQ,sBAAsB;IAC5E,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,UAAU,CAAC;CACtB;AAED,qBAAa,wBAAyB,SAAQ,SAAS;;gBAOvC,IAAI,EAAE,gCAAgC;IAUlD,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG;IAiBrB,KAAK,IAAI,IAAI;
|
|
1
|
+
{"version":3,"file":"stsTransportLoggerSocket.d.ts","sourceRoot":"","sources":["../../src/logger/stsTransportLoggerSocket.ts"],"names":[],"mappings":"AACA,OAAO,SAAS,EAAE,EAAE,sBAAsB,EAAE,MAAM,mBAAmB,CAAC;AAStE,OAAO,EAAE,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAE/C,MAAM,WAAW,gCAAiC,SAAQ,sBAAsB;IAC5E,KAAK,EAAE,MAAM,EAAE,CAAC;IAChB,MAAM,EAAE,UAAU,CAAC;CACtB;AAED,qBAAa,wBAAyB,SAAQ,SAAS;;gBAOvC,IAAI,EAAE,gCAAgC;IAUlD,GAAG,CAAC,IAAI,EAAE,GAAG,EAAE,QAAQ,EAAE,GAAG;IAiBrB,KAAK,IAAI,IAAI;CAKvB"}
|
|
@@ -1,11 +1,15 @@
|
|
|
1
1
|
import { IClusterWorkerManager } from "./../commonTypes.js";
|
|
2
|
+
import { JSONObject } from "@nsshunt/stsutils";
|
|
2
3
|
import { TinyEmitter } from "tiny-emitter";
|
|
4
|
+
export interface IClusterWorkerManagerOptions {
|
|
5
|
+
workerEnvironmentVars: JSONObject;
|
|
6
|
+
}
|
|
3
7
|
export declare class ClusterWorkerManager extends TinyEmitter implements IClusterWorkerManager {
|
|
4
8
|
#private;
|
|
5
9
|
private readonly metrics;
|
|
6
10
|
private readonly options;
|
|
7
11
|
private readonly loggerManager;
|
|
8
|
-
constructor();
|
|
12
|
+
constructor(options: IClusterWorkerManagerOptions);
|
|
9
13
|
KillWorker: (id: string, signal: NodeJS.Signals | undefined, options: any, killProcess: boolean, allowKillAll: boolean) => boolean;
|
|
10
14
|
KillWorkers: (signal: NodeJS.Signals, keepOne?: boolean) => void;
|
|
11
15
|
IncWorkers: () => void;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"clusterworkermanager.d.ts","sourceRoot":"","sources":["../../src/plugins/clusterworkermanager.ts"],"names":[],"mappings":"AAUA,OAAO,EAAE,qBAAqB,EAAE,MAAM,qBAAqB,CAAC;AAE5D,OAAO,EAAU,UAAU,EAAE,MAAM,mBAAmB,CAAC;AAEvD,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAK3C,MAAM,WAAW,4BAA4B;IACzC,qBAAqB,EAAE,UAAU,CAAC;CACrC;AAED,qBAAa,oBACT,SAAQ,WACR,YAAW,qBAAqB;;IAKhC,OAAO,CAAC,QAAQ,CAAC,OAAO,CAAiC;IACzD,OAAO,CAAC,QAAQ,CAAC,OAAO,CAA+B;IACvD,OAAO,CAAC,QAAQ,CAAC,aAAa,CAAgC;gBAElD,OAAO,EAAE,4BAA4B;IA+HjD,UAAU,GACN,IAAI,MAAM,EACV,QAAQ,MAAM,CAAC,OAAO,YAAY,EAClC,SAAS,GAAG,EACZ,aAAa,OAAO,EACpB,cAAc,OAAO,KACtB,OAAO,CA0CR;IAEF,WAAW,GAAI,QAAQ,MAAM,CAAC,OAAO,EAAE,UAAU,OAAO,KAAG,IAAI,CAwB7D;IAUF,UAAU,QAAO,IAAI,CAMnB;IAEF,UAAU,QAAO,IAAI,CAMnB;IAEF,SAAS,GAAI,SAAS,GAAG,KAAG,MAAM,CAehC;IAEF,WAAW,GAAI,qBAAqB,GAAG,KAAG,MAAM,CA+C9C;IAEF,sBAAsB,GAAI,SAAS,GAAG,EAAE,MAAM,GAAG,UAc/C;CACL"}
|