Class: Registry
A controlled-mutation key-value store with dot-path access and deep-clone isolation.
Remarks
The registry enforces a safe read/write contract: callers never hold a live reference into the internal store. Every value that enters (set) or leaves (get, all) is deep-cloned via klona, so mutations to a retrieved value cannot affect stored state and vice versa.
Keys are dot-delimited paths (e.g. "user.profile.name"), resolved via dlv for reads and dset for writes; intermediate objects are created automatically on write.
Constructors
Constructor
new Registry(initial?: Record<string, unknown>): Registry;Parameters
| Parameter | Type | Description |
|---|---|---|
initial? | Record<string, unknown> | Optional plain object to seed the registry. Deep-cloned on construction. |
Returns
Registry
Throws
@nhtio/adk!E_INVALID_INITIAL_REGISTRY_VALUE when initial is defined but not a plain object.
Methods
all()
all(): Record<string, unknown>;Returns a deep clone of the entire store contents.
Returns
Record<string, unknown>
A plain object snapshot of all stored key-value pairs.
get()
get<T>(key: string, defaultValue?: T): T;Retrieves the value at key, returning defaultValue if the path is absent.
Type Parameters
| Type Parameter | Default type | Description |
|---|---|---|
T | unknown | Expected type of the value at key. |
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | Dot-delimited path into the store (e.g. "user.name"). |
defaultValue? | T | Fallback returned when the path resolves to undefined. |
Returns
T
A deep clone of the stored value cast to T, or defaultValue when the path is absent.
Remarks
The returned value is a deep clone — mutating it will not affect the stored state.
has()
has(key: string): boolean;Returns true if the registry has a value at key, false otherwise.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | Dot-delimited path into the store (e.g. "user.name"). |
Returns
boolean
true when the path resolves to a value other than undefined.
Remarks
A key resolving to undefined is treated as absent — same convention as Registry.get's defaultValue fallback. No clone is performed; this is a pure existence check.
keys()
keys(): string[];Returns all leaf dot-paths present in the registry.
Returns
string[]
A string array of dot-delimited paths to leaf values in the store.
Remarks
The store is deep-cloned before traversal. Plain objects are walked recursively with path segments joined by dots; arrays, primitives, null, and class instances are treated as leaves.
set()
set(key: string, value: unknown): void;Sets the value at key, creating intermediate objects as needed.
Parameters
| Parameter | Type | Description |
|---|---|---|
key | string | Dot-delimited path into the store (e.g. "user.name"). |
value | unknown | Value to store at the path. |
Returns
void
Remarks
The stored value is isolated from the caller — mutating value after this call will not affect what is held in the registry.
isRegistry()
static isRegistry(value: unknown): value is Registry;Returns true if value is a Registry instance.
Parameters
| Parameter | Type | Description |
|---|---|---|
value | unknown | The value to test. |
Returns
value is Registry
true when value is a Registry instance.
Remarks
Uses @nhtio/adk!isInstanceOf for cross-realm safety.