@dnax/core 0.20.2 → 0.21.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/app/index.ts +75 -65
- package/config/index.ts +2 -0
- package/driver/mongo/rest.ts +12 -0
- package/package.json +1 -1
- package/types/arktype.ts +1 -0
- package/types/index.ts +2 -1
- package/utils/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
|
@@ -204,6 +204,7 @@ class useRest {
|
|
|
204
204
|
if (col?.hooks?.beforeOperation && useHook) {
|
|
205
205
|
await col.hooks.beforeOperation({
|
|
206
206
|
io: Cfg.io,
|
|
207
|
+
error: fn.error,
|
|
207
208
|
sharedData: sharedData,
|
|
208
209
|
pipeline: pipeline,
|
|
209
210
|
c: this.#c,
|
|
@@ -278,6 +279,7 @@ class useRest {
|
|
|
278
279
|
await col.hooks.beforeOperation({
|
|
279
280
|
sharedData: sharedData,
|
|
280
281
|
io: Cfg.io,
|
|
282
|
+
error: fn.error,
|
|
281
283
|
data: data,
|
|
282
284
|
c: this.#c,
|
|
283
285
|
driver: "mongodb",
|
|
@@ -399,6 +401,7 @@ class useRest {
|
|
|
399
401
|
if (col?.hooks?.beforeOperation && useHook) {
|
|
400
402
|
await col.hooks.beforeOperation({
|
|
401
403
|
sharedData: sharedData,
|
|
404
|
+
error: fn.error,
|
|
402
405
|
data: toJson(data),
|
|
403
406
|
io: Cfg.io,
|
|
404
407
|
c: this.#c,
|
|
@@ -575,6 +578,7 @@ class useRest {
|
|
|
575
578
|
await col.hooks.beforeOperation({
|
|
576
579
|
sharedData: sharedData,
|
|
577
580
|
c: this.#c,
|
|
581
|
+
error: fn.error,
|
|
578
582
|
driver: "mongodb",
|
|
579
583
|
io: Cfg.io,
|
|
580
584
|
action: "find",
|
|
@@ -701,6 +705,7 @@ class useRest {
|
|
|
701
705
|
await col.hooks.beforeOperation({
|
|
702
706
|
sharedData: sharedData,
|
|
703
707
|
c: this.#c,
|
|
708
|
+
error: fn.error,
|
|
704
709
|
driver: "mongodb",
|
|
705
710
|
io: Cfg.io,
|
|
706
711
|
action: "find",
|
|
@@ -811,6 +816,7 @@ class useRest {
|
|
|
811
816
|
sharedData: sharedData,
|
|
812
817
|
id: id,
|
|
813
818
|
io: Cfg.io,
|
|
819
|
+
error: fn.error,
|
|
814
820
|
c: this.#c,
|
|
815
821
|
driver: "mongodb",
|
|
816
822
|
action: "findOne",
|
|
@@ -926,6 +932,7 @@ class useRest {
|
|
|
926
932
|
sharedData: sharedData,
|
|
927
933
|
id: id,
|
|
928
934
|
io: Cfg.io,
|
|
935
|
+
error: fn.error,
|
|
929
936
|
c: this.#c,
|
|
930
937
|
driver: "mongodb",
|
|
931
938
|
action: "updateOne",
|
|
@@ -1083,6 +1090,7 @@ class useRest {
|
|
|
1083
1090
|
sharedData: sharedData,
|
|
1084
1091
|
filter: filter || {},
|
|
1085
1092
|
c: this.#c,
|
|
1093
|
+
error: fn.error,
|
|
1086
1094
|
io: Cfg.io,
|
|
1087
1095
|
driver: "mongodb",
|
|
1088
1096
|
action: "findOneAndUpdate",
|
|
@@ -1202,6 +1210,7 @@ class useRest {
|
|
|
1202
1210
|
sharedData: sharedData,
|
|
1203
1211
|
ids: ids,
|
|
1204
1212
|
c: this.#c,
|
|
1213
|
+
error: fn.error,
|
|
1205
1214
|
driver: "mongodb",
|
|
1206
1215
|
io: Cfg.io,
|
|
1207
1216
|
action: "updateMany",
|
|
@@ -1367,6 +1376,8 @@ class useRest {
|
|
|
1367
1376
|
c: this.#c,
|
|
1368
1377
|
io: Cfg.io,
|
|
1369
1378
|
driver: "mongodb",
|
|
1379
|
+
error: fn.error,
|
|
1380
|
+
|
|
1370
1381
|
action: "deleteOne",
|
|
1371
1382
|
session: sessionStorage(),
|
|
1372
1383
|
rest: new useRest({
|
|
@@ -1468,6 +1479,7 @@ class useRest {
|
|
|
1468
1479
|
ids: ids,
|
|
1469
1480
|
c: this.#c,
|
|
1470
1481
|
driver: "mongodb",
|
|
1482
|
+
error: fn.error,
|
|
1471
1483
|
io: Cfg.io,
|
|
1472
1484
|
action: "deleteMany",
|
|
1473
1485
|
session: sessionStorage(),
|
package/package.json
CHANGED
package/types/arktype.ts
ADDED
|
@@ -0,0 +1 @@
|
|
|
1
|
+
import { type } from "arktype";
|
package/types/index.ts
CHANGED
|
@@ -203,6 +203,7 @@ export type hooksCtx = (ctx: {
|
|
|
203
203
|
rest: InstanceType<typeof useRest>;
|
|
204
204
|
session?: sessionCtx;
|
|
205
205
|
io: socketIoType;
|
|
206
|
+
error: typeof fn.error;
|
|
206
207
|
}) => any;
|
|
207
208
|
|
|
208
209
|
export type ctxApi = {
|
|
@@ -377,7 +378,7 @@ export type Config = {
|
|
|
377
378
|
driver: "mistral" | "openai" | "gemini";
|
|
378
379
|
key: string;
|
|
379
380
|
};
|
|
380
|
-
|
|
381
|
+
clusterMode?: boolean;
|
|
381
382
|
server: {
|
|
382
383
|
id?: string;
|
|
383
384
|
logger?: Boolean | loggerFunction;
|
package/utils/index.ts
CHANGED