/** * 安全检查工具 * 用于防止误操作删库等危险行为 */ import type { DbConfig, PermissionType } from '../types/adapter.js'; /** * 操作类型到 SQL 关键字的映射 */ type SqlOperationPermission = Exclude; /** * Dangerous keywords that are NOT in OPERATION_KEYWORDS but should be * explicitly blocked unless `ddl` permission is granted. These are * administrative operations that could compromise security. * * Defense-in-depth list — `detectOperationType` does NOT match these, so * callers must explicitly check `hasAnyDangerousKeyword` before execution. */ export declare const DANGEROUS_ADMIN_KEYWORDS: readonly string[]; /** * 解析配置得到最终权限列表 */ export declare function resolvePermissions(config: DbConfig): PermissionType[]; /** * 检查 SQL 语句是否包含写操作 * @param query - 待检查的 SQL 语句 * @returns 如果包含写操作返回 true */ export declare function isWriteOperation(query: string): boolean; /** * 检测查询的操作类型 * 检测每条语句的第一个关键字以确定其类型。 * 多语句脚本中,所有语句都会被检测。 */ export declare function detectOperationType(query: string): { type: SqlOperationPermission; keyword: string; } | null; /** * 验证查询是否允许执行 * @param query - 待执行的查询 * @param configOrAllowWrite - DbConfig 对象或 allowWrite 布尔值(向后兼容) * @throws 如果查询被拒绝,抛出带有中文提示的错误 */ export declare function validateQuery(query: string, configOrAllowWrite: DbConfig | boolean): void; /** * 获取查询中的危险关键字(用于日志记录) * @param query - SQL 查询语句 * @returns 找到的危险关键字数组 */ export declare function getDangerousKeywords(query: string): string[]; /** * 格式化权限列表用于显示 * * 注意: labels 使用 Partial,因为 'script' / 'batch' 不是核心操作类型 * 而是 opt-in 工具权限 —— 它们在显示时仍然需要有可读的中文标签。 */ export declare function formatPermissions(permissions: PermissionType[]): string; export {}; //# sourceMappingURL=safety.d.ts.map