befly 3.8.11 → 3.8.13

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/env.ts CHANGED
@@ -19,39 +19,37 @@ const coreEnv: EnvConfig = {
19
19
  APP_NAME: isProd ? '野蜂飞舞正式环境' : '野蜂飞舞开发环境',
20
20
  APP_PORT: 3000,
21
21
  APP_HOST: '127.0.0.1',
22
- DEV_EMAIL: 'dev@qq.com',
22
+ DEV_EMAIL: '',
23
23
  DEV_PASSWORD: '123456',
24
- BODY_LIMIT: 10485760, // 10MB
24
+ BODY_LIMIT: 10 * 1024 * 1024, // 10MB
25
+ // ========== 时区配置 ==========
26
+ TZ: 'Asia/Shanghai',
25
27
 
26
28
  // ========== 日志配置 ==========
27
- LOG_DEBUG: 0,
29
+ LOG_DEBUG: 1,
28
30
  LOG_EXCLUDE_FIELDS: 'password,token,secret',
29
31
  LOG_DIR: './logs',
30
32
  LOG_TO_CONSOLE: 1,
31
- LOG_MAX_SIZE: 52428800, // 50MB
32
-
33
- // ========== 时区配置 ==========
34
- TZ: 'Asia/Shanghai',
33
+ LOG_MAX_SIZE: 10 * 1024 * 1024, // 10MB
35
34
 
36
35
  // ========== 数据库配置 ==========
37
- DB_ENABLE: 1,
36
+ DB_ENABLE: 0,
38
37
  DB_TYPE: 'mysql',
39
38
  DB_HOST: '127.0.0.1',
40
39
  DB_PORT: 3306,
41
40
  DB_USER: 'root',
42
- DB_PASS: '',
41
+ DB_PASS: 'root',
43
42
  DB_NAME: 'befly_demo',
44
- DB_DEBUG: 0,
45
43
  DB_POOL_MAX: 10,
46
44
 
47
45
  // ========== Redis 配置 ==========
48
- REDIS_ENABLE: 1,
46
+ REDIS_ENABLE: 0,
49
47
  REDIS_HOST: '127.0.0.1',
50
48
  REDIS_PORT: 6379,
51
49
  REDIS_USERNAME: '',
52
50
  REDIS_PASSWORD: '',
53
51
  REDIS_DB: 0,
54
- REDIS_KEY_PREFIX: 'befly',
52
+ REDIS_KEY_PREFIX: 'befly_demo',
55
53
 
56
54
  // ========== JWT 配置 ==========
57
55
  JWT_SECRET: 'befly-secret',
@@ -64,17 +62,7 @@ const coreEnv: EnvConfig = {
64
62
  CORS_ALLOWED_HEADERS: 'Content-Type, Authorization, authorization, token',
65
63
  CORS_EXPOSE_HEADERS: 'Content-Range, X-Content-Range, Authorization, authorization, token',
66
64
  CORS_MAX_AGE: 86400,
67
- CORS_ALLOW_CREDENTIALS: 'true',
68
-
69
- // ========== 邮件配置 ==========
70
- MAIL_HOST: '',
71
- MAIL_PORT: 587,
72
- MAIL_POOL: 'true',
73
- MAIL_SECURE: 'false',
74
- MAIL_USER: '',
75
- MAIL_PASS: '',
76
- MAIL_SENDER: '',
77
- MAIL_ADDRESS: ''
65
+ CORS_ALLOW_CREDENTIALS: 'true'
78
66
  };
79
67
 
80
68
  /**
package/lib/logger.ts CHANGED
@@ -31,14 +31,6 @@ function formatDate(): string {
31
31
  * 日志器类
32
32
  */
33
33
  export class Logger {
34
- /** 日志配置(直接使用 Env) */
35
- private static readonly config = {
36
- logDir: Env.LOG_DIR || 'logs',
37
- maxFileSize: Env.LOG_MAX_SIZE || 50 * 1024 * 1024,
38
- enableDebug: Env.LOG_DEBUG === 1,
39
- toConsole: Env.LOG_TO_CONSOLE === 1
40
- };
41
-
42
34
  /** 当前使用的日志文件缓存 */
43
35
  private static currentFiles: Map<string, string> = new Map();
44
36
 
@@ -48,8 +40,8 @@ export class Logger {
48
40
  * @param message - 日志消息
49
41
  */
50
42
  static async log(level: LogLevel, message: LogMessage): Promise<void> {
51
- // debug 日志特殊处理:仅当 enableDebug 为 true 时才记录
52
- if (level === 'debug' && !this.config.enableDebug) return;
43
+ // debug 日志特殊处理:仅当 LOG_DEBUG=1 时才记录
44
+ if (level === 'debug' && Env.LOG_DEBUG !== 1) return;
53
45
 
54
46
  // 格式化消息
55
47
  const timestamp = formatDate();
@@ -67,7 +59,7 @@ export class Logger {
67
59
  const logMessage = `[${timestamp}] ${levelStr} - ${content}`;
68
60
 
69
61
  // 控制台输出
70
- if (this.config.toConsole) {
62
+ if (Env.LOG_TO_CONSOLE === 1) {
71
63
  console.log(logMessage);
72
64
  }
73
65
 
@@ -99,7 +91,7 @@ export class Logger {
99
91
  if (currentLogFile) {
100
92
  try {
101
93
  const stats = await stat(currentLogFile);
102
- if (stats.size >= this.config.maxFileSize) {
94
+ if (stats.size >= Env.LOG_MAX_SIZE) {
103
95
  this.currentFiles.delete(prefix);
104
96
  currentLogFile = undefined;
105
97
  }
@@ -112,7 +104,7 @@ export class Logger {
112
104
  // 查找或创建新文件
113
105
  if (!currentLogFile) {
114
106
  const glob = new Bun.Glob(`${prefix}.*.log`);
115
- const files = await Array.fromAsync(glob.scan(this.config.logDir));
107
+ const files = await Array.fromAsync(glob.scan(Env.LOG_DIR || 'logs'));
116
108
 
117
109
  // 按索引排序并查找可用文件
118
110
  const getIndex = (f: string) => parseInt(f.match(/\.(\d+)\.log$/)?.[1] || '0');
@@ -120,10 +112,10 @@ export class Logger {
120
112
 
121
113
  let foundFile = false;
122
114
  for (let i = files.length - 1; i >= 0; i--) {
123
- const filePath = join(this.config.logDir, files[i]);
115
+ const filePath = join(Env.LOG_DIR || 'logs', files[i]);
124
116
  try {
125
117
  const stats = await stat(filePath);
126
- if (stats.size < this.config.maxFileSize) {
118
+ if (stats.size < Env.LOG_MAX_SIZE) {
127
119
  currentLogFile = filePath;
128
120
  foundFile = true;
129
121
  break;
@@ -136,7 +128,7 @@ export class Logger {
136
128
  // 没有可用文件,创建新文件
137
129
  if (!foundFile) {
138
130
  const maxIndex = files.length > 0 ? Math.max(...files.map(getIndex)) : -1;
139
- currentLogFile = join(this.config.logDir, `${prefix}.${maxIndex + 1}.log`);
131
+ currentLogFile = join(Env.LOG_DIR || 'logs', `${prefix}.${maxIndex + 1}.log`);
140
132
  }
141
133
 
142
134
  this.currentFiles.set(prefix, currentLogFile);
@@ -128,8 +128,8 @@ async function initApi(apiRoutes: Map<string, ApiRoute>, apiInfo: { file: string
128
128
  // 设置默认值
129
129
  api.method = api.method || 'POST';
130
130
  api.auth = api.auth !== undefined ? api.auth : true;
131
- // 合并默认字段:先设置自定义字段,再用默认字段覆盖(默认字段优先级更高)
132
- api.fields = { ...(api.fields || {}), ...DEFAULT_API_FIELDS };
131
+ // 合并默认字段:默认字段作为基础,API 自定义字段优先级更高
132
+ api.fields = { ...DEFAULT_API_FIELDS, ...(api.fields || {}) };
133
133
  api.required = api.required || [];
134
134
 
135
135
  // 构建路由
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.8.11",
3
+ "version": "3.8.13",
4
4
  "description": "Befly - 为 Bun 专属打造的 TypeScript API 接口框架核心引擎",
5
5
  "type": "module",
6
6
  "private": false,
@@ -65,5 +65,5 @@
65
65
  "es-toolkit": "^1.41.0",
66
66
  "pathe": "^2.0.3"
67
67
  },
68
- "gitHead": "1159315bc410ec8fea8328ba5946e1d8690106b1"
68
+ "gitHead": "afb329b2cce2ab5f5821d8515ae7dba4622a4f1f"
69
69
  }
package/types/env.ts CHANGED
@@ -30,7 +30,6 @@ export interface EnvConfig {
30
30
  DB_USER: string;
31
31
  DB_PASS: string;
32
32
  DB_NAME: string;
33
- DB_DEBUG: number;
34
33
  DB_POOL_MAX: number;
35
34
 
36
35
  // ========== Redis 配置 ==========