@swizzyweb/swerve 0.5.3
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/LICENSE +202 -0
- package/README.md +237 -0
- package/dist/bootstrapBun.d.ts +2 -0
- package/dist/bootstrapBun.js +3 -0
- package/dist/bootstrapBunCluster.d.ts +2 -0
- package/dist/bootstrapBunCluster.js +35 -0
- package/dist/bootstrapDeno.d.ts +2 -0
- package/dist/bootstrapDeno.js +3 -0
- package/dist/bootstrapDeno.sh +3 -0
- package/dist/bootstrapDeno.ts +4 -0
- package/dist/bootstrapDenoCluster.d.ts +1 -0
- package/dist/bootstrapDenoCluster.js +35 -0
- package/dist/bootstrapDenoCluster.ts +39 -0
- package/dist/bootstrapNode.d.ts +2 -0
- package/dist/bootstrapNode.js +3 -0
- package/dist/bootstrapNodeCluster.d.ts +2 -0
- package/dist/bootstrapNodeCluster.js +35 -0
- package/dist/config/config-parser.d.ts +17 -0
- package/dist/config/config-parser.js +43 -0
- package/dist/config/config.d.ts +15 -0
- package/dist/config/config.js +1 -0
- package/dist/config/index.d.ts +2 -0
- package/dist/config/index.js +2 -0
- package/dist/index.d.ts +3 -0
- package/dist/index.js +3 -0
- package/dist/logs/swerve-jmoney-Laptop-16-AMD-Ryzen-7040-Series-2025-08-10-00.log +3 -0
- package/dist/logs/swerve-jmoney-Laptop-16-AMD-Ryzen-7040-Series-2025-08-11-00.log +2 -0
- package/dist/main.d.ts +10 -0
- package/dist/main.js +100 -0
- package/dist/main.ts +129 -0
- package/dist/mainCluster.d.ts +2 -0
- package/dist/mainCluster.js +40 -0
- package/dist/mainCluster.ts +46 -0
- package/dist/swerve.d.ts +82 -0
- package/dist/swerve.js +275 -0
- package/dist/utils/getArgs.d.ts +12 -0
- package/dist/utils/getArgs.js +208 -0
- package/dist/utils/getPackageJson.d.ts +14 -0
- package/dist/utils/getPackageJson.js +78 -0
- package/dist/utils/index.d.ts +2 -0
- package/dist/utils/index.js +2 -0
- package/dist/utils/installWebservice.d.ts +4 -0
- package/dist/utils/installWebservice.js +87 -0
- package/package.json +67 -0
|
@@ -0,0 +1,43 @@
|
|
|
1
|
+
import { readFile } from "fs/promises";
|
|
2
|
+
import path from "path";
|
|
3
|
+
export class SwerveConfigException {
|
|
4
|
+
message;
|
|
5
|
+
stack;
|
|
6
|
+
constructor(message) {
|
|
7
|
+
this.message = message;
|
|
8
|
+
this.stack = new Error(message).stack;
|
|
9
|
+
}
|
|
10
|
+
}
|
|
11
|
+
export class SwerveConfigParser {
|
|
12
|
+
async parse(configPath) {
|
|
13
|
+
let actualPath;
|
|
14
|
+
if (configPath.startsWith(".")) {
|
|
15
|
+
actualPath = path.join(configPath);
|
|
16
|
+
}
|
|
17
|
+
else {
|
|
18
|
+
actualPath = configPath;
|
|
19
|
+
}
|
|
20
|
+
const content = await readFile(actualPath, {
|
|
21
|
+
encoding: "utf-8",
|
|
22
|
+
});
|
|
23
|
+
try {
|
|
24
|
+
const config = JSON.parse(content);
|
|
25
|
+
this.validateConfig(config);
|
|
26
|
+
return config;
|
|
27
|
+
}
|
|
28
|
+
catch (e) {
|
|
29
|
+
throw {
|
|
30
|
+
message: `Error parsing config, ${e.message}`,
|
|
31
|
+
stack: e.stack ?? new Error("Error parsing config").stack,
|
|
32
|
+
};
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
validateConfig(config) {
|
|
36
|
+
if (typeof config.port !== "number") {
|
|
37
|
+
throw new SwerveConfigException("Invalid port");
|
|
38
|
+
}
|
|
39
|
+
if (typeof config.services !== "object") {
|
|
40
|
+
throw new SwerveConfigException("Invalid services configuration");
|
|
41
|
+
}
|
|
42
|
+
}
|
|
43
|
+
}
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
export type KeyValue<VALUE> = {
|
|
2
|
+
[k: string]: VALUE;
|
|
3
|
+
};
|
|
4
|
+
export interface IService {
|
|
5
|
+
packageName?: string;
|
|
6
|
+
servicePath?: string;
|
|
7
|
+
packageJson?: any;
|
|
8
|
+
logLevel?: string;
|
|
9
|
+
[key: string]: any;
|
|
10
|
+
}
|
|
11
|
+
export interface IConfig {
|
|
12
|
+
port?: number;
|
|
13
|
+
services: KeyValue<IService>;
|
|
14
|
+
[key: string]: any;
|
|
15
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
{"label":"jmoney-Laptop-16-AMD-Ryzen-7040-Series:::swerve:121451:swerve:","level":"info","message":"Getting webservice package @swizzyweb/swerve and will run on port 3005","timestamp":"2025-08-11T03:55:34.252Z"}
|
|
2
|
+
{"label":"jmoney-Laptop-16-AMD-Ryzen-7040-Series:::swerve:121451:swerve:","level":"error","message":"Failed to install web service","timestamp":"2025-08-11T03:55:34.253Z"}
|
|
3
|
+
{"label":"jmoney-Laptop-16-AMD-Ryzen-7040-Series:::swerve:121451:swerve:","level":"error","message":"Error occurred initializing service\n Invalid arguments\n TypeError: Invalid arguments\n at getFullImportPath (file:///home/jmoney/repos/BrowserToolkitWorkspace/swerve/node_modules/@swizzyweb/swerve-manager/dist/utils/installWebservice.js:54:37)\n at SwerveManager.installWebService (file:///home/jmoney/repos/BrowserToolkitWorkspace/swerve/node_modules/@swizzyweb/swerve-manager/dist/swerve.js:150:36)\n at SwerveManager.runWithArgs (file:///home/jmoney/repos/BrowserToolkitWorkspace/swerve/node_modules/@swizzyweb/swerve-manager/dist/swerve.js:61:47)\n at async SwerveManager.run (file:///home/jmoney/repos/BrowserToolkitWorkspace/swerve/node_modules/@swizzyweb/swerve-manager/dist/swerve.js:24:32)\n at async runV2 (file:///home/jmoney/repos/BrowserToolkitWorkspace/swerve/dist/bootstrapDeno.js:24:9)\n at async run (file:///home/jmoney/repos/BrowserToolkitWorkspace/swerve/dist/bootstrapDeno.js:34:16)","timestamp":"2025-08-11T03:55:34.253Z"}
|
|
@@ -0,0 +1,2 @@
|
|
|
1
|
+
{"label":"jmoney-Laptop-16-AMD-Ryzen-7040-Series:::swerve:121451:swerve:","level":"info","message":"swerveArgs.services.length < 1","timestamp":"2025-08-11T03:55:34.243Z"}
|
|
2
|
+
{"label":"jmoney-Laptop-16-AMD-Ryzen-7040-Series:::swerve:121451:swerve:","level":"error","message":"Exception running v2 TypeError: newWebServices is not iterable (cannot read property undefined)","timestamp":"2025-08-11T03:55:34.254Z"}
|
package/dist/main.d.ts
ADDED
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
import { Application } from "@swizzyweb/express";
|
|
2
|
+
import { SwerveArgs, ISwerveManager } from "@swizzyweb/swerve-manager";
|
|
3
|
+
export declare function runV2(): Promise<ISwerveManager>;
|
|
4
|
+
export declare function run(): Promise<ISwerveManager>;
|
|
5
|
+
interface RunWithAppArgs {
|
|
6
|
+
app: Application;
|
|
7
|
+
args: SwerveArgs;
|
|
8
|
+
}
|
|
9
|
+
export declare function runWithApp(props: RunWithAppArgs): Promise<any[]>;
|
|
10
|
+
export {};
|
package/dist/main.js
ADDED
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import express from "@swizzyweb/express";
|
|
3
|
+
import { getArgs, installWebService, SwerveManager, } from "@swizzyweb/swerve-manager";
|
|
4
|
+
import { SwizzyWinstonLogger } from "@swizzyweb/swizzy-web-service";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import process from "node:process";
|
|
7
|
+
export async function runV2() {
|
|
8
|
+
let gLogger = new SwizzyWinstonLogger({
|
|
9
|
+
port: 0,
|
|
10
|
+
logLevel: process.env.LOG_LEVEL ?? "info",
|
|
11
|
+
appDataRoot: ".",
|
|
12
|
+
appName: `swerve`,
|
|
13
|
+
ownerName: "swerve",
|
|
14
|
+
hostName: os.hostname(),
|
|
15
|
+
pid: process.pid,
|
|
16
|
+
});
|
|
17
|
+
const swerveManager = new SwerveManager({});
|
|
18
|
+
try {
|
|
19
|
+
const args = await getArgs(process.argv, gLogger);
|
|
20
|
+
await swerveManager.run({ args });
|
|
21
|
+
return swerveManager;
|
|
22
|
+
}
|
|
23
|
+
catch (e) {
|
|
24
|
+
gLogger.error(`Exception running v2 ${e}`);
|
|
25
|
+
throw e;
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
export async function run() {
|
|
29
|
+
if (true) {
|
|
30
|
+
return await runV2();
|
|
31
|
+
}
|
|
32
|
+
let gLogger = new SwizzyWinstonLogger({
|
|
33
|
+
port: 0,
|
|
34
|
+
logLevel: process.env.LOG_LEVEL ?? "info",
|
|
35
|
+
appDataRoot: ".",
|
|
36
|
+
appName: `swerve`,
|
|
37
|
+
hostName: os.hostname(),
|
|
38
|
+
pid: process.pid,
|
|
39
|
+
});
|
|
40
|
+
try {
|
|
41
|
+
const args = await getArgs(process.argv, gLogger);
|
|
42
|
+
const app = express();
|
|
43
|
+
const webServices = await runWithApp({ app, args });
|
|
44
|
+
const port = args.serviceArgs.port ?? 3005;
|
|
45
|
+
gLogger.debug(`Starting express app...`);
|
|
46
|
+
await app.listen(port, (err) => {
|
|
47
|
+
if (err) {
|
|
48
|
+
gLogger.log(err);
|
|
49
|
+
}
|
|
50
|
+
gLogger.info(`${webServices
|
|
51
|
+
.map((service) => {
|
|
52
|
+
return service.name;
|
|
53
|
+
})
|
|
54
|
+
.join(",")} running on port ${port}`);
|
|
55
|
+
});
|
|
56
|
+
}
|
|
57
|
+
catch (e) {
|
|
58
|
+
gLogger.error(`Error occurred initializing service\n ${e.message}\n ${e.stack ?? {}}`);
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
export async function runWithApp(props) {
|
|
62
|
+
const { app, args } = props;
|
|
63
|
+
let gLogger = new SwizzyWinstonLogger({
|
|
64
|
+
port: 0,
|
|
65
|
+
logLevel: process.env.LOG_LEVEL ?? "info",
|
|
66
|
+
appDataRoot: args.appDataRoot,
|
|
67
|
+
appName: `swerve`,
|
|
68
|
+
hostName: os.hostname(),
|
|
69
|
+
pid: process.pid,
|
|
70
|
+
});
|
|
71
|
+
try {
|
|
72
|
+
gLogger = new SwizzyWinstonLogger({
|
|
73
|
+
logLevel: args.serviceArgs.logLevel ?? process.env.LOG_LEVEL ?? "info",
|
|
74
|
+
port: args.port,
|
|
75
|
+
logDir: args.appDataRoot,
|
|
76
|
+
appName: `swerve`,
|
|
77
|
+
hostName: os.hostname(),
|
|
78
|
+
pid: process.pid,
|
|
79
|
+
});
|
|
80
|
+
gLogger.debug(`Swerve Args: ${JSON.stringify(args)}`);
|
|
81
|
+
const PORT = args.port ?? 3005;
|
|
82
|
+
const webServices = [];
|
|
83
|
+
for (const serviceEntry of Object.entries(args.services)) {
|
|
84
|
+
const service = serviceEntry[1];
|
|
85
|
+
const packageName = service.packageName;
|
|
86
|
+
const importPathOrName = service.servicePath;
|
|
87
|
+
const webservice = await installWebService(packageName, importPathOrName, PORT, app, {
|
|
88
|
+
appDataRoot: args.appDataRoot,
|
|
89
|
+
...service,
|
|
90
|
+
...service.serviceConfiguration,
|
|
91
|
+
...args.serviceArgs,
|
|
92
|
+
}, gLogger);
|
|
93
|
+
webServices.push(webservice);
|
|
94
|
+
}
|
|
95
|
+
return webServices;
|
|
96
|
+
}
|
|
97
|
+
catch (e) {
|
|
98
|
+
gLogger.error(`Error occurred initializing service\n ${e.message}\n ${e.stack ?? {}}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
package/dist/main.ts
ADDED
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// @ts-ignore
|
|
2
|
+
import express, { Application } from "../node_modules/@swizzyweb/express";
|
|
3
|
+
import {
|
|
4
|
+
getArgs,
|
|
5
|
+
installWebService,
|
|
6
|
+
SwerveArgs,
|
|
7
|
+
ISwerveManager,
|
|
8
|
+
SwerveManager,
|
|
9
|
+
} from "../node_modules/@swizzyweb/swerve-manager";
|
|
10
|
+
import { SwizzyWinstonLogger } from "../node_modules/@swizzyweb/swizzy-web-service";
|
|
11
|
+
import os from "node:os";
|
|
12
|
+
import process from "node:process";
|
|
13
|
+
|
|
14
|
+
export async function runV2(): Promise<ISwerveManager> {
|
|
15
|
+
let gLogger = new SwizzyWinstonLogger({
|
|
16
|
+
port: 0,
|
|
17
|
+
logLevel: process.env.LOG_LEVEL ?? "info",
|
|
18
|
+
appDataRoot: ".",
|
|
19
|
+
appName: `swerve`,
|
|
20
|
+
ownerName: "swerve",
|
|
21
|
+
hostName: os.hostname(),
|
|
22
|
+
pid: process.pid,
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
const swerveManager: ISwerveManager = new SwerveManager({});
|
|
26
|
+
try {
|
|
27
|
+
const args = await getArgs(process.argv, gLogger);
|
|
28
|
+
await swerveManager.run({ args });
|
|
29
|
+
return swerveManager;
|
|
30
|
+
} catch (e) {
|
|
31
|
+
gLogger.error(`Exception running v2 ${e}`);
|
|
32
|
+
throw e;
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
export async function run() {
|
|
36
|
+
if (true) {
|
|
37
|
+
return await runV2();
|
|
38
|
+
}
|
|
39
|
+
let gLogger = new SwizzyWinstonLogger({
|
|
40
|
+
port: 0,
|
|
41
|
+
logLevel: process.env.LOG_LEVEL ?? "info",
|
|
42
|
+
appDataRoot: ".",
|
|
43
|
+
appName: `swerve`,
|
|
44
|
+
hostName: os.hostname(),
|
|
45
|
+
pid: process.pid,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
try {
|
|
49
|
+
const args = await getArgs(process.argv, gLogger);
|
|
50
|
+
|
|
51
|
+
const app = express();
|
|
52
|
+
const webServices = await runWithApp({ app, args });
|
|
53
|
+
const port = args.serviceArgs.port ?? 3005;
|
|
54
|
+
gLogger.debug(`Starting express app...`);
|
|
55
|
+
await app.listen(port, (err) => {
|
|
56
|
+
if (err) {
|
|
57
|
+
gLogger.log(err);
|
|
58
|
+
}
|
|
59
|
+
gLogger.info(
|
|
60
|
+
`${webServices
|
|
61
|
+
.map((service) => {
|
|
62
|
+
return service.name;
|
|
63
|
+
})
|
|
64
|
+
.join(",")} running on port ${port}`,
|
|
65
|
+
);
|
|
66
|
+
});
|
|
67
|
+
} catch (e) {
|
|
68
|
+
gLogger.error(
|
|
69
|
+
`Error occurred initializing service\n ${e.message}\n ${e.stack ?? {}}`,
|
|
70
|
+
);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
interface RunWithAppArgs {
|
|
75
|
+
app: Application;
|
|
76
|
+
args: SwerveArgs;
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
export async function runWithApp(props: RunWithAppArgs) {
|
|
80
|
+
const { app, args } = props;
|
|
81
|
+
let gLogger = new SwizzyWinstonLogger({
|
|
82
|
+
port: 0,
|
|
83
|
+
logLevel: process.env.LOG_LEVEL ?? "info",
|
|
84
|
+
appDataRoot: args.appDataRoot,
|
|
85
|
+
appName: `swerve`,
|
|
86
|
+
hostName: os.hostname(),
|
|
87
|
+
pid: process.pid,
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
try {
|
|
91
|
+
gLogger = new SwizzyWinstonLogger({
|
|
92
|
+
logLevel: args.serviceArgs.logLevel ?? process.env.LOG_LEVEL ?? "info",
|
|
93
|
+
port: args.port,
|
|
94
|
+
logDir: args.appDataRoot,
|
|
95
|
+
appName: `swerve`,
|
|
96
|
+
hostName: os.hostname(),
|
|
97
|
+
pid: process.pid,
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
gLogger.debug(`Swerve Args: ${JSON.stringify(args)}`);
|
|
101
|
+
|
|
102
|
+
const PORT = args.port ?? 3005;
|
|
103
|
+
const webServices = [];
|
|
104
|
+
for (const serviceEntry of Object.entries(args.services)) {
|
|
105
|
+
const service = serviceEntry[1];
|
|
106
|
+
const packageName = service.packageName;
|
|
107
|
+
const importPathOrName = service.servicePath;
|
|
108
|
+
const webservice = await installWebService(
|
|
109
|
+
packageName,
|
|
110
|
+
importPathOrName,
|
|
111
|
+
PORT,
|
|
112
|
+
app,
|
|
113
|
+
{
|
|
114
|
+
appDataRoot: args.appDataRoot,
|
|
115
|
+
...service,
|
|
116
|
+
...service.serviceConfiguration,
|
|
117
|
+
...args.serviceArgs,
|
|
118
|
+
},
|
|
119
|
+
gLogger,
|
|
120
|
+
);
|
|
121
|
+
webServices.push(webservice);
|
|
122
|
+
}
|
|
123
|
+
return webServices;
|
|
124
|
+
} catch (e) {
|
|
125
|
+
gLogger.error(
|
|
126
|
+
`Error occurred initializing service\n ${e.message}\n ${e.stack ?? {}}`,
|
|
127
|
+
);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
import cluster from "node:cluster";
|
|
3
|
+
import os from "node:os";
|
|
4
|
+
import { run } from "./main.js";
|
|
5
|
+
import process from "node:process";
|
|
6
|
+
import { BrowserLogger } from "@swizzyweb/swizzy-common";
|
|
7
|
+
import { SwizzyWinstonLogger } from "@swizzyweb/swizzy-web-service";
|
|
8
|
+
import { getArgs } from "./utils/index.js";
|
|
9
|
+
/**
|
|
10
|
+
* extra arg:
|
|
11
|
+
* numThreads - number, default to num cpu cores from os
|
|
12
|
+
* */
|
|
13
|
+
async function runCluster() {
|
|
14
|
+
const args = await getArgs(process.argv, new BrowserLogger());
|
|
15
|
+
const logger = new SwizzyWinstonLogger({
|
|
16
|
+
port: args.port,
|
|
17
|
+
// appDataRoot: args.appDataRoot,
|
|
18
|
+
appName: `swerve-root`,
|
|
19
|
+
hostName: os.hostname(),
|
|
20
|
+
pid: process.pid,
|
|
21
|
+
});
|
|
22
|
+
const numThreads = args.serviceArgs?.numThreads ?? os.availableParallelism();
|
|
23
|
+
if (cluster.isPrimary) {
|
|
24
|
+
logger.info(`[ParentThread]: Primary ${process.pid} is running`);
|
|
25
|
+
logger.info(`[ParentThread]: forking ${numThreads} threads`);
|
|
26
|
+
// Fork workers.
|
|
27
|
+
for (let i = 0; i < numThreads; i++) {
|
|
28
|
+
cluster.fork();
|
|
29
|
+
}
|
|
30
|
+
cluster.on("exit", (worker, code, signal) => {
|
|
31
|
+
logger.info(`[ParentThread]: worker ${worker.process.pid} died with code ${code} and singal ${signal}`);
|
|
32
|
+
});
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
// Workers can share any TCP connection
|
|
36
|
+
// In this case it is an HTTP server
|
|
37
|
+
run();
|
|
38
|
+
console.log(`Worker ${process.pid} started`);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
#!/usr/bin/env node
|
|
2
|
+
|
|
3
|
+
import cluster from "node:cluster";
|
|
4
|
+
import http from "node:http";
|
|
5
|
+
import os from "node:os";
|
|
6
|
+
import { run } from "./main.js";
|
|
7
|
+
import process from "node:process";
|
|
8
|
+
import { BrowserLogger } from "@swizzyweb/swizzy-common";
|
|
9
|
+
import { SwizzyWinstonLogger } from "@swizzyweb/swizzy-web-service";
|
|
10
|
+
|
|
11
|
+
import { getArgs } from "./utils/index.js";
|
|
12
|
+
/**
|
|
13
|
+
* extra arg:
|
|
14
|
+
* numThreads - number, default to num cpu cores from os
|
|
15
|
+
* */
|
|
16
|
+
async function runCluster() {
|
|
17
|
+
const args = await getArgs(process.argv, new BrowserLogger());
|
|
18
|
+
const logger = new SwizzyWinstonLogger({
|
|
19
|
+
port: args.port,
|
|
20
|
+
// appDataRoot: args.appDataRoot,
|
|
21
|
+
appName: `swerve-root`,
|
|
22
|
+
hostName: os.hostname(),
|
|
23
|
+
pid: process.pid,
|
|
24
|
+
});
|
|
25
|
+
const numThreads = args.serviceArgs?.numThreads ?? os.availableParallelism();
|
|
26
|
+
if (cluster.isPrimary) {
|
|
27
|
+
logger.info(`[ParentThread]: Primary ${process.pid} is running`);
|
|
28
|
+
logger.info(`[ParentThread]: forking ${numThreads} threads`);
|
|
29
|
+
// Fork workers.
|
|
30
|
+
for (let i = 0; i < numThreads; i++) {
|
|
31
|
+
cluster.fork();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
cluster.on("exit", (worker, code, signal) => {
|
|
35
|
+
logger.info(
|
|
36
|
+
`[ParentThread]: worker ${worker.process.pid} died with code ${code} and singal ${signal}`,
|
|
37
|
+
);
|
|
38
|
+
});
|
|
39
|
+
} else {
|
|
40
|
+
// Workers can share any TCP connection
|
|
41
|
+
// In this case it is an HTTP server
|
|
42
|
+
|
|
43
|
+
run();
|
|
44
|
+
console.log(`Worker ${process.pid} started`);
|
|
45
|
+
}
|
|
46
|
+
}
|
package/dist/swerve.d.ts
ADDED
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import { Application } from "@swizzyweb/express";
|
|
2
|
+
import { SwerveArgs } from "./utils/index.js";
|
|
3
|
+
import { AnyServer, IWebService, WebService } from "@swizzyweb/swizzy-web-service";
|
|
4
|
+
import { ILogger } from "@swizzyweb/swizzy-common";
|
|
5
|
+
export interface ISwerveManager {
|
|
6
|
+
run(request: RunRequest): Promise<RunResponse>;
|
|
7
|
+
stop(request: StopRequest): Promise<void>;
|
|
8
|
+
getRunningWebServices(props: GetRunningWebServiceRequest): Promise<GetRunningWebServiceResponse>;
|
|
9
|
+
}
|
|
10
|
+
export interface GetRunningWebServiceRequest {
|
|
11
|
+
}
|
|
12
|
+
export interface GetRunningWebServiceResponse {
|
|
13
|
+
webServices: {
|
|
14
|
+
[instanceId: string]: {
|
|
15
|
+
webService: any;
|
|
16
|
+
serviceConfig: any;
|
|
17
|
+
};
|
|
18
|
+
};
|
|
19
|
+
}
|
|
20
|
+
export declare enum InstanceType {
|
|
21
|
+
webservice = "webservice",
|
|
22
|
+
stack = "stack"
|
|
23
|
+
}
|
|
24
|
+
export interface InstanceDetails {
|
|
25
|
+
instanceType: InstanceType;
|
|
26
|
+
instanceId: string;
|
|
27
|
+
}
|
|
28
|
+
export interface StopRequest {
|
|
29
|
+
instanceDetails: InstanceDetails;
|
|
30
|
+
}
|
|
31
|
+
export interface RunRequest {
|
|
32
|
+
args?: SwerveArgs;
|
|
33
|
+
}
|
|
34
|
+
export interface RunResponse {
|
|
35
|
+
webServices: WebService<any>[];
|
|
36
|
+
}
|
|
37
|
+
export type Apps = {
|
|
38
|
+
[key: number]: {
|
|
39
|
+
app: Application;
|
|
40
|
+
server?: AnyServer;
|
|
41
|
+
services: {
|
|
42
|
+
[instanceId: string]: {
|
|
43
|
+
webService: IWebService;
|
|
44
|
+
serviceArgs: SwerveArgs;
|
|
45
|
+
runRequest: RunRequest;
|
|
46
|
+
};
|
|
47
|
+
};
|
|
48
|
+
};
|
|
49
|
+
};
|
|
50
|
+
export interface SwerveManagerProps {
|
|
51
|
+
apps?: Apps;
|
|
52
|
+
webServices?: WebService<any>[];
|
|
53
|
+
}
|
|
54
|
+
export interface WebServiceConfiguration {
|
|
55
|
+
}
|
|
56
|
+
type WebServiceConfigurations = {
|
|
57
|
+
[instanceId: string]: WebServiceConfiguration;
|
|
58
|
+
};
|
|
59
|
+
export declare class SwerveManager implements ISwerveManager {
|
|
60
|
+
apps: Apps;
|
|
61
|
+
webServices: WebService<any>[];
|
|
62
|
+
configurations: WebServiceConfigurations;
|
|
63
|
+
constructor(props: SwerveManagerProps);
|
|
64
|
+
run(request: RunRequest): Promise<RunResponse>;
|
|
65
|
+
runWithArgs(request: RunRequest): Promise<WebService<any>[]>;
|
|
66
|
+
private runWithApp;
|
|
67
|
+
installWebService(props: {
|
|
68
|
+
serviceKey: string;
|
|
69
|
+
importPathOrName: string;
|
|
70
|
+
app: Application;
|
|
71
|
+
appDataRoot: string;
|
|
72
|
+
packageName: string;
|
|
73
|
+
port: number;
|
|
74
|
+
gLogger: ILogger<any>;
|
|
75
|
+
serviceArgs: {
|
|
76
|
+
[key: string]: any;
|
|
77
|
+
};
|
|
78
|
+
}): Promise<any>;
|
|
79
|
+
stop(request: StopRequest): Promise<void>;
|
|
80
|
+
getRunningWebServices(props: GetRunningWebServiceRequest): Promise<GetRunningWebServiceResponse>;
|
|
81
|
+
}
|
|
82
|
+
export {};
|