@aalis/api-doctor 0.5.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/LICENSE +21 -0
- package/dist/index.d.ts +103 -0
- package/dist/index.d.ts.map +1 -0
- package/dist/index.js +27 -0
- package/dist/index.js.map +1 -0
- package/package.json +40 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Ace Nyan <ace@acenyan.com>
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @aalis/api-doctor — 诊断子系统的公共类型与消费者帮手
|
|
3
|
+
*
|
|
4
|
+
* 设计动机:
|
|
5
|
+
* plugin-doctor 是开放注册中心(DoctorService.registerCheck)。其它插件应
|
|
6
|
+
* 贡献自己领域的检查项(例如 storage 检查存储根可写、commands 检查指令
|
|
7
|
+
* 覆盖配置是否孤立),而不是把所有逻辑塞回 doctor 内部。
|
|
8
|
+
*
|
|
9
|
+
* 为避免 storage/commands 等下游插件直接 runtime depend 实现包 plugin-doctor
|
|
10
|
+
* (会形成「实现包 ↔ 业务插件」的双向耦合),仿照 api-storage /
|
|
11
|
+
* api-commands 的模式抽出本 api 包,仅含类型 + 一个 useDoctorService
|
|
12
|
+
* helper(懒注册、doctor 未上线时延后到 whenService 触发)。
|
|
13
|
+
*
|
|
14
|
+
* AalisEvents 的模块增强统一在本文件做,避免多包
|
|
15
|
+
* 重复声明导致 TS 合并冲突。
|
|
16
|
+
*/
|
|
17
|
+
import type { Context } from '@aalis/core';
|
|
18
|
+
export type CheckLevel = 'ok' | 'warn' | 'error';
|
|
19
|
+
export type CheckCategory = 'env' | 'filesystem' | 'plugins' | 'config' | 'service' | 'other';
|
|
20
|
+
export interface CheckResult {
|
|
21
|
+
id: string;
|
|
22
|
+
category: CheckCategory;
|
|
23
|
+
level: CheckLevel;
|
|
24
|
+
message: string;
|
|
25
|
+
detail?: string;
|
|
26
|
+
}
|
|
27
|
+
export interface DoctorReport {
|
|
28
|
+
generatedAt: string;
|
|
29
|
+
summary: {
|
|
30
|
+
ok: number;
|
|
31
|
+
warn: number;
|
|
32
|
+
error: number;
|
|
33
|
+
};
|
|
34
|
+
checks: CheckResult[];
|
|
35
|
+
}
|
|
36
|
+
/** 检查项定义:插件通过 `registerCheck` 注册到 DoctorService */
|
|
37
|
+
export interface CheckSpec {
|
|
38
|
+
/** 唯一 id,如 'memory.connectivity';重复注册以最后一次为准 */
|
|
39
|
+
id: string;
|
|
40
|
+
/** 检查分类,影响表格分组与默认排序 */
|
|
41
|
+
category: CheckCategory;
|
|
42
|
+
/** 可选标签:仅用于日志/调试显示 */
|
|
43
|
+
label?: string;
|
|
44
|
+
/** 来源插件名,自动由 DoctorService 注入;外部传入也可 */
|
|
45
|
+
pluginName?: string;
|
|
46
|
+
/** 执行函数:返回 1~N 条结果(一个 spec 可输出多条相关 check) */
|
|
47
|
+
run(ctx: Context): Promise<CheckResult | CheckResult[]> | CheckResult | CheckResult[];
|
|
48
|
+
}
|
|
49
|
+
export interface DoctorService {
|
|
50
|
+
/** 同步运行所有检查,返回报告 */
|
|
51
|
+
runChecks(): Promise<DoctorReport>;
|
|
52
|
+
/** 取上一次报告(未运行过返回 undefined) */
|
|
53
|
+
getLastReport(): DoctorReport | undefined;
|
|
54
|
+
/**
|
|
55
|
+
* 注册检查项。返回 dispose 函数;同 id 重复注册以最后一次为准。
|
|
56
|
+
* 其他插件应在 apply() 中调用以贡献自我诊断。
|
|
57
|
+
*/
|
|
58
|
+
registerCheck(spec: CheckSpec): () => void;
|
|
59
|
+
/** 列出当前所有已注册的检查项(id + category + pluginName) */
|
|
60
|
+
listChecks(): Array<{
|
|
61
|
+
id: string;
|
|
62
|
+
category: CheckCategory;
|
|
63
|
+
pluginName?: string;
|
|
64
|
+
}>;
|
|
65
|
+
}
|
|
66
|
+
declare module '@aalis/core' {
|
|
67
|
+
interface AalisEvents {
|
|
68
|
+
/** 一次诊断完成后发射,供 WebUI 等订阅者即时刷新 */
|
|
69
|
+
'doctor:updated': [info: {
|
|
70
|
+
generatedAt: string;
|
|
71
|
+
summary: {
|
|
72
|
+
ok: number;
|
|
73
|
+
warn: number;
|
|
74
|
+
error: number;
|
|
75
|
+
};
|
|
76
|
+
}];
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* 在 ctx scope 内注册一个诊断检查项;doctor 服务未就绪时延迟到 whenService 触发。
|
|
81
|
+
* 返回的 dispose 既能在 doctor 已就绪时立即解注册,也能在 doctor 还未来时取消挂起的
|
|
82
|
+
* whenService 订阅。
|
|
83
|
+
*
|
|
84
|
+
* 用法:
|
|
85
|
+
* useDoctorService(ctx).registerCheck({
|
|
86
|
+
* id: 'storage.roots',
|
|
87
|
+
* category: 'filesystem',
|
|
88
|
+
* async run() { ... }
|
|
89
|
+
* });
|
|
90
|
+
*
|
|
91
|
+
* 调用方应在 inject.optional 中声明 'doctor',否则 doctor 重启时不会带动本插件。
|
|
92
|
+
*/
|
|
93
|
+
export interface ScopedDoctorService {
|
|
94
|
+
/** 立即或延迟注册一条 check;返回 dispose */
|
|
95
|
+
registerCheck(spec: CheckSpec): () => void;
|
|
96
|
+
}
|
|
97
|
+
export declare function useDoctorService(ctx: Context): ScopedDoctorService;
|
|
98
|
+
declare module '@aalis/core' {
|
|
99
|
+
interface ServiceTypeMap {
|
|
100
|
+
doctor: DoctorService;
|
|
101
|
+
}
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=index.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAEH,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAI3C,MAAM,MAAM,UAAU,GAAG,IAAI,GAAG,MAAM,GAAG,OAAO,CAAC;AACjD,MAAM,MAAM,aAAa,GAAG,KAAK,GAAG,YAAY,GAAG,SAAS,GAAG,QAAQ,GAAG,SAAS,GAAG,OAAO,CAAC;AAE9F,MAAM,WAAW,WAAW;IAC1B,EAAE,EAAE,MAAM,CAAC;IACX,QAAQ,EAAE,aAAa,CAAC;IACxB,KAAK,EAAE,UAAU,CAAC;IAClB,OAAO,EAAE,MAAM,CAAC;IAChB,MAAM,CAAC,EAAE,MAAM,CAAC;CACjB;AAED,MAAM,WAAW,YAAY;IAC3B,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE;QAAE,EAAE,EAAE,MAAM,CAAC;QAAC,IAAI,EAAE,MAAM,CAA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,MAAM,IAAI,CAAC;CAC5C;AAED,wBAAgB,gBAAgB,CAAC,GAAG,EAAE,OAAO,GAAG,mBAAmB,CASlE;AAGD,OAAO,QAAQ,aAAa,CAAC;IAC3B,UAAU,cAAc;QACtB,MAAM,EAAE,aAAa,CAAC;KACvB;CACF"}
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* @aalis/api-doctor — 诊断子系统的公共类型与消费者帮手
|
|
3
|
+
*
|
|
4
|
+
* 设计动机:
|
|
5
|
+
* plugin-doctor 是开放注册中心(DoctorService.registerCheck)。其它插件应
|
|
6
|
+
* 贡献自己领域的检查项(例如 storage 检查存储根可写、commands 检查指令
|
|
7
|
+
* 覆盖配置是否孤立),而不是把所有逻辑塞回 doctor 内部。
|
|
8
|
+
*
|
|
9
|
+
* 为避免 storage/commands 等下游插件直接 runtime depend 实现包 plugin-doctor
|
|
10
|
+
* (会形成「实现包 ↔ 业务插件」的双向耦合),仿照 api-storage /
|
|
11
|
+
* api-commands 的模式抽出本 api 包,仅含类型 + 一个 useDoctorService
|
|
12
|
+
* helper(懒注册、doctor 未上线时延后到 whenService 触发)。
|
|
13
|
+
*
|
|
14
|
+
* AalisEvents 的模块增强统一在本文件做,避免多包
|
|
15
|
+
* 重复声明导致 TS 合并冲突。
|
|
16
|
+
*/
|
|
17
|
+
export function useDoctorService(ctx) {
|
|
18
|
+
return {
|
|
19
|
+
registerCheck(spec) {
|
|
20
|
+
const filledSpec = { pluginName: ctx.id ?? spec.pluginName, ...spec };
|
|
21
|
+
// 持续订阅 'doctor':服务每次上线都重新挂 check;下线/dispose 时 whenService
|
|
22
|
+
// 自动调用上次 cb 返回的解注册函数。
|
|
23
|
+
return ctx.whenService('doctor', svc => svc.registerCheck(filledSpec));
|
|
24
|
+
},
|
|
25
|
+
};
|
|
26
|
+
}
|
|
27
|
+
//# sourceMappingURL=index.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;GAeG;AAiFH,MAAM,UAAU,gBAAgB,CAAC,GAAY;IAC3C,OAAO;QACL,aAAa,CAAC,IAAe;YAC3B,MAAM,UAAU,GAAc,EAAE,UAAU,EAAE,GAAG,CAAC,EAAE,IAAI,IAAI,CAAC,UAAU,EAAE,GAAG,IAAI,EAAE,CAAC;YACjF,0DAA0D;YAC1D,sBAAsB;YACtB,OAAO,GAAG,CAAC,WAAW,CAAgB,QAAQ,EAAE,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,aAAa,CAAC,UAAU,CAAC,CAAC,CAAC;QACxF,CAAC;KACF,CAAC;AACJ,CAAC"}
|
package/package.json
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@aalis/api-doctor",
|
|
3
|
+
"version": "0.5.0",
|
|
4
|
+
"license": "MIT",
|
|
5
|
+
"repository": {
|
|
6
|
+
"type": "git",
|
|
7
|
+
"url": "git+https://github.com/AalisLabs/Aalis.git",
|
|
8
|
+
"directory": "packages/api-doctor"
|
|
9
|
+
},
|
|
10
|
+
"author": "Ace Nyan <ace@acenyan.com>",
|
|
11
|
+
"bugs": {
|
|
12
|
+
"url": "https://github.com/AalisLabs/Aalis/issues"
|
|
13
|
+
},
|
|
14
|
+
"homepage": "https://github.com/AalisLabs/Aalis#readme",
|
|
15
|
+
"type": "module",
|
|
16
|
+
"main": "dist/index.js",
|
|
17
|
+
"types": "dist/index.d.ts",
|
|
18
|
+
"files": [
|
|
19
|
+
"dist"
|
|
20
|
+
],
|
|
21
|
+
"devDependencies": {
|
|
22
|
+
"@types/node": "^22.0.0",
|
|
23
|
+
"typescript": "^5.7.0",
|
|
24
|
+
"@aalis/core": "0.10.0"
|
|
25
|
+
},
|
|
26
|
+
"aalis": {
|
|
27
|
+
"types": true
|
|
28
|
+
},
|
|
29
|
+
"peerDependencies": {
|
|
30
|
+
"@aalis/core": ">=0.2.0 <1.0.0"
|
|
31
|
+
},
|
|
32
|
+
"keywords": [
|
|
33
|
+
"aalis",
|
|
34
|
+
"aalis-api"
|
|
35
|
+
],
|
|
36
|
+
"scripts": {
|
|
37
|
+
"build": "tsc",
|
|
38
|
+
"dev": "tsc --watch"
|
|
39
|
+
}
|
|
40
|
+
}
|