Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable Computed Cfgu Properties #337

Open
rannn505 opened this issue Jan 2, 2024 · 0 comments
Open

Enable Computed Cfgu Properties #337

rannn505 opened this issue Jan 2, 2024 · 0 comments
Labels
feat New feature or request

Comments

@rannn505
Copy link
Contributor

rannn505 commented Jan 2, 2024

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);
@rannn505 rannn505 added the feat New feature or request label Jan 2, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
feat New feature or request
Projects
None yet
Development

No branches or pull requests

1 participant