@travetto/config 5.0.0-rc.1 → 5.0.0-rc.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 +3 -3
- package/package.json +3 -3
- package/src/decorator.ts +1 -1
- package/src/parser/parser.ts +1 -1
- package/src/service.ts +9 -10
- package/src/source/file.ts +3 -3
- package/src/trv.d.ts +1 -1
package/README.md
CHANGED
|
@@ -148,7 +148,7 @@ export class EnvConfigSource implements ConfigSource {
|
|
|
148
148
|
```
|
|
149
149
|
|
|
150
150
|
### Custom Configuration Provider
|
|
151
|
-
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#
|
|
151
|
+
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#L20) service for input. This means any needed configuration will need to be accessed via specific patterns.
|
|
152
152
|
|
|
153
153
|
**Code: Custom Configuration Source**
|
|
154
154
|
```typescript
|
|
@@ -167,10 +167,10 @@ export class CustomConfigSource implements ConfigSource {
|
|
|
167
167
|
```
|
|
168
168
|
|
|
169
169
|
## Startup
|
|
170
|
-
At startup, the [ConfigurationService](https://github.com/travetto/travetto/tree/main/module/config/src/service.ts#
|
|
170
|
+
At startup, the [ConfigurationService](https://github.com/travetto/travetto/tree/main/module/config/src/service.ts#L20) 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 [ConfigurationService](https://github.com/travetto/travetto/tree/main/module/config/src/service.ts#
|
|
173
|
+
The [ConfigurationService](https://github.com/travetto/travetto/tree/main/module/config/src/service.ts#L20) 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/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/config",
|
|
3
|
-
"version": "5.0.0-rc.
|
|
3
|
+
"version": "5.0.0-rc.2",
|
|
4
4
|
"description": "Configuration support",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"yaml",
|
|
@@ -26,8 +26,8 @@
|
|
|
26
26
|
"directory": "module/config"
|
|
27
27
|
},
|
|
28
28
|
"dependencies": {
|
|
29
|
-
"@travetto/di": "^5.0.0-rc.
|
|
30
|
-
"@travetto/schema": "^5.0.0-rc.
|
|
29
|
+
"@travetto/di": "^5.0.0-rc.2",
|
|
30
|
+
"@travetto/schema": "^5.0.0-rc.2",
|
|
31
31
|
"yaml": "^2.4.5"
|
|
32
32
|
},
|
|
33
33
|
"travetto": {
|
package/src/decorator.ts
CHANGED
package/src/parser/parser.ts
CHANGED
|
@@ -2,7 +2,7 @@ import fs from 'node:fs/promises';
|
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
4
|
import { DependencyRegistry, Injectable } from '@travetto/di';
|
|
5
|
-
import { AppError } from '@travetto/
|
|
5
|
+
import { AppError } from '@travetto/runtime';
|
|
6
6
|
|
|
7
7
|
import { ConfigParserTarget } from '../internal/types';
|
|
8
8
|
import { ConfigData, ConfigParser } from './types';
|
package/src/service.ts
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import util from 'node:util';
|
|
2
2
|
|
|
3
|
-
import {
|
|
4
|
-
import { AppError, Class, ClassInstance, Env, RuntimeContext, RuntimeResources } from '@travetto/base';
|
|
3
|
+
import { AppError, Class, ClassInstance, Env, Runtime, RuntimeResources } from '@travetto/runtime';
|
|
5
4
|
import { DependencyRegistry, Injectable } from '@travetto/di';
|
|
6
5
|
import { BindUtil, DataUtil, SchemaRegistry, SchemaValidator, ValidationResultError } from '@travetto/schema';
|
|
7
6
|
|
|
@@ -127,7 +126,7 @@ export class ConfigurationService {
|
|
|
127
126
|
const ogMessage = err.message;
|
|
128
127
|
err.message = `Failed to construct ${cls.Ⲑid} as validation errors have occurred`;
|
|
129
128
|
err.stack = err.stack?.replace(ogMessage, err.message);
|
|
130
|
-
const file =
|
|
129
|
+
const file = Runtime.getSource(cls);
|
|
131
130
|
Object.defineProperty(err, 'details', { value: { class: cls.Ⲑid, file, ...(err.details ?? {}) } });
|
|
132
131
|
}
|
|
133
132
|
throw err;
|
|
@@ -145,14 +144,14 @@ export class ConfigurationService {
|
|
|
145
144
|
|
|
146
145
|
console.log('Initialized', {
|
|
147
146
|
manifest: {
|
|
148
|
-
main:
|
|
149
|
-
workspace:
|
|
147
|
+
main: Runtime.main,
|
|
148
|
+
workspace: Runtime.workspace
|
|
150
149
|
},
|
|
151
|
-
|
|
152
|
-
name:
|
|
153
|
-
debug:
|
|
154
|
-
production:
|
|
155
|
-
dynamic:
|
|
150
|
+
runtime: {
|
|
151
|
+
name: Runtime.name,
|
|
152
|
+
debug: Runtime.debug,
|
|
153
|
+
production: Runtime.production,
|
|
154
|
+
dynamic: Runtime.dynamic,
|
|
156
155
|
resourcePaths: RuntimeResources.searchPaths,
|
|
157
156
|
profiles: Env.TRV_PROFILES.list ?? []
|
|
158
157
|
},
|
package/src/source/file.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import fs from 'node:fs/promises';
|
|
2
2
|
import path from 'node:path';
|
|
3
3
|
|
|
4
|
-
import { Env,
|
|
4
|
+
import { Env, Runtime, RuntimeResources } from '@travetto/runtime';
|
|
5
5
|
|
|
6
6
|
import { ConfigSource, ConfigSpec } from './types';
|
|
7
7
|
import { ParserManager } from '../parser/parser';
|
|
@@ -22,7 +22,7 @@ export class FileConfigSource implements ConfigSource {
|
|
|
22
22
|
this.#searchPaths = RuntimeResources.searchPaths.slice().reverse();
|
|
23
23
|
this.#profiles = ([
|
|
24
24
|
['application', 100],
|
|
25
|
-
[
|
|
25
|
+
[Runtime.name!, 200],
|
|
26
26
|
...(Env.TRV_PROFILES.list ?? [])
|
|
27
27
|
.map((p, i) => [p, 300 + i * 10] as const)
|
|
28
28
|
] as const).filter(x => !!x[0]);
|
|
@@ -42,7 +42,7 @@ export class FileConfigSource implements ConfigSource {
|
|
|
42
42
|
data,
|
|
43
43
|
priority: priority + i++,
|
|
44
44
|
source: `file://${profile}`,
|
|
45
|
-
detail:
|
|
45
|
+
detail: Runtime.stripWorkspacePath(full)
|
|
46
46
|
})));
|
|
47
47
|
}
|
|
48
48
|
}
|
package/src/trv.d.ts
CHANGED