Interface IDictionaryInstance

Interface for dictionary instance implementations. Defines the contract for local, persist, and dummy backends.

Intended use: per-signal Map-like storage for strategy callbacks — e.g. caching LLM annotations, per-level flags, or any keyed data tied to the lifetime of one signal.

Every operation receives the logical when timestamp for look-ahead bias protection: an entry whose stored when is greater than the requested when is invisible (get returns null, has returns false, keys/values/entries/size skip it). A write with a smaller when overwrites an existing record — that lets a restarted backtest reset live-written entries.

interface IDictionaryInstance {
    clear(when: Date): Promise<void>;
    delete(key: string, when: Date): Promise<boolean>;
    dispose(): Promise<void>;
    entries<Value = unknown>(when: Date): Promise<[string, Value][]>;
    get<Value = unknown>(key: string, when: Date): Promise<Value>;
    has(key: string, when: Date): Promise<boolean>;
    keys(when: Date): Promise<string[]>;
    set<Value = unknown>(key: string, value: Value, when: Date): Promise<void>;
    size(when: Date): Promise<number>;
    values<Value = unknown>(when: Date): Promise<Value[]>;
    waitForInit(initial: boolean): Promise<void>;
}

Methods

  • Remove all entries (hard delete).

    Parameters

    • when: Date

      Logical timestamp at which the clear is happening

    Returns Promise<void>

  • Remove the entry under key (hard delete, regardless of its when).

    Parameters

    • key: string

      Entry key

    • when: Date

      Logical timestamp at which the delete is happening

    Returns Promise<boolean>

    true if an entry existed and was removed

  • Releases any resources held by this instance.

    Returns Promise<void>

  • List [key, value] pairs of visible entries (look-ahead-guarded).

    Type Parameters

    • Value = unknown

    Parameters

    • when: Date

      Logical timestamp at which the read is happening

    Returns Promise<[string, Value][]>

    Array of [key, value] tuples

  • Read the value stored under key. Returns null when the entry is missing or its stored when is greater than the requested when (look-ahead bias protection).

    Type Parameters

    • Value = unknown

    Parameters

    • key: string

      Entry key

    • when: Date

      Logical timestamp at which the read is happening

    Returns Promise<Value>

    Stored value, or null

  • Check whether a visible entry exists under key. An entry with a stored when greater than the requested when counts as absent.

    Parameters

    • key: string

      Entry key

    • when: Date

      Logical timestamp at which the check is happening

    Returns Promise<boolean>

    true if a visible entry exists

  • List keys of visible entries (look-ahead-guarded).

    Parameters

    • when: Date

      Logical timestamp at which the read is happening

    Returns Promise<string[]>

    Array of keys

  • Write value under key, stamping it with when. A write with a smaller when overwrites an existing record.

    Type Parameters

    • Value = unknown

    Parameters

    • key: string

      Entry key

    • value: Value

      Value to store

    • when: Date

      Logical timestamp this value belongs to

    Returns Promise<void>

  • Count visible entries (look-ahead-guarded).

    Parameters

    • when: Date

      Logical timestamp at which the read is happening

    Returns Promise<number>

    Number of visible entries

  • List values of visible entries (look-ahead-guarded).

    Type Parameters

    • Value = unknown

    Parameters

    • when: Date

      Logical timestamp at which the read is happening

    Returns Promise<Value[]>

    Array of values

  • Initialize the dictionary instance.

    Parameters

    • initial: boolean

      Whether this is the first initialization

    Returns Promise<void>