@dnax/core 0.20.1 → 0.21.0
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/app/index.ts +75 -65
- package/config/index.ts +2 -0
- package/driver/mongo/rest.ts +9 -2
- package/package.json +1 -1
- package/types/index.ts +1 -1
package/app/index.ts
CHANGED
|
@@ -25,6 +25,7 @@ async function runApp(config?: configRunApp, clb?: Function) {
|
|
|
25
25
|
await loadCfg(); // Load Config
|
|
26
26
|
|
|
27
27
|
const PORT = Cfg.server?.port || process.env?.PORT || 4000;
|
|
28
|
+
const CLUSTER_MODE = Cfg?.clusterMode ?? false;
|
|
28
29
|
/* const PORT_SOCKET = Cfg.server?.socket?.port || 9000;
|
|
29
30
|
|
|
30
31
|
// available port Socket
|
|
@@ -37,81 +38,90 @@ async function runApp(config?: configRunApp, clb?: Function) {
|
|
|
37
38
|
}); */
|
|
38
39
|
|
|
39
40
|
// available port Server
|
|
40
|
-
await findPort
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
//
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
if (config?.beforeStart) {
|
|
49
|
-
for (const fn of config?.beforeStart) {
|
|
50
|
-
await fn();
|
|
51
|
-
}
|
|
41
|
+
await findPort
|
|
42
|
+
.isAvailable(PORT)
|
|
43
|
+
.then(async (available: boolean) => {
|
|
44
|
+
// Start App server
|
|
45
|
+
if (!available && !Cfg?.clusterMode) {
|
|
46
|
+
console.error(`⚠️ Port ${PORT} is not available`);
|
|
47
|
+
console.log("");
|
|
48
|
+
process.exit();
|
|
52
49
|
}
|
|
53
50
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
51
|
+
if (available) {
|
|
52
|
+
// Load all ressouce
|
|
53
|
+
await init();
|
|
54
|
+
const HonoApp = HonoInstance();
|
|
55
|
+
//await loadSocket(HonoApp);
|
|
56
|
+
//BeforeStart
|
|
57
|
+
if (config?.beforeStart) {
|
|
58
|
+
for (const fn of config?.beforeStart) {
|
|
59
|
+
await fn();
|
|
60
60
|
}
|
|
61
|
+
}
|
|
61
62
|
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
63
|
+
var server: any = Bun.serve({
|
|
64
|
+
port: PORT,
|
|
65
|
+
reusePort: CLUSTER_MODE,
|
|
66
|
+
fetch: (req, server) => {
|
|
67
|
+
if (server.upgrade(req)) {
|
|
68
|
+
// handle authentication
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
67
71
|
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
info +=
|
|
74
|
-
`Env: ${
|
|
75
|
-
process.env.NODE_ENV === "production"
|
|
76
|
-
? "production"
|
|
77
|
-
: process.env?.NODE_ENV || "development"
|
|
78
|
-
}`.italic.blue.green + "\n";
|
|
79
|
-
info += `Server: http://localhost:${PORT}\n`.italic.blue;
|
|
80
|
-
info += `\n`;
|
|
81
|
-
info += "TENANTS :".gray.italic.underline;
|
|
82
|
-
info += `\n`;
|
|
83
|
-
Cfg.tenants?.map((t: any) => {
|
|
84
|
-
info += `\n${t?.name?.blue || "_"} : ${t?.id?.green}`.italic;
|
|
85
|
-
});
|
|
86
|
-
info += `\n`;
|
|
72
|
+
return HonoApp.fetch(req, server);
|
|
73
|
+
},
|
|
74
|
+
maxRequestBodySize: 1024 * 1024 * 900,
|
|
75
|
+
websocket: webSocketServer(server),
|
|
76
|
+
});
|
|
87
77
|
|
|
88
|
-
|
|
78
|
+
console.log();
|
|
79
|
+
let info = "";
|
|
80
|
+
info += "SERVER :".gray.italic.underline;
|
|
81
|
+
info += `\n`;
|
|
82
|
+
info += `\n`;
|
|
83
|
+
info +=
|
|
84
|
+
`Env: ${
|
|
85
|
+
process.env.NODE_ENV === "production"
|
|
86
|
+
? "production"
|
|
87
|
+
: process.env?.NODE_ENV || "development"
|
|
88
|
+
}`.italic.blue.green + "\n";
|
|
89
|
+
info += `Server: http://localhost:${PORT}\n`.italic.blue;
|
|
90
|
+
info += `\n`;
|
|
91
|
+
info += "TENANTS :".gray.italic.underline;
|
|
92
|
+
info += `\n`;
|
|
93
|
+
Cfg.tenants?.map((t: any) => {
|
|
94
|
+
info += `\n${t?.name?.blue || "_"} : ${t?.id?.green}`.italic;
|
|
95
|
+
});
|
|
96
|
+
info += `\n`;
|
|
89
97
|
|
|
90
|
-
|
|
91
|
-
boxen(info, {
|
|
92
|
-
borderStyle: "round",
|
|
93
|
-
title: `@dnax/server ${pkg.version}`.italic,
|
|
94
|
-
padding: 1,
|
|
95
|
-
dimBorder: true,
|
|
96
|
-
titleAlignment: "center",
|
|
97
|
-
//float: "center",
|
|
98
|
-
//margin: 1,
|
|
99
|
-
borderColor: "gray",
|
|
100
|
-
})
|
|
101
|
-
);
|
|
98
|
+
if (clb) clb();
|
|
102
99
|
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
100
|
+
console.log(
|
|
101
|
+
boxen(info, {
|
|
102
|
+
borderStyle: "round",
|
|
103
|
+
title: `@dnax/server ${pkg.version}`.italic,
|
|
104
|
+
padding: 1,
|
|
105
|
+
dimBorder: true,
|
|
106
|
+
titleAlignment: "center",
|
|
107
|
+
//float: "center",
|
|
108
|
+
//margin: 1,
|
|
109
|
+
borderColor: "gray",
|
|
110
|
+
})
|
|
111
|
+
);
|
|
112
|
+
|
|
113
|
+
//AfterStart
|
|
114
|
+
if (config?.afterStart) {
|
|
115
|
+
for (const fn of config?.afterStart) {
|
|
116
|
+
await fn();
|
|
117
|
+
}
|
|
107
118
|
}
|
|
108
119
|
}
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
console.
|
|
112
|
-
process.exit();
|
|
113
|
-
}
|
|
114
|
-
});
|
|
120
|
+
})
|
|
121
|
+
.catch((err: any) => {
|
|
122
|
+
console.error("Warning", err?.message);
|
|
123
|
+
process.exit(1);
|
|
124
|
+
});
|
|
115
125
|
}
|
|
116
126
|
|
|
117
127
|
//process.on("exit", async () => {});
|
package/config/index.ts
CHANGED
|
@@ -23,6 +23,8 @@ const Cfg: Config = {
|
|
|
23
23
|
};
|
|
24
24
|
|
|
25
25
|
function setCfg(config: Config) {
|
|
26
|
+
if (!config?.clusterMode) Cfg.clusterMode = true;
|
|
27
|
+
Cfg.clusterMode = config?.clusterMode ?? false;
|
|
26
28
|
Cfg.server = config.server;
|
|
27
29
|
Cfg.tenants = config?.tenants;
|
|
28
30
|
Cfg.email = config?.email;
|
package/driver/mongo/rest.ts
CHANGED
|
@@ -974,7 +974,11 @@ class useRest {
|
|
|
974
974
|
update = omit(update, omitUpdate);
|
|
975
975
|
|
|
976
976
|
if (update?.$set) {
|
|
977
|
-
update.$set = getEntryBykeys(
|
|
977
|
+
update.$set = getEntryBykeys(
|
|
978
|
+
dotJson.object(update.$set),
|
|
979
|
+
allFieldKeys
|
|
980
|
+
);
|
|
981
|
+
|
|
978
982
|
update.$set = deepSetId(
|
|
979
983
|
col,
|
|
980
984
|
omit(update.$set, ["createdAt", "updatedAt", "_id"])
|
|
@@ -1246,7 +1250,10 @@ class useRest {
|
|
|
1246
1250
|
update = omit(update, omitUpdate);
|
|
1247
1251
|
|
|
1248
1252
|
if (update.$set) {
|
|
1249
|
-
update.$set = getEntryBykeys(
|
|
1253
|
+
update.$set = getEntryBykeys(
|
|
1254
|
+
dotJson.object(update.$set),
|
|
1255
|
+
allFieldKeys
|
|
1256
|
+
);
|
|
1250
1257
|
|
|
1251
1258
|
update.$set = deepSetId(
|
|
1252
1259
|
col,
|
package/package.json
CHANGED