befly 3.65.0 → 3.67.0

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.
@@ -37,6 +37,7 @@ export default {
37
37
  }
38
38
 
39
39
  return befly.tool.Yes("获取成功", {
40
+ runMode: befly.config.runMode,
40
41
  os: `${os.type()} ${os.arch()}`,
41
42
  server: `${os.platform()} ${os.release()}`,
42
43
  runtimeVersion: runtimeVersion,
@@ -86,7 +86,7 @@ function buildProductSummary(item, stats, todayCount) {
86
86
  };
87
87
  }
88
88
 
89
- async function loadProjectLists(befly) {
89
+ async function loadProjects(befly) {
90
90
  if (!befly.mysql) {
91
91
  return [];
92
92
  }
@@ -102,9 +102,9 @@ async function loadProjectLists(befly) {
102
102
  }
103
103
 
104
104
  async function buildDailyStatsProducts(befly, history, dateStats) {
105
- const projectLists = await loadProjectLists(befly);
105
+ const projects = await loadProjects(befly);
106
106
  const products = await Promise.all(
107
- projectLists.map(async (item) => {
107
+ projects.map(async (item) => {
108
108
  const stats = history[item.code] || { yesterday: 0, dayBeforeYesterday: 0, month: 0, lastMonth: 0 };
109
109
  const todayCount = await getTodayCount(befly, dateStats.reportDate, item.code);
110
110
 
package/checks/config.js CHANGED
@@ -12,31 +12,6 @@ const noTrimString = z.string().refine(isNoTrimStringAllowEmpty, "不允许首
12
12
  const beflyModeSchema = z.union([z.literal("manual"), z.literal("auto")]);
13
13
  const uploadExtensionListSchema = noTrimString.regex(/^\.[a-z0-9]+(?:,\.[a-z0-9]+)*$/);
14
14
  const uploadMimeTypeListSchema = noTrimString.regex(/^[a-z0-9][a-z0-9.+-]*\/[a-z0-9][a-z0-9.+-]*(?:,[a-z0-9][a-z0-9.+-]*\/[a-z0-9][a-z0-9.+-]*)*$/);
15
- const projectListCodeSchema = z.string().regex(/^[a-zA-Z][a-zA-Z0-9_-]*$/, "必须以字母开头,只允许字母、数字、短横线、下划线");
16
- const projectListItemSchema = z
17
- .object({
18
- code: projectListCodeSchema,
19
- name: noTrimString.min(1)
20
- })
21
- .strict();
22
- const projectListsSchema = z.array(projectListItemSchema).superRefine((projectLists, ctx) => {
23
- const codeSet = new Set();
24
-
25
- for (let index = 0; index < projectLists.length; index += 1) {
26
- const code = projectLists[index].code;
27
-
28
- if (codeSet.has(code)) {
29
- ctx.addIssue({
30
- code: "custom",
31
- message: `projectLists[${index}].code 重复`,
32
- path: [index, "code"]
33
- });
34
- }
35
-
36
- codeSet.add(code);
37
- }
38
- });
39
-
40
15
  const configSchema = z
41
16
  .object({
42
17
  runMode: z.enum(RUN_MODE_VALUES),
@@ -142,9 +117,7 @@ const configSchema = z
142
117
  skipRoutes: z.array(noTrimString),
143
118
  rules: z.array(z.object({}).passthrough())
144
119
  })
145
- .strict(),
146
-
147
- projectLists: projectListsSchema
120
+ .strict()
148
121
  })
149
122
  .strict();
150
123
 
@@ -70,6 +70,5 @@
70
70
  "key": "ip",
71
71
  "skipRoutes": [],
72
72
  "rules": []
73
- },
74
- "projectLists": []
73
+ }
75
74
  }
package/index.js CHANGED
@@ -55,34 +55,6 @@ function prefixMenuPaths(menus, prefix) {
55
55
  });
56
56
  }
57
57
 
58
- function mergeProjectListsByCode(projectLists) {
59
- if (!Array.isArray(projectLists)) {
60
- return [];
61
- }
62
-
63
- const itemMap = new Map();
64
-
65
- for (const item of projectLists) {
66
- const code = String(item?.code || "");
67
- const name = String(item?.name || "");
68
-
69
- if (!code) {
70
- continue;
71
- }
72
-
73
- if (itemMap.has(code)) {
74
- itemMap.delete(code);
75
- }
76
-
77
- itemMap.set(code, {
78
- code: code,
79
- name: name
80
- });
81
- }
82
-
83
- return Array.from(itemMap.values());
84
- }
85
-
86
58
  async function ensureSyncPrerequisites(ctx) {
87
59
  const missingCtxKeys = ["ctx.redis", "ctx.mysql", "ctx.cache"].filter((key) => !ctx[key.slice(4)]);
88
60
  if (missingCtxKeys.length > 0) {
@@ -115,10 +87,9 @@ async function ensureSyncPrerequisites(ctx) {
115
87
  }
116
88
  }
117
89
 
118
- export async function createBefly(env = {}, config = {}, menus = []) {
90
+ export async function createBefly(config = {}, menus = []) {
119
91
  const mergedConfig = deepMerge(beflyConfig, config);
120
92
  const mergedMenus = deepMerge(prefixMenuPaths(beflyMenus, "core"), menus);
121
- mergedConfig.projectLists = mergeProjectListsByCode(mergedConfig.projectLists);
122
93
 
123
94
  Logger.configure({
124
95
  runtimeEnv: mergedConfig.runMode,
@@ -144,7 +115,6 @@ export async function createBefly(env = {}, config = {}, menus = []) {
144
115
  }
145
116
 
146
117
  return new Befly({
147
- env: env,
148
118
  config: mergedConfig,
149
119
  tables: tables,
150
120
  menus: mergedMenus,
@@ -162,7 +132,6 @@ export async function createBefly(env = {}, config = {}, menus = []) {
162
132
  export class Befly {
163
133
  constructor(init = {}) {
164
134
  this.context = {
165
- env: init.env || {},
166
135
  config: init.config || {},
167
136
  tables: init.tables || {}
168
137
  };
@@ -208,7 +177,7 @@ export class Befly {
208
177
  await ensureSyncPrerequisites(this.context);
209
178
 
210
179
  // 自动同步(PM2 cluster:主进程执行,其它进程等待同步完成)
211
- if (isPrimaryProcess(this.context.env)) {
180
+ if (isPrimaryProcess(Bun.env)) {
212
181
  await syncApi(this.context, this.apis);
213
182
  await syncMenu(this.context, this.menus);
214
183
  await syncDev(this.context);
@@ -229,7 +198,7 @@ export class Befly {
229
198
  port: this.context.config.appPort || 3000,
230
199
  hostname: this.context.config.appHost || "0.0.0.0",
231
200
  // 开发模式下启用详细错误信息
232
- development: this.context.env.RUN_MODE === "development",
201
+ development: this.context.config.runMode === "development",
233
202
  // 空闲连接超时时间(秒),防止恶意连接占用资源
234
203
  fetch: async (req, httpServer) => {
235
204
  const url = new URL(req.url);
@@ -247,7 +216,7 @@ export class Befly {
247
216
  error: (error) => {
248
217
  Logger.error("服务启动时发生错误", error);
249
218
  // 开发模式下返回详细错误信息
250
- if (this.context.env.RUN_MODE === "development") {
219
+ if (this.context.config.runMode === "development") {
251
220
  return Response.json(
252
221
  {
253
222
  code: 1,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.65.0",
3
+ "version": "3.67.0",
4
4
  "gitHead": "49c39d36695036e85fc64083cc43c1652fff96cb",
5
5
  "private": false,
6
6
  "description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",