- 新增 config-contract 模块(TypeBox fragments、Ajv 契约校验、ConfigValidationIssue) - CheckerDefinition 扩展为含 configKey、schemas、validate 的完整插件接口 - HTTP/Command 各自维护 contract.ts + validate.ts,校验从 resolve 中分离 - resolve 不再承担校验,只做默认值合并和路径/单位解析 - config-loader 流程: unknown → RawProbeConfig → ValidatedProbeConfig → ResolvedConfig - 导出 probe-config.schema.json,新增 schema/schema:check 脚本 - 更新 DEVELOPMENT.md 新增 1.7 开发新 Checker 完整指引 - 同步更新 4 个 main specs(probe-config、command-checker、expect-body-checkers、checker-runner-abstraction)
35 lines
873 B
TypeScript
35 lines
873 B
TypeScript
import type { CheckerDefinition } from "./types";
|
|
|
|
export class CheckerRegistry {
|
|
get definitions(): CheckerDefinition[] {
|
|
return [...this.checkers.values()];
|
|
}
|
|
|
|
get supportedTypes(): string[] {
|
|
return [...this.checkers.keys()];
|
|
}
|
|
|
|
private checkers = new Map<string, CheckerDefinition>();
|
|
|
|
get(type: string): CheckerDefinition {
|
|
const checker = this.checkers.get(type);
|
|
if (!checker) {
|
|
throw new Error(`不支持的 probe type: "${type}"`);
|
|
}
|
|
return checker;
|
|
}
|
|
|
|
register(checker: CheckerDefinition): void {
|
|
if (this.checkers.has(checker.type)) {
|
|
throw new Error(`Checker type "${checker.type}" 已注册`);
|
|
}
|
|
this.checkers.set(checker.type, checker);
|
|
}
|
|
|
|
tryGet(type: string): CheckerDefinition | undefined {
|
|
return this.checkers.get(type);
|
|
}
|
|
}
|
|
|
|
export const checkerRegistry = new CheckerRegistry();
|