@travetto/config 3.0.2 → 3.0.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 +5 -12
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
<!-- This file was generated by @travetto/doc and should not be modified directly -->
|
|
2
|
-
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/config/DOC.
|
|
2
|
+
<!-- Please modify https://github.com/travetto/travetto/tree/main/module/config/DOC.tsx and execute "npx trv doc" to rebuild -->
|
|
3
3
|
# Configuration
|
|
4
|
+
|
|
4
5
|
## Configuration support
|
|
5
6
|
|
|
6
7
|
**Install: @travetto/config**
|
|
@@ -12,27 +13,19 @@ npm install @travetto/config
|
|
|
12
13
|
yarn add @travetto/config
|
|
13
14
|
```
|
|
14
15
|
|
|
15
|
-
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/travetto/travetto/tree/main/module/yaml#readme "Simple YAML support, provides only clean subset of 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
|
|
16
|
-
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#L38) functionality applies.
|
|
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/travetto/travetto/tree/main/module/yaml#readme "Simple YAML support, provides only clean subset of 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#L38) functionality applies.
|
|
17
17
|
|
|
18
18
|
## Resolution
|
|
19
|
-
|
|
20
19
|
The configuration information is comprised of:
|
|
21
|
-
|
|
22
|
-
|
|
23
20
|
* configuration files - [YAML](https://en.wikipedia.org/wiki/YAML), [JSON](https://www.json.org), and basic properties file
|
|
24
21
|
* configuration classes
|
|
25
|
-
|
|
26
22
|
Config loading follows a defined resolution path, below is the order in increasing specificity (`ext` can be `yaml`, `yml`, `json`, `properties`):
|
|
27
|
-
|
|
28
23
|
1. `resources/application.<ext>` - Load the default `application.<ext>` if available.
|
|
29
24
|
1. `resources/*.<ext>` - Load profile specific configurations as defined by the values in `process.env.TRV_PROFILES`
|
|
30
25
|
1. `resources/{env}.<ext>` - Load environment specific profile configurations as defined by the values of `process.env.TRV_ENV`.
|
|
31
|
-
|
|
32
26
|
By default all configuration data is inert, and will only be applied when constructing an instance of a configuration class.
|
|
33
27
|
|
|
34
28
|
### A Complete Example
|
|
35
|
-
|
|
36
29
|
A more complete example setup would look like:
|
|
37
30
|
|
|
38
31
|
**Config: resources/application.yml**
|
|
@@ -116,7 +109,7 @@ At startup, the [Configuration](https://github.com/travetto/travetto/tree/main/m
|
|
|
116
109
|
The [Configuration](https://github.com/travetto/travetto/tree/main/module/config/src/configuration.ts#L14) 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.
|
|
117
110
|
|
|
118
111
|
### Environment Variables
|
|
119
|
-
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.
|
|
112
|
+
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.
|
|
120
113
|
|
|
121
114
|
The decorator takes in a namespace, of what part of the resolved configuration you want to bind to your class. Given the following class:
|
|
122
115
|
|
|
@@ -161,7 +154,7 @@ $ trv main doc/dbconfig-run.ts
|
|
|
161
154
|
}
|
|
162
155
|
```
|
|
163
156
|
|
|
164
|
-
What you see, is that the configuration structure must be honored and the application will fail to start if the constraints do not hold true. This helps to ensure that the configuration, as input to the system, is verified and correct.
|
|
157
|
+
What you see, is that the configuration structure must be honored and the application will fail to start if the constraints do not hold true. This helps to ensure that the configuration, as input to the system, is verified and correct.
|
|
165
158
|
|
|
166
159
|
By passing in the port via the environment variable, the config will construct properly, and the application will startup correctly:
|
|
167
160
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@travetto/config",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.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.0.
|
|
30
|
-
"@travetto/schema": "^3.0.
|
|
31
|
-
"@travetto/yaml": "^3.0.
|
|
29
|
+
"@travetto/di": "^3.0.3",
|
|
30
|
+
"@travetto/schema": "^3.0.3",
|
|
31
|
+
"@travetto/yaml": "^3.0.3"
|
|
32
32
|
},
|
|
33
33
|
"travetto": {
|
|
34
34
|
"displayName": "Configuration"
|