Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@travetto/config

Package Overview
Dependencies
Maintainers
1
Versions
297
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@travetto/config - npm Package Compare versions

Comparing version 0.0.14 to 0.0.16

src/service/loader.ts

2

bootstrap.ts
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');
SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc