or run

tessl search
Log in

Version

Files

tile.json

task.mdevals/scenario-9/

Configuration Manager

Build a configuration management system that safely combines default settings with user-provided overrides without modifying the original configuration objects.

Requirements

Your task is to implement a configuration manager that:

  1. Accepts default configuration objects and user override objects
  2. Merges them to create a final configuration without mutating the inputs
  3. Handles deeply nested configuration structures
  4. Returns a new merged configuration object

The system should work with configuration objects that can have multiple levels of nesting, and later configurations should override earlier ones at the primitive value level while preserving nested object structures.

Implementation

@generates

API

/**
 * Creates a merged configuration from defaults and user overrides
 * @param {Object} defaults - The default configuration object
 * @param {Object} userConfig - User-provided configuration overrides
 * @returns {Object} A new merged configuration object
 */
function createConfig(defaults, userConfig);

/**
 * Merges multiple configuration sources into a single configuration
 * @param {...Object} configs - Multiple configuration objects to merge
 * @returns {Object} A new merged configuration object
 */
function mergeConfigs(...configs);

Test Cases

Basic non-mutating merge

  • Given defaults = { api: { timeout: 5000 } } and overrides = { api: { retries: 3 } }, calling createConfig(defaults, overrides) returns a new object { api: { timeout: 5000, retries: 3 } } and the defaults object remains unchanged @test

Multiple level nesting

  • Given default config with nested structure { server: { port: 3000, ssl: { enabled: false } } } and user config { server: { ssl: { enabled: true, cert: 'path/to/cert' } } }, the merged config contains { server: { port: 3000, ssl: { enabled: true, cert: 'path/to/cert' } } } @test

Multiple configuration sources

  • Given three configs: config1 = { a: 1, b: 2 }, config2 = { b: 3, c: 4 }, and config3 = { a: 5, d: 6 }, calling mergeConfigs(config1, config2, config3) returns { a: 5, b: 3, c: 4, d: 6 } and all input configs remain unchanged @test

Original objects unchanged

  • After merging default config { database: { host: 'localhost', port: 5432 } } with user config { database: { port: 3306 } }, both the original default and user config objects are unmodified @test

Dependencies { .dependencies }

mixin-deep { .dependency }

Provides deep object merging capabilities.