taskflow-ai
Version:
TaskFlow AI - 智能PRD文档解析与任务管理助手,支持多模型AI协同、MCP编辑器集成,专为开发团队设计的CLI工具
139 lines (138 loc) • 3.19 kB
TypeScript
/**
* 输入验证系统
* 提供类型安全的输入验证和清理功能
*/
import { JSONValue, JSONObject } from '../../types/strict-types';
/**
* 验证规则接口
*/
export interface ValidationRule {
type: 'string' | 'number' | 'boolean' | 'object' | 'array' | 'email' | 'url' | 'path';
required?: boolean;
min?: number;
max?: number;
pattern?: RegExp;
enum?: JSONValue[];
custom?: (value: JSONValue) => boolean | string;
sanitize?: boolean;
}
/**
* 验证结果接口
*/
export interface ValidationResult {
isValid: boolean;
errors: string[];
sanitizedValue?: JSONValue;
}
/**
* 输入验证器类
*/
export declare class InputValidator {
private static readonly EMAIL_PATTERN;
private static readonly URL_PATTERN;
private static readonly PATH_PATTERN;
/**
* 验证单个值
*/
static validate(value: JSONValue, rule: ValidationRule): ValidationResult;
/**
* 验证对象
*/
static validateObject(obj: JSONObject, schema: Record<string, ValidationRule>): {
isValid: boolean;
errors: Record<string, string[]>;
sanitizedObject?: JSONObject;
};
/**
* 类型验证
*/
private static validateType;
/**
* 范围验证
*/
private static validateRange;
/**
* 字符串清理
*/
private static sanitizeString;
/**
* 验证装饰器
*/
static validateInput(schema: Record<string, ValidationRule>): (target: object, propertyKey: string, descriptor: PropertyDescriptor) => PropertyDescriptor;
}
/**
* 常用验证规则
*/
export declare const CommonValidationRules: {
projectName: {
type: "string";
required: boolean;
min: number;
max: number;
pattern: RegExp;
sanitize: boolean;
};
email: {
type: "email";
required: boolean;
sanitize: boolean;
};
url: {
type: "url";
required: boolean;
sanitize: boolean;
};
apiKey: {
type: "string";
required: boolean;
min: number;
max: number;
pattern: RegExp;
};
language: {
type: "string";
required: boolean;
enum: string[];
};
projectType: {
type: "string";
required: boolean;
enum: string[];
};
filePath: {
type: "path";
required: boolean;
min: number;
max: number;
};
port: {
type: "number";
required: boolean;
min: number;
max: number;
};
timeout: {
type: "number";
required: boolean;
min: number;
max: number;
};
};
/**
* 快速验证函数
*/
export declare function validateProjectName(name: string): void;
export declare function validateEmail(email: string): void;
export declare function validateApiKey(apiKey: string): void;
/**
* 安全字符串清理
*/
export declare function sanitizeInput(input: string): string;
/**
* SQL注入防护
*/
export declare function escapeSql(input: string): string;
/**
* XSS防护
*/
export declare function escapeHtml(input: string): string;