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 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. 单表查询,不存在明确查询字段又排除某些字段的混合情况。
@@ -17,7 +17,7 @@ export default {
17
17
  limit: ctx.body.limit,
18
18
  where: {
19
19
  roleCode: {
20
- $ne: "dev"
20
+ $not: "dev"
21
21
  }
22
22
  },
23
23
  orderBy: ["createdAt#DESC"]
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: { $ne: 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: { $ne: 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 AS typeName"],
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
 
@@ -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 AS typeName"],
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 AS typeName"],
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
@@ -47,7 +47,7 @@ export default {
47
47
  where: {
48
48
  typeCode: checkTypeCode,
49
49
  key: checkKey,
50
- id$ne: id
50
+ id$not: id
51
51
  }
52
52
  });
53
53
 
@@ -25,7 +25,7 @@ export default {
25
25
  table: "beflyDictType",
26
26
  where: {
27
27
  code: code,
28
- id$ne: id
28
+ id$not: id
29
29
  }
30
30
  });
31
31
 
package/apis/role/all.js CHANGED
@@ -10,7 +10,7 @@ export default {
10
10
  table: "beflyRole",
11
11
  where: {
12
12
  code: {
13
- $ne: "dev"
13
+ $not: "dev"
14
14
  }
15
15
  },
16
16
  orderBy: ["sort#ASC", "id#ASC"]
package/apis/role/list.js CHANGED
@@ -16,7 +16,7 @@ export default {
16
16
  table: "beflyRole",
17
17
  where: {
18
18
  code: {
19
- $ne: "dev"
19
+ $not: "dev"
20
20
  }
21
21
  },
22
22
  orderBy: ["sort#ASC", "id#ASC"]
package/apis/role/upd.js CHANGED
@@ -22,7 +22,7 @@ export default {
22
22
  table: "beflyRole",
23
23
  where: {
24
24
  code: ctx.body.code,
25
- id$ne: ctx.body.id
25
+ id$not: ctx.body.id
26
26
  }
27
27
  });
28
28
 
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 = tableListSchema.safeParse(tables);
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);
@@ -14,9 +14,7 @@
14
14
  "excludeFields": ["password", "token", "secret"],
15
15
  "dir": "./logs",
16
16
  "console": 1,
17
- "maxSize": 20,
18
- "maxStringLen": 100,
19
- "maxArrayItems": 100
17
+ "maxSize": 20
20
18
  },
21
19
 
22
20
  "mysql": {
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 : [];