{"version":3,"sources":["/home/mkabumattar/work/withrawi/rawi/dist/chunk-TN3YZIMQ.cjs","../src/core/file-readers/managers/file-reader.manager.ts"],"names":["FileReaderManager","#readers","#options","#batchProcessor","options","#initializeReaders","BatchFileProcessor","officeReader","OfficeReader","officeFileTypes","fileType","textReader","TextReader","textFileTypes","filePath","#determineFileType","isSupportedFileType","getFileTypeDescription","reader","#getReader"],"mappings":"AAAA;AACA,wDAAwC,wDAAyC,wDAAyC,wDAAuD,ICuBpKA,CAAAA,CAAN,KAAwB,CAC7BC,CAAAA,CAAAA,CACAC,CAAAA,CAAAA,CACAC,CAAAA,CAAAA,CAEA,WAAA,CAAYC,CAAAA,CAAoC,CAAC,CAAA,CAAG,CAClD,IAAA,CAAKF,CAAAA,CAAAA,CAAW,CACd,cAAA,CAAgB,CAAA,CAAA,CAChB,GAAGE,CACL,CAAA,CAEA,IAAA,CAAKH,CAAAA,CAAAA,CAAW,IAAI,GAAA,CACpB,IAAA,CAAKI,CAAAA,CAAAA,CAAmB,CAAA,CACxB,IAAA,CAAKF,CAAAA,CAAAA,CAAkB,IAAIG,wBAAAA,CAAmB,IAAI,CACpD,CAEAD,CAAAA,CAAAA,CAAAA,CAA2B,CACzB,IAAME,CAAAA,CAAe,IAAIC,wBAAAA,CAAa,IAAA,CAAKN,CAAAA,CAAQ,CAAA,CAC7CO,CAAAA,CAAkB,CAAA,KAAA,CAAA,MAAA,CAAA,MAAA,CAAA,MAAA,CAAA,KAAA,CAAA,KAAA,CAAA,KAQxB,CAAA,CAEA,GAAA,CAAA,IAAWC,EAAAA,GAAYD,CAAAA,CACrB,IAAA,CAAKR,CAAAA,CAAAA,CAAS,GAAA,CAAIS,CAAAA,CAAUH,CAAY,CAAA,CAG1C,IAAMI,CAAAA,CAAa,IAAIC,wBAAAA,CAAW,IAAA,CAAKV,CAAAA,CAAQ,CAAA,CACzCW,CAAAA,CAAgB,CAAA,KAAA,CAAA,IAAA,CAAA,KAAA,CAAA,MAAA,CAAA,KAAA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\n  BatchProcessingSummary,\n  FileReaderOptions,\n  FileReaderResult,\n  GlobOptions,\n  SupportedFileType,\n} from '../interfaces/types.js';\nimport {SupportedFileType as FileType} from '../interfaces/types.js';\nimport type {AbstractFileReader} from '../readers/base.reader.js';\nimport {OfficeReader} from '../readers/office.reader.js';\nimport {TextReader} from '../readers/text.reader.js';\nimport {BatchFileProcessor} from '../utils/batch-processor.js';\nimport {\n  detectFileType,\n  getFileTypeDescription,\n  isSupportedFileType,\n} from '../utils/file-type.detector.js';\n\nexport interface FileReaderManagerOptions extends FileReaderOptions {\n  forceFileType?: SupportedFileType;\n  enableFallback?: boolean;\n}\n\nexport class FileReaderManager {\n  #readers: Map<SupportedFileType, AbstractFileReader>;\n  #options: FileReaderManagerOptions;\n  #batchProcessor: BatchFileProcessor;\n\n  constructor(options: FileReaderManagerOptions = {}) {\n    this.#options = {\n      enableFallback: true,\n      ...options,\n    };\n\n    this.#readers = new Map();\n    this.#initializeReaders();\n    this.#batchProcessor = new BatchFileProcessor(this);\n  }\n\n  #initializeReaders(): void {\n    const officeReader = new OfficeReader(this.#options);\n    const officeFileTypes = [\n      FileType.PDF,\n      FileType.DOCX,\n      FileType.PPTX,\n      FileType.XLSX,\n      FileType.ODT,\n      FileType.ODP,\n      FileType.ODS,\n    ];\n\n    for (const fileType of officeFileTypes) {\n      this.#readers.set(fileType, officeReader);\n    }\n\n    const textReader = new TextReader(this.#options);\n    const textFileTypes = [\n      FileType.TXT,\n      FileType.MD,\n      FileType.XML,\n      FileType.HTML,\n      FileType.HTM,\n      FileType.JS,\n      FileType.JSX,\n      FileType.TS,\n      FileType.TSX,\n      FileType.CSS,\n      FileType.JSON,\n      FileType.PY,\n      FileType.JAVA,\n      FileType.CPP,\n      FileType.C,\n      FileType.H,\n      FileType.GO,\n      FileType.RS,\n      FileType.RB,\n      FileType.KT,\n      FileType.SWIFT,\n      FileType.DART,\n      FileType.SCALA,\n      FileType.R,\n      FileType.M,\n      FileType.PL,\n      FileType.LUA,\n      FileType.PHP,\n      FileType.YML,\n      FileType.YAML,\n      FileType.CSV,\n      FileType.TOML,\n      FileType.ENV,\n      FileType.INI,\n      FileType.CONF,\n      FileType.CFG,\n      FileType.SQL,\n      FileType.SH,\n      FileType.BASH,\n      FileType.VIM,\n      FileType.DOCKERFILE,\n      FileType.MAKEFILE,\n      FileType.GITIGNORE,\n      FileType.LOG,\n    ];\n\n    for (const fileType of textFileTypes) {\n      this.#readers.set(fileType, textReader);\n    }\n  }\n\n  async readFile(filePath: string): Promise<FileReaderResult> {\n    try {\n      const fileType = await this.#determineFileType(filePath);\n\n      if (!isSupportedFileType(fileType)) {\n        return {\n          success: false,\n          error: `Unsupported file type: ${getFileTypeDescription(fileType)}. Supported formats include office documents (PDF, DOCX, PPTX, XLSX, ODT, ODP, ODS), programming languages (JS, TS, Python, Java, C/C++, Go, Rust, etc.), configuration files (YAML, JSON, TOML, etc.), and many more.`,\n        };\n      }\n\n      const reader = this.#getReader(fileType);\n      if (!reader) {\n        return {\n          success: false,\n          error: `No reader available for file type: ${getFileTypeDescription(fileType)}`,\n        };\n      }\n\n      this.#logVerbose(\n        `Using ${reader.constructor.name} for ${getFileTypeDescription(fileType)}`,\n      );\n\n      const result = await reader.read(filePath);\n\n      if (result.success && result.content) {\n        result.content.metadata.additionalInfo = {\n          ...result.content.metadata.additionalInfo,\n          detectedFileType: fileType,\n          readerUsed: reader.constructor.name,\n        };\n      }\n\n      return result;\n    } catch (error) {\n      return {\n        success: false,\n        error: `File reading failed: ${error instanceof Error ? error.message : String(error)}`,\n      };\n    }\n  }\n\n  async readFiles(filePaths: string[]): Promise<FileReaderResult[]> {\n    const results: FileReaderResult[] = [];\n\n    for (const filePath of filePaths) {\n      const result = await this.readFile(filePath);\n      results.push(result);\n    }\n\n    return results;\n  }\n\n  async readFilesParallel(filePaths: string[]): Promise<FileReaderResult[]> {\n    const promises = filePaths.map((filePath) => this.readFile(filePath));\n    return Promise.all(promises);\n  }\n\n  async canReadFile(filePath: string): Promise<boolean> {\n    try {\n      const fileType = await this.#determineFileType(filePath);\n      return isSupportedFileType(fileType) && this.#readers.has(fileType);\n    } catch {\n      return false;\n    }\n  }\n\n  async getFileInfo(filePath: string) {\n    const fileType = await this.#determineFileType(filePath);\n\n    return {\n      filePath,\n      fileType,\n      description: getFileTypeDescription(fileType),\n      supported: isSupportedFileType(fileType),\n      readerAvailable: this.#readers.has(fileType),\n    };\n  }\n\n  getSupportedFileTypes(): SupportedFileType[] {\n    return Array.from(this.#readers.keys());\n  }\n\n  registerReader(\n    fileType: SupportedFileType,\n    reader: AbstractFileReader,\n  ): void {\n    this.#readers.set(fileType, reader);\n    this.#logVerbose(\n      `Registered custom reader for ${getFileTypeDescription(fileType)}`,\n    );\n  }\n\n  updateOptions(newOptions: Partial<FileReaderManagerOptions>): void {\n    this.#options = {...this.#options, ...newOptions};\n    this.#initializeReaders();\n    this.#batchProcessor = new BatchFileProcessor(this);\n    this.#logVerbose('Updated reader options and reinitialized readers');\n  }\n\n  async processMultipleFiles(\n    filePaths: string[],\n    options: BatchProcessingOptions = {},\n  ): Promise<BatchProcessingSummary> {\n    return this.#batchProcessor.processFiles(filePaths, options);\n  }\n\n  async processGlobPatterns(\n    patterns: string[],\n    options: BatchProcessingOptions & GlobOptions = {},\n  ): Promise<BatchProcessingSummary> {\n    return this.#batchProcessor.processGlobPatterns(patterns, options);\n  }\n\n  async expandGlob(\n    patterns: string[],\n    options: GlobOptions = {},\n  ): Promise<string[]> {\n    return this.#batchProcessor.expandGlobPatterns(patterns, options);\n  }\n\n  async filterSupportedFiles(filePaths: string[]): Promise<string[]> {\n    return this.#batchProcessor.filterSupportedFiles(filePaths);\n  }\n\n  async #determineFileType(filePath: string): Promise<SupportedFileType> {\n    if (this.#options.forceFileType) {\n      return this.#options.forceFileType;\n    }\n\n    const detection = await detectFileType(filePath);\n    return detection.fileType;\n  }\n\n  #getReader(fileType: SupportedFileType): AbstractFileReader | undefined {\n    return this.#readers.get(fileType);\n  }\n\n  #logVerbose(message: string): void {\n    if (this.#options.verbose) {\n      console.log(`[FileReaderManager] ${message}`);\n    }\n  }\n}\n\nexport const defaultFileReaderManager = new FileReaderManager();\n"]}