@syntropysoft/praetorian
Version:
Praetorian CLI – A universal multi-environment configuration validator for DevSecOps teams. Validate, compare, and secure YAML/ENV files with ease.
34 lines • 1.2 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.JsonFileAdapter = void 0;
const AbstractFileAdapter_1 = require("../base/AbstractFileAdapter");
class JsonFileAdapter extends AbstractFileAdapter_1.AbstractFileAdapter {
canHandle(filePath) {
return filePath.endsWith('.json');
}
async read(filePath) {
this.validateFileExists(filePath);
try {
const content = await this.readFileContent(filePath);
const parsedContent = JSON.parse(content);
if (typeof parsedContent !== 'object' || parsedContent === null) {
throw new Error(`Invalid JSON content in ${filePath}: expected object, got ${typeof parsedContent}`);
}
return parsedContent;
}
catch (error) {
if (error instanceof SyntaxError) {
throw new Error(`Invalid JSON syntax in ${filePath}: ${error.message}`);
}
throw error;
}
}
getFormat() {
return 'json';
}
getSupportedExtensions() {
return ['.json'];
}
}
exports.JsonFileAdapter = JsonFileAdapter;
//# sourceMappingURL=JsonFileAdapter.js.map