Config

Type parameters

T: SuperConstructor

T: SuperConstructor

Hierarchy

Struct

Implements

Index

Constructors

Properties

Methods

Constructors

constructor

+ new Config(): Config

Overrides Struct.constructor

Creates an instance of Config. Creates an instance of Config.

example

@define()
class MyConfig extends Config {
appId: string
logging: {
isEnabled = true,
level: 'debug' | 'info'
}
constructor(props: Partial<MyConfig>) {
super();
Object.assign(this, this.processProps(props));
}
}

example

@define()
class MyConfig extends Config {
appId: string
logging: {
isEnabled = true,
level: 'debug' | 'info'
}
constructor(props: Partial<MyConfig>) {
super();
Object.assign(this, this.processProps(props));
}
}

Returns: Config

Properties

Optional included

included? : Record‹string, Configurable›


Optional merged

merged? : Record‹string, Configurable›

Methods

assign

assign(props: Props): void

Implementation of Configurable

Assign collection of values to configuration.

throws {ValidationError} Thrown if the provided properties does not match prop types.

example

@define()
class MyConfig extends Config {
appId: string
logging: {
isEnabled = true,
level: 'debug' | 'info'
}
constructor(props: Partial<MyConfig>) {
super();
Object.assign(this, this.processProps(props));
}
}
const config = new MyAppConfig({
appId: 'my-app-id',
logging: {isEnabled: true, level: 'debug'}
});
const newProps = {
appId: 'my-other-app-id',
logging: {isEnabled: false, level: 'info'}
};
config.assign(newProps);
expect(config).to.be.eql(newProps);
expect(() =>
config.assign({invalidKey: 'invalid-value'})
).to.throw(ValidationError);

Parameters:

NameTypeDescription
propsPropsProperties with relation path: value matching prop types.

Returns: void


equals

equals(other: any): boolean

Implementation of Configurable

Inherited from DefinableMixin.equals

Overrides CreateEmployee.equals

Parameters:

NameType
otherany

Returns: boolean


get

getT›(path: string, runtimeDefaultValue?: T): T | any

Returns value from configuration, included ones or default fallbacks.

example

@define()
class MyConfig extends Config {
appId: string
logging: {
isEnabled = true,
level: 'debug' | 'info'
}
constructor(props: Partial<MyConfig>) {
super();
Object.assign(this, this.processProps(props));
}
}
const config = new MyAppConfig({
appId: 'my-app-id',
logging: {isEnabled: true, level: 'debug'}
})
expect(config.get('appId')).to.be.equal('my-app-id');
expect(config.get('logging.level')).to.be.equal('debug');
expect(
config.get('logging.nonExistentPath', 'my-runtime-fallback')
).to.be.equal('my-runtime-fallback');

Type parameters:

T: any

Parameters:

NameTypeDescription
pathstringConfiguration path using dotted notation for nested objects.
runtimeDefaultValue?TValue that will be returned as default if no value is set on configuration.

Returns: T | any

Resolved value from instance if its found on path; value from other included configurations; the runtime default value(if provided) or undefined.


getActions

getActions(): Actions

Implementation of Hookable

Inherited from HookableMixin.getActions

Overrides CreateEmployee.getActions

Returns: Actions


getDefault

getDefaultT›(path: string): T | any

Implementation of Configurable

Returns default value for configuration(if property initializers are set) or included ones.

Type parameters:

T: any

Parameters:

NameTypeDescription
pathstringConfiguration path using dotted notation for nested objects.

Returns: T | any

Resolved default value or undefined.


getExact

getExactT›(path: string): T | any

Implementation of Configurable

Returns exact value set on configuration or included ones(without any fallback in place).

Type parameters:

T: any

Parameters:

NameTypeDescription
pathstringConfiguration path using dotted notation for nested objects.

Returns: T | any

Resolved value if its found over provided path or value from other included configurations.


getHook

getHook(action: string, id: string): Hook | undefined

Implementation of Hookable

Inherited from HookableMixin.getHook

Overrides CreateEmployee.getHook

Parameters:

NameType
actionstring
idstring

Returns: Hook | undefined


getHookOrThrow

getHookOrThrow(action: string, id: string): Hook

Implementation of Hookable

Inherited from HookableMixin.getHookOrThrow

Overrides CreateEmployee.getHookOrThrow

Parameters:

NameType
actionstring
idstring

Returns: Hook


getHooks

getHooks(action: string): Mappings

Implementation of Hookable

Inherited from HookableMixin.getHooks

Overrides CreateEmployee.getHooks

Parameters:

NameType
actionstring

Returns: Mappings


getPropTypes

getPropTypes(): Props

Implementation of Configurable

Overrides DefinableMixin.getPropTypes

Returns all prop types from whole inheritance tree and other included configurations.

Returns: Props

Plain object representation of prop types.


getPropertyInitializers

getPropertyInitializers(): Props

Implementation of Configurable

Inherited from DefinableMixin.getPropertyInitializers

Overrides CreateEmployee.getPropertyInitializers

Returns: Props


has

has(path: string): boolean

Implementation of Configurable

Evaluates if value is set on configuration or included ones.

example

@define()
class MyConfig extends Config {
appId: string
logging: {
isEnabled = true,
level: 'debug' | 'info'
}
constructor(props: Partial<MyConfig>) {
super();
Object.assign(this, this.processProps(props));
}
}
const config = new MyAppConfig({
appId: 'my-app-id',
logging: {isEnabled: true, level: 'debug'}
})
expect(config.has('appId')).to.be.true;
expect(config.has('logging.level')).to.be.true;
expect(config.has('logging.nonExistentPath')).to.be.false;

Parameters:

NameTypeDescription
pathstringConfiguration path using dotted notation for nested objects.

Returns: boolean

Returns true if configuration is set under questioned path, else false.


hasAction

hasAction(action: string): boolean

Implementation of Hookable

Inherited from HookableMixin.hasAction

Overrides CreateEmployee.hasAction

Parameters:

NameType
actionstring

Returns: boolean


hasDefault

hasDefault(path: string): boolean

Implementation of Configurable

Evaluates if there is default value set for path on configuration or included ones.

Parameters:

NameTypeDescription
pathstringConfiguration path using dotted notation for nested objects.

Returns: boolean

Returns true if default value is set on configuration, else false.


hasHook

hasHook(action: string, id: string): boolean

Implementation of Hookable

Inherited from HookableMixin.hasHook

Overrides CreateEmployee.hasHook

Parameters:

NameType
actionstring
idstring

Returns: boolean


include

include(config: Configurable): void

Implementation of Configurable

Attaches another configuration instance to current configuration.

throws {InvalidConfigError} Thrown if the passed configuration is not implementation of Configurable interface.

example

@define('First')
class First extends Config {
firstKey: string;
constructor(props: Partial<First>) {
super();
Object.assign(this, this.processProps(props));
}
}
@define('Second')
class Second extends Config {
secondKey: string;
constructor(props: Partial<Second>) {
super();
Object.assign(this, this.processProps(props));
}
}
const first = new First({ firstKey: 'first' });
const second = new Second({ secondKey: 'second' });
first.include(second);
expect(first.included).to.be.eql({ Second: second });
expect(first.get('firstKey')).to.be.equal('first');
expect(first.get('secondKey')).to.be.equal('second');

Parameters:

NameTypeDescription
configConfigurableInstance implementing Configurable interface.

Returns: void


isConfigurable

isConfigurable(path: string): boolean

Implementation of Configurable

Evaluates if value can be configured on specific path.

example

@define()
class MyConfig extends Config {
appId: string
logging: {
isEnabled = true,
level: 'debug' | 'info'
}
constructor(props: Partial<MyConfig>) {
super();
Object.assign(this, this.processProps(props));
}
}
const config = new MyAppConfig()
expect(config.isConfigurable('appId')).to.be.true;
expect(config.isConfigurable('logging.level')).to.be.true;
expect(config.isConfigurable('logging.nonExistentPath')).to.be.false;

Parameters:

NameTypeDescription
pathstringConfiguration path using dotted notation for nested objects.

Returns: boolean

Returns true if property on path is configurable on configuration, else false.


merge

merge(config: Configurable): void

Implementation of Configurable

Attaches another configuration instance to current configuration and merges all properties. Parent configuration merging child will always have precedence in values assigned on same paths.

throws {InvalidConfigError} Thrown if the passed configuration is not implementation of Configurable interface.

@define('Config.First')
class First extends Config {
key = 'first-key';
foo = 'first-foo';
constructor(props: Partial<First>) {
super();
Object.assign(this, this.processProps(props));
}
}
@define('Config.Second')
class Second extends Config {
key = 'second-key';
baz = 'second-baz';
constructor(props: Partial<Second>) {
super();
Object.assign(this, this.processProps(props));
}
}
const first = new First({
key: 'first-key',
foo: 'first-foo',
});
const second = new Second({
key: 'second-key',
baz: 'second-baz',
});
first.merge(second);
expect(first.getPropTypes()).to.be.eql({
included: PropTypes.interface({}).isOptional,
merged: PropTypes.interface({}).isOptional,
foo: PropTypes.instanceOf(String),
key: PropTypes.instanceOf(String),
baz: PropTypes.instanceOf(String),
});
expect(first).to.be.eql({
merged: { 'Config.Second': second },
foo: 'first-foo',
baz: 'second-baz',
key: 'first-key',
});

Parameters:

NameTypeDescription
configConfigurableInstance implementing Configurable interface.

Returns: void


overrideHook

overrideHook(action: string, id: string, hook: Hook): void

Implementation of Hookable

Inherited from HookableMixin.overrideHook

Overrides CreateEmployee.overrideHook

Parameters:

NameType
actionstring
idstring
hookHook

Returns: void


registerHook

registerHook(action: string, id: string, hook: Hook, shouldOverride?: boolean): void

Implementation of Hookable

Inherited from HookableMixin.registerHook

Overrides CreateEmployee.registerHook

Parameters:

NameType
actionstring
idstring
hookHook
shouldOverride?boolean

Returns: void


removeHook

removeHook(action: string, id: string): void

Implementation of Hookable

Inherited from HookableMixin.removeHook

Overrides CreateEmployee.removeHook

Parameters:

NameType
actionstring
idstring

Returns: void


set

setT›(path: string, value: T): void

Implementation of Configurable

Sets a value on configuration.

throws {ValidationError} Thrown if the provided value does not match the prop types.

example

@define()
class MyConfig extends Config {
appId: string
logging: {
isEnabled = true,
level: 'debug' | 'info'
}
constructor(props: Partial<MyConfig>) {
super();
Object.assign(this, this.processProps(props));
}
}
const config = new MyAppConfig({
appId: 'my-app-id',
logging: {isEnabled: true, level: 'debug'}
});
config.set('appId', 'set-id')
config.set('logging.level', 'info')
expect(config.get('appId')).to.be.equal('set-id');
expect(config.get('logging.level')).to.be.equal('info');
expect(() =>
config.set('appId', 1337)
).to.throw(ValidationError)
expect(() =>
config.set('logging.nonExistentPath', 'my-value')
).to.throw(ValidationError)

Type parameters:

T: any

Parameters:

NameTypeDescription
pathstringConfiguration path using dotted notation for nested objects.
valueTValue to be set on configuration.

Returns: void


toPlainObject

toPlainObject(): Props

Implementation of Configurable

Inherited from DefinableMixin.toPlainObject

Overrides CreateEmployee.toPlainObject

Returns: Props


validateProps

validateProps(props: Record‹string | number | symbol, any› | undefined, propTypes: PropTypes, isStrict?: boolean): boolean

Inherited from DefinableMixin.validateProps

Overrides CreateEmployee.validateProps

Parameters:

NameType
propsRecord‹string | number | symbol, any› | undefined
propTypesPropTypes
isStrict?boolean

Returns: boolean


Static from

fromT›(props: Record‹string, any›): T

Create an Config from plain object source of properties.

throws {ValidationError} Thrown if the passed properties does not match config property types.

Type parameters:

T

Parameters:

NameTypeDescription
propsRecord‹string, any›Properties as object that can contains other nested configurations.

Returns: T

New instance of Config with assigned properties.


Static getPropTypes

getPropTypes(): Props

Inherited from DefinableMixin.getPropTypes

Overrides CreateEmployee.getPropTypes

Returns: Props


Static getPropertyInitializers

getPropertyInitializers(): Props

Inherited from DefinableMixin.getPropertyInitializers

Overrides CreateEmployee.getPropertyInitializers

Returns: Props