befly 3.2.1 → 3.3.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/bin/index.ts +138 -0
- package/checks/conflict.ts +35 -25
- package/checks/table.ts +6 -6
- package/commands/addon.ts +57 -0
- package/commands/build.ts +74 -0
- package/commands/dev.ts +94 -0
- package/commands/index.ts +252 -0
- package/commands/script.ts +303 -0
- package/commands/start.ts +80 -0
- package/commands/syncApi.ts +327 -0
- package/{scripts → commands}/syncDb/apply.ts +2 -2
- package/{scripts → commands}/syncDb/constants.ts +13 -7
- package/{scripts → commands}/syncDb/ddl.ts +7 -5
- package/{scripts → commands}/syncDb/helpers.ts +18 -18
- package/{scripts → commands}/syncDb/index.ts +37 -23
- package/{scripts → commands}/syncDb/sqlite.ts +1 -1
- package/{scripts → commands}/syncDb/state.ts +10 -4
- package/{scripts → commands}/syncDb/table.ts +7 -7
- package/{scripts → commands}/syncDb/tableCreate.ts +7 -6
- package/{scripts → commands}/syncDb/types.ts +5 -5
- package/{scripts → commands}/syncDb/version.ts +1 -1
- package/commands/syncDb.ts +35 -0
- package/commands/syncDev.ts +174 -0
- package/commands/syncMenu.ts +368 -0
- package/config/env.ts +4 -4
- package/config/menu.json +67 -0
- package/{utils/crypto.ts → lib/cipher.ts} +16 -67
- package/lib/database.ts +296 -0
- package/{utils → lib}/dbHelper.ts +102 -56
- package/{utils → lib}/jwt.ts +124 -151
- package/{utils → lib}/logger.ts +47 -24
- package/lib/middleware.ts +271 -0
- package/{utils → lib}/redisHelper.ts +4 -4
- package/{utils/validate.ts → lib/validator.ts} +101 -78
- package/lifecycle/bootstrap.ts +63 -0
- package/lifecycle/checker.ts +165 -0
- package/lifecycle/cluster.ts +241 -0
- package/lifecycle/lifecycle.ts +139 -0
- package/lifecycle/loader.ts +513 -0
- package/main.ts +14 -12
- package/package.json +21 -9
- package/paths.ts +34 -0
- package/plugins/cache.ts +187 -0
- package/plugins/db.ts +4 -4
- package/plugins/logger.ts +1 -1
- package/plugins/redis.ts +4 -4
- package/router/api.ts +155 -0
- package/router/root.ts +53 -0
- package/router/static.ts +76 -0
- package/types/api.d.ts +0 -36
- package/types/befly.d.ts +8 -6
- package/types/common.d.ts +1 -1
- package/types/context.d.ts +3 -3
- package/types/util.d.ts +45 -0
- package/util.ts +299 -0
- package/config/fields.ts +0 -55
- package/config/regexAliases.ts +0 -51
- package/config/reserved.ts +0 -96
- package/scripts/syncDb/tests/constants.test.ts +0 -105
- package/scripts/syncDb/tests/ddl.test.ts +0 -134
- package/scripts/syncDb/tests/helpers.test.ts +0 -70
- package/scripts/syncDb.ts +0 -10
- package/types/index.d.ts +0 -450
- package/types/index.ts +0 -438
- package/types/validator.ts +0 -43
- package/utils/colors.ts +0 -221
- package/utils/database.ts +0 -348
- package/utils/helper.ts +0 -812
- package/utils/index.ts +0 -33
- package/utils/requestContext.ts +0 -167
- /package/{scripts → commands}/syncDb/schema.ts +0 -0
- /package/{utils → lib}/sqlBuilder.ts +0 -0
- /package/{utils → lib}/xml.ts +0 -0
package/utils/index.ts
DELETED
|
@@ -1,33 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Befly 工具函数集 - TypeScript 版本
|
|
3
|
-
*
|
|
4
|
-
* 本文件作为统一导出入口,从各个专用工具模块重新导出功能
|
|
5
|
-
* 保持向后兼容性,支持从 utils/index.js 导入所有工具函数
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
// ========== 通用辅助工具(helpers.ts)==========
|
|
9
|
-
export { Yes, No, isDebug, isType, isEmptyObject, isEmptyArray, pickFields, formatDate, calcPerfTime, cleanData, toSnakeCase, toCamelCase, keysToSnake, keysToCamel } from './helper.js';
|
|
10
|
-
export type { DataCleanOptions } from './helper.js';
|
|
11
|
-
|
|
12
|
-
// ========== 框架工具 ==========
|
|
13
|
-
export { scanAddons, getAddonDir, addonDirExists, sortPlugins, parseRule } from './helper.js';
|
|
14
|
-
|
|
15
|
-
// ========== 数据库工具 ==========
|
|
16
|
-
export { buildDatabaseUrl, createSqlClient, buildRedisUrl, createRedisClient, initDatabase, closeDatabase, initSqlOnly, initRedisOnly, getRedis, getSql, getDbHelper, isDatabaseInitialized } from './database.js';
|
|
17
|
-
|
|
18
|
-
// 导出其他大型模块
|
|
19
|
-
export { Colors } from './colors.js';
|
|
20
|
-
export { Logger } from './logger.js';
|
|
21
|
-
export { Validator } from './validate.js';
|
|
22
|
-
export { SqlBuilder } from './sqlBuilder.js';
|
|
23
|
-
export { DbHelper } from './dbHelper.js';
|
|
24
|
-
export { RedisHelper } from './redisHelper.js';
|
|
25
|
-
export { Jwt } from './jwt.js';
|
|
26
|
-
export { Crypto2 } from './crypto.js';
|
|
27
|
-
export { Xml } from './xml.js';
|
|
28
|
-
|
|
29
|
-
// 类型导出
|
|
30
|
-
export type { QueryOptions, InsertOptions, UpdateOptions, DeleteOptions, ListResult, TransactionCallback } from './dbHelper.js';
|
|
31
|
-
export type { JwtPayload } from './jwt.js';
|
|
32
|
-
export type { EncodingType, HashAlgorithm } from './crypto.js';
|
|
33
|
-
export type { XmlParseOptions } from './xml.js';
|
package/utils/requestContext.ts
DELETED
|
@@ -1,167 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 请求上下文类
|
|
3
|
-
* 提供统一的请求数据访问接口和类型安全
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/**
|
|
7
|
-
* 标准请求上下文类
|
|
8
|
-
*/
|
|
9
|
-
export class RequestContext {
|
|
10
|
-
/** 原始请求对象 */
|
|
11
|
-
public readonly request: Request;
|
|
12
|
-
|
|
13
|
-
/** 请求开始时间(毫秒) */
|
|
14
|
-
public readonly startTime: number;
|
|
15
|
-
|
|
16
|
-
/** 请求体参数 (GET/POST 解析后的数据) */
|
|
17
|
-
public body: Record<string, any> = {};
|
|
18
|
-
|
|
19
|
-
/** 用户信息 (认证后填充) */
|
|
20
|
-
public user: Record<string, any> = {};
|
|
21
|
-
|
|
22
|
-
/** 自定义状态 (用于在中间件间传递数据) */
|
|
23
|
-
public state: Record<string, any> = {};
|
|
24
|
-
|
|
25
|
-
/** 响应数据 (由 handler 设置) */
|
|
26
|
-
public response?: any;
|
|
27
|
-
|
|
28
|
-
constructor(req: Request) {
|
|
29
|
-
this.request = req;
|
|
30
|
-
this.startTime = Date.now();
|
|
31
|
-
}
|
|
32
|
-
|
|
33
|
-
// ========== 便捷访问器 ==========
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* 获取请求方法
|
|
37
|
-
*/
|
|
38
|
-
get method(): string {
|
|
39
|
-
return this.request.method;
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
/**
|
|
43
|
-
* 获取请求 URL
|
|
44
|
-
*/
|
|
45
|
-
get url(): string {
|
|
46
|
-
return this.request.url;
|
|
47
|
-
}
|
|
48
|
-
|
|
49
|
-
/**
|
|
50
|
-
* 获取请求头对象
|
|
51
|
-
*/
|
|
52
|
-
get headers(): Headers {
|
|
53
|
-
return this.request.headers;
|
|
54
|
-
}
|
|
55
|
-
|
|
56
|
-
/**
|
|
57
|
-
* 获取客户端 IP 地址
|
|
58
|
-
*/
|
|
59
|
-
get ip(): string | null {
|
|
60
|
-
return this.request.headers.get('x-forwarded-for') || this.request.headers.get('x-real-ip') || this.request.headers.get('cf-connecting-ip') || null;
|
|
61
|
-
}
|
|
62
|
-
|
|
63
|
-
/**
|
|
64
|
-
* 获取 User-Agent
|
|
65
|
-
*/
|
|
66
|
-
get userAgent(): string | null {
|
|
67
|
-
return this.request.headers.get('user-agent');
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
/**
|
|
71
|
-
* 获取 Content-Type
|
|
72
|
-
*/
|
|
73
|
-
get contentType(): string | null {
|
|
74
|
-
return this.request.headers.get('content-type');
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
// ========== 工具方法 ==========
|
|
78
|
-
|
|
79
|
-
/**
|
|
80
|
-
* 获取请求头
|
|
81
|
-
* @param name - 请求头名称
|
|
82
|
-
*/
|
|
83
|
-
header(name: string): string | null {
|
|
84
|
-
return this.request.headers.get(name);
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
/**
|
|
88
|
-
* 获取参数值
|
|
89
|
-
* @param key - 参数键名
|
|
90
|
-
*/
|
|
91
|
-
get(key: string): any {
|
|
92
|
-
return this.body[key];
|
|
93
|
-
}
|
|
94
|
-
|
|
95
|
-
/**
|
|
96
|
-
* 设置参数值
|
|
97
|
-
* @param key - 参数键名
|
|
98
|
-
* @param value - 参数值
|
|
99
|
-
*/
|
|
100
|
-
set(key: string, value: any): void {
|
|
101
|
-
this.body[key] = value;
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
/**
|
|
105
|
-
* 检查参数是否存在
|
|
106
|
-
* @param key - 参数键名
|
|
107
|
-
*/
|
|
108
|
-
has(key: string): boolean {
|
|
109
|
-
return key in this.body;
|
|
110
|
-
}
|
|
111
|
-
|
|
112
|
-
/**
|
|
113
|
-
* 获取所有参数
|
|
114
|
-
*/
|
|
115
|
-
all(): Record<string, any> {
|
|
116
|
-
return { ...this.body };
|
|
117
|
-
}
|
|
118
|
-
|
|
119
|
-
/**
|
|
120
|
-
* 计算请求耗时(毫秒)
|
|
121
|
-
*/
|
|
122
|
-
getElapsedTime(): number {
|
|
123
|
-
return Date.now() - this.startTime;
|
|
124
|
-
}
|
|
125
|
-
|
|
126
|
-
/**
|
|
127
|
-
* 获取格式化的请求信息(用于日志)
|
|
128
|
-
*/
|
|
129
|
-
getRequestInfo(): Record<string, any> {
|
|
130
|
-
return {
|
|
131
|
-
method: this.method,
|
|
132
|
-
url: this.url,
|
|
133
|
-
ip: this.ip,
|
|
134
|
-
userAgent: this.userAgent,
|
|
135
|
-
elapsedTime: this.getElapsedTime()
|
|
136
|
-
};
|
|
137
|
-
}
|
|
138
|
-
|
|
139
|
-
/**
|
|
140
|
-
* 设置响应数据
|
|
141
|
-
* @param data - 响应数据
|
|
142
|
-
*/
|
|
143
|
-
setResponse(data: any): void {
|
|
144
|
-
this.response = data;
|
|
145
|
-
}
|
|
146
|
-
|
|
147
|
-
/**
|
|
148
|
-
* 判断用户是否已登录
|
|
149
|
-
*/
|
|
150
|
-
isAuthenticated(): boolean {
|
|
151
|
-
return !!this.user.id;
|
|
152
|
-
}
|
|
153
|
-
|
|
154
|
-
/**
|
|
155
|
-
* 获取用户 ID
|
|
156
|
-
*/
|
|
157
|
-
getUserId(): number | null {
|
|
158
|
-
return this.user.id || null;
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
/**
|
|
162
|
-
* 获取用户角色
|
|
163
|
-
*/
|
|
164
|
-
getUserRole(): string | null {
|
|
165
|
-
return this.user.role || this.user.roleType || null;
|
|
166
|
-
}
|
|
167
|
-
}
|
|
File without changes
|
|
File without changes
|
/package/{utils → lib}/xml.ts
RENAMED
|
File without changes
|