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

Add unscoped variables support #24

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

CheerlessCloud
Copy link
Member

I want add ability to map raw variables without MODULE__ prefix for simplify migration.

In this case config definition will be similar to this:

@UnscopedConfig()
export class LegacyConfig {
  @Env('LEGACY_VARIABLE')
  @String()
  readonly fieldOne: string;
}

For details see changes in README and e2e tests.

@CheerlessCloud CheerlessCloud marked this pull request as ready for review November 7, 2022 15:59
@@ -326,8 +337,8 @@ Library will throw an error on launch application: `Cat.weight received 'not_a_n

## Requirements

1. @nestjs/common ^7.2.0
2. @nestjs/core ^7.2.0
1. @nestjs/common >=7.2.0
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Или "^9.1.4" ?

import { plainToClass } from '../transformer';

export class ConfigFactory {
public createConfig(
configStorage: ConfigStorage,
ConfigClass: ClassType,
): typeof ConfigClass.prototype {
if (ConfigClass[UNSCOPED_CONFIG_SYMBOL]) {
return plainToClass(ConfigClass, configStorage[UNSCOPED_CONFIG_SYMBOL], {
excludeExtraneousValues: true,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there will be different behaviour with @UnscopedConfig and usuall @Config. So after migration could be implicit consequences

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, but without excludeExtraneousValues all envs will be automatically exposed to class instance which is more terrible than the inconsistent behavior. Moreover, I do not understand why this option is not enabled in the @Config mode. And, I hope, @UnscopedConfig is more for migration cases than for everyday use, because implementation is one big workaround.

I think we should describe excludeExtraneousValues behavior in readme of @UnscopedConfig and enable it for @Config in next major version.

P.S. But in general, you gave me a strange idea how to reduce workaroundness of this solution, I'll try to implement it.

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

Successfully merging this pull request may close these issues.

3 participants