Skip to content

Class: ConfigBound<TSchema>

Defined in: packages/core/src/configBound.ts:101

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.

The optional TSchema generic parameter enables schema-driven type inference for all read methods. When supplied, get(), getOrThrow(), getFromCache(), and getOrThrowFromCache() accept only valid section/element names from the schema and return the corresponding inferred value type.

Type Parameters

Type ParameterDefault type
TSchema extends ConfigSchemaConfigSchema

Implements

Constructors

Constructor

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

Defined in: packages/core/src/configBound.ts:120

Parameters

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

Returns

ConfigBound<TSchema>

Properties

PropertyModifierTypeDefined in
namereadonlystringpackages/core/src/configBound.ts:102

Accessors

binds

Get Signature

ts
get binds(): readonly Bind[];

Defined in: packages/core/src/configBound.ts:111

Configured binds in resolution order.

Returns

readonly Bind[]


sections

Get Signature

ts
get sections(): readonly Section[];

Defined in: packages/core/src/configBound.ts:116

Configured sections.

Returns

readonly Section[]

Methods

addBind()

ts
addBind(bind): void;

Defined in: packages/core/src/configBound.ts:153

Adds a Bind to the ConfigBound

Parameters

ParameterTypeDescription
bindBindThe Bind to add

Returns

void


addSection()

ts
addSection(section): void;

Defined in: packages/core/src/configBound.ts:163

Adds a Section to the ConfigBound

Parameters

ParameterTypeDescription
sectionSectionThe Section to add

Returns

void


get()

Call Signature

ts
get<K, E>(sectionName, elementName): Promise<
  | InferConfigType<TSchema>[K][E]
| undefined>;

Defined in: packages/core/src/configBound.ts:201

Resolves a configuration value from binds/defaults.

When the schema generic TSchema is specified, sectionName and elementName are constrained to valid keys and the return type is inferred from the schema.

Type Parameters
Type Parameter
K extends string
E extends string
Parameters
ParameterTypeDescription
sectionNameKThe name of the section
elementNameEThe name of the element
Returns

Promise< | InferConfigType<TSchema>[K][E] | 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

Call Signature

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

Defined in: packages/core/src/configBound.ts:205

Resolves a configuration value from binds/defaults.

When the schema generic TSchema is specified, sectionName and elementName are constrained to valid keys and the return type is inferred from the schema.

Type Parameters
Type ParameterDefault type
Vunknown
Parameters
ParameterTypeDescription
sectionNamestringThe name of the section
elementNamestringThe name of the element
Returns

Promise<V | 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
ts
ConfigValueProvider.get

getFromCache()

Call Signature

ts
getFromCache<K, E>(sectionName, elementName): 
  | InferConfigType<TSchema>[K][E]
  | undefined;

Defined in: packages/core/src/configBound.ts:299

Gets a cached element value without querying binds.

Returns the value captured by the most recent populateCache call. This method is synchronous and safe to call in contexts that cannot await, such as class constructors.

The returned value reflects the state of the configuration at the time populateCache() last ran — it is not updated by subsequent get calls. Call populateCache() again to refresh the snapshot (e.g. after FileBind.reload()).

When the schema generic TSchema is specified, sectionName and elementName are constrained to valid keys and the return type is inferred from the schema.

Type Parameters
Type Parameter
K extends string
E extends string
Parameters
ParameterTypeDescription
sectionNameKSection name containing the element.
elementNameEElement name to read from cache.
Returns

| InferConfigType<TSchema>[K][E] | undefined

The cached value, or undefined when the element had no value at population time.

Throws

SectionNotFoundException If the section does not exist.

Throws

ElementNotFoundException If the element does not exist in the section.

Throws

ConfigInvalidException If the cache is not ready or the element had a validation error at population time.

Call Signature

ts
getFromCache<V>(sectionName, elementName): V | undefined;

Defined in: packages/core/src/configBound.ts:303

Gets a cached element value without querying binds.

Returns the value captured by the most recent populateCache call. This method is synchronous and safe to call in contexts that cannot await, such as class constructors.

The returned value reflects the state of the configuration at the time populateCache() last ran — it is not updated by subsequent get calls. Call populateCache() again to refresh the snapshot (e.g. after FileBind.reload()).

When the schema generic TSchema is specified, sectionName and elementName are constrained to valid keys and the return type is inferred from the schema.

Type Parameters
Type ParameterDefault type
Vunknown
Parameters
ParameterTypeDescription
sectionNamestringSection name containing the element.
elementNamestringElement name to read from cache.
Returns

V | undefined

The cached value, or undefined when the element had no value at population time.

Throws

SectionNotFoundException If the section does not exist.

Throws

ElementNotFoundException If the element does not exist in the section.

Throws

ConfigInvalidException If the cache is not ready or the element had a validation error at population time.


getOrThrow()

Call Signature

ts
getOrThrow<K, E>(sectionName, elementName): Promise<InferConfigType<TSchema>[K][E]>;

Defined in: packages/core/src/configBound.ts:265

Resolves a configuration value and throws when it is undefined.

When the schema generic TSchema is specified, sectionName and elementName are constrained to valid keys and the return type is inferred from the schema.

Type Parameters
Type Parameter
K extends string
E extends string
Parameters
ParameterTypeDescription
sectionNameKThe name of the section
elementNameEThe name of the element
Returns

Promise<InferConfigType<TSchema>[K][E]>

The value of the element (never undefined)

Throws

SectionNotFoundException If section doesn't exist

Throws

ElementNotFoundException If element doesn't exist in the section

Throws

ConfigUnsetException If the element exists but has no value and no default

Throws

ConfigInvalidException If value fails validation

Call Signature

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

Defined in: packages/core/src/configBound.ts:269

Resolves a configuration value and throws when it is undefined.

When the schema generic TSchema is specified, sectionName and elementName are constrained to valid keys and the return type is inferred from the schema.

Type Parameters
Type ParameterDefault type
Vunknown
Parameters
ParameterTypeDescription
sectionNamestringThe name of the section
elementNamestringThe name of the element
Returns

Promise<V>

The value of the element (never undefined)

Throws

SectionNotFoundException If section doesn't exist

Throws

ElementNotFoundException If element doesn't exist in the section

Throws

ConfigUnsetException If the element exists but has no value and no default

Throws

ConfigInvalidException If value fails validation


getOrThrowFromCache()

Call Signature

ts
getOrThrowFromCache<K, E>(sectionName, elementName): InferConfigType<TSchema>[K][E];

Defined in: packages/core/src/configBound.ts:330

Gets a cached element value and throws when the value is undefined.

When the schema generic TSchema is specified, sectionName and elementName are constrained to valid keys and the return type is inferred from the schema.

Type Parameters
Type Parameter
K extends string
E extends string
Parameters
ParameterTypeDescription
sectionNameKSection name containing the element.
elementNameEElement name to read from cache.
Returns

InferConfigType<TSchema>[K][E]

The cached value.

Throws

SectionNotFoundException If the section does not exist.

Throws

ElementNotFoundException If the element does not exist in the section.

Throws

ConfigUnsetException If the element exists but has no cached value.

Throws

ConfigInvalidException If the cache is not ready.

Throws

Error Re-throws a cached validation error for this element, when present.

Call Signature

ts
getOrThrowFromCache<V>(sectionName, elementName): V;

Defined in: packages/core/src/configBound.ts:334

Gets a cached element value and throws when the value is undefined.

When the schema generic TSchema is specified, sectionName and elementName are constrained to valid keys and the return type is inferred from the schema.

Type Parameters
Type ParameterDefault type
Vunknown
Parameters
ParameterTypeDescription
sectionNamestringSection name containing the element.
elementNamestringElement name to read from cache.
Returns

V

The cached value.

Throws

SectionNotFoundException If the section does not exist.

Throws

ElementNotFoundException If the element does not exist in the section.

Throws

ConfigUnsetException If the element exists but has no cached value.

Throws

ConfigInvalidException If the cache is not ready.

Throws

Error Re-throws a cached validation error for this element, when present.


getSections()

ts
getSections(): readonly Section[];

Defined in: packages/core/src/configBound.ts:181

Gets the Sections of the ConfigBound

Returns

readonly Section[]

The Sections


getValidationErrors()

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

Defined in: packages/core/src/configBound.ts:410

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


isCacheReady()

ts
isCacheReady(): boolean;

Defined in: packages/core/src/configBound.ts:379

Indicates whether the cache has been populated and is ready for cached reads.

Returns

boolean

true when cache population has completed; otherwise false.


populateCache()

ts
populateCache(options?): Promise<void>;

Defined in: packages/core/src/configBound.ts:352

Populates the cache for all known elements.

Parameters

ParameterTypeDescription
options?CacheRefreshOptionsCache population options.

Returns

Promise<void>

A promise that resolves when cache population is complete.

Throws

ConfigInvalidException When an element value is invalid and ignoreInvalid is not enabled.

Throws

SectionNotFoundException If a section lookup fails during population.

Throws

ElementNotFoundException If an element lookup fails during population.


validate()

ts
validate(): Promise<void>;

Defined in: packages/core/src/configBound.ts:391

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<ConfigBound<T>>;

Defined in: packages/core/src/configBound.ts:533

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

ParameterTypeDescription
schemaTDeclarative configuration schema.
options?ConfigBoundCreateOptionsOptional name, binds, logger, and cache mode.

Returns

Promise<ConfigBound<T>>

A fully initialized TypedConfigBound instance typed to the provided schema.

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: [await EnvVarBind.create()]
  }
);

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