@adviser/cement - v0.0.0
    Preparing search index...

    Interface KeyedIf<ITEM, V, K, CTX>

    Interface defining the contract for keyed collection implementations.

    Provides a common interface for managing keyed collections with lifecycle callbacks, LRU support, and flexible key handling. Implementations should provide type-safe access to values indexed by keys.

    class MyKeyed implements KeyedIf<MyItem, MyValue, string, MyContext> {
    // Implementation...
    }
    interface KeyedIf<ITEM, V, K = string, CTX = unknown> {
        onSet(fn: (value: ITEM) => void): UnregFn;
        onDelete(fn: (value: ITEM) => void): UnregFn;
        setParam(params: Partial<KeyedNgOptions<K, ITEM, CTX>>): void;
        asyncGet(key: () => Promise<K>): Promise<V>;
        get(key: K | (() => K)): V;
        getItem(key: K, ctx?: unknown): ITEM;
        has(key: K | (() => K)): boolean;
        delete(key: K): void;
        values(): ITEM[];
        keys(): K[];
        forEach(fn: (v: ITEM, idx: number) => void): void;
        entries(): Iterable<[ITEM, number]>;
    }

    Type Parameters

    • ITEM

      The item type stored in the collection (typically KeyedNgItem)

    • V

      The value type extracted from items

    • K = string

      The key type (defaults to string)

    • CTX = unknown

      The context type (defaults to unknown)

    Implemented by

    Index

    Methods

    • Registers a callback that fires when a new entry is added to the map.

      Parameters

      • fn: (value: ITEM) => void

        Callback function receiving key and value

      Returns UnregFn

      Unregister function to remove the callback

    • Registers a callback that fires when an entry is deleted from the map.

      Parameters

      • fn: (value: ITEM) => void

        Callback function receiving key and value

      Returns UnregFn

      Unregister function to remove the callback

    • Async variant of get() that accepts a function returning a promise for the key.

      Parameters

      • key: () => Promise<K>

        Function that returns a promise resolving to the key

      Returns Promise<V>

      Promise resolving to the value

    • Gets or creates a value for the given key.

      If the key doesn't exist, creates a new instance using the factory function.

      Parameters

      • key: K | (() => K)

        The key or function returning the key

      Returns V

      The value associated with the key

    • Checks if a key exists in the map.

      Parameters

      • key: K | (() => K)

        The key or function returning the key

      Returns boolean

      True if the key exists

    • Deletes an entry from the map.

      Parameters

      • key: K

        The key to delete

      Returns void

    • Returns all keys in the map.

      Returns K[]

      Array of all keys

    • Iterates over all entries in the map.

      Parameters

      • fn: (v: ITEM, idx: number) => void

      Returns void

      Key-value pairs