/** * Request-scoped scan state for tracking pre-scanner results. * Uses the sidecar pattern to collect issues during scanning. * * @module pre-scanner/scan-state */ import type { PreScannerErrorCode } from './errors'; /** * Severity levels for pre-scan issues */ export type PreScanIssueSeverity = 'error' | 'warning' | 'info'; /** * A single issue detected during pre-scanning */ export interface PreScanIssue { /** Error code identifying the issue type */ code: PreScannerErrorCode; /** Severity level */ severity: PreScanIssueSeverity; /** Human-readable message */ message: string; /** Position in source (byte offset) */ position?: number; /** Line number (1-indexed) */ line?: number; /** Column number (1-indexed) */ column?: number; /** Additional context data */ data?: Record; } /** * Regex pattern found during scanning */ export interface DetectedRegex { /** The regex pattern (without flags) */ pattern: string; /** Regex flags */ flags: string; /** Position in source */ position: number; /** Line number */ line: number; /** ReDoS vulnerability score (0-100) */ vulnerabilityScore?: number; /** Type of vulnerability if detected */ vulnerabilityType?: string; } /** * Statistics collected during pre-scanning */ export interface PreScanStats { /** Input size in bytes */ inputSize: number; /** Number of lines */ lineCount: number; /** Maximum line length found */ maxLineLengthFound: number; /** Maximum nesting depth found */ maxNestingDepthFound: number; /** Number of regex literals found */ regexCount: number; /** Total string content size */ totalStringContent: number; /** Number of unicode issues found */ unicodeIssueCount: number; /** Scan duration in milliseconds */ scanDurationMs: number; } /** * Result of a pre-scan operation */ export interface PreScanResult { /** Whether the scan passed (no errors) */ success: boolean; /** All issues found (errors, warnings, info) */ issues: PreScanIssue[]; /** The fatal issue that caused failure (if any) */ fatalIssue?: PreScanIssue; /** Detected regex patterns (for analysis mode) */ detectedRegex: DetectedRegex[]; /** Scan statistics */ stats: PreScanStats; } /** * Mutable scan state for collecting results during scanning. * This is the "sidecar" that accumulates issues as the scanner runs. */ export declare class ScanState { private issues; private detectedRegex; private fatalIssue?; private startTime; private _inputSize; private _lineCount; private _maxLineLengthFound; private _maxNestingDepthFound; private _totalStringContent; private _unicodeIssueCount; constructor(); /** * Report an issue (error/warning/info) */ reportIssue(issue: PreScanIssue): void; /** * Report a fatal error that stops scanning */ reportFatalError(issue: Omit): void; /** * Report a warning */ reportWarning(issue: Omit): void; /** * Report an info message */ reportInfo(issue: Omit): void; /** * Add a detected regex pattern */ addRegex(regex: DetectedRegex): void; /** * Check if scanning should stop (fatal error encountered) */ shouldStop(): boolean; /** * Check if scan is currently passing (no errors) */ isPassing(): boolean; /** * Get all issues of a specific severity */ getIssuesBySeverity(severity: PreScanIssueSeverity): PreScanIssue[]; /** * Get error count */ getErrorCount(): number; /** * Get warning count */ getWarningCount(): number; setInputSize(size: number): void; setLineCount(count: number): void; updateMaxLineLength(length: number): void; updateMaxNestingDepth(depth: number): void; addStringContent(size: number): void; incrementUnicodeIssues(): void; /** * Finalize and return the scan result */ finalize(): PreScanResult; /** * Create a quick failure result for early termination */ static quickFail(issue: Omit): PreScanResult; }