@travetto/config 7.0.6 → 7.1.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 +18 -8
- package/package.json +4 -3
- package/src/service.ts +2 -2
- package/src/source/file.ts +17 -6
- package/src/trv.d.ts +1 -1
package/README.md
CHANGED
|
@@ -22,8 +22,8 @@ The configuration information is comprised of:
|
|
|
22
22
|
|
|
23
23
|
Config loading follows a defined resolution path, below is the order in increasing specificity (`ext` can be `yaml`, `yml`, `json`, `properties`):
|
|
24
24
|
1. `resources/application.<ext>` - Priority `100` - Load the default `application.<ext>` if available.
|
|
25
|
-
1. `resources/{
|
|
26
|
-
1. `resources/*.<ext>` - Priority `
|
|
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
|
+
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
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.
|
|
29
29
|
|
|
@@ -48,7 +48,7 @@ database:
|
|
|
48
48
|
password: test
|
|
49
49
|
```
|
|
50
50
|
|
|
51
|
-
**Config: resources/
|
|
51
|
+
**Config: resources/production.json**
|
|
52
52
|
```json
|
|
53
53
|
{
|
|
54
54
|
"database": {
|
|
@@ -64,7 +64,7 @@ with environment variables
|
|
|
64
64
|
|
|
65
65
|
**Config: Environment variables**
|
|
66
66
|
```properties
|
|
67
|
-
|
|
67
|
+
TRV_PROFILES=production
|
|
68
68
|
```
|
|
69
69
|
|
|
70
70
|
At runtime the resolved config would be:
|
|
@@ -85,10 +85,15 @@ Config {
|
|
|
85
85
|
source: 'file://application',
|
|
86
86
|
detail: 'module/config/doc/resources/application.yml'
|
|
87
87
|
},
|
|
88
|
+
{
|
|
89
|
+
priority: 200,
|
|
90
|
+
source: 'file://local',
|
|
91
|
+
detail: 'resources/local.yml'
|
|
92
|
+
},
|
|
88
93
|
{
|
|
89
94
|
priority: 300,
|
|
90
|
-
source: 'file://
|
|
91
|
-
detail: 'module/config/doc/resources/
|
|
95
|
+
source: 'file://production',
|
|
96
|
+
detail: 'module/config/doc/resources/production.json'
|
|
92
97
|
},
|
|
93
98
|
{ priority: 999, source: 'memory://override' }
|
|
94
99
|
],
|
|
@@ -245,10 +250,15 @@ Config {
|
|
|
245
250
|
source: 'file://application',
|
|
246
251
|
detail: 'module/config/doc/resources/application.yml'
|
|
247
252
|
},
|
|
253
|
+
{
|
|
254
|
+
priority: 200,
|
|
255
|
+
source: 'file://local',
|
|
256
|
+
detail: 'resources/local.yml'
|
|
257
|
+
},
|
|
248
258
|
{
|
|
249
259
|
priority: 300,
|
|
250
|
-
source: 'file://
|
|
251
|
-
detail: 'module/config/doc/resources/
|
|
260
|
+
source: 'file://production',
|
|
261
|
+
detail: 'module/config/doc/resources/production.json'
|
|
252
262
|
},
|
|
253
263
|
{ priority: 999, source: 'memory://override' }
|
|
254
264
|
],
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/config",
|
|
3
|
-
"version": "7.0
|
|
3
|
+
"version": "7.1.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "Configuration support",
|
|
6
6
|
"keywords": [
|
|
@@ -27,8 +27,9 @@
|
|
|
27
27
|
"directory": "module/config"
|
|
28
28
|
},
|
|
29
29
|
"dependencies": {
|
|
30
|
-
"@travetto/
|
|
31
|
-
"@travetto/
|
|
30
|
+
"@travetto/cli": "^7.1.0",
|
|
31
|
+
"@travetto/di": "^7.1.0",
|
|
32
|
+
"@travetto/schema": "^7.1.0",
|
|
32
33
|
"yaml": "^2.8.2"
|
|
33
34
|
},
|
|
34
35
|
"travetto": {
|
package/src/service.ts
CHANGED
|
@@ -149,8 +149,8 @@ export class ConfigurationService {
|
|
|
149
149
|
workspace: Runtime.workspace
|
|
150
150
|
},
|
|
151
151
|
runtime: {
|
|
152
|
-
|
|
153
|
-
|
|
152
|
+
production: Runtime.production,
|
|
153
|
+
role: Runtime.role,
|
|
154
154
|
debug: Runtime.debug,
|
|
155
155
|
resourcePaths: RuntimeResources.searchPaths,
|
|
156
156
|
profiles: Env.TRV_PROFILES.list ?? []
|
package/src/source/file.ts
CHANGED
|
@@ -13,6 +13,22 @@ type Profile = [string, number] | readonly [string, number];
|
|
|
13
13
|
*/
|
|
14
14
|
export class FileConfigSource implements ConfigSource {
|
|
15
15
|
|
|
16
|
+
static getProfiles(): Profile[] {
|
|
17
|
+
const profiles: Profile[] = [
|
|
18
|
+
['application', 100]
|
|
19
|
+
];
|
|
20
|
+
if (Runtime.role === 'std') {
|
|
21
|
+
if (Runtime.localDevelopment) {
|
|
22
|
+
profiles.push(['local', 200]);
|
|
23
|
+
}
|
|
24
|
+
} else {
|
|
25
|
+
profiles.push([Runtime.role, 200]);
|
|
26
|
+
}
|
|
27
|
+
profiles.push(...(Env.TRV_PROFILES.list ?? [])
|
|
28
|
+
.map((profile, i) => [profile, 300 + i * 10] as const));
|
|
29
|
+
return profiles;
|
|
30
|
+
}
|
|
31
|
+
|
|
16
32
|
#profiles: Profile[];
|
|
17
33
|
#searchPaths: string[];
|
|
18
34
|
#parser: ParserManager;
|
|
@@ -20,12 +36,7 @@ export class FileConfigSource implements ConfigSource {
|
|
|
20
36
|
constructor(parser: ParserManager) {
|
|
21
37
|
this.#parser = parser;
|
|
22
38
|
this.#searchPaths = RuntimeResources.searchPaths.toReversed();
|
|
23
|
-
this.#profiles = (
|
|
24
|
-
['application', 100],
|
|
25
|
-
[Runtime.env!, 200],
|
|
26
|
-
...(Env.TRV_PROFILES.list ?? [])
|
|
27
|
-
.map((profile, i) => [profile, 300 + i * 10] as const)
|
|
28
|
-
] as const).filter(entry => !!entry[0]);
|
|
39
|
+
this.#profiles = FileConfigSource.getProfiles();
|
|
29
40
|
}
|
|
30
41
|
|
|
31
42
|
async get(): Promise<ConfigPayload[]> {
|