UNPKG

sca-tool

Version:

Universal static code analysis tool for calculating API operation costs across multiple frameworks (NestJS, Express, Fastify)

321 lines 9.39 kB
export interface AnalyzerConfig { /** Database operation cost definitions */ operations: Record<string, number>; /** Pattern matching rules for different frameworks */ patterns: { [frameworkName: string]: { pattern: string | RegExp; operations?: Record<string, number>; defaultCost?: number; description?: string; }; }; /** Parallel execution patterns to detect */ parallelExecutionPatterns: string[]; /** Patterns to ignore during analysis */ ignorePatterns: string[]; /** Cost multipliers for different code structures */ costMultipliers: { loop: number; recursion: number; nested: number; conditional: number; }; /** Expected costs for validation (optional) */ methodCosts?: { [methodName: string]: { paths?: Array<{ name: string; conditions?: string[]; expectedCost: number; }>; expectedCost?: number; }; }; /** Output configuration */ output?: OutputConfig; /** Analysis configuration */ analysis?: AnalysisConfig; /** Path configuration */ paths?: PathsConfig; /** Editor configuration */ editor?: EditorConfig; } export interface OutputConfig { /** Default output format */ defaultFormat?: 'text' | 'json' | 'markdown' | 'html'; /** Default output directory */ defaultOutputDir?: string; /** File naming configuration */ fileNaming?: { /** Pattern for output files, supports {filename}, {timestamp}, {format} */ pattern?: string; /** Whether to include timestamp in filename */ includeTimestamp?: boolean; }; /** HTML-specific configuration */ html?: HtmlConfig; } export interface HtmlConfig { /** Theme for HTML reports */ theme?: 'light' | 'dark' | 'auto'; /** Whether to include interactive charts */ includeCharts?: boolean; /** Custom CSS to inject */ customCss?: string; /** Custom JavaScript to inject */ customJs?: string; /** Custom title for reports */ title?: string; /** Custom footer text */ footer?: string; /** Whether to open report in browser after generation */ openInBrowser?: boolean; } export interface AnalysisConfig { /** Cost thresholds for categorization */ costThresholds?: { low?: number; medium?: number; high?: number; }; /** Recommendation system configuration */ recommendations?: { enabled?: boolean; customRules?: RecommendationRule[]; }; /** Parallel operation detection */ parallel?: { detectParallelOperations?: boolean; parallelThreshold?: number; }; /** Method filtering */ methodFilters?: { minCost?: number; maxCost?: number; excludePatterns?: string[]; }; } export interface PathsConfig { /** Custom config file path */ configFile?: string; /** Output directory for reports */ outputDir?: string; /** Temporary files directory */ tempDir?: string; /** Cache directory for analysis results */ cacheDir?: string; /** Patterns to exclude from analysis */ excludePatterns?: string[]; /** Patterns to include in analysis */ includePatterns?: string[]; /** Watch mode configuration */ watch?: { debounceMs?: number; excludePatterns?: string[]; }; } export interface RecommendationRule { name: string; condition: (method: MethodAnalysis) => boolean; message: string; priority: 'low' | 'medium' | 'high'; } export interface OutputConfig { /** Default output format */ defaultFormat?: 'text' | 'json' | 'markdown' | 'html'; /** Default output directory */ defaultOutputDir?: string; /** File naming configuration */ fileNaming?: { /** Pattern for output files, supports {filename}, {timestamp}, {format} */ pattern?: string; /** Whether to include timestamp in filename */ includeTimestamp?: boolean; }; /** HTML-specific configuration */ html?: HtmlConfig; } export interface HtmlConfig { /** Theme for HTML reports */ theme?: 'light' | 'dark' | 'auto'; /** Whether to include interactive charts */ includeCharts?: boolean; /** Custom CSS to inject */ customCss?: string; /** Custom JavaScript to inject */ customJs?: string; /** Custom title for reports */ title?: string; /** Custom footer text */ footer?: string; /** Whether to open report in browser after generation */ openInBrowser?: boolean; } export interface AnalysisConfig { /** Cost thresholds for categorization */ costThresholds?: { low?: number; medium?: number; high?: number; }; /** Recommendation system configuration */ recommendations?: { enabled?: boolean; customRules?: RecommendationRule[]; }; /** Parallel operation detection */ parallel?: { detectParallelOperations?: boolean; parallelThreshold?: number; }; /** Method filtering */ methodFilters?: { minCost?: number; maxCost?: number; excludePatterns?: string[]; }; } export interface PathsConfig { /** Custom config file path */ configFile?: string; /** Output directory for reports */ outputDir?: string; /** Temporary files directory */ tempDir?: string; /** Cache directory for analysis results */ cacheDir?: string; /** Patterns to exclude from analysis */ excludePatterns?: string[]; /** Patterns to include in analysis */ includePatterns?: string[]; /** Watch mode configuration */ watch?: { debounceMs?: number; excludePatterns?: string[]; }; } export interface RecommendationRule { name: string; condition: (method: MethodAnalysis) => boolean; message: string; priority: 'low' | 'medium' | 'high'; } export interface EditorConfig { /** Default code editor command */ defaultEditor?: string; /** Detected editor from environment */ detectedEditor?: string; /** Whether to open files in editor after analysis */ openInEditor?: boolean; /** Custom editor commands for different editors */ editorCommands?: { [editorName: string]: { command: string; args?: string[]; supportsLineNumbers?: boolean; lineNumberFormat?: string; name: string; }; }; /** Integration settings */ integration?: { /** Generate .vscode/tasks.json for VS Code integration */ generateVSCodeTasks?: boolean; /** Generate editor-specific configuration files */ generateEditorConfig?: boolean; }; } export interface DatabaseOperation { method: string; cost: number; line: number; conditions: string[]; isParallel?: boolean; expression: string; isComposite?: boolean; framework?: string; } export interface ExecutionPath { name: string; conditions: string[]; operations: DatabaseOperation[]; totalCost: number; description: string; parallelGroups: DatabaseOperation[][]; } export interface MethodAnalysis { methodName: string; className?: string; filePath: string; totalPaths: number; paths: ExecutionPath[]; summary: { minCost: number; maxCost: number; avgCost: number; commonPath: ExecutionPath; expectedCosts?: any; }; recommendations: string[]; } export interface FileAnalysis { filePath: string; fileName: string; methods: MethodAnalysis[]; summary: { totalMethods: number; totalPaths: number; costRange: { min: number; max: number; average: number; }; }; } export interface ProjectAnalysis { projectPath: string; files: FileAnalysis[]; summary: { totalFiles: number; totalMethods: number; totalPaths: number; costDistribution: { low: number; medium: number; high: number; }; optimizationOpportunities: OptimizationOpportunity[]; }; generatedAt: string; } export interface OptimizationOpportunity { file: string; method: string; type: 'high_variance' | 'high_cost' | 'parallelization' | 'caching' | 'batching'; description: string; priority: 'low' | 'medium' | 'high'; suggestion?: string; } export interface FrameworkPreset { name: string; description: string; config: Partial<AnalyzerConfig>; } export interface AnalyzerOptions { /** Custom configuration (overrides preset) */ config?: Partial<AnalyzerConfig>; /** Framework preset to use */ preset?: 'nestjs' | 'express' | 'fastify' | 'custom'; /** Output format */ format?: 'text' | 'json' | 'markdown' | 'html'; /** Include optimization suggestions */ includeRecommendations?: boolean; /** Verbose logging */ verbose?: boolean; /** Watch for file changes */ watch?: boolean; } export type ReportFormat = 'text' | 'json' | 'markdown' | 'html'; export type FrameworkType = 'nestjs' | 'express' | 'fastify' | 'custom'; //# sourceMappingURL=types.d.ts.map