/** * 配置验证系统 * 提供配置schema验证和默认值处理 */ import { ValidationError } from "./errors.js"; export { ValidationError }; export interface Choice { label: string; value: T; } export interface ValidationRule { required?: boolean; type?: "string" | "number" | "boolean" | "object" | "array"; min?: number; max?: number; pattern?: RegExp; /** 带展示文案的枚举选项(Web 下拉据此渲染) */ choices?: Array>; /** choices 只作为建议,允许列表中出现额外的自定义字符串。 */ allowCustomValues?: boolean; /** * 自定义校验:返回 true / null / undefined 表示通过; * 返回 false 或错误文案表示失败 */ validator?: (value: T) => boolean | string | null | undefined; default?: T | (() => T); transform?: (value: unknown) => T; /** 用于表单展示的标签 */ label?: string; /** 用于表单展示的说明 */ description?: string; /** 用于表单展示的占位提示 */ placeholder?: string; /** Web 表单按密码输入展示;仅影响显示,不改变配置值或运行时校验。 */ sensitive?: boolean; /** Web 表单展示元数据,不参与运行时校验。 */ ui?: { widget?: "endpoint-list" | "event-filter" | "choice-list" | "record-list"; /** Web 配置页中的语义分区;布局由消费端统一决定。 */ section?: "transport" | "delivery" | "credentials" | "filter" | "advanced"; itemLabel?: string; addLabel?: string; schemes?: string[]; fields?: Array<{ key: string; label: string; type?: "string" | "number" | "boolean"; choices?: Array>; placeholder?: string; description?: string; sensitive?: boolean; /** 相对于同一列表项的字段显示条件。 */ visibleWhen?: { path: string; oneOf: Array; }; }>; eventFields?: Array<{ path: string; label: string; choices?: Array; }>; /** 仅当同一 Schema 根下的依赖字段命中任一值时展示并保存。 */ visibleWhen?: { path: string; oneOf: Array; }; /** 当前字段缺失时,按同一 Schema 根下已存在的字段推断初始选择。 */ inferValueFromPresence?: Array<{ path: string; value: string | number | boolean; }>; }; } export type Schema = { [key: string]: ValidationRule | Schema; }; /** 判断 Schema 节点是否为字段规则,而不是嵌套对象。 */ export declare function isValidationRule(value: ValidationRule | Schema): value is ValidationRule; /** * 校验供管理端生成表单的 Schema 元数据。 * * 适配器注册边界调用本函数,使缺失分区、悬空显示依赖或泄露敏感凭据的错误 * 在插件加载时立即失败,而不是退化成难以维护的通用 JSON 输入。 */ export declare function assertSchemaFormContract(schema: Schema): void; /** * 配置验证器 */ export declare class ConfigValidator { /** * 验证配置对象 */ static validate>(config: T, schema: Schema, path?: string): T; /** * 检查类型 */ private static checkType; /** * 验证并应用默认值 */ static validateWithDefaults>(config: Partial, schema: Schema): T; } /** * BaseApp 配置 Schema */ export declare const BaseAppConfigSchema: Schema;