@onebots/core 0.5.0 → 1.0.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 +3 -3
- package/lib/__tests__/config-validator.test.d.ts +4 -0
- package/lib/__tests__/config-validator.test.js +152 -0
- package/lib/__tests__/di-container.test.d.ts +4 -0
- package/lib/__tests__/di-container.test.js +114 -0
- package/lib/__tests__/errors.test.d.ts +4 -0
- package/lib/__tests__/errors.test.js +111 -0
- package/lib/__tests__/integration.test.d.ts +5 -0
- package/lib/__tests__/integration.test.js +112 -0
- package/lib/__tests__/lifecycle.test.d.ts +4 -0
- package/lib/__tests__/lifecycle.test.js +163 -0
- package/lib/account.js +2 -1
- package/lib/base-app.d.ts +14 -3
- package/lib/base-app.js +215 -137
- package/lib/config-validator.d.ts +45 -0
- package/lib/config-validator.js +173 -0
- package/lib/db.d.ts +1 -1
- package/lib/di-container.d.ts +60 -0
- package/lib/di-container.js +103 -0
- package/lib/errors.d.ts +157 -0
- package/lib/errors.js +257 -0
- package/lib/index.d.ts +8 -4
- package/lib/index.js +11 -3
- package/lib/lifecycle.d.ts +75 -0
- package/lib/lifecycle.js +175 -0
- package/lib/logger.d.ts +76 -0
- package/lib/logger.js +156 -0
- package/lib/protocol.d.ts +2 -3
- package/lib/protocol.js +4 -0
- package/lib/rate-limiter.d.ts +88 -0
- package/lib/rate-limiter.js +196 -0
- package/lib/registry.js +0 -5
- package/lib/retry.d.ts +87 -0
- package/lib/retry.js +205 -0
- package/lib/router.d.ts +43 -6
- package/lib/router.js +139 -12
- package/lib/types.d.ts +1 -0
- package/lib/types.js +2 -1
- package/package.json +19 -10
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置验证系统
|
|
3
|
+
* 提供配置schema验证和默认值处理
|
|
4
|
+
*/
|
|
5
|
+
import { ValidationError } from './errors.js';
|
|
6
|
+
export { ValidationError };
|
|
7
|
+
export interface ValidationRule<T = any> {
|
|
8
|
+
required?: boolean;
|
|
9
|
+
type?: 'string' | 'number' | 'boolean' | 'object' | 'array';
|
|
10
|
+
min?: number;
|
|
11
|
+
max?: number;
|
|
12
|
+
pattern?: RegExp;
|
|
13
|
+
enum?: any[];
|
|
14
|
+
validator?: (value: T) => boolean | string;
|
|
15
|
+
default?: T | (() => T);
|
|
16
|
+
transform?: (value: any) => T;
|
|
17
|
+
}
|
|
18
|
+
export interface Schema {
|
|
19
|
+
[key: string]: ValidationRule | Schema;
|
|
20
|
+
}
|
|
21
|
+
/**
|
|
22
|
+
* 配置验证器
|
|
23
|
+
*/
|
|
24
|
+
export declare class ConfigValidator {
|
|
25
|
+
/**
|
|
26
|
+
* 验证配置对象
|
|
27
|
+
*/
|
|
28
|
+
static validate<T extends Record<string, any>>(config: T, schema: Schema, path?: string): T;
|
|
29
|
+
/**
|
|
30
|
+
* 检查类型
|
|
31
|
+
*/
|
|
32
|
+
private static checkType;
|
|
33
|
+
/**
|
|
34
|
+
* 判断是否为嵌套schema
|
|
35
|
+
*/
|
|
36
|
+
private static isSchema;
|
|
37
|
+
/**
|
|
38
|
+
* 验证并应用默认值
|
|
39
|
+
*/
|
|
40
|
+
static validateWithDefaults<T extends Record<string, any>>(config: Partial<T>, schema: Schema): T;
|
|
41
|
+
}
|
|
42
|
+
/**
|
|
43
|
+
* BaseApp 配置 Schema
|
|
44
|
+
*/
|
|
45
|
+
export declare const BaseAppConfigSchema: Schema;
|
|
@@ -0,0 +1,173 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 配置验证系统
|
|
3
|
+
* 提供配置schema验证和默认值处理
|
|
4
|
+
*/
|
|
5
|
+
import { ValidationError } from './errors.js';
|
|
6
|
+
export { ValidationError };
|
|
7
|
+
/**
|
|
8
|
+
* 配置验证器
|
|
9
|
+
*/
|
|
10
|
+
export class ConfigValidator {
|
|
11
|
+
/**
|
|
12
|
+
* 验证配置对象
|
|
13
|
+
*/
|
|
14
|
+
static validate(config, schema, path = '') {
|
|
15
|
+
const result = { ...config };
|
|
16
|
+
const errors = [];
|
|
17
|
+
for (const [key, rule] of Object.entries(schema)) {
|
|
18
|
+
const currentPath = path ? `${path}.${key}` : key;
|
|
19
|
+
const value = config[key];
|
|
20
|
+
// 如果是嵌套schema,递归验证
|
|
21
|
+
if (this.isSchema(rule)) {
|
|
22
|
+
if (value !== undefined) {
|
|
23
|
+
result[key] = this.validate(value || {}, rule, currentPath);
|
|
24
|
+
}
|
|
25
|
+
continue;
|
|
26
|
+
}
|
|
27
|
+
const validationRule = rule;
|
|
28
|
+
// 检查必填字段
|
|
29
|
+
if (validationRule.required && (value === undefined || value === null)) {
|
|
30
|
+
if (validationRule.default !== undefined) {
|
|
31
|
+
result[key] = typeof validationRule.default === 'function'
|
|
32
|
+
? validationRule.default()
|
|
33
|
+
: validationRule.default;
|
|
34
|
+
continue;
|
|
35
|
+
}
|
|
36
|
+
errors.push(`${currentPath} is required`);
|
|
37
|
+
continue;
|
|
38
|
+
}
|
|
39
|
+
// 如果值为undefined且有默认值,使用默认值
|
|
40
|
+
if (value === undefined && validationRule.default !== undefined) {
|
|
41
|
+
result[key] = typeof validationRule.default === 'function'
|
|
42
|
+
? validationRule.default()
|
|
43
|
+
: validationRule.default;
|
|
44
|
+
continue;
|
|
45
|
+
}
|
|
46
|
+
// 如果值为undefined,跳过验证
|
|
47
|
+
if (value === undefined) {
|
|
48
|
+
continue;
|
|
49
|
+
}
|
|
50
|
+
// 类型转换
|
|
51
|
+
if (validationRule.transform) {
|
|
52
|
+
try {
|
|
53
|
+
result[key] = validationRule.transform(value);
|
|
54
|
+
}
|
|
55
|
+
catch (error) {
|
|
56
|
+
errors.push(`${currentPath} transform failed: ${error.message}`);
|
|
57
|
+
continue;
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
const finalValue = result[key];
|
|
61
|
+
// 类型检查
|
|
62
|
+
if (validationRule.type) {
|
|
63
|
+
const typeError = this.checkType(finalValue, validationRule.type, currentPath);
|
|
64
|
+
if (typeError) {
|
|
65
|
+
errors.push(typeError);
|
|
66
|
+
continue;
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
// 数值范围检查
|
|
70
|
+
if (validationRule.type === 'number') {
|
|
71
|
+
if (validationRule.min !== undefined && finalValue < validationRule.min) {
|
|
72
|
+
errors.push(`${currentPath} must be >= ${validationRule.min}`);
|
|
73
|
+
}
|
|
74
|
+
if (validationRule.max !== undefined && finalValue > validationRule.max) {
|
|
75
|
+
errors.push(`${currentPath} must be <= ${validationRule.max}`);
|
|
76
|
+
}
|
|
77
|
+
}
|
|
78
|
+
// 字符串长度检查
|
|
79
|
+
if (validationRule.type === 'string') {
|
|
80
|
+
if (validationRule.min !== undefined && finalValue.length < validationRule.min) {
|
|
81
|
+
errors.push(`${currentPath} length must be >= ${validationRule.min}`);
|
|
82
|
+
}
|
|
83
|
+
if (validationRule.max !== undefined && finalValue.length > validationRule.max) {
|
|
84
|
+
errors.push(`${currentPath} length must be <= ${validationRule.max}`);
|
|
85
|
+
}
|
|
86
|
+
if (validationRule.pattern && !validationRule.pattern.test(finalValue)) {
|
|
87
|
+
errors.push(`${currentPath} does not match pattern ${validationRule.pattern}`);
|
|
88
|
+
}
|
|
89
|
+
}
|
|
90
|
+
// 枚举检查
|
|
91
|
+
if (validationRule.enum && !validationRule.enum.includes(finalValue)) {
|
|
92
|
+
errors.push(`${currentPath} must be one of: ${validationRule.enum.join(', ')}`);
|
|
93
|
+
}
|
|
94
|
+
// 自定义验证器
|
|
95
|
+
if (validationRule.validator) {
|
|
96
|
+
const validationResult = validationRule.validator(finalValue);
|
|
97
|
+
if (validationResult !== true) {
|
|
98
|
+
errors.push(`${currentPath}: ${validationResult || 'validation failed'}`);
|
|
99
|
+
}
|
|
100
|
+
}
|
|
101
|
+
}
|
|
102
|
+
if (errors.length > 0) {
|
|
103
|
+
throw new ValidationError('Configuration validation failed', {
|
|
104
|
+
context: {
|
|
105
|
+
errors,
|
|
106
|
+
path,
|
|
107
|
+
},
|
|
108
|
+
});
|
|
109
|
+
}
|
|
110
|
+
return result;
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* 检查类型
|
|
114
|
+
*/
|
|
115
|
+
static checkType(value, expectedType, path) {
|
|
116
|
+
const actualType = Array.isArray(value) ? 'array' : typeof value;
|
|
117
|
+
if (actualType !== expectedType) {
|
|
118
|
+
return `${path} must be ${expectedType}, got ${actualType}`;
|
|
119
|
+
}
|
|
120
|
+
return null;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* 判断是否为嵌套schema
|
|
124
|
+
*/
|
|
125
|
+
static isSchema(rule) {
|
|
126
|
+
return !('required' in rule) && !('type' in rule) && typeof rule === 'object';
|
|
127
|
+
}
|
|
128
|
+
/**
|
|
129
|
+
* 验证并应用默认值
|
|
130
|
+
*/
|
|
131
|
+
static validateWithDefaults(config, schema) {
|
|
132
|
+
return this.validate(config, schema);
|
|
133
|
+
}
|
|
134
|
+
}
|
|
135
|
+
/**
|
|
136
|
+
* BaseApp 配置 Schema
|
|
137
|
+
*/
|
|
138
|
+
export const BaseAppConfigSchema = {
|
|
139
|
+
port: {
|
|
140
|
+
type: 'number',
|
|
141
|
+
min: 1,
|
|
142
|
+
max: 65535,
|
|
143
|
+
default: 6727,
|
|
144
|
+
},
|
|
145
|
+
path: {
|
|
146
|
+
type: 'string',
|
|
147
|
+
default: '',
|
|
148
|
+
},
|
|
149
|
+
database: {
|
|
150
|
+
type: 'string',
|
|
151
|
+
default: 'onebots.db',
|
|
152
|
+
},
|
|
153
|
+
timeout: {
|
|
154
|
+
type: 'number',
|
|
155
|
+
min: 1,
|
|
156
|
+
default: 30,
|
|
157
|
+
},
|
|
158
|
+
username: {
|
|
159
|
+
type: 'string',
|
|
160
|
+
min: 1,
|
|
161
|
+
default: 'admin',
|
|
162
|
+
},
|
|
163
|
+
password: {
|
|
164
|
+
type: 'string',
|
|
165
|
+
min: 1,
|
|
166
|
+
default: '123456',
|
|
167
|
+
},
|
|
168
|
+
log_level: {
|
|
169
|
+
type: 'string',
|
|
170
|
+
enum: ['trace', 'debug', 'info', 'warn', 'error', 'fatal', 'mark', 'off'],
|
|
171
|
+
default: 'info',
|
|
172
|
+
},
|
|
173
|
+
};
|
package/lib/db.d.ts
CHANGED
|
@@ -62,7 +62,7 @@ export declare class Selection {
|
|
|
62
62
|
groupBy(field: string): this;
|
|
63
63
|
orderBy(field: string, order?: "ASC" | "DESC"): this;
|
|
64
64
|
get sql(): string;
|
|
65
|
-
run():
|
|
65
|
+
run(): Record<string, import("node:sqlite").SQLOutputValue>[];
|
|
66
66
|
}
|
|
67
67
|
export declare class Insertion {
|
|
68
68
|
#private;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 依赖注入容器
|
|
3
|
+
* 提供依赖注入和生命周期管理
|
|
4
|
+
*/
|
|
5
|
+
import type { Class } from './utils.js';
|
|
6
|
+
export type Token<T = any> = string | symbol | Class<T>;
|
|
7
|
+
export type Factory<T = any> = (container: Container) => T;
|
|
8
|
+
export type Provider<T = any> = Class<T> | Factory<T>;
|
|
9
|
+
export interface ServiceOptions {
|
|
10
|
+
/** 是否单例 */
|
|
11
|
+
singleton?: boolean;
|
|
12
|
+
/** 依赖的token列表 */
|
|
13
|
+
deps?: Token[];
|
|
14
|
+
}
|
|
15
|
+
/**
|
|
16
|
+
* 依赖注入容器
|
|
17
|
+
*/
|
|
18
|
+
export declare class Container {
|
|
19
|
+
private services;
|
|
20
|
+
/**
|
|
21
|
+
* 注册服务
|
|
22
|
+
*/
|
|
23
|
+
register<T>(token: Token<T>, provider: Provider<T>, options?: ServiceOptions): void;
|
|
24
|
+
/**
|
|
25
|
+
* 注册单例服务
|
|
26
|
+
*/
|
|
27
|
+
registerSingleton<T>(token: Token<T>, provider: Provider<T>, deps?: Token[]): void;
|
|
28
|
+
/**
|
|
29
|
+
* 注册瞬态服务(每次获取都创建新实例)
|
|
30
|
+
*/
|
|
31
|
+
registerTransient<T>(token: Token<T>, provider: Provider<T>, deps?: Token[]): void;
|
|
32
|
+
/**
|
|
33
|
+
* 获取服务实例
|
|
34
|
+
*/
|
|
35
|
+
get<T>(token: Token<T>): T;
|
|
36
|
+
/**
|
|
37
|
+
* 检查服务是否已注册
|
|
38
|
+
*/
|
|
39
|
+
has(token: Token): boolean;
|
|
40
|
+
/**
|
|
41
|
+
* 解析依赖
|
|
42
|
+
*/
|
|
43
|
+
private resolveDependencies;
|
|
44
|
+
/**
|
|
45
|
+
* 判断是否为类
|
|
46
|
+
*/
|
|
47
|
+
private isClass;
|
|
48
|
+
/**
|
|
49
|
+
* 清除所有服务
|
|
50
|
+
*/
|
|
51
|
+
clear(): void;
|
|
52
|
+
/**
|
|
53
|
+
* 移除服务
|
|
54
|
+
*/
|
|
55
|
+
remove(token: Token): boolean;
|
|
56
|
+
}
|
|
57
|
+
/**
|
|
58
|
+
* 全局容器实例
|
|
59
|
+
*/
|
|
60
|
+
export declare const container: Container;
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 依赖注入容器
|
|
3
|
+
* 提供依赖注入和生命周期管理
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 依赖注入容器
|
|
7
|
+
*/
|
|
8
|
+
export class Container {
|
|
9
|
+
services = new Map();
|
|
10
|
+
/**
|
|
11
|
+
* 注册服务
|
|
12
|
+
*/
|
|
13
|
+
register(token, provider, options = {}) {
|
|
14
|
+
this.services.set(token, {
|
|
15
|
+
provider,
|
|
16
|
+
options: {
|
|
17
|
+
singleton: true,
|
|
18
|
+
...options,
|
|
19
|
+
},
|
|
20
|
+
});
|
|
21
|
+
}
|
|
22
|
+
/**
|
|
23
|
+
* 注册单例服务
|
|
24
|
+
*/
|
|
25
|
+
registerSingleton(token, provider, deps) {
|
|
26
|
+
this.register(token, provider, {
|
|
27
|
+
singleton: true,
|
|
28
|
+
deps,
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
/**
|
|
32
|
+
* 注册瞬态服务(每次获取都创建新实例)
|
|
33
|
+
*/
|
|
34
|
+
registerTransient(token, provider, deps) {
|
|
35
|
+
this.register(token, provider, {
|
|
36
|
+
singleton: false,
|
|
37
|
+
deps,
|
|
38
|
+
});
|
|
39
|
+
}
|
|
40
|
+
/**
|
|
41
|
+
* 获取服务实例
|
|
42
|
+
*/
|
|
43
|
+
get(token) {
|
|
44
|
+
const service = this.services.get(token);
|
|
45
|
+
if (!service) {
|
|
46
|
+
throw new Error(`Service not found: ${String(token)}`);
|
|
47
|
+
}
|
|
48
|
+
// 如果是单例且已有实例,直接返回
|
|
49
|
+
if (service.options.singleton && service.instance !== undefined) {
|
|
50
|
+
return service.instance;
|
|
51
|
+
}
|
|
52
|
+
// 创建实例
|
|
53
|
+
let instance;
|
|
54
|
+
if (this.isClass(service.provider)) {
|
|
55
|
+
// 类构造函数
|
|
56
|
+
const deps = this.resolveDependencies(service.options.deps || []);
|
|
57
|
+
instance = new service.provider(...deps);
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// 工厂函数
|
|
61
|
+
instance = service.provider(this);
|
|
62
|
+
}
|
|
63
|
+
// 如果是单例,保存实例
|
|
64
|
+
if (service.options.singleton) {
|
|
65
|
+
service.instance = instance;
|
|
66
|
+
}
|
|
67
|
+
return instance;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* 检查服务是否已注册
|
|
71
|
+
*/
|
|
72
|
+
has(token) {
|
|
73
|
+
return this.services.has(token);
|
|
74
|
+
}
|
|
75
|
+
/**
|
|
76
|
+
* 解析依赖
|
|
77
|
+
*/
|
|
78
|
+
resolveDependencies(tokens) {
|
|
79
|
+
return tokens.map(token => this.get(token));
|
|
80
|
+
}
|
|
81
|
+
/**
|
|
82
|
+
* 判断是否为类
|
|
83
|
+
*/
|
|
84
|
+
isClass(provider) {
|
|
85
|
+
return typeof provider === 'function' && provider.prototype && provider.prototype.constructor === provider;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 清除所有服务
|
|
89
|
+
*/
|
|
90
|
+
clear() {
|
|
91
|
+
this.services.clear();
|
|
92
|
+
}
|
|
93
|
+
/**
|
|
94
|
+
* 移除服务
|
|
95
|
+
*/
|
|
96
|
+
remove(token) {
|
|
97
|
+
return this.services.delete(token);
|
|
98
|
+
}
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* 全局容器实例
|
|
102
|
+
*/
|
|
103
|
+
export const container = new Container();
|
package/lib/errors.d.ts
ADDED
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 错误处理和分类系统
|
|
3
|
+
* 提供统一的错误类型和处理机制
|
|
4
|
+
*/
|
|
5
|
+
/**
|
|
6
|
+
* 错误分类枚举
|
|
7
|
+
*/
|
|
8
|
+
export declare enum ErrorCategory {
|
|
9
|
+
/** 网络相关错误 */
|
|
10
|
+
NETWORK = "NETWORK",
|
|
11
|
+
/** 配置相关错误 */
|
|
12
|
+
CONFIG = "CONFIG",
|
|
13
|
+
/** 运行时错误 */
|
|
14
|
+
RUNTIME = "RUNTIME",
|
|
15
|
+
/** 验证错误 */
|
|
16
|
+
VALIDATION = "VALIDATION",
|
|
17
|
+
/** 资源错误 */
|
|
18
|
+
RESOURCE = "RESOURCE",
|
|
19
|
+
/** 协议错误 */
|
|
20
|
+
PROTOCOL = "PROTOCOL",
|
|
21
|
+
/** 适配器错误 */
|
|
22
|
+
ADAPTER = "ADAPTER",
|
|
23
|
+
/** 未知错误 */
|
|
24
|
+
UNKNOWN = "UNKNOWN"
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* 错误严重程度
|
|
28
|
+
*/
|
|
29
|
+
export declare enum ErrorSeverity {
|
|
30
|
+
/** 低 - 可以忽略或自动恢复 */
|
|
31
|
+
LOW = "LOW",
|
|
32
|
+
/** 中 - 需要记录但可以继续运行 */
|
|
33
|
+
MEDIUM = "MEDIUM",
|
|
34
|
+
/** 高 - 影响功能,需要处理 */
|
|
35
|
+
HIGH = "HIGH",
|
|
36
|
+
/** 严重 - 可能导致服务停止 */
|
|
37
|
+
CRITICAL = "CRITICAL"
|
|
38
|
+
}
|
|
39
|
+
/**
|
|
40
|
+
* 基础错误类
|
|
41
|
+
*/
|
|
42
|
+
export declare class OneBotsError extends Error {
|
|
43
|
+
readonly category: ErrorCategory;
|
|
44
|
+
readonly severity: ErrorSeverity;
|
|
45
|
+
readonly code: string;
|
|
46
|
+
readonly context?: Record<string, any>;
|
|
47
|
+
readonly timestamp: Date;
|
|
48
|
+
readonly cause?: Error;
|
|
49
|
+
constructor(message: string, options?: {
|
|
50
|
+
category?: ErrorCategory;
|
|
51
|
+
severity?: ErrorSeverity;
|
|
52
|
+
code?: string;
|
|
53
|
+
context?: Record<string, any>;
|
|
54
|
+
cause?: Error;
|
|
55
|
+
});
|
|
56
|
+
/**
|
|
57
|
+
* 转换为可序列化的对象
|
|
58
|
+
*/
|
|
59
|
+
toJSON(): {
|
|
60
|
+
name: string;
|
|
61
|
+
message: string;
|
|
62
|
+
category: ErrorCategory;
|
|
63
|
+
severity: ErrorSeverity;
|
|
64
|
+
code: string;
|
|
65
|
+
context: Record<string, any>;
|
|
66
|
+
timestamp: string;
|
|
67
|
+
stack: string;
|
|
68
|
+
cause: {
|
|
69
|
+
message: string;
|
|
70
|
+
stack: string;
|
|
71
|
+
};
|
|
72
|
+
};
|
|
73
|
+
/**
|
|
74
|
+
* 转换为字符串
|
|
75
|
+
*/
|
|
76
|
+
toString(): string;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* 网络错误
|
|
80
|
+
*/
|
|
81
|
+
export declare class NetworkError extends OneBotsError {
|
|
82
|
+
constructor(message: string, options?: {
|
|
83
|
+
context?: Record<string, any>;
|
|
84
|
+
cause?: Error;
|
|
85
|
+
});
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* 配置错误
|
|
89
|
+
*/
|
|
90
|
+
export declare class ConfigError extends OneBotsError {
|
|
91
|
+
constructor(message: string, options?: {
|
|
92
|
+
context?: Record<string, any>;
|
|
93
|
+
cause?: Error;
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* 验证错误
|
|
98
|
+
*/
|
|
99
|
+
export declare class ValidationError extends OneBotsError {
|
|
100
|
+
constructor(message: string, options?: {
|
|
101
|
+
context?: Record<string, any>;
|
|
102
|
+
cause?: Error;
|
|
103
|
+
});
|
|
104
|
+
}
|
|
105
|
+
/**
|
|
106
|
+
* 资源错误
|
|
107
|
+
*/
|
|
108
|
+
export declare class ResourceError extends OneBotsError {
|
|
109
|
+
constructor(message: string, options?: {
|
|
110
|
+
context?: Record<string, any>;
|
|
111
|
+
cause?: Error;
|
|
112
|
+
});
|
|
113
|
+
}
|
|
114
|
+
/**
|
|
115
|
+
* 协议错误
|
|
116
|
+
*/
|
|
117
|
+
export declare class ProtocolError extends OneBotsError {
|
|
118
|
+
constructor(message: string, options?: {
|
|
119
|
+
context?: Record<string, any>;
|
|
120
|
+
cause?: Error;
|
|
121
|
+
});
|
|
122
|
+
}
|
|
123
|
+
/**
|
|
124
|
+
* 适配器错误
|
|
125
|
+
*/
|
|
126
|
+
export declare class AdapterError extends OneBotsError {
|
|
127
|
+
constructor(message: string, options?: {
|
|
128
|
+
context?: Record<string, any>;
|
|
129
|
+
cause?: Error;
|
|
130
|
+
});
|
|
131
|
+
}
|
|
132
|
+
/**
|
|
133
|
+
* 运行时错误
|
|
134
|
+
*/
|
|
135
|
+
export declare class RuntimeError extends OneBotsError {
|
|
136
|
+
constructor(message: string, options?: {
|
|
137
|
+
context?: Record<string, any>;
|
|
138
|
+
cause?: Error;
|
|
139
|
+
});
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* 错误处理工具函数
|
|
143
|
+
*/
|
|
144
|
+
export declare class ErrorHandler {
|
|
145
|
+
/**
|
|
146
|
+
* 包装错误,转换为 OneBotsError
|
|
147
|
+
*/
|
|
148
|
+
static wrap(error: unknown, context?: Record<string, any>): OneBotsError;
|
|
149
|
+
/**
|
|
150
|
+
* 判断错误是否可恢复
|
|
151
|
+
*/
|
|
152
|
+
static isRecoverable(error: OneBotsError): boolean;
|
|
153
|
+
/**
|
|
154
|
+
* 判断错误是否致命
|
|
155
|
+
*/
|
|
156
|
+
static isFatal(error: OneBotsError): boolean;
|
|
157
|
+
}
|