All files / src/rendering renderer-config.js

69.59% Statements 103/148
100% Branches 5/5
62.5% Functions 5/8
69.59% Lines 103/148

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 1601x 1x 1x 1x 1x 1x       1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x   1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x   1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x   1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x   1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x   1x 1x 1x 1x                                                   1x 1x 1x 1x           1x 1x 1x 1x                                     1x 1x 1x 1x 1x 1x 1x 1x 1x 1x  
/**
 * Renderer Configuration Utilities
 * 
 * Provides helper functions for working with unified renderer configuration
 * across HTML, Streaming, and DOM renderers.
 */
 
import { DEFAULT_RENDERER_CONFIG } from './base-renderer.js';
 
/**
 * Create configuration optimized for HTML rendering
 */
export function createHtmlConfig(options = {}) {
    return {
        ...DEFAULT_RENDERER_CONFIG,
        // HTML-specific optimizations
        enableCache: true,
        enableMonitoring: true,
        minify: false,
        maxDepth: 100,
        ...options
    };
}
 
/**
 * Create configuration optimized for streaming rendering
 */
export function createStreamingConfig(options = {}) {
    return {
        ...DEFAULT_RENDERER_CONFIG,
        // Streaming-specific optimizations
        maxDepth: 1000,
        enableMetrics: true,
        chunkSize: 1024,
        bufferSize: 4096,
        yieldThreshold: 100,
        encoding: 'utf8',
        ...options
    };
}
 
/**
 * Create configuration optimized for DOM rendering
 */
export function createDomConfig(options = {}) {
    return {
        ...DEFAULT_RENDERER_CONFIG,
        // DOM-specific optimizations
        enableHydration: true,
        maxDepth: 100,
        namespace: null,
        ...options
    };
}
 
/**
 * Create development-friendly configuration with debugging enabled
 */
export function createDevConfig(options = {}) {
    return {
        ...DEFAULT_RENDERER_CONFIG,
        // Development optimizations
        enableDevWarnings: true,
        enableDebugLogging: true,
        enablePerformanceTracking: true,
        enableMonitoring: true,
        throwOnError: true,
        ...options
    };
}
 
/**
 * Create production-optimized configuration
 */
export function createProdConfig(options = {}) {
    return {
        ...DEFAULT_RENDERER_CONFIG,
        // Production optimizations
        enableDevWarnings: false,
        enableDebugLogging: false,
        enableCache: true,
        minify: true,
        enablePerformanceTracking: false,
        throwOnError: false,
        errorFallback: '<!-- Render Error -->',
        ...options
    };
}
 
/**
 * Validate configuration object
 */
export function validateConfig(config) {
    const errors = [];
    
    if (config.maxDepth !== undefined && (typeof config.maxDepth !== 'number' || config.maxDepth <= 0)) {
        errors.push('maxDepth must be a positive number');
    }
    
    if (config.chunkSize !== undefined && (typeof config.chunkSize !== 'number' || config.chunkSize <= 0)) {
        errors.push('chunkSize must be a positive number');
    }
    
    if (config.yieldThreshold !== undefined && (typeof config.yieldThreshold !== 'number' || config.yieldThreshold <= 0)) {
        errors.push('yieldThreshold must be a positive number');
    }
    
    if (config.encoding !== undefined && config.encoding && !['utf8', 'ascii', 'base64', 'hex'].includes(config.encoding)) {
        errors.push('encoding must be one of: utf8, ascii, base64, hex');
    }
    
    if (errors.length > 0) {
        throw new Error(`Configuration validation failed:\n${errors.join('\n')}`);
    }
    
    return true;
}
 
/**
 * Merge multiple configuration objects with validation
 */
export function mergeConfigs(...configs) {
    const merged = configs.reduce((acc, config) => ({ ...acc, ...config }), {});
    validateConfig(merged);
    return merged;
}
 
/**
 * Get configuration preset by name
 */
export function getConfigPreset(preset, options = {}) {
    switch (preset) {
        case 'html':
            return createHtmlConfig(options);
        case 'streaming':
            return createStreamingConfig(options);
        case 'dom':
            return createDomConfig(options);
        case 'dev':
        case 'development':
            return createDevConfig(options);
        case 'prod':
        case 'production':
            return createProdConfig(options);
        default:
            throw new Error(`Unknown configuration preset: ${preset}`);
    }
}
 
/**
 * Configuration presets for easy access
 */
export const CONFIG_PRESETS = {
    html: createHtmlConfig(),
    streaming: createStreamingConfig(),
    dom: createDomConfig(),
    dev: createDevConfig(),
    prod: createProdConfig()
};