befly 3.10.19 → 3.11.1

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 (125) hide show
  1. package/dist/befly.config.d.ts +1 -1
  2. package/dist/befly.config.js +3 -5
  3. package/dist/befly.js +15621 -0
  4. package/dist/befly.min.js +21 -0
  5. package/dist/checks/checkApi.js +2 -3
  6. package/dist/checks/checkHook.js +50 -3
  7. package/dist/checks/checkMenu.d.ts +2 -2
  8. package/dist/checks/checkMenu.js +3 -3
  9. package/dist/checks/checkPlugin.js +50 -3
  10. package/dist/checks/checkTable.d.ts +1 -1
  11. package/dist/checks/checkTable.js +1 -1
  12. package/dist/hooks/auth.d.ts +3 -1
  13. package/dist/hooks/auth.js +3 -1
  14. package/dist/hooks/cors.d.ts +3 -1
  15. package/dist/hooks/cors.js +3 -1
  16. package/dist/hooks/parser.d.ts +3 -1
  17. package/dist/hooks/parser.js +4 -3
  18. package/dist/hooks/permission.d.ts +3 -1
  19. package/dist/hooks/permission.js +5 -3
  20. package/dist/hooks/validator.d.ts +3 -1
  21. package/dist/hooks/validator.js +4 -2
  22. package/dist/{main.d.ts → index.d.ts} +1 -1
  23. package/dist/{main.js → index.js} +24 -24
  24. package/dist/lib/cacheHelper.js +2 -2
  25. package/dist/lib/cipher.d.ts +1 -1
  26. package/dist/lib/connect.d.ts +1 -1
  27. package/dist/lib/connect.js +1 -1
  28. package/dist/lib/dbHelper.d.ts +3 -3
  29. package/dist/lib/dbHelper.js +9 -11
  30. package/dist/lib/dbUtils.d.ts +1 -1
  31. package/dist/lib/dbUtils.js +2 -3
  32. package/dist/lib/jwt.d.ts +2 -2
  33. package/dist/lib/logger.d.ts +17 -7
  34. package/dist/lib/logger.js +620 -210
  35. package/dist/lib/redisHelper.js +2 -2
  36. package/dist/lib/sqlBuilder.d.ts +1 -1
  37. package/dist/lib/sqlBuilder.js +1 -1
  38. package/dist/lib/validator.d.ts +1 -1
  39. package/dist/lib/validator.js +1 -1
  40. package/dist/loader/loadApis.d.ts +2 -2
  41. package/dist/loader/loadApis.js +3 -3
  42. package/dist/loader/loadHooks.d.ts +3 -4
  43. package/dist/loader/loadHooks.js +6 -8
  44. package/dist/loader/loadPlugins.d.ts +4 -4
  45. package/dist/loader/loadPlugins.js +7 -7
  46. package/dist/plugins/cache.d.ts +4 -2
  47. package/dist/plugins/cache.js +3 -1
  48. package/dist/plugins/cipher.d.ts +3 -1
  49. package/dist/plugins/cipher.js +3 -1
  50. package/dist/plugins/config.d.ts +4 -2
  51. package/dist/plugins/config.js +2 -0
  52. package/dist/plugins/db.d.ts +4 -2
  53. package/dist/plugins/db.js +6 -4
  54. package/dist/plugins/jwt.d.ts +4 -2
  55. package/dist/plugins/jwt.js +3 -1
  56. package/dist/plugins/logger.d.ts +7 -3
  57. package/dist/plugins/logger.js +3 -1
  58. package/dist/plugins/redis.d.ts +4 -2
  59. package/dist/plugins/redis.js +5 -3
  60. package/dist/plugins/tool.d.ts +3 -1
  61. package/dist/plugins/tool.js +2 -0
  62. package/dist/router/api.d.ts +3 -3
  63. package/dist/router/api.js +5 -5
  64. package/dist/router/static.d.ts +1 -1
  65. package/dist/router/static.js +3 -3
  66. package/dist/scripts/ensureDist.js +218 -2
  67. package/dist/sync/syncApi.d.ts +2 -2
  68. package/dist/sync/syncApi.js +2 -2
  69. package/dist/sync/syncCache.d.ts +1 -1
  70. package/dist/sync/syncDev.d.ts +1 -1
  71. package/dist/sync/syncDev.js +2 -2
  72. package/dist/sync/syncMenu.d.ts +2 -2
  73. package/dist/sync/syncMenu.js +4 -4
  74. package/dist/sync/syncTable.d.ts +6 -6
  75. package/dist/sync/syncTable.js +4 -4
  76. package/dist/types/api.d.ts +4 -4
  77. package/dist/types/befly.d.ts +8 -12
  78. package/dist/types/cache.d.ts +2 -2
  79. package/dist/types/cipher.d.ts +1 -1
  80. package/dist/types/context.d.ts +1 -1
  81. package/dist/types/database.d.ts +1 -1
  82. package/dist/types/hook.d.ts +4 -2
  83. package/dist/types/logger.d.ts +14 -2
  84. package/dist/types/plugin.d.ts +3 -1
  85. package/dist/types/sync.d.ts +2 -2
  86. package/dist/utils/cors.d.ts +1 -1
  87. package/dist/utils/importDefault.js +1 -1
  88. package/dist/utils/loadMenuConfigs.d.ts +26 -2
  89. package/dist/utils/loadMenuConfigs.js +44 -3
  90. package/dist/utils/mergeAndConcat.d.ts +7 -0
  91. package/dist/utils/mergeAndConcat.js +72 -0
  92. package/dist/utils/processAtSymbol.d.ts +4 -0
  93. package/dist/utils/{processFields.js → processAtSymbol.js} +2 -2
  94. package/dist/utils/response.d.ts +1 -1
  95. package/dist/utils/response.js +1 -1
  96. package/dist/utils/scanAddons.js +3 -3
  97. package/dist/utils/scanConfig.js +6 -7
  98. package/dist/utils/scanCoreBuiltins.d.ts +3 -0
  99. package/dist/utils/scanCoreBuiltins.js +65 -0
  100. package/dist/utils/scanFiles.js +19 -6
  101. package/dist/utils/scanSources.d.ts +2 -2
  102. package/dist/utils/scanSources.js +16 -11
  103. package/dist/utils/sortModules.js +2 -2
  104. package/dist/utils/util.d.ts +84 -0
  105. package/dist/utils/util.js +262 -0
  106. package/package.json +20 -14
  107. package/dist/utils/arrayKeysToCamel.d.ts +0 -13
  108. package/dist/utils/arrayKeysToCamel.js +0 -18
  109. package/dist/utils/configTypes.d.ts +0 -1
  110. package/dist/utils/configTypes.js +0 -1
  111. package/dist/utils/genShortId.d.ts +0 -10
  112. package/dist/utils/genShortId.js +0 -12
  113. package/dist/utils/keysToCamel.d.ts +0 -10
  114. package/dist/utils/keysToCamel.js +0 -21
  115. package/dist/utils/keysToSnake.d.ts +0 -10
  116. package/dist/utils/keysToSnake.js +0 -21
  117. package/dist/utils/pickFields.d.ts +0 -4
  118. package/dist/utils/pickFields.js +0 -16
  119. package/dist/utils/processFields.d.ts +0 -4
  120. package/dist/utils/regex.d.ts +0 -145
  121. package/dist/utils/regex.js +0 -202
  122. package/dist/utils/sqlLog.d.ts +0 -14
  123. package/dist/utils/sqlLog.js +0 -25
  124. /package/dist/utils/{process.d.ts → processInfo.d.ts} +0 -0
  125. /package/dist/utils/{process.js → processInfo.js} +0 -0
@@ -0,0 +1,262 @@
1
+ /**
2
+ * 注意:本文件用于集中维护 core 内部通用 utils。
3
+ * - 按项目规范:避免零散小文件噪音;实现集中在本文件,而不是做 re-export 聚合。
4
+ * - 仅在 packages/core 内部使用;core 对外不承诺这些路径导出。
5
+ */
6
+ export function isPlainObject(value) {
7
+ if (typeof value !== "object" || value === null) {
8
+ return false;
9
+ }
10
+ const proto = Object.getPrototypeOf(value);
11
+ return proto === Object.prototype || proto === null;
12
+ }
13
+ /**
14
+ * 激进空值判断(项目约定):
15
+ * - null/undefined => empty
16
+ * - "" / 全空白字符串 => empty
17
+ * - 0 / NaN => empty
18
+ * - false => empty
19
+ * - Array => length === 0
20
+ * - Map/Set => size === 0
21
+ * - plain object => 无自有 key
22
+ * - 其他类型 => false
23
+ */
24
+ export function isEmpty(value) {
25
+ if (value === null || value === undefined) {
26
+ return true;
27
+ }
28
+ if (typeof value === "string") {
29
+ return value.trim().length === 0;
30
+ }
31
+ if (typeof value === "number") {
32
+ return value === 0 || Number.isNaN(value);
33
+ }
34
+ if (typeof value === "boolean") {
35
+ return value === false;
36
+ }
37
+ if (Array.isArray(value)) {
38
+ return value.length === 0;
39
+ }
40
+ if (value instanceof Map || value instanceof Set) {
41
+ return value.size === 0;
42
+ }
43
+ if (isPlainObject(value)) {
44
+ return Object.keys(value).length === 0;
45
+ }
46
+ return false;
47
+ }
48
+ export function forOwn(obj, iteratee) {
49
+ if (typeof iteratee !== "function") {
50
+ return;
51
+ }
52
+ if (!isPlainObject(obj)) {
53
+ return;
54
+ }
55
+ for (const key of Object.keys(obj)) {
56
+ iteratee(obj[key], key);
57
+ }
58
+ }
59
+ function toWordParts(input) {
60
+ const normalized = String(input)
61
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
62
+ .replace(/[^a-zA-Z0-9]+/g, " ")
63
+ .trim();
64
+ if (normalized.length === 0) {
65
+ return [];
66
+ }
67
+ return normalized.split(/\s+/).filter((p) => p.length > 0);
68
+ }
69
+ function upperFirst(s) {
70
+ if (s.length === 0) {
71
+ return s;
72
+ }
73
+ return s[0].toUpperCase() + s.slice(1);
74
+ }
75
+ /**
76
+ * 把字符串转为小驼峰。
77
+ * - 主要用于文件名/目录名(例如 my_plugin / my-plugin / my plugin)。
78
+ */
79
+ export function camelCase(input) {
80
+ const parts = toWordParts(input);
81
+ if (parts.length === 0) {
82
+ return "";
83
+ }
84
+ const first = parts[0].toLowerCase();
85
+ const rest = parts.slice(1).map((p) => upperFirst(p.toLowerCase()));
86
+ return [first, ...rest].join("");
87
+ }
88
+ function normalizeToWords(input) {
89
+ return String(input)
90
+ .replace(/([a-z0-9])([A-Z])/g, "$1 $2")
91
+ .replace(/[^a-zA-Z0-9]+/g, " ")
92
+ .trim();
93
+ }
94
+ /**
95
+ * 把字符串转为 snake_case。
96
+ * - 主要用于表名/字段名(例如 userId -> user_id)。
97
+ */
98
+ export function snakeCase(input) {
99
+ const normalized = normalizeToWords(input);
100
+ if (normalized.length === 0) {
101
+ return "";
102
+ }
103
+ return normalized
104
+ .split(/\s+/)
105
+ .filter((p) => p.length > 0)
106
+ .map((p) => p.toLowerCase())
107
+ .join("_");
108
+ }
109
+ /**
110
+ * 对象字段名转小驼峰
111
+ * @param obj - 源对象
112
+ * @returns 字段名转为小驼峰格式的新对象
113
+ *
114
+ * @example
115
+ * keysToCamel({ user_id: 123, user_name: 'John' }) // { userId: 123, userName: 'John' }
116
+ * keysToCamel({ created_at: 1697452800000 }) // { createdAt: 1697452800000 }
117
+ */
118
+ export const keysToCamel = (obj) => {
119
+ if (!obj || !isPlainObject(obj))
120
+ return obj;
121
+ const result = {};
122
+ for (const [key, value] of Object.entries(obj)) {
123
+ const camelKey = camelCase(key);
124
+ result[camelKey] = value;
125
+ }
126
+ return result;
127
+ };
128
+ /**
129
+ * 对象字段名转下划线
130
+ * @param obj - 源对象
131
+ * @returns 字段名转为下划线格式的新对象
132
+ *
133
+ * @example
134
+ * keysToSnake({ userId: 123, userName: 'John' }) // { user_id: 123, user_name: 'John' }
135
+ * keysToSnake({ createdAt: 1697452800000 }) // { created_at: 1697452800000 }
136
+ */
137
+ export const keysToSnake = (obj) => {
138
+ if (!obj || !isPlainObject(obj))
139
+ return obj;
140
+ const result = {};
141
+ for (const [key, value] of Object.entries(obj)) {
142
+ const snakeKey = snakeCase(key);
143
+ result[snakeKey] = value;
144
+ }
145
+ return result;
146
+ };
147
+ /**
148
+ * 数组对象字段名批量转小驼峰
149
+ * @param arr - 源数组
150
+ * @returns 字段名转为小驼峰格式的新数组
151
+ *
152
+ * @example
153
+ * arrayKeysToCamel([
154
+ * { user_id: 1, user_name: 'John' },
155
+ * { user_id: 2, user_name: 'Jane' }
156
+ * ])
157
+ * // [{ userId: 1, userName: 'John' }, { userId: 2, userName: 'Jane' }]
158
+ */
159
+ export const arrayKeysToCamel = (arr) => {
160
+ if (!arr || !Array.isArray(arr))
161
+ return arr;
162
+ return arr.map((item) => keysToCamel(item));
163
+ };
164
+ export function getByPath(obj, path) {
165
+ if (!path) {
166
+ return obj;
167
+ }
168
+ const parts = path.split(".");
169
+ let cur = obj;
170
+ for (const part of parts) {
171
+ if (cur === null || cur === undefined) {
172
+ return undefined;
173
+ }
174
+ if (typeof cur !== "object") {
175
+ return undefined;
176
+ }
177
+ cur = cur[part];
178
+ }
179
+ return cur;
180
+ }
181
+ export function setByPath(target, path, value) {
182
+ const parts = path.split(".");
183
+ // 避免无效 path(如 a..b)导致部分写入
184
+ for (const part of parts) {
185
+ if (!part) {
186
+ return;
187
+ }
188
+ }
189
+ let cur = target;
190
+ for (let i = 0; i < parts.length; i++) {
191
+ const key = parts[i];
192
+ const isLast = i === parts.length - 1;
193
+ if (isLast) {
194
+ cur[key] = value;
195
+ return;
196
+ }
197
+ const nextVal = cur[key];
198
+ if (!isPlainObject(nextVal)) {
199
+ cur[key] = {};
200
+ }
201
+ cur = cur[key];
202
+ }
203
+ }
204
+ /**
205
+ * 返回一个移除指定 key 的浅拷贝。
206
+ * - 仅处理 plain object;其他类型返回空对象,避免日志场景抛错。
207
+ */
208
+ export function omit(obj, keys) {
209
+ if (!isPlainObject(obj)) {
210
+ return {};
211
+ }
212
+ const keySet = new Set(Array.isArray(keys) ? keys : []);
213
+ const out = {};
214
+ for (const [k, v] of Object.entries(obj)) {
215
+ if (keySet.has(k)) {
216
+ continue;
217
+ }
218
+ out[k] = v;
219
+ }
220
+ return out;
221
+ }
222
+ /**
223
+ * 挑选指定字段
224
+ */
225
+ export const pickFields = (obj, keys) => {
226
+ if (!obj || (!isPlainObject(obj) && !Array.isArray(obj))) {
227
+ return {};
228
+ }
229
+ const result = {};
230
+ for (const key of keys) {
231
+ if (key in obj) {
232
+ result[key] = obj[key];
233
+ }
234
+ }
235
+ return result;
236
+ };
237
+ export function keyBy(items, getKey) {
238
+ const out = {};
239
+ if (!Array.isArray(items) || typeof getKey !== "function") {
240
+ return out;
241
+ }
242
+ for (const item of items) {
243
+ const key = getKey(item);
244
+ if (typeof key !== "string" || key === "") {
245
+ continue;
246
+ }
247
+ out[key] = item;
248
+ }
249
+ return out;
250
+ }
251
+ /**
252
+ * 生成短 ID
253
+ * 由时间戳(base36)+ 随机字符组成,约 13 位
254
+ * - 前 8 位:时间戳(可排序)
255
+ * - 后 5 位:随机字符(防冲突)
256
+ * @returns 短 ID 字符串
257
+ * @example
258
+ * genShortId() // "lxyz1a2b3c4"
259
+ */
260
+ export function genShortId() {
261
+ return Date.now().toString(36) + Math.random().toString(36).slice(2, 7);
262
+ }
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "befly",
3
- "version": "3.10.19",
4
- "gitHead": "0914e9a6efb3f41136034f14d5f9cda4d5e7c3d0",
3
+ "version": "3.11.1",
4
+ "gitHead": "b566edda48fcd5e8e7c66d001fefedc68520036a",
5
5
  "private": false,
6
6
  "description": "Befly - 为 Bun 专属打造的 TypeScript API 接口框架核心引擎",
7
7
  "keywords": [
@@ -25,12 +25,22 @@
25
25
  "dist/"
26
26
  ],
27
27
  "type": "module",
28
- "main": "./dist/main.js",
29
- "types": "./dist/main.d.ts",
28
+ "main": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
30
  "exports": {
31
31
  ".": {
32
- "types": "./dist/main.d.ts",
33
- "default": "./dist/main.js"
32
+ "types": "./dist/index.d.ts",
33
+ "default": "./dist/index.js"
34
+ },
35
+ "./all": {
36
+ "types": "./dist/index.d.ts",
37
+ "import": "./dist/befly.js",
38
+ "default": "./dist/befly.js"
39
+ },
40
+ "./min": {
41
+ "types": "./dist/index.d.ts",
42
+ "import": "./dist/befly.min.js",
43
+ "default": "./dist/befly.min.js"
34
44
  },
35
45
  "./types/*": {
36
46
  "types": "./dist/types/*.d.ts"
@@ -43,20 +53,16 @@
43
53
  "scripts": {
44
54
  "clean": "rimraf dist",
45
55
  "test": "bun test",
46
- "build": "bunx tsgo -p tsconfig.build.json",
56
+ "bundle": "bun build ./index.ts --outfile ./dist/befly.js --target bun --format esm --packages bundle",
57
+ "bundle:min": "bun build ./index.ts --outdir ./dist --entry-naming befly.min.js --target bun --format esm --packages bundle --minify",
58
+ "build": "rimraf dist && bunx tsgo -p tsconfig.build.json && bun run bundle && bun run bundle:min",
47
59
  "prepack": "bun run build && bun run ./scripts/ensureDist.ts",
48
60
  "typecheck": "bunx tsgo -p tsconfig.json --noEmit"
49
61
  },
50
62
  "dependencies": {
51
- "befly-shared": "^1.3.11",
52
- "chalk": "^5.6.2",
53
- "es-toolkit": "^1.43.0",
54
63
  "fast-jwt": "^6.1.0",
55
64
  "fast-xml-parser": "^5.3.3",
56
- "merge-anything": "^6.0.6",
57
- "pathe": "^2.0.3",
58
- "pino": "^10.1.0",
59
- "pino-roll": "^4.0.0"
65
+ "pathe": "^2.0.3"
60
66
  },
61
67
  "engines": {
62
68
  "bun": ">=1.3.0"
@@ -1,13 +0,0 @@
1
- /**
2
- * 数组对象字段名批量转小驼峰
3
- * @param arr - 源数组
4
- * @returns 字段名转为小驼峰格式的新数组
5
- *
6
- * @example
7
- * arrayKeysToCamel([
8
- * { user_id: 1, user_name: 'John' },
9
- * { user_id: 2, user_name: 'Jane' }
10
- * ])
11
- * // [{ userId: 1, userName: 'John' }, { userId: 2, userName: 'Jane' }]
12
- */
13
- export declare const arrayKeysToCamel: <T = any>(arr: Record<string, any>[]) => T[];
@@ -1,18 +0,0 @@
1
- import { keysToCamel } from "./keysToCamel.js";
2
- /**
3
- * 数组对象字段名批量转小驼峰
4
- * @param arr - 源数组
5
- * @returns 字段名转为小驼峰格式的新数组
6
- *
7
- * @example
8
- * arrayKeysToCamel([
9
- * { user_id: 1, user_name: 'John' },
10
- * { user_id: 2, user_name: 'Jane' }
11
- * ])
12
- * // [{ userId: 1, userName: 'John' }, { userId: 2, userName: 'Jane' }]
13
- */
14
- export const arrayKeysToCamel = (arr) => {
15
- if (!arr || !Array.isArray(arr))
16
- return arr;
17
- return arr.map((item) => keysToCamel(item));
18
- };
@@ -1 +0,0 @@
1
- export {};
@@ -1 +0,0 @@
1
- export {};
@@ -1,10 +0,0 @@
1
- /**
2
- * 生成短 ID
3
- * 由时间戳(base36)+ 随机字符组成,约 13 位
4
- * - 前 8 位:时间戳(可排序)
5
- * - 后 5 位:随机字符(防冲突)
6
- * @returns 短 ID 字符串
7
- * @example
8
- * genShortId() // "lxyz1a2b3c4"
9
- */
10
- export declare function genShortId(): string;
@@ -1,12 +0,0 @@
1
- /**
2
- * 生成短 ID
3
- * 由时间戳(base36)+ 随机字符组成,约 13 位
4
- * - 前 8 位:时间戳(可排序)
5
- * - 后 5 位:随机字符(防冲突)
6
- * @returns 短 ID 字符串
7
- * @example
8
- * genShortId() // "lxyz1a2b3c4"
9
- */
10
- export function genShortId() {
11
- return Date.now().toString(36) + Math.random().toString(36).slice(2, 7);
12
- }
@@ -1,10 +0,0 @@
1
- /**
2
- * 对象字段名转小驼峰
3
- * @param obj - 源对象
4
- * @returns 字段名转为小驼峰格式的新对象
5
- *
6
- * @example
7
- * keysToCamel({ user_id: 123, user_name: 'John' }) // { userId: 123, userName: 'John' }
8
- * keysToCamel({ created_at: 1697452800000 }) // { createdAt: 1697452800000 }
9
- */
10
- export declare const keysToCamel: <T = any>(obj: Record<string, any>) => T;
@@ -1,21 +0,0 @@
1
- import { isPlainObject } from "es-toolkit/compat";
2
- import { camelCase } from "es-toolkit/string";
3
- /**
4
- * 对象字段名转小驼峰
5
- * @param obj - 源对象
6
- * @returns 字段名转为小驼峰格式的新对象
7
- *
8
- * @example
9
- * keysToCamel({ user_id: 123, user_name: 'John' }) // { userId: 123, userName: 'John' }
10
- * keysToCamel({ created_at: 1697452800000 }) // { createdAt: 1697452800000 }
11
- */
12
- export const keysToCamel = (obj) => {
13
- if (!obj || !isPlainObject(obj))
14
- return obj;
15
- const result = {};
16
- for (const [key, value] of Object.entries(obj)) {
17
- const camelKey = camelCase(key);
18
- result[camelKey] = value;
19
- }
20
- return result;
21
- };
@@ -1,10 +0,0 @@
1
- /**
2
- * 对象字段名转下划线
3
- * @param obj - 源对象
4
- * @returns 字段名转为下划线格式的新对象
5
- *
6
- * @example
7
- * keysToSnake({ userId: 123, userName: 'John' }) // { user_id: 123, user_name: 'John' }
8
- * keysToSnake({ createdAt: 1697452800000 }) // { created_at: 1697452800000 }
9
- */
10
- export declare const keysToSnake: <T = any>(obj: Record<string, any>) => T;
@@ -1,21 +0,0 @@
1
- import { isPlainObject } from "es-toolkit/compat";
2
- import { snakeCase } from "es-toolkit/string";
3
- /**
4
- * 对象字段名转下划线
5
- * @param obj - 源对象
6
- * @returns 字段名转为下划线格式的新对象
7
- *
8
- * @example
9
- * keysToSnake({ userId: 123, userName: 'John' }) // { user_id: 123, user_name: 'John' }
10
- * keysToSnake({ createdAt: 1697452800000 }) // { created_at: 1697452800000 }
11
- */
12
- export const keysToSnake = (obj) => {
13
- if (!obj || !isPlainObject(obj))
14
- return obj;
15
- const result = {};
16
- for (const [key, value] of Object.entries(obj)) {
17
- const snakeKey = snakeCase(key);
18
- result[snakeKey] = value;
19
- }
20
- return result;
21
- };
@@ -1,4 +0,0 @@
1
- /**
2
- * 挑选指定字段
3
- */
4
- export declare const pickFields: <T extends Record<string, any>>(obj: T, keys: string[]) => Partial<T>;
@@ -1,16 +0,0 @@
1
- import { isPlainObject } from "es-toolkit/compat";
2
- /**
3
- * 挑选指定字段
4
- */
5
- export const pickFields = (obj, keys) => {
6
- if (!obj || (!isPlainObject(obj) && !Array.isArray(obj))) {
7
- return {};
8
- }
9
- const result = {};
10
- for (const key of keys) {
11
- if (key in obj) {
12
- result[key] = obj[key];
13
- }
14
- }
15
- return result;
16
- };
@@ -1,4 +0,0 @@
1
- /**
2
- * 处理字段定义:将 @ 符号引用替换为实际字段定义
3
- */
4
- export declare function processFields(fields: Record<string, any>, apiName: string, routePath: string): Record<string, any>;
@@ -1,145 +0,0 @@
1
- /**
2
- * 内置正则表达式别名
3
- * 用于表单验证和数据校验
4
- * 命名规范:小驼峰格式
5
- */
6
- export declare const RegexAliases: {
7
- /** 正整数(不含0) */
8
- readonly number: "^\\d+$";
9
- /** 整数(含负数) */
10
- readonly integer: "^-?\\d+$";
11
- /** 浮点数 */
12
- readonly float: "^-?\\d+(\\.\\d+)?$";
13
- /** 正整数(不含0) */
14
- readonly positive: "^[1-9]\\d*$";
15
- /** 负整数 */
16
- readonly negative: "^-\\d+$";
17
- /** 零 */
18
- readonly zero: "^0$";
19
- /** 纯字母 */
20
- readonly word: "^[a-zA-Z]+$";
21
- /** 字母和数字 */
22
- readonly alphanumeric: "^[a-zA-Z0-9]+$";
23
- /** 字母、数字和下划线 */
24
- readonly alphanumeric_: "^[a-zA-Z0-9_]+$";
25
- /** 字母、数字、下划线和短横线 */
26
- readonly alphanumericDash_: "^[a-zA-Z0-9_-]+$";
27
- /** 小写字母 */
28
- readonly lowercase: "^[a-z]+$";
29
- /** 大写字母 */
30
- readonly uppercase: "^[A-Z]+$";
31
- /** 纯中文 */
32
- readonly chinese: "^[\\u4e00-\\u9fa5]+$";
33
- /** 中文和字母 */
34
- readonly chineseWord: "^[\\u4e00-\\u9fa5a-zA-Z]+$";
35
- /** 邮箱地址 */
36
- readonly email: "^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,}$";
37
- /** 中国大陆手机号 */
38
- readonly phone: "^1[3-9]\\d{9}$";
39
- /** 固定电话(区号-号码) */
40
- readonly telephone: "^0\\d{2,3}-?\\d{7,8}$";
41
- /** URL 地址 */
42
- readonly url: "^https?://";
43
- /** IPv4 地址 */
44
- readonly ip: "^((25[0-5]|2[0-4]\\d|[01]?\\d\\d?)\\.){3}(25[0-5]|2[0-4]\\d|[01]?\\d\\d?)$";
45
- /** IPv6 地址 */
46
- readonly ipv6: "^([0-9a-fA-F]{1,4}:){7}[0-9a-fA-F]{1,4}$";
47
- /** 域名 */
48
- readonly domain: "^(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?\\.)+[a-zA-Z]{2,}$";
49
- /** UUID */
50
- readonly uuid: "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$";
51
- /** 十六进制字符串 */
52
- readonly hex: "^[0-9a-fA-F]+$";
53
- /** Base64 编码 */
54
- readonly base64: "^[A-Za-z0-9+/=]+$";
55
- /** MD5 哈希 */
56
- readonly md5: "^[a-f0-9]{32}$";
57
- /** SHA1 哈希 */
58
- readonly sha1: "^[a-f0-9]{40}$";
59
- /** SHA256 哈希 */
60
- readonly sha256: "^[a-f0-9]{64}$";
61
- /** 日期 YYYY-MM-DD */
62
- readonly date: "^\\d{4}-\\d{2}-\\d{2}$";
63
- /** 时间 HH:MM:SS */
64
- readonly time: "^\\d{2}:\\d{2}:\\d{2}$";
65
- /** ISO 日期时间 */
66
- readonly datetime: "^\\d{4}-\\d{2}-\\d{2}T\\d{2}:\\d{2}:\\d{2}";
67
- /** 年份 */
68
- readonly year: "^\\d{4}$";
69
- /** 月份 01-12 */
70
- readonly month: "^(0[1-9]|1[0-2])$";
71
- /** 日期 01-31 */
72
- readonly day: "^(0[1-9]|[12]\\d|3[01])$";
73
- /** 变量名 */
74
- readonly variable: "^[a-zA-Z_][a-zA-Z0-9_]*$";
75
- /** 常量名(全大写) */
76
- readonly constant: "^[A-Z][A-Z0-9_]*$";
77
- /** 包名(小写+连字符) */
78
- readonly package: "^[a-z][a-z0-9-]*$";
79
- /** 中国身份证号(18位) */
80
- readonly idCard: "^\\d{17}[\\dXx]$";
81
- /** 护照号 */
82
- readonly passport: "^[a-zA-Z0-9]{5,17}$";
83
- /** 银行卡号(16-19位数字) */
84
- readonly bankCard: "^\\d{16,19}$";
85
- /** 微信号(6-20位,字母开头,可包含字母、数字、下划线、减号) */
86
- readonly wechat: "^[a-zA-Z][a-zA-Z0-9_-]{5,19}$";
87
- /** QQ号(5-11位数字,首位非0) */
88
- readonly qq: "^[1-9]\\d{4,10}$";
89
- /** 支付宝账号(手机号或邮箱) */
90
- readonly alipay: "^(1[3-9]\\d{9}|[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\\.[a-zA-Z]{2,})$";
91
- /** 用户名(4-20位,字母开头,可包含字母、数字、下划线) */
92
- readonly username: "^[a-zA-Z][a-zA-Z0-9_]{3,19}$";
93
- /** 昵称(2-20位,支持中文、字母、数字) */
94
- readonly nickname: "^[\\u4e00-\\u9fa5a-zA-Z0-9]{2,20}$";
95
- /** 弱密码(至少6位) */
96
- readonly passwordWeak: "^.{6,}$";
97
- /** 中等密码(至少8位,包含字母和数字) */
98
- readonly passwordMedium: "^(?=.*[a-zA-Z])(?=.*\\d).{8,}$";
99
- /** 强密码(至少8位,包含大小写字母、数字和特殊字符) */
100
- readonly passwordStrong: "^(?=.*[a-z])(?=.*[A-Z])(?=.*\\d)(?=.*[!@#$%^&*]).{8,}$";
101
- /** 车牌号(新能源+普通) */
102
- readonly licensePlate: "^[京津沪渝冀豫云辽黑湘皖鲁新苏浙赣鄂桂甘晋蒙陕吉闽贵粤青藏川宁琼使领][A-Z][A-HJ-NP-Z0-9]{4,5}[A-HJ-NP-Z0-9挂学警港澳]$";
103
- /** 邮政编码 */
104
- readonly postalCode: "^\\d{6}$";
105
- /** 版本号(语义化版本) */
106
- readonly semver: "^\\d+\\.\\d+\\.\\d+(-[a-zA-Z0-9.]+)?(\\+[a-zA-Z0-9.]+)?$";
107
- /** 颜色值(十六进制) */
108
- readonly colorHex: "^#([0-9a-fA-F]{3}|[0-9a-fA-F]{6})$";
109
- /** 空字符串 */
110
- readonly empty: "^$";
111
- /** 非空 */
112
- readonly notempty: ".+";
113
- };
114
- /**
115
- * 正则别名类型
116
- */
117
- export type RegexAliasName = keyof typeof RegexAliases;
118
- /**
119
- * 获取正则表达式字符串
120
- * @param name 正则别名(以 @ 开头)或自定义正则字符串
121
- * @returns 正则表达式字符串
122
- */
123
- export declare function getRegex(name: string): string;
124
- /**
125
- * 获取编译后的正则表达式对象(带缓存)
126
- * @param pattern 正则别名或正则字符串
127
- * @param flags 正则标志(如 'i', 'g')
128
- * @returns 编译后的 RegExp 对象
129
- */
130
- export declare function getCompiledRegex(pattern: string, flags?: string): RegExp;
131
- /**
132
- * 验证值是否匹配正则(使用缓存)
133
- * @param value 要验证的值
134
- * @param pattern 正则别名或正则字符串
135
- * @returns 是否匹配
136
- */
137
- export declare function matchRegex(value: string, pattern: string): boolean;
138
- /**
139
- * 清除正则缓存
140
- */
141
- export declare function clearRegexCache(): void;
142
- /**
143
- * 获取缓存大小
144
- */
145
- export declare function getRegexCacheSize(): number;