milkio 0.5.2 → 0.6.0-alpha.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.
@@ -32,7 +32,8 @@ export function defineHttpHandler(app: MilkioApp, options: ExecuteHttpServerOpti
32
32
 
33
33
  loggerPushTags(executeId, {
34
34
  from: "http-server",
35
- fullUrl: fullurl.pathname,
35
+ url: fullurl.pathname,
36
+ fullurl: fullurl.pathname,
36
37
  ip,
37
38
  method: request.request.method,
38
39
  // @ts-ignore
@@ -1,5 +1,4 @@
1
1
  export const defineUse = <CreatorFn extends () => Promise<unknown> | unknown>(creatorFn: CreatorFn): (() => Promise<Awaited<ReturnType<CreatorFn>>>) => {
2
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
3
2
  let use: any | undefined;
4
3
 
5
4
  const getUse = async () => {
package/kernel/fail.ts CHANGED
@@ -1,7 +1,6 @@
1
1
  import { failCode } from "../../../src/fail-code";
2
2
 
3
3
  export function reject<Code extends keyof typeof failCode, FailData extends (typeof failCode)[Code]>(code: Code, data: Parameters<FailData>[0]) {
4
- // eslint-disable-next-line @typescript-eslint/no-explicit-any, @typescript-eslint/no-unsafe-argument
5
4
  const message = failCode[code]?.(data as any) ?? "";
6
5
  const error = {
7
6
  name: "MilkioReject",
@@ -18,5 +17,4 @@ export function reject<Code extends keyof typeof failCode, FailData extends (typ
18
17
 
19
18
  export type MilkioReject = ReturnType<typeof reject>;
20
19
 
21
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
22
20
  export type MilkioFailCode = Record<string, (arg: any) => string>;
package/kernel/logger.ts CHANGED
@@ -1,5 +1,5 @@
1
- import { runtime, type ExecuteId } from "..";
2
- import { loggerOptions } from "../../../src/logger";
1
+ import { ExecuteResultFail, runtime, type ExecuteId } from "..";
2
+ import { loggerOptions, LoggerTags } from "../../../src/logger";
3
3
 
4
4
  export type LoggerItem = {
5
5
  executeId: ExecuteId;
@@ -8,11 +8,26 @@ export type LoggerItem = {
8
8
  params: Array<unknown>;
9
9
  };
10
10
 
11
- export type LoggerTags = Record<string, any>;
11
+ export type MilkioLoggerTags = {
12
+ executeId: string;
13
+ from?: "http-server" | "execute";
14
+ method?: "POST" | "GET" | "PUT" | "DELETE" | "PATCH" | "OPTIONS" | string;
15
+ ip?: string;
16
+ path?: string;
17
+ status?: number;
18
+ url?: string;
19
+ params?: any;
20
+ body?: string;
21
+ fail?: ExecuteResultFail;
22
+ timein?: number;
23
+ timeout?: number;
24
+ requestHeaders?: Record<string, string>;
25
+ responseHeaders?: Record<string, string>;
26
+ };
12
27
 
13
28
  export type LoggerOptions = {
14
29
  onInsert: (options: LoggerItem) => boolean;
15
- onSubmit: (tags: LoggerTags, logs: Array<LoggerItem>) => Promise<void> | void;
30
+ onSubmit: (tags: MilkioLoggerTags & LoggerTags, logs: Array<LoggerItem>) => Promise<void> | void;
16
31
  };
17
32
 
18
33
  export type Logger = {
@@ -26,18 +41,18 @@ export type Logger = {
26
41
  export const loggerController = (() => {
27
42
  const logs = new Map<ExecuteId, { __LOG_DETAIL__: Array<LoggerItem>;[key: string]: any }>();
28
43
 
29
- const loggerPushTags = (executeId: ExecuteId, tags: Record<string, any>) => {
44
+ const loggerPushTags = (executeId: ExecuteId, tags: Partial<MilkioLoggerTags & LoggerTags>) => {
30
45
  if (!logs.has(executeId)) logs.set(executeId, { __LOG_DETAIL__: [] });
31
46
  const logItem = logs.get(executeId);
32
47
  for (const key in tags) {
33
- logItem![key] = tags[key];
48
+ logItem![key] = (tags as any)[key];
34
49
  }
35
50
  };
36
51
 
37
52
  const loggerSubmit = async (executeId: ExecuteId) => {
38
53
  if (!logs.has(executeId)) return;
39
54
  if (executeId === "global") return;
40
- const loggerSubmitOptions: Record<string, string> = {
55
+ const loggerSubmitOptions: any = {
41
56
  executeId,
42
57
  };
43
58
  const log = logs.get(executeId)!;
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "milkio",
3
3
  "type": "module",
4
4
  "module": "index.ts",
5
- "version": "0.5.2",
5
+ "version": "0.6.0-alpha.1",
6
6
  "peerDependencies": {
7
7
  "typescript": "^5.4.2"
8
8
  },
package/utils/exec.ts CHANGED
@@ -13,7 +13,6 @@ export const exec = async (cwd: string, command: Array<string>, options: Partial
13
13
  if (!("env" in options)) options.env = { ...env };
14
14
 
15
15
  options.onExit = (proc, exitCode, signalCode, error) => {
16
- // eslint-disable-next-line prefer-promise-reject-errors
17
16
  if (exitCode !== 0) reject({ proc, exitCode, signalCode, error });
18
17
  else resolve({ proc, exitCode, signalCode, error });
19
18
  };
@@ -1,8 +1,7 @@
1
1
  import { failCode } from "../../../src/fail-code";
2
- import { useLogger, type ExecuteId, type ExecuteResult } from "..";
2
+ import { loggerPushTags, useLogger, type ExecuteId, type ExecuteResult } from "..";
3
3
  import { configMilkio } from "../../../src/config/milkio";
4
4
 
5
- // eslint-disable-next-line @typescript-eslint/no-explicit-any
6
5
  export function handleCatchError(error: any, executeId: ExecuteId): ExecuteResult<any> {
7
6
  const logger = useLogger(executeId);
8
7
 
@@ -12,13 +11,15 @@ export function handleCatchError(error: any, executeId: ExecuteId): ExecuteResul
12
11
  else logger.error("Error Stack: ", error);
13
12
  }
14
13
 
14
+ let result: ExecuteResult<any>;
15
+
15
16
  if (error.name !== "MilkioReject") {
16
17
  if (configMilkio.debug === true) {
17
18
  // If it is not MilkioReject, it is considered an internal server error that should not be exposed
18
19
  logger.error(`FailCode: INTERNAL_SERVER_ERROR`);
19
20
  }
20
21
 
21
- return {
22
+ result = {
22
23
  executeId,
23
24
  success: false,
24
25
  fail: {
@@ -27,19 +28,25 @@ export function handleCatchError(error: any, executeId: ExecuteId): ExecuteResul
27
28
  data: undefined,
28
29
  },
29
30
  };
30
- }
31
+ } else {
32
+ if (configMilkio.debug === true) {
33
+ logger.error(`FailCode: ${error.code}`);
34
+ }
31
35
 
32
- if (configMilkio.debug === true) {
33
- logger.error(`FailCode: ${error.code}`);
36
+ result = {
37
+ executeId,
38
+ success: false,
39
+ fail: {
40
+ code: error.code,
41
+ message: error.message,
42
+ data: error.data,
43
+ },
44
+ };
34
45
  }
35
46
 
36
- return {
37
- executeId,
38
- success: false,
39
- fail: {
40
- code: error.code,
41
- message: error.message,
42
- data: error.data,
43
- },
44
- };
47
+ loggerPushTags(executeId, {
48
+ fail: result
49
+ });
50
+
51
+ return result;
45
52
  }