UNPKG

hypershield

Version:

Middleware suite for high-performance and resilient APIs

48 lines 3.26 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.ConfigValidator = void 0; class ConfigValidator { static validate(config) { return { cache: this.validateCacheConfig(config.cache), compression: this.validateCompressionConfig(config.compression), metrics: this.validateMetricsConfig(config.metrics) }; } static validateCacheConfig(config) { var _a, _b, _c, _d, _e, _f, _g, _h, _j, _k; return { enabled: (_a = config === null || config === void 0 ? void 0 : config.enabled) !== null && _a !== void 0 ? _a : false, provider: (_b = config === null || config === void 0 ? void 0 : config.provider) !== null && _b !== void 0 ? _b : 'memory', ttl: (_c = config === null || config === void 0 ? void 0 : config.ttl) !== null && _c !== void 0 ? _c : 3600, connection: { host: (_e = (_d = config === null || config === void 0 ? void 0 : config.connection) === null || _d === void 0 ? void 0 : _d.host) !== null && _e !== void 0 ? _e : 'localhost', port: (_g = (_f = config === null || config === void 0 ? void 0 : config.connection) === null || _f === void 0 ? void 0 : _f.port) !== null && _g !== void 0 ? _g : 6379, password: (_h = config === null || config === void 0 ? void 0 : config.connection) === null || _h === void 0 ? void 0 : _h.password }, maxRetries: (_j = config === null || config === void 0 ? void 0 : config.maxRetries) !== null && _j !== void 0 ? _j : 3, retryDelay: (_k = config === null || config === void 0 ? void 0 : config.retryDelay) !== null && _k !== void 0 ? _k : 1000 }; } static validateCompressionConfig(config) { var _a, _b, _c, _d; return { enabled: (_a = config === null || config === void 0 ? void 0 : config.enabled) !== null && _a !== void 0 ? _a : true, type: (_b = config === null || config === void 0 ? void 0 : config.type) !== null && _b !== void 0 ? _b : 'gzip', level: (_c = config === null || config === void 0 ? void 0 : config.level) !== null && _c !== void 0 ? _c : 6, threshold: (_d = config === null || config === void 0 ? void 0 : config.threshold) !== null && _d !== void 0 ? _d : 1024 }; } static validateMetricsConfig(config) { var _a, _b, _c, _d, _e; return { enabled: (_a = config === null || config === void 0 ? void 0 : config.enabled) !== null && _a !== void 0 ? _a : false, path: (_b = config === null || config === void 0 ? void 0 : config.path) !== null && _b !== void 0 ? _b : '/metrics', prefix: (_c = config === null || config === void 0 ? void 0 : config.prefix) !== null && _c !== void 0 ? _c : 'hypershield_', collectDefaultMetrics: (_d = config === null || config === void 0 ? void 0 : config.collectDefaultMetrics) !== null && _d !== void 0 ? _d : true, defaultLabels: (_e = config === null || config === void 0 ? void 0 : config.defaultLabels) !== null && _e !== void 0 ? _e : {} }; } } exports.ConfigValidator = ConfigValidator; //# sourceMappingURL=validator.js.map