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

Validate on access #10

Open
justsml opened this issue Sep 28, 2022 · 0 comments
Open

Validate on access #10

justsml opened this issue Sep 28, 2022 · 0 comments

Comments

@justsml
Copy link
Contributor

justsml commented Sep 28, 2022

Why

Some applications may prefer to delay evaluation of the validation.

Pros

  • Stack trace leads to the usage location, not the config file.

Cons

  • May hide config problems during development & testing.

Dev notes

Possible implementations:

  • get getter wrapper object?
  • Or ES6 Proxy?

Considerations

  • Set via an option?
    • Per value?
    • Set per config set?

Usage?

Option naming:

  • deferred: true
  • delayed: true
  • validate: 'delayed',
  • validateOn: 'load' | 'access'
  • ?

Some Examples

1/3: Per Config: deferred option

import { autoConfig } from '@elite-libs/auto-config';

const config = autoConfig({
  port: {
    args: ['--port', 'PORT'],
    deferred: true,
    required: true,
  },
});

2/3: autoConfig Instance Default

import { autoConfig } from '@elite-libs/auto-config';

const config = autoConfig({
  port: {
    args: ['--port', 'PORT'],
    required: true,
  },
}, {
  deferred: true
});

3/3: Global Override

import { autoConfig } from '@elite-libs/auto-config';

autoConfig.deferred = true;

const config = autoConfig({
  port: {
    args: ['--port', 'PORT'],
    required: true,
  },
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant