Skip to content

Class: FileBind

Defined in: packages/core/src/bind/binds/file.ts:96

A Bind that reads configuration values from a JSON, JSONC, or YAML file.

The file is read and parsed once via FileBind.create. Values are cached in memory and served from the cache on every retrieve() call. Call reload to re-read the file when its contents have changed.

Key resolution follows a nested-first strategy: the element path "database.host" first tries data.database.host, then falls back to data["database.host"] for flat-keyed files.

Explicit null values in the file are treated as "not set" and return undefined, allowing the next bind or element default to take over.

Example

typescript
const bind = await FileBind.create({ filePath: './config.yaml' });

Extends

Properties

PropertyModifierTypeInherited fromDefined in
formatreadonlyFileFormat-packages/core/src/bind/binds/file.ts:98
namereadonlyBindNameBind.namepackages/core/src/bind/bind.ts:19
resolvedPathreadonlystring-packages/core/src/bind/binds/file.ts:97

Methods

get()

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

Defined in: packages/core/src/bind/bind.ts:38

Gets the value from the bind for a specific element

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
sectionNamestringThe name of the Section
elementNamestringThe name of the Element

Returns

Promise<T | undefined>

The value of the element

Inherited from

Bind.get


reload()

ts
reload(): Promise<void>;

Defined in: packages/core/src/bind/binds/file.ts:151

Re-reads and re-parses the configuration file, replacing the cached data.

Returns

Promise<void>

Throws

ConfigInvalidException If the file cannot be read, parsed, or scoped.


retrieve()

ts
retrieve<T>(elementPath): Promise<T | undefined>;

Defined in: packages/core/src/bind/binds/file.ts:139

Retrieves a value for the given element path from the cached file data.

Resolution is nested-first (e.g. a.b -> data.a.b) with a fallback to flat keys (e.g. data["a.b"]). null and undefined are treated as unset and return undefined so downstream binds/defaults can take over.

Type Parameters

Type Parameter
T

Parameters

ParameterTypeDescription
elementPathstringDot-separated element path to resolve.

Returns

Promise<T | undefined>

The resolved value when present, otherwise undefined.

Overrides

Bind.retrieve


create()

ts
static create(options): Promise<FileBind>;

Defined in: packages/core/src/bind/binds/file.ts:122

Creates a FileBind by asynchronously reading and parsing the config file.

Parameters

ParameterTypeDescription
optionsFileBindOptionsFile bind options.

Returns

Promise<FileBind>

A fully initialised FileBind instance.

Throws

ConfigInvalidException If the file cannot be read, parsed, or scoped.