Skip to content

Validate on access #10

Description

@justsml

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,
  },
});

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions