milkio 0.4.0 → 0.4.2

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.
@@ -148,6 +148,13 @@ export function defineHttpHandler(app: MilkioApp, options: ExecuteHttpServerOpti
148
148
 
149
149
  const resultsRaw = await app._call(mode, pathstr, params, headers, { executeId, logger, detail });
150
150
 
151
+ if (resultsRaw.$result.success === false) {
152
+ if (resultsRaw.$result.fail.code === "TYPE_SAFE_ERROR") {
153
+ if (((resultsRaw.$result.fail.data as any).value) === undefined) (resultsRaw.$result.fail.data as any).value === "undefined";
154
+ if (((resultsRaw.$result.fail.data as any).value) === null) (resultsRaw.$result.fail.data as any).value === "null";
155
+ }
156
+ }
157
+
151
158
  let fn: any;
152
159
  try {
153
160
  fn = await schema.apiValidator.validate[pathstr]();
package/kernel/execute.ts CHANGED
@@ -88,8 +88,8 @@ export async function _call(
88
88
  // after execute middleware
89
89
  await MiddlewareEvent.handle("afterExecute", [context, result]);
90
90
 
91
- if (mode === "execute" && !(result.value as AsyncGenerator)[Symbol.asyncIterator]) return { $type: "result", $result: { executeId, success: true, data: result.value } };
92
- if (mode === "stream" && (result.value as AsyncGenerator)[Symbol.asyncIterator]) return { $type: "stream", $result: { executeId, success: true, data: "$" }, $generator: result.value as AsyncGenerator };
91
+ if (mode === "execute" && !(result.value as AsyncGenerator)?.[Symbol.asyncIterator]) return { $type: "result", $result: { executeId, success: true, data: result.value } };
92
+ if (mode === "stream" && (result.value as AsyncGenerator)?.[Symbol.asyncIterator]) return { $type: "stream", $result: { executeId, success: true, data: "$" }, $generator: result.value as AsyncGenerator };
93
93
  console.log(mode);
94
94
 
95
95
  throw reject("BUSINESS_FAIL", `It looks like you used the wrong syntax, for this API you should use "client.${mode}(...)"`);
package/kernel/logger.ts CHANGED
@@ -18,12 +18,13 @@ export type LoggerOptions = {
18
18
  export type Logger = {
19
19
  debug: (description: string, ...params: Array<unknown>) => void;
20
20
  log: (description: string, ...params: Array<unknown>) => void;
21
+ info: (description: string, ...params: Array<unknown>) => void;
21
22
  warn: (description: string, ...params: Array<unknown>) => void;
22
23
  error: (description: string, ...params: Array<unknown>) => void;
23
24
  };
24
25
 
25
26
  export const loggerController = (() => {
26
- const logs = new Map<ExecuteId, { __LOG_DETAIL__: Array<LoggerItem>; [key: string]: any }>();
27
+ const logs = new Map<ExecuteId, { __LOG_DETAIL__: Array<LoggerItem>;[key: string]: any }>();
27
28
 
28
29
  const loggerPushTags = (executeId: ExecuteId, tags: Record<string, any>) => {
29
30
  if (!logs.has(executeId)) logs.set(executeId, { __LOG_DETAIL__: [] });
@@ -83,6 +84,9 @@ export const loggerController = (() => {
83
84
  log(description: string, ...params: Array<unknown>) {
84
85
  insertItem(executeId, "log", description, params);
85
86
  },
87
+ info(description: string, ...params: Array<unknown>) {
88
+ insertItem(executeId, "log", description, params);
89
+ },
86
90
  warn(description: string, ...params: Array<unknown>) {
87
91
  insertItem(executeId, "warn", description, params);
88
92
  },
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "milkio",
3
3
  "type": "module",
4
4
  "module": "index.ts",
5
- "version": "0.4.0",
5
+ "version": "0.4.2",
6
6
  "peerDependencies": {
7
7
  "typescript": "^5.4.2"
8
8
  },