Skip to content
3 min read · 565 words

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

ts
new Registry(initial?: Record<string, unknown>): Registry;

Parameters

ParameterTypeDescription
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()

ts
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()

ts
get<T>(key: string, defaultValue?: T): T;

Retrieves the value at key, returning defaultValue if the path is absent.

Type Parameters

Type ParameterDefault typeDescription
TunknownExpected type of the value at key.

Parameters

ParameterTypeDescription
keystringDot-delimited path into the store (e.g. "user.name").
defaultValue?TFallback 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()

ts
has(key: string): boolean;

Returns true if the registry has a value at key, false otherwise.

Parameters

ParameterTypeDescription
keystringDot-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()

ts
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()

ts
set(key: string, value: unknown): void;

Sets the value at key, creating intermediate objects as needed.

Parameters

ParameterTypeDescription
keystringDot-delimited path into the store (e.g. "user.name").
valueunknownValue 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()

ts
static isRegistry(value: unknown): value is Registry;

Returns true if value is a Registry instance.

Parameters

ParameterTypeDescription
valueunknownThe value to test.

Returns

value is Registry

true when value is a Registry instance.

Remarks

Uses @nhtio/adk!isInstanceOf for cross-realm safety.