Skip to content

Class: ConfigBound

Defined in: packages/config-bound/src/configBound.ts:238

A ConfigBound is the top level object that contains all the Sections and Binds. It is used to retrieve the values of the Elements from its binds.

Implements

Constructors

Constructor

ts
new ConfigBound(
   name, 
   binds?, 
   sections?, 
   logger?): ConfigBound;

Defined in: packages/config-bound/src/configBound.ts:244

Parameters

ParameterTypeDefault value
namestringundefined
bindsBind[][]
sectionsSection[][]
logger?Loggerundefined

Returns

ConfigBound

Properties

PropertyModifierTypeDefined in
bindsreadonlyBind[]packages/config-bound/src/configBound.ts:241
namereadonlystringpackages/config-bound/src/configBound.ts:239
sectionsreadonlySection[]packages/config-bound/src/configBound.ts:242

Methods

addBind()

ts
addBind(bind): void;

Defined in: packages/config-bound/src/configBound.ts:265

Adds a Bind to the ConfigBound

Parameters

ParameterTypeDescription
bindBindThe Bind to add

Returns

void


addSection()

ts
addSection(section): void;

Defined in: packages/config-bound/src/configBound.ts:274

Adds a Section to the ConfigBound

Parameters

ParameterTypeDescription
sectionSectionThe Section to add

Returns

void


get()

ts
get<T>(sectionName, elementName): Promise<T | undefined>;

Defined in: packages/config-bound/src/configBound.ts:308

Gets the value of an Element using the first available Bind.

Type Parameters

Type ParameterDefault type
Tunknown

Parameters

ParameterTypeDescription
sectionNamestringThe name of the section
elementNamestringThe name of the element

Returns

Promise<T | undefined>

The value of the element, or undefined if not found

Throws

SectionNotFoundException If section doesn't exist

Throws

ElementNotFoundException If element doesn't exist in section

Throws

ConfigInvalidException If value fails validation

See

Implementation of

ConfigValueProvider.get


getOrThrow()

ts
getOrThrow<T>(sectionName, elementName): Promise<T>;

Defined in: packages/config-bound/src/configBound.ts:387

Gets the value of an Element, throwing an error if the value is undefined. This is useful for required configuration values.

Error Handling:

  • Throws SectionNotFoundException if the section doesn't exist
  • Throws ElementNotFoundException if the element doesn't exist OR if no value is found
  • Throws ConfigInvalidException if the value fails validation

Type Parameters

Type ParameterDefault type
Tunknown

Parameters

ParameterTypeDescription
sectionNamestringThe name of the section
elementNamestringThe name of the element

Returns

Promise<T>

The value of the element (never undefined)

Throws

SectionNotFoundException If section doesn't exist

Throws

ElementNotFoundException If element doesn't exist or value is undefined

Throws

ConfigInvalidException If value fails validation


getSections()

ts
getSections(): Section[];

Defined in: packages/config-bound/src/configBound.ts:291

Gets the Sections of the ConfigBound

Returns

Section[]

The Sections


getValidationErrors()

ts
getValidationErrors(): Promise<object[]>;

Defined in: packages/config-bound/src/configBound.ts:422

Gets all validation errors for the current configuration without throwing. Useful for collecting all errors at once or implementing custom error handling.

Returns

Promise<object[]>

Array of validation errors with path and message


validate()

ts
validate(): Promise<void>;

Defined in: packages/config-bound/src/configBound.ts:403

Validates all configuration values eagerly without retrieving them. This allows you to catch configuration errors at startup rather than at first access.

Returns

Promise<void>

Throws

ConfigInvalidException if any value fails validation

See


createConfig()

ts
static createConfig<T>(schema, options?): Promise<TypedConfigBound<T>>;

Defined in: packages/config-bound/src/configBound.ts:484

Creates a ConfigBound instance from a declarative schema with full type safety. This is the recommended way to create configuration objects.

Type Parameters

Type Parameter
T extends ConfigSchema<Record<string, unknown>>

Parameters

ParameterType
schemaT
options?{ binds?: Bind[]; logger?: Logger; name?: string; validateOnInit?: boolean; }
options.binds?Bind[]
options.logger?Logger
options.name?string
options.validateOnInit?boolean

Returns

Promise<TypedConfigBound<T>>

Example

typescript
const config = await ConfigBound.createConfig(
  {
    port: {
      default: 3000,
      validator: z.number(),
      description: 'Server port'
    },
    database: {
      properties: {
        host: { default: 'localhost', validator: z.string() },
        port: { default: 5432, validator: z.number() }
      }
    }
  },
  {
    binds: [new EnvVarBind()]
  }
);

const port = await config.get('app', 'port'); // Fully type-safe with autocomplete!