befly 3.75.0 → 3.75.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.
package/checks/api.js CHANGED
@@ -67,7 +67,8 @@ export async function checkApi(apis) {
67
67
  apis.forEach((api, index) => issues.push(...checkApiItem(api, index)));
68
68
  }
69
69
 
70
- if (issues.length === 0) return false;
71
- Logger.warn("接口校验失败", { errors: formatValidationIssues(issues, { items: apis, itemLabel: "api" }) });
72
- return true;
70
+ if (issues.length === 0) return [];
71
+ const errors = formatValidationIssues(issues, { items: apis, itemLabel: "api" });
72
+ Logger.warn("接口校验失败", { errors: errors });
73
+ return errors;
73
74
  }
package/checks/config.js CHANGED
@@ -4,14 +4,15 @@ import { formatValidationIssues } from "../utils/formatValidationIssues.js";
4
4
 
5
5
  export async function checkConfig(config) {
6
6
  const issues = validateConfig(config);
7
- if (issues.length === 0) return false;
7
+ if (issues.length === 0) return [];
8
8
 
9
+ const errors = formatValidationIssues(issues, { item: config, itemLabel: "config" });
9
10
  Logger.warn(
10
11
  "配置校验失败",
11
12
  {
12
- errors: formatValidationIssues(issues, { item: config, itemLabel: "config" })
13
+ errors: errors
13
14
  },
14
15
  false
15
16
  );
16
- return true;
17
+ return errors;
17
18
  }
package/checks/items.js CHANGED
@@ -24,11 +24,12 @@ function checkItem(item) {
24
24
 
25
25
  function checkItemList(items, label, labelEn) {
26
26
  if (!Array.isArray(items)) {
27
- Logger.warn(`${label}校验失败`, { errors: formatValidationIssues([{ path: [], message: "必须是数组" }], { item: items, itemLabel: labelEn }) });
28
- return true;
27
+ const errors = formatValidationIssues([{ path: [], message: "必须是数组" }], { item: items, itemLabel: labelEn });
28
+ Logger.warn(`${label}校验失败`, { errors: errors });
29
+ return errors;
29
30
  }
30
31
 
31
- let hasError = false;
32
+ const errors = [];
32
33
 
33
34
  // order 冲突校验:同 order 的执行顺序依赖扫描顺序,要求显式区分
34
35
  const orderMap = new Map();
@@ -38,17 +39,25 @@ function checkItemList(items, label, labelEn) {
38
39
  }
39
40
  const duplicateOrders = [...orderMap].filter(([, count]) => count > 1).map(([order]) => order);
40
41
  if (duplicateOrders.length > 0) {
41
- Logger.warn(`${label}校验失败`, { errors: [{ path: [], message: `order 重复: ${duplicateOrders.join("、")}` }] });
42
- hasError = true;
42
+ const duplicateItems = items.filter((item) => duplicateOrders.includes(item.order));
43
+ errors.push(
44
+ ...formatValidationIssues(
45
+ duplicateItems.map((item, index) => ({ path: [index], message: `order ${item.order} 重复,请显式区分` })),
46
+ { items: duplicateItems, itemLabel: labelEn }
47
+ )
48
+ );
43
49
  }
44
50
 
45
51
  for (const item of items) {
46
52
  const issues = checkItem(item);
47
53
  if (issues.length === 0) continue;
48
- Logger.warn(`${label}校验失败`, { errors: formatValidationIssues(issues, { item: item, itemLabel: labelEn }) });
49
- hasError = true;
54
+ errors.push(...formatValidationIssues(issues, { item: item, itemLabel: labelEn }));
50
55
  }
51
- return hasError;
56
+
57
+ if (errors.length > 0) {
58
+ Logger.warn(`${label}校验失败`, { errors: errors });
59
+ }
60
+ return errors;
52
61
  }
53
62
 
54
63
  export const checkHook = (hooks) => checkItemList(hooks, "钩子", "hook");
package/checks/menu.js CHANGED
@@ -42,7 +42,8 @@ export async function checkMenu(menus) {
42
42
  if (!Array.isArray(menus)) issues.push({ path: [], message: "必须是数组" });
43
43
  else menus.forEach((menu, index) => checkMenuItem(issues, menu, [index]));
44
44
 
45
- if (issues.length === 0) return false;
46
- Logger.warn("菜单校验失败", { errors: formatValidationIssues(issues, { items: menus, itemLabel: "menus" }) });
47
- return true;
45
+ if (issues.length === 0) return [];
46
+ const errors = formatValidationIssues(issues, { items: menus, itemLabel: "menus" });
47
+ Logger.warn("菜单校验失败", { errors: errors });
48
+ return errors;
48
49
  }
package/checks/table.js CHANGED
@@ -35,7 +35,8 @@ export async function checkTable(tables) {
35
35
  }
36
36
  }
37
37
 
38
- if (issues.length === 0) return false;
39
- Logger.warn("表结构校验失败", { errors: formatValidationIssues(issues, { item: tables, itemLabel: "table" }) });
40
- return true;
38
+ if (issues.length === 0) return [];
39
+ const errors = formatValidationIssues(issues, { item: tables, itemLabel: "table" });
40
+ Logger.warn("表结构校验失败", { errors: errors });
41
+ return errors;
41
42
  }
package/index.js CHANGED
@@ -104,7 +104,7 @@ export async function createBefly(config = {}, menus = []) {
104
104
  Logger.info(`启动 合并配置 耗时 ${calcPerfTime(mergeStartTime)}`);
105
105
 
106
106
  let stageStartTime = Bun.nanoseconds();
107
- const configHasError = await checkConfig(mergedConfig);
107
+ const configErrors = await checkConfig(mergedConfig);
108
108
  Logger.info(`启动 检查配置 耗时 ${calcPerfTime(stageStartTime)}`);
109
109
 
110
110
  stageStartTime = Bun.nanoseconds();
@@ -112,27 +112,42 @@ export async function createBefly(config = {}, menus = []) {
112
112
  Logger.info(`启动 扫描源码 耗时 ${calcPerfTime(stageStartTime)}`);
113
113
 
114
114
  stageStartTime = Bun.nanoseconds();
115
- const apiHasError = await checkApi(apis);
115
+ const apiErrors = await checkApi(apis);
116
116
  Logger.info(`启动 检查接口 耗时 ${calcPerfTime(stageStartTime)}`);
117
117
 
118
118
  stageStartTime = Bun.nanoseconds();
119
- const tableHasError = await checkTable(tables);
119
+ const tableErrors = await checkTable(tables);
120
120
  Logger.info(`启动 检查表 耗时 ${calcPerfTime(stageStartTime)}`);
121
121
 
122
122
  stageStartTime = Bun.nanoseconds();
123
- const pluginHasError = await checkPlugin(plugins);
123
+ const pluginErrors = await checkPlugin(plugins);
124
124
  Logger.info(`启动 检查插件 耗时 ${calcPerfTime(stageStartTime)}`);
125
125
 
126
126
  stageStartTime = Bun.nanoseconds();
127
- const hookHasError = await checkHook(hooks);
127
+ const hookErrors = await checkHook(hooks);
128
128
  Logger.info(`启动 检查钩子 耗时 ${calcPerfTime(stageStartTime)}`);
129
129
 
130
130
  stageStartTime = Bun.nanoseconds();
131
- const menuHasError = await checkMenu(mergedMenus);
131
+ const menuErrors = await checkMenu(mergedMenus);
132
132
  Logger.info(`启动 检查菜单 耗时 ${calcPerfTime(stageStartTime)}`);
133
133
 
134
- if (configHasError || apiHasError || tableHasError || pluginHasError || hookHasError || menuHasError) {
135
- throw createError("检查失败:存在配置/结构问题", { code: "policy", subsystem: "checks", operation: "checkAll" });
134
+ // 汇总各检查明细,报错可直接定位到具体文件/路径/配置/字段
135
+ const failedChecks = [
136
+ { check: "配置", errors: configErrors },
137
+ { check: "接口", errors: apiErrors },
138
+ { check: "表结构", errors: tableErrors },
139
+ { check: "插件", errors: pluginErrors },
140
+ { check: "钩子", errors: hookErrors },
141
+ { check: "菜单", errors: menuErrors }
142
+ ].filter((entry) => entry.errors.length > 0);
143
+
144
+ if (failedChecks.length > 0) {
145
+ throw createError("检查失败:存在配置/结构问题", {
146
+ code: "policy",
147
+ subsystem: "checks",
148
+ operation: "checkAll",
149
+ errors: failedChecks
150
+ });
136
151
  }
137
152
 
138
153
  // 运行模式以环境为准(NODE_ENV,线上部署注入 production;本地开发默认 development),
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.75.0",
3
+ "version": "3.75.2",
4
4
  "gitHead": "49c39d36695036e85fc64083cc43c1652fff96cb",
5
5
  "private": false,
6
6
  "description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",