UNPKG

@typecad/kicad-symbols

Version:

Intelligent fuzzy search for KiCad symbols with CLI interface

147 lines 4.8 kB
/** * Extractor for processing KiCad symbol files and extracting symbol definitions * Combines file reading with S-Expression parsing to extract structured symbol data */ import { SymbolDefinition } from './SExpressionParser.js'; import { SymbolFileInfo } from './KiCadSymbolFileScanner.js'; /** * Extended symbol information including file metadata */ export interface ExtractedSymbol extends SymbolDefinition { /** Library name derived from file name */ library: string; /** Source file path */ sourceFile: string; /** Relative path from symbols root */ relativePath: string; /** File last modified date */ fileModified: Date; /** Whether this symbol has a description */ hasDescription: boolean; /** Whether this symbol has keywords */ hasKeywords: boolean; /** Combined search text (description + keywords) */ searchText: string; } /** * Statistics for symbol extraction operation */ export interface ExtractionStatistics { /** Number of files processed */ filesProcessed: number; /** Number of files that failed to process */ filesWithErrors: number; /** Total number of symbols extracted */ symbolsExtracted: number; /** Number of symbols with descriptions */ symbolsWithDescriptions: number; /** Number of symbols with keywords */ symbolsWithKeywords: number; /** Processing time in milliseconds */ processingTime: number; /** List of processing errors */ errors: ExtractionError[]; } /** * Error information for failed extractions */ export interface ExtractionError { /** File that caused the error */ file: string; /** Error message */ message: string; /** Symbol name if applicable */ symbolName?: string; /** Error type */ type: 'parse_error' | 'file_read_error' | 'invalid_format' | 'encoding_error'; } /** * Options for controlling symbol extraction */ export interface ExtractionOptions { /** Whether to include symbols without descriptions */ includeWithoutDescription: boolean; /** Whether to include symbols without keywords */ includeWithoutKeywords: boolean; /** Maximum file size to process in bytes (0 = no limit) */ maxFileSize: number; /** Text encoding to use when reading files */ encoding: BufferEncoding; /** Whether to continue processing on errors */ continueOnError: boolean; /** Validate symbol definitions strictly */ strictValidation: boolean; } /** * KiCad symbol extractor for processing symbol files */ export declare class KiCadSymbolExtractor { private parser; private options; private statistics; constructor(options?: Partial<ExtractionOptions>); /** * Extract symbols from a list of symbol files * @param symbolFiles - Array of symbol file information * @returns Promise resolving to array of extracted symbols */ extractSymbolsFromFiles(symbolFiles: SymbolFileInfo[]): Promise<ExtractedSymbol[]>; /** * Extract symbols from a single file * @param fileInfo - Information about the symbol file * @returns Promise resolving to array of extracted symbols from the file */ extractSymbolsFromFile(fileInfo: SymbolFileInfo): Promise<ExtractedSymbol[]>; /** * Get extraction statistics from the last operation * @returns Extraction statistics */ getStatistics(): ExtractionStatistics; /** * Create an ExtractedSymbol from a SymbolDefinition * @param symbolDef - Symbol definition from parser * @param fileInfo - File information * @param libraryName - Library name derived from file * @returns Extended symbol with metadata * @private */ private createExtractedSymbol; /** * Extract library name from file information * @param fileInfo - File information * @returns Library name * @private */ private extractLibraryName; /** * Check if a symbol should be included based on options * @param symbol - Symbol to check * @returns True if symbol should be included * @private */ private shouldIncludeSymbol; /** * Handle file processing errors * @param fileInfo - File that caused the error * @param error - Error that occurred * @private */ private handleFileError; /** * Reset extraction statistics * @private */ private resetStatistics; /** * Get a human-readable summary of the extraction results * @returns Formatted summary string */ getExtractionSummary(): string; /** * Group errors by type for summary reporting * @returns Object with error counts by type * @private */ private groupErrorsByType; } //# sourceMappingURL=KiCadSymbolExtractor.d.ts.map