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
const bind = await FileBind.create({ filePath: './config.yaml' });Extends
Properties
| Property | Modifier | Type | Inherited from | Defined in |
|---|---|---|---|---|
format | readonly | FileFormat | - | packages/core/src/bind/binds/file.ts:98 |
name | readonly | BindName | Bind.name | packages/core/src/bind/bind.ts:19 |
resolvedPath | readonly | string | - | packages/core/src/bind/binds/file.ts:97 |
Methods
get()
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
| Parameter | Type | Description |
|---|---|---|
sectionName | string | The name of the Section |
elementName | string | The name of the Element |
Returns
Promise<T | undefined>
The value of the element
Inherited from
reload()
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()
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
| Parameter | Type | Description |
|---|---|---|
elementPath | string | Dot-separated element path to resolve. |
Returns
Promise<T | undefined>
The resolved value when present, otherwise undefined.
Overrides
create()
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
| Parameter | Type | Description |
|---|---|---|
options | FileBindOptions | File bind options. |
Returns
Promise<FileBind>
A fully initialised FileBind instance.
Throws
ConfigInvalidException If the file cannot be read, parsed, or scoped.