unified-error-handling
Version:
A lightweight, zero-dependency error handling library with dynamic adapter loading for multiple error tracking services
90 lines • 3.08 kB
TypeScript
/**
* Configuration merging utilities
*
* This module provides utilities for merging user configurations with defaults,
* ensuring that user-provided values always take precedence.
*/
import type { UnifiedErrorConfig, ErrorProviderType } from '../types';
/**
* Deep merge two objects, with source taking precedence over target
*/
export declare function deepMerge<T extends Record<string, any>>(target: T, source: Partial<T>): T;
/**
* Merge user configuration with defaults
*/
export declare function mergeWithDefaults(userConfig: Partial<UnifiedErrorConfig>, environment?: 'development' | 'staging' | 'production'): UnifiedErrorConfig;
/**
* Merge provider-specific configuration
*/
export declare function mergeProviderConfig<T extends Record<string, any>>(providerType: ErrorProviderType, userConfig: Partial<T>): T;
/**
* Check if a configuration value is user-provided (not default)
*/
export declare function isUserProvided<T>(userConfig: Partial<T>, defaultConfig: T, key: keyof T): boolean;
/**
* Get configuration diff between user config and defaults
*/
export declare function getConfigDiff<T extends Record<string, any>>(userConfig: Partial<T>, defaultConfig: T): Partial<T>;
/**
* Validate that user configuration only contains valid keys
*/
export declare function validateConfigKeys<T extends Record<string, any>>(userConfig: Partial<T>, validKeys: (keyof T)[]): {
isValid: boolean;
invalidKeys: string[];
};
/**
* Create a configuration builder for fluent API
*/
export declare class ConfigBuilder {
private config;
constructor(provider?: ErrorProviderType);
/**
* Set the error provider
*/
withProvider(provider: ErrorProviderType): this;
/**
* Set the environment
*/
withEnvironment(environment: 'development' | 'staging' | 'production'): this;
/**
* Enable debug mode
*/
withDebug(debug?: boolean): this;
/**
* Set sample rate
*/
withSampleRate(rate: number): this;
/**
* Set maximum breadcrumbs
*/
withMaxBreadcrumbs(max: number): this;
/**
* Enable offline support
*/
withOfflineSupport(enabled?: boolean): this;
/**
* Set provider-specific configuration
*/
withProviderConfig<T>(providerConfig: Partial<T>): this;
/**
* Set ignored errors
*/
withIgnoredErrors(errors: (string | RegExp)[]): this;
/**
* Build the final configuration
*/
build(): UnifiedErrorConfig;
}
/**
* Create a new configuration builder
*/
export declare function createConfigBuilder(provider?: ErrorProviderType): ConfigBuilder;
/**
* Create a configuration for a specific environment
*/
export declare function createEnvironmentConfig(environment: 'development' | 'staging' | 'production', overrides?: Partial<UnifiedErrorConfig>): UnifiedErrorConfig;
/**
* Create a provider-specific configuration
*/
export declare function createProviderConfig<T extends Record<string, any>>(provider: ErrorProviderType, config: Partial<T>): UnifiedErrorConfig;
//# sourceMappingURL=merger.d.ts.map