befly 3.10.18 → 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.
- package/README.md +83 -307
- package/dist/befly.config.d.ts +7 -0
- package/{befly.config.ts → dist/befly.config.js} +11 -36
- package/dist/befly.js +15621 -0
- package/dist/befly.min.js +21 -0
- package/dist/checks/checkApi.d.ts +1 -0
- package/{checks/checkApi.ts → dist/checks/checkApi.js} +12 -30
- package/dist/checks/checkHook.d.ts +1 -0
- package/dist/checks/checkHook.js +86 -0
- package/dist/checks/checkMenu.d.ts +7 -0
- package/{checks/checkMenu.ts → dist/checks/checkMenu.js} +18 -53
- package/dist/checks/checkPlugin.d.ts +1 -0
- package/dist/checks/checkPlugin.js +86 -0
- package/dist/checks/checkTable.d.ts +6 -0
- package/{checks/checkTable.ts → dist/checks/checkTable.js} +17 -41
- package/dist/configs/presetFields.d.ts +4 -0
- package/{configs/presetFields.ts → dist/configs/presetFields.js} +1 -1
- package/dist/configs/presetRegexp.d.ts +145 -0
- package/{utils/regex.ts → dist/configs/presetRegexp.js} +8 -31
- package/dist/hooks/auth.d.ts +7 -0
- package/{hooks/auth.ts → dist/hooks/auth.js} +8 -10
- package/dist/hooks/cors.d.ts +11 -0
- package/{hooks/cors.ts → dist/hooks/cors.js} +5 -13
- package/dist/hooks/parser.d.ts +14 -0
- package/{hooks/parser.ts → dist/hooks/parser.js} +31 -45
- package/dist/hooks/permission.d.ts +14 -0
- package/{hooks/permission.ts → dist/hooks/permission.js} +16 -25
- package/dist/hooks/validator.d.ts +11 -0
- package/{hooks/validator.ts → dist/hooks/validator.js} +9 -14
- package/dist/index.d.ts +26 -0
- package/{main.ts → dist/index.js} +61 -100
- package/dist/lib/asyncContext.d.ts +21 -0
- package/dist/lib/asyncContext.js +27 -0
- package/dist/lib/cacheHelper.d.ts +95 -0
- package/{lib/cacheHelper.ts → dist/lib/cacheHelper.js} +45 -105
- package/dist/lib/cacheKeys.d.ts +23 -0
- package/{lib/cacheKeys.ts → dist/lib/cacheKeys.js} +5 -10
- package/dist/lib/cipher.d.ts +153 -0
- package/{lib/cipher.ts → dist/lib/cipher.js} +23 -44
- package/dist/lib/connect.d.ts +91 -0
- package/{lib/connect.ts → dist/lib/connect.js} +47 -88
- package/dist/lib/dbDialect.d.ts +87 -0
- package/{lib/dbDialect.ts → dist/lib/dbDialect.js} +32 -112
- package/dist/lib/dbHelper.d.ts +204 -0
- package/{lib/dbHelper.ts → dist/lib/dbHelper.js} +82 -241
- package/dist/lib/dbUtils.d.ts +68 -0
- package/{lib/dbUtils.ts → dist/lib/dbUtils.js} +51 -126
- package/dist/lib/jwt.d.ts +13 -0
- package/{lib/jwt.ts → dist/lib/jwt.js} +11 -32
- package/dist/lib/logger.d.ts +42 -0
- package/dist/lib/logger.js +1144 -0
- package/dist/lib/redisHelper.d.ts +185 -0
- package/{lib/redisHelper.ts → dist/lib/redisHelper.js} +97 -141
- package/dist/lib/sqlBuilder.d.ts +160 -0
- package/{lib/sqlBuilder.ts → dist/lib/sqlBuilder.js} +132 -278
- package/dist/lib/sqlCheck.d.ts +23 -0
- package/{lib/sqlCheck.ts → dist/lib/sqlCheck.js} +24 -41
- package/dist/lib/validator.d.ts +45 -0
- package/{lib/validator.ts → dist/lib/validator.js} +44 -61
- package/dist/loader/loadApis.d.ts +12 -0
- package/{loader/loadApis.ts → dist/loader/loadApis.js} +10 -20
- package/dist/loader/loadHooks.d.ts +7 -0
- package/dist/loader/loadHooks.js +35 -0
- package/dist/loader/loadPlugins.d.ts +8 -0
- package/{loader/loadPlugins.ts → dist/loader/loadPlugins.js} +14 -26
- package/dist/paths.d.ts +93 -0
- package/{paths.ts → dist/paths.js} +6 -19
- package/dist/plugins/cache.d.ts +16 -0
- package/{plugins/cache.ts → dist/plugins/cache.js} +7 -12
- package/dist/plugins/cipher.d.ts +12 -0
- package/{plugins/cipher.ts → dist/plugins/cipher.js} +4 -6
- package/dist/plugins/config.d.ts +12 -0
- package/dist/plugins/config.js +8 -0
- package/dist/plugins/db.d.ts +16 -0
- package/{plugins/db.ts → dist/plugins/db.js} +11 -17
- package/dist/plugins/jwt.d.ts +12 -0
- package/dist/plugins/jwt.js +12 -0
- package/dist/plugins/logger.d.ts +32 -0
- package/{plugins/logger.ts → dist/plugins/logger.js} +5 -8
- package/dist/plugins/redis.d.ts +16 -0
- package/{plugins/redis.ts → dist/plugins/redis.js} +9 -12
- package/dist/plugins/tool.d.ts +81 -0
- package/{plugins/tool.ts → dist/plugins/tool.js} +9 -30
- package/dist/router/api.d.ts +14 -0
- package/dist/router/api.js +107 -0
- package/dist/router/static.d.ts +9 -0
- package/{router/static.ts → dist/router/static.js} +20 -34
- package/dist/scripts/ensureDist.d.ts +1 -0
- package/dist/scripts/ensureDist.js +296 -0
- package/dist/sync/syncApi.d.ts +3 -0
- package/{sync/syncApi.ts → dist/sync/syncApi.js} +35 -55
- package/dist/sync/syncCache.d.ts +2 -0
- package/{sync/syncCache.ts → dist/sync/syncCache.js} +1 -6
- package/dist/sync/syncDev.d.ts +6 -0
- package/{sync/syncDev.ts → dist/sync/syncDev.js} +29 -62
- package/dist/sync/syncMenu.d.ts +14 -0
- package/{sync/syncMenu.ts → dist/sync/syncMenu.js} +65 -125
- package/dist/sync/syncTable.d.ts +151 -0
- package/{sync/syncTable.ts → dist/sync/syncTable.js} +172 -379
- package/{types → dist/types}/api.d.ts +12 -51
- package/dist/types/api.js +4 -0
- package/{types → dist/types}/befly.d.ts +32 -227
- package/dist/types/befly.js +4 -0
- package/{types → dist/types}/cache.d.ts +7 -15
- package/dist/types/cache.js +4 -0
- package/dist/types/cipher.d.ts +27 -0
- package/dist/types/cipher.js +7 -0
- package/{types → dist/types}/common.d.ts +8 -33
- package/dist/types/common.js +5 -0
- package/{types → dist/types}/context.d.ts +3 -5
- package/dist/types/context.js +4 -0
- package/{types → dist/types}/crypto.d.ts +0 -3
- package/dist/types/crypto.js +4 -0
- package/dist/types/database.d.ts +138 -0
- package/dist/types/database.js +4 -0
- package/dist/types/hook.d.ts +17 -0
- package/dist/types/hook.js +6 -0
- package/dist/types/jwt.d.ts +75 -0
- package/dist/types/jwt.js +4 -0
- package/dist/types/logger.d.ts +59 -0
- package/dist/types/logger.js +6 -0
- package/dist/types/plugin.d.ts +16 -0
- package/dist/types/plugin.js +6 -0
- package/dist/types/redis.d.ts +71 -0
- package/dist/types/redis.js +4 -0
- package/{types/roleApisCache.ts → dist/types/roleApisCache.d.ts} +0 -2
- package/dist/types/roleApisCache.js +8 -0
- package/dist/types/sync.d.ts +92 -0
- package/dist/types/sync.js +4 -0
- package/dist/types/table.d.ts +34 -0
- package/dist/types/table.js +4 -0
- package/dist/types/validate.d.ts +67 -0
- package/dist/types/validate.js +4 -0
- package/dist/utils/calcPerfTime.d.ts +4 -0
- package/{utils/calcPerfTime.ts → dist/utils/calcPerfTime.js} +3 -3
- package/dist/utils/convertBigIntFields.d.ts +11 -0
- package/{utils/convertBigIntFields.ts → dist/utils/convertBigIntFields.js} +5 -9
- package/dist/utils/cors.d.ts +8 -0
- package/{utils/cors.ts → dist/utils/cors.js} +1 -3
- package/dist/utils/disableMenusGlob.d.ts +13 -0
- package/{utils/disableMenusGlob.ts → dist/utils/disableMenusGlob.js} +9 -29
- package/dist/utils/fieldClear.d.ts +11 -0
- package/{utils/fieldClear.ts → dist/utils/fieldClear.js} +15 -33
- package/dist/utils/getClientIp.d.ts +6 -0
- package/{utils/getClientIp.ts → dist/utils/getClientIp.js} +1 -7
- package/dist/utils/importDefault.d.ts +1 -0
- package/dist/utils/importDefault.js +29 -0
- package/dist/utils/isDirentDirectory.d.ts +2 -0
- package/{utils/isDirentDirectory.ts → dist/utils/isDirentDirectory.js} +3 -8
- package/dist/utils/loadMenuConfigs.d.ts +29 -0
- package/{utils/loadMenuConfigs.ts → dist/utils/loadMenuConfigs.js} +66 -52
- package/dist/utils/mergeAndConcat.d.ts +7 -0
- package/dist/utils/mergeAndConcat.js +72 -0
- package/dist/utils/processAtSymbol.d.ts +4 -0
- package/{utils/processFields.ts → dist/utils/processAtSymbol.js} +5 -9
- package/dist/utils/processInfo.d.ts +24 -0
- package/{utils/process.ts → dist/utils/processInfo.js} +2 -18
- package/dist/utils/response.d.ts +20 -0
- package/{utils/response.ts → dist/utils/response.js} +28 -49
- package/dist/utils/scanAddons.d.ts +17 -0
- package/{utils/scanAddons.ts → dist/utils/scanAddons.js} +7 -41
- package/dist/utils/scanConfig.d.ts +26 -0
- package/{utils/scanConfig.ts → dist/utils/scanConfig.js} +28 -66
- package/dist/utils/scanCoreBuiltins.d.ts +3 -0
- package/dist/utils/scanCoreBuiltins.js +65 -0
- package/dist/utils/scanFiles.d.ts +30 -0
- package/{utils/scanFiles.ts → dist/utils/scanFiles.js} +44 -71
- package/dist/utils/scanSources.d.ts +10 -0
- package/dist/utils/scanSources.js +46 -0
- package/dist/utils/sortModules.d.ts +28 -0
- package/{utils/sortModules.ts → dist/utils/sortModules.js} +26 -66
- package/dist/utils/util.d.ts +84 -0
- package/dist/utils/util.js +262 -0
- package/package.json +26 -34
- package/.gitignore +0 -0
- package/bunfig.toml +0 -3
- package/checks/checkHook.ts +0 -48
- package/checks/checkPlugin.ts +0 -48
- package/configs/presetRegexp.ts +0 -225
- package/docs/README.md +0 -98
- package/docs/api/api.md +0 -1921
- package/docs/guide/examples.md +0 -926
- package/docs/guide/quickstart.md +0 -354
- package/docs/hooks/auth.md +0 -38
- package/docs/hooks/cors.md +0 -28
- package/docs/hooks/hook.md +0 -838
- package/docs/hooks/parser.md +0 -19
- package/docs/hooks/rateLimit.md +0 -47
- package/docs/infra/redis.md +0 -628
- package/docs/plugins/cipher.md +0 -61
- package/docs/plugins/database.md +0 -189
- package/docs/plugins/plugin.md +0 -986
- package/docs/reference/addon.md +0 -510
- package/docs/reference/config.md +0 -573
- package/docs/reference/logger.md +0 -495
- package/docs/reference/sync.md +0 -478
- package/docs/reference/table.md +0 -763
- package/docs/reference/validator.md +0 -620
- package/lib/asyncContext.ts +0 -43
- package/lib/logger.ts +0 -811
- package/loader/loadHooks.ts +0 -51
- package/plugins/config.ts +0 -13
- package/plugins/jwt.ts +0 -15
- package/router/api.ts +0 -130
- package/tsconfig.json +0 -8
- package/types/database.d.ts +0 -541
- package/types/hook.d.ts +0 -25
- package/types/jwt.d.ts +0 -118
- package/types/logger.d.ts +0 -65
- package/types/plugin.d.ts +0 -19
- package/types/redis.d.ts +0 -83
- package/types/sync.d.ts +0 -398
- package/types/table.d.ts +0 -216
- package/types/validate.d.ts +0 -69
- package/utils/arrayKeysToCamel.ts +0 -18
- package/utils/configTypes.ts +0 -3
- package/utils/genShortId.ts +0 -12
- package/utils/importDefault.ts +0 -21
- package/utils/keysToCamel.ts +0 -22
- package/utils/keysToSnake.ts +0 -22
- package/utils/pickFields.ts +0 -19
- package/utils/scanSources.ts +0 -64
- package/utils/sqlLog.ts +0 -37
package/types/table.d.ts
DELETED
|
@@ -1,216 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 表类型定义 - 用于增强 DbHelper 泛型推断
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 保留字段(系统自动管理)
|
|
7
|
-
*/
|
|
8
|
-
export type ReservedFields = "id" | "created_at" | "updated_at" | "deleted_at" | "state";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 系统字段(所有表都有的字段)
|
|
12
|
-
*/
|
|
13
|
-
export interface SystemFields {
|
|
14
|
-
/** 主键 ID(雪花 ID) */
|
|
15
|
-
id: number;
|
|
16
|
-
/** 状态:0=已删除, 1=正常, 2=禁用 */
|
|
17
|
-
state: number;
|
|
18
|
-
/** 创建时间(毫秒时间戳) */
|
|
19
|
-
createdAt: number;
|
|
20
|
-
/** 更新时间(毫秒时间戳) */
|
|
21
|
-
updatedAt: number;
|
|
22
|
-
/** 删除时间(毫秒时间戳,软删除时设置) */
|
|
23
|
-
deletedAt: number | null;
|
|
24
|
-
}
|
|
25
|
-
|
|
26
|
-
/**
|
|
27
|
-
* 基础表类型(包含系统字段)
|
|
28
|
-
*/
|
|
29
|
-
export type BaseTable<T extends Record<string, any>> = T & SystemFields;
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* 插入类型:排除系统自动生成的字段
|
|
33
|
-
*/
|
|
34
|
-
export type InsertType<T> = Omit<T, keyof SystemFields>;
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* 更新类型:所有字段可选,排除不可修改的系统字段
|
|
38
|
-
*/
|
|
39
|
-
export type UpdateType<T> = Partial<Omit<T, "id" | "createdAt" | "updatedAt" | "deletedAt">>;
|
|
40
|
-
|
|
41
|
-
/**
|
|
42
|
-
* 查询结果类型:完整的表记录
|
|
43
|
-
*/
|
|
44
|
-
export type SelectType<T> = T;
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* 排除保留字段
|
|
48
|
-
*/
|
|
49
|
-
export type ExcludeReserved<T> = Omit<T, ReservedFields>;
|
|
50
|
-
|
|
51
|
-
// ============================================
|
|
52
|
-
// 数据库表映射接口
|
|
53
|
-
// ============================================
|
|
54
|
-
|
|
55
|
-
/**
|
|
56
|
-
* 数据库表映射
|
|
57
|
-
* 用户可以在项目中扩展此接口来添加表类型
|
|
58
|
-
*
|
|
59
|
-
* @example
|
|
60
|
-
* ```typescript
|
|
61
|
-
* // 在项目的 types/index.d.ts 中扩展
|
|
62
|
-
* declare module 'befly/types/table' {
|
|
63
|
-
* interface DatabaseTables {
|
|
64
|
-
* user: BaseTable<{
|
|
65
|
-
* email: string;
|
|
66
|
-
* username: string;
|
|
67
|
-
* password: string;
|
|
68
|
-
* nickname: string | null;
|
|
69
|
-
* }>;
|
|
70
|
-
* article: BaseTable<{
|
|
71
|
-
* title: string;
|
|
72
|
-
* content: string;
|
|
73
|
-
* authorId: number;
|
|
74
|
-
* }>;
|
|
75
|
-
* }
|
|
76
|
-
* }
|
|
77
|
-
* ```
|
|
78
|
-
*/
|
|
79
|
-
export interface DatabaseTables {
|
|
80
|
-
// 用户通过模块扩展添加表类型
|
|
81
|
-
[tableName: string]: BaseTable<Record<string, any>>;
|
|
82
|
-
}
|
|
83
|
-
|
|
84
|
-
/**
|
|
85
|
-
* 表名类型(从 DatabaseTables 提取所有键)
|
|
86
|
-
*/
|
|
87
|
-
export type TableName = keyof DatabaseTables;
|
|
88
|
-
|
|
89
|
-
/**
|
|
90
|
-
* 根据表名获取表类型
|
|
91
|
-
*/
|
|
92
|
-
export type TableType<K extends TableName> = DatabaseTables[K];
|
|
93
|
-
|
|
94
|
-
/**
|
|
95
|
-
* 根据表名获取插入类型
|
|
96
|
-
*/
|
|
97
|
-
export type TableInsertType<K extends TableName> = InsertType<DatabaseTables[K]>;
|
|
98
|
-
|
|
99
|
-
/**
|
|
100
|
-
* 根据表名获取更新类型
|
|
101
|
-
*/
|
|
102
|
-
export type TableUpdateType<K extends TableName> = UpdateType<DatabaseTables[K]>;
|
|
103
|
-
|
|
104
|
-
// ============================================
|
|
105
|
-
// WHERE 条件类型增强
|
|
106
|
-
// ============================================
|
|
107
|
-
|
|
108
|
-
/**
|
|
109
|
-
* 比较操作符(值类型与字段类型相同)
|
|
110
|
-
*/
|
|
111
|
-
type CompareOperators = "gt" | "gte" | "lt" | "lte" | "ne" | "not";
|
|
112
|
-
|
|
113
|
-
/**
|
|
114
|
-
* 数组操作符(值类型为字段类型的数组)
|
|
115
|
-
*/
|
|
116
|
-
type ArrayOperators = "in" | "nin" | "notIn";
|
|
117
|
-
|
|
118
|
-
/**
|
|
119
|
-
* 字符串操作符(值类型为字符串)
|
|
120
|
-
*/
|
|
121
|
-
type StringOperators = "like" | "notLike";
|
|
122
|
-
|
|
123
|
-
/**
|
|
124
|
-
* 范围操作符(值类型为 [min, max] 元组)
|
|
125
|
-
*/
|
|
126
|
-
type RangeOperators = "between" | "notBetween";
|
|
127
|
-
|
|
128
|
-
/**
|
|
129
|
-
* 空值操作符(值类型为 boolean)
|
|
130
|
-
*/
|
|
131
|
-
type NullOperators = "null" | "notNull";
|
|
132
|
-
|
|
133
|
-
/**
|
|
134
|
-
* 所有操作符联合类型
|
|
135
|
-
*/
|
|
136
|
-
export type FieldOperator = `$${CompareOperators}` | `$${ArrayOperators}` | `$${StringOperators}` | `$${RangeOperators}` | `$${NullOperators}`;
|
|
137
|
-
|
|
138
|
-
/**
|
|
139
|
-
* 比较操作符条件(值类型与字段类型相同)
|
|
140
|
-
* @example { userId$gt: 10, age$lte: 65 }
|
|
141
|
-
*/
|
|
142
|
-
type CompareConditions<T> = {
|
|
143
|
-
[K in keyof T as `${K & string}$${CompareOperators}`]?: T[K];
|
|
144
|
-
};
|
|
145
|
-
|
|
146
|
-
/**
|
|
147
|
-
* 数组操作符条件(值类型为字段类型的数组)
|
|
148
|
-
* @example { status$in: [1, 2, 3], roleId$nin: [100, 200] }
|
|
149
|
-
*/
|
|
150
|
-
type ArrayConditions<T> = {
|
|
151
|
-
[K in keyof T as `${K & string}$${ArrayOperators}`]?: T[K][];
|
|
152
|
-
};
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* 字符串操作符条件(值类型为字符串)
|
|
156
|
-
* @example { name$like: '%test%', email$notLike: '%spam%' }
|
|
157
|
-
*/
|
|
158
|
-
type StringConditions<T> = {
|
|
159
|
-
[K in keyof T as `${K & string}$${StringOperators}`]?: string;
|
|
160
|
-
};
|
|
161
|
-
|
|
162
|
-
/**
|
|
163
|
-
* 范围操作符条件(值类型为 [min, max] 元组)
|
|
164
|
-
* @example { age$between: [18, 65], createdAt$notBetween: [start, end] }
|
|
165
|
-
*/
|
|
166
|
-
type RangeConditions<T> = {
|
|
167
|
-
[K in keyof T as `${K & string}$${RangeOperators}`]?: [T[K], T[K]];
|
|
168
|
-
};
|
|
169
|
-
|
|
170
|
-
/**
|
|
171
|
-
* 空值操作符条件(值类型为 true)
|
|
172
|
-
* @example { deletedAt$null: true, avatar$notNull: true }
|
|
173
|
-
*/
|
|
174
|
-
type NullConditions<T> = {
|
|
175
|
-
[K in keyof T as `${K & string}$${NullOperators}`]?: true;
|
|
176
|
-
};
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* 类型安全的 WHERE 条件
|
|
180
|
-
*
|
|
181
|
-
* 支持的操作符:
|
|
182
|
-
* - 比较:$gt, $gte, $lt, $lte, $ne, $not(值类型与字段相同)
|
|
183
|
-
* - 数组:$in, $nin, $notIn(值类型为数组)
|
|
184
|
-
* - 字符串:$like, $notLike(值类型为字符串)
|
|
185
|
-
* - 范围:$between, $notBetween(值类型为 [min, max] 元组)
|
|
186
|
-
* - 空值:$null, $notNull(值类型为 true)
|
|
187
|
-
* - 逻辑:$or, $and(递归条件数组)
|
|
188
|
-
*
|
|
189
|
-
* @example
|
|
190
|
-
* ```typescript
|
|
191
|
-
* const where: TypedWhereConditions<UserTable> = {
|
|
192
|
-
* state: 1, // 精确匹配
|
|
193
|
-
* age$gte: 18, // 大于等于
|
|
194
|
-
* roleId$in: [1, 2, 3], // IN 数组
|
|
195
|
-
* name$like: '%test%', // LIKE 匹配
|
|
196
|
-
* createdAt$between: [start, end], // BETWEEN 范围
|
|
197
|
-
* deletedAt$null: true, // IS NULL
|
|
198
|
-
* $or: [ // OR 条件
|
|
199
|
-
* { email$like: '%@gmail.com' },
|
|
200
|
-
* { email$like: '%@qq.com' }
|
|
201
|
-
* ]
|
|
202
|
-
* };
|
|
203
|
-
* ```
|
|
204
|
-
*/
|
|
205
|
-
export type TypedWhereConditions<T> = Partial<T> & // 精确匹配
|
|
206
|
-
CompareConditions<T> & // 比较操作符
|
|
207
|
-
ArrayConditions<T> & // 数组操作符
|
|
208
|
-
StringConditions<T> & // 字符串操作符
|
|
209
|
-
RangeConditions<T> & // 范围操作符
|
|
210
|
-
NullConditions<T> & {
|
|
211
|
-
// 空值操作符
|
|
212
|
-
/** OR 条件组 */
|
|
213
|
-
$or?: TypedWhereConditions<T>[];
|
|
214
|
-
/** AND 条件组 */
|
|
215
|
-
$and?: TypedWhereConditions<T>[];
|
|
216
|
-
};
|
package/types/validate.d.ts
DELETED
|
@@ -1,69 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 验证相关类型定义
|
|
3
|
-
*/
|
|
4
|
-
|
|
5
|
-
/**
|
|
6
|
-
* 字段类型
|
|
7
|
-
*/
|
|
8
|
-
export type FieldType = "string" | "number" | "text" | "array_string" | "array_text" | "array_number_string" | "array_number_text";
|
|
9
|
-
|
|
10
|
-
/**
|
|
11
|
-
* 字段定义类型(对象格式)
|
|
12
|
-
*/
|
|
13
|
-
export interface FieldDefinition {
|
|
14
|
-
/** 字段标签/描述 */
|
|
15
|
-
name: string;
|
|
16
|
-
/** 字段详细说明 */
|
|
17
|
-
detail: string;
|
|
18
|
-
/** 字段类型 */
|
|
19
|
-
type: FieldType;
|
|
20
|
-
/** 最小值/最小长度 */
|
|
21
|
-
min: number | null;
|
|
22
|
-
/** 最大值/最大长度 */
|
|
23
|
-
max: number | null;
|
|
24
|
-
/** 默认值 */
|
|
25
|
-
default: any;
|
|
26
|
-
/** 是否创建索引 */
|
|
27
|
-
index: boolean;
|
|
28
|
-
/** 是否唯一 */
|
|
29
|
-
unique: boolean;
|
|
30
|
-
/** 是否允许为空 */
|
|
31
|
-
nullable: boolean;
|
|
32
|
-
/** 是否无符号(仅 number 类型) */
|
|
33
|
-
unsigned: boolean;
|
|
34
|
-
/** 正则验证 */
|
|
35
|
-
regexp: string | null;
|
|
36
|
-
}
|
|
37
|
-
|
|
38
|
-
/**
|
|
39
|
-
* 表定义类型(对象格式)
|
|
40
|
-
*/
|
|
41
|
-
export type TableDefinition = Record<string, FieldDefinition>;
|
|
42
|
-
|
|
43
|
-
/**
|
|
44
|
-
* 验证结果类型
|
|
45
|
-
*/
|
|
46
|
-
export interface ValidateResult {
|
|
47
|
-
/** 状态码:0=通过,1=失败 */
|
|
48
|
-
code: 0 | 1;
|
|
49
|
-
/** 是否失败 */
|
|
50
|
-
failed: boolean;
|
|
51
|
-
/** 第一个错误 */
|
|
52
|
-
firstError: string | null;
|
|
53
|
-
/** 所有错误 */
|
|
54
|
-
errors: string[];
|
|
55
|
-
/** 错误字段列表 */
|
|
56
|
-
errorFields: string[];
|
|
57
|
-
/** 字段错误映射 */
|
|
58
|
-
fieldErrors: Record<string, string>;
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* 单值验证结果
|
|
63
|
-
*/
|
|
64
|
-
export interface SingleResult {
|
|
65
|
-
/** 转换后的值 */
|
|
66
|
-
value: any;
|
|
67
|
-
/** 错误信息(null 表示通过) */
|
|
68
|
-
error: string | null;
|
|
69
|
-
}
|
|
@@ -1,18 +0,0 @@
|
|
|
1
|
-
import { keysToCamel } from "./keysToCamel.ts";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 数组对象字段名批量转小驼峰
|
|
5
|
-
* @param arr - 源数组
|
|
6
|
-
* @returns 字段名转为小驼峰格式的新数组
|
|
7
|
-
*
|
|
8
|
-
* @example
|
|
9
|
-
* arrayKeysToCamel([
|
|
10
|
-
* { user_id: 1, user_name: 'John' },
|
|
11
|
-
* { user_id: 2, user_name: 'Jane' }
|
|
12
|
-
* ])
|
|
13
|
-
* // [{ userId: 1, userName: 'John' }, { userId: 2, userName: 'Jane' }]
|
|
14
|
-
*/
|
|
15
|
-
export const arrayKeysToCamel = <T = any>(arr: Record<string, any>[]): T[] => {
|
|
16
|
-
if (!arr || !Array.isArray(arr)) return arr as T[];
|
|
17
|
-
return arr.map((item) => keysToCamel<T>(item));
|
|
18
|
-
};
|
package/utils/configTypes.ts
DELETED
package/utils/genShortId.ts
DELETED
|
@@ -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(): string {
|
|
11
|
-
return Date.now().toString(36) + Math.random().toString(36).slice(2, 7);
|
|
12
|
-
}
|
package/utils/importDefault.ts
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 动态导入模块并优先返回其 default 导出。
|
|
3
|
-
*
|
|
4
|
-
* - import() 报错:返回 defaultValue
|
|
5
|
-
* - default 导出为 null/undefined:返回 defaultValue
|
|
6
|
-
*/
|
|
7
|
-
import { Logger } from "../lib/logger.ts";
|
|
8
|
-
|
|
9
|
-
export async function importDefault<T>(file: string, defaultValue: T): Promise<T> {
|
|
10
|
-
try {
|
|
11
|
-
const mod = (await import(file)) as { default?: unknown } | null | undefined;
|
|
12
|
-
const value = mod?.default;
|
|
13
|
-
if (value === null || value === undefined) {
|
|
14
|
-
return defaultValue;
|
|
15
|
-
}
|
|
16
|
-
return value as T;
|
|
17
|
-
} catch (err: any) {
|
|
18
|
-
Logger.warn({ err: err, file: file }, "importDefault 导入失败,已回退到默认值");
|
|
19
|
-
return defaultValue;
|
|
20
|
-
}
|
|
21
|
-
}
|
package/utils/keysToCamel.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { isPlainObject } from "es-toolkit/compat";
|
|
2
|
-
import { camelCase } from "es-toolkit/string";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 对象字段名转小驼峰
|
|
6
|
-
* @param obj - 源对象
|
|
7
|
-
* @returns 字段名转为小驼峰格式的新对象
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* keysToCamel({ user_id: 123, user_name: 'John' }) // { userId: 123, userName: 'John' }
|
|
11
|
-
* keysToCamel({ created_at: 1697452800000 }) // { createdAt: 1697452800000 }
|
|
12
|
-
*/
|
|
13
|
-
export const keysToCamel = <T = any>(obj: Record<string, any>): T => {
|
|
14
|
-
if (!obj || !isPlainObject(obj)) return obj as T;
|
|
15
|
-
|
|
16
|
-
const result: any = {};
|
|
17
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
18
|
-
const camelKey = camelCase(key);
|
|
19
|
-
result[camelKey] = value;
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
};
|
package/utils/keysToSnake.ts
DELETED
|
@@ -1,22 +0,0 @@
|
|
|
1
|
-
import { isPlainObject } from "es-toolkit/compat";
|
|
2
|
-
import { snakeCase } from "es-toolkit/string";
|
|
3
|
-
|
|
4
|
-
/**
|
|
5
|
-
* 对象字段名转下划线
|
|
6
|
-
* @param obj - 源对象
|
|
7
|
-
* @returns 字段名转为下划线格式的新对象
|
|
8
|
-
*
|
|
9
|
-
* @example
|
|
10
|
-
* keysToSnake({ userId: 123, userName: 'John' }) // { user_id: 123, user_name: 'John' }
|
|
11
|
-
* keysToSnake({ createdAt: 1697452800000 }) // { created_at: 1697452800000 }
|
|
12
|
-
*/
|
|
13
|
-
export const keysToSnake = <T = any>(obj: Record<string, any>): T => {
|
|
14
|
-
if (!obj || !isPlainObject(obj)) return obj as T;
|
|
15
|
-
|
|
16
|
-
const result: any = {};
|
|
17
|
-
for (const [key, value] of Object.entries(obj)) {
|
|
18
|
-
const snakeKey = snakeCase(key);
|
|
19
|
-
result[snakeKey] = value;
|
|
20
|
-
}
|
|
21
|
-
return result;
|
|
22
|
-
};
|
package/utils/pickFields.ts
DELETED
|
@@ -1,19 +0,0 @@
|
|
|
1
|
-
import { isPlainObject } from "es-toolkit/compat";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
* 挑选指定字段
|
|
5
|
-
*/
|
|
6
|
-
export const pickFields = <T extends Record<string, any>>(obj: T, keys: string[]): Partial<T> => {
|
|
7
|
-
if (!obj || (!isPlainObject(obj) && !Array.isArray(obj))) {
|
|
8
|
-
return {};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
const result: any = {};
|
|
12
|
-
for (const key of keys) {
|
|
13
|
-
if (key in obj) {
|
|
14
|
-
result[key] = obj[key];
|
|
15
|
-
}
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
return result;
|
|
19
|
-
};
|
package/utils/scanSources.ts
DELETED
|
@@ -1,64 +0,0 @@
|
|
|
1
|
-
import type { AddonInfo } from "./scanAddons.ts";
|
|
2
|
-
import type { ScanFileResult } from "./scanFiles.ts";
|
|
3
|
-
|
|
4
|
-
import { join } from "pathe";
|
|
5
|
-
|
|
6
|
-
import { coreDir, appDir } from "../paths.ts";
|
|
7
|
-
import { scanAddons } from "./scanAddons.ts";
|
|
8
|
-
import { scanFiles } from "./scanFiles.ts";
|
|
9
|
-
|
|
10
|
-
export type ScanSourcesResult = {
|
|
11
|
-
hooks: ScanFileResult[];
|
|
12
|
-
plugins: ScanFileResult[];
|
|
13
|
-
apis: ScanFileResult[];
|
|
14
|
-
tables: ScanFileResult[];
|
|
15
|
-
addons: AddonInfo[];
|
|
16
|
-
};
|
|
17
|
-
|
|
18
|
-
export const scanSources = async (): Promise<ScanSourcesResult> => {
|
|
19
|
-
const apis: ScanFileResult[] = [];
|
|
20
|
-
const plugins: ScanFileResult[] = [];
|
|
21
|
-
const hooks: ScanFileResult[] = [];
|
|
22
|
-
const tables: ScanFileResult[] = [];
|
|
23
|
-
|
|
24
|
-
const addons: AddonInfo[] = await scanAddons();
|
|
25
|
-
|
|
26
|
-
// 处理表格
|
|
27
|
-
tables.push(...(await scanFiles(join(appDir, "tables"), "app", "table", "*.json")));
|
|
28
|
-
|
|
29
|
-
for (const addon of addons) {
|
|
30
|
-
tables.push(...(await scanFiles(join(addon.fullPath, "tables"), "addon", "table", "*.json")));
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// 处理插件
|
|
34
|
-
plugins.push(...(await scanFiles(join(coreDir, "plugins"), "core", "plugin", "*.ts")));
|
|
35
|
-
plugins.push(...(await scanFiles(join(appDir, "plugins"), "app", "plugin", "*.ts")));
|
|
36
|
-
|
|
37
|
-
for (const addon of addons) {
|
|
38
|
-
plugins.push(...(await scanFiles(join(addon.fullPath, "plugins"), "addon", "plugin", "*.ts")));
|
|
39
|
-
}
|
|
40
|
-
|
|
41
|
-
// 处理接口
|
|
42
|
-
apis.push(...(await scanFiles(join(coreDir, "apis"), "core", "api", "**/*.ts")));
|
|
43
|
-
apis.push(...(await scanFiles(join(appDir, "apis"), "app", "api", "**/*.ts")));
|
|
44
|
-
|
|
45
|
-
for (const addon of addons) {
|
|
46
|
-
apis.push(...(await scanFiles(join(addon.fullPath, "apis"), "addon", "api", "**/*.ts")));
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
// 处理钩子
|
|
50
|
-
hooks.push(...(await scanFiles(join(coreDir, "hooks"), "core", "hook", "*.ts")));
|
|
51
|
-
hooks.push(...(await scanFiles(join(appDir, "hooks"), "app", "hook", "*.ts")));
|
|
52
|
-
|
|
53
|
-
for (const addon of addons) {
|
|
54
|
-
hooks.push(...(await scanFiles(join(addon.fullPath, "hooks"), "addon", "hook", "*.ts")));
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
return {
|
|
58
|
-
hooks: hooks,
|
|
59
|
-
plugins: plugins,
|
|
60
|
-
apis: apis,
|
|
61
|
-
tables: tables,
|
|
62
|
-
addons: addons
|
|
63
|
-
};
|
|
64
|
-
};
|
package/utils/sqlLog.ts
DELETED
|
@@ -1,37 +0,0 @@
|
|
|
1
|
-
import type { ListSql, SqlInfo } from "../types/database.ts";
|
|
2
|
-
|
|
3
|
-
export function toSqlLogFields(sqlInfo: SqlInfo): { sqlPreview: string; sqlParams: any[]; sqlDurationMs: number } {
|
|
4
|
-
return {
|
|
5
|
-
sqlPreview: sqlInfo.sql,
|
|
6
|
-
sqlParams: Array.isArray(sqlInfo.params) ? sqlInfo.params : [],
|
|
7
|
-
sqlDurationMs: typeof sqlInfo.duration === "number" ? sqlInfo.duration : 0
|
|
8
|
-
};
|
|
9
|
-
}
|
|
10
|
-
|
|
11
|
-
export function toListSqlLogFields(listSql: ListSql): {
|
|
12
|
-
countSqlPreview: string;
|
|
13
|
-
countSqlParams: any[];
|
|
14
|
-
countSqlDurationMs: number;
|
|
15
|
-
dataSqlPreview?: string;
|
|
16
|
-
dataSqlParams?: any[];
|
|
17
|
-
dataSqlDurationMs?: number;
|
|
18
|
-
} {
|
|
19
|
-
const base = {
|
|
20
|
-
countSqlPreview: listSql.count.sql,
|
|
21
|
-
countSqlParams: Array.isArray(listSql.count.params) ? listSql.count.params : [],
|
|
22
|
-
countSqlDurationMs: typeof listSql.count.duration === "number" ? listSql.count.duration : 0
|
|
23
|
-
};
|
|
24
|
-
|
|
25
|
-
if (!listSql.data) {
|
|
26
|
-
return base;
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
return {
|
|
30
|
-
countSqlPreview: base.countSqlPreview,
|
|
31
|
-
countSqlParams: base.countSqlParams,
|
|
32
|
-
countSqlDurationMs: base.countSqlDurationMs,
|
|
33
|
-
dataSqlPreview: listSql.data.sql,
|
|
34
|
-
dataSqlParams: Array.isArray(listSql.data.params) ? listSql.data.params : [],
|
|
35
|
-
dataSqlDurationMs: typeof listSql.data.duration === "number" ? listSql.data.duration : 0
|
|
36
|
-
};
|
|
37
|
-
}
|