@travetto/config 8.0.0-alpha.0 → 8.0.0-alpha.2

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
@@ -25,7 +25,7 @@ Config loading follows a defined resolution path, below is the order in increasi
25
25
  1. `resources/{role}.<ext>` - Priority `150` - Load environment specific profile configurations as defined by the values of `process.env.TRV_ROLE`. If the role is `std`, it is replaced with `local` for local development.
26
26
  1. `resources/*.<ext>` - Priority `200` - Load profile specific configurations as defined by the values in `process.env.TRV_PROFILES`
27
27
  1. [@Injectable](https://github.com/travetto/travetto/tree/main/module/di/src/decorator.ts#L16) [ConfigSource](https://github.com/travetto/travetto/tree/main/module/config/src/source/types.ts#L11) - Priority `???` - These are custom config sources provided by the module, and are able to define their own priorities
28
- 1. [OverrideConfigSource](https://github.com/travetto/travetto/tree/main/module/config/src/source/override.ts#L9) - Priority `999` - This is for [@EnvVar](https://github.com/travetto/travetto/tree/main/module/config/src/decorator.ts#L37) overrides, and is at the top priority for all built-in config sources.
28
+ 1. [OverrideConfigSource](https://github.com/travetto/travetto/tree/main/module/config/src/source/override.ts#L9) - Priority `999` - This is for [@EnvVar](https://github.com/travetto/travetto/tree/main/module/config/src/decorator.ts#L36) overrides, and is at the top priority for all built-in config sources.
29
29
 
30
30
  By default all configuration data is inert, and will only be applied when constructing an instance of a configuration class.
31
31
 
@@ -182,7 +182,7 @@ At startup, the [ConfigurationService](https://github.com/travetto/travetto/tree
182
182
  The [ConfigurationService](https://github.com/travetto/travetto/tree/main/module/config/src/service.ts#L24) 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.
183
183
 
184
184
  ### Environment Variables
185
- 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#L37) supports override configuration values when environment variables are present.
185
+ 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#L36) supports override configuration values when environment variables are present.
186
186
 
187
187
  The decorator takes in a namespace, of what part of the resolved configuration you want to bind to your class. Given the following class:
188
188
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@travetto/config",
3
- "version": "8.0.0-alpha.0",
3
+ "version": "8.0.0-alpha.2",
4
4
  "type": "module",
5
5
  "description": "Configuration support",
6
6
  "keywords": [
@@ -27,8 +27,8 @@
27
27
  "directory": "module/config"
28
28
  },
29
29
  "dependencies": {
30
- "@travetto/di": "^8.0.0-alpha.0",
31
- "@travetto/schema": "^8.0.0-alpha.0",
30
+ "@travetto/di": "^8.0.0-alpha.2",
31
+ "@travetto/schema": "^8.0.0-alpha.2",
32
32
  "yaml": "^2.8.2"
33
33
  },
34
34
  "travetto": {
package/src/decorator.ts CHANGED
@@ -17,15 +17,14 @@ export function Config(namespace: string) {
17
17
 
18
18
  ConfigOverrideUtil.setOverrideConfig(cls, namespace);
19
19
 
20
- DependencyRegistryIndex.getForRegister(cls).registerClass();
21
-
22
- const handle: Function = cls.prototype.postConstruct;
23
- cls.prototype.postConstruct = async function (): Promise<void> {
24
- // Apply config
25
- const config = await DependencyRegistryIndex.getInstance(ConfigurationService);
26
- await config.bindTo(cls, this, namespace);
27
- await handle?.call(this);
28
- };
20
+ DependencyRegistryIndex.registerClass(cls);
21
+ DependencyRegistryIndex.registerPostConstruct(cls, {
22
+ priority: 0,
23
+ async operation(this: ClassInstance): Promise<void> {
24
+ const config = await DependencyRegistryIndex.getInstance(ConfigurationService);
25
+ await config.bindTo(cls, this, namespace);
26
+ }
27
+ });
29
28
  return cls;
30
29
  };
31
30
  }
@@ -1,7 +1,7 @@
1
1
  import fs from 'node:fs/promises';
2
2
  import path from 'node:path';
3
3
 
4
- import { DependencyRegistryIndex, Injectable } from '@travetto/di';
4
+ import { DependencyRegistryIndex, Injectable, PostConstruct } from '@travetto/di';
5
5
  import { RuntimeError, toConcrete } from '@travetto/runtime';
6
6
 
7
7
  import type { ConfigData, ConfigParser } from './types.ts';
@@ -12,7 +12,8 @@ export class ParserManager {
12
12
  #extMatch: RegExp;
13
13
  #parsers: Record<string, ConfigParser>;
14
14
 
15
- async postConstruct(): Promise<void> {
15
+ @PostConstruct()
16
+ async initializeParsers(): Promise<void> {
16
17
  const parsers = await DependencyRegistryIndex.getInstances(toConcrete<ConfigParser>());
17
18
 
18
19
  // Register parsers
package/src/service.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  import util from 'node:util';
2
2
 
3
3
  import { RuntimeError, toConcrete, castTo, type Class, Env, Runtime, RuntimeResources, getClass } from '@travetto/runtime';
4
- import { DependencyRegistryIndex, getDefaultQualifier, Injectable } from '@travetto/di';
4
+ import { DependencyRegistryIndex, getDefaultQualifier, Injectable, PostConstruct } from '@travetto/di';
5
5
  import { BindUtil, DataUtil, SchemaRegistryIndex, SchemaValidator, ValidationResultError } from '@travetto/schema';
6
6
 
7
7
  import { ParserManager } from './parser/parser.ts';
@@ -49,7 +49,8 @@ export class ConfigurationService {
49
49
  * - When dealing with two profiles of the same name, they are then sorted by priority
50
50
  * - If of the same priority, then alpha sort on the source
51
51
  */
52
- async postConstruct(): Promise<void> {
52
+ @PostConstruct()
53
+ async loadConfigurations(): Promise<void> {
53
54
  const providers = DependencyRegistryIndex.getCandidates(toConcrete<ConfigSource>());
54
55
 
55
56
  const configs = await Promise.all(