UNPKG

@syntropysoft/praetorian

Version:

Praetorian CLI – A universal multi-environment configuration validator for DevSecOps teams. Validate, compare, and secure YAML/ENV files with ease.

78 lines 2.92 kB
"use strict"; /** * TODO: DECLARATIVE PROGRAMMING PATTERN * * This file demonstrates excellent declarative programming practices: * - Pure functions with functional array methods (find, flatMap, some) * - Immutable data handling with spread operator * - Strategy pattern with adapter selection * - No imperative loops or state mutations * - Clear data transformations with join() * - Factory pattern with static methods * * Mutation Score: 94.74% - Declarative patterns make testing straightforward! */ Object.defineProperty(exports, "__esModule", { value: true }); exports.FileAdapterFactory = void 0; const YamlFileAdapter_1 = require("./readers/YamlFileAdapter"); const JsonFileAdapter_1 = require("./readers/JsonFileAdapter"); const EnvFileAdapter_1 = require("./readers/EnvFileAdapter"); const TomlFileAdapter_1 = require("./readers/TomlFileAdapter"); const IniFileAdapter_1 = require("./readers/IniFileAdapter"); const XmlFileAdapter_1 = require("./readers/XmlFileAdapter"); const PropertiesFileAdapter_1 = require("./readers/PropertiesFileAdapter"); const HclFileAdapter_1 = require("./readers/HclFileAdapter"); const PlistFileAdapterV2_1 = require("./readers/PlistFileAdapterV2"); class FileAdapterFactory { /** * Get the appropriate adapter for a file */ static getAdapter(filePath) { const adapter = this.adapters.find(adapter => adapter.canHandle(filePath)); if (!adapter) { const supportedExtensions = this.adapters .flatMap(adapter => adapter.getSupportedExtensions()) .join(', '); throw new Error(`Unsupported file format: ${filePath}. ` + `Supported extensions: ${supportedExtensions}`); } return adapter; } /** * Get all supported file extensions */ static getSupportedExtensions() { return this.adapters.flatMap(adapter => adapter.getSupportedExtensions()); } /** * Get all available adapters */ static getAllAdapters() { return [...this.adapters]; } /** * Register a new adapter */ static registerAdapter(adapter) { this.adapters.push(adapter); } /** * Check if a file format is supported */ static isSupported(filePath) { return this.adapters.some(adapter => adapter.canHandle(filePath)); } } exports.FileAdapterFactory = FileAdapterFactory; FileAdapterFactory.adapters = [ new YamlFileAdapter_1.YamlFileAdapter(), new JsonFileAdapter_1.JsonFileAdapter(), new EnvFileAdapter_1.EnvFileAdapter(), new TomlFileAdapter_1.TomlFileAdapter(), new IniFileAdapter_1.IniFileAdapter(), new XmlFileAdapter_1.XmlFileAdapter(), new PropertiesFileAdapter_1.PropertiesFileAdapter(), new HclFileAdapter_1.HclFileAdapter(), new PlistFileAdapterV2_1.PlistFileAdapterV2(), ]; //# sourceMappingURL=FileAdapterFactory.js.map