befly 3.17.2 → 3.17.4

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.
Files changed (3) hide show
  1. package/index.js +27 -19
  2. package/lib/connect.js +3 -7
  3. package/package.json +2 -2
package/index.js CHANGED
@@ -166,20 +166,38 @@ export class Befly {
166
166
  return instance;
167
167
  }
168
168
 
169
+ ensureCreatedByFactory(methodName) {
170
+ if (this.createdByFactory) {
171
+ return;
172
+ }
173
+
174
+ throw new Error(`请使用 Befly.create(...) 创建实例后再调用 ${methodName}`, {
175
+ cause: null,
176
+ code: "policy",
177
+ subsystem: methodName === "start" ? "start" : "syncDb",
178
+ operation: "factoryGuard"
179
+ });
180
+ }
181
+
182
+ async dbCheck() {
183
+ this.ensureCreatedByFactory("dbCheck");
184
+
185
+ return syncDbCheck(this.context.config.mysql);
186
+ }
187
+
188
+ async dbApply() {
189
+ this.ensureCreatedByFactory("dbApply");
190
+
191
+ return syncDbApply(this.context.config.mysql);
192
+ }
193
+
169
194
  /**
170
195
  * 启动完整的生命周期流程
171
196
  * @returns HTTP 服务器实例
172
197
  */
173
198
  async start() {
174
199
  try {
175
- if (!this.createdByFactory) {
176
- throw new Error("请使用 Befly.create(...) 创建实例后再调用 start", {
177
- cause: null,
178
- code: "policy",
179
- subsystem: "start",
180
- operation: "factoryGuard"
181
- });
182
- }
200
+ this.ensureCreatedByFactory("start");
183
201
 
184
202
  const serverStartTime = Bun.nanoseconds();
185
203
  if (!Array.isArray(this.scanApis) || !Array.isArray(this.scanPlugins) || !Array.isArray(this.scanHooks)) {
@@ -313,14 +331,4 @@ export class Befly {
313
331
  }
314
332
  }
315
333
 
316
- async function dbCheck(config = {}) {
317
- const mergedConfig = deepMerge(beflyConfig, config);
318
- return syncDbCheck(mergedConfig.mysql);
319
- }
320
-
321
- async function dbApply(config = {}) {
322
- const mergedConfig = deepMerge(beflyConfig, config);
323
- return syncDbApply(mergedConfig.mysql);
324
- }
325
-
326
- export { dbApply, dbCheck, Logger };
334
+ export { Logger };
package/lib/connect.js CHANGED
@@ -48,7 +48,7 @@ export class Connect {
48
48
  this.mysqlClient = new SQL(sqlConfig);
49
49
 
50
50
  await this.mysqlClient`SELECT 1`;
51
- Logger.info("Mysql 连接成功");
51
+ Logger.info(`Mysql 连接成功 (${config.hostname})`);
52
52
  } catch (error) {
53
53
  await this.mysqlClient?.close();
54
54
  this.mysqlClient = null;
@@ -83,16 +83,12 @@ export class Connect {
83
83
  this.redisClient = new RedisClient(redisUrl);
84
84
  // Called when successfully connected to Redis server
85
85
  this.redisClient.onconnect = () => {
86
- Logger.info("Redis 连接成功");
86
+ Logger.info(`Redis 连接成功 (${config.hostname})`);
87
87
  };
88
88
 
89
89
  // Called when disconnected from Redis server
90
90
  this.redisClient.onclose = (error) => {
91
- Logger.warn("Redis 断开连接", {
92
- subsystem: "redis",
93
- operation: "onclose",
94
- cause: error
95
- });
91
+ Logger.warn("Redis 断开连接");
96
92
  };
97
93
  } catch (error) {
98
94
  await this.redisClient?.close();
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.17.2",
4
- "gitHead": "0227130890b66df1469e8ad3441235d7af0655c0",
3
+ "version": "3.17.4",
4
+ "gitHead": "bb2ab272371940036eaa305495c90d29b23fedc5",
5
5
  "private": false,
6
6
  "description": "Befly - 为 Bun 专属打造的 JavaScript API 接口框架核心引擎",
7
7
  "keywords": [