befly 3.21.1 → 3.22.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.
- package/README.md +7 -0
- package/apis/admin/list.js +1 -1
- package/apis/admin/upd.js +2 -2
- package/apis/dict/all.js +1 -1
- package/apis/dict/detail.js +1 -1
- package/apis/dict/list.js +1 -1
- package/apis/dict/upd.js +1 -1
- package/apis/dictType/upd.js +1 -1
- package/apis/role/all.js +1 -1
- package/apis/role/list.js +1 -1
- package/apis/role/upd.js +1 -1
- package/checks/config.js +1 -3
- package/checks/table.js +2 -15
- package/configs/beflyConfig.json +1 -3
- package/index.js +5 -10
- package/lib/dbHelper.js +201 -736
- package/lib/dbParse.js +1045 -0
- package/lib/dbUtil.js +83 -438
- package/lib/logger.js +21 -45
- package/lib/sqlBuilder.js +78 -294
- package/package.json +2 -2
- package/plugins/mysql.js +2 -1
- package/scripts/syncDb/context.js +62 -47
- package/scripts/syncDb/diff.js +78 -15
- package/scripts/syncDb/index.js +16 -46
- package/scripts/syncDb/report.js +97 -98
- package/tables/admin.json +24 -0
- package/tables/api.json +24 -0
- package/tables/dict.json +24 -0
- package/tables/dictType.json +24 -0
- package/tables/emailLog.json +24 -0
- package/tables/errorReport.json +140 -0
- package/tables/infoReport.json +123 -0
- package/tables/loginLog.json +24 -0
- package/tables/menu.json +24 -0
- package/tables/operateLog.json +24 -0
- package/tables/role.json +24 -0
- package/tables/sysConfig.json +24 -0
- package/utils/loggerUtils.js +9 -14
- package/utils/scanSources.js +3 -3
- package/scripts/syncDb/query.js +0 -26
package/README.md
CHANGED
|
@@ -9,3 +9,10 @@
|
|
|
9
9
|
"bundle:min": "bun build ./index.js --outfile ./befly.min.js --target bun --format esm --packages bundle --minify",
|
|
10
10
|
"build": "rimraf befly.js befly.min.js && bun run bundle && bun run bundle:min"
|
|
11
11
|
```
|
|
12
|
+
|
|
13
|
+
我们把要求和实现对齐一下,要符合如下规范:
|
|
14
|
+
|
|
15
|
+
1. 单表查询,不传fields或fields为空数组,表示查询所有字段。
|
|
16
|
+
2. 单表查询,fields指定查询字段,表示明确只查询这些字段。
|
|
17
|
+
3. 单表查询,fields用!感叹号开头,表示排除不查询这些字段。
|
|
18
|
+
4. 单表查询,不存在明确查询字段又排除某些字段的混合情况。
|
package/apis/admin/list.js
CHANGED
package/apis/admin/upd.js
CHANGED
|
@@ -39,7 +39,7 @@ export default {
|
|
|
39
39
|
if (username && username !== admin.data.username) {
|
|
40
40
|
const existingUsername = await befly.mysql.getOne({
|
|
41
41
|
table: "beflyAdmin",
|
|
42
|
-
where: { username: username, id: { $
|
|
42
|
+
where: { username: username, id: { $not: id } }
|
|
43
43
|
});
|
|
44
44
|
if (existingUsername.data?.id) {
|
|
45
45
|
return befly.tool.No("用户名已被使用");
|
|
@@ -50,7 +50,7 @@ export default {
|
|
|
50
50
|
if (nickname && nickname !== admin.data.nickname) {
|
|
51
51
|
const existingNickname = await befly.mysql.getOne({
|
|
52
52
|
table: "beflyAdmin",
|
|
53
|
-
where: { nickname: nickname, id: { $
|
|
53
|
+
where: { nickname: nickname, id: { $not: id } }
|
|
54
54
|
});
|
|
55
55
|
if (existingNickname.data?.id) {
|
|
56
56
|
return befly.tool.No("昵称已被使用");
|
package/apis/dict/all.js
CHANGED
|
@@ -12,7 +12,7 @@ export default {
|
|
|
12
12
|
const result = await befly.mysql.getAll({
|
|
13
13
|
table: ["beflyDict", "beflyDictType"],
|
|
14
14
|
leftJoin: ["beflyDict.typeCode beflyDictType.code"],
|
|
15
|
-
fields: ["beflyDict.id", "beflyDict.typeCode", "beflyDict.key", "beflyDict.label", "beflyDict.sort", "beflyDict.remark", "beflyDict.createdAt", "beflyDict.updatedAt", "beflyDictType.name
|
|
15
|
+
fields: ["beflyDict.id", "beflyDict.typeCode", "beflyDict.key", "beflyDict.label", "beflyDict.sort", "beflyDict.remark", "beflyDict.createdAt", "beflyDict.updatedAt", "beflyDictType.name typeName"],
|
|
16
16
|
orderBy: ["beflyDict.sort#ASC", "beflyDict.id#ASC"]
|
|
17
17
|
});
|
|
18
18
|
|
package/apis/dict/detail.js
CHANGED
|
@@ -11,7 +11,7 @@ export default {
|
|
|
11
11
|
const dict = await befly.mysql.getOne({
|
|
12
12
|
table: ["beflyDict", "beflyDictType"],
|
|
13
13
|
leftJoin: ["beflyDict.typeCode beflyDictType.code"],
|
|
14
|
-
fields: ["beflyDict.id", "beflyDict.typeCode", "beflyDict.key", "beflyDict.label", "beflyDict.sort", "beflyDict.remark", "beflyDict.createdAt", "beflyDict.updatedAt", "beflyDictType.name
|
|
14
|
+
fields: ["beflyDict.id", "beflyDict.typeCode", "beflyDict.key", "beflyDict.label", "beflyDict.sort", "beflyDict.remark", "beflyDict.createdAt", "beflyDict.updatedAt", "beflyDictType.name typeName"],
|
|
15
15
|
where: { "beflyDict.id": ctx.body.id }
|
|
16
16
|
});
|
|
17
17
|
|
package/apis/dict/list.js
CHANGED
|
@@ -16,7 +16,7 @@ export default {
|
|
|
16
16
|
const result = await befly.mysql.getList({
|
|
17
17
|
table: ["beflyDict", "beflyDictType"],
|
|
18
18
|
leftJoin: ["beflyDict.typeCode beflyDictType.code"],
|
|
19
|
-
fields: ["beflyDict.id", "beflyDict.typeCode", "beflyDict.key", "beflyDict.label", "beflyDict.sort", "beflyDict.remark", "beflyDict.createdAt", "beflyDict.updatedAt", "beflyDictType.name
|
|
19
|
+
fields: ["beflyDict.id", "beflyDict.typeCode", "beflyDict.key", "beflyDict.label", "beflyDict.sort", "beflyDict.remark", "beflyDict.createdAt", "beflyDict.updatedAt", "beflyDictType.name typeName"],
|
|
20
20
|
where: {
|
|
21
21
|
"beflyDict.typeCode": ctx.body.typeCode
|
|
22
22
|
},
|
package/apis/dict/upd.js
CHANGED
package/apis/dictType/upd.js
CHANGED
package/apis/role/all.js
CHANGED
package/apis/role/list.js
CHANGED
package/apis/role/upd.js
CHANGED
package/checks/config.js
CHANGED
|
@@ -29,9 +29,7 @@ const configSchema = z
|
|
|
29
29
|
excludeFields: z.array(noTrimString),
|
|
30
30
|
dir: noTrimString,
|
|
31
31
|
console: boolIntSchema,
|
|
32
|
-
maxSize: z.int().min(1)
|
|
33
|
-
maxStringLen: z.int().min(1),
|
|
34
|
-
maxArrayItems: z.int().min(1)
|
|
32
|
+
maxSize: z.int().min(1)
|
|
35
33
|
})
|
|
36
34
|
.strict(),
|
|
37
35
|
|
package/checks/table.js
CHANGED
|
@@ -76,20 +76,7 @@ const fieldDefSchema = z
|
|
|
76
76
|
});
|
|
77
77
|
|
|
78
78
|
const tableContentSchema = z.record(z.string().regex(lowerCamelRegex), fieldDefSchema);
|
|
79
|
-
|
|
80
|
-
const tableItemSchema = z
|
|
81
|
-
.object({
|
|
82
|
-
source: noTrimString.min(1),
|
|
83
|
-
type: noTrimString.min(1),
|
|
84
|
-
filePath: noTrimString.min(1),
|
|
85
|
-
relativePath: noTrimString.min(1),
|
|
86
|
-
apiPath: noTrimString.min(1),
|
|
87
|
-
fileName: z.string().min(1).regex(lowerCamelRegex),
|
|
88
|
-
fieldsDef: tableContentSchema
|
|
89
|
-
})
|
|
90
|
-
.strict();
|
|
91
|
-
|
|
92
|
-
const tableListSchema = z.array(tableItemSchema);
|
|
79
|
+
const tableRegistrySchema = z.record(z.string().regex(lowerCamelRegex), tableContentSchema);
|
|
93
80
|
|
|
94
81
|
/**
|
|
95
82
|
* 检查表定义文件
|
|
@@ -99,7 +86,7 @@ export async function checkTable(tables) {
|
|
|
99
86
|
// 收集所有表文件
|
|
100
87
|
let hasError = false;
|
|
101
88
|
|
|
102
|
-
const schemaResult =
|
|
89
|
+
const schemaResult = tableRegistrySchema.safeParse(tables);
|
|
103
90
|
if (!schemaResult.success) {
|
|
104
91
|
const errors = formatZodIssues(schemaResult.error.issues, { items: tables, itemLabel: "table" });
|
|
105
92
|
Logger.warn("表结构校验失败", { errors: errors }, false);
|
package/configs/beflyConfig.json
CHANGED
package/index.js
CHANGED
|
@@ -26,13 +26,14 @@ import { syncApi } from "./sync/api.js";
|
|
|
26
26
|
import { syncCache } from "./sync/cache.js";
|
|
27
27
|
import { syncDev } from "./sync/dev.js";
|
|
28
28
|
import { syncMenu } from "./sync/menu.js";
|
|
29
|
-
import { syncDbApply, syncDbCheck } from "./scripts/syncDb/index.js";
|
|
30
29
|
// 工具
|
|
31
30
|
import { calcPerfTime } from "./utils/calcPerfTime.js";
|
|
32
31
|
import { scanSources } from "./utils/scanSources.js";
|
|
33
32
|
import { isPrimaryProcess } from "./utils/is.js";
|
|
34
33
|
import { deepMerge } from "./utils/deepMerge.js";
|
|
35
34
|
|
|
35
|
+
export { syncDbApply as syncDb } from "./scripts/syncDb/index.js";
|
|
36
|
+
|
|
36
37
|
function prefixMenuPaths(menus, prefix) {
|
|
37
38
|
const output = [];
|
|
38
39
|
for (const menu of menus) {
|
|
@@ -94,14 +95,6 @@ async function ensureSyncPrerequisites(ctx) {
|
|
|
94
95
|
}
|
|
95
96
|
}
|
|
96
97
|
|
|
97
|
-
export async function dbCheck(mysqlConfig) {
|
|
98
|
-
return syncDbCheck(mysqlConfig);
|
|
99
|
-
}
|
|
100
|
-
|
|
101
|
-
export async function dbApply(mysqlConfig) {
|
|
102
|
-
return syncDbApply(mysqlConfig);
|
|
103
|
-
}
|
|
104
|
-
|
|
105
98
|
export async function createBefly(env = {}, config = {}, menus = []) {
|
|
106
99
|
const mergedConfig = deepMerge(beflyConfig, config);
|
|
107
100
|
const mergedMenus = deepMerge(prefixMenuPaths(beflyMenus, "core"), menus);
|
|
@@ -127,6 +120,7 @@ export async function createBefly(env = {}, config = {}, menus = []) {
|
|
|
127
120
|
return new Befly({
|
|
128
121
|
env: env,
|
|
129
122
|
config: mergedConfig,
|
|
123
|
+
tables: tables,
|
|
130
124
|
menus: mergedMenus,
|
|
131
125
|
apis: apis,
|
|
132
126
|
hooks: hooks,
|
|
@@ -143,7 +137,8 @@ export class Befly {
|
|
|
143
137
|
constructor(init = {}) {
|
|
144
138
|
this.context = {
|
|
145
139
|
env: init.env || {},
|
|
146
|
-
config: init.config || {}
|
|
140
|
+
config: init.config || {},
|
|
141
|
+
tables: init.tables || {}
|
|
147
142
|
};
|
|
148
143
|
this.menus = Array.isArray(init.menus) ? init.menus : [];
|
|
149
144
|
this.hooks = Array.isArray(init.hooks) ? init.hooks : [];
|