@dnax/core 0.5.1 → 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/app/hono.ts CHANGED
@@ -29,12 +29,54 @@ function HonoInstance(): typeof app {
29
29
  if (Cfg?.server?.logger) {
30
30
  if (typeof Cfg?.server?.logger == "function") {
31
31
  app.use(async (c, next) => {
32
- Cfg?.server?.logger(c);
33
- return await next();
32
+ const start = Date.now();
33
+ const { action, collection, cleanDeep, useCache } = c.req.query() as Q;
34
+ Cfg.server.logger(c, {
35
+ mode: "incomming",
36
+ start: start,
37
+ action: action,
38
+ collection: collection,
39
+ cleanDeep: cleanDeep,
40
+ useCache: useCache,
41
+ method: c.req.method,
42
+ url: c.req.url,
43
+ });
44
+ await next();
45
+ const duration = Date.now() - start;
46
+ Cfg.server.logger(c, {
47
+ mode: "outgoing",
48
+ duration,
49
+ start,
50
+ action,
51
+ collection,
52
+ cleanDeep,
53
+ useCache,
54
+ method: c.req.method,
55
+ url: c.req.url,
56
+ status: c.res.status,
57
+ });
34
58
  });
35
59
  }
36
60
  if (typeof Cfg?.server?.logger == "boolean") {
37
- app.use(logger());
61
+ app.use(async (c, next) => {
62
+ const start = Date.now();
63
+ const { action, collection, cleanDeep, useCache } = c.req.query() as Q;
64
+ // Log the incoming request
65
+ console.log(
66
+ `<-- ${c.req.method} /${c.req.url} - C ${collection || ""} - A ${
67
+ action || ""
68
+ }\n`
69
+ );
70
+
71
+ await next();
72
+ // Calculate the duration of the request processing
73
+ const duration = Date.now() - start;
74
+ console.log(
75
+ `--> ${c.req.method} /${c.req.url} - C ${collection || ""} - A ${
76
+ action || ""
77
+ } - ${c.res.status} - (${duration + "".green}ms)\n`
78
+ );
79
+ });
38
80
  }
39
81
  }
40
82
  app.use(
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@dnax/core",
3
- "version": "0.5.1",
3
+ "version": "0.5.3",
4
4
  "module": "index.ts",
5
5
  "type": "module",
6
6
  "bin": {
package/types/index.ts CHANGED
@@ -294,7 +294,21 @@ export type Collection = {
294
294
  }>;
295
295
  };
296
296
 
297
- export type loggerFunction = (c: Context) => void;
297
+ export type loggerFunction = (
298
+ c: Context,
299
+ ctx: {
300
+ mode: "incomming" | "outgoing";
301
+ start: number;
302
+ action?: string;
303
+ collection?: string;
304
+ cleanDeep?: boolean;
305
+ useCache?: boolean;
306
+ method: string;
307
+ url?: string;
308
+ status?: number;
309
+ duration?: number;
310
+ }
311
+ ) => void;
298
312
 
299
313
  export type Config = {
300
314
  email?: {