@dnax/core 0.1.12 → 0.1.14

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 CHANGED
@@ -6,7 +6,14 @@ import "@colors/colors";
6
6
  import pkg from "../package.json";
7
7
  import findPort from "find-open-port";
8
8
  import { HonoInstance } from "./hono";
9
- async function runApp(config?: any, clb?: Function) {
9
+ type configRunApp = {
10
+ register?: Array<Function>,
11
+ beforeStart?: Array<Function>,
12
+ afterStart?: Array<Function>,
13
+ onError?: Array<Function>,
14
+ destroy?: Array<Function>,
15
+ }
16
+ async function runApp(config?: configRunApp, clb?: Function) {
10
17
  console.log("\n");
11
18
 
12
19
  await loadCfg();
@@ -15,18 +22,30 @@ async function runApp(config?: any, clb?: Function) {
15
22
  // Load all ressouce
16
23
  await init();
17
24
 
25
+ // Register all plugins
26
+
18
27
  // Load Hono App and route api
19
28
  const HonoApp = HonoInstance();
20
29
  const PORT = Cfg.server?.port || process.env?.PORT || 4000;
21
30
 
22
- await findPort.isAvailable(PORT).then((available: boolean) => {
31
+ await findPort.isAvailable(PORT).then(async (available: boolean) => {
23
32
  // Start App server
24
33
 
25
34
  if (available) {
35
+
36
+
37
+ //BeforeStart
38
+ if (config?.beforeStart) {
39
+ for (const fn of config?.beforeStart) {
40
+ await fn();
41
+ }
42
+ }
43
+
26
44
  Bun.serve({
27
45
  port: PORT,
28
46
  fetch: HonoApp.fetch,
29
47
  maxRequestBodySize: 1024 * 1024 * 900,
48
+
30
49
  });
31
50
 
32
51
  console.log();
@@ -35,9 +54,8 @@ async function runApp(config?: any, clb?: Function) {
35
54
  info += `\n`;
36
55
  info += `\n`;
37
56
  info +=
38
- `Env: ${
39
- process.env.NODE_ENV === "production" ? "production" : "development"
40
- }`.italic.blue.green + "\n";
57
+ `Env: ${process.env.NODE_ENV === "production" ? "production" : "development"
58
+ }`.italic.blue.green + "\n";
41
59
  info += `Server: http://localhost:${PORT}\n`.italic.blue;
42
60
  info += `\n`;
43
61
  info += "TENANTS DETAILS :".gray.italic.underline;
@@ -61,6 +79,14 @@ async function runApp(config?: any, clb?: Function) {
61
79
  borderColor: "gray",
62
80
  })
63
81
  );
82
+
83
+ //AfterStart
84
+ if (config?.afterStart) {
85
+ for (const fn of config?.afterStart) {
86
+ await fn();
87
+ }
88
+ }
89
+
64
90
  } else {
65
91
  console.error(`⚠️ Port ${PORT} is not available`);
66
92
  console.log("");
@@ -82,6 +82,12 @@ class useRest {
82
82
  let valid = true;
83
83
  let output = { ...data };
84
84
  let errorMxg;
85
+ let control = {
86
+ error: null,
87
+ value: null,
88
+ waring: null
89
+ }
90
+
85
91
  /* let issue = err?.issues[0] || {};
86
92
  let msg = `Field : ${issue?.path[0]?.key} - ${issue?.message}`;
87
93
  */
@@ -96,12 +102,12 @@ class useRest {
96
102
  return sc.optional();
97
103
  }
98
104
  );
99
- const { error, value } = partialSchema.validate(data);
105
+ control = partialSchema.validate(data) as any;
100
106
  } else {
101
- const { error, value } = schema.validate(data);
107
+ control = schema.validate(data) as any;
102
108
  }
103
109
 
104
- const { error, value } = schema.validate(data);
110
+ const { error, value } = control;
105
111
 
106
112
  if (error) {
107
113
  valid = false;
@@ -112,7 +118,6 @@ class useRest {
112
118
  ...data,
113
119
  ...output,
114
120
  };
115
-
116
121
  //console.log(value);
117
122
  }
118
123
  }
@@ -171,7 +176,7 @@ class useRest {
171
176
 
172
177
  result.docs = await this.#tenant.database.db
173
178
  ?.collection(collection)
174
- .aggregate(formatData(pipeline), {
179
+ .aggregate(pipeline, {
175
180
  allowDiskUse: true,
176
181
  })
177
182
  .toArray();
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.1.12",
3
+ "version": "0.1.14",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "devDependencies": {