configu / configu

Open-source ConfigOps infrastructure ⚙️

Home Page:https://configu.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Enable Computed Cfgu Properties

rannn505 opened this issue · comments

Suggestion

Introducing the capability for computed values in Cfgu declarations, specifically for properties like default and required. This feature will allow users to provide expressions for these properties, enabling dynamic evaluation based on the context or other configuration values.

When running commands using a Schema with computed Cfgu properties, the expressions will be evaluated to determine the actual value of these properties. This enhancement opens up possibilities for more flexible and context-sensitive configuration setups.

For instance, it could allow for the creation of conditional properties like required-if or computed-default. Consider the following JSON schema example:

{
  "ENABLE_FEAT": {
    "type": "Boolean",
    "default": "{{#$}}return '{{CONFIGU_SET.path}}' == 'production'{{/$}}"
  },
  "FEAT_CONF": {
    "type": "String",
    "required": "{{#$}}return {{ENABLE_FEAT}}{{/$}}" 
  }
  ...
}

In this example:

  • The ENABLE_FEAT boolean property dynamically sets its default value based on whether the CONFIGU_SET.path is 'production'.
  • The FEAT_CONF string property becomes required if ENABLE_FEAT is true.

Motivation

The ability to define computed properties significantly enhances the flexibility and adaptability of the Cfgu declaration. It allows for context-dependent settings, enabling configurations to adapt to different environments or conditions automatically. This feature is particularly beneficial in complex deployment scenarios where configuration needs may vary significantly based on the environment, application state, or other dynamic factors. By implementing computed properties, Configu will offer a more powerful and versatile solution for configuration management, meeting diverse and evolving user needs.

Context

potential implementation for JS (mustache functions api and JS Function constructor):

const Mustache = require('mustache');

const view = {
  title: "Joe",
  calc: () => ( 7 + 7 + 7 ),
  threshold: 11, 
  eval: function () {
    return function (text, render) {
      return Function(render(text))();
    }
  }
};

const output = Mustache.render("{{#eval}} return {{calc}} > {{threshold}} && '{{title}}' === 'Ran' {{/eval}}", view);