befly 3.9.12 → 3.9.14
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/docs/README.md +85 -0
- package/docs/addon.md +512 -0
- package/docs/api.md +1604 -0
- package/docs/cipher.md +580 -0
- package/docs/config.md +638 -0
- package/docs/database.md +147 -3
- package/docs/examples.md +892 -0
- package/docs/hook.md +754 -0
- package/docs/logger.md +495 -0
- package/docs/plugin.md +978 -0
- package/docs/quickstart.md +331 -0
- package/docs/sync.md +586 -0
- package/docs/table.md +765 -0
- package/docs/validator.md +618 -0
- package/loader/loadApis.ts +33 -36
- package/package.json +3 -3
- package/sync/syncDb/apply.ts +1 -1
- package/sync/syncDb/constants.ts +0 -11
- package/sync/syncDb/helpers.ts +0 -1
- package/sync/syncDb/table.ts +2 -2
- package/sync/syncDb/tableCreate.ts +3 -3
- package/tests/syncDb-constants.test.ts +1 -23
- package/tests/syncDb-helpers.test.ts +0 -1
- package/types/database.d.ts +0 -2
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "befly",
|
|
3
|
-
"version": "3.9.
|
|
3
|
+
"version": "3.9.14",
|
|
4
4
|
"description": "Befly - 为 Bun 专属打造的 TypeScript API 接口框架核心引擎",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"private": false,
|
|
@@ -65,7 +65,7 @@
|
|
|
65
65
|
"bun": ">=1.3.0"
|
|
66
66
|
},
|
|
67
67
|
"dependencies": {
|
|
68
|
-
"befly-shared": "^1.2.
|
|
68
|
+
"befly-shared": "^1.2.3",
|
|
69
69
|
"chalk": "^5.6.2",
|
|
70
70
|
"es-toolkit": "^1.42.0",
|
|
71
71
|
"fast-jwt": "^6.1.0",
|
|
@@ -74,7 +74,7 @@
|
|
|
74
74
|
"pino": "^10.1.0",
|
|
75
75
|
"pino-roll": "^4.0.0"
|
|
76
76
|
},
|
|
77
|
-
"gitHead": "
|
|
77
|
+
"gitHead": "9f37fe1d7b660c79cbee174865b9d65b1a4ead22",
|
|
78
78
|
"devDependencies": {
|
|
79
79
|
"typescript": "^5.9.3"
|
|
80
80
|
}
|
package/sync/syncDb/apply.ts
CHANGED
|
@@ -61,7 +61,7 @@ export function compareFieldDefinition(existingColumn: ColumnInfo, fieldDef: Fie
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
-
// 检查注释变化(MySQL/PG
|
|
64
|
+
// 检查注释变化(MySQL/PG 支持列注释,对比数据库 comment 与字段 name)
|
|
65
65
|
if (!isSQLite()) {
|
|
66
66
|
const currentComment = existingColumn.comment || '';
|
|
67
67
|
if (currentComment !== fieldDef.name) {
|
package/sync/syncDb/constants.ts
CHANGED
|
@@ -18,17 +18,6 @@ export const DB_VERSION_REQUIREMENTS = {
|
|
|
18
18
|
SQLITE_MIN_VERSION_NUM: 35000 // 3 * 10000 + 50 * 100
|
|
19
19
|
} as const;
|
|
20
20
|
|
|
21
|
-
/**
|
|
22
|
-
* 系统字段定义(所有表都包含的固定字段)
|
|
23
|
-
*/
|
|
24
|
-
export const SYSTEM_FIELDS = {
|
|
25
|
-
ID: { name: 'id', comment: '主键ID' },
|
|
26
|
-
CREATED_AT: { name: 'created_at', comment: '创建时间' },
|
|
27
|
-
UPDATED_AT: { name: 'updated_at', comment: '更新时间' },
|
|
28
|
-
DELETED_AT: { name: 'deleted_at', comment: '删除时间' },
|
|
29
|
-
STATE: { name: 'state', comment: '状态字段' }
|
|
30
|
-
} as const;
|
|
31
|
-
|
|
32
21
|
/**
|
|
33
22
|
* 需要创建索引的系统字段
|
|
34
23
|
*/
|
package/sync/syncDb/helpers.ts
CHANGED
|
@@ -81,7 +81,6 @@ export function applyFieldDefaults(fieldDef: any): void {
|
|
|
81
81
|
fieldDef.default = fieldDef.default ?? null;
|
|
82
82
|
fieldDef.index = fieldDef.index ?? false;
|
|
83
83
|
fieldDef.unique = fieldDef.unique ?? false;
|
|
84
|
-
fieldDef.comment = fieldDef.comment ?? '';
|
|
85
84
|
fieldDef.nullable = fieldDef.nullable ?? false;
|
|
86
85
|
fieldDef.unsigned = fieldDef.unsigned ?? true;
|
|
87
86
|
fieldDef.regexp = fieldDef.regexp ?? null;
|
package/sync/syncDb/table.ts
CHANGED
|
@@ -170,8 +170,8 @@ export async function modifyTable(sql: SQL, tableName: string, fields: Record<st
|
|
|
170
170
|
}
|
|
171
171
|
}
|
|
172
172
|
|
|
173
|
-
// PG
|
|
174
|
-
const commentActions = [];
|
|
173
|
+
// PG 列注释处理(对比数据库 comment 与字段 name)
|
|
174
|
+
const commentActions: string[] = [];
|
|
175
175
|
if (isPG()) {
|
|
176
176
|
for (const [fieldKey, fieldDef] of Object.entries(fields)) {
|
|
177
177
|
// 转换字段名为下划线格式
|
|
@@ -19,7 +19,7 @@ import type { SQL } from 'bun';
|
|
|
19
19
|
import type { FieldDefinition } from 'befly-shared/types';
|
|
20
20
|
|
|
21
21
|
/**
|
|
22
|
-
* 为 PostgreSQL
|
|
22
|
+
* 为 PostgreSQL 表添加列注释(使用字段的 name 作为注释)
|
|
23
23
|
*
|
|
24
24
|
* @param sql - SQL 客户端实例
|
|
25
25
|
* @param tableName - 表名
|
|
@@ -44,7 +44,7 @@ async function addPostgresComments(sql: SQL, tableName: string, fields: Record<s
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
|
|
47
|
-
//
|
|
47
|
+
// 业务字段注释(使用 fieldDef.name 作为数据库列注释)
|
|
48
48
|
for (const [fieldKey, fieldDef] of Object.entries(fields)) {
|
|
49
49
|
// 转换字段名为下划线格式
|
|
50
50
|
const dbFieldName = snakeCase(fieldKey);
|
|
@@ -149,7 +149,7 @@ export async function createTable(sql: SQL, tableName: string, fields: Record<st
|
|
|
149
149
|
await sql.unsafe(createSQL);
|
|
150
150
|
}
|
|
151
151
|
|
|
152
|
-
// PostgreSQL:
|
|
152
|
+
// PostgreSQL: 添加列注释(使用字段 name 作为数据库列注释)
|
|
153
153
|
if (isPG() && !IS_PLAN) {
|
|
154
154
|
await addPostgresComments(sql, tableName, fields);
|
|
155
155
|
} else if (isPG() && IS_PLAN) {
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
*
|
|
4
4
|
* 测试 constants.ts 中的常量:
|
|
5
5
|
* - DB_VERSION_REQUIREMENTS
|
|
6
|
-
* -
|
|
6
|
+
* - SYSTEM_INDEX_FIELDS
|
|
7
7
|
* - SYSTEM_INDEX_FIELDS
|
|
8
8
|
* - CHANGE_TYPE_LABELS
|
|
9
9
|
* - MYSQL_TABLE_CONFIG
|
|
@@ -36,28 +36,6 @@ describe('DB_VERSION_REQUIREMENTS', () => {
|
|
|
36
36
|
});
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
describe('SYSTEM_FIELDS', () => {
|
|
40
|
-
test('包含 id 字段', () => {
|
|
41
|
-
expect(constants.SYSTEM_FIELDS.ID.name).toBe('id');
|
|
42
|
-
});
|
|
43
|
-
|
|
44
|
-
test('包含 created_at 字段', () => {
|
|
45
|
-
expect(constants.SYSTEM_FIELDS.CREATED_AT.name).toBe('created_at');
|
|
46
|
-
});
|
|
47
|
-
|
|
48
|
-
test('包含 updated_at 字段', () => {
|
|
49
|
-
expect(constants.SYSTEM_FIELDS.UPDATED_AT.name).toBe('updated_at');
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
test('包含 deleted_at 字段', () => {
|
|
53
|
-
expect(constants.SYSTEM_FIELDS.DELETED_AT.name).toBe('deleted_at');
|
|
54
|
-
});
|
|
55
|
-
|
|
56
|
-
test('包含 state 字段', () => {
|
|
57
|
-
expect(constants.SYSTEM_FIELDS.STATE.name).toBe('state');
|
|
58
|
-
});
|
|
59
|
-
});
|
|
60
|
-
|
|
61
39
|
describe('SYSTEM_INDEX_FIELDS', () => {
|
|
62
40
|
test('包含 created_at', () => {
|
|
63
41
|
expect(constants.SYSTEM_INDEX_FIELDS).toContain('created_at');
|
|
@@ -67,7 +67,6 @@ describe('applyFieldDefaults', () => {
|
|
|
67
67
|
expect(fieldDef.default).toBe(null);
|
|
68
68
|
expect(fieldDef.index).toBe(false);
|
|
69
69
|
expect(fieldDef.unique).toBe(false);
|
|
70
|
-
expect(fieldDef.comment).toBe('');
|
|
71
70
|
expect(fieldDef.nullable).toBe(false);
|
|
72
71
|
expect(fieldDef.unsigned).toBe(true);
|
|
73
72
|
expect(fieldDef.regexp).toBe(null);
|