hapipal / confidence

Dynamic, declarative configurations
Other
263 stars 43 forks source link

Share keys above $filter #36

Closed CodisRedding closed 9 years ago

CodisRedding commented 9 years ago

Is it possible to share keys? I find myself repeating keys that I would normally only write once.

example:

var config = {
  api: {
    $filter: 'env',
    production: {
      root: process.env.API_ROOT,
      log_file: './api/hapi.log',
      session_cookie_name: 'sid',
      session_secret: process.env.SESSION_SECRET
    },
    $default: {
      root: process.env.DEV_API_ROOT,
      log_file: './api/hapi.log',
      session_cookie_name: 'sid',
      session_secret: process.env.DEV_SESSION_SECRET
    }
  }
}

Here 'log_file' is repeated. It would be nice if I could put it above the $filter and allow it to share with both 'env''s.

example:

var config = {
  api: {
    log_file: './api/hapi.log',
    $filter: 'env',
    production: {
      root: process.env.API_ROOT,
      session_cookie_name: 'sid',
      session_secret: process.env.SESSION_SECRET
    },
    $default: {
      root: process.env.DEV_API_ROOT,
      session_cookie_name: 'sid',
      session_secret: process.env.DEV_SESSION_SECRET
    }
  }
}
alobodig commented 9 years ago

Property order is not guaranteed in JavaScript, so I don't believe the syntax you suggested is possible.

patrickkettner commented 9 years ago

hey @fourq! Sorry for taking so long to get back to you.

@alobodig is somewhat correct - your syntax is not possible (though we don't iterate over objects, so order has no importance at all to us in this case). The actual issue at hand is that there is nothing stopping log_file from being a value for env. It therefore creates ambiguity as to what the the results should be. That being said, I created something similar using a new $base directive. Check out #37 and let me know what you think

CodisRedding commented 9 years ago

Thanks @alobodig and @patrickkettner

@patrickkettner I just looked over #37 and I think that's a great idea. Looking forward to it!