@travetto/config
Advanced tools
Comparing version 0.0.14 to 0.0.16
export const init = { | ||
priority: 0, | ||
action: () => require('./src/service/config-loader').ConfigLoader.initialize() | ||
action: () => require('./src/service/loader').ConfigLoader.initialize() | ||
} |
@@ -8,5 +8,3 @@ { | ||
"@travetto/base": "0.x.x", | ||
"@types/flat": "0.0.28", | ||
"@types/js-yaml": "^3.10.1", | ||
"flat": "^4.0.0", | ||
"js-yaml": "^3.11.0" | ||
@@ -22,3 +20,3 @@ }, | ||
"scripts": {}, | ||
"version": "0.0.14" | ||
"version": "0.0.16" | ||
} |
travetto: Config | ||
=== | ||
This module provides common infrastructure for application based initialization. There is a common | ||
infrastructure pattern used: | ||
- Configuration | ||
- A scan for all `src/app/**/config.ts`. | ||
- Each `config.ts` file must call `registerNamespace` to define a new configuration | ||
namespace. | ||
- Every configuration property can be overridden via environment variables (case-insensitive). | ||
- Object navigation is separated by underscores | ||
- e.g. `MAIL_TRANSPORT_HOST` would override `mail.transport.host` and specifically `transport.host` | ||
in the `mail` namespace. | ||
- All configuration variables should be loaded before any modules use it. | ||
- `config.ts` should not require any code from your modules to ensure the order of loading | ||
- Bootstrap | ||
- Supports initializing the application, and then requiring classes using a glob pattern | ||
to handle the common initialization process. | ||
Common functionality for reading configuration from yaml files, and allowing overriding at execution time | ||
- Process all config information: | ||
- `node_modules/@travetto/*/config/*.yml` | ||
- `config/*.yml` | ||
- `env/<env>.yml` | ||
- `process.env` (override only) | ||
- Depending on which environments are specified, will selectively load `env/<env>.yml` files | ||
- Every configuration property can be overridden via environment variables (case-insensitive). | ||
- Object navigation is separated by underscores | ||
- e.g. `MAIL_TRANSPORT_HOST` would override `mail.transport.host` and specifically `transport.host` | ||
in the `mail` namespace. | ||
Provides a decorator, `@Config("namespace")` that allows for classes to automatically bind config information | ||
on post construct. The decorator will install a `postConstruct` method if not already defined. This is a hook | ||
that is used by other modules. | ||
```typescript config.ts | ||
@Config('sample') | ||
class SampleConfig { | ||
private host: string; | ||
private port: number; | ||
private creds = { | ||
user: '', | ||
password: '' | ||
}; | ||
} | ||
``` | ||
And the corresponding config file | ||
```yaml app.yml | ||
- sample | ||
host: google.com | ||
port: 80 | ||
creds: | ||
user: bob | ||
password: bobspw | ||
``` |
@@ -1,2 +0,2 @@ | ||
import { ConfigLoader } from '../service/config-loader'; | ||
import { ConfigLoader } from '../service/loader'; | ||
@@ -3,0 +3,0 @@ export function Config(ns: string, depTarget?: new (...args: any[]) => any, name: string = '') { |
@@ -1,1 +0,2 @@ | ||
export * from './config-loader'; | ||
export * from './loader'; | ||
export * from './map'; |
import { Config, ConfigLoader } from '../src'; | ||
import * as assert from 'assert'; | ||
@@ -17,4 +18,11 @@ class DbConfig { | ||
if (conf.name !== 'Oscar') { | ||
throw new Error('Should match!'); | ||
} | ||
assert(conf.name === 'Oscar'); | ||
process.env.DB_MYSQL_NAME = 'Roger'; | ||
delete (ConfigLoader as any)['_initialized']; | ||
ConfigLoader.initialize(); | ||
ConfigLoader.bindTo(conf, 'db.mysql'); | ||
assert(conf.name === 'Roger'); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
3
15
42
7626
177
1
- Removed@types/flat@0.0.28
- Removedflat@^4.0.0
- Removed@types/flat@0.0.28(transitive)
- Removedflat@4.1.1(transitive)
- Removedis-buffer@2.0.5(transitive)