@syntropysoft/praetorian
Version:
Praetorian CLI – A universal multi-environment configuration validator for DevSecOps teams. Validate, compare, and secure YAML/ENV files with ease.
80 lines • 2.48 kB
JavaScript
;
/**
* TODO: DECLARATIVE PROGRAMMING PATTERN
*
* This file demonstrates excellent declarative programming practices:
* - Pure functions with clear input/output contracts
* - Functional composition with async/await
* - Immutable data handling
* - Clear separation of concerns
* - No imperative state mutations
* - Error handling with type guards
*
* Mutation Score: 86.36% - Declarative patterns make testing reliable!
*/
Object.defineProperty(exports, "__esModule", { value: true });
exports.FileReaderService = void 0;
const FileAdapterFactory_1 = require("./FileAdapterFactory");
class FileReaderService {
/**
* Read a single file and return its parsed content
*/
async readFile(filePath) {
const adapter = FileAdapterFactory_1.FileAdapterFactory.getAdapter(filePath);
const content = await adapter.read(filePath);
return {
path: filePath,
content,
format: adapter.getFormat(),
metadata: {
encoding: 'utf8'
}
};
}
/**
* Read multiple files and return their parsed contents
*/
async readFiles(filePaths) {
const configFiles = [];
for (const filePath of filePaths) {
try {
const configFile = await this.readFile(filePath);
configFiles.push(configFile);
}
catch (error) {
throw new Error(`Failed to read file ${filePath}: ${error instanceof Error ? error.message : 'Unknown error'}`);
}
}
return configFiles;
}
/**
* Check if a file format is supported
*/
isSupported(filePath) {
return FileAdapterFactory_1.FileAdapterFactory.isSupported(filePath);
}
/**
* Get all supported file extensions
*/
getSupportedExtensions() {
return FileAdapterFactory_1.FileAdapterFactory.getSupportedExtensions();
}
/**
* Validate that all files are supported before reading
*/
validateFiles(filePaths) {
const valid = [];
const invalid = [];
for (const filePath of filePaths) {
if (this.isSupported(filePath)) {
valid.push(filePath);
}
else {
invalid.push(filePath);
}
}
return { valid, invalid };
}
}
exports.FileReaderService = FileReaderService;
//# sourceMappingURL=FileReaderService.js.map