@travetto/config 5.0.0-rc.8 → 5.0.0
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 +3 -3
- package/package.json +4 -4
- package/src/service.ts +2 -3
- package/src/source/env.ts +1 -1
package/README.md
CHANGED
|
@@ -13,7 +13,7 @@ npm install @travetto/config
|
|
|
13
13
|
yarn add @travetto/config
|
|
14
14
|
```
|
|
15
15
|
|
|
16
|
-
The config module provides support for loading application config on startup. Configuration values support the common [YAML](https://en.wikipedia.org/wiki/YAML) constructs as defined in [yaml](https://github.com/eemeli/yaml). Additionally, the configuration is built upon the [Schema](https://github.com/travetto/travetto/tree/main/module/schema#readme "Data type registry for runtime validation, reflection and binding.") module, to enforce type correctness, and allow for validation of configuration as an entrypoint into the application. Given that all [@Config](https://github.com/travetto/travetto/tree/main/module/config/src/decorator.ts#L13) classes are [@Schema](https://github.com/travetto/travetto/tree/main/module/schema/src/decorator/schema.ts#L14)-based classes, all the standard [@Schema](https://github.com/travetto/travetto/tree/main/module/schema/src/decorator/schema.ts#L14) and [@Field](https://github.com/travetto/travetto/tree/main/module/schema/src/decorator/field.ts#
|
|
16
|
+
The config module provides support for loading application config on startup. Configuration values support the common [YAML](https://en.wikipedia.org/wiki/YAML) constructs as defined in [yaml](https://github.com/eemeli/yaml). Additionally, the configuration is built upon the [Schema](https://github.com/travetto/travetto/tree/main/module/schema#readme "Data type registry for runtime validation, reflection and binding.") module, to enforce type correctness, and allow for validation of configuration as an entrypoint into the application. Given that all [@Config](https://github.com/travetto/travetto/tree/main/module/config/src/decorator.ts#L13) classes are [@Schema](https://github.com/travetto/travetto/tree/main/module/schema/src/decorator/schema.ts#L14)-based classes, all the standard [@Schema](https://github.com/travetto/travetto/tree/main/module/schema/src/decorator/schema.ts#L14) and [@Field](https://github.com/travetto/travetto/tree/main/module/schema/src/decorator/field.ts#L30) functionality applies.
|
|
17
17
|
|
|
18
18
|
## Resolution
|
|
19
19
|
The configuration information is comprised of:
|
|
@@ -23,7 +23,7 @@ Config loading follows a defined resolution path, below is the order in increasi
|
|
|
23
23
|
1. `resources/application.<ext>` - Priority `100` - Load the default `application.<ext>` if available.
|
|
24
24
|
1. `resources/{env}.<ext>` - Priority `200` - Load environment specific profile configurations as defined by the values of `process.env.TRV_ENV`.
|
|
25
25
|
1. `resources/*.<ext>` - Priority `300` - Load profile specific configurations as defined by the values in `process.env.TRV_PROFILES`
|
|
26
|
-
1. [@Injectable](https://github.com/travetto/travetto/tree/main/module/di/src/decorator.ts#
|
|
26
|
+
1. [@Injectable](https://github.com/travetto/travetto/tree/main/module/di/src/decorator.ts#L29) [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
|
|
27
27
|
1. [OverrideConfigSource](https://github.com/travetto/travetto/tree/main/module/config/src/source/override.ts#L11) - Priority `999` - This is for [EnvVar](https://github.com/travetto/travetto/tree/main/module/config/src/decorator.ts#L34) overrides, and is at the top priority for all built-in config sources.
|
|
28
28
|
By default all configuration data is inert, and will only be applied when constructing an instance of a configuration class.
|
|
29
29
|
|
|
@@ -140,7 +140,7 @@ export class EnvConfigSource implements ConfigSource {
|
|
|
140
140
|
try {
|
|
141
141
|
const data = JSON.parse(process.env[this.#envKey] || '{}');
|
|
142
142
|
return { data, priority: this.#priority, source: `env://${this.#envKey}` };
|
|
143
|
-
} catch
|
|
143
|
+
} catch {
|
|
144
144
|
console.error(`env.${this.#envKey} is an invalid format`, { text: process.env[this.#envKey] });
|
|
145
145
|
}
|
|
146
146
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/config",
|
|
3
|
-
"version": "5.0.0
|
|
3
|
+
"version": "5.0.0",
|
|
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": "^5.0.0
|
|
30
|
-
"@travetto/schema": "^5.0.0
|
|
31
|
-
"yaml": "^2.
|
|
29
|
+
"@travetto/di": "^5.0.0",
|
|
30
|
+
"@travetto/schema": "^5.0.0",
|
|
31
|
+
"yaml": "^2.5.0"
|
|
32
32
|
},
|
|
33
33
|
"travetto": {
|
|
34
34
|
"displayName": "Configuration"
|
package/src/service.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import util from 'node:util';
|
|
2
2
|
|
|
3
|
-
import { AppError, Class, ClassInstance, Env, Runtime, RuntimeResources } from '@travetto/runtime';
|
|
3
|
+
import { AppError, castTo, Class, ClassInstance, Env, Runtime, RuntimeResources } from '@travetto/runtime';
|
|
4
4
|
import { DependencyRegistry, Injectable } from '@travetto/di';
|
|
5
5
|
import { BindUtil, DataUtil, SchemaRegistry, SchemaValidator, ValidationResultError } from '@travetto/schema';
|
|
6
6
|
|
|
@@ -33,8 +33,7 @@ export class ConfigurationService {
|
|
|
33
33
|
|
|
34
34
|
while (parts.length && sub) {
|
|
35
35
|
const next = parts.shift()!;
|
|
36
|
-
|
|
37
|
-
sub = sub[next] as Record<string, unknown>;
|
|
36
|
+
sub = castTo(sub[next]);
|
|
38
37
|
}
|
|
39
38
|
|
|
40
39
|
return sub;
|
package/src/source/env.ts
CHANGED
|
@@ -16,7 +16,7 @@ export class EnvConfigSource implements ConfigSource {
|
|
|
16
16
|
try {
|
|
17
17
|
const data = JSON.parse(process.env[this.#envKey] || '{}');
|
|
18
18
|
return { data, priority: this.#priority, source: `env://${this.#envKey}` };
|
|
19
|
-
} catch
|
|
19
|
+
} catch {
|
|
20
20
|
console.error(`env.${this.#envKey} is an invalid format`, { text: process.env[this.#envKey] });
|
|
21
21
|
}
|
|
22
22
|
}
|