@travetto/config 3.3.1 → 3.3.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -141,7 +141,7 @@ export class EnvConfigSource implements ConfigSource {
141
141
  ```
142
142
 
143
143
  ### Custom Configuration Provider
144
- In addition to files and environment variables, configuration sources can also be provided via the class itself. This is useful for reading remote configurations, or dealing with complex configuration normalization. The only caveat to this pattern, is that the these configuration sources cannot rely on the [Configuration](https://github.com/travetto/travetto/tree/main/module/config/src/configuration.ts#L16) service for input. This means any needed configuration will need to be accessed via specific patterns.
144
+ In addition to files and environment variables, configuration sources can also be provided via the class itself. This is useful for reading remote configurations, or dealing with complex configuration normalization. The only caveat to this pattern, is that the these configuration sources cannot rely on the [ConfigurationService](https://github.com/travetto/travetto/tree/main/module/config/src/service.ts#L16) service for input. This means any needed configuration will need to be accessed via specific patterns.
145
145
 
146
146
  **Code: Custom Configuration Source**
147
147
  ```typescript
@@ -167,10 +167,10 @@ export class CustomConfigSource implements ConfigSource {
167
167
  ```
168
168
 
169
169
  ## Startup
170
- At startup, the [Configuration](https://github.com/travetto/travetto/tree/main/module/config/src/configuration.ts#L16) service will log out all the registered configuration objects. The configuration state output is useful to determine if everything is configured properly when diagnosing runtime errors. This service will find all configurations, and output a redacted version with all secrets removed. The default pattern for secrets is `/password|private|secret/i`. More values can be added in your configuration under the path `config.secrets`. These values can either be simple strings (for exact match), or `/pattern/` to create a regular expression.
170
+ At startup, the [ConfigurationService](https://github.com/travetto/travetto/tree/main/module/config/src/service.ts#L16) service will log out all the registered configuration objects. The configuration state output is useful to determine if everything is configured properly when diagnosing runtime errors. This service will find all configurations, and output a redacted version with all secrets removed. The default pattern for secrets is `/password|private|secret/i`. More values can be added in your configuration under the path `config.secrets`. These values can either be simple strings (for exact match), or `/pattern/` to create a regular expression.
171
171
 
172
172
  ## Consuming
173
- The [Configuration](https://github.com/travetto/travetto/tree/main/module/config/src/configuration.ts#L16) service provides injectable access to all of the loaded configuration. For simplicity, a decorator, [@Config](https://github.com/travetto/travetto/tree/main/module/config/src/decorator.ts#L13) allows for classes to automatically be bound with config information on post construction via the [Dependency Injection](https://github.com/travetto/travetto/tree/main/module/di#readme "Dependency registration/management and injection support.") module. The decorator will install a `postConstruct` method if not already defined, that performs the binding of configuration. This is due to the fact that we cannot rewrite the constructor, and order of operation matters.
173
+ The [ConfigurationService](https://github.com/travetto/travetto/tree/main/module/config/src/service.ts#L16) service provides injectable access to all of the loaded configuration. For simplicity, a decorator, [@Config](https://github.com/travetto/travetto/tree/main/module/config/src/decorator.ts#L13) allows for classes to automatically be bound with config information on post construction via the [Dependency Injection](https://github.com/travetto/travetto/tree/main/module/di#readme "Dependency registration/management and injection support.") module. The decorator will install a `postConstruct` method if not already defined, that performs the binding of configuration. This is due to the fact that we cannot rewrite the constructor, and order of operation matters.
174
174
 
175
175
  ### Environment Variables
176
176
  Additionally there are times in which you may want to also support configuration via environment variables. [EnvVar](https://github.com/travetto/travetto/tree/main/module/config/src/decorator.ts#L34) supports override configuration values when environment variables are present.
package/__index__.ts CHANGED
@@ -1,5 +1,5 @@
1
1
  export * from './src/decorator';
2
- export * from './src/configuration';
2
+ export * from './src/service';
3
3
  export * from './src/source/env';
4
4
  export * from './src/source/file';
5
5
  export * from './src/parser/json';
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/config",
3
- "version": "3.3.1",
3
+ "version": "3.3.3",
4
4
  "description": "Configuration support",
5
5
  "keywords": [
6
6
  "yaml",
@@ -26,9 +26,9 @@
26
26
  "directory": "module/config"
27
27
  },
28
28
  "dependencies": {
29
- "@travetto/di": "^3.3.1",
30
- "@travetto/schema": "^3.3.1",
31
- "@travetto/yaml": "^3.3.1"
29
+ "@travetto/di": "^3.3.3",
30
+ "@travetto/schema": "^3.3.3",
31
+ "@travetto/yaml": "^3.3.3"
32
32
  },
33
33
  "travetto": {
34
34
  "displayName": "Configuration"
package/src/decorator.ts CHANGED
@@ -2,7 +2,7 @@ import { Class, ClassInstance } from '@travetto/base';
2
2
  import { DependencyRegistry } from '@travetto/di';
3
3
  import { SchemaRegistry } from '@travetto/schema';
4
4
 
5
- import { Configuration } from './configuration';
5
+ import { ConfigurationService } from './service';
6
6
  import { ConfigTarget, ConfigOverrides, CONFIG_OVERRIDES } from './internal/types';
7
7
 
8
8
  /**
@@ -20,7 +20,7 @@ export function Config(ns: string) {
20
20
 
21
21
  target.prototype.postConstruct = async function (): Promise<void> {
22
22
  // Apply config
23
- const cfg = await DependencyRegistry.getInstance(Configuration);
23
+ const cfg = await DependencyRegistry.getInstance(ConfigurationService);
24
24
  await cfg.bindTo(target, this, ns);
25
25
  await og?.call(this);
26
26
  };
@@ -13,7 +13,7 @@ import { ConfigSource, ConfigValue } from './source/types';
13
13
  * Manager for application configuration
14
14
  */
15
15
  @Injectable()
16
- export class Configuration {
16
+ export class ConfigurationService {
17
17
 
18
18
  private static getSorted(configs: ConfigValue[], profiles: string[]): ConfigValue[] {
19
19
  const order = Object.fromEntries(Object.entries(profiles).map(([k, v]) => [v, +k] as const));
@@ -63,7 +63,7 @@ export class Configuration {
63
63
  })
64
64
  );
65
65
 
66
- const sorted = Configuration.getSorted(configs.flat(), this.#profiles);
66
+ const sorted = ConfigurationService.getSorted(configs.flat(), this.#profiles);
67
67
 
68
68
  this.#sources = sorted.map(x => `${x.profile}.${x.priority} - ${x.source}`);
69
69
 
@@ -122,7 +122,9 @@ export class Configuration {
122
122
  await SchemaValidator.validate(cls, out);
123
123
  } catch (err) {
124
124
  if (err instanceof ValidationResultError) {
125
+ const ogMessage = err.message;
125
126
  err.message = `Failed to construct ${cls.Ⲑid} as validation errors have occurred`;
127
+ err.stack = err.stack?.replace(ogMessage, err.message);
126
128
  const file = RootIndex.getFunctionMetadata(cls)!.source;
127
129
  err.payload = { class: cls.Ⲑid, file, ...(err.payload ?? {}) };
128
130
  }