datapilot-cli
Version:
Enterprise-grade streaming multi-format data analysis with comprehensive statistical insights and intelligent relationship detection - supports CSV, JSON, Excel, TSV, Parquet - memory-efficient, cross-platform
65 lines • 2.09 kB
JavaScript
;
/**
* Universal Data Parser Interface
* Enables multi-format support while maintaining streaming capability
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.BaseParser = void 0;
/**
* Base parser class with common functionality
*/
class BaseParser {
stats;
aborted = false;
options;
constructor(options = {}) {
this.options = options;
this.stats = {
bytesProcessed: 0,
rowsProcessed: 0,
errors: [],
startTime: Date.now(),
format: this.getFormatName(),
};
}
getStats() {
return { ...this.stats, endTime: Date.now() };
}
abort() {
this.aborted = true;
}
async validate(filePath) {
try {
const detection = await this.detect(filePath);
return {
valid: detection.confidence > 0.8,
errors: detection.confidence > 0.8 ? [] : [`Not a valid ${this.getFormatName()} file`],
warnings: detection.confidence < 0.9 && detection.confidence > 0.8
? [`Low confidence detection for ${this.getFormatName()}`]
: [],
canProceed: detection.confidence > 0.5,
suggestedFixes: detection.confidence < 0.8
? [`Try specifying format explicitly: --format ${this.getFormatName()}`]
: [],
};
}
catch (error) {
return {
valid: false,
errors: [error.message],
warnings: [],
canProceed: false,
suggestedFixes: ['Check file format and try again'],
};
}
}
addError(row, message, code, column) {
this.stats.errors.push({ row, column, message, code });
}
updateStats(bytesProcessed, rowsProcessed) {
this.stats.bytesProcessed += bytesProcessed;
this.stats.rowsProcessed += rowsProcessed;
}
}
exports.BaseParser = BaseParser;
//# sourceMappingURL=data-parser.js.map