befly-shared 1.1.1 → 1.2.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 +22 -25
- package/dist/{types.js → constants.js} +2 -2
- package/dist/defineAddonConfig.js +7 -26
- package/dist/defineBeflyConfig.js +28 -0
- package/dist/index.js +4 -3
- package/dist/regex.js +3 -1
- package/package.json +2 -2
- package/src/configTypes.ts +4 -2
- package/src/constants.ts +60 -0
- package/src/index.ts +3 -4
- package/src/regex.ts +3 -1
- package/src/scanConfig.ts +4 -2
- package/tests/regex.test.ts +3 -3
- package/tests/types.test.ts +8 -2
- package/types/addon.d.ts +50 -0
- package/types/api.d.ts +63 -0
- package/types/common.d.ts +8 -0
- package/types/configTypes.d.ts +2 -0
- package/types/constants.d.ts +48 -0
- package/types/context.d.ts +38 -0
- package/types/crypto.d.ts +23 -0
- package/types/database.d.ts +55 -0
- package/types/index.d.ts +1 -2
- package/types/jwt.d.ts +99 -0
- package/types/logger.d.ts +22 -0
- package/types/menu.d.ts +49 -0
- package/types/regex.d.ts +3 -1
- package/types/table.d.ts +49 -0
- package/types/tool.d.ts +67 -0
- package/types/types.d.ts +41 -271
- package/types/validate.d.ts +71 -0
- package/src/defineAddonConfig.ts +0 -45
- package/src/types.ts +0 -338
- package/types/defineAddonConfig.d.ts +0 -19
package/types/index.d.ts
CHANGED
|
@@ -2,10 +2,9 @@
|
|
|
2
2
|
* Befly Shared 统一导出
|
|
3
3
|
* 跨包共享的工具函数、常量、类型定义
|
|
4
4
|
*/
|
|
5
|
-
export * from './
|
|
5
|
+
export * from './constants.js';
|
|
6
6
|
export * from './redisKeys.js';
|
|
7
7
|
export * from './regex.js';
|
|
8
|
-
export * from './defineAddonConfig.js';
|
|
9
8
|
export * from './addonHelper.js';
|
|
10
9
|
export * from './arrayKeysToCamel.js';
|
|
11
10
|
export * from './arrayToTree.js';
|
package/types/jwt.d.ts
ADDED
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* JWT 相关类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* JWT 算法类型
|
|
7
|
+
*/
|
|
8
|
+
export type JwtAlgorithm = 'HS256' | 'HS384' | 'HS512';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* JWT Header 接口
|
|
12
|
+
*/
|
|
13
|
+
export interface JwtHeader {
|
|
14
|
+
alg: JwtAlgorithm;
|
|
15
|
+
typ: 'JWT';
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* JWT 完整解码结果
|
|
20
|
+
*/
|
|
21
|
+
export interface JwtDecoded {
|
|
22
|
+
header: JwtHeader;
|
|
23
|
+
payload: JwtPayload;
|
|
24
|
+
signature: string;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* JWT 载荷
|
|
29
|
+
*/
|
|
30
|
+
export interface JwtPayload {
|
|
31
|
+
/** 用户 ID */
|
|
32
|
+
userId?: string;
|
|
33
|
+
/** 用户名 */
|
|
34
|
+
username?: string;
|
|
35
|
+
/** 角色 */
|
|
36
|
+
role?: string;
|
|
37
|
+
/** 角色列表 */
|
|
38
|
+
roles?: string[];
|
|
39
|
+
/** 权限列表 */
|
|
40
|
+
permissions?: string[];
|
|
41
|
+
/** 签发时间 */
|
|
42
|
+
iat?: number;
|
|
43
|
+
/** 过期时间 */
|
|
44
|
+
exp?: number;
|
|
45
|
+
/** 主题 */
|
|
46
|
+
sub?: string;
|
|
47
|
+
/** 签发者 */
|
|
48
|
+
iss?: string;
|
|
49
|
+
/** 受众 */
|
|
50
|
+
aud?: string | string[];
|
|
51
|
+
/** JWT ID */
|
|
52
|
+
jti?: string;
|
|
53
|
+
/** 生效时间 */
|
|
54
|
+
nbf?: number;
|
|
55
|
+
/** 其他自定义字段 */
|
|
56
|
+
[key: string]: any;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* JWT 签名选项
|
|
61
|
+
*/
|
|
62
|
+
export interface JwtSignOptions {
|
|
63
|
+
/** 密钥 */
|
|
64
|
+
secret?: string;
|
|
65
|
+
/** 算法 */
|
|
66
|
+
algorithm?: JwtAlgorithm;
|
|
67
|
+
/** 过期时间 */
|
|
68
|
+
expiresIn?: string | number;
|
|
69
|
+
/** 签发者 */
|
|
70
|
+
issuer?: string;
|
|
71
|
+
/** 受众 */
|
|
72
|
+
audience?: string;
|
|
73
|
+
/** 主题 */
|
|
74
|
+
subject?: string;
|
|
75
|
+
/** 生效时间 */
|
|
76
|
+
notBefore?: string | number;
|
|
77
|
+
/** JWT ID */
|
|
78
|
+
jwtId?: string;
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
/**
|
|
82
|
+
* JWT 验证选项
|
|
83
|
+
*/
|
|
84
|
+
export interface JwtVerifyOptions {
|
|
85
|
+
/** 密钥 */
|
|
86
|
+
secret?: string;
|
|
87
|
+
/** 算法列表 */
|
|
88
|
+
algorithms?: JwtAlgorithm[];
|
|
89
|
+
/** 签发者 */
|
|
90
|
+
issuer?: string;
|
|
91
|
+
/** 受众 */
|
|
92
|
+
audience?: string;
|
|
93
|
+
/** 主题 */
|
|
94
|
+
subject?: string;
|
|
95
|
+
/** 是否忽略过期 */
|
|
96
|
+
ignoreExpiration?: boolean;
|
|
97
|
+
/** 是否忽略生效时间 */
|
|
98
|
+
ignoreNotBefore?: boolean;
|
|
99
|
+
}
|
|
@@ -0,0 +1,22 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 日志相关类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 日志级别
|
|
7
|
+
*/
|
|
8
|
+
export type LogLevel = 'trace' | 'debug' | 'info' | 'warn' | 'error' | 'fatal';
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 日志配置
|
|
12
|
+
*/
|
|
13
|
+
export interface LoggerConfig {
|
|
14
|
+
/** 是否开启调试模式 (0: 关闭, 1: 开启) @default 0 */
|
|
15
|
+
debug?: number;
|
|
16
|
+
/** 日志目录 @default './logs' */
|
|
17
|
+
dir?: string;
|
|
18
|
+
/** 是否输出到控制台 (0: 关闭, 1: 开启) @default 1 */
|
|
19
|
+
console?: number;
|
|
20
|
+
/** 单个日志文件最大大小 (MB) @default 10 */
|
|
21
|
+
maxSize?: number;
|
|
22
|
+
}
|
package/types/menu.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 菜单权限相关类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 菜单项类型
|
|
7
|
+
*/
|
|
8
|
+
export interface MenuItem {
|
|
9
|
+
/** 菜单 ID */
|
|
10
|
+
id: number;
|
|
11
|
+
/** 父级 ID */
|
|
12
|
+
pid: number;
|
|
13
|
+
/** 菜单名称 */
|
|
14
|
+
name: string;
|
|
15
|
+
/** 菜单路径 */
|
|
16
|
+
path: string;
|
|
17
|
+
/** 菜单图标 */
|
|
18
|
+
icon?: string;
|
|
19
|
+
/** 排序 */
|
|
20
|
+
sort: number;
|
|
21
|
+
/** 是否隐藏 */
|
|
22
|
+
hidden?: boolean;
|
|
23
|
+
/** 子菜单 */
|
|
24
|
+
children?: MenuItem[];
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* 权限项类型
|
|
29
|
+
*/
|
|
30
|
+
export interface PermissionItem {
|
|
31
|
+
/** API 路由(如 POST/api/user/list) */
|
|
32
|
+
route: string;
|
|
33
|
+
/** 权限名称 */
|
|
34
|
+
name: string;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/**
|
|
38
|
+
* 角色信息类型
|
|
39
|
+
*/
|
|
40
|
+
export interface RoleInfo {
|
|
41
|
+
/** 角色 ID */
|
|
42
|
+
id: number;
|
|
43
|
+
/** 角色代码 */
|
|
44
|
+
code: string;
|
|
45
|
+
/** 角色名称 */
|
|
46
|
+
name: string;
|
|
47
|
+
/** 角色描述 */
|
|
48
|
+
desc?: string;
|
|
49
|
+
}
|
package/types/regex.d.ts
CHANGED
|
@@ -21,7 +21,9 @@ export declare const RegexAliases: {
|
|
|
21
21
|
/** 字母和数字 */
|
|
22
22
|
readonly alphanumeric: '^[a-zA-Z0-9]+$';
|
|
23
23
|
/** 字母、数字和下划线 */
|
|
24
|
-
readonly
|
|
24
|
+
readonly alphanumeric_: '^[a-zA-Z0-9_]+$';
|
|
25
|
+
/** 字母、数字、下划线和短横线 */
|
|
26
|
+
readonly alphanumericDash_: '^[a-zA-Z0-9_-]+$';
|
|
25
27
|
/** 小写字母 */
|
|
26
28
|
readonly lowercase: '^[a-z]+$';
|
|
27
29
|
/** 大写字母 */
|
package/types/table.d.ts
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 表结构相关类型定义
|
|
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>;
|
package/types/tool.d.ts
ADDED
|
@@ -0,0 +1,67 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 工具函数相关类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 日期格式化类型
|
|
7
|
+
*/
|
|
8
|
+
export type DateFormat = 'YYYY-MM-DD' | 'YYYY-MM-DD HH:mm:ss' | 'HH:mm:ss' | 'YYYY/MM/DD' | 'MM-DD' | string;
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* 颜色代码
|
|
12
|
+
*/
|
|
13
|
+
export type ColorCode = 'reset' | 'bright' | 'dim' | 'underscore' | 'blink' | 'reverse' | 'hidden' | 'black' | 'red' | 'green' | 'yellow' | 'blue' | 'magenta' | 'cyan' | 'white';
|
|
14
|
+
|
|
15
|
+
/**
|
|
16
|
+
* 分页参数
|
|
17
|
+
*/
|
|
18
|
+
export interface PaginationParams {
|
|
19
|
+
/** 页码(从 1 开始) */
|
|
20
|
+
page?: number;
|
|
21
|
+
/** 每页数量 */
|
|
22
|
+
limit?: number;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* 分页结果
|
|
27
|
+
*/
|
|
28
|
+
export interface PaginationResult<T = any> {
|
|
29
|
+
/** 数据列表 */
|
|
30
|
+
list: T[];
|
|
31
|
+
/** 总条数 */
|
|
32
|
+
total: number;
|
|
33
|
+
/** 当前页码 */
|
|
34
|
+
page: number;
|
|
35
|
+
/** 每页数量 */
|
|
36
|
+
limit: number;
|
|
37
|
+
/** 总页数 */
|
|
38
|
+
pages: number;
|
|
39
|
+
/** 是否有下一页 */
|
|
40
|
+
hasNext: boolean;
|
|
41
|
+
/** 是否有上一页 */
|
|
42
|
+
hasPrev: boolean;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 文件类型
|
|
47
|
+
*/
|
|
48
|
+
export type FileType = 'image' | 'video' | 'audio' | 'document' | 'archive' | 'other';
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* MIME 类型
|
|
52
|
+
*/
|
|
53
|
+
export type MimeType = string;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* 文件上传选项
|
|
57
|
+
*/
|
|
58
|
+
export interface FileUploadOptions {
|
|
59
|
+
/** 允许的文件类型 */
|
|
60
|
+
allowedTypes?: string[];
|
|
61
|
+
/** 最大文件大小(字节) */
|
|
62
|
+
maxSize?: number;
|
|
63
|
+
/** 保存目录 */
|
|
64
|
+
saveDir?: string;
|
|
65
|
+
/** 文件名生成函数 */
|
|
66
|
+
filename?: (originalName: string) => string;
|
|
67
|
+
}
|
package/types/types.d.ts
CHANGED
|
@@ -1,274 +1,44 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Befly 共享类型定义
|
|
2
|
+
* Befly 共享类型定义 - 统一导出入口
|
|
3
3
|
* 这些类型可以在 core、tpl、admin 等多个包中复用
|
|
4
4
|
*/
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
export
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
}
|
|
46
|
-
/**
|
|
47
|
-
* HTTP 方法类型
|
|
48
|
-
*/
|
|
49
|
-
export type HttpMethod = 'GET' | 'POST' | 'PUT' | 'DELETE' | 'PATCH' | 'HEAD' | 'OPTIONS';
|
|
50
|
-
/**
|
|
51
|
-
* 通用键值对类型
|
|
52
|
-
*/
|
|
53
|
-
export type KeyValue<T = any> = Record<string, T>;
|
|
54
|
-
/**
|
|
55
|
-
* 字段类型
|
|
56
|
-
*/
|
|
57
|
-
export type FieldType = 'string' | 'number' | 'text' | 'array_string' | 'array_text';
|
|
58
|
-
/**
|
|
59
|
-
* 字段定义类型(对象格式)
|
|
60
|
-
*/
|
|
61
|
-
export interface FieldDefinition {
|
|
62
|
-
/** 字段标签/描述 */
|
|
63
|
-
name: string;
|
|
64
|
-
/** 字段详细说明 */
|
|
65
|
-
detail: string;
|
|
66
|
-
/** 字段类型 */
|
|
67
|
-
type: FieldType;
|
|
68
|
-
/** 最小值/最小长度 */
|
|
69
|
-
min: number | null;
|
|
70
|
-
/** 最大值/最大长度 */
|
|
71
|
-
max: number | null;
|
|
72
|
-
/** 默认值 */
|
|
73
|
-
default: any;
|
|
74
|
-
/** 是否创建索引 */
|
|
75
|
-
index: boolean;
|
|
76
|
-
/** 是否唯一 */
|
|
77
|
-
unique: boolean;
|
|
78
|
-
/** 字段注释 */
|
|
79
|
-
comment: string;
|
|
80
|
-
/** 是否允许为空 */
|
|
81
|
-
nullable: boolean;
|
|
82
|
-
/** 是否无符号(仅 number 类型) */
|
|
83
|
-
unsigned: boolean;
|
|
84
|
-
/** 正则验证 */
|
|
85
|
-
regexp: string | null;
|
|
86
|
-
}
|
|
87
|
-
/**
|
|
88
|
-
* 表定义类型(对象格式)
|
|
89
|
-
*/
|
|
90
|
-
export type TableDefinition = Record<string, FieldDefinition>;
|
|
91
|
-
/**
|
|
92
|
-
* 用户信息类型
|
|
93
|
-
*/
|
|
94
|
-
export interface UserInfo {
|
|
95
|
-
/** 用户 ID */
|
|
96
|
-
id: number;
|
|
97
|
-
/** 用户名 */
|
|
98
|
-
username?: string;
|
|
99
|
-
/** 邮箱 */
|
|
100
|
-
email?: string;
|
|
101
|
-
/** 角色代码 */
|
|
102
|
-
roleCode?: string;
|
|
103
|
-
/** 其他自定义字段 */
|
|
104
|
-
[key: string]: any;
|
|
105
|
-
}
|
|
106
|
-
/**
|
|
107
|
-
* 请求上下文基础接口
|
|
108
|
-
* 用于跨包共享的最小上下文定义
|
|
109
|
-
*/
|
|
110
|
-
export interface BaseRequestContext {
|
|
111
|
-
/** 请求体参数 */
|
|
112
|
-
body: Record<string, any>;
|
|
113
|
-
/** 用户信息 */
|
|
114
|
-
user: Record<string, any>;
|
|
115
|
-
/** 请求开始时间(毫秒) */
|
|
116
|
-
now: number;
|
|
117
|
-
/** 客户端 IP 地址 */
|
|
118
|
-
ip: string;
|
|
119
|
-
/** API 路由路径(如 POST/api/user/login) */
|
|
120
|
-
route: string;
|
|
121
|
-
/** 请求唯一 ID */
|
|
122
|
-
requestId: string;
|
|
123
|
-
}
|
|
124
|
-
/**
|
|
125
|
-
* API 路由基础配置
|
|
126
|
-
* 用于跨包共享的最小路由定义
|
|
127
|
-
*/
|
|
128
|
-
export interface BaseApiRoute {
|
|
129
|
-
/** 接口名称(必填) */
|
|
130
|
-
name: string;
|
|
131
|
-
/** HTTP 方法(可选,默认 POST) */
|
|
132
|
-
method?: HttpMethod;
|
|
133
|
-
/** 认证类型(可选,默认 true) */
|
|
134
|
-
auth?: boolean;
|
|
135
|
-
/** 字段定义(验证规则) */
|
|
136
|
-
fields?: TableDefinition;
|
|
137
|
-
/** 必填字段 */
|
|
138
|
-
required?: string[];
|
|
139
|
-
/** 路由路径(运行时生成) */
|
|
140
|
-
route?: string;
|
|
141
|
-
}
|
|
142
|
-
/**
|
|
143
|
-
* SQL 值类型
|
|
144
|
-
*/
|
|
145
|
-
export type SqlValue = string | number | boolean | null | Date;
|
|
146
|
-
/**
|
|
147
|
-
* SQL 参数数组类型
|
|
148
|
-
*/
|
|
149
|
-
export type SqlParams = SqlValue[];
|
|
150
|
-
/**
|
|
151
|
-
* 排序方向
|
|
152
|
-
*/
|
|
153
|
-
export type OrderDirection = 'ASC' | 'DESC' | 'asc' | 'desc';
|
|
154
|
-
/**
|
|
155
|
-
* 数据库类型
|
|
156
|
-
*/
|
|
157
|
-
export type DatabaseType = 'mysql' | 'postgresql' | 'sqlite';
|
|
158
|
-
/**
|
|
159
|
-
* 数据库配置类型
|
|
160
|
-
*/
|
|
161
|
-
export interface DatabaseConfig {
|
|
162
|
-
/** 数据库类型 */
|
|
163
|
-
type: DatabaseType;
|
|
164
|
-
/** 主机地址 */
|
|
165
|
-
host: string;
|
|
166
|
-
/** 端口号 */
|
|
167
|
-
port: number;
|
|
168
|
-
/** 用户名 */
|
|
169
|
-
user: string;
|
|
170
|
-
/** 密码 */
|
|
171
|
-
password: string;
|
|
172
|
-
/** 数据库名 */
|
|
173
|
-
database: string;
|
|
174
|
-
}
|
|
175
|
-
/**
|
|
176
|
-
* Redis 配置类型
|
|
177
|
-
*/
|
|
178
|
-
export interface RedisConfig {
|
|
179
|
-
/** 主机地址 */
|
|
180
|
-
host: string;
|
|
181
|
-
/** 端口号 */
|
|
182
|
-
port: number;
|
|
183
|
-
/** 密码 */
|
|
184
|
-
password?: string;
|
|
185
|
-
/** 数据库索引 */
|
|
186
|
-
db?: number;
|
|
187
|
-
}
|
|
188
|
-
/**
|
|
189
|
-
* 菜单项类型
|
|
190
|
-
*/
|
|
191
|
-
export interface MenuItem {
|
|
192
|
-
/** 菜单 ID */
|
|
193
|
-
id: number;
|
|
194
|
-
/** 父级 ID */
|
|
195
|
-
pid: number;
|
|
196
|
-
/** 菜单名称 */
|
|
197
|
-
name: string;
|
|
198
|
-
/** 菜单路径 */
|
|
199
|
-
path: string;
|
|
200
|
-
/** 菜单图标 */
|
|
201
|
-
icon?: string;
|
|
202
|
-
/** 排序 */
|
|
203
|
-
sort: number;
|
|
204
|
-
/** 是否隐藏 */
|
|
205
|
-
hidden?: boolean;
|
|
206
|
-
/** 子菜单 */
|
|
207
|
-
children?: MenuItem[];
|
|
208
|
-
}
|
|
209
|
-
/**
|
|
210
|
-
* 权限项类型
|
|
211
|
-
*/
|
|
212
|
-
export interface PermissionItem {
|
|
213
|
-
/** API 路由(如 POST/api/user/list) */
|
|
214
|
-
route: string;
|
|
215
|
-
/** 权限名称 */
|
|
216
|
-
name: string;
|
|
217
|
-
}
|
|
218
|
-
/**
|
|
219
|
-
* 角色信息类型
|
|
220
|
-
*/
|
|
221
|
-
export interface RoleInfo {
|
|
222
|
-
/** 角色 ID */
|
|
223
|
-
id: number;
|
|
224
|
-
/** 角色代码 */
|
|
225
|
-
code: string;
|
|
226
|
-
/** 角色名称 */
|
|
227
|
-
name: string;
|
|
228
|
-
/** 角色描述 */
|
|
229
|
-
desc?: string;
|
|
230
|
-
}
|
|
231
|
-
/**
|
|
232
|
-
* API 响应码
|
|
233
|
-
*/
|
|
234
|
-
export declare const ApiCode: {
|
|
235
|
-
/** 成功 */
|
|
236
|
-
readonly SUCCESS: 0;
|
|
237
|
-
/** 通用失败 */
|
|
238
|
-
readonly FAIL: 1;
|
|
239
|
-
/** 未授权 */
|
|
240
|
-
readonly UNAUTHORIZED: 401;
|
|
241
|
-
/** 禁止访问 */
|
|
242
|
-
readonly FORBIDDEN: 403;
|
|
243
|
-
/** 未找到 */
|
|
244
|
-
readonly NOT_FOUND: 404;
|
|
245
|
-
/** 服务器错误 */
|
|
246
|
-
readonly SERVER_ERROR: 500;
|
|
247
|
-
};
|
|
248
|
-
/**
|
|
249
|
-
* API 响应码类型
|
|
250
|
-
*/
|
|
251
|
-
export type ApiCodeType = (typeof ApiCode)[keyof typeof ApiCode];
|
|
252
|
-
/**
|
|
253
|
-
* 通用错误消息
|
|
254
|
-
*/
|
|
255
|
-
export declare const ErrorMessages: {
|
|
256
|
-
/** 未授权 */
|
|
257
|
-
readonly UNAUTHORIZED: '请先登录';
|
|
258
|
-
/** 禁止访问 */
|
|
259
|
-
readonly FORBIDDEN: '无访问权限';
|
|
260
|
-
/** 未找到 */
|
|
261
|
-
readonly NOT_FOUND: '资源不存在';
|
|
262
|
-
/** 服务器错误 */
|
|
263
|
-
readonly SERVER_ERROR: '服务器错误';
|
|
264
|
-
/** 参数错误 */
|
|
265
|
-
readonly INVALID_PARAMS: '参数错误';
|
|
266
|
-
/** Token 过期 */
|
|
267
|
-
readonly TOKEN_EXPIRED: 'Token 已过期';
|
|
268
|
-
/** Token 无效 */
|
|
269
|
-
readonly TOKEN_INVALID: 'Token 无效';
|
|
270
|
-
};
|
|
271
|
-
/**
|
|
272
|
-
* 错误消息类型
|
|
273
|
-
*/
|
|
274
|
-
export type ErrorMessageType = (typeof ErrorMessages)[keyof typeof ErrorMessages];
|
|
5
|
+
|
|
6
|
+
// 常量(从 constants 导出)
|
|
7
|
+
export { ApiCode, ErrorMessages } from './constants';
|
|
8
|
+
export type { ApiCodeType, ErrorMessageType } from './constants';
|
|
9
|
+
|
|
10
|
+
// 验证相关
|
|
11
|
+
export type { FieldType, FieldDefinition, TableDefinition, ValidateResult, SingleResult } from './validate';
|
|
12
|
+
|
|
13
|
+
// API 相关
|
|
14
|
+
export type { HttpMethod, ResponseResult, PaginatedResult, BaseApiRoute } from './api';
|
|
15
|
+
|
|
16
|
+
// 数据库相关
|
|
17
|
+
export type { SqlValue, SqlParams, OrderDirection, DatabaseType, DatabaseConfig, RedisConfig } from './database';
|
|
18
|
+
|
|
19
|
+
// 上下文相关
|
|
20
|
+
export type { UserInfo, BaseRequestContext } from './context';
|
|
21
|
+
|
|
22
|
+
// 菜单权限相关
|
|
23
|
+
export type { MenuItem, PermissionItem, RoleInfo } from './menu';
|
|
24
|
+
|
|
25
|
+
// 通用类型
|
|
26
|
+
export type { KeyValue } from './common';
|
|
27
|
+
|
|
28
|
+
// Addon 相关
|
|
29
|
+
export type { AddonAuthor, AddonConfig } from './addon';
|
|
30
|
+
|
|
31
|
+
// 日志相关
|
|
32
|
+
export type { LogLevel, LoggerConfig } from './logger';
|
|
33
|
+
|
|
34
|
+
// 加密相关
|
|
35
|
+
export type { EncodingType, HashAlgorithm, PasswordHashOptions } from './crypto';
|
|
36
|
+
|
|
37
|
+
// JWT 相关
|
|
38
|
+
export type { JwtAlgorithm, JwtHeader, JwtDecoded, JwtPayload, JwtSignOptions, JwtVerifyOptions } from './jwt';
|
|
39
|
+
|
|
40
|
+
// 工具相关
|
|
41
|
+
export type { DateFormat, ColorCode, PaginationParams, PaginationResult, FileType, MimeType, FileUploadOptions } from './tool';
|
|
42
|
+
|
|
43
|
+
// 表结构相关
|
|
44
|
+
export type { ReservedFields, SystemFields, BaseTable, InsertType, UpdateType, SelectType, ExcludeReserved } from './table';
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 验证相关类型定义
|
|
3
|
+
*/
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* 字段类型
|
|
7
|
+
*/
|
|
8
|
+
export type FieldType = 'string' | 'number' | 'text' | 'array_string' | 'array_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
|
+
comment: string;
|
|
32
|
+
/** 是否允许为空 */
|
|
33
|
+
nullable: boolean;
|
|
34
|
+
/** 是否无符号(仅 number 类型) */
|
|
35
|
+
unsigned: boolean;
|
|
36
|
+
/** 正则验证 */
|
|
37
|
+
regexp: string | null;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
/**
|
|
41
|
+
* 表定义类型(对象格式)
|
|
42
|
+
*/
|
|
43
|
+
export type TableDefinition = Record<string, FieldDefinition>;
|
|
44
|
+
|
|
45
|
+
/**
|
|
46
|
+
* 验证结果类型
|
|
47
|
+
*/
|
|
48
|
+
export interface ValidateResult {
|
|
49
|
+
/** 状态码:0=通过,1=失败 */
|
|
50
|
+
code: 0 | 1;
|
|
51
|
+
/** 是否失败 */
|
|
52
|
+
failed: boolean;
|
|
53
|
+
/** 第一个错误 */
|
|
54
|
+
firstError: string | null;
|
|
55
|
+
/** 所有错误 */
|
|
56
|
+
errors: string[];
|
|
57
|
+
/** 错误字段列表 */
|
|
58
|
+
errorFields: string[];
|
|
59
|
+
/** 字段错误映射 */
|
|
60
|
+
fieldErrors: Record<string, string>;
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* 单值验证结果
|
|
65
|
+
*/
|
|
66
|
+
export interface SingleResult {
|
|
67
|
+
/** 转换后的值 */
|
|
68
|
+
value: any;
|
|
69
|
+
/** 错误信息(null 表示通过) */
|
|
70
|
+
error: string | null;
|
|
71
|
+
}
|